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;
128 gboolean dispose_has_run;
129 } EmpathyAccountsDialogPriv;
135 COL_ACCOUNT_SETTINGS,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
159 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
160 EmpathyAccountSettings *settings);
162 static void accounts_dialog_connection_changed_cb (TpAccount *account,
166 gchar *dbus_error_name,
168 EmpathyAccountsDialog *dialog);
170 static void accounts_dialog_presence_changed_cb (TpAccount *account,
173 gchar *status_message,
174 EmpathyAccountsDialog *dialog);
176 static void accounts_dialog_model_selection_changed (
177 GtkTreeSelection *selection,
178 EmpathyAccountsDialog *dialog);
181 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
182 const gchar *display_name)
185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
187 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
188 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
194 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
195 const gchar *message)
197 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
198 gchar *message_markup;
200 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
201 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
202 g_free (message_markup);
206 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
209 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
210 gchar *status_message = NULL;
216 GtkTreeSelection *selection;
218 TpAccount *selected_account;
219 gboolean account_enabled;
220 gboolean creating_account;
222 view = GTK_TREE_VIEW (priv->treeview);
223 selection = gtk_tree_view_get_selection (view);
225 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
228 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
229 if (selected_account != NULL)
230 g_object_unref (selected_account);
232 /* do not update the infobar when the account is not selected */
233 if (account != selected_account)
238 status = tp_account_get_connection_status (account, &reason);
239 presence = tp_account_get_current_presence (account, NULL, &status_message);
240 account_enabled = tp_account_is_enabled (account);
241 creating_account = FALSE;
243 if (status == TP_CONNECTION_STATUS_CONNECTED &&
244 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
245 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
246 /* If presence is Unset (CM doesn't implement SimplePresence) but we
247 * are connected, consider ourself as Available.
248 * We also check Offline because of this MC5 bug: fd.o #26060 */
249 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
251 /* set presence to offline if account is disabled
252 * (else no icon is shown in infobar)*/
253 if (!account_enabled)
254 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
258 status = TP_CONNECTION_STATUS_DISCONNECTED;
259 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
260 account_enabled = FALSE;
261 creating_account = TRUE;
264 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
265 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
271 case TP_CONNECTION_STATUS_CONNECTING:
272 accounts_dialog_status_infobar_set_message (dialog,
274 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
277 gtk_spinner_start (GTK_SPINNER (priv->throbber));
278 gtk_widget_show (priv->throbber);
279 gtk_widget_hide (priv->image_status);
281 case TP_CONNECTION_STATUS_CONNECTED:
282 if (g_strcmp0 (status_message, "") == 0)
286 message = g_strdup_printf ("%s",
287 empathy_presence_get_default_message (presence));
289 accounts_dialog_status_infobar_set_message (dialog, message);
296 message = g_strdup_printf ("%s — %s",
297 empathy_presence_get_default_message (presence),
300 accounts_dialog_status_infobar_set_message (dialog, message);
303 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
306 gtk_widget_show (priv->image_status);
307 gtk_widget_hide (priv->throbber);
309 case TP_CONNECTION_STATUS_DISCONNECTED:
310 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
314 message = g_strdup_printf (_("Offline — %s"),
315 empathy_status_reason_get_default_message (reason));
316 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
317 GTK_MESSAGE_WARNING);
319 accounts_dialog_status_infobar_set_message (dialog, message);
326 message = g_strdup_printf (_("Disconnected — %s"),
327 empathy_status_reason_get_default_message (reason));
328 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
331 accounts_dialog_status_infobar_set_message (dialog, message);
335 if (!empathy_connectivity_is_online (priv->connectivity))
336 accounts_dialog_status_infobar_set_message (dialog,
337 _("Offline — No Network Connection"));
339 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
340 gtk_widget_show (priv->image_status);
341 gtk_widget_hide (priv->throbber);
344 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
345 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
346 GTK_MESSAGE_WARNING);
348 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
349 gtk_widget_hide (priv->image_status);
350 gtk_widget_hide (priv->throbber);
355 accounts_dialog_status_infobar_set_message (dialog,
356 _("Offline — Account Disabled"));
358 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
359 GTK_MESSAGE_WARNING);
360 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
361 gtk_widget_show (priv->image_status);
362 gtk_widget_hide (priv->throbber);
365 gtk_widget_show (priv->label_status);
367 if (!creating_account)
368 gtk_widget_show (priv->infobar);
370 gtk_widget_hide (priv->infobar);
372 g_free (status_message);
376 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
380 GtkTreeSelection *selection;
382 EmpathyAccountSettings *settings;
384 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
386 view = GTK_TREE_VIEW (priv->treeview);
387 selection = gtk_tree_view_get_selection (view);
389 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
392 gtk_tree_model_get (model, &iter,
393 COL_ACCOUNT_SETTINGS, &settings,
394 COL_ACCOUNT, &account, -1);
396 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
400 /* We were creating an account. We remove the selected row */
401 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
405 /* We were modifying an account. We discard the changes by reloading the
406 * settings and the UI. */
407 accounts_dialog_update_settings (dialog, settings);
408 g_object_unref (account);
411 gtk_widget_set_sensitive (priv->treeview, TRUE);
412 gtk_widget_set_sensitive (priv->button_add, TRUE);
413 gtk_widget_set_sensitive (priv->button_remove, TRUE);
414 gtk_widget_set_sensitive (priv->button_import, TRUE);
416 if (settings != NULL)
417 g_object_unref (settings);
421 empathy_account_dialog_widget_cancelled_cb (
422 EmpathyAccountWidget *widget_object,
423 EmpathyAccountsDialog *dialog)
425 empathy_account_dialog_cancel (dialog);
429 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
431 EmpathyAccountsDialog *dialog)
433 EmpathyAccountSettings *settings =
434 accounts_dialog_model_get_selected_settings (dialog);
435 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
437 accounts_dialog_update_settings (dialog, settings);
438 accounts_dialog_update_status_infobar (dialog,
439 empathy_account_settings_get_account (settings));
441 gtk_widget_set_sensitive (priv->treeview, TRUE);
442 gtk_widget_set_sensitive (priv->button_add, TRUE);
443 gtk_widget_set_sensitive (priv->button_remove, TRUE);
444 gtk_widget_set_sensitive (priv->button_import, TRUE);
447 g_object_unref (settings);
451 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
453 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
458 g_object_get (priv->setting_widget_object,
459 "creating-account", &creating, NULL);
464 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
466 if (gtk_tree_model_get_iter_first (model, &iter))
467 return gtk_tree_model_iter_next (model, &iter);
473 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
474 EmpathyAccountSettings *settings)
476 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
480 priv->setting_widget_object =
481 empathy_account_widget_new_for_protocol (settings, FALSE);
483 if (accounts_dialog_has_valid_accounts (dialog))
484 empathy_account_widget_set_other_accounts_exist (
485 priv->setting_widget_object, TRUE);
487 priv->settings_widget =
488 empathy_account_widget_get_widget (priv->setting_widget_object);
490 g_signal_connect (priv->setting_widget_object, "account-created",
491 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
492 g_signal_connect (priv->setting_widget_object, "cancelled",
493 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
495 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
496 priv->settings_widget);
497 gtk_widget_show (priv->settings_widget);
499 icon_name = empathy_account_settings_get_icon_name (settings);
501 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
503 /* show the default icon; keep this in sync with the default
504 * one in empathy-accounts-dialog.ui.
506 icon_name = GTK_STOCK_CUT;
508 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
509 icon_name, GTK_ICON_SIZE_DIALOG);
510 gtk_widget_set_tooltip_text (priv->image_type,
511 empathy_protocol_name_to_display_name
512 (empathy_account_settings_get_protocol (settings)));
513 gtk_widget_show (priv->image_type);
515 accounts_dialog_update_name_label (dialog,
516 empathy_account_settings_get_display_name (settings));
518 account = empathy_account_settings_get_account (settings);
519 accounts_dialog_update_status_infobar (dialog, account);
523 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
525 EmpathyAccountsDialog *dialog)
527 if (empathy_account_settings_is_ready (settings))
528 account_dialog_create_settings_widget (dialog, settings);
532 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
536 GtkTreeSelection *selection;
538 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
541 view = GTK_TREE_VIEW (priv->treeview);
542 model = gtk_tree_view_get_model (view);
544 if (gtk_tree_model_get_iter_first (model, &iter))
546 selection = gtk_tree_view_get_selection (view);
547 gtk_tree_selection_select_iter (selection, &iter);
551 accounts_dialog_update_settings (dialog, NULL);
556 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
561 GtkTreeSelection *selection;
562 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
564 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
566 if (gtk_tree_selection_get_selected (selection, &model, &iter))
567 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
569 return priv->setting_widget_object != NULL
570 && empathy_account_widget_contains_pending_changes (
571 priv->setting_widget_object);
575 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
577 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
578 EmpathyAccountSettings *settings;
580 const gchar *name, *display_name;
581 TpConnectionManager *cm;
582 TpConnectionManagerProtocol *proto;
583 gboolean is_gtalk, is_facebook;
585 cm = empathy_protocol_chooser_dup_selected (
586 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk,
593 else if (is_facebook)
598 display_name = empathy_protocol_name_to_display_name (name);
599 if (display_name == NULL)
600 display_name = proto->name;
603 /* To translator: %s is the name of the protocol, such as "Google Talk" or
606 str = g_strdup_printf (_("New %s account"), display_name);
607 settings = empathy_account_settings_new (cm->name, proto->name, str);
613 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
615 /* We should not have to set the server but that may cause issue with
617 empathy_account_settings_set_string (settings, "server",
620 else if (is_facebook)
622 empathy_account_settings_set_icon_name_async (settings, "im-facebook",
625 empathy_account_settings_set_string (settings, "server",
626 "chat.facebook.com");
629 accounts_dialog_add (dialog, settings);
630 accounts_dialog_model_set_selected (dialog, settings);
632 gtk_widget_show_all (priv->hbox_protocol);
634 g_object_unref (settings);
639 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
640 EmpathyAccountsDialog *dialog)
642 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
643 GtkTreeSelection *selection;
647 EmpathyAccountSettings *settings;
648 gchar *account = NULL, *password = NULL;
650 /* The "changed" signal is fired during the initiation of the
651 * EmpathyProtocolChooser while populating the widget. Such signals should
652 * be ignored so we check if we are actually creating a new account. */
653 if (priv->setting_widget_object == NULL)
656 g_object_get (priv->setting_widget_object,
657 "creating-account", &creating, NULL);
661 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
663 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
666 /* Save "account" and "password" parameters */
667 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
669 if (settings != NULL)
671 account = g_strdup (empathy_account_settings_get_string (settings,
673 password = g_strdup (empathy_account_settings_get_string (settings,
675 g_object_unref (settings);
678 /* We are creating a new widget to replace the current one, don't ask
679 * confirmation to the user. */
680 priv->force_change_row = TRUE;
682 /* We'll update the selection after we create the new account widgets;
683 * updating it right now causes problems for the # of accounts = zero case */
684 g_signal_handlers_block_by_func (selection,
685 accounts_dialog_model_selection_changed, dialog);
687 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
689 g_signal_handlers_unblock_by_func (selection,
690 accounts_dialog_model_selection_changed, dialog);
692 accounts_dialog_setup_ui_to_add_account (dialog);
694 /* Restore "account" and "password" parameters in the new widget */
697 empathy_account_widget_set_account_param (priv->setting_widget_object,
702 if (password != NULL)
704 empathy_account_widget_set_password_param (priv->setting_widget_object,
711 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
712 const gchar *primary_text,
713 const gchar *secondary_text,
714 GCallback response_callback,
716 const gchar *first_button_text,
720 GtkWidget *message_dialog;
721 const gchar *button_text;
723 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
724 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
725 GTK_MESSAGE_QUESTION,
729 gtk_message_dialog_format_secondary_text (
730 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
732 va_start (button_args, first_button_text);
733 for (button_text = first_button_text;
735 button_text = va_arg (button_args, const gchar *))
738 response_id = va_arg (button_args, gint);
740 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
743 va_end (button_args);
745 g_signal_connect (message_dialog, "response", response_callback, user_data);
747 gtk_widget_show (message_dialog);
751 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
755 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
756 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
758 gtk_widget_destroy (GTK_WIDGET (message_dialog));
760 if (response_id == GTK_RESPONSE_YES)
762 empathy_account_widget_discard_pending_changes (
763 priv->setting_widget_object);
764 accounts_dialog_setup_ui_to_add_account (dialog);
769 get_dialog_primary_text (TpAccount *account)
773 /* Existing account */
774 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
775 tp_account_get_display_name (account));
779 /* Newly created account */
780 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
785 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
786 EmpathyAccountsDialog *dialog)
788 TpAccount *account = NULL;
789 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
791 if (accounts_dialog_has_pending_change (dialog, &account))
793 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
795 accounts_dialog_show_question_dialog (dialog,
796 question_dialog_primary_text,
797 _("You are about to create a new account, which will discard\n"
798 "your changes. Are you sure you want to proceed?"),
799 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
801 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
802 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
804 g_free (question_dialog_primary_text);
808 accounts_dialog_setup_ui_to_add_account (dialog);
809 gtk_widget_set_sensitive (priv->treeview, FALSE);
810 gtk_widget_set_sensitive (priv->button_add, FALSE);
811 gtk_widget_set_sensitive (priv->button_remove, FALSE);
812 gtk_widget_set_sensitive (priv->button_import, FALSE);
816 g_object_unref (account);
820 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
821 EmpathyAccountSettings *settings)
823 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
825 if (priv->settings_ready != NULL)
827 g_signal_handler_disconnect (priv->settings_ready,
828 priv->settings_ready_id);
829 priv->settings_ready = NULL;
830 priv->settings_ready_id = 0;
837 GtkTreeSelection *selection;
839 view = GTK_TREE_VIEW (priv->treeview);
840 model = gtk_tree_view_get_model (view);
841 selection = gtk_tree_view_get_selection (view);
843 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
845 /* We have configured accounts, select the first one if there
846 * is no other account selected already. */
847 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
848 accounts_dialog_model_select_first (dialog);
852 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
854 /* We have no account configured but we have some
855 * profiles installed. The user obviously wants to add
856 * an account. Click on the Add button for him. */
857 accounts_dialog_button_add_clicked_cb (priv->button_add,
862 /* No account and no profile, warn the user */
863 gtk_widget_hide (priv->vbox_details);
864 gtk_widget_show (priv->frame_no_protocol);
865 gtk_widget_set_sensitive (priv->button_add, FALSE);
869 /* We have an account selected, destroy old settings and create a new
870 * one for the account selected */
871 gtk_widget_hide (priv->frame_no_protocol);
872 gtk_widget_show (priv->vbox_details);
873 gtk_widget_hide (priv->hbox_protocol);
875 if (priv->settings_widget)
877 gtk_widget_destroy (priv->settings_widget);
878 priv->settings_widget = NULL;
881 if (empathy_account_settings_is_ready (settings))
883 account_dialog_create_settings_widget (dialog, settings);
887 priv->settings_ready = settings;
888 priv->settings_ready_id =
889 g_signal_connect (settings, "notify::ready",
890 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
896 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
897 GtkCellEditable *editable,
899 EmpathyAccountsDialog *dialog)
901 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
903 if (priv->connecting_id)
904 g_source_remove (priv->connecting_id);
906 DEBUG ("Editing account name started; stopping flashing");
910 get_status_icon_for_account (EmpathyAccountsDialog *self,
913 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
914 TpConnectionStatus status;
915 TpConnectionStatusReason reason;
916 TpConnectionPresenceType presence;
919 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
921 if (!tp_account_is_enabled (account))
922 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
924 status = tp_account_get_connection_status (account, &reason);
926 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
928 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
929 /* An error occured */
930 return GTK_STOCK_DIALOG_ERROR;
932 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
934 else if (status == TP_CONNECTION_STATUS_CONNECTING)
936 /* Account is connecting. Display a blinking account alternating between
937 * the offline icon and the requested presence. */
938 if (priv->connecting_show)
939 presence = tp_account_get_requested_presence (account, NULL, NULL);
941 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
945 /* status == TP_CONNECTION_STATUS_CONNECTED */
946 presence = tp_account_get_current_presence (account, NULL, NULL);
948 /* If presence is Unset (CM doesn't implement SimplePresence),
949 * display the 'available' icon.
950 * We also check Offline because of this MC5 bug: fd.o #26060 */
951 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
952 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
953 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
956 return empathy_icon_name_for_presence (presence);
960 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
961 GtkCellRenderer *cell,
964 EmpathyAccountsDialog *dialog)
968 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
971 "icon-name", get_status_icon_for_account (dialog, account),
975 g_object_unref (account);
979 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
980 GtkCellRenderer *cell,
983 EmpathyAccountsDialog *dialog)
985 EmpathyAccountSettings *settings;
988 TpConnectionStatus status;
990 gtk_tree_model_get (model, iter,
992 COL_ACCOUNT_SETTINGS, &settings,
995 icon_name = empathy_account_settings_get_icon_name (settings);
996 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
1003 g_object_unref (settings);
1006 g_object_unref (pixbuf);
1010 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
1015 gtk_tree_model_row_changed (model, path, iter);
1021 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
1024 GtkTreeModel *model;
1025 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1027 priv->connecting_show = !priv->connecting_show;
1029 view = GTK_TREE_VIEW (priv->treeview);
1030 model = gtk_tree_view_get_model (view);
1032 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1038 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1041 EmpathyAccountsDialog *dialog)
1043 EmpathyAccountSettings *settings;
1044 GtkTreeModel *model;
1045 GtkTreePath *treepath;
1047 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1048 gboolean connecting;
1050 empathy_account_manager_get_accounts_connected (&connecting);
1054 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1055 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1059 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1060 treepath = gtk_tree_path_new_from_string (path);
1061 gtk_tree_model_get_iter (model, &iter, treepath);
1062 gtk_tree_model_get (model, &iter,
1063 COL_ACCOUNT_SETTINGS, &settings,
1065 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1068 gtk_tree_path_free (treepath);
1070 empathy_account_settings_set_display_name_async (settings, new_text,
1072 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1073 g_object_unref (settings);
1077 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1082 GtkTreeModel *model;
1084 GtkTreeSelection *selection;
1085 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1086 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1088 if (response_id == GTK_RESPONSE_YES)
1090 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1092 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1095 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1097 if (account != NULL)
1099 tp_account_remove_async (account, NULL, NULL);
1100 g_object_unref (account);
1104 /* No need to call accounts_dialog_model_selection_changed while
1105 * removing as we are going to call accounts_dialog_model_select_first
1106 * right after which will update the selection. */
1107 g_signal_handlers_block_by_func (selection,
1108 accounts_dialog_model_selection_changed, account_dialog);
1110 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1112 g_signal_handlers_unblock_by_func (selection,
1113 accounts_dialog_model_selection_changed, account_dialog);
1115 accounts_dialog_model_select_first (account_dialog);
1118 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1122 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1125 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1127 GtkTreeModel *model;
1128 gchar *question_dialog_primary_text;
1130 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1132 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1134 if (account == NULL || !tp_account_is_valid (account))
1136 if (account != NULL)
1137 g_object_unref (account);
1138 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1139 accounts_dialog_model_select_first (dialog);
1143 question_dialog_primary_text = g_strdup_printf (
1144 _("Do you want to remove %s from your computer?"),
1145 tp_account_get_display_name (account));
1147 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1148 _("This will not remove your account on the server."),
1149 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1151 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1152 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1154 g_free (question_dialog_primary_text);
1155 g_object_unref (account);
1159 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1160 EmpathyAccountsDialog *dialog)
1162 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1164 GtkTreeModel *model;
1165 GtkTreeSelection *selection;
1168 view = GTK_TREE_VIEW (priv->treeview);
1169 model = gtk_tree_view_get_model (view);
1170 selection = gtk_tree_view_get_selection (view);
1171 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1174 accounts_dialog_remove_account_iter (dialog, &iter);
1179 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1180 const gchar *path_string,
1181 EmpathyAccountsDialog *dialog)
1183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1184 GtkTreeModel *model;
1187 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1188 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1191 accounts_dialog_remove_account_iter (dialog, &iter);
1193 #endif /* HAVE_MEEGO */
1196 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1199 GtkTreeViewColumn *column;
1200 GtkCellRenderer *cell;
1201 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1203 view = GTK_TREE_VIEW (priv->treeview);
1204 gtk_tree_view_set_headers_visible (view, FALSE);
1206 /* Account column */
1207 column = gtk_tree_view_column_new ();
1208 gtk_tree_view_column_set_expand (column, TRUE);
1209 gtk_tree_view_append_column (view, column);
1211 /* Status icon renderer */
1212 cell = gtk_cell_renderer_pixbuf_new ();
1213 gtk_tree_view_column_pack_start (column, cell, FALSE);
1214 gtk_tree_view_column_set_cell_data_func (column, cell,
1215 (GtkTreeCellDataFunc)
1216 accounts_dialog_model_status_pixbuf_data_func,
1220 /* Protocol icon renderer */
1221 cell = gtk_cell_renderer_pixbuf_new ();
1222 gtk_tree_view_column_pack_start (column, cell, FALSE);
1223 gtk_tree_view_column_set_cell_data_func (column, cell,
1224 (GtkTreeCellDataFunc)
1225 accounts_dialog_model_protocol_pixbuf_data_func,
1230 cell = gtk_cell_renderer_text_new ();
1232 "ellipsize", PANGO_ELLIPSIZE_END,
1236 gtk_tree_view_column_pack_start (column, cell, TRUE);
1237 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1238 g_signal_connect (cell, "edited",
1239 G_CALLBACK (accounts_dialog_name_edited_cb),
1241 g_signal_connect (cell, "editing-started",
1242 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1244 g_object_set (cell, "ypad", 4, NULL);
1248 cell = empathy_cell_renderer_activatable_new ();
1249 gtk_tree_view_column_pack_start (column, cell, FALSE);
1251 "icon-name", GTK_STOCK_DELETE,
1252 "show-on-select", TRUE,
1255 g_signal_connect (cell, "path-activated",
1256 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1258 #endif /* HAVE_MEEGO */
1261 static EmpathyAccountSettings *
1262 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1265 GtkTreeModel *model;
1266 GtkTreeSelection *selection;
1268 EmpathyAccountSettings *settings;
1269 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1271 view = GTK_TREE_VIEW (priv->treeview);
1272 selection = gtk_tree_view_get_selection (view);
1274 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1277 gtk_tree_model_get (model, &iter,
1278 COL_ACCOUNT_SETTINGS, &settings, -1);
1284 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1285 EmpathyAccountsDialog *dialog)
1287 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1288 EmpathyAccountSettings *settings;
1289 GtkTreeModel *model;
1291 gboolean is_selection;
1292 gboolean creating = FALSE;
1294 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1296 settings = accounts_dialog_model_get_selected_settings (dialog);
1297 accounts_dialog_update_settings (dialog, settings);
1299 if (settings != NULL)
1300 g_object_unref (settings);
1302 if (priv->setting_widget_object != NULL)
1304 g_object_get (priv->setting_widget_object,
1305 "creating-account", &creating, NULL);
1308 /* Update remove button sensitivity */
1309 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating);
1313 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1315 gpointer *user_data)
1317 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1318 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1320 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1322 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1324 /* The user wants to lose unsaved changes to the currently selected
1325 * account and select another account. We discard the changes and
1326 * select the other account. */
1328 GtkTreeSelection *selection;
1330 priv->force_change_row = TRUE;
1331 empathy_account_widget_discard_pending_changes (
1332 priv->setting_widget_object);
1334 path = gtk_tree_row_reference_get_path (priv->destination_row);
1335 selection = gtk_tree_view_get_selection (
1336 GTK_TREE_VIEW (priv->treeview));
1340 /* This will trigger a call to
1341 * accounts_dialog_account_selection_change() */
1342 gtk_tree_selection_select_path (selection, path);
1343 gtk_tree_path_free (path);
1346 gtk_tree_row_reference_free (priv->destination_row);
1350 priv->force_change_row = FALSE;
1355 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1356 GtkTreeModel *model,
1358 gboolean path_currently_selected,
1361 TpAccount *account = NULL;
1362 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1363 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1366 if (priv->force_change_row)
1368 /* We came back here because the user wants to discard changes to his
1369 * modified account. The changes have already been discarded so we
1370 * just change the selected row. */
1371 priv->force_change_row = FALSE;
1375 if (accounts_dialog_has_pending_change (dialog, &account))
1377 /* The currently selected account has some unsaved changes. We ask
1378 * the user if he really wants to lose his changes and select another
1380 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1381 priv->destination_row = gtk_tree_row_reference_new (model, path);
1383 accounts_dialog_show_question_dialog (dialog,
1384 question_dialog_primary_text,
1385 _("You are about to select another account, which will discard\n"
1386 "your changes. Are you sure you want to proceed?"),
1387 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1389 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1390 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1392 g_free (question_dialog_primary_text);
1400 if (account != NULL)
1401 g_object_unref (account);
1407 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1409 GtkListStore *store;
1410 GtkTreeSelection *selection;
1411 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1413 store = gtk_list_store_new (COL_COUNT,
1414 G_TYPE_STRING, /* name */
1415 G_TYPE_UINT, /* status */
1416 TP_TYPE_ACCOUNT, /* account */
1417 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1419 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1420 GTK_TREE_MODEL (store));
1422 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1423 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1424 gtk_tree_selection_set_select_function (selection,
1425 accounts_dialog_account_selection_change, dialog, NULL);
1427 g_signal_connect (selection, "changed",
1428 G_CALLBACK (accounts_dialog_model_selection_changed),
1431 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1432 COL_NAME, GTK_SORT_ASCENDING);
1434 accounts_dialog_model_add_columns (dialog);
1436 g_object_unref (store);
1440 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1441 EmpathyAccountSettings *settings,
1445 GtkTreeSelection *selection;
1446 GtkTreeModel *model;
1448 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1450 /* Update the status in the model */
1451 view = GTK_TREE_VIEW (priv->treeview);
1452 selection = gtk_tree_view_get_selection (view);
1453 model = gtk_tree_view_get_model (view);
1455 for (ok = gtk_tree_model_get_iter_first (model, iter);
1457 ok = gtk_tree_model_iter_next (model, iter))
1459 EmpathyAccountSettings *this_settings;
1462 gtk_tree_model_get (model, iter,
1463 COL_ACCOUNT_SETTINGS, &this_settings,
1466 equal = (this_settings == settings);
1467 g_object_unref (this_settings);
1477 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1482 GtkTreeSelection *selection;
1483 GtkTreeModel *model;
1485 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1487 /* Update the status in the model */
1488 view = GTK_TREE_VIEW (priv->treeview);
1489 selection = gtk_tree_view_get_selection (view);
1490 model = gtk_tree_view_get_model (view);
1492 for (ok = gtk_tree_model_get_iter_first (model, iter);
1494 ok = gtk_tree_model_iter_next (model, iter))
1496 EmpathyAccountSettings *settings;
1499 gtk_tree_model_get (model, iter,
1500 COL_ACCOUNT_SETTINGS, &settings,
1503 equal = empathy_account_settings_has_account (settings, account);
1504 g_object_unref (settings);
1514 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1515 EmpathyAccountSettings *settings)
1517 GtkTreeSelection *selection;
1519 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1521 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1522 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1523 gtk_tree_selection_select_iter (selection, &iter);
1526 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1527 EmpathyAccountSettings *settings)
1529 GtkTreeModel *model;
1532 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1534 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1535 name = empathy_account_settings_get_display_name (settings);
1537 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1539 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1541 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1542 COL_ACCOUNT_SETTINGS, settings,
1547 accounts_dialog_connection_changed_cb (TpAccount *account,
1551 gchar *dbus_error_name,
1552 GHashTable *details,
1553 EmpathyAccountsDialog *dialog)
1555 GtkTreeModel *model;
1558 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1560 /* Update the status-infobar in the details view */
1561 accounts_dialog_update_status_infobar (dialog, account);
1563 /* Update the status in the model */
1564 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1566 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1570 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1571 COL_STATUS, current,
1574 path = gtk_tree_model_get_path (model, &iter);
1575 gtk_tree_model_row_changed (model, path, &iter);
1576 gtk_tree_path_free (path);
1579 empathy_account_manager_get_accounts_connected (&found);
1581 if (!found && priv->connecting_id)
1583 g_source_remove (priv->connecting_id);
1584 priv->connecting_id = 0;
1587 if (found && !priv->connecting_id)
1588 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1589 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1594 update_account_in_treeview (EmpathyAccountsDialog *self,
1597 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1599 GtkTreeModel *model;
1601 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1602 if (accounts_dialog_get_account_iter (self, account, &iter))
1606 path = gtk_tree_model_get_path (model, &iter);
1607 gtk_tree_model_row_changed (model, path, &iter);
1608 gtk_tree_path_free (path);
1613 accounts_dialog_presence_changed_cb (TpAccount *account,
1616 gchar *status_message,
1617 EmpathyAccountsDialog *dialog)
1619 /* Update the status-infobar in the details view */
1620 accounts_dialog_update_status_infobar (dialog, account);
1622 update_account_in_treeview (dialog, account);
1626 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1630 const gchar *display_name;
1632 GtkTreeModel *model;
1633 EmpathyAccountSettings *settings;
1634 TpAccount *selected_account;
1635 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1636 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1638 display_name = tp_account_get_display_name (account);
1639 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1640 settings = accounts_dialog_model_get_selected_settings (dialog);
1641 if (settings == NULL)
1644 selected_account = empathy_account_settings_get_account (settings);
1646 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1648 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1649 COL_NAME, display_name,
1653 if (selected_account == account)
1654 accounts_dialog_update_name_label (dialog, display_name);
1656 g_object_unref (settings);
1660 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1663 EmpathyAccountSettings *settings;
1664 GtkTreeModel *model;
1666 TpConnectionStatus status;
1669 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1671 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1672 status = tp_account_get_connection_status (account, NULL);
1673 name = tp_account_get_display_name (account);
1674 enabled = tp_account_is_enabled (account);
1676 settings = empathy_account_settings_new_for_account (account);
1678 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1679 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1681 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1684 COL_ACCOUNT, account,
1685 COL_ACCOUNT_SETTINGS, settings,
1688 accounts_dialog_connection_changed_cb (account,
1691 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1696 tp_g_signal_connect_object (account, "notify::display-name",
1697 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1700 tp_g_signal_connect_object (account, "status-changed",
1701 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1702 tp_g_signal_connect_object (account, "presence-changed",
1703 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1705 g_object_unref (settings);
1709 account_prepare_cb (GObject *source_object,
1710 GAsyncResult *result,
1713 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1714 TpAccount *account = TP_ACCOUNT (source_object);
1715 GError *error = NULL;
1717 if (!tp_account_prepare_finish (account, result, &error))
1719 DEBUG ("Failed to prepare account: %s", error->message);
1720 g_error_free (error);
1724 accounts_dialog_add_account (dialog, account);
1728 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1731 EmpathyAccountsDialog *dialog)
1733 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1737 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1740 EmpathyAccountsDialog *dialog)
1742 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1744 if (priv->setting_widget_object != NULL &&
1745 accounts_dialog_has_valid_accounts (dialog))
1747 empathy_account_widget_set_other_accounts_exist (
1748 priv->setting_widget_object, TRUE);
1753 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1755 EmpathyAccountsDialog *dialog)
1757 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1759 if (priv->setting_widget_object != NULL &&
1760 !accounts_dialog_has_valid_accounts (dialog))
1762 empathy_account_widget_set_other_accounts_exist (
1763 priv->setting_widget_object, FALSE);
1768 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1770 EmpathyAccountsDialog *dialog)
1773 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1775 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1777 gtk_list_store_remove (GTK_LIST_STORE (
1778 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1783 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1787 GtkTreeModel *model;
1788 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1790 /* Update the status in the model */
1791 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1793 /* Update the status-infobar in the details view */
1794 accounts_dialog_update_status_infobar (dialog, account);
1796 DEBUG ("Account %s is now %s",
1797 tp_account_get_display_name (account),
1798 enabled ? "enabled" : "disabled");
1802 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1804 EmpathyAccountsDialog *dialog)
1806 enable_or_disable_account (dialog, account, FALSE);
1807 update_account_in_treeview (dialog, account);
1811 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1813 EmpathyAccountsDialog *dialog)
1815 enable_or_disable_account (dialog, account, TRUE);
1819 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1820 EmpathyAccountsDialog *dialog)
1822 GtkWidget *import_dialog;
1824 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1826 gtk_widget_show (import_dialog);
1830 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1834 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1836 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1838 if (response_id == GTK_RESPONSE_YES)
1839 gtk_widget_destroy (account_dialog);
1843 accounts_dialog_delete_event_cb (GtkWidget *widget,
1845 EmpathyAccountsDialog *dialog)
1847 /* we maunally handle responses to delete events */
1852 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1855 GtkTreeSelection *selection;
1857 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1859 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1860 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1861 gtk_tree_selection_select_iter (selection, &iter);
1865 accounts_dialog_cms_prepare_cb (GObject *source,
1866 GAsyncResult *result,
1869 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1870 EmpathyAccountsDialog *dialog = user_data;
1871 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1873 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1876 accounts_dialog_update_settings (dialog, NULL);
1878 if (priv->initial_selection != NULL)
1880 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1881 g_object_unref (priv->initial_selection);
1882 priv->initial_selection = NULL;
1887 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1889 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1890 GList *accounts, *l;
1892 g_signal_connect (priv->account_manager, "account-validity-changed",
1893 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1895 g_signal_connect (priv->account_manager, "account-removed",
1896 G_CALLBACK (accounts_dialog_account_removed_cb),
1898 g_signal_connect (priv->account_manager, "account-enabled",
1899 G_CALLBACK (accounts_dialog_account_enabled_cb),
1901 g_signal_connect (priv->account_manager, "account-disabled",
1902 G_CALLBACK (accounts_dialog_account_disabled_cb),
1905 /* Add existing accounts */
1906 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1907 for (l = accounts; l; l = l->next)
1909 accounts_dialog_add_account (dialog, l->data);
1911 g_list_free (accounts);
1913 priv->cms = empathy_connection_managers_dup_singleton ();
1915 empathy_connection_managers_prepare_async (priv->cms,
1916 accounts_dialog_cms_prepare_cb, dialog);
1918 accounts_dialog_model_select_first (dialog);
1922 accounts_dialog_manager_ready_cb (GObject *source_object,
1923 GAsyncResult *result,
1926 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1927 GError *error = NULL;
1929 if (!tp_account_manager_prepare_finish (manager, result, &error))
1931 DEBUG ("Failed to prepare account manager: %s", error->message);
1932 g_error_free (error);
1936 accounts_dialog_accounts_setup (user_data);
1940 dialog_response_cb (GtkWidget *widget,
1944 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1946 if (response_id == GTK_RESPONSE_HELP)
1948 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1950 else if (response_id == GTK_RESPONSE_CLOSE ||
1951 response_id == GTK_RESPONSE_DELETE_EVENT)
1953 TpAccount *account = NULL;
1955 if (accounts_dialog_has_pending_change (dialog, &account))
1957 gchar *question_dialog_primary_text = get_dialog_primary_text (
1960 accounts_dialog_show_question_dialog (dialog,
1961 question_dialog_primary_text,
1962 _("You are about to close the window, which will discard\n"
1963 "your changes. Are you sure you want to proceed?"),
1964 G_CALLBACK (accounts_dialog_close_response_cb),
1966 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1967 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1969 g_free (question_dialog_primary_text);
1973 gtk_widget_destroy (widget);
1976 if (account != NULL)
1977 g_object_unref (account);
1982 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1984 GtkWidget *top_hbox;
1987 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1988 GtkWidget *content_area;
1989 GtkWidget *action_area, *vbox, *hbox, *align;
1991 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1993 gui = empathy_builder_get_file (filename,
1994 "accounts_dialog_hbox", &top_hbox,
1995 "vbox_details", &priv->vbox_details,
1996 "frame_no_protocol", &priv->frame_no_protocol,
1997 "alignment_settings", &priv->alignment_settings,
1998 "alignment_infobar", &priv->alignment_infobar,
1999 "treeview", &priv->treeview,
2000 "button_add", &priv->button_add,
2001 "button_remove", &priv->button_remove,
2002 "button_import", &priv->button_import,
2003 "hbox_protocol", &priv->hbox_protocol,
2007 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2009 empathy_builder_connect (gui, dialog,
2010 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2011 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2012 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2015 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2017 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
2019 g_object_unref (gui);
2021 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2024 gtk_widget_hide (action_area);
2025 gtk_widget_hide (priv->button_remove);
2026 #endif /* HAVE_MEEGO */
2028 /* Remove button is unsensitive until we have a selected account */
2029 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2031 priv->combobox_protocol = empathy_protocol_chooser_new ();
2032 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
2034 g_signal_connect (priv->combobox_protocol, "changed",
2035 G_CALLBACK (accounts_dialog_protocol_changed_cb),
2038 if (priv->parent_window)
2039 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2040 priv->parent_window);
2042 priv->infobar = gtk_info_bar_new ();
2043 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2045 gtk_widget_show (priv->infobar);
2047 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
2049 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2050 GTK_ICON_SIZE_DIALOG);
2051 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2052 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
2053 gtk_widget_show (priv->image_type);
2055 vbox = gtk_vbox_new (FALSE, 6);
2056 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
2057 gtk_widget_show (vbox);
2060 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2061 gtk_widget_show (align);
2063 priv->label_name = gtk_label_new (NULL);
2064 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
2065 gtk_widget_show (priv->label_name);
2067 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2070 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2071 gtk_widget_show (align);
2072 hbox = gtk_hbox_new (FALSE, 6);
2073 gtk_widget_show (hbox);
2074 gtk_container_add (GTK_CONTAINER (align), hbox);
2076 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2078 /* set up spinner */
2079 priv->throbber = gtk_spinner_new ();
2081 priv->image_status = gtk_image_new_from_icon_name (
2082 empathy_icon_name_for_presence (
2083 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2085 priv->label_status = gtk_label_new (NULL);
2086 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
2087 gtk_widget_show (priv->label_status);
2089 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2090 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
2091 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
2093 /* Tweak the dialog */
2094 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2095 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2097 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2099 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2101 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
2103 /* add dialog buttons */
2104 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2106 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2107 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2108 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2111 g_signal_connect (dialog, "response",
2112 G_CALLBACK (dialog_response_cb), dialog);
2114 g_signal_connect (dialog, "delete-event",
2115 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2119 do_dispose (GObject *obj)
2121 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2122 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2123 GtkTreeModel *model;
2125 if (priv->dispose_has_run)
2128 priv->dispose_has_run = TRUE;
2130 /* Disconnect signals */
2131 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2132 g_signal_handlers_disconnect_by_func (model,
2133 accounts_dialog_accounts_model_row_inserted_cb, dialog);
2134 g_signal_handlers_disconnect_by_func (model,
2135 accounts_dialog_accounts_model_row_deleted_cb, dialog);
2137 g_signal_handlers_disconnect_by_func (priv->account_manager,
2138 accounts_dialog_account_validity_changed_cb,
2140 g_signal_handlers_disconnect_by_func (priv->account_manager,
2141 accounts_dialog_account_removed_cb,
2143 g_signal_handlers_disconnect_by_func (priv->account_manager,
2144 accounts_dialog_account_enabled_cb,
2146 g_signal_handlers_disconnect_by_func (priv->account_manager,
2147 accounts_dialog_account_disabled_cb,
2149 g_signal_handlers_disconnect_by_func (priv->account_manager,
2150 accounts_dialog_manager_ready_cb,
2153 if (priv->connecting_id)
2154 g_source_remove (priv->connecting_id);
2156 if (priv->account_manager != NULL)
2158 g_object_unref (priv->account_manager);
2159 priv->account_manager = NULL;
2162 if (priv->cms != NULL)
2164 g_object_unref (priv->cms);
2168 if (priv->connectivity)
2170 g_object_unref (priv->connectivity);
2171 priv->connectivity = NULL;
2174 if (priv->initial_selection != NULL)
2175 g_object_unref (priv->initial_selection);
2176 priv->initial_selection = NULL;
2178 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2182 do_get_property (GObject *object,
2187 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2189 switch (property_id)
2192 g_value_set_object (value, priv->parent_window);
2195 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2200 do_set_property (GObject *object,
2202 const GValue *value,
2205 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2207 switch (property_id)
2210 priv->parent_window = g_value_get_object (value);
2213 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2218 do_constructed (GObject *object)
2220 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2221 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2222 GtkTreeModel *model;
2223 GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
2225 accounts_dialog_build_ui (dialog);
2226 accounts_dialog_model_setup (dialog);
2228 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2229 g_signal_connect (model, "row-inserted",
2230 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2231 g_signal_connect (model, "row-deleted",
2232 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2234 /* Set up signalling */
2235 priv->account_manager = tp_account_manager_dup ();
2237 tp_account_manager_prepare_async (priv->account_manager, NULL,
2238 accounts_dialog_manager_ready_cb, dialog);
2240 if (empathy_import_accounts_to_import ())
2242 gtk_widget_show (priv->button_import);
2244 if (!g_settings_get_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED))
2246 GtkWidget *import_dialog;
2248 g_settings_set_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED, TRUE);
2249 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2251 gtk_widget_show (import_dialog);
2255 priv->connectivity = empathy_connectivity_dup_singleton ();
2257 g_object_unref (gsettings);
2261 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2263 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2264 GParamSpec *param_spec;
2266 oclass->dispose = do_dispose;
2267 oclass->constructed = do_constructed;
2268 oclass->set_property = do_set_property;
2269 oclass->get_property = do_get_property;
2271 param_spec = g_param_spec_object ("parent",
2272 "parent", "The parent window",
2274 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2275 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2277 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2281 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2283 EmpathyAccountsDialogPriv *priv;
2285 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2286 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2287 EmpathyAccountsDialogPriv);
2288 dialog->priv = priv;
2291 /* public methods */
2294 empathy_accounts_dialog_show (GtkWindow *parent,
2295 TpAccount *selected_account)
2297 EmpathyAccountsDialog *dialog;
2298 EmpathyAccountsDialogPriv *priv;
2300 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2301 "parent", parent, NULL);
2303 priv = GET_PRIV (dialog);
2305 if (selected_account)
2307 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2308 accounts_dialog_set_selected_account (dialog, selected_account);
2310 /* save the selection to set it later when the cms
2313 priv->initial_selection = g_object_ref (selected_account);
2316 gtk_window_present (GTK_WINDOW (dialog));
2318 return GTK_WIDGET (dialog);
2322 empathy_accounts_dialog_show_application (GdkScreen *screen,
2323 TpAccount *selected_account,
2327 GError *error = NULL;
2328 gchar *argv[4] = { NULL, };
2330 gchar *account_option = NULL;
2333 g_return_if_fail (GDK_IS_SCREEN (screen));
2334 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2336 /* Try to run from source directory if possible */
2337 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
2338 "empathy-accounts", NULL);
2340 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2343 path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
2348 if (selected_account != NULL)
2350 const gchar *account_path;
2352 account_path = tp_proxy_get_object_path (TP_PROXY (selected_account));
2353 account_option = g_strdup_printf ("--select-account=%s",
2354 &account_path[strlen (TP_ACCOUNT_OBJECT_PATH_BASE)]);
2356 argv[i++] = account_option;
2360 argv[i++] = "--if-needed";
2363 argv[i++] = "--hidden";
2365 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2367 selected_account == NULL ? "<none selected>" :
2368 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2370 gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
2371 NULL, NULL, NULL, &error);
2374 g_warning ("Failed to open accounts dialog: %s", error->message);
2375 g_error_free (error);
2378 g_free (account_option);
2383 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2385 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2386 gboolean result = FALSE;
2388 if (priv->setting_widget_object == NULL)
2391 g_object_get (priv->setting_widget_object,
2392 "creating-account", &result, NULL);