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-connectivity.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;
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_object;
127 gboolean connecting_show;
130 gulong settings_ready_id;
131 EmpathyAccountSettings *settings_ready;
133 TpAccountManager *account_manager;
134 EmpathyConnectionManagers *cms;
135 EmpathyConnectivity *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 *account,
223 GAsyncResult *result,
226 GError *error = NULL;
228 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
232 DEBUG ("Could not enable the account: %s", error->message);
233 g_error_free (error);
237 TpAccountManager *am = tp_account_manager_dup ();
239 empathy_connect_new_account (TP_ACCOUNT (account), am);
245 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
247 EmpathyAccountsDialog *dialog)
249 EmpathyAccountSettings *settings;
252 settings = accounts_dialog_model_get_selected_settings (dialog);
253 if (settings == NULL)
256 account = empathy_account_settings_get_account (settings);
260 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
261 accounts_dialog_enable_account_cb, NULL);
265 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
268 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
269 gchar *status_message = NULL;
275 GtkTreeSelection *selection;
277 TpAccount *selected_account;
278 gboolean account_enabled;
279 gboolean creating_account;
280 TpStorageRestrictionFlags storage_restrictions = 0;
282 view = GTK_TREE_VIEW (priv->treeview);
283 selection = gtk_tree_view_get_selection (view);
285 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
288 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
289 if (selected_account != NULL)
290 g_object_unref (selected_account);
292 /* do not update the infobar when the account is not selected */
293 if (account != selected_account)
298 status = tp_account_get_connection_status (account, &reason);
299 presence = tp_account_get_current_presence (account, NULL, &status_message);
300 account_enabled = tp_account_is_enabled (account);
301 creating_account = FALSE;
303 if (status == TP_CONNECTION_STATUS_CONNECTED &&
304 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
305 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
306 /* If presence is Unset (CM doesn't implement SimplePresence) but we
307 * are connected, consider ourself as Available.
308 * We also check Offline because of this MC5 bug: fd.o #26060 */
309 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
311 /* set presence to offline if account is disabled
312 * (else no icon is shown in infobar)*/
313 if (!account_enabled)
314 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
316 storage_restrictions = tp_account_get_storage_restrictions (account);
320 status = TP_CONNECTION_STATUS_DISCONNECTED;
321 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
322 account_enabled = FALSE;
323 creating_account = TRUE;
326 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
327 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
329 /* update the enabled switch */
330 g_signal_handlers_block_by_func (priv->enabled_switch,
331 accounts_dialog_enable_switch_active_cb, dialog);
332 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
334 g_signal_handlers_unblock_by_func (priv->enabled_switch,
335 accounts_dialog_enable_switch_active_cb, dialog);
337 /* Display the Enable switch if account supports it */
338 gtk_widget_set_visible (priv->enabled_switch,
339 !(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED));
345 case TP_CONNECTION_STATUS_CONNECTING:
346 accounts_dialog_status_infobar_set_message (dialog,
348 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
351 gtk_spinner_start (GTK_SPINNER (priv->throbber));
352 gtk_widget_show (priv->throbber);
353 gtk_widget_hide (priv->image_status);
355 case TP_CONNECTION_STATUS_CONNECTED:
356 if (g_strcmp0 (status_message, "") == 0)
360 message = g_strdup_printf ("%s",
361 empathy_presence_get_default_message (presence));
363 accounts_dialog_status_infobar_set_message (dialog, message);
370 message = g_strdup_printf ("%s — %s",
371 empathy_presence_get_default_message (presence),
374 accounts_dialog_status_infobar_set_message (dialog, message);
377 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
380 gtk_widget_show (priv->image_status);
381 gtk_widget_hide (priv->throbber);
383 case TP_CONNECTION_STATUS_DISCONNECTED:
384 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
388 message = g_strdup_printf (_("Offline — %s"),
389 empathy_account_get_error_message (account, NULL));
390 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
391 GTK_MESSAGE_WARNING);
393 accounts_dialog_status_infobar_set_message (dialog, message);
400 message = g_strdup_printf (_("Disconnected — %s"),
401 empathy_account_get_error_message (account, NULL));
402 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
405 accounts_dialog_status_infobar_set_message (dialog, message);
409 if (!empathy_connectivity_is_online (priv->connectivity))
410 accounts_dialog_status_infobar_set_message (dialog,
411 _("Offline — No Network Connection"));
413 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
414 gtk_widget_show (priv->image_status);
415 gtk_widget_hide (priv->throbber);
418 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
419 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
420 GTK_MESSAGE_WARNING);
422 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
423 gtk_widget_hide (priv->image_status);
424 gtk_widget_hide (priv->throbber);
429 accounts_dialog_status_infobar_set_message (dialog,
430 _("Offline — Account Disabled"));
432 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
433 GTK_MESSAGE_WARNING);
434 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
435 gtk_widget_show (priv->image_status);
436 gtk_widget_hide (priv->throbber);
439 gtk_widget_show (priv->label_status);
441 if (!creating_account)
442 gtk_widget_show (priv->infobar);
444 gtk_widget_hide (priv->infobar);
446 g_free (status_message);
450 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
454 GtkTreeSelection *selection;
456 EmpathyAccountSettings *settings;
458 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
460 view = GTK_TREE_VIEW (priv->treeview);
461 selection = gtk_tree_view_get_selection (view);
463 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
466 gtk_tree_model_get (model, &iter,
467 COL_ACCOUNT_SETTINGS, &settings,
468 COL_ACCOUNT, &account, -1);
470 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
474 /* We were creating an account. We remove the selected row */
475 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
479 /* We were modifying an account. We discard the changes by reloading the
480 * settings and the UI. */
481 accounts_dialog_update_settings (dialog, settings);
482 g_object_unref (account);
485 gtk_widget_set_sensitive (priv->treeview, TRUE);
486 gtk_widget_set_sensitive (priv->button_add, TRUE);
487 gtk_widget_set_sensitive (priv->button_remove, TRUE);
488 gtk_widget_set_sensitive (priv->button_import, TRUE);
490 if (settings != NULL)
491 g_object_unref (settings);
495 empathy_account_dialog_widget_cancelled_cb (
496 EmpathyAccountWidget *widget_object,
497 EmpathyAccountsDialog *dialog)
499 empathy_account_dialog_cancel (dialog);
503 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
505 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
510 g_object_get (priv->setting_widget_object,
511 "creating-account", &creating, NULL);
516 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
518 if (gtk_tree_model_get_iter_first (model, &iter))
519 return gtk_tree_model_iter_next (model, &iter);
525 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
527 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
528 EmpathyAccountSettings *settings;
529 GtkWidget *subdialog, *content, *content_area, *align;
531 settings = accounts_dialog_model_get_selected_settings (dialog);
533 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
535 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
538 priv->setting_widget_object =
539 empathy_account_widget_new_for_protocol (settings, FALSE);
541 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
542 (gpointer *) &priv->setting_widget_object);
544 if (accounts_dialog_has_valid_accounts (dialog))
545 empathy_account_widget_set_other_accounts_exist (
546 priv->setting_widget_object, TRUE);
548 content = empathy_account_widget_get_widget (priv->setting_widget_object);
550 g_signal_connect (priv->setting_widget_object, "cancelled",
551 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
553 g_signal_connect_swapped (priv->setting_widget_object, "close",
554 G_CALLBACK (gtk_widget_destroy), subdialog);
556 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
558 align = gtk_alignment_new (0.5, 0.5, 1, 1);
559 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
561 gtk_container_add (GTK_CONTAINER (align), content);
562 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
564 gtk_widget_show (content);
565 gtk_widget_show (align);
566 gtk_widget_show (subdialog);
570 start_external_app (GAppInfo *app_info)
572 GError *error = NULL;
573 GdkAppLaunchContext *context = NULL;
576 display = gdk_display_get_default ();
577 context = gdk_display_get_app_launch_context (display);
579 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
582 g_critical ("Failed to bisho: %s", error->message);
583 g_clear_error (&error);
586 tp_clear_object (&context);
590 use_external_storage_provider (EmpathyAccountsDialog *self,
593 const gchar *provider;
595 provider = tp_account_get_storage_provider (account);
596 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
598 GDesktopAppInfo *desktop_info;
601 GError *error = NULL;
603 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
604 if (desktop_info == NULL)
606 g_critical ("Could not locate 'gnome-control-center.desktop'");
610 /* glib doesn't have API to start a desktop file with args... (#637875) */
611 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
612 (GAppInfo *) desktop_info));
614 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
616 if (app_info == NULL)
618 DEBUG ("Failed to create app info: %s", error->message);
619 g_error_free (error);
623 start_external_app (app_info);
624 g_object_unref (app_info);
627 g_object_unref (desktop_info);
631 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
633 GDesktopAppInfo *desktop_info;
635 desktop_info = g_desktop_app_info_new (
636 "gnome-online-accounts-panel.desktop");
637 if (desktop_info == NULL)
639 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
643 start_external_app (G_APP_INFO (desktop_info));
644 g_object_unref (desktop_info);
651 DEBUG ("Don't know how to handle %s", provider);
657 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
660 EmpathyAccountSettings *settings;
662 TpStorageRestrictionFlags storage_restrictions;
664 settings = accounts_dialog_model_get_selected_settings (dialog);
666 account = empathy_account_settings_get_account (settings);
667 g_return_if_fail (account != NULL);
669 storage_restrictions = tp_account_get_storage_restrictions (account);
671 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
672 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
674 DEBUG ("Account is provided by an external storage provider");
676 use_external_storage_provider (dialog, account);
680 account_dialog_create_edit_params_dialog (dialog);
685 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
688 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
689 GtkWidget *infobar, *label;
691 infobar = gtk_info_bar_new ();
695 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
696 label = gtk_label_new (_("Failed to retrieve your personal information "
697 "from the server."));
701 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
702 label = gtk_label_new (_("Go online to edit your personal information."));
706 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
708 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
709 gtk_widget_show_all (infobar);
713 account_dialog_got_self_contact (TpConnection *conn,
714 EmpathyContact *contact,
715 const GError *in_error,
719 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
720 GtkWidget *editor, *alig;
722 if (in_error != NULL)
724 DEBUG ("Failed to get self-contact: %s", in_error->message);
725 account_dialog_show_contact_details_failed (
726 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
730 alig = gtk_alignment_new (0.5, 0, 1, 1);
732 /* create the contact info editor for this account */
733 editor = empathy_contact_widget_new (contact,
734 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
735 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
736 EMPATHY_CONTACT_WIDGET_NO_STATUS |
737 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS);
739 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
740 gtk_container_add (GTK_CONTAINER (alig), editor);
741 gtk_widget_show (alig);
742 gtk_widget_show (editor);
746 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
747 EmpathyAccountSettings *settings)
749 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
750 const gchar *icon_name;
752 TpConnection *conn = NULL;
753 GtkWidget *bbox, *button;
755 account = empathy_account_settings_get_account (settings);
757 // if (priv->setting_widget_object != NULL)
758 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
759 // (gpointer *) &priv->setting_widget_object);
761 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
762 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
763 priv->dialog_content);
764 gtk_widget_show (priv->dialog_content);
766 /* request the self contact */
768 conn = tp_account_get_connection (account);
772 empathy_tp_contact_factory_get_from_handle (conn,
773 tp_connection_get_self_handle (conn),
774 account_dialog_got_self_contact,
775 NULL, NULL, G_OBJECT (dialog));
779 account_dialog_show_contact_details_failed (dialog, FALSE);
782 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
783 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
784 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
785 gtk_widget_show (bbox);
787 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
788 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
789 gtk_widget_show (button);
790 g_signal_connect_swapped (button, "clicked",
791 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
793 icon_name = empathy_account_settings_get_icon_name (settings);
795 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
797 /* show the default icon; keep this in sync with the default
798 * one in empathy-accounts-dialog.ui.
800 icon_name = GTK_STOCK_CUT;
802 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
803 icon_name, GTK_ICON_SIZE_DIALOG);
804 gtk_widget_set_tooltip_text (priv->image_type,
805 empathy_protocol_name_to_display_name
806 (empathy_account_settings_get_protocol (settings)));
807 gtk_widget_show (priv->image_type);
809 accounts_dialog_update_name_label (dialog,
810 empathy_account_settings_get_display_name (settings));
812 accounts_dialog_update_status_infobar (dialog, account);
816 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
818 EmpathyAccountsDialog *dialog)
820 if (empathy_account_settings_is_ready (settings))
821 account_dialog_create_dialog_content (dialog, settings);
825 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
829 GtkTreeSelection *selection;
831 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
834 view = GTK_TREE_VIEW (priv->treeview);
835 model = gtk_tree_view_get_model (view);
837 if (gtk_tree_model_get_iter_first (model, &iter))
839 selection = gtk_tree_view_get_selection (view);
840 gtk_tree_selection_select_iter (selection, &iter);
844 accounts_dialog_update_settings (dialog, NULL);
849 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
854 GtkTreeSelection *selection;
855 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
857 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
859 if (gtk_tree_selection_get_selected (selection, &model, &iter))
860 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
862 return priv->setting_widget_object != NULL
863 && empathy_account_widget_contains_pending_changes (
864 priv->setting_widget_object);
868 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
869 const gchar *primary_text,
870 const gchar *secondary_text,
871 GCallback response_callback,
873 const gchar *first_button_text,
877 GtkWidget *message_dialog;
878 const gchar *button_text;
880 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
881 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
882 GTK_MESSAGE_QUESTION,
886 gtk_message_dialog_format_secondary_text (
887 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
889 va_start (button_args, first_button_text);
890 for (button_text = first_button_text;
892 button_text = va_arg (button_args, const gchar *))
895 response_id = va_arg (button_args, gint);
897 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
900 va_end (button_args);
902 g_signal_connect (message_dialog, "response", response_callback, user_data);
904 gtk_widget_show (message_dialog);
908 get_dialog_primary_text (TpAccount *account)
912 /* Existing account */
913 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
914 tp_account_get_display_name (account));
918 /* Newly created account */
919 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
924 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
925 EmpathyAccountsDialog *self)
930 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
931 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
933 response = gtk_dialog_run (GTK_DIALOG (dialog));
935 if (response == GTK_RESPONSE_OK)
937 EmpathyAccountSettings *settings;
940 settings = empathy_new_account_dialog_get_settings (
941 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
943 /* The newly created account has already been added by
944 * accounts_dialog_account_validity_changed_cb so we just
945 * have to select it. */
946 account = empathy_account_settings_get_account (settings);
947 accounts_dialog_model_set_selected (self, account);
950 gtk_widget_destroy (dialog);
954 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
955 EmpathyAccountSettings *settings)
957 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
959 if (priv->settings_ready != NULL)
961 g_signal_handler_disconnect (priv->settings_ready,
962 priv->settings_ready_id);
963 priv->settings_ready = NULL;
964 priv->settings_ready_id = 0;
971 GtkTreeSelection *selection;
973 view = GTK_TREE_VIEW (priv->treeview);
974 model = gtk_tree_view_get_model (view);
975 selection = gtk_tree_view_get_selection (view);
977 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
979 /* We have configured accounts, select the first one if there
980 * is no other account selected already. */
981 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
982 accounts_dialog_model_select_first (dialog);
987 /* No account and no profile, warn the user */
988 gtk_widget_hide (priv->vbox_details);
989 gtk_widget_set_sensitive (priv->button_add, FALSE);
991 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
992 NOTEBOOK_PAGE_NO_PROTOCOL);
996 /* We have an account selected, destroy old settings and create a new
997 * one for the account selected */
998 gtk_widget_show (priv->vbox_details);
1000 if (priv->dialog_content)
1002 gtk_widget_destroy (priv->dialog_content);
1003 priv->dialog_content = NULL;
1006 if (empathy_account_settings_is_ready (settings))
1008 account_dialog_create_dialog_content (dialog, settings);
1012 priv->settings_ready = settings;
1013 priv->settings_ready_id =
1014 g_signal_connect (settings, "notify::ready",
1015 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1021 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1022 GtkCellEditable *editable,
1024 EmpathyAccountsDialog *dialog)
1026 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1028 if (priv->connecting_id)
1029 g_source_remove (priv->connecting_id);
1031 DEBUG ("Editing account name started; stopping flashing");
1034 static const gchar *
1035 get_status_icon_for_account (EmpathyAccountsDialog *self,
1038 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1039 TpConnectionStatus status;
1040 TpConnectionStatusReason reason;
1041 TpConnectionPresenceType presence;
1043 if (account == NULL)
1044 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1046 if (!tp_account_is_enabled (account))
1047 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1049 status = tp_account_get_connection_status (account, &reason);
1051 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1053 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1054 /* An error occured */
1055 return GTK_STOCK_DIALOG_ERROR;
1057 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1059 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1061 /* Account is connecting. Display a blinking account alternating between
1062 * the offline icon and the requested presence. */
1063 if (priv->connecting_show)
1064 presence = tp_account_get_requested_presence (account, NULL, NULL);
1066 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1070 /* status == TP_CONNECTION_STATUS_CONNECTED */
1071 presence = tp_account_get_current_presence (account, NULL, NULL);
1073 /* If presence is Unset (CM doesn't implement SimplePresence),
1074 * display the 'available' icon.
1075 * We also check Offline because of this MC5 bug: fd.o #26060 */
1076 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1077 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1078 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1081 return empathy_icon_name_for_presence (presence);
1085 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1086 GtkCellRenderer *cell,
1087 GtkTreeModel *model,
1089 EmpathyAccountsDialog *dialog)
1093 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1096 "icon-name", get_status_icon_for_account (dialog, account),
1099 if (account != NULL)
1100 g_object_unref (account);
1104 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1105 GtkCellRenderer *cell,
1106 GtkTreeModel *model,
1108 EmpathyAccountsDialog *dialog)
1110 EmpathyAccountSettings *settings;
1113 TpConnectionStatus status;
1115 gtk_tree_model_get (model, iter,
1116 COL_STATUS, &status,
1117 COL_ACCOUNT_SETTINGS, &settings,
1120 icon_name = empathy_account_settings_get_icon_name (settings);
1121 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1128 g_object_unref (settings);
1131 g_object_unref (pixbuf);
1135 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1142 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1144 if (account == NULL)
1147 if (tp_account_get_connection_status (account, NULL) ==
1148 TP_CONNECTION_STATUS_CONNECTING)
1150 /* Only update the row where we have a connecting account as that's the
1151 * ones having a blinking icon. */
1152 gtk_tree_model_row_changed (model, path, iter);
1155 g_object_unref (account);
1160 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1163 GtkTreeModel *model;
1164 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1166 priv->connecting_show = !priv->connecting_show;
1168 view = GTK_TREE_VIEW (priv->treeview);
1169 model = gtk_tree_view_get_model (view);
1171 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1177 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1180 EmpathyAccountsDialog *dialog)
1182 EmpathyAccountSettings *settings;
1183 GtkTreeModel *model;
1184 GtkTreePath *treepath;
1186 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1187 gboolean connecting;
1189 empathy_account_manager_get_accounts_connected (&connecting);
1193 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1194 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1198 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1199 treepath = gtk_tree_path_new_from_string (path);
1200 gtk_tree_model_get_iter (model, &iter, treepath);
1201 gtk_tree_model_get (model, &iter,
1202 COL_ACCOUNT_SETTINGS, &settings,
1204 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1207 gtk_tree_path_free (treepath);
1209 empathy_account_settings_set_display_name_async (settings, new_text,
1211 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1212 g_object_unref (settings);
1216 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1221 GtkTreeModel *model;
1223 GtkTreeSelection *selection;
1224 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1225 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1227 if (response_id == GTK_RESPONSE_YES)
1229 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1231 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1234 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1236 if (account != NULL)
1238 tp_account_remove_async (account, NULL, NULL);
1239 g_object_unref (account);
1243 /* No need to call accounts_dialog_model_selection_changed while
1244 * removing as we are going to call accounts_dialog_model_select_first
1245 * right after which will update the selection. */
1246 g_signal_handlers_block_by_func (selection,
1247 accounts_dialog_model_selection_changed, account_dialog);
1249 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1251 g_signal_handlers_unblock_by_func (selection,
1252 accounts_dialog_model_selection_changed, account_dialog);
1254 accounts_dialog_model_select_first (account_dialog);
1257 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1261 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1264 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1266 GtkTreeModel *model;
1267 gchar *question_dialog_primary_text;
1269 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1271 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1273 if (account == NULL || !tp_account_is_valid (account))
1275 if (account != NULL)
1276 g_object_unref (account);
1277 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1278 accounts_dialog_model_select_first (dialog);
1282 question_dialog_primary_text = g_strdup_printf (
1283 _("Do you want to remove %s from your computer?"),
1284 tp_account_get_display_name (account));
1286 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1287 _("This will not remove your account on the server."),
1288 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1290 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1291 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1293 g_free (question_dialog_primary_text);
1294 g_object_unref (account);
1298 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1299 EmpathyAccountsDialog *dialog)
1301 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1303 GtkTreeSelection *selection;
1306 view = GTK_TREE_VIEW (priv->treeview);
1307 selection = gtk_tree_view_get_selection (view);
1308 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1311 accounts_dialog_remove_account_iter (dialog, &iter);
1316 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1317 const gchar *path_string,
1318 EmpathyAccountsDialog *dialog)
1320 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1321 GtkTreeModel *model;
1324 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1325 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1328 accounts_dialog_remove_account_iter (dialog, &iter);
1330 #endif /* HAVE_MEEGO */
1333 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1336 GtkTreeViewColumn *column;
1337 GtkCellRenderer *cell;
1338 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1340 view = GTK_TREE_VIEW (priv->treeview);
1341 gtk_tree_view_set_headers_visible (view, FALSE);
1343 /* Account column */
1344 column = gtk_tree_view_column_new ();
1345 gtk_tree_view_column_set_expand (column, TRUE);
1346 gtk_tree_view_append_column (view, column);
1348 /* Status icon renderer */
1349 cell = gtk_cell_renderer_pixbuf_new ();
1350 gtk_tree_view_column_pack_start (column, cell, FALSE);
1351 gtk_tree_view_column_set_cell_data_func (column, cell,
1352 (GtkTreeCellDataFunc)
1353 accounts_dialog_model_status_pixbuf_data_func,
1357 /* Protocol icon renderer */
1358 cell = gtk_cell_renderer_pixbuf_new ();
1359 gtk_tree_view_column_pack_start (column, cell, FALSE);
1360 gtk_tree_view_column_set_cell_data_func (column, cell,
1361 (GtkTreeCellDataFunc)
1362 accounts_dialog_model_protocol_pixbuf_data_func,
1367 cell = gtk_cell_renderer_text_new ();
1369 "ellipsize", PANGO_ELLIPSIZE_END,
1373 gtk_tree_view_column_pack_start (column, cell, TRUE);
1374 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1375 g_signal_connect (cell, "edited",
1376 G_CALLBACK (accounts_dialog_name_edited_cb),
1378 g_signal_connect (cell, "editing-started",
1379 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1381 g_object_set (cell, "ypad", 4, NULL);
1385 cell = empathy_cell_renderer_activatable_new ();
1386 gtk_tree_view_column_pack_start (column, cell, FALSE);
1388 "icon-name", GTK_STOCK_DELETE,
1389 "show-on-select", TRUE,
1392 g_signal_connect (cell, "path-activated",
1393 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1395 #endif /* HAVE_MEEGO */
1398 static EmpathyAccountSettings *
1399 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1402 GtkTreeModel *model;
1403 GtkTreeSelection *selection;
1405 EmpathyAccountSettings *settings;
1406 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1408 view = GTK_TREE_VIEW (priv->treeview);
1409 selection = gtk_tree_view_get_selection (view);
1411 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1414 gtk_tree_model_get (model, &iter,
1415 COL_ACCOUNT_SETTINGS, &settings, -1);
1421 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1422 EmpathyAccountsDialog *dialog)
1424 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1425 EmpathyAccountSettings *settings;
1426 GtkTreeModel *model;
1428 gboolean is_selection;
1429 gboolean creating = FALSE;
1431 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1433 settings = accounts_dialog_model_get_selected_settings (dialog);
1434 accounts_dialog_update_settings (dialog, settings);
1436 if (settings != NULL)
1437 g_object_unref (settings);
1439 if (priv->setting_widget_object != NULL)
1441 g_object_get (priv->setting_widget_object,
1442 "creating-account", &creating, NULL);
1445 /* Update remove button sensitivity */
1446 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1451 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1453 gpointer *user_data)
1455 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1456 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1458 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1460 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1462 /* The user wants to lose unsaved changes to the currently selected
1463 * account and select another account. We discard the changes and
1464 * select the other account. */
1466 GtkTreeSelection *selection;
1468 priv->force_change_row = TRUE;
1469 empathy_account_widget_discard_pending_changes (
1470 priv->setting_widget_object);
1472 path = gtk_tree_row_reference_get_path (priv->destination_row);
1473 selection = gtk_tree_view_get_selection (
1474 GTK_TREE_VIEW (priv->treeview));
1478 /* This will trigger a call to
1479 * accounts_dialog_account_selection_change() */
1480 gtk_tree_selection_select_path (selection, path);
1481 gtk_tree_path_free (path);
1484 gtk_tree_row_reference_free (priv->destination_row);
1488 priv->force_change_row = FALSE;
1493 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1494 GtkTreeModel *model,
1496 gboolean path_currently_selected,
1499 TpAccount *account = NULL;
1500 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1501 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1504 if (priv->force_change_row)
1506 /* We came back here because the user wants to discard changes to his
1507 * modified account. The changes have already been discarded so we
1508 * just change the selected row. */
1509 priv->force_change_row = FALSE;
1513 if (accounts_dialog_has_pending_change (dialog, &account))
1515 /* The currently selected account has some unsaved changes. We ask
1516 * the user if he really wants to lose his changes and select another
1518 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1519 priv->destination_row = gtk_tree_row_reference_new (model, path);
1521 accounts_dialog_show_question_dialog (dialog,
1522 question_dialog_primary_text,
1523 _("You are about to select another account, which will discard\n"
1524 "your changes. Are you sure you want to proceed?"),
1525 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1527 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1528 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1530 g_free (question_dialog_primary_text);
1538 if (account != NULL)
1539 g_object_unref (account);
1545 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1547 GtkListStore *store;
1548 GtkTreeSelection *selection;
1549 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1551 store = gtk_list_store_new (COL_COUNT,
1552 G_TYPE_STRING, /* name */
1553 G_TYPE_UINT, /* status */
1554 TP_TYPE_ACCOUNT, /* account */
1555 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1557 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1558 GTK_TREE_MODEL (store));
1560 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1561 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1562 gtk_tree_selection_set_select_function (selection,
1563 accounts_dialog_account_selection_change, dialog, NULL);
1565 g_signal_connect (selection, "changed",
1566 G_CALLBACK (accounts_dialog_model_selection_changed),
1569 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1570 COL_NAME, GTK_SORT_ASCENDING);
1572 accounts_dialog_model_add_columns (dialog);
1574 g_object_unref (store);
1578 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1583 GtkTreeModel *model;
1585 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1587 /* Update the status in the model */
1588 view = GTK_TREE_VIEW (priv->treeview);
1589 model = gtk_tree_view_get_model (view);
1591 for (ok = gtk_tree_model_get_iter_first (model, iter);
1593 ok = gtk_tree_model_iter_next (model, iter))
1595 TpAccount *this_account;
1598 gtk_tree_model_get (model, iter,
1599 COL_ACCOUNT, &this_account,
1602 equal = (this_account == account);
1603 g_object_unref (this_account);
1613 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1616 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1617 GtkTreeSelection *selection;
1619 GtkTreeModel *model;
1621 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1623 gtk_tree_selection_select_iter (selection, iter);
1625 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1626 path = gtk_tree_model_get_path (model, iter);
1628 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1631 gtk_tree_path_free (path);
1635 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1640 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1641 select_and_scroll_to_iter (dialog, &iter);
1645 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1650 enabled = tp_account_is_enabled (account);
1651 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1655 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1656 GdkEventButton *event,
1657 EmpathyAccountsDialog *dialog)
1659 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1660 TpAccount *account = NULL;
1661 GtkTreeModel *model = NULL;
1662 GtkTreePath *path = NULL;
1665 GtkWidget *item_enable, *item_disable;
1666 GtkWidget *image_enable, *image_disable;
1668 /* ignore multiple clicks */
1669 if (event->type != GDK_BUTTON_PRESS)
1672 if (event->button != 3)
1675 /* Selection is not yet set, so we have to get account from event position */
1676 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1677 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1678 event->x, event->y, &path, NULL, NULL, NULL))
1681 if (!gtk_tree_model_get_iter (model, &iter, path))
1684 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1686 /* Create the menu */
1687 menu = empathy_context_menu_new (GTK_WIDGET (view));
1689 /* Get images for menu items */
1690 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1691 tp_account_manager_get_most_available_presence (
1692 priv->account_manager, NULL, NULL)),
1693 GTK_ICON_SIZE_MENU);
1694 image_disable = gtk_image_new_from_icon_name (
1695 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1696 GTK_ICON_SIZE_MENU);
1698 /* Menu items: to enabled/disable the account */
1699 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1700 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1701 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1703 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1706 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1707 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1709 if (tp_account_is_enabled (account))
1711 tp_g_signal_connect_object (item_disable, "activate",
1712 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1713 gtk_widget_set_sensitive (item_enable, FALSE);
1717 tp_g_signal_connect_object (item_enable, "activate",
1718 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1719 gtk_widget_set_sensitive (item_disable, FALSE);
1722 gtk_widget_show (item_enable);
1723 gtk_widget_show (item_disable);
1725 /* FIXME: Add here presence items, to be able to set per-account presence */
1728 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1729 event->button, event->time);
1732 tp_clear_object (&account);
1733 gtk_tree_path_free (path);
1739 accounts_dialog_connection_changed_cb (TpAccount *account,
1743 gchar *dbus_error_name,
1744 GHashTable *details,
1745 EmpathyAccountsDialog *dialog)
1747 GtkTreeModel *model;
1750 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1752 /* Update the status-infobar in the details view */
1753 accounts_dialog_update_status_infobar (dialog, account);
1755 /* Update the status in the model */
1756 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1758 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1762 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1763 COL_STATUS, current,
1766 path = gtk_tree_model_get_path (model, &iter);
1767 gtk_tree_model_row_changed (model, path, &iter);
1768 gtk_tree_path_free (path);
1771 empathy_account_manager_get_accounts_connected (&found);
1773 if (!found && priv->connecting_id)
1775 g_source_remove (priv->connecting_id);
1776 priv->connecting_id = 0;
1779 if (found && !priv->connecting_id)
1780 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1781 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1786 update_account_in_treeview (EmpathyAccountsDialog *self,
1789 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1791 GtkTreeModel *model;
1793 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1794 if (accounts_dialog_get_account_iter (self, account, &iter))
1798 path = gtk_tree_model_get_path (model, &iter);
1799 gtk_tree_model_row_changed (model, path, &iter);
1800 gtk_tree_path_free (path);
1805 accounts_dialog_presence_changed_cb (TpAccount *account,
1808 gchar *status_message,
1809 EmpathyAccountsDialog *dialog)
1811 /* Update the status-infobar in the details view */
1812 accounts_dialog_update_status_infobar (dialog, account);
1814 update_account_in_treeview (dialog, account);
1818 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1822 const gchar *display_name;
1824 GtkTreeModel *model;
1825 EmpathyAccountSettings *settings;
1826 TpAccount *selected_account;
1827 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1828 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1830 display_name = tp_account_get_display_name (account);
1831 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1832 settings = accounts_dialog_model_get_selected_settings (dialog);
1833 if (settings == NULL)
1836 selected_account = empathy_account_settings_get_account (settings);
1838 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1840 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1841 COL_NAME, display_name,
1845 if (selected_account == account)
1846 accounts_dialog_update_name_label (dialog, display_name);
1848 g_object_unref (settings);
1852 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1855 EmpathyAccountSettings *settings;
1856 GtkTreeModel *model;
1858 TpConnectionStatus status;
1860 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1861 gboolean selected = FALSE;
1862 GtkTreeSelection *selection;
1864 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1865 status = tp_account_get_connection_status (account, NULL);
1866 name = tp_account_get_display_name (account);
1868 settings = empathy_account_settings_new_for_account (account);
1870 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1872 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1874 /* Select the account if it's the first added */
1875 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1878 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1882 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1885 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1888 COL_ACCOUNT, account,
1889 COL_ACCOUNT_SETTINGS, settings,
1894 /* We just modified the selected account. Its display name may have been
1895 * changed and so it's place in the treeview. Scroll to it so it stays
1897 select_and_scroll_to_iter (dialog, &iter);
1900 accounts_dialog_connection_changed_cb (account,
1903 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1908 tp_g_signal_connect_object (account, "notify::display-name",
1909 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1912 tp_g_signal_connect_object (account, "status-changed",
1913 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1914 tp_g_signal_connect_object (account, "presence-changed",
1915 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1917 g_object_unref (settings);
1921 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1924 EmpathyAccountsDialog *dialog)
1926 accounts_dialog_add_account (dialog, account);
1930 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1933 EmpathyAccountsDialog *dialog)
1935 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1937 if (priv->setting_widget_object != NULL &&
1938 accounts_dialog_has_valid_accounts (dialog))
1940 empathy_account_widget_set_other_accounts_exist (
1941 priv->setting_widget_object, TRUE);
1946 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1948 EmpathyAccountsDialog *dialog)
1950 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1952 if (priv->setting_widget_object != NULL &&
1953 !accounts_dialog_has_valid_accounts (dialog))
1955 empathy_account_widget_set_other_accounts_exist (
1956 priv->setting_widget_object, FALSE);
1961 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1963 EmpathyAccountsDialog *dialog)
1966 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1968 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1970 gtk_list_store_remove (GTK_LIST_STORE (
1971 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1976 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1980 /* Update the status-infobar in the details view */
1981 accounts_dialog_update_status_infobar (dialog, account);
1983 DEBUG ("Account %s is now %s",
1984 tp_account_get_display_name (account),
1985 enabled ? "enabled" : "disabled");
1989 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1991 EmpathyAccountsDialog *dialog)
1993 enable_or_disable_account (dialog, account, FALSE);
1994 update_account_in_treeview (dialog, account);
1998 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2000 EmpathyAccountsDialog *dialog)
2002 enable_or_disable_account (dialog, account, TRUE);
2006 display_import_dialog (EmpathyAccountsDialog *dialog)
2008 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2009 GtkWidget *import_dialog;
2011 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2013 gtk_widget_show (import_dialog);
2015 return import_dialog;
2019 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2020 EmpathyAccountsDialog *dialog)
2022 display_import_dialog (dialog);
2026 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2030 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2032 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2034 if (response_id == GTK_RESPONSE_YES)
2035 gtk_widget_destroy (account_dialog);
2039 accounts_dialog_delete_event_cb (GtkWidget *widget,
2041 EmpathyAccountsDialog *dialog)
2043 /* we maunally handle responses to delete events */
2048 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2053 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2054 select_and_scroll_to_iter (dialog, &iter);
2058 salut_valid_cb (GtkWidget *widget,
2062 gtk_widget_set_sensitive (button, valid);
2066 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2068 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2069 GtkWidget *dialog, *widget, *content, *button;
2072 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2073 priv->account_manager))
2076 widget = empathy_local_xmpp_assistant_widget_new ();
2077 gtk_widget_show (widget);
2079 dialog = gtk_dialog_new ();
2081 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2083 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2086 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2087 _("_Connect"), GTK_RESPONSE_YES);
2088 gtk_widget_set_sensitive (button, FALSE);
2090 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2093 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2094 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2096 response = gtk_dialog_run (GTK_DIALOG (dialog));
2098 if (response == GTK_RESPONSE_YES)
2100 empathy_local_xmpp_assistant_widget_create_account (
2101 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2104 gtk_widget_destroy (dialog);
2108 import_dialog_response_cb (GtkDialog *dialog,
2110 EmpathyAccountsDialog *self)
2112 maybe_show_salut_dialog (self);
2116 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2118 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2121 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2124 if (!empathy_import_accounts_to_import ())
2126 maybe_show_salut_dialog (self);
2130 dialog = display_import_dialog (self);
2132 tp_g_signal_connect_object (dialog, "response",
2133 G_CALLBACK (import_dialog_response_cb), self, 0);
2137 finished_loading (EmpathyAccountsDialog *self)
2139 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2140 GtkTreeSelection *selection;
2141 gboolean has_selected;
2143 priv->loading = FALSE;
2145 gtk_widget_set_sensitive (priv->button_add, TRUE);
2146 gtk_widget_set_sensitive (priv->button_import, TRUE);
2147 gtk_widget_set_sensitive (priv->treeview, TRUE);
2149 /* Sensitive the remove button if there is an account selected */
2150 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2151 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2152 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2154 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2155 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2156 NOTEBOOK_PAGE_ACCOUNT);
2158 maybe_show_import_dialog (self);
2162 accounts_dialog_cms_prepare_cb (GObject *source,
2163 GAsyncResult *result,
2166 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2167 EmpathyAccountsDialog *dialog = user_data;
2168 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2170 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2173 /* No need to update the settings if we are already preparing one */
2174 if (priv->settings_ready == NULL)
2175 accounts_dialog_update_settings (dialog, NULL);
2177 if (priv->initial_selection != NULL)
2179 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2180 g_object_unref (priv->initial_selection);
2181 priv->initial_selection = NULL;
2185 finished_loading (dialog);
2189 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2191 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2192 GList *accounts, *l;
2194 g_signal_connect (priv->account_manager, "account-validity-changed",
2195 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2197 g_signal_connect (priv->account_manager, "account-removed",
2198 G_CALLBACK (accounts_dialog_account_removed_cb),
2200 g_signal_connect (priv->account_manager, "account-enabled",
2201 G_CALLBACK (accounts_dialog_account_enabled_cb),
2203 g_signal_connect (priv->account_manager, "account-disabled",
2204 G_CALLBACK (accounts_dialog_account_disabled_cb),
2207 /* Add existing accounts */
2208 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2209 for (l = accounts; l; l = l->next)
2211 accounts_dialog_add_account (dialog, l->data);
2213 g_list_free (accounts);
2215 priv->cms = empathy_connection_managers_dup_singleton ();
2217 empathy_connection_managers_prepare_async (priv->cms,
2218 accounts_dialog_cms_prepare_cb, dialog);
2220 accounts_dialog_model_select_first (dialog);
2224 accounts_dialog_manager_ready_cb (GObject *source_object,
2225 GAsyncResult *result,
2228 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2229 GError *error = NULL;
2231 if (!tp_proxy_prepare_finish (manager, result, &error))
2233 DEBUG ("Failed to prepare account manager: %s", error->message);
2234 g_error_free (error);
2238 accounts_dialog_accounts_setup (user_data);
2242 dialog_response_cb (GtkWidget *widget,
2246 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2248 if (response_id == GTK_RESPONSE_HELP)
2250 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2252 else if (response_id == GTK_RESPONSE_CLOSE ||
2253 response_id == GTK_RESPONSE_DELETE_EVENT)
2255 TpAccount *account = NULL;
2257 if (accounts_dialog_has_pending_change (dialog, &account))
2259 gchar *question_dialog_primary_text = get_dialog_primary_text (
2262 accounts_dialog_show_question_dialog (dialog,
2263 question_dialog_primary_text,
2264 _("You are about to close the window, which will discard\n"
2265 "your changes. Are you sure you want to proceed?"),
2266 G_CALLBACK (accounts_dialog_close_response_cb),
2268 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2269 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2271 g_free (question_dialog_primary_text);
2275 gtk_widget_destroy (widget);
2278 if (account != NULL)
2279 g_object_unref (account);
2284 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2286 GtkWidget *top_hbox;
2289 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2290 GtkWidget *content_area, *action_area;
2291 GtkWidget *grid, *hbox;
2293 GtkWidget *sw, *toolbar;
2294 GtkStyleContext *context;
2296 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2298 gui = empathy_builder_get_file (filename,
2299 "accounts_dialog_hbox", &top_hbox,
2300 "vbox_details", &priv->vbox_details,
2301 "alignment_settings", &priv->alignment_settings,
2302 "alignment_infobar", &priv->alignment_infobar,
2303 "treeview", &priv->treeview,
2304 "button_add", &priv->button_add,
2305 "button_remove", &priv->button_remove,
2306 "button_import", &priv->button_import,
2307 "notebook_account", &priv->notebook_account,
2308 "alignment_loading", &alig,
2310 "add_remove_toolbar", &toolbar,
2314 empathy_builder_connect (gui, dialog,
2315 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2316 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2317 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2318 "treeview", "button-press-event",
2319 accounts_dialog_treeview_button_press_event_cb,
2322 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2324 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2326 g_object_unref (gui);
2328 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2331 gtk_widget_hide (action_area);
2332 gtk_widget_hide (priv->button_remove);
2333 #endif /* HAVE_MEEGO */
2335 /* Display loading page */
2336 priv->loading = TRUE;
2338 priv->spinner = gtk_spinner_new ();
2340 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2341 gtk_widget_show (priv->spinner);
2343 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2345 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2346 NOTEBOOK_PAGE_LOADING);
2348 /* Remove button is insensitive until we have a selected account */
2349 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2351 /* Add and Import buttons and treeview are insensitive while the dialog
2353 gtk_widget_set_sensitive (priv->button_add, FALSE);
2354 gtk_widget_set_sensitive (priv->button_import, FALSE);
2355 gtk_widget_set_sensitive (priv->treeview, FALSE);
2357 if (priv->parent_window)
2358 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2359 priv->parent_window);
2361 priv->infobar = gtk_info_bar_new ();
2362 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2364 gtk_widget_show (priv->infobar);
2366 grid = gtk_grid_new ();
2368 GTK_CONTAINER (gtk_info_bar_get_content_area (
2369 GTK_INFO_BAR (priv->infobar))),
2372 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2373 GTK_ICON_SIZE_DIALOG);
2374 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2375 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2378 priv->label_name = gtk_label_new (NULL);
2379 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2382 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2383 gtk_widget_set_hexpand (hbox, TRUE);
2384 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2385 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2387 /* set up spinner */
2388 priv->throbber = gtk_spinner_new ();
2390 priv->image_status = gtk_image_new_from_icon_name (
2391 empathy_icon_name_for_presence (
2392 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2394 priv->label_status = gtk_label_new (NULL);
2395 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2397 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2398 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2399 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2401 /* enabled switch */
2402 priv->enabled_switch = gtk_switch_new ();
2403 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2404 g_signal_connect (priv->enabled_switch, "notify::active",
2405 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2406 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2408 gtk_widget_show_all (grid);
2410 /* Tweak the dialog */
2411 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2412 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2414 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2416 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2418 /* join the add/remove toolbar to the treeview */
2419 context = gtk_widget_get_style_context (sw);
2420 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2422 context = gtk_widget_get_style_context (toolbar);
2423 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2425 /* add dialog buttons */
2426 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2428 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2429 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2430 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2433 g_signal_connect (dialog, "response",
2434 G_CALLBACK (dialog_response_cb), dialog);
2436 g_signal_connect (dialog, "delete-event",
2437 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2441 do_dispose (GObject *obj)
2443 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2444 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2446 if (priv->connecting_id != 0)
2448 g_source_remove (priv->connecting_id);
2449 priv->connecting_id = 0;
2452 if (priv->account_manager != NULL)
2454 g_object_unref (priv->account_manager);
2455 priv->account_manager = NULL;
2458 if (priv->cms != NULL)
2460 g_object_unref (priv->cms);
2464 if (priv->connectivity)
2466 g_object_unref (priv->connectivity);
2467 priv->connectivity = NULL;
2470 if (priv->initial_selection != NULL)
2472 g_object_unref (priv->initial_selection);
2473 priv->initial_selection = NULL;
2476 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2480 do_get_property (GObject *object,
2485 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2487 switch (property_id)
2490 g_value_set_object (value, priv->parent_window);
2493 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2498 do_set_property (GObject *object,
2500 const GValue *value,
2503 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2505 switch (property_id)
2508 priv->parent_window = g_value_get_object (value);
2511 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2516 do_constructed (GObject *object)
2518 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2519 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2520 GtkTreeModel *model;
2522 accounts_dialog_build_ui (dialog);
2523 accounts_dialog_model_setup (dialog);
2525 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2526 g_signal_connect (model, "row-inserted",
2527 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2528 g_signal_connect (model, "row-deleted",
2529 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2531 /* Set up signalling */
2532 priv->account_manager = tp_account_manager_dup ();
2534 tp_proxy_prepare_async (priv->account_manager, NULL,
2535 accounts_dialog_manager_ready_cb, dialog);
2537 priv->connectivity = empathy_connectivity_dup_singleton ();
2541 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2543 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2544 GParamSpec *param_spec;
2546 oclass->dispose = do_dispose;
2547 oclass->constructed = do_constructed;
2548 oclass->set_property = do_set_property;
2549 oclass->get_property = do_get_property;
2551 param_spec = g_param_spec_object ("parent",
2552 "parent", "The parent window",
2554 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2555 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2557 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2561 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2563 EmpathyAccountsDialogPriv *priv;
2565 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2566 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2567 EmpathyAccountsDialogPriv);
2568 dialog->priv = priv;
2571 /* public methods */
2574 empathy_accounts_dialog_show (GtkWindow *parent,
2575 TpAccount *selected_account)
2577 EmpathyAccountsDialog *dialog;
2578 EmpathyAccountsDialogPriv *priv;
2580 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2581 "parent", parent, NULL);
2583 priv = GET_PRIV (dialog);
2585 if (selected_account)
2587 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2588 accounts_dialog_set_selected_account (dialog, selected_account);
2590 /* save the selection to set it later when the cms
2593 priv->initial_selection = g_object_ref (selected_account);
2596 gtk_window_present (GTK_WINDOW (dialog));
2598 return GTK_WIDGET (dialog);
2602 empathy_accounts_dialog_show_application (GdkScreen *screen,
2603 TpAccount *selected_account,
2609 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2611 args = g_string_new (NULL);
2613 if (selected_account != NULL)
2614 g_string_append_printf (args, " --select-account=%s",
2615 tp_account_get_path_suffix (selected_account));
2618 g_string_append_printf (args, " --if-needed");
2621 g_string_append_printf (args, " --hidden");
2623 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2625 selected_account == NULL ? "<none selected>" :
2626 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2628 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2630 g_string_free (args, TRUE);
2634 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2636 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2637 gboolean result = FALSE;
2639 if (priv->setting_widget_object == NULL)
2642 g_object_get (priv->setting_widget_object,
2643 "creating-account", &result, NULL);