[gnome-todo] storage-goa: use GoaObject directly



commit 36ad6fe77e069e93055f0c5aef47ee613882484e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Aug 24 13:15:20 2015 -0300

    storage-goa: use GoaObject directly
    
    Instead of using a GoaAccount, use the GoaObject directly
    so we can have access to more data.

 src/gtd-manager.c             |   12 +----
 src/storage/gtd-storage-goa.c |  111 ++++++++++++++++++++++-------------------
 src/storage/gtd-storage-goa.h |    7 ++-
 3 files changed, 68 insertions(+), 62 deletions(-)
---
diff --git a/src/gtd-manager.c b/src/gtd-manager.c
index 8f7b49e..fee5d28 100644
--- a/src/gtd-manager.c
+++ b/src/gtd-manager.c
@@ -275,7 +275,7 @@ gtd_manager__goa_account_added_cb (GoaClient  *client,
 
       default_location = g_settings_get_string (priv->settings, "storage-location");
 
-      storage = gtd_storage_goa_new (account);
+      storage = gtd_storage_goa_new (object);
 
       gtd_storage_set_enabled (storage, !goa_account_get_calendar_disabled (account));
       gtd_storage_set_is_default (storage, g_strcmp0 (gtd_storage_get_id (storage), default_location) == 0);
@@ -329,17 +329,11 @@ gtd_manager__goa_client_finish_cb (GObject      *client,
           if (g_strv_contains (supported_providers, goa_account_get_provider_type (account)))
             {
               GtdStorage *storage;
-              GoaCalendar *calendar;
-              gchar *uri;
-
-              calendar = goa_object_peek_calendar (object);
-              uri = goa_calendar_dup_uri (calendar);
 
               /* Create the new GOA storage */
-              storage = gtd_storage_goa_new (account);
+              storage = gtd_storage_goa_new (object);
               gtd_storage_set_enabled (storage, !goa_account_get_calendar_disabled (account));
               gtd_storage_set_is_default (storage, g_strcmp0 (gtd_storage_get_id (storage), 
default_location) == 0);
-              gtd_storage_goa_set_uri (GTD_STORAGE_GOA (storage), uri);
 
               g_assert (gtd_storage_goa_get_account (GTD_STORAGE_GOA (storage)) == account);
 
@@ -349,8 +343,6 @@ gtd_manager__goa_client_finish_cb (GObject      *client,
                                                               storage,
                                                               (GCompareFunc) gtd_storage_compare);
 
-              g_free (uri);
-
               g_signal_emit (user_data, signals[STORAGE_ADDED], 0, storage);
             }
         }
diff --git a/src/storage/gtd-storage-goa.c b/src/storage/gtd-storage-goa.c
index 13adea7..b78cb70 100644
--- a/src/storage/gtd-storage-goa.c
+++ b/src/storage/gtd-storage-goa.c
@@ -26,7 +26,7 @@ struct _GtdStorageGoa
 {
   GtdStorage          parent;
 
-  GoaAccount         *account;
+  GoaObject          *goa_object;
   GIcon              *icon;
   gchar              *parent_source;
   gchar              *uri;
@@ -36,7 +36,7 @@ G_DEFINE_TYPE (GtdStorageGoa, gtd_storage_goa, GTD_TYPE_STORAGE)
 
 enum {
   PROP_0,
-  PROP_ACCOUNT,
+  PROP_GOA_OBJECT,
   PROP_PARENT,
   PROP_URI,
   LAST_PROP
@@ -125,7 +125,7 @@ gtd_storage_goa_finalize (GObject *object)
 {
   GtdStorageGoa *self = (GtdStorageGoa *)object;
 
-  g_clear_object (&self->account);
+  g_clear_object (&self->goa_object);
   g_clear_object (&self->icon);
   g_clear_pointer (&self->parent_source, g_free);
 
@@ -142,8 +142,8 @@ gtd_storage_goa_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_ACCOUNT:
-      g_value_set_object (value, self->account);
+    case PROP_GOA_OBJECT:
+      g_value_set_object (value, self->goa_object);
       break;
 
     case PROP_PARENT:
@@ -169,25 +169,8 @@ gtd_storage_goa_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_ACCOUNT:
-      g_set_object (&self->account, g_value_get_object (value));
-      g_object_notify (object, "account");
-
-      if (self->account)
-        {
-          gchar *icon_name;
-
-          icon_name = g_strdup_printf ("goa-account-%s", goa_account_get_provider_type (self->account));
-
-          gtd_storage_set_name (GTD_STORAGE (object), goa_account_get_identity (self->account));
-          gtd_storage_set_provider (GTD_STORAGE (object), goa_account_get_provider_name (self->account));
-
-          g_set_object (&self->icon, g_themed_icon_new (icon_name));
-          g_object_notify (object, "icon");
-
-          g_free (icon_name);
-        }
-
+    case PROP_GOA_OBJECT:
+      gtd_storage_goa_set_object (self, g_value_get_object (value));
       break;
 
     case PROP_PARENT:
@@ -224,11 +207,11 @@ gtd_storage_goa_class_init (GtdStorageGoaClass *klass)
    */
   g_object_class_install_property (
         object_class,
-        PROP_ACCOUNT,
-        g_param_spec_object ("account",
-                             _("Account of the storage"),
-                             _("The account of the storage location."),
-                             GOA_TYPE_ACCOUNT,
+        PROP_GOA_OBJECT,
+        g_param_spec_object ("goa-object",
+                             _("GoaObject of the storage"),
+                             _("The GoaObject this storage location represents."),
+                             GOA_TYPE_OBJECT,
                              G_PARAM_READWRITE));
 
   /**
@@ -266,37 +249,19 @@ gtd_storage_goa_init (GtdStorageGoa *self)
 }
 
 GtdStorage*
-gtd_storage_goa_new (GoaAccount *account)
+gtd_storage_goa_new (GoaObject *object)
 {
-  GtdStorageGoa *self;
   GtdStorage *storage;
 
   storage =  g_object_new (GTD_TYPE_STORAGE_GOA,
-                           "account", account,
+                           "goa-object", object,
                            NULL);
-  self = GTD_STORAGE_GOA (storage);
 
   /*
    * HACK: for any esoteric reason, gtd_storage_goa_set_property
    * is not called when we set ::account property.
    */
-  g_set_object (&self->account, account);
-  g_object_notify (G_OBJECT (self), "account");
-
-  if (self->account)
-    {
-      gchar *icon_name;
-
-      icon_name = g_strdup_printf ("goa-account-%s", goa_account_get_provider_type (self->account));
-
-      gtd_storage_set_name (storage, goa_account_get_identity (account));
-      gtd_storage_set_provider (storage, goa_account_get_provider_name (account));
-
-      g_set_object (&self->icon, g_themed_icon_new (icon_name));
-      g_object_notify (G_OBJECT (self), "icon");
-
-      g_free (icon_name);
-    }
+  gtd_storage_goa_set_object (GTD_STORAGE_GOA (storage), object);
 
   return storage;
 }
@@ -306,7 +271,51 @@ gtd_storage_goa_get_account (GtdStorageGoa *goa_storage)
 {
   g_return_val_if_fail (GTD_IS_STORAGE_GOA (goa_storage), NULL);
 
-  return goa_storage->account;
+  return goa_storage->goa_object ? goa_object_peek_account (goa_storage->goa_object) : NULL;
+}
+
+GoaObject*
+gtd_storage_goa_get_object (GtdStorageGoa *goa_storage)
+{
+  g_return_val_if_fail (GTD_IS_STORAGE_GOA (goa_storage), NULL);
+
+  return goa_storage->goa_object;
+}
+
+void
+gtd_storage_goa_set_object (GtdStorageGoa *goa_storage,
+                            GoaObject     *object)
+{
+  g_return_if_fail (GTD_IS_STORAGE_GOA (goa_storage));
+
+  if (goa_storage->goa_object != object)
+    {
+      g_set_object (&goa_storage->goa_object, object);
+      g_object_notify (G_OBJECT (goa_storage), "goa-object");
+
+      if (goa_storage->goa_object)
+        {
+          GoaCalendar *calendar;
+          GoaAccount *account;
+          gchar *icon_name;
+
+          /* Setup calendar */
+          calendar = goa_object_peek_calendar (goa_storage->goa_object);
+          gtd_storage_goa_set_uri (goa_storage, goa_calendar_get_uri (calendar));
+
+          /* Setup account */
+          account = goa_object_peek_account (goa_storage->goa_object);
+          icon_name = g_strdup_printf ("goa-account-%s", goa_account_get_provider_type (account));
+
+          gtd_storage_set_name (GTD_STORAGE (goa_storage), goa_account_get_identity (account));
+          gtd_storage_set_provider (GTD_STORAGE (goa_storage), goa_account_get_provider_name (account));
+
+          g_set_object (&goa_storage->icon, g_themed_icon_new (icon_name));
+          g_object_notify (G_OBJECT (goa_storage), "icon");
+
+          g_free (icon_name);
+        }
+    }
 }
 
 const gchar*
diff --git a/src/storage/gtd-storage-goa.h b/src/storage/gtd-storage-goa.h
index 4095d56..a28e881 100644
--- a/src/storage/gtd-storage-goa.h
+++ b/src/storage/gtd-storage-goa.h
@@ -31,10 +31,15 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (GtdStorageGoa, gtd_storage_goa, GTD, STORAGE_GOA, GtdStorage)
 
-GtdStorage*          gtd_storage_goa_new                         (GoaAccount         *account);
+GtdStorage*          gtd_storage_goa_new                         (GoaObject          *object);
 
 GoaAccount*          gtd_storage_goa_get_account                 (GtdStorageGoa      *goa_storage);
 
+GoaObject*           gtd_storage_goa_get_object                  (GtdStorageGoa      *goa_storage);
+
+void                 gtd_storage_goa_set_object                  (GtdStorageGoa      *goa_storage,
+                                                                  GoaObject          *object);
+
 const gchar*         gtd_storage_goa_get_parent                  (GtdStorageGoa      *goa_storage);
 
 void                 gtd_storage_goa_set_parent                  (GtdStorageGoa      *goa_storage,


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