]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts-dialog.c
Merge branch 'gnome-3-8'
[empathy.git] / src / empathy-accounts-dialog.c
index 74cc85939bde9a0c21aef6cb955e785094a8759d..e2e63dc4a0ba713b579a4a165ed40d4648057cf8 100644 (file)
  *          Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
-#include <config.h>
-
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-accounts-dialog.h"
 
-#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>
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-connection-managers.h>
-#include <libempathy/empathy-pkg-kit.h>
-
-#include <libempathy-gtk/empathy-ui-utils.h>
-#include <libempathy-gtk/empathy-protocol-chooser.h>
-#include <libempathy-gtk/empathy-account-widget.h>
-#include <libempathy-gtk/empathy-account-widget-irc.h>
-#include <libempathy-gtk/empathy-account-widget-sip.h>
-#include <libempathy-gtk/empathy-cell-renderer-activatable.h>
-#include <libempathy-gtk/empathy-user-info.h>
-#include <libempathy-gtk/empathy-images.h>
-#include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
-#include <libempathy-gtk/empathy-new-account-dialog.h>
 
 #include "empathy-accounts-common.h"
-#include "empathy-accounts-dialog.h"
+#include "empathy-account-widget-sip.h"
 #include "empathy-import-dialog.h"
 #include "empathy-import-utils.h"
+#include "empathy-local-xmpp-assistant-widget.h"
+#include "empathy-new-account-dialog.h"
+#include "empathy-pkg-kit.h"
+#include "empathy-ui-utils.h"
+#include "empathy-user-info.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 /* Flashing delay for icons (milliseconds). */
 #define FLASH_TIMEOUT 500
@@ -145,6 +127,8 @@ typedef struct {
    * EmpathyAccountsDialog object. */
   gboolean force_change_row;
   GtkTreeRowReference *destination_row;
+
+  GHashTable *icons_cache;
 } EmpathyAccountsDialogPriv;
 
 enum {
@@ -610,6 +594,8 @@ account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
       NULL, NULL);
 
+  gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
+
   priv->setting_widget = (EmpathyAccountWidget *)
     empathy_account_widget_new_for_protocol (settings, FALSE);
 
@@ -639,42 +625,6 @@ account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
   gtk_widget_show (subdialog);
 }
 
-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
-start_from_desktop_file (const char *desktop)
-{
-  GDesktopAppInfo *desktop_info;
-
-  desktop_info = g_desktop_app_info_new (desktop);
-  if (desktop_info == NULL)
-    {
-      g_critical ("Could not locate '%s'", desktop);
-      return;
-    }
-
-  start_external_app (G_APP_INFO (desktop_info));
-  g_object_unref (desktop_info);
-}
-
 static void
 use_external_storage_provider (EmpathyAccountsDialog *self,
     TpAccount *account)
@@ -684,47 +634,20 @@ use_external_storage_provider (EmpathyAccountsDialog *self,
   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);
+      empathy_launch_external_app ("gnome-control-center.desktop",
+          "bisho.desktop", NULL);
       return;
     }
   else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
     {
-      start_from_desktop_file ("gnome-online-accounts-panel.desktop");
+      empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
+          NULL, NULL);
       return;
     }
   else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
     {
-      start_from_desktop_file ("gnome-credentials-panel.desktop");
+      empathy_launch_external_app ("gnome-credentials-panel.desktop",
+          NULL, NULL);
       return;
     }
   else
@@ -993,9 +916,10 @@ accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
           return;
         }
 
-      /* No account and no profile, warn the user */
+      /* No account selected */
       gtk_widget_hide (priv->vbox_details);
-      gtk_widget_set_sensitive (priv->button_add, FALSE);
+      gtk_widget_set_sensitive (priv->button_add, TRUE);
+      gtk_widget_set_sensitive (priv->button_remove, FALSE);
 
       gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
           NOTEBOOK_PAGE_NO_PROTOCOL);
@@ -1096,6 +1020,28 @@ get_status_icon_for_account (EmpathyAccountsDialog *self,
   return empathy_icon_name_for_presence (presence);
 }
 
+static GdkPixbuf *
+ensure_icon (EmpathyAccountsDialog *self,
+    const gchar *icon_name)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+  GdkPixbuf *pixbuf;
+
+  pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
+  if (pixbuf == NULL)
+    {
+      pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+
+      if (pixbuf == NULL)
+        return NULL;
+
+      g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
+          pixbuf);
+    }
+
+  return g_object_ref (pixbuf);
+}
+
 static void
 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
     GtkCellRenderer *cell,
