2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
24 * Danielle Madeley <danielle.madeley@collabora.co.uk>
28 #include "empathy-accounts-dialog.h"
30 #include <glib/gi18n-lib.h>
32 #include "empathy-accounts-common.h"
33 #include "empathy-account-widget-sip.h"
34 #include "empathy-import-dialog.h"
35 #include "empathy-import-utils.h"
36 #include "empathy-local-xmpp-assistant-widget.h"
37 #include "empathy-new-account-dialog.h"
38 #include "empathy-pkg-kit.h"
39 #include "empathy-ui-utils.h"
40 #include "empathy-user-info.h"
41 #include "empathy-utils.h"
43 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
44 #include "empathy-debug.h"
46 /* Flashing delay for icons (milliseconds). */
47 #define FLASH_TIMEOUT 500
49 /* The primary text of the dialog shown to the user when he is about to lose
51 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
52 _("There are unsaved modifications to your %s account.")
53 /* The primary text of the dialog shown to the user when he is about to lose
54 * an unsaved new account */
55 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
56 _("Your new account has not been saved yet.")
58 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
59 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
63 NOTEBOOK_PAGE_ACCOUNT = 0,
64 NOTEBOOK_PAGE_LOADING,
65 NOTEBOOK_PAGE_NO_PROTOCOL
69 GtkWidget *alignment_settings;
70 GtkWidget *alignment_infobar;
72 GtkWidget *vbox_details;
74 GtkWidget *label_status;
75 GtkWidget *image_status;
77 GtkWidget *enabled_switch;
80 GtkCellRenderer *name_renderer;
82 GtkWidget *button_add;
83 GtkWidget *button_remove;
84 GtkWidget *button_import;
86 GtkWidget *image_type;
87 GtkWidget *label_name;
88 GtkWidget *label_type;
89 GtkWidget *dialog_content;
92 GtkWidget *notebook_account;
96 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
97 * just its GtkWidget. It is the only reliable source we can query to know if
98 * there are any unsaved changes to the currently selected account. We can't
99 * look at the account settings because it does not contain everything that
100 * can be changed using the EmpathyAccountWidget. For instance, it does not
101 * contain the state of the "Enabled" checkbox.
103 * Even if we create it ourself, we just get a weak ref and not a strong one
104 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
105 * That's kinda ugly; cf bgo #640417.
108 EmpathyAccountWidget *setting_widget;
110 gboolean connecting_show;
113 gulong settings_ready_id;
114 EmpathyAccountSettings *settings_ready;
116 TpAccountManager *account_manager;
117 EmpathyConnectionManagers *cms;
118 GNetworkMonitor *connectivity;
120 GtkWindow *parent_window;
121 TpAccount *initial_selection;
123 /* Those are needed when changing the selected row. When a user selects
124 * another account and there are unsaved changes on the currently selected
125 * one, a confirmation message box is presented to him. Since his answer
126 * is retrieved asynchronously, we keep some information as member of the
127 * EmpathyAccountsDialog object. */
128 gboolean force_change_row;
129 GtkTreeRowReference *destination_row;
131 GHashTable *icons_cache;
132 } EmpathyAccountsDialogPriv;
138 COL_ACCOUNT_SETTINGS,
146 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
147 EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
152 EmpathyAccountSettings *settings);
154 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
157 static void accounts_dialog_connection_changed_cb (TpAccount *account,
161 gchar *dbus_error_name,
163 EmpathyAccountsDialog *dialog);
165 static void accounts_dialog_presence_changed_cb (TpAccount *account,
168 gchar *status_message,
169 EmpathyAccountsDialog *dialog);
171 static void accounts_dialog_model_selection_changed (
172 GtkTreeSelection *selection,
173 EmpathyAccountsDialog *dialog);
175 static gboolean accounts_dialog_has_pending_change (
176 EmpathyAccountsDialog *dialog, TpAccount **account);
179 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
180 const gchar *display_name)
183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
185 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
186 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
192 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
193 const gchar *message)
195 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
196 gchar *message_markup;
198 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
199 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
201 gtk_widget_set_tooltip_text (priv->label_status, message);
203 g_free (message_markup);
207 accounts_dialog_enable_account_cb (GObject *object,
208 GAsyncResult *result,
211 TpAccount *account = TP_ACCOUNT (object);
212 gboolean enable = GPOINTER_TO_UINT (user_data);
213 GError *error = NULL;
214 TpAccountManager *am;
216 if (!tp_account_set_enabled_finish (account, result, &error))
218 DEBUG ("Could not enable the account: %s", error->message);
219 g_error_free (error);
223 /* tp_account_is_enabled() is not updated yet at this point */
226 am = tp_account_manager_dup ();
228 empathy_connect_new_account (account, am);
234 enable_and_connect_account (TpAccount *account,
237 tp_account_set_enabled_async (account, enable,
238 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
242 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
244 EmpathyAccountsDialog *dialog)
246 EmpathyAccountSettings *settings;
250 settings = accounts_dialog_model_get_selected_settings (dialog);
251 if (settings == NULL)
254 account = empathy_account_settings_get_account (settings);
258 enable = gtk_switch_get_active (sw);
260 enable_and_connect_account (account, enable);
264 install_haze_cb (GObject *source,
265 GAsyncResult *result,
268 GError *error = NULL;
270 if (!empathy_pkg_kit_install_packages_finish (result, &error))
272 DEBUG ("Failed to install telepathy-haze: %s", error->message);
274 g_error_free (error);
279 account_is_selected (EmpathyAccountsDialog *dialog,
282 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
283 GtkTreeSelection *selection;
286 TpAccount *selected_account;
291 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
293 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
296 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
298 if (selected_account != NULL)
299 g_object_unref (selected_account);
301 return account == selected_account;
305 account_can_be_enabled (TpAccount *account)
307 TpStorageRestrictionFlags storage_restrictions;
309 storage_restrictions = tp_account_get_storage_restrictions (account);
310 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
313 /* Butterfly accounts shouldn't be used any more */
314 if (!tp_strdiff (tp_account_get_cm_name (account),
322 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
325 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
326 gchar *status_message = NULL;
330 gboolean account_enabled;
331 gboolean creating_account;
332 gboolean display_switch = TRUE;
334 /* do not update the infobar when the account is not selected */
335 if (!account_is_selected (dialog, account))
340 status = tp_account_get_connection_status (account, &reason);
341 presence = tp_account_get_current_presence (account, NULL, &status_message);
342 account_enabled = tp_account_is_enabled (account);
343 creating_account = FALSE;
345 if (status == TP_CONNECTION_STATUS_CONNECTED &&
346 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
347 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
348 /* If presence is Unset (CM doesn't implement SimplePresence) but we
349 * are connected, consider ourself as Available.
350 * We also check Offline because of this MC5 bug: fd.o #26060 */
351 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
353 /* set presence to offline if account is disabled
354 * (else no icon is shown in infobar)*/
355 if (!account_enabled)
356 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
358 display_switch = account_can_be_enabled (account);
362 status = TP_CONNECTION_STATUS_DISCONNECTED;
363 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
364 account_enabled = FALSE;
365 creating_account = TRUE;
368 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
369 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
371 /* update the enabled switch */
372 g_signal_handlers_block_by_func (priv->enabled_switch,
373 accounts_dialog_enable_switch_active_cb, dialog);
374 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
376 g_signal_handlers_unblock_by_func (priv->enabled_switch,
377 accounts_dialog_enable_switch_active_cb, dialog);
379 /* Display the Enable switch if account supports it */
380 gtk_widget_set_visible (priv->enabled_switch, display_switch);
386 case TP_CONNECTION_STATUS_CONNECTING:
387 accounts_dialog_status_infobar_set_message (dialog,
389 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
392 gtk_spinner_start (GTK_SPINNER (priv->throbber));
393 gtk_widget_show (priv->throbber);
394 gtk_widget_hide (priv->image_status);
396 case TP_CONNECTION_STATUS_CONNECTED:
397 if (g_strcmp0 (status_message, "") == 0)
401 message = g_strdup_printf ("%s",
402 empathy_presence_get_default_message (presence));
404 accounts_dialog_status_infobar_set_message (dialog, message);
411 message = g_strdup_printf ("%s — %s",
412 empathy_presence_get_default_message (presence),
415 accounts_dialog_status_infobar_set_message (dialog, message);
418 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
421 gtk_widget_show (priv->image_status);
422 gtk_widget_hide (priv->throbber);
424 case TP_CONNECTION_STATUS_DISCONNECTED:
425 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
429 message = g_strdup_printf (_("Offline — %s"),
430 empathy_account_get_error_message (account, NULL));
431 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
432 GTK_MESSAGE_WARNING);
434 accounts_dialog_status_infobar_set_message (dialog, message);
441 message = g_strdup_printf (_("Disconnected — %s"),
442 empathy_account_get_error_message (account, NULL));
443 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
446 accounts_dialog_status_infobar_set_message (dialog, message);
450 if (!g_network_monitor_get_network_available (priv->connectivity))
451 accounts_dialog_status_infobar_set_message (dialog,
452 _("Offline — No Network Connection"));
454 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
455 gtk_widget_show (priv->image_status);
456 gtk_widget_hide (priv->throbber);
459 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
460 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
461 GTK_MESSAGE_WARNING);
463 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
464 gtk_widget_hide (priv->image_status);
465 gtk_widget_hide (priv->throbber);
470 if (!tp_strdiff (tp_account_get_cm_name (account),
473 const gchar *packages[] = { "telepathy-haze", NULL };
475 accounts_dialog_status_infobar_set_message (dialog,
476 _("This account has been disabled because it relies on an old, "
477 "unsupported backend. Please install telepathy-haze and "
478 "restart your session to migrate the account."));
480 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
481 install_haze_cb, NULL);
485 accounts_dialog_status_infobar_set_message (dialog,
486 _("Offline — Account Disabled"));
489 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
490 GTK_MESSAGE_WARNING);
491 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
492 gtk_widget_show (priv->image_status);
493 gtk_widget_hide (priv->throbber);
496 gtk_widget_show (priv->label_status);
498 if (!creating_account)
499 gtk_widget_show (priv->infobar);
501 gtk_widget_hide (priv->infobar);
503 g_free (status_message);
507 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
511 GtkTreeSelection *selection;
513 EmpathyAccountSettings *settings;
515 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
517 view = GTK_TREE_VIEW (priv->treeview);
518 selection = gtk_tree_view_get_selection (view);
520 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
523 gtk_tree_model_get (model, &iter,
524 COL_ACCOUNT_SETTINGS, &settings,
525 COL_ACCOUNT, &account, -1);
527 empathy_account_widget_discard_pending_changes (priv->setting_widget);
531 /* We were creating an account. We remove the selected row */
532 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
536 /* We were modifying an account. We discard the changes by reloading the
537 * settings and the UI. */
538 accounts_dialog_update_settings (dialog, settings);
539 g_object_unref (account);
542 gtk_widget_set_sensitive (priv->treeview, TRUE);
543 gtk_widget_set_sensitive (priv->button_add, TRUE);
544 gtk_widget_set_sensitive (priv->button_remove, TRUE);
545 gtk_widget_set_sensitive (priv->button_import, TRUE);
547 if (settings != NULL)
548 g_object_unref (settings);
552 empathy_account_dialog_widget_cancelled_cb (
553 EmpathyAccountWidget *widget_object,
554 EmpathyAccountsDialog *dialog)
556 empathy_account_dialog_cancel (dialog);
560 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
562 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
567 g_object_get (priv->setting_widget,
568 "creating-account", &creating, NULL);
573 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
575 if (gtk_tree_model_get_iter_first (model, &iter))
576 return gtk_tree_model_iter_next (model, &iter);
582 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
585 EmpathyAccountSettings *settings;
586 GtkWidget *subdialog, *content_area, *align;
588 settings = accounts_dialog_model_get_selected_settings (dialog);
589 if (settings == NULL)
592 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
594 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
597 gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
599 priv->setting_widget = (EmpathyAccountWidget *)
600 empathy_account_widget_new_for_protocol (settings, FALSE);
602 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
603 (gpointer *) &priv->setting_widget);
605 if (accounts_dialog_has_valid_accounts (dialog))
606 empathy_account_widget_set_other_accounts_exist (
607 priv->setting_widget, TRUE);
609 g_signal_connect (priv->setting_widget, "cancelled",
610 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
612 g_signal_connect_swapped (priv->setting_widget, "close",
613 G_CALLBACK (gtk_widget_destroy), subdialog);
615 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
617 align = gtk_alignment_new (0.5, 0.5, 1, 1);
618 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
620 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
621 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
623 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
624 gtk_widget_show (align);
625 gtk_widget_show (subdialog);
629 use_external_storage_provider (EmpathyAccountsDialog *self,
632 const gchar *provider;
634 provider = tp_account_get_storage_provider (account);
635 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
637 empathy_launch_external_app ("gnome-control-center.desktop",
638 "bisho.desktop", NULL);
641 else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
643 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
647 else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
649 empathy_launch_external_app ("gnome-credentials-panel.desktop",
655 DEBUG ("Don't know how to handle %s", provider);
661 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
664 EmpathyAccountSettings *settings;
666 TpStorageRestrictionFlags storage_restrictions;
668 settings = accounts_dialog_model_get_selected_settings (dialog);
669 if (settings == NULL)
672 account = empathy_account_settings_get_account (settings);
673 g_return_if_fail (account != NULL);
675 storage_restrictions = tp_account_get_storage_restrictions (account);
677 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
678 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
680 DEBUG ("Account is provided by an external storage provider");
682 use_external_storage_provider (dialog, account);
686 account_dialog_create_edit_params_dialog (dialog);
691 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
692 EmpathyAccountSettings *settings)
694 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
695 const gchar *icon_name;
697 GtkWidget *bbox, *button;
700 account = empathy_account_settings_get_account (settings);
702 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
703 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
704 priv->dialog_content);
705 gtk_widget_show (priv->dialog_content);
707 alig = gtk_alignment_new (0.5, 0, 1, 1);
708 priv->user_info = empathy_user_info_new (account);
709 gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
710 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
711 gtk_widget_show (alig);
712 gtk_widget_show (priv->user_info);
714 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
715 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
716 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
717 gtk_widget_show (bbox);
719 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
720 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
721 gtk_widget_show (button);
722 g_signal_connect_swapped (button, "clicked",
723 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
725 icon_name = empathy_account_settings_get_icon_name (settings);
727 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
729 /* show the default icon; keep this in sync with the default
730 * one in empathy-accounts-dialog.ui.
732 icon_name = GTK_STOCK_CUT;
734 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
735 icon_name, GTK_ICON_SIZE_DIALOG);
736 gtk_widget_set_tooltip_text (priv->image_type,
737 empathy_protocol_name_to_display_name
738 (empathy_account_settings_get_protocol (settings)));
739 gtk_widget_show (priv->image_type);
741 accounts_dialog_update_name_label (dialog,
742 empathy_account_settings_get_display_name (settings));
744 accounts_dialog_update_status_infobar (dialog, account);
748 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
750 EmpathyAccountsDialog *dialog)
752 if (empathy_account_settings_is_ready (settings))
753 account_dialog_create_dialog_content (dialog, settings);
757 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
761 GtkTreeSelection *selection;
763 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
766 view = GTK_TREE_VIEW (priv->treeview);
767 model = gtk_tree_view_get_model (view);
769 if (gtk_tree_model_get_iter_first (model, &iter))
771 selection = gtk_tree_view_get_selection (view);
772 gtk_tree_selection_select_iter (selection, &iter);
776 accounts_dialog_update_settings (dialog, NULL);
781 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
786 GtkTreeSelection *selection;
787 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
789 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
791 if (gtk_tree_selection_get_selected (selection, &model, &iter))
792 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
794 return priv->setting_widget != NULL
795 && empathy_account_widget_contains_pending_changes (
796 priv->setting_widget);
800 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
801 const gchar *primary_text,
802 const gchar *secondary_text,
803 GCallback response_callback,
805 const gchar *first_button_text,
809 GtkWidget *message_dialog;
810 const gchar *button_text;
812 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
813 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
814 GTK_MESSAGE_QUESTION,
818 gtk_message_dialog_format_secondary_text (
819 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
821 va_start (button_args, first_button_text);
822 for (button_text = first_button_text;
824 button_text = va_arg (button_args, const gchar *))
827 response_id = va_arg (button_args, gint);
829 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
832 va_end (button_args);
834 g_signal_connect (message_dialog, "response", response_callback, user_data);
836 gtk_widget_show (message_dialog);
840 get_dialog_primary_text (TpAccount *account)
844 /* Existing account */
845 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
846 tp_account_get_display_name (account));
850 /* Newly created account */
851 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
856 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
857 EmpathyAccountsDialog *self)
862 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
863 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
865 response = gtk_dialog_run (GTK_DIALOG (dialog));
867 if (response == GTK_RESPONSE_APPLY)
869 EmpathyAccountSettings *settings;
872 settings = empathy_new_account_dialog_get_settings (
873 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
875 /* The newly created account has already been added by
876 * accounts_dialog_account_validity_changed_cb so we just
877 * have to select it. */
878 account = empathy_account_settings_get_account (settings);
879 accounts_dialog_model_set_selected (self, account);
882 gtk_widget_destroy (dialog);
886 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
887 EmpathyAccountSettings *settings)
889 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
891 if (priv->settings_ready != NULL)
893 g_signal_handler_disconnect (priv->settings_ready,
894 priv->settings_ready_id);
895 priv->settings_ready = NULL;
896 priv->settings_ready_id = 0;
903 GtkTreeSelection *selection;
905 view = GTK_TREE_VIEW (priv->treeview);
906 model = gtk_tree_view_get_model (view);
907 selection = gtk_tree_view_get_selection (view);
909 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
911 /* We have configured accounts, select the first one if there
912 * is no other account selected already. */
913 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
914 accounts_dialog_model_select_first (dialog);
919 /* No account selected */
920 gtk_widget_hide (priv->vbox_details);
921 gtk_widget_set_sensitive (priv->button_add, TRUE);
922 gtk_widget_set_sensitive (priv->button_remove, FALSE);
924 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
925 NOTEBOOK_PAGE_NO_PROTOCOL);
929 /* We have an account selected, destroy old settings and create a new
930 * one for the account selected */
931 gtk_widget_show (priv->vbox_details);
933 if (priv->user_info != NULL)
935 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
937 priv->user_info = NULL;
939 if (priv->dialog_content)
941 gtk_widget_destroy (priv->dialog_content);
942 priv->dialog_content = NULL;
945 if (empathy_account_settings_is_ready (settings))
947 account_dialog_create_dialog_content (dialog, settings);
951 priv->settings_ready = settings;
952 priv->settings_ready_id =
953 g_signal_connect (settings, "notify::ready",
954 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
960 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
961 GtkCellEditable *editable,
963 EmpathyAccountsDialog *dialog)
965 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
967 if (priv->connecting_id)
968 g_source_remove (priv->connecting_id);
970 DEBUG ("Editing account name started; stopping flashing");
974 get_status_icon_for_account (EmpathyAccountsDialog *self,
977 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
978 TpConnectionStatus status;
979 TpConnectionStatusReason reason;
980 TpConnectionPresenceType presence;
983 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
985 if (!tp_account_is_enabled (account))
986 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
988 status = tp_account_get_connection_status (account, &reason);
990 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
992 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
993 /* An error occured */
994 return GTK_STOCK_DIALOG_ERROR;
996 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
998 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1000 /* Account is connecting. Display a blinking account alternating between
1001 * the offline icon and the requested presence. */
1002 if (priv->connecting_show)
1003 presence = tp_account_get_requested_presence (account, NULL, NULL);
1005 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1009 /* status == TP_CONNECTION_STATUS_CONNECTED */
1010 presence = tp_account_get_current_presence (account, NULL, NULL);
1012 /* If presence is Unset (CM doesn't implement SimplePresence),
1013 * display the 'available' icon.
1014 * We also check Offline because of this MC5 bug: fd.o #26060 */
1015 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1016 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1017 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1020 return empathy_icon_name_for_presence (presence);
1024 ensure_icon (EmpathyAccountsDialog *self,
1025 const gchar *icon_name)
1027 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1030 pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
1033 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1038 g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
1042 return g_object_ref (pixbuf);
1046 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1047 GtkCellRenderer *cell,
1048 GtkTreeModel *model,
1050 EmpathyAccountsDialog *dialog)
1053 const gchar *icon_name;
1056 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1058 icon_name = get_status_icon_for_account (dialog, account);
1059 pixbuf = ensure_icon (dialog, icon_name);
1065 if (account != NULL)
1066 g_object_unref (account);
1069 g_object_unref (pixbuf);
1073 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1074 GtkCellRenderer *cell,
1075 GtkTreeModel *model,
1077 EmpathyAccountsDialog *dialog)
1079 EmpathyAccountSettings *settings;
1082 TpConnectionStatus status;
1084 gtk_tree_model_get (model, iter,
1085 COL_STATUS, &status,
1086 COL_ACCOUNT_SETTINGS, &settings,
1089 icon_name = empathy_account_settings_get_icon_name (settings);
1090 pixbuf = ensure_icon (dialog, icon_name);
1097 g_object_unref (settings);
1100 g_object_unref (pixbuf);
1104 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1111 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1113 if (account == NULL)
1116 if (tp_account_get_connection_status (account, NULL) ==
1117 TP_CONNECTION_STATUS_CONNECTING)
1119 /* Only update the row where we have a connecting account as that's the
1120 * ones having a blinking icon. */
1121 gtk_tree_model_row_changed (model, path, iter);
1124 g_object_unref (account);
1129 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1132 GtkTreeModel *model;
1133 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1135 priv->connecting_show = !priv->connecting_show;
1137 view = GTK_TREE_VIEW (priv->treeview);
1138 model = gtk_tree_view_get_model (view);
1140 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1146 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1149 EmpathyAccountsDialog *dialog)
1151 EmpathyAccountSettings *settings;
1152 GtkTreeModel *model;
1153 GtkTreePath *treepath;
1155 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1156 gboolean connecting;
1158 empathy_account_manager_get_accounts_connected (&connecting);
1162 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1163 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1167 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1168 treepath = gtk_tree_path_new_from_string (path);
1169 gtk_tree_model_get_iter (model, &iter, treepath);
1170 gtk_tree_model_get (model, &iter,
1171 COL_ACCOUNT_SETTINGS, &settings,
1173 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1176 gtk_tree_path_free (treepath);
1178 empathy_account_settings_set_display_name_async (settings, new_text,
1180 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1181 g_object_unref (settings);
1185 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1190 GtkTreeModel *model;
1192 GtkTreeSelection *selection;
1193 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1194 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1196 if (response_id == GTK_RESPONSE_YES)
1198 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1200 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1203 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1205 if (account != NULL)
1207 tp_account_remove_async (account, NULL, NULL);
1208 g_object_unref (account);
1212 /* No need to call accounts_dialog_model_selection_changed while
1213 * removing as we are going to call accounts_dialog_model_select_first
1214 * right after which will update the selection. */
1215 g_signal_handlers_block_by_func (selection,
1216 accounts_dialog_model_selection_changed, account_dialog);
1218 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1220 g_signal_handlers_unblock_by_func (selection,
1221 accounts_dialog_model_selection_changed, account_dialog);
1223 accounts_dialog_model_select_first (account_dialog);
1226 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1230 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1233 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1235 GtkTreeModel *model;
1236 gchar *question_dialog_primary_text;
1238 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1240 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1242 if (account == NULL || !tp_account_is_valid (account))
1244 if (account != NULL)
1245 g_object_unref (account);
1246 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1247 accounts_dialog_model_select_first (dialog);
1251 question_dialog_primary_text = g_strdup_printf (
1252 _("Do you want to remove %s from your computer?"),
1253 tp_account_get_display_name (account));
1255 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1256 _("This will not remove your account on the server."),
1257 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1259 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1260 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1262 g_free (question_dialog_primary_text);
1263 g_object_unref (account);
1267 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1268 EmpathyAccountsDialog *dialog)
1270 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1272 GtkTreeSelection *selection;
1275 view = GTK_TREE_VIEW (priv->treeview);
1276 selection = gtk_tree_view_get_selection (view);
1277 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1280 accounts_dialog_remove_account_iter (dialog, &iter);
1284 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1287 GtkTreeViewColumn *column;
1288 GtkCellRenderer *cell;
1289 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1291 view = GTK_TREE_VIEW (priv->treeview);
1292 gtk_tree_view_set_headers_visible (view, FALSE);
1294 /* Account column */
1295 column = gtk_tree_view_column_new ();
1296 gtk_tree_view_column_set_expand (column, TRUE);
1297 gtk_tree_view_append_column (view, column);
1299 /* Status icon renderer */
1300 cell = gtk_cell_renderer_pixbuf_new ();
1301 gtk_tree_view_column_pack_start (column, cell, FALSE);
1302 gtk_tree_view_column_set_cell_data_func (column, cell,
1303 (GtkTreeCellDataFunc)
1304 accounts_dialog_model_status_pixbuf_data_func,
1308 /* Protocol icon renderer */
1309 cell = gtk_cell_renderer_pixbuf_new ();
1310 gtk_tree_view_column_pack_start (column, cell, FALSE);
1311 gtk_tree_view_column_set_cell_data_func (column, cell,
1312 (GtkTreeCellDataFunc)
1313 accounts_dialog_model_protocol_pixbuf_data_func,
1318 priv->name_renderer = gtk_cell_renderer_text_new ();
1319 g_object_set (priv->name_renderer,
1320 "ellipsize", PANGO_ELLIPSIZE_END,
1324 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1325 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1327 g_signal_connect (priv->name_renderer, "edited",
1328 G_CALLBACK (accounts_dialog_name_edited_cb),
1330 g_signal_connect (priv->name_renderer, "editing-started",
1331 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1333 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1336 static EmpathyAccountSettings *
1337 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1340 GtkTreeModel *model;
1341 GtkTreeSelection *selection;
1343 EmpathyAccountSettings *settings;
1344 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1346 view = GTK_TREE_VIEW (priv->treeview);
1347 selection = gtk_tree_view_get_selection (view);
1349 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1352 gtk_tree_model_get (model, &iter,
1353 COL_ACCOUNT_SETTINGS, &settings, -1);
1359 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1360 EmpathyAccountsDialog *dialog)
1362 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1363 EmpathyAccountSettings *settings;
1364 GtkTreeModel *model;
1366 gboolean is_selection;
1367 gboolean creating = FALSE;
1369 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1371 settings = accounts_dialog_model_get_selected_settings (dialog);
1372 accounts_dialog_update_settings (dialog, settings);
1374 if (settings != NULL)
1375 g_object_unref (settings);
1377 if (priv->setting_widget != NULL)
1379 g_object_get (priv->setting_widget,
1380 "creating-account", &creating, NULL);
1383 /* Update remove button sensitivity */
1384 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1389 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1391 gpointer *user_data)
1393 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1394 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1396 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1398 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1400 /* The user wants to lose unsaved changes to the currently selected
1401 * account and select another account. We discard the changes and
1402 * select the other account. */
1404 GtkTreeSelection *selection;
1406 priv->force_change_row = TRUE;
1407 empathy_account_widget_discard_pending_changes (
1408 priv->setting_widget);
1410 path = gtk_tree_row_reference_get_path (priv->destination_row);
1411 selection = gtk_tree_view_get_selection (
1412 GTK_TREE_VIEW (priv->treeview));
1416 /* This will trigger a call to
1417 * accounts_dialog_account_selection_change() */
1418 gtk_tree_selection_select_path (selection, path);
1419 gtk_tree_path_free (path);
1422 gtk_tree_row_reference_free (priv->destination_row);
1426 priv->force_change_row = FALSE;
1431 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1432 GtkTreeModel *model,
1434 gboolean path_currently_selected,
1437 TpAccount *account = NULL;
1438 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1439 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1442 if (priv->force_change_row)
1444 /* We came back here because the user wants to discard changes to his
1445 * modified account. The changes have already been discarded so we
1446 * just change the selected row. */
1447 priv->force_change_row = FALSE;
1451 if (accounts_dialog_has_pending_change (dialog, &account))
1453 /* The currently selected account has some unsaved changes. We ask
1454 * the user if he really wants to lose his changes and select another
1456 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1457 priv->destination_row = gtk_tree_row_reference_new (model, path);
1459 accounts_dialog_show_question_dialog (dialog,
1460 question_dialog_primary_text,
1461 _("You are about to select another account, which will discard\n"
1462 "your changes. Are you sure you want to proceed?"),
1463 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1465 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1466 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1468 g_free (question_dialog_primary_text);
1476 if (account != NULL)
1477 g_object_unref (account);
1483 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1485 GtkListStore *store;
1486 GtkTreeSelection *selection;
1487 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1489 store = gtk_list_store_new (COL_COUNT,
1490 G_TYPE_STRING, /* name */
1491 G_TYPE_UINT, /* status */
1492 TP_TYPE_ACCOUNT, /* account */
1493 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1495 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1496 GTK_TREE_MODEL (store));
1498 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1499 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1500 gtk_tree_selection_set_select_function (selection,
1501 accounts_dialog_account_selection_change, dialog, NULL);
1503 g_signal_connect (selection, "changed",
1504 G_CALLBACK (accounts_dialog_model_selection_changed),
1507 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1508 COL_NAME, GTK_SORT_ASCENDING);
1510 accounts_dialog_model_add_columns (dialog);
1512 g_object_unref (store);
1516 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1521 GtkTreeModel *model;
1523 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1525 /* Update the status in the model */
1526 view = GTK_TREE_VIEW (priv->treeview);
1527 model = gtk_tree_view_get_model (view);
1529 for (ok = gtk_tree_model_get_iter_first (model, iter);
1531 ok = gtk_tree_model_iter_next (model, iter))
1533 TpAccount *this_account;
1536 gtk_tree_model_get (model, iter,
1537 COL_ACCOUNT, &this_account,
1540 equal = (this_account == account);
1541 g_object_unref (this_account);
1551 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1554 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1555 GtkTreeSelection *selection;
1557 GtkTreeModel *model;
1559 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1561 gtk_tree_selection_select_iter (selection, iter);
1563 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1564 path = gtk_tree_model_get_path (model, iter);
1566 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1569 gtk_tree_path_free (path);
1573 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1578 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1579 select_and_scroll_to_iter (dialog, &iter);
1583 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1588 enabled = tp_account_is_enabled (account);
1590 enable_and_connect_account (account, !enabled);
1594 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1595 EmpathyAccountsDialog *self)
1597 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1600 GtkTreeSelection *selection;
1601 GtkTreeModel *model;
1603 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1604 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1606 path = gtk_tree_model_get_path (model, &iter);
1608 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1610 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1611 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1612 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1614 gtk_tree_path_free (path);
1618 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1619 GdkEventButton *event,
1620 EmpathyAccountsDialog *dialog)
1622 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1623 TpAccount *account = NULL;
1624 GtkTreeModel *model = NULL;
1625 GtkTreePath *path = NULL;
1630 /* ignore multiple clicks */
1631 if (event->type != GDK_BUTTON_PRESS)
1634 if (event->button != 3)
1637 /* Selection is not yet set, so we have to get account from event position */
1638 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1639 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1640 event->x, event->y, &path, NULL, NULL, NULL))
1643 if (!gtk_tree_model_get_iter (model, &iter, path))
1646 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1648 /* Create the menu */
1649 menu = empathy_context_menu_new (GTK_WIDGET (view));
1651 /* Menu item: to enabled/disable the account */
1652 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1654 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1656 if (account_can_be_enabled (account))
1660 active = tp_account_is_enabled (account);
1661 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1664 tp_g_signal_connect_object (item, "activate",
1665 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1669 gtk_widget_set_sensitive (item, FALSE);
1672 gtk_widget_show (item);
1674 /* Menu item: Rename */
1675 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1676 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1678 tp_g_signal_connect_object (item, "activate",
1679 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1681 gtk_widget_show (item);
1683 /* FIXME: Add here presence items, to be able to set per-account presence */
1686 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1687 event->button, event->time);
1690 tp_clear_object (&account);
1691 gtk_tree_path_free (path);
1697 reload_account_widget (EmpathyAccountsDialog *self)
1699 EmpathyAccountSettings *settings;
1701 settings = accounts_dialog_model_get_selected_settings (self);
1702 accounts_dialog_update_settings (self, settings);
1706 accounts_dialog_connection_changed_cb (TpAccount *account,
1710 gchar *dbus_error_name,
1711 GHashTable *details,
1712 EmpathyAccountsDialog *dialog)
1714 GtkTreeModel *model;
1717 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1719 /* Update the status-infobar in the details view */
1720 accounts_dialog_update_status_infobar (dialog, account);
1722 /* Update the status in the model */
1723 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1725 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1729 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1730 COL_STATUS, current,
1733 path = gtk_tree_model_get_path (model, &iter);
1734 gtk_tree_model_row_changed (model, path, &iter);
1735 gtk_tree_path_free (path);
1738 empathy_account_manager_get_accounts_connected (&found);
1740 if (!found && priv->connecting_id)
1742 g_source_remove (priv->connecting_id);
1743 priv->connecting_id = 0;
1746 if (found && !priv->connecting_id)
1747 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1748 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1753 update_account_in_treeview (EmpathyAccountsDialog *self,
1756 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1758 GtkTreeModel *model;
1760 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1761 if (accounts_dialog_get_account_iter (self, account, &iter))
1765 path = gtk_tree_model_get_path (model, &iter);
1766 gtk_tree_model_row_changed (model, path, &iter);
1767 gtk_tree_path_free (path);
1772 accounts_dialog_presence_changed_cb (TpAccount *account,
1775 gchar *status_message,
1776 EmpathyAccountsDialog *dialog)
1778 /* Update the status-infobar in the details view */
1779 accounts_dialog_update_status_infobar (dialog, account);
1781 update_account_in_treeview (dialog, account);
1785 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1789 const gchar *display_name;
1791 GtkTreeModel *model;
1792 EmpathyAccountSettings *settings;
1793 TpAccount *selected_account;
1794 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1795 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1797 display_name = tp_account_get_display_name (account);
1798 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1799 settings = accounts_dialog_model_get_selected_settings (dialog);
1800 if (settings == NULL)
1803 selected_account = empathy_account_settings_get_account (settings);
1805 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1807 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1808 COL_NAME, display_name,
1812 if (selected_account == account)
1813 accounts_dialog_update_name_label (dialog, display_name);
1815 g_object_unref (settings);
1819 conn_prepare_cb (GObject *source,
1820 GAsyncResult *result,
1823 EmpathyAccountsDialog *self = user_data;
1825 reload_account_widget (self);
1829 accounts_dialog_notify_connection_cb (TpAccount *account,
1831 EmpathyAccountsDialog *self)
1834 if (!account_is_selected (self, account))
1837 conn = tp_account_get_connection (account);
1840 reload_account_widget (self);
1844 /* Wait for this feature so TpConnection will have fetch the
1846 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1848 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1853 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1856 EmpathyAccountSettings *settings;
1857 GtkTreeModel *model;
1859 TpConnectionStatus status;
1861 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1862 gboolean selected = FALSE;
1863 GtkTreeSelection *selection;
1865 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1866 status = tp_account_get_connection_status (account, NULL);
1867 name = tp_account_get_display_name (account);
1869 settings = empathy_account_settings_new_for_account (account);
1871 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1873 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1875 /* Select the account if it's the first added */
1876 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1879 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1882 COL_ACCOUNT, account,
1883 COL_ACCOUNT_SETTINGS, settings,
1888 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1890 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1893 COL_ACCOUNT, account,
1894 COL_ACCOUNT_SETTINGS, settings,
1900 /* We just modified the selected account. Its display name may have been
1901 * changed and so it's place in the treeview. Scroll to it so it stays
1903 select_and_scroll_to_iter (dialog, &iter);
1906 accounts_dialog_connection_changed_cb (account,
1909 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1914 tp_g_signal_connect_object (account, "notify::display-name",
1915 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1918 tp_g_signal_connect_object (account, "status-changed",
1919 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1920 tp_g_signal_connect_object (account, "presence-changed",
1921 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1922 tp_g_signal_connect_object (account, "notify::connection",
1923 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
1925 g_object_unref (settings);
1929 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1932 EmpathyAccountsDialog *dialog)
1934 accounts_dialog_add_account (dialog, account);
1938 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1941 EmpathyAccountsDialog *dialog)
1943 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1945 if (priv->setting_widget != NULL &&
1946 accounts_dialog_has_valid_accounts (dialog))
1948 empathy_account_widget_set_other_accounts_exist (
1949 priv->setting_widget, TRUE);
1954 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1956 EmpathyAccountsDialog *dialog)
1958 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1960 if (priv->setting_widget != NULL &&
1961 !accounts_dialog_has_valid_accounts (dialog))
1963 empathy_account_widget_set_other_accounts_exist (
1964 priv->setting_widget, FALSE);
1969 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1971 EmpathyAccountsDialog *dialog)
1974 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1976 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1978 gtk_list_store_remove (GTK_LIST_STORE (
1979 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1984 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1988 /* Update the status-infobar in the details view */
1989 accounts_dialog_update_status_infobar (dialog, account);
1991 DEBUG ("Account %s is now %s",
1992 tp_account_get_display_name (account),
1993 enabled ? "enabled" : "disabled");
1997 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1999 EmpathyAccountsDialog *dialog)
2001 enable_or_disable_account (dialog, account, FALSE);
2002 update_account_in_treeview (dialog, account);
2006 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2008 EmpathyAccountsDialog *dialog)
2010 enable_or_disable_account (dialog, account, TRUE);
2014 display_import_dialog (EmpathyAccountsDialog *dialog)
2016 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2017 GtkWidget *import_dialog;
2019 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2021 gtk_widget_show (import_dialog);
2023 return import_dialog;
2027 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2028 EmpathyAccountsDialog *dialog)
2030 display_import_dialog (dialog);
2034 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2038 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2040 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2042 if (response_id == GTK_RESPONSE_YES)
2043 gtk_widget_destroy (account_dialog);
2047 accounts_dialog_delete_event_cb (GtkWidget *widget,
2049 EmpathyAccountsDialog *dialog)
2051 /* we maunally handle responses to delete events */
2056 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2061 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2062 select_and_scroll_to_iter (dialog, &iter);
2066 salut_valid_cb (GtkWidget *widget,
2070 gtk_widget_set_sensitive (button, valid);
2074 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2076 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2077 GtkWidget *dialog, *widget, *content, *button;
2080 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2081 priv->account_manager))
2084 widget = empathy_local_xmpp_assistant_widget_new ();
2085 gtk_widget_show (widget);
2087 dialog = gtk_dialog_new ();
2089 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2091 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2094 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2095 _("_Connect"), GTK_RESPONSE_YES);
2096 gtk_widget_set_sensitive (button,
2097 empathy_local_xmpp_assistant_widget_is_valid (
2098 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2100 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2103 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2104 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2106 response = gtk_dialog_run (GTK_DIALOG (dialog));
2108 if (response == GTK_RESPONSE_YES)
2110 empathy_local_xmpp_assistant_widget_create_account (
2111 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2114 gtk_widget_destroy (dialog);
2118 import_dialog_response_cb (GtkDialog *dialog,
2120 EmpathyAccountsDialog *self)
2122 maybe_show_salut_dialog (self);
2126 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2128 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2131 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2134 if (!empathy_import_accounts_to_import ())
2136 maybe_show_salut_dialog (self);
2140 dialog = display_import_dialog (self);
2142 tp_g_signal_connect_object (dialog, "response",
2143 G_CALLBACK (import_dialog_response_cb), self, 0);
2147 finished_loading (EmpathyAccountsDialog *self)
2149 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2150 GtkTreeSelection *selection;
2151 gboolean has_selected;
2153 priv->loading = FALSE;
2155 gtk_widget_set_sensitive (priv->button_add, TRUE);
2156 gtk_widget_set_sensitive (priv->button_import, TRUE);
2157 gtk_widget_set_sensitive (priv->treeview, TRUE);
2159 /* Sensitive the remove button if there is an account selected */
2160 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2161 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2162 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2164 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2165 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2166 NOTEBOOK_PAGE_ACCOUNT);
2168 maybe_show_import_dialog (self);
2172 accounts_dialog_cms_prepare_cb (GObject *source,
2173 GAsyncResult *result,
2176 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2177 EmpathyAccountsDialog *dialog = user_data;
2178 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2180 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2183 /* No need to update the settings if we are already preparing one */
2184 if (priv->settings_ready == NULL)
2185 accounts_dialog_update_settings (dialog, NULL);
2187 if (priv->initial_selection != NULL)
2189 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2190 g_object_unref (priv->initial_selection);
2191 priv->initial_selection = NULL;
2195 finished_loading (dialog);
2199 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2201 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2202 GList *accounts, *l;
2204 g_signal_connect (priv->account_manager, "account-validity-changed",
2205 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2207 g_signal_connect (priv->account_manager, "account-removed",
2208 G_CALLBACK (accounts_dialog_account_removed_cb),
2210 g_signal_connect (priv->account_manager, "account-enabled",
2211 G_CALLBACK (accounts_dialog_account_enabled_cb),
2213 g_signal_connect (priv->account_manager, "account-disabled",
2214 G_CALLBACK (accounts_dialog_account_disabled_cb),
2217 /* Add existing accounts */
2218 accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
2219 for (l = accounts; l; l = l->next)
2221 accounts_dialog_add_account (dialog, l->data);
2223 g_list_free_full (accounts, g_object_unref);
2225 priv->cms = empathy_connection_managers_dup_singleton ();
2227 empathy_connection_managers_prepare_async (priv->cms,
2228 accounts_dialog_cms_prepare_cb, dialog);
2230 accounts_dialog_model_select_first (dialog);
2234 accounts_dialog_manager_ready_cb (GObject *source_object,
2235 GAsyncResult *result,
2238 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2239 GError *error = NULL;
2241 if (!tp_proxy_prepare_finish (manager, result, &error))
2243 DEBUG ("Failed to prepare account manager: %s", error->message);
2244 g_error_free (error);
2248 accounts_dialog_accounts_setup (user_data);
2252 dialog_response_cb (GtkWidget *widget,
2256 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2258 if (response_id == GTK_RESPONSE_HELP)
2260 empathy_url_show (widget, "help:empathy/accounts-window");
2262 else if (response_id == GTK_RESPONSE_CLOSE ||
2263 response_id == GTK_RESPONSE_DELETE_EVENT)
2265 TpAccount *account = NULL;
2267 if (accounts_dialog_has_pending_change (dialog, &account))
2269 gchar *question_dialog_primary_text = get_dialog_primary_text (
2272 accounts_dialog_show_question_dialog (dialog,
2273 question_dialog_primary_text,
2274 _("You are about to close the window, which will discard\n"
2275 "your changes. Are you sure you want to proceed?"),
2276 G_CALLBACK (accounts_dialog_close_response_cb),
2278 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2279 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2281 g_free (question_dialog_primary_text);
2285 gtk_widget_destroy (widget);
2288 if (account != NULL)
2289 g_object_unref (account);
2294 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2296 GtkWidget *top_hbox;
2299 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2300 GtkWidget *content_area, *action_area;
2301 GtkWidget *grid, *hbox;
2303 GtkWidget *sw, *toolbar;
2304 GtkStyleContext *context;
2306 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2308 gui = empathy_builder_get_file (filename,
2309 "accounts_dialog_hbox", &top_hbox,
2310 "vbox_details", &priv->vbox_details,
2311 "alignment_settings", &priv->alignment_settings,
2312 "alignment_infobar", &priv->alignment_infobar,
2313 "treeview", &priv->treeview,
2314 "button_add", &priv->button_add,
2315 "button_remove", &priv->button_remove,
2316 "button_import", &priv->button_import,
2317 "notebook_account", &priv->notebook_account,
2318 "alignment_loading", &alig,
2320 "add_remove_toolbar", &toolbar,
2324 empathy_builder_connect (gui, dialog,
2325 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2326 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2327 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2328 "treeview", "button-press-event",
2329 accounts_dialog_treeview_button_press_event_cb,
2332 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2334 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2336 g_object_unref (gui);
2338 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2340 /* Display loading page */
2341 priv->loading = TRUE;
2343 priv->spinner = gtk_spinner_new ();
2345 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2346 gtk_widget_show (priv->spinner);
2348 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2350 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2351 NOTEBOOK_PAGE_LOADING);
2353 /* Remove button is insensitive until we have a selected account */
2354 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2356 /* Add and Import buttons and treeview are insensitive while the dialog
2358 gtk_widget_set_sensitive (priv->button_add, FALSE);
2359 gtk_widget_set_sensitive (priv->button_import, FALSE);
2360 gtk_widget_set_sensitive (priv->treeview, FALSE);
2362 if (priv->parent_window)
2363 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2364 priv->parent_window);
2366 priv->infobar = gtk_info_bar_new ();
2367 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2369 gtk_widget_show (priv->infobar);
2371 grid = gtk_grid_new ();
2372 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2374 GTK_CONTAINER (gtk_info_bar_get_content_area (
2375 GTK_INFO_BAR (priv->infobar))),
2378 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2379 GTK_ICON_SIZE_DIALOG);
2380 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2381 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2384 priv->label_name = gtk_label_new (NULL);
2385 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2388 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2389 gtk_widget_set_hexpand (hbox, TRUE);
2390 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2391 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2393 /* set up spinner */
2394 priv->throbber = gtk_spinner_new ();
2396 priv->image_status = gtk_image_new_from_icon_name (
2397 empathy_icon_name_for_presence (
2398 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2400 priv->label_status = gtk_label_new (NULL);
2401 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2403 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2404 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2405 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2407 /* enabled switch */
2408 priv->enabled_switch = gtk_switch_new ();
2409 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2410 g_signal_connect (priv->enabled_switch, "notify::active",
2411 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2412 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2414 gtk_widget_show_all (grid);
2416 /* Tweak the dialog */
2417 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2418 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2420 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2422 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2424 /* join the add/remove toolbar to the treeview */
2425 context = gtk_widget_get_style_context (sw);
2426 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2428 context = gtk_widget_get_style_context (toolbar);
2429 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2431 /* add dialog buttons */
2432 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2434 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2435 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2436 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2439 g_signal_connect (dialog, "response",
2440 G_CALLBACK (dialog_response_cb), dialog);
2442 g_signal_connect (dialog, "delete-event",
2443 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2447 do_dispose (GObject *obj)
2449 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2450 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2452 if (priv->user_info != NULL)
2454 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
2456 priv->user_info = NULL;
2459 if (priv->connecting_id != 0)
2461 g_source_remove (priv->connecting_id);
2462 priv->connecting_id = 0;
2465 if (priv->connectivity)
2467 g_object_unref (priv->connectivity);
2468 priv->connectivity = NULL;
2471 if (priv->account_manager != NULL)
2473 g_object_unref (priv->account_manager);
2474 priv->account_manager = NULL;
2477 if (priv->cms != NULL)
2479 g_object_unref (priv->cms);
2483 if (priv->initial_selection != NULL)
2485 g_object_unref (priv->initial_selection);
2486 priv->initial_selection = NULL;
2489 tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
2491 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2495 do_get_property (GObject *object,
2500 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2502 switch (property_id)
2505 g_value_set_object (value, priv->parent_window);
2508 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2513 do_set_property (GObject *object,
2515 const GValue *value,
2518 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2520 switch (property_id)
2523 priv->parent_window = g_value_get_object (value);
2526 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2531 do_constructed (GObject *object)
2533 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2534 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2535 GtkTreeModel *model;
2537 accounts_dialog_build_ui (dialog);
2538 accounts_dialog_model_setup (dialog);
2540 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2541 g_signal_connect (model, "row-inserted",
2542 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2543 g_signal_connect (model, "row-deleted",
2544 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2546 /* Set up signalling */
2547 priv->account_manager = tp_account_manager_dup ();
2549 tp_proxy_prepare_async (priv->account_manager, NULL,
2550 accounts_dialog_manager_ready_cb, dialog);
2552 priv->connectivity = g_network_monitor_get_default ();
2553 g_object_ref (priv->connectivity);
2557 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2559 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2560 GParamSpec *param_spec;
2562 oclass->dispose = do_dispose;
2563 oclass->constructed = do_constructed;
2564 oclass->set_property = do_set_property;
2565 oclass->get_property = do_get_property;
2567 param_spec = g_param_spec_object ("parent",
2568 "parent", "The parent window",
2570 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2571 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2573 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2577 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2579 EmpathyAccountsDialogPriv *priv;
2581 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2582 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2583 EmpathyAccountsDialogPriv);
2584 dialog->priv = priv;
2586 priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
2587 g_free, g_object_unref);
2590 /* public methods */
2593 empathy_accounts_dialog_show (GtkWindow *parent,
2594 TpAccount *selected_account)
2596 EmpathyAccountsDialog *dialog;
2597 EmpathyAccountsDialogPriv *priv;
2599 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2600 "parent", parent, NULL);
2602 priv = GET_PRIV (dialog);
2604 if (selected_account)
2606 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2607 accounts_dialog_set_selected_account (dialog, selected_account);
2609 /* save the selection to set it later when the cms
2612 priv->initial_selection = g_object_ref (selected_account);
2615 gtk_window_present (GTK_WINDOW (dialog));
2617 return GTK_WIDGET (dialog);
2627 static LaunchUOACtx *
2628 launch_uoa_ctx_new (TpAccount *account,
2633 ctx = g_slice_new0 (LaunchUOACtx);
2634 if (account != NULL)
2635 ctx->account = g_object_ref (account);
2636 ctx->if_needed = if_needed;
2642 launch_uoa_ctx_free (LaunchUOACtx *ctx)
2644 g_clear_object (&ctx->account);
2645 g_slice_free (LaunchUOACtx, ctx);
2649 am_prepare_cb (GObject *source,
2650 GAsyncResult *result,
2653 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
2654 GError *error = NULL;
2655 LaunchUOACtx *ctx = user_data;
2658 if (!tp_proxy_prepare_finish (manager, result, &error))
2660 DEBUG ("Failed to prepare account manager: %s", error->message);
2661 g_error_free (error);
2665 if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
2668 if (ctx->account != NULL)
2670 const GValue *value;
2672 value = tp_account_get_storage_identifier (ctx->account);
2674 if (G_VALUE_HOLDS_UINT (value))
2675 args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
2678 empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
2682 launch_uoa_ctx_free (ctx);
2686 launch_uoa_panel (TpAccount *selected_account,
2690 TpAccountManager *manager;
2696 manager = tp_account_manager_dup ();
2698 tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
2699 launch_uoa_ctx_new (selected_account, if_needed));
2701 g_object_unref (manager);
2704 #else /* HAVE_UOA */
2707 launch_empathy_accounts (TpAccount *selected_account,
2713 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2715 args = g_string_new (NULL);
2717 if (selected_account != NULL)
2718 g_string_append_printf (args, " --select-account=%s",
2719 tp_account_get_path_suffix (selected_account));
2722 g_string_append_printf (args, " --if-needed");
2725 g_string_append_printf (args, " --hidden");
2727 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2729 selected_account == NULL ? "<none selected>" :
2730 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2732 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2734 g_string_free (args, TRUE);
2736 #endif /* HAVE_UOA */
2739 empathy_accounts_dialog_show_application (GdkScreen *screen,
2740 TpAccount *selected_account,
2745 launch_uoa_panel (selected_account, if_needed, hidden);
2747 launch_empathy_accounts (selected_account, if_needed, hidden);
2752 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2754 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2755 gboolean result = FALSE;
2757 if (priv->setting_widget == NULL)
2760 g_object_get (priv->setting_widget,
2761 "creating-account", &result, NULL);