[empathy/mc5: 187/483] Synchronize EmpathyProtocolChooser and EmpathyAccountsDialog



commit 4b6db27ff05428dda571c5e60bc7229a4dd91d5f
Author: Cosimo Cecchi <cosimo cecchi collabora co uk>
Date:   Wed Jul 22 14:15:01 2009 +0200

    Synchronize EmpathyProtocolChooser and EmpathyAccountsDialog
    
    Synchronize the two objects with the help of EmpathyConnectionManagers,
    so that we can get a consistent list of the CMs when using the chooser.

 libempathy-gtk/empathy-protocol-chooser.c |   77 +++++++++++++----------------
 libempathy-gtk/empathy-protocol-chooser.h |    6 ++-
 tests/test-empathy-protocol-chooser.c     |    8 ++--
 3 files changed, 43 insertions(+), 48 deletions(-)
---
diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c
index ebb1984..4629798 100644
--- a/libempathy-gtk/empathy-protocol-chooser.c
+++ b/libempathy-gtk/empathy-protocol-chooser.c
@@ -29,6 +29,7 @@
 #include <gtk/gtk.h>
 
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-connection-managers.h>
 
 #include "empathy-protocol-chooser.h"
 #include "empathy-ui-utils.h"
@@ -59,6 +60,7 @@ typedef struct
 {
   GtkListStore *store;
   gboolean dispose_run;
+  EmpathyConnectionManagers *cms;
 
 } EmpathyProtocolChooserPriv;
 
@@ -154,27 +156,26 @@ protocol_choosers_add_cm (EmpathyProtocolChooser *chooser,
     }
 }
 
-
 static void
-protocol_choosers_cms_listed (TpConnectionManager * const *cms,
-    gsize n_cms,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
+protocol_chooser_add_cms_list (EmpathyProtocolChooser *protocol_chooser,
+    GList *cms)
 {
-  TpConnectionManager * const *iter;
+  GList *l;
 
-  if (error !=NULL)
-    {
-      DEBUG ("Failed to get connection managers: %s", error->message);
-      return;
-    }
+  for (l = cms; l != NULL; l = l->next)
+    protocol_choosers_add_cm (protocol_chooser, l->data);
 
-  for (iter = cms ; iter != NULL && *iter != NULL; iter++)
-    protocol_choosers_add_cm (EMPATHY_PROTOCOL_CHOOSER (weak_object),
-      *iter);
+  gtk_combo_box_set_active (GTK_COMBO_BOX (protocol_chooser), 0);
+}
 
-  gtk_combo_box_set_active (GTK_COMBO_BOX (weak_object), 0);
+static void
+protocol_chooser_cms_ready_cb (EmpathyConnectionManagers *cms,
+    GParamSpec *pspec,
+    EmpathyProtocolChooser *protocol_chooser)
+{
+  if (empathy_connection_managers_is_ready (cms))
+    protocol_chooser_add_cms_list
+        (protocol_chooser, empathy_connection_managers_get_cms (cms));
 }
 
 static void
@@ -182,9 +183,7 @@ protocol_chooser_constructed (GObject *object)
 {
   EmpathyProtocolChooser *protocol_chooser;
   EmpathyProtocolChooserPriv *priv;
-
   GtkCellRenderer *renderer;
-  TpDBusDaemon *dbus;
 
   priv = GET_PRIV (object);
   protocol_chooser = EMPATHY_PROTOCOL_CHOOSER (object);
@@ -212,11 +211,6 @@ protocol_chooser_constructed (GObject *object)
       "text", COL_LABEL,
       NULL);
 
-  dbus = tp_dbus_daemon_dup (NULL);
-  tp_list_connection_managers (dbus, protocol_choosers_cms_listed,
-    NULL, NULL, object);
-  g_object_unref (dbus);
-
   /* Set the protocol sort function */
   gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (priv->store),
       COL_PROTOCOL,
@@ -226,6 +220,13 @@ protocol_chooser_constructed (GObject *object)
       COL_PROTOCOL,
       GTK_SORT_ASCENDING);
 
+  if (empathy_connection_managers_is_ready (priv->cms))
+    protocol_chooser_add_cms_list (protocol_chooser,
+        empathy_connection_managers_get_cms (priv->cms));
+  else
+    g_signal_connect (priv->cms, "notify::ready",
+        G_CALLBACK (protocol_chooser_cms_ready_cb), protocol_chooser);
+
   if (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed)
     G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->constructed (object);
 }
