From 25dadf4cd14de2ce0d39bdb4143e7cdd2631fe9a Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Mon, 14 Mar 2011 21:24:15 +1100 Subject: Add an enabled switch to the account dialog GtkInfoBar --- src/empathy-accounts-dialog.c | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/empathy-accounts-dialog.c') diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 868ef3146..3dfb40589 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -48,6 +48,7 @@ #include #include #include +#include #include "empathy-accounts-dialog.h" #include "empathy-import-dialog.h" @@ -86,6 +87,7 @@ typedef struct { GtkWidget *label_status; GtkWidget *image_status; GtkWidget *throbber; + GtkWidget *enabled_switch; GtkWidget *frame_no_protocol; GtkWidget *treeview; @@ -216,6 +218,49 @@ accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog, g_free (message_markup); } +static void +accounts_dialog_enable_account_cb (GObject *account, + GAsyncResult *result, + gpointer user_data) +{ + GError *error = NULL; + + tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error); + + if (error != NULL) + { + DEBUG ("Could not enable the account: %s", error->message); + g_error_free (error); + } + else + { + TpAccountManager *am = tp_account_manager_dup (); + + empathy_connect_new_account (TP_ACCOUNT (account), am); + g_object_unref (am); + } +} + +static void +accounts_dialog_enable_switch_flipped (MxGtkLightSwitch *sw, + gboolean state, + EmpathyAccountsDialog *dialog) +{ + EmpathyAccountSettings *settings; + TpAccount *account; + + settings = accounts_dialog_model_get_selected_settings (dialog); + if (settings == NULL) + return; + + account = empathy_account_settings_get_account (settings); + if (account == NULL) + return; + + tp_account_set_enabled_async (account, state, + accounts_dialog_enable_account_cb, NULL); +} + static void accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, TpAccount *account) @@ -278,6 +323,14 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status), empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR); + /* update the enabled switch */ + g_signal_handlers_block_by_func (priv->enabled_switch, + accounts_dialog_enable_switch_flipped, dialog); + mx_gtk_light_switch_set_active (MX_GTK_LIGHT_SWITCH (priv->enabled_switch), + account_enabled); + g_signal_handlers_unblock_by_func (priv->enabled_switch, + accounts_dialog_enable_switch_flipped, dialog); + if (account_enabled) { switch (status) @@ -2192,6 +2245,16 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog) gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3); gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0); + /* enabled switch */ + align = gtk_alignment_new (0.5, 0.5, 1., 0.); + gtk_box_pack_start (GTK_BOX (content_area), align, FALSE, TRUE, 0); + + priv->enabled_switch = mx_gtk_light_switch_new (); + gtk_container_add (GTK_CONTAINER (align), priv->enabled_switch); + g_signal_connect (priv->enabled_switch, "switch-flipped", + G_CALLBACK (accounts_dialog_enable_switch_flipped), dialog); + gtk_widget_show_all (align); + /* Tweak the dialog */ gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts")); gtk_window_set_role (GTK_WINDOW (dialog), "accounts"); -- cgit v1.2.3