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);
215 g_free (message_markup);
219 accounts_dialog_enable_account_cb (GObject *account,
220 GAsyncResult *result,
223 GError *error = NULL;
225 tp_account_set_enabled_finish (TP_ACCOUNT (account), result, &error);
229 DEBUG ("Could not enable the account: %s", error->message);
230 g_error_free (error);
234 TpAccountManager *am = tp_account_manager_dup ();
236 empathy_connect_new_account (TP_ACCOUNT (account), am);
242 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
244 EmpathyAccountsDialog *dialog)
246 EmpathyAccountSettings *settings;
249 settings = accounts_dialog_model_get_selected_settings (dialog);
250 if (settings == NULL)
253 account = empathy_account_settings_get_account (settings);
257 tp_account_set_enabled_async (account, gtk_switch_get_active (sw),
258 accounts_dialog_enable_account_cb, NULL);
262 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
265 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
266 gchar *status_message = NULL;
272 GtkTreeSelection *selection;
274 TpAccount *selected_account;
275 gboolean account_enabled;
276 gboolean creating_account;
277 TpStorageRestrictionFlags storage_restrictions = 0;
279 view = GTK_TREE_VIEW (priv->treeview);
280 selection = gtk_tree_view_get_selection (view);
282 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
285 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
286 if (selected_account != NULL)
287 g_object_unref (selected_account);
289 /* do not update the infobar when the account is not selected */
290 if (account != selected_account)
295 status = tp_account_get_connection_status (account, &reason);
296 presence = tp_account_get_current_presence (account, NULL, &status_message);
297 account_enabled = tp_account_is_enabled (account);
298 creating_account = FALSE;
300 if (status == TP_CONNECTION_STATUS_CONNECTED &&
301 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
302 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
303 /* If presence is Unset (CM doesn't implement SimplePresence) but we
304 * are connected, consider ourself as Available.
305 * We also check Offline because of this MC5 bug: fd.o #26060 */
306 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
308 /* set presence to offline if account is disabled
309 * (else no icon is shown in infobar)*/
310 if (!account_enabled)
311 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
313 storage_restrictions = tp_account_get_storage_restrictions (account);
317 status = TP_CONNECTION_STATUS_DISCONNECTED;
318 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
319 account_enabled = FALSE;
320 creating_account = TRUE;
323 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
324 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
326 /* update the enabled switch */
327 g_signal_handlers_block_by_func (priv->enabled_switch,
328 accounts_dialog_enable_switch_active_cb, dialog);
329 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
331 g_signal_handlers_unblock_by_func (priv->enabled_switch,
332 accounts_dialog_enable_switch_active_cb, dialog);
334 /* Display the Enable switch if account supports it */
335 gtk_widget_set_visible (priv->enabled_switch,
336 !(storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED));
342 case TP_CONNECTION_STATUS_CONNECTING:
343 accounts_dialog_status_infobar_set_message (dialog,
345 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
348 gtk_spinner_start (GTK_SPINNER (priv->throbber));
349 gtk_widget_show (priv->throbber);
350 gtk_widget_hide (priv->image_status);
352 case TP_CONNECTION_STATUS_CONNECTED:
353 if (g_strcmp0 (status_message, "") == 0)
357 message = g_strdup_printf ("%s",
358 empathy_presence_get_default_message (presence));
360 accounts_dialog_status_infobar_set_message (dialog, message);
367 message = g_strdup_printf ("%s — %s",
368 empathy_presence_get_default_message (presence),
371 accounts_dialog_status_infobar_set_message (dialog, message);
374 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
377 gtk_widget_show (priv->image_status);
378 gtk_widget_hide (priv->throbber);
380 case TP_CONNECTION_STATUS_DISCONNECTED:
381 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
385 message = g_strdup_printf (_("Offline — %s"),
386 empathy_account_get_error_message (account, NULL));
387 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
388 GTK_MESSAGE_WARNING);
390 accounts_dialog_status_infobar_set_message (dialog, message);
397 message = g_strdup_printf (_("Disconnected — %s"),
398 empathy_account_get_error_message (account, NULL));
399 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
402 accounts_dialog_status_infobar_set_message (dialog, message);
406 if (!empathy_connectivity_is_online (priv->connectivity))
407 accounts_dialog_status_infobar_set_message (dialog,
408 _("Offline — No Network Connection"));
410 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
411 gtk_widget_show (priv->image_status);
412 gtk_widget_hide (priv->throbber);
415 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
416 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
417 GTK_MESSAGE_WARNING);
419 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
420 gtk_widget_hide (priv->image_status);
421 gtk_widget_hide (priv->throbber);
426 accounts_dialog_status_infobar_set_message (dialog,
427 _("Offline — Account Disabled"));
429 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
430 GTK_MESSAGE_WARNING);
431 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
432 gtk_widget_show (priv->image_status);
433 gtk_widget_hide (priv->throbber);
436 gtk_widget_show (priv->label_status);
438 if (!creating_account)
439 gtk_widget_show (priv->infobar);
441 gtk_widget_hide (priv->infobar);
443 g_free (status_message);
447 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
451 GtkTreeSelection *selection;
453 EmpathyAccountSettings *settings;
455 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
457 view = GTK_TREE_VIEW (priv->treeview);
458 selection = gtk_tree_view_get_selection (view);
460 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
463 gtk_tree_model_get (model, &iter,
464 COL_ACCOUNT_SETTINGS, &settings,
465 COL_ACCOUNT, &account, -1);
467 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
471 /* We were creating an account. We remove the selected row */
472 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
476 /* We were modifying an account. We discard the changes by reloading the
477 * settings and the UI. */
478 accounts_dialog_update_settings (dialog, settings);
479 g_object_unref (account);
482 gtk_widget_set_sensitive (priv->treeview, TRUE);
483 gtk_widget_set_sensitive (priv->button_add, TRUE);
484 gtk_widget_set_sensitive (priv->button_remove, TRUE);
485 gtk_widget_set_sensitive (priv->button_import, TRUE);
487 if (settings != NULL)
488 g_object_unref (settings);
492 empathy_account_dialog_widget_cancelled_cb (
493 EmpathyAccountWidget *widget_object,
494 EmpathyAccountsDialog *dialog)
496 empathy_account_dialog_cancel (dialog);
500 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
502 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
507 g_object_get (priv->setting_widget_object,
508 "creating-account", &creating, NULL);
513 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
515 if (gtk_tree_model_get_iter_first (model, &iter))
516 return gtk_tree_model_iter_next (model, &iter);
522 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
524 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
525 EmpathyAccountSettings *settings;
526 GtkWidget *subdialog, *content, *content_area, *align;
528 settings = accounts_dialog_model_get_selected_settings (dialog);
530 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
532 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
535 priv->setting_widget_object =
536 empathy_account_widget_new_for_protocol (settings, FALSE);
538 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget_object),
539 (gpointer *) &priv->setting_widget_object);
541 if (accounts_dialog_has_valid_accounts (dialog))
542 empathy_account_widget_set_other_accounts_exist (
543 priv->setting_widget_object, TRUE);
545 content = empathy_account_widget_get_widget (priv->setting_widget_object);
547 g_signal_connect (priv->setting_widget_object, "cancelled",
548 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
550 g_signal_connect_swapped (priv->setting_widget_object, "close",
551 G_CALLBACK (gtk_widget_destroy), subdialog);
553 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
555 align = gtk_alignment_new (0.5, 0.5, 1, 1);
556 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
558 gtk_container_add (GTK_CONTAINER (align), content);
559 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
561 gtk_widget_show (content);
562 gtk_widget_show (align);
563 gtk_widget_show (subdialog);
567 start_external_app (GAppInfo *app_info)
569 GError *error = NULL;
570 GdkAppLaunchContext *context = NULL;
573 display = gdk_display_get_default ();
574 context = gdk_display_get_app_launch_context (display);
576 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
579 g_critical ("Failed to bisho: %s", error->message);
580 g_clear_error (&error);
583 tp_clear_object (&context);
587 use_external_storage_provider (EmpathyAccountsDialog *self,
590 const gchar *provider;
592 provider = tp_account_get_storage_provider (account);
593 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
595 GDesktopAppInfo *desktop_info;
598 GError *error = NULL;
600 desktop_info = g_desktop_app_info_new ("gnome-control-center.desktop");
601 if (desktop_info == NULL)
603 g_critical ("Could not locate 'gnome-control-center.desktop'");
607 /* glib doesn't have API to start a desktop file with args... (#637875) */
608 cmd = g_strdup_printf ("%s bisho.desktop", g_app_info_get_commandline (
609 (GAppInfo *) desktop_info));
611 app_info = g_app_info_create_from_commandline (cmd, NULL, 0, &error);
613 if (app_info == NULL)
615 DEBUG ("Failed to create app info: %s", error->message);
616 g_error_free (error);
620 start_external_app (app_info);
621 g_object_unref (app_info);
624 g_object_unref (desktop_info);
628 else if (!tp_strdiff (provider, "org.gnome.OnlineAccounts"))
630 GDesktopAppInfo *desktop_info;
632 desktop_info = g_desktop_app_info_new (
633 "gnome-online-accounts-panel.desktop");
634 if (desktop_info == NULL)
636 g_critical ("Could not locate 'gnome-online-accounts-panel.desktop'");
640 start_external_app (G_APP_INFO (desktop_info));
641 g_object_unref (desktop_info);
648 DEBUG ("Don't know how to handle %s", provider);
654 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
657 EmpathyAccountSettings *settings;
659 TpStorageRestrictionFlags storage_restrictions;
661 settings = accounts_dialog_model_get_selected_settings (dialog);
663 account = empathy_account_settings_get_account (settings);
664 g_return_if_fail (account != NULL);
666 storage_restrictions = tp_account_get_storage_restrictions (account);
668 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
669 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
671 DEBUG ("Account is provided by an external storage provider");
673 use_external_storage_provider (dialog, account);
677 account_dialog_create_edit_params_dialog (dialog);
682 account_dialog_show_contact_details_failed (EmpathyAccountsDialog *dialog,
685 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
686 GtkWidget *infobar, *label;
688 infobar = gtk_info_bar_new ();
692 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_ERROR);
693 label = gtk_label_new (_("Failed to retrieve your personal information "
694 "from the server."));
698 gtk_info_bar_set_message_type (GTK_INFO_BAR (infobar), GTK_MESSAGE_INFO);
699 label = gtk_label_new (_("Go online to edit your personal information."));
703 GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar))),
705 gtk_box_pack_start (GTK_BOX (priv->dialog_content), infobar, FALSE, FALSE, 0);
706 gtk_widget_show_all (infobar);
710 account_dialog_got_self_contact (TpConnection *conn,
711 EmpathyContact *contact,
712 const GError *in_error,
716 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
717 GtkWidget *editor, *alig;
719 if (in_error != NULL)
721 DEBUG ("Failed to get self-contact: %s", in_error->message);
722 account_dialog_show_contact_details_failed (
723 EMPATHY_ACCOUNTS_DIALOG (dialog), TRUE);
727 alig = gtk_alignment_new (0.5, 0, 1, 1);
729 /* create the contact info editor for this account */
730 editor = empathy_contact_widget_new (contact,
731 EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
732 EMPATHY_CONTACT_WIDGET_EDIT_AVATAR |
733 EMPATHY_CONTACT_WIDGET_NO_STATUS |
734 EMPATHY_CONTACT_WIDGET_EDIT_DETAILS);
736 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
737 gtk_container_add (GTK_CONTAINER (alig), editor);
738 gtk_widget_show (alig);
739 gtk_widget_show (editor);
743 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
744 EmpathyAccountSettings *settings)
746 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
747 const gchar *icon_name;
749 TpConnection *conn = NULL;
750 GtkWidget *bbox, *button;
752 account = empathy_account_settings_get_account (settings);
754 // if (priv->setting_widget_object != NULL)
755 // g_object_remove_weak_pointer (G_OBJECT (priv->setting_widget_object),
756 // (gpointer *) &priv->setting_widget_object);
758 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
759 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
760 priv->dialog_content);
761 gtk_widget_show (priv->dialog_content);
763 /* request the self contact */
765 conn = tp_account_get_connection (account);
769 empathy_tp_contact_factory_get_from_handle (conn,
770 tp_connection_get_self_handle (conn),
771 account_dialog_got_self_contact,
772 NULL, NULL, G_OBJECT (dialog));
776 account_dialog_show_contact_details_failed (dialog, FALSE);
779 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
780 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
781 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
782 gtk_widget_show (bbox);
784 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters..."));
785 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
786 gtk_widget_show (button);
787 g_signal_connect_swapped (button, "clicked",
788 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
790 icon_name = empathy_account_settings_get_icon_name (settings);
792 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
794 /* show the default icon; keep this in sync with the default
795 * one in empathy-accounts-dialog.ui.
797 icon_name = GTK_STOCK_CUT;
799 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
800 icon_name, GTK_ICON_SIZE_DIALOG);
801 gtk_widget_set_tooltip_text (priv->image_type,
802 empathy_protocol_name_to_display_name
803 (empathy_account_settings_get_protocol (settings)));
804 gtk_widget_show (priv->image_type);
806 accounts_dialog_update_name_label (dialog,
807 empathy_account_settings_get_display_name (settings));
809 accounts_dialog_update_status_infobar (dialog, account);
813 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
815 EmpathyAccountsDialog *dialog)
817 if (empathy_account_settings_is_ready (settings))
818 account_dialog_create_dialog_content (dialog, settings);
822 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
826 GtkTreeSelection *selection;
828 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
831 view = GTK_TREE_VIEW (priv->treeview);
832 model = gtk_tree_view_get_model (view);
834 if (gtk_tree_model_get_iter_first (model, &iter))
836 selection = gtk_tree_view_get_selection (view);
837 gtk_tree_selection_select_iter (selection, &iter);
841 accounts_dialog_update_settings (dialog, NULL);
846 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
851 GtkTreeSelection *selection;
852 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
854 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
856 if (gtk_tree_selection_get_selected (selection, &model, &iter))
857 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
859 return priv->setting_widget_object != NULL
860 && empathy_account_widget_contains_pending_changes (
861 priv->setting_widget_object);
865 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
866 const gchar *primary_text,
867 const gchar *secondary_text,
868 GCallback response_callback,
870 const gchar *first_button_text,
874 GtkWidget *message_dialog;
875 const gchar *button_text;
877 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
878 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
879 GTK_MESSAGE_QUESTION,
883 gtk_message_dialog_format_secondary_text (
884 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
886 va_start (button_args, first_button_text);
887 for (button_text = first_button_text;
889 button_text = va_arg (button_args, const gchar *))
892 response_id = va_arg (button_args, gint);
894 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
897 va_end (button_args);
899 g_signal_connect (message_dialog, "response", response_callback, user_data);
901 gtk_widget_show (message_dialog);
905 get_dialog_primary_text (TpAccount *account)
909 /* Existing account */
910 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
911 tp_account_get_display_name (account));
915 /* Newly created account */
916 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
921 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
922 EmpathyAccountsDialog *self)
927 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
928 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
930 response = gtk_dialog_run (GTK_DIALOG (dialog));
932 if (response == GTK_RESPONSE_OK)
934 EmpathyAccountSettings *settings;
937 settings = empathy_new_account_dialog_get_settings (
938 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
940 /* The newly created account has already been added by
941 * accounts_dialog_account_validity_changed_cb so we just
942 * have to select it. */
943 account = empathy_account_settings_get_account (settings);
944 accounts_dialog_model_set_selected (self, account);
947 gtk_widget_destroy (dialog);
951 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
952 EmpathyAccountSettings *settings)
954 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
956 if (priv->settings_ready != NULL)
958 g_signal_handler_disconnect (priv->settings_ready,
959 priv->settings_ready_id);
960 priv->settings_ready = NULL;
961 priv->settings_ready_id = 0;
968 GtkTreeSelection *selection;
970 view = GTK_TREE_VIEW (priv->treeview);
971 model = gtk_tree_view_get_model (view);
972 selection = gtk_tree_view_get_selection (view);
974 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
976 /* We have configured accounts, select the first one if there
977 * is no other account selected already. */
978 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
979 accounts_dialog_model_select_first (dialog);
983 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
985 /* We have no account configured but we have some
986 * profiles installed. The user obviously wants to add
987 * an account. Click on the Add button for him. */
988 accounts_dialog_button_add_clicked_cb (priv->button_add,
993 /* No account and no profile, warn the user */
994 gtk_widget_hide (priv->vbox_details);
995 gtk_widget_show (priv->frame_no_protocol);
996 gtk_widget_set_sensitive (priv->button_add, FALSE);
1000 /* We have an account selected, destroy old settings and create a new
1001 * one for the account selected */
1002 gtk_widget_hide (priv->frame_no_protocol);
1003 gtk_widget_show (priv->vbox_details);
1004 gtk_widget_hide (priv->hbox_protocol);
1006 if (priv->dialog_content)
1008 gtk_widget_destroy (priv->dialog_content);
1009 priv->dialog_content = NULL;
1012 if (empathy_account_settings_is_ready (settings))
1014 account_dialog_create_dialog_content (dialog, settings);
1018 priv->settings_ready = settings;
1019 priv->settings_ready_id =
1020 g_signal_connect (settings, "notify::ready",
1021 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
1027 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
1028 GtkCellEditable *editable,
1030 EmpathyAccountsDialog *dialog)
1032 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1034 if (priv->connecting_id)
1035 g_source_remove (priv->connecting_id);
1037 DEBUG ("Editing account name started; stopping flashing");
1040 static const gchar *
1041 get_status_icon_for_account (EmpathyAccountsDialog *self,
1044 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1045 TpConnectionStatus status;
1046 TpConnectionStatusReason reason;
1047 TpConnectionPresenceType presence;
1049 if (account == NULL)
1050 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1052 if (!tp_account_is_enabled (account))
1053 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
1055 status = tp_account_get_connection_status (account, &reason);
1057 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
1059 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
1060 /* An error occured */
1061 return GTK_STOCK_DIALOG_ERROR;
1063 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1065 else if (status == TP_CONNECTION_STATUS_CONNECTING)
1067 /* Account is connecting. Display a blinking account alternating between
1068 * the offline icon and the requested presence. */
1069 if (priv->connecting_show)
1070 presence = tp_account_get_requested_presence (account, NULL, NULL);
1072 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1076 /* status == TP_CONNECTION_STATUS_CONNECTED */
1077 presence = tp_account_get_current_presence (account, NULL, NULL);
1079 /* If presence is Unset (CM doesn't implement SimplePresence),
1080 * display the 'available' icon.
1081 * We also check Offline because of this MC5 bug: fd.o #26060 */
1082 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1083 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1084 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1087 return empathy_icon_name_for_presence (presence);
1091 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1092 GtkCellRenderer *cell,
1093 GtkTreeModel *model,
1095 EmpathyAccountsDialog *dialog)
1099 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1102 "icon-name", get_status_icon_for_account (dialog, account),
1105 if (account != NULL)
1106 g_object_unref (account);
1110 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1111 GtkCellRenderer *cell,
1112 GtkTreeModel *model,
1114 EmpathyAccountsDialog *dialog)
1116 EmpathyAccountSettings *settings;
1119 TpConnectionStatus status;
1121 gtk_tree_model_get (model, iter,
1122 COL_STATUS, &status,
1123 COL_ACCOUNT_SETTINGS, &settings,
1126 icon_name = empathy_account_settings_get_icon_name (settings);
1127 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1134 g_object_unref (settings);
1137 g_object_unref (pixbuf);
1141 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1148 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1150 if (account == NULL)
1153 if (tp_account_get_connection_status (account, NULL) ==
1154 TP_CONNECTION_STATUS_CONNECTING)
1156 /* Only update the row where we have a connecting account as that's the
1157 * ones having a blinking icon. */
1158 gtk_tree_model_row_changed (model, path, iter);
1161 g_object_unref (account);
1166 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1169 GtkTreeModel *model;
1170 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1172 priv->connecting_show = !priv->connecting_show;
1174 view = GTK_TREE_VIEW (priv->treeview);
1175 model = gtk_tree_view_get_model (view);
1177 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1183 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1186 EmpathyAccountsDialog *dialog)
1188 EmpathyAccountSettings *settings;
1189 GtkTreeModel *model;
1190 GtkTreePath *treepath;
1192 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1193 gboolean connecting;
1195 empathy_account_manager_get_accounts_connected (&connecting);
1199 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1200 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1204 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1205 treepath = gtk_tree_path_new_from_string (path);
1206 gtk_tree_model_get_iter (model, &iter, treepath);
1207 gtk_tree_model_get (model, &iter,
1208 COL_ACCOUNT_SETTINGS, &settings,
1210 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1213 gtk_tree_path_free (treepath);
1215 empathy_account_settings_set_display_name_async (settings, new_text,
1217 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1218 g_object_unref (settings);
1222 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1227 GtkTreeModel *model;
1229 GtkTreeSelection *selection;
1230 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1231 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1233 if (response_id == GTK_RESPONSE_YES)
1235 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1237 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1240 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1242 if (account != NULL)
1244 tp_account_remove_async (account, NULL, NULL);
1245 g_object_unref (account);
1249 /* No need to call accounts_dialog_model_selection_changed while
1250 * removing as we are going to call accounts_dialog_model_select_first
1251 * right after which will update the selection. */
1252 g_signal_handlers_block_by_func (selection,
1253 accounts_dialog_model_selection_changed, account_dialog);
1255 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1257 g_signal_handlers_unblock_by_func (selection,
1258 accounts_dialog_model_selection_changed, account_dialog);
1260 accounts_dialog_model_select_first (account_dialog);
1263 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1267 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1270 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1272 GtkTreeModel *model;
1273 gchar *question_dialog_primary_text;
1275 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1277 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1279 if (account == NULL || !tp_account_is_valid (account))
1281 if (account != NULL)
1282 g_object_unref (account);
1283 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1284 accounts_dialog_model_select_first (dialog);
1288 question_dialog_primary_text = g_strdup_printf (
1289 _("Do you want to remove %s from your computer?"),
1290 tp_account_get_display_name (account));
1292 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1293 _("This will not remove your account on the server."),
1294 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1296 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1297 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1299 g_free (question_dialog_primary_text);
1300 g_object_unref (account);
1304 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1305 EmpathyAccountsDialog *dialog)
1307 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1309 GtkTreeSelection *selection;
1312 view = GTK_TREE_VIEW (priv->treeview);
1313 selection = gtk_tree_view_get_selection (view);
1314 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1317 accounts_dialog_remove_account_iter (dialog, &iter);
1322 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1323 const gchar *path_string,
1324 EmpathyAccountsDialog *dialog)
1326 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1327 GtkTreeModel *model;
1330 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1331 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1334 accounts_dialog_remove_account_iter (dialog, &iter);
1336 #endif /* HAVE_MEEGO */
1339 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1342 GtkTreeViewColumn *column;
1343 GtkCellRenderer *cell;
1344 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1346 view = GTK_TREE_VIEW (priv->treeview);
1347 gtk_tree_view_set_headers_visible (view, FALSE);
1349 /* Account column */
1350 column = gtk_tree_view_column_new ();
1351 gtk_tree_view_column_set_expand (column, TRUE);
1352 gtk_tree_view_append_column (view, column);
1354 /* Status icon renderer */
1355 cell = gtk_cell_renderer_pixbuf_new ();
1356 gtk_tree_view_column_pack_start (column, cell, FALSE);
1357 gtk_tree_view_column_set_cell_data_func (column, cell,
1358 (GtkTreeCellDataFunc)
1359 accounts_dialog_model_status_pixbuf_data_func,
1363 /* Protocol icon renderer */
1364 cell = gtk_cell_renderer_pixbuf_new ();
1365 gtk_tree_view_column_pack_start (column, cell, FALSE);
1366 gtk_tree_view_column_set_cell_data_func (column, cell,
1367 (GtkTreeCellDataFunc)
1368 accounts_dialog_model_protocol_pixbuf_data_func,
1373 cell = gtk_cell_renderer_text_new ();
1375 "ellipsize", PANGO_ELLIPSIZE_END,
1379 gtk_tree_view_column_pack_start (column, cell, TRUE);
1380 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1381 g_signal_connect (cell, "edited",
1382 G_CALLBACK (accounts_dialog_name_edited_cb),
1384 g_signal_connect (cell, "editing-started",
1385 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1387 g_object_set (cell, "ypad", 4, NULL);
1391 cell = empathy_cell_renderer_activatable_new ();
1392 gtk_tree_view_column_pack_start (column, cell, FALSE);
1394 "icon-name", GTK_STOCK_DELETE,
1395 "show-on-select", TRUE,
1398 g_signal_connect (cell, "path-activated",
1399 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1401 #endif /* HAVE_MEEGO */
1404 static EmpathyAccountSettings *
1405 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1408 GtkTreeModel *model;
1409 GtkTreeSelection *selection;
1411 EmpathyAccountSettings *settings;
1412 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1414 view = GTK_TREE_VIEW (priv->treeview);
1415 selection = gtk_tree_view_get_selection (view);
1417 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1420 gtk_tree_model_get (model, &iter,
1421 COL_ACCOUNT_SETTINGS, &settings, -1);
1427 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1428 EmpathyAccountsDialog *dialog)
1430 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1431 EmpathyAccountSettings *settings;
1432 GtkTreeModel *model;
1434 gboolean is_selection;
1435 gboolean creating = FALSE;
1437 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1439 settings = accounts_dialog_model_get_selected_settings (dialog);
1440 accounts_dialog_update_settings (dialog, settings);
1442 if (settings != NULL)
1443 g_object_unref (settings);
1445 if (priv->setting_widget_object != NULL)
1447 g_object_get (priv->setting_widget_object,
1448 "creating-account", &creating, NULL);
1451 /* Update remove button sensitivity */
1452 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1457 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1459 gpointer *user_data)
1461 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1462 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1464 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1466 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1468 /* The user wants to lose unsaved changes to the currently selected
1469 * account and select another account. We discard the changes and
1470 * select the other account. */
1472 GtkTreeSelection *selection;
1474 priv->force_change_row = TRUE;
1475 empathy_account_widget_discard_pending_changes (
1476 priv->setting_widget_object);
1478 path = gtk_tree_row_reference_get_path (priv->destination_row);
1479 selection = gtk_tree_view_get_selection (
1480 GTK_TREE_VIEW (priv->treeview));
1484 /* This will trigger a call to
1485 * accounts_dialog_account_selection_change() */
1486 gtk_tree_selection_select_path (selection, path);
1487 gtk_tree_path_free (path);
1490 gtk_tree_row_reference_free (priv->destination_row);
1494 priv->force_change_row = FALSE;
1499 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1500 GtkTreeModel *model,
1502 gboolean path_currently_selected,
1505 TpAccount *account = NULL;
1506 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1507 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1510 if (priv->force_change_row)
1512 /* We came back here because the user wants to discard changes to his
1513 * modified account. The changes have already been discarded so we
1514 * just change the selected row. */
1515 priv->force_change_row = FALSE;
1519 if (accounts_dialog_has_pending_change (dialog, &account))
1521 /* The currently selected account has some unsaved changes. We ask
1522 * the user if he really wants to lose his changes and select another
1524 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1525 priv->destination_row = gtk_tree_row_reference_new (model, path);
1527 accounts_dialog_show_question_dialog (dialog,
1528 question_dialog_primary_text,
1529 _("You are about to select another account, which will discard\n"
1530 "your changes. Are you sure you want to proceed?"),
1531 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1533 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1534 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1536 g_free (question_dialog_primary_text);
1544 if (account != NULL)
1545 g_object_unref (account);
1551 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1553 GtkListStore *store;
1554 GtkTreeSelection *selection;
1555 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1557 store = gtk_list_store_new (COL_COUNT,
1558 G_TYPE_STRING, /* name */
1559 G_TYPE_UINT, /* status */
1560 TP_TYPE_ACCOUNT, /* account */
1561 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1563 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1564 GTK_TREE_MODEL (store));
1566 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1567 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1568 gtk_tree_selection_set_select_function (selection,
1569 accounts_dialog_account_selection_change, dialog, NULL);
1571 g_signal_connect (selection, "changed",
1572 G_CALLBACK (accounts_dialog_model_selection_changed),
1575 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1576 COL_NAME, GTK_SORT_ASCENDING);
1578 accounts_dialog_model_add_columns (dialog);
1580 g_object_unref (store);
1584 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1589 GtkTreeModel *model;
1591 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1593 /* Update the status in the model */
1594 view = GTK_TREE_VIEW (priv->treeview);
1595 model = gtk_tree_view_get_model (view);
1597 for (ok = gtk_tree_model_get_iter_first (model, iter);
1599 ok = gtk_tree_model_iter_next (model, iter))
1601 TpAccount *this_account;
1604 gtk_tree_model_get (model, iter,
1605 COL_ACCOUNT, &this_account,
1608 equal = (this_account == account);
1609 g_object_unref (this_account);
1619 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1622 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1623 GtkTreeSelection *selection;
1625 GtkTreeModel *model;
1627 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1629 gtk_tree_selection_select_iter (selection, iter);
1631 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1632 path = gtk_tree_model_get_path (model, iter);
1634 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1637 gtk_tree_path_free (path);
1641 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1646 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1647 select_and_scroll_to_iter (dialog, &iter);
1651 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1656 enabled = tp_account_is_enabled (account);
1657 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1661 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1662 GdkEventButton *event,
1663 EmpathyAccountsDialog *dialog)
1665 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1666 TpAccount *account = NULL;
1667 GtkTreeModel *model = NULL;
1668 GtkTreePath *path = NULL;
1671 GtkWidget *item_enable, *item_disable;
1672 GtkWidget *image_enable, *image_disable;
1674 /* ignore multiple clicks */
1675 if (event->type != GDK_BUTTON_PRESS)
1678 if (event->button != 3)
1681 /* Selection is not yet set, so we have to get account from event position */
1682 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1683 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1684 event->x, event->y, &path, NULL, NULL, NULL))
1687 if (!gtk_tree_model_get_iter (model, &iter, path))
1690 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1692 /* Create the menu */
1693 menu = empathy_context_menu_new (GTK_WIDGET (view));
1695 /* Get images for menu items */
1696 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1697 tp_account_manager_get_most_available_presence (
1698 priv->account_manager, NULL, NULL)),
1699 GTK_ICON_SIZE_MENU);
1700 image_disable = gtk_image_new_from_icon_name (
1701 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1702 GTK_ICON_SIZE_MENU);
1704 /* Menu items: to enabled/disable the account */
1705 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1706 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1707 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1709 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1712 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1713 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1715 if (tp_account_is_enabled (account))
1717 tp_g_signal_connect_object (item_disable, "activate",
1718 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1719 gtk_widget_set_sensitive (item_enable, FALSE);
1723 tp_g_signal_connect_object (item_enable, "activate",
1724 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1725 gtk_widget_set_sensitive (item_disable, FALSE);
1728 gtk_widget_show (item_enable);
1729 gtk_widget_show (item_disable);
1731 /* FIXME: Add here presence items, to be able to set per-account presence */
1734 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1735 event->button, event->time);
1738 tp_clear_object (&account);
1739 gtk_tree_path_free (path);
1745 accounts_dialog_connection_changed_cb (TpAccount *account,
1749 gchar *dbus_error_name,
1750 GHashTable *details,
1751 EmpathyAccountsDialog *dialog)
1753 GtkTreeModel *model;
1756 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1758 /* Update the status-infobar in the details view */
1759 accounts_dialog_update_status_infobar (dialog, account);
1761 /* Update the status in the model */
1762 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1764 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1768 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1769 COL_STATUS, current,
1772 path = gtk_tree_model_get_path (model, &iter);
1773 gtk_tree_model_row_changed (model, path, &iter);
1774 gtk_tree_path_free (path);
1777 empathy_account_manager_get_accounts_connected (&found);
1779 if (!found && priv->connecting_id)
1781 g_source_remove (priv->connecting_id);
1782 priv->connecting_id = 0;
1785 if (found && !priv->connecting_id)
1786 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1787 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1792 update_account_in_treeview (EmpathyAccountsDialog *self,
1795 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1797 GtkTreeModel *model;
1799 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1800 if (accounts_dialog_get_account_iter (self, account, &iter))
1804 path = gtk_tree_model_get_path (model, &iter);
1805 gtk_tree_model_row_changed (model, path, &iter);
1806 gtk_tree_path_free (path);
1811 accounts_dialog_presence_changed_cb (TpAccount *account,
1814 gchar *status_message,
1815 EmpathyAccountsDialog *dialog)
1817 /* Update the status-infobar in the details view */
1818 accounts_dialog_update_status_infobar (dialog, account);
1820 update_account_in_treeview (dialog, account);
1824 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1828 const gchar *display_name;
1830 GtkTreeModel *model;
1831 EmpathyAccountSettings *settings;
1832 TpAccount *selected_account;
1833 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1834 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1836 display_name = tp_account_get_display_name (account);
1837 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1838 settings = accounts_dialog_model_get_selected_settings (dialog);
1839 if (settings == NULL)
1842 selected_account = empathy_account_settings_get_account (settings);
1844 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1846 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1847 COL_NAME, display_name,
1851 if (selected_account == account)
1852 accounts_dialog_update_name_label (dialog, display_name);
1854 g_object_unref (settings);
1858 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1861 EmpathyAccountSettings *settings;
1862 GtkTreeModel *model;
1864 TpConnectionStatus status;
1866 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1867 gboolean selected = FALSE;
1869 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1870 status = tp_account_get_connection_status (account, NULL);
1871 name = tp_account_get_display_name (account);
1873 settings = empathy_account_settings_new_for_account (account);
1875 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1877 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1881 GtkTreeSelection *selection;
1883 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1884 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1887 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1890 COL_ACCOUNT, account,
1891 COL_ACCOUNT_SETTINGS, settings,
1896 /* We just modified the selected account. Its display name may have been
1897 * changed and so it's place in the treeview. Scroll to it so it stays
1899 select_and_scroll_to_iter (dialog, &iter);
1902 accounts_dialog_connection_changed_cb (account,
1905 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1910 tp_g_signal_connect_object (account, "notify::display-name",
1911 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1914 tp_g_signal_connect_object (account, "status-changed",
1915 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1916 tp_g_signal_connect_object (account, "presence-changed",
1917 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1919 g_object_unref (settings);
1923 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1926 EmpathyAccountsDialog *dialog)
1928 accounts_dialog_add_account (dialog, account);
1932 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1935 EmpathyAccountsDialog *dialog)
1937 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1939 if (priv->setting_widget_object != NULL &&
1940 accounts_dialog_has_valid_accounts (dialog))
1942 empathy_account_widget_set_other_accounts_exist (
1943 priv->setting_widget_object, TRUE);
1948 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1950 EmpathyAccountsDialog *dialog)
1952 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1954 if (priv->setting_widget_object != NULL &&
1955 !accounts_dialog_has_valid_accounts (dialog))
1957 empathy_account_widget_set_other_accounts_exist (
1958 priv->setting_widget_object, FALSE);
1963 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1965 EmpathyAccountsDialog *dialog)
1968 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1970 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1972 gtk_list_store_remove (GTK_LIST_STORE (
1973 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1978 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1982 /* Update the status-infobar in the details view */
1983 accounts_dialog_update_status_infobar (dialog, account);
1985 DEBUG ("Account %s is now %s",
1986 tp_account_get_display_name (account),
1987 enabled ? "enabled" : "disabled");
1991 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1993 EmpathyAccountsDialog *dialog)
1995 enable_or_disable_account (dialog, account, FALSE);
1996 update_account_in_treeview (dialog, account);
2000 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
2002 EmpathyAccountsDialog *dialog)
2004 enable_or_disable_account (dialog, account, TRUE);
2008 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2009 EmpathyAccountsDialog *dialog)
2011 GtkWidget *import_dialog;
2013 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2015 gtk_widget_show (import_dialog);
2019 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2023 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2025 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2027 if (response_id == GTK_RESPONSE_YES)
2028 gtk_widget_destroy (account_dialog);
2032 accounts_dialog_delete_event_cb (GtkWidget *widget,
2034 EmpathyAccountsDialog *dialog)
2036 /* we maunally handle responses to delete events */
2041 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2046 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2047 select_and_scroll_to_iter (dialog, &iter);
2051 finished_loading (EmpathyAccountsDialog *self)
2053 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2054 GtkTreeSelection *selection;
2055 gboolean has_selected;
2057 priv->loading = FALSE;
2059 gtk_widget_set_sensitive (priv->button_add, TRUE);
2060 gtk_widget_set_sensitive (priv->button_import, TRUE);
2061 gtk_widget_set_sensitive (priv->treeview, TRUE);
2063 /* Sensitive the remove button if there is an account selected */
2064 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2065 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2066 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2068 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2069 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2070 NOTEBOOK_PAGE_ACCOUNT);
2074 accounts_dialog_cms_prepare_cb (GObject *source,
2075 GAsyncResult *result,
2078 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
2079 EmpathyAccountsDialog *dialog = user_data;
2080 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2082 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
2085 /* No need to update the settings if we are already preparing one */
2086 if (priv->settings_ready == NULL)
2087 accounts_dialog_update_settings (dialog, NULL);
2089 if (priv->initial_selection != NULL)
2091 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2092 g_object_unref (priv->initial_selection);
2093 priv->initial_selection = NULL;
2097 finished_loading (dialog);
2101 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2104 GList *accounts, *l;
2106 g_signal_connect (priv->account_manager, "account-validity-changed",
2107 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2109 g_signal_connect (priv->account_manager, "account-removed",
2110 G_CALLBACK (accounts_dialog_account_removed_cb),
2112 g_signal_connect (priv->account_manager, "account-enabled",
2113 G_CALLBACK (accounts_dialog_account_enabled_cb),
2115 g_signal_connect (priv->account_manager, "account-disabled",
2116 G_CALLBACK (accounts_dialog_account_disabled_cb),
2119 /* Add existing accounts */
2120 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
2121 for (l = accounts; l; l = l->next)
2123 accounts_dialog_add_account (dialog, l->data);
2125 g_list_free (accounts);
2127 priv->cms = empathy_connection_managers_dup_singleton ();
2129 empathy_connection_managers_prepare_async (priv->cms,
2130 accounts_dialog_cms_prepare_cb, dialog);
2132 accounts_dialog_model_select_first (dialog);
2136 accounts_dialog_manager_ready_cb (GObject *source_object,
2137 GAsyncResult *result,
2140 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2141 GError *error = NULL;
2143 if (!tp_proxy_prepare_finish (manager, result, &error))
2145 DEBUG ("Failed to prepare account manager: %s", error->message);
2146 g_error_free (error);
2150 accounts_dialog_accounts_setup (user_data);
2154 dialog_response_cb (GtkWidget *widget,
2158 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2160 if (response_id == GTK_RESPONSE_HELP)
2162 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2164 else if (response_id == GTK_RESPONSE_CLOSE ||
2165 response_id == GTK_RESPONSE_DELETE_EVENT)
2167 TpAccount *account = NULL;
2169 if (accounts_dialog_has_pending_change (dialog, &account))
2171 gchar *question_dialog_primary_text = get_dialog_primary_text (
2174 accounts_dialog_show_question_dialog (dialog,
2175 question_dialog_primary_text,
2176 _("You are about to close the window, which will discard\n"
2177 "your changes. Are you sure you want to proceed?"),
2178 G_CALLBACK (accounts_dialog_close_response_cb),
2180 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2181 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2183 g_free (question_dialog_primary_text);
2187 gtk_widget_destroy (widget);
2190 if (account != NULL)
2191 g_object_unref (account);
2196 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2198 GtkWidget *top_hbox;
2201 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2202 GtkWidget *content_area, *action_area;
2203 GtkWidget *grid, *hbox;
2205 GtkWidget *sw, *toolbar;
2206 GtkStyleContext *context;
2208 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2210 gui = empathy_builder_get_file (filename,
2211 "accounts_dialog_hbox", &top_hbox,
2212 "vbox_details", &priv->vbox_details,
2213 "frame_no_protocol", &priv->frame_no_protocol,
2214 "alignment_settings", &priv->alignment_settings,
2215 "alignment_infobar", &priv->alignment_infobar,
2216 "treeview", &priv->treeview,
2217 "button_add", &priv->button_add,
2218 "button_remove", &priv->button_remove,
2219 "button_import", &priv->button_import,
2220 "hbox_protocol", &priv->hbox_protocol,
2221 "notebook_account", &priv->notebook_account,
2222 "alignment_loading", &alig,
2224 "add_remove_toolbar", &toolbar,
2228 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2230 empathy_builder_connect (gui, dialog,
2231 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2232 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2233 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2234 "treeview", "button-press-event",
2235 accounts_dialog_treeview_button_press_event_cb,
2238 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2240 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2242 g_object_unref (gui);
2244 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2247 gtk_widget_hide (action_area);
2248 gtk_widget_hide (priv->button_remove);
2249 #endif /* HAVE_MEEGO */
2251 /* Display loading page */
2252 priv->loading = TRUE;
2254 priv->spinner = gtk_spinner_new ();
2256 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2257 gtk_widget_show (priv->spinner);
2259 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2261 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2262 NOTEBOOK_PAGE_LOADING);
2264 /* Remove button is insensitive until we have a selected account */
2265 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2267 /* Add and Import buttons and treeview are insensitive while the dialog
2269 gtk_widget_set_sensitive (priv->button_add, FALSE);
2270 gtk_widget_set_sensitive (priv->button_import, FALSE);
2271 gtk_widget_set_sensitive (priv->treeview, FALSE);
2273 if (priv->parent_window)
2274 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2275 priv->parent_window);
2277 priv->infobar = gtk_info_bar_new ();
2278 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2280 gtk_widget_show (priv->infobar);
2282 grid = gtk_grid_new ();
2284 GTK_CONTAINER (gtk_info_bar_get_content_area (
2285 GTK_INFO_BAR (priv->infobar))),
2288 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2289 GTK_ICON_SIZE_DIALOG);
2290 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2291 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2294 priv->label_name = gtk_label_new (NULL);
2295 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2298 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2299 gtk_widget_set_hexpand (hbox, TRUE);
2300 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2301 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2303 /* set up spinner */
2304 priv->throbber = gtk_spinner_new ();
2306 priv->image_status = gtk_image_new_from_icon_name (
2307 empathy_icon_name_for_presence (
2308 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2310 priv->label_status = gtk_label_new (NULL);
2311 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2313 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2314 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2315 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2317 /* enabled switch */
2318 priv->enabled_switch = gtk_switch_new ();
2319 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2320 g_signal_connect (priv->enabled_switch, "notify::active",
2321 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2322 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2324 gtk_widget_show_all (grid);
2326 /* Tweak the dialog */
2327 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2328 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2330 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2332 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2334 /* join the add/remove toolbar to the treeview */
2335 context = gtk_widget_get_style_context (sw);
2336 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2338 context = gtk_widget_get_style_context (toolbar);
2339 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2341 /* add dialog buttons */
2342 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2344 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2345 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2346 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2349 g_signal_connect (dialog, "response",
2350 G_CALLBACK (dialog_response_cb), dialog);
2352 g_signal_connect (dialog, "delete-event",
2353 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2357 do_dispose (GObject *obj)
2359 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2360 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2362 if (priv->connecting_id != 0)
2364 g_source_remove (priv->connecting_id);
2365 priv->connecting_id = 0;
2368 if (priv->account_manager != NULL)
2370 g_object_unref (priv->account_manager);
2371 priv->account_manager = NULL;
2374 if (priv->cms != NULL)
2376 g_object_unref (priv->cms);
2380 if (priv->connectivity)
2382 g_object_unref (priv->connectivity);
2383 priv->connectivity = NULL;
2386 if (priv->initial_selection != NULL)
2388 g_object_unref (priv->initial_selection);
2389 priv->initial_selection = NULL;
2392 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2396 do_get_property (GObject *object,
2401 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2403 switch (property_id)
2406 g_value_set_object (value, priv->parent_window);
2409 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2414 do_set_property (GObject *object,
2416 const GValue *value,
2419 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2421 switch (property_id)
2424 priv->parent_window = g_value_get_object (value);
2427 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2432 do_constructed (GObject *object)
2434 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2435 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2436 GtkTreeModel *model;
2438 accounts_dialog_build_ui (dialog);
2439 accounts_dialog_model_setup (dialog);
2441 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2442 g_signal_connect (model, "row-inserted",
2443 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2444 g_signal_connect (model, "row-deleted",
2445 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2447 /* Set up signalling */
2448 priv->account_manager = tp_account_manager_dup ();
2450 tp_proxy_prepare_async (priv->account_manager, NULL,
2451 accounts_dialog_manager_ready_cb, dialog);
2453 priv->connectivity = empathy_connectivity_dup_singleton ();
2457 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2459 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2460 GParamSpec *param_spec;
2462 oclass->dispose = do_dispose;
2463 oclass->constructed = do_constructed;
2464 oclass->set_property = do_set_property;
2465 oclass->get_property = do_get_property;
2467 param_spec = g_param_spec_object ("parent",
2468 "parent", "The parent window",
2470 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2471 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2473 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2477 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2479 EmpathyAccountsDialogPriv *priv;
2481 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2482 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2483 EmpathyAccountsDialogPriv);
2484 dialog->priv = priv;
2487 /* public methods */
2490 empathy_accounts_dialog_show (GtkWindow *parent,
2491 TpAccount *selected_account)
2493 EmpathyAccountsDialog *dialog;
2494 EmpathyAccountsDialogPriv *priv;
2496 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2497 "parent", parent, NULL);
2499 priv = GET_PRIV (dialog);
2501 if (selected_account)
2503 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2504 accounts_dialog_set_selected_account (dialog, selected_account);
2506 /* save the selection to set it later when the cms
2509 priv->initial_selection = g_object_ref (selected_account);
2512 gtk_window_present (GTK_WINDOW (dialog));
2514 return GTK_WIDGET (dialog);
2518 empathy_accounts_dialog_show_application (GdkScreen *screen,
2519 TpAccount *selected_account,
2525 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2527 args = g_string_new (NULL);
2529 if (selected_account != NULL)
2530 g_string_append_printf (args, " --select-account=%s",
2531 tp_account_get_path_suffix (selected_account));
2534 g_string_append_printf (args, " --if-needed");
2537 g_string_append_printf (args, " --hidden");
2539 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2541 selected_account == NULL ? "<none selected>" :
2542 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2544 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2546 g_string_free (args, TRUE);
2550 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2552 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2553 gboolean result = FALSE;
2555 if (priv->setting_widget_object == NULL)
2558 g_object_get (priv->setting_widget_object,
2559 "creating-account", &result, NULL);