[gnome-photos] item-manager: Clean up add_item



commit c472a16a40f966ffed045a1a87373e538bce98d9
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Jan 18 15:16:31 2014 +0100

    item-manager: Clean up add_item
    
    Check if an item already exists for an ID / URN before creating it, and
    do not leak the newly created item. There is no need to return the
    item as it is not used.

 src/photos-item-manager.c |   15 +++++++++++----
 src/photos-item-manager.h |    2 +-
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 906f862..c75cb26 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012, 2013 Red Hat, Inc.
+ * Copyright © 2012, 2013, 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <tracker-sparql.h>
 
 #include "photos-collection-manager.h"
 #include "photos-item-manager.h"
@@ -261,10 +262,15 @@ photos_item_manager_activate_previous_collection (PhotosItemManager *self)
 }
 
 
-PhotosBaseItem *
+void
 photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *cursor)
 {
-  PhotosBaseItem *item;
+  PhotosBaseItem *item = NULL;
+  const gchar *id;
+
+  id = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URN, NULL);
+  if (photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), id) != NULL)
+    goto out;
 
   item = photos_item_manager_create_item (self, cursor);
   photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (item));
@@ -272,7 +278,8 @@ photos_item_manager_add_item (PhotosItemManager *self, TrackerSparqlCursor *curs
   if (photos_base_item_is_collection (item))
     photos_base_manager_add_object (self->priv->col_mngr, G_OBJECT (item));
 
-  return item;
+ out:
+  g_clear_object (&item);
 }
 
 
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index 5d514f9..e2d3e93 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -76,7 +76,7 @@ PhotosBaseManager        *photos_item_manager_dup_singleton      (void);
 
 void                      photos_item_manager_activate_previous_collection (PhotosItemManager *self);
 
-PhotosBaseItem           *photos_item_manager_add_item           (PhotosItemManager *self,
+void                      photos_item_manager_add_item           (PhotosItemManager *self,
                                                                   TrackerSparqlCursor *cursor);
 
 PhotosBaseItem           *photos_item_manager_create_item        (PhotosItemManager *self,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]