2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
24 * Danielle Madeley <danielle.madeley@collabora.co.uk>
33 #include <glib/gi18n-lib.h>
34 #include <dbus/dbus-glib.h>
35 #include <gio/gdesktopappinfo.h>
37 #include <telepathy-glib/account-manager.h>
38 #include <telepathy-glib/defs.h>
39 #include <telepathy-glib/util.h>
41 #include <libempathy/empathy-utils.h>
42 #include <libempathy/empathy-connection-managers.h>
43 #include <libempathy/empathy-pkg-kit.h>
45 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include <libempathy-gtk/empathy-protocol-chooser.h>
47 #include <libempathy-gtk/empathy-account-widget.h>
48 #include <libempathy-gtk/empathy-account-widget-irc.h>
49 #include <libempathy-gtk/empathy-account-widget-sip.h>
50 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
51 #include <libempathy-gtk/empathy-contact-widget.h>
52 #include <libempathy-gtk/empathy-images.h>
53 #include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
54 #include <libempathy-gtk/empathy-new-account-dialog.h>
56 #include "empathy-accounts-common.h"
57 #include "empathy-accounts-dialog.h"
58 #include "empathy-import-dialog.h"
59 #include "empathy-import-utils.h"
61 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
62 #include <libempathy/empathy-debug.h>
64 /* Flashing delay for icons (milliseconds). */
65 #define FLASH_TIMEOUT 500
67 /* The primary text of the dialog shown to the user when he is about to lose
69 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
70 _("There are unsaved modifications to your %s account.")
71 /* The primary text of the dialog shown to the user when he is about to lose
72 * an unsaved new account */
73 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
74 _("Your new account has not been saved yet.")
76 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
77 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
81 NOTEBOOK_PAGE_ACCOUNT = 0,
82 NOTEBOOK_PAGE_LOADING,
83 NOTEBOOK_PAGE_NO_PROTOCOL
87 GtkWidget *alignment_settings;
88 GtkWidget *alignment_infobar;
90 GtkWidget *vbox_details;
92 GtkWidget *label_status;
93 GtkWidget *image_status;
95 GtkWidget *enabled_switch;
98 GtkCellRenderer *name_renderer;
100 GtkWidget *button_add;
101 GtkWidget *button_remove;
102 GtkWidget *button_import;
104 GtkWidget *image_type;
105 GtkWidget *label_name;
106 GtkWidget *label_type;
107 GtkWidget *dialog_content;
109 GtkWidget *notebook_account;
113 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
114 * just its GtkWidget. It is the only reliable source we can query to know if
115 * there are any unsaved changes to the currently selected account. We can't
116 * look at the account settings because it does not contain everything that
117 * can be changed using the EmpathyAccountWidget. For instance, it does not
118 * contain the state of the "Enabled" checkbox.
120 * Even if we create it ourself, we just get a weak ref and not a strong one
121 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
122 * That's kinda ugly; cf bgo #640417.
125 EmpathyAccountWidget *setting_widget;
127 gboolean connecting_show;
130 gulong settings_ready_id;
131 EmpathyAccountSettings *settings_ready;
133 TpAccountManager *account_manager;
134 EmpathyConnectionManagers *cms;
135 GNetworkMonitor *connectivity;
137 GtkWindow *parent_window;
138 TpAccount *initial_selection;
140 /* Those are needed when changing the selected row. When a user selects
141 * another account and there are unsaved changes on the currently selected
142 * one, a confirmation message box is presented to him. Since his answer
143 * is retrieved asynchronously, we keep some information as member of the
144 * EmpathyAccountsDialog object. */
145 gboolean force_change_row;
146 GtkTreeRowReference *destination_row;
147 } EmpathyAccountsDialogPriv;
153 COL_ACCOUNT_SETTINGS,
161 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
162 EmpathyAccountsDialog *dialog);
164 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
166 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
167 EmpathyAccountSettings *settings);
169 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
172 static void accounts_dialog_connection_changed_cb (TpAccount *account,
176 gchar *dbus_error_name,
178 EmpathyAccountsDialog *dialog);
180 static void accounts_dialog_presence_changed_cb (TpAccount *account,
183 gchar *status_message,
184 EmpathyAccountsDialog *dialog);
186 static void accounts_dialog_model_selection_changed (
187 GtkTreeSelection *selection,
188 EmpathyAccountsDialog *dialog);
190 static gboolean accounts_dialog_has_pending_change (
191 EmpathyAccountsDialog *dialog, TpAccount **account);
194 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
195 const gchar *display_name)
198 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
200 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
201 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
207 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
208 const gchar *message)
210 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
211 gchar *message_markup;
213 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
214 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
216 gtk_widget_set_tooltip_text (priv->label_status, message);
218 g_free (message_markup);
222 accounts_dialog_enable_account_cb (GObject *object,
223 GAsyncResult *result,
226 TpAccount *account = TP_ACCOUNT (object);
227 gboolean enable = GPOINTER_TO_UINT (user_data);
228 GError *error = NULL;
229 TpAccountManager *am;
231 if (!tp_account_set_enabled_finish (account, result, &error))
233 DEBUG ("Could not enable the account: %s", error->message);
234 g_error_free (error);
238 /* tp_account_is_enabled() is not updated yet at this point */
241 am = tp_account_manager_dup ();
243 empathy_connect_new_account (account, am);
249 enable_and_connect_account (TpAccount *account,
252 tp_account_set_enabled_async (account, enable,
253 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
257 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
259 EmpathyAccountsDialog *dialog)
261 EmpathyAccountSettings *settings;
265 settings = accounts_dialog_model_get_selected_settings (dialog);
266 if (settings == NULL)
269 account = empathy_account_settings_get_account (settings);
273 enable = gtk_switch_get_active (sw);
275 enable_and_connect_account (account, enable);
279 install_haze_cb (GObject *source,
280 GAsyncResult *result,
283 GError *error = NULL;
285 if (!empathy_pkg_kit_install_packages_finish (result, &error))
287 DEBUG ("Failed to install telepathy-haze: %s", error->message);
289 g_error_free (error);
294 account_is_selected (EmpathyAccountsDialog *dialog,
297 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
298 GtkTreeSelection *selection;
301 TpAccount *selected_account;
306 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
308 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
311 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
313 if (selected_account != NULL)
314 g_object_unref (selected_account);
316 return account == selected_account;
320 account_can_be_enabled (TpAccount *account)
322 TpStorageRestrictionFlags storage_restrictions;
324 storage_restrictions = tp_account_get_storage_restrictions (account);
325 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
328 /* Butterfly accounts shouldn't be used any more */
329 if (!tp_strdiff (tp_account_get_connection_manager (account),
337 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
340 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
341 gchar *status_message = NULL;
345 gboolean account_enabled;
346 gboolean creating_account;
347 gboolean display_switch = TRUE;
349 /* do not update the infobar when the account is not selected */
350 if (!account_is_selected (dialog, account))
355 status = tp_account_get_connection_status (account, &reason);
356 presence = tp_account_get_current_presence (account, NULL, &status_message);
357 account_enabled = tp_account_is_enabled (account);
358 creating_account = FALSE;
360 if (status == TP_CONNECTION_STATUS_CONNECTED &&
361 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
362 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
363 /* If presence is Unset (CM doesn't implement SimplePresence) but we
364 * are connected, consider ourself as Available.
365 * We also check Offline because of this MC5 bug: fd.o #26060 */
366 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
368 /* set presence to offline if account is disabled
369 * (else no icon is shown in infobar)*/
370 if (!account_enabled)
371 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
373 display_switch = account_can_be_enabled (account);
377 status = TP_CONNECTION_STATUS_DISCONNECTED;
378 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
379 account_enabled = FALSE;
380 creating_account = TRUE;
383 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
384 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
386 /* update the enabled switch */
387 g_signal_handlers_block_by_func (priv->enabled_switch,
388 accounts_dialog_enable_switch_active_cb, dialog);
389 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
391 g_signal_handlers_unblock_by_func (priv->enabled_switch,
392 accounts_dialog_enable_switch_active_cb, dialog);
394 /* Display the Enable switch if account supports it */
395 gtk_widget_set_visible (priv->enabled_switch, display_switch);
401 case TP_CONNECTION_STATUS_CONNECTING:
402 accounts_dialog_status_infobar_set_message (dialog,
404 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
407 gtk_spinner_start (GTK_SPINNER (priv->throbber));
408 gtk_widget_show (priv->throbber);
409 gtk_widget_hide (priv->image_status);
411 case TP_CONNECTION_STATUS_CONNECTED:
412 if (g_strcmp0 (status_message, "") == 0)
416 message = g_strdup_printf ("%s",
417 empathy_presence_get_default_message (presence));
419 accounts_dialog_status_infobar_set_message (dialog, message);
426 message = g_strdup_printf ("%s — %s",
427 empathy_presence_get_default_message (presence),
430 accounts_dialog_status_infobar_set_message (dialog, message);
433 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
436 gtk_widget_show (priv->image_status);
437 gtk_widget_hide (priv->throbber);
439 case TP_CONNECTION_STATUS_DISCONNECTED:
440 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
444 message = g_strdup_printf (_("Offline — %s"),
445 empathy_account_get_error_message (account, NULL));
446 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
447 GTK_MESSAGE_WARNING);
449 accounts_dialog_status_infobar_set_message (dialog, message);
456 message = g_strdup_printf (_("Disconnected — %s"),
457 empathy_account_get_error_message (account, NULL));
458 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
461 accounts_dialog_status_infobar_set_message (dialog, message);
465 if (!g_network_monitor_get_network_available (priv->connectivity))
466 accounts_dialog_status_infobar_set_message (dialog,
467 _("Offline — No Network Connection"));
469 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
470 gtk_widget_show (priv->image_status);
471 gtk_widget_hide (priv->throbber);
474 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
475 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
476 GTK_MESSAGE_WARNING);
478 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
479 gtk_widget_hide (priv->image_status);
480 gtk_widget_hide (priv->throbber);
485 if (!tp_strdiff (tp_account_get_connection_manager (account),
488 const gchar *packages[] = { "telepathy-haze", NULL };
490 accounts_dialog_status_infobar_set_message (dialog,
491 _("This account has been disabled because it relies on an old, "
492 "unsupported backend. Please install telepathy-haze and "
493 "restart your session to migrate the account."));
495 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
496 install_haze_cb, NULL);
500 accounts_dialog_status_infobar_set_message (dialog,
501 _("Offline — Account Disabled"));
504 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
505 GTK_MESSAGE_WARNING);
506 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
507 gtk_widget_show (priv->image_status);
508 gtk_widget_hide (priv->throbber);
511 gtk_widget_show (priv->label_status);
513 if (!creating_account)
514 gtk_widget_show (priv->infobar);
516 gtk_widget_hide (priv->infobar);
518 g_free (status_message);
522 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
526 GtkTreeSelection *selection;
528 EmpathyAccountSettings *settings;
530 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
532 view = GTK_TREE_VIEW (priv->treeview);
533 selection = gtk_tree_view_get_selection (view);
535 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
538 gtk_tree_model_get (model, &iter,
539 COL_ACCOUNT_SETTINGS, &settings,
540 COL_ACCOUNT, &account, -1);
542 empathy_account_widget_discard_pending_changes (priv->setting_widget);
546 /* We were creating an account. We remove the selected row */
547 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
551 /* We were modifying an account. We discard the changes by reloading the
552 * settings and the UI. */
553 accounts_dialog_update_settings (dialog, settings);
554 g_object_unref (account);
557 gtk_widget_set_sensitive (priv->treeview, TRUE);
558 gtk_widget_set_sensitive (priv->button_add, TRUE);
559 gtk_widget_set_sensitive (priv->button_remove, TRUE);
560 gtk_widget_set_sensitive (priv->button_import, TRUE);
562 if (settings != NULL)
563 g_object_unref (settings);
567 empathy_account_dialog_widget_cancelled_cb (
568 EmpathyAccountWidget *widget_object,
569 EmpathyAccountsDialog *dialog)
571 empathy_account_dialog_cancel (dialog);
575 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
577 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
582 g_object_get (priv->setting_widget,
583 "creating-account", &creating, NULL);
588 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
590 if (gtk_tree_model_get_iter_first (model, &iter))
591 return gtk_tree_model_iter_next (model, &iter);
597 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
599 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
600 EmpathyAccountSettings *settings;
601 GtkWidget *subdialog, *content_area, *align;
603 settings = accounts_dialog_model_get_selected_settings (dialog);
604 if (settings == NULL)
607 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
609 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
612 priv->setting_widget = (EmpathyAccountWidget *)
613 empathy_account_widget_new_for_protocol (settings, FALSE);
615 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
616 (gpointer *) &priv->setting_widget);
618 if (accounts_dialog_has_valid_accounts (dialog))
619 empathy_account_widget_set_other_accounts_exist (
620 priv->setting_widget, TRUE);
622 g_signal_connect (priv->setting_widget, "cancelled",
623 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
625 g_signal_connect_swapped (priv->setting_widget, "close",
626 G_CALLBACK (gtk_widget_destroy), subdialog);
628 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
630 align = gtk_alignment_new (0.5, 0.5, 1, 1);
631 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
633 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
634 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
636 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
637 gtk_widget_show (align);
638 gtk_widget_show (subdialog);
642 start_external_app (GAppInfo *app_info)
644 GError *error = NULL;
645 GdkAppLaunchContext *context = NULL;
648 display = gdk_display_get_default ();
649 context = gdk_display_get_app_launch_context (display);
651 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
654 g_critical ("Failed to bisho: %s", error->message);
655 g_clear_error (&error);
658 tp_clear_object (&context);
662 use_external_storage_provider (EmpathyAccountsDialog *self,
665 const gchar *provider;
667 provider = tp_account_get_storage_provider (account);
668 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
670 GDesktopAppInfo *desktop_info;
673 GError *error = NULL;
675 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
676 if (desktop_info == NULL)
678 g_critical ("Could not locate 'gnome-control-center.desktop'");
682 /* glib doesn't have API to start a desktop file with args... (#637875) */
683 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
684 (GAppInfo *) desktop_info));
686 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
688 if (app_info == NULL)
690 DEBUG ("Failed to create app info: %s", error->message);
691 g_error_free (error);
695 start_external_app (app_info);
696 g_object_unref (app_info);
699 g_object_unref (desktop_info);
703 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
705 GDesktopAppInfo *desktop_info;
707 desktop_info = g_desktop_app_info_new (
708 "gnome-online-accounts-panel.desktop");
709 if (desktop_info == NULL)
711 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
715 start_external_app (G_APP_INFO (desktop_info));
716 g_object_unref (desktop_info);
723 DEBUG ("Don't know how to handle %s", provider);
729 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
732 EmpathyAccountSettings *settings;
734 TpStorageRestrictionFlags storage_restrictions;
736 settings = accounts_dialog_model_get_selected_settings (dialog);
737 if (settings == NULL)
740 account = empathy_account_settings_get_account (settings);
741 g_return_if_fail (account != NULL);
743 storage_restrictions = tp_account_get_storage_restrictions (account);
745 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
746 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
748 DEBUG ("Account is provided by an external storage provider");
750 use_external_storage_provider (dialog, account);
754 account_dialog_create_edit_params_dialog (dialog);
759 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
762 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
763 GtkWidget *infobar, *label;
765 infobar = gtk_info_bar_new ();
769 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
770 label = gtk_label_new (_("Failed to retrieve your personal information "
771 "from the server."));
775 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
776 label = gtk_label_new (_("Go online to edit your personal information."));
780 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
782 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
783 gtk_widget_show_all (infobar);
787 create_contact_info_editor (EmpathyAccountsDialog *self,
788 TpContact *tp_contact)
790 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
791 GtkWidget *editor, *alig;
792 EmpathyContact *contact;
793 EmpathyContactWidgetFlags flags;
796 contact = empathy_contact_dup_from_tp_contact (tp_contact);
798 alig = gtk_alignment_new (0.5, 0, 1, 1);
800 flags = EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
801 EMPATHY_CONTACT_WIDGET_NO_STATUS |
802 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS |
803 EMPATHY_CONTACT_WIDGET_NO_ACCOUNT;
805 conn = tp_contact_get_connection (tp_contact);
806 if (tp_proxy_has_interface_by_id (conn,
807 TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS))
808 flags |= EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
810 /* create the contact info editor for this account */
811 editor = empathy_contact_widget_new (contact, flags);
813 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
814 gtk_container_add (GTK_CONTAINER (alig), editor);
815 gtk_widget_show (alig);
816 gtk_widget_show (editor);
817 g_object_unref (contact);
821 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
822 EmpathyAccountSettings *settings)
824 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
825 const gchar *icon_name;
827 TpConnection *conn = NULL;
828 TpContact *contact = NULL;
829 GtkWidget *bbox, *button;
831 account = empathy_account_settings_get_account (settings);
833 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
834 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
835 priv->dialog_content);
836 gtk_widget_show (priv->dialog_content);
838 /* request the self contact */
840 conn = tp_account_get_connection (account);
843 tp_proxy_get_invalidated (conn) == NULL)
845 contact = tp_connection_get_self_contact (conn);
850 create_contact_info_editor (dialog, contact);
854 account_dialog_show_contact_details_failed (dialog, FALSE);
857 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
858 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
859 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
860 gtk_widget_show (bbox);
862 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
863 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
864 gtk_widget_show (button);
865 g_signal_connect_swapped (button, "clicked",
866 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
868 icon_name = empathy_account_settings_get_icon_name (settings);
870 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
872 /* show the default icon; keep this in sync with the default
873 * one in empathy-accounts-dialog.ui.
875 icon_name = GTK_STOCK_CUT;
877 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
878 icon_name, GTK_ICON_SIZE_DIALOG);
879 gtk_widget_set_tooltip_text (priv->image_type,
880 empathy_protocol_name_to_display_name
881 (empathy_account_settings_get_protocol (settings)));
882 gtk_widget_show (priv->image_type);
884 accounts_dialog_update_name_label (dialog,
885 empathy_account_settings_get_display_name (settings));
887 accounts_dialog_update_status_infobar (dialog, account);
891 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
893 EmpathyAccountsDialog *dialog)
895 if (empathy_account_settings_is_ready (settings))
896 account_dialog_create_dialog_content (dialog, settings);
900 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
904 GtkTreeSelection *selection;
906 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
909 view = GTK_TREE_VIEW (priv->treeview);
910 model = gtk_tree_view_get_model (view);
912 if (gtk_tree_model_get_iter_first (model, &iter))
914 selection = gtk_tree_view_get_selection (view);
915 gtk_tree_selection_select_iter (selection, &iter);
919 accounts_dialog_update_settings (dialog, NULL);
924 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
929 GtkTreeSelection *selection;
930 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
932 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
934 if (gtk_tree_selection_get_selected (selection, &model, &iter))
935 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
937 return priv->setting_widget != NULL
938 && empathy_account_widget_contains_pending_changes (
939 priv->setting_widget);
943 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
944 const gchar *primary_text,
945 const gchar *secondary_text,
946 GCallback response_callback,
948 const gchar *first_button_text,
952 GtkWidget *message_dialog;
953 const gchar *button_text;
955 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
956 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
957 GTK_MESSAGE_QUESTION,
961 gtk_message_dialog_format_secondary_text (
962 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
964 va_start (button_args, first_button_text);
965 for (button_text = first_button_text;
967 button_text = va_arg (button_args, const gchar *))
970 response_id = va_arg (button_args, gint);
972 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
975 va_end (button_args);
977 g_signal_connect (message_dialog, "response", response_callback, user_data);
979 gtk_widget_show (message_dialog);
983 get_dialog_primary_text (TpAccount *account)
987 /* Existing account */
988 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
989 tp_account_get_display_name (account));
993 /* Newly created account */
994 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
999 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
1000 EmpathyAccountsDialog *self)
1005 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
1006 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
1008 response = gtk_dialog_run (GTK_DIALOG (dialog));
1010 if (response == GTK_RESPONSE_APPLY)
1012 EmpathyAccountSettings *settings;
1015 settings = empathy_new_account_dialog_get_settings (
1016 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
1018 /* The newly created account has already been added by
1019 * accounts_dialog_account_validity_changed_cb so we just
1020 * have to select it. */
1021 account = empathy_account_settings_get_account (settings);
1022 accounts_dialog_model_set_selected (self, account);
1025 gtk_widget_destroy (dialog);
1029 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
1030 EmpathyAccountSettings *settings)
1032 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1034 if (priv->settings_ready != NULL)
1036 g_signal_handler_disconnect (priv->settings_ready,
1037 priv->settings_ready_id);
1038 priv->settings_ready = NULL;
1039 priv->settings_ready_id = 0;
1045 GtkTreeModel *model;
1046 GtkTreeSelection *selection;
1048 view = GTK_TREE_VIEW (priv->treeview);
1049 model = gtk_tree_view_get_model (view);
1050 selection = gtk_tree_view_get_selection (view);
1052 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
1054 /* We have configured accounts, select the first one if there
1055 * is no other account selected already. */
1056 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
1057 accounts_dialog_model_select_first (dialog);
1062 /* No account and no profile, warn the user */
1063 gtk_widget_hide (priv->vbox_details);
1064 gtk_widget_set_sensitive (priv->button_add, FALSE);
1066 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
1067 NOTEBOOK_PAGE_NO_PROTOCOL);
1071 /* We have an account selected, destroy old settings and create a new
1072 * one for the account selected */
1073 gtk_widget_show (priv->vbox_details);
1075 if (priv->dialog_content)
1077 gtk_widget_destroy (priv->dialog_content);
1078 priv->dialog_content = NULL;
1081 if (empathy_account_settings_is_ready (settings))
1083 account_dialog_create_dialog_content (dialog, settings);
1087 priv->settings_ready = settings;
1088 priv->settings_ready_id =
1089 g_signal_connect (settings, "notify::ready",
1090 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1096 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1097 GtkCellEditable *editable,
1099 EmpathyAccountsDialog *dialog)
1101 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1103 if (priv->connecting_id)
1104 g_source_remove (priv->connecting_id);
1106 DEBUG ("Editing account name started; stopping flashing");
1109 static const gchar *
1110 get_status_icon_for_account (EmpathyAccountsDialog *self,
1113 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1114 TpConnectionStatus status;
1115 TpConnectionStatusReason reason;
1116 TpConnectionPresenceType presence;
1118 if (account == NULL)
1119 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1121 if (!tp_account_is_enabled (account))
1122 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1124 status = tp_account_get_connection_status (account, &reason);
1126 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1128 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1129 /* An error occured */
1130 return GTK_STOCK_DIALOG_ERROR;
1132 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1134 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1136 /* Account is connecting. Display a blinking account alternating between
1137 * the offline icon and the requested presence. */
1138 if (priv->connecting_show)
1139 presence = tp_account_get_requested_presence (account, NULL, NULL);
1141 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1145 /* status == TP_CONNECTION_STATUS_CONNECTED */
1146 presence = tp_account_get_current_presence (account, NULL, NULL);
1148 /* If presence is Unset (CM doesn't implement SimplePresence),
1149 * display the 'available' icon.
1150 * We also check Offline because of this MC5 bug: fd.o #26060 */
1151 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1152 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1153 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1156 return empathy_icon_name_for_presence (presence);
1160 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1161 GtkCellRenderer *cell,
1162 GtkTreeModel *model,
1164 EmpathyAccountsDialog *dialog)
1168 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1171 "icon-name", get_status_icon_for_account (dialog, account),
1174 if (account != NULL)
1175 g_object_unref (account);
1179 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1180 GtkCellRenderer *cell,
1181 GtkTreeModel *model,
1183 EmpathyAccountsDialog *dialog)
1185 EmpathyAccountSettings *settings;
1188 TpConnectionStatus status;
1190 gtk_tree_model_get (model, iter,
1191 COL_STATUS, &status,
1192 COL_ACCOUNT_SETTINGS, &settings,
1195 icon_name = empathy_account_settings_get_icon_name (settings);
1196 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1203 g_object_unref (settings);
1206 g_object_unref (pixbuf);
1210 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1217 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1219 if (account == NULL)
1222 if (tp_account_get_connection_status (account, NULL) ==
1223 TP_CONNECTION_STATUS_CONNECTING)
1225 /* Only update the row where we have a connecting account as that's the
1226 * ones having a blinking icon. */
1227 gtk_tree_model_row_changed (model, path, iter);
1230 g_object_unref (account);
1235 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1238 GtkTreeModel *model;
1239 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1241 priv->connecting_show = !priv->connecting_show;
1243 view = GTK_TREE_VIEW (priv->treeview);
1244 model = gtk_tree_view_get_model (view);
1246 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1252 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1255 EmpathyAccountsDialog *dialog)
1257 EmpathyAccountSettings *settings;
1258 GtkTreeModel *model;
1259 GtkTreePath *treepath;
1261 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1262 gboolean connecting;
1264 empathy_account_manager_get_accounts_connected (&connecting);
1268 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1269 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1273 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1274 treepath = gtk_tree_path_new_from_string (path);
1275 gtk_tree_model_get_iter (model, &iter, treepath);
1276 gtk_tree_model_get (model, &iter,
1277 COL_ACCOUNT_SETTINGS, &settings,
1279 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1282 gtk_tree_path_free (treepath);
1284 empathy_account_settings_set_display_name_async (settings, new_text,
1286 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1287 g_object_unref (settings);
1291 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1296 GtkTreeModel *model;
1298 GtkTreeSelection *selection;
1299 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1300 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1302 if (response_id == GTK_RESPONSE_YES)
1304 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1306 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1309 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1311 if (account != NULL)
1313 tp_account_remove_async (account, NULL, NULL);
1314 g_object_unref (account);
1318 /* No need to call accounts_dialog_model_selection_changed while
1319 * removing as we are going to call accounts_dialog_model_select_first
1320 * right after which will update the selection. */
1321 g_signal_handlers_block_by_func (selection,
1322 accounts_dialog_model_selection_changed, account_dialog);
1324 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1326 g_signal_handlers_unblock_by_func (selection,
1327 accounts_dialog_model_selection_changed, account_dialog);
1329 accounts_dialog_model_select_first (account_dialog);
1332 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1336 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1339 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1341 GtkTreeModel *model;
1342 gchar *question_dialog_primary_text;
1344 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1346 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1348 if (account == NULL || !tp_account_is_valid (account))
1350 if (account != NULL)
1351 g_object_unref (account);
1352 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1353 accounts_dialog_model_select_first (dialog);
1357 question_dialog_primary_text = g_strdup_printf (
1358 _("Do you want to remove %s from your computer?"),
1359 tp_account_get_display_name (account));
1361 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1362 _("This will not remove your account on the server."),
1363 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1365 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1366 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1368 g_free (question_dialog_primary_text);
1369 g_object_unref (account);
1373 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1374 EmpathyAccountsDialog *dialog)
1376 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1378 GtkTreeSelection *selection;
1381 view = GTK_TREE_VIEW (priv->treeview);
1382 selection = gtk_tree_view_get_selection (view);
1383 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1386 accounts_dialog_remove_account_iter (dialog, &iter);
1390 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1393 GtkTreeViewColumn *column;
1394 GtkCellRenderer *cell;
1395 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1397 view = GTK_TREE_VIEW (priv->treeview);
1398 gtk_tree_view_set_headers_visible (view, FALSE);
1400 /* Account column */
1401 column = gtk_tree_view_column_new ();
1402 gtk_tree_view_column_set_expand (column, TRUE);
1403 gtk_tree_view_append_column (view, column);
1405 /* Status icon renderer */
1406 cell = gtk_cell_renderer_pixbuf_new ();
1407 gtk_tree_view_column_pack_start (column, cell, FALSE);
1408 gtk_tree_view_column_set_cell_data_func (column, cell,
1409 (GtkTreeCellDataFunc)
1410 accounts_dialog_model_status_pixbuf_data_func,
1414 /* Protocol icon renderer */
1415 cell = gtk_cell_renderer_pixbuf_new ();
1416 gtk_tree_view_column_pack_start (column, cell, FALSE);
1417 gtk_tree_view_column_set_cell_data_func (column, cell,
1418 (GtkTreeCellDataFunc)
1419 accounts_dialog_model_protocol_pixbuf_data_func,
1424 priv->name_renderer = gtk_cell_renderer_text_new ();
1425 g_object_set (priv->name_renderer,
1426 "ellipsize", PANGO_ELLIPSIZE_END,
1430 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1431 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1433 g_signal_connect (priv->name_renderer, "edited",
1434 G_CALLBACK (accounts_dialog_name_edited_cb),
1436 g_signal_connect (priv->name_renderer, "editing-started",
1437 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1439 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1442 static EmpathyAccountSettings *
1443 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1446 GtkTreeModel *model;
1447 GtkTreeSelection *selection;
1449 EmpathyAccountSettings *settings;
1450 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1452 view = GTK_TREE_VIEW (priv->treeview);
1453 selection = gtk_tree_view_get_selection (view);
1455 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1458 gtk_tree_model_get (model, &iter,
1459 COL_ACCOUNT_SETTINGS, &settings, -1);
1465 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1466 EmpathyAccountsDialog *dialog)
1468 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1469 EmpathyAccountSettings *settings;
1470 GtkTreeModel *model;
1472 gboolean is_selection;
1473 gboolean creating = FALSE;
1475 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1477 settings = accounts_dialog_model_get_selected_settings (dialog);
1478 accounts_dialog_update_settings (dialog, settings);
1480 if (settings != NULL)
1481 g_object_unref (settings);
1483 if (priv->setting_widget != NULL)
1485 g_object_get (priv->setting_widget,
1486 "creating-account", &creating, NULL);
1489 /* Update remove button sensitivity */
1490 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1495 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1497 gpointer *user_data)
1499 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1500 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1502 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1504 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1506 /* The user wants to lose unsaved changes to the currently selected
1507 * account and select another account. We discard the changes and
1508 * select the other account. */
1510 GtkTreeSelection *selection;
1512 priv->force_change_row = TRUE;
1513 empathy_account_widget_discard_pending_changes (
1514 priv->setting_widget);
1516 path = gtk_tree_row_reference_get_path (priv->destination_row);
1517 selection = gtk_tree_view_get_selection (
1518 GTK_TREE_VIEW (priv->treeview));
1522 /* This will trigger a call to
1523 * accounts_dialog_account_selection_change() */
1524 gtk_tree_selection_select_path (selection, path);
1525 gtk_tree_path_free (path);
1528 gtk_tree_row_reference_free (priv->destination_row);
1532 priv->force_change_row = FALSE;
1537 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1538 GtkTreeModel *model,
1540 gboolean path_currently_selected,
1543 TpAccount *account = NULL;
1544 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1545 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1548 if (priv->force_change_row)
1550 /* We came back here because the user wants to discard changes to his
1551 * modified account. The changes have already been discarded so we
1552 * just change the selected row. */
1553 priv->force_change_row = FALSE;
1557 if (accounts_dialog_has_pending_change (dialog, &account))
1559 /* The currently selected account has some unsaved changes. We ask
1560 * the user if he really wants to lose his changes and select another
1562 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1563 priv->destination_row = gtk_tree_row_reference_new (model, path);
1565 accounts_dialog_show_question_dialog (dialog,
1566 question_dialog_primary_text,
1567 _("You are about to select another account, which will discard\n"
1568 "your changes. Are you sure you want to proceed?"),
1569 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1571 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1572 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1574 g_free (question_dialog_primary_text);
1582 if (account != NULL)
1583 g_object_unref (account);
1589 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1591 GtkListStore *store;
1592 GtkTreeSelection *selection;
1593 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1595 store = gtk_list_store_new (COL_COUNT,
1596 G_TYPE_STRING, /* name */
1597 G_TYPE_UINT, /* status */
1598 TP_TYPE_ACCOUNT, /* account */
1599 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1601 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1602 GTK_TREE_MODEL (store));
1604 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1605 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1606 gtk_tree_selection_set_select_function (selection,
1607 accounts_dialog_account_selection_change, dialog, NULL);
1609 g_signal_connect (selection, "changed",
1610 G_CALLBACK (accounts_dialog_model_selection_changed),
1613 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1614 COL_NAME, GTK_SORT_ASCENDING);
1616 accounts_dialog_model_add_columns (dialog);
1618 g_object_unref (store);
1622 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1627 GtkTreeModel *model;
1629 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1631 /* Update the status in the model */
1632 view = GTK_TREE_VIEW (priv->treeview);
1633 model = gtk_tree_view_get_model (view);
1635 for (ok = gtk_tree_model_get_iter_first (model, iter);
1637 ok = gtk_tree_model_iter_next (model, iter))
1639 TpAccount *this_account;
1642 gtk_tree_model_get (model, iter,
1643 COL_ACCOUNT, &this_account,
1646 equal = (this_account == account);
1647 g_object_unref (this_account);
1657 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1660 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1661 GtkTreeSelection *selection;
1663 GtkTreeModel *model;
1665 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1667 gtk_tree_selection_select_iter (selection, iter);
1669 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1670 path = gtk_tree_model_get_path (model, iter);
1672 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1675 gtk_tree_path_free (path);
1679 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1684 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1685 select_and_scroll_to_iter (dialog, &iter);
1689 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1694 enabled = tp_account_is_enabled (account);
1696 enable_and_connect_account (account, !enabled);
1700 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1701 EmpathyAccountsDialog *self)
1703 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1706 GtkTreeSelection *selection;
1707 GtkTreeModel *model;
1709 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1710 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1712 path = gtk_tree_model_get_path (model, &iter);
1714 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1716 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1717 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1718 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1720 gtk_tree_path_free (path);
1724 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1725 GdkEventButton *event,
1726 EmpathyAccountsDialog *dialog)
1728 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1729 TpAccount *account = NULL;
1730 GtkTreeModel *model = NULL;
1731 GtkTreePath *path = NULL;
1736 /* ignore multiple clicks */
1737 if (event->type != GDK_BUTTON_PRESS)
1740 if (event->button != 3)
1743 /* Selection is not yet set, so we have to get account from event position */
1744 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1745 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1746 event->x, event->y, &path, NULL, NULL, NULL))
1749 if (!gtk_tree_model_get_iter (model, &iter, path))
1752 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1754 /* Create the menu */
1755 menu = empathy_context_menu_new (GTK_WIDGET (view));
1757 /* Menu item: to enabled/disable the account */
1758 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1760 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1762 if (account_can_be_enabled (account))
1766 active = tp_account_is_enabled (account);
1767 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1770 tp_g_signal_connect_object (item, "activate",
1771 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1775 gtk_widget_set_sensitive (item, FALSE);
1778 gtk_widget_show (item);
1780 /* Menu item: Rename */
1781 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1782 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1784 tp_g_signal_connect_object (item, "activate",
1785 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1787 gtk_widget_show (item);
1789 /* FIXME: Add here presence items, to be able to set per-account presence */
1792 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1793 event->button, event->time);
1796 tp_clear_object (&account);
1797 gtk_tree_path_free (path);
1803 reload_account_widget (EmpathyAccountsDialog *self)
1805 EmpathyAccountSettings *settings;
1807 settings = accounts_dialog_model_get_selected_settings (self);
1808 accounts_dialog_update_settings (self, settings);
1812 accounts_dialog_connection_changed_cb (TpAccount *account,
1816 gchar *dbus_error_name,
1817 GHashTable *details,
1818 EmpathyAccountsDialog *dialog)
1820 GtkTreeModel *model;
1823 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1825 /* Update the status-infobar in the details view */
1826 accounts_dialog_update_status_infobar (dialog, account);
1828 /* Update the status in the model */
1829 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1831 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1835 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1836 COL_STATUS, current,
1839 path = gtk_tree_model_get_path (model, &iter);
1840 gtk_tree_model_row_changed (model, path, &iter);
1841 gtk_tree_path_free (path);
1844 empathy_account_manager_get_accounts_connected (&found);
1846 if (!found && priv->connecting_id)
1848 g_source_remove (priv->connecting_id);
1849 priv->connecting_id = 0;
1852 if (found && !priv->connecting_id)
1853 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1854 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1859 update_account_in_treeview (EmpathyAccountsDialog *self,
1862 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1864 GtkTreeModel *model;
1866 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1867 if (accounts_dialog_get_account_iter (self, account, &iter))
1871 path = gtk_tree_model_get_path (model, &iter);
1872 gtk_tree_model_row_changed (model, path, &iter);
1873 gtk_tree_path_free (path);
1878 accounts_dialog_presence_changed_cb (TpAccount *account,
1881 gchar *status_message,
1882 EmpathyAccountsDialog *dialog)
1884 /* Update the status-infobar in the details view */
1885 accounts_dialog_update_status_infobar (dialog, account);
1887 update_account_in_treeview (dialog, account);
1891 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1895 const gchar *display_name;
1897 GtkTreeModel *model;
1898 EmpathyAccountSettings *settings;
1899 TpAccount *selected_account;
1900 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1901 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1903 display_name = tp_account_get_display_name (account);
1904 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1905 settings = accounts_dialog_model_get_selected_settings (dialog);
1906 if (settings == NULL)
1909 selected_account = empathy_account_settings_get_account (settings);
1911 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1913 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1914 COL_NAME, display_name,
1918 if (selected_account == account)
1919 accounts_dialog_update_name_label (dialog, display_name);
1921 g_object_unref (settings);
1925 conn_prepare_cb (GObject *source,
1926 GAsyncResult *result,
1929 EmpathyAccountsDialog *self = user_data;
1931 reload_account_widget (self);
1935 accounts_dialog_notify_connection_cb (TpAccount *account,
1937 EmpathyAccountsDialog *self)
1940 if (!account_is_selected (self, account))
1943 conn = tp_account_get_connection (account);
1946 reload_account_widget (self);
1950 /* Wait for this feature so TpConnection will have fetch the
1952 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1954 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1959 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1962 EmpathyAccountSettings *settings;
1963 GtkTreeModel *model;
1965 TpConnectionStatus status;
1967 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1968 gboolean selected = FALSE;
1969 GtkTreeSelection *selection;
1971 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1972 status = tp_account_get_connection_status (account, NULL);
1973 name = tp_account_get_display_name (account);
1975 settings = empathy_account_settings_new_for_account (account);
1977 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1979 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1981 /* Select the account if it's the first added */
1982 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1985 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1988 COL_ACCOUNT, account,
1989 COL_ACCOUNT_SETTINGS, settings,
1994 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1996 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1999 COL_ACCOUNT, account,
2000 COL_ACCOUNT_SETTINGS, settings,
2006 /* We just modified the selected account. Its display name may have been
2007 * changed and so it's place in the treeview. Scroll to it so it stays
2009 select_and_scroll_to_iter (dialog, &iter);
2012 accounts_dialog_connection_changed_cb (account,
2015 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
2020 tp_g_signal_connect_object (account, "notify::display-name",
2021 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
2024 tp_g_signal_connect_object (account, "status-changed",
2025 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
2026 tp_g_signal_connect_object (account, "presence-changed",
2027 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
2028 tp_g_signal_connect_object (account, "notify::connection",
2029 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
2031 g_object_unref (settings);
2035 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
2038 EmpathyAccountsDialog *dialog)
2040 accounts_dialog_add_account (dialog, account);
2044 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
2047 EmpathyAccountsDialog *dialog)
2049 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2051 if (priv->setting_widget != NULL &&
2052 accounts_dialog_has_valid_accounts (dialog))
2054 empathy_account_widget_set_other_accounts_exist (
2055 priv->setting_widget, TRUE);
2060 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
2062 EmpathyAccountsDialog *dialog)
2064 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2066 if (priv->setting_widget != NULL &&
2067 !accounts_dialog_has_valid_accounts (dialog))
2069 empathy_account_widget_set_other_accounts_exist (
2070 priv->setting_widget, FALSE);
2075 accounts_dialog_account_removed_cb (TpAccountManager *manager,
2077 EmpathyAccountsDialog *dialog)
2080 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2082 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2084 gtk_list_store_remove (GTK_LIST_STORE (
2085 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
2090 enable_or_disable_account (EmpathyAccountsDialog *dialog,
2094 /* Update the status-infobar in the details view */
2095 accounts_dialog_update_status_infobar (dialog, account);
2097 DEBUG ("Account %s is now %s",
2098 tp_account_get_display_name (account),
2099 enabled ? "enabled" : "disabled");
2103 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
2105 EmpathyAccountsDialog *dialog)
2107 enable_or_disable_account (dialog, account, FALSE);
2108 update_account_in_treeview (dialog, account);
2112 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2114 EmpathyAccountsDialog *dialog)
2116 enable_or_disable_account (dialog, account, TRUE);
2120 display_import_dialog (EmpathyAccountsDialog *dialog)
2122 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2123 GtkWidget *import_dialog;
2125 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2127 gtk_widget_show (import_dialog);
2129 return import_dialog;
2133 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2134 EmpathyAccountsDialog *dialog)
2136 display_import_dialog (dialog);
2140 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2144 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2146 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2148 if (response_id == GTK_RESPONSE_YES)
2149 gtk_widget_destroy (account_dialog);
2153 accounts_dialog_delete_event_cb (GtkWidget *widget,
2155 EmpathyAccountsDialog *dialog)
2157 /* we maunally handle responses to delete events */
2162 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2167 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2168 select_and_scroll_to_iter (dialog, &iter);
2172 salut_valid_cb (GtkWidget *widget,
2176 gtk_widget_set_sensitive (button, valid);
2180 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2182 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2183 GtkWidget *dialog, *widget, *content, *button;
2186 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2187 priv->account_manager))
2190 widget = empathy_local_xmpp_assistant_widget_new ();
2191 gtk_widget_show (widget);
2193 dialog = gtk_dialog_new ();
2195 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2197 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2200 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2201 _("_Connect"), GTK_RESPONSE_YES);
2202 gtk_widget_set_sensitive (button,
2203 empathy_local_xmpp_assistant_widget_is_valid (
2204 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2206 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2209 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2210 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2212 response = gtk_dialog_run (GTK_DIALOG (dialog));
2214 if (response == GTK_RESPONSE_YES)
2216 empathy_local_xmpp_assistant_widget_create_account (
2217 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2220 gtk_widget_destroy (dialog);
2224 import_dialog_response_cb (GtkDialog *dialog,
2226 EmpathyAccountsDialog *self)
2228 maybe_show_salut_dialog (self);
2232 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2234 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2237 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2240 if (!empathy_import_accounts_to_import ())
2242 maybe_show_salut_dialog (self);
2246 dialog = display_import_dialog (self);
2248 tp_g_signal_connect_object (dialog, "response",
2249 G_CALLBACK (import_dialog_response_cb), self, 0);
2253 finished_loading (EmpathyAccountsDialog *self)
2255 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2256 GtkTreeSelection *selection;
2257 gboolean has_selected;
2259 priv->loading = FALSE;
2261 gtk_widget_set_sensitive (priv->button_add, TRUE);
2262 gtk_widget_set_sensitive (priv->button_import, TRUE);
2263 gtk_widget_set_sensitive (priv->treeview, TRUE);
2265 /* Sensitive the remove button if there is an account selected */
2266 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2267 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2268 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2270 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2271 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2272 NOTEBOOK_PAGE_ACCOUNT);
2274 maybe_show_import_dialog (self);
2278 accounts_dialog_cms_prepare_cb (GObject *source,
2279 GAsyncResult *result,
2282 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2283 EmpathyAccountsDialog *dialog = user_data;
2284 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2286 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2289 /* No need to update the settings if we are already preparing one */
2290 if (priv->settings_ready == NULL)
2291 accounts_dialog_update_settings (dialog, NULL);
2293 if (priv->initial_selection != NULL)
2295 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2296 g_object_unref (priv->initial_selection);
2297 priv->initial_selection = NULL;
2301 finished_loading (dialog);
2305 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2307 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2308 GList *accounts, *l;
2310 g_signal_connect (priv->account_manager, "account-validity-changed",
2311 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2313 g_signal_connect (priv->account_manager, "account-removed",
2314 G_CALLBACK (accounts_dialog_account_removed_cb),
2316 g_signal_connect (priv->account_manager, "account-enabled",
2317 G_CALLBACK (accounts_dialog_account_enabled_cb),
2319 g_signal_connect (priv->account_manager, "account-disabled",
2320 G_CALLBACK (accounts_dialog_account_disabled_cb),
2323 /* Add existing accounts */
2324 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2325 for (l = accounts; l; l = l->next)
2327 accounts_dialog_add_account (dialog, l->data);
2329 g_list_free (accounts);
2331 priv->cms = empathy_connection_managers_dup_singleton ();
2333 empathy_connection_managers_prepare_async (priv->cms,
2334 accounts_dialog_cms_prepare_cb, dialog);
2336 accounts_dialog_model_select_first (dialog);
2340 accounts_dialog_manager_ready_cb (GObject *source_object,
2341 GAsyncResult *result,
2344 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2345 GError *error = NULL;
2347 if (!tp_proxy_prepare_finish (manager, result, &error))
2349 DEBUG ("Failed to prepare account manager: %s", error->message);
2350 g_error_free (error);
2354 accounts_dialog_accounts_setup (user_data);
2358 dialog_response_cb (GtkWidget *widget,
2362 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2364 if (response_id == GTK_RESPONSE_HELP)
2366 empathy_url_show (widget, "help:empathy/accounts-window");
2368 else if (response_id == GTK_RESPONSE_CLOSE ||
2369 response_id == GTK_RESPONSE_DELETE_EVENT)
2371 TpAccount *account = NULL;
2373 if (accounts_dialog_has_pending_change (dialog, &account))
2375 gchar *question_dialog_primary_text = get_dialog_primary_text (
2378 accounts_dialog_show_question_dialog (dialog,
2379 question_dialog_primary_text,
2380 _("You are about to close the window, which will discard\n"
2381 "your changes. Are you sure you want to proceed?"),
2382 G_CALLBACK (accounts_dialog_close_response_cb),
2384 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2385 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2387 g_free (question_dialog_primary_text);
2391 gtk_widget_destroy (widget);
2394 if (account != NULL)
2395 g_object_unref (account);
2400 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2402 GtkWidget *top_hbox;
2405 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2406 GtkWidget *content_area, *action_area;
2407 GtkWidget *grid, *hbox;
2409 GtkWidget *sw, *toolbar;
2410 GtkStyleContext *context;
2412 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2414 gui = empathy_builder_get_file (filename,
2415 "accounts_dialog_hbox", &top_hbox,
2416 "vbox_details", &priv->vbox_details,
2417 "alignment_settings", &priv->alignment_settings,
2418 "alignment_infobar", &priv->alignment_infobar,
2419 "treeview", &priv->treeview,
2420 "button_add", &priv->button_add,
2421 "button_remove", &priv->button_remove,
2422 "button_import", &priv->button_import,
2423 "notebook_account", &priv->notebook_account,
2424 "alignment_loading", &alig,
2426 "add_remove_toolbar", &toolbar,
2430 empathy_builder_connect (gui, dialog,
2431 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2432 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2433 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2434 "treeview", "button-press-event",
2435 accounts_dialog_treeview_button_press_event_cb,
2438 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2440 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2442 g_object_unref (gui);
2444 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2446 /* Display loading page */
2447 priv->loading = TRUE;
2449 priv->spinner = gtk_spinner_new ();
2451 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2452 gtk_widget_show (priv->spinner);
2454 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2456 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2457 NOTEBOOK_PAGE_LOADING);
2459 /* Remove button is insensitive until we have a selected account */
2460 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2462 /* Add and Import buttons and treeview are insensitive while the dialog
2464 gtk_widget_set_sensitive (priv->button_add, FALSE);
2465 gtk_widget_set_sensitive (priv->button_import, FALSE);
2466 gtk_widget_set_sensitive (priv->treeview, FALSE);
2468 if (priv->parent_window)
2469 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2470 priv->parent_window);
2472 priv->infobar = gtk_info_bar_new ();
2473 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2475 gtk_widget_show (priv->infobar);
2477 grid = gtk_grid_new ();
2478 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2480 GTK_CONTAINER (gtk_info_bar_get_content_area (
2481 GTK_INFO_BAR (priv->infobar))),
2484 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2485 GTK_ICON_SIZE_DIALOG);
2486 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2487 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2490 priv->label_name = gtk_label_new (NULL);
2491 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2494 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2495 gtk_widget_set_hexpand (hbox, TRUE);
2496 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2497 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2499 /* set up spinner */
2500 priv->throbber = gtk_spinner_new ();
2502 priv->image_status = gtk_image_new_from_icon_name (
2503 empathy_icon_name_for_presence (
2504 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2506 priv->label_status = gtk_label_new (NULL);
2507 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2509 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2510 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2511 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2513 /* enabled switch */
2514 priv->enabled_switch = gtk_switch_new ();
2515 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2516 g_signal_connect (priv->enabled_switch, "notify::active",
2517 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2518 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2520 gtk_widget_show_all (grid);
2522 /* Tweak the dialog */
2523 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2524 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2526 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2528 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2530 /* join the add/remove toolbar to the treeview */
2531 context = gtk_widget_get_style_context (sw);
2532 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2534 context = gtk_widget_get_style_context (toolbar);
2535 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2537 /* add dialog buttons */
2538 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2540 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2541 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2542 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2545 g_signal_connect (dialog, "response",
2546 G_CALLBACK (dialog_response_cb), dialog);
2548 g_signal_connect (dialog, "delete-event",
2549 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2553 do_dispose (GObject *obj)
2555 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2556 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2558 if (priv->connecting_id != 0)
2560 g_source_remove (priv->connecting_id);
2561 priv->connecting_id = 0;
2564 if (priv->connectivity)
2566 g_object_unref (priv->connectivity);
2567 priv->connectivity = NULL;
2570 if (priv->account_manager != NULL)
2572 g_object_unref (priv->account_manager);
2573 priv->account_manager = NULL;
2576 if (priv->cms != NULL)
2578 g_object_unref (priv->cms);
2582 if (priv->initial_selection != NULL)
2584 g_object_unref (priv->initial_selection);
2585 priv->initial_selection = NULL;
2588 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2592 do_get_property (GObject *object,
2597 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2599 switch (property_id)
2602 g_value_set_object (value, priv->parent_window);
2605 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2610 do_set_property (GObject *object,
2612 const GValue *value,
2615 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2617 switch (property_id)
2620 priv->parent_window = g_value_get_object (value);
2623 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2628 do_constructed (GObject *object)
2630 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2631 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2632 GtkTreeModel *model;
2634 accounts_dialog_build_ui (dialog);
2635 accounts_dialog_model_setup (dialog);
2637 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2638 g_signal_connect (model, "row-inserted",
2639 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2640 g_signal_connect (model, "row-deleted",
2641 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2643 /* Set up signalling */
2644 priv->account_manager = tp_account_manager_dup ();
2646 tp_proxy_prepare_async (priv->account_manager, NULL,
2647 accounts_dialog_manager_ready_cb, dialog);
2649 priv->connectivity = g_network_monitor_get_default ();
2650 g_object_ref (priv->connectivity);
2654 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2656 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2657 GParamSpec *param_spec;
2659 oclass->dispose = do_dispose;
2660 oclass->constructed = do_constructed;
2661 oclass->set_property = do_set_property;
2662 oclass->get_property = do_get_property;
2664 param_spec = g_param_spec_object ("parent",
2665 "parent", "The parent window",
2667 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2668 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2670 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2674 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2676 EmpathyAccountsDialogPriv *priv;
2678 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2679 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2680 EmpathyAccountsDialogPriv);
2681 dialog->priv = priv;
2684 /* public methods */
2687 empathy_accounts_dialog_show (GtkWindow *parent,
2688 TpAccount *selected_account)
2690 EmpathyAccountsDialog *dialog;
2691 EmpathyAccountsDialogPriv *priv;
2693 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2694 "parent", parent, NULL);
2696 priv = GET_PRIV (dialog);
2698 if (selected_account)
2700 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2701 accounts_dialog_set_selected_account (dialog, selected_account);
2703 /* save the selection to set it later when the cms
2706 priv->initial_selection = g_object_ref (selected_account);
2709 gtk_window_present (GTK_WINDOW (dialog));
2711 return GTK_WIDGET (dialog);
2715 empathy_accounts_dialog_show_application (GdkScreen *screen,
2716 TpAccount *selected_account,
2722 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2724 args = g_string_new (NULL);
2726 if (selected_account != NULL)
2727 g_string_append_printf (args, " --select-account=%s",
2728 tp_account_get_path_suffix (selected_account));
2731 g_string_append_printf (args, " --if-needed");
2734 g_string_append_printf (args, " --hidden");
2736 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2738 selected_account == NULL ? "<none selected>" :
2739 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2741 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2743 g_string_free (args, TRUE);
2747 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2749 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2750 gboolean result = FALSE;
2752 if (priv->setting_widget == NULL)
2755 g_object_get (priv->setting_widget,
2756 "creating-account", &result, NULL);