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>
43 #include <libempathy-gtk/empathy-ui-utils.h>
44 #include <libempathy-gtk/empathy-protocol-chooser.h>
45 #include <libempathy-gtk/empathy-account-widget.h>
46 #include <libempathy-gtk/empathy-account-widget-irc.h>
47 #include <libempathy-gtk/empathy-account-widget-sip.h>
48 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
49 #include <libempathy-gtk/empathy-images.h>
51 #include "empathy-accounts-dialog.h"
52 #include "empathy-import-dialog.h"
53 #include "empathy-import-utils.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
56 #include <libempathy/empathy-debug.h>
58 /* Flashing delay for icons (milliseconds). */
59 #define FLASH_TIMEOUT 500
61 /* The primary text of the dialog shown to the user when he is about to lose
63 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
64 _("There are unsaved modifications to your %s account.")
65 /* The primary text of the dialog shown to the user when he is about to lose
66 * an unsaved new account */
67 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
68 _("Your new account has not been saved yet.")
70 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
71 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
75 NOTEBOOK_PAGE_ACCOUNT = 0,
80 GtkWidget *alignment_settings;
81 GtkWidget *alignment_infobar;
83 GtkWidget *vbox_details;
85 GtkWidget *label_status;
86 GtkWidget *image_status;
88 GtkWidget *frame_no_protocol;
92 GtkWidget *button_add;
93 GtkWidget *button_remove;
94 GtkWidget *button_import;
96 GtkWidget *combobox_protocol;
97 GtkWidget *hbox_protocol;
99 GtkWidget *image_type;
100 GtkWidget *label_name;
101 GtkWidget *label_type;
102 GtkWidget *settings_widget;
104 GtkWidget *notebook_account;
108 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
109 * his GtkWidget. It is the only reliable source we can query to know if
110 * there are any unsaved changes to the currently selected account. We can't
111 * look at the account settings because it does not contain everything that
112 * can be changed using the EmpathyAccountWidget. For instance, it does not
113 * contain the state of the "Enabled" checkbox. */
114 EmpathyAccountWidget *setting_widget_object;
116 gboolean connecting_show;
119 gulong settings_ready_id;
120 EmpathyAccountSettings *settings_ready;
122 TpAccountManager *account_manager;
123 EmpathyConnectionManagers *cms;
124 EmpathyConnectivity *connectivity;
126 GtkWindow *parent_window;
127 TpAccount *initial_selection;
129 /* Those are needed when changing the selected row. When a user selects
130 * another account and there are unsaved changes on the currently selected
131 * one, a confirmation message box is presented to him. Since his answer
132 * is retrieved asynchronously, we keep some information as member of the
133 * EmpathyAccountsDialog object. */
134 gboolean force_change_row;
135 GtkTreeRowReference *destination_row;
136 } EmpathyAccountsDialogPriv;
142 COL_ACCOUNT_SETTINGS,
150 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
151 EmpathyAccountsDialog *dialog);
153 static gboolean accounts_dialog_get_settings_iter (
154 EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings,
158 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
160 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
161 EmpathyAccountSettings *settings);
163 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
164 EmpathyAccountSettings *settings);
166 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
167 EmpathyAccountSettings *settings);
169 static void accounts_dialog_connection_changed_cb (TpAccount *account,
173 gchar *dbus_error_name,
175 EmpathyAccountsDialog *dialog);
177 static void accounts_dialog_presence_changed_cb (TpAccount *account,
180 gchar *status_message,
181 EmpathyAccountsDialog *dialog);
183 static void accounts_dialog_model_selection_changed (
184 GtkTreeSelection *selection,
185 EmpathyAccountsDialog *dialog);
188 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
189 const gchar *display_name)
192 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
194 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
195 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
201 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
202 const gchar *message)
204 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
205 gchar *message_markup;
207 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
208 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
209 g_free (message_markup);
213 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
216 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
217 gchar *status_message = NULL;
223 GtkTreeSelection *selection;
225 TpAccount *selected_account;
226 gboolean account_enabled;
227 gboolean creating_account;
229 view = GTK_TREE_VIEW (priv->treeview);
230 selection = gtk_tree_view_get_selection (view);
232 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
235 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
236 if (selected_account != NULL)
237 g_object_unref (selected_account);
239 /* do not update the infobar when the account is not selected */
240 if (account != selected_account)
245 status = tp_account_get_connection_status (account, &reason);
246 presence = tp_account_get_current_presence (account, NULL, &status_message);
247 account_enabled = tp_account_is_enabled (account);
248 creating_account = FALSE;
250 if (status == TP_CONNECTION_STATUS_CONNECTED &&
251 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
252 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
253 /* If presence is Unset (CM doesn't implement SimplePresence) but we
254 * are connected, consider ourself as Available.
255 * We also check Offline because of this MC5 bug: fd.o #26060 */
256 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
258 /* set presence to offline if account is disabled
259 * (else no icon is shown in infobar)*/
260 if (!account_enabled)
261 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
265 status = TP_CONNECTION_STATUS_DISCONNECTED;
266 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
267 account_enabled = FALSE;
268 creating_account = TRUE;
271 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
272 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
278 case TP_CONNECTION_STATUS_CONNECTING:
279 accounts_dialog_status_infobar_set_message (dialog,
281 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
284 gtk_spinner_start (GTK_SPINNER (priv->throbber));
285 gtk_widget_show (priv->throbber);
286 gtk_widget_hide (priv->image_status);
288 case TP_CONNECTION_STATUS_CONNECTED:
289 if (g_strcmp0 (status_message, "") == 0)
293 message = g_strdup_printf ("%s",
294 empathy_presence_get_default_message (presence));
296 accounts_dialog_status_infobar_set_message (dialog, message);
303 message = g_strdup_printf ("%s — %s",
304 empathy_presence_get_default_message (presence),
307 accounts_dialog_status_infobar_set_message (dialog, message);
310 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
313 gtk_widget_show (priv->image_status);
314 gtk_widget_hide (priv->throbber);
316 case TP_CONNECTION_STATUS_DISCONNECTED:
317 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
321 message = g_strdup_printf (_("Offline — %s"),
322 empathy_account_get_error_message (account, NULL));
323 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
324 GTK_MESSAGE_WARNING);
326 accounts_dialog_status_infobar_set_message (dialog, message);
333 message = g_strdup_printf (_("Disconnected — %s"),
334 empathy_account_get_error_message (account, NULL));
335 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
338 accounts_dialog_status_infobar_set_message (dialog, message);
342 if (!empathy_connectivity_is_online (priv->connectivity))
343 accounts_dialog_status_infobar_set_message (dialog,
344 _("Offline — No Network Connection"));
346 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
347 gtk_widget_show (priv->image_status);
348 gtk_widget_hide (priv->throbber);
351 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
352 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
353 GTK_MESSAGE_WARNING);
355 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
356 gtk_widget_hide (priv->image_status);
357 gtk_widget_hide (priv->throbber);
362 accounts_dialog_status_infobar_set_message (dialog,
363 _("Offline — Account Disabled"));
365 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
366 GTK_MESSAGE_WARNING);
367 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
368 gtk_widget_show (priv->image_status);
369 gtk_widget_hide (priv->throbber);
372 gtk_widget_show (priv->label_status);
374 if (!creating_account)
375 gtk_widget_show (priv->infobar);
377 gtk_widget_hide (priv->infobar);
379 g_free (status_message);
383 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
387 GtkTreeSelection *selection;
389 EmpathyAccountSettings *settings;
391 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
393 view = GTK_TREE_VIEW (priv->treeview);
394 selection = gtk_tree_view_get_selection (view);
396 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
399 gtk_tree_model_get (model, &iter,
400 COL_ACCOUNT_SETTINGS, &settings,
401 COL_ACCOUNT, &account, -1);
403 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
407 /* We were creating an account. We remove the selected row */
408 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
412 /* We were modifying an account. We discard the changes by reloading the
413 * settings and the UI. */
414 accounts_dialog_update_settings (dialog, settings);
415 g_object_unref (account);
418 gtk_widget_set_sensitive (priv->treeview, TRUE);
419 gtk_widget_set_sensitive (priv->button_add, TRUE);
420 gtk_widget_set_sensitive (priv->button_remove, TRUE);
421 gtk_widget_set_sensitive (priv->button_import, TRUE);
423 if (settings != NULL)
424 g_object_unref (settings);
428 empathy_account_dialog_widget_cancelled_cb (
429 EmpathyAccountWidget *widget_object,
430 EmpathyAccountsDialog *dialog)
432 empathy_account_dialog_cancel (dialog);
436 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
438 EmpathyAccountsDialog *dialog)
440 EmpathyAccountSettings *settings =
441 accounts_dialog_model_get_selected_settings (dialog);
442 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
444 accounts_dialog_update_settings (dialog, settings);
445 accounts_dialog_update_status_infobar (dialog,
446 empathy_account_settings_get_account (settings));
448 gtk_widget_set_sensitive (priv->treeview, TRUE);
449 gtk_widget_set_sensitive (priv->button_add, TRUE);
450 gtk_widget_set_sensitive (priv->button_remove, TRUE);
451 gtk_widget_set_sensitive (priv->button_import, TRUE);
454 g_object_unref (settings);
458 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
460 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
465 g_object_get (priv->setting_widget_object,
466 "creating-account", &creating, NULL);
471 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
473 if (gtk_tree_model_get_iter_first (model, &iter))
474 return gtk_tree_model_iter_next (model, &iter);
480 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
481 EmpathyAccountSettings *settings)
483 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
484 const gchar *icon_name;
487 priv->setting_widget_object =
488 empathy_account_widget_new_for_protocol (settings, FALSE);
490 if (accounts_dialog_has_valid_accounts (dialog))
491 empathy_account_widget_set_other_accounts_exist (
492 priv->setting_widget_object, TRUE);
494 priv->settings_widget =
495 empathy_account_widget_get_widget (priv->setting_widget_object);
497 g_signal_connect (priv->setting_widget_object, "account-created",
498 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
499 g_signal_connect (priv->setting_widget_object, "cancelled",
500 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
502 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
503 priv->settings_widget);
504 gtk_widget_show (priv->settings_widget);
506 icon_name = empathy_account_settings_get_icon_name (settings);
508 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
510 /* show the default icon; keep this in sync with the default
511 * one in empathy-accounts-dialog.ui.
513 icon_name = GTK_STOCK_CUT;
515 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
516 icon_name, GTK_ICON_SIZE_DIALOG);
517 gtk_widget_set_tooltip_text (priv->image_type,
518 empathy_protocol_name_to_display_name
519 (empathy_account_settings_get_protocol (settings)));
520 gtk_widget_show (priv->image_type);
522 accounts_dialog_update_name_label (dialog,
523 empathy_account_settings_get_display_name (settings));
525 account = empathy_account_settings_get_account (settings);
526 accounts_dialog_update_status_infobar (dialog, account);
530 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
532 EmpathyAccountsDialog *dialog)
534 if (empathy_account_settings_is_ready (settings))
535 account_dialog_create_settings_widget (dialog, settings);
539 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
543 GtkTreeSelection *selection;
545 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
548 view = GTK_TREE_VIEW (priv->treeview);
549 model = gtk_tree_view_get_model (view);
551 if (gtk_tree_model_get_iter_first (model, &iter))
553 selection = gtk_tree_view_get_selection (view);
554 gtk_tree_selection_select_iter (selection, &iter);
558 accounts_dialog_update_settings (dialog, NULL);
563 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
568 GtkTreeSelection *selection;
569 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
571 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
573 if (gtk_tree_selection_get_selected (selection, &model, &iter))
574 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
576 return priv->setting_widget_object != NULL
577 && empathy_account_widget_contains_pending_changes (
578 priv->setting_widget_object);
582 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
585 EmpathyAccountSettings *settings;
587 settings = empathy_protocol_chooser_create_account_settings (
588 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol));
589 if (settings == NULL)
592 accounts_dialog_add (dialog, settings);
593 accounts_dialog_model_set_selected (dialog, settings);
595 gtk_widget_show_all (priv->hbox_protocol);
597 g_object_unref (settings);
601 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
602 EmpathyAccountsDialog *dialog)
604 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
605 GtkTreeSelection *selection;
609 EmpathyAccountSettings *settings;
610 gchar *account = NULL, *password = NULL;
612 /* The "changed" signal is fired during the initiation of the
613 * EmpathyProtocolChooser while populating the widget. Such signals should
614 * be ignored so we check if we are actually creating a new account. */
615 if (priv->setting_widget_object == NULL)
618 g_object_get (priv->setting_widget_object,
619 "creating-account", &creating, NULL);
623 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
625 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
628 /* Save "account" and "password" parameters */
629 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
631 if (settings != NULL)
633 account = g_strdup (empathy_account_settings_get_string (settings,
635 password = g_strdup (empathy_account_settings_get_string (settings,
637 g_object_unref (settings);
640 /* We are creating a new widget to replace the current one, don't ask
641 * confirmation to the user. */
642 priv->force_change_row = TRUE;
644 /* We'll update the selection after we create the new account widgets;
645 * updating it right now causes problems for the # of accounts = zero case */
646 g_signal_handlers_block_by_func (selection,
647 accounts_dialog_model_selection_changed, dialog);
649 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
651 g_signal_handlers_unblock_by_func (selection,
652 accounts_dialog_model_selection_changed, dialog);
654 accounts_dialog_setup_ui_to_add_account (dialog);
656 /* Restore "account" and "password" parameters in the new widget */
659 empathy_account_widget_set_account_param (priv->setting_widget_object,
664 if (password != NULL)
666 empathy_account_widget_set_password_param (priv->setting_widget_object,
673 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
674 const gchar *primary_text,
675 const gchar *secondary_text,
676 GCallback response_callback,
678 const gchar *first_button_text,
682 GtkWidget *message_dialog;
683 const gchar *button_text;
685 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
686 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
687 GTK_MESSAGE_QUESTION,
691 gtk_message_dialog_format_secondary_text (
692 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
694 va_start (button_args, first_button_text);
695 for (button_text = first_button_text;
697 button_text = va_arg (button_args, const gchar *))
700 response_id = va_arg (button_args, gint);
702 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
705 va_end (button_args);
707 g_signal_connect (message_dialog, "response", response_callback, user_data);
709 gtk_widget_show (message_dialog);
713 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
717 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
718 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
720 gtk_widget_destroy (GTK_WIDGET (message_dialog));
722 if (response_id == GTK_RESPONSE_YES)
724 empathy_account_widget_discard_pending_changes (
725 priv->setting_widget_object);
726 accounts_dialog_setup_ui_to_add_account (dialog);
731 get_dialog_primary_text (TpAccount *account)
735 /* Existing account */
736 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
737 tp_account_get_display_name (account));
741 /* Newly created account */
742 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
747 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
748 EmpathyAccountsDialog *dialog)
750 TpAccount *account = NULL;
751 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
753 if (accounts_dialog_has_pending_change (dialog, &account))
755 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
757 accounts_dialog_show_question_dialog (dialog,
758 question_dialog_primary_text,
759 _("You are about to create a new account, which will discard\n"
760 "your changes. Are you sure you want to proceed?"),
761 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
763 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
764 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
766 g_free (question_dialog_primary_text);
770 accounts_dialog_setup_ui_to_add_account (dialog);
771 gtk_widget_set_sensitive (priv->treeview, FALSE);
772 gtk_widget_set_sensitive (priv->button_add, FALSE);
773 gtk_widget_set_sensitive (priv->button_remove, FALSE);
774 gtk_widget_set_sensitive (priv->button_import, FALSE);
778 g_object_unref (account);
782 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
783 EmpathyAccountSettings *settings)
785 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
787 if (priv->settings_ready != NULL)
789 g_signal_handler_disconnect (priv->settings_ready,
790 priv->settings_ready_id);
791 priv->settings_ready = NULL;
792 priv->settings_ready_id = 0;
799 GtkTreeSelection *selection;
801 view = GTK_TREE_VIEW (priv->treeview);
802 model = gtk_tree_view_get_model (view);
803 selection = gtk_tree_view_get_selection (view);
805 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
807 /* We have configured accounts, select the first one if there
808 * is no other account selected already. */
809 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
810 accounts_dialog_model_select_first (dialog);
814 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
816 /* We have no account configured but we have some
817 * profiles installed. The user obviously wants to add
818 * an account. Click on the Add button for him. */
819 accounts_dialog_button_add_clicked_cb (priv->button_add,
824 /* No account and no profile, warn the user */
825 gtk_widget_hide (priv->vbox_details);
826 gtk_widget_show (priv->frame_no_protocol);
827 gtk_widget_set_sensitive (priv->button_add, FALSE);
831 /* We have an account selected, destroy old settings and create a new
832 * one for the account selected */
833 gtk_widget_hide (priv->frame_no_protocol);
834 gtk_widget_show (priv->vbox_details);
835 gtk_widget_hide (priv->hbox_protocol);
837 if (priv->settings_widget)
839 gtk_widget_destroy (priv->settings_widget);
840 priv->settings_widget = NULL;
843 if (empathy_account_settings_is_ready (settings))
845 account_dialog_create_settings_widget (dialog, settings);
849 priv->settings_ready = settings;
850 priv->settings_ready_id =
851 g_signal_connect (settings, "notify::ready",
852 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
858 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
859 GtkCellEditable *editable,
861 EmpathyAccountsDialog *dialog)
863 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
865 if (priv->connecting_id)
866 g_source_remove (priv->connecting_id);
868 DEBUG ("Editing account name started; stopping flashing");
872 get_status_icon_for_account (EmpathyAccountsDialog *self,
875 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
876 TpConnectionStatus status;
877 TpConnectionStatusReason reason;
878 TpConnectionPresenceType presence;
881 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
883 if (!tp_account_is_enabled (account))
884 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
886 status = tp_account_get_connection_status (account, &reason);
888 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
890 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
891 /* An error occured */
892 return GTK_STOCK_DIALOG_ERROR;
894 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
896 else if (status == TP_CONNECTION_STATUS_CONNECTING)
898 /* Account is connecting. Display a blinking account alternating between
899 * the offline icon and the requested presence. */
900 if (priv->connecting_show)
901 presence = tp_account_get_requested_presence (account, NULL, NULL);
903 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
907 /* status == TP_CONNECTION_STATUS_CONNECTED */
908 presence = tp_account_get_current_presence (account, NULL, NULL);
910 /* If presence is Unset (CM doesn't implement SimplePresence),
911 * display the 'available' icon.
912 * We also check Offline because of this MC5 bug: fd.o #26060 */
913 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
914 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
915 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
918 return empathy_icon_name_for_presence (presence);
922 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
923 GtkCellRenderer *cell,
926 EmpathyAccountsDialog *dialog)
930 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
933 "icon-name", get_status_icon_for_account (dialog, account),
937 g_object_unref (account);
941 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
942 GtkCellRenderer *cell,
945 EmpathyAccountsDialog *dialog)
947 EmpathyAccountSettings *settings;
950 TpConnectionStatus status;
952 gtk_tree_model_get (model, iter,
954 COL_ACCOUNT_SETTINGS, &settings,
957 icon_name = empathy_account_settings_get_icon_name (settings);
958 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
965 g_object_unref (settings);
968 g_object_unref (pixbuf);
972 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
977 gtk_tree_model_row_changed (model, path, iter);
983 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
987 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
989 priv->connecting_show = !priv->connecting_show;
991 view = GTK_TREE_VIEW (priv->treeview);
992 model = gtk_tree_view_get_model (view);
994 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1000 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1003 EmpathyAccountsDialog *dialog)
1005 EmpathyAccountSettings *settings;
1006 GtkTreeModel *model;
1007 GtkTreePath *treepath;
1009 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1010 gboolean connecting;
1012 empathy_account_manager_get_accounts_connected (&connecting);
1016 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1017 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1021 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1022 treepath = gtk_tree_path_new_from_string (path);
1023 gtk_tree_model_get_iter (model, &iter, treepath);
1024 gtk_tree_model_get (model, &iter,
1025 COL_ACCOUNT_SETTINGS, &settings,
1027 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1030 gtk_tree_path_free (treepath);
1032 empathy_account_settings_set_display_name_async (settings, new_text,
1034 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1035 g_object_unref (settings);
1039 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1044 GtkTreeModel *model;
1046 GtkTreeSelection *selection;
1047 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1048 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1050 if (response_id == GTK_RESPONSE_YES)
1052 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1054 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1057 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1059 if (account != NULL)
1061 tp_account_remove_async (account, NULL, NULL);
1062 g_object_unref (account);
1066 /* No need to call accounts_dialog_model_selection_changed while
1067 * removing as we are going to call accounts_dialog_model_select_first
1068 * right after which will update the selection. */
1069 g_signal_handlers_block_by_func (selection,
1070 accounts_dialog_model_selection_changed, account_dialog);
1072 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1074 g_signal_handlers_unblock_by_func (selection,
1075 accounts_dialog_model_selection_changed, account_dialog);
1077 accounts_dialog_model_select_first (account_dialog);
1080 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1084 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1087 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1089 GtkTreeModel *model;
1090 gchar *question_dialog_primary_text;
1092 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1094 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1096 if (account == NULL || !tp_account_is_valid (account))
1098 if (account != NULL)
1099 g_object_unref (account);
1100 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1101 accounts_dialog_model_select_first (dialog);
1105 question_dialog_primary_text = g_strdup_printf (
1106 _("Do you want to remove %s from your computer?"),
1107 tp_account_get_display_name (account));
1109 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1110 _("This will not remove your account on the server."),
1111 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1113 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1114 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1116 g_free (question_dialog_primary_text);
1117 g_object_unref (account);
1121 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1122 EmpathyAccountsDialog *dialog)
1124 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1126 GtkTreeModel *model;
1127 GtkTreeSelection *selection;
1130 view = GTK_TREE_VIEW (priv->treeview);
1131 model = gtk_tree_view_get_model (view);
1132 selection = gtk_tree_view_get_selection (view);
1133 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1136 accounts_dialog_remove_account_iter (dialog, &iter);
1141 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1142 const gchar *path_string,
1143 EmpathyAccountsDialog *dialog)
1145 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1146 GtkTreeModel *model;
1149 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1150 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1153 accounts_dialog_remove_account_iter (dialog, &iter);
1155 #endif /* HAVE_MEEGO */
1158 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1161 GtkTreeViewColumn *column;
1162 GtkCellRenderer *cell;
1163 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1165 view = GTK_TREE_VIEW (priv->treeview);
1166 gtk_tree_view_set_headers_visible (view, FALSE);
1168 /* Account column */
1169 column = gtk_tree_view_column_new ();
1170 gtk_tree_view_column_set_expand (column, TRUE);
1171 gtk_tree_view_append_column (view, column);
1173 /* Status icon renderer */
1174 cell = gtk_cell_renderer_pixbuf_new ();
1175 gtk_tree_view_column_pack_start (column, cell, FALSE);
1176 gtk_tree_view_column_set_cell_data_func (column, cell,
1177 (GtkTreeCellDataFunc)
1178 accounts_dialog_model_status_pixbuf_data_func,
1182 /* Protocol icon renderer */
1183 cell = gtk_cell_renderer_pixbuf_new ();
1184 gtk_tree_view_column_pack_start (column, cell, FALSE);
1185 gtk_tree_view_column_set_cell_data_func (column, cell,
1186 (GtkTreeCellDataFunc)
1187 accounts_dialog_model_protocol_pixbuf_data_func,
1192 cell = gtk_cell_renderer_text_new ();
1194 "ellipsize", PANGO_ELLIPSIZE_END,
1198 gtk_tree_view_column_pack_start (column, cell, TRUE);
1199 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1200 g_signal_connect (cell, "edited",
1201 G_CALLBACK (accounts_dialog_name_edited_cb),
1203 g_signal_connect (cell, "editing-started",
1204 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1206 g_object_set (cell, "ypad", 4, NULL);
1210 cell = empathy_cell_renderer_activatable_new ();
1211 gtk_tree_view_column_pack_start (column, cell, FALSE);
1213 "icon-name", GTK_STOCK_DELETE,
1214 "show-on-select", TRUE,
1217 g_signal_connect (cell, "path-activated",
1218 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1220 #endif /* HAVE_MEEGO */
1223 static EmpathyAccountSettings *
1224 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1227 GtkTreeModel *model;
1228 GtkTreeSelection *selection;
1230 EmpathyAccountSettings *settings;
1231 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1233 view = GTK_TREE_VIEW (priv->treeview);
1234 selection = gtk_tree_view_get_selection (view);
1236 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1239 gtk_tree_model_get (model, &iter,
1240 COL_ACCOUNT_SETTINGS, &settings, -1);
1246 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1247 EmpathyAccountsDialog *dialog)
1249 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1250 EmpathyAccountSettings *settings;
1251 GtkTreeModel *model;
1253 gboolean is_selection;
1254 gboolean creating = FALSE;
1256 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1258 settings = accounts_dialog_model_get_selected_settings (dialog);
1259 accounts_dialog_update_settings (dialog, settings);
1261 if (settings != NULL)
1262 g_object_unref (settings);
1264 if (priv->setting_widget_object != NULL)
1266 g_object_get (priv->setting_widget_object,
1267 "creating-account", &creating, NULL);
1270 /* Update remove button sensitivity */
1271 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1276 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1278 gpointer *user_data)
1280 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1281 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1283 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1285 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1287 /* The user wants to lose unsaved changes to the currently selected
1288 * account and select another account. We discard the changes and
1289 * select the other account. */
1291 GtkTreeSelection *selection;
1293 priv->force_change_row = TRUE;
1294 empathy_account_widget_discard_pending_changes (
1295 priv->setting_widget_object);
1297 path = gtk_tree_row_reference_get_path (priv->destination_row);
1298 selection = gtk_tree_view_get_selection (
1299 GTK_TREE_VIEW (priv->treeview));
1303 /* This will trigger a call to
1304 * accounts_dialog_account_selection_change() */
1305 gtk_tree_selection_select_path (selection, path);
1306 gtk_tree_path_free (path);
1309 gtk_tree_row_reference_free (priv->destination_row);
1313 priv->force_change_row = FALSE;
1318 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1319 GtkTreeModel *model,
1321 gboolean path_currently_selected,
1324 TpAccount *account = NULL;
1325 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1326 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1329 if (priv->force_change_row)
1331 /* We came back here because the user wants to discard changes to his
1332 * modified account. The changes have already been discarded so we
1333 * just change the selected row. */
1334 priv->force_change_row = FALSE;
1338 if (accounts_dialog_has_pending_change (dialog, &account))
1340 /* The currently selected account has some unsaved changes. We ask
1341 * the user if he really wants to lose his changes and select another
1343 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1344 priv->destination_row = gtk_tree_row_reference_new (model, path);
1346 accounts_dialog_show_question_dialog (dialog,
1347 question_dialog_primary_text,
1348 _("You are about to select another account, which will discard\n"
1349 "your changes. Are you sure you want to proceed?"),
1350 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1352 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1353 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1355 g_free (question_dialog_primary_text);
1363 if (account != NULL)
1364 g_object_unref (account);
1370 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1372 GtkListStore *store;
1373 GtkTreeSelection *selection;
1374 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1376 store = gtk_list_store_new (COL_COUNT,
1377 G_TYPE_STRING, /* name */
1378 G_TYPE_UINT, /* status */
1379 TP_TYPE_ACCOUNT, /* account */
1380 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1382 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1383 GTK_TREE_MODEL (store));
1385 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1386 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1387 gtk_tree_selection_set_select_function (selection,
1388 accounts_dialog_account_selection_change, dialog, NULL);
1390 g_signal_connect (selection, "changed",
1391 G_CALLBACK (accounts_dialog_model_selection_changed),
1394 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1395 COL_NAME, GTK_SORT_ASCENDING);
1397 accounts_dialog_model_add_columns (dialog);
1399 g_object_unref (store);
1403 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1404 EmpathyAccountSettings *settings,
1408 GtkTreeSelection *selection;
1409 GtkTreeModel *model;
1411 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1413 /* Update the status in the model */
1414 view = GTK_TREE_VIEW (priv->treeview);
1415 selection = gtk_tree_view_get_selection (view);
1416 model = gtk_tree_view_get_model (view);
1418 for (ok = gtk_tree_model_get_iter_first (model, iter);
1420 ok = gtk_tree_model_iter_next (model, iter))
1422 EmpathyAccountSettings *this_settings;
1425 gtk_tree_model_get (model, iter,
1426 COL_ACCOUNT_SETTINGS, &this_settings,
1429 equal = (this_settings == settings);
1430 g_object_unref (this_settings);
1440 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
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 *settings;
1462 gtk_tree_model_get (model, iter,
1463 COL_ACCOUNT_SETTINGS, &settings,
1466 equal = empathy_account_settings_has_account (settings, account);
1467 g_object_unref (settings);
1477 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1478 EmpathyAccountSettings *settings)
1480 GtkTreeSelection *selection;
1482 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1484 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1485 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1486 gtk_tree_selection_select_iter (selection, &iter);
1489 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1490 EmpathyAccountSettings *settings)
1492 GtkTreeModel *model;
1495 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1497 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1498 name = empathy_account_settings_get_display_name (settings);
1500 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1502 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1504 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1505 COL_ACCOUNT_SETTINGS, settings,
1510 accounts_dialog_connection_changed_cb (TpAccount *account,
1514 gchar *dbus_error_name,
1515 GHashTable *details,
1516 EmpathyAccountsDialog *dialog)
1518 GtkTreeModel *model;
1521 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1523 /* Update the status-infobar in the details view */
1524 accounts_dialog_update_status_infobar (dialog, account);
1526 /* Update the status in the model */
1527 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1529 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1533 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1534 COL_STATUS, current,
1537 path = gtk_tree_model_get_path (model, &iter);
1538 gtk_tree_model_row_changed (model, path, &iter);
1539 gtk_tree_path_free (path);
1542 empathy_account_manager_get_accounts_connected (&found);
1544 if (!found && priv->connecting_id)
1546 g_source_remove (priv->connecting_id);
1547 priv->connecting_id = 0;
1550 if (found && !priv->connecting_id)
1551 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1552 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1557 update_account_in_treeview (EmpathyAccountsDialog *self,
1560 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1562 GtkTreeModel *model;
1564 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1565 if (accounts_dialog_get_account_iter (self, account, &iter))
1569 path = gtk_tree_model_get_path (model, &iter);
1570 gtk_tree_model_row_changed (model, path, &iter);
1571 gtk_tree_path_free (path);
1576 accounts_dialog_presence_changed_cb (TpAccount *account,
1579 gchar *status_message,
1580 EmpathyAccountsDialog *dialog)
1582 /* Update the status-infobar in the details view */
1583 accounts_dialog_update_status_infobar (dialog, account);
1585 update_account_in_treeview (dialog, account);
1589 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1593 const gchar *display_name;
1595 GtkTreeModel *model;
1596 EmpathyAccountSettings *settings;
1597 TpAccount *selected_account;
1598 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1599 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1601 display_name = tp_account_get_display_name (account);
1602 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1603 settings = accounts_dialog_model_get_selected_settings (dialog);
1604 if (settings == NULL)
1607 selected_account = empathy_account_settings_get_account (settings);
1609 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1611 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1612 COL_NAME, display_name,
1616 if (selected_account == account)
1617 accounts_dialog_update_name_label (dialog, display_name);
1619 g_object_unref (settings);
1623 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1626 EmpathyAccountSettings *settings;
1627 GtkTreeModel *model;
1629 TpConnectionStatus status;
1632 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1634 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1635 status = tp_account_get_connection_status (account, NULL);
1636 name = tp_account_get_display_name (account);
1637 enabled = tp_account_is_enabled (account);
1639 settings = empathy_account_settings_new_for_account (account);
1641 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1642 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1644 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1647 COL_ACCOUNT, account,
1648 COL_ACCOUNT_SETTINGS, settings,
1651 accounts_dialog_connection_changed_cb (account,
1654 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1659 tp_g_signal_connect_object (account, "notify::display-name",
1660 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1663 tp_g_signal_connect_object (account, "status-changed",
1664 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1665 tp_g_signal_connect_object (account, "presence-changed",
1666 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1668 g_object_unref (settings);
1672 account_prepare_cb (GObject *source_object,
1673 GAsyncResult *result,
1676 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1677 TpAccount *account = TP_ACCOUNT (source_object);
1678 GError *error = NULL;
1680 if (!tp_account_prepare_finish (account, result, &error))
1682 DEBUG ("Failed to prepare account: %s", error->message);
1683 g_error_free (error);
1687 accounts_dialog_add_account (dialog, account);
1691 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1694 EmpathyAccountsDialog *dialog)
1696 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1700 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1703 EmpathyAccountsDialog *dialog)
1705 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1707 if (priv->setting_widget_object != NULL &&
1708 accounts_dialog_has_valid_accounts (dialog))
1710 empathy_account_widget_set_other_accounts_exist (
1711 priv->setting_widget_object, TRUE);
1716 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1718 EmpathyAccountsDialog *dialog)
1720 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1722 if (priv->setting_widget_object != NULL &&
1723 !accounts_dialog_has_valid_accounts (dialog))
1725 empathy_account_widget_set_other_accounts_exist (
1726 priv->setting_widget_object, FALSE);
1731 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1733 EmpathyAccountsDialog *dialog)
1736 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1738 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1740 gtk_list_store_remove (GTK_LIST_STORE (
1741 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1746 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1750 GtkTreeModel *model;
1751 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1753 /* Update the status in the model */
1754 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1756 /* Update the status-infobar in the details view */
1757 accounts_dialog_update_status_infobar (dialog, account);
1759 DEBUG ("Account %s is now %s",
1760 tp_account_get_display_name (account),
1761 enabled ? "enabled" : "disabled");
1765 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1767 EmpathyAccountsDialog *dialog)
1769 enable_or_disable_account (dialog, account, FALSE);
1770 update_account_in_treeview (dialog, account);
1774 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1776 EmpathyAccountsDialog *dialog)
1778 enable_or_disable_account (dialog, account, TRUE);
1782 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1783 EmpathyAccountsDialog *dialog)
1785 GtkWidget *import_dialog;
1787 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1789 gtk_widget_show (import_dialog);
1793 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1797 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1799 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1801 if (response_id == GTK_RESPONSE_YES)
1802 gtk_widget_destroy (account_dialog);
1806 accounts_dialog_delete_event_cb (GtkWidget *widget,
1808 EmpathyAccountsDialog *dialog)
1810 /* we maunally handle responses to delete events */
1815 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1818 GtkTreeSelection *selection;
1820 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1822 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1823 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1824 gtk_tree_selection_select_iter (selection, &iter);
1828 finished_loading (EmpathyAccountsDialog *self)
1830 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1831 GtkTreeSelection *selection;
1832 gboolean has_selected;
1834 priv->loading = FALSE;
1836 gtk_widget_set_sensitive (priv->button_add, TRUE);
1837 gtk_widget_set_sensitive (priv->button_import, TRUE);
1838 gtk_widget_set_sensitive (priv->treeview, TRUE);
1840 /* Sensitive the remove button if there is an account selected */
1841 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1842 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
1843 gtk_widget_set_sensitive (priv->button_remove, has_selected);
1845 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
1846 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
1847 NOTEBOOK_PAGE_ACCOUNT);
1851 accounts_dialog_cms_prepare_cb (GObject *source,
1852 GAsyncResult *result,
1855 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1856 EmpathyAccountsDialog *dialog = user_data;
1857 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1859 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1862 accounts_dialog_update_settings (dialog, NULL);
1864 if (priv->initial_selection != NULL)
1866 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1867 g_object_unref (priv->initial_selection);
1868 priv->initial_selection = NULL;
1872 finished_loading (dialog);
1876 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1878 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1879 GList *accounts, *l;
1881 g_signal_connect (priv->account_manager, "account-validity-changed",
1882 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1884 g_signal_connect (priv->account_manager, "account-removed",
1885 G_CALLBACK (accounts_dialog_account_removed_cb),
1887 g_signal_connect (priv->account_manager, "account-enabled",
1888 G_CALLBACK (accounts_dialog_account_enabled_cb),
1890 g_signal_connect (priv->account_manager, "account-disabled",
1891 G_CALLBACK (accounts_dialog_account_disabled_cb),
1894 /* Add existing accounts */
1895 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1896 for (l = accounts; l; l = l->next)
1898 accounts_dialog_add_account (dialog, l->data);
1900 g_list_free (accounts);
1902 priv->cms = empathy_connection_managers_dup_singleton ();
1904 empathy_connection_managers_prepare_async (priv->cms,
1905 accounts_dialog_cms_prepare_cb, dialog);
1907 accounts_dialog_model_select_first (dialog);
1911 accounts_dialog_manager_ready_cb (GObject *source_object,
1912 GAsyncResult *result,
1915 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1916 GError *error = NULL;
1918 if (!tp_account_manager_prepare_finish (manager, result, &error))
1920 DEBUG ("Failed to prepare account manager: %s", error->message);
1921 g_error_free (error);
1925 accounts_dialog_accounts_setup (user_data);
1929 dialog_response_cb (GtkWidget *widget,
1933 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1935 if (response_id == GTK_RESPONSE_HELP)
1937 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1939 else if (response_id == GTK_RESPONSE_CLOSE ||
1940 response_id == GTK_RESPONSE_DELETE_EVENT)
1942 TpAccount *account = NULL;
1944 if (accounts_dialog_has_pending_change (dialog, &account))
1946 gchar *question_dialog_primary_text = get_dialog_primary_text (
1949 accounts_dialog_show_question_dialog (dialog,
1950 question_dialog_primary_text,
1951 _("You are about to close the window, which will discard\n"
1952 "your changes. Are you sure you want to proceed?"),
1953 G_CALLBACK (accounts_dialog_close_response_cb),
1955 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1956 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1958 g_free (question_dialog_primary_text);
1962 gtk_widget_destroy (widget);
1965 if (account != NULL)
1966 g_object_unref (account);
1971 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1973 GtkWidget *top_hbox;
1976 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1977 GtkWidget *content_area;
1978 GtkWidget *action_area, *vbox, *hbox, *align;
1981 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1983 gui = empathy_builder_get_file (filename,
1984 "accounts_dialog_hbox", &top_hbox,
1985 "vbox_details", &priv->vbox_details,
1986 "frame_no_protocol", &priv->frame_no_protocol,
1987 "alignment_settings", &priv->alignment_settings,
1988 "alignment_infobar", &priv->alignment_infobar,
1989 "treeview", &priv->treeview,
1990 "button_add", &priv->button_add,
1991 "button_remove", &priv->button_remove,
1992 "button_import", &priv->button_import,
1993 "hbox_protocol", &priv->hbox_protocol,
1994 "notebook_account", &priv->notebook_account,
1995 "alignment_loading", &alig,
1999 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2001 empathy_builder_connect (gui, dialog,
2002 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2003 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2004 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2007 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2009 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2011 g_object_unref (gui);
2013 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2016 gtk_widget_hide (action_area);
2017 gtk_widget_hide (priv->button_remove);
2018 #endif /* HAVE_MEEGO */
2020 /* Display loading page */
2021 priv->loading = TRUE;
2023 priv->spinner = gtk_spinner_new ();
2025 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2026 gtk_widget_show (priv->spinner);
2028 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2030 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2031 NOTEBOOK_PAGE_LOADING);
2033 /* Remove button is insensitive until we have a selected account */
2034 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2036 /* Add and Import buttons and treeview are insensitive while the dialog
2038 gtk_widget_set_sensitive (priv->button_add, FALSE);
2039 gtk_widget_set_sensitive (priv->button_import, FALSE);
2040 gtk_widget_set_sensitive (priv->treeview, FALSE);
2042 priv->combobox_protocol = empathy_protocol_chooser_new ();
2043 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
2045 g_signal_connect (priv->combobox_protocol, "changed",
2046 G_CALLBACK (accounts_dialog_protocol_changed_cb),
2049 if (priv->parent_window)
2050 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2051 priv->parent_window);
2053 priv->infobar = gtk_info_bar_new ();
2054 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2056 gtk_widget_show (priv->infobar);
2058 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
2060 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2061 GTK_ICON_SIZE_DIALOG);
2062 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2063 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
2064 gtk_widget_show (priv->image_type);
2066 vbox = gtk_vbox_new (FALSE, 6);
2067 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
2068 gtk_widget_show (vbox);
2071 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2072 gtk_widget_show (align);
2074 priv->label_name = gtk_label_new (NULL);
2075 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
2076 gtk_widget_show (priv->label_name);
2078 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2081 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2082 gtk_widget_show (align);
2083 hbox = gtk_hbox_new (FALSE, 6);
2084 gtk_widget_show (hbox);
2085 gtk_container_add (GTK_CONTAINER (align), hbox);
2087 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2089 /* set up spinner */
2090 priv->throbber = gtk_spinner_new ();
2092 priv->image_status = gtk_image_new_from_icon_name (
2093 empathy_icon_name_for_presence (
2094 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2096 priv->label_status = gtk_label_new (NULL);
2097 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
2098 gtk_widget_show (priv->label_status);
2100 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2101 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
2102 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
2104 /* Tweak the dialog */
2105 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2106 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2108 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2110 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2112 /* add dialog buttons */
2113 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2115 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2116 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2117 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2120 g_signal_connect (dialog, "response",
2121 G_CALLBACK (dialog_response_cb), dialog);
2123 g_signal_connect (dialog, "delete-event",
2124 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2128 do_dispose (GObject *obj)
2130 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2131 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2133 if (priv->connecting_id != 0)
2135 g_source_remove (priv->connecting_id);
2136 priv->connecting_id = 0;
2139 if (priv->account_manager != NULL)
2141 g_object_unref (priv->account_manager);
2142 priv->account_manager = NULL;
2145 if (priv->cms != NULL)
2147 g_object_unref (priv->cms);
2151 if (priv->connectivity)
2153 g_object_unref (priv->connectivity);
2154 priv->connectivity = NULL;
2157 if (priv->initial_selection != NULL)
2159 g_object_unref (priv->initial_selection);
2160 priv->initial_selection = NULL;
2163 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2167 do_get_property (GObject *object,
2172 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2174 switch (property_id)
2177 g_value_set_object (value, priv->parent_window);
2180 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2185 do_set_property (GObject *object,
2187 const GValue *value,
2190 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2192 switch (property_id)
2195 priv->parent_window = g_value_get_object (value);
2198 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2203 do_constructed (GObject *object)
2205 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2206 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2207 GtkTreeModel *model;
2209 accounts_dialog_build_ui (dialog);
2210 accounts_dialog_model_setup (dialog);
2212 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2213 g_signal_connect (model, "row-inserted",
2214 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2215 g_signal_connect (model, "row-deleted",
2216 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2218 /* Set up signalling */
2219 priv->account_manager = tp_account_manager_dup ();
2221 tp_account_manager_prepare_async (priv->account_manager, NULL,
2222 accounts_dialog_manager_ready_cb, dialog);
2224 priv->connectivity = empathy_connectivity_dup_singleton ();
2228 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2230 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2231 GParamSpec *param_spec;
2233 oclass->dispose = do_dispose;
2234 oclass->constructed = do_constructed;
2235 oclass->set_property = do_set_property;
2236 oclass->get_property = do_get_property;
2238 param_spec = g_param_spec_object ("parent",
2239 "parent", "The parent window",
2241 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2242 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2244 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2248 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2250 EmpathyAccountsDialogPriv *priv;
2252 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2253 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2254 EmpathyAccountsDialogPriv);
2255 dialog->priv = priv;
2258 /* public methods */
2261 empathy_accounts_dialog_show (GtkWindow *parent,
2262 TpAccount *selected_account)
2264 EmpathyAccountsDialog *dialog;
2265 EmpathyAccountsDialogPriv *priv;
2267 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2268 "parent", parent, NULL);
2270 priv = GET_PRIV (dialog);
2272 if (selected_account)
2274 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2275 accounts_dialog_set_selected_account (dialog, selected_account);
2277 /* save the selection to set it later when the cms
2280 priv->initial_selection = g_object_ref (selected_account);
2283 gtk_window_present (GTK_WINDOW (dialog));
2285 return GTK_WIDGET (dialog);
2289 empathy_accounts_dialog_show_application (GdkScreen *screen,
2290 TpAccount *selected_account,
2294 GError *error = NULL;
2295 const gchar *argv[4] = { NULL, };
2297 gchar *account_option = NULL;
2300 g_return_if_fail (GDK_IS_SCREEN (screen));
2301 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2303 /* Try to run from source directory if possible */
2304 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
2305 "empathy-accounts", NULL);
2307 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2310 path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
2315 if (selected_account != NULL)
2317 const gchar *account_path;
2319 account_path = tp_proxy_get_object_path (TP_PROXY (selected_account));
2320 account_option = g_strdup_printf ("--select-account=%s",
2321 &account_path[strlen (TP_ACCOUNT_OBJECT_PATH_BASE)]);
2323 argv[i++] = account_option;
2327 argv[i++] = "--if-needed";
2330 argv[i++] = "--hidden";
2332 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2334 selected_account == NULL ? "<none selected>" :
2335 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2337 gdk_spawn_on_screen (screen, NULL, (gchar**) argv, NULL, G_SPAWN_SEARCH_PATH,
2338 NULL, NULL, NULL, &error);
2341 g_warning ("Failed to open accounts dialog: %s", error->message);
2342 g_error_free (error);
2345 g_free (account_option);
2350 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2352 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2353 gboolean result = FALSE;
2355 if (priv->setting_widget_object == NULL)
2358 g_object_get (priv->setting_widget_object,
2359 "creating-account", &result, NULL);