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-new-account-dialog.h>
56 #include "empathy-accounts-dialog.h"
57 #include "empathy-import-dialog.h"
58 #include "empathy-import-utils.h"
60 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
61 #include <libempathy/empathy-debug.h>
63 /* Flashing delay for icons (milliseconds). */
64 #define FLASH_TIMEOUT 500
66 /* The primary text of the dialog shown to the user when he is about to lose
68 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
69 _("There are unsaved modifications to your %s account.")
70 /* The primary text of the dialog shown to the user when he is about to lose
71 * an unsaved new account */
72 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
73 _("Your new account has not been saved yet.")
75 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
76 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
80 NOTEBOOK_PAGE_ACCOUNT = 0,
81 NOTEBOOK_PAGE_LOADING,
82 NOTEBOOK_PAGE_NO_PROTOCOL
86 GtkWidget *alignment_settings;
87 GtkWidget *alignment_infobar;
89 GtkWidget *vbox_details;
91 GtkWidget *label_status;
92 GtkWidget *image_status;
94 GtkWidget *enabled_switch;
98 GtkWidget *button_add;
99 GtkWidget *button_remove;
100 GtkWidget *button_import;
102 GtkWidget *image_type;
103 GtkWidget *label_name;
104 GtkWidget *label_type;
105 GtkWidget *dialog_content;
107 GtkWidget *notebook_account;
111 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
112 * just its GtkWidget. It is the only reliable source we can query to know if
113 * there are any unsaved changes to the currently selected account. We can't
114 * look at the account settings because it does not contain everything that
115 * can be changed using the EmpathyAccountWidget. For instance, it does not
116 * contain the state of the "Enabled" checkbox.
118 * Even if we create it ourself, we just get a weak ref and not a strong one
119 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
120 * That's kinda ugly; cf bgo #640417.
123 EmpathyAccountWidget *setting_widget_object;
125 gboolean connecting_show;
128 gulong settings_ready_id;
129 EmpathyAccountSettings *settings_ready;
131 TpAccountManager *account_manager;
132 EmpathyConnectionManagers *cms;
133 EmpathyConnectivity *connectivity;
135 GtkWindow *parent_window;
136 TpAccount *initial_selection;
138 /* Those are needed when changing the selected row. When a user selects
139 * another account and there are unsaved changes on the currently selected
140 * one, a confirmation message box is presented to him. Since his answer
141 * is retrieved asynchronously, we keep some information as member of the
142 * EmpathyAccountsDialog object. */
143 gboolean force_change_row;
144 GtkTreeRowReference *destination_row;
145 } EmpathyAccountsDialogPriv;
151 COL_ACCOUNT_SETTINGS,
159 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
160 EmpathyAccountsDialog *dialog);
162 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
164 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
165 EmpathyAccountSettings *settings);
167 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
170 static void accounts_dialog_connection_changed_cb (TpAccount *account,
174 gchar *dbus_error_name,
176 EmpathyAccountsDialog *dialog);
178 static void accounts_dialog_presence_changed_cb (TpAccount *account,
181 gchar *status_message,
182 EmpathyAccountsDialog *dialog);
184 static void accounts_dialog_model_selection_changed (
185 GtkTreeSelection *selection,
186 EmpathyAccountsDialog *dialog);
188 static gboolean accounts_dialog_has_pending_change (
189 EmpathyAccountsDialog *dialog, TpAccount **account);
192 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
193 const gchar *display_name)
196 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
198 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
199 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
205 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
206 const gchar *message)
208 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
209 gchar *message_markup;
211 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
212 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
214 gtk_widget_set_tooltip_text (priv->label_status, message);
216 g_free (message_markup);
220 accounts_dialog_enable_account_cb (GObject *account,
221 GAsyncResult *result,
224 GError *error = NULL;
226 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
230 DEBUG ("Could not enable the account: %s", error->message);
231 g_error_free (error);
235 TpAccountManager *am = tp_account_manager_dup ();
237 empathy_connect_new_account (TP_ACCOUNT (account), am);
243 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
245 EmpathyAccountsDialog *dialog)
247 EmpathyAccountSettings *settings;
250 settings = accounts_dialog_model_get_selected_settings (dialog);
251 if (settings == NULL)
254 account = empathy_account_settings_get_account (settings);
258 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
259 accounts_dialog_enable_account_cb, NULL);
263 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
266 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
267 gchar *status_message = NULL;
273 GtkTreeSelection *selection;
275 TpAccount *selected_account;
276 gboolean account_enabled;
277 gboolean creating_account;
278 TpStorageRestrictionFlags storage_restrictions = 0;
280 view = GTK_TREE_VIEW (priv->treeview);
281 selection = gtk_tree_view_get_selection (view);
283 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
286 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
287 if (selected_account != NULL)
288 g_object_unref (selected_account);
290 /* do not update the infobar when the account is not selected */
291 if (account != selected_account)
296 status = tp_account_get_connection_status (account, &reason);
297 presence = tp_account_get_current_presence (account, NULL, &status_message);
298 account_enabled = tp_account_is_enabled (account);
299 creating_account = FALSE;
301 if (status == TP_CONNECTION_STATUS_CONNECTED &&
302 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
303 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
304 /* If presence is Unset (CM doesn't implement SimplePresence) but we
305 * are connected, consider ourself as Available.
306 * We also check Offline because of this MC5 bug: fd.o #26060 */
307 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
309 /* set presence to offline if account is disabled
310 * (else no icon is shown in infobar)*/
311 if (!account_enabled)
312 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
314 storage_restrictions = tp_account_get_storage_restrictions (account);
318 status = TP_CONNECTION_STATUS_DISCONNECTED;
319 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
320 account_enabled = FALSE;
321 creating_account = TRUE;
324 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
325 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
327 /* update the enabled switch */
328 g_signal_handlers_block_by_func (priv->enabled_switch,
329 accounts_dialog_enable_switch_active_cb, dialog);
330 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
332 g_signal_handlers_unblock_by_func (priv->enabled_switch,
333 accounts_dialog_enable_switch_active_cb, dialog);
335 /* Display the Enable switch if account supports it */
336 gtk_widget_set_visible (priv->enabled_switch,
337 !(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED));
343 case TP_CONNECTION_STATUS_CONNECTING:
344 accounts_dialog_status_infobar_set_message (dialog,
346 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
349 gtk_spinner_start (GTK_SPINNER (priv->throbber));
350 gtk_widget_show (priv->throbber);
351 gtk_widget_hide (priv->image_status);
353 case TP_CONNECTION_STATUS_CONNECTED:
354 if (g_strcmp0 (status_message, "") == 0)
358 message = g_strdup_printf ("%s",
359 empathy_presence_get_default_message (presence));
361 accounts_dialog_status_infobar_set_message (dialog, message);
368 message = g_strdup_printf ("%s — %s",
369 empathy_presence_get_default_message (presence),
372 accounts_dialog_status_infobar_set_message (dialog, message);
375 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
378 gtk_widget_show (priv->image_status);
379 gtk_widget_hide (priv->throbber);
381 case TP_CONNECTION_STATUS_DISCONNECTED:
382 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
386 message = g_strdup_printf (_("Offline — %s"),
387 empathy_account_get_error_message (account, NULL));
388 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
389 GTK_MESSAGE_WARNING);
391 accounts_dialog_status_infobar_set_message (dialog, message);
398 message = g_strdup_printf (_("Disconnected — %s"),
399 empathy_account_get_error_message (account, NULL));
400 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
403 accounts_dialog_status_infobar_set_message (dialog, message);
407 if (!empathy_connectivity_is_online (priv->connectivity))
408 accounts_dialog_status_infobar_set_message (dialog,
409 _("Offline — No Network Connection"));
411 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
412 gtk_widget_show (priv->image_status);
413 gtk_widget_hide (priv->throbber);
416 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
417 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
418 GTK_MESSAGE_WARNING);
420 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
421 gtk_widget_hide (priv->image_status);
422 gtk_widget_hide (priv->throbber);
427 accounts_dialog_status_infobar_set_message (dialog,
428 _("Offline — Account Disabled"));
430 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
431 GTK_MESSAGE_WARNING);
432 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
433 gtk_widget_show (priv->image_status);
434 gtk_widget_hide (priv->throbber);
437 gtk_widget_show (priv->label_status);
439 if (!creating_account)
440 gtk_widget_show (priv->infobar);
442 gtk_widget_hide (priv->infobar);
444 g_free (status_message);
448 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
452 GtkTreeSelection *selection;
454 EmpathyAccountSettings *settings;
456 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
458 view = GTK_TREE_VIEW (priv->treeview);
459 selection = gtk_tree_view_get_selection (view);
461 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
464 gtk_tree_model_get (model, &iter,
465 COL_ACCOUNT_SETTINGS, &settings,
466 COL_ACCOUNT, &account, -1);
468 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
472 /* We were creating an account. We remove the selected row */
473 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
477 /* We were modifying an account. We discard the changes by reloading the
478 * settings and the UI. */
479 accounts_dialog_update_settings (dialog, settings);
480 g_object_unref (account);
483 gtk_widget_set_sensitive (priv->treeview, TRUE);
484 gtk_widget_set_sensitive (priv->button_add, TRUE);
485 gtk_widget_set_sensitive (priv->button_remove, TRUE);
486 gtk_widget_set_sensitive (priv->button_import, TRUE);
488 if (settings != NULL)
489 g_object_unref (settings);
493 empathy_account_dialog_widget_cancelled_cb (
494 EmpathyAccountWidget *widget_object,
495 EmpathyAccountsDialog *dialog)
497 empathy_account_dialog_cancel (dialog);
501 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
503 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
508 g_object_get (priv->setting_widget_object,
509 "creating-account", &creating, NULL);
514 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
516 if (gtk_tree_model_get_iter_first (model, &iter))
517 return gtk_tree_model_iter_next (model, &iter);
523 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
525 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
526 EmpathyAccountSettings *settings;
527 GtkWidget *subdialog, *content, *content_area, *align;
529 settings = accounts_dialog_model_get_selected_settings (dialog);
531 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
533 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
536 priv->setting_widget_object =
537 empathy_account_widget_new_for_protocol (settings, FALSE);
539 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
540 (gpointer *) &priv->setting_widget_object);
542 if (accounts_dialog_has_valid_accounts (dialog))
543 empathy_account_widget_set_other_accounts_exist (
544 priv->setting_widget_object, TRUE);
546 content = empathy_account_widget_get_widget (priv->setting_widget_object);
548 g_signal_connect (priv->setting_widget_object, "cancelled",
549 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
551 g_signal_connect_swapped (priv->setting_widget_object, "close",
552 G_CALLBACK (gtk_widget_destroy), subdialog);
554 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
556 align = gtk_alignment_new (0.5, 0.5, 1, 1);
557 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
559 gtk_container_add (GTK_CONTAINER (align), content);
560 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
562 gtk_widget_show (content);
563 gtk_widget_show (align);
564 gtk_widget_show (subdialog);
568 start_external_app (GAppInfo *app_info)
570 GError *error = NULL;
571 GdkAppLaunchContext *context = NULL;
574 display = gdk_display_get_default ();
575 context = gdk_display_get_app_launch_context (display);
577 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
580 g_critical ("Failed to bisho: %s", error->message);
581 g_clear_error (&error);
584 tp_clear_object (&context);
588 use_external_storage_provider (EmpathyAccountsDialog *self,
591 const gchar *provider;
593 provider = tp_account_get_storage_provider (account);
594 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
596 GDesktopAppInfo *desktop_info;
599 GError *error = NULL;
601 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
602 if (desktop_info == NULL)
604 g_critical ("Could not locate 'gnome-control-center.desktop'");
608 /* glib doesn't have API to start a desktop file with args... (#637875) */
609 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
610 (GAppInfo *) desktop_info));
612 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
614 if (app_info == NULL)
616 DEBUG ("Failed to create app info: %s", error->message);
617 g_error_free (error);
621 start_external_app (app_info);
622 g_object_unref (app_info);
625 g_object_unref (desktop_info);
629 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
631 GDesktopAppInfo *desktop_info;
633 desktop_info = g_desktop_app_info_new (
634 "gnome-online-accounts-panel.desktop");
635 if (desktop_info == NULL)
637 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
641 start_external_app (G_APP_INFO (desktop_info));
642 g_object_unref (desktop_info);
649 DEBUG ("Don't know how to handle %s", provider);
655 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
658 EmpathyAccountSettings *settings;
660 TpStorageRestrictionFlags storage_restrictions;
662 settings = accounts_dialog_model_get_selected_settings (dialog);
664 account = empathy_account_settings_get_account (settings);
665 g_return_if_fail (account != NULL);
667 storage_restrictions = tp_account_get_storage_restrictions (account);
669 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
670 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
672 DEBUG ("Account is provided by an external storage provider");
674 use_external_storage_provider (dialog, account);
678 account_dialog_create_edit_params_dialog (dialog);
683 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
686 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
687 GtkWidget *infobar, *label;
689 infobar = gtk_info_bar_new ();
693 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
694 label = gtk_label_new (_("Failed to retrieve your personal information "
695 "from the server."));
699 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
700 label = gtk_label_new (_("Go online to edit your personal information."));
704 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
706 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
707 gtk_widget_show_all (infobar);
711 account_dialog_got_self_contact (TpConnection *conn,
712 EmpathyContact *contact,
713 const GError *in_error,
717 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
718 GtkWidget *editor, *alig;
720 if (in_error != NULL)
722 DEBUG ("Failed to get self-contact: %s", in_error->message);
723 account_dialog_show_contact_details_failed (
724 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
728 alig = gtk_alignment_new (0.5, 0, 1, 1);
730 /* create the contact info editor for this account */
731 editor = empathy_contact_widget_new (contact,
732 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
733 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
734 EMPATHY_CONTACT_WIDGET_NO_STATUS |
735 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS);
737 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
738 gtk_container_add (GTK_CONTAINER (alig), editor);
739 gtk_widget_show (alig);
740 gtk_widget_show (editor);
744 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
745 EmpathyAccountSettings *settings)
747 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
748 const gchar *icon_name;
750 TpConnection *conn = NULL;
751 GtkWidget *bbox, *button;
753 account = empathy_account_settings_get_account (settings);
755 // if (priv->setting_widget_object != NULL)
756 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
757 // (gpointer *) &priv->setting_widget_object);
759 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
760 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
761 priv->dialog_content);
762 gtk_widget_show (priv->dialog_content);
764 /* request the self contact */
766 conn = tp_account_get_connection (account);
770 empathy_tp_contact_factory_get_from_handle (conn,
771 tp_connection_get_self_handle (conn),
772 account_dialog_got_self_contact,
773 NULL, NULL, G_OBJECT (dialog));
777 account_dialog_show_contact_details_failed (dialog, FALSE);
780 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
781 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
782 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
783 gtk_widget_show (bbox);
785 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
786 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
787 gtk_widget_show (button);
788 g_signal_connect_swapped (button, "clicked",
789 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
791 icon_name = empathy_account_settings_get_icon_name (settings);
793 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
795 /* show the default icon; keep this in sync with the default
796 * one in empathy-accounts-dialog.ui.
798 icon_name = GTK_STOCK_CUT;
800 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
801 icon_name, GTK_ICON_SIZE_DIALOG);
802 gtk_widget_set_tooltip_text (priv->image_type,
803 empathy_protocol_name_to_display_name
804 (empathy_account_settings_get_protocol (settings)));
805 gtk_widget_show (priv->image_type);
807 accounts_dialog_update_name_label (dialog,
808 empathy_account_settings_get_display_name (settings));
810 accounts_dialog_update_status_infobar (dialog, account);
814 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
816 EmpathyAccountsDialog *dialog)
818 if (empathy_account_settings_is_ready (settings))
819 account_dialog_create_dialog_content (dialog, settings);
823 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
827 GtkTreeSelection *selection;
829 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
832 view = GTK_TREE_VIEW (priv->treeview);
833 model = gtk_tree_view_get_model (view);
835 if (gtk_tree_model_get_iter_first (model, &iter))
837 selection = gtk_tree_view_get_selection (view);
838 gtk_tree_selection_select_iter (selection, &iter);
842 accounts_dialog_update_settings (dialog, NULL);
847 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
852 GtkTreeSelection *selection;
853 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
855 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
857 if (gtk_tree_selection_get_selected (selection, &model, &iter))
858 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
860 return priv->setting_widget_object != NULL
861 && empathy_account_widget_contains_pending_changes (
862 priv->setting_widget_object);
866 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
867 const gchar *primary_text,
868 const gchar *secondary_text,
869 GCallback response_callback,
871 const gchar *first_button_text,
875 GtkWidget *message_dialog;
876 const gchar *button_text;
878 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
879 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
880 GTK_MESSAGE_QUESTION,
884 gtk_message_dialog_format_secondary_text (
885 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
887 va_start (button_args, first_button_text);
888 for (button_text = first_button_text;
890 button_text = va_arg (button_args, const gchar *))
893 response_id = va_arg (button_args, gint);
895 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
898 va_end (button_args);
900 g_signal_connect (message_dialog, "response", response_callback, user_data);
902 gtk_widget_show (message_dialog);
906 get_dialog_primary_text (TpAccount *account)
910 /* Existing account */
911 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
912 tp_account_get_display_name (account));
916 /* Newly created account */
917 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
922 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
923 EmpathyAccountsDialog *self)
928 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
929 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
931 response = gtk_dialog_run (GTK_DIALOG (dialog));
933 if (response == GTK_RESPONSE_OK)
935 EmpathyAccountSettings *settings;
938 settings = empathy_new_account_dialog_get_settings (
939 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
941 /* The newly created account has already been added by
942 * accounts_dialog_account_validity_changed_cb so we just
943 * have to select it. */
944 account = empathy_account_settings_get_account (settings);
945 accounts_dialog_model_set_selected (self, account);
948 gtk_widget_destroy (dialog);
952 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
953 EmpathyAccountSettings *settings)
955 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
957 if (priv->settings_ready != NULL)
959 g_signal_handler_disconnect (priv->settings_ready,
960 priv->settings_ready_id);
961 priv->settings_ready = NULL;
962 priv->settings_ready_id = 0;
969 GtkTreeSelection *selection;
971 view = GTK_TREE_VIEW (priv->treeview);
972 model = gtk_tree_view_get_model (view);
973 selection = gtk_tree_view_get_selection (view);
975 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
977 /* We have configured accounts, select the first one if there
978 * is no other account selected already. */
979 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
980 accounts_dialog_model_select_first (dialog);
985 /* No account and no profile, warn the user */
986 gtk_widget_hide (priv->vbox_details);
987 gtk_widget_set_sensitive (priv->button_add, FALSE);
989 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
990 NOTEBOOK_PAGE_NO_PROTOCOL);
994 /* We have an account selected, destroy old settings and create a new
995 * one for the account selected */
996 gtk_widget_show (priv->vbox_details);
998 if (priv->dialog_content)
1000 gtk_widget_destroy (priv->dialog_content);
1001 priv->dialog_content = NULL;
1004 if (empathy_account_settings_is_ready (settings))
1006 account_dialog_create_dialog_content (dialog, settings);
1010 priv->settings_ready = settings;
1011 priv->settings_ready_id =
1012 g_signal_connect (settings, "notify::ready",
1013 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1019 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1020 GtkCellEditable *editable,
1022 EmpathyAccountsDialog *dialog)
1024 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1026 if (priv->connecting_id)
1027 g_source_remove (priv->connecting_id);
1029 DEBUG ("Editing account name started; stopping flashing");
1032 static const gchar *
1033 get_status_icon_for_account (EmpathyAccountsDialog *self,
1036 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1037 TpConnectionStatus status;
1038 TpConnectionStatusReason reason;
1039 TpConnectionPresenceType presence;
1041 if (account == NULL)
1042 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1044 if (!tp_account_is_enabled (account))
1045 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1047 status = tp_account_get_connection_status (account, &reason);
1049 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1051 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1052 /* An error occured */
1053 return GTK_STOCK_DIALOG_ERROR;
1055 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1057 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1059 /* Account is connecting. Display a blinking account alternating between
1060 * the offline icon and the requested presence. */
1061 if (priv->connecting_show)
1062 presence = tp_account_get_requested_presence (account, NULL, NULL);
1064 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1068 /* status == TP_CONNECTION_STATUS_CONNECTED */
1069 presence = tp_account_get_current_presence (account, NULL, NULL);
1071 /* If presence is Unset (CM doesn't implement SimplePresence),
1072 * display the 'available' icon.
1073 * We also check Offline because of this MC5 bug: fd.o #26060 */
1074 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1075 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1076 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1079 return empathy_icon_name_for_presence (presence);
1083 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1084 GtkCellRenderer *cell,
1085 GtkTreeModel *model,
1087 EmpathyAccountsDialog *dialog)
1091 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1094 "icon-name", get_status_icon_for_account (dialog, account),
1097 if (account != NULL)
1098 g_object_unref (account);
1102 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1103 GtkCellRenderer *cell,
1104 GtkTreeModel *model,
1106 EmpathyAccountsDialog *dialog)
1108 EmpathyAccountSettings *settings;
1111 TpConnectionStatus status;
1113 gtk_tree_model_get (model, iter,
1114 COL_STATUS, &status,
1115 COL_ACCOUNT_SETTINGS, &settings,
1118 icon_name = empathy_account_settings_get_icon_name (settings);
1119 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1126 g_object_unref (settings);
1129 g_object_unref (pixbuf);
1133 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1140 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1142 if (account == NULL)
1145 if (tp_account_get_connection_status (account, NULL) ==
1146 TP_CONNECTION_STATUS_CONNECTING)
1148 /* Only update the row where we have a connecting account as that's the
1149 * ones having a blinking icon. */
1150 gtk_tree_model_row_changed (model, path, iter);
1153 g_object_unref (account);
1158 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1161 GtkTreeModel *model;
1162 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1164 priv->connecting_show = !priv->connecting_show;
1166 view = GTK_TREE_VIEW (priv->treeview);
1167 model = gtk_tree_view_get_model (view);
1169 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1175 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1178 EmpathyAccountsDialog *dialog)
1180 EmpathyAccountSettings *settings;
1181 GtkTreeModel *model;
1182 GtkTreePath *treepath;
1184 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1185 gboolean connecting;
1187 empathy_account_manager_get_accounts_connected (&connecting);
1191 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1192 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1196 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1197 treepath = gtk_tree_path_new_from_string (path);
1198 gtk_tree_model_get_iter (model, &iter, treepath);
1199 gtk_tree_model_get (model, &iter,
1200 COL_ACCOUNT_SETTINGS, &settings,
1202 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1205 gtk_tree_path_free (treepath);
1207 empathy_account_settings_set_display_name_async (settings, new_text,
1209 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1210 g_object_unref (settings);
1214 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1219 GtkTreeModel *model;
1221 GtkTreeSelection *selection;
1222 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1223 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1225 if (response_id == GTK_RESPONSE_YES)
1227 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1229 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1232 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1234 if (account != NULL)
1236 tp_account_remove_async (account, NULL, NULL);
1237 g_object_unref (account);
1241 /* No need to call accounts_dialog_model_selection_changed while
1242 * removing as we are going to call accounts_dialog_model_select_first
1243 * right after which will update the selection. */
1244 g_signal_handlers_block_by_func (selection,
1245 accounts_dialog_model_selection_changed, account_dialog);
1247 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1249 g_signal_handlers_unblock_by_func (selection,
1250 accounts_dialog_model_selection_changed, account_dialog);
1252 accounts_dialog_model_select_first (account_dialog);
1255 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1259 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1262 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1264 GtkTreeModel *model;
1265 gchar *question_dialog_primary_text;
1267 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1269 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1271 if (account == NULL || !tp_account_is_valid (account))
1273 if (account != NULL)
1274 g_object_unref (account);
1275 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1276 accounts_dialog_model_select_first (dialog);
1280 question_dialog_primary_text = g_strdup_printf (
1281 _("Do you want to remove %s from your computer?"),
1282 tp_account_get_display_name (account));
1284 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1285 _("This will not remove your account on the server."),
1286 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1288 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1289 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1291 g_free (question_dialog_primary_text);
1292 g_object_unref (account);
1296 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1297 EmpathyAccountsDialog *dialog)
1299 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1301 GtkTreeSelection *selection;
1304 view = GTK_TREE_VIEW (priv->treeview);
1305 selection = gtk_tree_view_get_selection (view);
1306 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1309 accounts_dialog_remove_account_iter (dialog, &iter);
1314 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1315 const gchar *path_string,
1316 EmpathyAccountsDialog *dialog)
1318 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1319 GtkTreeModel *model;
1322 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1323 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1326 accounts_dialog_remove_account_iter (dialog, &iter);
1328 #endif /* HAVE_MEEGO */
1331 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1334 GtkTreeViewColumn *column;
1335 GtkCellRenderer *cell;
1336 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1338 view = GTK_TREE_VIEW (priv->treeview);
1339 gtk_tree_view_set_headers_visible (view, FALSE);
1341 /* Account column */
1342 column = gtk_tree_view_column_new ();
1343 gtk_tree_view_column_set_expand (column, TRUE);
1344 gtk_tree_view_append_column (view, column);
1346 /* Status icon renderer */
1347 cell = gtk_cell_renderer_pixbuf_new ();
1348 gtk_tree_view_column_pack_start (column, cell, FALSE);
1349 gtk_tree_view_column_set_cell_data_func (column, cell,
1350 (GtkTreeCellDataFunc)
1351 accounts_dialog_model_status_pixbuf_data_func,
1355 /* Protocol icon renderer */
1356 cell = gtk_cell_renderer_pixbuf_new ();
1357 gtk_tree_view_column_pack_start (column, cell, FALSE);
1358 gtk_tree_view_column_set_cell_data_func (column, cell,
1359 (GtkTreeCellDataFunc)
1360 accounts_dialog_model_protocol_pixbuf_data_func,
1365 cell = gtk_cell_renderer_text_new ();
1367 "ellipsize", PANGO_ELLIPSIZE_END,
1371 gtk_tree_view_column_pack_start (column, cell, TRUE);
1372 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1373 g_signal_connect (cell, "edited",
1374 G_CALLBACK (accounts_dialog_name_edited_cb),
1376 g_signal_connect (cell, "editing-started",
1377 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1379 g_object_set (cell, "ypad", 4, NULL);
1383 cell = empathy_cell_renderer_activatable_new ();
1384 gtk_tree_view_column_pack_start (column, cell, FALSE);
1386 "icon-name", GTK_STOCK_DELETE,
1387 "show-on-select", TRUE,
1390 g_signal_connect (cell, "path-activated",
1391 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1393 #endif /* HAVE_MEEGO */
1396 static EmpathyAccountSettings *
1397 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1400 GtkTreeModel *model;
1401 GtkTreeSelection *selection;
1403 EmpathyAccountSettings *settings;
1404 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1406 view = GTK_TREE_VIEW (priv->treeview);
1407 selection = gtk_tree_view_get_selection (view);
1409 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1412 gtk_tree_model_get (model, &iter,
1413 COL_ACCOUNT_SETTINGS, &settings, -1);
1419 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1420 EmpathyAccountsDialog *dialog)
1422 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1423 EmpathyAccountSettings *settings;
1424 GtkTreeModel *model;
1426 gboolean is_selection;
1427 gboolean creating = FALSE;
1429 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1431 settings = accounts_dialog_model_get_selected_settings (dialog);
1432 accounts_dialog_update_settings (dialog, settings);
1434 if (settings != NULL)
1435 g_object_unref (settings);
1437 if (priv->setting_widget_object != NULL)
1439 g_object_get (priv->setting_widget_object,
1440 "creating-account", &creating, NULL);
1443 /* Update remove button sensitivity */
1444 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1449 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1451 gpointer *user_data)
1453 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1454 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1456 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1458 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1460 /* The user wants to lose unsaved changes to the currently selected
1461 * account and select another account. We discard the changes and
1462 * select the other account. */
1464 GtkTreeSelection *selection;
1466 priv->force_change_row = TRUE;
1467 empathy_account_widget_discard_pending_changes (
1468 priv->setting_widget_object);
1470 path = gtk_tree_row_reference_get_path (priv->destination_row);
1471 selection = gtk_tree_view_get_selection (
1472 GTK_TREE_VIEW (priv->treeview));
1476 /* This will trigger a call to
1477 * accounts_dialog_account_selection_change() */
1478 gtk_tree_selection_select_path (selection, path);
1479 gtk_tree_path_free (path);
1482 gtk_tree_row_reference_free (priv->destination_row);
1486 priv->force_change_row = FALSE;
1491 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1492 GtkTreeModel *model,
1494 gboolean path_currently_selected,
1497 TpAccount *account = NULL;
1498 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1499 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1502 if (priv->force_change_row)
1504 /* We came back here because the user wants to discard changes to his
1505 * modified account. The changes have already been discarded so we
1506 * just change the selected row. */
1507 priv->force_change_row = FALSE;
1511 if (accounts_dialog_has_pending_change (dialog, &account))
1513 /* The currently selected account has some unsaved changes. We ask
1514 * the user if he really wants to lose his changes and select another
1516 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1517 priv->destination_row = gtk_tree_row_reference_new (model, path);
1519 accounts_dialog_show_question_dialog (dialog,
1520 question_dialog_primary_text,
1521 _("You are about to select another account, which will discard\n"
1522 "your changes. Are you sure you want to proceed?"),
1523 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1525 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1526 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1528 g_free (question_dialog_primary_text);
1536 if (account != NULL)
1537 g_object_unref (account);
1543 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1545 GtkListStore *store;
1546 GtkTreeSelection *selection;
1547 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1549 store = gtk_list_store_new (COL_COUNT,
1550 G_TYPE_STRING, /* name */
1551 G_TYPE_UINT, /* status */
1552 TP_TYPE_ACCOUNT, /* account */
1553 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1555 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1556 GTK_TREE_MODEL (store));
1558 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1559 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1560 gtk_tree_selection_set_select_function (selection,
1561 accounts_dialog_account_selection_change, dialog, NULL);
1563 g_signal_connect (selection, "changed",
1564 G_CALLBACK (accounts_dialog_model_selection_changed),
1567 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1568 COL_NAME, GTK_SORT_ASCENDING);
1570 accounts_dialog_model_add_columns (dialog);
1572 g_object_unref (store);
1576 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1581 GtkTreeModel *model;
1583 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1585 /* Update the status in the model */
1586 view = GTK_TREE_VIEW (priv->treeview);
1587 model = gtk_tree_view_get_model (view);
1589 for (ok = gtk_tree_model_get_iter_first (model, iter);
1591 ok = gtk_tree_model_iter_next (model, iter))
1593 TpAccount *this_account;
1596 gtk_tree_model_get (model, iter,
1597 COL_ACCOUNT, &this_account,
1600 equal = (this_account == account);
1601 g_object_unref (this_account);
1611 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1614 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1615 GtkTreeSelection *selection;
1617 GtkTreeModel *model;
1619 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1621 gtk_tree_selection_select_iter (selection, iter);
1623 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1624 path = gtk_tree_model_get_path (model, iter);
1626 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1629 gtk_tree_path_free (path);
1633 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1638 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1639 select_and_scroll_to_iter (dialog, &iter);
1643 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1648 enabled = tp_account_is_enabled (account);
1649 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1653 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1654 GdkEventButton *event,
1655 EmpathyAccountsDialog *dialog)
1657 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1658 TpAccount *account = NULL;
1659 GtkTreeModel *model = NULL;
1660 GtkTreePath *path = NULL;
1663 GtkWidget *item_enable, *item_disable;
1664 GtkWidget *image_enable, *image_disable;
1666 /* ignore multiple clicks */
1667 if (event->type != GDK_BUTTON_PRESS)
1670 if (event->button != 3)
1673 /* Selection is not yet set, so we have to get account from event position */
1674 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1675 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1676 event->x, event->y, &path, NULL, NULL, NULL))
1679 if (!gtk_tree_model_get_iter (model, &iter, path))
1682 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1684 /* Create the menu */
1685 menu = empathy_context_menu_new (GTK_WIDGET (view));
1687 /* Get images for menu items */
1688 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1689 tp_account_manager_get_most_available_presence (
1690 priv->account_manager, NULL, NULL)),
1691 GTK_ICON_SIZE_MENU);
1692 image_disable = gtk_image_new_from_icon_name (
1693 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1694 GTK_ICON_SIZE_MENU);
1696 /* Menu items: to enabled/disable the account */
1697 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1698 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1699 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1701 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1704 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1705 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1707 if (tp_account_is_enabled (account))
1709 tp_g_signal_connect_object (item_disable, "activate",
1710 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1711 gtk_widget_set_sensitive (item_enable, FALSE);
1715 tp_g_signal_connect_object (item_enable, "activate",
1716 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1717 gtk_widget_set_sensitive (item_disable, FALSE);
1720 gtk_widget_show (item_enable);
1721 gtk_widget_show (item_disable);
1723 /* FIXME: Add here presence items, to be able to set per-account presence */
1726 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1727 event->button, event->time);
1730 tp_clear_object (&account);
1731 gtk_tree_path_free (path);
1737 accounts_dialog_connection_changed_cb (TpAccount *account,
1741 gchar *dbus_error_name,
1742 GHashTable *details,
1743 EmpathyAccountsDialog *dialog)
1745 GtkTreeModel *model;
1748 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1750 /* Update the status-infobar in the details view */
1751 accounts_dialog_update_status_infobar (dialog, account);
1753 /* Update the status in the model */
1754 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1756 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1760 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1761 COL_STATUS, current,
1764 path = gtk_tree_model_get_path (model, &iter);
1765 gtk_tree_model_row_changed (model, path, &iter);
1766 gtk_tree_path_free (path);
1769 empathy_account_manager_get_accounts_connected (&found);
1771 if (!found && priv->connecting_id)
1773 g_source_remove (priv->connecting_id);
1774 priv->connecting_id = 0;
1777 if (found && !priv->connecting_id)
1778 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1779 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1784 update_account_in_treeview (EmpathyAccountsDialog *self,
1787 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1789 GtkTreeModel *model;
1791 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1792 if (accounts_dialog_get_account_iter (self, account, &iter))
1796 path = gtk_tree_model_get_path (model, &iter);
1797 gtk_tree_model_row_changed (model, path, &iter);
1798 gtk_tree_path_free (path);
1803 accounts_dialog_presence_changed_cb (TpAccount *account,
1806 gchar *status_message,
1807 EmpathyAccountsDialog *dialog)
1809 /* Update the status-infobar in the details view */
1810 accounts_dialog_update_status_infobar (dialog, account);
1812 update_account_in_treeview (dialog, account);
1816 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1820 const gchar *display_name;
1822 GtkTreeModel *model;
1823 EmpathyAccountSettings *settings;
1824 TpAccount *selected_account;
1825 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1826 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1828 display_name = tp_account_get_display_name (account);
1829 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1830 settings = accounts_dialog_model_get_selected_settings (dialog);
1831 if (settings == NULL)
1834 selected_account = empathy_account_settings_get_account (settings);
1836 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1838 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1839 COL_NAME, display_name,
1843 if (selected_account == account)
1844 accounts_dialog_update_name_label (dialog, display_name);
1846 g_object_unref (settings);
1850 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1853 EmpathyAccountSettings *settings;
1854 GtkTreeModel *model;
1856 TpConnectionStatus status;
1858 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1859 gboolean selected = FALSE;
1860 GtkTreeSelection *selection;
1862 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1863 status = tp_account_get_connection_status (account, NULL);
1864 name = tp_account_get_display_name (account);
1866 settings = empathy_account_settings_new_for_account (account);
1868 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1870 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1872 /* Select the account if it's the first added */
1873 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1876 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1880 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1883 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1886 COL_ACCOUNT, account,
1887 COL_ACCOUNT_SETTINGS, settings,
1892 /* We just modified the selected account. Its display name may have been
1893 * changed and so it's place in the treeview. Scroll to it so it stays
1895 select_and_scroll_to_iter (dialog, &iter);
1898 accounts_dialog_connection_changed_cb (account,
1901 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1906 tp_g_signal_connect_object (account, "notify::display-name",
1907 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1910 tp_g_signal_connect_object (account, "status-changed",
1911 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1912 tp_g_signal_connect_object (account, "presence-changed",
1913 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1915 g_object_unref (settings);
1919 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1922 EmpathyAccountsDialog *dialog)
1924 accounts_dialog_add_account (dialog, account);
1928 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1931 EmpathyAccountsDialog *dialog)
1933 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1935 if (priv->setting_widget_object != NULL &&
1936 accounts_dialog_has_valid_accounts (dialog))
1938 empathy_account_widget_set_other_accounts_exist (
1939 priv->setting_widget_object, TRUE);
1944 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1946 EmpathyAccountsDialog *dialog)
1948 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1950 if (priv->setting_widget_object != NULL &&
1951 !accounts_dialog_has_valid_accounts (dialog))
1953 empathy_account_widget_set_other_accounts_exist (
1954 priv->setting_widget_object, FALSE);
1959 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1961 EmpathyAccountsDialog *dialog)
1964 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1966 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1968 gtk_list_store_remove (GTK_LIST_STORE (
1969 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1974 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1978 /* Update the status-infobar in the details view */
1979 accounts_dialog_update_status_infobar (dialog, account);
1981 DEBUG ("Account %s is now %s",
1982 tp_account_get_display_name (account),
1983 enabled ? "enabled" : "disabled");
1987 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1989 EmpathyAccountsDialog *dialog)
1991 enable_or_disable_account (dialog, account, FALSE);
1992 update_account_in_treeview (dialog, account);
1996 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1998 EmpathyAccountsDialog *dialog)
2000 enable_or_disable_account (dialog, account, TRUE);
2004 display_import_dialog (EmpathyAccountsDialog *dialog)
2006 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2007 GtkWidget *import_dialog;
2009 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2011 gtk_widget_show (import_dialog);
2013 return import_dialog;
2017 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2018 EmpathyAccountsDialog *dialog)
2020 display_import_dialog (dialog);
2024 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2028 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2030 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2032 if (response_id == GTK_RESPONSE_YES)
2033 gtk_widget_destroy (account_dialog);
2037 accounts_dialog_delete_event_cb (GtkWidget *widget,
2039 EmpathyAccountsDialog *dialog)
2041 /* we maunally handle responses to delete events */
2046 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2051 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2052 select_and_scroll_to_iter (dialog, &iter);
2056 finished_loading (EmpathyAccountsDialog *self)
2058 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2059 GtkTreeSelection *selection;
2060 gboolean has_selected;
2062 priv->loading = FALSE;
2064 gtk_widget_set_sensitive (priv->button_add, TRUE);
2065 gtk_widget_set_sensitive (priv->button_import, TRUE);
2066 gtk_widget_set_sensitive (priv->treeview, TRUE);
2068 /* Sensitive the remove button if there is an account selected */
2069 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2070 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2071 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2073 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2074 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2075 NOTEBOOK_PAGE_ACCOUNT);
2079 accounts_dialog_cms_prepare_cb (GObject *source,
2080 GAsyncResult *result,
2083 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2084 EmpathyAccountsDialog *dialog = user_data;
2085 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2087 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2090 /* No need to update the settings if we are already preparing one */
2091 if (priv->settings_ready == NULL)
2092 accounts_dialog_update_settings (dialog, NULL);
2094 if (priv->initial_selection != NULL)
2096 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2097 g_object_unref (priv->initial_selection);
2098 priv->initial_selection = NULL;
2102 finished_loading (dialog);
2106 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2108 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2109 GList *accounts, *l;
2111 g_signal_connect (priv->account_manager, "account-validity-changed",
2112 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2114 g_signal_connect (priv->account_manager, "account-removed",
2115 G_CALLBACK (accounts_dialog_account_removed_cb),
2117 g_signal_connect (priv->account_manager, "account-enabled",
2118 G_CALLBACK (accounts_dialog_account_enabled_cb),
2120 g_signal_connect (priv->account_manager, "account-disabled",
2121 G_CALLBACK (accounts_dialog_account_disabled_cb),
2124 /* Add existing accounts */
2125 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2126 for (l = accounts; l; l = l->next)
2128 accounts_dialog_add_account (dialog, l->data);
2130 g_list_free (accounts);
2132 priv->cms = empathy_connection_managers_dup_singleton ();
2134 empathy_connection_managers_prepare_async (priv->cms,
2135 accounts_dialog_cms_prepare_cb, dialog);
2137 accounts_dialog_model_select_first (dialog);
2141 accounts_dialog_manager_ready_cb (GObject *source_object,
2142 GAsyncResult *result,
2145 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2146 GError *error = NULL;
2148 if (!tp_proxy_prepare_finish (manager, result, &error))
2150 DEBUG ("Failed to prepare account manager: %s", error->message);
2151 g_error_free (error);
2155 accounts_dialog_accounts_setup (user_data);
2159 dialog_response_cb (GtkWidget *widget,
2163 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2165 if (response_id == GTK_RESPONSE_HELP)
2167 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2169 else if (response_id == GTK_RESPONSE_CLOSE ||
2170 response_id == GTK_RESPONSE_DELETE_EVENT)
2172 TpAccount *account = NULL;
2174 if (accounts_dialog_has_pending_change (dialog, &account))
2176 gchar *question_dialog_primary_text = get_dialog_primary_text (
2179 accounts_dialog_show_question_dialog (dialog,
2180 question_dialog_primary_text,
2181 _("You are about to close the window, which will discard\n"
2182 "your changes. Are you sure you want to proceed?"),
2183 G_CALLBACK (accounts_dialog_close_response_cb),
2185 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2186 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2188 g_free (question_dialog_primary_text);
2192 gtk_widget_destroy (widget);
2195 if (account != NULL)
2196 g_object_unref (account);
2201 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2203 GtkWidget *top_hbox;
2206 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2207 GtkWidget *content_area, *action_area;
2208 GtkWidget *grid, *hbox;
2210 GtkWidget *sw, *toolbar;
2211 GtkStyleContext *context;
2213 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2215 gui = empathy_builder_get_file (filename,
2216 "accounts_dialog_hbox", &top_hbox,
2217 "vbox_details", &priv->vbox_details,
2218 "alignment_settings", &priv->alignment_settings,
2219 "alignment_infobar", &priv->alignment_infobar,
2220 "treeview", &priv->treeview,
2221 "button_add", &priv->button_add,
2222 "button_remove", &priv->button_remove,
2223 "button_import", &priv->button_import,
2224 "notebook_account", &priv->notebook_account,
2225 "alignment_loading", &alig,
2227 "add_remove_toolbar", &toolbar,
2231 empathy_builder_connect (gui, dialog,
2232 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2233 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2234 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2235 "treeview", "button-press-event",
2236 accounts_dialog_treeview_button_press_event_cb,
2239 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2241 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2243 g_object_unref (gui);
2245 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2248 gtk_widget_hide (action_area);
2249 gtk_widget_hide (priv->button_remove);
2250 #endif /* HAVE_MEEGO */
2252 /* Display loading page */
2253 priv->loading = TRUE;
2255 priv->spinner = gtk_spinner_new ();
2257 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2258 gtk_widget_show (priv->spinner);
2260 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2262 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2263 NOTEBOOK_PAGE_LOADING);
2265 /* Remove button is insensitive until we have a selected account */
2266 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2268 /* Add and Import buttons and treeview are insensitive while the dialog
2270 gtk_widget_set_sensitive (priv->button_add, FALSE);
2271 gtk_widget_set_sensitive (priv->button_import, FALSE);
2272 gtk_widget_set_sensitive (priv->treeview, FALSE);
2274 if (priv->parent_window)
2275 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2276 priv->parent_window);
2278 priv->infobar = gtk_info_bar_new ();
2279 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2281 gtk_widget_show (priv->infobar);
2283 grid = gtk_grid_new ();
2285 GTK_CONTAINER (gtk_info_bar_get_content_area (
2286 GTK_INFO_BAR (priv->infobar))),
2289 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2290 GTK_ICON_SIZE_DIALOG);
2291 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2292 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2295 priv->label_name = gtk_label_new (NULL);
2296 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2299 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2300 gtk_widget_set_hexpand (hbox, TRUE);
2301 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2302 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2304 /* set up spinner */
2305 priv->throbber = gtk_spinner_new ();
2307 priv->image_status = gtk_image_new_from_icon_name (
2308 empathy_icon_name_for_presence (
2309 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2311 priv->label_status = gtk_label_new (NULL);
2312 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2314 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2315 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2316 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2318 /* enabled switch */
2319 priv->enabled_switch = gtk_switch_new ();
2320 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2321 g_signal_connect (priv->enabled_switch, "notify::active",
2322 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2323 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2325 gtk_widget_show_all (grid);
2327 /* Tweak the dialog */
2328 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2329 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2331 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2333 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2335 /* join the add/remove toolbar to the treeview */
2336 context = gtk_widget_get_style_context (sw);
2337 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2339 context = gtk_widget_get_style_context (toolbar);
2340 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2342 /* add dialog buttons */
2343 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2345 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2346 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2347 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2350 g_signal_connect (dialog, "response",
2351 G_CALLBACK (dialog_response_cb), dialog);
2353 g_signal_connect (dialog, "delete-event",
2354 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2358 do_dispose (GObject *obj)
2360 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2361 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2363 if (priv->connecting_id != 0)
2365 g_source_remove (priv->connecting_id);
2366 priv->connecting_id = 0;
2369 if (priv->account_manager != NULL)
2371 g_object_unref (priv->account_manager);
2372 priv->account_manager = NULL;
2375 if (priv->cms != NULL)
2377 g_object_unref (priv->cms);
2381 if (priv->connectivity)
2383 g_object_unref (priv->connectivity);
2384 priv->connectivity = NULL;
2387 if (priv->initial_selection != NULL)
2389 g_object_unref (priv->initial_selection);
2390 priv->initial_selection = NULL;
2393 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2397 do_get_property (GObject *object,
2402 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2404 switch (property_id)
2407 g_value_set_object (value, priv->parent_window);
2410 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2415 do_set_property (GObject *object,
2417 const GValue *value,
2420 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2422 switch (property_id)
2425 priv->parent_window = g_value_get_object (value);
2428 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2433 do_constructed (GObject *object)
2435 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2436 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2437 GtkTreeModel *model;
2439 accounts_dialog_build_ui (dialog);
2440 accounts_dialog_model_setup (dialog);
2442 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2443 g_signal_connect (model, "row-inserted",
2444 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2445 g_signal_connect (model, "row-deleted",
2446 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2448 /* Set up signalling */
2449 priv->account_manager = tp_account_manager_dup ();
2451 tp_proxy_prepare_async (priv->account_manager, NULL,
2452 accounts_dialog_manager_ready_cb, dialog);
2454 priv->connectivity = empathy_connectivity_dup_singleton ();
2458 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2460 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2461 GParamSpec *param_spec;
2463 oclass->dispose = do_dispose;
2464 oclass->constructed = do_constructed;
2465 oclass->set_property = do_set_property;
2466 oclass->get_property = do_get_property;
2468 param_spec = g_param_spec_object ("parent",
2469 "parent", "The parent window",
2471 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2472 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2474 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2478 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2480 EmpathyAccountsDialogPriv *priv;
2482 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2483 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2484 EmpathyAccountsDialogPriv);
2485 dialog->priv = priv;
2488 /* public methods */
2491 empathy_accounts_dialog_show (GtkWindow *parent,
2492 TpAccount *selected_account)
2494 EmpathyAccountsDialog *dialog;
2495 EmpathyAccountsDialogPriv *priv;
2497 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2498 "parent", parent, NULL);
2500 priv = GET_PRIV (dialog);
2502 if (selected_account)
2504 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2505 accounts_dialog_set_selected_account (dialog, selected_account);
2507 /* save the selection to set it later when the cms
2510 priv->initial_selection = g_object_ref (selected_account);
2513 gtk_window_present (GTK_WINDOW (dialog));
2515 return GTK_WIDGET (dialog);
2519 empathy_accounts_dialog_show_application (GdkScreen *screen,
2520 TpAccount *selected_account,
2526 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2528 args = g_string_new (NULL);
2530 if (selected_account != NULL)
2531 g_string_append_printf (args, " --select-account=%s",
2532 tp_account_get_path_suffix (selected_account));
2535 g_string_append_printf (args, " --if-needed");
2538 g_string_append_printf (args, " --hidden");
2540 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2542 selected_account == NULL ? "<none selected>" :
2543 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2545 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2547 g_string_free (args, TRUE);
2551 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2553 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2554 gboolean result = FALSE;
2556 if (priv->setting_widget_object == NULL)
2559 g_object_get (priv->setting_widget_object,
2560 "creating-account", &result, NULL);