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 *name, *display_name;
534 TpConnectionManager *cm;
535 TpConnectionManagerProtocol *proto;
536 gboolean is_gtalk, is_facebook;
538 cm = empathy_protocol_chooser_dup_selected (
539 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk,
546 else if (is_facebook)
551 display_name = empathy_protocol_name_to_display_name (name);
552 if (display_name == NULL)
553 display_name = proto->name;
556 /* To translator: %s is the name of the protocol, such as "Google Talk" or
559 str = g_strdup_printf (_("New %s account"), display_name);
560 settings = empathy_account_settings_new (cm->name, proto->name, str);
565 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
567 else if (is_facebook)
568 empathy_account_settings_set_icon_name_async (settings, "im-facebook",
571 accounts_dialog_add (dialog, settings);
572 accounts_dialog_model_set_selected (dialog, settings);
574 gtk_widget_show_all (priv->hbox_protocol);
576 g_object_unref (settings);
581 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
582 EmpathyAccountsDialog *dialog)
584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
585 GtkTreeSelection *selection;
589 EmpathyAccountSettings *settings;
590 gchar *account = NULL, *password = NULL;
592 /* The "changed" signal is fired during the initiation of the
593 * EmpathyProtocolChooser while populating the widget. Such signals should
594 * be ignored so we check if we are actually creating a new account. */
595 if (priv->setting_widget_object == NULL)
598 g_object_get (priv->setting_widget_object,
599 "creating-account", &creating, NULL);
603 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
605 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
608 /* Save "account" and "password" parameters */
609 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
611 if (settings != NULL)
613 account = g_strdup (empathy_account_settings_get_string (settings,
615 password = g_strdup (empathy_account_settings_get_string (settings,
617 g_object_unref (settings);
620 /* We are creating a new widget to replace the current one, don't ask
621 * confirmation to the user. */
622 priv->force_change_row = TRUE;
623 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
625 accounts_dialog_setup_ui_to_add_account (dialog);
627 /* Restore "account" and "password" parameters in the new widget */
630 empathy_account_widget_set_account_param (priv->setting_widget_object,
635 if (password != NULL)
637 empathy_account_widget_set_password_param (priv->setting_widget_object,
644 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
645 const gchar *primary_text,
646 const gchar *secondary_text,
647 GCallback response_callback,
649 const gchar *first_button_text,
653 GtkWidget *message_dialog;
654 const gchar *button_text;
656 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
657 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
658 GTK_MESSAGE_QUESTION,
662 gtk_message_dialog_format_secondary_text (
663 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
665 va_start (button_args, first_button_text);
666 for (button_text = first_button_text;
668 button_text = va_arg (button_args, const gchar *))
671 response_id = va_arg (button_args, gint);
673 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
676 va_end (button_args);
678 g_signal_connect (message_dialog, "response", response_callback, user_data);
680 gtk_widget_show (message_dialog);
684 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
688 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
689 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
691 gtk_widget_destroy (GTK_WIDGET (message_dialog));
693 if (response_id == GTK_RESPONSE_YES)
695 empathy_account_widget_discard_pending_changes (
696 priv->setting_widget_object);
697 accounts_dialog_setup_ui_to_add_account (dialog);
702 get_dialog_primary_text (TpAccount *account)
706 /* Existing account */
707 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
708 tp_account_get_display_name (account));
712 /* Newly created account */
713 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
718 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
719 EmpathyAccountsDialog *dialog)
721 TpAccount *account = NULL;
722 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
724 if (accounts_dialog_has_pending_change (dialog, &account))
726 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
728 accounts_dialog_show_question_dialog (dialog,
729 question_dialog_primary_text,
730 _("You are about to create a new account, which will discard\n"
731 "your changes. Are you sure you want to proceed?"),
732 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
734 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
735 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
737 g_free (question_dialog_primary_text);
741 accounts_dialog_setup_ui_to_add_account (dialog);
742 gtk_widget_set_sensitive (priv->treeview, FALSE);
743 gtk_widget_set_sensitive (priv->button_add, FALSE);
744 gtk_widget_set_sensitive (priv->button_remove, FALSE);
745 gtk_widget_set_sensitive (priv->button_import, FALSE);
749 g_object_unref (account);
753 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
754 EmpathyAccountSettings *settings)
756 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
758 if (priv->settings_ready != NULL)
760 g_signal_handler_disconnect (priv->settings_ready,
761 priv->settings_ready_id);
762 priv->settings_ready = NULL;
763 priv->settings_ready_id = 0;
770 GtkTreeSelection *selection;
772 view = GTK_TREE_VIEW (priv->treeview);
773 model = gtk_tree_view_get_model (view);
774 selection = gtk_tree_view_get_selection (view);
776 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
778 /* We have configured accounts, select the first one if there
779 * is no other account selected already. */
780 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
781 accounts_dialog_model_select_first (dialog);
785 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
787 /* We have no account configured but we have some
788 * profiles installed. The user obviously wants to add
789 * an account. Click on the Add button for him. */
790 accounts_dialog_button_add_clicked_cb (priv->button_add,
795 /* No account and no profile, warn the user */
796 gtk_widget_hide (priv->vbox_details);
797 gtk_widget_show (priv->frame_no_protocol);
798 gtk_widget_set_sensitive (priv->button_add, FALSE);
802 /* We have an account selected, destroy old settings and create a new
803 * one for the account selected */
804 gtk_widget_hide (priv->frame_no_protocol);
805 gtk_widget_show (priv->vbox_details);
806 gtk_widget_hide (priv->hbox_protocol);
808 if (priv->settings_widget)
810 gtk_widget_destroy (priv->settings_widget);
811 priv->settings_widget = NULL;
814 if (empathy_account_settings_is_ready (settings))
816 account_dialog_create_settings_widget (dialog, settings);
820 priv->settings_ready = settings;
821 priv->settings_ready_id =
822 g_signal_connect (settings, "notify::ready",
823 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
829 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
830 GtkCellEditable *editable,
832 EmpathyAccountsDialog *dialog)
834 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
836 if (priv->connecting_id)
837 g_source_remove (priv->connecting_id);
839 DEBUG ("Editing account name started; stopping flashing");
843 get_status_icon_for_account (EmpathyAccountsDialog *self,
846 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
847 TpConnectionStatus status;
848 TpConnectionStatusReason reason;
849 TpConnectionPresenceType presence;
852 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
854 if (!tp_account_is_enabled (account))
855 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
857 status = tp_account_get_connection_status (account, &reason);
859 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
861 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
862 /* An error occured */
863 return GTK_STOCK_DIALOG_ERROR;
865 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
867 else if (status == TP_CONNECTION_STATUS_CONNECTING)
869 /* Account is connecting. Display a blinking account alternating between
870 * the offline icon and the requested presence. */
871 if (priv->connecting_show)
872 presence = tp_account_get_requested_presence (account, NULL, NULL);
874 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
878 /* status == TP_CONNECTION_STATUS_CONNECTED */
879 presence = tp_account_get_current_presence (account, NULL, NULL);
881 /* If presence is Unset (CM doesn't implement SimplePresence),
882 * display the 'available' icon.
883 * We also check Offline because of this MC5 bug: fd.o #26060 */
884 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
885 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
886 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
889 return empathy_icon_name_for_presence (presence);
893 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
894 GtkCellRenderer *cell,
897 EmpathyAccountsDialog *dialog)
901 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
904 "icon-name", get_status_icon_for_account (dialog, account),
908 g_object_unref (account);
912 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
913 GtkCellRenderer *cell,
916 EmpathyAccountsDialog *dialog)
918 EmpathyAccountSettings *settings;
921 TpConnectionStatus status;
923 gtk_tree_model_get (model, iter,
925 COL_ACCOUNT_SETTINGS, &settings,
928 icon_name = empathy_account_settings_get_icon_name (settings);
929 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
936 g_object_unref (settings);
939 g_object_unref (pixbuf);
943 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
948 gtk_tree_model_row_changed (model, path, iter);
954 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
958 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
960 priv->connecting_show = !priv->connecting_show;
962 view = GTK_TREE_VIEW (priv->treeview);
963 model = gtk_tree_view_get_model (view);
965 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
971 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
974 EmpathyAccountsDialog *dialog)
976 EmpathyAccountSettings *settings;
978 GtkTreePath *treepath;
980 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
983 empathy_account_manager_get_accounts_connected (&connecting);
987 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
988 (GSourceFunc) accounts_dialog_flash_connecting_cb,
992 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
993 treepath = gtk_tree_path_new_from_string (path);
994 gtk_tree_model_get_iter (model, &iter, treepath);
995 gtk_tree_model_get (model, &iter,
996 COL_ACCOUNT_SETTINGS, &settings,
998 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1001 gtk_tree_path_free (treepath);
1003 empathy_account_settings_set_display_name_async (settings, new_text,
1005 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1006 g_object_unref (settings);
1010 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1015 GtkTreeModel *model;
1017 GtkTreeSelection *selection;
1018 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1019 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1021 if (response_id == GTK_RESPONSE_YES)
1023 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1025 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1028 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1030 if (account != NULL)
1032 tp_account_remove_async (account, NULL, NULL);
1033 g_object_unref (account);
1037 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1038 accounts_dialog_model_select_first (account_dialog);
1041 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1045 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1048 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1050 GtkTreeModel *model;
1051 gchar *question_dialog_primary_text;
1053 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1055 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1057 if (account == NULL || !tp_account_is_valid (account))
1059 if (account != NULL)
1060 g_object_unref (account);
1061 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1062 accounts_dialog_model_select_first (dialog);
1066 question_dialog_primary_text = g_strdup_printf (
1067 _("Do you want to remove %s from your computer?"),
1068 tp_account_get_display_name (account));
1070 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1071 _("This will not remove your account on the server."),
1072 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1074 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1075 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1077 g_free (question_dialog_primary_text);
1078 g_object_unref (account);
1082 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1083 EmpathyAccountsDialog *dialog)
1085 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1087 GtkTreeModel *model;
1088 GtkTreeSelection *selection;
1091 view = GTK_TREE_VIEW (priv->treeview);
1092 model = gtk_tree_view_get_model (view);
1093 selection = gtk_tree_view_get_selection (view);
1094 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1097 accounts_dialog_remove_account_iter (dialog, &iter);
1102 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1103 const gchar *path_string,
1104 EmpathyAccountsDialog *dialog)
1106 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1107 GtkTreeModel *model;
1110 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1111 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1114 accounts_dialog_remove_account_iter (dialog, &iter);
1119 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1122 GtkTreeViewColumn *column;
1123 GtkCellRenderer *cell;
1124 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1126 view = GTK_TREE_VIEW (priv->treeview);
1127 gtk_tree_view_set_headers_visible (view, FALSE);
1129 /* Account column */
1130 column = gtk_tree_view_column_new ();
1131 gtk_tree_view_column_set_expand (column, TRUE);
1132 gtk_tree_view_append_column (view, column);
1134 /* Status 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_status_pixbuf_data_func,
1143 /* Protocol icon renderer */
1144 cell = gtk_cell_renderer_pixbuf_new ();
1145 gtk_tree_view_column_pack_start (column, cell, FALSE);
1146 gtk_tree_view_column_set_cell_data_func (column, cell,
1147 (GtkTreeCellDataFunc)
1148 accounts_dialog_model_protocol_pixbuf_data_func,
1153 cell = gtk_cell_renderer_text_new ();
1155 "ellipsize", PANGO_ELLIPSIZE_END,
1159 gtk_tree_view_column_pack_start (column, cell, TRUE);
1160 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1161 g_signal_connect (cell, "edited",
1162 G_CALLBACK (accounts_dialog_name_edited_cb),
1164 g_signal_connect (cell, "editing-started",
1165 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1167 g_object_set (cell, "ypad", 4, NULL);
1171 cell = empathy_cell_renderer_activatable_new ();
1172 gtk_tree_view_column_pack_start (column, cell, FALSE);
1174 "icon-name", GTK_STOCK_DELETE,
1175 "show-on-select", TRUE,
1178 g_signal_connect (cell, "path-activated",
1179 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1184 static EmpathyAccountSettings *
1185 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1188 GtkTreeModel *model;
1189 GtkTreeSelection *selection;
1191 EmpathyAccountSettings *settings;
1192 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1194 view = GTK_TREE_VIEW (priv->treeview);
1195 selection = gtk_tree_view_get_selection (view);
1197 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1200 gtk_tree_model_get (model, &iter,
1201 COL_ACCOUNT_SETTINGS, &settings, -1);
1207 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1208 EmpathyAccountsDialog *dialog)
1210 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1211 EmpathyAccountSettings *settings;
1212 GtkTreeModel *model;
1214 gboolean is_selection;
1216 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1218 settings = accounts_dialog_model_get_selected_settings (dialog);
1219 accounts_dialog_update_settings (dialog, settings);
1221 if (settings != NULL)
1222 g_object_unref (settings);
1224 /* Update remove button sensitivity */
1225 gtk_widget_set_sensitive (priv->button_remove, is_selection);
1229 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1231 gpointer *user_data)
1233 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1234 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1236 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1238 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1240 /* The user wants to lose unsaved changes to the currently selected
1241 * account and select another account. We discard the changes and
1242 * select the other account. */
1244 GtkTreeSelection *selection;
1246 priv->force_change_row = TRUE;
1247 empathy_account_widget_discard_pending_changes (
1248 priv->setting_widget_object);
1250 path = gtk_tree_row_reference_get_path (priv->destination_row);
1251 selection = gtk_tree_view_get_selection (
1252 GTK_TREE_VIEW (priv->treeview));
1256 /* This will trigger a call to
1257 * accounts_dialog_account_selection_change() */
1258 gtk_tree_selection_select_path (selection, path);
1259 gtk_tree_path_free (path);
1262 gtk_tree_row_reference_free (priv->destination_row);
1266 priv->force_change_row = FALSE;
1271 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1272 GtkTreeModel *model,
1274 gboolean path_currently_selected,
1277 TpAccount *account = NULL;
1278 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1279 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1282 if (priv->force_change_row)
1284 /* We came back here because the user wants to discard changes to his
1285 * modified account. The changes have already been discarded so we
1286 * just change the selected row. */
1287 priv->force_change_row = FALSE;
1291 if (accounts_dialog_has_pending_change (dialog, &account))
1293 /* The currently selected account has some unsaved changes. We ask
1294 * the user if he really wants to lose his changes and select another
1296 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1297 priv->destination_row = gtk_tree_row_reference_new (model, path);
1299 accounts_dialog_show_question_dialog (dialog,
1300 question_dialog_primary_text,
1301 _("You are about to select another account, which will discard\n"
1302 "your changes. Are you sure you want to proceed?"),
1303 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1305 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1306 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1308 g_free (question_dialog_primary_text);
1316 if (account != NULL)
1317 g_object_unref (account);
1323 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1325 GtkListStore *store;
1326 GtkTreeSelection *selection;
1327 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1329 store = gtk_list_store_new (COL_COUNT,
1330 G_TYPE_STRING, /* name */
1331 G_TYPE_UINT, /* status */
1332 TP_TYPE_ACCOUNT, /* account */
1333 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1335 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1336 GTK_TREE_MODEL (store));
1338 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1339 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1340 gtk_tree_selection_set_select_function (selection,
1341 accounts_dialog_account_selection_change, dialog, NULL);
1343 g_signal_connect (selection, "changed",
1344 G_CALLBACK (accounts_dialog_model_selection_changed),
1347 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1348 COL_NAME, GTK_SORT_ASCENDING);
1350 accounts_dialog_model_add_columns (dialog);
1352 g_object_unref (store);
1356 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1357 EmpathyAccountSettings *settings,
1361 GtkTreeSelection *selection;
1362 GtkTreeModel *model;
1364 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1366 /* Update the status in the model */
1367 view = GTK_TREE_VIEW (priv->treeview);
1368 selection = gtk_tree_view_get_selection (view);
1369 model = gtk_tree_view_get_model (view);
1371 for (ok = gtk_tree_model_get_iter_first (model, iter);
1373 ok = gtk_tree_model_iter_next (model, iter))
1375 EmpathyAccountSettings *this_settings;
1378 gtk_tree_model_get (model, iter,
1379 COL_ACCOUNT_SETTINGS, &this_settings,
1382 equal = (this_settings == settings);
1383 g_object_unref (this_settings);
1393 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1398 GtkTreeSelection *selection;
1399 GtkTreeModel *model;
1401 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1403 /* Update the status in the model */
1404 view = GTK_TREE_VIEW (priv->treeview);
1405 selection = gtk_tree_view_get_selection (view);
1406 model = gtk_tree_view_get_model (view);
1408 for (ok = gtk_tree_model_get_iter_first (model, iter);
1410 ok = gtk_tree_model_iter_next (model, iter))
1412 EmpathyAccountSettings *settings;
1415 gtk_tree_model_get (model, iter,
1416 COL_ACCOUNT_SETTINGS, &settings,
1419 equal = empathy_account_settings_has_account (settings, account);
1420 g_object_unref (settings);
1430 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1431 EmpathyAccountSettings *settings)
1433 GtkTreeSelection *selection;
1435 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1437 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1438 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1439 gtk_tree_selection_select_iter (selection, &iter);
1442 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1443 EmpathyAccountSettings *settings)
1445 GtkTreeModel *model;
1448 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1450 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1451 name = empathy_account_settings_get_display_name (settings);
1453 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1455 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1457 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1458 COL_ACCOUNT_SETTINGS, settings,
1463 accounts_dialog_connection_changed_cb (TpAccount *account,
1467 gchar *dbus_error_name,
1468 GHashTable *details,
1469 EmpathyAccountsDialog *dialog)
1471 GtkTreeModel *model;
1474 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1476 /* Update the status-infobar in the details view */
1477 accounts_dialog_update_status_infobar (dialog, account);
1479 /* Update the status in the model */
1480 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1482 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1486 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1487 COL_STATUS, current,
1490 path = gtk_tree_model_get_path (model, &iter);
1491 gtk_tree_model_row_changed (model, path, &iter);
1492 gtk_tree_path_free (path);
1495 empathy_account_manager_get_accounts_connected (&found);
1497 if (!found && priv->connecting_id)
1499 g_source_remove (priv->connecting_id);
1500 priv->connecting_id = 0;
1503 if (found && !priv->connecting_id)
1504 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1505 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1510 update_account_in_treeview (EmpathyAccountsDialog *self,
1513 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1515 GtkTreeModel *model;
1517 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1518 if (accounts_dialog_get_account_iter (self, account, &iter))
1522 path = gtk_tree_model_get_path (model, &iter);
1523 gtk_tree_model_row_changed (model, path, &iter);
1524 gtk_tree_path_free (path);
1529 accounts_dialog_presence_changed_cb (TpAccount *account,
1532 gchar *status_message,
1533 EmpathyAccountsDialog *dialog)
1535 /* Update the status-infobar in the details view */
1536 accounts_dialog_update_status_infobar (dialog, account);
1538 update_account_in_treeview (dialog, account);
1542 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1546 const gchar *display_name;
1548 GtkTreeModel *model;
1549 EmpathyAccountSettings *settings;
1550 TpAccount *selected_account;
1551 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1552 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1554 display_name = tp_account_get_display_name (account);
1555 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1556 settings = accounts_dialog_model_get_selected_settings (dialog);
1557 if (settings == NULL)
1560 selected_account = empathy_account_settings_get_account (settings);
1562 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1564 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1565 COL_NAME, display_name,
1569 if (selected_account == account)
1570 accounts_dialog_update_name_label (dialog, display_name);
1572 g_object_unref (settings);
1576 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1579 EmpathyAccountSettings *settings;
1580 GtkTreeModel *model;
1582 TpConnectionStatus status;
1585 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1587 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1588 status = tp_account_get_connection_status (account, NULL);
1589 name = tp_account_get_display_name (account);
1590 enabled = tp_account_is_enabled (account);
1592 settings = empathy_account_settings_new_for_account (account);
1594 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1595 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1597 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1600 COL_ACCOUNT, account,
1601 COL_ACCOUNT_SETTINGS, settings,
1604 accounts_dialog_connection_changed_cb (account,
1607 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1612 empathy_signal_connect_weak (account, "notify::display-name",
1613 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1616 g_object_unref (settings);
1620 account_prepare_cb (GObject *source_object,
1621 GAsyncResult *result,
1624 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1625 TpAccount *account = TP_ACCOUNT (source_object);
1626 GError *error = NULL;
1628 if (!tp_account_prepare_finish (account, result, &error))
1630 DEBUG ("Failed to prepare account: %s", error->message);
1631 g_error_free (error);
1635 accounts_dialog_add_account (dialog, account);
1639 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1642 EmpathyAccountsDialog *dialog)
1644 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1648 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1650 EmpathyAccountsDialog *dialog)
1653 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1655 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1657 gtk_list_store_remove (GTK_LIST_STORE (
1658 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1663 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1667 GtkTreeModel *model;
1668 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1670 /* Update the status in the model */
1671 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1673 /* Update the status-infobar in the details view when disabling */
1675 accounts_dialog_update_status_infobar (dialog, account);
1677 DEBUG ("Account %s is now %s",
1678 tp_account_get_display_name (account),
1679 enabled ? "enabled" : "disabled");
1683 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1685 EmpathyAccountsDialog *dialog)
1687 enable_or_disable_account (dialog, account, FALSE);
1688 update_account_in_treeview (dialog, account);
1692 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1694 EmpathyAccountsDialog *dialog)
1696 enable_or_disable_account (dialog, account, TRUE);
1700 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1701 EmpathyAccountsDialog *dialog)
1703 GtkWidget *import_dialog;
1705 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1707 gtk_widget_show (import_dialog);
1711 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1715 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1717 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1719 if (response_id == GTK_RESPONSE_YES)
1720 gtk_widget_destroy (account_dialog);
1724 accounts_dialog_delete_event_cb (GtkWidget *widget,
1726 EmpathyAccountsDialog *dialog)
1728 /* we maunally handle responses to delete events */
1733 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1736 GtkTreeSelection *selection;
1738 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1740 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1741 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1742 gtk_tree_selection_select_iter (selection, &iter);
1746 accounts_dialog_cms_prepare_cb (GObject *source,
1747 GAsyncResult *result,
1750 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1751 EmpathyAccountsDialog *dialog = user_data;
1752 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1754 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1757 accounts_dialog_update_settings (dialog, NULL);
1759 if (priv->initial_selection != NULL)
1761 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1762 g_object_unref (priv->initial_selection);
1763 priv->initial_selection = NULL;
1768 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1770 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1771 GList *accounts, *l;
1773 g_signal_connect (priv->account_manager, "account-validity-changed",
1774 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1776 g_signal_connect (priv->account_manager, "account-removed",
1777 G_CALLBACK (accounts_dialog_account_removed_cb),
1779 g_signal_connect (priv->account_manager, "account-enabled",
1780 G_CALLBACK (accounts_dialog_account_enabled_cb),
1782 g_signal_connect (priv->account_manager, "account-disabled",
1783 G_CALLBACK (accounts_dialog_account_disabled_cb),
1786 /* Add existing accounts */
1787 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1788 for (l = accounts; l; l = l->next)
1790 accounts_dialog_add_account (dialog, l->data);
1792 empathy_signal_connect_weak (l->data, "status-changed",
1793 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1794 empathy_signal_connect_weak (l->data, "presence-changed",
1795 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1797 g_list_free (accounts);
1799 priv->cms = empathy_connection_managers_dup_singleton ();
1801 empathy_connection_managers_prepare_async (priv->cms,
1802 accounts_dialog_cms_prepare_cb, dialog);
1804 accounts_dialog_model_select_first (dialog);
1808 accounts_dialog_manager_ready_cb (GObject *source_object,
1809 GAsyncResult *result,
1812 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1813 GError *error = NULL;
1815 if (!tp_account_manager_prepare_finish (manager, result, &error))
1817 DEBUG ("Failed to prepare account manager: %s", error->message);
1818 g_error_free (error);
1822 accounts_dialog_accounts_setup (user_data);
1826 dialog_response_cb (GtkWidget *widget,
1830 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1832 if (response_id == GTK_RESPONSE_HELP)
1834 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1836 else if (response_id == GTK_RESPONSE_CLOSE ||
1837 response_id == GTK_RESPONSE_DELETE_EVENT)
1839 TpAccount *account = NULL;
1841 if (accounts_dialog_has_pending_change (dialog, &account))
1843 gchar *question_dialog_primary_text = get_dialog_primary_text (
1846 accounts_dialog_show_question_dialog (dialog,
1847 question_dialog_primary_text,
1848 _("You are about to close the window, which will discard\n"
1849 "your changes. Are you sure you want to proceed?"),
1850 G_CALLBACK (accounts_dialog_close_response_cb),
1852 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1853 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1855 g_free (question_dialog_primary_text);
1859 gtk_widget_destroy (widget);
1862 if (account != NULL)
1863 g_object_unref (account);
1868 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1870 GtkWidget *top_hbox;
1873 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1874 GtkWidget *content_area;
1875 GtkWidget *action_area, *vbox, *hbox, *align;
1877 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1879 gui = empathy_builder_get_file (filename,
1880 "accounts_dialog_hbox", &top_hbox,
1881 "vbox_details", &priv->vbox_details,
1882 "frame_no_protocol", &priv->frame_no_protocol,
1883 "alignment_settings", &priv->alignment_settings,
1884 "alignment_infobar", &priv->alignment_infobar,
1885 "treeview", &priv->treeview,
1886 "button_add", &priv->button_add,
1887 "button_remove", &priv->button_remove,
1888 "button_import", &priv->button_import,
1889 "hbox_protocol", &priv->hbox_protocol,
1893 empathy_builder_connect (gui, dialog,
1894 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1895 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
1896 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1899 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1901 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
1903 g_object_unref (gui);
1905 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
1908 gtk_widget_hide (action_area);
1909 gtk_widget_hide (priv->button_remove);
1912 /* Remove button is unsensitive until we have a selected account */
1913 gtk_widget_set_sensitive (priv->button_remove, FALSE);
1915 priv->combobox_protocol = empathy_protocol_chooser_new ();
1916 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
1918 g_signal_connect (priv->combobox_protocol, "changed",
1919 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1922 if (priv->parent_window)
1923 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1924 priv->parent_window);
1926 priv->infobar = gtk_info_bar_new ();
1927 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1929 gtk_widget_show (priv->infobar);
1931 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1933 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
1934 GTK_ICON_SIZE_DIALOG);
1935 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
1936 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
1937 gtk_widget_show (priv->image_type);
1939 vbox = gtk_vbox_new (FALSE, 6);
1940 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
1941 gtk_widget_show (vbox);
1944 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
1945 gtk_widget_show (align);
1947 priv->label_name = gtk_label_new (NULL);
1948 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
1949 gtk_widget_show (priv->label_name);
1951 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
1954 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
1955 gtk_widget_show (align);
1956 hbox = gtk_hbox_new (FALSE, 6);
1957 gtk_widget_show (hbox);
1958 gtk_container_add (GTK_CONTAINER (align), hbox);
1960 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
1962 /* set up spinner */
1963 priv->throbber = ephy_spinner_new ();
1964 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1966 priv->image_status = gtk_image_new_from_icon_name (
1967 empathy_icon_name_for_presence (
1968 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1970 priv->label_status = gtk_label_new (NULL);
1971 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
1972 gtk_widget_show (priv->label_status);
1974 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
1975 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
1976 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
1978 /* Tweak the dialog */
1979 gtk_window_set_title (GTK_WINDOW (dialog), _("Accounts"));
1980 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
1982 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, -1);
1984 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
1986 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
1988 /* add dialog buttons */
1989 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
1991 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1992 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1993 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1996 g_signal_connect (dialog, "response",
1997 G_CALLBACK (dialog_response_cb), dialog);
1999 g_signal_connect (dialog, "delete-event",
2000 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2004 do_dispose (GObject *obj)
2006 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2007 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2009 if (priv->dispose_has_run)
2012 priv->dispose_has_run = TRUE;
2014 /* Disconnect signals */
2015 g_signal_handlers_disconnect_by_func (priv->account_manager,
2016 accounts_dialog_account_validity_changed_cb,
2018 g_signal_handlers_disconnect_by_func (priv->account_manager,
2019 accounts_dialog_account_removed_cb,
2021 g_signal_handlers_disconnect_by_func (priv->account_manager,
2022 accounts_dialog_account_enabled_cb,
2024 g_signal_handlers_disconnect_by_func (priv->account_manager,
2025 accounts_dialog_account_disabled_cb,
2027 g_signal_handlers_disconnect_by_func (priv->account_manager,
2028 accounts_dialog_manager_ready_cb,
2031 if (priv->connecting_id)
2032 g_source_remove (priv->connecting_id);
2034 if (priv->account_manager != NULL)
2036 g_object_unref (priv->account_manager);
2037 priv->account_manager = NULL;
2040 if (priv->cms != NULL)
2042 g_object_unref (priv->cms);
2046 if (priv->initial_selection != NULL)
2047 g_object_unref (priv->initial_selection);
2048 priv->initial_selection = NULL;
2050 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2054 do_constructor (GType type,
2056 GObjectConstructParam *props)
2060 if (dialog_singleton)
2062 retval = G_OBJECT (dialog_singleton);
2067 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
2068 (type, n_props, props);
2070 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
2071 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
2078 do_get_property (GObject *object,
2083 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2085 switch (property_id)
2088 g_value_set_object (value, priv->parent_window);
2091 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2096 do_set_property (GObject *object,
2098 const GValue *value,
2101 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2103 switch (property_id)
2106 priv->parent_window = g_value_get_object (value);
2109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2114 do_constructed (GObject *object)
2116 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2117 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2118 gboolean import_asked;
2120 accounts_dialog_build_ui (dialog);
2121 accounts_dialog_model_setup (dialog);
2123 /* Set up signalling */
2124 priv->account_manager = tp_account_manager_dup ();
2126 tp_account_manager_prepare_async (priv->account_manager, NULL,
2127 accounts_dialog_manager_ready_cb, dialog);
2129 empathy_conf_get_bool (empathy_conf_get (),
2130 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
2132 if (empathy_import_accounts_to_import ())
2134 gtk_widget_show (priv->button_import);
2138 GtkWidget *import_dialog;
2140 empathy_conf_set_bool (empathy_conf_get (),
2141 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
2142 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
2144 gtk_widget_show (import_dialog);
2150 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2152 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2153 GParamSpec *param_spec;
2155 oclass->constructor = do_constructor;
2156 oclass->dispose = do_dispose;
2157 oclass->constructed = do_constructed;
2158 oclass->set_property = do_set_property;
2159 oclass->get_property = do_get_property;
2161 param_spec = g_param_spec_object ("parent",
2162 "parent", "The parent window",
2164 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2165 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2167 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2171 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2173 EmpathyAccountsDialogPriv *priv;
2175 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2176 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2177 EmpathyAccountsDialogPriv);
2178 dialog->priv = priv;
2181 /* public methods */
2184 empathy_accounts_dialog_show (GtkWindow *parent,
2185 TpAccount *selected_account)
2187 EmpathyAccountsDialog *dialog;
2188 EmpathyAccountsDialogPriv *priv;
2190 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2191 "parent", parent, NULL);
2193 priv = GET_PRIV (dialog);
2195 if (selected_account)
2197 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2198 accounts_dialog_set_selected_account (dialog, selected_account);
2200 /* save the selection to set it later when the cms
2203 priv->initial_selection = g_object_ref (selected_account);
2206 gtk_window_present (GTK_WINDOW (dialog));
2208 return GTK_WIDGET (dialog);