From 0805caad8bb48b83e74648dbb3be85fd2869b541 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 18 Nov 2009 12:32:12 +0000 Subject: account-widget: use the account-manaer instead of idle Also ensure that the 'apply' button is correctly updated when the status is changed. --- libempathy-gtk/empathy-account-widget.c | 88 +++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/libempathy-gtk/empathy-account-widget.c b/libempathy-gtk/empathy-account-widget.c index a4d0f2802..58eb539e2 100644 --- a/libempathy-gtk/empathy-account-widget.c +++ b/libempathy-gtk/empathy-account-widget.c @@ -35,9 +35,9 @@ #endif #include -#include #include +#include #include #include #include @@ -75,7 +75,7 @@ typedef struct { * account has been created */ gboolean account_created; - EmpathyIdle *idle; + TpAccountManager *account_manager; gboolean dispose_run; } EmpathyAccountWidgetPriv; @@ -1153,23 +1153,58 @@ do_get_property (GObject *object, } static void -idle_state_change_cb (EmpathyIdle *idle, - GParamSpec *spec, +presence_changed_cb (TpAccountManager *manager, + TpConnectionPresenceType state, + const gchar *status, + const gchar *message, EmpathyAccountWidget *self) { EmpathyAccountWidgetPriv *priv = GET_PRIV (self); - TpConnectionPresenceType state; - - state = empathy_idle_get_state (priv->idle); if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE) { - g_object_set (priv->apply_button, "label", GTK_STOCK_CONNECT, NULL); + /* We are online, display a Login button */ + GtkWidget *image; + + gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), FALSE); + gtk_button_set_label (GTK_BUTTON (priv->apply_button), _("L_og in")); + + image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, + GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (priv->apply_button), image); } else { - g_object_set (priv->apply_button, "label", GTK_STOCK_APPLY, NULL); + /* We are offline, display a Save button */ + gtk_button_set_image (GTK_BUTTON (priv->apply_button), NULL); + gtk_button_set_use_stock (GTK_BUTTON (priv->apply_button), TRUE); + gtk_button_set_label (GTK_BUTTON (priv->apply_button), GTK_STOCK_SAVE); + } +} + +static void +account_manager_ready_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + EmpathyAccountWidget *self = EMPATHY_ACCOUNT_WIDGET (user_data); + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; + TpConnectionPresenceType state; + + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; } + + state = tp_account_manager_get_most_available_presence (account_manager, NULL, + NULL); + + /* simulate a presence change so the apply button will be changed + * if needed */ + presence_changed_cb (account_manager, state, NULL, NULL, self); } #define WIDGET(cm, proto) \ @@ -1273,29 +1308,18 @@ do_constructed (GObject *obj) if (priv->creating_account) { - TpConnectionPresenceType state; - priv->idle = empathy_idle_dup_singleton (); - - empathy_signal_connect_weak (priv->idle, "notify::state", - G_CALLBACK (idle_state_change_cb), obj); + priv->account_manager = tp_account_manager_dup (); - state = empathy_idle_get_state (priv->idle); + empathy_signal_connect_weak (priv->account_manager, + "most-available-presence-changed", + G_CALLBACK (presence_changed_cb), obj); - if (state > TP_CONNECTION_PRESENCE_TYPE_OFFLINE) - { - /* We are online, display a Login button */ - GtkWidget *image; + tp_account_manager_prepare_async (priv->account_manager, NULL, + account_manager_ready_cb, self); - priv->apply_button = gtk_button_new_with_mnemonic (_("L_og in")); - image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, - GTK_ICON_SIZE_BUTTON); - gtk_button_set_image (GTK_BUTTON (priv->apply_button), image); - } - else - { - /* We are offline, display a Save button */ - priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE); - } + /* Assumre we are offline, display a Save button. We'll update + * it once the account manager is ready if needed */ + priv->apply_button = gtk_button_new_from_stock (GTK_STOCK_SAVE); } else { @@ -1437,10 +1461,10 @@ do_dispose (GObject *obj) priv->settings = NULL; } - if (priv->idle != NULL) + if (priv->account_manager != NULL) { - g_object_unref (priv->idle); - priv->idle = NULL; + g_object_unref (priv->account_manager); + priv->account_manager = NULL; } if (G_OBJECT_CLASS (empathy_account_widget_parent_class)->dispose != NULL) -- cgit v1.2.3