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>
33 #include <glib/gi18n-lib.h>
34 #include <dbus/dbus-glib.h>
35 #include <gio/gdesktopappinfo.h>
37 #include <telepathy-glib/account-manager.h>
38 #include <telepathy-glib/defs.h>
39 #include <telepathy-glib/util.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy/empathy-connection-managers.h>
43 #include <libempathy/empathy-pkg-kit.h>
45 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include <libempathy-gtk/empathy-protocol-chooser.h>
47 #include <libempathy-gtk/empathy-account-widget.h>
48 #include <libempathy-gtk/empathy-account-widget-irc.h>
49 #include <libempathy-gtk/empathy-account-widget-sip.h>
50 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
51 #include <libempathy-gtk/empathy-user-info.h>
52 #include <libempathy-gtk/empathy-images.h>
53 #include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
54 #include <libempathy-gtk/empathy-new-account-dialog.h>
56 #include "empathy-accounts-common.h"
57 #include "empathy-accounts-dialog.h"
58 #include "empathy-import-dialog.h"
59 #include "empathy-import-utils.h"
61 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
62 #include <libempathy/empathy-debug.h>
64 /* Flashing delay for icons (milliseconds). */
65 #define FLASH_TIMEOUT 500
67 /* The primary text of the dialog shown to the user when he is about to lose
69 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
70 _("There are unsaved modifications to your %s account.")
71 /* The primary text of the dialog shown to the user when he is about to lose
72 * an unsaved new account */
73 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
74 _("Your new account has not been saved yet.")
76 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
77 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
81 NOTEBOOK_PAGE_ACCOUNT = 0,
82 NOTEBOOK_PAGE_LOADING,
83 NOTEBOOK_PAGE_NO_PROTOCOL
87 GtkWidget *alignment_settings;
88 GtkWidget *alignment_infobar;
90 GtkWidget *vbox_details;
92 GtkWidget *label_status;
93 GtkWidget *image_status;
95 GtkWidget *enabled_switch;
98 GtkCellRenderer *name_renderer;
100 GtkWidget *button_add;
101 GtkWidget *button_remove;
102 GtkWidget *button_import;
104 GtkWidget *image_type;
105 GtkWidget *label_name;
106 GtkWidget *label_type;
107 GtkWidget *dialog_content;
108 GtkWidget *user_info;
110 GtkWidget *notebook_account;
114 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
115 * just its GtkWidget. It is the only reliable source we can query to know if
116 * there are any unsaved changes to the currently selected account. We can't
117 * look at the account settings because it does not contain everything that
118 * can be changed using the EmpathyAccountWidget. For instance, it does not
119 * contain the state of the "Enabled" checkbox.
121 * Even if we create it ourself, we just get a weak ref and not a strong one
122 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
123 * That's kinda ugly; cf bgo #640417.
126 EmpathyAccountWidget *setting_widget;
128 gboolean connecting_show;
131 gulong settings_ready_id;
132 EmpathyAccountSettings *settings_ready;
134 TpAccountManager *account_manager;
135 EmpathyConnectionManagers *cms;
136 GNetworkMonitor *connectivity;
138 GtkWindow *parent_window;
139 TpAccount *initial_selection;
141 /* Those are needed when changing the selected row. When a user selects
142 * another account and there are unsaved changes on the currently selected
143 * one, a confirmation message box is presented to him. Since his answer
144 * is retrieved asynchronously, we keep some information as member of the
145 * EmpathyAccountsDialog object. */
146 gboolean force_change_row;
147 GtkTreeRowReference *destination_row;
148 } EmpathyAccountsDialogPriv;
154 COL_ACCOUNT_SETTINGS,
162 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
163 EmpathyAccountsDialog *dialog);
165 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
167 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
168 EmpathyAccountSettings *settings);
170 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
173 static void accounts_dialog_connection_changed_cb (TpAccount *account,
177 gchar *dbus_error_name,
179 EmpathyAccountsDialog *dialog);
181 static void accounts_dialog_presence_changed_cb (TpAccount *account,
184 gchar *status_message,
185 EmpathyAccountsDialog *dialog);
187 static void accounts_dialog_model_selection_changed (
188 GtkTreeSelection *selection,
189 EmpathyAccountsDialog *dialog);
191 static gboolean accounts_dialog_has_pending_change (
192 EmpathyAccountsDialog *dialog, TpAccount **account);
195 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
196 const gchar *display_name)
199 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
201 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
202 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
208 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
209 const gchar *message)
211 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
212 gchar *message_markup;
214 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
215 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
217 gtk_widget_set_tooltip_text (priv->label_status, message);
219 g_free (message_markup);
223 accounts_dialog_enable_account_cb (GObject *object,
224 GAsyncResult *result,
227 TpAccount *account = TP_ACCOUNT (object);
228 gboolean enable = GPOINTER_TO_UINT (user_data);
229 GError *error = NULL;
230 TpAccountManager *am;
232 if (!tp_account_set_enabled_finish (account, result, &error))
234 DEBUG ("Could not enable the account: %s", error->message);
235 g_error_free (error);
239 /* tp_account_is_enabled() is not updated yet at this point */
242 am = tp_account_manager_dup ();
244 empathy_connect_new_account (account, am);
250 enable_and_connect_account (TpAccount *account,
253 tp_account_set_enabled_async (account, enable,
254 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
258 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
260 EmpathyAccountsDialog *dialog)
262 EmpathyAccountSettings *settings;
266 settings = accounts_dialog_model_get_selected_settings (dialog);
267 if (settings == NULL)
270 account = empathy_account_settings_get_account (settings);
274 enable = gtk_switch_get_active (sw);
276 enable_and_connect_account (account, enable);
280 install_haze_cb (GObject *source,
281 GAsyncResult *result,
284 GError *error = NULL;
286 if (!empathy_pkg_kit_install_packages_finish (result, &error))
288 DEBUG ("Failed to install telepathy-haze: %s", error->message);
290 g_error_free (error);
295 account_is_selected (EmpathyAccountsDialog *dialog,
298 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
299 GtkTreeSelection *selection;
302 TpAccount *selected_account;
307 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
309 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
312 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
314 if (selected_account != NULL)
315 g_object_unref (selected_account);
317 return account == selected_account;
321 account_can_be_enabled (TpAccount *account)
323 TpStorageRestrictionFlags storage_restrictions;
325 storage_restrictions = tp_account_get_storage_restrictions (account);
326 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
329 /* Butterfly accounts shouldn't be used any more */
330 if (!tp_strdiff (tp_account_get_cm_name (account),
338 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
341 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
342 gchar *status_message = NULL;
346 gboolean account_enabled;
347 gboolean creating_account;
348 gboolean display_switch = TRUE;
350 /* do not update the infobar when the account is not selected */
351 if (!account_is_selected (dialog, account))
356 status = tp_account_get_connection_status (account, &reason);
357 presence = tp_account_get_current_presence (account, NULL, &status_message);
358 account_enabled = tp_account_is_enabled (account);
359 creating_account = FALSE;
361 if (status == TP_CONNECTION_STATUS_CONNECTED &&
362 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
363 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
364 /* If presence is Unset (CM doesn't implement SimplePresence) but we
365 * are connected, consider ourself as Available.
366 * We also check Offline because of this MC5 bug: fd.o #26060 */
367 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
369 /* set presence to offline if account is disabled
370 * (else no icon is shown in infobar)*/
371 if (!account_enabled)
372 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
374 display_switch = account_can_be_enabled (account);
378 status = TP_CONNECTION_STATUS_DISCONNECTED;
379 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
380 account_enabled = FALSE;
381 creating_account = TRUE;
384 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
385 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
387 /* update the enabled switch */
388 g_signal_handlers_block_by_func (priv->enabled_switch,
389 accounts_dialog_enable_switch_active_cb, dialog);
390 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
392 g_signal_handlers_unblock_by_func (priv->enabled_switch,
393 accounts_dialog_enable_switch_active_cb, dialog);
395 /* Display the Enable switch if account supports it */
396 gtk_widget_set_visible (priv->enabled_switch, display_switch);
402 case TP_CONNECTION_STATUS_CONNECTING:
403 accounts_dialog_status_infobar_set_message (dialog,
405 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
408 gtk_spinner_start (GTK_SPINNER (priv->throbber));
409 gtk_widget_show (priv->throbber);
410 gtk_widget_hide (priv->image_status);
412 case TP_CONNECTION_STATUS_CONNECTED:
413 if (g_strcmp0 (status_message, "") == 0)
417 message = g_strdup_printf ("%s",
418 empathy_presence_get_default_message (presence));
420 accounts_dialog_status_infobar_set_message (dialog, message);
427 message = g_strdup_printf ("%s — %s",
428 empathy_presence_get_default_message (presence),
431 accounts_dialog_status_infobar_set_message (dialog, message);
434 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
437 gtk_widget_show (priv->image_status);
438 gtk_widget_hide (priv->throbber);
440 case TP_CONNECTION_STATUS_DISCONNECTED:
441 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
445 message = g_strdup_printf (_("Offline — %s"),
446 empathy_account_get_error_message (account, NULL));
447 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
448 GTK_MESSAGE_WARNING);
450 accounts_dialog_status_infobar_set_message (dialog, message);
457 message = g_strdup_printf (_("Disconnected — %s"),
458 empathy_account_get_error_message (account, NULL));
459 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
462 accounts_dialog_status_infobar_set_message (dialog, message);
466 if (!g_network_monitor_get_network_available (priv->connectivity))
467 accounts_dialog_status_infobar_set_message (dialog,
468 _("Offline — No Network Connection"));
470 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
471 gtk_widget_show (priv->image_status);
472 gtk_widget_hide (priv->throbber);
475 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
476 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
477 GTK_MESSAGE_WARNING);
479 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
480 gtk_widget_hide (priv->image_status);
481 gtk_widget_hide (priv->throbber);
486 if (!tp_strdiff (tp_account_get_cm_name (account),
489 const gchar *packages[] = { "telepathy-haze", NULL };
491 accounts_dialog_status_infobar_set_message (dialog,
492 _("This account has been disabled because it relies on an old, "
493 "unsupported backend. Please install telepathy-haze and "
494 "restart your session to migrate the account."));
496 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
497 install_haze_cb, NULL);
501 accounts_dialog_status_infobar_set_message (dialog,
502 _("Offline — Account Disabled"));
505 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
506 GTK_MESSAGE_WARNING);
507 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
508 gtk_widget_show (priv->image_status);
509 gtk_widget_hide (priv->throbber);
512 gtk_widget_show (priv->label_status);
514 if (!creating_account)
515 gtk_widget_show (priv->infobar);
517 gtk_widget_hide (priv->infobar);
519 g_free (status_message);
523 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
527 GtkTreeSelection *selection;
529 EmpathyAccountSettings *settings;
531 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
533 view = GTK_TREE_VIEW (priv->treeview);
534 selection = gtk_tree_view_get_selection (view);
536 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
539 gtk_tree_model_get (model, &iter,
540 COL_ACCOUNT_SETTINGS, &settings,
541 COL_ACCOUNT, &account, -1);
543 empathy_account_widget_discard_pending_changes (priv->setting_widget);
547 /* We were creating an account. We remove the selected row */
548 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
552 /* We were modifying an account. We discard the changes by reloading the
553 * settings and the UI. */
554 accounts_dialog_update_settings (dialog, settings);
555 g_object_unref (account);
558 gtk_widget_set_sensitive (priv->treeview, TRUE);
559 gtk_widget_set_sensitive (priv->button_add, TRUE);
560 gtk_widget_set_sensitive (priv->button_remove, TRUE);
561 gtk_widget_set_sensitive (priv->button_import, TRUE);
563 if (settings != NULL)
564 g_object_unref (settings);
568 empathy_account_dialog_widget_cancelled_cb (
569 EmpathyAccountWidget *widget_object,
570 EmpathyAccountsDialog *dialog)
572 empathy_account_dialog_cancel (dialog);
576 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
578 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
583 g_object_get (priv->setting_widget,
584 "creating-account", &creating, NULL);
589 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
591 if (gtk_tree_model_get_iter_first (model, &iter))
592 return gtk_tree_model_iter_next (model, &iter);
598 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
600 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
601 EmpathyAccountSettings *settings;
602 GtkWidget *subdialog, *content_area, *align;
604 settings = accounts_dialog_model_get_selected_settings (dialog);
605 if (settings == NULL)
608 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
610 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
613 priv->setting_widget = (EmpathyAccountWidget *)
614 empathy_account_widget_new_for_protocol (settings, FALSE);
616 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
617 (gpointer *) &priv->setting_widget);
619 if (accounts_dialog_has_valid_accounts (dialog))
620 empathy_account_widget_set_other_accounts_exist (
621 priv->setting_widget, TRUE);
623 g_signal_connect (priv->setting_widget, "cancelled",
624 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
626 g_signal_connect_swapped (priv->setting_widget, "close",
627 G_CALLBACK (gtk_widget_destroy), subdialog);
629 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
631 align = gtk_alignment_new (0.5, 0.5, 1, 1);
632 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
634 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
635 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
637 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
638 gtk_widget_show (align);
639 gtk_widget_show (subdialog);
643 use_external_storage_provider (EmpathyAccountsDialog *self,
646 const gchar *provider;
648 provider = tp_account_get_storage_provider (account);
649 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
651 empathy_launch_external_app ("gnome-control-center.desktop",
652 "bisho.desktop", NULL);
655 else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
657 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
661 else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
663 empathy_launch_external_app ("gnome-credentials-panel.desktop",
669 DEBUG ("Don't know how to handle %s", provider);
675 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
678 EmpathyAccountSettings *settings;
680 TpStorageRestrictionFlags storage_restrictions;
682 settings = accounts_dialog_model_get_selected_settings (dialog);
683 if (settings == NULL)
686 account = empathy_account_settings_get_account (settings);
687 g_return_if_fail (account != NULL);
689 storage_restrictions = tp_account_get_storage_restrictions (account);
691 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
692 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
694 DEBUG ("Account is provided by an external storage provider");
696 use_external_storage_provider (dialog, account);
700 account_dialog_create_edit_params_dialog (dialog);
705 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
706 EmpathyAccountSettings *settings)
708 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
709 const gchar *icon_name;
711 GtkWidget *bbox, *button;
714 account = empathy_account_settings_get_account (settings);
716 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
717 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
718 priv->dialog_content);
719 gtk_widget_show (priv->dialog_content);
721 alig = gtk_alignment_new (0.5, 0, 1, 1);
722 priv->user_info = empathy_user_info_new (account);
723 gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
724 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
725 gtk_widget_show (alig);
726 gtk_widget_show (priv->user_info);
728 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
729 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
730 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
731 gtk_widget_show (bbox);
733 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
734 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
735 gtk_widget_show (button);
736 g_signal_connect_swapped (button, "clicked",
737 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
739 icon_name = empathy_account_settings_get_icon_name (settings);
741 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
743 /* show the default icon; keep this in sync with the default
744 * one in empathy-accounts-dialog.ui.
746 icon_name = GTK_STOCK_CUT;
748 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
749 icon_name, GTK_ICON_SIZE_DIALOG);
750 gtk_widget_set_tooltip_text (priv->image_type,
751 empathy_protocol_name_to_display_name
752 (empathy_account_settings_get_protocol (settings)));
753 gtk_widget_show (priv->image_type);
755 accounts_dialog_update_name_label (dialog,
756 empathy_account_settings_get_display_name (settings));
758 accounts_dialog_update_status_infobar (dialog, account);
762 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
764 EmpathyAccountsDialog *dialog)
766 if (empathy_account_settings_is_ready (settings))
767 account_dialog_create_dialog_content (dialog, settings);
771 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
775 GtkTreeSelection *selection;
777 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
780 view = GTK_TREE_VIEW (priv->treeview);
781 model = gtk_tree_view_get_model (view);
783 if (gtk_tree_model_get_iter_first (model, &iter))
785 selection = gtk_tree_view_get_selection (view);
786 gtk_tree_selection_select_iter (selection, &iter);
790 accounts_dialog_update_settings (dialog, NULL);
795 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
800 GtkTreeSelection *selection;
801 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
803 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
805 if (gtk_tree_selection_get_selected (selection, &model, &iter))
806 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
808 return priv->setting_widget != NULL
809 && empathy_account_widget_contains_pending_changes (
810 priv->setting_widget);
814 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
815 const gchar *primary_text,
816 const gchar *secondary_text,
817 GCallback response_callback,
819 const gchar *first_button_text,
823 GtkWidget *message_dialog;
824 const gchar *button_text;
826 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
827 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
828 GTK_MESSAGE_QUESTION,
832 gtk_message_dialog_format_secondary_text (
833 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
835 va_start (button_args, first_button_text);
836 for (button_text = first_button_text;
838 button_text = va_arg (button_args, const gchar *))
841 response_id = va_arg (button_args, gint);
843 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
846 va_end (button_args);
848 g_signal_connect (message_dialog, "response", response_callback, user_data);
850 gtk_widget_show (message_dialog);
854 get_dialog_primary_text (TpAccount *account)
858 /* Existing account */
859 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
860 tp_account_get_display_name (account));
864 /* Newly created account */
865 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
870 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
871 EmpathyAccountsDialog *self)
876 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
877 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
879 response = gtk_dialog_run (GTK_DIALOG (dialog));
881 if (response == GTK_RESPONSE_APPLY)
883 EmpathyAccountSettings *settings;
886 settings = empathy_new_account_dialog_get_settings (
887 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
889 /* The newly created account has already been added by
890 * accounts_dialog_account_validity_changed_cb so we just
891 * have to select it. */
892 account = empathy_account_settings_get_account (settings);
893 accounts_dialog_model_set_selected (self, account);
896 gtk_widget_destroy (dialog);
900 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
901 EmpathyAccountSettings *settings)
903 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
905 if (priv->settings_ready != NULL)
907 g_signal_handler_disconnect (priv->settings_ready,
908 priv->settings_ready_id);
909 priv->settings_ready = NULL;
910 priv->settings_ready_id = 0;
917 GtkTreeSelection *selection;
919 view = GTK_TREE_VIEW (priv->treeview);
920 model = gtk_tree_view_get_model (view);
921 selection = gtk_tree_view_get_selection (view);
923 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
925 /* We have configured accounts, select the first one if there
926 * is no other account selected already. */
927 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
928 accounts_dialog_model_select_first (dialog);
933 /* No account and no profile, warn the user */
934 gtk_widget_hide (priv->vbox_details);
935 gtk_widget_set_sensitive (priv->button_add, FALSE);
937 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
938 NOTEBOOK_PAGE_NO_PROTOCOL);
942 /* We have an account selected, destroy old settings and create a new
943 * one for the account selected */
944 gtk_widget_show (priv->vbox_details);
946 if (priv->user_info != NULL)
948 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
950 priv->user_info = NULL;
952 if (priv->dialog_content)
954 gtk_widget_destroy (priv->dialog_content);
955 priv->dialog_content = NULL;
958 if (empathy_account_settings_is_ready (settings))
960 account_dialog_create_dialog_content (dialog, settings);
964 priv->settings_ready = settings;
965 priv->settings_ready_id =
966 g_signal_connect (settings, "notify::ready",
967 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
973 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
974 GtkCellEditable *editable,
976 EmpathyAccountsDialog *dialog)
978 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
980 if (priv->connecting_id)
981 g_source_remove (priv->connecting_id);
983 DEBUG ("Editing account name started; stopping flashing");
987 get_status_icon_for_account (EmpathyAccountsDialog *self,
990 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
991 TpConnectionStatus status;
992 TpConnectionStatusReason reason;
993 TpConnectionPresenceType presence;
996 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
998 if (!tp_account_is_enabled (account))
999 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1001 status = tp_account_get_connection_status (account, &reason);
1003 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1005 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1006 /* An error occured */
1007 return GTK_STOCK_DIALOG_ERROR;
1009 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1011 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1013 /* Account is connecting. Display a blinking account alternating between
1014 * the offline icon and the requested presence. */
1015 if (priv->connecting_show)
1016 presence = tp_account_get_requested_presence (account, NULL, NULL);
1018 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1022 /* status == TP_CONNECTION_STATUS_CONNECTED */
1023 presence = tp_account_get_current_presence (account, NULL, NULL);
1025 /* If presence is Unset (CM doesn't implement SimplePresence),
1026 * display the 'available' icon.
1027 * We also check Offline because of this MC5 bug: fd.o #26060 */
1028 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1029 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1030 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1033 return empathy_icon_name_for_presence (presence);
1037 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1038 GtkCellRenderer *cell,
1039 GtkTreeModel *model,
1041 EmpathyAccountsDialog *dialog)
1045 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1048 "icon-name", get_status_icon_for_account (dialog, account),
1051 if (account != NULL)
1052 g_object_unref (account);
1056 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1057 GtkCellRenderer *cell,
1058 GtkTreeModel *model,
1060 EmpathyAccountsDialog *dialog)
1062 EmpathyAccountSettings *settings;
1065 TpConnectionStatus status;
1067 gtk_tree_model_get (model, iter,
1068 COL_STATUS, &status,
1069 COL_ACCOUNT_SETTINGS, &settings,
1072 icon_name = empathy_account_settings_get_icon_name (settings);
1073 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1080 g_object_unref (settings);
1083 g_object_unref (pixbuf);
1087 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1094 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1096 if (account == NULL)
1099 if (tp_account_get_connection_status (account, NULL) ==
1100 TP_CONNECTION_STATUS_CONNECTING)
1102 /* Only update the row where we have a connecting account as that's the
1103 * ones having a blinking icon. */
1104 gtk_tree_model_row_changed (model, path, iter);
1107 g_object_unref (account);
1112 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1115 GtkTreeModel *model;
1116 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1118 priv->connecting_show = !priv->connecting_show;
1120 view = GTK_TREE_VIEW (priv->treeview);
1121 model = gtk_tree_view_get_model (view);
1123 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1129 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1132 EmpathyAccountsDialog *dialog)
1134 EmpathyAccountSettings *settings;
1135 GtkTreeModel *model;
1136 GtkTreePath *treepath;
1138 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1139 gboolean connecting;
1141 empathy_account_manager_get_accounts_connected (&connecting);
1145 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1146 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1150 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1151 treepath = gtk_tree_path_new_from_string (path);
1152 gtk_tree_model_get_iter (model, &iter, treepath);
1153 gtk_tree_model_get (model, &iter,
1154 COL_ACCOUNT_SETTINGS, &settings,
1156 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1159 gtk_tree_path_free (treepath);
1161 empathy_account_settings_set_display_name_async (settings, new_text,
1163 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1164 g_object_unref (settings);
1168 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1173 GtkTreeModel *model;
1175 GtkTreeSelection *selection;
1176 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1177 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1179 if (response_id == GTK_RESPONSE_YES)
1181 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1183 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1186 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1188 if (account != NULL)
1190 tp_account_remove_async (account, NULL, NULL);
1191 g_object_unref (account);
1195 /* No need to call accounts_dialog_model_selection_changed while
1196 * removing as we are going to call accounts_dialog_model_select_first
1197 * right after which will update the selection. */
1198 g_signal_handlers_block_by_func (selection,
1199 accounts_dialog_model_selection_changed, account_dialog);
1201 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1203 g_signal_handlers_unblock_by_func (selection,
1204 accounts_dialog_model_selection_changed, account_dialog);
1206 accounts_dialog_model_select_first (account_dialog);
1209 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1213 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1216 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1218 GtkTreeModel *model;
1219 gchar *question_dialog_primary_text;
1221 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1223 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1225 if (account == NULL || !tp_account_is_valid (account))
1227 if (account != NULL)
1228 g_object_unref (account);
1229 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1230 accounts_dialog_model_select_first (dialog);
1234 question_dialog_primary_text = g_strdup_printf (
1235 _("Do you want to remove %s from your computer?"),
1236 tp_account_get_display_name (account));
1238 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1239 _("This will not remove your account on the server."),
1240 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1242 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1243 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1245 g_free (question_dialog_primary_text);
1246 g_object_unref (account);
1250 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1251 EmpathyAccountsDialog *dialog)
1253 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1255 GtkTreeSelection *selection;
1258 view = GTK_TREE_VIEW (priv->treeview);
1259 selection = gtk_tree_view_get_selection (view);
1260 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1263 accounts_dialog_remove_account_iter (dialog, &iter);
1267 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1270 GtkTreeViewColumn *column;
1271 GtkCellRenderer *cell;
1272 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1274 view = GTK_TREE_VIEW (priv->treeview);
1275 gtk_tree_view_set_headers_visible (view, FALSE);
1277 /* Account column */
1278 column = gtk_tree_view_column_new ();
1279 gtk_tree_view_column_set_expand (column, TRUE);
1280 gtk_tree_view_append_column (view, column);
1282 /* Status icon renderer */
1283 cell = gtk_cell_renderer_pixbuf_new ();
1284 gtk_tree_view_column_pack_start (column, cell, FALSE);
1285 gtk_tree_view_column_set_cell_data_func (column, cell,
1286 (GtkTreeCellDataFunc)
1287 accounts_dialog_model_status_pixbuf_data_func,
1291 /* Protocol icon renderer */
1292 cell = gtk_cell_renderer_pixbuf_new ();
1293 gtk_tree_view_column_pack_start (column, cell, FALSE);
1294 gtk_tree_view_column_set_cell_data_func (column, cell,
1295 (GtkTreeCellDataFunc)
1296 accounts_dialog_model_protocol_pixbuf_data_func,
1301 priv->name_renderer = gtk_cell_renderer_text_new ();
1302 g_object_set (priv->name_renderer,
1303 "ellipsize", PANGO_ELLIPSIZE_END,
1307 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1308 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1310 g_signal_connect (priv->name_renderer, "edited",
1311 G_CALLBACK (accounts_dialog_name_edited_cb),
1313 g_signal_connect (priv->name_renderer, "editing-started",
1314 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1316 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1319 static EmpathyAccountSettings *
1320 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1323 GtkTreeModel *model;
1324 GtkTreeSelection *selection;
1326 EmpathyAccountSettings *settings;
1327 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1329 view = GTK_TREE_VIEW (priv->treeview);
1330 selection = gtk_tree_view_get_selection (view);
1332 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1335 gtk_tree_model_get (model, &iter,
1336 COL_ACCOUNT_SETTINGS, &settings, -1);
1342 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1343 EmpathyAccountsDialog *dialog)
1345 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1346 EmpathyAccountSettings *settings;
1347 GtkTreeModel *model;
1349 gboolean is_selection;
1350 gboolean creating = FALSE;
1352 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1354 settings = accounts_dialog_model_get_selected_settings (dialog);
1355 accounts_dialog_update_settings (dialog, settings);
1357 if (settings != NULL)
1358 g_object_unref (settings);
1360 if (priv->setting_widget != NULL)
1362 g_object_get (priv->setting_widget,
1363 "creating-account", &creating, NULL);
1366 /* Update remove button sensitivity */
1367 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1372 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1374 gpointer *user_data)
1376 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1377 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1379 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1381 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1383 /* The user wants to lose unsaved changes to the currently selected
1384 * account and select another account. We discard the changes and
1385 * select the other account. */
1387 GtkTreeSelection *selection;
1389 priv->force_change_row = TRUE;
1390 empathy_account_widget_discard_pending_changes (
1391 priv->setting_widget);
1393 path = gtk_tree_row_reference_get_path (priv->destination_row);
1394 selection = gtk_tree_view_get_selection (
1395 GTK_TREE_VIEW (priv->treeview));
1399 /* This will trigger a call to
1400 * accounts_dialog_account_selection_change() */
1401 gtk_tree_selection_select_path (selection, path);
1402 gtk_tree_path_free (path);
1405 gtk_tree_row_reference_free (priv->destination_row);
1409 priv->force_change_row = FALSE;
1414 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1415 GtkTreeModel *model,
1417 gboolean path_currently_selected,
1420 TpAccount *account = NULL;
1421 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1422 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1425 if (priv->force_change_row)
1427 /* We came back here because the user wants to discard changes to his
1428 * modified account. The changes have already been discarded so we
1429 * just change the selected row. */
1430 priv->force_change_row = FALSE;
1434 if (accounts_dialog_has_pending_change (dialog, &account))
1436 /* The currently selected account has some unsaved changes. We ask
1437 * the user if he really wants to lose his changes and select another
1439 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1440 priv->destination_row = gtk_tree_row_reference_new (model, path);
1442 accounts_dialog_show_question_dialog (dialog,
1443 question_dialog_primary_text,
1444 _("You are about to select another account, which will discard\n"
1445 "your changes. Are you sure you want to proceed?"),
1446 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1448 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1449 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1451 g_free (question_dialog_primary_text);
1459 if (account != NULL)
1460 g_object_unref (account);
1466 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1468 GtkListStore *store;
1469 GtkTreeSelection *selection;
1470 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1472 store = gtk_list_store_new (COL_COUNT,
1473 G_TYPE_STRING, /* name */
1474 G_TYPE_UINT, /* status */
1475 TP_TYPE_ACCOUNT, /* account */
1476 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1478 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1479 GTK_TREE_MODEL (store));
1481 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1482 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1483 gtk_tree_selection_set_select_function (selection,
1484 accounts_dialog_account_selection_change, dialog, NULL);
1486 g_signal_connect (selection, "changed",
1487 G_CALLBACK (accounts_dialog_model_selection_changed),
1490 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1491 COL_NAME, GTK_SORT_ASCENDING);
1493 accounts_dialog_model_add_columns (dialog);
1495 g_object_unref (store);
1499 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1504 GtkTreeModel *model;
1506 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1508 /* Update the status in the model */
1509 view = GTK_TREE_VIEW (priv->treeview);
1510 model = gtk_tree_view_get_model (view);
1512 for (ok = gtk_tree_model_get_iter_first (model, iter);
1514 ok = gtk_tree_model_iter_next (model, iter))
1516 TpAccount *this_account;
1519 gtk_tree_model_get (model, iter,
1520 COL_ACCOUNT, &this_account,
1523 equal = (this_account == account);
1524 g_object_unref (this_account);
1534 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1537 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1538 GtkTreeSelection *selection;
1540 GtkTreeModel *model;
1542 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1544 gtk_tree_selection_select_iter (selection, iter);
1546 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1547 path = gtk_tree_model_get_path (model, iter);
1549 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1552 gtk_tree_path_free (path);
1556 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1561 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1562 select_and_scroll_to_iter (dialog, &iter);
1566 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1571 enabled = tp_account_is_enabled (account);
1573 enable_and_connect_account (account, !enabled);
1577 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1578 EmpathyAccountsDialog *self)
1580 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1583 GtkTreeSelection *selection;
1584 GtkTreeModel *model;
1586 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1587 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1589 path = gtk_tree_model_get_path (model, &iter);
1591 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1593 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1594 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1595 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1597 gtk_tree_path_free (path);
1601 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1602 GdkEventButton *event,
1603 EmpathyAccountsDialog *dialog)
1605 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1606 TpAccount *account = NULL;
1607 GtkTreeModel *model = NULL;
1608 GtkTreePath *path = NULL;
1613 /* ignore multiple clicks */
1614 if (event->type != GDK_BUTTON_PRESS)
1617 if (event->button != 3)
1620 /* Selection is not yet set, so we have to get account from event position */
1621 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1622 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1623 event->x, event->y, &path, NULL, NULL, NULL))
1626 if (!gtk_tree_model_get_iter (model, &iter, path))
1629 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1631 /* Create the menu */
1632 menu = empathy_context_menu_new (GTK_WIDGET (view));
1634 /* Menu item: to enabled/disable the account */
1635 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1637 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1639 if (account_can_be_enabled (account))
1643 active = tp_account_is_enabled (account);
1644 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1647 tp_g_signal_connect_object (item, "activate",
1648 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1652 gtk_widget_set_sensitive (item, FALSE);
1655 gtk_widget_show (item);
1657 /* Menu item: Rename */
1658 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1659 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1661 tp_g_signal_connect_object (item, "activate",
1662 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1664 gtk_widget_show (item);
1666 /* FIXME: Add here presence items, to be able to set per-account presence */
1669 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1670 event->button, event->time);
1673 tp_clear_object (&account);
1674 gtk_tree_path_free (path);
1680 reload_account_widget (EmpathyAccountsDialog *self)
1682 EmpathyAccountSettings *settings;
1684 settings = accounts_dialog_model_get_selected_settings (self);
1685 accounts_dialog_update_settings (self, settings);
1689 accounts_dialog_connection_changed_cb (TpAccount *account,
1693 gchar *dbus_error_name,
1694 GHashTable *details,
1695 EmpathyAccountsDialog *dialog)
1697 GtkTreeModel *model;
1700 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1702 /* Update the status-infobar in the details view */
1703 accounts_dialog_update_status_infobar (dialog, account);
1705 /* Update the status in the model */
1706 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1708 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1712 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1713 COL_STATUS, current,
1716 path = gtk_tree_model_get_path (model, &iter);
1717 gtk_tree_model_row_changed (model, path, &iter);
1718 gtk_tree_path_free (path);
1721 empathy_account_manager_get_accounts_connected (&found);
1723 if (!found && priv->connecting_id)
1725 g_source_remove (priv->connecting_id);
1726 priv->connecting_id = 0;
1729 if (found && !priv->connecting_id)
1730 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1731 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1736 update_account_in_treeview (EmpathyAccountsDialog *self,
1739 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1741 GtkTreeModel *model;
1743 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1744 if (accounts_dialog_get_account_iter (self, account, &iter))
1748 path = gtk_tree_model_get_path (model, &iter);
1749 gtk_tree_model_row_changed (model, path, &iter);
1750 gtk_tree_path_free (path);
1755 accounts_dialog_presence_changed_cb (TpAccount *account,
1758 gchar *status_message,
1759 EmpathyAccountsDialog *dialog)
1761 /* Update the status-infobar in the details view */
1762 accounts_dialog_update_status_infobar (dialog, account);
1764 update_account_in_treeview (dialog, account);
1768 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1772 const gchar *display_name;
1774 GtkTreeModel *model;
1775 EmpathyAccountSettings *settings;
1776 TpAccount *selected_account;
1777 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1778 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1780 display_name = tp_account_get_display_name (account);
1781 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1782 settings = accounts_dialog_model_get_selected_settings (dialog);
1783 if (settings == NULL)
1786 selected_account = empathy_account_settings_get_account (settings);
1788 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1790 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1791 COL_NAME, display_name,
1795 if (selected_account == account)
1796 accounts_dialog_update_name_label (dialog, display_name);
1798 g_object_unref (settings);
1802 conn_prepare_cb (GObject *source,
1803 GAsyncResult *result,
1806 EmpathyAccountsDialog *self = user_data;
1808 reload_account_widget (self);
1812 accounts_dialog_notify_connection_cb (TpAccount *account,
1814 EmpathyAccountsDialog *self)
1817 if (!account_is_selected (self, account))
1820 conn = tp_account_get_connection (account);
1823 reload_account_widget (self);
1827 /* Wait for this feature so TpConnection will have fetch the
1829 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1831 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1836 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1839 EmpathyAccountSettings *settings;
1840 GtkTreeModel *model;
1842 TpConnectionStatus status;
1844 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1845 gboolean selected = FALSE;
1846 GtkTreeSelection *selection;
1848 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1849 status = tp_account_get_connection_status (account, NULL);
1850 name = tp_account_get_display_name (account);
1852 settings = empathy_account_settings_new_for_account (account);
1854 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1856 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1858 /* Select the account if it's the first added */
1859 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1862 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1865 COL_ACCOUNT, account,
1866 COL_ACCOUNT_SETTINGS, settings,
1871 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1873 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1876 COL_ACCOUNT, account,
1877 COL_ACCOUNT_SETTINGS, settings,
1883 /* We just modified the selected account. Its display name may have been
1884 * changed and so it's place in the treeview. Scroll to it so it stays
1886 select_and_scroll_to_iter (dialog, &iter);
1889 accounts_dialog_connection_changed_cb (account,
1892 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1897 tp_g_signal_connect_object (account, "notify::display-name",
1898 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1901 tp_g_signal_connect_object (account, "status-changed",
1902 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1903 tp_g_signal_connect_object (account, "presence-changed",
1904 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1905 tp_g_signal_connect_object (account, "notify::connection",
1906 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
1908 g_object_unref (settings);
1912 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1915 EmpathyAccountsDialog *dialog)
1917 accounts_dialog_add_account (dialog, account);
1921 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1924 EmpathyAccountsDialog *dialog)
1926 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1928 if (priv->setting_widget != NULL &&
1929 accounts_dialog_has_valid_accounts (dialog))
1931 empathy_account_widget_set_other_accounts_exist (
1932 priv->setting_widget, TRUE);
1937 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1939 EmpathyAccountsDialog *dialog)
1941 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1943 if (priv->setting_widget != NULL &&
1944 !accounts_dialog_has_valid_accounts (dialog))
1946 empathy_account_widget_set_other_accounts_exist (
1947 priv->setting_widget, FALSE);
1952 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1954 EmpathyAccountsDialog *dialog)
1957 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1959 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1961 gtk_list_store_remove (GTK_LIST_STORE (
1962 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1967 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1971 /* Update the status-infobar in the details view */
1972 accounts_dialog_update_status_infobar (dialog, account);
1974 DEBUG ("Account %s is now %s",
1975 tp_account_get_display_name (account),
1976 enabled ? "enabled" : "disabled");
1980 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1982 EmpathyAccountsDialog *dialog)
1984 enable_or_disable_account (dialog, account, FALSE);
1985 update_account_in_treeview (dialog, account);
1989 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1991 EmpathyAccountsDialog *dialog)
1993 enable_or_disable_account (dialog, account, TRUE);
1997 display_import_dialog (EmpathyAccountsDialog *dialog)
1999 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2000 GtkWidget *import_dialog;
2002 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2004 gtk_widget_show (import_dialog);
2006 return import_dialog;
2010 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2011 EmpathyAccountsDialog *dialog)
2013 display_import_dialog (dialog);
2017 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2021 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2023 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2025 if (response_id == GTK_RESPONSE_YES)
2026 gtk_widget_destroy (account_dialog);
2030 accounts_dialog_delete_event_cb (GtkWidget *widget,
2032 EmpathyAccountsDialog *dialog)
2034 /* we maunally handle responses to delete events */
2039 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2044 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2045 select_and_scroll_to_iter (dialog, &iter);
2049 salut_valid_cb (GtkWidget *widget,
2053 gtk_widget_set_sensitive (button, valid);
2057 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2059 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2060 GtkWidget *dialog, *widget, *content, *button;
2063 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2064 priv->account_manager))
2067 widget = empathy_local_xmpp_assistant_widget_new ();
2068 gtk_widget_show (widget);
2070 dialog = gtk_dialog_new ();
2072 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2074 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2077 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2078 _("_Connect"), GTK_RESPONSE_YES);
2079 gtk_widget_set_sensitive (button,
2080 empathy_local_xmpp_assistant_widget_is_valid (
2081 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2083 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2086 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2087 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2089 response = gtk_dialog_run (GTK_DIALOG (dialog));
2091 if (response == GTK_RESPONSE_YES)
2093 empathy_local_xmpp_assistant_widget_create_account (
2094 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2097 gtk_widget_destroy (dialog);
2101 import_dialog_response_cb (GtkDialog *dialog,
2103 EmpathyAccountsDialog *self)
2105 maybe_show_salut_dialog (self);
2109 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2111 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2114 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2117 if (!empathy_import_accounts_to_import ())
2119 maybe_show_salut_dialog (self);
2123 dialog = display_import_dialog (self);
2125 tp_g_signal_connect_object (dialog, "response",
2126 G_CALLBACK (import_dialog_response_cb), self, 0);
2130 finished_loading (EmpathyAccountsDialog *self)
2132 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2133 GtkTreeSelection *selection;
2134 gboolean has_selected;
2136 priv->loading = FALSE;
2138 gtk_widget_set_sensitive (priv->button_add, TRUE);
2139 gtk_widget_set_sensitive (priv->button_import, TRUE);
2140 gtk_widget_set_sensitive (priv->treeview, TRUE);
2142 /* Sensitive the remove button if there is an account selected */
2143 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2144 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2145 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2147 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2148 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2149 NOTEBOOK_PAGE_ACCOUNT);
2151 maybe_show_import_dialog (self);
2155 accounts_dialog_cms_prepare_cb (GObject *source,
2156 GAsyncResult *result,
2159 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2160 EmpathyAccountsDialog *dialog = user_data;
2161 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2163 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2166 /* No need to update the settings if we are already preparing one */
2167 if (priv->settings_ready == NULL)
2168 accounts_dialog_update_settings (dialog, NULL);
2170 if (priv->initial_selection != NULL)
2172 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2173 g_object_unref (priv->initial_selection);
2174 priv->initial_selection = NULL;
2178 finished_loading (dialog);
2182 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2184 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2185 GList *accounts, *l;
2187 g_signal_connect (priv->account_manager, "account-validity-changed",
2188 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2190 g_signal_connect (priv->account_manager, "account-removed",
2191 G_CALLBACK (accounts_dialog_account_removed_cb),
2193 g_signal_connect (priv->account_manager, "account-enabled",
2194 G_CALLBACK (accounts_dialog_account_enabled_cb),
2196 g_signal_connect (priv->account_manager, "account-disabled",
2197 G_CALLBACK (accounts_dialog_account_disabled_cb),
2200 /* Add existing accounts */
2201 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2202 for (l = accounts; l; l = l->next)
2204 accounts_dialog_add_account (dialog, l->data);
2206 g_list_free (accounts);
2208 priv->cms = empathy_connection_managers_dup_singleton ();
2210 empathy_connection_managers_prepare_async (priv->cms,
2211 accounts_dialog_cms_prepare_cb, dialog);
2213 accounts_dialog_model_select_first (dialog);
2217 accounts_dialog_manager_ready_cb (GObject *source_object,
2218 GAsyncResult *result,
2221 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2222 GError *error = NULL;
2224 if (!tp_proxy_prepare_finish (manager, result, &error))
2226 DEBUG ("Failed to prepare account manager: %s", error->message);
2227 g_error_free (error);
2231 accounts_dialog_accounts_setup (user_data);
2235 dialog_response_cb (GtkWidget *widget,
2239 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2241 if (response_id == GTK_RESPONSE_HELP)
2243 empathy_url_show (widget, "help:empathy/accounts-window");
2245 else if (response_id == GTK_RESPONSE_CLOSE ||
2246 response_id == GTK_RESPONSE_DELETE_EVENT)
2248 TpAccount *account = NULL;
2250 if (accounts_dialog_has_pending_change (dialog, &account))
2252 gchar *question_dialog_primary_text = get_dialog_primary_text (
2255 accounts_dialog_show_question_dialog (dialog,
2256 question_dialog_primary_text,
2257 _("You are about to close the window, which will discard\n"
2258 "your changes. Are you sure you want to proceed?"),
2259 G_CALLBACK (accounts_dialog_close_response_cb),
2261 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2262 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2264 g_free (question_dialog_primary_text);
2268 gtk_widget_destroy (widget);
2271 if (account != NULL)
2272 g_object_unref (account);
2277 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2279 GtkWidget *top_hbox;
2282 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2283 GtkWidget *content_area, *action_area;
2284 GtkWidget *grid, *hbox;
2286 GtkWidget *sw, *toolbar;
2287 GtkStyleContext *context;
2289 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2291 gui = empathy_builder_get_file (filename,
2292 "accounts_dialog_hbox", &top_hbox,
2293 "vbox_details", &priv->vbox_details,
2294 "alignment_settings", &priv->alignment_settings,
2295 "alignment_infobar", &priv->alignment_infobar,
2296 "treeview", &priv->treeview,
2297 "button_add", &priv->button_add,
2298 "button_remove", &priv->button_remove,
2299 "button_import", &priv->button_import,
2300 "notebook_account", &priv->notebook_account,
2301 "alignment_loading", &alig,
2303 "add_remove_toolbar", &toolbar,
2307 empathy_builder_connect (gui, dialog,
2308 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2309 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2310 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2311 "treeview", "button-press-event",
2312 accounts_dialog_treeview_button_press_event_cb,
2315 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2317 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2319 g_object_unref (gui);
2321 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2323 /* Display loading page */
2324 priv->loading = TRUE;
2326 priv->spinner = gtk_spinner_new ();
2328 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2329 gtk_widget_show (priv->spinner);
2331 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2333 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2334 NOTEBOOK_PAGE_LOADING);
2336 /* Remove button is insensitive until we have a selected account */
2337 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2339 /* Add and Import buttons and treeview are insensitive while the dialog
2341 gtk_widget_set_sensitive (priv->button_add, FALSE);
2342 gtk_widget_set_sensitive (priv->button_import, FALSE);
2343 gtk_widget_set_sensitive (priv->treeview, FALSE);
2345 if (priv->parent_window)
2346 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2347 priv->parent_window);
2349 priv->infobar = gtk_info_bar_new ();
2350 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2352 gtk_widget_show (priv->infobar);
2354 grid = gtk_grid_new ();
2355 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2357 GTK_CONTAINER (gtk_info_bar_get_content_area (
2358 GTK_INFO_BAR (priv->infobar))),
2361 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2362 GTK_ICON_SIZE_DIALOG);
2363 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2364 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2367 priv->label_name = gtk_label_new (NULL);
2368 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2371 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2372 gtk_widget_set_hexpand (hbox, TRUE);
2373 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2374 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2376 /* set up spinner */
2377 priv->throbber = gtk_spinner_new ();
2379 priv->image_status = gtk_image_new_from_icon_name (
2380 empathy_icon_name_for_presence (
2381 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2383 priv->label_status = gtk_label_new (NULL);
2384 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2386 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2387 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2388 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2390 /* enabled switch */
2391 priv->enabled_switch = gtk_switch_new ();
2392 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2393 g_signal_connect (priv->enabled_switch, "notify::active",
2394 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2395 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2397 gtk_widget_show_all (grid);
2399 /* Tweak the dialog */
2400 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2401 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2403 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2405 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2407 /* join the add/remove toolbar to the treeview */
2408 context = gtk_widget_get_style_context (sw);
2409 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2411 context = gtk_widget_get_style_context (toolbar);
2412 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2414 /* add dialog buttons */
2415 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2417 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2418 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2419 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2422 g_signal_connect (dialog, "response",
2423 G_CALLBACK (dialog_response_cb), dialog);
2425 g_signal_connect (dialog, "delete-event",
2426 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2430 do_dispose (GObject *obj)
2432 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2435 if (priv->user_info != NULL)
2437 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
2439 priv->user_info = NULL;
2442 if (priv->connecting_id != 0)
2444 g_source_remove (priv->connecting_id);
2445 priv->connecting_id = 0;
2448 if (priv->connectivity)
2450 g_object_unref (priv->connectivity);
2451 priv->connectivity = NULL;
2454 if (priv->account_manager != NULL)
2456 g_object_unref (priv->account_manager);
2457 priv->account_manager = NULL;
2460 if (priv->cms != NULL)
2462 g_object_unref (priv->cms);
2466 if (priv->initial_selection != NULL)
2468 g_object_unref (priv->initial_selection);
2469 priv->initial_selection = NULL;
2472 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2476 do_get_property (GObject *object,
2481 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2483 switch (property_id)
2486 g_value_set_object (value, priv->parent_window);
2489 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2494 do_set_property (GObject *object,
2496 const GValue *value,
2499 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2501 switch (property_id)
2504 priv->parent_window = g_value_get_object (value);
2507 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2512 do_constructed (GObject *object)
2514 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2515 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2516 GtkTreeModel *model;
2518 accounts_dialog_build_ui (dialog);
2519 accounts_dialog_model_setup (dialog);
2521 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2522 g_signal_connect (model, "row-inserted",
2523 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2524 g_signal_connect (model, "row-deleted",
2525 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2527 /* Set up signalling */
2528 priv->account_manager = tp_account_manager_dup ();
2530 tp_proxy_prepare_async (priv->account_manager, NULL,
2531 accounts_dialog_manager_ready_cb, dialog);
2533 priv->connectivity = g_network_monitor_get_default ();
2534 g_object_ref (priv->connectivity);
2538 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2540 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2541 GParamSpec *param_spec;
2543 oclass->dispose = do_dispose;
2544 oclass->constructed = do_constructed;
2545 oclass->set_property = do_set_property;
2546 oclass->get_property = do_get_property;
2548 param_spec = g_param_spec_object ("parent",
2549 "parent", "The parent window",
2551 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2552 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2554 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2558 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2560 EmpathyAccountsDialogPriv *priv;
2562 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2563 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2564 EmpathyAccountsDialogPriv);
2565 dialog->priv = priv;
2568 /* public methods */
2571 empathy_accounts_dialog_show (GtkWindow *parent,
2572 TpAccount *selected_account)
2574 EmpathyAccountsDialog *dialog;
2575 EmpathyAccountsDialogPriv *priv;
2577 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2578 "parent", parent, NULL);
2580 priv = GET_PRIV (dialog);
2582 if (selected_account)
2584 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2585 accounts_dialog_set_selected_account (dialog, selected_account);
2587 /* save the selection to set it later when the cms
2590 priv->initial_selection = g_object_ref (selected_account);
2593 gtk_window_present (GTK_WINDOW (dialog));
2595 return GTK_WIDGET (dialog);
2605 static LaunchUOACtx *
2606 launch_uoa_ctx_new (TpAccount *account,
2611 ctx = g_slice_new0 (LaunchUOACtx);
2612 if (account != NULL)
2613 ctx->account = g_object_ref (account);
2614 ctx->if_needed = if_needed;
2620 launch_uoa_ctx_free (LaunchUOACtx *ctx)
2622 g_clear_object (&ctx->account);
2623 g_slice_free (LaunchUOACtx, ctx);
2627 am_prepare_cb (GObject *source,
2628 GAsyncResult *result,
2631 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
2632 GError *error = NULL;
2633 LaunchUOACtx *ctx = user_data;
2636 if (!tp_proxy_prepare_finish (manager, result, &error))
2638 DEBUG ("Failed to prepare account manager: %s", error->message);
2639 g_error_free (error);
2643 if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
2646 if (ctx->account != NULL)
2648 const GValue *value;
2650 value = tp_account_get_storage_identifier (ctx->account);
2652 if (G_VALUE_HOLDS_UINT (value))
2653 args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
2656 empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
2660 launch_uoa_ctx_free (ctx);
2664 launch_uoa_panel (TpAccount *selected_account,
2668 TpAccountManager *manager;
2674 manager = tp_account_manager_dup ();
2676 tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
2677 launch_uoa_ctx_new (selected_account, if_needed));
2679 g_object_unref (manager);
2682 #else /* HAVE_UOA */
2685 launch_empathy_accounts (TpAccount *selected_account,
2691 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2693 args = g_string_new (NULL);
2695 if (selected_account != NULL)
2696 g_string_append_printf (args, " --select-account=%s",
2697 tp_account_get_path_suffix (selected_account));
2700 g_string_append_printf (args, " --if-needed");
2703 g_string_append_printf (args, " --hidden");
2705 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2707 selected_account == NULL ? "<none selected>" :
2708 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2710 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2712 g_string_free (args, TRUE);
2714 #endif /* HAVE_UOA */
2717 empathy_accounts_dialog_show_application (GdkScreen *screen,
2718 TpAccount *selected_account,
2723 launch_uoa_panel (selected_account, if_needed, hidden);
2725 launch_empathy_accounts (selected_account, if_needed, hidden);
2730 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2732 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2733 gboolean result = FALSE;
2735 if (priv->setting_widget == NULL)
2738 g_object_get (priv->setting_widget,
2739 "creating-account", &result, NULL);