[empathy] properly handle accounts using an external storage



commit 4ac8b47ea3be8a91f2ccc1c0a49aaa69e4aaed9e
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Mon Dec 19 12:39:01 2011 +0100

    properly handle accounts using an external storage

 libempathy-gtk/empathy-account-widget.c |  228 +++----------------------------
 src/empathy-accounts-dialog.c           |  112 +++++++++++++++-
 2 files changed, 129 insertions(+), 211 deletions(-)
---
diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c
index abfda9f..71a08a9 100644
--- a/libempathy-gtk/empathy-account-widget.c
+++ b/libempathy-gtk/empathy-account-widget.c
@@ -1089,175 +1089,6 @@ account_widget_build_generic (EmpathyAccountWidget *self,
 }
 
 static void
-account_widget_launch_external_clicked (GtkWidget *button,
-    TpAccount *account)
-{
-  GdkAppLaunchContext *context = NULL;
-  GdkDisplay *display;
-  GAppInfo *app_info;
-  GError *error = NULL;
-
-  app_info = g_object_get_data (G_OBJECT (button), "app-info");
-
-  g_return_if_fail (G_IS_APP_INFO (app_info));
-
-  display = gdk_display_get_default ();
-  context = gdk_display_get_app_launch_context (display);
-
-  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-        &error))
-    {
-      g_critical ("Failed to bisho: %s", error->message);
-      g_clear_error (&error);
-    }
-}
-
-static void
-account_widget_launch_external_clicked_meego (GtkWidget *button,
-    TpAccount *account)
-{
-  if (!tp_strdiff (tp_account_get_storage_provider (account),
-        "com.meego.libsocialweb"))
-    {
-      /* we know how to handle this external provider */
-      GDesktopAppInfo *desktop_info;
-      GError *error = NULL;
-      GdkAppLaunchContext *context = NULL;
-      GdkDisplay *display;
-      gchar *cmd;
-      GAppInfo *app_info;
-
-      desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
-      if (desktop_info == NULL)
-        {
-          g_critical ("Could not locate 'gnome-control-center.desktop'");
-          return;
-        }
-
-      /* glib doesn't have API to start a desktop file with args... (#637875) */
-      cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
-            (GAppInfo *) desktop_info));
-
-      app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
-      g_free (cmd);
-
-      if (app_info == NULL)
-        {
-          DEBUG ("Failed to create app info: %s", error->message);
-          g_error_free (error);
-          goto out;
-        }
-
-      display = gdk_display_get_default ();
-      context = gdk_display_get_app_launch_context (display);
-
-      if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
-            &error))
-        {
-          g_critical ("Failed to bisho: %s", error->message);
-          g_clear_error (&error);
-        }
-
-out:
-      g_object_unref (desktop_info);
-      tp_clear_object (&app_info);
-      tp_clear_object (&context);
-    }
-}
-
-static void
-account_widget_build_external (EmpathyAccountWidget *self,
-    EmpathyAccountSettings *settings)
-{
-  EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
-  TpAccount *account = empathy_account_settings_get_account (settings);
-  GtkWidget *bar, *widget;
-  gchar *str;
-  const gchar *provider, *name = NULL;
-  GDesktopAppInfo *desktop_info = NULL;
-
-  self->ui_details->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
-  priv->grid_common_settings = gtk_grid_new ();
-
-  provider = tp_account_get_storage_provider (account);
-
-  if (!tp_strdiff (provider, "com.meego.libsocialweb"))
-    {
-      name = _("My Web Accounts");
-    }
-  else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
-    {
-      /* FIXME: we should publish the .desktop file in some general way */
-      desktop_info = g_desktop_app_info_new (
-          "gnome-online-accounts-panel.desktop");
-
-      if (desktop_info == NULL)
-        g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
-      else
-        name = g_app_info_get_name (G_APP_INFO (desktop_info));
-    }
-
-  if (name != NULL)
-    {
-      str = g_strdup_printf (
-          _("The account %s is edited via %s."),
-          empathy_account_settings_get_display_name (settings), name);
-    }
-  else
-    {
-      str = g_strdup_printf (
-          _("The account %s cannot be edited in Empathy."),
-          empathy_account_settings_get_display_name (settings));
-    }
-
-  widget = gtk_label_new (str);
-  gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
-  g_free (str);
-
-  bar = gtk_info_bar_new ();
-  gtk_info_bar_set_message_type (GTK_INFO_BAR (bar), GTK_MESSAGE_INFO);
-  gtk_container_add (
-      GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (bar))),
-      widget);
-  gtk_container_set_border_width (GTK_CONTAINER (bar), 6);
-
-  if (!tp_strdiff (provider, "com.meego.libsocialweb"))
-    {
-      /* we know how to handle this external provider */
-      widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
-          _("Launch My Web Accounts"), RESPONSE_LAUNCH);
-
-      g_signal_connect (widget, "clicked",
-          G_CALLBACK (account_widget_launch_external_clicked_meego), account);
-    }
-  else if (desktop_info != NULL)
-    {
-      /* general handler */
-      str = g_strdup_printf (_("Edit %s"), name);
-
-      widget = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
-          str, RESPONSE_LAUNCH);
-
-      g_object_set_data_full (G_OBJECT (widget), "app-info",
-          g_object_ref (desktop_info), g_object_unref);
-
-      g_signal_connect (widget, "clicked",
-          G_CALLBACK (account_widget_launch_external_clicked), account);
-
-      g_free (str);
-    }
-
-  gtk_box_pack_start (GTK_BOX (self->ui_details->widget), bar,
-      FALSE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (self->ui_details->widget),
-      priv->grid_common_settings, FALSE, TRUE, 0);
-
-  gtk_widget_show_all (self->ui_details->widget);
-
-  tp_clear_object (&desktop_info);
-}
-
-static void
 account_widget_build_salut (EmpathyAccountWidget *self,
     const char *filename)
 {
@@ -2067,7 +1898,6 @@ do_constructed (GObject *obj)
   EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (obj);
   EmpathyAccountWidgetPriv *priv = GET_PRIV (self);
   TpAccount *account;
-  TpStorageRestrictionFlags storage_restrictions;
   const gchar *display_name, *default_display_name;
   guint i = 0;
   struct {
@@ -2087,51 +1917,35 @@ do_constructed (GObject *obj)
     WIDGET (idle, irc),
     WIDGET (sofiasip, sip),
   };
+  const gchar *protocol, *cm_name;
 
   account = empathy_account_settings_get_account (priv->settings);
 
-  if (account != NULL)
-    storage_restrictions = tp_account_get_storage_restrictions (account);
-  else
-    storage_restrictions = 0;
-
-  /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
-  if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
-    {
-      DEBUG ("Account is provided by an external storage provider");
+  cm_name = empathy_account_settings_get_cm (priv->settings);
+  protocol = empathy_account_settings_get_protocol (priv->settings);
 
-      account_widget_build_external (self, priv->settings);
-    }
-  else
+  for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
     {
-      const gchar *protocol, *cm_name;
-
-      cm_name = empathy_account_settings_get_cm (priv->settings);
-      protocol = empathy_account_settings_get_protocol (priv->settings);
-
-      for (i = 0 ; i < G_N_ELEMENTS (widgets); i++)
+      if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
+          !tp_strdiff (widgets[i].protocol, protocol))
         {
-          if (!tp_strdiff (widgets[i].cm_name, cm_name) &&
-              !tp_strdiff (widgets[i].protocol, protocol))
-            {
-              gchar *filename;
+          gchar *filename;
 
-              filename = empathy_file_lookup (widgets[i].file,
-                  "libempathy-gtk");
-              widgets[i].func (self, filename);
-              g_free (filename);
+          filename = empathy_file_lookup (widgets[i].file,
+              "libempathy-gtk");
+          widgets[i].func (self, filename);
+          g_free (filename);
 
-              break;
-            }
+          break;
         }
+    }
 
