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,
85 GtkWidget *alignment_settings;
86 GtkWidget *alignment_infobar;
88 GtkWidget *vbox_details;
90 GtkWidget *label_status;
91 GtkWidget *image_status;
93 GtkWidget *enabled_switch;
94 GtkWidget *frame_no_protocol;
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_show (priv->frame_no_protocol);
988 gtk_widget_set_sensitive (priv->button_add, FALSE);
992 /* We have an account selected, destroy old settings and create a new
993 * one for the account selected */
994 gtk_widget_hide (priv->frame_no_protocol);
995 gtk_widget_show (priv->vbox_details);
997 if (priv->dialog_content)
999 gtk_widget_destroy (priv->dialog_content);
1000 priv->dialog_content = NULL;
1003 if (empathy_account_settings_is_ready (settings))
1005 account_dialog_create_dialog_content (dialog, settings);
1009 priv->settings_ready = settings;
1010 priv->settings_ready_id =
1011 g_signal_connect (settings, "notify::ready",
1012 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1018 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1019 GtkCellEditable *editable,
1021 EmpathyAccountsDialog *dialog)
1023 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1025 if (priv->connecting_id)
1026 g_source_remove (priv->connecting_id);
1028 DEBUG ("Editing account name started; stopping flashing");
1031 static const gchar *
1032 get_status_icon_for_account (EmpathyAccountsDialog *self,
1035 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1036 TpConnectionStatus status;
1037 TpConnectionStatusReason reason;
1038 TpConnectionPresenceType presence;
1040 if (account == NULL)
1041 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1043 if (!tp_account_is_enabled (account))
1044 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1046 status = tp_account_get_connection_status (account, &reason);
1048 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1050 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1051 /* An error occured */
1052 return GTK_STOCK_DIALOG_ERROR;
1054 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1056 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1058 /* Account is connecting. Display a blinking account alternating between
1059 * the offline icon and the requested presence. */
1060 if (priv->connecting_show)
1061 presence = tp_account_get_requested_presence (account, NULL, NULL);
1063 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1067 /* status == TP_CONNECTION_STATUS_CONNECTED */
1068 presence = tp_account_get_current_presence (account, NULL, NULL);
1070 /* If presence is Unset (CM doesn't implement SimplePresence),
1071 * display the 'available' icon.
1072 * We also check Offline because of this MC5 bug: fd.o #26060 */
1073 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1074 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1075 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1078 return empathy_icon_name_for_presence (presence);
1082 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1083 GtkCellRenderer *cell,
1084 GtkTreeModel *model,
1086 EmpathyAccountsDialog *dialog)
1090 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1093 "icon-name", get_status_icon_for_account (dialog, account),
1096 if (account != NULL)
1097 g_object_unref (account);
1101 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1102 GtkCellRenderer *cell,
1103 GtkTreeModel *model,
1105 EmpathyAccountsDialog *dialog)
1107 EmpathyAccountSettings *settings;
1110 TpConnectionStatus status;
1112 gtk_tree_model_get (model, iter,
1113 COL_STATUS, &status,
1114 COL_ACCOUNT_SETTINGS, &settings,
1117 icon_name = empathy_account_settings_get_icon_name (settings);
1118 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1125 g_object_unref (settings);
1128 g_object_unref (pixbuf);
1132 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1139 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1141 if (account == NULL)
1144 if (tp_account_get_connection_status (account, NULL) ==
1145 TP_CONNECTION_STATUS_CONNECTING)
1147 /* Only update the row where we have a connecting account as that's the
1148 * ones having a blinking icon. */
1149 gtk_tree_model_row_changed (model, path, iter);
1152 g_object_unref (account);
1157 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1160 GtkTreeModel *model;
1161 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1163 priv->connecting_show = !priv->connecting_show;
1165 view = GTK_TREE_VIEW (priv->treeview);
1166 model = gtk_tree_view_get_model (view);
1168 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1174 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1177 EmpathyAccountsDialog *dialog)
1179 EmpathyAccountSettings *settings;
1180 GtkTreeModel *model;
1181 GtkTreePath *treepath;
1183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1184 gboolean connecting;
1186 empathy_account_manager_get_accounts_connected (&connecting);
1190 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1191 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1195 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1196 treepath = gtk_tree_path_new_from_string (path);
1197 gtk_tree_model_get_iter (model, &iter, treepath);
1198 gtk_tree_model_get (model, &iter,
1199 COL_ACCOUNT_SETTINGS, &settings,
1201 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1204 gtk_tree_path_free (treepath);
1206 empathy_account_settings_set_display_name_async (settings, new_text,
1208 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1209 g_object_unref (settings);
1213 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1218 GtkTreeModel *model;
1220 GtkTreeSelection *selection;
1221 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1222 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1224 if (response_id == GTK_RESPONSE_YES)
1226 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1228 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1231 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1233 if (account != NULL)
1235 tp_account_remove_async (account, NULL, NULL);
1236 g_object_unref (account);
1240 /* No need to call accounts_dialog_model_selection_changed while
1241 * removing as we are going to call accounts_dialog_model_select_first
1242 * right after which will update the selection. */
1243 g_signal_handlers_block_by_func (selection,
1244 accounts_dialog_model_selection_changed, account_dialog);
1246 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1248 g_signal_handlers_unblock_by_func (selection,
1249 accounts_dialog_model_selection_changed, account_dialog);
1251 accounts_dialog_model_select_first (account_dialog);
1254 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1258 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1261 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1263 GtkTreeModel *model;
1264 gchar *question_dialog_primary_text;
1266 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1268 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1270 if (account == NULL || !tp_account_is_valid (account))
1272 if (account != NULL)
1273 g_object_unref (account);
1274 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1275 accounts_dialog_model_select_first (dialog);
1279 question_dialog_primary_text = g_strdup_printf (
1280 _("Do you want to remove %s from your computer?"),
1281 tp_account_get_display_name (account));
1283 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1284 _("This will not remove your account on the server."),
1285 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1287 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1288 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1290 g_free (question_dialog_primary_text);
1291 g_object_unref (account);
1295 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1296 EmpathyAccountsDialog *dialog)
1298 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1300 GtkTreeSelection *selection;
1303 view = GTK_TREE_VIEW (priv->treeview);
1304 selection = gtk_tree_view_get_selection (view);
1305 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1308 accounts_dialog_remove_account_iter (dialog, &iter);
1313 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1314 const gchar *path_string,
1315 EmpathyAccountsDialog *dialog)
1317 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1318 GtkTreeModel *model;
1321 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1322 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1325 accounts_dialog_remove_account_iter (dialog, &iter);
1327 #endif /* HAVE_MEEGO */
1330 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1333 GtkTreeViewColumn *column;
1334 GtkCellRenderer *cell;
1335 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1337 view = GTK_TREE_VIEW (priv->treeview);
1338 gtk_tree_view_set_headers_visible (view, FALSE);
1340 /* Account column */
1341 column = gtk_tree_view_column_new ();
1342 gtk_tree_view_column_set_expand (column, TRUE);
1343 gtk_tree_view_append_column (view, column);
1345 /* Status icon renderer */
1346 cell = gtk_cell_renderer_pixbuf_new ();
1347 gtk_tree_view_column_pack_start (column, cell, FALSE);
1348 gtk_tree_view_column_set_cell_data_func (column, cell,
1349 (GtkTreeCellDataFunc)
1350 accounts_dialog_model_status_pixbuf_data_func,
1354 /* Protocol icon renderer */
1355 cell = gtk_cell_renderer_pixbuf_new ();
1356 gtk_tree_view_column_pack_start (column, cell, FALSE);
1357 gtk_tree_view_column_set_cell_data_func (column, cell,
1358 (GtkTreeCellDataFunc)
1359 accounts_dialog_model_protocol_pixbuf_data_func,
1364 cell = gtk_cell_renderer_text_new ();
1366 "ellipsize", PANGO_ELLIPSIZE_END,
1370 gtk_tree_view_column_pack_start (column, cell, TRUE);
1371 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1372 g_signal_connect (cell, "edited",
1373 G_CALLBACK (accounts_dialog_name_edited_cb),
1375 g_signal_connect (cell, "editing-started",
1376 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1378 g_object_set (cell, "ypad", 4, NULL);
1382 cell = empathy_cell_renderer_activatable_new ();
1383 gtk_tree_view_column_pack_start (column, cell, FALSE);
1385 "icon-name", GTK_STOCK_DELETE,
1386 "show-on-select", TRUE,
1389 g_signal_connect (cell, "path-activated",
1390 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1392 #endif /* HAVE_MEEGO */
1395 static EmpathyAccountSettings *
1396 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1399 GtkTreeModel *model;
1400 GtkTreeSelection *selection;
1402 EmpathyAccountSettings *settings;
1403 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1405 view = GTK_TREE_VIEW (priv->treeview);
1406 selection = gtk_tree_view_get_selection (view);
1408 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1411 gtk_tree_model_get (model, &iter,
1412 COL_ACCOUNT_SETTINGS, &settings, -1);
1418 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1419 EmpathyAccountsDialog *dialog)
1421 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1422 EmpathyAccountSettings *settings;
1423 GtkTreeModel *model;
1425 gboolean is_selection;
1426 gboolean creating = FALSE;
1428 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1430 settings = accounts_dialog_model_get_selected_settings (dialog);
1431 accounts_dialog_update_settings (dialog, settings);
1433 if (settings != NULL)
1434 g_object_unref (settings);
1436 if (priv->setting_widget_object != NULL)
1438 g_object_get (priv->setting_widget_object,
1439 "creating-account", &creating, NULL);
1442 /* Update remove button sensitivity */
1443 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1448 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1450 gpointer *user_data)
1452 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1453 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1455 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1457 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1459 /* The user wants to lose unsaved changes to the currently selected
1460 * account and select another account. We discard the changes and
1461 * select the other account. */
1463 GtkTreeSelection *selection;
1465 priv->force_change_row = TRUE;
1466 empathy_account_widget_discard_pending_changes (
1467 priv->setting_widget_object);
1469 path = gtk_tree_row_reference_get_path (priv->destination_row);
1470 selection = gtk_tree_view_get_selection (
1471 GTK_TREE_VIEW (priv->treeview));
1475 /* This will trigger a call to
1476 * accounts_dialog_account_selection_change() */
1477 gtk_tree_selection_select_path (selection, path);
1478 gtk_tree_path_free (path);
1481 gtk_tree_row_reference_free (priv->destination_row);
1485 priv->force_change_row = FALSE;
1490 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1491 GtkTreeModel *model,
1493 gboolean path_currently_selected,
1496 TpAccount *account = NULL;
1497 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1498 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1501 if (priv->force_change_row)
1503 /* We came back here because the user wants to discard changes to his
1504 * modified account. The changes have already been discarded so we
1505 * just change the selected row. */
1506 priv->force_change_row = FALSE;
1510 if (accounts_dialog_has_pending_change (dialog, &account))
1512 /* The currently selected account has some unsaved changes. We ask
1513 * the user if he really wants to lose his changes and select another
1515 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1516 priv->destination_row = gtk_tree_row_reference_new (model, path);
1518 accounts_dialog_show_question_dialog (dialog,
1519 question_dialog_primary_text,
1520 _("You are about to select another account, which will discard\n"
1521 "your changes. Are you sure you want to proceed?"),
1522 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1524 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1525 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1527 g_free (question_dialog_primary_text);
1535 if (account != NULL)
1536 g_object_unref (account);
1542 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1544 GtkListStore *store;
1545 GtkTreeSelection *selection;
1546 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1548 store = gtk_list_store_new (COL_COUNT,
1549 G_TYPE_STRING, /* name */
1550 G_TYPE_UINT, /* status */
1551 TP_TYPE_ACCOUNT, /* account */
1552 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1554 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1555 GTK_TREE_MODEL (store));
1557 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1558 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1559 gtk_tree_selection_set_select_function (selection,
1560 accounts_dialog_account_selection_change, dialog, NULL);
1562 g_signal_connect (selection, "changed",
1563 G_CALLBACK (accounts_dialog_model_selection_changed),
1566 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1567 COL_NAME, GTK_SORT_ASCENDING);
1569 accounts_dialog_model_add_columns (dialog);
1571 g_object_unref (store);
1575 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1580 GtkTreeModel *model;
1582 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1584 /* Update the status in the model */
1585 view = GTK_TREE_VIEW (priv->treeview);
1586 model = gtk_tree_view_get_model (view);
1588 for (ok = gtk_tree_model_get_iter_first (model, iter);
1590 ok = gtk_tree_model_iter_next (model, iter))
1592 TpAccount *this_account;
1595 gtk_tree_model_get (model, iter,
1596 COL_ACCOUNT, &this_account,
1599 equal = (this_account == account);
1600 g_object_unref (this_account);
1610 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1613 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1614 GtkTreeSelection *selection;
1616 GtkTreeModel *model;
1618 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1620 gtk_tree_selection_select_iter (selection, iter);
1622 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1623 path = gtk_tree_model_get_path (model, iter);
1625 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1628 gtk_tree_path_free (path);
1632 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1637 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1638 select_and_scroll_to_iter (dialog, &iter);
1642 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1647 enabled = tp_account_is_enabled (account);
1648 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1652 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1653 GdkEventButton *event,
1654 EmpathyAccountsDialog *dialog)
1656 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1657 TpAccount *account = NULL;
1658 GtkTreeModel *model = NULL;
1659 GtkTreePath *path = NULL;
1662 GtkWidget *item_enable, *item_disable;
1663 GtkWidget *image_enable, *image_disable;
1665 /* ignore multiple clicks */
1666 if (event->type != GDK_BUTTON_PRESS)
1669 if (event->button != 3)
1672 /* Selection is not yet set, so we have to get account from event position */
1673 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1674 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1675 event->x, event->y, &path, NULL, NULL, NULL))
1678 if (!gtk_tree_model_get_iter (model, &iter, path))
1681 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1683 /* Create the menu */
1684 menu = empathy_context_menu_new (GTK_WIDGET (view));
1686 /* Get images for menu items */
1687 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1688 tp_account_manager_get_most_available_presence (
1689 priv->account_manager, NULL, NULL)),
1690 GTK_ICON_SIZE_MENU);
1691 image_disable = gtk_image_new_from_icon_name (
1692 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1693 GTK_ICON_SIZE_MENU);
1695 /* Menu items: to enabled/disable the account */
1696 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1697 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1698 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1700 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1703 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1704 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1706 if (tp_account_is_enabled (account))
1708 tp_g_signal_connect_object (item_disable, "activate",
1709 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1710 gtk_widget_set_sensitive (item_enable, FALSE);
1714 tp_g_signal_connect_object (item_enable, "activate",
1715 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1716 gtk_widget_set_sensitive (item_disable, FALSE);
1719 gtk_widget_show (item_enable);
1720 gtk_widget_show (item_disable);
1722 /* FIXME: Add here presence items, to be able to set per-account presence */
1725 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1726 event->button, event->time);
1729 tp_clear_object (&account);
1730 gtk_tree_path_free (path);
1736 accounts_dialog_connection_changed_cb (TpAccount *account,
1740 gchar *dbus_error_name,
1741 GHashTable *details,
1742 EmpathyAccountsDialog *dialog)
1744 GtkTreeModel *model;
1747 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1749 /* Update the status-infobar in the details view */
1750 accounts_dialog_update_status_infobar (dialog, account);
1752 /* Update the status in the model */
1753 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1755 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1759 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1760 COL_STATUS, current,
1763 path = gtk_tree_model_get_path (model, &iter);
1764 gtk_tree_model_row_changed (model, path, &iter);
1765 gtk_tree_path_free (path);
1768 empathy_account_manager_get_accounts_connected (&found);
1770 if (!found && priv->connecting_id)
1772 g_source_remove (priv->connecting_id);
1773 priv->connecting_id = 0;
1776 if (found && !priv->connecting_id)
1777 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1778 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1783 update_account_in_treeview (EmpathyAccountsDialog *self,
1786 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1788 GtkTreeModel *model;
1790 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1791 if (accounts_dialog_get_account_iter (self, account, &iter))
1795 path = gtk_tree_model_get_path (model, &iter);
1796 gtk_tree_model_row_changed (model, path, &iter);
1797 gtk_tree_path_free (path);
1802 accounts_dialog_presence_changed_cb (TpAccount *account,
1805 gchar *status_message,
1806 EmpathyAccountsDialog *dialog)
1808 /* Update the status-infobar in the details view */
1809 accounts_dialog_update_status_infobar (dialog, account);
1811 update_account_in_treeview (dialog, account);
1815 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1819 const gchar *display_name;
1821 GtkTreeModel *model;
1822 EmpathyAccountSettings *settings;
1823 TpAccount *selected_account;
1824 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1825 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1827 display_name = tp_account_get_display_name (account);
1828 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1829 settings = accounts_dialog_model_get_selected_settings (dialog);
1830 if (settings == NULL)
1833 selected_account = empathy_account_settings_get_account (settings);
1835 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1837 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1838 COL_NAME, display_name,
1842 if (selected_account == account)
1843 accounts_dialog_update_name_label (dialog, display_name);
1845 g_object_unref (settings);
1849 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1852 EmpathyAccountSettings *settings;
1853 GtkTreeModel *model;
1855 TpConnectionStatus status;
1857 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1858 gboolean selected = FALSE;
1860 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1861 status = tp_account_get_connection_status (account, NULL);
1862 name = tp_account_get_display_name (account);
1864 settings = empathy_account_settings_new_for_account (account);
1866 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1868 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1872 GtkTreeSelection *selection;
1874 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1875 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1878 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1881 COL_ACCOUNT, account,
1882 COL_ACCOUNT_SETTINGS, settings,
1887 /* We just modified the selected account. Its display name may have been
1888 * changed and so it's place in the treeview. Scroll to it so it stays
1890 select_and_scroll_to_iter (dialog, &iter);
1893 accounts_dialog_connection_changed_cb (account,
1896 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1901 tp_g_signal_connect_object (account, "notify::display-name",
1902 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1905 tp_g_signal_connect_object (account, "status-changed",
1906 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1907 tp_g_signal_connect_object (account, "presence-changed",
1908 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1910 g_object_unref (settings);
1914 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1917 EmpathyAccountsDialog *dialog)
1919 accounts_dialog_add_account (dialog, account);
1923 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1926 EmpathyAccountsDialog *dialog)
1928 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1930 if (priv->setting_widget_object != NULL &&
1931 accounts_dialog_has_valid_accounts (dialog))
1933 empathy_account_widget_set_other_accounts_exist (
1934 priv->setting_widget_object, TRUE);
1939 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1941 EmpathyAccountsDialog *dialog)
1943 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1945 if (priv->setting_widget_object != NULL &&
1946 !accounts_dialog_has_valid_accounts (dialog))
1948 empathy_account_widget_set_other_accounts_exist (
1949 priv->setting_widget_object, FALSE);
1954 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1956 EmpathyAccountsDialog *dialog)
1959 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1961 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1963 gtk_list_store_remove (GTK_LIST_STORE (
1964 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1969 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1973 /* Update the status-infobar in the details view */
1974 accounts_dialog_update_status_infobar (dialog, account);
1976 DEBUG ("Account %s is now %s",
1977 tp_account_get_display_name (account),
1978 enabled ? "enabled" : "disabled");
1982 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1984 EmpathyAccountsDialog *dialog)
1986 enable_or_disable_account (dialog, account, FALSE);
1987 update_account_in_treeview (dialog, account);
1991 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1993 EmpathyAccountsDialog *dialog)
1995 enable_or_disable_account (dialog, account, TRUE);
1999 display_import_dialog (EmpathyAccountsDialog *dialog)
2001 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2002 GtkWidget *import_dialog;
2004 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2006 gtk_widget_show (import_dialog);
2008 return import_dialog;
2012 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2013 EmpathyAccountsDialog *dialog)
2015 display_import_dialog (dialog);
2019 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2023 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2025 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2027 if (response_id == GTK_RESPONSE_YES)
2028 gtk_widget_destroy (account_dialog);
2032 accounts_dialog_delete_event_cb (GtkWidget *widget,
2034 EmpathyAccountsDialog *dialog)
2036 /* we maunally handle responses to delete events */
2041 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2046 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2047 select_and_scroll_to_iter (dialog, &iter);
2051 finished_loading (EmpathyAccountsDialog *self)
2053 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2054 GtkTreeSelection *selection;
2055 gboolean has_selected;
2057 priv->loading = FALSE;
2059 gtk_widget_set_sensitive (priv->button_add, TRUE);
2060 gtk_widget_set_sensitive (priv->button_import, TRUE);
2061 gtk_widget_set_sensitive (priv->treeview, TRUE);
2063 /* Sensitive the remove button if there is an account selected */
2064 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2065 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2066 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2068 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2069 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2070 NOTEBOOK_PAGE_ACCOUNT);
2074 accounts_dialog_cms_prepare_cb (GObject *source,
2075 GAsyncResult *result,
2078 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2079 EmpathyAccountsDialog *dialog = user_data;
2080 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2082 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2085 /* No need to update the settings if we are already preparing one */
2086 if (priv->settings_ready == NULL)
2087 accounts_dialog_update_settings (dialog, NULL);
2089 if (priv->initial_selection != NULL)
2091 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2092 g_object_unref (priv->initial_selection);
2093 priv->initial_selection = NULL;
2097 finished_loading (dialog);
2101 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2104 GList *accounts, *l;
2106 g_signal_connect (priv->account_manager, "account-validity-changed",
2107 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2109 g_signal_connect (priv->account_manager, "account-removed",
2110 G_CALLBACK (accounts_dialog_account_removed_cb),
2112 g_signal_connect (priv->account_manager, "account-enabled",
2113 G_CALLBACK (accounts_dialog_account_enabled_cb),
2115 g_signal_connect (priv->account_manager, "account-disabled",
2116 G_CALLBACK (accounts_dialog_account_disabled_cb),
2119 /* Add existing accounts */
2120 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2121 for (l = accounts; l; l = l->next)
2123 accounts_dialog_add_account (dialog, l->data);
2125 g_list_free (accounts);
2127 priv->cms = empathy_connection_managers_dup_singleton ();
2129 empathy_connection_managers_prepare_async (priv->cms,
2130 accounts_dialog_cms_prepare_cb, dialog);
2132 accounts_dialog_model_select_first (dialog);
2136 accounts_dialog_manager_ready_cb (GObject *source_object,
2137 GAsyncResult *result,
2140 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2141 GError *error = NULL;
2143 if (!tp_proxy_prepare_finish (manager, result, &error))
2145 DEBUG ("Failed to prepare account manager: %s", error->message);
2146 g_error_free (error);
2150 accounts_dialog_accounts_setup (user_data);
2154 dialog_response_cb (GtkWidget *widget,
2158 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2160 if (response_id == GTK_RESPONSE_HELP)
2162 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2164 else if (response_id == GTK_RESPONSE_CLOSE ||
2165 response_id == GTK_RESPONSE_DELETE_EVENT)
2167 TpAccount *account = NULL;
2169 if (accounts_dialog_has_pending_change (dialog, &account))
2171 gchar *question_dialog_primary_text = get_dialog_primary_text (
2174 accounts_dialog_show_question_dialog (dialog,
2175 question_dialog_primary_text,
2176 _("You are about to close the window, which will discard\n"
2177 "your changes. Are you sure you want to proceed?"),
2178 G_CALLBACK (accounts_dialog_close_response_cb),
2180 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2181 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2183 g_free (question_dialog_primary_text);
2187 gtk_widget_destroy (widget);
2190 if (account != NULL)
2191 g_object_unref (account);
2196 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2198 GtkWidget *top_hbox;
2201 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2202 GtkWidget *content_area, *action_area;
2203 GtkWidget *grid, *hbox;
2205 GtkWidget *sw, *toolbar;
2206 GtkStyleContext *context;
2208 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2210 gui = empathy_builder_get_file (filename,
2211 "accounts_dialog_hbox", &top_hbox,
2212 "vbox_details", &priv->vbox_details,
2213 "frame_no_protocol", &priv->frame_no_protocol,
2214 "alignment_settings", &priv->alignment_settings,
2215 "alignment_infobar", &priv->alignment_infobar,
2216 "treeview", &priv->treeview,
2217 "button_add", &priv->button_add,
2218 "button_remove", &priv->button_remove,
2219 "button_import", &priv->button_import,
2220 "notebook_account", &priv->notebook_account,
2221 "alignment_loading", &alig,
2223 "add_remove_toolbar", &toolbar,
2227 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2229 empathy_builder_connect (gui, dialog,
2230 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2231 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2232 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2233 "treeview", "button-press-event",
2234 accounts_dialog_treeview_button_press_event_cb,
2237 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2239 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2241 g_object_unref (gui);
2243 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2246 gtk_widget_hide (action_area);
2247 gtk_widget_hide (priv->button_remove);
2248 #endif /* HAVE_MEEGO */
2250 /* Display loading page */
2251 priv->loading = TRUE;
2253 priv->spinner = gtk_spinner_new ();
2255 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2256 gtk_widget_show (priv->spinner);
2258 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2260 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2261 NOTEBOOK_PAGE_LOADING);
2263 /* Remove button is insensitive until we have a selected account */
2264 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2266 /* Add and Import buttons and treeview are insensitive while the dialog
2268 gtk_widget_set_sensitive (priv->button_add, FALSE);
2269 gtk_widget_set_sensitive (priv->button_import, FALSE);
2270 gtk_widget_set_sensitive (priv->treeview, FALSE);
2272 if (priv->parent_window)
2273 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2274 priv->parent_window);
2276 priv->infobar = gtk_info_bar_new ();
2277 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2279 gtk_widget_show (priv->infobar);
2281 grid = gtk_grid_new ();
2283 GTK_CONTAINER (gtk_info_bar_get_content_area (
2284 GTK_INFO_BAR (priv->infobar))),
2287 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2288 GTK_ICON_SIZE_DIALOG);
2289 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2290 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2293 priv->label_name = gtk_label_new (NULL);
2294 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2297 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2298 gtk_widget_set_hexpand (hbox, TRUE);
2299 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2300 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2302 /* set up spinner */
2303 priv->throbber = gtk_spinner_new ();
2305 priv->image_status = gtk_image_new_from_icon_name (
2306 empathy_icon_name_for_presence (
2307 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2309 priv->label_status = gtk_label_new (NULL);
2310 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2312 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2313 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2314 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2316 /* enabled switch */
2317 priv->enabled_switch = gtk_switch_new ();
2318 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2319 g_signal_connect (priv->enabled_switch, "notify::active",
2320 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2321 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2323 gtk_widget_show_all (grid);
2325 /* Tweak the dialog */
2326 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2327 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2329 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2331 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2333 /* join the add/remove toolbar to the treeview */
2334 context = gtk_widget_get_style_context (sw);
2335 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2337 context = gtk_widget_get_style_context (toolbar);
2338 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2340 /* add dialog buttons */
2341 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2343 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2344 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2345 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2348 g_signal_connect (dialog, "response",
2349 G_CALLBACK (dialog_response_cb), dialog);
2351 g_signal_connect (dialog, "delete-event",
2352 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2356 do_dispose (GObject *obj)
2358 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2359 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2361 if (priv->connecting_id != 0)
2363 g_source_remove (priv->connecting_id);
2364 priv->connecting_id = 0;
2367 if (priv->account_manager != NULL)
2369 g_object_unref (priv->account_manager);
2370 priv->account_manager = NULL;
2373 if (priv->cms != NULL)
2375 g_object_unref (priv->cms);
2379 if (priv->connectivity)
2381 g_object_unref (priv->connectivity);
2382 priv->connectivity = NULL;
2385 if (priv->initial_selection != NULL)
2387 g_object_unref (priv->initial_selection);
2388 priv->initial_selection = NULL;
2391 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2395 do_get_property (GObject *object,
2400 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2402 switch (property_id)
2405 g_value_set_object (value, priv->parent_window);
2408 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2413 do_set_property (GObject *object,
2415 const GValue *value,
2418 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2420 switch (property_id)
2423 priv->parent_window = g_value_get_object (value);
2426 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2431 do_constructed (GObject *object)
2433 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2434 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2435 GtkTreeModel *model;
2437 accounts_dialog_build_ui (dialog);
2438 accounts_dialog_model_setup (dialog);
2440 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2441 g_signal_connect (model, "row-inserted",
2442 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2443 g_signal_connect (model, "row-deleted",
2444 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2446 /* Set up signalling */
2447 priv->account_manager = tp_account_manager_dup ();
2449 tp_proxy_prepare_async (priv->account_manager, NULL,
2450 accounts_dialog_manager_ready_cb, dialog);
2452 priv->connectivity = empathy_connectivity_dup_singleton ();
2456 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2458 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2459 GParamSpec *param_spec;
2461 oclass->dispose = do_dispose;
2462 oclass->constructed = do_constructed;
2463 oclass->set_property = do_set_property;
2464 oclass->get_property = do_get_property;
2466 param_spec = g_param_spec_object ("parent",
2467 "parent", "The parent window",
2469 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2470 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2472 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2476 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2478 EmpathyAccountsDialogPriv *priv;
2480 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2481 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2482 EmpathyAccountsDialogPriv);
2483 dialog->priv = priv;
2486 /* public methods */
2489 empathy_accounts_dialog_show (GtkWindow *parent,
2490 TpAccount *selected_account)
2492 EmpathyAccountsDialog *dialog;
2493 EmpathyAccountsDialogPriv *priv;
2495 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2496 "parent", parent, NULL);
2498 priv = GET_PRIV (dialog);
2500 if (selected_account)
2502 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2503 accounts_dialog_set_selected_account (dialog, selected_account);
2505 /* save the selection to set it later when the cms
2508 priv->initial_selection = g_object_ref (selected_account);
2511 gtk_window_present (GTK_WINDOW (dialog));
2513 return GTK_WIDGET (dialog);
2517 empathy_accounts_dialog_show_application (GdkScreen *screen,
2518 TpAccount *selected_account,
2524 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2526 args = g_string_new (NULL);
2528 if (selected_account != NULL)
2529 g_string_append_printf (args, " --select-account=%s",
2530 tp_account_get_path_suffix (selected_account));
2533 g_string_append_printf (args, " --if-needed");
2536 g_string_append_printf (args, " --hidden");
2538 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2540 selected_account == NULL ? "<none selected>" :
2541 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2543 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2545 g_string_free (args, TRUE);
2549 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2551 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2552 gboolean result = FALSE;
2554 if (priv->setting_widget_object == NULL)
2557 g_object_get (priv->setting_widget_object,
2558 "creating-account", &result, NULL);