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-common.h"
57 #include "empathy-accounts-dialog.h"
58 #include "empathy-import-dialog.h"
59 #include "empathy-import-utils.h"
61 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
62 #include <libempathy/empathy-debug.h>
64 /* Flashing delay for icons (milliseconds). */
65 #define FLASH_TIMEOUT 500
67 /* The primary text of the dialog shown to the user when he is about to lose
69 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
70 _("There are unsaved modifications to your %s account.")
71 /* The primary text of the dialog shown to the user when he is about to lose
72 * an unsaved new account */
73 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
74 _("Your new account has not been saved yet.")
76 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
77 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
81 NOTEBOOK_PAGE_ACCOUNT = 0,
82 NOTEBOOK_PAGE_LOADING,
83 NOTEBOOK_PAGE_NO_PROTOCOL
87 GtkWidget *alignment_settings;
88 GtkWidget *alignment_infobar;
90 GtkWidget *vbox_details;
92 GtkWidget *label_status;
93 GtkWidget *image_status;
95 GtkWidget *enabled_switch;
99 GtkWidget *button_add;
100 GtkWidget *button_remove;
101 GtkWidget *button_import;
103 GtkWidget *image_type;
104 GtkWidget *label_name;
105 GtkWidget *label_type;
106 GtkWidget *dialog_content;
108 GtkWidget *notebook_account;
112 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
113 * just its GtkWidget. It is the only reliable source we can query to know if
114 * there are any unsaved changes to the currently selected account. We can't
115 * look at the account settings because it does not contain everything that
116 * can be changed using the EmpathyAccountWidget. For instance, it does not
117 * contain the state of the "Enabled" checkbox.
119 * Even if we create it ourself, we just get a weak ref and not a strong one
120 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
121 * That's kinda ugly; cf bgo #640417.
124 EmpathyAccountWidget *setting_widget_object;
126 gboolean connecting_show;
129 gulong settings_ready_id;
130 EmpathyAccountSettings *settings_ready;
132 TpAccountManager *account_manager;
133 EmpathyConnectionManagers *cms;
134 EmpathyConnectivity *connectivity;
136 GtkWindow *parent_window;
137 TpAccount *initial_selection;
139 /* Those are needed when changing the selected row. When a user selects
140 * another account and there are unsaved changes on the currently selected
141 * one, a confirmation message box is presented to him. Since his answer
142 * is retrieved asynchronously, we keep some information as member of the
143 * EmpathyAccountsDialog object. */
144 gboolean force_change_row;
145 GtkTreeRowReference *destination_row;
146 } EmpathyAccountsDialogPriv;
152 COL_ACCOUNT_SETTINGS,
160 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
161 EmpathyAccountsDialog *dialog);
163 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
165 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
166 EmpathyAccountSettings *settings);
168 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
171 static void accounts_dialog_connection_changed_cb (TpAccount *account,
175 gchar *dbus_error_name,
177 EmpathyAccountsDialog *dialog);
179 static void accounts_dialog_presence_changed_cb (TpAccount *account,
182 gchar *status_message,
183 EmpathyAccountsDialog *dialog);
185 static void accounts_dialog_model_selection_changed (
186 GtkTreeSelection *selection,
187 EmpathyAccountsDialog *dialog);
189 static gboolean accounts_dialog_has_pending_change (
190 EmpathyAccountsDialog *dialog, TpAccount **account);
193 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
194 const gchar *display_name)
197 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
199 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
200 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
206 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
207 const gchar *message)
209 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
210 gchar *message_markup;
212 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
213 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
215 gtk_widget_set_tooltip_text (priv->label_status, message);
217 g_free (message_markup);
221 accounts_dialog_enable_account_cb (GObject *account,
222 GAsyncResult *result,
225 GError *error = NULL;
227 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
231 DEBUG ("Could not enable the account: %s", error->message);
232 g_error_free (error);
236 TpAccountManager *am = tp_account_manager_dup ();
238 empathy_connect_new_account (TP_ACCOUNT (account), am);
244 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
246 EmpathyAccountsDialog *dialog)
248 EmpathyAccountSettings *settings;
251 settings = accounts_dialog_model_get_selected_settings (dialog);
252 if (settings == NULL)
255 account = empathy_account_settings_get_account (settings);
259 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
260 accounts_dialog_enable_account_cb, NULL);
264 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
267 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
268 gchar *status_message = NULL;
274 GtkTreeSelection *selection;
276 TpAccount *selected_account;
277 gboolean account_enabled;
278 gboolean creating_account;
279 TpStorageRestrictionFlags storage_restrictions = 0;
281 view = GTK_TREE_VIEW (priv->treeview);
282 selection = gtk_tree_view_get_selection (view);
284 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
287 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
288 if (selected_account != NULL)
289 g_object_unref (selected_account);
291 /* do not update the infobar when the account is not selected */
292 if (account != selected_account)
297 status = tp_account_get_connection_status (account, &reason);
298 presence = tp_account_get_current_presence (account, NULL, &status_message);
299 account_enabled = tp_account_is_enabled (account);
300 creating_account = FALSE;
302 if (status == TP_CONNECTION_STATUS_CONNECTED &&
303 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
304 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
305 /* If presence is Unset (CM doesn't implement SimplePresence) but we
306 * are connected, consider ourself as Available.
307 * We also check Offline because of this MC5 bug: fd.o #26060 */
308 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
310 /* set presence to offline if account is disabled
311 * (else no icon is shown in infobar)*/
312 if (!account_enabled)
313 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
315 storage_restrictions = tp_account_get_storage_restrictions (account);
319 status = TP_CONNECTION_STATUS_DISCONNECTED;
320 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
321 account_enabled = FALSE;
322 creating_account = TRUE;
325 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
326 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
328 /* update the enabled switch */
329 g_signal_handlers_block_by_func (priv->enabled_switch,
330 accounts_dialog_enable_switch_active_cb, dialog);
331 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
333 g_signal_handlers_unblock_by_func (priv->enabled_switch,
334 accounts_dialog_enable_switch_active_cb, dialog);
336 /* Display the Enable switch if account supports it */
337 gtk_widget_set_visible (priv->enabled_switch,
338 !(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED));
344 case TP_CONNECTION_STATUS_CONNECTING:
345 accounts_dialog_status_infobar_set_message (dialog,
347 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
350 gtk_spinner_start (GTK_SPINNER (priv->throbber));
351 gtk_widget_show (priv->throbber);
352 gtk_widget_hide (priv->image_status);
354 case TP_CONNECTION_STATUS_CONNECTED:
355 if (g_strcmp0 (status_message, "") == 0)
359 message = g_strdup_printf ("%s",
360 empathy_presence_get_default_message (presence));
362 accounts_dialog_status_infobar_set_message (dialog, message);
369 message = g_strdup_printf ("%s — %s",
370 empathy_presence_get_default_message (presence),
373 accounts_dialog_status_infobar_set_message (dialog, message);
376 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
379 gtk_widget_show (priv->image_status);
380 gtk_widget_hide (priv->throbber);
382 case TP_CONNECTION_STATUS_DISCONNECTED:
383 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
387 message = g_strdup_printf (_("Offline — %s"),
388 empathy_account_get_error_message (account, NULL));
389 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
390 GTK_MESSAGE_WARNING);
392 accounts_dialog_status_infobar_set_message (dialog, message);
399 message = g_strdup_printf (_("Disconnected — %s"),
400 empathy_account_get_error_message (account, NULL));
401 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
404 accounts_dialog_status_infobar_set_message (dialog, message);
408 if (!empathy_connectivity_is_online (priv->connectivity))
409 accounts_dialog_status_infobar_set_message (dialog,
410 _("Offline — No Network Connection"));
412 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
413 gtk_widget_show (priv->image_status);
414 gtk_widget_hide (priv->throbber);
417 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
418 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
419 GTK_MESSAGE_WARNING);
421 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
422 gtk_widget_hide (priv->image_status);
423 gtk_widget_hide (priv->throbber);
428 accounts_dialog_status_infobar_set_message (dialog,
429 _("Offline — Account Disabled"));
431 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
432 GTK_MESSAGE_WARNING);
433 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
434 gtk_widget_show (priv->image_status);
435 gtk_widget_hide (priv->throbber);
438 gtk_widget_show (priv->label_status);
440 if (!creating_account)
441 gtk_widget_show (priv->infobar);
443 gtk_widget_hide (priv->infobar);
445 g_free (status_message);
449 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
453 GtkTreeSelection *selection;
455 EmpathyAccountSettings *settings;
457 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
459 view = GTK_TREE_VIEW (priv->treeview);
460 selection = gtk_tree_view_get_selection (view);
462 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
465 gtk_tree_model_get (model, &iter,
466 COL_ACCOUNT_SETTINGS, &settings,
467 COL_ACCOUNT, &account, -1);
469 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
473 /* We were creating an account. We remove the selected row */
474 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
478 /* We were modifying an account. We discard the changes by reloading the
479 * settings and the UI. */
480 accounts_dialog_update_settings (dialog, settings);
481 g_object_unref (account);
484 gtk_widget_set_sensitive (priv->treeview, TRUE);
485 gtk_widget_set_sensitive (priv->button_add, TRUE);
486 gtk_widget_set_sensitive (priv->button_remove, TRUE);
487 gtk_widget_set_sensitive (priv->button_import, TRUE);
489 if (settings != NULL)
490 g_object_unref (settings);
494 empathy_account_dialog_widget_cancelled_cb (
495 EmpathyAccountWidget *widget_object,
496 EmpathyAccountsDialog *dialog)
498 empathy_account_dialog_cancel (dialog);
502 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
504 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
509 g_object_get (priv->setting_widget_object,
510 "creating-account", &creating, NULL);
515 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
517 if (gtk_tree_model_get_iter_first (model, &iter))
518 return gtk_tree_model_iter_next (model, &iter);
524 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
526 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
527 EmpathyAccountSettings *settings;
528 GtkWidget *subdialog, *content, *content_area, *align;
530 settings = accounts_dialog_model_get_selected_settings (dialog);
532 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
534 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
537 priv->setting_widget_object =
538 empathy_account_widget_new_for_protocol (settings, FALSE);
540 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
541 (gpointer *) &priv->setting_widget_object);
543 if (accounts_dialog_has_valid_accounts (dialog))
544 empathy_account_widget_set_other_accounts_exist (
545 priv->setting_widget_object, TRUE);
547 content = empathy_account_widget_get_widget (priv->setting_widget_object);
549 g_signal_connect (priv->setting_widget_object, "cancelled",
550 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
552 g_signal_connect_swapped (priv->setting_widget_object, "close",
553 G_CALLBACK (gtk_widget_destroy), subdialog);
555 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
557 align = gtk_alignment_new (0.5, 0.5, 1, 1);
558 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
560 gtk_container_add (GTK_CONTAINER (align), content);
561 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
563 gtk_widget_show (content);
564 gtk_widget_show (align);
565 gtk_widget_show (subdialog);
569 start_external_app (GAppInfo *app_info)
571 GError *error = NULL;
572 GdkAppLaunchContext *context = NULL;
575 display = gdk_display_get_default ();
576 context = gdk_display_get_app_launch_context (display);
578 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
581 g_critical ("Failed to bisho: %s", error->message);
582 g_clear_error (&error);
585 tp_clear_object (&context);
589 use_external_storage_provider (EmpathyAccountsDialog *self,
592 const gchar *provider;
594 provider = tp_account_get_storage_provider (account);
595 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
597 GDesktopAppInfo *desktop_info;
600 GError *error = NULL;
602 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
603 if (desktop_info == NULL)
605 g_critical ("Could not locate 'gnome-control-center.desktop'");
609 /* glib doesn't have API to start a desktop file with args... (#637875) */
610 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
611 (GAppInfo *) desktop_info));
613 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
615 if (app_info == NULL)
617 DEBUG ("Failed to create app info: %s", error->message);
618 g_error_free (error);
622 start_external_app (app_info);
623 g_object_unref (app_info);
626 g_object_unref (desktop_info);
630 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
632 GDesktopAppInfo *desktop_info;
634 desktop_info = g_desktop_app_info_new (
635 "gnome-online-accounts-panel.desktop");
636 if (desktop_info == NULL)
638 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
642 start_external_app (G_APP_INFO (desktop_info));
643 g_object_unref (desktop_info);
650 DEBUG ("Don't know how to handle %s", provider);
656 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
659 EmpathyAccountSettings *settings;
661 TpStorageRestrictionFlags storage_restrictions;
663 settings = accounts_dialog_model_get_selected_settings (dialog);
665 account = empathy_account_settings_get_account (settings);
666 g_return_if_fail (account != NULL);
668 storage_restrictions = tp_account_get_storage_restrictions (account);
670 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
671 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
673 DEBUG ("Account is provided by an external storage provider");
675 use_external_storage_provider (dialog, account);
679 account_dialog_create_edit_params_dialog (dialog);
684 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
687 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
688 GtkWidget *infobar, *label;
690 infobar = gtk_info_bar_new ();
694 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
695 label = gtk_label_new (_("Failed to retrieve your personal information "
696 "from the server."));
700 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
701 label = gtk_label_new (_("Go online to edit your personal information."));
705 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
707 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
708 gtk_widget_show_all (infobar);
712 account_dialog_got_self_contact (TpConnection *conn,
713 EmpathyContact *contact,
714 const GError *in_error,
718 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
719 GtkWidget *editor, *alig;
721 if (in_error != NULL)
723 DEBUG ("Failed to get self-contact: %s", in_error->message);
724 account_dialog_show_contact_details_failed (
725 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
729 alig = gtk_alignment_new (0.5, 0, 1, 1);
731 /* create the contact info editor for this account */
732 editor = empathy_contact_widget_new (contact,
733 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
734 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
735 EMPATHY_CONTACT_WIDGET_NO_STATUS |
736 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS);
738 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
739 gtk_container_add (GTK_CONTAINER (alig), editor);
740 gtk_widget_show (alig);
741 gtk_widget_show (editor);
745 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
746 EmpathyAccountSettings *settings)
748 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
749 const gchar *icon_name;
751 TpConnection *conn = NULL;
752 GtkWidget *bbox, *button;
754 account = empathy_account_settings_get_account (settings);
756 // if (priv->setting_widget_object != NULL)
757 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
758 // (gpointer *) &priv->setting_widget_object);
760 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
761 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
762 priv->dialog_content);
763 gtk_widget_show (priv->dialog_content);
765 /* request the self contact */
767 conn = tp_account_get_connection (account);
771 empathy_tp_contact_factory_get_from_handle (conn,
772 tp_connection_get_self_handle (conn),
773 account_dialog_got_self_contact,
774 NULL, NULL, G_OBJECT (dialog));
778 account_dialog_show_contact_details_failed (dialog, FALSE);
781 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
782 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
783 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
784 gtk_widget_show (bbox);
786 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
787 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
788 gtk_widget_show (button);
789 g_signal_connect_swapped (button, "clicked",
790 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
792 icon_name = empathy_account_settings_get_icon_name (settings);
794 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
796 /* show the default icon; keep this in sync with the default
797 * one in empathy-accounts-dialog.ui.
799 icon_name = GTK_STOCK_CUT;
801 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
802 icon_name, GTK_ICON_SIZE_DIALOG);
803 gtk_widget_set_tooltip_text (priv->image_type,
804 empathy_protocol_name_to_display_name
805 (empathy_account_settings_get_protocol (settings)));
806 gtk_widget_show (priv->image_type);
808 accounts_dialog_update_name_label (dialog,
809 empathy_account_settings_get_display_name (settings));
811 accounts_dialog_update_status_infobar (dialog, account);
815 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
817 EmpathyAccountsDialog *dialog)
819 if (empathy_account_settings_is_ready (settings))
820 account_dialog_create_dialog_content (dialog, settings);
824 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
828 GtkTreeSelection *selection;
830 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
833 view = GTK_TREE_VIEW (priv->treeview);
834 model = gtk_tree_view_get_model (view);
836 if (gtk_tree_model_get_iter_first (model, &iter))
838 selection = gtk_tree_view_get_selection (view);
839 gtk_tree_selection_select_iter (selection, &iter);
843 accounts_dialog_update_settings (dialog, NULL);
848 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
853 GtkTreeSelection *selection;
854 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
856 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
858 if (gtk_tree_selection_get_selected (selection, &model, &iter))
859 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
861 return priv->setting_widget_object != NULL
862 && empathy_account_widget_contains_pending_changes (
863 priv->setting_widget_object);
867 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
868 const gchar *primary_text,
869 const gchar *secondary_text,
870 GCallback response_callback,
872 const gchar *first_button_text,
876 GtkWidget *message_dialog;
877 const gchar *button_text;
879 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
880 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
881 GTK_MESSAGE_QUESTION,
885 gtk_message_dialog_format_secondary_text (
886 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
888 va_start (button_args, first_button_text);
889 for (button_text = first_button_text;
891 button_text = va_arg (button_args, const gchar *))
894 response_id = va_arg (button_args, gint);
896 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
899 va_end (button_args);
901 g_signal_connect (message_dialog, "response", response_callback, user_data);
903 gtk_widget_show (message_dialog);
907 get_dialog_primary_text (TpAccount *account)
911 /* Existing account */
912 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
913 tp_account_get_display_name (account));
917 /* Newly created account */
918 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
923 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
924 EmpathyAccountsDialog *self)
929 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
930 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
932 response = gtk_dialog_run (GTK_DIALOG (dialog));
934 if (response == GTK_RESPONSE_OK)
936 EmpathyAccountSettings *settings;
939 settings = empathy_new_account_dialog_get_settings (
940 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
942 /* The newly created account has already been added by
943 * accounts_dialog_account_validity_changed_cb so we just
944 * have to select it. */
945 account = empathy_account_settings_get_account (settings);
946 accounts_dialog_model_set_selected (self, account);
949 gtk_widget_destroy (dialog);
953 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
954 EmpathyAccountSettings *settings)
956 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
958 if (priv->settings_ready != NULL)
960 g_signal_handler_disconnect (priv->settings_ready,
961 priv->settings_ready_id);
962 priv->settings_ready = NULL;
963 priv->settings_ready_id = 0;
970 GtkTreeSelection *selection;
972 view = GTK_TREE_VIEW (priv->treeview);
973 model = gtk_tree_view_get_model (view);
974 selection = gtk_tree_view_get_selection (view);
976 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
978 /* We have configured accounts, select the first one if there
979 * is no other account selected already. */
980 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
981 accounts_dialog_model_select_first (dialog);
986 /* No account and no profile, warn the user */
987 gtk_widget_hide (priv->vbox_details);
988 gtk_widget_set_sensitive (priv->button_add, FALSE);
990 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
991 NOTEBOOK_PAGE_NO_PROTOCOL);
995 /* We have an account selected, destroy old settings and create a new
996 * one for the account selected */
997 gtk_widget_show (priv->vbox_details);
999 if (priv->dialog_content)
1001 gtk_widget_destroy (priv->dialog_content);
1002 priv->dialog_content = NULL;
1005 if (empathy_account_settings_is_ready (settings))
1007 account_dialog_create_dialog_content (dialog, settings);
1011 priv->settings_ready = settings;
1012 priv->settings_ready_id =
1013 g_signal_connect (settings, "notify::ready",
1014 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1020 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1021 GtkCellEditable *editable,
1023 EmpathyAccountsDialog *dialog)
1025 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1027 if (priv->connecting_id)
1028 g_source_remove (priv->connecting_id);
1030 DEBUG ("Editing account name started; stopping flashing");
1033 static const gchar *
1034 get_status_icon_for_account (EmpathyAccountsDialog *self,
1037 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1038 TpConnectionStatus status;
1039 TpConnectionStatusReason reason;
1040 TpConnectionPresenceType presence;
1042 if (account == NULL)
1043 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1045 if (!tp_account_is_enabled (account))
1046 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1048 status = tp_account_get_connection_status (account, &reason);
1050 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1052 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1053 /* An error occured */
1054 return GTK_STOCK_DIALOG_ERROR;
1056 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1058 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1060 /* Account is connecting. Display a blinking account alternating between
1061 * the offline icon and the requested presence. */
1062 if (priv->connecting_show)
1063 presence = tp_account_get_requested_presence (account, NULL, NULL);
1065 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1069 /* status == TP_CONNECTION_STATUS_CONNECTED */
1070 presence = tp_account_get_current_presence (account, NULL, NULL);
1072 /* If presence is Unset (CM doesn't implement SimplePresence),
1073 * display the 'available' icon.
1074 * We also check Offline because of this MC5 bug: fd.o #26060 */
1075 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1076 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1077 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1080 return empathy_icon_name_for_presence (presence);
1084 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1085 GtkCellRenderer *cell,
1086 GtkTreeModel *model,
1088 EmpathyAccountsDialog *dialog)
1092 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1095 "icon-name", get_status_icon_for_account (dialog, account),
1098 if (account != NULL)
1099 g_object_unref (account);
1103 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1104 GtkCellRenderer *cell,
1105 GtkTreeModel *model,
1107 EmpathyAccountsDialog *dialog)
1109 EmpathyAccountSettings *settings;
1112 TpConnectionStatus status;
1114 gtk_tree_model_get (model, iter,
1115 COL_STATUS, &status,
1116 COL_ACCOUNT_SETTINGS, &settings,
1119 icon_name = empathy_account_settings_get_icon_name (settings);
1120 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1127 g_object_unref (settings);
1130 g_object_unref (pixbuf);
1134 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1141 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1143 if (account == NULL)
1146 if (tp_account_get_connection_status (account, NULL) ==
1147 TP_CONNECTION_STATUS_CONNECTING)
1149 /* Only update the row where we have a connecting account as that's the
1150 * ones having a blinking icon. */
1151 gtk_tree_model_row_changed (model, path, iter);
1154 g_object_unref (account);
1159 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1162 GtkTreeModel *model;
1163 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1165 priv->connecting_show = !priv->connecting_show;
1167 view = GTK_TREE_VIEW (priv->treeview);
1168 model = gtk_tree_view_get_model (view);
1170 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1176 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1179 EmpathyAccountsDialog *dialog)
1181 EmpathyAccountSettings *settings;
1182 GtkTreeModel *model;
1183 GtkTreePath *treepath;
1185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1186 gboolean connecting;
1188 empathy_account_manager_get_accounts_connected (&connecting);
1192 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1193 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1197 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1198 treepath = gtk_tree_path_new_from_string (path);
1199 gtk_tree_model_get_iter (model, &iter, treepath);
1200 gtk_tree_model_get (model, &iter,
1201 COL_ACCOUNT_SETTINGS, &settings,
1203 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1206 gtk_tree_path_free (treepath);
1208 empathy_account_settings_set_display_name_async (settings, new_text,
1210 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1211 g_object_unref (settings);
1215 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1220 GtkTreeModel *model;
1222 GtkTreeSelection *selection;
1223 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1224 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1226 if (response_id == GTK_RESPONSE_YES)
1228 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1230 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1233 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1235 if (account != NULL)
1237 tp_account_remove_async (account, NULL, NULL);
1238 g_object_unref (account);
1242 /* No need to call accounts_dialog_model_selection_changed while
1243 * removing as we are going to call accounts_dialog_model_select_first
1244 * right after which will update the selection. */
1245 g_signal_handlers_block_by_func (selection,
1246 accounts_dialog_model_selection_changed, account_dialog);
1248 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1250 g_signal_handlers_unblock_by_func (selection,
1251 accounts_dialog_model_selection_changed, account_dialog);
1253 accounts_dialog_model_select_first (account_dialog);
1256 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1260 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1263 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1265 GtkTreeModel *model;
1266 gchar *question_dialog_primary_text;
1268 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1270 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1272 if (account == NULL || !tp_account_is_valid (account))
1274 if (account != NULL)
1275 g_object_unref (account);
1276 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1277 accounts_dialog_model_select_first (dialog);
1281 question_dialog_primary_text = g_strdup_printf (
1282 _("Do you want to remove %s from your computer?"),
1283 tp_account_get_display_name (account));
1285 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1286 _("This will not remove your account on the server."),
1287 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1289 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1290 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1292 g_free (question_dialog_primary_text);
1293 g_object_unref (account);
1297 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1298 EmpathyAccountsDialog *dialog)
1300 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1302 GtkTreeSelection *selection;
1305 view = GTK_TREE_VIEW (priv->treeview);
1306 selection = gtk_tree_view_get_selection (view);
1307 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1310 accounts_dialog_remove_account_iter (dialog, &iter);
1315 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1316 const gchar *path_string,
1317 EmpathyAccountsDialog *dialog)
1319 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1320 GtkTreeModel *model;
1323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1324 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1327 accounts_dialog_remove_account_iter (dialog, &iter);
1329 #endif /* HAVE_MEEGO */
1332 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1335 GtkTreeViewColumn *column;
1336 GtkCellRenderer *cell;
1337 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1339 view = GTK_TREE_VIEW (priv->treeview);
1340 gtk_tree_view_set_headers_visible (view, FALSE);
1342 /* Account column */
1343 column = gtk_tree_view_column_new ();
1344 gtk_tree_view_column_set_expand (column, TRUE);
1345 gtk_tree_view_append_column (view, column);
1347 /* Status icon renderer */
1348 cell = gtk_cell_renderer_pixbuf_new ();
1349 gtk_tree_view_column_pack_start (column, cell, FALSE);
1350 gtk_tree_view_column_set_cell_data_func (column, cell,
1351 (GtkTreeCellDataFunc)
1352 accounts_dialog_model_status_pixbuf_data_func,
1356 /* Protocol icon renderer */
1357 cell = gtk_cell_renderer_pixbuf_new ();
1358 gtk_tree_view_column_pack_start (column, cell, FALSE);
1359 gtk_tree_view_column_set_cell_data_func (column, cell,
1360 (GtkTreeCellDataFunc)
1361 accounts_dialog_model_protocol_pixbuf_data_func,
1366 cell = gtk_cell_renderer_text_new ();
1368 "ellipsize", PANGO_ELLIPSIZE_END,
1372 gtk_tree_view_column_pack_start (column, cell, TRUE);
1373 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1374 g_signal_connect (cell, "edited",
1375 G_CALLBACK (accounts_dialog_name_edited_cb),
1377 g_signal_connect (cell, "editing-started",
1378 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1380 g_object_set (cell, "ypad", 4, NULL);
1384 cell = empathy_cell_renderer_activatable_new ();
1385 gtk_tree_view_column_pack_start (column, cell, FALSE);
1387 "icon-name", GTK_STOCK_DELETE,
1388 "show-on-select", TRUE,
1391 g_signal_connect (cell, "path-activated",
1392 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1394 #endif /* HAVE_MEEGO */
1397 static EmpathyAccountSettings *
1398 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1401 GtkTreeModel *model;
1402 GtkTreeSelection *selection;
1404 EmpathyAccountSettings *settings;
1405 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1407 view = GTK_TREE_VIEW (priv->treeview);
1408 selection = gtk_tree_view_get_selection (view);
1410 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1413 gtk_tree_model_get (model, &iter,
1414 COL_ACCOUNT_SETTINGS, &settings, -1);
1420 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1421 EmpathyAccountsDialog *dialog)
1423 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1424 EmpathyAccountSettings *settings;
1425 GtkTreeModel *model;
1427 gboolean is_selection;
1428 gboolean creating = FALSE;
1430 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1432 settings = accounts_dialog_model_get_selected_settings (dialog);
1433 accounts_dialog_update_settings (dialog, settings);
1435 if (settings != NULL)
1436 g_object_unref (settings);
1438 if (priv->setting_widget_object != NULL)
1440 g_object_get (priv->setting_widget_object,
1441 "creating-account", &creating, NULL);
1444 /* Update remove button sensitivity */
1445 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1450 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1452 gpointer *user_data)
1454 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1455 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1457 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1459 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1461 /* The user wants to lose unsaved changes to the currently selected
1462 * account and select another account. We discard the changes and
1463 * select the other account. */
1465 GtkTreeSelection *selection;
1467 priv->force_change_row = TRUE;
1468 empathy_account_widget_discard_pending_changes (
1469 priv->setting_widget_object);
1471 path = gtk_tree_row_reference_get_path (priv->destination_row);
1472 selection = gtk_tree_view_get_selection (
1473 GTK_TREE_VIEW (priv->treeview));
1477 /* This will trigger a call to
1478 * accounts_dialog_account_selection_change() */
1479 gtk_tree_selection_select_path (selection, path);
1480 gtk_tree_path_free (path);
1483 gtk_tree_row_reference_free (priv->destination_row);
1487 priv->force_change_row = FALSE;
1492 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1493 GtkTreeModel *model,
1495 gboolean path_currently_selected,
1498 TpAccount *account = NULL;
1499 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1500 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1503 if (priv->force_change_row)
1505 /* We came back here because the user wants to discard changes to his
1506 * modified account. The changes have already been discarded so we
1507 * just change the selected row. */
1508 priv->force_change_row = FALSE;
1512 if (accounts_dialog_has_pending_change (dialog, &account))
1514 /* The currently selected account has some unsaved changes. We ask
1515 * the user if he really wants to lose his changes and select another
1517 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1518 priv->destination_row = gtk_tree_row_reference_new (model, path);
1520 accounts_dialog_show_question_dialog (dialog,
1521 question_dialog_primary_text,
1522 _("You are about to select another account, which will discard\n"
1523 "your changes. Are you sure you want to proceed?"),
1524 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1526 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1527 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1529 g_free (question_dialog_primary_text);
1537 if (account != NULL)
1538 g_object_unref (account);
1544 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1546 GtkListStore *store;
1547 GtkTreeSelection *selection;
1548 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1550 store = gtk_list_store_new (COL_COUNT,
1551 G_TYPE_STRING, /* name */
1552 G_TYPE_UINT, /* status */
1553 TP_TYPE_ACCOUNT, /* account */
1554 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1556 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1557 GTK_TREE_MODEL (store));
1559 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1560 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1561 gtk_tree_selection_set_select_function (selection,
1562 accounts_dialog_account_selection_change, dialog, NULL);
1564 g_signal_connect (selection, "changed",
1565 G_CALLBACK (accounts_dialog_model_selection_changed),
1568 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1569 COL_NAME, GTK_SORT_ASCENDING);
1571 accounts_dialog_model_add_columns (dialog);
1573 g_object_unref (store);
1577 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1582 GtkTreeModel *model;
1584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1586 /* Update the status in the model */
1587 view = GTK_TREE_VIEW (priv->treeview);
1588 model = gtk_tree_view_get_model (view);
1590 for (ok = gtk_tree_model_get_iter_first (model, iter);
1592 ok = gtk_tree_model_iter_next (model, iter))
1594 TpAccount *this_account;
1597 gtk_tree_model_get (model, iter,
1598 COL_ACCOUNT, &this_account,
1601 equal = (this_account == account);
1602 g_object_unref (this_account);
1612 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1615 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1616 GtkTreeSelection *selection;
1618 GtkTreeModel *model;
1620 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1622 gtk_tree_selection_select_iter (selection, iter);
1624 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1625 path = gtk_tree_model_get_path (model, iter);
1627 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1630 gtk_tree_path_free (path);
1634 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1639 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1640 select_and_scroll_to_iter (dialog, &iter);
1644 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1649 enabled = tp_account_is_enabled (account);
1650 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1654 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1655 GdkEventButton *event,
1656 EmpathyAccountsDialog *dialog)
1658 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1659 TpAccount *account = NULL;
1660 GtkTreeModel *model = NULL;
1661 GtkTreePath *path = NULL;
1664 GtkWidget *item_enable, *item_disable;
1665 GtkWidget *image_enable, *image_disable;
1667 /* ignore multiple clicks */
1668 if (event->type != GDK_BUTTON_PRESS)
1671 if (event->button != 3)
1674 /* Selection is not yet set, so we have to get account from event position */
1675 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1676 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1677 event->x, event->y, &path, NULL, NULL, NULL))
1680 if (!gtk_tree_model_get_iter (model, &iter, path))
1683 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1685 /* Create the menu */
1686 menu = empathy_context_menu_new (GTK_WIDGET (view));
1688 /* Get images for menu items */
1689 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1690 tp_account_manager_get_most_available_presence (
1691 priv->account_manager, NULL, NULL)),
1692 GTK_ICON_SIZE_MENU);
1693 image_disable = gtk_image_new_from_icon_name (
1694 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1695 GTK_ICON_SIZE_MENU);
1697 /* Menu items: to enabled/disable the account */
1698 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1699 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1700 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1702 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1705 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1706 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1708 if (tp_account_is_enabled (account))
1710 tp_g_signal_connect_object (item_disable, "activate",
1711 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1712 gtk_widget_set_sensitive (item_enable, FALSE);
1716 tp_g_signal_connect_object (item_enable, "activate",
1717 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1718 gtk_widget_set_sensitive (item_disable, FALSE);
1721 gtk_widget_show (item_enable);
1722 gtk_widget_show (item_disable);
1724 /* FIXME: Add here presence items, to be able to set per-account presence */
1727 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1728 event->button, event->time);
1731 tp_clear_object (&account);
1732 gtk_tree_path_free (path);
1738 accounts_dialog_connection_changed_cb (TpAccount *account,
1742 gchar *dbus_error_name,
1743 GHashTable *details,
1744 EmpathyAccountsDialog *dialog)
1746 GtkTreeModel *model;
1749 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1751 /* Update the status-infobar in the details view */
1752 accounts_dialog_update_status_infobar (dialog, account);
1754 /* Update the status in the model */
1755 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1757 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1761 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1762 COL_STATUS, current,
1765 path = gtk_tree_model_get_path (model, &iter);
1766 gtk_tree_model_row_changed (model, path, &iter);
1767 gtk_tree_path_free (path);
1770 empathy_account_manager_get_accounts_connected (&found);
1772 if (!found && priv->connecting_id)
1774 g_source_remove (priv->connecting_id);
1775 priv->connecting_id = 0;
1778 if (found && !priv->connecting_id)
1779 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1780 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1785 update_account_in_treeview (EmpathyAccountsDialog *self,
1788 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1790 GtkTreeModel *model;
1792 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1793 if (accounts_dialog_get_account_iter (self, account, &iter))
1797 path = gtk_tree_model_get_path (model, &iter);
1798 gtk_tree_model_row_changed (model, path, &iter);
1799 gtk_tree_path_free (path);
1804 accounts_dialog_presence_changed_cb (TpAccount *account,
1807 gchar *status_message,
1808 EmpathyAccountsDialog *dialog)
1810 /* Update the status-infobar in the details view */
1811 accounts_dialog_update_status_infobar (dialog, account);
1813 update_account_in_treeview (dialog, account);
1817 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1821 const gchar *display_name;
1823 GtkTreeModel *model;
1824 EmpathyAccountSettings *settings;
1825 TpAccount *selected_account;
1826 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1827 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1829 display_name = tp_account_get_display_name (account);
1830 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1831 settings = accounts_dialog_model_get_selected_settings (dialog);
1832 if (settings == NULL)
1835 selected_account = empathy_account_settings_get_account (settings);
1837 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1839 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1840 COL_NAME, display_name,
1844 if (selected_account == account)
1845 accounts_dialog_update_name_label (dialog, display_name);
1847 g_object_unref (settings);
1851 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1854 EmpathyAccountSettings *settings;
1855 GtkTreeModel *model;
1857 TpConnectionStatus status;
1859 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1860 gboolean selected = FALSE;
1861 GtkTreeSelection *selection;
1863 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1864 status = tp_account_get_connection_status (account, NULL);
1865 name = tp_account_get_display_name (account);
1867 settings = empathy_account_settings_new_for_account (account);
1869 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1871 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1873 /* Select the account if it's the first added */
1874 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1877 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1881 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1884 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1887 COL_ACCOUNT, account,
1888 COL_ACCOUNT_SETTINGS, settings,
1893 /* We just modified the selected account. Its display name may have been
1894 * changed and so it's place in the treeview. Scroll to it so it stays
1896 select_and_scroll_to_iter (dialog, &iter);
1899 accounts_dialog_connection_changed_cb (account,
1902 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1907 tp_g_signal_connect_object (account, "notify::display-name",
1908 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1911 tp_g_signal_connect_object (account, "status-changed",
1912 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1913 tp_g_signal_connect_object (account, "presence-changed",
1914 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1916 g_object_unref (settings);
1920 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1923 EmpathyAccountsDialog *dialog)
1925 accounts_dialog_add_account (dialog, account);
1929 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1932 EmpathyAccountsDialog *dialog)
1934 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1936 if (priv->setting_widget_object != NULL &&
1937 accounts_dialog_has_valid_accounts (dialog))
1939 empathy_account_widget_set_other_accounts_exist (
1940 priv->setting_widget_object, TRUE);
1945 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1947 EmpathyAccountsDialog *dialog)
1949 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1951 if (priv->setting_widget_object != NULL &&
1952 !accounts_dialog_has_valid_accounts (dialog))
1954 empathy_account_widget_set_other_accounts_exist (
1955 priv->setting_widget_object, FALSE);
1960 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1962 EmpathyAccountsDialog *dialog)
1965 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1967 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1969 gtk_list_store_remove (GTK_LIST_STORE (
1970 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1975 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1979 /* Update the status-infobar in the details view */
1980 accounts_dialog_update_status_infobar (dialog, account);
1982 DEBUG ("Account %s is now %s",
1983 tp_account_get_display_name (account),
1984 enabled ? "enabled" : "disabled");
1988 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1990 EmpathyAccountsDialog *dialog)
1992 enable_or_disable_account (dialog, account, FALSE);
1993 update_account_in_treeview (dialog, account);
1997 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1999 EmpathyAccountsDialog *dialog)
2001 enable_or_disable_account (dialog, account, TRUE);
2005 display_import_dialog (EmpathyAccountsDialog *dialog)
2007 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2008 GtkWidget *import_dialog;
2010 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2012 gtk_widget_show (import_dialog);
2014 return import_dialog;
2018 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2019 EmpathyAccountsDialog *dialog)
2021 display_import_dialog (dialog);
2025 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2029 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2031 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2033 if (response_id == GTK_RESPONSE_YES)
2034 gtk_widget_destroy (account_dialog);
2038 accounts_dialog_delete_event_cb (GtkWidget *widget,
2040 EmpathyAccountsDialog *dialog)
2042 /* we maunally handle responses to delete events */
2047 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2052 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2053 select_and_scroll_to_iter (dialog, &iter);
2057 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2059 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2061 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2064 if (!empathy_import_accounts_to_import ())
2067 display_import_dialog (self);
2071 finished_loading (EmpathyAccountsDialog *self)
2073 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2074 GtkTreeSelection *selection;
2075 gboolean has_selected;
2077 priv->loading = FALSE;
2079 gtk_widget_set_sensitive (priv->button_add, TRUE);
2080 gtk_widget_set_sensitive (priv->button_import, TRUE);
2081 gtk_widget_set_sensitive (priv->treeview, TRUE);
2083 /* Sensitive the remove button if there is an account selected */
2084 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2085 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2086 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2088 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2089 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2090 NOTEBOOK_PAGE_ACCOUNT);
2092 maybe_show_import_dialog (self);
2096 accounts_dialog_cms_prepare_cb (GObject *source,
2097 GAsyncResult *result,
2100 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2101 EmpathyAccountsDialog *dialog = user_data;
2102 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2104 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2107 /* No need to update the settings if we are already preparing one */
2108 if (priv->settings_ready == NULL)
2109 accounts_dialog_update_settings (dialog, NULL);
2111 if (priv->initial_selection != NULL)
2113 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2114 g_object_unref (priv->initial_selection);
2115 priv->initial_selection = NULL;
2119 finished_loading (dialog);
2123 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2125 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2126 GList *accounts, *l;
2128 g_signal_connect (priv->account_manager, "account-validity-changed",
2129 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2131 g_signal_connect (priv->account_manager, "account-removed",
2132 G_CALLBACK (accounts_dialog_account_removed_cb),
2134 g_signal_connect (priv->account_manager, "account-enabled",
2135 G_CALLBACK (accounts_dialog_account_enabled_cb),
2137 g_signal_connect (priv->account_manager, "account-disabled",
2138 G_CALLBACK (accounts_dialog_account_disabled_cb),
2141 /* Add existing accounts */
2142 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2143 for (l = accounts; l; l = l->next)
2145 accounts_dialog_add_account (dialog, l->data);
2147 g_list_free (accounts);
2149 priv->cms = empathy_connection_managers_dup_singleton ();
2151 empathy_connection_managers_prepare_async (priv->cms,
2152 accounts_dialog_cms_prepare_cb, dialog);
2154 accounts_dialog_model_select_first (dialog);
2158 accounts_dialog_manager_ready_cb (GObject *source_object,
2159 GAsyncResult *result,
2162 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2163 GError *error = NULL;
2165 if (!tp_proxy_prepare_finish (manager, result, &error))
2167 DEBUG ("Failed to prepare account manager: %s", error->message);
2168 g_error_free (error);
2172 accounts_dialog_accounts_setup (user_data);
2176 dialog_response_cb (GtkWidget *widget,
2180 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2182 if (response_id == GTK_RESPONSE_HELP)
2184 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2186 else if (response_id == GTK_RESPONSE_CLOSE ||
2187 response_id == GTK_RESPONSE_DELETE_EVENT)
2189 TpAccount *account = NULL;
2191 if (accounts_dialog_has_pending_change (dialog, &account))
2193 gchar *question_dialog_primary_text = get_dialog_primary_text (
2196 accounts_dialog_show_question_dialog (dialog,
2197 question_dialog_primary_text,
2198 _("You are about to close the window, which will discard\n"
2199 "your changes. Are you sure you want to proceed?"),
2200 G_CALLBACK (accounts_dialog_close_response_cb),
2202 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2203 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2205 g_free (question_dialog_primary_text);
2209 gtk_widget_destroy (widget);
2212 if (account != NULL)
2213 g_object_unref (account);
2218 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2220 GtkWidget *top_hbox;
2223 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2224 GtkWidget *content_area, *action_area;
2225 GtkWidget *grid, *hbox;
2227 GtkWidget *sw, *toolbar;
2228 GtkStyleContext *context;
2230 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2232 gui = empathy_builder_get_file (filename,
2233 "accounts_dialog_hbox", &top_hbox,
2234 "vbox_details", &priv->vbox_details,
2235 "alignment_settings", &priv->alignment_settings,
2236 "alignment_infobar", &priv->alignment_infobar,
2237 "treeview", &priv->treeview,
2238 "button_add", &priv->button_add,
2239 "button_remove", &priv->button_remove,
2240 "button_import", &priv->button_import,
2241 "notebook_account", &priv->notebook_account,
2242 "alignment_loading", &alig,
2244 "add_remove_toolbar", &toolbar,
2248 empathy_builder_connect (gui, dialog,
2249 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2250 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2251 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2252 "treeview", "button-press-event",
2253 accounts_dialog_treeview_button_press_event_cb,
2256 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2258 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2260 g_object_unref (gui);
2262 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2265 gtk_widget_hide (action_area);
2266 gtk_widget_hide (priv->button_remove);
2267 #endif /* HAVE_MEEGO */
2269 /* Display loading page */
2270 priv->loading = TRUE;
2272 priv->spinner = gtk_spinner_new ();
2274 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2275 gtk_widget_show (priv->spinner);
2277 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2279 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2280 NOTEBOOK_PAGE_LOADING);
2282 /* Remove button is insensitive until we have a selected account */
2283 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2285 /* Add and Import buttons and treeview are insensitive while the dialog
2287 gtk_widget_set_sensitive (priv->button_add, FALSE);
2288 gtk_widget_set_sensitive (priv->button_import, FALSE);
2289 gtk_widget_set_sensitive (priv->treeview, FALSE);
2291 if (priv->parent_window)
2292 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2293 priv->parent_window);
2295 priv->infobar = gtk_info_bar_new ();
2296 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2298 gtk_widget_show (priv->infobar);
2300 grid = gtk_grid_new ();
2302 GTK_CONTAINER (gtk_info_bar_get_content_area (
2303 GTK_INFO_BAR (priv->infobar))),
2306 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2307 GTK_ICON_SIZE_DIALOG);
2308 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2309 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2312 priv->label_name = gtk_label_new (NULL);
2313 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2316 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2317 gtk_widget_set_hexpand (hbox, TRUE);
2318 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2319 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2321 /* set up spinner */
2322 priv->throbber = gtk_spinner_new ();
2324 priv->image_status = gtk_image_new_from_icon_name (
2325 empathy_icon_name_for_presence (
2326 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2328 priv->label_status = gtk_label_new (NULL);
2329 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2331 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2332 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2333 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2335 /* enabled switch */
2336 priv->enabled_switch = gtk_switch_new ();
2337 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2338 g_signal_connect (priv->enabled_switch, "notify::active",
2339 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2340 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2342 gtk_widget_show_all (grid);
2344 /* Tweak the dialog */
2345 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2346 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2348 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2350 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2352 /* join the add/remove toolbar to the treeview */
2353 context = gtk_widget_get_style_context (sw);
2354 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2356 context = gtk_widget_get_style_context (toolbar);
2357 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2359 /* add dialog buttons */
2360 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2362 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2363 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2364 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2367 g_signal_connect (dialog, "response",
2368 G_CALLBACK (dialog_response_cb), dialog);
2370 g_signal_connect (dialog, "delete-event",
2371 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2375 do_dispose (GObject *obj)
2377 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2378 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2380 if (priv->connecting_id != 0)
2382 g_source_remove (priv->connecting_id);
2383 priv->connecting_id = 0;
2386 if (priv->account_manager != NULL)
2388 g_object_unref (priv->account_manager);
2389 priv->account_manager = NULL;
2392 if (priv->cms != NULL)
2394 g_object_unref (priv->cms);
2398 if (priv->connectivity)
2400 g_object_unref (priv->connectivity);
2401 priv->connectivity = NULL;
2404 if (priv->initial_selection != NULL)
2406 g_object_unref (priv->initial_selection);
2407 priv->initial_selection = NULL;
2410 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2414 do_get_property (GObject *object,
2419 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2421 switch (property_id)
2424 g_value_set_object (value, priv->parent_window);
2427 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2432 do_set_property (GObject *object,
2434 const GValue *value,
2437 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2439 switch (property_id)
2442 priv->parent_window = g_value_get_object (value);
2445 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2450 do_constructed (GObject *object)
2452 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2453 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2454 GtkTreeModel *model;
2456 accounts_dialog_build_ui (dialog);
2457 accounts_dialog_model_setup (dialog);
2459 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2460 g_signal_connect (model, "row-inserted",
2461 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2462 g_signal_connect (model, "row-deleted",
2463 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2465 /* Set up signalling */
2466 priv->account_manager = tp_account_manager_dup ();
2468 tp_proxy_prepare_async (priv->account_manager, NULL,
2469 accounts_dialog_manager_ready_cb, dialog);
2471 priv->connectivity = empathy_connectivity_dup_singleton ();
2475 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2477 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2478 GParamSpec *param_spec;
2480 oclass->dispose = do_dispose;
2481 oclass->constructed = do_constructed;
2482 oclass->set_property = do_set_property;
2483 oclass->get_property = do_get_property;
2485 param_spec = g_param_spec_object ("parent",
2486 "parent", "The parent window",
2488 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2489 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2491 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2495 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2497 EmpathyAccountsDialogPriv *priv;
2499 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2500 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2501 EmpathyAccountsDialogPriv);
2502 dialog->priv = priv;
2505 /* public methods */
2508 empathy_accounts_dialog_show (GtkWindow *parent,
2509 TpAccount *selected_account)
2511 EmpathyAccountsDialog *dialog;
2512 EmpathyAccountsDialogPriv *priv;
2514 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2515 "parent", parent, NULL);
2517 priv = GET_PRIV (dialog);
2519 if (selected_account)
2521 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2522 accounts_dialog_set_selected_account (dialog, selected_account);
2524 /* save the selection to set it later when the cms
2527 priv->initial_selection = g_object_ref (selected_account);
2530 gtk_window_present (GTK_WINDOW (dialog));
2532 return GTK_WIDGET (dialog);
2536 empathy_accounts_dialog_show_application (GdkScreen *screen,
2537 TpAccount *selected_account,
2543 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2545 args = g_string_new (NULL);
2547 if (selected_account != NULL)
2548 g_string_append_printf (args, " --select-account=%s",
2549 tp_account_get_path_suffix (selected_account));
2552 g_string_append_printf (args, " --if-needed");
2555 g_string_append_printf (args, " --hidden");
2557 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2559 selected_account == NULL ? "<none selected>" :
2560 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2562 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2564 g_string_free (args, TRUE);
2568 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2570 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2571 gboolean result = FALSE;
2573 if (priv->setting_widget_object == NULL)
2576 g_object_get (priv->setting_widget_object,
2577 "creating-account", &result, NULL);