From: Cosimo Cecchi Date: Wed, 22 Jul 2009 12:15:01 +0000 (+0200) Subject: Synchronize EmpathyProtocolChooser and EmpathyAccountsDialog X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=4b6db27ff05428dda571c5e60bc7229a4dd91d5f 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. --- diff --git a/libempathy-gtk/empathy-protocol-chooser.c b/libempathy-gtk/empathy-protocol-chooser.c index ebb19845..46297984 100644 --- a/libempathy-gtk/empathy-protocol-chooser.c +++ b/libempathy-gtk/empathy-protocol-chooser.c @@ -29,6 +29,7 @@ #include #include +#include #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 @@ -307,31 +317,14 @@ TpConnectionManager *empathy_protocol_chooser_dup_selected ( return cm; } -/** - * 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 75f9343c..9d881958 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 07b1c70e..90b1797a 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);