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>
31 #include <tp-account-widgets/tpaw-account-widget.h>
33 #include "empathy-accounts-common.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 %.50s 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 TpawAccountWidget, 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 TpawAccountWidget. 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 TpawAccountWidget unrefs itself when the GtkWidget is destroyed.
105 * That's kinda ugly; cf bgo #640417.
108 TpawAccountWidget *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_status_infobar_set_message (EmpathyAccountsDialog *dialog,
180 const gchar *message)
182 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
183 gchar *message_markup;
185 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
186 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
188 gtk_widget_set_tooltip_text (priv->label_status, message);
190 g_free (message_markup);
194 accounts_dialog_enable_account_cb (GObject *object,
195 GAsyncResult *result,
198 TpAccount *account = TP_ACCOUNT (object);
199 gboolean enable = GPOINTER_TO_UINT (user_data);
200 GError *error = NULL;
201 TpAccountManager *am;
203 if (!tp_account_set_enabled_finish (account, result, &error))
205 DEBUG ("Could not enable the account: %s", error->message);
206 g_error_free (error);
210 /* tp_account_is_enabled() is not updated yet at this point */
213 am = tp_account_manager_dup ();
215 empathy_connect_new_account (account, am);
221 enable_and_connect_account (TpAccount *account,
224 tp_account_set_enabled_async (account, enable,
225 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
229 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
231 EmpathyAccountsDialog *dialog)
233 EmpathyAccountSettings *settings;
237 settings = accounts_dialog_model_get_selected_settings (dialog);
238 if (settings == NULL)
241 account = empathy_account_settings_get_account (settings);
245 enable = gtk_switch_get_active (sw);
247 enable_and_connect_account (account, enable);
251 install_haze_cb (GObject *source,
252 GAsyncResult *result,
255 GError *error = NULL;
257 if (!empathy_pkg_kit_install_packages_finish (result, &error))
259 DEBUG ("Failed to install telepathy-haze: %s", error->message);
261 g_error_free (error);
266 account_is_selected (EmpathyAccountsDialog *dialog,
269 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
270 GtkTreeSelection *selection;
273 TpAccount *selected_account;
278 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
280 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
283 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
285 if (selected_account != NULL)
286 g_object_unref (selected_account);
288 return account == selected_account;
292 account_can_be_enabled (TpAccount *account)
294 TpStorageRestrictionFlags storage_restrictions;
296 storage_restrictions = tp_account_get_storage_restrictions (account);
297 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
300 /* Butterfly accounts shouldn't be used any more */
301 if (!tp_strdiff (tp_account_get_cm_name (account),
309 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
312 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
313 gchar *status_message = NULL;
317 gboolean account_enabled;
318 gboolean creating_account;
319 gboolean display_switch = TRUE;
321 /* do not update the infobar when the account is not selected */
322 if (!account_is_selected (dialog, account))
329 status = tp_account_get_connection_status (account, &reason);
330 presence = tp_account_get_current_presence (account, NULL, &status_message);
331 account_enabled = tp_account_is_enabled (account);
332 creating_account = FALSE;
334 if (status == TP_CONNECTION_STATUS_CONNECTED &&
335 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
336 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
337 /* If presence is Unset (CM doesn't implement SimplePresence) but we
338 * are connected, consider ourself as Available.
339 * We also check Offline because of this MC5 bug: fd.o #26060 */
340 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
342 /* set presence to offline if account is disabled
343 * (else no icon is shown in infobar)*/
344 if (!account_enabled)
345 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
347 display_switch = account_can_be_enabled (account);
349 text = g_markup_printf_escaped ("<b>%.50s</b>",
350 tp_account_get_display_name (account));
351 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
356 status = TP_CONNECTION_STATUS_DISCONNECTED;
357 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
358 account_enabled = FALSE;
359 creating_account = TRUE;
362 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
363 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
365 /* update the enabled switch */
366 g_signal_handlers_block_by_func (priv->enabled_switch,
367 accounts_dialog_enable_switch_active_cb, dialog);
368 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
370 g_signal_handlers_unblock_by_func (priv->enabled_switch,
371 accounts_dialog_enable_switch_active_cb, dialog);
373 /* Display the Enable switch if account supports it */
374 gtk_widget_set_visible (priv->enabled_switch, display_switch);
380 case TP_CONNECTION_STATUS_CONNECTING:
381 accounts_dialog_status_infobar_set_message (dialog,
383 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
386 gtk_spinner_start (GTK_SPINNER (priv->throbber));
387 gtk_widget_show (priv->throbber);
388 gtk_widget_hide (priv->image_status);
390 case TP_CONNECTION_STATUS_CONNECTED:
391 if (g_strcmp0 (status_message, "") == 0)
395 message = g_strdup_printf ("%s",
396 empathy_presence_get_default_message (presence));
398 accounts_dialog_status_infobar_set_message (dialog, message);
405 message = g_strdup_printf ("%s — %s",
406 empathy_presence_get_default_message (presence),
409 accounts_dialog_status_infobar_set_message (dialog, message);
412 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
415 gtk_widget_show (priv->image_status);
416 gtk_widget_hide (priv->throbber);
418 case TP_CONNECTION_STATUS_DISCONNECTED:
419 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
423 message = g_strdup_printf (_("Offline — %s"),
424 empathy_account_get_error_message (account, NULL));
425 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
426 GTK_MESSAGE_WARNING);
428 accounts_dialog_status_infobar_set_message (dialog, message);
435 message = g_strdup_printf (_("Disconnected — %s"),
436 empathy_account_get_error_message (account, NULL));
437 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
440 accounts_dialog_status_infobar_set_message (dialog, message);
444 if (!g_network_monitor_get_network_available (priv->connectivity))
445 accounts_dialog_status_infobar_set_message (dialog,
446 _("Offline — No Network Connection"));
448 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
449 gtk_widget_show (priv->image_status);
450 gtk_widget_hide (priv->throbber);
453 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
454 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
455 GTK_MESSAGE_WARNING);
457 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
458 gtk_widget_hide (priv->image_status);
459 gtk_widget_hide (priv->throbber);
464 if (!tp_strdiff (tp_account_get_cm_name (account),
467 const gchar *packages[] = { "telepathy-haze", NULL };
469 accounts_dialog_status_infobar_set_message (dialog,
470 _("This account has been disabled because it relies on an old, "
471 "unsupported backend. Please install telepathy-haze and "
472 "restart your session to migrate the account."));
474 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
475 install_haze_cb, NULL);
479 accounts_dialog_status_infobar_set_message (dialog,
480 _("Offline — Account Disabled"));
483 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
484 GTK_MESSAGE_WARNING);
485 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
486 gtk_widget_show (priv->image_status);
487 gtk_widget_hide (priv->throbber);
490 gtk_widget_show (priv->label_status);
492 if (!creating_account)
493 gtk_widget_show (priv->infobar);
495 gtk_widget_hide (priv->infobar);
497 g_free (status_message);
501 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
505 GtkTreeSelection *selection;
507 EmpathyAccountSettings *settings;
509 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
511 view = GTK_TREE_VIEW (priv->treeview);
512 selection = gtk_tree_view_get_selection (view);
514 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
517 gtk_tree_model_get (model, &iter,
518 COL_ACCOUNT_SETTINGS, &settings,
519 COL_ACCOUNT, &account, -1);
521 tpaw_account_widget_discard_pending_changes (priv->setting_widget);
525 /* We were creating an account. We remove the selected row */
526 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
530 /* We were modifying an account. We discard the changes by reloading the
531 * settings and the UI. */
532 accounts_dialog_update_settings (dialog, settings);
533 g_object_unref (account);
536 gtk_widget_set_sensitive (priv->treeview, TRUE);
537 gtk_widget_set_sensitive (priv->button_add, TRUE);
538 gtk_widget_set_sensitive (priv->button_remove, TRUE);
539 gtk_widget_set_sensitive (priv->button_import, TRUE);
541 if (settings != NULL)
542 g_object_unref (settings);
546 empathy_account_dialog_widget_cancelled_cb (
547 TpawAccountWidget *widget_object,
548 EmpathyAccountsDialog *dialog)
550 empathy_account_dialog_cancel (dialog);
554 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
556 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
561 g_object_get (priv->setting_widget,
562 "creating-account", &creating, NULL);
567 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
569 if (gtk_tree_model_get_iter_first (model, &iter))
570 return gtk_tree_model_iter_next (model, &iter);
576 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
578 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
579 EmpathyAccountSettings *settings;
580 GtkWidget *subdialog, *content_area, *align;
582 settings = accounts_dialog_model_get_selected_settings (dialog);
583 if (settings == NULL)
586 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
588 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
591 gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
593 priv->setting_widget = (TpawAccountWidget *)
594 tpaw_account_widget_new_for_protocol (settings, FALSE);
596 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
597 (gpointer *) &priv->setting_widget);
599 if (accounts_dialog_has_valid_accounts (dialog))
600 tpaw_account_widget_set_other_accounts_exist (
601 priv->setting_widget, TRUE);
603 g_signal_connect (priv->setting_widget, "cancelled",
604 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
606 g_signal_connect_swapped (priv->setting_widget, "close",
607 G_CALLBACK (gtk_widget_destroy), subdialog);
609 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
611 align = gtk_alignment_new (0.5, 0.5, 1, 1);
612 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
614 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
615 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
617 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
618 gtk_widget_show (align);
619 gtk_widget_show (subdialog);
623 use_external_storage_provider (EmpathyAccountsDialog *self,
626 const gchar *provider;
628 provider = tp_account_get_storage_provider (account);
629 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
631 empathy_launch_external_app ("gnome-control-center.desktop",
632 "bisho.desktop", NULL);
635 else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
637 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
641 else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
643 empathy_launch_external_app ("gnome-credentials-panel.desktop",
649 DEBUG ("Don't know how to handle %s", provider);
655 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
658 EmpathyAccountSettings *settings;
660 TpStorageRestrictionFlags storage_restrictions;
662 settings = accounts_dialog_model_get_selected_settings (dialog);
663 if (settings == NULL)
666 account = empathy_account_settings_get_account (settings);
667 g_return_if_fail (account != NULL);
669 storage_restrictions = tp_account_get_storage_restrictions (account);
671 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
672 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
674 DEBUG ("Account is provided by an external storage provider");
676 use_external_storage_provider (dialog, account);
680 account_dialog_create_edit_params_dialog (dialog);
685 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
686 EmpathyAccountSettings *settings)
688 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
689 const gchar *icon_name;
691 GtkWidget *bbox, *button;
694 account = empathy_account_settings_get_account (settings);
696 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
697 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
698 priv->dialog_content);
699 gtk_widget_show (priv->dialog_content);
701 alig = gtk_alignment_new (0.5, 0, 1, 1);
702 priv->user_info = empathy_user_info_new (account);
703 gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
704 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
705 gtk_widget_show (alig);
706 gtk_widget_show (priv->user_info);
708 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
709 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
710 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
711 gtk_widget_show (bbox);
713 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
714 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
715 gtk_widget_show (button);
716 g_signal_connect_swapped (button, "clicked",
717 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
719 icon_name = empathy_account_settings_get_icon_name (settings);
721 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
723 /* show the default icon; keep this in sync with the default
724 * one in empathy-accounts-dialog.ui.
726 icon_name = GTK_STOCK_CUT;
728 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
729 icon_name, GTK_ICON_SIZE_DIALOG);
730 gtk_widget_set_tooltip_text (priv->image_type,
731 empathy_protocol_name_to_display_name
732 (empathy_account_settings_get_protocol (settings)));
733 gtk_widget_show (priv->image_type);
735 accounts_dialog_update_status_infobar (dialog, account);
739 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
741 EmpathyAccountsDialog *dialog)
743 if (empathy_account_settings_is_ready (settings))
744 account_dialog_create_dialog_content (dialog, settings);
748 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
752 GtkTreeSelection *selection;
754 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
757 view = GTK_TREE_VIEW (priv->treeview);
758 model = gtk_tree_view_get_model (view);
760 if (gtk_tree_model_get_iter_first (model, &iter))
762 selection = gtk_tree_view_get_selection (view);
763 gtk_tree_selection_select_iter (selection, &iter);
767 accounts_dialog_update_settings (dialog, NULL);
772 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
777 GtkTreeSelection *selection;
778 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
780 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
782 if (gtk_tree_selection_get_selected (selection, &model, &iter))
783 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
785 return priv->setting_widget != NULL
786 && tpaw_account_widget_contains_pending_changes (
787 priv->setting_widget);
791 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
792 const gchar *primary_text,
793 const gchar *secondary_text,
794 GCallback response_callback,
796 const gchar *first_button_text,
800 GtkWidget *message_dialog;
801 const gchar *button_text;
803 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
804 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
805 GTK_MESSAGE_QUESTION,
809 gtk_message_dialog_format_secondary_text (
810 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
812 va_start (button_args, first_button_text);
813 for (button_text = first_button_text;
815 button_text = va_arg (button_args, const gchar *))
818 response_id = va_arg (button_args, gint);
820 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
823 va_end (button_args);
825 g_signal_connect (message_dialog, "response", response_callback, user_data);
827 gtk_widget_show (message_dialog);
831 get_dialog_primary_text (TpAccount *account)
835 /* Existing account */
836 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
837 tp_account_get_display_name (account));
841 /* Newly created account */
842 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
847 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
848 EmpathyAccountsDialog *self)
853 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
854 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
856 response = gtk_dialog_run (GTK_DIALOG (dialog));
858 if (response == GTK_RESPONSE_APPLY)
860 EmpathyAccountSettings *settings;
863 settings = empathy_new_account_dialog_get_settings (
864 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
866 /* The newly created account has already been added by
867 * accounts_dialog_account_validity_changed_cb so we just
868 * have to select it. */
869 account = empathy_account_settings_get_account (settings);
870 accounts_dialog_model_set_selected (self, account);
873 gtk_widget_destroy (dialog);
877 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
878 EmpathyAccountSettings *settings)
880 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
882 if (priv->settings_ready != NULL)
884 g_signal_handler_disconnect (priv->settings_ready,
885 priv->settings_ready_id);
886 priv->settings_ready = NULL;
887 priv->settings_ready_id = 0;
894 GtkTreeSelection *selection;
896 view = GTK_TREE_VIEW (priv->treeview);
897 model = gtk_tree_view_get_model (view);
898 selection = gtk_tree_view_get_selection (view);
900 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
902 /* We have configured accounts, select the first one if there
903 * is no other account selected already. */
904 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
905 accounts_dialog_model_select_first (dialog);
910 /* No account selected */
911 gtk_widget_hide (priv->vbox_details);
912 gtk_widget_set_sensitive (priv->button_add, TRUE);
913 gtk_widget_set_sensitive (priv->button_remove, FALSE);
915 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
916 NOTEBOOK_PAGE_NO_PROTOCOL);
920 /* We have an account selected, destroy old settings and create a new
921 * one for the account selected */
922 gtk_widget_show (priv->vbox_details);
924 if (priv->user_info != NULL)
926 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
928 priv->user_info = NULL;
930 if (priv->dialog_content)
932 gtk_widget_destroy (priv->dialog_content);
933 priv->dialog_content = NULL;
936 if (empathy_account_settings_is_ready (settings))
938 account_dialog_create_dialog_content (dialog, settings);
942 priv->settings_ready = settings;
943 priv->settings_ready_id =
944 g_signal_connect (settings, "notify::ready",
945 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
951 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
952 GtkCellEditable *editable,
954 EmpathyAccountsDialog *dialog)
956 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
958 if (priv->connecting_id)
959 g_source_remove (priv->connecting_id);
961 DEBUG ("Editing account name started; stopping flashing");
965 get_status_icon_for_account (EmpathyAccountsDialog *self,
968 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
969 TpConnectionStatus status;
970 TpConnectionStatusReason reason;
971 TpConnectionPresenceType presence;
974 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
976 if (!tp_account_is_enabled (account))
977 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
979 status = tp_account_get_connection_status (account, &reason);
981 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
983 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
984 /* An error occured */
985 return GTK_STOCK_DIALOG_ERROR;
987 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
989 else if (status == TP_CONNECTION_STATUS_CONNECTING)
991 /* Account is connecting. Display a blinking account alternating between
992 * the offline icon and the requested presence. */
993 if (priv->connecting_show)
994 presence = tp_account_get_requested_presence (account, NULL, NULL);
996 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1000 /* status == TP_CONNECTION_STATUS_CONNECTED */
1001 presence = tp_account_get_current_presence (account, NULL, NULL);
1003 /* If presence is Unset (CM doesn't implement SimplePresence),
1004 * display the 'available' icon.
1005 * We also check Offline because of this MC5 bug: fd.o #26060 */
1006 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1007 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1008 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1011 return empathy_icon_name_for_presence (presence);
1015 ensure_icon (EmpathyAccountsDialog *self,
1016 const gchar *icon_name)
1018 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1021 pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
1024 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1029 g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
1033 return g_object_ref (pixbuf);
1037 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1038 GtkCellRenderer *cell,
1039 GtkTreeModel *model,
1041 EmpathyAccountsDialog *dialog)
1044 const gchar *icon_name;
1047 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1049 icon_name = get_status_icon_for_account (dialog, account);
1050 pixbuf = ensure_icon (dialog, icon_name);
1056 if (account != NULL)
1057 g_object_unref (account);
1060 g_object_unref (pixbuf);
1064 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1065 GtkCellRenderer *cell,
1066 GtkTreeModel *model,
1068 EmpathyAccountsDialog *dialog)
1070 EmpathyAccountSettings *settings;
1073 TpConnectionStatus status;
1075 gtk_tree_model_get (model, iter,
1076 COL_STATUS, &status,
1077 COL_ACCOUNT_SETTINGS, &settings,
1080 icon_name = empathy_account_settings_get_icon_name (settings);
1081 pixbuf = ensure_icon (dialog, icon_name);
1088 g_object_unref (settings);
1091 g_object_unref (pixbuf);
1095 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1102 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1104 if (account == NULL)
1107 if (tp_account_get_connection_status (account, NULL) ==
1108 TP_CONNECTION_STATUS_CONNECTING)
1110 /* Only update the row where we have a connecting account as that's the
1111 * ones having a blinking icon. */
1112 gtk_tree_model_row_changed (model, path, iter);
1115 g_object_unref (account);
1120 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1123 GtkTreeModel *model;
1124 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1126 priv->connecting_show = !priv->connecting_show;
1128 view = GTK_TREE_VIEW (priv->treeview);
1129 model = gtk_tree_view_get_model (view);
1131 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1137 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1140 EmpathyAccountsDialog *dialog)
1142 EmpathyAccountSettings *settings;
1143 GtkTreeModel *model;
1144 GtkTreePath *treepath;
1146 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1147 gboolean connecting;
1149 empathy_account_manager_get_accounts_connected (&connecting);
1153 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1154 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1158 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1159 treepath = gtk_tree_path_new_from_string (path);
1160 gtk_tree_model_get_iter (model, &iter, treepath);
1161 gtk_tree_model_get (model, &iter,
1162 COL_ACCOUNT_SETTINGS, &settings,
1164 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1167 gtk_tree_path_free (treepath);
1169 empathy_account_settings_set_display_name_async (settings, new_text,
1171 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1172 g_object_unref (settings);
1176 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1181 GtkTreeModel *model;
1183 GtkTreeSelection *selection;
1184 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1185 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1187 if (response_id == GTK_RESPONSE_YES)
1189 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1191 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1194 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1196 if (account != NULL)
1198 tp_account_remove_async (account, NULL, NULL);
1199 g_object_unref (account);
1203 /* No need to call accounts_dialog_model_selection_changed while
1204 * removing as we are going to call accounts_dialog_model_select_first
1205 * right after which will update the selection. */
1206 g_signal_handlers_block_by_func (selection,
1207 accounts_dialog_model_selection_changed, account_dialog);
1209 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1211 g_signal_handlers_unblock_by_func (selection,
1212 accounts_dialog_model_selection_changed, account_dialog);
1214 accounts_dialog_model_select_first (account_dialog);
1217 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1221 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1224 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1226 GtkTreeModel *model;
1227 gchar *question_dialog_primary_text;
1229 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1231 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1233 if (account == NULL || !tp_account_is_valid (account))
1235 if (account != NULL)
1236 g_object_unref (account);
1237 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1238 accounts_dialog_model_select_first (dialog);
1242 question_dialog_primary_text = g_strdup_printf (
1243 _("Do you want to remove %.50s from your computer?"),
1244 tp_account_get_display_name (account));
1246 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1247 _("This will not remove your account on the server."),
1248 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1250 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1251 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1253 g_free (question_dialog_primary_text);
1254 g_object_unref (account);
1258 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1259 EmpathyAccountsDialog *dialog)
1261 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1263 GtkTreeSelection *selection;
1266 view = GTK_TREE_VIEW (priv->treeview);
1267 selection = gtk_tree_view_get_selection (view);
1268 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1271 accounts_dialog_remove_account_iter (dialog, &iter);
1275 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1278 GtkTreeViewColumn *column;
1279 GtkCellRenderer *cell;
1280 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1282 view = GTK_TREE_VIEW (priv->treeview);
1283 gtk_tree_view_set_headers_visible (view, FALSE);
1285 /* Account column */
1286 column = gtk_tree_view_column_new ();
1287 gtk_tree_view_column_set_expand (column, TRUE);
1288 gtk_tree_view_append_column (view, column);
1290 /* Status icon renderer */
1291 cell = gtk_cell_renderer_pixbuf_new ();
1292 gtk_tree_view_column_pack_start (column, cell, FALSE);
1293 gtk_tree_view_column_set_cell_data_func (column, cell,
1294 (GtkTreeCellDataFunc)
1295 accounts_dialog_model_status_pixbuf_data_func,
1299 /* Protocol 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_protocol_pixbuf_data_func,
1309 priv->name_renderer = gtk_cell_renderer_text_new ();
1310 g_object_set (priv->name_renderer,
1311 "ellipsize", PANGO_ELLIPSIZE_END,
1315 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1316 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1318 g_signal_connect (priv->name_renderer, "edited",
1319 G_CALLBACK (accounts_dialog_name_edited_cb),
1321 g_signal_connect (priv->name_renderer, "editing-started",
1322 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1324 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1327 static EmpathyAccountSettings *
1328 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1331 GtkTreeModel *model;
1332 GtkTreeSelection *selection;
1334 EmpathyAccountSettings *settings;
1335 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1337 view = GTK_TREE_VIEW (priv->treeview);
1338 selection = gtk_tree_view_get_selection (view);
1340 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1343 gtk_tree_model_get (model, &iter,
1344 COL_ACCOUNT_SETTINGS, &settings, -1);
1350 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1351 EmpathyAccountsDialog *dialog)
1353 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1354 EmpathyAccountSettings *settings;
1355 GtkTreeModel *model;
1357 gboolean is_selection;
1358 gboolean creating = FALSE;
1360 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1362 settings = accounts_dialog_model_get_selected_settings (dialog);
1363 accounts_dialog_update_settings (dialog, settings);
1365 if (settings != NULL)
1366 g_object_unref (settings);
1368 if (priv->setting_widget != NULL)
1370 g_object_get (priv->setting_widget,
1371 "creating-account", &creating, NULL);
1374 /* Update remove button sensitivity */
1375 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1380 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1382 gpointer *user_data)
1384 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1385 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1387 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1389 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1391 /* The user wants to lose unsaved changes to the currently selected
1392 * account and select another account. We discard the changes and
1393 * select the other account. */
1395 GtkTreeSelection *selection;
1397 priv->force_change_row = TRUE;
1398 tpaw_account_widget_discard_pending_changes (
1399 priv->setting_widget);
1401 path = gtk_tree_row_reference_get_path (priv->destination_row);
1402 selection = gtk_tree_view_get_selection (
1403 GTK_TREE_VIEW (priv->treeview));
1407 /* This will trigger a call to
1408 * accounts_dialog_account_selection_change() */
1409 gtk_tree_selection_select_path (selection, path);
1410 gtk_tree_path_free (path);
1413 gtk_tree_row_reference_free (priv->destination_row);
1417 priv->force_change_row = FALSE;
1422 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1423 GtkTreeModel *model,
1425 gboolean path_currently_selected,
1428 TpAccount *account = NULL;
1429 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1430 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1433 if (priv->force_change_row)
1435 /* We came back here because the user wants to discard changes to his
1436 * modified account. The changes have already been discarded so we
1437 * just change the selected row. */
1438 priv->force_change_row = FALSE;
1442 if (accounts_dialog_has_pending_change (dialog, &account))
1444 /* The currently selected account has some unsaved changes. We ask
1445 * the user if he really wants to lose his changes and select another
1447 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1448 priv->destination_row = gtk_tree_row_reference_new (model, path);
1450 accounts_dialog_show_question_dialog (dialog,
1451 question_dialog_primary_text,
1452 _("You are about to select another account, which will discard\n"
1453 "your changes. Are you sure you want to proceed?"),
1454 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1456 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1457 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1459 g_free (question_dialog_primary_text);
1467 if (account != NULL)
1468 g_object_unref (account);
1474 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1476 GtkListStore *store;
1477 GtkTreeSelection *selection;
1478 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1480 store = gtk_list_store_new (COL_COUNT,
1481 G_TYPE_STRING, /* name */
1482 G_TYPE_UINT, /* status */
1483 TP_TYPE_ACCOUNT, /* account */
1484 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1486 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1487 GTK_TREE_MODEL (store));
1489 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1490 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1491 gtk_tree_selection_set_select_function (selection,
1492 accounts_dialog_account_selection_change, dialog, NULL);
1494 g_signal_connect (selection, "changed",
1495 G_CALLBACK (accounts_dialog_model_selection_changed),
1498 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1499 COL_NAME, GTK_SORT_ASCENDING);
1501 accounts_dialog_model_add_columns (dialog);
1503 g_object_unref (store);
1507 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1512 GtkTreeModel *model;
1514 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1516 /* Update the status in the model */
1517 view = GTK_TREE_VIEW (priv->treeview);
1518 model = gtk_tree_view_get_model (view);
1520 for (ok = gtk_tree_model_get_iter_first (model, iter);
1522 ok = gtk_tree_model_iter_next (model, iter))
1524 TpAccount *this_account;
1527 gtk_tree_model_get (model, iter,
1528 COL_ACCOUNT, &this_account,
1531 equal = (this_account == account);
1532 g_object_unref (this_account);
1542 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1545 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1546 GtkTreeSelection *selection;
1548 GtkTreeModel *model;
1550 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1552 gtk_tree_selection_select_iter (selection, iter);
1554 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1555 path = gtk_tree_model_get_path (model, iter);
1557 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1560 gtk_tree_path_free (path);
1564 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1569 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1570 select_and_scroll_to_iter (dialog, &iter);
1574 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1579 enabled = tp_account_is_enabled (account);
1581 enable_and_connect_account (account, !enabled);
1585 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1586 EmpathyAccountsDialog *self)
1588 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1591 GtkTreeSelection *selection;
1592 GtkTreeModel *model;
1594 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1595 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1597 path = gtk_tree_model_get_path (model, &iter);
1599 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1601 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1602 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1603 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1605 gtk_tree_path_free (path);
1609 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1610 GdkEventButton *event,
1611 EmpathyAccountsDialog *dialog)
1613 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1614 TpAccount *account = NULL;
1615 GtkTreeModel *model = NULL;
1616 GtkTreePath *path = NULL;
1621 /* ignore multiple clicks */
1622 if (event->type != GDK_BUTTON_PRESS)
1625 if (event->button != 3)
1628 /* Selection is not yet set, so we have to get account from event position */
1629 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1630 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1631 event->x, event->y, &path, NULL, NULL, NULL))
1634 if (!gtk_tree_model_get_iter (model, &iter, path))
1637 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1639 /* Create the menu */
1640 menu = empathy_context_menu_new (GTK_WIDGET (view));
1642 /* Menu item: to enabled/disable the account */
1643 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1645 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1647 if (account_can_be_enabled (account))
1651 active = tp_account_is_enabled (account);
1652 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1655 tp_g_signal_connect_object (item, "activate",
1656 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1660 gtk_widget_set_sensitive (item, FALSE);
1663 gtk_widget_show (item);
1665 /* Menu item: Rename */
1666 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1667 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1669 tp_g_signal_connect_object (item, "activate",
1670 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1672 gtk_widget_show (item);
1674 /* FIXME: Add here presence items, to be able to set per-account presence */
1677 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1678 event->button, event->time);
1681 tp_clear_object (&account);
1682 gtk_tree_path_free (path);
1688 reload_account_widget (EmpathyAccountsDialog *self)
1690 EmpathyAccountSettings *settings;
1692 settings = accounts_dialog_model_get_selected_settings (self);
1693 accounts_dialog_update_settings (self, settings);
1697 accounts_dialog_connection_changed_cb (TpAccount *account,
1701 gchar *dbus_error_name,
1702 GHashTable *details,
1703 EmpathyAccountsDialog *dialog)
1705 GtkTreeModel *model;
1708 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1710 /* Update the status-infobar in the details view */
1711 accounts_dialog_update_status_infobar (dialog, account);
1713 /* Update the status in the model */
1714 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1716 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1720 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1721 COL_STATUS, current,
1724 path = gtk_tree_model_get_path (model, &iter);
1725 gtk_tree_model_row_changed (model, path, &iter);
1726 gtk_tree_path_free (path);
1729 empathy_account_manager_get_accounts_connected (&found);
1731 if (!found && priv->connecting_id)
1733 g_source_remove (priv->connecting_id);
1734 priv->connecting_id = 0;
1737 if (found && !priv->connecting_id)
1738 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1739 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1744 update_account_in_treeview (EmpathyAccountsDialog *self,
1747 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1749 GtkTreeModel *model;
1751 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1752 if (accounts_dialog_get_account_iter (self, account, &iter))
1756 path = gtk_tree_model_get_path (model, &iter);
1757 gtk_tree_model_row_changed (model, path, &iter);
1758 gtk_tree_path_free (path);
1763 accounts_dialog_presence_changed_cb (TpAccount *account,
1766 gchar *status_message,
1767 EmpathyAccountsDialog *dialog)
1769 /* Update the status-infobar in the details view */
1770 accounts_dialog_update_status_infobar (dialog, account);
1772 update_account_in_treeview (dialog, account);
1776 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1778 EmpathyAccountsDialog *dialog)
1780 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1781 GtkTreeModel *model;
1784 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1785 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1787 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1788 COL_NAME, tp_account_get_display_name (account),
1792 accounts_dialog_update_status_infobar (dialog, account);
1796 conn_prepare_cb (GObject *source,
1797 GAsyncResult *result,
1800 EmpathyAccountsDialog *self = user_data;
1802 reload_account_widget (self);
1806 accounts_dialog_notify_connection_cb (TpAccount *account,
1808 EmpathyAccountsDialog *self)
1811 if (!account_is_selected (self, account))
1814 conn = tp_account_get_connection (account);
1817 reload_account_widget (self);
1821 /* Wait for this feature so TpConnection will have fetch the
1823 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1825 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1830 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1833 EmpathyAccountSettings *settings;
1834 GtkTreeModel *model;
1836 TpConnectionStatus status;
1838 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1839 gboolean selected = FALSE;
1840 GtkTreeSelection *selection;
1842 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1843 status = tp_account_get_connection_status (account, NULL);
1844 name = tp_account_get_display_name (account);
1846 settings = empathy_account_settings_new_for_account (account);
1848 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1850 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1852 /* Select the account if it's the first added */
1853 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1856 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1859 COL_ACCOUNT, account,
1860 COL_ACCOUNT_SETTINGS, settings,
1865 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1867 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1870 COL_ACCOUNT, account,
1871 COL_ACCOUNT_SETTINGS, settings,
1877 /* We just modified the selected account. Its display name may have been
1878 * changed and so it's place in the treeview. Scroll to it so it stays
1880 select_and_scroll_to_iter (dialog, &iter);
1883 accounts_dialog_connection_changed_cb (account,
1886 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1891 tp_g_signal_connect_object (account, "notify::display-name",
1892 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1895 tp_g_signal_connect_object (account, "status-changed",
1896 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1897 tp_g_signal_connect_object (account, "presence-changed",
1898 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1899 tp_g_signal_connect_object (account, "notify::connection",
1900 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
1902 g_object_unref (settings);
1906 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1909 EmpathyAccountsDialog *dialog)
1911 accounts_dialog_add_account (dialog, account);
1915 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1918 EmpathyAccountsDialog *dialog)
1920 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1922 if (priv->setting_widget != NULL &&
1923 accounts_dialog_has_valid_accounts (dialog))
1925 tpaw_account_widget_set_other_accounts_exist (
1926 priv->setting_widget, TRUE);
1931 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1933 EmpathyAccountsDialog *dialog)
1935 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1937 if (priv->setting_widget != NULL &&
1938 !accounts_dialog_has_valid_accounts (dialog))
1940 tpaw_account_widget_set_other_accounts_exist (
1941 priv->setting_widget, FALSE);
1946 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1948 EmpathyAccountsDialog *dialog)
1951 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1953 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1955 gtk_list_store_remove (GTK_LIST_STORE (
1956 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1961 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1965 /* Update the status-infobar in the details view */
1966 accounts_dialog_update_status_infobar (dialog, account);
1968 DEBUG ("Account %s is now %s",
1969 tp_account_get_display_name (account),
1970 enabled ? "enabled" : "disabled");
1974 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1976 EmpathyAccountsDialog *dialog)
1978 enable_or_disable_account (dialog, account, FALSE);
1979 update_account_in_treeview (dialog, account);
1983 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1985 EmpathyAccountsDialog *dialog)
1987 enable_or_disable_account (dialog, account, TRUE);
1991 display_import_dialog (EmpathyAccountsDialog *dialog)
1993 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1994 GtkWidget *import_dialog;
1996 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1998 gtk_widget_show (import_dialog);
2000 return import_dialog;
2004 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2005 EmpathyAccountsDialog *dialog)
2007 display_import_dialog (dialog);
2011 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2015 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2017 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2019 if (response_id == GTK_RESPONSE_YES)
2020 gtk_widget_destroy (account_dialog);
2024 accounts_dialog_delete_event_cb (GtkWidget *widget,
2026 EmpathyAccountsDialog *dialog)
2028 /* we maunally handle responses to delete events */
2033 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2038 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2039 select_and_scroll_to_iter (dialog, &iter);
2043 salut_valid_cb (GtkWidget *widget,
2047 gtk_widget_set_sensitive (button, valid);
2051 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2053 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2054 GtkWidget *dialog, *widget, *content, *button;
2057 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2058 priv->account_manager))
2061 widget = empathy_local_xmpp_assistant_widget_new ();
2062 gtk_widget_show (widget);
2064 dialog = gtk_dialog_new ();
2066 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2068 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2071 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2072 _("_Connect"), GTK_RESPONSE_YES);
2073 gtk_widget_set_sensitive (button,
2074 empathy_local_xmpp_assistant_widget_is_valid (
2075 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2077 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2080 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2081 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2083 response = gtk_dialog_run (GTK_DIALOG (dialog));
2085 if (response == GTK_RESPONSE_YES)
2087 empathy_local_xmpp_assistant_widget_create_account (
2088 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2091 gtk_widget_destroy (dialog);
2095 import_dialog_response_cb (GtkDialog *dialog,
2097 EmpathyAccountsDialog *self)
2099 maybe_show_salut_dialog (self);
2103 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2105 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2108 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2111 if (!empathy_import_accounts_to_import ())
2113 maybe_show_salut_dialog (self);
2117 dialog = display_import_dialog (self);
2119 tp_g_signal_connect_object (dialog, "response",
2120 G_CALLBACK (import_dialog_response_cb), self, 0);
2124 finished_loading (EmpathyAccountsDialog *self)
2126 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2127 GtkTreeSelection *selection;
2128 gboolean has_selected;
2130 priv->loading = FALSE;
2132 gtk_widget_set_sensitive (priv->button_add, TRUE);
2133 gtk_widget_set_sensitive (priv->button_import, TRUE);
2134 gtk_widget_set_sensitive (priv->treeview, TRUE);
2136 /* Sensitive the remove button if there is an account selected */
2137 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2138 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2139 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2141 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2142 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2143 NOTEBOOK_PAGE_ACCOUNT);
2145 maybe_show_import_dialog (self);
2149 accounts_dialog_cms_prepare_cb (GObject *source,
2150 GAsyncResult *result,
2153 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2154 EmpathyAccountsDialog *dialog = user_data;
2155 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2157 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2160 /* No need to update the settings if we are already preparing one */
2161 if (priv->settings_ready == NULL)
2162 accounts_dialog_update_settings (dialog, NULL);
2164 if (priv->initial_selection != NULL)
2166 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2167 g_object_unref (priv->initial_selection);
2168 priv->initial_selection = NULL;
2172 finished_loading (dialog);
2176 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2178 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2179 GList *accounts, *l;
2181 g_signal_connect (priv->account_manager, "account-validity-changed",
2182 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2184 g_signal_connect (priv->account_manager, "account-removed",
2185 G_CALLBACK (accounts_dialog_account_removed_cb),
2187 g_signal_connect (priv->account_manager, "account-enabled",
2188 G_CALLBACK (accounts_dialog_account_enabled_cb),
2190 g_signal_connect (priv->account_manager, "account-disabled",
2191 G_CALLBACK (accounts_dialog_account_disabled_cb),
2194 /* Add existing accounts */
2195 accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
2196 for (l = accounts; l; l = l->next)
2198 accounts_dialog_add_account (dialog, l->data);
2200 g_list_free_full (accounts, g_object_unref);
2202 priv->cms = empathy_connection_managers_dup_singleton ();
2204 empathy_connection_managers_prepare_async (priv->cms,
2205 accounts_dialog_cms_prepare_cb, dialog);
2207 accounts_dialog_model_select_first (dialog);
2211 accounts_dialog_manager_ready_cb (GObject *source_object,
2212 GAsyncResult *result,
2215 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2216 GError *error = NULL;
2218 if (!tp_proxy_prepare_finish (manager, result, &error))
2220 DEBUG ("Failed to prepare account manager: %s", error->message);
2221 g_error_free (error);
2225 accounts_dialog_accounts_setup (user_data);
2229 dialog_response_cb (GtkWidget *widget,
2233 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2235 if (response_id == GTK_RESPONSE_HELP)
2237 empathy_url_show (widget, "help:empathy/accounts-window");
2239 else if (response_id == GTK_RESPONSE_CLOSE ||
2240 response_id == GTK_RESPONSE_DELETE_EVENT)
2242 TpAccount *account = NULL;
2244 if (accounts_dialog_has_pending_change (dialog, &account))
2246 gchar *question_dialog_primary_text = get_dialog_primary_text (
2249 accounts_dialog_show_question_dialog (dialog,
2250 question_dialog_primary_text,
2251 _("You are about to close the window, which will discard\n"
2252 "your changes. Are you sure you want to proceed?"),
2253 G_CALLBACK (accounts_dialog_close_response_cb),
2255 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2256 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2258 g_free (question_dialog_primary_text);
2262 gtk_widget_destroy (widget);
2265 if (account != NULL)
2266 g_object_unref (account);
2271 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2273 GtkWidget *top_hbox;
2276 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2277 GtkWidget *content_area, *action_area;
2278 GtkWidget *grid, *hbox;
2280 GtkWidget *sw, *toolbar;
2281 GtkStyleContext *context;
2283 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2285 gui = empathy_builder_get_file (filename,
2286 "accounts_dialog_hbox", &top_hbox,
2287 "vbox_details", &priv->vbox_details,
2288 "alignment_settings", &priv->alignment_settings,
2289 "alignment_infobar", &priv->alignment_infobar,
2290 "treeview", &priv->treeview,
2291 "button_add", &priv->button_add,
2292 "button_remove", &priv->button_remove,
2293 "button_import", &priv->button_import,
2294 "notebook_account", &priv->notebook_account,
2295 "alignment_loading", &alig,
2297 "add_remove_toolbar", &toolbar,
2301 empathy_builder_connect (gui, dialog,
2302 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2303 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2304 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2305 "treeview", "button-press-event",
2306 accounts_dialog_treeview_button_press_event_cb,
2309 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2311 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2313 g_object_unref (gui);
2315 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2317 /* Display loading page */
2318 priv->loading = TRUE;
2320 priv->spinner = gtk_spinner_new ();
2322 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2323 gtk_widget_show (priv->spinner);
2325 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2327 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2328 NOTEBOOK_PAGE_LOADING);
2330 /* Remove button is insensitive until we have a selected account */
2331 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2333 /* Add and Import buttons and treeview are insensitive while the dialog
2335 gtk_widget_set_sensitive (priv->button_add, FALSE);
2336 gtk_widget_set_sensitive (priv->button_import, FALSE);
2337 gtk_widget_set_sensitive (priv->treeview, FALSE);
2339 if (priv->parent_window)
2340 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2341 priv->parent_window);
2343 priv->infobar = gtk_info_bar_new ();
2344 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2346 gtk_widget_show (priv->infobar);
2348 grid = gtk_grid_new ();
2349 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2351 GTK_CONTAINER (gtk_info_bar_get_content_area (
2352 GTK_INFO_BAR (priv->infobar))),
2355 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2356 GTK_ICON_SIZE_DIALOG);
2357 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2358 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2361 priv->label_name = gtk_label_new (NULL);
2362 gtk_label_set_ellipsize (GTK_LABEL (priv->label_name), PANGO_ELLIPSIZE_END);
2363 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2366 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2367 gtk_widget_set_hexpand (hbox, TRUE);
2368 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2369 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2371 /* set up spinner */
2372 priv->throbber = gtk_spinner_new ();
2374 priv->image_status = gtk_image_new_from_icon_name (
2375 empathy_icon_name_for_presence (
2376 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2378 priv->label_status = gtk_label_new (NULL);
2379 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2381 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2382 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2383 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2385 /* enabled switch */
2386 priv->enabled_switch = gtk_switch_new ();
2387 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2388 g_signal_connect (priv->enabled_switch, "notify::active",
2389 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2390 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2392 gtk_widget_show_all (grid);
2394 /* Tweak the dialog */
2395 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2396 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2398 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2400 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2402 /* join the add/remove toolbar to the treeview */
2403 context = gtk_widget_get_style_context (sw);
2404 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2406 context = gtk_widget_get_style_context (toolbar);
2407 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2409 /* add dialog buttons */
2410 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2412 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2413 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2414 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2417 g_signal_connect (dialog, "response",
2418 G_CALLBACK (dialog_response_cb), dialog);
2420 g_signal_connect (dialog, "delete-event",
2421 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2425 do_dispose (GObject *obj)
2427 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2428 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2430 if (priv->user_info != NULL)
2432 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
2434 priv->user_info = NULL;
2437 if (priv->connecting_id != 0)
2439 g_source_remove (priv->connecting_id);
2440 priv->connecting_id = 0;
2443 if (priv->connectivity)
2445 g_object_unref (priv->connectivity);
2446 priv->connectivity = NULL;
2449 if (priv->account_manager != NULL)
2451 g_object_unref (priv->account_manager);
2452 priv->account_manager = NULL;
2455 if (priv->cms != NULL)
2457 g_object_unref (priv->cms);
2461 if (priv->initial_selection != NULL)
2463 g_object_unref (priv->initial_selection);
2464 priv->initial_selection = NULL;
2467 tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
2469 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2473 do_get_property (GObject *object,
2478 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2480 switch (property_id)
2483 g_value_set_object (value, priv->parent_window);
2486 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2491 do_set_property (GObject *object,
2493 const GValue *value,
2496 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2498 switch (property_id)
2501 priv->parent_window = g_value_get_object (value);
2504 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2509 do_constructed (GObject *object)
2511 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2512 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2513 GtkTreeModel *model;
2515 accounts_dialog_build_ui (dialog);
2516 accounts_dialog_model_setup (dialog);
2518 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2519 g_signal_connect (model, "row-inserted",
2520 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2521 g_signal_connect (model, "row-deleted",
2522 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2524 /* Set up signalling */
2525 priv->account_manager = tp_account_manager_dup ();
2527 tp_proxy_prepare_async (priv->account_manager, NULL,
2528 accounts_dialog_manager_ready_cb, dialog);
2530 priv->connectivity = g_network_monitor_get_default ();
2531 g_object_ref (priv->connectivity);
2535 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2537 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2538 GParamSpec *param_spec;
2540 oclass->dispose = do_dispose;
2541 oclass->constructed = do_constructed;
2542 oclass->set_property = do_set_property;
2543 oclass->get_property = do_get_property;
2545 param_spec = g_param_spec_object ("parent",
2546 "parent", "The parent window",
2548 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2549 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2551 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2555 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2557 EmpathyAccountsDialogPriv *priv;
2559 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2560 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2561 EmpathyAccountsDialogPriv);
2562 dialog->priv = priv;
2564 priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
2565 g_free, g_object_unref);
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);