[gnome-photos] source-manager: Simplify tracking of GOA accounts



commit 10e45db9fd5d646b8e668a0c7d4ab06c9f5ab553
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Dec 8 02:17:54 2013 +0100

    source-manager: Simplify tracking of GOA accounts

 src/photos-source-manager.c |   72 ++++++++++++------------------------------
 1 files changed, 21 insertions(+), 51 deletions(-)
---
diff --git a/src/photos-source-manager.c b/src/photos-source-manager.c
index 64a1a09..24c73c3 100644
--- a/src/photos-source-manager.c
+++ b/src/photos-source-manager.c
@@ -43,55 +43,21 @@ G_DEFINE_TYPE_WITH_PRIVATE (PhotosSourceManager, photos_source_manager, PHOTOS_T
 
 
 static void
-photos_source_manager_client_account_added (GoaClient *client, GoaObject *object, gpointer user_data)
-{
-  PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
-  PhotosSource *source;
-
-  if (goa_object_peek_photos (object) == NULL)
-    return;
-
-  source = photos_source_new_from_goa_object (object);
-  photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source));
-  g_object_unref (source);
-}
-
-
-static void
-photos_source_manager_client_account_removed (GoaClient *client, GoaObject *object, gpointer user_data)
-{
-  PhotosSourceManager *self = PHOTOS_SOURCE_MANAGER (user_data);
-  GoaAccount *account;
-  const gchar *id;
-
-  account = goa_object_peek_account (object);
-  id = goa_account_get_id (account);
-  photos_base_manager_remove_object_by_id (PHOTOS_BASE_MANAGER (self), id);
-}
-
-
-static void
-photos_source_manager_client_account_changed (GoaClient *client, GoaObject *object, gpointer user_data)
-{
-  if (goa_object_peek_photos (object) == NULL)
-    photos_source_manager_client_account_removed (client, object, user_data);
-  else
-    photos_source_manager_client_account_added (client, object, user_data);
-}
-
-
-static void
 photos_source_manager_refresh_accounts (PhotosSourceManager *self)
 {
   PhotosSourceManagerPrivate *priv = self->priv;
+  GHashTable *new_sources;
   GList *accounts;
   GList *l;
 
   accounts = goa_client_get_accounts (priv->client);
+  new_sources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
   for (l = accounts; l != NULL; l = l->next)
     {
       GoaObject *object = GOA_OBJECT (l->data);
       PhotosSource *source;
+      gchar *id;
 
       if (goa_object_peek_account (object) == NULL)
         continue;
@@ -100,10 +66,14 @@ photos_source_manager_refresh_accounts (PhotosSourceManager *self)
         continue;
 
       source = photos_source_new_from_goa_object (GOA_OBJECT (l->data));
-      photos_base_manager_add_object (PHOTOS_BASE_MANAGER (self), G_OBJECT (source));
+      g_object_get (source, "id", &id, NULL);
+      g_hash_table_insert (new_sources, id, g_object_ref (source));
       g_object_unref (source);
     }
 
+  photos_base_manager_process_new_objects (PHOTOS_BASE_MANAGER (self), new_sources);
+
+  g_hash_table_unref (new_sources);
   g_list_free_full (accounts, g_object_unref);
 }
 
@@ -159,18 +129,18 @@ photos_source_manager_init (PhotosSourceManager *self)
   priv->client = goa_client_new_sync (NULL, NULL); /* TODO: use GError */
   if (priv->client != NULL)
     {
-      g_signal_connect (priv->client,
-                        "account-added",
-                        G_CALLBACK (photos_source_manager_client_account_added),
-                        self);
-      g_signal_connect (priv->client,
-                        "account-changed",
-                        G_CALLBACK (photos_source_manager_client_account_changed),
-                        self);
-      g_signal_connect (priv->client,
-                        "account-removed",
-                        G_CALLBACK (photos_source_manager_client_account_removed),
-                        self);
+      g_signal_connect_swapped (priv->client,
+                                "account-added",
+                                G_CALLBACK (photos_source_manager_refresh_accounts),
+                                self);
+      g_signal_connect_swapped (priv->client,
+                                "account-changed",
+                                G_CALLBACK (photos_source_manager_refresh_accounts),
+                                self);
+      g_signal_connect_swapped (priv->client,
+                                "account-removed",
+                                G_CALLBACK (photos_source_manager_refresh_accounts),
+                                self);
     }
 
   photos_source_manager_refresh_accounts (self);


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