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.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-connection-managers.h>
40 #include <libempathy/empathy-connectivity.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include <libempathy-gtk/empathy-protocol-chooser.h>
44 #include <libempathy-gtk/empathy-account-widget.h>
45 #include <libempathy-gtk/empathy-account-widget-irc.h>
46 #include <libempathy-gtk/empathy-account-widget-sip.h>
47 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
48 #include <libempathy-gtk/empathy-conf.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"
54 #include "ephy-spinner.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);
74 static EmpathyAccountsDialog *dialog_singleton = NULL;
77 GtkWidget *alignment_settings;
78 GtkWidget *alignment_infobar;
80 GtkWidget *vbox_details;
82 GtkWidget *label_status;
83 GtkWidget *image_status;
85 GtkWidget *frame_no_protocol;
89 GtkWidget *button_add;
90 GtkWidget *button_remove;
91 GtkWidget *button_import;
93 GtkWidget *combobox_protocol;
94 GtkWidget *hbox_protocol;
96 GtkWidget *image_type;
97 GtkWidget *label_name;
98 GtkWidget *label_type;
99 GtkWidget *settings_widget;
101 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
102 * his GtkWidget. It is the only reliable source we can query to know if
103 * there are any unsaved changes to the currently selected account. We can't
104 * look at the account settings because it does not contain everything that
105 * can be changed using the EmpathyAccountWidget. For instance, it does not
106 * contain the state of the "Enabled" checkbox. */
107 EmpathyAccountWidget *setting_widget_object;
109 gboolean connecting_show;
112 gulong settings_ready_id;
113 EmpathyAccountSettings *settings_ready;
115 TpAccountManager *account_manager;
116 EmpathyConnectionManagers *cms;
118 GtkWindow *parent_window;
119 TpAccount *initial_selection;
121 /* Those are needed when changing the selected row. When a user selects
122 * another account and there are unsaved changes on the currently selected
123 * one, a confirmation message box is presented to him. Since his answer
124 * is retrieved asynchronously, we keep some information as member of the
125 * EmpathyAccountsDialog object. */
126 gboolean force_change_row;
127 GtkTreeRowReference *destination_row;
129 gboolean dispose_has_run;
130 } EmpathyAccountsDialogPriv;
136 COL_ACCOUNT_SETTINGS,
144 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
145 EmpathyAccountsDialog *dialog);
147 static gboolean accounts_dialog_get_settings_iter (
148 EmpathyAccountsDialog *dialog,
149 EmpathyAccountSettings *settings,
152 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
154 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings);
157 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
158 EmpathyAccountSettings *settings);
160 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
161 EmpathyAccountSettings *settings);
163 static void accounts_dialog_connection_changed_cb (TpAccount *account,
167 gchar *dbus_error_name,
169 EmpathyAccountsDialog *dialog);
171 static void accounts_dialog_presence_changed_cb (TpAccount *account,
174 gchar *status_message,
175 EmpathyAccountsDialog *dialog);
178 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
179 const gchar *display_name)
182 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
184 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
185 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
191 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
194 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
195 const gchar *message;
196 gchar *message_markup;
197 gchar *status_message = NULL;
201 EmpathyConnectivity *connectivity;
204 GtkTreeSelection *selection;
206 TpAccount *selected_account;
207 gboolean account_enabled;
208 gboolean creating_account;
210 view = GTK_TREE_VIEW (priv->treeview);
211 selection = gtk_tree_view_get_selection (view);
213 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
216 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
217 if (selected_account != NULL)
218 g_object_unref (selected_account);
220 /* do not update the infobar when the account is not selected */
221 if (account != selected_account)
226 status = tp_account_get_connection_status (account, &reason);
227 presence = tp_account_get_current_presence (account, NULL, &status_message);
228 account_enabled = tp_account_is_enabled (account);
229 creating_account = FALSE;
231 if (status == TP_CONNECTION_STATUS_CONNECTED &&
232 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
233 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
234 /* If presence is Unset (CM doesn't implement SimplePresence) but we
235 * are connected, consider ourself as Available.
236 * We also check Offline because of this MC5 bug: fd.o #26060 */
237 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
239 /* set presence to offline if account is disabled
240 * (else no icon is shown in infobar)*/
241 if (!account_enabled)
242 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
246 status = TP_CONNECTION_STATUS_DISCONNECTED;
247 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
248 account_enabled = FALSE;
249 creating_account = TRUE;
252 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
253 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
259 case TP_CONNECTION_STATUS_CONNECTING:
260 message = _("Connecting…");
261 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
264 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
265 gtk_widget_show (priv->throbber);
266 gtk_widget_hide (priv->image_status);
268 case TP_CONNECTION_STATUS_CONNECTED:
269 if (g_strcmp0 (status_message, "") == 0)
271 message = g_strdup_printf ("%s",
272 empathy_presence_get_default_message (presence));
276 message = g_strdup_printf ("%s — %s",
277 empathy_presence_get_default_message (presence),
280 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
283 gtk_widget_show (priv->image_status);
284 gtk_widget_hide (priv->throbber);
286 case TP_CONNECTION_STATUS_DISCONNECTED:
287 message = g_strdup_printf (_("Disconnected — %s"),
288 empathy_status_reason_get_default_message (reason));
290 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
292 message = g_strdup_printf (_("Offline — %s"),
293 empathy_status_reason_get_default_message (reason));
294 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
295 GTK_MESSAGE_WARNING);
299 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
303 connectivity = empathy_connectivity_dup_singleton ();
304 if (!empathy_connectivity_is_online (connectivity))
305 message = _("Offline — No Network Connection");
307 g_object_unref (connectivity);
308 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
309 gtk_widget_show (priv->image_status);
310 gtk_widget_hide (priv->throbber);
313 message = _("Unknown Status");
314 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
315 GTK_MESSAGE_WARNING);
317 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
318 gtk_widget_hide (priv->image_status);
319 gtk_widget_hide (priv->throbber);
324 message = _("Offline — Account Disabled");
326 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
327 GTK_MESSAGE_WARNING);
328 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
329 gtk_widget_show (priv->image_status);
330 gtk_widget_hide (priv->throbber);
333 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
334 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
335 gtk_widget_show (priv->label_status);
337 if (!creating_account)
338 gtk_widget_show (priv->infobar);
340 gtk_widget_hide (priv->infobar);
342 g_free (status_message);
343 g_free (message_markup);
347 empathy_account_dialog_widget_cancelled_cb (
348 EmpathyAccountWidget *widget_object,
349 EmpathyAccountsDialog *dialog)
353 GtkTreeSelection *selection;
355 EmpathyAccountSettings *settings;
357 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
359 view = GTK_TREE_VIEW (priv->treeview);
360 selection = gtk_tree_view_get_selection (view);
362 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
365 gtk_tree_model_get (model, &iter,
366 COL_ACCOUNT_SETTINGS, &settings,
367 COL_ACCOUNT, &account, -1);
369 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
373 /* We were creating an account. We remove the selected row */
374 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
378 /* We were modifying an account. We discard the changes by reloading the
379 * settings and the UI. */
380 accounts_dialog_update_settings (dialog, settings);
381 g_object_unref (account);
384 gtk_widget_set_sensitive (priv->treeview, TRUE);
385 gtk_widget_set_sensitive (priv->button_add, TRUE);
386 gtk_widget_set_sensitive (priv->button_remove, TRUE);
387 gtk_widget_set_sensitive (priv->button_import, TRUE);
389 if (settings != NULL)
390 g_object_unref (settings);
394 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
396 EmpathyAccountsDialog *dialog)
399 EmpathyAccountSettings *settings =
400 accounts_dialog_model_get_selected_settings (dialog);
401 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
403 display_name = empathy_account_widget_get_default_display_name (
406 empathy_account_settings_set_display_name_async (settings,
407 display_name, NULL, NULL);
409 g_free (display_name);
411 accounts_dialog_update_settings (dialog, settings);
412 accounts_dialog_update_status_infobar (dialog,
413 empathy_account_settings_get_account (settings));
415 gtk_widget_set_sensitive (priv->treeview, TRUE);
416 gtk_widget_set_sensitive (priv->button_add, TRUE);
417 gtk_widget_set_sensitive (priv->button_remove, TRUE);
418 gtk_widget_set_sensitive (priv->button_import, TRUE);
420 empathy_signal_connect_weak (account, "status-changed",
421 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
422 empathy_signal_connect_weak (account, "presence-changed",
423 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
426 g_object_unref (settings);
430 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
431 EmpathyAccountSettings *settings)
433 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
437 priv->setting_widget_object =
438 empathy_account_widget_new_for_protocol (settings, FALSE);
440 priv->settings_widget =
441 empathy_account_widget_get_widget (priv->setting_widget_object);
443 g_signal_connect (priv->setting_widget_object, "account-created",
444 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
445 g_signal_connect (priv->setting_widget_object, "cancelled",
446 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
448 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
449 priv->settings_widget);
450 gtk_widget_show (priv->settings_widget);
452 icon_name = empathy_account_settings_get_icon_name (settings);
454 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
456 /* show the default icon; keep this in sync with the default
457 * one in empathy-accounts-dialog.ui.
459 icon_name = GTK_STOCK_CUT;
461 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
462 icon_name, GTK_ICON_SIZE_DIALOG);
463 gtk_widget_set_tooltip_text (priv->image_type,
464 empathy_protocol_name_to_display_name
465 (empathy_account_settings_get_protocol (settings)));
466 gtk_widget_show (priv->image_type);
468 accounts_dialog_update_name_label (dialog,
469 empathy_account_settings_get_display_name (settings));
471 account = empathy_account_settings_get_account (settings);
472 accounts_dialog_update_status_infobar (dialog, account);
476 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
478 EmpathyAccountsDialog *dialog)
480 if (empathy_account_settings_is_ready (settings))
481 account_dialog_create_settings_widget (dialog, settings);
485 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
489 GtkTreeSelection *selection;
491 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
494 view = GTK_TREE_VIEW (priv->treeview);
495 model = gtk_tree_view_get_model (view);
497 if (gtk_tree_model_get_iter_first (model, &iter))
499 selection = gtk_tree_view_get_selection (view);
500 gtk_tree_selection_select_iter (selection, &iter);
504 accounts_dialog_update_settings (dialog, NULL);
509 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
514 GtkTreeSelection *selection;
515 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
517 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
519 if (gtk_tree_selection_get_selected (selection, &model, &iter))
520 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
522 return priv->setting_widget_object != NULL
523 && empathy_account_widget_contains_pending_changes (
524 priv->setting_widget_object);
528 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
530 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
531 EmpathyAccountSettings *settings;
533 const gchar *display_name;
534 TpConnectionManager *cm;
535 TpConnectionManagerProtocol *proto;
538 cm = empathy_protocol_chooser_dup_selected (
539 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
543 display_name = empathy_protocol_name_to_display_name (
544 is_gtalk ? "gtalk" : proto->name);
546 if (display_name == NULL)
547 display_name = proto->name;
550 /* To translator: %s is the name of the protocol, such as "Google Talk" or
553 str = g_strdup_printf (_("New %s account"), display_name);
554 settings = empathy_account_settings_new (cm->name, proto->name, str);
559 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
562 accounts_dialog_add (dialog, settings);
563 accounts_dialog_model_set_selected (dialog, settings);
565 gtk_widget_show_all (priv->hbox_protocol);
567 g_object_unref (settings);
572 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
573 EmpathyAccountsDialog *dialog)
575 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
576 GtkTreeSelection *selection;
580 EmpathyAccountSettings *settings;
581 gchar *account = NULL, *password = NULL;
583 /* The "changed" signal is fired during the initiation of the
584 * EmpathyProtocolChooser while populating the widget. Such signals should
585 * be ignored so we check if we are actually creating a new account. */
586 if (priv->setting_widget_object == NULL)
589 g_object_get (priv->setting_widget_object,
590 "creating-account", &creating, NULL);
594 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
596 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
599 /* Save "account" and "password" parameters */
600 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
602 if (settings != NULL)
604 account = g_strdup (empathy_account_settings_get_string (settings,
606 password = g_strdup (empathy_account_settings_get_string (settings,
608 g_object_unref (settings);
611 /* We are creating a new widget to replace the current one, don't ask
612 * confirmation to the user. */
613 priv->force_change_row = TRUE;
614 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
616 accounts_dialog_setup_ui_to_add_account (dialog);
618 /* Restore "account" and "password" parameters in the new widget */
621 empathy_account_widget_set_account_param (priv->setting_widget_object,
626 if (password != NULL)
628 empathy_account_widget_set_password_param (priv->setting_widget_object,
635 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
636 const gchar *primary_text,
637 const gchar *secondary_text,
638 GCallback response_callback,
640 const gchar *first_button_text,
644 GtkWidget *message_dialog;
645 const gchar *button_text;
647 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
648 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
649 GTK_MESSAGE_QUESTION,
653 gtk_message_dialog_format_secondary_text (
654 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
656 va_start (button_args, first_button_text);
657 for (button_text = first_button_text;
659 button_text = va_arg (button_args, const gchar *))
662 response_id = va_arg (button_args, gint);
664 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
667 va_end (button_args);
669 g_signal_connect (message_dialog, "response", response_callback, user_data);
671 gtk_widget_show (message_dialog);
675 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
679 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
680 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
682 gtk_widget_destroy (GTK_WIDGET (message_dialog));
684 if (response_id == GTK_RESPONSE_YES)
686 empathy_account_widget_discard_pending_changes (
687 priv->setting_widget_object);
688 accounts_dialog_setup_ui_to_add_account (dialog);
693 get_dialog_primary_text (TpAccount *account)
697 /* Existing account */
698 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
699 tp_account_get_display_name (account));
703 /* Newly created account */
704 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
709 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
710 EmpathyAccountsDialog *dialog)
712 TpAccount *account = NULL;
713 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
715 if (accounts_dialog_has_pending_change (dialog, &account))
717 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
719 accounts_dialog_show_question_dialog (dialog,
720 question_dialog_primary_text,
721 _("You are about to create a new account, which will discard\n"
722 "your changes. Are you sure you want to proceed?"),
723 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
725 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
726 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
728 g_free (question_dialog_primary_text);
732 accounts_dialog_setup_ui_to_add_account (dialog);
733 gtk_widget_set_sensitive (priv->treeview, FALSE);
734 gtk_widget_set_sensitive (priv->button_add, FALSE);
735 gtk_widget_set_sensitive (priv->button_remove, FALSE);
736 gtk_widget_set_sensitive (priv->button_import, FALSE);
740 g_object_unref (account);
744 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
745 EmpathyAccountSettings *settings)
747 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
749 if (priv->settings_ready != NULL)
751 g_signal_handler_disconnect (priv->settings_ready,
752 priv->settings_ready_id);
753 priv->settings_ready = NULL;
754 priv->settings_ready_id = 0;
761 GtkTreeSelection *selection;
763 view = GTK_TREE_VIEW (priv->treeview);
764 model = gtk_tree_view_get_model (view);
765 selection = gtk_tree_view_get_selection (view);
767 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
769 /* We have configured accounts, select the first one if there
770 * is no other account selected already. */
771 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
772 accounts_dialog_model_select_first (dialog);
776 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
778 /* We have no account configured but we have some
779 * profiles installed. The user obviously wants to add
780 * an account. Click on the Add button for him. */
781 accounts_dialog_button_add_clicked_cb (priv->button_add,
786 /* No account and no profile, warn the user */
787 gtk_widget_hide (priv->vbox_details);
788 gtk_widget_show (priv->frame_no_protocol);
789 gtk_widget_set_sensitive (priv->button_add, FALSE);
793 /* We have an account selected, destroy old settings and create a new
794 * one for the account selected */
795 gtk_widget_hide (priv->frame_no_protocol);
796 gtk_widget_show (priv->vbox_details);
797 gtk_widget_hide (priv->hbox_protocol);
799 if (priv->settings_widget)
801 gtk_widget_destroy (priv->settings_widget);
802 priv->settings_widget = NULL;
805 if (empathy_account_settings_is_ready (settings))
807 account_dialog_create_settings_widget (dialog, settings);
811 priv->settings_ready = settings;
812 priv->settings_ready_id =
813 g_signal_connect (settings, "notify::ready",
814 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
820 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
821 GtkCellEditable *editable,
823 EmpathyAccountsDialog *dialog)
825 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
827 if (priv->connecting_id)
828 g_source_remove (priv->connecting_id);
830 DEBUG ("Editing account name started; stopping flashing");
834 get_status_icon_for_account (EmpathyAccountsDialog *self,
837 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
838 TpConnectionStatus status;
839 TpConnectionStatusReason reason;
840 TpConnectionPresenceType presence;
843 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
845 if (!tp_account_is_enabled (account))
846 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
848 status = tp_account_get_connection_status (account, &reason);
850 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
852 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
853 /* An error occured */
854 return GTK_STOCK_DIALOG_ERROR;
856 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
858 else if (status == TP_CONNECTION_STATUS_CONNECTING)
860 /* Account is connecting. Display a blinking account alternating between
861 * the offline icon and the requested presence. */
862 if (priv->connecting_show)
863 presence = tp_account_get_requested_presence (account, NULL, NULL);
865 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
869 /* status == TP_CONNECTION_STATUS_CONNECTED */
870 presence = tp_account_get_current_presence (account, NULL, NULL);
872 /* If presence is Unset (CM doesn't implement SimplePresence),
873 * display the 'available' icon.
874 * We also check Offline because of this MC5 bug: fd.o #26060 */
875 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
876 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
877 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
880 return empathy_icon_name_for_presence (presence);
884 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
885 GtkCellRenderer *cell,
888 EmpathyAccountsDialog *dialog)
892 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
895 "icon-name", get_status_icon_for_account (dialog, account),
899 g_object_unref (account);
903 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
904 GtkCellRenderer *cell,
907 EmpathyAccountsDialog *dialog)
909 EmpathyAccountSettings *settings;
912 TpConnectionStatus status;
914 gtk_tree_model_get (model, iter,
916 COL_ACCOUNT_SETTINGS, &settings,
919 icon_name = empathy_account_settings_get_icon_name (settings);
920 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
927 g_object_unref (settings);
930 g_object_unref (pixbuf);
934 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
939 gtk_tree_model_row_changed (model, path, iter);
945 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
949 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
951 priv->connecting_show = !priv->connecting_show;
953 view = GTK_TREE_VIEW (priv->treeview);
954 model = gtk_tree_view_get_model (view);
956 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
962 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
965 EmpathyAccountsDialog *dialog)
967 EmpathyAccountSettings *settings;
969 GtkTreePath *treepath;
971 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
974 empathy_account_manager_get_accounts_connected (&connecting);
978 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
979 (GSourceFunc) accounts_dialog_flash_connecting_cb,
983 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
984 treepath = gtk_tree_path_new_from_string (path);
985 gtk_tree_model_get_iter (model, &iter, treepath);
986 gtk_tree_model_get (model, &iter,
987 COL_ACCOUNT_SETTINGS, &settings,
989 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
992 gtk_tree_path_free (treepath);
994 empathy_account_settings_set_display_name_async (settings, new_text,
996 g_object_set (settings, "display-name-overridden", TRUE, NULL);
997 g_object_unref (settings);
1001 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1006 GtkTreeModel *model;
1008 GtkTreeSelection *selection;
1009 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1010 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1012 if (response_id == GTK_RESPONSE_YES)
1014 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1016 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1019 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1021 if (account != NULL)
1023 tp_account_remove_async (account, NULL, NULL);
1024 g_object_unref (account);
1028 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1029 accounts_dialog_model_select_first (account_dialog);
1032 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1036 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1039 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1041 GtkTreeModel *model;
1042 gchar *question_dialog_primary_text;
1044 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1046 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1048 if (account == NULL || !tp_account_is_valid (account))
1050 if (account != NULL)
1051 g_object_unref (account);
1052 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1053 accounts_dialog_model_select_first (dialog);
1057 question_dialog_primary_text = g_strdup_printf (
1058 _("Do you want to remove %s from your computer?"),
1059 tp_account_get_display_name (account));
1061 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1062 _("This will not remove your account on the server."),
1063 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1065 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1066 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1068 g_free (question_dialog_primary_text);
1069 g_object_unref (account);
1073 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1074 EmpathyAccountsDialog *dialog)
1076 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1078 GtkTreeModel *model;
1079 GtkTreeSelection *selection;
1082 view = GTK_TREE_VIEW (priv->treeview);
1083 model = gtk_tree_view_get_model (view);
1084 selection = gtk_tree_view_get_selection (view);
1085 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1088 accounts_dialog_remove_account_iter (dialog, &iter);
1093 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1094 const gchar *path_string,
1095 EmpathyAccountsDialog *dialog)
1097 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1098 GtkTreeModel *model;
1101 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1102 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1105 accounts_dialog_remove_account_iter (dialog, &iter);
1110 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1113 GtkTreeViewColumn *column;
1114 GtkCellRenderer *cell;
1115 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1117 view = GTK_TREE_VIEW (priv->treeview);
1118 gtk_tree_view_set_headers_visible (view, FALSE);
1120 /* Account column */
1121 column = gtk_tree_view_column_new ();
1122 gtk_tree_view_column_set_expand (column, TRUE);
1123 gtk_tree_view_append_column (view, column);
1125 /* Status icon renderer */
1126 cell = gtk_cell_renderer_pixbuf_new ();
1127 gtk_tree_view_column_pack_start (column, cell, FALSE);
1128 gtk_tree_view_column_set_cell_data_func (column, cell,
1129 (GtkTreeCellDataFunc)
1130 accounts_dialog_model_status_pixbuf_data_func,
1134 /* Protocol icon renderer */
1135 cell = gtk_cell_renderer_pixbuf_new ();
1136 gtk_tree_view_column_pack_start (column, cell, FALSE);
1137 gtk_tree_view_column_set_cell_data_func (column, cell,
1138 (GtkTreeCellDataFunc)
1139 accounts_dialog_model_protocol_pixbuf_data_func,
1144 cell = gtk_cell_renderer_text_new ();
1146 "ellipsize", PANGO_ELLIPSIZE_END,
1150 gtk_tree_view_column_pack_start (column, cell, TRUE);
1151 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1152 g_signal_connect (cell, "edited",
1153 G_CALLBACK (accounts_dialog_name_edited_cb),
1155 g_signal_connect (cell, "editing-started",
1156 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1158 g_object_set (cell, "ypad", 4, NULL);
1162 cell = empathy_cell_renderer_activatable_new ();
1163 gtk_tree_view_column_pack_start (column, cell, FALSE);
1165 "icon-name", GTK_STOCK_DELETE,
1166 "show-on-select", TRUE,
1169 g_signal_connect (cell, "path-activated",
1170 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1175 static EmpathyAccountSettings *
1176 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1179 GtkTreeModel *model;
1180 GtkTreeSelection *selection;
1182 EmpathyAccountSettings *settings;
1183 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1185 view = GTK_TREE_VIEW (priv->treeview);
1186 selection = gtk_tree_view_get_selection (view);
1188 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1191 gtk_tree_model_get (model, &iter,
1192 COL_ACCOUNT_SETTINGS, &settings, -1);
1198 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1199 EmpathyAccountsDialog *dialog)
1201 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1202 EmpathyAccountSettings *settings;
1203 GtkTreeModel *model;
1205 gboolean is_selection;
1207 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1209 settings = accounts_dialog_model_get_selected_settings (dialog);
1210 accounts_dialog_update_settings (dialog, settings);
1212 if (settings != NULL)
1213 g_object_unref (settings);
1215 /* Update remove button sensitivity */
1216 gtk_widget_set_sensitive (priv->button_remove, is_selection);
1220 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1222 gpointer *user_data)
1224 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1225 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1227 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1229 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1231 /* The user wants to lose unsaved changes to the currently selected
1232 * account and select another account. We discard the changes and
1233 * select the other account. */
1235 GtkTreeSelection *selection;
1237 priv->force_change_row = TRUE;
1238 empathy_account_widget_discard_pending_changes (
1239 priv->setting_widget_object);
1241 path = gtk_tree_row_reference_get_path (priv->destination_row);
1242 selection = gtk_tree_view_get_selection (
1243 GTK_TREE_VIEW (priv->treeview));
1247 /* This will trigger a call to
1248 * accounts_dialog_account_selection_change() */
1249 gtk_tree_selection_select_path (selection, path);
1250 gtk_tree_path_free (path);
1253 gtk_tree_row_reference_free (priv->destination_row);
1257 priv->force_change_row = FALSE;
1262 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1263 GtkTreeModel *model,
1265 gboolean path_currently_selected,
1268 TpAccount *account = NULL;
1269 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1270 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1273 if (priv->force_change_row)
1275 /* We came back here because the user wants to discard changes to his
1276 * modified account. The changes have already been discarded so we
1277 * just change the selected row. */
1278 priv->force_change_row = FALSE;
1282 if (accounts_dialog_has_pending_change (dialog, &account))
1284 /* The currently selected account has some unsaved changes. We ask
1285 * the user if he really wants to lose his changes and select another
1287 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1288 priv->destination_row = gtk_tree_row_reference_new (model, path);
1290 accounts_dialog_show_question_dialog (dialog,
1291 question_dialog_primary_text,
1292 _("You are about to select another account, which will discard\n"
1293 "your changes. Are you sure you want to proceed?"),
1294 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1296 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1297 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1299 g_free (question_dialog_primary_text);
1307 if (account != NULL)
1308 g_object_unref (account);
1314 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1316 GtkListStore *store;
1317 GtkTreeSelection *selection;
1318 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1320 store = gtk_list_store_new (COL_COUNT,
1321 G_TYPE_STRING, /* name */
1322 G_TYPE_UINT, /* status */
1323 TP_TYPE_ACCOUNT, /* account */
1324 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1326 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1327 GTK_TREE_MODEL (store));
1329 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1330 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1331 gtk_tree_selection_set_select_function (selection,
1332 accounts_dialog_account_selection_change, dialog, NULL);
1334 g_signal_connect (selection, "changed",
1335 G_CALLBACK (accounts_dialog_model_selection_changed),
1338 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1339 COL_NAME, GTK_SORT_ASCENDING);
1341 accounts_dialog_model_add_columns (dialog);
1343 g_object_unref (store);
1347 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1348 EmpathyAccountSettings *settings,
1352 GtkTreeSelection *selection;
1353 GtkTreeModel *model;
1355 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1357 /* Update the status in the model */
1358 view = GTK_TREE_VIEW (priv->treeview);
1359 selection = gtk_tree_view_get_selection (view);
1360 model = gtk_tree_view_get_model (view);
1362 for (ok = gtk_tree_model_get_iter_first (model, iter);
1364 ok = gtk_tree_model_iter_next (model, iter))
1366 EmpathyAccountSettings *this_settings;
1369 gtk_tree_model_get (model, iter,
1370 COL_ACCOUNT_SETTINGS, &this_settings,
1373 equal = (this_settings == settings);
1374 g_object_unref (this_settings);
1384 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1389 GtkTreeSelection *selection;
1390 GtkTreeModel *model;
1392 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1394 /* Update the status in the model */
1395 view = GTK_TREE_VIEW (priv->treeview);
1396 selection = gtk_tree_view_get_selection (view);
1397 model = gtk_tree_view_get_model (view);
1399 for (ok = gtk_tree_model_get_iter_first (model, iter);
1401 ok = gtk_tree_model_iter_next (model, iter))
1403 EmpathyAccountSettings *settings;
1406 gtk_tree_model_get (model, iter,
1407 COL_ACCOUNT_SETTINGS, &settings,
1410 equal = empathy_account_settings_has_account (settings, account);
1411 g_object_unref (settings);
1421 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1422 EmpathyAccountSettings *settings)
1424 GtkTreeSelection *selection;
1426 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1428 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1429 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1430 gtk_tree_selection_select_iter (selection, &iter);
1433 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1434 EmpathyAccountSettings *settings)
1436 GtkTreeModel *model;
1439 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1441 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1442 name = empathy_account_settings_get_display_name (settings);
1444 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1446 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1448 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1449 COL_ACCOUNT_SETTINGS, settings,
1454 accounts_dialog_connection_changed_cb (TpAccount *account,
1458 gchar *dbus_error_name,
1459 GHashTable *details,
1460 EmpathyAccountsDialog *dialog)
1462 GtkTreeModel *model;
1465 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1467 /* Update the status-infobar in the details view */
1468 accounts_dialog_update_status_infobar (dialog, account);
1470 /* Update the status in the model */
1471 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1473 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1477 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1478 COL_STATUS, current,
1481 path = gtk_tree_model_get_path (model, &iter);
1482 gtk_tree_model_row_changed (model, path, &iter);
1483 gtk_tree_path_free (path);
1486 empathy_account_manager_get_accounts_connected (&found);
1488 if (!found && priv->connecting_id)
1490 g_source_remove (priv->connecting_id);
1491 priv->connecting_id = 0;
1494 if (found && !priv->connecting_id)
1495 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1496 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1501 update_account_in_treeview (EmpathyAccountsDialog *self,
1504 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1506 GtkTreeModel *model;
1508 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1509 if (accounts_dialog_get_account_iter (self, account, &iter))
1513 path = gtk_tree_model_get_path (model, &iter);
1514 gtk_tree_model_row_changed (model, path, &iter);
1515 gtk_tree_path_free (path);
1520 accounts_dialog_presence_changed_cb (TpAccount *account,
1523 gchar *status_message,
1524 EmpathyAccountsDialog *dialog)
1526 /* Update the status-infobar in the details view */
1527 accounts_dialog_update_status_infobar (dialog, account);
1529 update_account_in_treeview (dialog, account);
1533 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1537 const gchar *display_name;
1539 GtkTreeModel *model;
1540 EmpathyAccountSettings *settings;
1541 TpAccount *selected_account;
1542 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1543 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1545 display_name = tp_account_get_display_name (account);
1546 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1547 settings = accounts_dialog_model_get_selected_settings (dialog);
1548 if (settings == NULL)
1551 selected_account = empathy_account_settings_get_account (settings);
1553 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1555 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1556 COL_NAME, display_name,
1560 if (selected_account == account)
1561 accounts_dialog_update_name_label (dialog, display_name);
1563 g_object_unref (settings);
1567 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1570 EmpathyAccountSettings *settings;
1571 GtkTreeModel *model;
1573 TpConnectionStatus status;
1576 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1578 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1579 status = tp_account_get_connection_status (account, NULL);
1580 name = tp_account_get_display_name (account);
1581 enabled = tp_account_is_enabled (account);
1583 settings = empathy_account_settings_new_for_account (account);
1585 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1586 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1588 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1591 COL_ACCOUNT, account,
1592 COL_ACCOUNT_SETTINGS, settings,
1595 accounts_dialog_connection_changed_cb (account,
1598 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1603 empathy_signal_connect_weak (account, "notify::display-name",
1604 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1607 g_object_unref (settings);
1611 account_prepare_cb (GObject *source_object,
1612 GAsyncResult *result,
1615 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1616 TpAccount *account = TP_ACCOUNT (source_object);
1617 GError *error = NULL;
1619 if (!tp_account_prepare_finish (account, result, &error))
1621 DEBUG ("Failed to prepare account: %s", error->message);
1622 g_error_free (error);
1626 accounts_dialog_add_account (dialog, account);
1630 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1633 EmpathyAccountsDialog *dialog)
1635 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1639 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1641 EmpathyAccountsDialog *dialog)
1644 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1646 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1648 gtk_list_store_remove (GTK_LIST_STORE (
1649 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1654 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1658 GtkTreeModel *model;
1659 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1661 /* Update the status in the model */
1662 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1664 /* Update the status-infobar in the details view when disabling */
1666 accounts_dialog_update_status_infobar (dialog, account);
1668 DEBUG ("Account %s is now %s",
1669 tp_account_get_display_name (account),
1670 enabled ? "enabled" : "disabled");
1674 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1676 EmpathyAccountsDialog *dialog)
1678 enable_or_disable_account (dialog, account, FALSE);
1679 update_account_in_treeview (dialog, account);
1683 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1685 EmpathyAccountsDialog *dialog)
1687 enable_or_disable_account (dialog, account, TRUE);
1691 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1692 EmpathyAccountsDialog *dialog)
1694 GtkWidget *import_dialog;
1696 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1698 gtk_widget_show (import_dialog);
1702 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1706 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1708 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1710 if (response_id == GTK_RESPONSE_YES)
1711 gtk_widget_destroy (account_dialog);
1715 accounts_dialog_delete_event_cb (GtkWidget *widget,
1717 EmpathyAccountsDialog *dialog)
1719 /* we maunally handle responses to delete events */
1724 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1727 GtkTreeSelection *selection;
1729 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1731 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1732 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1733 gtk_tree_selection_select_iter (selection, &iter);
1737 accounts_dialog_cms_prepare_cb (GObject *source,
1738 GAsyncResult *result,
1741 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1742 EmpathyAccountsDialog *dialog = user_data;
1743 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1745 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1748 accounts_dialog_update_settings (dialog, NULL);
1750 if (priv->initial_selection != NULL)
1752 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1753 g_object_unref (priv->initial_selection);
1754 priv->initial_selection = NULL;
1759 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1761 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1762 GList *accounts, *l;
1764 g_signal_connect (priv->account_manager, "account-validity-changed",
1765 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1767 g_signal_connect (priv->account_manager, "account-removed",
1768 G_CALLBACK (accounts_dialog_account_removed_cb),
1770 g_signal_connect (priv->account_manager, "account-enabled",
1771 G_CALLBACK (accounts_dialog_account_enabled_cb),
1773 g_signal_connect (priv->account_manager, "account-disabled",
1774 G_CALLBACK (accounts_dialog_account_disabled_cb),
1777 /* Add existing accounts */
1778 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1779 for (l = accounts; l; l = l->next)
1781 accounts_dialog_add_account (dialog, l->data);
1783 empathy_signal_connect_weak (l->data, "status-changed",
1784 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1785 empathy_signal_connect_weak (l->data, "presence-changed",
1786 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1788 g_list_free (accounts);
1790 priv->cms = empathy_connection_managers_dup_singleton ();
1792 empathy_connection_managers_prepare_async (priv->cms,
1793 accounts_dialog_cms_prepare_cb, dialog);
1795 accounts_dialog_model_select_first (dialog);
1799 accounts_dialog_manager_ready_cb (GObject *source_object,
1800 GAsyncResult *result,
1803 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1804 GError *error = NULL;
1806 if (!tp_account_manager_prepare_finish (manager, result, &error))
1808 DEBUG ("Failed to prepare account manager: %s", error->message);
1809 g_error_free (error);
1813 accounts_dialog_accounts_setup (user_data);
1817 dialog_response_cb (GtkWidget *widget,
1821 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1823 if (response_id == GTK_RESPONSE_HELP)
1825 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1827 else if (response_id == GTK_RESPONSE_CLOSE ||
1828 response_id == GTK_RESPONSE_DELETE_EVENT)
1830 TpAccount *account = NULL;
1832 if (accounts_dialog_has_pending_change (dialog, &account))
1834 gchar *question_dialog_primary_text = get_dialog_primary_text (
1837 accounts_dialog_show_question_dialog (dialog,
1838 question_dialog_primary_text,
1839 _("You are about to close the window, which will discard\n"
1840 "your changes. Are you sure you want to proceed?"),
1841 G_CALLBACK (accounts_dialog_close_response_cb),
1843 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1844 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1846 g_free (question_dialog_primary_text);
1850 gtk_widget_destroy (widget);
1853 if (account != NULL)
1854 g_object_unref (account);
1859 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1861 GtkWidget *top_hbox;
1864 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1865 GtkWidget *content_area;
1866 GtkWidget *action_area, *vbox, *hbox, *align;
1868 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1870 gui = empathy_builder_get_file (filename,
1871 "accounts_dialog_hbox", &top_hbox,
1872 "vbox_details", &priv->vbox_details,
1873 "frame_no_protocol", &priv->frame_no_protocol,
1874 "alignment_settings", &priv->alignment_settings,
1875 "alignment_infobar", &priv->alignment_infobar,
1876 "treeview", &priv->treeview,
1877 "button_add", &priv->button_add,
1878 "button_remove", &priv->button_remove,
1879 "button_import", &priv->button_import,
1880 "hbox_protocol", &priv->hbox_protocol,
1884 empathy_builder_connect (gui, dialog,
1885 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1886 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1887 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1890 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1892 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
1894 g_object_unref (gui);
1896 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
1899 gtk_widget_hide (action_area);
1900 gtk_widget_hide (priv->button_remove);
1903 /* Remove button is unsensitive until we have a selected account */
1904 gtk_widget_set_sensitive (priv->button_remove, FALSE);
1906 priv->combobox_protocol = empathy_protocol_chooser_new ();
1907 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
1909 g_signal_connect (priv->combobox_protocol, "changed",
1910 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1913 if (priv->parent_window)
1914 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1915 priv->parent_window);
1917 priv->infobar = gtk_info_bar_new ();
1918 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1920 gtk_widget_show (priv->infobar);
1922 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1924 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
1925 GTK_ICON_SIZE_DIALOG);
1926 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
1927 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
1928 gtk_widget_show (priv->image_type);
1930 vbox = gtk_vbox_new (FALSE, 6);
1931 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
1932 gtk_widget_show (vbox);
1935 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
1936 gtk_widget_show (align);
1938 priv->label_name = gtk_label_new (NULL);
1939 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
1940 gtk_widget_show (priv->label_name);
1942 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
1945 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
1946 gtk_widget_show (align);
1947 hbox = gtk_hbox_new (FALSE, 6);
1948 gtk_widget_show (hbox);
1949 gtk_container_add (GTK_CONTAINER (align), hbox);
1951 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
1953 /* set up spinner */
1954 priv->throbber = ephy_spinner_new ();
1955 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1957 priv->image_status = gtk_image_new_from_icon_name (
1958 empathy_icon_name_for_presence (
1959 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1961 priv->label_status = gtk_label_new (NULL);
1962 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
1963 gtk_widget_show (priv->label_status);
1965 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
1966 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
1967 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
1969 /* Tweak the dialog */
1970 gtk_window_set_title (GTK_WINDOW (dialog), _("Accounts"));
1971 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
1973 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, -1);
1975 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
1977 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
1979 /* add dialog buttons */
1980 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
1982 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1983 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1984 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1987 g_signal_connect (dialog, "response",
1988 G_CALLBACK (dialog_response_cb), dialog);
1990 g_signal_connect (dialog, "delete-event",
1991 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
1995 do_dispose (GObject *obj)
1997 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1998 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2000 if (priv->dispose_has_run)
2003 priv->dispose_has_run = TRUE;
2005 /* Disconnect signals */
2006 g_signal_handlers_disconnect_by_func (priv->account_manager,
2007 accounts_dialog_account_validity_changed_cb,
2009 g_signal_handlers_disconnect_by_func (priv->account_manager,
2010 accounts_dialog_account_removed_cb,
2012 g_signal_handlers_disconnect_by_func (priv->account_manager,
2013 accounts_dialog_account_enabled_cb,
2015 g_signal_handlers_disconnect_by_func (priv->account_manager,
2016 accounts_dialog_account_disabled_cb,
2018 g_signal_handlers_disconnect_by_func (priv->account_manager,
2019 accounts_dialog_manager_ready_cb,
2022 if (priv->connecting_id)
2023 g_source_remove (priv->connecting_id);
2025 if (priv->account_manager != NULL)
2027 g_object_unref (priv->account_manager);
2028 priv->account_manager = NULL;
2031 if (priv->cms != NULL)
2033 g_object_unref (priv->cms);
2037 if (priv->initial_selection != NULL)
2038 g_object_unref (priv->initial_selection);
2039 priv->initial_selection = NULL;
2041 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2045 do_constructor (GType type,
2047 GObjectConstructParam *props)
2051 if (dialog_singleton)
2053 retval = G_OBJECT (dialog_singleton);
2058 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
2059 (type, n_props, props);
2061 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
2062 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
2069 do_get_property (GObject *object,
2074 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2076 switch (property_id)
2079 g_value_set_object (value, priv->parent_window);
2082 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2087 do_set_property (GObject *object,
2089 const GValue *value,
2092 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2094 switch (property_id)
2097 priv->parent_window = g_value_get_object (value);
2100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2105 do_constructed (GObject *object)
2107 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2108 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2109 gboolean import_asked;
2111 accounts_dialog_build_ui (dialog);
2112 accounts_dialog_model_setup (dialog);
2114 /* Set up signalling */
2115 priv->account_manager = tp_account_manager_dup ();
2117 tp_account_manager_prepare_async (priv->account_manager, NULL,
2118 accounts_dialog_manager_ready_cb, dialog);
2120 empathy_conf_get_bool (empathy_conf_get (),
2121 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
2123 if (empathy_import_accounts_to_import ())
2125 gtk_widget_show (priv->button_import);
2129 GtkWidget *import_dialog;
2131 empathy_conf_set_bool (empathy_conf_get (),
2132 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
2133 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2135 gtk_widget_show (import_dialog);
2141 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2143 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2144 GParamSpec *param_spec;
2146 oclass->constructor = do_constructor;
2147 oclass->dispose = do_dispose;
2148 oclass->constructed = do_constructed;
2149 oclass->set_property = do_set_property;
2150 oclass->get_property = do_get_property;
2152 param_spec = g_param_spec_object ("parent",
2153 "parent", "The parent window",
2155 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2156 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2158 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2162 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2164 EmpathyAccountsDialogPriv *priv;
2166 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2167 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2168 EmpathyAccountsDialogPriv);
2169 dialog->priv = priv;
2172 /* public methods */
2175 empathy_accounts_dialog_show (GtkWindow *parent,
2176 TpAccount *selected_account)
2178 EmpathyAccountsDialog *dialog;
2179 EmpathyAccountsDialogPriv *priv;
2181 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2182 "parent", parent, NULL);
2184 priv = GET_PRIV (dialog);
2186 if (selected_account)
2188 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2189 accounts_dialog_set_selected_account (dialog, selected_account);
2191 /* save the selection to set it later when the cms
2194 priv->initial_selection = g_object_ref (selected_account);
2197 gtk_window_present (GTK_WINDOW (dialog));
2199 return GTK_WIDGET (dialog);