[gnome-photos] collection-icon-watcher: Make it a final class



commit 55a70891af8624e17b38ca23572c8b626f538abb
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Mar 15 10:17:32 2016 +0100

    collection-icon-watcher: Make it a final class

 src/photos-collection-icon-watcher.c |  125 ++++++++++++++++------------------
 src/photos-collection-icon-watcher.h |   31 +--------
 2 files changed, 60 insertions(+), 96 deletions(-)
---
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index c88479b..7ff8295 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -40,8 +40,9 @@
 #include "photos-utils.h"
 
 
-struct _PhotosCollectionIconWatcherPrivate
+struct _PhotosCollectionIconWatcher
 {
+  GObject parent_instance;
   GHashTable *item_connections;
   GList *items;
   GList *urns;
@@ -51,6 +52,14 @@ struct _PhotosCollectionIconWatcherPrivate
   guint to_query_remaining;
 };
 
+struct _PhotosCollectionIconWatcherClass
+{
+  GObjectClass parent_class;
+
+  /* signals */
+  void (*icon_updated) (PhotosCollectionIconWatcher *self, GIcon *icon);
+};
+
 enum
 {
   PROP_0,
@@ -66,19 +75,18 @@ enum
 static guint signals[LAST_SIGNAL] = { 0 };
 
 
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosCollectionIconWatcher, photos_collection_icon_watcher, G_TYPE_OBJECT);
+G_DEFINE_TYPE (PhotosCollectionIconWatcher, photos_collection_icon_watcher, G_TYPE_OBJECT);
 
 
 static void
 photos_collection_icon_watcher_create_collection_icon (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GIcon *icon;
   GList *icons = NULL;
   GList *l;
   gint size;
 
-  for (l = priv->items; l != NULL; l = l->next)
+  for (l = self->items; l != NULL; l = l->next)
     {
       GdkPixbuf *original_icon;
       PhotosBaseItem *item = PHOTOS_BASE_ITEM (l->data);
@@ -92,7 +100,7 @@ photos_collection_icon_watcher_create_collection_icon (PhotosCollectionIconWatch
   size = photos_utils_get_icon_size ();
   icon = photos_utils_create_collection_icon (size, icons);
 
-  if (priv->collection != NULL)
+  if (self->collection != NULL)
     g_signal_emit (self, signals[ICON_UPDATED], 0, icon);
 
   g_list_free_full (icons, g_object_unref);
@@ -103,10 +111,9 @@ photos_collection_icon_watcher_create_collection_icon (PhotosCollectionIconWatch
 static void
 photos_collection_icon_watcher_all_items_ready (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GList *l;
 
-  for (l = priv->items; l != NULL; l = l->next)
+  for (l = self->items; l != NULL; l = l->next)
     {
       PhotosBaseItem *item = PHOTOS_BASE_ITEM (l->data);
       gulong update_id;
@@ -115,7 +122,7 @@ photos_collection_icon_watcher_all_items_ready (PhotosCollectionIconWatcher *sel
                                             "info-updated",
                                             G_CALLBACK 
(photos_collection_icon_watcher_create_collection_icon),
                                             self);
-      g_hash_table_insert (priv->item_connections, GUINT_TO_POINTER ((guint) update_id), g_object_ref 
(item));
+      g_hash_table_insert (self->item_connections, GUINT_TO_POINTER ((guint) update_id), g_object_ref 
(item));
     }
 
   photos_collection_icon_watcher_create_collection_icon (self);
@@ -125,27 +132,24 @@ photos_collection_icon_watcher_all_items_ready (PhotosCollectionIconWatcher *sel
 static void
 photos_collection_icon_watcher_clear (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
+  g_hash_table_remove_all (self->item_connections);
 
-  g_hash_table_remove_all (priv->item_connections);
+  g_list_free_full (self->urns, g_free);
+  self->urns = NULL;
 
-  g_list_free_full (priv->urns, g_free);
-  priv->urns = NULL;
-
-  g_list_free_full (priv->items, g_object_unref);
-  priv->items = NULL;
+  g_list_free_full (self->items, g_object_unref);
+  self->items = NULL;
 }
 
 
 static void
 photos_collection_icon_watcher_destroy (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GHashTableIter iter;
   PhotosBaseItem *item;
   gpointer key;
 
-  g_hash_table_iter_init (&iter, priv->item_connections);
+  g_hash_table_iter_init (&iter, self->item_connections);
   while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &item))
     {
       guint id = GPOINTER_TO_UINT (key);
@@ -157,10 +161,8 @@ photos_collection_icon_watcher_destroy (PhotosCollectionIconWatcher *self)
 static void
 photos_collection_icon_watcher_to_query_collector (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
-
-  priv->to_query_remaining--;
-  if (priv->to_query_remaining == 0)
+  self->to_query_remaining--;
+  if (self->to_query_remaining == 0)
     photos_collection_icon_watcher_all_items_ready (self);
 }
 
@@ -169,14 +171,13 @@ static void
 photos_collection_icon_watcher_to_query_executed (TrackerSparqlCursor *cursor, gpointer user_data)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (user_data);
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
 
-  if (cursor != NULL && priv->item_mngr != NULL)
+  if (cursor != NULL && self->item_mngr != NULL)
     {
       PhotosBaseItem *item;
 
-      item = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (priv->item_mngr), cursor);
-      priv->items = g_list_prepend (priv->items, item);
+      item = photos_item_manager_create_item (PHOTOS_ITEM_MANAGER (self->item_mngr), cursor);
+      self->items = g_list_prepend (self->items, item);
     }
 
   photos_collection_icon_watcher_to_query_collector (self);
@@ -187,38 +188,37 @@ photos_collection_icon_watcher_to_query_executed (TrackerSparqlCursor *cursor, g
 static void
 photos_collection_icon_watcher_finished (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GApplication *app;
   GList *l;
   GList *to_query = NULL;
   PhotosSearchContextState *state;
 
-  g_return_if_fail (priv->item_mngr != NULL);
+  g_return_if_fail (self->item_mngr != NULL);
 
-  if (priv->urns == NULL)
+  if (self->urns == NULL)
     return;
 
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  priv->to_query_remaining = 0;
+  self->to_query_remaining = 0;
 
-  for (l = priv->urns; l != NULL; l = l->next)
+  for (l = self->urns; l != NULL; l = l->next)
     {
       GObject *item;
       const gchar *urn = (gchar *) l->data;
 
-      item = photos_base_manager_get_object_by_id (priv->item_mngr, urn);
+      item = photos_base_manager_get_object_by_id (self->item_mngr, urn);
       if (item != NULL)
-        priv->items = g_list_prepend (priv->items, g_object_ref (item));
+        self->items = g_list_prepend (self->items, g_object_ref (item));
       else
         {
           to_query = g_list_prepend (to_query, g_strdup (urn));
-          priv->to_query_remaining++;
+          self->to_query_remaining++;
         }
     }
 
-  if (priv->to_query_remaining == 0)
+  if (self->to_query_remaining == 0)
     {
       photos_collection_icon_watcher_all_items_ready (self);
       return;
@@ -246,7 +246,6 @@ static void
 photos_collection_icon_watcher_cursor_next (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (user_data);
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (source_object);
   GError *error;
   gboolean valid;
@@ -264,7 +263,7 @@ photos_collection_icon_watcher_cursor_next (GObject *source_object, GAsyncResult
     goto end;
 
   urn = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
-  priv->urns = g_list_prepend (priv->urns, urn);
+  self->urns = g_list_prepend (self->urns, urn);
 
   tracker_sparql_cursor_next_async (cursor,
                                     NULL,
@@ -273,7 +272,7 @@ photos_collection_icon_watcher_cursor_next (GObject *source_object, GAsyncResult
   return;
 
  end:
-  priv->urns = g_list_reverse (priv->urns);
+  self->urns = g_list_reverse (self->urns);
   photos_collection_icon_watcher_finished (self);
   tracker_sparql_cursor_close (cursor);
   g_object_unref (self);
@@ -308,7 +307,6 @@ photos_collection_icon_watcher_query_executed (GObject *source_object, GAsyncRes
 static void
 photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
   GApplication *app;
   PhotosQuery *query;
   PhotosSearchContextState *state;
@@ -316,18 +314,18 @@ photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
 
   photos_collection_icon_watcher_clear (self);
 
-  if (G_UNLIKELY (priv->queue == NULL))
+  if (G_UNLIKELY (self->queue == NULL))
     return;
 
-  if (priv->collection == NULL)
+  if (self->collection == NULL)
     return;
 
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  id = photos_filterable_get_id (PHOTOS_FILTERABLE (priv->collection));
+  id = photos_filterable_get_id (PHOTOS_FILTERABLE (self->collection));
   query = photos_query_builder_collection_icon_query (state, id);
-  photos_tracker_queue_select (priv->queue,
+  photos_tracker_queue_select (self->queue,
                                query->sparql,
                                NULL,
                                photos_collection_icon_watcher_query_executed,
@@ -351,19 +349,18 @@ static void
 photos_collection_icon_watcher_dispose (GObject *object)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (object);
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
 
-  if (priv->item_connections != NULL)
+  if (self->item_connections != NULL)
     {
       photos_collection_icon_watcher_destroy (self);
-      g_hash_table_unref (priv->item_connections);
-      priv->item_connections = NULL;
+      g_hash_table_unref (self->item_connections);
+      self->item_connections = NULL;
     }
 
-  g_list_free_full (priv->items, g_object_unref);
-  priv->items = NULL;
+  g_list_free_full (self->items, g_object_unref);
+  self->items = NULL;
 
-  g_clear_object (&priv->queue);
+  g_clear_object (&self->queue);
 
   G_OBJECT_CLASS (photos_collection_icon_watcher_parent_class)->dispose (object);
 }
@@ -373,15 +370,14 @@ static void
 photos_collection_icon_watcher_finalize (GObject *object)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (object);
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
 
-  g_list_free_full (priv->urns, g_free);
+  g_list_free_full (self->urns, g_free);
 
-  if (priv->collection != NULL)
-    g_object_remove_weak_pointer (G_OBJECT (priv->collection), (gpointer *) &priv->collection);
+  if (self->collection != NULL)
+    g_object_remove_weak_pointer (G_OBJECT (self->collection), (gpointer *) &self->collection);
 
-  if (priv->item_mngr != NULL)
-    g_object_remove_weak_pointer (G_OBJECT (priv->item_mngr), (gpointer *) &priv->item_mngr);
+  if (self->item_mngr != NULL)
+    g_object_remove_weak_pointer (G_OBJECT (self->item_mngr), (gpointer *) &self->item_mngr);
 
   G_OBJECT_CLASS (photos_collection_icon_watcher_parent_class)->finalize (object);
 }
@@ -394,14 +390,13 @@ photos_collection_icon_watcher_set_property (GObject *object,
                                              GParamSpec *pspec)
 {
   PhotosCollectionIconWatcher *self = PHOTOS_COLLECTION_ICON_WATCHER (object);
-  PhotosCollectionIconWatcherPrivate *priv = self->priv;
 
   switch (prop_id)
     {
     case PROP_COLLECTION:
-      priv->collection = PHOTOS_BASE_ITEM (g_value_get_object (value)); /* self is owned by collection */
-      if (priv->collection != NULL)
-        g_object_add_weak_pointer (G_OBJECT (priv->collection), (gpointer *) &priv->collection);
+      self->collection = PHOTOS_BASE_ITEM (g_value_get_object (value)); /* self is owned by collection */
+      if (self->collection != NULL)
+        g_object_add_weak_pointer (G_OBJECT (self->collection), (gpointer *) &self->collection);
       break;
 
     default:
@@ -414,22 +409,18 @@ photos_collection_icon_watcher_set_property (GObject *object,
 static void
 photos_collection_icon_watcher_init (PhotosCollectionIconWatcher *self)
 {
-  PhotosCollectionIconWatcherPrivate *priv;
   GApplication *app;
   PhotosSearchContextState *state;
 
-  self->priv = photos_collection_icon_watcher_get_instance_private (self);
-  priv = self->priv;
-
   app = g_application_get_default ();
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
-  priv->item_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+  self->item_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
 
-  priv->item_mngr = state->item_mngr;
-  g_object_add_weak_pointer (G_OBJECT (priv->item_mngr), (gpointer *) &priv->item_mngr);
+  self->item_mngr = state->item_mngr;
+  g_object_add_weak_pointer (G_OBJECT (self->item_mngr), (gpointer *) &self->item_mngr);
 
-  priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+  self->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
 }
 
 
diff --git a/src/photos-collection-icon-watcher.h b/src/photos-collection-icon-watcher.h
index 1207857..e6635b5 100644
--- a/src/photos-collection-icon-watcher.h
+++ b/src/photos-collection-icon-watcher.h
@@ -37,41 +37,14 @@ G_BEGIN_DECLS
   (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
    PHOTOS_TYPE_COLLECTION_ICON_WATCHER, PhotosCollectionIconWatcher))
 
-#define PHOTOS_COLLECTION_ICON_WATCHER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_CAST ((klass), \
-   PHOTOS_TYPE_COLLECTION_ICON_WATCHER, PhotosCollectionIconWatcherClass))
-
 #define PHOTOS_IS_COLLECTION_ICON_WATCHER(obj) \
   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
    PHOTOS_TYPE_COLLECTION_ICON_WATCHER))
 
-#define PHOTOS_IS_COLLECTION_ICON_WATCHER_CLASS(klass) \
-  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
-   PHOTOS_TYPE_COLLECTION_ICON_WATCHER))
-
-#define PHOTOS_COLLECTION_ICON_WATCHER_GET_CLASS(obj) \
-  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
-   PHOTOS_TYPE_COLLECTION_ICON_WATCHER, PhotosCollectionIconWatcherClass))
-
 typedef void (*PhotosCollectionIconWatcherCallback) (TrackerSparqlCursor *, gpointer);
 
-typedef struct _PhotosCollectionIconWatcher        PhotosCollectionIconWatcher;
-typedef struct _PhotosCollectionIconWatcherClass   PhotosCollectionIconWatcherClass;
-typedef struct _PhotosCollectionIconWatcherPrivate PhotosCollectionIconWatcherPrivate;
-
-struct _PhotosCollectionIconWatcher
-{
-  GObject parent_instance;
-  PhotosCollectionIconWatcherPrivate *priv;
-};
-
-struct _PhotosCollectionIconWatcherClass
-{
-  GObjectClass parent_class;
-
-  /* signals */
-  void (*icon_updated) (PhotosCollectionIconWatcher *self, GIcon *icon);
-};
+typedef struct _PhotosCollectionIconWatcher      PhotosCollectionIconWatcher;
+typedef struct _PhotosCollectionIconWatcherClass PhotosCollectionIconWatcherClass;
 
 GType                         photos_collection_icon_watcher_get_type    (void) G_GNUC_CONST;
 


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