@@ -238,6 +239,7 @@ empathy_protocol_chooser_init (EmpathyProtocolChooser *protocol_chooser)
         EMPATHY_TYPE_PROTOCOL_CHOOSER, EmpathyProtocolChooserPriv);
 
   priv->dispose_run = FALSE;
+  priv->cms = empathy_connection_managers_dup_singleton ();
 
   protocol_chooser->priv = priv;
 }
@@ -259,6 +261,12 @@ protocol_chooser_dispose (GObject *object)
       priv->store = NULL;
     }
 
+  if (priv->cms)
+    {
+      g_object_unref (priv->cms);
+      priv->cms = NULL;
+    }
+
   (G_OBJECT_CLASS (empathy_protocol_chooser_parent_class)->dispose) (object);
 }
 
@@ -273,6 +281,8 @@ empathy_protocol_chooser_class_init (EmpathyProtocolChooserClass *klass)
   g_type_class_add_private (object_class, sizeof (EmpathyProtocolChooserPriv));
 }
 
+/* public methods */
+
 /**
  * empathy_protocol_chooser_get_selected_protocol:
  * @protocol_chooser: an #EmpathyProtocolChooser
@@ -308,30 +318,13 @@ TpConnectionManager *empathy_protocol_chooser_dup_selected (
 }
 
 /**
- * empathy_protocol_chooser_n_protocols:
- * @protocol_chooser: an #EmpathyProtocolChooser
- *
- * Returns the number of protocols in @protocol_chooser.
- *
- * Return value: the number of protocols in @protocol_chooser
- */
-gint
-empathy_protocol_chooser_n_protocols (EmpathyProtocolChooser *protocol_chooser)
-{
-  EmpathyProtocolChooserPriv *priv = GET_PRIV (protocol_chooser);
-
-  g_return_val_if_fail (EMPATHY_IS_PROTOCOL_CHOOSER (protocol_chooser), 0);
-
-  return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL);
-}
-
-/**
  * empathy_protocol_chooser_new:
  *
- * Creates a new #EmpathyProtocolChooser widget.
+ * Triggers the creation of a new #EmpathyProtocolChooser.
  *
  * Return value: a new #EmpathyProtocolChooser widget
  */
+
 GtkWidget *
 empathy_protocol_chooser_new (void)
 {
diff --git a/libempathy-gtk/empathy-protocol-chooser.h b/libempathy-gtk/empathy-protocol-chooser.h
index 75f9343..9d88195 100644
--- a/libempathy-gtk/empathy-protocol-chooser.h
+++ b/libempathy-gtk/empathy-protocol-chooser.h
@@ -58,13 +58,15 @@ struct _EmpathyProtocolChooserClass
   GtkComboBoxClass parent_class;
 };
 
+typedef void (* EmpathyProtocolChooserReadyCb) (GtkWidget *chooser,
+    GError *error,
+    gpointer user_data);
+
 GType empathy_protocol_chooser_get_type (void) G_GNUC_CONST;
 GtkWidget * empathy_protocol_chooser_new (void);
 TpConnectionManager *empathy_protocol_chooser_dup_selected (
     EmpathyProtocolChooser *protocol_chooser,
     TpConnectionManagerProtocol **protocol);
-gint empathy_protocol_chooser_n_protocols (
-    EmpathyProtocolChooser *protocol_chooser);
 
 G_END_DECLS
 #endif /*  __EMPATHY_PROTOCOL_CHOOSER_H__ */
diff --git a/tests/test-empathy-protocol-chooser.c b/tests/test-empathy-protocol-chooser.c
index 07b1c70..90b1797 100644
--- a/tests/test-empathy-protocol-chooser.c
+++ b/tests/test-empathy-protocol-chooser.c
@@ -9,15 +9,15 @@ int
 main (int argc,
     char **argv)
 {
-  GtkWidget *window;
-  GtkWidget *chooser;
+  GtkWidget *window, *c;
 
   gtk_init (&argc, &argv);
   empathy_gtk_init ();
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  chooser = empathy_protocol_chooser_new ();
-  gtk_container_add (GTK_CONTAINER (window), chooser);
+  c = empathy_protocol_chooser_new ();
+
+  gtk_container_add (GTK_CONTAINER (window), c);
 
   /*  gtk_window_set_default_size (GTK_WINDOW (window), 150, -1);*/
   gtk_widget_show_all (window);



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