@@ -1104,15 +1050,23 @@ accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
     EmpathyAccountsDialog *dialog)
 {
   TpAccount *account;
+  const gchar *icon_name;
+  GdkPixbuf *pixbuf;
 
   gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
 
+  icon_name = get_status_icon_for_account (dialog, account);
+  pixbuf = ensure_icon (dialog, icon_name);
+
   g_object_set (cell,
-      "icon-name", get_status_icon_for_account (dialog, account),
+      "pixbuf", pixbuf,
       NULL);
 
   if (account != NULL)
     g_object_unref (account);
+
+  if (pixbuf != NULL)
+    g_object_unref (pixbuf);
 }
 
 static void
@@ -1133,7 +1087,7 @@ accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
       -1);
 
   icon_name = empathy_account_settings_get_icon_name (settings);
-  pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+  pixbuf = ensure_icon (dialog, icon_name);
 
   g_object_set (cell,
       "visible", TRUE,
@@ -2261,12 +2215,12 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
       dialog);
 
   /* Add existing accounts */
-  accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
+  accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
   for (l = accounts; l; l = l->next)
     {
       accounts_dialog_add_account (dialog, l->data);
     }
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 
   priv->cms = empathy_connection_managers_dup_singleton ();
 
@@ -2428,6 +2382,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
 
   /* first row */
   priv->label_name = gtk_label_new (NULL);
+  gtk_label_set_ellipsize (GTK_LABEL (priv->label_name), PANGO_ELLIPSIZE_END);
   gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
 
   /* second row */
@@ -2532,6 +2487,8 @@ do_dispose (GObject *obj)
       priv->initial_selection = NULL;
     }
 
+  tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
+
   G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
 }
 
@@ -2626,6 +2583,9 @@ empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
       EMPATHY_TYPE_ACCOUNTS_DIALOG,
       EmpathyAccountsDialogPriv);
   dialog->priv = priv;
+
+  priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+      g_free, g_object_unref);
 }
 
 /* public methods */
@@ -2658,6 +2618,92 @@ empathy_accounts_dialog_show (GtkWindow *parent,
   return GTK_WIDGET (dialog);
 }
 
+#ifdef HAVE_UOA
+typedef struct
+{
+  TpAccount *account;
+  gboolean if_needed;
+} LaunchUOACtx;
+
+static LaunchUOACtx *
+launch_uoa_ctx_new (TpAccount *account,
+    gboolean if_needed)
+{
+  LaunchUOACtx *ctx;
+
+  ctx = g_slice_new0 (LaunchUOACtx);
+  if (account != NULL)
+    ctx->account = g_object_ref (account);
+  ctx->if_needed = if_needed;
+
+  return ctx;
+}
+
+static void
+launch_uoa_ctx_free (LaunchUOACtx *ctx)
+{
+  g_clear_object (&ctx->account);
+  g_slice_free (LaunchUOACtx, ctx);
+}
+
+static void
+am_prepare_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
+  GError *error = NULL;
+  LaunchUOACtx *ctx = user_data;
+  gchar *args = NULL;
+
+  if (!tp_proxy_prepare_finish (manager, result, &error))
+    {
+      DEBUG ("Failed to prepare account manager: %s", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
+    goto out;
+
+  if (ctx->account != NULL)
+    {
+      const GValue *value;
+
+      value = tp_account_get_storage_identifier (ctx->account);
+
+      if (G_VALUE_HOLDS_UINT (value))
+        args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
+    }
+
+  empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
+
+  g_free (args);
+out:
+  launch_uoa_ctx_free (ctx);
+}
+
+static void
+launch_uoa_panel (TpAccount *selected_account,
+    gboolean if_needed,
+    gboolean hidden)
+{
+  TpAccountManager *manager;
+
+  if (hidden)
+    /* Nothing to do */
+    return;
+
+  manager = tp_account_manager_dup ();
+
+  tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
+      launch_uoa_ctx_new (selected_account, if_needed));
+
+  g_object_unref (manager);
+}
+
+#else /* HAVE_UOA */
+
 static void
 launch_empathy_accounts (TpAccount *selected_account,
     gboolean if_needed,
@@ -2688,6 +2734,7 @@ launch_empathy_accounts (TpAccount *selected_account,
 
   g_string_free (args, TRUE);
 }
+#endif /* HAVE_UOA */
 
 void
 empathy_accounts_dialog_show_application (GdkScreen *screen,
@@ -2695,7 +2742,11 @@ empathy_accounts_dialog_show_application (GdkScreen *screen,
     gboolean if_needed,
     gboolean hidden)
 {
+#ifdef HAVE_UOA
+  launch_uoa_panel (selected_account, if_needed, hidden);
+#else
   launch_empathy_accounts (selected_account, if_needed, hidden);
+#endif
 }
 
 gboolean