Pass EmpathyConnectionManagers to the import widget
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 15 Feb 2012 11:43:38 +0000 (12:43 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 16 Feb 2012 13:09:19 +0000 (14:09 +0100)
The widget doesn't have to prepare EmpathyConnectionManagers itself any more
and so can populate its treeview right away. By doing so it will request a
more decent size and so the dialog will actually display the accounts which
can be imported without forcing user to resize it.

https://bugzilla.gnome.org/show_bug.cgi?id=670201

src/empathy-account-assistant.c
src/empathy-accounts-dialog.c
src/empathy-import-dialog.c
src/empathy-import-dialog.h
src/empathy-import-widget.c
src/empathy-import-widget.h

index 3c31b81ba01e2962050ac3d5ccec0f670fe19bc5..e4ee048b547713dac4c318bd48e3f8c57cc095dc 100644 (file)
@@ -737,7 +737,8 @@ account_assistant_build_import_page (EmpathyAccountAssistant *self)
   gtk_widget_show (w);
 
   /* NOTE: this is hardcoded as we support pidgin only */
-  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
+  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN,
+      priv->connection_mgrs);
   import = empathy_import_widget_get_widget (iw);
   gtk_container_add (GTK_CONTAINER (w), import);
   gtk_widget_show (import);
index 70a50b33f631a1fd0285cfa8b3fb31e8132a0d17..c6e706dc320409ea00ceb288a9e33942b70d173d 100644 (file)
@@ -2010,10 +2010,11 @@ accounts_dialog_account_enabled_cb (TpAccountManager *manager,
 static GtkWidget *
 display_import_dialog (EmpathyAccountsDialog *dialog)
 {
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   GtkWidget *import_dialog;
 
   import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
-      FALSE);
+      FALSE, priv->cms);
   gtk_widget_show (import_dialog);
 
   return import_dialog;
index 77d11298f3de3c7648ff9d6fcc6351bf4e1d697b..a16d3a6fb8195b3d3a415379e39ef8a15de34f31 100644 (file)
@@ -39,7 +39,8 @@
 
 enum {
   PROP_PARENT = 1,
-  PROP_SHOW_WARNING
+  PROP_SHOW_WARNING,
+  PROP_CMS,
 };
 
 typedef struct {
@@ -48,6 +49,7 @@ typedef struct {
   EmpathyImportWidget *iw;
 
   gboolean show_warning;
+  EmpathyConnectionManagers *cms;
 } EmpathyImportDialogPriv;
 
 G_DEFINE_TYPE (EmpathyImportDialog, empathy_import_dialog, GTK_TYPE_DIALOG)
@@ -62,7 +64,7 @@ import_dialog_add_import_widget (EmpathyImportDialog *self)
 
   area = gtk_dialog_get_content_area (GTK_DIALOG (self));
 
-  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL);
+  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_ALL, priv->cms);
   widget = empathy_import_widget_get_widget (iw);
   gtk_box_pack_start (GTK_BOX (area), widget, FALSE, FALSE, 0);
   gtk_widget_show (widget);
@@ -134,6 +136,9 @@ do_get_property (GObject *object,
     case PROP_SHOW_WARNING:
       g_value_set_boolean (value, priv->show_warning);
       break;
+    case PROP_CMS:
+      g_value_set_object (value, priv->cms);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -155,6 +160,9 @@ do_set_property (GObject *object,
     case PROP_SHOW_WARNING:
       priv->show_warning = g_value_get_boolean (value);
       break;
+    case PROP_CMS:
+      priv->cms = g_value_dup_object (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -199,6 +207,15 @@ empathy_import_dialog_init (EmpathyImportDialog *self)
   gtk_window_set_title (GTK_WINDOW (self), _("Import Accounts"));
   gtk_window_set_modal (GTK_WINDOW (self), TRUE);
 }
+static void
+do_dispose (GObject *obj)
+{
+  EmpathyImportDialogPriv *priv = GET_PRIV (obj);
+
+  g_clear_object (&priv->cms);
+
+  G_OBJECT_CLASS (empathy_import_dialog_parent_class)->dispose (obj);
+}
 
 static void
 empathy_import_dialog_class_init (EmpathyImportDialogClass *klass)
@@ -210,6 +227,7 @@ empathy_import_dialog_class_init (EmpathyImportDialogClass *klass)
   oclass->constructed = do_constructed;
   oclass->get_property = do_get_property;
   oclass->set_property = do_set_property;
+  oclass->dispose = do_dispose;
 
   gtkclass->response = impl_signal_response;
 
@@ -226,13 +244,25 @@ empathy_import_dialog_class_init (EmpathyImportDialogClass *klass)
       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
   g_object_class_install_property (oclass, PROP_SHOW_WARNING, param_spec);
 
+  param_spec = g_param_spec_object ("cms",
+      "EmpathyConnectionManagers", "EmpathyConnectionManager",
+      EMPATHY_TYPE_CONNECTION_MANAGERS,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_CMS, param_spec);
+
   g_type_class_add_private (klass, sizeof (EmpathyImportDialogPriv));
 }
 
 GtkWidget *
 empathy_import_dialog_new (GtkWindow *parent,
-    gboolean warning)
+    gboolean warning,
+    EmpathyConnectionManagers *cms)
 {
-  return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG, "parent-window",
-      parent, "show-warning", warning, NULL);
+  g_return_val_if_fail (EMPATHY_IS_CONNECTION_MANAGERS (cms), NULL);
+
+  return g_object_new (EMPATHY_TYPE_IMPORT_DIALOG,
+      "parent-window", parent,
+      "show-warning", warning,
+      "cms", cms,
+      NULL);
 }
