[gnome-calendar] source-dialog: Move Online Accounts panel spawn to utils



commit 8743121f4d594bcb3a9a2c294560fcdb081dd43a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon May 27 19:52:15 2019 -0300

    source-dialog: Move Online Accounts panel spawn to utils
    
    So that it can be reused by other files.

 src/gui/gcal-source-dialog.c | 76 ++++----------------------------------------
 src/utils/gcal-utils.c       | 55 ++++++++++++++++++++++++++++++++
 src/utils/gcal-utils.h       |  5 +++
 3 files changed, 67 insertions(+), 69 deletions(-)
---
diff --git a/src/gui/gcal-source-dialog.c b/src/gui/gcal-source-dialog.c
index cc90f5ea..8fac4439 100644
--- a/src/gui/gcal-source-dialog.c
+++ b/src/gui/gcal-source-dialog.c
@@ -191,10 +191,6 @@ static void       stack_visible_child_name_changed      (GObject             *ob
 static void       settings_button_clicked               (GtkWidget           *button,
                                                          gpointer             user_data);
 
-
-static void       spawn_goa_with_args                    (const gchar        *action,
-                                                          const gchar        *arg);
-
 static gboolean   pulse_web_entry                       (GcalSourceDialog    *dialog);
 
 static void       url_entry_text_changed                (GObject             *object,
@@ -571,7 +567,8 @@ description_label_link_activated (GtkWidget *widget,
                                   gchar     *uri,
                                   gpointer   user_data)
 {
-  spawn_goa_with_args (NULL, NULL);
+  GApplication *app = g_application_get_default ();
+  gcal_utils_launch_online_accounts_panel (g_application_get_dbus_connection (app), NULL, NULL);
   return TRUE;
 }
 
@@ -630,69 +627,6 @@ name_entry_text_changed (GObject    *object,
     e_source_set_display_name (self->source, gtk_entry_get_text (GTK_ENTRY (self->name_entry)));
 }
 
-static GVariant*
-build_dbus_parameters (const gchar *action,
-                       const gchar *arg)
-{
-  GVariantBuilder builder;
-  GVariant *array[1], *params2[3];
-
-  g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
-
-  if (!action && !arg)
-    {
-      g_variant_builder_add (&builder, "v", g_variant_new_string (""));
-    }
-  else
-    {
-      if (action)
-        g_variant_builder_add (&builder, "v", g_variant_new_string (action));
-
-      if (arg)
-        g_variant_builder_add (&builder, "v", g_variant_new_string (arg));
-    }
-
-  array[0] = g_variant_new ("v", g_variant_new ("(sav)", "online-accounts", &builder));
-
-  params2[0] = g_variant_new_string ("launch-panel");
-  params2[1] = g_variant_new_array (G_VARIANT_TYPE ("v"), array, 1);
-  params2[2] = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
-
-  return g_variant_new_tuple (params2, 3);
-}
-
-static void
-spawn_goa_with_args (const gchar *action,
-                     const gchar *arg)
-{
-  GDBusProxy *proxy;
-
-  proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
-                                         G_DBUS_PROXY_FLAGS_NONE,
-                                         NULL,
-                                         "org.gnome.ControlCenter",
-                                         "/org/gnome/ControlCenter",
-                                         "org.gtk.Actions",
-                                         NULL,
-                                         NULL);
-
-  if (!proxy)
-    {
-      g_warning ("Couldn't open Online Accounts panel");
-      return;
-    }
-
-  g_dbus_proxy_call_sync (proxy,
-                          "Activate",
-                          build_dbus_parameters (action, arg),
-                          G_DBUS_CALL_FLAGS_NONE,
-                          -1,
-                          NULL,
-                          NULL);
-
-  g_clear_object (&proxy);
-}
-
 static void
 response_signal (GtkDialog *dialog,
                  gint       response_id,
@@ -776,13 +710,17 @@ settings_button_clicked (GtkWidget *button,
                          gpointer   user_data)
 {
   GcalSourceDialog *self;
+  GApplication *app;
   const gchar *account_id;
 
   self = GCAL_SOURCE_DIALOG (user_data);
   /* Selects the account to open */
   account_id = g_object_get_data (G_OBJECT (self->account_label), "account-id");
 
-  spawn_goa_with_args ((gchar*) account_id, NULL);
+  app = g_application_get_default ();
+  gcal_utils_launch_online_accounts_panel (g_application_get_dbus_connection (app),
+                                           (gchar*) account_id,
+                                           NULL);
 }
 
 static void
diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 855ac459..495efc0a 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -1188,3 +1188,58 @@ gcal_translate_child_window_position (GtkWidget *target,
 
   return TRUE;
 }
+
+void
+gcal_utils_launch_online_accounts_panel (GDBusConnection *connection,
+                                         const gchar     *action,
+                                         const gchar     *arg)
+{
+  g_autoptr (GDBusProxy) proxy = NULL;
+  GVariantBuilder builder;
+  GVariant *params[3];
+  GVariant *array[1];
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+
+  if (!action && !arg)
+    {
+      g_variant_builder_add (&builder, "v", g_variant_new_string (""));
+    }
+  else
+    {
+      if (action)
+        g_variant_builder_add (&builder, "v", g_variant_new_string (action));
+
+      if (arg)
+        g_variant_builder_add (&builder, "v", g_variant_new_string (arg));
+    }
+
+  array[0] = g_variant_new ("v", g_variant_new ("(sav)", "online-accounts", &builder));
+
+  params[0] = g_variant_new_string ("launch-panel");
+  params[1] = g_variant_new_array (G_VARIANT_TYPE ("v"), array, 1);
+  params[2] = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
+
+  proxy = g_dbus_proxy_new_sync (connection,
+                                 G_DBUS_PROXY_FLAGS_NONE,
+                                 NULL,
+                                 "org.gnome.ControlCenter",
+                                 "/org/gnome/ControlCenter",
+                                 "org.gtk.Actions",
+                                 NULL,
+                                 NULL);
+
+  if (!proxy)
+    {
+      g_warning ("Couldn't open Online Accounts panel");
+      return;
+    }
+
+  g_dbus_proxy_call_sync (proxy,
+                          "Activate",
+                          g_variant_new_tuple (params, 3),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          -1,
+                          NULL,
+                          NULL);
+}
diff --git a/src/utils/gcal-utils.h b/src/utils/gcal-utils.h
index 924fc6e8..9dd751e4 100644
--- a/src/utils/gcal-utils.h
+++ b/src/utils/gcal-utils.h
@@ -121,4 +121,9 @@ gboolean             gcal_translate_child_window_position        (GtkWidget
                                                                   gdouble              src_y,
                                                                   gdouble             *real_x,
                                                                   gdouble             *real_y);
+
+void                 gcal_utils_launch_online_accounts_panel     (GDBusConnection     *connection,
+                                                                  const gchar         *action,
+                                                                  const gchar         *arg);
+
 #endif /* __GCAL_UTILS_H__ */


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