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>
32 #include <glib/gi18n-lib.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/defs.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-connection-managers.h>
41 #include <libempathy/empathy-connectivity.h>
42 #include <libempathy/empathy-gsettings.h>
44 #include <libempathy-gtk/empathy-ui-utils.h>
45 #include <libempathy-gtk/empathy-protocol-chooser.h>
46 #include <libempathy-gtk/empathy-account-widget.h>
47 #include <libempathy-gtk/empathy-account-widget-irc.h>
48 #include <libempathy-gtk/empathy-account-widget-sip.h>
49 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
50 #include <libempathy-gtk/empathy-images.h>
52 #include "empathy-accounts-dialog.h"
53 #include "empathy-import-dialog.h"
54 #include "empathy-import-utils.h"
56 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
57 #include <libempathy/empathy-debug.h>
59 /* Flashing delay for icons (milliseconds). */
60 #define FLASH_TIMEOUT 500
62 /* The primary text of the dialog shown to the user when he is about to lose
64 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
65 _("There are unsaved modifications to your %s account.")
66 /* The primary text of the dialog shown to the user when he is about to lose
67 * an unsaved new account */
68 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
69 _("Your new account has not been saved yet.")
71 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
72 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
75 GtkWidget *alignment_settings;
76 GtkWidget *alignment_infobar;
78 GtkWidget *vbox_details;
80 GtkWidget *label_status;
81 GtkWidget *image_status;
83 GtkWidget *frame_no_protocol;
87 GtkWidget *button_add;
88 GtkWidget *button_remove;
89 GtkWidget *button_import;
91 GtkWidget *combobox_protocol;
92 GtkWidget *hbox_protocol;
94 GtkWidget *image_type;
95 GtkWidget *label_name;
96 GtkWidget *label_type;
97 GtkWidget *settings_widget;
99 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
100 * his 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 EmpathyAccountWidget. For instance, it does not
104 * contain the state of the "Enabled" checkbox. */
105 EmpathyAccountWidget *setting_widget_object;
107 gboolean connecting_show;
110 gulong settings_ready_id;
111 EmpathyAccountSettings *settings_ready;
113 TpAccountManager *account_manager;
114 EmpathyConnectionManagers *cms;
115 EmpathyConnectivity *connectivity;
117 GtkWindow *parent_window;
118 TpAccount *initial_selection;
120 /* Those are needed when changing the selected row. When a user selects
121 * another account and there are unsaved changes on the currently selected
122 * one, a confirmation message box is presented to him. Since his answer
123 * is retrieved asynchronously, we keep some information as member of the
124 * EmpathyAccountsDialog object. */
125 gboolean force_change_row;
126 GtkTreeRowReference *destination_row;
127 } EmpathyAccountsDialogPriv;
133 COL_ACCOUNT_SETTINGS,
141 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
142 EmpathyAccountsDialog *dialog);
144 static gboolean accounts_dialog_get_settings_iter (
145 EmpathyAccountsDialog *dialog,
146 EmpathyAccountSettings *settings,
149 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
151 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
152 EmpathyAccountSettings *settings);
154 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings);
157 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
158 EmpathyAccountSettings *settings);
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);
179 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
180 const gchar *display_name)
183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
185 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
186 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
192 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
193 const gchar *message)
195 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
196 gchar *message_markup;
198 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
199 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
200 g_free (message_markup);
204 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
207 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
208 gchar *status_message = NULL;
214 GtkTreeSelection *selection;
216 TpAccount *selected_account;
217 gboolean account_enabled;
218 gboolean creating_account;
220 view = GTK_TREE_VIEW (priv->treeview);
221 selection = gtk_tree_view_get_selection (view);
223 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
226 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
227 if (selected_account != NULL)
228 g_object_unref (selected_account);
230 /* do not update the infobar when the account is not selected */
231 if (account != selected_account)
236 status = tp_account_get_connection_status (account, &reason);
237 presence = tp_account_get_current_presence (account, NULL, &status_message);
238 account_enabled = tp_account_is_enabled (account);
239 creating_account = FALSE;
241 if (status == TP_CONNECTION_STATUS_CONNECTED &&
242 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
243 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
244 /* If presence is Unset (CM doesn't implement SimplePresence) but we
245 * are connected, consider ourself as Available.
246 * We also check Offline because of this MC5 bug: fd.o #26060 */
247 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
249 /* set presence to offline if account is disabled
250 * (else no icon is shown in infobar)*/
251 if (!account_enabled)
252 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
256 status = TP_CONNECTION_STATUS_DISCONNECTED;
257 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
258 account_enabled = FALSE;
259 creating_account = TRUE;
262 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
263 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
269 case TP_CONNECTION_STATUS_CONNECTING:
270 accounts_dialog_status_infobar_set_message (dialog,
272 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
275 gtk_spinner_start (GTK_SPINNER (priv->throbber));
276 gtk_widget_show (priv->throbber);
277 gtk_widget_hide (priv->image_status);
279 case TP_CONNECTION_STATUS_CONNECTED:
280 if (g_strcmp0 (status_message, "") == 0)
284 message = g_strdup_printf ("%s",
285 empathy_presence_get_default_message (presence));
287 accounts_dialog_status_infobar_set_message (dialog, message);
294 message = g_strdup_printf ("%s — %s",
295 empathy_presence_get_default_message (presence),
298 accounts_dialog_status_infobar_set_message (dialog, message);
301 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
304 gtk_widget_show (priv->image_status);
305 gtk_widget_hide (priv->throbber);
307 case TP_CONNECTION_STATUS_DISCONNECTED:
308 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
312 message = g_strdup_printf (_("Offline — %s"),
313 empathy_account_get_error_message (account, NULL));
314 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
315 GTK_MESSAGE_WARNING);
317 accounts_dialog_status_infobar_set_message (dialog, message);
324 message = g_strdup_printf (_("Disconnected — %s"),
325 empathy_account_get_error_message (account, NULL));
326 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
329 accounts_dialog_status_infobar_set_message (dialog, message);
333 if (!empathy_connectivity_is_online (priv->connectivity))
334 accounts_dialog_status_infobar_set_message (dialog,
335 _("Offline — No Network Connection"));
337 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
338 gtk_widget_show (priv->image_status);
339 gtk_widget_hide (priv->throbber);
342 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
343 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
344 GTK_MESSAGE_WARNING);
346 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
347 gtk_widget_hide (priv->image_status);
348 gtk_widget_hide (priv->throbber);
353 accounts_dialog_status_infobar_set_message (dialog,
354 _("Offline — Account Disabled"));
356 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
357 GTK_MESSAGE_WARNING);
358 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
359 gtk_widget_show (priv->image_status);
360 gtk_widget_hide (priv->throbber);
363 gtk_widget_show (priv->label_status);
365 if (!creating_account)
366 gtk_widget_show (priv->infobar);
368 gtk_widget_hide (priv->infobar);
370 g_free (status_message);
374 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
378 GtkTreeSelection *selection;
380 EmpathyAccountSettings *settings;
382 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
384 view = GTK_TREE_VIEW (priv->treeview);
385 selection = gtk_tree_view_get_selection (view);
387 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
390 gtk_tree_model_get (model, &iter,
391 COL_ACCOUNT_SETTINGS, &settings,
392 COL_ACCOUNT, &account, -1);
394 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
398 /* We were creating an account. We remove the selected row */
399 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
403 /* We were modifying an account. We discard the changes by reloading the
404 * settings and the UI. */
405 accounts_dialog_update_settings (dialog, settings);
406 g_object_unref (account);
409 gtk_widget_set_sensitive (priv->treeview, TRUE);
410 gtk_widget_set_sensitive (priv->button_add, TRUE);
411 gtk_widget_set_sensitive (priv->button_remove, TRUE);
412 gtk_widget_set_sensitive (priv->button_import, TRUE);
414 if (settings != NULL)
415 g_object_unref (settings);
419 empathy_account_dialog_widget_cancelled_cb (
420 EmpathyAccountWidget *widget_object,
421 EmpathyAccountsDialog *dialog)
423 empathy_account_dialog_cancel (dialog);
427 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
429 EmpathyAccountsDialog *dialog)
431 EmpathyAccountSettings *settings =
432 accounts_dialog_model_get_selected_settings (dialog);
433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
435 accounts_dialog_update_settings (dialog, settings);
436 accounts_dialog_update_status_infobar (dialog,
437 empathy_account_settings_get_account (settings));
439 gtk_widget_set_sensitive (priv->treeview, TRUE);
440 gtk_widget_set_sensitive (priv->button_add, TRUE);
441 gtk_widget_set_sensitive (priv->button_remove, TRUE);
442 gtk_widget_set_sensitive (priv->button_import, TRUE);
445 g_object_unref (settings);
449 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
451 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
456 g_object_get (priv->setting_widget_object,
457 "creating-account", &creating, NULL);
462 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
464 if (gtk_tree_model_get_iter_first (model, &iter))
465 return gtk_tree_model_iter_next (model, &iter);
471 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
472 EmpathyAccountSettings *settings)
474 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
475 const gchar *icon_name;
478 priv->setting_widget_object =
479 empathy_account_widget_new_for_protocol (settings, FALSE);
481 if (accounts_dialog_has_valid_accounts (dialog))
482 empathy_account_widget_set_other_accounts_exist (
483 priv->setting_widget_object, TRUE);
485 priv->settings_widget =
486 empathy_account_widget_get_widget (priv->setting_widget_object);
488 g_signal_connect (priv->setting_widget_object, "account-created",
489 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
490 g_signal_connect (priv->setting_widget_object, "cancelled",
491 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
493 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
494 priv->settings_widget);
495 gtk_widget_show (priv->settings_widget);
497 icon_name = empathy_account_settings_get_icon_name (settings);
499 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
501 /* show the default icon; keep this in sync with the default
502 * one in empathy-accounts-dialog.ui.
504 icon_name = GTK_STOCK_CUT;
506 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
507 icon_name, GTK_ICON_SIZE_DIALOG);
508 gtk_widget_set_tooltip_text (priv->image_type,
509 empathy_protocol_name_to_display_name
510 (empathy_account_settings_get_protocol (settings)));
511 gtk_widget_show (priv->image_type);
513 accounts_dialog_update_name_label (dialog,
514 empathy_account_settings_get_display_name (settings));
516 account = empathy_account_settings_get_account (settings);
517 accounts_dialog_update_status_infobar (dialog, account);
521 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
523 EmpathyAccountsDialog *dialog)
525 if (empathy_account_settings_is_ready (settings))
526 account_dialog_create_settings_widget (dialog, settings);
530 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
534 GtkTreeSelection *selection;
536 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
539 view = GTK_TREE_VIEW (priv->treeview);
540 model = gtk_tree_view_get_model (view);
542 if (gtk_tree_model_get_iter_first (model, &iter))
544 selection = gtk_tree_view_get_selection (view);
545 gtk_tree_selection_select_iter (selection, &iter);
549 accounts_dialog_update_settings (dialog, NULL);
554 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
559 GtkTreeSelection *selection;
560 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
562 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
564 if (gtk_tree_selection_get_selected (selection, &model, &iter))
565 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
567 return priv->setting_widget_object != NULL
568 && empathy_account_widget_contains_pending_changes (
569 priv->setting_widget_object);
573 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
575 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
576 EmpathyAccountSettings *settings;
578 const gchar *name, *display_name;
579 TpConnectionManager *cm;
580 TpConnectionManagerProtocol *proto;
581 gboolean is_gtalk, is_facebook;
583 cm = empathy_protocol_chooser_dup_selected (
584 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk,
591 else if (is_facebook)
596 display_name = empathy_protocol_name_to_display_name (name);
597 if (display_name == NULL)
598 display_name = proto->name;
601 /* To translator: %s is the name of the protocol, such as "Google Talk" or
604 str = g_strdup_printf (_("New %s account"), display_name);
605 settings = empathy_account_settings_new (cm->name, proto->name, str);
611 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
613 /* We should not have to set the server but that may cause issue with
615 empathy_account_settings_set_string (settings, "server",
618 else if (is_facebook)
620 empathy_account_settings_set_icon_name_async (settings, "im-facebook",
623 empathy_account_settings_set_string (settings, "server",
624 "chat.facebook.com");
627 accounts_dialog_add (dialog, settings);
628 accounts_dialog_model_set_selected (dialog, settings);
630 gtk_widget_show_all (priv->hbox_protocol);
632 g_object_unref (settings);
637 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
638 EmpathyAccountsDialog *dialog)
640 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
641 GtkTreeSelection *selection;
645 EmpathyAccountSettings *settings;
646 gchar *account = NULL, *password = NULL;
648 /* The "changed" signal is fired during the initiation of the
649 * EmpathyProtocolChooser while populating the widget. Such signals should
650 * be ignored so we check if we are actually creating a new account. */
651 if (priv->setting_widget_object == NULL)
654 g_object_get (priv->setting_widget_object,
655 "creating-account", &creating, NULL);
659 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
661 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
664 /* Save "account" and "password" parameters */
665 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
667 if (settings != NULL)
669 account = g_strdup (empathy_account_settings_get_string (settings,
671 password = g_strdup (empathy_account_settings_get_string (settings,
673 g_object_unref (settings);
676 /* We are creating a new widget to replace the current one, don't ask
677 * confirmation to the user. */
678 priv->force_change_row = TRUE;
680 /* We'll update the selection after we create the new account widgets;
681 * updating it right now causes problems for the # of accounts = zero case */
682 g_signal_handlers_block_by_func (selection,
683 accounts_dialog_model_selection_changed, dialog);
685 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
687 g_signal_handlers_unblock_by_func (selection,
688 accounts_dialog_model_selection_changed, dialog);
690 accounts_dialog_setup_ui_to_add_account (dialog);
692 /* Restore "account" and "password" parameters in the new widget */
695 empathy_account_widget_set_account_param (priv->setting_widget_object,
700 if (password != NULL)
702 empathy_account_widget_set_password_param (priv->setting_widget_object,
709 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
710 const gchar *primary_text,
711 const gchar *secondary_text,
712 GCallback response_callback,
714 const gchar *first_button_text,
718 GtkWidget *message_dialog;
719 const gchar *button_text;
721 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
722 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
723 GTK_MESSAGE_QUESTION,
727 gtk_message_dialog_format_secondary_text (
728 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
730 va_start (button_args, first_button_text);
731 for (button_text = first_button_text;
733 button_text = va_arg (button_args, const gchar *))
736 response_id = va_arg (button_args, gint);
738 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
741 va_end (button_args);
743 g_signal_connect (message_dialog, "response", response_callback, user_data);
745 gtk_widget_show (message_dialog);
749 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
753 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
754 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
756 gtk_widget_destroy (GTK_WIDGET (message_dialog));
758 if (response_id == GTK_RESPONSE_YES)
760 empathy_account_widget_discard_pending_changes (
761 priv->setting_widget_object);
762 accounts_dialog_setup_ui_to_add_account (dialog);
767 get_dialog_primary_text (TpAccount *account)
771 /* Existing account */
772 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
773 tp_account_get_display_name (account));
777 /* Newly created account */
778 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
783 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
784 EmpathyAccountsDialog *dialog)
786 TpAccount *account = NULL;
787 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
789 if (accounts_dialog_has_pending_change (dialog, &account))
791 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
793 accounts_dialog_show_question_dialog (dialog,
794 question_dialog_primary_text,
795 _("You are about to create a new account, which will discard\n"
796 "your changes. Are you sure you want to proceed?"),
797 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
799 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
800 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
802 g_free (question_dialog_primary_text);
806 accounts_dialog_setup_ui_to_add_account (dialog);
807 gtk_widget_set_sensitive (priv->treeview, FALSE);
808 gtk_widget_set_sensitive (priv->button_add, FALSE);
809 gtk_widget_set_sensitive (priv->button_remove, FALSE);
810 gtk_widget_set_sensitive (priv->button_import, FALSE);
814 g_object_unref (account);
818 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
819 EmpathyAccountSettings *settings)
821 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
823 if (priv->settings_ready != NULL)
825 g_signal_handler_disconnect (priv->settings_ready,
826 priv->settings_ready_id);
827 priv->settings_ready = NULL;
828 priv->settings_ready_id = 0;
835 GtkTreeSelection *selection;
837 view = GTK_TREE_VIEW (priv->treeview);
838 model = gtk_tree_view_get_model (view);
839 selection = gtk_tree_view_get_selection (view);
841 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
843 /* We have configured accounts, select the first one if there
844 * is no other account selected already. */
845 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
846 accounts_dialog_model_select_first (dialog);
850 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
852 /* We have no account configured but we have some
853 * profiles installed. The user obviously wants to add
854 * an account. Click on the Add button for him. */
855 accounts_dialog_button_add_clicked_cb (priv->button_add,
860 /* No account and no profile, warn the user */
861 gtk_widget_hide (priv->vbox_details);
862 gtk_widget_show (priv->frame_no_protocol);
863 gtk_widget_set_sensitive (priv->button_add, FALSE);
867 /* We have an account selected, destroy old settings and create a new
868 * one for the account selected */
869 gtk_widget_hide (priv->frame_no_protocol);
870 gtk_widget_show (priv->vbox_details);
871 gtk_widget_hide (priv->hbox_protocol);
873 if (priv->settings_widget)
875 gtk_widget_destroy (priv->settings_widget);
876 priv->settings_widget = NULL;
879 if (empathy_account_settings_is_ready (settings))
881 account_dialog_create_settings_widget (dialog, settings);
885 priv->settings_ready = settings;
886 priv->settings_ready_id =
887 g_signal_connect (settings, "notify::ready",
888 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
894 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
895 GtkCellEditable *editable,
897 EmpathyAccountsDialog *dialog)
899 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
901 if (priv->connecting_id)
902 g_source_remove (priv->connecting_id);
904 DEBUG ("Editing account name started; stopping flashing");
908 get_status_icon_for_account (EmpathyAccountsDialog *self,
911 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
912 TpConnectionStatus status;
913 TpConnectionStatusReason reason;
914 TpConnectionPresenceType presence;
917 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
919 if (!tp_account_is_enabled (account))
920 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
922 status = tp_account_get_connection_status (account, &reason);
924 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
926 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
927 /* An error occured */
928 return GTK_STOCK_DIALOG_ERROR;
930 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
932 else if (status == TP_CONNECTION_STATUS_CONNECTING)
934 /* Account is connecting. Display a blinking account alternating between
935 * the offline icon and the requested presence. */
936 if (priv->connecting_show)
937 presence = tp_account_get_requested_presence (account, NULL, NULL);
939 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
943 /* status == TP_CONNECTION_STATUS_CONNECTED */
944 presence = tp_account_get_current_presence (account, NULL, NULL);
946 /* If presence is Unset (CM doesn't implement SimplePresence),
947 * display the 'available' icon.
948 * We also check Offline because of this MC5 bug: fd.o #26060 */
949 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
950 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
951 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
954 return empathy_icon_name_for_presence (presence);
958 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
959 GtkCellRenderer *cell,
962 EmpathyAccountsDialog *dialog)
966 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
969 "icon-name", get_status_icon_for_account (dialog, account),
973 g_object_unref (account);
977 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
978 GtkCellRenderer *cell,
981 EmpathyAccountsDialog *dialog)
983 EmpathyAccountSettings *settings;
986 TpConnectionStatus status;
988 gtk_tree_model_get (model, iter,
990 COL_ACCOUNT_SETTINGS, &settings,
993 icon_name = empathy_account_settings_get_icon_name (settings);
994 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1001 g_object_unref (settings);
1004 g_object_unref (pixbuf);
1008 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1013 gtk_tree_model_row_changed (model, path, iter);
1019 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1022 GtkTreeModel *model;
1023 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1025 priv->connecting_show = !priv->connecting_show;
1027 view = GTK_TREE_VIEW (priv->treeview);
1028 model = gtk_tree_view_get_model (view);
1030 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1036 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1039 EmpathyAccountsDialog *dialog)
1041 EmpathyAccountSettings *settings;
1042 GtkTreeModel *model;
1043 GtkTreePath *treepath;
1045 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1046 gboolean connecting;
1048 empathy_account_manager_get_accounts_connected (&connecting);
1052 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1053 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1057 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1058 treepath = gtk_tree_path_new_from_string (path);
1059 gtk_tree_model_get_iter (model, &iter, treepath);
1060 gtk_tree_model_get (model, &iter,
1061 COL_ACCOUNT_SETTINGS, &settings,
1063 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1066 gtk_tree_path_free (treepath);
1068 empathy_account_settings_set_display_name_async (settings, new_text,
1070 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1071 g_object_unref (settings);
1075 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1080 GtkTreeModel *model;
1082 GtkTreeSelection *selection;
1083 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1084 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1086 if (response_id == GTK_RESPONSE_YES)
1088 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1090 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1093 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1095 if (account != NULL)
1097 tp_account_remove_async (account, NULL, NULL);
1098 g_object_unref (account);
1102 /* No need to call accounts_dialog_model_selection_changed while
1103 * removing as we are going to call accounts_dialog_model_select_first
1104 * right after which will update the selection. */
1105 g_signal_handlers_block_by_func (selection,
1106 accounts_dialog_model_selection_changed, account_dialog);
1108 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1110 g_signal_handlers_unblock_by_func (selection,
1111 accounts_dialog_model_selection_changed, account_dialog);
1113 accounts_dialog_model_select_first (account_dialog);
1116 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1120 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1123 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1125 GtkTreeModel *model;
1126 gchar *question_dialog_primary_text;
1128 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1130 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1132 if (account == NULL || !tp_account_is_valid (account))
1134 if (account != NULL)
1135 g_object_unref (account);
1136 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1137 accounts_dialog_model_select_first (dialog);
1141 question_dialog_primary_text = g_strdup_printf (
1142 _("Do you want to remove %s from your computer?"),
1143 tp_account_get_display_name (account));
1145 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1146 _("This will not remove your account on the server."),
1147 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1149 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1150 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1152 g_free (question_dialog_primary_text);
1153 g_object_unref (account);
1157 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1158 EmpathyAccountsDialog *dialog)
1160 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1162 GtkTreeModel *model;
1163 GtkTreeSelection *selection;
1166 view = GTK_TREE_VIEW (priv->treeview);
1167 model = gtk_tree_view_get_model (view);
1168 selection = gtk_tree_view_get_selection (view);
1169 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1172 accounts_dialog_remove_account_iter (dialog, &iter);
1177 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1178 const gchar *path_string,
1179 EmpathyAccountsDialog *dialog)
1181 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1182 GtkTreeModel *model;
1185 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1186 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1189 accounts_dialog_remove_account_iter (dialog, &iter);
1191 #endif /* HAVE_MEEGO */
1194 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1197 GtkTreeViewColumn *column;
1198 GtkCellRenderer *cell;
1199 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1201 view = GTK_TREE_VIEW (priv->treeview);
1202 gtk_tree_view_set_headers_visible (view, FALSE);
1204 /* Account column */
1205 column = gtk_tree_view_column_new ();
1206 gtk_tree_view_column_set_expand (column, TRUE);
1207 gtk_tree_view_append_column (view, column);
1209 /* Status icon renderer */
1210 cell = gtk_cell_renderer_pixbuf_new ();
1211 gtk_tree_view_column_pack_start (column, cell, FALSE);
1212 gtk_tree_view_column_set_cell_data_func (column, cell,
1213 (GtkTreeCellDataFunc)
1214 accounts_dialog_model_status_pixbuf_data_func,
1218 /* Protocol icon renderer */
1219 cell = gtk_cell_renderer_pixbuf_new ();
1220 gtk_tree_view_column_pack_start (column, cell, FALSE);
1221 gtk_tree_view_column_set_cell_data_func (column, cell,
1222 (GtkTreeCellDataFunc)
1223 accounts_dialog_model_protocol_pixbuf_data_func,
1228 cell = gtk_cell_renderer_text_new ();
1230 "ellipsize", PANGO_ELLIPSIZE_END,
1234 gtk_tree_view_column_pack_start (column, cell, TRUE);
1235 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1236 g_signal_connect (cell, "edited",
1237 G_CALLBACK (accounts_dialog_name_edited_cb),
1239 g_signal_connect (cell, "editing-started",
1240 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1242 g_object_set (cell, "ypad", 4, NULL);
1246 cell = empathy_cell_renderer_activatable_new ();
1247 gtk_tree_view_column_pack_start (column, cell, FALSE);
1249 "icon-name", GTK_STOCK_DELETE,
1250 "show-on-select", TRUE,
1253 g_signal_connect (cell, "path-activated",
1254 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1256 #endif /* HAVE_MEEGO */
1259 static EmpathyAccountSettings *
1260 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1263 GtkTreeModel *model;
1264 GtkTreeSelection *selection;
1266 EmpathyAccountSettings *settings;
1267 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1269 view = GTK_TREE_VIEW (priv->treeview);
1270 selection = gtk_tree_view_get_selection (view);
1272 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1275 gtk_tree_model_get (model, &iter,
1276 COL_ACCOUNT_SETTINGS, &settings, -1);
1282 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1283 EmpathyAccountsDialog *dialog)
1285 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1286 EmpathyAccountSettings *settings;
1287 GtkTreeModel *model;
1289 gboolean is_selection;
1290 gboolean creating = FALSE;
1292 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1294 settings = accounts_dialog_model_get_selected_settings (dialog);
1295 accounts_dialog_update_settings (dialog, settings);
1297 if (settings != NULL)
1298 g_object_unref (settings);
1300 if (priv->setting_widget_object != NULL)
1302 g_object_get (priv->setting_widget_object,
1303 "creating-account", &creating, NULL);
1306 /* Update remove button sensitivity */
1307 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating);
1311 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1313 gpointer *user_data)
1315 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1316 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1318 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1320 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1322 /* The user wants to lose unsaved changes to the currently selected
1323 * account and select another account. We discard the changes and
1324 * select the other account. */
1326 GtkTreeSelection *selection;
1328 priv->force_change_row = TRUE;
1329 empathy_account_widget_discard_pending_changes (
1330 priv->setting_widget_object);
1332 path = gtk_tree_row_reference_get_path (priv->destination_row);
1333 selection = gtk_tree_view_get_selection (
1334 GTK_TREE_VIEW (priv->treeview));
1338 /* This will trigger a call to
1339 * accounts_dialog_account_selection_change() */
1340 gtk_tree_selection_select_path (selection, path);
1341 gtk_tree_path_free (path);
1344 gtk_tree_row_reference_free (priv->destination_row);
1348 priv->force_change_row = FALSE;
1353 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1354 GtkTreeModel *model,
1356 gboolean path_currently_selected,
1359 TpAccount *account = NULL;
1360 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1361 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1364 if (priv->force_change_row)
1366 /* We came back here because the user wants to discard changes to his
1367 * modified account. The changes have already been discarded so we
1368 * just change the selected row. */
1369 priv->force_change_row = FALSE;
1373 if (accounts_dialog_has_pending_change (dialog, &account))
1375 /* The currently selected account has some unsaved changes. We ask
1376 * the user if he really wants to lose his changes and select another
1378 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1379 priv->destination_row = gtk_tree_row_reference_new (model, path);
1381 accounts_dialog_show_question_dialog (dialog,
1382 question_dialog_primary_text,
1383 _("You are about to select another account, which will discard\n"
1384 "your changes. Are you sure you want to proceed?"),
1385 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1387 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1388 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1390 g_free (question_dialog_primary_text);
1398 if (account != NULL)
1399 g_object_unref (account);
1405 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1407 GtkListStore *store;
1408 GtkTreeSelection *selection;
1409 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1411 store = gtk_list_store_new (COL_COUNT,
1412 G_TYPE_STRING, /* name */
1413 G_TYPE_UINT, /* status */
1414 TP_TYPE_ACCOUNT, /* account */
1415 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1417 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1418 GTK_TREE_MODEL (store));
1420 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1421 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1422 gtk_tree_selection_set_select_function (selection,
1423 accounts_dialog_account_selection_change, dialog, NULL);
1425 g_signal_connect (selection, "changed",
1426 G_CALLBACK (accounts_dialog_model_selection_changed),
1429 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1430 COL_NAME, GTK_SORT_ASCENDING);
1432 accounts_dialog_model_add_columns (dialog);
1434 g_object_unref (store);
1438 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1439 EmpathyAccountSettings *settings,
1443 GtkTreeSelection *selection;
1444 GtkTreeModel *model;
1446 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1448 /* Update the status in the model */
1449 view = GTK_TREE_VIEW (priv->treeview);
1450 selection = gtk_tree_view_get_selection (view);
1451 model = gtk_tree_view_get_model (view);
1453 for (ok = gtk_tree_model_get_iter_first (model, iter);
1455 ok = gtk_tree_model_iter_next (model, iter))
1457 EmpathyAccountSettings *this_settings;
1460 gtk_tree_model_get (model, iter,
1461 COL_ACCOUNT_SETTINGS, &this_settings,
1464 equal = (this_settings == settings);
1465 g_object_unref (this_settings);
1475 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1480 GtkTreeSelection *selection;
1481 GtkTreeModel *model;
1483 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1485 /* Update the status in the model */
1486 view = GTK_TREE_VIEW (priv->treeview);
1487 selection = gtk_tree_view_get_selection (view);
1488 model = gtk_tree_view_get_model (view);
1490 for (ok = gtk_tree_model_get_iter_first (model, iter);
1492 ok = gtk_tree_model_iter_next (model, iter))
1494 EmpathyAccountSettings *settings;
1497 gtk_tree_model_get (model, iter,
1498 COL_ACCOUNT_SETTINGS, &settings,
1501 equal = empathy_account_settings_has_account (settings, account);
1502 g_object_unref (settings);
1512 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1513 EmpathyAccountSettings *settings)
1515 GtkTreeSelection *selection;
1517 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1519 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1520 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1521 gtk_tree_selection_select_iter (selection, &iter);
1524 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1525 EmpathyAccountSettings *settings)
1527 GtkTreeModel *model;
1530 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1532 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1533 name = empathy_account_settings_get_display_name (settings);
1535 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1537 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1539 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1540 COL_ACCOUNT_SETTINGS, settings,
1545 accounts_dialog_connection_changed_cb (TpAccount *account,
1549 gchar *dbus_error_name,
1550 GHashTable *details,
1551 EmpathyAccountsDialog *dialog)
1553 GtkTreeModel *model;
1556 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1558 /* Update the status-infobar in the details view */
1559 accounts_dialog_update_status_infobar (dialog, account);
1561 /* Update the status in the model */
1562 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1564 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1568 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1569 COL_STATUS, current,
1572 path = gtk_tree_model_get_path (model, &iter);
1573 gtk_tree_model_row_changed (model, path, &iter);
1574 gtk_tree_path_free (path);
1577 empathy_account_manager_get_accounts_connected (&found);
1579 if (!found && priv->connecting_id)
1581 g_source_remove (priv->connecting_id);
1582 priv->connecting_id = 0;
1585 if (found && !priv->connecting_id)
1586 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1587 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1592 update_account_in_treeview (EmpathyAccountsDialog *self,
1595 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1597 GtkTreeModel *model;
1599 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1600 if (accounts_dialog_get_account_iter (self, account, &iter))
1604 path = gtk_tree_model_get_path (model, &iter);
1605 gtk_tree_model_row_changed (model, path, &iter);
1606 gtk_tree_path_free (path);
1611 accounts_dialog_presence_changed_cb (TpAccount *account,
1614 gchar *status_message,
1615 EmpathyAccountsDialog *dialog)
1617 /* Update the status-infobar in the details view */
1618 accounts_dialog_update_status_infobar (dialog, account);
1620 update_account_in_treeview (dialog, account);
1624 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1628 const gchar *display_name;
1630 GtkTreeModel *model;
1631 EmpathyAccountSettings *settings;
1632 TpAccount *selected_account;
1633 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1634 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1636 display_name = tp_account_get_display_name (account);
1637 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1638 settings = accounts_dialog_model_get_selected_settings (dialog);
1639 if (settings == NULL)
1642 selected_account = empathy_account_settings_get_account (settings);
1644 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1646 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1647 COL_NAME, display_name,
1651 if (selected_account == account)
1652 accounts_dialog_update_name_label (dialog, display_name);
1654 g_object_unref (settings);
1658 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1661 EmpathyAccountSettings *settings;
1662 GtkTreeModel *model;
1664 TpConnectionStatus status;
1667 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1669 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1670 status = tp_account_get_connection_status (account, NULL);
1671 name = tp_account_get_display_name (account);
1672 enabled = tp_account_is_enabled (account);
1674 settings = empathy_account_settings_new_for_account (account);
1676 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1677 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1679 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1682 COL_ACCOUNT, account,
1683 COL_ACCOUNT_SETTINGS, settings,
1686 accounts_dialog_connection_changed_cb (account,
1689 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1694 tp_g_signal_connect_object (account, "notify::display-name",
1695 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1698 tp_g_signal_connect_object (account, "status-changed",
1699 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1700 tp_g_signal_connect_object (account, "presence-changed",
1701 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1703 g_object_unref (settings);
1707 account_prepare_cb (GObject *source_object,
1708 GAsyncResult *result,
1711 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1712 TpAccount *account = TP_ACCOUNT (source_object);
1713 GError *error = NULL;
1715 if (!tp_account_prepare_finish (account, result, &error))
1717 DEBUG ("Failed to prepare account: %s", error->message);
1718 g_error_free (error);
1722 accounts_dialog_add_account (dialog, account);
1726 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1729 EmpathyAccountsDialog *dialog)
1731 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1735 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1738 EmpathyAccountsDialog *dialog)
1740 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1742 if (priv->setting_widget_object != NULL &&
1743 accounts_dialog_has_valid_accounts (dialog))
1745 empathy_account_widget_set_other_accounts_exist (
1746 priv->setting_widget_object, TRUE);
1751 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1753 EmpathyAccountsDialog *dialog)
1755 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1757 if (priv->setting_widget_object != NULL &&
1758 !accounts_dialog_has_valid_accounts (dialog))
1760 empathy_account_widget_set_other_accounts_exist (
1761 priv->setting_widget_object, FALSE);
1766 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1768 EmpathyAccountsDialog *dialog)
1771 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1773 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1775 gtk_list_store_remove (GTK_LIST_STORE (
1776 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1781 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1785 GtkTreeModel *model;
1786 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1788 /* Update the status in the model */
1789 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1791 /* Update the status-infobar in the details view */
1792 accounts_dialog_update_status_infobar (dialog, account);
1794 DEBUG ("Account %s is now %s",
1795 tp_account_get_display_name (account),
1796 enabled ? "enabled" : "disabled");
1800 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1802 EmpathyAccountsDialog *dialog)
1804 enable_or_disable_account (dialog, account, FALSE);
1805 update_account_in_treeview (dialog, account);
1809 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1811 EmpathyAccountsDialog *dialog)
1813 enable_or_disable_account (dialog, account, TRUE);
1817 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1818 EmpathyAccountsDialog *dialog)
1820 GtkWidget *import_dialog;
1822 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1824 gtk_widget_show (import_dialog);
1828 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1832 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1834 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1836 if (response_id == GTK_RESPONSE_YES)
1837 gtk_widget_destroy (account_dialog);
1841 accounts_dialog_delete_event_cb (GtkWidget *widget,
1843 EmpathyAccountsDialog *dialog)
1845 /* we maunally handle responses to delete events */
1850 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1853 GtkTreeSelection *selection;
1855 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1857 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1858 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1859 gtk_tree_selection_select_iter (selection, &iter);
1863 finished_loading (EmpathyAccountsDialog *self)
1865 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1867 gtk_widget_set_sensitive (priv->button_add, TRUE);
1868 gtk_widget_set_sensitive (priv->button_import, TRUE);
1872 accounts_dialog_cms_prepare_cb (GObject *source,
1873 GAsyncResult *result,
1876 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1877 EmpathyAccountsDialog *dialog = user_data;
1878 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1880 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1883 accounts_dialog_update_settings (dialog, NULL);
1885 if (priv->initial_selection != NULL)
1887 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1888 g_object_unref (priv->initial_selection);
1889 priv->initial_selection = NULL;
1893 finished_loading (dialog);
1897 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1899 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1900 GList *accounts, *l;
1902 g_signal_connect (priv->account_manager, "account-validity-changed",
1903 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1905 g_signal_connect (priv->account_manager, "account-removed",
1906 G_CALLBACK (accounts_dialog_account_removed_cb),
1908 g_signal_connect (priv->account_manager, "account-enabled",
1909 G_CALLBACK (accounts_dialog_account_enabled_cb),
1911 g_signal_connect (priv->account_manager, "account-disabled",
1912 G_CALLBACK (accounts_dialog_account_disabled_cb),
1915 /* Add existing accounts */
1916 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1917 for (l = accounts; l; l = l->next)
1919 accounts_dialog_add_account (dialog, l->data);
1921 g_list_free (accounts);
1923 priv->cms = empathy_connection_managers_dup_singleton ();
1925 empathy_connection_managers_prepare_async (priv->cms,
1926 accounts_dialog_cms_prepare_cb, dialog);
1928 accounts_dialog_model_select_first (dialog);
1932 accounts_dialog_manager_ready_cb (GObject *source_object,
1933 GAsyncResult *result,
1936 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1937 GError *error = NULL;
1939 if (!tp_account_manager_prepare_finish (manager, result, &error))
1941 DEBUG ("Failed to prepare account manager: %s", error->message);
1942 g_error_free (error);
1946 accounts_dialog_accounts_setup (user_data);
1950 dialog_response_cb (GtkWidget *widget,
1954 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1956 if (response_id == GTK_RESPONSE_HELP)
1958 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1960 else if (response_id == GTK_RESPONSE_CLOSE ||
1961 response_id == GTK_RESPONSE_DELETE_EVENT)
1963 TpAccount *account = NULL;
1965 if (accounts_dialog_has_pending_change (dialog, &account))
1967 gchar *question_dialog_primary_text = get_dialog_primary_text (
1970 accounts_dialog_show_question_dialog (dialog,
1971 question_dialog_primary_text,
1972 _("You are about to close the window, which will discard\n"
1973 "your changes. Are you sure you want to proceed?"),
1974 G_CALLBACK (accounts_dialog_close_response_cb),
1976 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1977 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1979 g_free (question_dialog_primary_text);
1983 gtk_widget_destroy (widget);
1986 if (account != NULL)
1987 g_object_unref (account);
1992 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1994 GtkWidget *top_hbox;
1997 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1998 GtkWidget *content_area;
1999 GtkWidget *action_area, *vbox, *hbox, *align;
2001 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2003 gui = empathy_builder_get_file (filename,
2004 "accounts_dialog_hbox", &top_hbox,
2005 "vbox_details", &priv->vbox_details,
2006 "frame_no_protocol", &priv->frame_no_protocol,
2007 "alignment_settings", &priv->alignment_settings,
2008 "alignment_infobar", &priv->alignment_infobar,
2009 "treeview", &priv->treeview,
2010 "button_add", &priv->button_add,
2011 "button_remove", &priv->button_remove,
2012 "button_import", &priv->button_import,
2013 "hbox_protocol", &priv->hbox_protocol,
2017 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2019 empathy_builder_connect (gui, dialog,
2020 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2021 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2022 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2025 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2027 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
2029 g_object_unref (gui);
2031 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2034 gtk_widget_hide (action_area);
2035 gtk_widget_hide (priv->button_remove);
2036 #endif /* HAVE_MEEGO */
2038 /* Remove button is insensitive until we have a selected account */
2039 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2041 /* Add and Import buttons are insensitive while the dialog is loading */
2042 gtk_widget_set_sensitive (priv->button_add, FALSE);
2043 gtk_widget_set_sensitive (priv->button_import, FALSE);
2045 priv->combobox_protocol = empathy_protocol_chooser_new ();
2046 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
2048 g_signal_connect (priv->combobox_protocol, "changed",
2049 G_CALLBACK (accounts_dialog_protocol_changed_cb),
2052 if (priv->parent_window)
2053 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2054 priv->parent_window);
2056 priv->infobar = gtk_info_bar_new ();
2057 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2059 gtk_widget_show (priv->infobar);
2061 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
2063 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2064 GTK_ICON_SIZE_DIALOG);
2065 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2066 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
2067 gtk_widget_show (priv->image_type);
2069 vbox = gtk_vbox_new (FALSE, 6);
2070 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
2071 gtk_widget_show (vbox);
2074 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2075 gtk_widget_show (align);
2077 priv->label_name = gtk_label_new (NULL);
2078 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
2079 gtk_widget_show (priv->label_name);
2081 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2084 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2085 gtk_widget_show (align);
2086 hbox = gtk_hbox_new (FALSE, 6);
2087 gtk_widget_show (hbox);
2088 gtk_container_add (GTK_CONTAINER (align), hbox);
2090 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2092 /* set up spinner */
2093 priv->throbber = gtk_spinner_new ();
2095 priv->image_status = gtk_image_new_from_icon_name (
2096 empathy_icon_name_for_presence (
2097 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2099 priv->label_status = gtk_label_new (NULL);
2100 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
2101 gtk_widget_show (priv->label_status);
2103 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2104 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
2105 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
2107 /* Tweak the dialog */
2108 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2109 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2111 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2113 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2115 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
2117 /* add dialog buttons */
2118 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2120 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2121 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2122 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2125 g_signal_connect (dialog, "response",
2126 G_CALLBACK (dialog_response_cb), dialog);
2128 g_signal_connect (dialog, "delete-event",
2129 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2133 do_dispose (GObject *obj)
2135 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2136 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2138 if (priv->connecting_id != 0)
2140 g_source_remove (priv->connecting_id);
2141 priv->connecting_id = 0;
2144 if (priv->account_manager != NULL)
2146 g_object_unref (priv->account_manager);
2147 priv->account_manager = NULL;
2150 if (priv->cms != NULL)
2152 g_object_unref (priv->cms);
2156 if (priv->connectivity)
2158 g_object_unref (priv->connectivity);
2159 priv->connectivity = NULL;
2162 if (priv->initial_selection != NULL)
2164 g_object_unref (priv->initial_selection);
2165 priv->initial_selection = NULL;
2168 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2172 do_get_property (GObject *object,
2177 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2179 switch (property_id)
2182 g_value_set_object (value, priv->parent_window);
2185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2190 do_set_property (GObject *object,
2192 const GValue *value,
2195 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2197 switch (property_id)
2200 priv->parent_window = g_value_get_object (value);
2203 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2208 do_constructed (GObject *object)
2210 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2211 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2212 GtkTreeModel *model;
2213 GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
2215 accounts_dialog_build_ui (dialog);
2216 accounts_dialog_model_setup (dialog);
2218 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2219 g_signal_connect (model, "row-inserted",
2220 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2221 g_signal_connect (model, "row-deleted",
2222 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2224 /* Set up signalling */
2225 priv->account_manager = tp_account_manager_dup ();
2227 tp_account_manager_prepare_async (priv->account_manager, NULL,
2228 accounts_dialog_manager_ready_cb, dialog);
2230 if (empathy_import_accounts_to_import ())
2232 gtk_widget_show (priv->button_import);
2234 if (!g_settings_get_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED))
2236 GtkWidget *import_dialog;
2238 g_settings_set_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED, TRUE);
2239 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2241 gtk_widget_show (import_dialog);
2245 priv->connectivity = empathy_connectivity_dup_singleton ();
2247 g_object_unref (gsettings);
2251 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2253 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2254 GParamSpec *param_spec;
2256 oclass->dispose = do_dispose;
2257 oclass->constructed = do_constructed;
2258 oclass->set_property = do_set_property;
2259 oclass->get_property = do_get_property;
2261 param_spec = g_param_spec_object ("parent",
2262 "parent", "The parent window",
2264 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2265 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2267 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2271 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2273 EmpathyAccountsDialogPriv *priv;
2275 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2276 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2277 EmpathyAccountsDialogPriv);
2278 dialog->priv = priv;
2281 /* public methods */
2284 empathy_accounts_dialog_show (GtkWindow *parent,
2285 TpAccount *selected_account)
2287 EmpathyAccountsDialog *dialog;
2288 EmpathyAccountsDialogPriv *priv;
2290 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2291 "parent", parent, NULL);
2293 priv = GET_PRIV (dialog);
2295 if (selected_account)
2297 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2298 accounts_dialog_set_selected_account (dialog, selected_account);
2300 /* save the selection to set it later when the cms
2303 priv->initial_selection = g_object_ref (selected_account);
2306 gtk_window_present (GTK_WINDOW (dialog));
2308 return GTK_WIDGET (dialog);
2312 empathy_accounts_dialog_show_application (GdkScreen *screen,
2313 TpAccount *selected_account,
2317 GError *error = NULL;
2318 const gchar *argv[4] = { NULL, };
2320 gchar *account_option = NULL;
2323 g_return_if_fail (GDK_IS_SCREEN (screen));
2324 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2326 /* Try to run from source directory if possible */
2327 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
2328 "empathy-accounts", NULL);
2330 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2333 path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
2338 if (selected_account != NULL)
2340 const gchar *account_path;
2342 account_path = tp_proxy_get_object_path (TP_PROXY (selected_account));
2343 account_option = g_strdup_printf ("--select-account=%s",
2344 &account_path[strlen (TP_ACCOUNT_OBJECT_PATH_BASE)]);
2346 argv[i++] = account_option;
2350 argv[i++] = "--if-needed";
2353 argv[i++] = "--hidden";
2355 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2357 selected_account == NULL ? "<none selected>" :
2358 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2360 gdk_spawn_on_screen (screen, NULL, (gchar**) argv, NULL, G_SPAWN_SEARCH_PATH,
2361 NULL, NULL, NULL, &error);
2364 g_warning ("Failed to open accounts dialog: %s", error->message);
2365 g_error_free (error);
2368 g_free (account_option);
2373 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2375 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2376 gboolean result = FALSE;
2378 if (priv->setting_widget_object == NULL)
2381 g_object_get (priv->setting_widget_object,
2382 "creating-account", &result, NULL);