From 563630a2afed64a18df0936a5da7aa178ef8e474 Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Thu, 17 Mar 2011 08:34:48 +1100 Subject: Disable all other psyke accounts when one is enabled --- libempathy-gtk/empathy-account-widget-skype.c | 73 +++++++++++++++++++++++++++ libempathy-gtk/empathy-account-widget-skype.h | 3 +- src/empathy-accounts-dialog.c | 14 +++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/libempathy-gtk/empathy-account-widget-skype.c b/libempathy-gtk/empathy-account-widget-skype.c index ea39da898..439c373cc 100644 --- a/libempathy-gtk/empathy-account-widget-skype.c +++ b/libempathy-gtk/empathy-account-widget-skype.c @@ -958,3 +958,76 @@ empathy_account_widget_skype_show_eula (GtkWindow *parent) return (result == GTK_RESPONSE_ACCEPT); } +gboolean +empathy_accounts_dialog_skype_disable_other_accounts (TpAccount *account, + GtkWindow *parent) +{ + TpAccountManager *am = tp_account_manager_dup (); + GList *accounts, *ptr; + gboolean other_psyke_accounts = FALSE; + + /* check if any other psyke accounts are enabled */ + accounts = tp_account_manager_get_valid_accounts (am); + + for (ptr = accounts; ptr != NULL; ptr = ptr->next) + { + TpAccount *a = ptr->data; + + if (tp_strdiff ( + tp_proxy_get_object_path (account), + tp_proxy_get_object_path (a)) && + tp_account_is_enabled (a) && + !tp_strdiff (tp_account_get_connection_manager (a), "psyke")) + { + other_psyke_accounts = TRUE; + break; + } + } + + g_list_free (accounts); + + if (other_psyke_accounts) + { + GtkWidget *msg = gtk_message_dialog_new (parent, 0, + GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, + "%s\n\n%s", + _("Multiple Skype accounts can not be enabled simultaneously. " + "Enabling this Skype account will disable all others."), + _("Continue to enable this account?")); + int response; + + response = gtk_dialog_run (GTK_DIALOG (msg)); + gtk_widget_destroy (msg); + + if (response != GTK_RESPONSE_YES) + { + /* the user chose not to proceed */ + g_object_unref (am); + + return FALSE; + } + + /* the user chose to proceed, disable the other accounts */ + accounts = tp_account_manager_get_valid_accounts (am); + + for (ptr = accounts; ptr != NULL; ptr = ptr->next) + { + TpAccount *a = ptr->data; + + if (tp_strdiff ( + tp_proxy_get_object_path (account), + tp_proxy_get_object_path (a)) && + tp_account_is_enabled (a) && + !tp_strdiff (tp_account_get_connection_manager (a), "psyke")) + { + tp_account_set_enabled_async (a, FALSE, NULL, NULL); + } + } + + g_list_free (accounts); + } + + g_object_unref (am); + + return TRUE; +} diff --git a/libempathy-gtk/empathy-account-widget-skype.h b/libempathy-gtk/empathy-account-widget-skype.h index 3ca1e76bc..5ba0c6ed5 100644 --- a/libempathy-gtk/empathy-account-widget-skype.h +++ b/libempathy-gtk/empathy-account-widget-skype.h @@ -30,7 +30,8 @@ G_BEGIN_DECLS void empathy_account_widget_build_skype (EmpathyAccountWidget *self, const char *filename); gboolean empathy_account_widget_skype_show_eula (GtkWindow *parent); - +gboolean empathy_accounts_dialog_skype_disable_other_accounts ( + TpAccount *account, GtkWindow *parent); G_END_DECLS diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 215102eb1..6619442a8 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -258,6 +258,20 @@ accounts_dialog_enable_switch_flipped (MxGtkLightSwitch *sw, if (account == NULL) return; + if (state == TRUE && + !tp_strdiff (tp_account_get_connection_manager (account), "psyke")) + { + /* psyke typically doesn't support more than one simultaneous connection + * unless you've compiled it to do so */ + if (!empathy_accounts_dialog_skype_disable_other_accounts (account, + GTK_WINDOW (dialog))) + { + /* user chose not to proceed */ + mx_gtk_light_switch_set_active (sw, FALSE); + return; + } + } + tp_account_set_enabled_async (account, state, accounts_dialog_enable_account_cb, NULL); } -- cgit v1.2.3