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-pkg-kit.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy-gtk/empathy-ui-utils.h>
48 #include <libempathy-gtk/empathy-protocol-chooser.h>
49 #include <libempathy-gtk/empathy-account-widget.h>
50 #include <libempathy-gtk/empathy-account-widget-irc.h>
51 #include <libempathy-gtk/empathy-account-widget-sip.h>
52 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
53 #include <libempathy-gtk/empathy-contact-widget.h>
54 #include <libempathy-gtk/empathy-images.h>
55 #include <libempathy-gtk/empathy-local-xmpp-assistant-widget.h>
56 #include <libempathy-gtk/empathy-new-account-dialog.h>
58 #include "empathy-accounts-common.h"
59 #include "empathy-accounts-dialog.h"
60 #include "empathy-import-dialog.h"
61 #include "empathy-import-utils.h"
63 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
64 #include <libempathy/empathy-debug.h>
66 /* Flashing delay for icons (milliseconds). */
67 #define FLASH_TIMEOUT 500
69 /* The primary text of the dialog shown to the user when he is about to lose
71 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
72 _("There are unsaved modifications to your %s account.")
73 /* The primary text of the dialog shown to the user when he is about to lose
74 * an unsaved new account */
75 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
76 _("Your new account has not been saved yet.")
78 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
79 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
83 NOTEBOOK_PAGE_ACCOUNT = 0,
84 NOTEBOOK_PAGE_LOADING,
85 NOTEBOOK_PAGE_NO_PROTOCOL
89 GtkWidget *alignment_settings;
90 GtkWidget *alignment_infobar;
92 GtkWidget *vbox_details;
94 GtkWidget *label_status;
95 GtkWidget *image_status;
97 GtkWidget *enabled_switch;
101 GtkWidget *button_add;
102 GtkWidget *button_remove;
103 GtkWidget *button_import;
105 GtkWidget *image_type;
106 GtkWidget *label_name;
107 GtkWidget *label_type;
108 GtkWidget *dialog_content;
110 GtkWidget *notebook_account;
114 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
115 * just its GtkWidget. It is the only reliable source we can query to know if
116 * there are any unsaved changes to the currently selected account. We can't
117 * look at the account settings because it does not contain everything that
118 * can be changed using the EmpathyAccountWidget. For instance, it does not
119 * contain the state of the "Enabled" checkbox.
121 * Even if we create it ourself, we just get a weak ref and not a strong one
122 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
123 * That's kinda ugly; cf bgo #640417.
126 EmpathyAccountWidget *setting_widget_object;
128 gboolean connecting_show;
131 gulong settings_ready_id;
132 EmpathyAccountSettings *settings_ready;
134 TpAccountManager *account_manager;
135 EmpathyConnectionManagers *cms;
136 EmpathyConnectivity *connectivity;
138 GtkWindow *parent_window;
139 TpAccount *initial_selection;
141 /* Those are needed when changing the selected row. When a user selects
142 * another account and there are unsaved changes on the currently selected
143 * one, a confirmation message box is presented to him. Since his answer
144 * is retrieved asynchronously, we keep some information as member of the
145 * EmpathyAccountsDialog object. */
146 gboolean force_change_row;
147 GtkTreeRowReference *destination_row;
148 } EmpathyAccountsDialogPriv;
154 COL_ACCOUNT_SETTINGS,
162 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
163 EmpathyAccountsDialog *dialog);
165 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
167 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
168 EmpathyAccountSettings *settings);
170 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
173 static void accounts_dialog_connection_changed_cb (TpAccount *account,
177 gchar *dbus_error_name,
179 EmpathyAccountsDialog *dialog);
181 static void accounts_dialog_presence_changed_cb (TpAccount *account,
184 gchar *status_message,
185 EmpathyAccountsDialog *dialog);
187 static void accounts_dialog_model_selection_changed (
188 GtkTreeSelection *selection,
189 EmpathyAccountsDialog *dialog);
191 static gboolean accounts_dialog_has_pending_change (
192 EmpathyAccountsDialog *dialog, TpAccount **account);
195 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
196 const gchar *display_name)
199 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
201 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
202 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
208 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
209 const gchar *message)
211 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
212 gchar *message_markup;
214 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
215 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
217 gtk_widget_set_tooltip_text (priv->label_status, message);
219 g_free (message_markup);
223 accounts_dialog_enable_account_cb (GObject *account,
224 GAsyncResult *result,
227 GError *error = NULL;
229 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
233 DEBUG ("Could not enable the account: %s", error->message);
234 g_error_free (error);
238 TpAccountManager *am = tp_account_manager_dup ();
240 empathy_connect_new_account (TP_ACCOUNT (account), am);
246 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
248 EmpathyAccountsDialog *dialog)
250 EmpathyAccountSettings *settings;
253 settings = accounts_dialog_model_get_selected_settings (dialog);
254 if (settings == NULL)
257 account = empathy_account_settings_get_account (settings);
261 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
262 accounts_dialog_enable_account_cb, NULL);
266 install_haze_cb (GObject *source,
267 GAsyncResult *result,
270 GError *error = NULL;
272 if (!empathy_pkg_kit_install_packages_finish (result, &error))
274 DEBUG ("Failed to install telepathy-haze: %s", error->message);
276 g_error_free (error);
281 account_is_selected (EmpathyAccountsDialog *dialog,
284 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
285 GtkTreeSelection *selection;
288 TpAccount *selected_account;
293 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
295 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
298 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
300 if (selected_account != NULL)
301 g_object_unref (selected_account);
303 return account == selected_account;
307 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
310 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
311 gchar *status_message = NULL;
315 gboolean account_enabled;
316 gboolean creating_account;
317 TpStorageRestrictionFlags storage_restrictions = 0;
318 gboolean display_switch = TRUE;
320 /* do not update the infobar when the account is not selected */
321 if (!account_is_selected (dialog, account))
326 status = tp_account_get_connection_status (account, &reason);
327 presence = tp_account_get_current_presence (account, NULL, &status_message);
328 account_enabled = tp_account_is_enabled (account);
329 creating_account = FALSE;
331 if (status == TP_CONNECTION_STATUS_CONNECTED &&
332 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
333 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
334 /* If presence is Unset (CM doesn't implement SimplePresence) but we
335 * are connected, consider ourself as Available.
336 * We also check Offline because of this MC5 bug: fd.o #26060 */
337 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
339 /* set presence to offline if account is disabled
340 * (else no icon is shown in infobar)*/
341 if (!account_enabled)
342 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
344 storage_restrictions = tp_account_get_storage_restrictions (account);
345 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
346 display_switch = FALSE;
348 /* Butterfly accounts shouldn't be used any more */
349 if (!tp_strdiff (tp_account_get_connection_manager (account),
351 display_switch = FALSE;
355 status = TP_CONNECTION_STATUS_DISCONNECTED;
356 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
357 account_enabled = FALSE;
358 creating_account = TRUE;
361 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
362 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
364 /* update the enabled switch */
365 g_signal_handlers_block_by_func (priv->enabled_switch,
366 accounts_dialog_enable_switch_active_cb, dialog);
367 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
369 g_signal_handlers_unblock_by_func (priv->enabled_switch,
370 accounts_dialog_enable_switch_active_cb, dialog);
372 /* Display the Enable switch if account supports it */
373 gtk_widget_set_visible (priv->enabled_switch, display_switch);
379 case TP_CONNECTION_STATUS_CONNECTING:
380 accounts_dialog_status_infobar_set_message (dialog,
382 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
385 gtk_spinner_start (GTK_SPINNER (priv->throbber));
386 gtk_widget_show (priv->throbber);
387 gtk_widget_hide (priv->image_status);
389 case TP_CONNECTION_STATUS_CONNECTED:
390 if (g_strcmp0 (status_message, "") == 0)
394 message = g_strdup_printf ("%s",
395 empathy_presence_get_default_message (presence));
397 accounts_dialog_status_infobar_set_message (dialog, message);
404 message = g_strdup_printf ("%s — %s",
405 empathy_presence_get_default_message (presence),
408 accounts_dialog_status_infobar_set_message (dialog, message);
411 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
414 gtk_widget_show (priv->image_status);
415 gtk_widget_hide (priv->throbber);
417 case TP_CONNECTION_STATUS_DISCONNECTED:
418 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
422 message = g_strdup_printf (_("Offline — %s"),
423 empathy_account_get_error_message (account, NULL));
424 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
425 GTK_MESSAGE_WARNING);
427 accounts_dialog_status_infobar_set_message (dialog, message);
434 message = g_strdup_printf (_("Disconnected — %s"),
435 empathy_account_get_error_message (account, NULL));
436 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
439 accounts_dialog_status_infobar_set_message (dialog, message);
443 if (!empathy_connectivity_is_online (priv->connectivity))
444 accounts_dialog_status_infobar_set_message (dialog,
445 _("Offline — No Network Connection"));
447 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
448 gtk_widget_show (priv->image_status);
449 gtk_widget_hide (priv->throbber);
452 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
453 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
454 GTK_MESSAGE_WARNING);
456 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
457 gtk_widget_hide (priv->image_status);
458 gtk_widget_hide (priv->throbber);
463 if (!tp_strdiff (tp_account_get_connection_manager (account),
466 const gchar *packages[] = { "telepathy-haze", NULL };
468 accounts_dialog_status_infobar_set_message (dialog,
469 _("This account has been disabled because it relies on an old, "
470 "unsupported backend. Please install telepathy-haze and "
471 "restart your session to migrate the account."));
473 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
474 install_haze_cb, NULL);
478 accounts_dialog_status_infobar_set_message (dialog,
479 _("Offline — Account Disabled"));
482 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
483 GTK_MESSAGE_WARNING);
484 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
485 gtk_widget_show (priv->image_status);
486 gtk_widget_hide (priv->throbber);
489 gtk_widget_show (priv->label_status);
491 if (!creating_account)
492 gtk_widget_show (priv->infobar);
494 gtk_widget_hide (priv->infobar);
496 g_free (status_message);
500 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
504 GtkTreeSelection *selection;
506 EmpathyAccountSettings *settings;
508 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
510 view = GTK_TREE_VIEW (priv->treeview);
511 selection = gtk_tree_view_get_selection (view);
513 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
516 gtk_tree_model_get (model, &iter,
517 COL_ACCOUNT_SETTINGS, &settings,
518 COL_ACCOUNT, &account, -1);
520 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
524 /* We were creating an account. We remove the selected row */
525 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
529 /* We were modifying an account. We discard the changes by reloading the
530 * settings and the UI. */
531 accounts_dialog_update_settings (dialog, settings);
532 g_object_unref (account);
535 gtk_widget_set_sensitive (priv->treeview, TRUE);
536 gtk_widget_set_sensitive (priv->button_add, TRUE);
537 gtk_widget_set_sensitive (priv->button_remove, TRUE);
538 gtk_widget_set_sensitive (priv->button_import, TRUE);
540 if (settings != NULL)
541 g_object_unref (settings);
545 empathy_account_dialog_widget_cancelled_cb (
546 EmpathyAccountWidget *widget_object,
547 EmpathyAccountsDialog *dialog)
549 empathy_account_dialog_cancel (dialog);
553 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
555 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
560 g_object_get (priv->setting_widget_object,
561 "creating-account", &creating, NULL);
566 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
568 if (gtk_tree_model_get_iter_first (model, &iter))
569 return gtk_tree_model_iter_next (model, &iter);
575 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
577 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
578 EmpathyAccountSettings *settings;
579 GtkWidget *subdialog, *content, *content_area, *align;
581 settings = accounts_dialog_model_get_selected_settings (dialog);
582 if (settings == NULL)
585 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
587 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
590 priv->setting_widget_object =
591 empathy_account_widget_new_for_protocol (settings, FALSE);
593 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
594 (gpointer *) &priv->setting_widget_object);
596 if (accounts_dialog_has_valid_accounts (dialog))
597 empathy_account_widget_set_other_accounts_exist (
598 priv->setting_widget_object, TRUE);
600 content = empathy_account_widget_get_widget (priv->setting_widget_object);
602 g_signal_connect (priv->setting_widget_object, "cancelled",
603 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
605 g_signal_connect_swapped (priv->setting_widget_object, "close",
606 G_CALLBACK (gtk_widget_destroy), subdialog);
608 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
610 align = gtk_alignment_new (0.5, 0.5, 1, 1);
611 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
613 gtk_container_add (GTK_CONTAINER (align), content);
614 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
616 gtk_widget_show (content);
617 gtk_widget_show (align);
618 gtk_widget_show (subdialog);
622 start_external_app (GAppInfo *app_info)
624 GError *error = NULL;
625 GdkAppLaunchContext *context = NULL;
628 display = gdk_display_get_default ();
629 context = gdk_display_get_app_launch_context (display);
631 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
634 g_critical ("Failed to bisho: %s", error->message);
635 g_clear_error (&error);
638 tp_clear_object (&context);
642 use_external_storage_provider (EmpathyAccountsDialog *self,
645 const gchar *provider;
647 provider = tp_account_get_storage_provider (account);
648 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
650 GDesktopAppInfo *desktop_info;
653 GError *error = NULL;
655 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
656 if (desktop_info == NULL)
658 g_critical ("Could not locate 'gnome-control-center.desktop'");
662 /* glib doesn't have API to start a desktop file with args... (#637875) */
663 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
664 (GAppInfo *) desktop_info));
666 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
668 if (app_info == NULL)
670 DEBUG ("Failed to create app info: %s", error->message);
671 g_error_free (error);
675 start_external_app (app_info);
676 g_object_unref (app_info);
679 g_object_unref (desktop_info);
683 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
685 GDesktopAppInfo *desktop_info;
687 desktop_info = g_desktop_app_info_new (
688 "gnome-online-accounts-panel.desktop");
689 if (desktop_info == NULL)
691 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
695 start_external_app (G_APP_INFO (desktop_info));
696 g_object_unref (desktop_info);
703 DEBUG ("Don't know how to handle %s", provider);
709 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
712 EmpathyAccountSettings *settings;
714 TpStorageRestrictionFlags storage_restrictions;
716 settings = accounts_dialog_model_get_selected_settings (dialog);
717 if (settings == NULL)
720 account = empathy_account_settings_get_account (settings);
721 g_return_if_fail (account != NULL);
723 storage_restrictions = tp_account_get_storage_restrictions (account);
725 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
726 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
728 DEBUG ("Account is provided by an external storage provider");
730 use_external_storage_provider (dialog, account);
734 account_dialog_create_edit_params_dialog (dialog);
739 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
742 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
743 GtkWidget *infobar, *label;
745 infobar = gtk_info_bar_new ();
749 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
750 label = gtk_label_new (_("Failed to retrieve your personal information "
751 "from the server."));
755 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
756 label = gtk_label_new (_("Go online to edit your personal information."));
760 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
762 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
763 gtk_widget_show_all (infobar);
767 account_dialog_got_self_contact (TpConnection *conn,
768 EmpathyContact *contact,
769 const GError *in_error,
773 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
774 GtkWidget *editor, *alig;
776 if (in_error != NULL)
778 DEBUG ("Failed to get self-contact: %s", in_error->message);
779 account_dialog_show_contact_details_failed (
780 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
784 alig = gtk_alignment_new (0.5, 0, 1, 1);
786 /* create the contact info editor for this account */
787 editor = empathy_contact_widget_new (contact,
788 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
789 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
790 EMPATHY_CONTACT_WIDGET_NO_STATUS |
791 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS |
792 EMPATHY_CONTACT_WIDGET_NO_ACCOUNT);
794 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
795 gtk_container_add (GTK_CONTAINER (alig), editor);
796 gtk_widget_show (alig);
797 gtk_widget_show (editor);
801 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
802 EmpathyAccountSettings *settings)
804 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
805 const gchar *icon_name;
807 TpConnection *conn = NULL;
808 GtkWidget *bbox, *button;
810 account = empathy_account_settings_get_account (settings);
812 // if (priv->setting_widget_object != NULL)
813 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
814 // (gpointer *) &priv->setting_widget_object);
816 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
817 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
818 priv->dialog_content);
819 gtk_widget_show (priv->dialog_content);
821 /* request the self contact */
823 conn = tp_account_get_connection (account);
826 tp_proxy_get_invalidated (conn) == NULL)
828 empathy_tp_contact_factory_get_from_handle (conn,
829 tp_connection_get_self_handle (conn),
830 account_dialog_got_self_contact,
831 NULL, NULL, G_OBJECT (dialog));
835 account_dialog_show_contact_details_failed (dialog, FALSE);
838 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
839 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
840 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
841 gtk_widget_show (bbox);
843 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
844 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
845 gtk_widget_show (button);
846 g_signal_connect_swapped (button, "clicked",
847 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
849 icon_name = empathy_account_settings_get_icon_name (settings);
851 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
853 /* show the default icon; keep this in sync with the default
854 * one in empathy-accounts-dialog.ui.
856 icon_name = GTK_STOCK_CUT;
858 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
859 icon_name, GTK_ICON_SIZE_DIALOG);
860 gtk_widget_set_tooltip_text (priv->image_type,
861 empathy_protocol_name_to_display_name
862 (empathy_account_settings_get_protocol (settings)));
863 gtk_widget_show (priv->image_type);
865 accounts_dialog_update_name_label (dialog,
866 empathy_account_settings_get_display_name (settings));
868 accounts_dialog_update_status_infobar (dialog, account);
872 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
874 EmpathyAccountsDialog *dialog)
876 if (empathy_account_settings_is_ready (settings))
877 account_dialog_create_dialog_content (dialog, settings);
881 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
885 GtkTreeSelection *selection;
887 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
890 view = GTK_TREE_VIEW (priv->treeview);
891 model = gtk_tree_view_get_model (view);
893 if (gtk_tree_model_get_iter_first (model, &iter))
895 selection = gtk_tree_view_get_selection (view);
896 gtk_tree_selection_select_iter (selection, &iter);
900 accounts_dialog_update_settings (dialog, NULL);
905 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
910 GtkTreeSelection *selection;
911 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
913 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
915 if (gtk_tree_selection_get_selected (selection, &model, &iter))
916 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
918 return priv->setting_widget_object != NULL
919 && empathy_account_widget_contains_pending_changes (
920 priv->setting_widget_object);
924 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
925 const gchar *primary_text,
926 const gchar *secondary_text,
927 GCallback response_callback,
929 const gchar *first_button_text,
933 GtkWidget *message_dialog;
934 const gchar *button_text;
936 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
937 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
938 GTK_MESSAGE_QUESTION,
942 gtk_message_dialog_format_secondary_text (
943 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
945 va_start (button_args, first_button_text);
946 for (button_text = first_button_text;
948 button_text = va_arg (button_args, const gchar *))
951 response_id = va_arg (button_args, gint);
953 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
956 va_end (button_args);
958 g_signal_connect (message_dialog, "response", response_callback, user_data);
960 gtk_widget_show (message_dialog);
964 get_dialog_primary_text (TpAccount *account)
968 /* Existing account */
969 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
970 tp_account_get_display_name (account));
974 /* Newly created account */
975 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
980 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
981 EmpathyAccountsDialog *self)
986 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
987 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
989 response = gtk_dialog_run (GTK_DIALOG (dialog));
991 if (response == GTK_RESPONSE_OK)
993 EmpathyAccountSettings *settings;
996 settings = empathy_new_account_dialog_get_settings (
997 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
999 /* The newly created account has already been added by
1000 * accounts_dialog_account_validity_changed_cb so we just
1001 * have to select it. */
1002 account = empathy_account_settings_get_account (settings);
1003 accounts_dialog_model_set_selected (self, account);
1006 gtk_widget_destroy (dialog);
1010 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
1011 EmpathyAccountSettings *settings)
1013 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1015 if (priv->settings_ready != NULL)
1017 g_signal_handler_disconnect (priv->settings_ready,
1018 priv->settings_ready_id);
1019 priv->settings_ready = NULL;
1020 priv->settings_ready_id = 0;
1026 GtkTreeModel *model;
1027 GtkTreeSelection *selection;
1029 view = GTK_TREE_VIEW (priv->treeview);
1030 model = gtk_tree_view_get_model (view);
1031 selection = gtk_tree_view_get_selection (view);
1033 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
1035 /* We have configured accounts, select the first one if there
1036 * is no other account selected already. */
1037 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
1038 accounts_dialog_model_select_first (dialog);
1043 /* No account and no profile, warn the user */
1044 gtk_widget_hide (priv->vbox_details);
1045 gtk_widget_set_sensitive (priv->button_add, FALSE);
1047 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
1048 NOTEBOOK_PAGE_NO_PROTOCOL);
1052 /* We have an account selected, destroy old settings and create a new
1053 * one for the account selected */
1054 gtk_widget_show (priv->vbox_details);
1056 if (priv->dialog_content)
1058 gtk_widget_destroy (priv->dialog_content);
1059 priv->dialog_content = NULL;
1062 if (empathy_account_settings_is_ready (settings))
1064 account_dialog_create_dialog_content (dialog, settings);
1068 priv->settings_ready = settings;
1069 priv->settings_ready_id =
1070 g_signal_connect (settings, "notify::ready",
1071 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1077 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1078 GtkCellEditable *editable,
1080 EmpathyAccountsDialog *dialog)
1082 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1084 if (priv->connecting_id)
1085 g_source_remove (priv->connecting_id);
1087 DEBUG ("Editing account name started; stopping flashing");
1090 static const gchar *
1091 get_status_icon_for_account (EmpathyAccountsDialog *self,
1094 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1095 TpConnectionStatus status;
1096 TpConnectionStatusReason reason;
1097 TpConnectionPresenceType presence;
1099 if (account == NULL)
1100 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1102 if (!tp_account_is_enabled (account))
1103 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1105 status = tp_account_get_connection_status (account, &reason);
1107 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1109 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1110 /* An error occured */
1111 return GTK_STOCK_DIALOG_ERROR;
1113 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1115 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1117 /* Account is connecting. Display a blinking account alternating between
1118 * the offline icon and the requested presence. */
1119 if (priv->connecting_show)
1120 presence = tp_account_get_requested_presence (account, NULL, NULL);
1122 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1126 /* status == TP_CONNECTION_STATUS_CONNECTED */
1127 presence = tp_account_get_current_presence (account, NULL, NULL);
1129 /* If presence is Unset (CM doesn't implement SimplePresence),
1130 * display the 'available' icon.
1131 * We also check Offline because of this MC5 bug: fd.o #26060 */
1132 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1133 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1134 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1137 return empathy_icon_name_for_presence (presence);
1141 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1142 GtkCellRenderer *cell,
1143 GtkTreeModel *model,
1145 EmpathyAccountsDialog *dialog)
1149 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1152 "icon-name", get_status_icon_for_account (dialog, account),
1155 if (account != NULL)
1156 g_object_unref (account);
1160 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1161 GtkCellRenderer *cell,
1162 GtkTreeModel *model,
1164 EmpathyAccountsDialog *dialog)
1166 EmpathyAccountSettings *settings;
1169 TpConnectionStatus status;
1171 gtk_tree_model_get (model, iter,
1172 COL_STATUS, &status,
1173 COL_ACCOUNT_SETTINGS, &settings,
1176 icon_name = empathy_account_settings_get_icon_name (settings);
1177 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1184 g_object_unref (settings);
1187 g_object_unref (pixbuf);
1191 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1198 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1200 if (account == NULL)
1203 if (tp_account_get_connection_status (account, NULL) ==
1204 TP_CONNECTION_STATUS_CONNECTING)
1206 /* Only update the row where we have a connecting account as that's the
1207 * ones having a blinking icon. */
1208 gtk_tree_model_row_changed (model, path, iter);
1211 g_object_unref (account);
1216 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1219 GtkTreeModel *model;
1220 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1222 priv->connecting_show = !priv->connecting_show;
1224 view = GTK_TREE_VIEW (priv->treeview);
1225 model = gtk_tree_view_get_model (view);
1227 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1233 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1236 EmpathyAccountsDialog *dialog)
1238 EmpathyAccountSettings *settings;
1239 GtkTreeModel *model;
1240 GtkTreePath *treepath;
1242 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1243 gboolean connecting;
1245 empathy_account_manager_get_accounts_connected (&connecting);
1249 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1250 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1254 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1255 treepath = gtk_tree_path_new_from_string (path);
1256 gtk_tree_model_get_iter (model, &iter, treepath);
1257 gtk_tree_model_get (model, &iter,
1258 COL_ACCOUNT_SETTINGS, &settings,
1260 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1263 gtk_tree_path_free (treepath);
1265 empathy_account_settings_set_display_name_async (settings, new_text,
1267 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1268 g_object_unref (settings);
1272 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1277 GtkTreeModel *model;
1279 GtkTreeSelection *selection;
1280 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1281 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1283 if (response_id == GTK_RESPONSE_YES)
1285 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1287 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1290 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1292 if (account != NULL)
1294 tp_account_remove_async (account, NULL, NULL);
1295 g_object_unref (account);
1299 /* No need to call accounts_dialog_model_selection_changed while
1300 * removing as we are going to call accounts_dialog_model_select_first
1301 * right after which will update the selection. */
1302 g_signal_handlers_block_by_func (selection,
1303 accounts_dialog_model_selection_changed, account_dialog);
1305 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1307 g_signal_handlers_unblock_by_func (selection,
1308 accounts_dialog_model_selection_changed, account_dialog);
1310 accounts_dialog_model_select_first (account_dialog);
1313 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1317 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1320 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1322 GtkTreeModel *model;
1323 gchar *question_dialog_primary_text;
1325 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1327 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1329 if (account == NULL || !tp_account_is_valid (account))
1331 if (account != NULL)
1332 g_object_unref (account);
1333 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1334 accounts_dialog_model_select_first (dialog);
1338 question_dialog_primary_text = g_strdup_printf (
1339 _("Do you want to remove %s from your computer?"),
1340 tp_account_get_display_name (account));
1342 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1343 _("This will not remove your account on the server."),
1344 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1346 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1347 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1349 g_free (question_dialog_primary_text);
1350 g_object_unref (account);
1354 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1355 EmpathyAccountsDialog *dialog)
1357 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1359 GtkTreeSelection *selection;
1362 view = GTK_TREE_VIEW (priv->treeview);
1363 selection = gtk_tree_view_get_selection (view);
1364 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1367 accounts_dialog_remove_account_iter (dialog, &iter);
1372 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1373 const gchar *path_string,
1374 EmpathyAccountsDialog *dialog)
1376 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1377 GtkTreeModel *model;
1380 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1381 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1384 accounts_dialog_remove_account_iter (dialog, &iter);
1386 #endif /* HAVE_MEEGO */
1389 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1392 GtkTreeViewColumn *column;
1393 GtkCellRenderer *cell;
1394 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1396 view = GTK_TREE_VIEW (priv->treeview);
1397 gtk_tree_view_set_headers_visible (view, FALSE);
1399 /* Account column */
1400 column = gtk_tree_view_column_new ();
1401 gtk_tree_view_column_set_expand (column, TRUE);
1402 gtk_tree_view_append_column (view, column);
1404 /* Status icon renderer */
1405 cell = gtk_cell_renderer_pixbuf_new ();
1406 gtk_tree_view_column_pack_start (column, cell, FALSE);
1407 gtk_tree_view_column_set_cell_data_func (column, cell,
1408 (GtkTreeCellDataFunc)
1409 accounts_dialog_model_status_pixbuf_data_func,
1413 /* Protocol icon renderer */
1414 cell = gtk_cell_renderer_pixbuf_new ();
1415 gtk_tree_view_column_pack_start (column, cell, FALSE);
1416 gtk_tree_view_column_set_cell_data_func (column, cell,
1417 (GtkTreeCellDataFunc)
1418 accounts_dialog_model_protocol_pixbuf_data_func,
1423 cell = gtk_cell_renderer_text_new ();
1425 "ellipsize", PANGO_ELLIPSIZE_END,
1429 gtk_tree_view_column_pack_start (column, cell, TRUE);
1430 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1431 g_signal_connect (cell, "edited",
1432 G_CALLBACK (accounts_dialog_name_edited_cb),
1434 g_signal_connect (cell, "editing-started",
1435 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1437 g_object_set (cell, "ypad", 4, NULL);
1441 cell = empathy_cell_renderer_activatable_new ();
1442 gtk_tree_view_column_pack_start (column, cell, FALSE);
1444 "icon-name", GTK_STOCK_DELETE,
1445 "show-on-select", TRUE,
1448 g_signal_connect (cell, "path-activated",
1449 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1451 #endif /* HAVE_MEEGO */
1454 static EmpathyAccountSettings *
1455 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1458 GtkTreeModel *model;
1459 GtkTreeSelection *selection;
1461 EmpathyAccountSettings *settings;
1462 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1464 view = GTK_TREE_VIEW (priv->treeview);
1465 selection = gtk_tree_view_get_selection (view);
1467 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1470 gtk_tree_model_get (model, &iter,
1471 COL_ACCOUNT_SETTINGS, &settings, -1);
1477 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1478 EmpathyAccountsDialog *dialog)
1480 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1481 EmpathyAccountSettings *settings;
1482 GtkTreeModel *model;
1484 gboolean is_selection;
1485 gboolean creating = FALSE;
1487 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1489 settings = accounts_dialog_model_get_selected_settings (dialog);
1490 accounts_dialog_update_settings (dialog, settings);
1492 if (settings != NULL)
1493 g_object_unref (settings);
1495 if (priv->setting_widget_object != NULL)
1497 g_object_get (priv->setting_widget_object,
1498 "creating-account", &creating, NULL);
1501 /* Update remove button sensitivity */
1502 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1507 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1509 gpointer *user_data)
1511 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1512 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1514 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1516 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1518 /* The user wants to lose unsaved changes to the currently selected
1519 * account and select another account. We discard the changes and
1520 * select the other account. */
1522 GtkTreeSelection *selection;
1524 priv->force_change_row = TRUE;
1525 empathy_account_widget_discard_pending_changes (
1526 priv->setting_widget_object);
1528 path = gtk_tree_row_reference_get_path (priv->destination_row);
1529 selection = gtk_tree_view_get_selection (
1530 GTK_TREE_VIEW (priv->treeview));
1534 /* This will trigger a call to
1535 * accounts_dialog_account_selection_change() */
1536 gtk_tree_selection_select_path (selection, path);
1537 gtk_tree_path_free (path);
1540 gtk_tree_row_reference_free (priv->destination_row);
1544 priv->force_change_row = FALSE;
1549 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1550 GtkTreeModel *model,
1552 gboolean path_currently_selected,
1555 TpAccount *account = NULL;
1556 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1557 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1560 if (priv->force_change_row)
1562 /* We came back here because the user wants to discard changes to his
1563 * modified account. The changes have already been discarded so we
1564 * just change the selected row. */
1565 priv->force_change_row = FALSE;
1569 if (accounts_dialog_has_pending_change (dialog, &account))
1571 /* The currently selected account has some unsaved changes. We ask
1572 * the user if he really wants to lose his changes and select another
1574 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1575 priv->destination_row = gtk_tree_row_reference_new (model, path);
1577 accounts_dialog_show_question_dialog (dialog,
1578 question_dialog_primary_text,
1579 _("You are about to select another account, which will discard\n"
1580 "your changes. Are you sure you want to proceed?"),
1581 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1583 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1584 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1586 g_free (question_dialog_primary_text);
1594 if (account != NULL)
1595 g_object_unref (account);
1601 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1603 GtkListStore *store;
1604 GtkTreeSelection *selection;
1605 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1607 store = gtk_list_store_new (COL_COUNT,
1608 G_TYPE_STRING, /* name */
1609 G_TYPE_UINT, /* status */
1610 TP_TYPE_ACCOUNT, /* account */
1611 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1613 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1614 GTK_TREE_MODEL (store));
1616 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1617 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1618 gtk_tree_selection_set_select_function (selection,
1619 accounts_dialog_account_selection_change, dialog, NULL);
1621 g_signal_connect (selection, "changed",
1622 G_CALLBACK (accounts_dialog_model_selection_changed),
1625 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1626 COL_NAME, GTK_SORT_ASCENDING);
1628 accounts_dialog_model_add_columns (dialog);
1630 g_object_unref (store);
1634 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1639 GtkTreeModel *model;
1641 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1643 /* Update the status in the model */
1644 view = GTK_TREE_VIEW (priv->treeview);
1645 model = gtk_tree_view_get_model (view);
1647 for (ok = gtk_tree_model_get_iter_first (model, iter);
1649 ok = gtk_tree_model_iter_next (model, iter))
1651 TpAccount *this_account;
1654 gtk_tree_model_get (model, iter,
1655 COL_ACCOUNT, &this_account,
1658 equal = (this_account == account);
1659 g_object_unref (this_account);
1669 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1672 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1673 GtkTreeSelection *selection;
1675 GtkTreeModel *model;
1677 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1679 gtk_tree_selection_select_iter (selection, iter);
1681 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1682 path = gtk_tree_model_get_path (model, iter);
1684 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1687 gtk_tree_path_free (path);
1691 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1696 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1697 select_and_scroll_to_iter (dialog, &iter);
1701 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1706 enabled = tp_account_is_enabled (account);
1707 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1711 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1712 GdkEventButton *event,
1713 EmpathyAccountsDialog *dialog)
1715 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1716 TpAccount *account = NULL;
1717 GtkTreeModel *model = NULL;
1718 GtkTreePath *path = NULL;
1721 GtkWidget *item_enable, *item_disable;
1722 GtkWidget *image_enable, *image_disable;
1724 /* ignore multiple clicks */
1725 if (event->type != GDK_BUTTON_PRESS)
1728 if (event->button != 3)
1731 /* Selection is not yet set, so we have to get account from event position */
1732 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1733 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1734 event->x, event->y, &path, NULL, NULL, NULL))
1737 if (!gtk_tree_model_get_iter (model, &iter, path))
1740 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1742 /* Create the menu */
1743 menu = empathy_context_menu_new (GTK_WIDGET (view));
1745 /* Get images for menu items */
1746 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1747 tp_account_manager_get_most_available_presence (
1748 priv->account_manager, NULL, NULL)),
1749 GTK_ICON_SIZE_MENU);
1750 image_disable = gtk_image_new_from_icon_name (
1751 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1752 GTK_ICON_SIZE_MENU);
1754 /* Menu items: to enabled/disable the account */
1755 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1756 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1757 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1759 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1762 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1763 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1765 if (tp_account_is_enabled (account))
1767 tp_g_signal_connect_object (item_disable, "activate",
1768 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1769 gtk_widget_set_sensitive (item_enable, FALSE);
1773 tp_g_signal_connect_object (item_enable, "activate",
1774 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1775 gtk_widget_set_sensitive (item_disable, FALSE);
1778 gtk_widget_show (item_enable);
1779 gtk_widget_show (item_disable);
1781 /* FIXME: Add here presence items, to be able to set per-account presence */
1784 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1785 event->button, event->time);
1788 tp_clear_object (&account);
1789 gtk_tree_path_free (path);
1795 reload_account_widget (EmpathyAccountsDialog *self)
1797 EmpathyAccountSettings *settings;
1799 settings = accounts_dialog_model_get_selected_settings (self);
1800 accounts_dialog_update_settings (self, settings);
1804 accounts_dialog_connection_changed_cb (TpAccount *account,
1808 gchar *dbus_error_name,
1809 GHashTable *details,
1810 EmpathyAccountsDialog *dialog)
1812 GtkTreeModel *model;
1815 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1817 /* Update the status-infobar in the details view */
1818 accounts_dialog_update_status_infobar (dialog, account);
1820 /* Update the status in the model */
1821 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1823 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1827 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1828 COL_STATUS, current,
1831 path = gtk_tree_model_get_path (model, &iter);
1832 gtk_tree_model_row_changed (model, path, &iter);
1833 gtk_tree_path_free (path);
1836 empathy_account_manager_get_accounts_connected (&found);
1838 if (!found && priv->connecting_id)
1840 g_source_remove (priv->connecting_id);
1841 priv->connecting_id = 0;
1844 if (found && !priv->connecting_id)
1845 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1846 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1851 update_account_in_treeview (EmpathyAccountsDialog *self,
1854 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1856 GtkTreeModel *model;
1858 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1859 if (accounts_dialog_get_account_iter (self, account, &iter))
1863 path = gtk_tree_model_get_path (model, &iter);
1864 gtk_tree_model_row_changed (model, path, &iter);
1865 gtk_tree_path_free (path);
1870 accounts_dialog_presence_changed_cb (TpAccount *account,
1873 gchar *status_message,
1874 EmpathyAccountsDialog *dialog)
1876 /* Update the status-infobar in the details view */
1877 accounts_dialog_update_status_infobar (dialog, account);
1879 update_account_in_treeview (dialog, account);
1883 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1887 const gchar *display_name;
1889 GtkTreeModel *model;
1890 EmpathyAccountSettings *settings;
1891 TpAccount *selected_account;
1892 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1893 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1895 display_name = tp_account_get_display_name (account);
1896 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1897 settings = accounts_dialog_model_get_selected_settings (dialog);
1898 if (settings == NULL)
1901 selected_account = empathy_account_settings_get_account (settings);
1903 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1905 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1906 COL_NAME, display_name,
1910 if (selected_account == account)
1911 accounts_dialog_update_name_label (dialog, display_name);
1913 g_object_unref (settings);
1917 conn_prepare_cb (GObject *source,
1918 GAsyncResult *result,
1921 EmpathyAccountsDialog *self = user_data;
1923 reload_account_widget (self);
1927 accounts_dialog_notify_connection_cb (TpAccount *account,
1929 EmpathyAccountsDialog *self)
1932 if (!account_is_selected (self, account))
1935 conn = tp_account_get_connection (account);
1938 reload_account_widget (self);
1942 /* Wait for this feature so TpConnection will have fetch the
1944 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1946 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1951 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1954 EmpathyAccountSettings *settings;
1955 GtkTreeModel *model;
1957 TpConnectionStatus status;
1959 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1960 gboolean selected = FALSE;
1961 GtkTreeSelection *selection;
1963 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1964 status = tp_account_get_connection_status (account, NULL);
1965 name = tp_account_get_display_name (account);
1967 settings = empathy_account_settings_new_for_account (account);
1969 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1971 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1973 /* Select the account if it's the first added */
1974 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1977 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1981 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1984 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1987 COL_ACCOUNT, account,
1988 COL_ACCOUNT_SETTINGS, settings,
1993 /* We just modified the selected account. Its display name may have been
1994 * changed and so it's place in the treeview. Scroll to it so it stays
1996 select_and_scroll_to_iter (dialog, &iter);
1999 accounts_dialog_connection_changed_cb (account,
2002 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
2007 tp_g_signal_connect_object (account, "notify::display-name",
2008 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
2011 tp_g_signal_connect_object (account, "status-changed",
2012 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
2013 tp_g_signal_connect_object (account, "presence-changed",
2014 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
2015 tp_g_signal_connect_object (account, "notify::connection",
2016 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
2018 g_object_unref (settings);
2022 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
2025 EmpathyAccountsDialog *dialog)
2027 accounts_dialog_add_account (dialog, account);
2031 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
2034 EmpathyAccountsDialog *dialog)
2036 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2038 if (priv->setting_widget_object != NULL &&
2039 accounts_dialog_has_valid_accounts (dialog))
2041 empathy_account_widget_set_other_accounts_exist (
2042 priv->setting_widget_object, TRUE);
2047 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
2049 EmpathyAccountsDialog *dialog)
2051 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2053 if (priv->setting_widget_object != NULL &&
2054 !accounts_dialog_has_valid_accounts (dialog))
2056 empathy_account_widget_set_other_accounts_exist (
2057 priv->setting_widget_object, FALSE);
2062 accounts_dialog_account_removed_cb (TpAccountManager *manager,
2064 EmpathyAccountsDialog *dialog)
2067 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2069 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2071 gtk_list_store_remove (GTK_LIST_STORE (
2072 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
2077 enable_or_disable_account (EmpathyAccountsDialog *dialog,
2081 /* Update the status-infobar in the details view */
2082 accounts_dialog_update_status_infobar (dialog, account);
2084 DEBUG ("Account %s is now %s",
2085 tp_account_get_display_name (account),
2086 enabled ? "enabled" : "disabled");
2090 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
2092 EmpathyAccountsDialog *dialog)
2094 enable_or_disable_account (dialog, account, FALSE);
2095 update_account_in_treeview (dialog, account);
2099 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2101 EmpathyAccountsDialog *dialog)
2103 enable_or_disable_account (dialog, account, TRUE);
2107 display_import_dialog (EmpathyAccountsDialog *dialog)
2109 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2110 GtkWidget *import_dialog;
2112 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2114 gtk_widget_show (import_dialog);
2116 return import_dialog;
2120 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2121 EmpathyAccountsDialog *dialog)
2123 display_import_dialog (dialog);
2127 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2131 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2133 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2135 if (response_id == GTK_RESPONSE_YES)
2136 gtk_widget_destroy (account_dialog);
2140 accounts_dialog_delete_event_cb (GtkWidget *widget,
2142 EmpathyAccountsDialog *dialog)
2144 /* we maunally handle responses to delete events */
2149 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2154 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2155 select_and_scroll_to_iter (dialog, &iter);
2159 salut_valid_cb (GtkWidget *widget,
2163 gtk_widget_set_sensitive (button, valid);
2167 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2169 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2170 GtkWidget *dialog, *widget, *content, *button;
2173 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2174 priv->account_manager))
2177 widget = empathy_local_xmpp_assistant_widget_new ();
2178 gtk_widget_show (widget);
2180 dialog = gtk_dialog_new ();
2182 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2184 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2187 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2188 _("_Connect"), GTK_RESPONSE_YES);
2189 gtk_widget_set_sensitive (button, FALSE);
2191 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2194 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2195 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2197 response = gtk_dialog_run (GTK_DIALOG (dialog));
2199 if (response == GTK_RESPONSE_YES)
2201 empathy_local_xmpp_assistant_widget_create_account (
2202 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2205 gtk_widget_destroy (dialog);
2209 import_dialog_response_cb (GtkDialog *dialog,
2211 EmpathyAccountsDialog *self)
2213 maybe_show_salut_dialog (self);
2217 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2219 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2222 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2225 if (!empathy_import_accounts_to_import ())
2227 maybe_show_salut_dialog (self);
2231 dialog = display_import_dialog (self);
2233 tp_g_signal_connect_object (dialog, "response",
2234 G_CALLBACK (import_dialog_response_cb), self, 0);
2238 finished_loading (EmpathyAccountsDialog *self)
2240 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2241 GtkTreeSelection *selection;
2242 gboolean has_selected;
2244 priv->loading = FALSE;
2246 gtk_widget_set_sensitive (priv->button_add, TRUE);
2247 gtk_widget_set_sensitive (priv->button_import, TRUE);
2248 gtk_widget_set_sensitive (priv->treeview, TRUE);
2250 /* Sensitive the remove button if there is an account selected */
2251 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2252 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2253 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2255 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2256 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2257 NOTEBOOK_PAGE_ACCOUNT);
2259 maybe_show_import_dialog (self);
2263 accounts_dialog_cms_prepare_cb (GObject *source,
2264 GAsyncResult *result,
2267 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2268 EmpathyAccountsDialog *dialog = user_data;
2269 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2271 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2274 /* No need to update the settings if we are already preparing one */
2275 if (priv->settings_ready == NULL)
2276 accounts_dialog_update_settings (dialog, NULL);
2278 if (priv->initial_selection != NULL)
2280 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2281 g_object_unref (priv->initial_selection);
2282 priv->initial_selection = NULL;
2286 finished_loading (dialog);
2290 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2292 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2293 GList *accounts, *l;
2295 g_signal_connect (priv->account_manager, "account-validity-changed",
2296 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2298 g_signal_connect (priv->account_manager, "account-removed",
2299 G_CALLBACK (accounts_dialog_account_removed_cb),
2301 g_signal_connect (priv->account_manager, "account-enabled",
2302 G_CALLBACK (accounts_dialog_account_enabled_cb),
2304 g_signal_connect (priv->account_manager, "account-disabled",
2305 G_CALLBACK (accounts_dialog_account_disabled_cb),
2308 /* Add existing accounts */
2309 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2310 for (l = accounts; l; l = l->next)
2312 accounts_dialog_add_account (dialog, l->data);
2314 g_list_free (accounts);
2316 priv->cms = empathy_connection_managers_dup_singleton ();
2318 empathy_connection_managers_prepare_async (priv->cms,
2319 accounts_dialog_cms_prepare_cb, dialog);
2321 accounts_dialog_model_select_first (dialog);
2325 accounts_dialog_manager_ready_cb (GObject *source_object,
2326 GAsyncResult *result,
2329 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2330 GError *error = NULL;
2332 if (!tp_proxy_prepare_finish (manager, result, &error))
2334 DEBUG ("Failed to prepare account manager: %s", error->message);
2335 g_error_free (error);
2339 accounts_dialog_accounts_setup (user_data);
2343 dialog_response_cb (GtkWidget *widget,
2347 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2349 if (response_id == GTK_RESPONSE_HELP)
2351 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2353 else if (response_id == GTK_RESPONSE_CLOSE ||
2354 response_id == GTK_RESPONSE_DELETE_EVENT)
2356 TpAccount *account = NULL;
2358 if (accounts_dialog_has_pending_change (dialog, &account))
2360 gchar *question_dialog_primary_text = get_dialog_primary_text (
2363 accounts_dialog_show_question_dialog (dialog,
2364 question_dialog_primary_text,
2365 _("You are about to close the window, which will discard\n"
2366 "your changes. Are you sure you want to proceed?"),
2367 G_CALLBACK (accounts_dialog_close_response_cb),
2369 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2370 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2372 g_free (question_dialog_primary_text);
2376 gtk_widget_destroy (widget);
2379 if (account != NULL)
2380 g_object_unref (account);
2385 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2387 GtkWidget *top_hbox;
2390 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2391 GtkWidget *content_area, *action_area;
2392 GtkWidget *grid, *hbox;
2394 GtkWidget *sw, *toolbar;
2395 GtkStyleContext *context;
2397 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2399 gui = empathy_builder_get_file (filename,
2400 "accounts_dialog_hbox", &top_hbox,
2401 "vbox_details", &priv->vbox_details,
2402 "alignment_settings", &priv->alignment_settings,
2403 "alignment_infobar", &priv->alignment_infobar,
2404 "treeview", &priv->treeview,
2405 "button_add", &priv->button_add,
2406 "button_remove", &priv->button_remove,
2407 "button_import", &priv->button_import,
2408 "notebook_account", &priv->notebook_account,
2409 "alignment_loading", &alig,
2411 "add_remove_toolbar", &toolbar,
2415 empathy_builder_connect (gui, dialog,
2416 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2417 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2418 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2419 "treeview", "button-press-event",
2420 accounts_dialog_treeview_button_press_event_cb,
2423 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2425 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2427 g_object_unref (gui);
2429 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2432 gtk_widget_hide (action_area);
2433 gtk_widget_hide (priv->button_remove);
2434 #endif /* HAVE_MEEGO */
2436 /* Display loading page */
2437 priv->loading = TRUE;
2439 priv->spinner = gtk_spinner_new ();
2441 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2442 gtk_widget_show (priv->spinner);
2444 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2446 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2447 NOTEBOOK_PAGE_LOADING);
2449 /* Remove button is insensitive until we have a selected account */
2450 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2452 /* Add and Import buttons and treeview are insensitive while the dialog
2454 gtk_widget_set_sensitive (priv->button_add, FALSE);
2455 gtk_widget_set_sensitive (priv->button_import, FALSE);
2456 gtk_widget_set_sensitive (priv->treeview, FALSE);
2458 if (priv->parent_window)
2459 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2460 priv->parent_window);
2462 priv->infobar = gtk_info_bar_new ();
2463 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2465 gtk_widget_show (priv->infobar);
2467 grid = gtk_grid_new ();
2468 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2470 GTK_CONTAINER (gtk_info_bar_get_content_area (
2471 GTK_INFO_BAR (priv->infobar))),
2474 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2475 GTK_ICON_SIZE_DIALOG);
2476 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2477 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2480 priv->label_name = gtk_label_new (NULL);
2481 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2484 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2485 gtk_widget_set_hexpand (hbox, TRUE);
2486 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2487 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2489 /* set up spinner */
2490 priv->throbber = gtk_spinner_new ();
2492 priv->image_status = gtk_image_new_from_icon_name (
2493 empathy_icon_name_for_presence (
2494 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2496 priv->label_status = gtk_label_new (NULL);
2497 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2499 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2500 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2501 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2503 /* enabled switch */
2504 priv->enabled_switch = gtk_switch_new ();
2505 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2506 g_signal_connect (priv->enabled_switch, "notify::active",
2507 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2508 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2510 gtk_widget_show_all (grid);
2512 /* Tweak the dialog */
2513 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2514 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2516 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2518 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2520 /* join the add/remove toolbar to the treeview */
2521 context = gtk_widget_get_style_context (sw);
2522 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2524 context = gtk_widget_get_style_context (toolbar);
2525 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2527 /* add dialog buttons */
2528 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2530 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2531 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2532 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2535 g_signal_connect (dialog, "response",
2536 G_CALLBACK (dialog_response_cb), dialog);
2538 g_signal_connect (dialog, "delete-event",
2539 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2543 do_dispose (GObject *obj)
2545 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2546 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2548 if (priv->connecting_id != 0)
2550 g_source_remove (priv->connecting_id);
2551 priv->connecting_id = 0;
2554 if (priv->account_manager != NULL)
2556 g_object_unref (priv->account_manager);
2557 priv->account_manager = NULL;
2560 if (priv->cms != NULL)
2562 g_object_unref (priv->cms);
2566 if (priv->connectivity)
2568 g_object_unref (priv->connectivity);
2569 priv->connectivity = NULL;
2572 if (priv->initial_selection != NULL)
2574 g_object_unref (priv->initial_selection);
2575 priv->initial_selection = NULL;
2578 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2582 do_get_property (GObject *object,
2587 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2589 switch (property_id)
2592 g_value_set_object (value, priv->parent_window);
2595 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2600 do_set_property (GObject *object,
2602 const GValue *value,
2605 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2607 switch (property_id)
2610 priv->parent_window = g_value_get_object (value);
2613 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2618 do_constructed (GObject *object)
2620 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2621 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2622 GtkTreeModel *model;
2624 accounts_dialog_build_ui (dialog);
2625 accounts_dialog_model_setup (dialog);
2627 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2628 g_signal_connect (model, "row-inserted",
2629 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2630 g_signal_connect (model, "row-deleted",
2631 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2633 /* Set up signalling */
2634 priv->account_manager = tp_account_manager_dup ();
2636 tp_proxy_prepare_async (priv->account_manager, NULL,
2637 accounts_dialog_manager_ready_cb, dialog);
2639 priv->connectivity = empathy_connectivity_dup_singleton ();
2643 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2645 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2646 GParamSpec *param_spec;
2648 oclass->dispose = do_dispose;
2649 oclass->constructed = do_constructed;
2650 oclass->set_property = do_set_property;
2651 oclass->get_property = do_get_property;
2653 param_spec = g_param_spec_object ("parent",
2654 "parent", "The parent window",
2656 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2657 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2659 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2663 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2665 EmpathyAccountsDialogPriv *priv;
2667 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2668 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2669 EmpathyAccountsDialogPriv);
2670 dialog->priv = priv;
2673 /* public methods */
2676 empathy_accounts_dialog_show (GtkWindow *parent,
2677 TpAccount *selected_account)
2679 EmpathyAccountsDialog *dialog;
2680 EmpathyAccountsDialogPriv *priv;
2682 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2683 "parent", parent, NULL);
2685 priv = GET_PRIV (dialog);
2687 if (selected_account)
2689 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2690 accounts_dialog_set_selected_account (dialog, selected_account);
2692 /* save the selection to set it later when the cms
2695 priv->initial_selection = g_object_ref (selected_account);
2698 gtk_window_present (GTK_WINDOW (dialog));
2700 return GTK_WIDGET (dialog);
2704 empathy_accounts_dialog_show_application (GdkScreen *screen,
2705 TpAccount *selected_account,
2711 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2713 args = g_string_new (NULL);
2715 if (selected_account != NULL)
2716 g_string_append_printf (args, " --select-account=%s",
2717 tp_account_get_path_suffix (selected_account));
2720 g_string_append_printf (args, " --if-needed");
2723 g_string_append_printf (args, " --hidden");
2725 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2727 selected_account == NULL ? "<none selected>" :
2728 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2730 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2732 g_string_free (args, TRUE);
2736 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2738 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2739 gboolean result = FALSE;
2741 if (priv->setting_widget_object == NULL)
2744 g_object_get (priv->setting_widget_object,
2745 "creating-account", &result, NULL);