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 *hbox_protocol;
104 GtkWidget *image_type;
105 GtkWidget *label_name;
106 GtkWidget *label_type;
107 GtkWidget *dialog_content;
109 GtkWidget *notebook_account;
113 /* We have to keep a weak reference on the actual EmpathyAccountWidget, not
114 * just its GtkWidget. It is the only reliable source we can query to know if
115 * there are any unsaved changes to the currently selected account. We can't
116 * look at the account settings because it does not contain everything that
117 * can be changed using the EmpathyAccountWidget. For instance, it does not
118 * contain the state of the "Enabled" checkbox.
120 * Even if we create it ourself, we just get a weak ref and not a strong one
121 * as EmpathyAccountWidget unrefs itself when the GtkWidget is destroyed.
122 * That's kinda ugly; cf bgo #640417.
125 EmpathyAccountWidget *setting_widget_object;
127 gboolean connecting_show;
130 gulong settings_ready_id;
131 EmpathyAccountSettings *settings_ready;
133 TpAccountManager *account_manager;
134 EmpathyConnectionManagers *cms;
135 EmpathyConnectivity *connectivity;
137 GtkWindow *parent_window;
138 TpAccount *initial_selection;
140 /* Those are needed when changing the selected row. When a user selects
141 * another account and there are unsaved changes on the currently selected
142 * one, a confirmation message box is presented to him. Since his answer
143 * is retrieved asynchronously, we keep some information as member of the
144 * EmpathyAccountsDialog object. */
145 gboolean force_change_row;
146 GtkTreeRowReference *destination_row;
147 } EmpathyAccountsDialogPriv;
153 COL_ACCOUNT_SETTINGS,
161 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
162 EmpathyAccountsDialog *dialog);
164 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
166 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
167 EmpathyAccountSettings *settings);
169 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
172 static void accounts_dialog_connection_changed_cb (TpAccount *account,
176 gchar *dbus_error_name,
178 EmpathyAccountsDialog *dialog);
180 static void accounts_dialog_presence_changed_cb (TpAccount *account,
183 gchar *status_message,
184 EmpathyAccountsDialog *dialog);
186 static void accounts_dialog_model_selection_changed (
187 GtkTreeSelection *selection,
188 EmpathyAccountsDialog *dialog);
190 static gboolean accounts_dialog_has_pending_change (
191 EmpathyAccountsDialog *dialog, TpAccount **account);
194 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
195 const gchar *display_name)
198 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
200 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
201 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
207 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
208 const gchar *message)
210 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
211 gchar *message_markup;
213 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
214 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
216 gtk_widget_set_tooltip_text (priv->label_status, message);
218 g_free (message_markup);
222 accounts_dialog_enable_account_cb (GObject *account,
223 GAsyncResult *result,
226 GError *error = NULL;
228 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
232 DEBUG ("Could not enable the account: %s", error->message);
233 g_error_free (error);
237 TpAccountManager *am = tp_account_manager_dup ();
239 empathy_connect_new_account (TP_ACCOUNT (account), am);
245 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
247 EmpathyAccountsDialog *dialog)
249 EmpathyAccountSettings *settings;
252 settings = accounts_dialog_model_get_selected_settings (dialog);
253 if (settings == NULL)
256 account = empathy_account_settings_get_account (settings);
260 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
261 accounts_dialog_enable_account_cb, NULL);
265 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
268 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
269 gchar *status_message = NULL;
275 GtkTreeSelection *selection;
277 TpAccount *selected_account;
278 gboolean account_enabled;
279 gboolean creating_account;
280 TpStorageRestrictionFlags storage_restrictions = 0;
282 view = GTK_TREE_VIEW (priv->treeview);
283 selection = gtk_tree_view_get_selection (view);
285 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
288 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
289 if (selected_account != NULL)
290 g_object_unref (selected_account);
292 /* do not update the infobar when the account is not selected */
293 if (account != selected_account)
298 status = tp_account_get_connection_status (account, &reason);
299 presence = tp_account_get_current_presence (account, NULL, &status_message);
300 account_enabled = tp_account_is_enabled (account);
301 creating_account = FALSE;
303 if (status == TP_CONNECTION_STATUS_CONNECTED &&
304 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
305 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
306 /* If presence is Unset (CM doesn't implement SimplePresence) but we
307 * are connected, consider ourself as Available.
308 * We also check Offline because of this MC5 bug: fd.o #26060 */
309 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
311 /* set presence to offline if account is disabled
312 * (else no icon is shown in infobar)*/
313 if (!account_enabled)
314 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
316 storage_restrictions = tp_account_get_storage_restrictions (account);
320 status = TP_CONNECTION_STATUS_DISCONNECTED;
321 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
322 account_enabled = FALSE;
323 creating_account = TRUE;
326 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
327 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
329 /* update the enabled switch */
330 g_signal_handlers_block_by_func (priv->enabled_switch,
331 accounts_dialog_enable_switch_active_cb, dialog);
332 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
334 g_signal_handlers_unblock_by_func (priv->enabled_switch,
335 accounts_dialog_enable_switch_active_cb, dialog);
337 /* Display the Enable switch if account supports it */
338 gtk_widget_set_visible (priv->enabled_switch,
339 !(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED));
345 case TP_CONNECTION_STATUS_CONNECTING:
346 accounts_dialog_status_infobar_set_message (dialog,
348 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
351 gtk_spinner_start (GTK_SPINNER (priv->throbber));
352 gtk_widget_show (priv->throbber);
353 gtk_widget_hide (priv->image_status);
355 case TP_CONNECTION_STATUS_CONNECTED:
356 if (g_strcmp0 (status_message, "") == 0)
360 message = g_strdup_printf ("%s",
361 empathy_presence_get_default_message (presence));
363 accounts_dialog_status_infobar_set_message (dialog, message);
370 message = g_strdup_printf ("%s — %s",
371 empathy_presence_get_default_message (presence),
374 accounts_dialog_status_infobar_set_message (dialog, message);
377 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
380 gtk_widget_show (priv->image_status);
381 gtk_widget_hide (priv->throbber);
383 case TP_CONNECTION_STATUS_DISCONNECTED:
384 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
388 message = g_strdup_printf (_("Offline — %s"),
389 empathy_account_get_error_message (account, NULL));
390 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
391 GTK_MESSAGE_WARNING);
393 accounts_dialog_status_infobar_set_message (dialog, message);
400 message = g_strdup_printf (_("Disconnected — %s"),
401 empathy_account_get_error_message (account, NULL));
402 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
405 accounts_dialog_status_infobar_set_message (dialog, message);
409 if (!empathy_connectivity_is_online (priv->connectivity))
410 accounts_dialog_status_infobar_set_message (dialog,
411 _("Offline — No Network Connection"));
413 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
414 gtk_widget_show (priv->image_status);
415 gtk_widget_hide (priv->throbber);
418 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
419 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
420 GTK_MESSAGE_WARNING);
422 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
423 gtk_widget_hide (priv->image_status);
424 gtk_widget_hide (priv->throbber);
429 accounts_dialog_status_infobar_set_message (dialog,
430 _("Offline — Account Disabled"));
432 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
433 GTK_MESSAGE_WARNING);
434 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
435 gtk_widget_show (priv->image_status);
436 gtk_widget_hide (priv->throbber);
439 gtk_widget_show (priv->label_status);
441 if (!creating_account)
442 gtk_widget_show (priv->infobar);
444 gtk_widget_hide (priv->infobar);
446 g_free (status_message);
450 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
454 GtkTreeSelection *selection;
456 EmpathyAccountSettings *settings;
458 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
460 view = GTK_TREE_VIEW (priv->treeview);
461 selection = gtk_tree_view_get_selection (view);
463 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
466 gtk_tree_model_get (model, &iter,
467 COL_ACCOUNT_SETTINGS, &settings,
468 COL_ACCOUNT, &account, -1);
470 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
474 /* We were creating an account. We remove the selected row */
475 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
479 /* We were modifying an account. We discard the changes by reloading the
480 * settings and the UI. */
481 accounts_dialog_update_settings (dialog, settings);
482 g_object_unref (account);
485 gtk_widget_set_sensitive (priv->treeview, TRUE);
486 gtk_widget_set_sensitive (priv->button_add, TRUE);
487 gtk_widget_set_sensitive (priv->button_remove, TRUE);
488 gtk_widget_set_sensitive (priv->button_import, TRUE);
490 if (settings != NULL)
491 g_object_unref (settings);
495 empathy_account_dialog_widget_cancelled_cb (
496 EmpathyAccountWidget *widget_object,
497 EmpathyAccountsDialog *dialog)
499 empathy_account_dialog_cancel (dialog);
503 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
505 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
510 g_object_get (priv->setting_widget_object,
511 "creating-account", &creating, NULL);
516 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
518 if (gtk_tree_model_get_iter_first (model, &iter))
519 return gtk_tree_model_iter_next (model, &iter);
525 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
527 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
528 EmpathyAccountSettings *settings;
529 GtkWidget *subdialog, *content, *content_area, *align;
531 settings = accounts_dialog_model_get_selected_settings (dialog);
533 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
535 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
538 priv->setting_widget_object =
539 empathy_account_widget_new_for_protocol (settings, FALSE);
541 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
542 (gpointer *) &priv->setting_widget_object);
544 if (accounts_dialog_has_valid_accounts (dialog))
545 empathy_account_widget_set_other_accounts_exist (
546 priv->setting_widget_object, TRUE);
548 content = empathy_account_widget_get_widget (priv->setting_widget_object);
550 g_signal_connect (priv->setting_widget_object, "cancelled",
551 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
553 g_signal_connect_swapped (priv->setting_widget_object, "close",
554 G_CALLBACK (gtk_widget_destroy), subdialog);
556 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
558 align = gtk_alignment_new (0.5, 0.5, 1, 1);
559 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
561 gtk_container_add (GTK_CONTAINER (align), content);
562 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
564 gtk_widget_show (content);
565 gtk_widget_show (align);
566 gtk_widget_show (subdialog);
570 start_external_app (GAppInfo *app_info)
572 GError *error = NULL;
573 GdkAppLaunchContext *context = NULL;
576 display = gdk_display_get_default ();
577 context = gdk_display_get_app_launch_context (display);
579 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
582 g_critical ("Failed to bisho: %s", error->message);
583 g_clear_error (&error);
586 tp_clear_object (&context);
590 use_external_storage_provider (EmpathyAccountsDialog *self,
593 const gchar *provider;
595 provider = tp_account_get_storage_provider (account);
596 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
598 GDesktopAppInfo *desktop_info;
601 GError *error = NULL;
603 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
604 if (desktop_info == NULL)
606 g_critical ("Could not locate 'gnome-control-center.desktop'");
610 /* glib doesn't have API to start a desktop file with args... (#637875) */
611 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
612 (GAppInfo *) desktop_info));
614 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
616 if (app_info == NULL)
618 DEBUG ("Failed to create app info: %s", error->message);
619 g_error_free (error);
623 start_external_app (app_info);
624 g_object_unref (app_info);
627 g_object_unref (desktop_info);
631 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
633 GDesktopAppInfo *desktop_info;
635 desktop_info = g_desktop_app_info_new (
636 "gnome-online-accounts-panel.desktop");
637 if (desktop_info == NULL)
639 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
643 start_external_app (G_APP_INFO (desktop_info));
644 g_object_unref (desktop_info);
651 DEBUG ("Don't know how to handle %s", provider);
657 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
660 EmpathyAccountSettings *settings;
662 TpStorageRestrictionFlags storage_restrictions;
664 settings = accounts_dialog_model_get_selected_settings (dialog);
666 account = empathy_account_settings_get_account (settings);
667 g_return_if_fail (account != NULL);
669 storage_restrictions = tp_account_get_storage_restrictions (account);
671 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
672 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
674 DEBUG ("Account is provided by an external storage provider");
676 use_external_storage_provider (dialog, account);
680 account_dialog_create_edit_params_dialog (dialog);
685 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
688 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
689 GtkWidget *infobar, *label;
691 infobar = gtk_info_bar_new ();
695 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
696 label = gtk_label_new (_("Failed to retrieve your personal information "
697 "from the server."));
701 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
702 label = gtk_label_new (_("Go online to edit your personal information."));
706 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
708 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
709 gtk_widget_show_all (infobar);
713 account_dialog_got_self_contact (TpConnection *conn,
714 EmpathyContact *contact,
715 const GError *in_error,
719 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
720 GtkWidget *editor, *alig;
722 if (in_error != NULL)
724 DEBUG ("Failed to get self-contact: %s", in_error->message);
725 account_dialog_show_contact_details_failed (
726 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
730 alig = gtk_alignment_new (0.5, 0, 1, 1);
732 /* create the contact info editor for this account */
733 editor = empathy_contact_widget_new (contact,
734 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
735 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
736 EMPATHY_CONTACT_WIDGET_NO_STATUS |
737 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS);
739 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
740 gtk_container_add (GTK_CONTAINER (alig), editor);
741 gtk_widget_show (alig);
742 gtk_widget_show (editor);
746 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
747 EmpathyAccountSettings *settings)
749 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
750 const gchar *icon_name;
752 TpConnection *conn = NULL;
753 GtkWidget *bbox, *button;
755 account = empathy_account_settings_get_account (settings);
757 // if (priv->setting_widget_object != NULL)
758 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
759 // (gpointer *) &priv->setting_widget_object);
761 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
762 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
763 priv->dialog_content);
764 gtk_widget_show (priv->dialog_content);
766 /* request the self contact */
768 conn = tp_account_get_connection (account);
772 empathy_tp_contact_factory_get_from_handle (conn,
773 tp_connection_get_self_handle (conn),
774 account_dialog_got_self_contact,
775 NULL, NULL, G_OBJECT (dialog));
779 account_dialog_show_contact_details_failed (dialog, FALSE);
782 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
783 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
784 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
785 gtk_widget_show (bbox);
787 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
788 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
789 gtk_widget_show (button);
790 g_signal_connect_swapped (button, "clicked",
791 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
793 icon_name = empathy_account_settings_get_icon_name (settings);
795 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
797 /* show the default icon; keep this in sync with the default
798 * one in empathy-accounts-dialog.ui.
800 icon_name = GTK_STOCK_CUT;
802 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
803 icon_name, GTK_ICON_SIZE_DIALOG);
804 gtk_widget_set_tooltip_text (priv->image_type,
805 empathy_protocol_name_to_display_name
806 (empathy_account_settings_get_protocol (settings)));
807 gtk_widget_show (priv->image_type);
809 accounts_dialog_update_name_label (dialog,
810 empathy_account_settings_get_display_name (settings));
812 accounts_dialog_update_status_infobar (dialog, account);
816 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
818 EmpathyAccountsDialog *dialog)
820 if (empathy_account_settings_is_ready (settings))
821 account_dialog_create_dialog_content (dialog, settings);
825 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
829 GtkTreeSelection *selection;
831 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
834 view = GTK_TREE_VIEW (priv->treeview);
835 model = gtk_tree_view_get_model (view);
837 if (gtk_tree_model_get_iter_first (model, &iter))
839 selection = gtk_tree_view_get_selection (view);
840 gtk_tree_selection_select_iter (selection, &iter);
844 accounts_dialog_update_settings (dialog, NULL);
849 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
854 GtkTreeSelection *selection;
855 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
857 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
859 if (gtk_tree_selection_get_selected (selection, &model, &iter))
860 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
862 return priv->setting_widget_object != NULL
863 && empathy_account_widget_contains_pending_changes (
864 priv->setting_widget_object);
868 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
869 const gchar *primary_text,
870 const gchar *secondary_text,
871 GCallback response_callback,
873 const gchar *first_button_text,
877 GtkWidget *message_dialog;
878 const gchar *button_text;
880 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
881 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
882 GTK_MESSAGE_QUESTION,
886 gtk_message_dialog_format_secondary_text (
887 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
889 va_start (button_args, first_button_text);
890 for (button_text = first_button_text;
892 button_text = va_arg (button_args, const gchar *))
895 response_id = va_arg (button_args, gint);
897 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
900 va_end (button_args);
902 g_signal_connect (message_dialog, "response", response_callback, user_data);
904 gtk_widget_show (message_dialog);
908 get_dialog_primary_text (TpAccount *account)
912 /* Existing account */
913 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
914 tp_account_get_display_name (account));
918 /* Newly created account */
919 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
924 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
925 EmpathyAccountsDialog *self)
930 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
931 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
933 response = gtk_dialog_run (GTK_DIALOG (dialog));
935 if (response == GTK_RESPONSE_OK)
937 EmpathyAccountSettings *settings;
940 settings = empathy_new_account_dialog_get_settings (
941 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
943 /* The newly created account has already been added by
944 * accounts_dialog_account_validity_changed_cb so we just
945 * have to select it. */
946 account = empathy_account_settings_get_account (settings);
947 accounts_dialog_model_set_selected (self, account);
950 gtk_widget_destroy (dialog);
954 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
955 EmpathyAccountSettings *settings)
957 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
959 if (priv->settings_ready != NULL)
961 g_signal_handler_disconnect (priv->settings_ready,
962 priv->settings_ready_id);
963 priv->settings_ready = NULL;
964 priv->settings_ready_id = 0;
971 GtkTreeSelection *selection;
973 view = GTK_TREE_VIEW (priv->treeview);
974 model = gtk_tree_view_get_model (view);
975 selection = gtk_tree_view_get_selection (view);
977 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
979 /* We have configured accounts, select the first one if there
980 * is no other account selected already. */
981 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
982 accounts_dialog_model_select_first (dialog);
986 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
988 /* We have no account configured but we have some
989 * profiles installed. The user obviously wants to add
990 * an account. Click on the Add button for him. */
991 accounts_dialog_button_add_clicked_cb (priv->button_add,
996 /* No account and no profile, warn the user */
997 gtk_widget_hide (priv->vbox_details);
998 gtk_widget_show (priv->frame_no_protocol);
999 gtk_widget_set_sensitive (priv->button_add, FALSE);
1003 /* We have an account selected, destroy old settings and create a new
1004 * one for the account selected */
1005 gtk_widget_hide (priv->frame_no_protocol);
1006 gtk_widget_show (priv->vbox_details);
1007 gtk_widget_hide (priv->hbox_protocol);
1009 if (priv->dialog_content)
1011 gtk_widget_destroy (priv->dialog_content);
1012 priv->dialog_content = NULL;
1015 if (empathy_account_settings_is_ready (settings))
1017 account_dialog_create_dialog_content (dialog, settings);
1021 priv->settings_ready = settings;
1022 priv->settings_ready_id =
1023 g_signal_connect (settings, "notify::ready",
1024 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1030 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1031 GtkCellEditable *editable,
1033 EmpathyAccountsDialog *dialog)
1035 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1037 if (priv->connecting_id)
1038 g_source_remove (priv->connecting_id);
1040 DEBUG ("Editing account name started; stopping flashing");
1043 static const gchar *
1044 get_status_icon_for_account (EmpathyAccountsDialog *self,
1047 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1048 TpConnectionStatus status;
1049 TpConnectionStatusReason reason;
1050 TpConnectionPresenceType presence;
1052 if (account == NULL)
1053 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1055 if (!tp_account_is_enabled (account))
1056 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1058 status = tp_account_get_connection_status (account, &reason);
1060 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1062 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1063 /* An error occured */
1064 return GTK_STOCK_DIALOG_ERROR;
1066 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1068 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1070 /* Account is connecting. Display a blinking account alternating between
1071 * the offline icon and the requested presence. */
1072 if (priv->connecting_show)
1073 presence = tp_account_get_requested_presence (account, NULL, NULL);
1075 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1079 /* status == TP_CONNECTION_STATUS_CONNECTED */
1080 presence = tp_account_get_current_presence (account, NULL, NULL);
1082 /* If presence is Unset (CM doesn't implement SimplePresence),
1083 * display the 'available' icon.
1084 * We also check Offline because of this MC5 bug: fd.o #26060 */
1085 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1086 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1087 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1090 return empathy_icon_name_for_presence (presence);
1094 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1095 GtkCellRenderer *cell,
1096 GtkTreeModel *model,
1098 EmpathyAccountsDialog *dialog)
1102 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1105 "icon-name", get_status_icon_for_account (dialog, account),
1108 if (account != NULL)
1109 g_object_unref (account);
1113 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1114 GtkCellRenderer *cell,
1115 GtkTreeModel *model,
1117 EmpathyAccountsDialog *dialog)
1119 EmpathyAccountSettings *settings;
1122 TpConnectionStatus status;
1124 gtk_tree_model_get (model, iter,
1125 COL_STATUS, &status,
1126 COL_ACCOUNT_SETTINGS, &settings,
1129 icon_name = empathy_account_settings_get_icon_name (settings);
1130 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1137 g_object_unref (settings);
1140 g_object_unref (pixbuf);
1144 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1151 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1153 if (account == NULL)
1156 if (tp_account_get_connection_status (account, NULL) ==
1157 TP_CONNECTION_STATUS_CONNECTING)
1159 /* Only update the row where we have a connecting account as that's the
1160 * ones having a blinking icon. */
1161 gtk_tree_model_row_changed (model, path, iter);
1164 g_object_unref (account);
1169 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1172 GtkTreeModel *model;
1173 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1175 priv->connecting_show = !priv->connecting_show;
1177 view = GTK_TREE_VIEW (priv->treeview);
1178 model = gtk_tree_view_get_model (view);
1180 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1186 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1189 EmpathyAccountsDialog *dialog)
1191 EmpathyAccountSettings *settings;
1192 GtkTreeModel *model;
1193 GtkTreePath *treepath;
1195 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1196 gboolean connecting;
1198 empathy_account_manager_get_accounts_connected (&connecting);
1202 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1203 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1207 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1208 treepath = gtk_tree_path_new_from_string (path);
1209 gtk_tree_model_get_iter (model, &iter, treepath);
1210 gtk_tree_model_get (model, &iter,
1211 COL_ACCOUNT_SETTINGS, &settings,
1213 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1216 gtk_tree_path_free (treepath);
1218 empathy_account_settings_set_display_name_async (settings, new_text,
1220 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1221 g_object_unref (settings);
1225 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1230 GtkTreeModel *model;
1232 GtkTreeSelection *selection;
1233 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1234 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1236 if (response_id == GTK_RESPONSE_YES)
1238 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1240 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1243 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1245 if (account != NULL)
1247 tp_account_remove_async (account, NULL, NULL);
1248 g_object_unref (account);
1252 /* No need to call accounts_dialog_model_selection_changed while
1253 * removing as we are going to call accounts_dialog_model_select_first
1254 * right after which will update the selection. */
1255 g_signal_handlers_block_by_func (selection,
1256 accounts_dialog_model_selection_changed, account_dialog);
1258 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1260 g_signal_handlers_unblock_by_func (selection,
1261 accounts_dialog_model_selection_changed, account_dialog);
1263 accounts_dialog_model_select_first (account_dialog);
1266 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1270 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1273 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1275 GtkTreeModel *model;
1276 gchar *question_dialog_primary_text;
1278 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1280 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1282 if (account == NULL || !tp_account_is_valid (account))
1284 if (account != NULL)
1285 g_object_unref (account);
1286 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1287 accounts_dialog_model_select_first (dialog);
1291 question_dialog_primary_text = g_strdup_printf (
1292 _("Do you want to remove %s from your computer?"),
1293 tp_account_get_display_name (account));
1295 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1296 _("This will not remove your account on the server."),
1297 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1299 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1300 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1302 g_free (question_dialog_primary_text);
1303 g_object_unref (account);
1307 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1308 EmpathyAccountsDialog *dialog)
1310 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1312 GtkTreeSelection *selection;
1315 view = GTK_TREE_VIEW (priv->treeview);
1316 selection = gtk_tree_view_get_selection (view);
1317 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1320 accounts_dialog_remove_account_iter (dialog, &iter);
1325 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1326 const gchar *path_string,
1327 EmpathyAccountsDialog *dialog)
1329 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1330 GtkTreeModel *model;
1333 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1334 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1337 accounts_dialog_remove_account_iter (dialog, &iter);
1339 #endif /* HAVE_MEEGO */
1342 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1345 GtkTreeViewColumn *column;
1346 GtkCellRenderer *cell;
1347 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1349 view = GTK_TREE_VIEW (priv->treeview);
1350 gtk_tree_view_set_headers_visible (view, FALSE);
1352 /* Account column */
1353 column = gtk_tree_view_column_new ();
1354 gtk_tree_view_column_set_expand (column, TRUE);
1355 gtk_tree_view_append_column (view, column);
1357 /* Status icon renderer */
1358 cell = gtk_cell_renderer_pixbuf_new ();
1359 gtk_tree_view_column_pack_start (column, cell, FALSE);
1360 gtk_tree_view_column_set_cell_data_func (column, cell,
1361 (GtkTreeCellDataFunc)
1362 accounts_dialog_model_status_pixbuf_data_func,
1366 /* Protocol icon renderer */
1367 cell = gtk_cell_renderer_pixbuf_new ();
1368 gtk_tree_view_column_pack_start (column, cell, FALSE);
1369 gtk_tree_view_column_set_cell_data_func (column, cell,
1370 (GtkTreeCellDataFunc)
1371 accounts_dialog_model_protocol_pixbuf_data_func,
1376 cell = gtk_cell_renderer_text_new ();
1378 "ellipsize", PANGO_ELLIPSIZE_END,
1382 gtk_tree_view_column_pack_start (column, cell, TRUE);
1383 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1384 g_signal_connect (cell, "edited",
1385 G_CALLBACK (accounts_dialog_name_edited_cb),
1387 g_signal_connect (cell, "editing-started",
1388 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1390 g_object_set (cell, "ypad", 4, NULL);
1394 cell = empathy_cell_renderer_activatable_new ();
1395 gtk_tree_view_column_pack_start (column, cell, FALSE);
1397 "icon-name", GTK_STOCK_DELETE,
1398 "show-on-select", TRUE,
1401 g_signal_connect (cell, "path-activated",
1402 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1404 #endif /* HAVE_MEEGO */
1407 static EmpathyAccountSettings *
1408 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1411 GtkTreeModel *model;
1412 GtkTreeSelection *selection;
1414 EmpathyAccountSettings *settings;
1415 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1417 view = GTK_TREE_VIEW (priv->treeview);
1418 selection = gtk_tree_view_get_selection (view);
1420 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1423 gtk_tree_model_get (model, &iter,
1424 COL_ACCOUNT_SETTINGS, &settings, -1);
1430 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1431 EmpathyAccountsDialog *dialog)
1433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1434 EmpathyAccountSettings *settings;
1435 GtkTreeModel *model;
1437 gboolean is_selection;
1438 gboolean creating = FALSE;
1440 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1442 settings = accounts_dialog_model_get_selected_settings (dialog);
1443 accounts_dialog_update_settings (dialog, settings);
1445 if (settings != NULL)
1446 g_object_unref (settings);
1448 if (priv->setting_widget_object != NULL)
1450 g_object_get (priv->setting_widget_object,
1451 "creating-account", &creating, NULL);
1454 /* Update remove button sensitivity */
1455 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1460 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1462 gpointer *user_data)
1464 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1465 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1467 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1469 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1471 /* The user wants to lose unsaved changes to the currently selected
1472 * account and select another account. We discard the changes and
1473 * select the other account. */
1475 GtkTreeSelection *selection;
1477 priv->force_change_row = TRUE;
1478 empathy_account_widget_discard_pending_changes (
1479 priv->setting_widget_object);
1481 path = gtk_tree_row_reference_get_path (priv->destination_row);
1482 selection = gtk_tree_view_get_selection (
1483 GTK_TREE_VIEW (priv->treeview));
1487 /* This will trigger a call to
1488 * accounts_dialog_account_selection_change() */
1489 gtk_tree_selection_select_path (selection, path);
1490 gtk_tree_path_free (path);
1493 gtk_tree_row_reference_free (priv->destination_row);
1497 priv->force_change_row = FALSE;
1502 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1503 GtkTreeModel *model,
1505 gboolean path_currently_selected,
1508 TpAccount *account = NULL;
1509 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1510 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1513 if (priv->force_change_row)
1515 /* We came back here because the user wants to discard changes to his
1516 * modified account. The changes have already been discarded so we
1517 * just change the selected row. */
1518 priv->force_change_row = FALSE;
1522 if (accounts_dialog_has_pending_change (dialog, &account))
1524 /* The currently selected account has some unsaved changes. We ask
1525 * the user if he really wants to lose his changes and select another
1527 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1528 priv->destination_row = gtk_tree_row_reference_new (model, path);
1530 accounts_dialog_show_question_dialog (dialog,
1531 question_dialog_primary_text,
1532 _("You are about to select another account, which will discard\n"
1533 "your changes. Are you sure you want to proceed?"),
1534 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1536 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1537 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1539 g_free (question_dialog_primary_text);
1547 if (account != NULL)
1548 g_object_unref (account);
1554 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1556 GtkListStore *store;
1557 GtkTreeSelection *selection;
1558 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1560 store = gtk_list_store_new (COL_COUNT,
1561 G_TYPE_STRING, /* name */
1562 G_TYPE_UINT, /* status */
1563 TP_TYPE_ACCOUNT, /* account */
1564 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1566 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1567 GTK_TREE_MODEL (store));
1569 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1570 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1571 gtk_tree_selection_set_select_function (selection,
1572 accounts_dialog_account_selection_change, dialog, NULL);
1574 g_signal_connect (selection, "changed",
1575 G_CALLBACK (accounts_dialog_model_selection_changed),
1578 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1579 COL_NAME, GTK_SORT_ASCENDING);
1581 accounts_dialog_model_add_columns (dialog);
1583 g_object_unref (store);
1587 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1592 GtkTreeModel *model;
1594 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1596 /* Update the status in the model */
1597 view = GTK_TREE_VIEW (priv->treeview);
1598 model = gtk_tree_view_get_model (view);
1600 for (ok = gtk_tree_model_get_iter_first (model, iter);
1602 ok = gtk_tree_model_iter_next (model, iter))
1604 TpAccount *this_account;
1607 gtk_tree_model_get (model, iter,
1608 COL_ACCOUNT, &this_account,
1611 equal = (this_account == account);
1612 g_object_unref (this_account);
1622 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1625 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1626 GtkTreeSelection *selection;
1628 GtkTreeModel *model;
1630 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1632 gtk_tree_selection_select_iter (selection, iter);
1634 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1635 path = gtk_tree_model_get_path (model, iter);
1637 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1640 gtk_tree_path_free (path);
1644 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1649 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1650 select_and_scroll_to_iter (dialog, &iter);
1654 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1659 enabled = tp_account_is_enabled (account);
1660 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1664 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1665 GdkEventButton *event,
1666 EmpathyAccountsDialog *dialog)
1668 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1669 TpAccount *account = NULL;
1670 GtkTreeModel *model = NULL;
1671 GtkTreePath *path = NULL;
1674 GtkWidget *item_enable, *item_disable;
1675 GtkWidget *image_enable, *image_disable;
1677 /* ignore multiple clicks */
1678 if (event->type != GDK_BUTTON_PRESS)
1681 if (event->button != 3)
1684 /* Selection is not yet set, so we have to get account from event position */
1685 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1686 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1687 event->x, event->y, &path, NULL, NULL, NULL))
1690 if (!gtk_tree_model_get_iter (model, &iter, path))
1693 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1695 /* Create the menu */
1696 menu = empathy_context_menu_new (GTK_WIDGET (view));
1698 /* Get images for menu items */
1699 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1700 tp_account_manager_get_most_available_presence (
1701 priv->account_manager, NULL, NULL)),
1702 GTK_ICON_SIZE_MENU);
1703 image_disable = gtk_image_new_from_icon_name (
1704 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1705 GTK_ICON_SIZE_MENU);
1707 /* Menu items: to enabled/disable the account */
1708 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1709 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1710 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1712 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1715 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1716 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1718 if (tp_account_is_enabled (account))
1720 tp_g_signal_connect_object (item_disable, "activate",
1721 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1722 gtk_widget_set_sensitive (item_enable, FALSE);
1726 tp_g_signal_connect_object (item_enable, "activate",
1727 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1728 gtk_widget_set_sensitive (item_disable, FALSE);
1731 gtk_widget_show (item_enable);
1732 gtk_widget_show (item_disable);
1734 /* FIXME: Add here presence items, to be able to set per-account presence */
1737 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1738 event->button, event->time);
1741 tp_clear_object (&account);
1742 gtk_tree_path_free (path);
1748 accounts_dialog_connection_changed_cb (TpAccount *account,
1752 gchar *dbus_error_name,
1753 GHashTable *details,
1754 EmpathyAccountsDialog *dialog)
1756 GtkTreeModel *model;
1759 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1761 /* Update the status-infobar in the details view */
1762 accounts_dialog_update_status_infobar (dialog, account);
1764 /* Update the status in the model */
1765 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1767 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1771 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1772 COL_STATUS, current,
1775 path = gtk_tree_model_get_path (model, &iter);
1776 gtk_tree_model_row_changed (model, path, &iter);
1777 gtk_tree_path_free (path);
1780 empathy_account_manager_get_accounts_connected (&found);
1782 if (!found && priv->connecting_id)
1784 g_source_remove (priv->connecting_id);
1785 priv->connecting_id = 0;
1788 if (found && !priv->connecting_id)
1789 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1790 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1795 update_account_in_treeview (EmpathyAccountsDialog *self,
1798 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1800 GtkTreeModel *model;
1802 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1803 if (accounts_dialog_get_account_iter (self, account, &iter))
1807 path = gtk_tree_model_get_path (model, &iter);
1808 gtk_tree_model_row_changed (model, path, &iter);
1809 gtk_tree_path_free (path);
1814 accounts_dialog_presence_changed_cb (TpAccount *account,
1817 gchar *status_message,
1818 EmpathyAccountsDialog *dialog)
1820 /* Update the status-infobar in the details view */
1821 accounts_dialog_update_status_infobar (dialog, account);
1823 update_account_in_treeview (dialog, account);
1827 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1831 const gchar *display_name;
1833 GtkTreeModel *model;
1834 EmpathyAccountSettings *settings;
1835 TpAccount *selected_account;
1836 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1837 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1839 display_name = tp_account_get_display_name (account);
1840 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1841 settings = accounts_dialog_model_get_selected_settings (dialog);
1842 if (settings == NULL)
1845 selected_account = empathy_account_settings_get_account (settings);
1847 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1849 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1850 COL_NAME, display_name,
1854 if (selected_account == account)
1855 accounts_dialog_update_name_label (dialog, display_name);
1857 g_object_unref (settings);
1861 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1864 EmpathyAccountSettings *settings;
1865 GtkTreeModel *model;
1867 TpConnectionStatus status;
1869 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1870 gboolean selected = FALSE;
1872 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1873 status = tp_account_get_connection_status (account, NULL);
1874 name = tp_account_get_display_name (account);
1876 settings = empathy_account_settings_new_for_account (account);
1878 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1880 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1884 GtkTreeSelection *selection;
1886 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1887 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1890 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1893 COL_ACCOUNT, account,
1894 COL_ACCOUNT_SETTINGS, settings,
1899 /* We just modified the selected account. Its display name may have been
1900 * changed and so it's place in the treeview. Scroll to it so it stays
1902 select_and_scroll_to_iter (dialog, &iter);
1905 accounts_dialog_connection_changed_cb (account,
1908 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1913 tp_g_signal_connect_object (account, "notify::display-name",
1914 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1917 tp_g_signal_connect_object (account, "status-changed",
1918 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1919 tp_g_signal_connect_object (account, "presence-changed",
1920 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1922 g_object_unref (settings);
1926 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1929 EmpathyAccountsDialog *dialog)
1931 accounts_dialog_add_account (dialog, account);
1935 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1938 EmpathyAccountsDialog *dialog)
1940 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1942 if (priv->setting_widget_object != NULL &&
1943 accounts_dialog_has_valid_accounts (dialog))
1945 empathy_account_widget_set_other_accounts_exist (
1946 priv->setting_widget_object, TRUE);
1951 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1953 EmpathyAccountsDialog *dialog)
1955 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1957 if (priv->setting_widget_object != NULL &&
1958 !accounts_dialog_has_valid_accounts (dialog))
1960 empathy_account_widget_set_other_accounts_exist (
1961 priv->setting_widget_object, FALSE);
1966 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1968 EmpathyAccountsDialog *dialog)
1971 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1973 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1975 gtk_list_store_remove (GTK_LIST_STORE (
1976 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1981 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1985 /* Update the status-infobar in the details view */
1986 accounts_dialog_update_status_infobar (dialog, account);
1988 DEBUG ("Account %s is now %s",
1989 tp_account_get_display_name (account),
1990 enabled ? "enabled" : "disabled");
1994 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1996 EmpathyAccountsDialog *dialog)
1998 enable_or_disable_account (dialog, account, FALSE);
1999 update_account_in_treeview (dialog, account);
2003 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2005 EmpathyAccountsDialog *dialog)
2007 enable_or_disable_account (dialog, account, TRUE);
2011 display_import_dialog (EmpathyAccountsDialog *dialog)
2013 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2014 GtkWidget *import_dialog;
2016 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2018 gtk_widget_show (import_dialog);
2020 return import_dialog;
2024 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2025 EmpathyAccountsDialog *dialog)
2027 display_import_dialog (dialog);
2031 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2035 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2037 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2039 if (response_id == GTK_RESPONSE_YES)
2040 gtk_widget_destroy (account_dialog);
2044 accounts_dialog_delete_event_cb (GtkWidget *widget,
2046 EmpathyAccountsDialog *dialog)
2048 /* we maunally handle responses to delete events */
2053 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2058 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2059 select_and_scroll_to_iter (dialog, &iter);
2063 finished_loading (EmpathyAccountsDialog *self)
2065 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2066 GtkTreeSelection *selection;
2067 gboolean has_selected;
2069 priv->loading = FALSE;
2071 gtk_widget_set_sensitive (priv->button_add, TRUE);
2072 gtk_widget_set_sensitive (priv->button_import, TRUE);
2073 gtk_widget_set_sensitive (priv->treeview, TRUE);
2075 /* Sensitive the remove button if there is an account selected */
2076 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2077 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2078 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2080 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2081 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2082 NOTEBOOK_PAGE_ACCOUNT);
2086 accounts_dialog_cms_prepare_cb (GObject *source,
2087 GAsyncResult *result,
2090 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2091 EmpathyAccountsDialog *dialog = user_data;
2092 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2094 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2097 /* No need to update the settings if we are already preparing one */
2098 if (priv->settings_ready == NULL)
2099 accounts_dialog_update_settings (dialog, NULL);
2101 if (priv->initial_selection != NULL)
2103 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2104 g_object_unref (priv->initial_selection);
2105 priv->initial_selection = NULL;
2109 finished_loading (dialog);
2113 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2115 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2116 GList *accounts, *l;
2118 g_signal_connect (priv->account_manager, "account-validity-changed",
2119 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2121 g_signal_connect (priv->account_manager, "account-removed",
2122 G_CALLBACK (accounts_dialog_account_removed_cb),
2124 g_signal_connect (priv->account_manager, "account-enabled",
2125 G_CALLBACK (accounts_dialog_account_enabled_cb),
2127 g_signal_connect (priv->account_manager, "account-disabled",
2128 G_CALLBACK (accounts_dialog_account_disabled_cb),
2131 /* Add existing accounts */
2132 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2133 for (l = accounts; l; l = l->next)
2135 accounts_dialog_add_account (dialog, l->data);
2137 g_list_free (accounts);
2139 priv->cms = empathy_connection_managers_dup_singleton ();
2141 empathy_connection_managers_prepare_async (priv->cms,
2142 accounts_dialog_cms_prepare_cb, dialog);
2144 accounts_dialog_model_select_first (dialog);
2148 accounts_dialog_manager_ready_cb (GObject *source_object,
2149 GAsyncResult *result,
2152 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2153 GError *error = NULL;
2155 if (!tp_proxy_prepare_finish (manager, result, &error))
2157 DEBUG ("Failed to prepare account manager: %s", error->message);
2158 g_error_free (error);
2162 accounts_dialog_accounts_setup (user_data);
2166 dialog_response_cb (GtkWidget *widget,
2170 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2172 if (response_id == GTK_RESPONSE_HELP)
2174 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2176 else if (response_id == GTK_RESPONSE_CLOSE ||
2177 response_id == GTK_RESPONSE_DELETE_EVENT)
2179 TpAccount *account = NULL;
2181 if (accounts_dialog_has_pending_change (dialog, &account))
2183 gchar *question_dialog_primary_text = get_dialog_primary_text (
2186 accounts_dialog_show_question_dialog (dialog,
2187 question_dialog_primary_text,
2188 _("You are about to close the window, which will discard\n"
2189 "your changes. Are you sure you want to proceed?"),
2190 G_CALLBACK (accounts_dialog_close_response_cb),
2192 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2193 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2195 g_free (question_dialog_primary_text);
2199 gtk_widget_destroy (widget);
2202 if (account != NULL)
2203 g_object_unref (account);
2208 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2210 GtkWidget *top_hbox;
2213 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2214 GtkWidget *content_area, *action_area;
2215 GtkWidget *grid, *hbox;
2217 GtkWidget *sw, *toolbar;
2218 GtkStyleContext *context;
2220 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2222 gui = empathy_builder_get_file (filename,
2223 "accounts_dialog_hbox", &top_hbox,
2224 "vbox_details", &priv->vbox_details,
2225 "frame_no_protocol", &priv->frame_no_protocol,
2226 "alignment_settings", &priv->alignment_settings,
2227 "alignment_infobar", &priv->alignment_infobar,
2228 "treeview", &priv->treeview,
2229 "button_add", &priv->button_add,
2230 "button_remove", &priv->button_remove,
2231 "button_import", &priv->button_import,
2232 "hbox_protocol", &priv->hbox_protocol,
2233 "notebook_account", &priv->notebook_account,
2234 "alignment_loading", &alig,
2236 "add_remove_toolbar", &toolbar,
2240 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2242 empathy_builder_connect (gui, dialog,
2243 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2244 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2245 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2246 "treeview", "button-press-event",
2247 accounts_dialog_treeview_button_press_event_cb,
2250 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2252 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2254 g_object_unref (gui);
2256 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2259 gtk_widget_hide (action_area);
2260 gtk_widget_hide (priv->button_remove);
2261 #endif /* HAVE_MEEGO */
2263 /* Display loading page */
2264 priv->loading = TRUE;
2266 priv->spinner = gtk_spinner_new ();
2268 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2269 gtk_widget_show (priv->spinner);
2271 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2273 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2274 NOTEBOOK_PAGE_LOADING);
2276 /* Remove button is insensitive until we have a selected account */
2277 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2279 /* Add and Import buttons and treeview are insensitive while the dialog
2281 gtk_widget_set_sensitive (priv->button_add, FALSE);
2282 gtk_widget_set_sensitive (priv->button_import, FALSE);
2283 gtk_widget_set_sensitive (priv->treeview, FALSE);
2285 if (priv->parent_window)
2286 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2287 priv->parent_window);
2289 priv->infobar = gtk_info_bar_new ();
2290 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2292 gtk_widget_show (priv->infobar);
2294 grid = gtk_grid_new ();
2296 GTK_CONTAINER (gtk_info_bar_get_content_area (
2297 GTK_INFO_BAR (priv->infobar))),
2300 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2301 GTK_ICON_SIZE_DIALOG);
2302 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2303 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2306 priv->label_name = gtk_label_new (NULL);
2307 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2310 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2311 gtk_widget_set_hexpand (hbox, TRUE);
2312 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2313 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2315 /* set up spinner */
2316 priv->throbber = gtk_spinner_new ();
2318 priv->image_status = gtk_image_new_from_icon_name (
2319 empathy_icon_name_for_presence (
2320 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2322 priv->label_status = gtk_label_new (NULL);
2323 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2325 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2326 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2327 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2329 /* enabled switch */
2330 priv->enabled_switch = gtk_switch_new ();
2331 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2332 g_signal_connect (priv->enabled_switch, "notify::active",
2333 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2334 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2336 gtk_widget_show_all (grid);
2338 /* Tweak the dialog */
2339 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2340 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2342 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2344 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2346 /* join the add/remove toolbar to the treeview */
2347 context = gtk_widget_get_style_context (sw);
2348 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2350 context = gtk_widget_get_style_context (toolbar);
2351 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2353 /* add dialog buttons */
2354 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2356 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2357 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2358 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2361 g_signal_connect (dialog, "response",
2362 G_CALLBACK (dialog_response_cb), dialog);
2364 g_signal_connect (dialog, "delete-event",
2365 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2369 do_dispose (GObject *obj)
2371 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2372 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2374 if (priv->connecting_id != 0)
2376 g_source_remove (priv->connecting_id);
2377 priv->connecting_id = 0;
2380 if (priv->account_manager != NULL)
2382 g_object_unref (priv->account_manager);
2383 priv->account_manager = NULL;
2386 if (priv->cms != NULL)
2388 g_object_unref (priv->cms);
2392 if (priv->connectivity)
2394 g_object_unref (priv->connectivity);
2395 priv->connectivity = NULL;
2398 if (priv->initial_selection != NULL)
2400 g_object_unref (priv->initial_selection);
2401 priv->initial_selection = NULL;
2404 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2408 do_get_property (GObject *object,
2413 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2415 switch (property_id)
2418 g_value_set_object (value, priv->parent_window);
2421 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2426 do_set_property (GObject *object,
2428 const GValue *value,
2431 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2433 switch (property_id)
2436 priv->parent_window = g_value_get_object (value);
2439 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2444 do_constructed (GObject *object)
2446 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2447 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2448 GtkTreeModel *model;
2450 accounts_dialog_build_ui (dialog);
2451 accounts_dialog_model_setup (dialog);
2453 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2454 g_signal_connect (model, "row-inserted",
2455 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2456 g_signal_connect (model, "row-deleted",
2457 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2459 /* Set up signalling */
2460 priv->account_manager = tp_account_manager_dup ();
2462 tp_proxy_prepare_async (priv->account_manager, NULL,
2463 accounts_dialog_manager_ready_cb, dialog);
2465 priv->connectivity = empathy_connectivity_dup_singleton ();
2469 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2471 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2472 GParamSpec *param_spec;
2474 oclass->dispose = do_dispose;
2475 oclass->constructed = do_constructed;
2476 oclass->set_property = do_set_property;
2477 oclass->get_property = do_get_property;
2479 param_spec = g_param_spec_object ("parent",
2480 "parent", "The parent window",
2482 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2483 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2485 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2489 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2491 EmpathyAccountsDialogPriv *priv;
2493 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2494 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2495 EmpathyAccountsDialogPriv);
2496 dialog->priv = priv;
2499 /* public methods */
2502 empathy_accounts_dialog_show (GtkWindow *parent,
2503 TpAccount *selected_account)
2505 EmpathyAccountsDialog *dialog;
2506 EmpathyAccountsDialogPriv *priv;
2508 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2509 "parent", parent, NULL);
2511 priv = GET_PRIV (dialog);
2513 if (selected_account)
2515 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2516 accounts_dialog_set_selected_account (dialog, selected_account);
2518 /* save the selection to set it later when the cms
2521 priv->initial_selection = g_object_ref (selected_account);
2524 gtk_window_present (GTK_WINDOW (dialog));
2526 return GTK_WIDGET (dialog);
2530 empathy_accounts_dialog_show_application (GdkScreen *screen,
2531 TpAccount *selected_account,
2537 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2539 args = g_string_new (NULL);
2541 if (selected_account != NULL)
2542 g_string_append_printf (args, " --select-account=%s",
2543 tp_account_get_path_suffix (selected_account));
2546 g_string_append_printf (args, " --if-needed");
2549 g_string_append_printf (args, " --hidden");
2551 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2553 selected_account == NULL ? "<none selected>" :
2554 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2556 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2558 g_string_free (args, TRUE);
2562 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2564 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2565 gboolean result = FALSE;
2567 if (priv->setting_widget_object == NULL)
2570 g_object_get (priv->setting_widget_object,
2571 "creating-account", &result, NULL);