index 0e9d225c4c163114b80f12763401dcdf7555e9bd..a412037d1bcbe9d69b56755bfc930bed6cfaacbf 100644 (file)
@@ -25,6 +25,8 @@
 #ifndef __EMPATHY_IMPORT_DIALOG_H__
 #define __EMPATHY_IMPORT_DIALOG_H__
 
+#include <libempathy/empathy-connection-managers.h>
+
 G_BEGIN_DECLS
 
 #define EMPATHY_TYPE_IMPORT_DIALOG empathy_import_dialog_get_type()
@@ -56,7 +58,8 @@ typedef struct {
 GType empathy_import_dialog_get_type (void);
 
 GtkWidget* empathy_import_dialog_new (GtkWindow *parent_window,
-    gboolean show_warning);
+    gboolean show_warning,
+    EmpathyConnectionManagers *cms);
 
 G_END_DECLS
 
index aaf20d5c59e7ef949f21d51c42a2ce136392db97..041c51003349dc8486134a70cea26f08d58ffaf4 100644 (file)
@@ -55,7 +55,8 @@ enum
 };
 
 enum {
-  PROP_APPLICATION_ID = 1
+  PROP_APPLICATION_ID = 1,
+  PROP_CMS
 };
 
 typedef struct {
@@ -358,20 +359,6 @@ import_widget_set_up_account_list (EmpathyImportWidget *self)
   import_widget_add_accounts_to_model (self);
 }
 
-static void
-import_widget_cms_prepare_cb (GObject *source,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  EmpathyImportWidget *self = user_data;
-
-  if (!empathy_connection_managers_prepare_finish (
-        EMPATHY_CONNECTION_MANAGERS (source), result, NULL))
-    return;
-
-  import_widget_set_up_account_list (self);
-}
-
 static void
 import_widget_destroy_cb (GtkWidget *w,
     EmpathyImportWidget *self)
@@ -392,6 +379,9 @@ do_get_property (GObject *object,
     case PROP_APPLICATION_ID:
       g_value_set_int (value, priv->app_id);
       break;
+    case PROP_CMS:
+      g_value_set_object (value, priv->cms);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -410,6 +400,9 @@ do_set_property (GObject *object,
     case PROP_APPLICATION_ID:
       priv->app_id = g_value_get_int (value);
       break;
+    case PROP_CMS:
+      priv->cms = g_value_dup_object (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -468,8 +461,7 @@ do_constructed (GObject *obj)
   g_signal_connect (priv->vbox, "destroy",
       G_CALLBACK (import_widget_destroy_cb), self);
 
-  empathy_connection_managers_prepare_async (priv->cms,
-      import_widget_cms_prepare_cb, self);
+  import_widget_set_up_account_list (self);
 }
 
 static void
@@ -490,6 +482,12 @@ empathy_import_widget_class_init (EmpathyImportWidgetClass *klass)
       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
   g_object_class_install_property (oclass, PROP_APPLICATION_ID, param_spec);
 
+  param_spec = g_param_spec_object ("cms",
+      "EmpathyConnectionManagers", "EmpathyConnectionManager",
+      EMPATHY_TYPE_CONNECTION_MANAGERS,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+  g_object_class_install_property (oclass, PROP_CMS, param_spec);
+
   g_type_class_add_private (klass, sizeof (EmpathyImportWidgetPriv));
 }
 
@@ -501,14 +499,18 @@ empathy_import_widget_init (EmpathyImportWidget *self)
         EmpathyImportWidgetPriv);
 
   self->priv = priv;
-
-  priv->cms = empathy_connection_managers_dup_singleton ();
 }
 
 EmpathyImportWidget *
-empathy_import_widget_new (EmpathyImportApplication id)
+empathy_import_widget_new (EmpathyImportApplication id,
+    EmpathyConnectionManagers *cms)
 {
-  return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET, "application-id", id, NULL);
+  g_return_val_if_fail (EMPATHY_IS_CONNECTION_MANAGERS (cms), NULL);
+
+  return g_object_new (EMPATHY_TYPE_IMPORT_WIDGET,
+      "application-id", id,
+      "cms", cms,
+      NULL);
 }
 
 GtkWidget *
index 48f2e1d489ae6aae4c70d8a2390fd273ef2fbbd0..14a01d79d7c451b5676192d738eeaa828d8a28b1 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <glib-object.h>
 
+#include <libempathy/empathy-connection-managers.h>
+
 #include "empathy-import-utils.h"
 
 G_BEGIN_DECLS
@@ -59,7 +61,8 @@ typedef struct {
 
 GType empathy_import_widget_get_type (void);
 
-EmpathyImportWidget* empathy_import_widget_new (EmpathyImportApplication id);
+EmpathyImportWidget* empathy_import_widget_new (EmpathyImportApplication id,
+    EmpathyConnectionManagers *cms);
 
 GtkWidget * empathy_import_widget_get_widget (EmpathyImportWidget *self);