-      if (i == G_N_ELEMENTS (widgets))
-        {
-          gchar *filename = empathy_file_lookup (
-              "empathy-account-widget-generic.ui", "libempathy-gtk");
-          account_widget_build_generic (self, filename);
-          g_free (filename);
-        }
+  if (i == G_N_ELEMENTS (widgets))
+    {
+      gchar *filename = empathy_file_lookup (
+          "empathy-account-widget-generic.ui", "libempathy-gtk");
+      account_widget_build_generic (self, filename);
+      g_free (filename);
     }
 
   /* handle default focus */
@@ -2190,9 +2004,7 @@ do_constructed (GObject *obj)
       account_manager_ready_cb, self);
 
   /* handle apply and cancel button */
-  if (!priv->simple &&
-      !(storage_restrictions &
-        TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS))
+  if (!priv->simple)
     {
       GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
 
diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c
index d7b16ed..0eb3a2a 100644
--- a/src/empathy-accounts-dialog.c
+++ b/src/empathy-accounts-dialog.c
@@ -32,6 +32,7 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 #include <dbus/dbus-glib.h>
+#include <gio/gdesktopappinfo.h>
 
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/defs.h>
@@ -595,12 +596,118 @@ account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
 }
 
 static void
+start_external_app (GAppInfo *app_info)
+{
+  GError *error = NULL;
+  GdkAppLaunchContext *context = NULL;
+  GdkDisplay *display;
+
+  display = gdk_display_get_default ();
+  context = gdk_display_get_app_launch_context (display);
+
+  if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
+        &error))
+    {
+      g_critical ("Failed to bisho: %s", error->message);
+      g_clear_error (&error);
+    }
+
+  tp_clear_object (&context);
+}
+
+static void
+use_external_storage_provider (EmpathyAccountsDialog *self,
+    TpAccount *account)
+{
+  const gchar *provider;
+
+  provider = tp_account_get_storage_provider (account);
+  if (!tp_strdiff (provider, "com.meego.libsocialweb"))
+    {
+      GDesktopAppInfo *desktop_info;
+      gchar *cmd;
+      GAppInfo *app_info;
+      GError *error = NULL;
+
+      desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
+      if (desktop_info == NULL)
+        {
+          g_critical ("Could not locate 'gnome-control-center.desktop'");
+          return;
+        }
+
+      /* glib doesn't have API to start a desktop file with args... (#637875) */
+      cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
+            (GAppInfo *) desktop_info));
+
+      app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
+
+      if (app_info == NULL)
+        {
+          DEBUG ("Failed to create app info: %s", error->message);
+          g_error_free (error);
+        }
+      else
+        {
+          start_external_app (app_info);
+          g_object_unref (app_info);
+        }
+
+      g_object_unref (desktop_info);
+      g_free (cmd);
+      return;
+    }
+  else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
+    {
+      GDesktopAppInfo *desktop_info;
+
+      desktop_info = g_desktop_app_info_new (
+          "gnome-online-accounts-panel.desktop");
+      if (desktop_info == NULL)
+        {
+          g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
+        }
+      else
+        {
+          start_external_app (G_APP_INFO (desktop_info));
+          g_object_unref (desktop_info);
+        }
+
+      return;
+    }
+  else
+    {
+      DEBUG ("Don't know how to handle %s", provider);
+      return;
+    }
+}
+
+static void
 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
     GtkButton *button)
 {
-  DEBUG ("clicked");
+  EmpathyAccountSettings *settings;
+  TpAccount *account;
+  TpStorageRestrictionFlags storage_restrictions;
 
-  account_dialog_create_edit_params_dialog (dialog);
+  settings = accounts_dialog_model_get_selected_settings (dialog);
+
+  account = empathy_account_settings_get_account (settings);
+  g_return_if_fail (account != NULL);
+
+  storage_restrictions = tp_account_get_storage_restrictions (account);
+
+  /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
+  if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
+    {
+      DEBUG ("Account is provided by an external storage provider");
+
+      use_external_storage_provider (dialog, account);
+    }
+  else
+    {
+      account_dialog_create_edit_params_dialog (dialog);
+    }
 }
 
 static void
@@ -702,7 +809,6 @@ account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
   gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
   gtk_widget_show (bbox);
 
-  /* FIXME: make this handle external accounts */
   button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
   gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
   gtk_widget_show (button);



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