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>
29 #include <glib/gi18n-lib.h>
31 #include "libempathy/empathy-utils.h"
32 #include "libempathy/empathy-pkg-kit.h"
34 #include "libempathy-gtk/empathy-ui-utils.h"
35 #include "libempathy-gtk/empathy-account-widget-sip.h"
36 #include "libempathy-gtk/empathy-user-info.h"
37 #include "libempathy-gtk/empathy-local-xmpp-assistant-widget.h"
38 #include "libempathy-gtk/empathy-new-account-dialog.h"
40 #include "empathy-accounts-common.h"
41 #include "empathy-accounts-dialog.h"
42 #include "empathy-import-dialog.h"
43 #include "empathy-import-utils.h"
45 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
46 #include "libempathy/empathy-debug.h"
48 /* Flashing delay for icons (milliseconds). */
49 #define FLASH_TIMEOUT 500
51 /* The primary text of the dialog shown to the user when he is about to lose
53 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
54 _("There are unsaved modifications to your %s account.")
55 /* The primary text of the dialog shown to the user when he is about to lose
56 * an unsaved new account */
57 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
58 _("Your new account has not been saved yet.")
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
61 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
65 NOTEBOOK_PAGE_ACCOUNT = 0,
66 NOTEBOOK_PAGE_LOADING,
67 NOTEBOOK_PAGE_NO_PROTOCOL
71 GtkWidget *alignment_settings;
72 GtkWidget *alignment_infobar;
74 GtkWidget *vbox_details;
76 GtkWidget *label_status;
77 GtkWidget *image_status;
79 GtkWidget *enabled_switch;
82 GtkCellRenderer *name_renderer;
84 GtkWidget *button_add;
85 GtkWidget *button_remove;
86 GtkWidget *button_import;
88 GtkWidget *image_type;
89 GtkWidget *label_name;
90 GtkWidget *label_type;
91 GtkWidget *dialog_content;
94 GtkWidget *notebook_account;
98 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
99 * just its GtkWidget. It is the only reliable source we can query to know if
100 * there are any unsaved changes to the currently selected account. We can't
101 * look at the account settings because it does not contain everything that
102 * can be changed using the EmpathyAccountWidget. For instance, it does not
103 * contain the state of the "Enabled" checkbox.
105 * Even if we create it ourself, we just get a weak ref and not a strong one
106 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
107 * That's kinda ugly; cf bgo #640417.
110 EmpathyAccountWidget *setting_widget;
112 gboolean connecting_show;
115 gulong settings_ready_id;
116 EmpathyAccountSettings *settings_ready;
118 TpAccountManager *account_manager;
119 EmpathyConnectionManagers *cms;
120 GNetworkMonitor *connectivity;
122 GtkWindow *parent_window;
123 TpAccount *initial_selection;
125 /* Those are needed when changing the selected row. When a user selects
126 * another account and there are unsaved changes on the currently selected
127 * one, a confirmation message box is presented to him. Since his answer
128 * is retrieved asynchronously, we keep some information as member of the
129 * EmpathyAccountsDialog object. */
130 gboolean force_change_row;
131 GtkTreeRowReference *destination_row;
133 GHashTable *icons_cache;
134 } EmpathyAccountsDialogPriv;
140 COL_ACCOUNT_SETTINGS,
148 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
149 EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
159 static void accounts_dialog_connection_changed_cb (TpAccount *account,
163 gchar *dbus_error_name,
165 EmpathyAccountsDialog *dialog);
167 static void accounts_dialog_presence_changed_cb (TpAccount *account,
170 gchar *status_message,
171 EmpathyAccountsDialog *dialog);
173 static void accounts_dialog_model_selection_changed (
174 GtkTreeSelection *selection,
175 EmpathyAccountsDialog *dialog);
177 static gboolean accounts_dialog_has_pending_change (
178 EmpathyAccountsDialog *dialog, TpAccount **account);
181 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
182 const gchar *display_name)
185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
187 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
188 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
194 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
195 const gchar *message)
197 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
198 gchar *message_markup;
200 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
201 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
203 gtk_widget_set_tooltip_text (priv->label_status, message);
205 g_free (message_markup);
209 accounts_dialog_enable_account_cb (GObject *object,
210 GAsyncResult *result,
213 TpAccount *account = TP_ACCOUNT (object);
214 gboolean enable = GPOINTER_TO_UINT (user_data);
215 GError *error = NULL;
216 TpAccountManager *am;
218 if (!tp_account_set_enabled_finish (account, result, &error))
220 DEBUG ("Could not enable the account: %s", error->message);
221 g_error_free (error);
225 /* tp_account_is_enabled() is not updated yet at this point */
228 am = tp_account_manager_dup ();
230 empathy_connect_new_account (account, am);
236 enable_and_connect_account (TpAccount *account,
239 tp_account_set_enabled_async (account, enable,
240 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
244 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
246 EmpathyAccountsDialog *dialog)
248 EmpathyAccountSettings *settings;
252 settings = accounts_dialog_model_get_selected_settings (dialog);
253 if (settings == NULL)
256 account = empathy_account_settings_get_account (settings);
260 enable = gtk_switch_get_active (sw);
262 enable_and_connect_account (account, enable);
266 install_haze_cb (GObject *source,
267 GAsyncResult *result,
270 GError *error = NULL;
272 if (!empathy_pkg_kit_install_packages_finish (result, &error))
274 DEBUG ("Failed to install telepathy-haze: %s", error->message);
276 g_error_free (error);
281 account_is_selected (EmpathyAccountsDialog *dialog,
284 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
285 GtkTreeSelection *selection;
288 TpAccount *selected_account;
293 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
295 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
298 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
300 if (selected_account != NULL)
301 g_object_unref (selected_account);
303 return account == selected_account;
307 account_can_be_enabled (TpAccount *account)
309 TpStorageRestrictionFlags storage_restrictions;
311 storage_restrictions = tp_account_get_storage_restrictions (account);
312 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
315 /* Butterfly accounts shouldn't be used any more */
316 if (!tp_strdiff (tp_account_get_cm_name (account),
324 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
327 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
328 gchar *status_message = NULL;
332 gboolean account_enabled;
333 gboolean creating_account;
334 gboolean display_switch = TRUE;
336 /* do not update the infobar when the account is not selected */
337 if (!account_is_selected (dialog, account))
342 status = tp_account_get_connection_status (account, &reason);
343 presence = tp_account_get_current_presence (account, NULL, &status_message);
344 account_enabled = tp_account_is_enabled (account);
345 creating_account = FALSE;
347 if (status == TP_CONNECTION_STATUS_CONNECTED &&
348 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
349 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
350 /* If presence is Unset (CM doesn't implement SimplePresence) but we
351 * are connected, consider ourself as Available.
352 * We also check Offline because of this MC5 bug: fd.o #26060 */
353 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
355 /* set presence to offline if account is disabled
356 * (else no icon is shown in infobar)*/
357 if (!account_enabled)
358 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
360 display_switch = account_can_be_enabled (account);
364 status = TP_CONNECTION_STATUS_DISCONNECTED;
365 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
366 account_enabled = FALSE;
367 creating_account = TRUE;
370 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
371 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
373 /* update the enabled switch */
374 g_signal_handlers_block_by_func (priv->enabled_switch,
375 accounts_dialog_enable_switch_active_cb, dialog);
376 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
378 g_signal_handlers_unblock_by_func (priv->enabled_switch,
379 accounts_dialog_enable_switch_active_cb, dialog);
381 /* Display the Enable switch if account supports it */
382 gtk_widget_set_visible (priv->enabled_switch, display_switch);
388 case TP_CONNECTION_STATUS_CONNECTING:
389 accounts_dialog_status_infobar_set_message (dialog,
391 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
394 gtk_spinner_start (GTK_SPINNER (priv->throbber));
395 gtk_widget_show (priv->throbber);
396 gtk_widget_hide (priv->image_status);
398 case TP_CONNECTION_STATUS_CONNECTED:
399 if (g_strcmp0 (status_message, "") == 0)
403 message = g_strdup_printf ("%s",
404 empathy_presence_get_default_message (presence));
406 accounts_dialog_status_infobar_set_message (dialog, message);
413 message = g_strdup_printf ("%s — %s",
414 empathy_presence_get_default_message (presence),
417 accounts_dialog_status_infobar_set_message (dialog, message);
420 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
423 gtk_widget_show (priv->image_status);
424 gtk_widget_hide (priv->throbber);
426 case TP_CONNECTION_STATUS_DISCONNECTED:
427 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
431 message = g_strdup_printf (_("Offline — %s"),
432 empathy_account_get_error_message (account, NULL));
433 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
434 GTK_MESSAGE_WARNING);
436 accounts_dialog_status_infobar_set_message (dialog, message);
443 message = g_strdup_printf (_("Disconnected — %s"),
444 empathy_account_get_error_message (account, NULL));
445 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
448 accounts_dialog_status_infobar_set_message (dialog, message);
452 if (!g_network_monitor_get_network_available (priv->connectivity))
453 accounts_dialog_status_infobar_set_message (dialog,
454 _("Offline — No Network Connection"));
456 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
457 gtk_widget_show (priv->image_status);
458 gtk_widget_hide (priv->throbber);
461 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
462 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
463 GTK_MESSAGE_WARNING);
465 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
466 gtk_widget_hide (priv->image_status);
467 gtk_widget_hide (priv->throbber);
472 if (!tp_strdiff (tp_account_get_cm_name (account),
475 const gchar *packages[] = { "telepathy-haze", NULL };
477 accounts_dialog_status_infobar_set_message (dialog,
478 _("This account has been disabled because it relies on an old, "
479 "unsupported backend. Please install telepathy-haze and "
480 "restart your session to migrate the account."));
482 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
483 install_haze_cb, NULL);
487 accounts_dialog_status_infobar_set_message (dialog,
488 _("Offline — Account Disabled"));
491 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
492 GTK_MESSAGE_WARNING);
493 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
494 gtk_widget_show (priv->image_status);
495 gtk_widget_hide (priv->throbber);
498 gtk_widget_show (priv->label_status);
500 if (!creating_account)
501 gtk_widget_show (priv->infobar);
503 gtk_widget_hide (priv->infobar);
505 g_free (status_message);
509 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
513 GtkTreeSelection *selection;
515 EmpathyAccountSettings *settings;
517 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
519 view = GTK_TREE_VIEW (priv->treeview);
520 selection = gtk_tree_view_get_selection (view);
522 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
525 gtk_tree_model_get (model, &iter,
526 COL_ACCOUNT_SETTINGS, &settings,
527 COL_ACCOUNT, &account, -1);
529 empathy_account_widget_discard_pending_changes (priv->setting_widget);
533 /* We were creating an account. We remove the selected row */
534 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
538 /* We were modifying an account. We discard the changes by reloading the
539 * settings and the UI. */
540 accounts_dialog_update_settings (dialog, settings);
541 g_object_unref (account);
544 gtk_widget_set_sensitive (priv->treeview, TRUE);
545 gtk_widget_set_sensitive (priv->button_add, TRUE);
546 gtk_widget_set_sensitive (priv->button_remove, TRUE);
547 gtk_widget_set_sensitive (priv->button_import, TRUE);
549 if (settings != NULL)
550 g_object_unref (settings);
554 empathy_account_dialog_widget_cancelled_cb (
555 EmpathyAccountWidget *widget_object,
556 EmpathyAccountsDialog *dialog)
558 empathy_account_dialog_cancel (dialog);
562 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
564 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
569 g_object_get (priv->setting_widget,
570 "creating-account", &creating, NULL);
575 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
577 if (gtk_tree_model_get_iter_first (model, &iter))
578 return gtk_tree_model_iter_next (model, &iter);
584 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
586 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
587 EmpathyAccountSettings *settings;
588 GtkWidget *subdialog, *content_area, *align;
590 settings = accounts_dialog_model_get_selected_settings (dialog);
591 if (settings == NULL)
594 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
596 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
599 gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
601 priv->setting_widget = (EmpathyAccountWidget *)
602 empathy_account_widget_new_for_protocol (settings, FALSE);
604 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
605 (gpointer *) &priv->setting_widget);
607 if (accounts_dialog_has_valid_accounts (dialog))
608 empathy_account_widget_set_other_accounts_exist (
609 priv->setting_widget, TRUE);
611 g_signal_connect (priv->setting_widget, "cancelled",
612 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
614 g_signal_connect_swapped (priv->setting_widget, "close",
615 G_CALLBACK (gtk_widget_destroy), subdialog);
617 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
619 align = gtk_alignment_new (0.5, 0.5, 1, 1);
620 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
622 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
623 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
625 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
626 gtk_widget_show (align);
627 gtk_widget_show (subdialog);
631 use_external_storage_provider (EmpathyAccountsDialog *self,
634 const gchar *provider;
636 provider = tp_account_get_storage_provider (account);
637 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
639 empathy_launch_external_app ("gnome-control-center.desktop",
640 "bisho.desktop", NULL);
643 else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
645 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
649 else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
651 empathy_launch_external_app ("gnome-credentials-panel.desktop",
657 DEBUG ("Don't know how to handle %s", provider);
663 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
666 EmpathyAccountSettings *settings;
668 TpStorageRestrictionFlags storage_restrictions;
670 settings = accounts_dialog_model_get_selected_settings (dialog);
671 if (settings == NULL)
674 account = empathy_account_settings_get_account (settings);
675 g_return_if_fail (account != NULL);
677 storage_restrictions = tp_account_get_storage_restrictions (account);
679 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
680 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
682 DEBUG ("Account is provided by an external storage provider");
684 use_external_storage_provider (dialog, account);
688 account_dialog_create_edit_params_dialog (dialog);
693 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
694 EmpathyAccountSettings *settings)
696 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
697 const gchar *icon_name;
699 GtkWidget *bbox, *button;
702 account = empathy_account_settings_get_account (settings);
704 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
705 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
706 priv->dialog_content);
707 gtk_widget_show (priv->dialog_content);
709 alig = gtk_alignment_new (0.5, 0, 1, 1);
710 priv->user_info = empathy_user_info_new (account);
711 gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
712 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
713 gtk_widget_show (alig);
714 gtk_widget_show (priv->user_info);
716 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
717 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
718 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
719 gtk_widget_show (bbox);
721 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
722 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
723 gtk_widget_show (button);
724 g_signal_connect_swapped (button, "clicked",
725 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
727 icon_name = empathy_account_settings_get_icon_name (settings);
729 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
731 /* show the default icon; keep this in sync with the default
732 * one in empathy-accounts-dialog.ui.
734 icon_name = GTK_STOCK_CUT;
736 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
737 icon_name, GTK_ICON_SIZE_DIALOG);
738 gtk_widget_set_tooltip_text (priv->image_type,
739 empathy_protocol_name_to_display_name
740 (empathy_account_settings_get_protocol (settings)));
741 gtk_widget_show (priv->image_type);
743 accounts_dialog_update_name_label (dialog,
744 empathy_account_settings_get_display_name (settings));
746 accounts_dialog_update_status_infobar (dialog, account);
750 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
752 EmpathyAccountsDialog *dialog)
754 if (empathy_account_settings_is_ready (settings))
755 account_dialog_create_dialog_content (dialog, settings);
759 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
763 GtkTreeSelection *selection;
765 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
768 view = GTK_TREE_VIEW (priv->treeview);
769 model = gtk_tree_view_get_model (view);
771 if (gtk_tree_model_get_iter_first (model, &iter))
773 selection = gtk_tree_view_get_selection (view);
774 gtk_tree_selection_select_iter (selection, &iter);
778 accounts_dialog_update_settings (dialog, NULL);
783 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
788 GtkTreeSelection *selection;
789 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
791 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
793 if (gtk_tree_selection_get_selected (selection, &model, &iter))
794 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
796 return priv->setting_widget != NULL
797 && empathy_account_widget_contains_pending_changes (
798 priv->setting_widget);
802 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
803 const gchar *primary_text,
804 const gchar *secondary_text,
805 GCallback response_callback,
807 const gchar *first_button_text,
811 GtkWidget *message_dialog;
812 const gchar *button_text;
814 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
815 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
816 GTK_MESSAGE_QUESTION,
820 gtk_message_dialog_format_secondary_text (
821 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
823 va_start (button_args, first_button_text);
824 for (button_text = first_button_text;
826 button_text = va_arg (button_args, const gchar *))
829 response_id = va_arg (button_args, gint);
831 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
834 va_end (button_args);
836 g_signal_connect (message_dialog, "response", response_callback, user_data);
838 gtk_widget_show (message_dialog);
842 get_dialog_primary_text (TpAccount *account)
846 /* Existing account */
847 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
848 tp_account_get_display_name (account));
852 /* Newly created account */
853 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
858 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
859 EmpathyAccountsDialog *self)
864 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
865 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
867 response = gtk_dialog_run (GTK_DIALOG (dialog));
869 if (response == GTK_RESPONSE_APPLY)
871 EmpathyAccountSettings *settings;
874 settings = empathy_new_account_dialog_get_settings (
875 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
877 /* The newly created account has already been added by
878 * accounts_dialog_account_validity_changed_cb so we just
879 * have to select it. */
880 account = empathy_account_settings_get_account (settings);
881 accounts_dialog_model_set_selected (self, account);
884 gtk_widget_destroy (dialog);
888 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
889 EmpathyAccountSettings *settings)
891 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
893 if (priv->settings_ready != NULL)
895 g_signal_handler_disconnect (priv->settings_ready,
896 priv->settings_ready_id);
897 priv->settings_ready = NULL;
898 priv->settings_ready_id = 0;
905 GtkTreeSelection *selection;
907 view = GTK_TREE_VIEW (priv->treeview);
908 model = gtk_tree_view_get_model (view);
909 selection = gtk_tree_view_get_selection (view);
911 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
913 /* We have configured accounts, select the first one if there
914 * is no other account selected already. */
915 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
916 accounts_dialog_model_select_first (dialog);
921 /* No account selected */
922 gtk_widget_hide (priv->vbox_details);
923 gtk_widget_set_sensitive (priv->button_add, TRUE);
924 gtk_widget_set_sensitive (priv->button_remove, FALSE);
926 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
927 NOTEBOOK_PAGE_NO_PROTOCOL);
931 /* We have an account selected, destroy old settings and create a new
932 * one for the account selected */
933 gtk_widget_show (priv->vbox_details);
935 if (priv->user_info != NULL)
937 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
939 priv->user_info = NULL;
941 if (priv->dialog_content)
943 gtk_widget_destroy (priv->dialog_content);
944 priv->dialog_content = NULL;
947 if (empathy_account_settings_is_ready (settings))
949 account_dialog_create_dialog_content (dialog, settings);
953 priv->settings_ready = settings;
954 priv->settings_ready_id =
955 g_signal_connect (settings, "notify::ready",
956 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
962 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
963 GtkCellEditable *editable,
965 EmpathyAccountsDialog *dialog)
967 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
969 if (priv->connecting_id)
970 g_source_remove (priv->connecting_id);
972 DEBUG ("Editing account name started; stopping flashing");
976 get_status_icon_for_account (EmpathyAccountsDialog *self,
979 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
980 TpConnectionStatus status;
981 TpConnectionStatusReason reason;
982 TpConnectionPresenceType presence;
985 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
987 if (!tp_account_is_enabled (account))
988 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
990 status = tp_account_get_connection_status (account, &reason);
992 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
994 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
995 /* An error occured */
996 return GTK_STOCK_DIALOG_ERROR;
998 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1000 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1002 /* Account is connecting. Display a blinking account alternating between
1003 * the offline icon and the requested presence. */
1004 if (priv->connecting_show)
1005 presence = tp_account_get_requested_presence (account, NULL, NULL);
1007 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1011 /* status == TP_CONNECTION_STATUS_CONNECTED */
1012 presence = tp_account_get_current_presence (account, NULL, NULL);
1014 /* If presence is Unset (CM doesn't implement SimplePresence),
1015 * display the 'available' icon.
1016 * We also check Offline because of this MC5 bug: fd.o #26060 */
1017 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1018 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1019 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1022 return empathy_icon_name_for_presence (presence);
1026 ensure_icon (EmpathyAccountsDialog *self,
1027 const gchar *icon_name)
1029 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1032 pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
1035 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1040 g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
1044 return g_object_ref (pixbuf);
1048 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1049 GtkCellRenderer *cell,
1050 GtkTreeModel *model,
1052 EmpathyAccountsDialog *dialog)
1055 const gchar *icon_name;
1058 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1060 icon_name = get_status_icon_for_account (dialog, account);
1061 pixbuf = ensure_icon (dialog, icon_name);
1067 if (account != NULL)
1068 g_object_unref (account);
1071 g_object_unref (pixbuf);
1075 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1076 GtkCellRenderer *cell,
1077 GtkTreeModel *model,
1079 EmpathyAccountsDialog *dialog)
1081 EmpathyAccountSettings *settings;
1084 TpConnectionStatus status;
1086 gtk_tree_model_get (model, iter,
1087 COL_STATUS, &status,
1088 COL_ACCOUNT_SETTINGS, &settings,
1091 icon_name = empathy_account_settings_get_icon_name (settings);
1092 pixbuf = ensure_icon (dialog, icon_name);
1099 g_object_unref (settings);
1102 g_object_unref (pixbuf);
1106 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1113 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1115 if (account == NULL)
1118 if (tp_account_get_connection_status (account, NULL) ==
1119 TP_CONNECTION_STATUS_CONNECTING)
1121 /* Only update the row where we have a connecting account as that's the
1122 * ones having a blinking icon. */
1123 gtk_tree_model_row_changed (model, path, iter);
1126 g_object_unref (account);
1131 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1134 GtkTreeModel *model;
1135 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1137 priv->connecting_show = !priv->connecting_show;
1139 view = GTK_TREE_VIEW (priv->treeview);
1140 model = gtk_tree_view_get_model (view);
1142 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1148 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1151 EmpathyAccountsDialog *dialog)
1153 EmpathyAccountSettings *settings;
1154 GtkTreeModel *model;
1155 GtkTreePath *treepath;
1157 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1158 gboolean connecting;
1160 empathy_account_manager_get_accounts_connected (&connecting);
1164 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1165 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1169 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1170 treepath = gtk_tree_path_new_from_string (path);
1171 gtk_tree_model_get_iter (model, &iter, treepath);
1172 gtk_tree_model_get (model, &iter,
1173 COL_ACCOUNT_SETTINGS, &settings,
1175 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1178 gtk_tree_path_free (treepath);
1180 empathy_account_settings_set_display_name_async (settings, new_text,
1182 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1183 g_object_unref (settings);
1187 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1192 GtkTreeModel *model;
1194 GtkTreeSelection *selection;
1195 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1196 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1198 if (response_id == GTK_RESPONSE_YES)
1200 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1202 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1205 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1207 if (account != NULL)
1209 tp_account_remove_async (account, NULL, NULL);
1210 g_object_unref (account);
1214 /* No need to call accounts_dialog_model_selection_changed while
1215 * removing as we are going to call accounts_dialog_model_select_first
1216 * right after which will update the selection. */
1217 g_signal_handlers_block_by_func (selection,
1218 accounts_dialog_model_selection_changed, account_dialog);
1220 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1222 g_signal_handlers_unblock_by_func (selection,
1223 accounts_dialog_model_selection_changed, account_dialog);
1225 accounts_dialog_model_select_first (account_dialog);
1228 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1232 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1235 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1237 GtkTreeModel *model;
1238 gchar *question_dialog_primary_text;
1240 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1242 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1244 if (account == NULL || !tp_account_is_valid (account))
1246 if (account != NULL)
1247 g_object_unref (account);
1248 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1249 accounts_dialog_model_select_first (dialog);
1253 question_dialog_primary_text = g_strdup_printf (
1254 _("Do you want to remove %s from your computer?"),
1255 tp_account_get_display_name (account));
1257 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1258 _("This will not remove your account on the server."),
1259 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1261 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1262 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1264 g_free (question_dialog_primary_text);
1265 g_object_unref (account);
1269 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1270 EmpathyAccountsDialog *dialog)
1272 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1274 GtkTreeSelection *selection;
1277 view = GTK_TREE_VIEW (priv->treeview);
1278 selection = gtk_tree_view_get_selection (view);
1279 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1282 accounts_dialog_remove_account_iter (dialog, &iter);
1286 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1289 GtkTreeViewColumn *column;
1290 GtkCellRenderer *cell;
1291 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1293 view = GTK_TREE_VIEW (priv->treeview);
1294 gtk_tree_view_set_headers_visible (view, FALSE);
1296 /* Account column */
1297 column = gtk_tree_view_column_new ();
1298 gtk_tree_view_column_set_expand (column, TRUE);
1299 gtk_tree_view_append_column (view, column);
1301 /* Status icon renderer */
1302 cell = gtk_cell_renderer_pixbuf_new ();
1303 gtk_tree_view_column_pack_start (column, cell, FALSE);
1304 gtk_tree_view_column_set_cell_data_func (column, cell,
1305 (GtkTreeCellDataFunc)
1306 accounts_dialog_model_status_pixbuf_data_func,
1310 /* Protocol icon renderer */
1311 cell = gtk_cell_renderer_pixbuf_new ();
1312 gtk_tree_view_column_pack_start (column, cell, FALSE);
1313 gtk_tree_view_column_set_cell_data_func (column, cell,
1314 (GtkTreeCellDataFunc)
1315 accounts_dialog_model_protocol_pixbuf_data_func,
1320 priv->name_renderer = gtk_cell_renderer_text_new ();
1321 g_object_set (priv->name_renderer,
1322 "ellipsize", PANGO_ELLIPSIZE_END,
1326 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1327 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1329 g_signal_connect (priv->name_renderer, "edited",
1330 G_CALLBACK (accounts_dialog_name_edited_cb),
1332 g_signal_connect (priv->name_renderer, "editing-started",
1333 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1335 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1338 static EmpathyAccountSettings *
1339 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1342 GtkTreeModel *model;
1343 GtkTreeSelection *selection;
1345 EmpathyAccountSettings *settings;
1346 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1348 view = GTK_TREE_VIEW (priv->treeview);
1349 selection = gtk_tree_view_get_selection (view);
1351 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1354 gtk_tree_model_get (model, &iter,
1355 COL_ACCOUNT_SETTINGS, &settings, -1);
1361 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1362 EmpathyAccountsDialog *dialog)
1364 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1365 EmpathyAccountSettings *settings;
1366 GtkTreeModel *model;
1368 gboolean is_selection;
1369 gboolean creating = FALSE;
1371 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1373 settings = accounts_dialog_model_get_selected_settings (dialog);
1374 accounts_dialog_update_settings (dialog, settings);
1376 if (settings != NULL)
1377 g_object_unref (settings);
1379 if (priv->setting_widget != NULL)
1381 g_object_get (priv->setting_widget,
1382 "creating-account", &creating, NULL);
1385 /* Update remove button sensitivity */
1386 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1391 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1393 gpointer *user_data)
1395 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1396 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1398 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1400 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1402 /* The user wants to lose unsaved changes to the currently selected
1403 * account and select another account. We discard the changes and
1404 * select the other account. */
1406 GtkTreeSelection *selection;
1408 priv->force_change_row = TRUE;
1409 empathy_account_widget_discard_pending_changes (
1410 priv->setting_widget);
1412 path = gtk_tree_row_reference_get_path (priv->destination_row);
1413 selection = gtk_tree_view_get_selection (
1414 GTK_TREE_VIEW (priv->treeview));
1418 /* This will trigger a call to
1419 * accounts_dialog_account_selection_change() */
1420 gtk_tree_selection_select_path (selection, path);
1421 gtk_tree_path_free (path);
1424 gtk_tree_row_reference_free (priv->destination_row);
1428 priv->force_change_row = FALSE;
1433 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1434 GtkTreeModel *model,
1436 gboolean path_currently_selected,
1439 TpAccount *account = NULL;
1440 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1441 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1444 if (priv->force_change_row)
1446 /* We came back here because the user wants to discard changes to his
1447 * modified account. The changes have already been discarded so we
1448 * just change the selected row. */
1449 priv->force_change_row = FALSE;
1453 if (accounts_dialog_has_pending_change (dialog, &account))
1455 /* The currently selected account has some unsaved changes. We ask
1456 * the user if he really wants to lose his changes and select another
1458 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1459 priv->destination_row = gtk_tree_row_reference_new (model, path);
1461 accounts_dialog_show_question_dialog (dialog,
1462 question_dialog_primary_text,
1463 _("You are about to select another account, which will discard\n"
1464 "your changes. Are you sure you want to proceed?"),
1465 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1467 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1468 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1470 g_free (question_dialog_primary_text);
1478 if (account != NULL)
1479 g_object_unref (account);
1485 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1487 GtkListStore *store;
1488 GtkTreeSelection *selection;
1489 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1491 store = gtk_list_store_new (COL_COUNT,
1492 G_TYPE_STRING, /* name */
1493 G_TYPE_UINT, /* status */
1494 TP_TYPE_ACCOUNT, /* account */
1495 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1497 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1498 GTK_TREE_MODEL (store));
1500 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1501 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1502 gtk_tree_selection_set_select_function (selection,
1503 accounts_dialog_account_selection_change, dialog, NULL);
1505 g_signal_connect (selection, "changed",
1506 G_CALLBACK (accounts_dialog_model_selection_changed),
1509 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1510 COL_NAME, GTK_SORT_ASCENDING);
1512 accounts_dialog_model_add_columns (dialog);
1514 g_object_unref (store);
1518 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1523 GtkTreeModel *model;
1525 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1527 /* Update the status in the model */
1528 view = GTK_TREE_VIEW (priv->treeview);
1529 model = gtk_tree_view_get_model (view);
1531 for (ok = gtk_tree_model_get_iter_first (model, iter);
1533 ok = gtk_tree_model_iter_next (model, iter))
1535 TpAccount *this_account;
1538 gtk_tree_model_get (model, iter,
1539 COL_ACCOUNT, &this_account,
1542 equal = (this_account == account);
1543 g_object_unref (this_account);
1553 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1556 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1557 GtkTreeSelection *selection;
1559 GtkTreeModel *model;
1561 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1563 gtk_tree_selection_select_iter (selection, iter);
1565 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1566 path = gtk_tree_model_get_path (model, iter);
1568 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1571 gtk_tree_path_free (path);
1575 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1580 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1581 select_and_scroll_to_iter (dialog, &iter);
1585 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1590 enabled = tp_account_is_enabled (account);
1592 enable_and_connect_account (account, !enabled);
1596 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1597 EmpathyAccountsDialog *self)
1599 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1602 GtkTreeSelection *selection;
1603 GtkTreeModel *model;
1605 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1606 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1608 path = gtk_tree_model_get_path (model, &iter);
1610 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1612 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1613 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1614 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1616 gtk_tree_path_free (path);
1620 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1621 GdkEventButton *event,
1622 EmpathyAccountsDialog *dialog)
1624 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1625 TpAccount *account = NULL;
1626 GtkTreeModel *model = NULL;
1627 GtkTreePath *path = NULL;
1632 /* ignore multiple clicks */
1633 if (event->type != GDK_BUTTON_PRESS)
1636 if (event->button != 3)
1639 /* Selection is not yet set, so we have to get account from event position */
1640 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1641 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1642 event->x, event->y, &path, NULL, NULL, NULL))
1645 if (!gtk_tree_model_get_iter (model, &iter, path))
1648 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1650 /* Create the menu */
1651 menu = empathy_context_menu_new (GTK_WIDGET (view));
1653 /* Menu item: to enabled/disable the account */
1654 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1656 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1658 if (account_can_be_enabled (account))
1662 active = tp_account_is_enabled (account);
1663 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1666 tp_g_signal_connect_object (item, "activate",
1667 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1671 gtk_widget_set_sensitive (item, FALSE);
1674 gtk_widget_show (item);
1676 /* Menu item: Rename */
1677 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1678 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1680 tp_g_signal_connect_object (item, "activate",
1681 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1683 gtk_widget_show (item);
1685 /* FIXME: Add here presence items, to be able to set per-account presence */
1688 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1689 event->button, event->time);
1692 tp_clear_object (&account);
1693 gtk_tree_path_free (path);
1699 reload_account_widget (EmpathyAccountsDialog *self)
1701 EmpathyAccountSettings *settings;
1703 settings = accounts_dialog_model_get_selected_settings (self);
1704 accounts_dialog_update_settings (self, settings);
1708 accounts_dialog_connection_changed_cb (TpAccount *account,
1712 gchar *dbus_error_name,
1713 GHashTable *details,
1714 EmpathyAccountsDialog *dialog)
1716 GtkTreeModel *model;
1719 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1721 /* Update the status-infobar in the details view */
1722 accounts_dialog_update_status_infobar (dialog, account);
1724 /* Update the status in the model */
1725 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1727 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1731 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1732 COL_STATUS, current,
1735 path = gtk_tree_model_get_path (model, &iter);
1736 gtk_tree_model_row_changed (model, path, &iter);
1737 gtk_tree_path_free (path);
1740 empathy_account_manager_get_accounts_connected (&found);
1742 if (!found && priv->connecting_id)
1744 g_source_remove (priv->connecting_id);
1745 priv->connecting_id = 0;
1748 if (found && !priv->connecting_id)
1749 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1750 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1755 update_account_in_treeview (EmpathyAccountsDialog *self,
1758 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1760 GtkTreeModel *model;
1762 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1763 if (accounts_dialog_get_account_iter (self, account, &iter))
1767 path = gtk_tree_model_get_path (model, &iter);
1768 gtk_tree_model_row_changed (model, path, &iter);
1769 gtk_tree_path_free (path);
1774 accounts_dialog_presence_changed_cb (TpAccount *account,
1777 gchar *status_message,
1778 EmpathyAccountsDialog *dialog)
1780 /* Update the status-infobar in the details view */
1781 accounts_dialog_update_status_infobar (dialog, account);
1783 update_account_in_treeview (dialog, account);
1787 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1791 const gchar *display_name;
1793 GtkTreeModel *model;
1794 EmpathyAccountSettings *settings;
1795 TpAccount *selected_account;
1796 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1797 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1799 display_name = tp_account_get_display_name (account);
1800 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1801 settings = accounts_dialog_model_get_selected_settings (dialog);
1802 if (settings == NULL)
1805 selected_account = empathy_account_settings_get_account (settings);
1807 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1809 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1810 COL_NAME, display_name,
1814 if (selected_account == account)
1815 accounts_dialog_update_name_label (dialog, display_name);
1817 g_object_unref (settings);
1821 conn_prepare_cb (GObject *source,
1822 GAsyncResult *result,
1825 EmpathyAccountsDialog *self = user_data;
1827 reload_account_widget (self);
1831 accounts_dialog_notify_connection_cb (TpAccount *account,
1833 EmpathyAccountsDialog *self)
1836 if (!account_is_selected (self, account))
1839 conn = tp_account_get_connection (account);
1842 reload_account_widget (self);
1846 /* Wait for this feature so TpConnection will have fetch the
1848 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1850 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1855 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1858 EmpathyAccountSettings *settings;
1859 GtkTreeModel *model;
1861 TpConnectionStatus status;
1863 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1864 gboolean selected = FALSE;
1865 GtkTreeSelection *selection;
1867 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1868 status = tp_account_get_connection_status (account, NULL);
1869 name = tp_account_get_display_name (account);
1871 settings = empathy_account_settings_new_for_account (account);
1873 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1875 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1877 /* Select the account if it's the first added */
1878 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1881 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1884 COL_ACCOUNT, account,
1885 COL_ACCOUNT_SETTINGS, settings,
1890 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1892 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1895 COL_ACCOUNT, account,
1896 COL_ACCOUNT_SETTINGS, settings,
1902 /* We just modified the selected account. Its display name may have been
1903 * changed and so it's place in the treeview. Scroll to it so it stays
1905 select_and_scroll_to_iter (dialog, &iter);
1908 accounts_dialog_connection_changed_cb (account,
1911 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1916 tp_g_signal_connect_object (account, "notify::display-name",
1917 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1920 tp_g_signal_connect_object (account, "status-changed",
1921 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1922 tp_g_signal_connect_object (account, "presence-changed",
1923 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1924 tp_g_signal_connect_object (account, "notify::connection",
1925 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
1927 g_object_unref (settings);
1931 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1934 EmpathyAccountsDialog *dialog)
1936 accounts_dialog_add_account (dialog, account);
1940 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1943 EmpathyAccountsDialog *dialog)
1945 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1947 if (priv->setting_widget != NULL &&
1948 accounts_dialog_has_valid_accounts (dialog))
1950 empathy_account_widget_set_other_accounts_exist (
1951 priv->setting_widget, TRUE);
1956 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1958 EmpathyAccountsDialog *dialog)
1960 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1962 if (priv->setting_widget != NULL &&
1963 !accounts_dialog_has_valid_accounts (dialog))
1965 empathy_account_widget_set_other_accounts_exist (
1966 priv->setting_widget, FALSE);
1971 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1973 EmpathyAccountsDialog *dialog)
1976 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1978 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1980 gtk_list_store_remove (GTK_LIST_STORE (
1981 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1986 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1990 /* Update the status-infobar in the details view */
1991 accounts_dialog_update_status_infobar (dialog, account);
1993 DEBUG ("Account %s is now %s",
1994 tp_account_get_display_name (account),
1995 enabled ? "enabled" : "disabled");
1999 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
2001 EmpathyAccountsDialog *dialog)
2003 enable_or_disable_account (dialog, account, FALSE);
2004 update_account_in_treeview (dialog, account);
2008 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2010 EmpathyAccountsDialog *dialog)
2012 enable_or_disable_account (dialog, account, TRUE);
2016 display_import_dialog (EmpathyAccountsDialog *dialog)
2018 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2019 GtkWidget *import_dialog;
2021 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2023 gtk_widget_show (import_dialog);
2025 return import_dialog;
2029 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2030 EmpathyAccountsDialog *dialog)
2032 display_import_dialog (dialog);
2036 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2040 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2042 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2044 if (response_id == GTK_RESPONSE_YES)
2045 gtk_widget_destroy (account_dialog);
2049 accounts_dialog_delete_event_cb (GtkWidget *widget,
2051 EmpathyAccountsDialog *dialog)
2053 /* we maunally handle responses to delete events */
2058 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2063 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2064 select_and_scroll_to_iter (dialog, &iter);
2068 salut_valid_cb (GtkWidget *widget,
2072 gtk_widget_set_sensitive (button, valid);
2076 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2078 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2079 GtkWidget *dialog, *widget, *content, *button;
2082 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2083 priv->account_manager))
2086 widget = empathy_local_xmpp_assistant_widget_new ();
2087 gtk_widget_show (widget);
2089 dialog = gtk_dialog_new ();
2091 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2093 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2096 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2097 _("_Connect"), GTK_RESPONSE_YES);
2098 gtk_widget_set_sensitive (button,
2099 empathy_local_xmpp_assistant_widget_is_valid (
2100 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2102 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2105 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2106 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2108 response = gtk_dialog_run (GTK_DIALOG (dialog));
2110 if (response == GTK_RESPONSE_YES)
2112 empathy_local_xmpp_assistant_widget_create_account (
2113 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2116 gtk_widget_destroy (dialog);
2120 import_dialog_response_cb (GtkDialog *dialog,
2122 EmpathyAccountsDialog *self)
2124 maybe_show_salut_dialog (self);
2128 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2130 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2133 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2136 if (!empathy_import_accounts_to_import ())
2138 maybe_show_salut_dialog (self);
2142 dialog = display_import_dialog (self);
2144 tp_g_signal_connect_object (dialog, "response",
2145 G_CALLBACK (import_dialog_response_cb), self, 0);
2149 finished_loading (EmpathyAccountsDialog *self)
2151 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2152 GtkTreeSelection *selection;
2153 gboolean has_selected;
2155 priv->loading = FALSE;
2157 gtk_widget_set_sensitive (priv->button_add, TRUE);
2158 gtk_widget_set_sensitive (priv->button_import, TRUE);
2159 gtk_widget_set_sensitive (priv->treeview, TRUE);
2161 /* Sensitive the remove button if there is an account selected */
2162 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2163 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2164 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2166 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2167 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2168 NOTEBOOK_PAGE_ACCOUNT);
2170 maybe_show_import_dialog (self);
2174 accounts_dialog_cms_prepare_cb (GObject *source,
2175 GAsyncResult *result,
2178 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2179 EmpathyAccountsDialog *dialog = user_data;
2180 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2182 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2185 /* No need to update the settings if we are already preparing one */
2186 if (priv->settings_ready == NULL)
2187 accounts_dialog_update_settings (dialog, NULL);
2189 if (priv->initial_selection != NULL)
2191 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2192 g_object_unref (priv->initial_selection);
2193 priv->initial_selection = NULL;
2197 finished_loading (dialog);
2201 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2203 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2204 GList *accounts, *l;
2206 g_signal_connect (priv->account_manager, "account-validity-changed",
2207 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2209 g_signal_connect (priv->account_manager, "account-removed",
2210 G_CALLBACK (accounts_dialog_account_removed_cb),
2212 g_signal_connect (priv->account_manager, "account-enabled",
2213 G_CALLBACK (accounts_dialog_account_enabled_cb),
2215 g_signal_connect (priv->account_manager, "account-disabled",
2216 G_CALLBACK (accounts_dialog_account_disabled_cb),
2219 /* Add existing accounts */
2220 accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
2221 for (l = accounts; l; l = l->next)
2223 accounts_dialog_add_account (dialog, l->data);
2225 g_list_free_full (accounts, g_object_unref);
2227 priv->cms = empathy_connection_managers_dup_singleton ();
2229 empathy_connection_managers_prepare_async (priv->cms,
2230 accounts_dialog_cms_prepare_cb, dialog);
2232 accounts_dialog_model_select_first (dialog);
2236 accounts_dialog_manager_ready_cb (GObject *source_object,
2237 GAsyncResult *result,
2240 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2241 GError *error = NULL;
2243 if (!tp_proxy_prepare_finish (manager, result, &error))
2245 DEBUG ("Failed to prepare account manager: %s", error->message);
2246 g_error_free (error);
2250 accounts_dialog_accounts_setup (user_data);
2254 dialog_response_cb (GtkWidget *widget,
2258 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2260 if (response_id == GTK_RESPONSE_HELP)
2262 empathy_url_show (widget, "help:empathy/accounts-window");
2264 else if (response_id == GTK_RESPONSE_CLOSE ||
2265 response_id == GTK_RESPONSE_DELETE_EVENT)
2267 TpAccount *account = NULL;
2269 if (accounts_dialog_has_pending_change (dialog, &account))
2271 gchar *question_dialog_primary_text = get_dialog_primary_text (
2274 accounts_dialog_show_question_dialog (dialog,
2275 question_dialog_primary_text,
2276 _("You are about to close the window, which will discard\n"
2277 "your changes. Are you sure you want to proceed?"),
2278 G_CALLBACK (accounts_dialog_close_response_cb),
2280 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2281 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2283 g_free (question_dialog_primary_text);
2287 gtk_widget_destroy (widget);
2290 if (account != NULL)
2291 g_object_unref (account);
2296 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2298 GtkWidget *top_hbox;
2301 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2302 GtkWidget *content_area, *action_area;
2303 GtkWidget *grid, *hbox;
2305 GtkWidget *sw, *toolbar;
2306 GtkStyleContext *context;
2308 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2310 gui = empathy_builder_get_file (filename,
2311 "accounts_dialog_hbox", &top_hbox,
2312 "vbox_details", &priv->vbox_details,
2313 "alignment_settings", &priv->alignment_settings,
2314 "alignment_infobar", &priv->alignment_infobar,
2315 "treeview", &priv->treeview,
2316 "button_add", &priv->button_add,
2317 "button_remove", &priv->button_remove,
2318 "button_import", &priv->button_import,
2319 "notebook_account", &priv->notebook_account,
2320 "alignment_loading", &alig,
2322 "add_remove_toolbar", &toolbar,
2326 empathy_builder_connect (gui, dialog,
2327 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2328 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2329 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2330 "treeview", "button-press-event",
2331 accounts_dialog_treeview_button_press_event_cb,
2334 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2336 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2338 g_object_unref (gui);
2340 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2342 /* Display loading page */
2343 priv->loading = TRUE;
2345 priv->spinner = gtk_spinner_new ();
2347 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2348 gtk_widget_show (priv->spinner);
2350 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2352 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2353 NOTEBOOK_PAGE_LOADING);
2355 /* Remove button is insensitive until we have a selected account */
2356 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2358 /* Add and Import buttons and treeview are insensitive while the dialog
2360 gtk_widget_set_sensitive (priv->button_add, FALSE);
2361 gtk_widget_set_sensitive (priv->button_import, FALSE);
2362 gtk_widget_set_sensitive (priv->treeview, FALSE);
2364 if (priv->parent_window)
2365 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2366 priv->parent_window);
2368 priv->infobar = gtk_info_bar_new ();
2369 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2371 gtk_widget_show (priv->infobar);
2373 grid = gtk_grid_new ();
2374 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2376 GTK_CONTAINER (gtk_info_bar_get_content_area (
2377 GTK_INFO_BAR (priv->infobar))),
2380 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2381 GTK_ICON_SIZE_DIALOG);
2382 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2383 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2386 priv->label_name = gtk_label_new (NULL);
2387 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2390 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2391 gtk_widget_set_hexpand (hbox, TRUE);
2392 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2393 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2395 /* set up spinner */
2396 priv->throbber = gtk_spinner_new ();
2398 priv->image_status = gtk_image_new_from_icon_name (
2399 empathy_icon_name_for_presence (
2400 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2402 priv->label_status = gtk_label_new (NULL);
2403 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2405 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2406 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2407 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2409 /* enabled switch */
2410 priv->enabled_switch = gtk_switch_new ();
2411 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2412 g_signal_connect (priv->enabled_switch, "notify::active",
2413 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2414 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2416 gtk_widget_show_all (grid);
2418 /* Tweak the dialog */
2419 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2420 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2422 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2424 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2426 /* join the add/remove toolbar to the treeview */
2427 context = gtk_widget_get_style_context (sw);
2428 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2430 context = gtk_widget_get_style_context (toolbar);
2431 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2433 /* add dialog buttons */
2434 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2436 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2437 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2438 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2441 g_signal_connect (dialog, "response",
2442 G_CALLBACK (dialog_response_cb), dialog);
2444 g_signal_connect (dialog, "delete-event",
2445 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2449 do_dispose (GObject *obj)
2451 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2452 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2454 if (priv->user_info != NULL)
2456 empathy_user_info_apply_async ((EmpathyUserInfo *) priv->user_info,
2458 priv->user_info = NULL;
2461 if (priv->connecting_id != 0)
2463 g_source_remove (priv->connecting_id);
2464 priv->connecting_id = 0;
2467 if (priv->connectivity)
2469 g_object_unref (priv->connectivity);
2470 priv->connectivity = NULL;
2473 if (priv->account_manager != NULL)
2475 g_object_unref (priv->account_manager);
2476 priv->account_manager = NULL;
2479 if (priv->cms != NULL)
2481 g_object_unref (priv->cms);
2485 if (priv->initial_selection != NULL)
2487 g_object_unref (priv->initial_selection);
2488 priv->initial_selection = NULL;
2491 tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
2493 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2497 do_get_property (GObject *object,
2502 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2504 switch (property_id)
2507 g_value_set_object (value, priv->parent_window);
2510 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2515 do_set_property (GObject *object,
2517 const GValue *value,
2520 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2522 switch (property_id)
2525 priv->parent_window = g_value_get_object (value);
2528 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2533 do_constructed (GObject *object)
2535 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2536 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2537 GtkTreeModel *model;
2539 accounts_dialog_build_ui (dialog);
2540 accounts_dialog_model_setup (dialog);
2542 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2543 g_signal_connect (model, "row-inserted",
2544 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2545 g_signal_connect (model, "row-deleted",
2546 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2548 /* Set up signalling */
2549 priv->account_manager = tp_account_manager_dup ();
2551 tp_proxy_prepare_async (priv->account_manager, NULL,
2552 accounts_dialog_manager_ready_cb, dialog);
2554 priv->connectivity = g_network_monitor_get_default ();
2555 g_object_ref (priv->connectivity);
2559 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2561 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2562 GParamSpec *param_spec;
2564 oclass->dispose = do_dispose;
2565 oclass->constructed = do_constructed;
2566 oclass->set_property = do_set_property;
2567 oclass->get_property = do_get_property;
2569 param_spec = g_param_spec_object ("parent",
2570 "parent", "The parent window",
2572 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2573 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2575 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2579 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2581 EmpathyAccountsDialogPriv *priv;
2583 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2584 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2585 EmpathyAccountsDialogPriv);
2586 dialog->priv = priv;
2588 priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
2589 g_free, g_object_unref);
2592 /* public methods */
2595 empathy_accounts_dialog_show (GtkWindow *parent,
2596 TpAccount *selected_account)
2598 EmpathyAccountsDialog *dialog;
2599 EmpathyAccountsDialogPriv *priv;
2601 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2602 "parent", parent, NULL);
2604 priv = GET_PRIV (dialog);
2606 if (selected_account)
2608 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2609 accounts_dialog_set_selected_account (dialog, selected_account);
2611 /* save the selection to set it later when the cms
2614 priv->initial_selection = g_object_ref (selected_account);
2617 gtk_window_present (GTK_WINDOW (dialog));
2619 return GTK_WIDGET (dialog);
2629 static LaunchUOACtx *
2630 launch_uoa_ctx_new (TpAccount *account,
2635 ctx = g_slice_new0 (LaunchUOACtx);
2636 if (account != NULL)
2637 ctx->account = g_object_ref (account);
2638 ctx->if_needed = if_needed;
2644 launch_uoa_ctx_free (LaunchUOACtx *ctx)
2646 g_clear_object (&ctx->account);
2647 g_slice_free (LaunchUOACtx, ctx);
2651 am_prepare_cb (GObject *source,
2652 GAsyncResult *result,
2655 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
2656 GError *error = NULL;
2657 LaunchUOACtx *ctx = user_data;
2660 if (!tp_proxy_prepare_finish (manager, result, &error))
2662 DEBUG ("Failed to prepare account manager: %s", error->message);
2663 g_error_free (error);
2667 if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
2670 if (ctx->account != NULL)
2672 const GValue *value;
2674 value = tp_account_get_storage_identifier (ctx->account);
2676 if (G_VALUE_HOLDS_UINT (value))
2677 args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
2680 empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
2684 launch_uoa_ctx_free (ctx);
2688 launch_uoa_panel (TpAccount *selected_account,
2692 TpAccountManager *manager;
2698 manager = tp_account_manager_dup ();
2700 tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
2701 launch_uoa_ctx_new (selected_account, if_needed));
2703 g_object_unref (manager);
2706 #else /* HAVE_UOA */
2709 launch_empathy_accounts (TpAccount *selected_account,
2715 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2717 args = g_string_new (NULL);
2719 if (selected_account != NULL)
2720 g_string_append_printf (args, " --select-account=%s",
2721 tp_account_get_path_suffix (selected_account));
2724 g_string_append_printf (args, " --if-needed");
2727 g_string_append_printf (args, " --hidden");
2729 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2731 selected_account == NULL ? "<none selected>" :
2732 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2734 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2736 g_string_free (args, TRUE);
2738 #endif /* HAVE_UOA */
2741 empathy_accounts_dialog_show_application (GdkScreen *screen,
2742 TpAccount *selected_account,
2747 launch_uoa_panel (selected_account, if_needed, hidden);
2749 launch_empathy_accounts (selected_account, if_needed, hidden);
2754 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2756 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2757 gboolean result = FALSE;
2759 if (priv->setting_widget == NULL)
2762 g_object_get (priv->setting_widget,
2763 "creating-account", &result, NULL);