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>
28 #include "empathy-accounts-dialog.h"
30 #include <glib/gi18n-lib.h>
31 #include <tp-account-widgets/tpaw-account-widget.h>
32 #include <tp-account-widgets/tpaw-builder.h>
33 #include <tp-account-widgets/tpaw-user-info.h>
34 #include <tp-account-widgets/tpaw-pixbuf-utils.h>
35 #include <tp-account-widgets/tpaw-utils.h>
37 #include "empathy-accounts-common.h"
38 #include "empathy-import-dialog.h"
39 #include "empathy-import-utils.h"
40 #include "empathy-local-xmpp-assistant-widget.h"
41 #include "empathy-new-account-dialog.h"
42 #include "empathy-pkg-kit.h"
43 #include "empathy-ui-utils.h"
44 #include "empathy-utils.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
47 #include "empathy-debug.h"
49 /* Flashing delay for icons (milliseconds). */
50 #define FLASH_TIMEOUT 500
52 /* The primary text of the dialog shown to the user when he is about to lose
54 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
55 _("There are unsaved modifications to your %.50s account.")
56 /* The primary text of the dialog shown to the user when he is about to lose
57 * an unsaved new account */
58 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
59 _("Your new account has not been saved yet.")
61 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
62 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
66 NOTEBOOK_PAGE_ACCOUNT = 0,
67 NOTEBOOK_PAGE_LOADING,
68 NOTEBOOK_PAGE_NO_PROTOCOL
72 GtkWidget *alignment_settings;
73 GtkWidget *alignment_infobar;
75 GtkWidget *vbox_details;
77 GtkWidget *label_status;
78 GtkWidget *image_status;
80 GtkWidget *enabled_switch;
83 GtkCellRenderer *name_renderer;
85 GtkWidget *button_add;
86 GtkWidget *button_remove;
87 GtkWidget *button_import;
89 GtkWidget *image_type;
90 GtkWidget *label_name;
91 GtkWidget *label_type;
92 GtkWidget *dialog_content;
95 GtkWidget *notebook_account;
99 /* We have to keep a weak reference on the actual TpawAccountWidget, not
100 * just its GtkWidget. It is the only reliable source we can query to know if
101 * there are any unsaved changes to the currently selected account. We can't
102 * look at the account settings because it does not contain everything that
103 * can be changed using the TpawAccountWidget. For instance, it does not
104 * contain the state of the "Enabled" checkbox.
106 * Even if we create it ourself, we just get a weak ref and not a strong one
107 * as TpawAccountWidget unrefs itself when the GtkWidget is destroyed.
108 * That's kinda ugly; cf bgo #640417.
111 TpawAccountWidget *setting_widget;
113 gboolean connecting_show;
116 gulong settings_ready_id;
117 TpawAccountSettings *settings_ready;
119 TpAccountManager *account_manager;
120 TpawConnectionManagers *cms;
121 GNetworkMonitor *connectivity;
123 GtkWindow *parent_window;
124 TpAccount *initial_selection;
126 /* Those are needed when changing the selected row. When a user selects
127 * another account and there are unsaved changes on the currently selected
128 * one, a confirmation message box is presented to him. Since his answer
129 * is retrieved asynchronously, we keep some information as member of the
130 * EmpathyAccountsDialog object. */
131 gboolean force_change_row;
132 GtkTreeRowReference *destination_row;
134 GHashTable *icons_cache;
135 } EmpathyAccountsDialogPriv;
141 COL_ACCOUNT_SETTINGS,
149 static TpawAccountSettings * accounts_dialog_model_get_selected_settings (
150 EmpathyAccountsDialog *dialog);
152 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
155 TpawAccountSettings *settings);
157 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
160 static void accounts_dialog_connection_changed_cb (TpAccount *account,
164 gchar *dbus_error_name,
166 EmpathyAccountsDialog *dialog);
168 static void accounts_dialog_presence_changed_cb (TpAccount *account,
171 gchar *status_message,
172 EmpathyAccountsDialog *dialog);
174 static void accounts_dialog_model_selection_changed (
175 GtkTreeSelection *selection,
176 EmpathyAccountsDialog *dialog);
178 static gboolean accounts_dialog_has_pending_change (
179 EmpathyAccountsDialog *dialog, TpAccount **account);
182 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
183 const gchar *message)
185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
186 gchar *message_markup;
188 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
189 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
191 gtk_widget_set_tooltip_text (priv->label_status, message);
193 g_free (message_markup);
197 accounts_dialog_enable_account_cb (GObject *object,
198 GAsyncResult *result,
201 TpAccount *account = TP_ACCOUNT (object);
202 gboolean enable = GPOINTER_TO_UINT (user_data);
203 GError *error = NULL;
204 TpAccountManager *am;
206 if (!tp_account_set_enabled_finish (account, result, &error))
208 DEBUG ("Could not enable the account: %s", error->message);
209 g_error_free (error);
213 /* tp_account_is_enabled() is not updated yet at this point */
216 am = tp_account_manager_dup ();
218 tpaw_connect_new_account (account, am);
224 enable_and_connect_account (TpAccount *account,
227 tp_account_set_enabled_async (account, enable,
228 accounts_dialog_enable_account_cb, GUINT_TO_POINTER (enable));
232 accounts_dialog_enable_switch_active_cb (GtkSwitch *sw,
234 EmpathyAccountsDialog *dialog)
236 TpawAccountSettings *settings;
240 settings = accounts_dialog_model_get_selected_settings (dialog);
241 if (settings == NULL)
244 account = tpaw_account_settings_get_account (settings);
248 enable = gtk_switch_get_active (sw);
250 enable_and_connect_account (account, enable);
254 install_haze_cb (GObject *source,
255 GAsyncResult *result,
258 GError *error = NULL;
260 if (!empathy_pkg_kit_install_packages_finish (result, &error))
262 DEBUG ("Failed to install telepathy-haze: %s", error->message);
264 g_error_free (error);
269 account_is_selected (EmpathyAccountsDialog *dialog,
272 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
273 GtkTreeSelection *selection;
276 TpAccount *selected_account;
281 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
283 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
286 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
288 if (selected_account != NULL)
289 g_object_unref (selected_account);
291 return account == selected_account;
295 account_can_be_enabled (TpAccount *account)
297 TpStorageRestrictionFlags storage_restrictions;
299 storage_restrictions = tp_account_get_storage_restrictions (account);
300 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED)
303 /* Butterfly accounts shouldn't be used any more */
304 if (!tp_strdiff (tp_account_get_cm_name (account),
312 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
315 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
316 gchar *status_message = NULL;
320 gboolean account_enabled;
321 gboolean creating_account;
322 gboolean display_switch = TRUE;
324 /* do not update the infobar when the account is not selected */
325 if (!account_is_selected (dialog, account))
332 status = tp_account_get_connection_status (account, &reason);
333 presence = tp_account_get_current_presence (account, NULL, &status_message);
334 account_enabled = tp_account_is_enabled (account);
335 creating_account = FALSE;
337 if (status == TP_CONNECTION_STATUS_CONNECTED &&
338 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
339 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
340 /* If presence is Unset (CM doesn't implement SimplePresence) but we
341 * are connected, consider ourself as Available.
342 * We also check Offline because of this MC5 bug: fd.o #26060 */
343 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
345 /* set presence to offline if account is disabled
346 * (else no icon is shown in infobar)*/
347 if (!account_enabled)
348 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
350 display_switch = account_can_be_enabled (account);
352 text = g_markup_printf_escaped ("<b>%.50s</b>",
353 tp_account_get_display_name (account));
354 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
359 status = TP_CONNECTION_STATUS_DISCONNECTED;
360 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
361 account_enabled = FALSE;
362 creating_account = TRUE;
365 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
366 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
368 /* update the enabled switch */
369 g_signal_handlers_block_by_func (priv->enabled_switch,
370 accounts_dialog_enable_switch_active_cb, dialog);
371 gtk_switch_set_active (GTK_SWITCH (priv->enabled_switch),
373 g_signal_handlers_unblock_by_func (priv->enabled_switch,
374 accounts_dialog_enable_switch_active_cb, dialog);
376 /* Display the Enable switch if account supports it */
377 gtk_widget_set_visible (priv->enabled_switch, display_switch);
383 case TP_CONNECTION_STATUS_CONNECTING:
384 accounts_dialog_status_infobar_set_message (dialog,
386 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
389 gtk_spinner_start (GTK_SPINNER (priv->throbber));
390 gtk_widget_show (priv->throbber);
391 gtk_widget_hide (priv->image_status);
393 case TP_CONNECTION_STATUS_CONNECTED:
394 if (g_strcmp0 (status_message, "") == 0)
398 message = g_strdup_printf ("%s",
399 empathy_presence_get_default_message (presence));
401 accounts_dialog_status_infobar_set_message (dialog, message);
408 message = g_strdup_printf ("%s — %s",
409 empathy_presence_get_default_message (presence),
412 accounts_dialog_status_infobar_set_message (dialog, message);
415 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
418 gtk_widget_show (priv->image_status);
419 gtk_widget_hide (priv->throbber);
421 case TP_CONNECTION_STATUS_DISCONNECTED:
422 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
426 message = g_strdup_printf (_("Offline — %s"),
427 empathy_account_get_error_message (account, NULL));
428 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
429 GTK_MESSAGE_WARNING);
431 accounts_dialog_status_infobar_set_message (dialog, message);
438 message = g_strdup_printf (_("Disconnected — %s"),
439 empathy_account_get_error_message (account, NULL));
440 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
443 accounts_dialog_status_infobar_set_message (dialog, message);
447 if (!g_network_monitor_get_network_available (priv->connectivity))
448 accounts_dialog_status_infobar_set_message (dialog,
449 _("Offline — No Network Connection"));
451 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
452 gtk_widget_show (priv->image_status);
453 gtk_widget_hide (priv->throbber);
456 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
457 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
458 GTK_MESSAGE_WARNING);
460 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
461 gtk_widget_hide (priv->image_status);
462 gtk_widget_hide (priv->throbber);
467 if (!tp_strdiff (tp_account_get_cm_name (account),
470 const gchar *packages[] = { "telepathy-haze", NULL };
472 accounts_dialog_status_infobar_set_message (dialog,
473 _("This account has been disabled because it relies on an old, "
474 "unsupported backend. Please install telepathy-haze and "
475 "restart your session to migrate the account."));
477 empathy_pkg_kit_install_packages_async (0, packages, NULL, NULL,
478 install_haze_cb, NULL);
482 accounts_dialog_status_infobar_set_message (dialog,
483 _("Offline — Account Disabled"));
486 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
487 GTK_MESSAGE_WARNING);
488 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
489 gtk_widget_show (priv->image_status);
490 gtk_widget_hide (priv->throbber);
493 gtk_widget_show (priv->label_status);
495 if (!creating_account)
496 gtk_widget_show (priv->infobar);
498 gtk_widget_hide (priv->infobar);
500 g_free (status_message);
504 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
508 GtkTreeSelection *selection;
510 TpawAccountSettings *settings;
512 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
514 view = GTK_TREE_VIEW (priv->treeview);
515 selection = gtk_tree_view_get_selection (view);
517 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
520 gtk_tree_model_get (model, &iter,
521 COL_ACCOUNT_SETTINGS, &settings,
522 COL_ACCOUNT, &account, -1);
524 tpaw_account_widget_discard_pending_changes (priv->setting_widget);
528 /* We were creating an account. We remove the selected row */
529 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
533 /* We were modifying an account. We discard the changes by reloading the
534 * settings and the UI. */
535 accounts_dialog_update_settings (dialog, settings);
536 g_object_unref (account);
539 gtk_widget_set_sensitive (priv->treeview, TRUE);
540 gtk_widget_set_sensitive (priv->button_add, TRUE);
541 gtk_widget_set_sensitive (priv->button_remove, TRUE);
542 gtk_widget_set_sensitive (priv->button_import, TRUE);
544 if (settings != NULL)
545 g_object_unref (settings);
549 empathy_account_dialog_widget_cancelled_cb (
550 TpawAccountWidget *widget_object,
551 EmpathyAccountsDialog *dialog)
553 empathy_account_dialog_cancel (dialog);
557 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
559 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
564 g_object_get (priv->setting_widget,
565 "creating-account", &creating, NULL);
570 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
572 if (gtk_tree_model_get_iter_first (model, &iter))
573 return gtk_tree_model_iter_next (model, &iter);
579 account_dialog_create_edit_params_dialog (EmpathyAccountsDialog *dialog)
581 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
582 TpawAccountSettings *settings;
583 GtkWidget *subdialog, *content_area, *align;
585 settings = accounts_dialog_model_get_selected_settings (dialog);
586 if (settings == NULL)
589 subdialog = gtk_dialog_new_with_buttons (_("Edit Connection Parameters"),
591 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
594 gtk_window_set_resizable (GTK_WINDOW (subdialog), FALSE);
596 priv->setting_widget = (TpawAccountWidget *)
597 tpaw_account_widget_new_for_protocol (settings, NULL, FALSE);
599 g_object_add_weak_pointer (G_OBJECT (priv->setting_widget),
600 (gpointer *) &priv->setting_widget);
602 if (accounts_dialog_has_valid_accounts (dialog))
603 tpaw_account_widget_set_other_accounts_exist (
604 priv->setting_widget, TRUE);
606 g_signal_connect (priv->setting_widget, "cancelled",
607 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
609 g_signal_connect_swapped (priv->setting_widget, "close",
610 G_CALLBACK (gtk_widget_destroy), subdialog);
612 content_area = gtk_dialog_get_content_area (GTK_DIALOG (subdialog));
614 align = gtk_alignment_new (0.5, 0.5, 1, 1);
615 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 6, 0, 6, 6);
617 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (priv->setting_widget));
618 gtk_box_pack_start (GTK_BOX (content_area), align, TRUE, TRUE, 0);
620 gtk_widget_show (GTK_WIDGET (priv->setting_widget));
621 gtk_widget_show (align);
622 gtk_widget_show (subdialog);
626 use_external_storage_provider (EmpathyAccountsDialog *self,
629 const gchar *provider;
631 provider = tp_account_get_storage_provider (account);
632 if (!tp_strdiff (provider, "com.meego.libsocialweb"))
634 empathy_launch_external_app ("gnome-control-center.desktop",
635 "bisho.desktop", NULL);
638 else if (!tp_strdiff (provider, EMPATHY_GOA_PROVIDER))
640 empathy_launch_external_app ("gnome-online-accounts-panel.desktop",
644 else if (!tp_strdiff (provider, EMPATHY_UOA_PROVIDER))
646 empathy_launch_external_app ("gnome-credentials-panel.desktop",
652 DEBUG ("Don't know how to handle %s", provider);
658 account_dialow_show_edit_params_dialog (EmpathyAccountsDialog *dialog,
661 TpawAccountSettings *settings;
663 TpStorageRestrictionFlags storage_restrictions;
665 settings = accounts_dialog_model_get_selected_settings (dialog);
666 if (settings == NULL)
669 account = tpaw_account_settings_get_account (settings);
670 g_return_if_fail (account != NULL);
672 storage_restrictions = tp_account_get_storage_restrictions (account);
674 /* Empathy can only edit accounts without the Cannot_Set_Parameters flag */
675 if (storage_restrictions & TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS)
677 DEBUG ("Account is provided by an external storage provider");
679 use_external_storage_provider (dialog, account);
683 account_dialog_create_edit_params_dialog (dialog);
688 account_dialog_create_dialog_content (EmpathyAccountsDialog *dialog,
689 TpawAccountSettings *settings)
691 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
692 const gchar *icon_name;
694 GtkWidget *bbox, *button;
697 account = tpaw_account_settings_get_account (settings);
699 priv->dialog_content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
700 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
701 priv->dialog_content);
702 gtk_widget_show (priv->dialog_content);
704 alig = gtk_alignment_new (0.5, 0, 1, 1);
705 priv->user_info = tpaw_user_info_new (account);
706 gtk_container_add (GTK_CONTAINER (alig), priv->user_info);
707 gtk_box_pack_start (GTK_BOX (priv->dialog_content), alig, TRUE, TRUE, 0);
708 gtk_widget_show (alig);
709 gtk_widget_show (priv->user_info);
711 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
712 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
713 gtk_box_pack_end (GTK_BOX (priv->dialog_content), bbox, FALSE, TRUE, 0);
714 gtk_widget_show (bbox);
716 button = gtk_button_new_with_mnemonic (_("_Edit Connection Parameters…"));
717 gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, TRUE, 0);
718 gtk_widget_show (button);
719 g_signal_connect_swapped (button, "clicked",
720 G_CALLBACK (account_dialow_show_edit_params_dialog), dialog);
722 icon_name = tpaw_account_settings_get_icon_name (settings);
724 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
726 /* show the default icon; keep this in sync with the default
727 * one in empathy-accounts-dialog.ui.
729 icon_name = GTK_STOCK_CUT;
731 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
732 icon_name, GTK_ICON_SIZE_DIALOG);
733 gtk_widget_set_tooltip_text (priv->image_type,
734 tpaw_protocol_name_to_display_name
735 (tpaw_account_settings_get_protocol (settings)));
736 gtk_widget_show (priv->image_type);
738 accounts_dialog_update_status_infobar (dialog, account);
742 account_dialog_settings_ready_cb (TpawAccountSettings *settings,
744 EmpathyAccountsDialog *dialog)
746 if (tpaw_account_settings_is_ready (settings))
747 account_dialog_create_dialog_content (dialog, settings);
751 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
755 GtkTreeSelection *selection;
757 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
760 view = GTK_TREE_VIEW (priv->treeview);
761 model = gtk_tree_view_get_model (view);
763 if (gtk_tree_model_get_iter_first (model, &iter))
765 selection = gtk_tree_view_get_selection (view);
766 gtk_tree_selection_select_iter (selection, &iter);
770 accounts_dialog_update_settings (dialog, NULL);
775 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
780 GtkTreeSelection *selection;
781 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
783 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
785 if (gtk_tree_selection_get_selected (selection, &model, &iter))
786 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
788 return priv->setting_widget != NULL
789 && tpaw_account_widget_contains_pending_changes (
790 priv->setting_widget);
794 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
795 const gchar *primary_text,
796 const gchar *secondary_text,
797 GCallback response_callback,
799 const gchar *first_button_text,
803 GtkWidget *message_dialog;
804 const gchar *button_text;
806 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
807 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
808 GTK_MESSAGE_QUESTION,
812 gtk_message_dialog_format_secondary_text (
813 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
815 va_start (button_args, first_button_text);
816 for (button_text = first_button_text;
818 button_text = va_arg (button_args, const gchar *))
821 response_id = va_arg (button_args, gint);
823 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
826 va_end (button_args);
828 g_signal_connect (message_dialog, "response", response_callback, user_data);
830 gtk_widget_show (message_dialog);
834 get_dialog_primary_text (TpAccount *account)
838 /* Existing account */
839 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
840 tp_account_get_display_name (account));
844 /* Newly created account */
845 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
850 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
851 EmpathyAccountsDialog *self)
856 dialog = empathy_new_account_dialog_new (GTK_WINDOW (self));
857 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
859 response = gtk_dialog_run (GTK_DIALOG (dialog));
861 if (response == GTK_RESPONSE_APPLY)
863 TpawAccountSettings *settings;
866 settings = empathy_new_account_dialog_get_settings (
867 EMPATHY_NEW_ACCOUNT_DIALOG (dialog));
869 /* The newly created account has already been added by
870 * accounts_dialog_account_validity_changed_cb so we just
871 * have to select it. */
872 account = tpaw_account_settings_get_account (settings);
873 accounts_dialog_model_set_selected (self, account);
876 gtk_widget_destroy (dialog);
880 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
881 TpawAccountSettings *settings)
883 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
885 if (priv->settings_ready != NULL)
887 g_signal_handler_disconnect (priv->settings_ready,
888 priv->settings_ready_id);
889 priv->settings_ready = NULL;
890 priv->settings_ready_id = 0;
897 GtkTreeSelection *selection;
899 view = GTK_TREE_VIEW (priv->treeview);
900 model = gtk_tree_view_get_model (view);
901 selection = gtk_tree_view_get_selection (view);
903 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
905 /* We have configured accounts, select the first one if there
906 * is no other account selected already. */
907 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
908 accounts_dialog_model_select_first (dialog);
913 /* No account selected */
914 gtk_widget_hide (priv->vbox_details);
915 gtk_widget_set_sensitive (priv->button_add, TRUE);
916 gtk_widget_set_sensitive (priv->button_remove, FALSE);
918 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
919 NOTEBOOK_PAGE_NO_PROTOCOL);
923 /* We have an account selected, destroy old settings and create a new
924 * one for the account selected */
925 gtk_widget_show (priv->vbox_details);
927 if (priv->user_info != NULL)
929 tpaw_user_info_apply_async ((TpawUserInfo *) priv->user_info,
931 priv->user_info = NULL;
933 if (priv->dialog_content)
935 gtk_widget_destroy (priv->dialog_content);
936 priv->dialog_content = NULL;
939 if (tpaw_account_settings_is_ready (settings))
941 account_dialog_create_dialog_content (dialog, settings);
945 priv->settings_ready = settings;
946 priv->settings_ready_id =
947 g_signal_connect (settings, "notify::ready",
948 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
954 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
955 GtkCellEditable *editable,
957 EmpathyAccountsDialog *dialog)
959 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
961 if (priv->connecting_id)
962 g_source_remove (priv->connecting_id);
964 DEBUG ("Editing account name started; stopping flashing");
968 get_status_icon_for_account (EmpathyAccountsDialog *self,
971 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
972 TpConnectionStatus status;
973 TpConnectionStatusReason reason;
974 TpConnectionPresenceType presence;
977 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
979 if (!tp_account_is_enabled (account))
980 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
982 status = tp_account_get_connection_status (account, &reason);
984 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
986 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
987 /* An error occured */
988 return GTK_STOCK_DIALOG_ERROR;
990 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
992 else if (status == TP_CONNECTION_STATUS_CONNECTING)
994 /* Account is connecting. Display a blinking account alternating between
995 * the offline icon and the requested presence. */
996 if (priv->connecting_show)
997 presence = tp_account_get_requested_presence (account, NULL, NULL);
999 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
1003 /* status == TP_CONNECTION_STATUS_CONNECTED */
1004 presence = tp_account_get_current_presence (account, NULL, NULL);
1006 /* If presence is Unset (CM doesn't implement SimplePresence),
1007 * display the 'available' icon.
1008 * We also check Offline because of this MC5 bug: fd.o #26060 */
1009 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
1010 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
1011 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
1014 return empathy_icon_name_for_presence (presence);
1018 ensure_icon (EmpathyAccountsDialog *self,
1019 const gchar *icon_name)
1021 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1024 pixbuf = g_hash_table_lookup (priv->icons_cache, icon_name);
1027 pixbuf = tpaw_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1032 g_hash_table_insert (priv->icons_cache, g_strdup (icon_name),
1036 return g_object_ref (pixbuf);
1040 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1041 GtkCellRenderer *cell,
1042 GtkTreeModel *model,
1044 EmpathyAccountsDialog *dialog)
1047 const gchar *icon_name;
1050 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1052 icon_name = get_status_icon_for_account (dialog, account);
1053 pixbuf = ensure_icon (dialog, icon_name);
1059 if (account != NULL)
1060 g_object_unref (account);
1063 g_object_unref (pixbuf);
1067 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
1068 GtkCellRenderer *cell,
1069 GtkTreeModel *model,
1071 EmpathyAccountsDialog *dialog)
1073 TpawAccountSettings *settings;
1076 TpConnectionStatus status;
1078 gtk_tree_model_get (model, iter,
1079 COL_STATUS, &status,
1080 COL_ACCOUNT_SETTINGS, &settings,
1083 icon_name = tpaw_account_settings_get_icon_name (settings);
1084 pixbuf = ensure_icon (dialog, icon_name);
1091 g_object_unref (settings);
1094 g_object_unref (pixbuf);
1098 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1105 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1107 if (account == NULL)
1110 if (tp_account_get_connection_status (account, NULL) ==
1111 TP_CONNECTION_STATUS_CONNECTING)
1113 /* Only update the row where we have a connecting account as that's the
1114 * ones having a blinking icon. */
1115 gtk_tree_model_row_changed (model, path, iter);
1118 g_object_unref (account);
1123 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1126 GtkTreeModel *model;
1127 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1129 priv->connecting_show = !priv->connecting_show;
1131 view = GTK_TREE_VIEW (priv->treeview);
1132 model = gtk_tree_view_get_model (view);
1134 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1140 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1143 EmpathyAccountsDialog *dialog)
1145 TpawAccountSettings *settings;
1146 GtkTreeModel *model;
1147 GtkTreePath *treepath;
1149 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1150 gboolean connecting;
1152 empathy_account_manager_get_accounts_connected (&connecting);
1156 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1157 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1161 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1162 treepath = gtk_tree_path_new_from_string (path);
1163 gtk_tree_model_get_iter (model, &iter, treepath);
1164 gtk_tree_model_get (model, &iter,
1165 COL_ACCOUNT_SETTINGS, &settings,
1167 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1170 gtk_tree_path_free (treepath);
1172 tpaw_account_settings_set_display_name_async (settings, new_text,
1174 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1175 g_object_unref (settings);
1179 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1184 GtkTreeModel *model;
1186 GtkTreeSelection *selection;
1187 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1188 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1190 if (response_id == GTK_RESPONSE_YES)
1192 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1194 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1197 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1199 if (account != NULL)
1201 tp_account_remove_async (account, NULL, NULL);
1202 g_object_unref (account);
1206 /* No need to call accounts_dialog_model_selection_changed while
1207 * removing as we are going to call accounts_dialog_model_select_first
1208 * right after which will update the selection. */
1209 g_signal_handlers_block_by_func (selection,
1210 accounts_dialog_model_selection_changed, account_dialog);
1212 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1214 g_signal_handlers_unblock_by_func (selection,
1215 accounts_dialog_model_selection_changed, account_dialog);
1217 accounts_dialog_model_select_first (account_dialog);
1220 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1224 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1227 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1229 GtkTreeModel *model;
1230 gchar *question_dialog_primary_text;
1232 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1234 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1236 if (account == NULL || !tp_account_is_valid (account))
1238 if (account != NULL)
1239 g_object_unref (account);
1240 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1241 accounts_dialog_model_select_first (dialog);
1245 question_dialog_primary_text = g_strdup_printf (
1246 _("Do you want to remove %.50s from your computer?"),
1247 tp_account_get_display_name (account));
1249 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1250 _("This will not remove your account on the server."),
1251 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1253 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1254 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1256 g_free (question_dialog_primary_text);
1257 g_object_unref (account);
1261 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1262 EmpathyAccountsDialog *dialog)
1264 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1266 GtkTreeSelection *selection;
1269 view = GTK_TREE_VIEW (priv->treeview);
1270 selection = gtk_tree_view_get_selection (view);
1271 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1274 accounts_dialog_remove_account_iter (dialog, &iter);
1278 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1281 GtkTreeViewColumn *column;
1282 GtkCellRenderer *cell;
1283 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1285 view = GTK_TREE_VIEW (priv->treeview);
1286 gtk_tree_view_set_headers_visible (view, FALSE);
1288 /* Account column */
1289 column = gtk_tree_view_column_new ();
1290 gtk_tree_view_column_set_expand (column, TRUE);
1291 gtk_tree_view_append_column (view, column);
1293 /* Status icon renderer */
1294 cell = gtk_cell_renderer_pixbuf_new ();
1295 gtk_tree_view_column_pack_start (column, cell, FALSE);
1296 gtk_tree_view_column_set_cell_data_func (column, cell,
1297 (GtkTreeCellDataFunc)
1298 accounts_dialog_model_status_pixbuf_data_func,
1302 /* Protocol icon renderer */
1303 cell = gtk_cell_renderer_pixbuf_new ();
1304 gtk_tree_view_column_pack_start (column, cell, FALSE);
1305 gtk_tree_view_column_set_cell_data_func (column, cell,
1306 (GtkTreeCellDataFunc)
1307 accounts_dialog_model_protocol_pixbuf_data_func,
1312 priv->name_renderer = gtk_cell_renderer_text_new ();
1313 g_object_set (priv->name_renderer,
1314 "ellipsize", PANGO_ELLIPSIZE_END,
1318 gtk_tree_view_column_pack_start (column, priv->name_renderer, TRUE);
1319 gtk_tree_view_column_add_attribute (column, priv->name_renderer,
1321 g_signal_connect (priv->name_renderer, "edited",
1322 G_CALLBACK (accounts_dialog_name_edited_cb),
1324 g_signal_connect (priv->name_renderer, "editing-started",
1325 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1327 g_object_set (priv->name_renderer, "ypad", 4, NULL);
1330 static TpawAccountSettings *
1331 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1334 GtkTreeModel *model;
1335 GtkTreeSelection *selection;
1337 TpawAccountSettings *settings;
1338 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1340 view = GTK_TREE_VIEW (priv->treeview);
1341 selection = gtk_tree_view_get_selection (view);
1343 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1346 gtk_tree_model_get (model, &iter,
1347 COL_ACCOUNT_SETTINGS, &settings, -1);
1353 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1354 EmpathyAccountsDialog *dialog)
1356 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1357 TpawAccountSettings *settings;
1358 GtkTreeModel *model;
1360 gboolean is_selection;
1361 gboolean creating = FALSE;
1363 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1365 settings = accounts_dialog_model_get_selected_settings (dialog);
1366 accounts_dialog_update_settings (dialog, settings);
1368 if (settings != NULL)
1369 g_object_unref (settings);
1371 if (priv->setting_widget != NULL)
1373 g_object_get (priv->setting_widget,
1374 "creating-account", &creating, NULL);
1377 /* Update remove button sensitivity */
1378 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1383 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1385 gpointer *user_data)
1387 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1388 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1390 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1392 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1394 /* The user wants to lose unsaved changes to the currently selected
1395 * account and select another account. We discard the changes and
1396 * select the other account. */
1398 GtkTreeSelection *selection;
1400 priv->force_change_row = TRUE;
1401 tpaw_account_widget_discard_pending_changes (
1402 priv->setting_widget);
1404 path = gtk_tree_row_reference_get_path (priv->destination_row);
1405 selection = gtk_tree_view_get_selection (
1406 GTK_TREE_VIEW (priv->treeview));
1410 /* This will trigger a call to
1411 * accounts_dialog_account_selection_change() */
1412 gtk_tree_selection_select_path (selection, path);
1413 gtk_tree_path_free (path);
1416 gtk_tree_row_reference_free (priv->destination_row);
1420 priv->force_change_row = FALSE;
1425 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1426 GtkTreeModel *model,
1428 gboolean path_currently_selected,
1431 TpAccount *account = NULL;
1432 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1436 if (priv->force_change_row)
1438 /* We came back here because the user wants to discard changes to his
1439 * modified account. The changes have already been discarded so we
1440 * just change the selected row. */
1441 priv->force_change_row = FALSE;
1445 if (accounts_dialog_has_pending_change (dialog, &account))
1447 /* The currently selected account has some unsaved changes. We ask
1448 * the user if he really wants to lose his changes and select another
1450 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1451 priv->destination_row = gtk_tree_row_reference_new (model, path);
1453 accounts_dialog_show_question_dialog (dialog,
1454 question_dialog_primary_text,
1455 _("You are about to select another account, which will discard\n"
1456 "your changes. Are you sure you want to proceed?"),
1457 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1459 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1460 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1462 g_free (question_dialog_primary_text);
1470 if (account != NULL)
1471 g_object_unref (account);
1477 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1479 GtkListStore *store;
1480 GtkTreeSelection *selection;
1481 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1483 store = gtk_list_store_new (COL_COUNT,
1484 G_TYPE_STRING, /* name */
1485 G_TYPE_UINT, /* status */
1486 TP_TYPE_ACCOUNT, /* account */
1487 TPAW_TYPE_ACCOUNT_SETTINGS); /* settings */
1489 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1490 GTK_TREE_MODEL (store));
1492 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1493 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1494 gtk_tree_selection_set_select_function (selection,
1495 accounts_dialog_account_selection_change, dialog, NULL);
1497 g_signal_connect (selection, "changed",
1498 G_CALLBACK (accounts_dialog_model_selection_changed),
1501 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1502 COL_NAME, GTK_SORT_ASCENDING);
1504 accounts_dialog_model_add_columns (dialog);
1506 g_object_unref (store);
1510 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1515 GtkTreeModel *model;
1517 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1519 /* Update the status in the model */
1520 view = GTK_TREE_VIEW (priv->treeview);
1521 model = gtk_tree_view_get_model (view);
1523 for (ok = gtk_tree_model_get_iter_first (model, iter);
1525 ok = gtk_tree_model_iter_next (model, iter))
1527 TpAccount *this_account;
1530 gtk_tree_model_get (model, iter,
1531 COL_ACCOUNT, &this_account,
1534 equal = (this_account == account);
1535 g_object_unref (this_account);
1545 select_and_scroll_to_iter (EmpathyAccountsDialog *dialog,
1548 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1549 GtkTreeSelection *selection;
1551 GtkTreeModel *model;
1553 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1555 gtk_tree_selection_select_iter (selection, iter);
1557 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1558 path = gtk_tree_model_get_path (model, iter);
1560 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL,
1563 gtk_tree_path_free (path);
1567 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1572 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1573 select_and_scroll_to_iter (dialog, &iter);
1577 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1582 enabled = tp_account_is_enabled (account);
1584 enable_and_connect_account (account, !enabled);
1588 accounts_dialog_treeview_rename_cb (GtkMenuItem *item,
1589 EmpathyAccountsDialog *self)
1591 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1594 GtkTreeSelection *selection;
1595 GtkTreeModel *model;
1597 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1598 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1600 path = gtk_tree_model_get_path (model, &iter);
1602 g_object_set (G_OBJECT (priv->name_renderer), "editable", TRUE, NULL);
1604 gtk_widget_grab_focus (GTK_WIDGET (priv->treeview));
1605 gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->treeview), path,
1606 gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), 0), TRUE);
1608 gtk_tree_path_free (path);
1612 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1613 GdkEventButton *event,
1614 EmpathyAccountsDialog *dialog)
1616 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1617 TpAccount *account = NULL;
1618 GtkTreeModel *model = NULL;
1619 GtkTreePath *path = NULL;
1624 /* ignore multiple clicks */
1625 if (event->type != GDK_BUTTON_PRESS)
1628 if (event->button != 3)
1631 /* Selection is not yet set, so we have to get account from event position */
1632 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1633 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1634 event->x, event->y, &path, NULL, NULL, NULL))
1637 if (!gtk_tree_model_get_iter (model, &iter, path))
1640 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1642 /* Create the menu */
1643 menu = empathy_context_menu_new (GTK_WIDGET (view));
1645 /* Menu item: to enabled/disable the account */
1646 item = gtk_check_menu_item_new_with_mnemonic (_("_Enabled"));
1648 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1650 if (account_can_be_enabled (account))
1654 active = tp_account_is_enabled (account);
1655 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
1658 tp_g_signal_connect_object (item, "activate",
1659 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1663 gtk_widget_set_sensitive (item, FALSE);
1666 gtk_widget_show (item);
1668 /* Menu item: Rename */
1669 item = gtk_menu_item_new_with_mnemonic (_("Rename"));
1670 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1672 tp_g_signal_connect_object (item, "activate",
1673 G_CALLBACK (accounts_dialog_treeview_rename_cb), dialog, 0);
1675 gtk_widget_show (item);
1677 /* FIXME: Add here presence items, to be able to set per-account presence */
1680 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1681 event->button, event->time);
1684 tp_clear_object (&account);
1685 gtk_tree_path_free (path);
1691 reload_account_widget (EmpathyAccountsDialog *self)
1693 TpawAccountSettings *settings;
1695 settings = accounts_dialog_model_get_selected_settings (self);
1696 accounts_dialog_update_settings (self, settings);
1700 accounts_dialog_connection_changed_cb (TpAccount *account,
1704 gchar *dbus_error_name,
1705 GHashTable *details,
1706 EmpathyAccountsDialog *dialog)
1708 GtkTreeModel *model;
1711 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1713 /* Update the status-infobar in the details view */
1714 accounts_dialog_update_status_infobar (dialog, account);
1716 /* Update the status in the model */
1717 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1719 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1723 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1724 COL_STATUS, current,
1727 path = gtk_tree_model_get_path (model, &iter);
1728 gtk_tree_model_row_changed (model, path, &iter);
1729 gtk_tree_path_free (path);
1732 empathy_account_manager_get_accounts_connected (&found);
1734 if (!found && priv->connecting_id)
1736 g_source_remove (priv->connecting_id);
1737 priv->connecting_id = 0;
1740 if (found && !priv->connecting_id)
1741 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1742 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1747 update_account_in_treeview (EmpathyAccountsDialog *self,
1750 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1752 GtkTreeModel *model;
1754 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1755 if (accounts_dialog_get_account_iter (self, account, &iter))
1759 path = gtk_tree_model_get_path (model, &iter);
1760 gtk_tree_model_row_changed (model, path, &iter);
1761 gtk_tree_path_free (path);
1766 accounts_dialog_presence_changed_cb (TpAccount *account,
1769 gchar *status_message,
1770 EmpathyAccountsDialog *dialog)
1772 /* Update the status-infobar in the details view */
1773 accounts_dialog_update_status_infobar (dialog, account);
1775 update_account_in_treeview (dialog, account);
1779 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1781 EmpathyAccountsDialog *dialog)
1783 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1784 GtkTreeModel *model;
1787 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1788 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1790 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1791 COL_NAME, tp_account_get_display_name (account),
1795 accounts_dialog_update_status_infobar (dialog, account);
1799 conn_prepare_cb (GObject *source,
1800 GAsyncResult *result,
1803 EmpathyAccountsDialog *self = user_data;
1805 reload_account_widget (self);
1809 accounts_dialog_notify_connection_cb (TpAccount *account,
1811 EmpathyAccountsDialog *self)
1814 if (!account_is_selected (self, account))
1817 conn = tp_account_get_connection (account);
1820 reload_account_widget (self);
1824 /* Wait for this feature so TpConnection will have fetch the
1826 GQuark features[] = { TP_CONNECTION_FEATURE_CONNECTED, 0 };
1828 tp_proxy_prepare_async (conn, features, conn_prepare_cb, self);
1833 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1836 TpawAccountSettings *settings;
1837 GtkTreeModel *model;
1839 TpConnectionStatus status;
1841 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1842 gboolean selected = FALSE;
1843 GtkTreeSelection *selection;
1845 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1846 status = tp_account_get_connection_status (account, NULL);
1847 name = tp_account_get_display_name (account);
1849 settings = tpaw_account_settings_new_for_account (account);
1851 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1853 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1855 /* Select the account if it's the first added */
1856 if (gtk_tree_selection_count_selected_rows (selection) == 0)
1859 gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, -1,
1862 COL_ACCOUNT, account,
1863 COL_ACCOUNT_SETTINGS, settings,
1868 selected = gtk_tree_selection_iter_is_selected (selection, &iter);
1870 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1873 COL_ACCOUNT, account,
1874 COL_ACCOUNT_SETTINGS, settings,
1880 /* We just modified the selected account. Its display name may have been
1881 * changed and so it's place in the treeview. Scroll to it so it stays
1883 select_and_scroll_to_iter (dialog, &iter);
1886 accounts_dialog_connection_changed_cb (account,
1889 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1894 tp_g_signal_connect_object (account, "notify::display-name",
1895 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1898 tp_g_signal_connect_object (account, "status-changed",
1899 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1900 tp_g_signal_connect_object (account, "presence-changed",
1901 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1902 tp_g_signal_connect_object (account, "notify::connection",
1903 G_CALLBACK (accounts_dialog_notify_connection_cb), dialog, 0);
1905 g_object_unref (settings);
1909 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1912 EmpathyAccountsDialog *dialog)
1914 accounts_dialog_add_account (dialog, account);
1918 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1921 EmpathyAccountsDialog *dialog)
1923 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1925 if (priv->setting_widget != NULL &&
1926 accounts_dialog_has_valid_accounts (dialog))
1928 tpaw_account_widget_set_other_accounts_exist (
1929 priv->setting_widget, TRUE);
1934 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1936 EmpathyAccountsDialog *dialog)
1938 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1940 if (priv->setting_widget != NULL &&
1941 !accounts_dialog_has_valid_accounts (dialog))
1943 tpaw_account_widget_set_other_accounts_exist (
1944 priv->setting_widget, FALSE);
1949 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1951 EmpathyAccountsDialog *dialog)
1954 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1956 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1958 gtk_list_store_remove (GTK_LIST_STORE (
1959 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1964 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1968 /* Update the status-infobar in the details view */
1969 accounts_dialog_update_status_infobar (dialog, account);
1971 DEBUG ("Account %s is now %s",
1972 tp_account_get_display_name (account),
1973 enabled ? "enabled" : "disabled");
1977 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1979 EmpathyAccountsDialog *dialog)
1981 enable_or_disable_account (dialog, account, FALSE);
1982 update_account_in_treeview (dialog, account);
1986 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1988 EmpathyAccountsDialog *dialog)
1990 enable_or_disable_account (dialog, account, TRUE);
1994 display_import_dialog (EmpathyAccountsDialog *dialog)
1996 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1997 GtkWidget *import_dialog;
1999 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2001 gtk_widget_show (import_dialog);
2003 return import_dialog;
2007 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
2008 EmpathyAccountsDialog *dialog)
2010 display_import_dialog (dialog);
2014 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
2018 GtkWidget *account_dialog = GTK_WIDGET (user_data);
2020 gtk_widget_destroy (GTK_WIDGET (message_dialog));
2022 if (response_id == GTK_RESPONSE_YES)
2023 gtk_widget_destroy (account_dialog);
2027 accounts_dialog_delete_event_cb (GtkWidget *widget,
2029 EmpathyAccountsDialog *dialog)
2031 /* we maunally handle responses to delete events */
2036 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
2041 if (accounts_dialog_get_account_iter (dialog, account, &iter))
2042 select_and_scroll_to_iter (dialog, &iter);
2046 salut_valid_cb (GtkWidget *widget,
2050 gtk_widget_set_sensitive (button, valid);
2054 maybe_show_salut_dialog (EmpathyAccountsDialog *self)
2056 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2057 GtkWidget *dialog, *widget, *content, *button;
2060 if (!empathy_local_xmpp_assistant_widget_should_create_account (
2061 priv->account_manager))
2064 widget = empathy_local_xmpp_assistant_widget_new ();
2065 gtk_widget_show (widget);
2067 dialog = gtk_dialog_new ();
2069 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
2071 gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"),
2074 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
2075 _("_Connect"), GTK_RESPONSE_YES);
2076 gtk_widget_set_sensitive (button,
2077 empathy_local_xmpp_assistant_widget_is_valid (
2078 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget)));
2080 g_signal_connect (widget, "valid", G_CALLBACK (salut_valid_cb),
2083 content = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2084 gtk_box_pack_start (GTK_BOX (content), widget, TRUE, TRUE, 0);
2086 response = gtk_dialog_run (GTK_DIALOG (dialog));
2088 if (response == GTK_RESPONSE_YES)
2090 empathy_local_xmpp_assistant_widget_create_account (
2091 EMPATHY_LOCAL_XMPP_ASSISTANT_WIDGET (widget));
2094 gtk_widget_destroy (dialog);
2098 import_dialog_response_cb (GtkDialog *dialog,
2100 EmpathyAccountsDialog *self)
2102 maybe_show_salut_dialog (self);
2106 maybe_show_import_dialog (EmpathyAccountsDialog *self)
2108 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2111 if (empathy_accounts_has_non_salut_accounts (priv->account_manager))
2114 if (!empathy_import_accounts_to_import ())
2116 maybe_show_salut_dialog (self);
2120 dialog = display_import_dialog (self);
2122 tp_g_signal_connect_object (dialog, "response",
2123 G_CALLBACK (import_dialog_response_cb), self, 0);
2127 finished_loading (EmpathyAccountsDialog *self)
2129 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
2130 GtkTreeSelection *selection;
2131 gboolean has_selected;
2133 priv->loading = FALSE;
2135 gtk_widget_set_sensitive (priv->button_add, TRUE);
2136 gtk_widget_set_sensitive (priv->button_import, TRUE);
2137 gtk_widget_set_sensitive (priv->treeview, TRUE);
2139 /* Sensitive the remove button if there is an account selected */
2140 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
2141 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
2142 gtk_widget_set_sensitive (priv->button_remove, has_selected);
2144 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
2145 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2146 NOTEBOOK_PAGE_ACCOUNT);
2148 maybe_show_import_dialog (self);
2152 accounts_dialog_cms_prepare_cb (GObject *source,
2153 GAsyncResult *result,
2156 TpawConnectionManagers *cms = TPAW_CONNECTION_MANAGERS (source);
2157 EmpathyAccountsDialog *dialog = user_data;
2158 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2160 if (!tpaw_connection_managers_prepare_finish (cms, result, NULL))
2163 /* No need to update the settings if we are already preparing one */
2164 if (priv->settings_ready == NULL)
2165 accounts_dialog_update_settings (dialog, NULL);
2167 if (priv->initial_selection != NULL)
2169 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
2170 g_object_unref (priv->initial_selection);
2171 priv->initial_selection = NULL;
2175 finished_loading (dialog);
2179 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
2181 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2182 GList *accounts, *l;
2184 g_signal_connect (priv->account_manager, "account-validity-changed",
2185 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
2187 g_signal_connect (priv->account_manager, "account-removed",
2188 G_CALLBACK (accounts_dialog_account_removed_cb),
2190 g_signal_connect (priv->account_manager, "account-enabled",
2191 G_CALLBACK (accounts_dialog_account_enabled_cb),
2193 g_signal_connect (priv->account_manager, "account-disabled",
2194 G_CALLBACK (accounts_dialog_account_disabled_cb),
2197 /* Add existing accounts */
2198 accounts = tp_account_manager_dup_valid_accounts (priv->account_manager);
2199 for (l = accounts; l; l = l->next)
2201 accounts_dialog_add_account (dialog, l->data);
2203 g_list_free_full (accounts, g_object_unref);
2205 priv->cms = tpaw_connection_managers_dup_singleton ();
2207 tpaw_connection_managers_prepare_async (priv->cms,
2208 accounts_dialog_cms_prepare_cb, dialog);
2210 accounts_dialog_model_select_first (dialog);
2214 accounts_dialog_manager_ready_cb (GObject *source_object,
2215 GAsyncResult *result,
2218 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2219 GError *error = NULL;
2221 if (!tp_proxy_prepare_finish (manager, result, &error))
2223 DEBUG ("Failed to prepare account manager: %s", error->message);
2224 g_error_free (error);
2228 accounts_dialog_accounts_setup (user_data);
2232 dialog_response_cb (GtkWidget *widget,
2236 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2238 if (response_id == GTK_RESPONSE_HELP)
2240 empathy_url_show (widget, "help:empathy/accounts-window");
2242 else if (response_id == GTK_RESPONSE_CLOSE ||
2243 response_id == GTK_RESPONSE_DELETE_EVENT)
2245 TpAccount *account = NULL;
2247 if (accounts_dialog_has_pending_change (dialog, &account))
2249 gchar *question_dialog_primary_text = get_dialog_primary_text (
2252 accounts_dialog_show_question_dialog (dialog,
2253 question_dialog_primary_text,
2254 _("You are about to close the window, which will discard\n"
2255 "your changes. Are you sure you want to proceed?"),
2256 G_CALLBACK (accounts_dialog_close_response_cb),
2258 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2259 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2261 g_free (question_dialog_primary_text);
2265 gtk_widget_destroy (widget);
2268 if (account != NULL)
2269 g_object_unref (account);
2274 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2276 GtkWidget *top_hbox;
2279 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2280 GtkWidget *content_area, *action_area;
2281 GtkWidget *grid, *hbox;
2283 GtkWidget *sw, *toolbar;
2284 GtkStyleContext *context;
2286 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2288 gui = tpaw_builder_get_file (filename,
2289 "accounts_dialog_hbox", &top_hbox,
2290 "vbox_details", &priv->vbox_details,
2291 "alignment_settings", &priv->alignment_settings,
2292 "alignment_infobar", &priv->alignment_infobar,
2293 "treeview", &priv->treeview,
2294 "button_add", &priv->button_add,
2295 "button_remove", &priv->button_remove,
2296 "button_import", &priv->button_import,
2297 "notebook_account", &priv->notebook_account,
2298 "alignment_loading", &alig,
2300 "add_remove_toolbar", &toolbar,
2304 tpaw_builder_connect (gui, dialog,
2305 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2306 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2307 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2308 "treeview", "button-press-event",
2309 accounts_dialog_treeview_button_press_event_cb,
2312 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2314 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2316 g_object_unref (gui);
2318 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2320 /* Display loading page */
2321 priv->loading = TRUE;
2323 priv->spinner = gtk_spinner_new ();
2325 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2326 gtk_widget_show (priv->spinner);
2328 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2330 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2331 NOTEBOOK_PAGE_LOADING);
2333 /* Remove button is insensitive until we have a selected account */
2334 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2336 /* Add and Import buttons and treeview are insensitive while the dialog
2338 gtk_widget_set_sensitive (priv->button_add, FALSE);
2339 gtk_widget_set_sensitive (priv->button_import, FALSE);
2340 gtk_widget_set_sensitive (priv->treeview, FALSE);
2342 if (priv->parent_window)
2343 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2344 priv->parent_window);
2346 priv->infobar = gtk_info_bar_new ();
2347 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2349 gtk_widget_show (priv->infobar);
2351 grid = gtk_grid_new ();
2352 gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
2354 GTK_CONTAINER (gtk_info_bar_get_content_area (
2355 GTK_INFO_BAR (priv->infobar))),
2358 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2359 GTK_ICON_SIZE_DIALOG);
2360 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2361 gtk_grid_attach (GTK_GRID (grid), priv->image_type, 0, 0, 1, 2);
2364 priv->label_name = gtk_label_new (NULL);
2365 gtk_label_set_ellipsize (GTK_LABEL (priv->label_name), PANGO_ELLIPSIZE_END);
2366 gtk_grid_attach (GTK_GRID (grid), priv->label_name, 1, 0, 1, 1);
2369 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
2370 gtk_widget_set_hexpand (hbox, TRUE);
2371 gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
2372 gtk_grid_attach (GTK_GRID (grid), hbox, 1, 1, 1, 1);
2374 /* set up spinner */
2375 priv->throbber = gtk_spinner_new ();
2377 priv->image_status = gtk_image_new_from_icon_name (
2378 empathy_icon_name_for_presence (
2379 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2381 priv->label_status = gtk_label_new (NULL);
2382 gtk_label_set_ellipsize (GTK_LABEL (priv->label_status), PANGO_ELLIPSIZE_END);
2384 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2385 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 0);
2386 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, FALSE, FALSE, 0);
2388 /* enabled switch */
2389 priv->enabled_switch = gtk_switch_new ();
2390 gtk_widget_set_valign (priv->enabled_switch, GTK_ALIGN_CENTER);
2391 g_signal_connect (priv->enabled_switch, "notify::active",
2392 G_CALLBACK (accounts_dialog_enable_switch_active_cb), dialog);
2393 gtk_grid_attach (GTK_GRID (grid), priv->enabled_switch, 2, 0, 1, 2);
2395 gtk_widget_show_all (grid);
2397 /* Tweak the dialog */
2398 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2399 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2401 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2403 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2405 /* join the add/remove toolbar to the treeview */
2406 context = gtk_widget_get_style_context (sw);
2407 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_BOTTOM);
2409 context = gtk_widget_get_style_context (toolbar);
2410 gtk_style_context_set_junction_sides (context, GTK_JUNCTION_TOP);
2412 /* add dialog buttons */
2413 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2415 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2416 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2417 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2420 g_signal_connect (dialog, "response",
2421 G_CALLBACK (dialog_response_cb), dialog);
2423 g_signal_connect (dialog, "delete-event",
2424 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2428 do_dispose (GObject *obj)
2430 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2431 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2433 if (priv->user_info != NULL)
2435 tpaw_user_info_apply_async ((TpawUserInfo *) priv->user_info,
2437 priv->user_info = NULL;
2440 if (priv->connecting_id != 0)
2442 g_source_remove (priv->connecting_id);
2443 priv->connecting_id = 0;
2446 if (priv->connectivity)
2448 g_object_unref (priv->connectivity);
2449 priv->connectivity = NULL;
2452 if (priv->account_manager != NULL)
2454 g_object_unref (priv->account_manager);
2455 priv->account_manager = NULL;
2458 if (priv->cms != NULL)
2460 g_object_unref (priv->cms);
2464 if (priv->initial_selection != NULL)
2466 g_object_unref (priv->initial_selection);
2467 priv->initial_selection = NULL;
2470 tp_clear_pointer (&priv->icons_cache, g_hash_table_unref);
2472 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2476 do_get_property (GObject *object,
2481 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2483 switch (property_id)
2486 g_value_set_object (value, priv->parent_window);
2489 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2494 do_set_property (GObject *object,
2496 const GValue *value,
2499 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2501 switch (property_id)
2504 priv->parent_window = g_value_get_object (value);
2507 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2512 do_constructed (GObject *object)
2514 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2515 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2516 GtkTreeModel *model;
2518 accounts_dialog_build_ui (dialog);
2519 accounts_dialog_model_setup (dialog);
2521 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2522 g_signal_connect (model, "row-inserted",
2523 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2524 g_signal_connect (model, "row-deleted",
2525 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2527 /* Set up signalling */
2528 priv->account_manager = tp_account_manager_dup ();
2530 tp_proxy_prepare_async (priv->account_manager, NULL,
2531 accounts_dialog_manager_ready_cb, dialog);
2533 priv->connectivity = g_network_monitor_get_default ();
2534 g_object_ref (priv->connectivity);
2538 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2540 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2541 GParamSpec *param_spec;
2543 oclass->dispose = do_dispose;
2544 oclass->constructed = do_constructed;
2545 oclass->set_property = do_set_property;
2546 oclass->get_property = do_get_property;
2548 param_spec = g_param_spec_object ("parent",
2549 "parent", "The parent window",
2551 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2552 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2554 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2558 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2560 EmpathyAccountsDialogPriv *priv;
2562 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2563 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2564 EmpathyAccountsDialogPriv);
2565 dialog->priv = priv;
2567 priv->icons_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
2568 g_free, g_object_unref);
2571 /* public methods */
2574 empathy_accounts_dialog_show (GtkWindow *parent,
2575 TpAccount *selected_account)
2577 EmpathyAccountsDialog *dialog;
2578 EmpathyAccountsDialogPriv *priv;
2580 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2581 "parent", parent, NULL);
2583 priv = GET_PRIV (dialog);
2585 if (selected_account)
2587 if (priv->cms != NULL && tpaw_connection_managers_is_ready (priv->cms))
2588 accounts_dialog_set_selected_account (dialog, selected_account);
2590 /* save the selection to set it later when the cms
2593 priv->initial_selection = g_object_ref (selected_account);
2596 gtk_window_present (GTK_WINDOW (dialog));
2598 return GTK_WIDGET (dialog);
2608 static LaunchUOACtx *
2609 launch_uoa_ctx_new (TpAccount *account,
2614 ctx = g_slice_new0 (LaunchUOACtx);
2615 if (account != NULL)
2616 ctx->account = g_object_ref (account);
2617 ctx->if_needed = if_needed;
2623 launch_uoa_ctx_free (LaunchUOACtx *ctx)
2625 g_clear_object (&ctx->account);
2626 g_slice_free (LaunchUOACtx, ctx);
2630 am_prepare_cb (GObject *source,
2631 GAsyncResult *result,
2634 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source);
2635 GError *error = NULL;
2636 LaunchUOACtx *ctx = user_data;
2639 if (!tp_proxy_prepare_finish (manager, result, &error))
2641 DEBUG ("Failed to prepare account manager: %s", error->message);
2642 g_error_free (error);
2646 if (ctx->if_needed && empathy_accounts_has_non_salut_accounts (manager))
2649 if (ctx->account != NULL)
2651 const GValue *value;
2653 value = tp_account_get_storage_identifier (ctx->account);
2655 if (G_VALUE_HOLDS_UINT (value))
2656 args = g_strdup_printf ("account-details=%u", g_value_get_uint (value));
2659 empathy_launch_external_app ("gnome-credentials-panel.desktop", args, NULL);
2663 launch_uoa_ctx_free (ctx);
2667 launch_uoa_panel (TpAccount *selected_account,
2671 TpAccountManager *manager;
2677 manager = tp_account_manager_dup ();
2679 tp_proxy_prepare_async (manager, NULL, am_prepare_cb,
2680 launch_uoa_ctx_new (selected_account, if_needed));
2682 g_object_unref (manager);
2685 #else /* HAVE_UOA */
2688 launch_empathy_accounts (TpAccount *selected_account,
2694 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2696 args = g_string_new (NULL);
2698 if (selected_account != NULL)
2699 g_string_append_printf (args, " --select-account=%s",
2700 tp_account_get_path_suffix (selected_account));
2703 g_string_append_printf (args, " --if-needed");
2706 g_string_append_printf (args, " --hidden");
2708 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2710 selected_account == NULL ? "<none selected>" :
2711 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2713 empathy_launch_program (BIN_DIR, "empathy-accounts", args->str);
2715 g_string_free (args, TRUE);
2717 #endif /* HAVE_UOA */
2720 empathy_accounts_dialog_show_application (GdkScreen *screen,
2721 TpAccount *selected_account,
2726 launch_uoa_panel (selected_account, if_needed, hidden);
2728 launch_empathy_accounts (selected_account, if_needed, hidden);
2733 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2735 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2736 gboolean result = FALSE;
2738 if (priv->setting_widget == NULL)
2741 g_object_get (priv->setting_widget,
2742 "creating-account", &result, NULL);