2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
24 * Danielle Madeley <danielle.madeley@collabora.co.uk>
33 #include <glib/gi18n-lib.h>
34 #include <dbus/dbus-glib.h>
35 #include <gio/gdesktopappinfo.h>
37 #include <telepathy-glib/account-manager.h>
38 #include <telepathy-glib/defs.h>
39 #include <telepathy-glib/util.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy/empathy-connection-managers.h>
43 #include <libempathy/empathy-pkg-kit.h>
44 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy-gtk/empathy-ui-utils.h>
47 #include <libempathy-gtk/empathy-protocol-chooser.h>
48 #include <libempathy-gtk/empathy-account-widget.h>
49 #include <libempathy-gtk/empathy-account-widget-irc.h>
50 #include <libempathy-gtk/empathy-account-widget-sip.h>
51 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
52 #include <libempathy-gtk/empathy-contact-widget.h>
53 #include <libempathy-gtk/empathy-images.h>
54 #include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
55 #include <libempathy-gtk/empathy-new-account-dialog.h>
57 #include "empathy-accounts-common.h"
58 #include "empathy-accounts-dialog.h"
59 #include "empathy-import-dialog.h"
60 #include "empathy-import-utils.h"
62 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
63 #include <libempathy/empathy-debug.h>
65 /* Flashing delay for icons (milliseconds). */
66 #define FLASH_TIMEOUT 500
68 /* The primary text of the dialog shown to the user when he is about to lose
70 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
71 _("There are unsaved modifications to your %s account.")
72 /* The primary text of the dialog shown to the user when he is about to lose
73 * an unsaved new account */
74 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
75 _("Your new account has not been saved yet.")
77 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
78 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
82 NOTEBOOK_PAGE_ACCOUNT = 0,
83 NOTEBOOK_PAGE_LOADING,
84 NOTEBOOK_PAGE_NO_PROTOCOL
88 GtkWidget *alignment_settings;
89 GtkWidget *alignment_infobar;
91 GtkWidget *vbox_details;
93 GtkWidget *label_status;
94 GtkWidget *image_status;
96 GtkWidget *enabled_switch;
99 GtkCellRenderer *name_renderer;
101 GtkWidget *button_add;
102 GtkWidget *button_remove;
103 GtkWidget *button_import;
105 GtkWidget *image_type;
106 GtkWidget *label_name;
107 GtkWidget *label_type;
108 GtkWidget *dialog_content;
110 GtkWidget *notebook_account;
114 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
115 * just its GtkWidget. It is the only reliable source we can query to know if
116 * there are any unsaved changes to the currently selected account. We can't
117 * look at the account settings because it does not contain everything that
118 * can be changed using the EmpathyAccountWidget. For instance, it does not
119 * contain the state of the "Enabled" checkbox.
121 * Even if we create it ourself, we just get a weak ref and not a strong one
122 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
123 * That's kinda ugly; cf bgo #640417.
126 EmpathyAccountWidget *setting_widget_object;
128 gboolean connecting_show;
131 gulong settings_ready_id;
132 EmpathyAccountSettings *settings_ready;
134 TpAccountManager *account_manager;
135 EmpathyConnectionManagers *cms;
136 GNetworkMonitor *connectivity;
138 GtkWindow *parent_window;
139 TpAccount *initial_selection;
141 /* Those are needed when changing the selected row. When a user selects
142 * another account and there are unsaved changes on the currently selected
143 * one, a confirmation message box is presented to him. Since his answer
144 * is retrieved asynchronously, we keep some information as member of the
145 * EmpathyAccountsDialog object. */
146 gboolean force_change_row;
147 GtkTreeRowReference *destination_row;
148 } EmpathyAccountsDialogPriv;
154 COL_ACCOUNT_SETTINGS,
162 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
163 EmpathyAccountsDialog *dialog);
165 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
167 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
168 EmpathyAccountSettings *settings);
170 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
173 static void accounts_dialog_connection_changed_cb (TpAccount *account,
177 gchar *dbus_error_name,
179 EmpathyAccountsDialog *dialog);
181 static void accounts_dialog_presence_changed_cb (TpAccount *account,
184 gchar *status_message,
185 EmpathyAccountsDialog *dialog);
187 static void accounts_dialog_model_selection_changed (
188 GtkTreeSelection *selection,
189 EmpathyAccountsDialog *dialog);
191 static gboolean accounts_dialog_has_pending_change (
192 EmpathyAccountsDialog *dialog, TpAccount **account);
195 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
196 const gchar *display_name)
199 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
201 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
202 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
208 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
209 const gchar *message)
211 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
212 gchar *message_markup;
214 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
215 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
217 gtk_widget_set_tooltip_text (priv->label_status, message);
219 g_free (message_markup);
223 accounts_dialog_enable_account_cb (GObject *object,
224 GAsyncResult *result,
227 TpAccount *account = TP_ACCOUNT (object);
228 gboolean enable = GPOINTER_TO_UINT (user_data);
229 GError *error = NULL;
230 TpAccountManager *am;
232 if (!tp_account_set_enabled_finish (account, result, &error))
234 DEBUG ("Could not enable the account: %s", error->message);
235 g_error_free (error);
239 /* tp_account_is_enabled() is not updated yet at this point */
242 am = tp_account_manager_dup ();
244 empathy_connect_new_account (account, am);
250 enable_and_connect_account (TpAccount *account,
253 tp_account_set_enabled_async (account, enable,
254 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
258 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
260 EmpathyAccountsDialog *dialog)
262 EmpathyAccountSettings *settings;
266 settings = accounts_dialog_model_get_selected_settings (dialog);
267 if (settings == NULL)
270 account = empathy_account_settings_get_account (settings);
274 enable = gtk_switch_get_active (sw);
276 enable_and_connect_account (account, enable);
280 install_haze_cb (GObject *source,
281 GAsyncResult *result,
284 GError *error = NULL;
286 if (!empathy_pkg_kit_install_packages_finish (result, &error))
288 DEBUG ("Failed to install telepathy-haze: %s", error->message);
290 g_error_free (error);
295 account_is_selected (EmpathyAccountsDialog *dialog,
298 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
299 GtkTreeSelection *selection;
302 TpAccount *selected_account;
307 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
309 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
312 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
314 if (selected_account != NULL)
315 g_object_unref (selected_account);
317 return account == selected_account;
321 account_can_be_enabled (TpAccount *account)
323 TpStorageRestrictionFlags storage_restrictions;
325 storage_restrictions = tp_account_get_storage_restrictions (account);
326 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
329 /* Butterfly accounts shouldn't be used any more */
330 if (!tp_strdiff (tp_account_get_connection_manager (account),
338 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
341 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
342 gchar *status_message = NULL;
346 gboolean account_enabled;
347 gboolean creating_account;
348 gboolean display_switch = TRUE;
350 /* do not update the infobar when the account is not selected */
351 if (!account_is_selected (dialog, account))
356 status = tp_account_get_connection_status (account, &reason);
357 presence = tp_account_get_current_presence (account, NULL, &status_message);
358 account_enabled = tp_account_is_enabled (account);
359 creating_account = FALSE;
361 if (status == TP_CONNECTION_STATUS_CONNECTED &&
362 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
363 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
364 /* If presence is Unset (CM doesn't implement SimplePresence) but we
365 * are connected, consider ourself as Available.
366 * We also check Offline because of this MC5 bug: fd.o #26060 */
367 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
369 /* set presence to offline if account is disabled
370 * (else no icon is shown in infobar)*/
371 if (!account_enabled)
372 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
374 display_switch = account_can_be_enabled (account);
378 status = TP_CONNECTION_STATUS_DISCONNECTED;
379 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
380 account_enabled = FALSE;
381 creating_account = TRUE;
384 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
385 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
387 /* update the enabled switch */
388 g_signal_handlers_block_by_func (priv->enabled_switch,
389 accounts_dialog_enable_switch_active_cb, dialog);
390 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
392 g_signal_handlers_unblock_by_func (priv->enabled_switch,
393 accounts_dialog_enable_switch_active_cb, dialog);
395 /* Display the Enable switch if account supports it */
396 gtk_widget_set_visible (priv->enabled_switch, display_switch);
402 case TP_CONNECTION_STATUS_CONNECTING:
403 accounts_dialog_status_infobar_set_message (dialog,
405 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
408 gtk_spinner_start (GTK_SPINNER (priv->throbber));
409 gtk_widget_show (priv->throbber);
410 gtk_widget_hide (priv->image_status);
412 case TP_CONNECTION_STATUS_CONNECTED:
413 if (g_strcmp0 (status_message, "") == 0)
417 message = g_strdup_printf ("%s",
418 empathy_presence_get_default_message (presence));
420 accounts_dialog_status_infobar_set_message (dialog, message);
427 message = g_strdup_printf ("%s — %s",
428 empathy_presence_get_default_message (presence),
431 accounts_dialog_status_infobar_set_message (dialog, message);
434 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
437 gtk_widget_show (priv->image_status);
438 gtk_widget_hide (priv->throbber);
440 case TP_CONNECTION_STATUS_DISCONNECTED:
441 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
445 message = g_strdup_printf (_("Offline — %s"),
446 empathy_account_get_error_message (account, NULL));
447 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
448 GTK_MESSAGE_WARNING);
450 accounts_dialog_status_infobar_set_message (dialog, message);
457 message = g_strdup_printf (_("Disconnected — %s"),
458 empathy_account_get_error_message (account, NULL));
459 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
462 accounts_dialog_status_infobar_set_message (dialog, message);
466 if (!g_network_monitor_get_network_available (priv->connectivity))
467 accounts_dialog_status_infobar_set_message (dialog,
468 _("Offline — No Network Connection"));
470 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
471 gtk_widget_show (priv->image_status);
472 gtk_widget_hide (priv->throbber);
475 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
476 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
477 GTK_MESSAGE_WARNING);
479 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
480 gtk_widget_hide (priv->image_status);
481 gtk_widget_hide (priv->throbber);
486 if (!tp_strdiff (tp_account_get_connection_manager (account),
489 const gchar *packages[] = { "telepathy-haze", NULL };
491 accounts_dialog_status_infobar_set_message (dialog,
492 _("This account has been disabled because it relies on an old, "
493 "unsupported backend. Please install telepathy-haze and "
494 "restart your session to migrate the account."));
496 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
497 install_haze_cb, NULL);
501 accounts_dialog_status_infobar_set_message (dialog,
502 _("Offline — Account Disabled"));
505 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
506 GTK_MESSAGE_WARNING);
507 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
508 gtk_widget_show (priv->image_status);
509 gtk_widget_hide (priv->throbber);
512 gtk_widget_show (priv->label_status);
514 if (!creating_account)
515 gtk_widget_show (priv->infobar);
517 gtk_widget_hide (priv->infobar);
519 g_free (status_message);
523 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
527 GtkTreeSelection *selection;
529 EmpathyAccountSettings *settings;
531 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
533 view = GTK_TREE_VIEW (priv->treeview);
534 selection = gtk_tree_view_get_selection (view);
536 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
539 gtk_tree_model_get (model, &iter,
540 COL_ACCOUNT_SETTINGS, &settings,
541 COL_ACCOUNT, &account, -1);
543 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
547 /* We were creating an account. We remove the selected row */
548 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
552 /* We were modifying an account. We discard the changes by reloading the
553 * settings and the UI. */
554 accounts_dialog_update_settings (dialog, settings);
555 g_object_unref (account);
558 gtk_widget_set_sensitive (priv->treeview, TRUE);
559 gtk_widget_set_sensitive (priv->button_add, TRUE);
560 gtk_widget_set_sensitive (priv->button_remove, TRUE);
561 gtk_widget_set_sensitive (priv->button_import, TRUE);
563 if (settings != NULL)
564 g_object_unref (settings);
568 empathy_account_dialog_widget_cancelled_cb (
569 EmpathyAccountWidget *widget_object,
570 EmpathyAccountsDialog *dialog)
572 empathy_account_dialog_cancel (dialog);
576 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
578 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
583 g_object_get (priv->setting_widget_object,
584 "creating-account", &creating, NULL);
589 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
591 if (gtk_tree_model_get_iter_first (model, &iter))
592 return gtk_tree_model_iter_next (model, &iter);
598 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
600 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
601 EmpathyAccountSettings *settings;
602 GtkWidget *subdialog, *content, *content_area, *align;
604 settings = accounts_dialog_model_get_selected_settings (dialog);
605 if (settings == NULL)
608 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
610 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
613 priv->setting_widget_object =
614 empathy_account_widget_new_for_protocol (settings, FALSE);
616 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
617 (gpointer *) &priv->setting_widget_object);
619 if (accounts_dialog_has_valid_accounts (dialog))
620 empathy_account_widget_set_other_accounts_exist (
621 priv->setting_widget_object, TRUE);
623 content = empathy_account_widget_get_widget (priv->setting_widget_object);
625 g_signal_connect (priv->setting_widget_object, "cancelled",
626 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
628 g_signal_connect_swapped (priv->setting_widget_object, "close",
629 G_CALLBACK (gtk_widget_destroy), subdialog);
631 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
633 align = gtk_alignment_new (0.5, 0.5, 1, 1);
634 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
636 gtk_container_add (GTK_CONTAINER (align), content);
637 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
639 gtk_widget_show (content);
640 gtk_widget_show (align);
641 gtk_widget_show (subdialog);
645 start_external_app (GAppInfo *app_info)
647 GError *error = NULL;
648 GdkAppLaunchContext *context = NULL;
651 display = gdk_display_get_default ();
652 context = gdk_display_get_app_launch_context (display);
654 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
657 g_critical ("Failed to bisho: %s", error->message);
658 g_clear_error (&error);
661 tp_clear_object (&context);
665 use_external_storage_provider (EmpathyAccountsDialog *self,
668 const gchar *provider;
670 provider = tp_account_get_storage_provider (account);
671 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
673 GDesktopAppInfo *desktop_info;
676 GError *error = NULL;
678 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
679 if (desktop_info == NULL)
681 g_critical ("Could not locate 'gnome-control-center.desktop'");
685 /* glib doesn't have API to start a desktop file with args... (#637875) */
686 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
687 (GAppInfo *) desktop_info));
689 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
691 if (app_info == NULL)
693 DEBUG ("Failed to create app info: %s", error->message);
694 g_error_free (error);
698 start_external_app (app_info);
699 g_object_unref (app_info);
702 g_object_unref (desktop_info);
706 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
708 GDesktopAppInfo *desktop_info;
710 desktop_info = g_desktop_app_info_new (
711 "gnome-online-accounts-panel.desktop");
712 if (desktop_info == NULL)
714 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
718 start_external_app (G_APP_INFO (desktop_info));
719 g_object_unref (desktop_info);
726 DEBUG ("Don't know how to handle %s", provider);
732 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
735 EmpathyAccountSettings *settings;
737 TpStorageRestrictionFlags storage_restrictions;
739 settings = accounts_dialog_model_get_selected_settings (dialog);
740 if (settings == NULL)
743 account = empathy_account_settings_get_account (settings);
744 g_return_if_fail (account != NULL);
746 storage_restrictions = tp_account_get_storage_restrictions (account);
748 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
749 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
751 DEBUG ("Account is provided by an external storage provider");
753 use_external_storage_provider (dialog, account);
757 account_dialog_create_edit_params_dialog (dialog);
762 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
765 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
766 GtkWidget *infobar, *label;
768 infobar = gtk_info_bar_new ();
772 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
773 label = gtk_label_new (_("Failed to retrieve your personal information "
774 "from the server."));
778 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
779 label = gtk_label_new (_("Go online to edit your personal information."));
783 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
785 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
786 gtk_widget_show_all (infobar);
790 account_dialog_got_self_contact (TpConnection *conn,
791 EmpathyContact *contact,
792 const GError *in_error,
796 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
797 GtkWidget *editor, *alig;
799 if (in_error != NULL)
801 DEBUG ("Failed to get self-contact: %s", in_error->message);
802 account_dialog_show_contact_details_failed (
803 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
807 alig = gtk_alignment_new (0.5, 0, 1, 1);
809 /* create the contact info editor for this account */
810 editor = empathy_contact_widget_new (contact,
811 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
812 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
813 EMPATHY_CONTACT_WIDGET_NO_STATUS |
814 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS |
815 EMPATHY_CONTACT_WIDGET_NO_ACCOUNT);
817 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
818 gtk_container_add (GTK_CONTAINER (alig), editor);
819 gtk_widget_show (alig);
820 gtk_widget_show (editor);
824 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
825 EmpathyAccountSettings *settings)
827 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
828 const gchar *icon_name;
830 TpConnection *conn = NULL;
831 GtkWidget *bbox, *button;
833 account = empathy_account_settings_get_account (settings);
835 // if (priv->setting_widget_object != NULL)
836 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
837 // (gpointer *) &priv->setting_widget_object);
839 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
840 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
841 priv->dialog_content);
842 gtk_widget_show (priv->dialog_content);
844 /* request the self contact */
846 conn = tp_account_get_connection (account);
849 tp_proxy_get_invalidated (conn) == NULL)
851 empathy_tp_contact_factory_get_from_handle (conn,
852 tp_connection_get_self_handle (conn),
853 account_dialog_got_self_contact,
854 NULL, NULL, G_OBJECT (dialog));
858 account_dialog_show_contact_details_failed (dialog, FALSE);
861 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
862 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
863 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
864 gtk_widget_show (bbox);
866 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
867 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
868 gtk_widget_show (button);
869 g_signal_connect_swapped (button, "clicked",
870 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
872 icon_name = empathy_account_settings_get_icon_name (settings);
874 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
876 /* show the default icon; keep this in sync with the default
877 * one in empathy-accounts-dialog.ui.
879 icon_name = GTK_STOCK_CUT;
881 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
882 icon_name, GTK_ICON_SIZE_DIALOG);
883 gtk_widget_set_tooltip_text (priv->image_type,
884 empathy_protocol_name_to_display_name
885 (empathy_account_settings_get_protocol (settings)));
886 gtk_widget_show (priv->image_type);
888 accounts_dialog_update_name_label (dialog,
889 empathy_account_settings_get_display_name (settings));
891 accounts_dialog_update_status_infobar (dialog, account);
895 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
897 EmpathyAccountsDialog *dialog)
899 if (empathy_account_settings_is_ready (settings))
900 account_dialog_create_dialog_content (dialog, settings);
904 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
908 GtkTreeSelection *selection;
910 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
913 view = GTK_TREE_VIEW (priv->treeview);
914 model = gtk_tree_view_get_model (view);
916 if (gtk_tree_model_get_iter_first (model, &iter))
918 selection = gtk_tree_view_get_selection (view);
919 gtk_tree_selection_select_iter (selection, &iter);
923 accounts_dialog_update_settings (dialog, NULL);
928 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
933 GtkTreeSelection *selection;
934 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
936 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
938 if (gtk_tree_selection_get_selected (selection, &model, &iter))
939 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
941 return priv->setting_widget_object != NULL
942 && empathy_account_widget_contains_pending_changes (
943 priv->setting_widget_object);
947 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
948 const gchar *primary_text,
949 const gchar *secondary_text,
950 GCallback response_callback,
952 const gchar *first_button_text,
956 GtkWidget *message_dialog;
957 const gchar *button_text;
959 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
960 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
961 GTK_MESSAGE_QUESTION,
965 gtk_message_dialog_format_secondary_text (
966 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
968 va_start (button_args, first_button_text);
969 for (button_text = first_button_text;
971 button_text = va_arg (button_args, const gchar *))
974 response_id = va_arg (button_args, gint);
976 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
979 va_end (button_args);
981 g_signal_connect (message_dialog, "response", response_callback, user_data);
983 gtk_widget_show (message_dialog);
987 get_dialog_primary_text (TpAccount *account)
991 /* Existing account */
992 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
993 tp_account_get_display_name (account));
997 /* Newly created account */
998 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
1003 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
1004 EmpathyAccountsDialog *self)
1009 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
1010 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
1012 response = gtk_dialog_run (GTK_DIALOG (dialog));
1014 if (response == GTK_RESPONSE_OK)
1016 EmpathyAccountSettings *settings;
1019 settings = empathy_new_account_dialog_get_settings (
1020 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
1022 /* The newly created account has already been added by
1023 * accounts_dialog_account_validity_changed_cb so we just
1024 * have to select it. */
1025 account = empathy_account_settings_get_account (settings);
1026 accounts_dialog_model_set_selected (self, account);
1029 gtk_widget_destroy (dialog);
1033 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
1034 EmpathyAccountSettings *settings)
1036 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1038 if (priv->settings_ready != NULL)
1040 g_signal_handler_disconnect (priv->settings_ready,
1041 priv->settings_ready_id);
1042 priv->settings_ready = NULL;
1043 priv->settings_ready_id = 0;
1049 GtkTreeModel *model;
1050 GtkTreeSelection *selection;
1052 view = GTK_TREE_VIEW (priv->treeview);
1053 model = gtk_tree_view_get_model (view);
1054 selection = gtk_tree_view_get_selection (view);
1056 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
1058 /* We have configured accounts, select the first one if there
1059 * is no other account selected already. */
1060 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
1061 accounts_dialog_model_select_first (dialog);
1066 /* No account and no profile, warn the user */
1067 gtk_widget_hide (priv->vbox_details);
1068 gtk_widget_set_sensitive (priv->button_add, FALSE);
1070 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
1071 NOTEBOOK_PAGE_NO_PROTOCOL);
1075 /* We have an account selected, destroy old settings and create a new
1076 * one for the account selected */
1077 gtk_widget_show (priv->vbox_details);
1079 if (priv->dialog_content)
1081 gtk_widget_destroy (priv->dialog_content);
1082 priv->dialog_content = NULL;
1085 if (empathy_account_settings_is_ready (settings))
1087 account_dialog_create_dialog_content (dialog, settings);
1091 priv->settings_ready = settings;
1092 priv->settings_ready_id =
1093 g_signal_connect (settings, "notify::ready",
1094 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1100 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1101 GtkCellEditable *editable,
1103 EmpathyAccountsDialog *dialog)
1105 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1107 if (priv->connecting_id)
1108 g_source_remove (priv->connecting_id);
1110 DEBUG ("Editing account name started; stopping flashing");
1113 static const gchar *
1114 get_status_icon_for_account (EmpathyAccountsDialog *self,
1117 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1118 TpConnectionStatus status;
1119 TpConnectionStatusReason reason;
1120 TpConnectionPresenceType presence;
1122 if (account == NULL)
1123 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1125 if (!tp_account_is_enabled (account))
1126 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1128 status = tp_account_get_connection_status (account, &reason);
1130 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1132 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1133 /* An error occured */
1134 return GTK_STOCK_DIALOG_ERROR;
1136 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1138 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1140 /* Account is connecting. Display a blinking account alternating between
1141 * the offline icon and the requested presence. */
1142 if (priv->connecting_show)
1143 presence = tp_account_get_requested_presence (account, NULL, NULL);
1145 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1149 /* status == TP_CONNECTION_STATUS_CONNECTED */
1150 presence = tp_account_get_current_presence (account, NULL, NULL);
1152 /* If presence is Unset (CM doesn't implement SimplePresence),
1153 * display the 'available' icon.
1154 * We also check Offline because of this MC5 bug: fd.o #26060 */
1155 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1156 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1157 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1160 return empathy_icon_name_for_presence (presence);
1164 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1165 GtkCellRenderer *cell,
1166 GtkTreeModel *model,
1168 EmpathyAccountsDialog *dialog)
1172 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1175 "icon-name", get_status_icon_for_account (dialog, account),
1178 if (account != NULL)
1179 g_object_unref (account);
1183 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1184 GtkCellRenderer *cell,
1185 GtkTreeModel *model,
1187 EmpathyAccountsDialog *dialog)
1189 EmpathyAccountSettings *settings;
1192 TpConnectionStatus status;
1194 gtk_tree_model_get (model, iter,
1195 COL_STATUS, &status,
1196 COL_ACCOUNT_SETTINGS, &settings,
1199 icon_name = empathy_account_settings_get_icon_name (settings);
1200 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1207 g_object_unref (settings);
1210 g_object_unref (pixbuf);
1214 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1221 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1223 if (account == NULL)
1226 if (tp_account_get_connection_status (account, NULL) ==
1227 TP_CONNECTION_STATUS_CONNECTING)
1229 /* Only update the row where we have a connecting account as that's the
1230 * ones having a blinking icon. */
1231 gtk_tree_model_row_changed (model, path, iter);
1234 g_object_unref (account);
1239 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1242 GtkTreeModel *model;
1243 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1245 priv->connecting_show = !priv->connecting_show;
1247 view = GTK_TREE_VIEW (priv->treeview);
1248 model = gtk_tree_view_get_model (view);
1250 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1256 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1259 EmpathyAccountsDialog *dialog)
1261 EmpathyAccountSettings *settings;
1262 GtkTreeModel *model;
1263 GtkTreePath *treepath;
1265 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1266 gboolean connecting;
1268 empathy_account_manager_get_accounts_connected (&connecting);
1272 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1273 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1277 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1278 treepath = gtk_tree_path_new_from_string (path);
1279 gtk_tree_model_get_iter (model, &iter, treepath);
1280 gtk_tree_model_get (model, &iter,
1281 COL_ACCOUNT_SETTINGS, &settings,
1283 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1286 gtk_tree_path_free (treepath);
1288 empathy_account_settings_set_display_name_async (settings, new_text,
1290 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1291 g_object_unref (settings);
1295 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1300 GtkTreeModel *model;
1302 GtkTreeSelection *selection;
1303 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1304 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1306 if (response_id == GTK_RESPONSE_YES)
1308 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1310 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1313 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1315 if (account != NULL)
1317 tp_account_remove_async (account, NULL, NULL);
1318 g_object_unref (account);
1322 /* No need to call accounts_dialog_model_selection_changed while
1323 * removing as we are going to call accounts_dialog_model_select_first
1324 * right after which will update the selection. */
1325 g_signal_handlers_block_by_func (selection,
1326 accounts_dialog_model_selection_changed, account_dialog);
1328 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1330 g_signal_handlers_unblock_by_func (selection,
1331 accounts_dialog_model_selection_changed, account_dialog);
1333 accounts_dialog_model_select_first (account_dialog);
1336 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1340 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1343 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1345 GtkTreeModel *model;
1346 gchar *question_dialog_primary_text;
1348 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1350 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1352 if (account == NULL || !tp_account_is_valid (account))
1354 if (account != NULL)
1355 g_object_unref (account);
1356 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1357 accounts_dialog_model_select_first (dialog);
1361 question_dialog_primary_text = g_strdup_printf (
1362 _("Do you want to remove %s from your computer?"),
1363 tp_account_get_display_name (account));
1365 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1366 _("This will not remove your account on the server."),
1367 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1369 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1370 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1372 g_free (question_dialog_primary_text);
1373 g_object_unref (account);
1377 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1378 EmpathyAccountsDialog *dialog)
1380 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1382 GtkTreeSelection *selection;
1385 view = GTK_TREE_VIEW (priv->treeview);
1386 selection = gtk_tree_view_get_selection (view);
1387 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1390 accounts_dialog_remove_account_iter (dialog, &iter);
1394 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1397 GtkTreeViewColumn *column;
1398 GtkCellRenderer *cell;
1399 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1401 view = GTK_TREE_VIEW (priv->treeview);
1402 gtk_tree_view_set_headers_visible (view, FALSE);
1404 /* Account column */
1405 column = gtk_tree_view_column_new ();
1406 gtk_tree_view_column_set_expand (column, TRUE);
1407 gtk_tree_view_append_column (view, column);
1409 /* Status icon renderer */
1410 cell = gtk_cell_renderer_pixbuf_new ();
1411 gtk_tree_view_column_pack_start (column, cell, FALSE);
1412 gtk_tree_view_column_set_cell_data_func (column, cell,
1413 (GtkTreeCellDataFunc)
1414 accounts_dialog_model_status_pixbuf_data_func,
1418 /* Protocol icon renderer */
1419 cell = gtk_cell_renderer_pixbuf_new ();
1420 gtk_tree_view_column_pack_start (column, cell, FALSE);
1421 gtk_tree_view_column_set_cell_data_func (column, cell,
1422 (GtkTreeCellDataFunc)
1423 accounts_dialog_model_protocol_pixbuf_data_func,
1428 priv->name_renderer = gtk_cell_renderer_text_new ();
1429 g_object_set (priv->name_renderer,
1430 "ellipsize", PANGO_ELLIPSIZE_END,
1434 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1435 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1437 g_signal_connect (priv->name_renderer, "edited",
1438 G_CALLBACK (accounts_dialog_name_edited_cb),
1440 g_signal_connect (priv->name_renderer, "editing-started",
1441 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1443 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1446 static EmpathyAccountSettings *
1447 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1450 GtkTreeModel *model;
1451 GtkTreeSelection *selection;
1453 EmpathyAccountSettings *settings;
1454 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1456 view = GTK_TREE_VIEW (priv->treeview);
1457 selection = gtk_tree_view_get_selection (view);
1459 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1462 gtk_tree_model_get (model, &iter,
1463 COL_ACCOUNT_SETTINGS, &settings, -1);
1469 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1470 EmpathyAccountsDialog *dialog)
1472 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1473 EmpathyAccountSettings *settings;
1474 GtkTreeModel *model;
1476 gboolean is_selection;
1477 gboolean creating = FALSE;
1479 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1481 settings = accounts_dialog_model_get_selected_settings (dialog);
1482 accounts_dialog_update_settings (dialog, settings);
1484 if (settings != NULL)
1485 g_object_unref (settings);
1487 if (priv->setting_widget_object != NULL)
1489 g_object_get (priv->setting_widget_object,
1490 "creating-account", &creating, NULL);
1493 /* Update remove button sensitivity */
1494 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1499 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1501 gpointer *user_data)
1503 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1504 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1506 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1508 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1510 /* The user wants to lose unsaved changes to the currently selected
1511 * account and select another account. We discard the changes and
1512 * select the other account. */
1514 GtkTreeSelection *selection;
1516 priv->force_change_row = TRUE;
1517 empathy_account_widget_discard_pending_changes (
1518 priv->setting_widget_object);
1520 path = gtk_tree_row_reference_get_path (priv->destination_row);
1521 selection = gtk_tree_view_get_selection (
1522 GTK_TREE_VIEW (priv->treeview));
1526 /* This will trigger a call to
1527 * accounts_dialog_account_selection_change() */
1528 gtk_tree_selection_select_path (selection, path);
1529 gtk_tree_path_free (path);
1532 gtk_tree_row_reference_free (priv->destination_row);
1536 priv->force_change_row = FALSE;
1541 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1542 GtkTreeModel *model,
1544 gboolean path_currently_selected,
1547 TpAccount *account = NULL;
1548 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1549 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1552 if (priv->force_change_row)
1554 /* We came back here because the user wants to discard changes to his
1555 * modified account. The changes have already been discarded so we
1556 * just change the selected row. */
1557 priv->force_change_row = FALSE;
1561 if (accounts_dialog_has_pending_change (dialog, &account))
1563 /* The currently selected account has some unsaved changes. We ask
1564 * the user if he really wants to lose his changes and select another
1566 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1567 priv->destination_row = gtk_tree_row_reference_new (model, path);
1569 accounts_dialog_show_question_dialog (dialog,
1570 question_dialog_primary_text,
1571 _("You are about to select another account, which will discard\n"
1572 "your changes. Are you sure you want to proceed?"),
1573 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1575 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1576 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1578 g_free (question_dialog_primary_text);
1586 if (account != NULL)
1587 g_object_unref (account);
1593 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1595 GtkListStore *store;
1596 GtkTreeSelection *selection;
1597 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1599 store = gtk_list_store_new (COL_COUNT,
1600 G_TYPE_STRING, /* name */
1601 G_TYPE_UINT, /* status */
1602 TP_TYPE_ACCOUNT, /* account */
1603 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1605 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1606 GTK_TREE_MODEL (store));
1608 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1609 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1610 gtk_tree_selection_set_select_function (selection,
1611 accounts_dialog_account_selection_change, dialog, NULL);
1613 g_signal_connect (selection, "changed",
1614 G_CALLBACK (accounts_dialog_model_selection_changed),
1617 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1618 COL_NAME, GTK_SORT_ASCENDING);
1620 accounts_dialog_model_add_columns (dialog);
1622 g_object_unref (store);
1626 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1631 GtkTreeModel *model;
1633 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1635 /* Update the status in the model */
1636 view = GTK_TREE_VIEW (priv->treeview);
1637 model = gtk_tree_view_get_model (view);
1639 for (ok = gtk_tree_model_get_iter_first (model, iter);
1641 ok = gtk_tree_model_iter_next (model, iter))
1643 TpAccount *this_account;
1646 gtk_tree_model_get (model, iter,
1647 COL_ACCOUNT, &this_account,
1650 equal = (this_account == account);
1651 g_object_unref (this_account);
1661 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1664 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1665 GtkTreeSelection *selection;
1667 GtkTreeModel *model;
1669 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1671 gtk_tree_selection_select_iter (selection, iter);
1673 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1674 path = gtk_tree_model_get_path (model, iter);
1676 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1679 gtk_tree_path_free (path);
1683 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1688 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1689 select_and_scroll_to_iter (dialog, &iter);
1693 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1698 enabled = tp_account_is_enabled (account);
1700 enable_and_connect_account (account, !enabled);
1704 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1705 EmpathyAccountsDialog *self)
1707 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1710 GtkTreeSelection *selection;
1711 GtkTreeModel *model;
1713 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1714 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1716 path = gtk_tree_model_get_path (model, &iter);
1718 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1720 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1721 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1722 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1724 gtk_tree_path_free (path);
1728 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1729 GdkEventButton *event,
1730 EmpathyAccountsDialog *dialog)
1732 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1733 TpAccount *account = NULL;
1734 GtkTreeModel *model = NULL;
1735 GtkTreePath *path = NULL;
1740 /* ignore multiple clicks */
1741 if (event->type != GDK_BUTTON_PRESS)
1744 if (event->button != 3)
1747 /* Selection is not yet set, so we have to get account from event position */
1748 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1749 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1750 event->x, event->y, &path, NULL, NULL, NULL))
1753 if (!gtk_tree_model_get_iter (model, &iter, path))
1756 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1758 /* Create the menu */
1759 menu = empathy_context_menu_new (GTK_WIDGET (view));
1761 /* Menu item: to enabled/disable the account */
1762 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1764 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1766 if (account_can_be_enabled (account))
1770 active = tp_account_is_enabled (account);
1771 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1774 tp_g_signal_connect_object (item, "activate",
1775 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1779 gtk_widget_set_sensitive (item, FALSE);
1782 gtk_widget_show (item);
1784 /* Menu item: Rename */
1785 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1786 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1788 tp_g_signal_connect_object (item, "activate",
1789 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1791 gtk_widget_show (item);
1793 /* FIXME: Add here presence items, to be able to set per-account presence */
1796 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1797 event->button, event->time);
1800 tp_clear_object (&account);
1801 gtk_tree_path_free (path);
1807 reload_account_widget (EmpathyAccountsDialog *self)
1809 EmpathyAccountSettings *settings;
1811 settings = accounts_dialog_model_get_selected_settings (self);
1812 accounts_dialog_update_settings (self, settings);
1816 accounts_dialog_connection_changed_cb (TpAccount *account,
1820 gchar *dbus_error_name,
1821 GHashTable *details,
1822 EmpathyAccountsDialog *dialog)
1824 GtkTreeModel *model;
1827 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1829 /* Update the status-infobar in the details view */
1830 accounts_dialog_update_status_infobar (dialog, account);
1832 /* Update the status in the model */
1833 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1835 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1839 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1840 COL_STATUS, current,
1843 path = gtk_tree_model_get_path (model, &iter);
1844 gtk_tree_model_row_changed (model, path, &iter);
1845 gtk_tree_path_free (path);
1848 empathy_account_manager_get_accounts_connected (&found);
1850 if (!found && priv->connecting_id)
1852 g_source_remove (priv->connecting_id);
1853 priv->connecting_id = 0;
1856 if (found && !priv->connecting_id)
1857 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1858 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1863 update_account_in_treeview (EmpathyAccountsDialog *self,
1866 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1868 GtkTreeModel *model;
1870 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1871 if (accounts_dialog_get_account_iter (self, account, &iter))
1875 path = gtk_tree_model_get_path (model, &iter);
1876 gtk_tree_model_row_changed (model, path, &iter);
1877 gtk_tree_path_free (path);
1882 accounts_dialog_presence_changed_cb (TpAccount *account,
1885 gchar *status_message,
1886 EmpathyAccountsDialog *dialog)
1888 /* Update the status-infobar in the details view */
1889 accounts_dialog_update_status_infobar (dialog, account);
1891 update_account_in_treeview (dialog, account);
1895 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1899 const gchar *display_name;
1901 GtkTreeModel *model;
1902 EmpathyAccountSettings *settings;
1903 TpAccount *selected_account;
1904 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1905 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1907 display_name = tp_account_get_display_name (account);
1908 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1909 settings = accounts_dialog_model_get_selected_settings (dialog);
1910 if (settings == NULL)
1913 selected_account = empathy_account_settings_get_account (settings);
1915 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1917 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1918 COL_NAME, display_name,
1922 if (selected_account == account)
1923 accounts_dialog_update_name_label (dialog, display_name);
1925 g_object_unref (settings);
1929 conn_prepare_cb (GObject *source,
1930 GAsyncResult *result,
1933 EmpathyAccountsDialog *self = user_data;
1935 reload_account_widget (self);
1939 accounts_dialog_notify_connection_cb (TpAccount *account,
1941 EmpathyAccountsDialog *self)
1944 if (!account_is_selected (self, account))
1947 conn = tp_account_get_connection (account);
1950 reload_account_widget (self);
1954 /* Wait for this feature so TpConnection will have fetch the
1956 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1958 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1963 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1966 EmpathyAccountSettings *settings;
1967 GtkTreeModel *model;
1969 TpConnectionStatus status;
1971 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1972 gboolean selected = FALSE;
1973 GtkTreeSelection *selection;
1975 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1976 status = tp_account_get_connection_status (account, NULL);
1977 name = tp_account_get_display_name (account);
1979 settings = empathy_account_settings_new_for_account (account);
1981 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1983 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1985 /* Select the account if it's the first added */
1986 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1989 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1992 COL_ACCOUNT, account,
1993 COL_ACCOUNT_SETTINGS, settings,
1998 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
2000 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
2003 COL_ACCOUNT, account,
2004 COL_ACCOUNT_SETTINGS, settings,
2010 /* We just modified the selected account. Its display name may have been
2011 * changed and so it's place in the treeview. Scroll to it so it stays
2013 select_and_scroll_to_iter (dialog, &iter);
2016 accounts_dialog_connection_changed_cb (account,
2019 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
2024 tp_g_signal_connect_object (account, "notify::display-name",
2025 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
2028 tp_g_signal_connect_object (account, "status-changed",
2029 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
2030 tp_g_signal_connect_object (account, "presence-changed",
2031 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
2032 tp_g_signal_connect_object (account, "notify::connection",
2033 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
2035 g_object_unref (settings);
2039 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
2042 EmpathyAccountsDialog *dialog)
2044 accounts_dialog_add_account (dialog, account);
2048 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
2051 EmpathyAccountsDialog *dialog)
2053 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2055 if (priv->setting_widget_object != NULL &&
2056 accounts_dialog_has_valid_accounts (dialog))
2058 empathy_account_widget_set_other_accounts_exist (
2059 priv->setting_widget_object, TRUE);
2064 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
2066 EmpathyAccountsDialog *dialog)
2068 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2070 if (priv->setting_widget_object != NULL &&
2071 !accounts_dialog_has_valid_accounts (dialog))
2073 empathy_account_widget_set_other_accounts_exist (
2074 priv->setting_widget_object, FALSE);
2079 accounts_dialog_account_removed_cb (TpAccountManager *manager,
2081 EmpathyAccountsDialog *dialog)
2084 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2086 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2088 gtk_list_store_remove (GTK_LIST_STORE (
2089 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
2094 enable_or_disable_account (EmpathyAccountsDialog *dialog,
2098 /* Update the status-infobar in the details view */
2099 accounts_dialog_update_status_infobar (dialog, account);
2101 DEBUG ("Account %s is now %s",
2102 tp_account_get_display_name (account),
2103 enabled ? "enabled" : "disabled");
2107 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
2109 EmpathyAccountsDialog *dialog)
2111 enable_or_disable_account (dialog, account, FALSE);
2112 update_account_in_treeview (dialog, account);
2116 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2118 EmpathyAccountsDialog *dialog)
2120 enable_or_disable_account (dialog, account, TRUE);
2124 display_import_dialog (EmpathyAccountsDialog *dialog)
2126 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2127 GtkWidget *import_dialog;
2129 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2131 gtk_widget_show (import_dialog);
2133 return import_dialog;
2137 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2138 EmpathyAccountsDialog *dialog)
2140 display_import_dialog (dialog);
2144 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2148 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2150 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2152 if (response_id == GTK_RESPONSE_YES)
2153 gtk_widget_destroy (account_dialog);
2157 accounts_dialog_delete_event_cb (GtkWidget *widget,
2159 EmpathyAccountsDialog *dialog)
2161 /* we maunally handle responses to delete events */
2166 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2171 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2172 select_and_scroll_to_iter (dialog, &iter);
2176 salut_valid_cb (GtkWidget *widget,
2180 gtk_widget_set_sensitive (button, valid);
2184 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2186 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2187 GtkWidget *dialog, *widget, *content, *button;
2190 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2191 priv->account_manager))
2194 widget = empathy_local_xmpp_assistant_widget_new ();
2195 gtk_widget_show (widget);
2197 dialog = gtk_dialog_new ();
2199 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2201 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2204 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2205 _("_Connect"), GTK_RESPONSE_YES);
2206 gtk_widget_set_sensitive (button,
2207 empathy_local_xmpp_assistant_widget_is_valid (
2208 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2210 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2213 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2214 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2216 response = gtk_dialog_run (GTK_DIALOG (dialog));
2218 if (response == GTK_RESPONSE_YES)
2220 empathy_local_xmpp_assistant_widget_create_account (
2221 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2224 gtk_widget_destroy (dialog);
2228 import_dialog_response_cb (GtkDialog *dialog,
2230 EmpathyAccountsDialog *self)
2232 maybe_show_salut_dialog (self);
2236 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2238 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2241 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2244 if (!empathy_import_accounts_to_import ())
2246 maybe_show_salut_dialog (self);
2250 dialog = display_import_dialog (self);
2252 tp_g_signal_connect_object (dialog, "response",
2253 G_CALLBACK (import_dialog_response_cb), self, 0);
2257 finished_loading (EmpathyAccountsDialog *self)
2259 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2260 GtkTreeSelection *selection;
2261 gboolean has_selected;
2263 priv->loading = FALSE;
2265 gtk_widget_set_sensitive (priv->button_add, TRUE);
2266 gtk_widget_set_sensitive (priv->button_import, TRUE);
2267 gtk_widget_set_sensitive (priv->treeview, TRUE);
2269 /* Sensitive the remove button if there is an account selected */
2270 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2271 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2272 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2274 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2275 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2276 NOTEBOOK_PAGE_ACCOUNT);
2278 maybe_show_import_dialog (self);
2282 accounts_dialog_cms_prepare_cb (GObject *source,
2283 GAsyncResult *result,
2286 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2287 EmpathyAccountsDialog *dialog = user_data;
2288 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2290 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2293 /* No need to update the settings if we are already preparing one */
2294 if (priv->settings_ready == NULL)
2295 accounts_dialog_update_settings (dialog, NULL);
2297 if (priv->initial_selection != NULL)
2299 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2300 g_object_unref (priv->initial_selection);
2301 priv->initial_selection = NULL;
2305 finished_loading (dialog);
2309 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2311 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2312 GList *accounts, *l;
2314 g_signal_connect (priv->account_manager, "account-validity-changed",
2315 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2317 g_signal_connect (priv->account_manager, "account-removed",
2318 G_CALLBACK (accounts_dialog_account_removed_cb),
2320 g_signal_connect (priv->account_manager, "account-enabled",
2321 G_CALLBACK (accounts_dialog_account_enabled_cb),
2323 g_signal_connect (priv->account_manager, "account-disabled",
2324 G_CALLBACK (accounts_dialog_account_disabled_cb),
2327 /* Add existing accounts */
2328 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2329 for (l = accounts; l; l = l->next)
2331 accounts_dialog_add_account (dialog, l->data);
2333 g_list_free (accounts);
2335 priv->cms = empathy_connection_managers_dup_singleton ();
2337 empathy_connection_managers_prepare_async (priv->cms,
2338 accounts_dialog_cms_prepare_cb, dialog);
2340 accounts_dialog_model_select_first (dialog);
2344 accounts_dialog_manager_ready_cb (GObject *source_object,
2345 GAsyncResult *result,
2348 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2349 GError *error = NULL;
2351 if (!tp_proxy_prepare_finish (manager, result, &error))
2353 DEBUG ("Failed to prepare account manager: %s", error->message);
2354 g_error_free (error);
2358 accounts_dialog_accounts_setup (user_data);
2362 dialog_response_cb (GtkWidget *widget,
2366 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2368 if (response_id == GTK_RESPONSE_HELP)
2370 empathy_url_show (widget, "help:empathy/accounts-window");
2372 else if (response_id == GTK_RESPONSE_CLOSE ||
2373 response_id == GTK_RESPONSE_DELETE_EVENT)
2375 TpAccount *account = NULL;
2377 if (accounts_dialog_has_pending_change (dialog, &account))
2379 gchar *question_dialog_primary_text = get_dialog_primary_text (
2382 accounts_dialog_show_question_dialog (dialog,
2383 question_dialog_primary_text,
2384 _("You are about to close the window, which will discard\n"
2385 "your changes. Are you sure you want to proceed?"),
2386 G_CALLBACK (accounts_dialog_close_response_cb),
2388 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2389 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2391 g_free (question_dialog_primary_text);
2395 gtk_widget_destroy (widget);
2398 if (account != NULL)
2399 g_object_unref (account);
2404 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2406 GtkWidget *top_hbox;
2409 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2410 GtkWidget *content_area, *action_area;
2411 GtkWidget *grid, *hbox;
2413 GtkWidget *sw, *toolbar;
2414 GtkStyleContext *context;
2416 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2418 gui = empathy_builder_get_file (filename,
2419 "accounts_dialog_hbox", &top_hbox,
2420 "vbox_details", &priv->vbox_details,
2421 "alignment_settings", &priv->alignment_settings,
2422 "alignment_infobar", &priv->alignment_infobar,
2423 "treeview", &priv->treeview,
2424 "button_add", &priv->button_add,
2425 "button_remove", &priv->button_remove,
2426 "button_import", &priv->button_import,
2427 "notebook_account", &priv->notebook_account,
2428 "alignment_loading", &alig,
2430 "add_remove_toolbar", &toolbar,
2434 empathy_builder_connect (gui, dialog,
2435 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2436 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2437 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2438 "treeview", "button-press-event",
2439 accounts_dialog_treeview_button_press_event_cb,
2442 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2444 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2446 g_object_unref (gui);
2448 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2450 /* Display loading page */
2451 priv->loading = TRUE;
2453 priv->spinner = gtk_spinner_new ();
2455 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2456 gtk_widget_show (priv->spinner);
2458 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2460 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2461 NOTEBOOK_PAGE_LOADING);
2463 /* Remove button is insensitive until we have a selected account */
2464 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2466 /* Add and Import buttons and treeview are insensitive while the dialog
2468 gtk_widget_set_sensitive (priv->button_add, FALSE);
2469 gtk_widget_set_sensitive (priv->button_import, FALSE);
2470 gtk_widget_set_sensitive (priv->treeview, FALSE);
2472 if (priv->parent_window)
2473 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2474 priv->parent_window);
2476 priv->infobar = gtk_info_bar_new ();
2477 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2479 gtk_widget_show (priv->infobar);
2481 grid = gtk_grid_new ();
2482 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2484 GTK_CONTAINER (gtk_info_bar_get_content_area (
2485 GTK_INFO_BAR (priv->infobar))),
2488 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2489 GTK_ICON_SIZE_DIALOG);
2490 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2491 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2494 priv->label_name = gtk_label_new (NULL);
2495 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2498 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2499 gtk_widget_set_hexpand (hbox, TRUE);
2500 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2501 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2503 /* set up spinner */
2504 priv->throbber = gtk_spinner_new ();
2506 priv->image_status = gtk_image_new_from_icon_name (
2507 empathy_icon_name_for_presence (
2508 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2510 priv->label_status = gtk_label_new (NULL);
2511 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2513 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2514 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2515 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2517 /* enabled switch */
2518 priv->enabled_switch = gtk_switch_new ();
2519 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2520 g_signal_connect (priv->enabled_switch, "notify::active",
2521 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2522 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2524 gtk_widget_show_all (grid);
2526 /* Tweak the dialog */
2527 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2528 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2530 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2532 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2534 /* join the add/remove toolbar to the treeview */
2535 context = gtk_widget_get_style_context (sw);
2536 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2538 context = gtk_widget_get_style_context (toolbar);
2539 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2541 /* add dialog buttons */
2542 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2544 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2545 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2546 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2549 g_signal_connect (dialog, "response",
2550 G_CALLBACK (dialog_response_cb), dialog);
2552 g_signal_connect (dialog, "delete-event",
2553 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2557 do_dispose (GObject *obj)
2559 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2560 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2562 if (priv->connecting_id != 0)
2564 g_source_remove (priv->connecting_id);
2565 priv->connecting_id = 0;
2568 if (priv->connectivity)
2570 g_object_unref (priv->connectivity);
2571 priv->connectivity = NULL;
2574 if (priv->account_manager != NULL)
2576 g_object_unref (priv->account_manager);
2577 priv->account_manager = NULL;
2580 if (priv->cms != NULL)
2582 g_object_unref (priv->cms);
2586 if (priv->initial_selection != NULL)
2588 g_object_unref (priv->initial_selection);
2589 priv->initial_selection = NULL;
2592 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2596 do_get_property (GObject *object,
2601 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2603 switch (property_id)
2606 g_value_set_object (value, priv->parent_window);
2609 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2614 do_set_property (GObject *object,
2616 const GValue *value,
2619 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2621 switch (property_id)
2624 priv->parent_window = g_value_get_object (value);
2627 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2632 do_constructed (GObject *object)
2634 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2635 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2636 GtkTreeModel *model;
2638 accounts_dialog_build_ui (dialog);
2639 accounts_dialog_model_setup (dialog);
2641 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2642 g_signal_connect (model, "row-inserted",
2643 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2644 g_signal_connect (model, "row-deleted",
2645 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2647 /* Set up signalling */
2648 priv->account_manager = tp_account_manager_dup ();
2650 tp_proxy_prepare_async (priv->account_manager, NULL,
2651 accounts_dialog_manager_ready_cb, dialog);
2653 priv->connectivity = g_network_monitor_get_default ();
2654 g_object_ref (priv->connectivity);
2658 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2660 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2661 GParamSpec *param_spec;
2663 oclass->dispose = do_dispose;
2664 oclass->constructed = do_constructed;
2665 oclass->set_property = do_set_property;
2666 oclass->get_property = do_get_property;
2668 param_spec = g_param_spec_object ("parent",
2669 "parent", "The parent window",
2671 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2672 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2674 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2678 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2680 EmpathyAccountsDialogPriv *priv;
2682 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2683 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2684 EmpathyAccountsDialogPriv);
2685 dialog->priv = priv;
2688 /* public methods */
2691 empathy_accounts_dialog_show (GtkWindow *parent,
2692 TpAccount *selected_account)
2694 EmpathyAccountsDialog *dialog;
2695 EmpathyAccountsDialogPriv *priv;
2697 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2698 "parent", parent, NULL);
2700 priv = GET_PRIV (dialog);
2702 if (selected_account)
2704 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2705 accounts_dialog_set_selected_account (dialog, selected_account);
2707 /* save the selection to set it later when the cms
2710 priv->initial_selection = g_object_ref (selected_account);
2713 gtk_window_present (GTK_WINDOW (dialog));
2715 return GTK_WIDGET (dialog);
2719 empathy_accounts_dialog_show_application (GdkScreen *screen,
2720 TpAccount *selected_account,
2726 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2728 args = g_string_new (NULL);
2730 if (selected_account != NULL)
2731 g_string_append_printf (args, " --select-account=%s",
2732 tp_account_get_path_suffix (selected_account));
2735 g_string_append_printf (args, " --if-needed");
2738 g_string_append_printf (args, " --hidden");
2740 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2742 selected_account == NULL ? "<none selected>" :
2743 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2745 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2747 g_string_free (args, TRUE);
2751 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2753 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2754 gboolean result = FALSE;
2756 if (priv->setting_widget_object == NULL)
2759 g_object_get (priv->setting_widget_object,
2760 "creating-account", &result, NULL);