[gnome-todo] eds: Simplify and reorganize the code



commit ace2974982723ce1884728e582dcd153d6d08227
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Jan 30 17:39:18 2018 -0200

    eds: Simplify and reorganize the code

 plugins/eds/gtd-plugin-eds.c   | 95 ++++++++++++++++++++----------------------
 plugins/eds/gtd-provider-goa.c | 10 ++---
 plugins/eds/gtd-task-eds.c     |  7 +---
 3 files changed, 52 insertions(+), 60 deletions(-)
---
diff --git a/plugins/eds/gtd-plugin-eds.c b/plugins/eds/gtd-plugin-eds.c
index 3ea3409..bfd2290 100644
--- a/plugins/eds/gtd-plugin-eds.c
+++ b/plugins/eds/gtd-plugin-eds.c
@@ -181,75 +181,72 @@ gtd_plugin_eds_goa_client_finish_cb (GObject      *client,
                                      GAsyncResult *result,
                                      gpointer      user_data)
 {
+  g_autoptr (GError) error = NULL;
   GtdPluginEds *self;
   GoaClient *goa_client;
-  GError *error;
+  GList *accounts;
+  GList *l;
 
   self = GTD_PLUGIN_EDS (user_data);
-  error = NULL;
-
   goa_client = goa_client_new_finish (result, &error);
 
-  if (!error)
+  if (error)
     {
-      GList *accounts;
-      GList *l;
+      g_warning ("%s: %s: %s",
+                 G_STRFUNC,
+                 "Error loading GNOME Online Accounts",
+                 error->message);
 
-      /* Load each supported GoaAccount into a GtdProviderGoa */
-      accounts = goa_client_get_accounts (goa_client);
+      gtd_manager_emit_error_message (gtd_manager_get_default (),
+                                      _("Error loading GNOME Online Accounts"),
+                                      error->message,
+                                      NULL,
+                                      NULL);
+      g_clear_error (&error);
+    }
 
-      for (l = accounts; l != NULL; l = l->next)
-        {
-          GoaObject *object;
-          GoaAccount *account;
+  /* Load each supported GoaAccount into a GtdProviderGoa */
+  accounts = goa_client_get_accounts (goa_client);
 
-          object = l->data;
-          account = goa_object_get_account (object);
+  for (l = accounts; l != NULL; l = l->next)
+    {
+      GtdProviderGoa *provider;
+      GoaAccount *account;
+      GoaObject *object;
 
-          if (g_strv_contains (supported_accounts, goa_account_get_provider_type (account)))
-            {
-              GtdProviderGoa *provider;
+      object = l->data;
+      account = goa_object_get_account (object);
 
-              g_debug ("Creating new provider for account '%s'", goa_account_get_identity (account));
+      if (!g_strv_contains (supported_accounts, goa_account_get_provider_type (account)))
+        {
+          g_object_unref (account);
+          continue;
+        }
 
-              /* Create the new GOA provider */
-              provider = gtd_provider_goa_new (self->registry, account);
+      g_debug ("Creating new provider for account '%s'", goa_account_get_identity (account));
 
-              self->providers = g_list_append (self->providers, provider);
+      /* Create the new GOA provider */
+      provider = gtd_provider_goa_new (self->registry, account);
 
-              g_signal_emit_by_name (self, "provider-added", provider);
-            }
+      self->providers = g_list_append (self->providers, provider);
 
-          g_object_unref (account);
-        }
+      g_signal_emit_by_name (self, "provider-added", provider);
 
-      /* Connect GoaClient signals */
-      g_signal_connect (goa_client,
-                        "account-added",
-                        G_CALLBACK (gtd_plugin_eds_goa_account_added_cb),
-                        user_data);
+      g_object_unref (account);
+    }
 
-      g_signal_connect (goa_client,
-                        "account-removed",
-                        G_CALLBACK (gtd_plugin_eds_goa_account_removed_cb),
-                        user_data);
+  /* Connect GoaClient signals */
+  g_signal_connect (goa_client,
+                    "account-added",
+                    G_CALLBACK (gtd_plugin_eds_goa_account_added_cb),
+                    user_data);
 
-      g_list_free_full (accounts, g_object_unref);
-    }
-  else
-    {
-      g_warning ("%s: %s: %s",
-                 G_STRFUNC,
-                 "Error loading GNOME Online Accounts",
-                 error->message);
+  g_signal_connect (goa_client,
+                    "account-removed",
+                    G_CALLBACK (gtd_plugin_eds_goa_account_removed_cb),
+                    user_data);
 
-      gtd_manager_emit_error_message (gtd_manager_get_default (),
-                                      _("Error loading GNOME Online Accounts"),
-                                      error->message,
-                                      NULL,
-                                      NULL);
-      g_clear_error (&error);
-    }
+  g_list_free_full (accounts, g_object_unref);
 }
 
 
diff --git a/plugins/eds/gtd-provider-goa.c b/plugins/eds/gtd-provider-goa.c
index 708ff42..e0fd49b 100644
--- a/plugins/eds/gtd-provider-goa.c
+++ b/plugins/eds/gtd-provider-goa.c
@@ -93,15 +93,15 @@ gtd_provider_goa_set_account (GtdProviderGoa *provider,
 
   if (provider->account != account)
     {
-      gchar *icon_name;
+      g_autofree gchar *icon_name = NULL;
 
       g_set_object (&provider->account, account);
       g_object_notify (G_OBJECT (provider), "account");
 
 
-      g_message ("Setting up Online Account: %s (%s)",
-                 goa_account_get_identity (account),
-                 goa_account_get_id (account));
+      g_debug ("Setting up Online Account: %s (%s)",
+               goa_account_get_identity (account),
+               goa_account_get_id (account));
 
       /* Update icon */
       icon_name = g_strdup_printf ("goa-account-%s", goa_account_get_provider_type (provider->account));
@@ -112,8 +112,6 @@ gtd_provider_goa_set_account (GtdProviderGoa *provider,
       provider->id = g_strdup_printf ("%s@%s",
                                       goa_account_get_provider_type (provider->account),
                                       goa_account_get_id (provider->account));
-
-      g_free (icon_name);
     }
 }
 
diff --git a/plugins/eds/gtd-task-eds.c b/plugins/eds/gtd-task-eds.c
index 43cd5f4..b3d44f5 100644
--- a/plugins/eds/gtd-task-eds.c
+++ b/plugins/eds/gtd-task-eds.c
@@ -204,7 +204,7 @@ gtd_task_eds_set_complete (GtdTask  *task,
 
   if (complete)
     {
-      GDateTime *now = g_date_time_new_now_utc ();
+      g_autoptr (GDateTime) now = g_date_time_new_now_utc ();
 
       percent = 100;
       status = ICAL_STATUS_COMPLETED;
@@ -223,10 +223,7 @@ gtd_task_eds_set_complete (GtdTask  *task,
        * FIXME: This does not do anything until we have an ical
        * timezone associated with the task
        */
-      icaltimezone_convert_time (dt,
-                                 NULL,
-                                 icaltimezone_get_utc_timezone ());
-      g_date_time_unref (now);
+      icaltimezone_convert_time (dt, NULL, icaltimezone_get_utc_timezone ());
     }
   else
     {


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