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-gtk/empathy-ui-utils.h>
42 #include <libempathy-gtk/empathy-protocol-chooser.h>
43 #include <libempathy-gtk/empathy-account-widget.h>
44 #include <libempathy-gtk/empathy-account-widget-irc.h>
45 #include <libempathy-gtk/empathy-account-widget-sip.h>
46 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
47 #include <libempathy-gtk/empathy-conf.h>
48 #include <libempathy-gtk/empathy-images.h>
50 #include "empathy-accounts-dialog.h"
51 #include "empathy-import-dialog.h"
52 #include "empathy-import-utils.h"
53 #include "ephy-spinner.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
56 #include <libempathy/empathy-debug.h>
58 /* Flashing delay for icons (milliseconds). */
59 #define FLASH_TIMEOUT 500
61 /* The primary text of the dialog shown to the user when he is about to lose
63 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
64 _("There are unsaved modification regarding your %s account.")
65 /* The primary text of the dialog shown to the user when he is about to lose
66 * an unsaved new account */
67 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
68 _("Your new account has not been saved yet.")
70 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
71 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
73 static EmpathyAccountsDialog *dialog_singleton = NULL;
78 GtkWidget *alignment_settings;
79 GtkWidget *alignment_infobar;
81 GtkWidget *vbox_details;
83 GtkWidget *label_status;
84 GtkWidget *image_status;
86 GtkWidget *frame_no_protocol;
90 GtkWidget *button_add;
91 GtkWidget *button_import;
93 GtkWidget *frame_new_account;
94 GtkWidget *combobox_protocol;
96 GtkWidget *button_create;
97 GtkWidget *button_back;
98 GtkWidget *radiobutton_reuse;
99 GtkWidget *radiobutton_register;
101 GtkWidget *image_type;
102 GtkWidget *label_name;
103 GtkWidget *label_type;
104 GtkWidget *settings_widget;
106 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
107 * his GtkWidget. It is the only reliable source we can query to know if
108 * there are any unsaved changes to the currently selected account. We can't
109 * look at the account settings because it does not contain everything that
110 * can be changed using the EmpathyAccountWidget. For instance, it does not
111 * contain the state of the "Enabled" checkbox. */
112 EmpathyAccountWidget *setting_widget_object;
114 gboolean connecting_show;
117 gulong settings_ready_id;
118 EmpathyAccountSettings *settings_ready;
120 TpAccountManager *account_manager;
121 EmpathyConnectionManagers *cms;
123 GtkWindow *parent_window;
124 TpAccount *initial_selection;
126 /* Those are needed when changing the selected row. When a user selects
127 * another account and there are unsaved changes on the currently selected
128 * one, a confirmation message box is presented to him. Since his answer
129 * is retrieved asynchronously, we keep some information as member of the
130 * EmpathyAccountsDialog object. */
131 gboolean force_change_row;
132 GtkTreeRowReference *destination_row;
135 } EmpathyAccountsDialogPriv;
141 COL_ACCOUNT_SETTINGS_POINTER,
149 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
150 EmpathyAccountsDialog *dialog);
152 static gboolean accounts_dialog_get_settings_iter (
153 EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings,
157 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
159 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
160 EmpathyAccountSettings *settings);
163 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
164 const gchar *display_name)
167 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
169 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
170 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
176 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
179 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
180 const gchar *message;
185 status = tp_account_get_connection_status (account, &reason);
186 presence = tp_account_get_current_presence (account, NULL, NULL);
188 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
189 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
191 if (tp_account_is_enabled (account))
195 case TP_CONNECTION_STATUS_CONNECTING:
196 message = _("Connecting...");
197 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
200 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
201 gtk_widget_show (priv->throbber);
202 gtk_widget_hide (priv->image_status);
204 case TP_CONNECTION_STATUS_CONNECTED:
205 message = g_strdup_printf (_("Connected with status %s"),
206 empathy_presence_get_default_message (presence));
208 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
211 gtk_widget_show (priv->image_status);
212 gtk_widget_hide (priv->throbber);
214 case TP_CONNECTION_STATUS_DISCONNECTED:
217 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
218 message = _("Disconnected - No error specified");
220 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
221 message = _("Disconnected - Network error");
223 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
224 message = _("Disconnected - Authentication failed");
226 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
227 message = _("Disconnected - Encryption error");
229 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
230 message = _("Disconnected - Name in use");
232 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
233 message = _("Disconnected - Certificate not provided");
235 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
236 message = _("Disconnected - Certificate untrusted");
238 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
239 message = _("Disconnected - Certificate expired");
241 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
242 message = _("Disconnected - Certificate not activated");
244 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
245 message = _("Disconnected - Certificate hostname mismatch");
247 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
248 message = _("Disconnected - Certificate fingerprint mismatch");
250 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
251 message = _("Disconnected - Certificate self-signed");
253 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
254 message = _("Disconnected - Certificate error");
257 message = _("Disconnected - Unknown reason");
261 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
264 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
265 gtk_widget_show (priv->image_status);
266 gtk_widget_hide (priv->throbber);
269 message = _("Unknown Status");
270 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
271 GTK_MESSAGE_WARNING);
273 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
274 gtk_widget_hide (priv->image_status);
275 gtk_widget_hide (priv->throbber);
280 message = _("Disconnected - Account disabled");
281 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
282 GTK_MESSAGE_WARNING);
283 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
284 gtk_widget_show (priv->image_status);
285 gtk_widget_hide (priv->throbber);
288 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
289 gtk_widget_show (priv->label_status);
290 gtk_widget_show (priv->infobar);
294 empathy_account_dialog_widget_cancelled_cb (
295 EmpathyAccountWidget *widget_object,
296 EmpathyAccountsDialog *dialog)
300 GtkTreeSelection *selection;
302 EmpathyAccountSettings *settings;
304 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
306 view = GTK_TREE_VIEW (priv->treeview);
307 selection = gtk_tree_view_get_selection (view);
309 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
312 gtk_tree_model_get (model, &iter,
313 COL_ACCOUNT_SETTINGS_POINTER, &settings,
314 COL_ACCOUNT_POINTER, &account, -1);
316 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
320 /* We were creating an account. We remove the selected row */
321 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
325 /* We were modifying an account. We discard the changes by reloading the
326 * settings and the UI. */
327 accounts_dialog_update_settings (dialog, settings);
328 g_object_unref (account);
331 if (settings != NULL)
332 g_object_unref (settings);
336 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
337 EmpathyAccountsDialog *dialog)
340 EmpathyAccountSettings *settings =
341 accounts_dialog_model_get_selected_settings (dialog);
343 display_name = empathy_account_widget_get_default_display_name (
346 empathy_account_settings_set_display_name_async (settings,
347 display_name, NULL, NULL);
349 g_free (display_name);
351 accounts_dialog_update_settings (dialog, settings);
354 g_object_unref (settings);
358 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
359 EmpathyAccountSettings *settings)
361 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
365 priv->setting_widget_object =
366 empathy_account_widget_new_for_protocol (settings, FALSE);
368 priv->settings_widget =
369 empathy_account_widget_get_widget (priv->setting_widget_object);
371 priv->settings_widget =
372 empathy_account_widget_get_widget (priv->setting_widget_object);
373 g_signal_connect (priv->setting_widget_object, "account-created",
374 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
375 g_signal_connect (priv->setting_widget_object, "cancelled",
376 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
378 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
379 priv->settings_widget);
380 gtk_widget_show (priv->settings_widget);
382 icon_name = empathy_account_settings_get_icon_name (settings);
384 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
386 /* show the default icon; keep this in sync with the default
387 * one in empathy-accounts-dialog.ui.
389 icon_name = GTK_STOCK_CUT;
391 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
392 icon_name, GTK_ICON_SIZE_DIALOG);
393 gtk_widget_set_tooltip_text (priv->image_type,
394 empathy_protocol_name_to_display_name
395 (empathy_account_settings_get_protocol (settings)));
396 gtk_widget_show (priv->image_type);
398 accounts_dialog_update_name_label (dialog,
399 empathy_account_settings_get_display_name (settings));
401 account = empathy_account_settings_get_account (settings);
402 accounts_dialog_update_status_infobar (dialog, account);
406 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
408 EmpathyAccountsDialog *dialog)
410 if (empathy_account_settings_is_ready (settings))
411 account_dialog_create_settings_widget (dialog, settings);
415 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
419 GtkTreeSelection *selection;
421 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
424 view = GTK_TREE_VIEW (priv->treeview);
425 model = gtk_tree_view_get_model (view);
427 if (gtk_tree_model_get_iter_first (model, &iter))
429 selection = gtk_tree_view_get_selection (view);
430 gtk_tree_selection_select_iter (selection, &iter);
434 accounts_dialog_update_settings (dialog, NULL);
439 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
444 GtkTreeSelection *selection;
445 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
447 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
449 if (gtk_tree_selection_get_selected (selection, &model, &iter))
450 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
452 return priv->setting_widget_object != NULL
453 && empathy_account_widget_contains_pending_changes (
454 priv->setting_widget_object);
458 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
459 EmpathyAccountsDialog *dialog)
461 TpConnectionManager *cm;
462 TpConnectionManagerProtocol *proto;
464 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
466 cm = empathy_protocol_chooser_dup_selected (
467 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
479 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
481 gtk_widget_show (priv->radiobutton_register);
482 gtk_widget_show (priv->radiobutton_reuse);
486 gtk_widget_hide (priv->radiobutton_register);
487 gtk_widget_hide (priv->radiobutton_reuse);
490 gtk_widget_hide (priv->radiobutton_register);
491 gtk_widget_hide (priv->radiobutton_reuse);
498 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
502 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
504 view = GTK_TREE_VIEW (priv->treeview);
505 model = gtk_tree_view_get_model (view);
507 gtk_widget_set_sensitive (priv->button_add, FALSE);
508 gtk_widget_hide (priv->vbox_details);
509 gtk_widget_hide (priv->frame_no_protocol);
510 gtk_widget_show (priv->frame_new_account);
512 /* If we have no account, no need of a back button */
513 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
514 gtk_widget_show (priv->button_back);
516 gtk_widget_hide (priv->button_back);
518 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
519 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
521 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
522 gtk_widget_grab_focus (priv->combobox_protocol);
526 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
527 const gchar *primary_text,
528 const gchar *secondary_text,
529 GCallback response_callback,
531 const gchar *first_button_text,
535 GtkWidget *message_dialog;
536 const gchar *button_text;
537 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
539 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
540 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
541 GTK_MESSAGE_QUESTION,
545 gtk_message_dialog_format_secondary_text (
546 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
548 va_start (button_args, first_button_text);
549 for (button_text = first_button_text;
551 button_text = va_arg (button_args, const gchar *))
554 response_id = va_arg (button_args, gint);
556 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
559 va_end (button_args);
561 g_signal_connect (message_dialog, "response", response_callback, user_data);
563 gtk_widget_show (message_dialog);
567 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
571 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
572 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
574 gtk_widget_destroy (GTK_WIDGET (message_dialog));
576 if (response_id == GTK_RESPONSE_YES)
578 empathy_account_widget_discard_pending_changes (
579 priv->setting_widget_object);
580 accounts_dialog_setup_ui_to_add_account (dialog);
585 get_dialog_primary_text (TpAccount *account)
589 /* Existing account */
590 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
591 tp_account_get_display_name (account));
595 /* Newly created account */
596 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
601 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
602 EmpathyAccountsDialog *dialog)
604 TpAccount *account = NULL;
606 if (accounts_dialog_has_pending_change (dialog, &account))
608 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
610 accounts_dialog_show_question_dialog (dialog,
611 question_dialog_primary_text,
612 _("You are about to create a new account, which will discard\n"
613 "your changes. Are you sure you want to proceed?"),
614 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
616 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
617 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
619 g_free (question_dialog_primary_text);
623 accounts_dialog_setup_ui_to_add_account (dialog);
628 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
629 EmpathyAccountSettings *settings)
631 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
633 if (priv->settings_ready != NULL)
635 g_signal_handler_disconnect (priv->settings_ready,
636 priv->settings_ready_id);
637 priv->settings_ready = NULL;
638 priv->settings_ready_id = 0;
645 GtkTreeSelection *selection;
647 view = GTK_TREE_VIEW (priv->treeview);
648 model = gtk_tree_view_get_model (view);
649 selection = gtk_tree_view_get_selection (view);
651 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
653 /* We have configured accounts, select the first one if there
654 * is no other account selected already. */
655 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
656 accounts_dialog_model_select_first (dialog);
660 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
662 /* We have no account configured but we have some
663 * profiles installed. The user obviously wants to add
664 * an account. Click on the Add button for him. */
665 accounts_dialog_button_add_clicked_cb (priv->button_add,
670 /* No account and no profile, warn the user */
671 gtk_widget_hide (priv->vbox_details);
672 gtk_widget_hide (priv->frame_new_account);
673 gtk_widget_show (priv->frame_no_protocol);
674 gtk_widget_set_sensitive (priv->button_add, FALSE);
678 /* We have an account selected, destroy old settings and create a new
679 * one for the account selected */
680 gtk_widget_hide (priv->frame_new_account);
681 gtk_widget_hide (priv->frame_no_protocol);
682 gtk_widget_show (priv->vbox_details);
683 gtk_widget_set_sensitive (priv->button_add, TRUE);
685 if (priv->settings_widget)
687 gtk_widget_destroy (priv->settings_widget);
688 priv->settings_widget = NULL;
691 if (empathy_account_settings_is_ready (settings))
693 account_dialog_create_settings_widget (dialog, settings);
697 priv->settings_ready = settings;
698 priv->settings_ready_id =
699 g_signal_connect (settings, "notify::ready",
700 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
706 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
707 GtkCellEditable *editable,
709 EmpathyAccountsDialog *dialog)
711 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
713 if (priv->connecting_id)
714 g_source_remove (priv->connecting_id);
716 DEBUG ("Editing account name started; stopping flashing");
720 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
721 GtkCellRenderer *cell,
724 EmpathyAccountsDialog *dialog)
726 EmpathyAccountSettings *settings;
729 TpConnectionStatus status;
730 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
732 gtk_tree_model_get (model, iter,
734 COL_ACCOUNT_SETTINGS_POINTER, &settings,
737 icon_name = empathy_account_settings_get_icon_name (settings);
738 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
742 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
743 (status == TP_CONNECTION_STATUS_CONNECTING &&
744 !priv->connecting_show))
746 GdkPixbuf *modded_pixbuf;
748 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
751 gdk_pixbuf_get_width (pixbuf),
752 gdk_pixbuf_get_height (pixbuf));
754 gdk_pixbuf_saturate_and_pixelate (pixbuf,
758 g_object_unref (pixbuf);
759 pixbuf = modded_pixbuf;
768 g_object_unref (settings);
771 g_object_unref (pixbuf);
775 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
780 gtk_tree_model_row_changed (model, path, iter);
786 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
790 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
792 priv->connecting_show = !priv->connecting_show;
794 view = GTK_TREE_VIEW (priv->treeview);
795 model = gtk_tree_view_get_model (view);
797 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
803 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
806 EmpathyAccountsDialog *dialog)
808 EmpathyAccountSettings *settings;
810 GtkTreePath *treepath;
812 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
815 empathy_account_manager_get_accounts_connected (&connecting);
819 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
820 (GSourceFunc) accounts_dialog_flash_connecting_cb,
824 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
825 treepath = gtk_tree_path_new_from_string (path);
826 gtk_tree_model_get_iter (model, &iter, treepath);
827 gtk_tree_model_get (model, &iter,
828 COL_ACCOUNT_SETTINGS_POINTER, &settings,
830 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
833 gtk_tree_path_free (treepath);
835 empathy_account_settings_set_display_name_async (settings, new_text,
837 g_object_set (settings, "display-name-overridden", TRUE, NULL);
838 g_object_unref (settings);
842 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
849 GtkTreeSelection *selection;
850 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
851 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
853 if (response_id == GTK_RESPONSE_YES)
855 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
857 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
860 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
864 tp_account_remove_async (account, NULL, NULL);
865 g_object_unref (account);
869 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
870 accounts_dialog_model_select_first (account_dialog);
873 gtk_widget_destroy (GTK_WIDGET (message_dialog));
877 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
878 const gchar *path_string,
879 EmpathyAccountsDialog *dialog)
884 gchar *question_dialog_primary_text;
885 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
887 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
889 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
892 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
894 if (account == NULL || !tp_account_is_valid (account))
896 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
897 accounts_dialog_model_select_first (dialog);
901 question_dialog_primary_text = g_strdup_printf (
902 _("Do you want to remove %s from your computer?"),
903 tp_account_get_display_name (account));
905 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
906 _("This will not remove your account on the server."),
907 G_CALLBACK (accounts_dialog_delete_account_response_cb),
909 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
910 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
912 g_free (question_dialog_primary_text);
916 g_object_unref (account);
922 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
925 GtkTreeViewColumn *column;
926 GtkCellRenderer *cell;
927 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
929 view = GTK_TREE_VIEW (priv->treeview);
930 gtk_tree_view_set_headers_visible (view, FALSE);
933 column = gtk_tree_view_column_new ();
934 gtk_tree_view_column_set_expand (column, TRUE);
935 gtk_tree_view_append_column (view, column);
938 cell = gtk_cell_renderer_pixbuf_new ();
939 gtk_tree_view_column_pack_start (column, cell, FALSE);
940 gtk_tree_view_column_set_cell_data_func (column, cell,
941 (GtkTreeCellDataFunc)
942 accounts_dialog_model_pixbuf_data_func,
947 cell = gtk_cell_renderer_text_new ();
949 "ellipsize", PANGO_ELLIPSIZE_END,
953 gtk_tree_view_column_pack_start (column, cell, TRUE);
954 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
955 g_signal_connect (cell, "edited",
956 G_CALLBACK (accounts_dialog_name_edited_cb),
958 g_signal_connect (cell, "editing-started",
959 G_CALLBACK (accounts_dialog_name_editing_started_cb),
961 g_object_set (cell, "ypad", 4, NULL);
964 cell = empathy_cell_renderer_activatable_new ();
965 gtk_tree_view_column_pack_start (column, cell, FALSE);
967 "icon-name", GTK_STOCK_DELETE,
968 "show-on-select", TRUE,
971 g_signal_connect (cell, "path-activated",
972 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
976 static EmpathyAccountSettings *
977 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
981 GtkTreeSelection *selection;
983 EmpathyAccountSettings *settings;
984 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
986 view = GTK_TREE_VIEW (priv->treeview);
987 selection = gtk_tree_view_get_selection (view);
989 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
992 gtk_tree_model_get (model, &iter,
993 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
999 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1000 EmpathyAccountsDialog *dialog)
1002 EmpathyAccountSettings *settings;
1003 GtkTreeModel *model;
1005 gboolean is_selection;
1007 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1009 settings = accounts_dialog_model_get_selected_settings (dialog);
1010 accounts_dialog_update_settings (dialog, settings);
1012 if (settings != NULL)
1013 g_object_unref (settings);
1017 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1019 gpointer *user_data)
1021 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1022 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1024 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1026 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1028 /* The user wants to lose unsaved changes to the currently selected
1029 * account and select another account. We discard the changes and
1030 * select the other account. */
1032 GtkTreeSelection *selection;
1034 priv->force_change_row = TRUE;
1035 empathy_account_widget_discard_pending_changes (
1036 priv->setting_widget_object);
1038 path = gtk_tree_row_reference_get_path (priv->destination_row);
1039 selection = gtk_tree_view_get_selection (
1040 GTK_TREE_VIEW (priv->treeview));
1044 /* This will trigger a call to
1045 * accounts_dialog_account_selection_change() */
1046 gtk_tree_selection_select_path (selection, path);
1047 gtk_tree_path_free (path);
1050 gtk_tree_row_reference_free (priv->destination_row);
1054 priv->force_change_row = FALSE;
1059 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1060 GtkTreeModel *model,
1062 gboolean path_currently_selected,
1065 TpAccount *account = NULL;
1066 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1067 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1069 if (priv->force_change_row)
1071 /* We came back here because the user wants to discard changes to his
1072 * modified account. The changes have already been discarded so we
1073 * just change the selected row. */
1074 priv->force_change_row = FALSE;
1078 if (accounts_dialog_has_pending_change (dialog, &account))
1080 /* The currently selected account has some unsaved changes. We ask
1081 * the user if he really wants to lose his changes and select another
1083 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1084 priv->destination_row = gtk_tree_row_reference_new (model, path);
1086 accounts_dialog_show_question_dialog (dialog,
1087 question_dialog_primary_text,
1088 _("You are about to select another account, which will discard\n"
1089 "your changes. Are you sure you want to proceed?"),
1090 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1092 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1093 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1095 g_free (question_dialog_primary_text);
1106 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1108 GtkListStore *store;
1109 GtkTreeSelection *selection;
1110 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1112 store = gtk_list_store_new (COL_COUNT,
1113 G_TYPE_STRING, /* name */
1114 G_TYPE_UINT, /* status */
1115 TP_TYPE_ACCOUNT, /* account */
1116 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1118 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1119 GTK_TREE_MODEL (store));
1121 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1122 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1123 gtk_tree_selection_set_select_function (selection,
1124 accounts_dialog_account_selection_change, dialog, NULL);
1126 g_signal_connect (selection, "changed",
1127 G_CALLBACK (accounts_dialog_model_selection_changed),
1130 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1131 COL_NAME, GTK_SORT_ASCENDING);
1133 accounts_dialog_model_add_columns (dialog);
1135 g_object_unref (store);
1139 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1140 EmpathyAccountSettings *settings,
1144 GtkTreeSelection *selection;
1145 GtkTreeModel *model;
1147 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1149 /* Update the status in the model */
1150 view = GTK_TREE_VIEW (priv->treeview);
1151 selection = gtk_tree_view_get_selection (view);
1152 model = gtk_tree_view_get_model (view);
1154 for (ok = gtk_tree_model_get_iter_first (model, iter);
1156 ok = gtk_tree_model_iter_next (model, iter))
1158 EmpathyAccountSettings *this_settings;
1161 gtk_tree_model_get (model, iter,
1162 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1165 equal = (this_settings == settings);
1166 g_object_unref (this_settings);
1176 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1181 GtkTreeSelection *selection;
1182 GtkTreeModel *model;
1184 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1186 /* Update the status in the model */
1187 view = GTK_TREE_VIEW (priv->treeview);
1188 selection = gtk_tree_view_get_selection (view);
1189 model = gtk_tree_view_get_model (view);
1191 for (ok = gtk_tree_model_get_iter_first (model, iter);
1193 ok = gtk_tree_model_iter_next (model, iter))
1195 EmpathyAccountSettings *settings;
1198 gtk_tree_model_get (model, iter,
1199 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1202 equal = empathy_account_settings_has_account (settings, account);
1203 g_object_unref (settings);
1213 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1214 EmpathyAccountSettings *settings)
1216 GtkTreeSelection *selection;
1218 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1220 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1221 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1222 gtk_tree_selection_select_iter (selection, &iter);
1225 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1226 EmpathyAccountSettings *settings)
1228 GtkTreeModel *model;
1231 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1233 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1234 name = empathy_account_settings_get_display_name (settings);
1236 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1238 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1240 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1241 COL_ACCOUNT_SETTINGS_POINTER, settings,
1246 accounts_dialog_connection_changed_cb (TpAccount *account,
1250 gchar *dbus_error_name,
1251 GHashTable *details,
1252 EmpathyAccountsDialog *dialog)
1254 GtkTreeModel *model;
1257 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1259 /* Update the status-infobar in the details view*/
1260 accounts_dialog_update_status_infobar (dialog, account);
1262 /* Update the status in the model */
1263 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1265 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1269 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1270 COL_STATUS, current,
1273 path = gtk_tree_model_get_path (model, &iter);
1274 gtk_tree_model_row_changed (model, path, &iter);
1275 gtk_tree_path_free (path);
1278 empathy_account_manager_get_accounts_connected (&found);
1280 if (!found && priv->connecting_id)
1282 g_source_remove (priv->connecting_id);
1283 priv->connecting_id = 0;
1286 if (found && !priv->connecting_id)
1287 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1288 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1293 accounts_dialog_presence_changed_cb (TpAccount *account,
1296 gchar *status_message,
1297 EmpathyAccountsDialog *dialog)
1299 /* Update the status-infobar in the details view*/
1300 accounts_dialog_update_status_infobar (dialog, account);
1304 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1308 const gchar *display_name;
1310 GtkTreeModel *model;
1311 EmpathyAccountSettings *settings;
1312 TpAccount *selected_account;
1313 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1314 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1316 display_name = tp_account_get_display_name (account);
1317 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1318 settings = accounts_dialog_model_get_selected_settings (dialog);
1319 if (settings == NULL)
1322 selected_account = empathy_account_settings_get_account (settings);
1324 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1326 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1327 COL_NAME, display_name,
1331 if (selected_account == account)
1332 accounts_dialog_update_name_label (dialog, display_name);
1334 g_object_unref (settings);
1338 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1341 EmpathyAccountSettings *settings;
1342 GtkTreeModel *model;
1344 TpConnectionStatus status;
1347 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1349 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1350 status = tp_account_get_connection_status (account, NULL);
1351 name = tp_account_get_display_name (account);
1352 enabled = tp_account_is_enabled (account);
1354 settings = empathy_account_settings_new_for_account (account);
1356 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1357 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1359 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1362 COL_ACCOUNT_POINTER, account,
1363 COL_ACCOUNT_SETTINGS_POINTER, settings,
1366 accounts_dialog_connection_changed_cb (account,
1369 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1374 empathy_signal_connect_weak (account, "notify::display-name",
1375 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1378 g_object_unref (settings);
1382 account_prepare_cb (GObject *source_object,
1383 GAsyncResult *result,
1386 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1387 TpAccount *account = TP_ACCOUNT (source_object);
1388 GError *error = NULL;
1390 if (!tp_account_prepare_finish (account, result, &error))
1392 DEBUG ("Failed to prepare account: %s", error->message);
1393 g_error_free (error);
1397 accounts_dialog_add_account (dialog, account);
1401 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1404 EmpathyAccountsDialog *dialog)
1406 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1410 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1412 EmpathyAccountsDialog *dialog)
1415 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1417 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1419 gtk_list_store_remove (GTK_LIST_STORE (
1420 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1425 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1429 GtkTreeModel *model;
1430 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1432 /* Update the status in the model */
1433 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1435 /* Update the status-infobar in the details view when disabling*/
1437 accounts_dialog_update_status_infobar (dialog, account);
1439 DEBUG ("Account %s is now %s",
1440 tp_account_get_display_name (account),
1441 enabled ? "enabled" : "disabled");
1445 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1447 EmpathyAccountsDialog *dialog)
1449 enable_or_disable_account (dialog, account, FALSE);
1453 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1455 EmpathyAccountsDialog *dialog)
1457 enable_or_disable_account (dialog, account, TRUE);
1461 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1462 EmpathyAccountsDialog *dialog)
1464 EmpathyAccountSettings *settings;
1466 const gchar *display_name;
1467 TpConnectionManager *cm;
1468 TpConnectionManagerProtocol *proto;
1469 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1472 cm = empathy_protocol_chooser_dup_selected (
1473 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1475 display_name = empathy_protocol_name_to_display_name (
1476 is_gtalk ? "gtalk" : proto->name);
1478 if (display_name == NULL)
1479 display_name = proto->name;
1481 /* Create account */
1482 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1485 str = g_strdup_printf (_("New %s account"), display_name);
1486 settings = empathy_account_settings_new (cm->name, proto->name, str);
1491 if (tp_connection_manager_protocol_can_register (proto))
1495 active = gtk_toggle_button_get_active
1496 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1498 empathy_account_settings_set_boolean (settings, "register", TRUE);
1503 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1506 accounts_dialog_add (dialog, settings);
1507 accounts_dialog_model_set_selected (dialog, settings);
1509 g_object_unref (settings);
1510 g_object_unref (cm);
1514 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1515 EmpathyAccountsDialog *dialog)
1517 EmpathyAccountSettings *settings;
1519 settings = accounts_dialog_model_get_selected_settings (dialog);
1520 accounts_dialog_update_settings (dialog, settings);
1523 g_object_unref (settings);
1527 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1528 EmpathyAccountsDialog *dialog)
1530 empathy_url_show (button, "ghelp:empathy?accounts-window");
1534 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1535 EmpathyAccountsDialog *dialog)
1537 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1538 GtkWidget *import_dialog;
1540 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1542 gtk_widget_show (import_dialog);
1546 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1550 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1552 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1554 if (response_id == GTK_RESPONSE_YES)
1555 gtk_widget_destroy (account_dialog);
1559 accounts_dialog_response_cb (GtkWidget *widget,
1561 EmpathyAccountsDialog *dialog)
1563 TpAccount *account = NULL;
1565 if (accounts_dialog_has_pending_change (dialog, &account))
1567 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1569 accounts_dialog_show_question_dialog (dialog,
1570 question_dialog_primary_text,
1571 _("You are about to close the window, which will discard\n"
1572 "your changes. Are you sure you want to proceed?"),
1573 G_CALLBACK (accounts_dialog_close_response_cb),
1575 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1576 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1578 g_free (question_dialog_primary_text);
1580 else if (response == GTK_RESPONSE_CLOSE ||
1581 response == GTK_RESPONSE_DELETE_EVENT)
1582 gtk_widget_destroy (widget);
1586 accounts_dialog_delete_event_cb (GtkWidget *widget,
1588 EmpathyAccountsDialog *dialog)
1590 /* we maunally handle responses to delete events */
1595 accounts_dialog_destroy_cb (GtkObject *obj,
1596 EmpathyAccountsDialog *dialog)
1600 g_object_unref (dialog);
1604 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1607 GtkTreeSelection *selection;
1609 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1611 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1612 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1613 gtk_tree_selection_select_iter (selection, &iter);
1617 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1619 EmpathyAccountsDialog *dialog)
1621 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1623 if (empathy_connection_managers_is_ready (cms))
1625 accounts_dialog_update_settings (dialog, NULL);
1627 if (priv->initial_selection != NULL)
1629 accounts_dialog_set_selected_account
1630 (dialog, priv->initial_selection);
1631 g_object_unref (priv->initial_selection);
1632 priv->initial_selection = NULL;
1638 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1640 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1641 GList *accounts, *l;
1643 g_signal_connect (priv->account_manager, "account-validity-changed",
1644 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1646 g_signal_connect (priv->account_manager, "account-removed",
1647 G_CALLBACK (accounts_dialog_account_removed_cb),
1649 g_signal_connect (priv->account_manager, "account-enabled",
1650 G_CALLBACK (accounts_dialog_account_enabled_cb),
1652 g_signal_connect (priv->account_manager, "account-disabled",
1653 G_CALLBACK (accounts_dialog_account_disabled_cb),
1656 /* Add existing accounts */
1657 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1658 for (l = accounts; l; l = l->next)
1660 accounts_dialog_add_account (dialog, l->data);
1662 empathy_signal_connect_weak (l->data, "status-changed",
1663 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1664 empathy_signal_connect_weak (l->data, "presence-changed",
1665 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1667 g_list_free (accounts);
1669 priv->cms = empathy_connection_managers_dup_singleton ();
1670 if (!empathy_connection_managers_is_ready (priv->cms))
1671 g_signal_connect (priv->cms, "notify::ready",
1672 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1674 accounts_dialog_model_select_first (dialog);
1678 accounts_dialog_manager_ready_cb (GObject *source_object,
1679 GAsyncResult *result,
1682 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1683 GError *error = NULL;
1685 if (!tp_account_manager_prepare_finish (manager, result, &error))
1687 DEBUG ("Failed to prepare account manager: %s", error->message);
1688 g_error_free (error);
1692 accounts_dialog_accounts_setup (user_data);
1696 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1700 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1701 GtkWidget *content_area;
1703 GtkWidget *action_area;
1706 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1708 gui = empathy_builder_get_file (filename,
1709 "accounts_dialog", &priv->window,
1710 "vbox_details", &priv->vbox_details,
1711 "frame_no_protocol", &priv->frame_no_protocol,
1712 "alignment_settings", &priv->alignment_settings,
1713 "alignment_infobar", &priv->alignment_infobar,
1714 "treeview", &priv->treeview,
1715 "frame_new_account", &priv->frame_new_account,
1716 "hbox_type", &priv->hbox_type,
1717 "button_create", &priv->button_create,
1718 "button_back", &priv->button_back,
1719 "radiobutton_reuse", &priv->radiobutton_reuse,
1720 "radiobutton_register", &priv->radiobutton_register,
1721 "image_type", &priv->image_type,
1722 "label_name", &priv->label_name,
1723 "button_add", &priv->button_add,
1724 "button_import", &priv->button_import,
1728 empathy_builder_connect (gui, dialog,
1729 "accounts_dialog", "response", accounts_dialog_response_cb,
1730 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1731 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1732 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1733 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1734 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1735 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1736 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1739 g_object_unref (gui);
1742 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1743 gtk_widget_hide (action_area);
1745 /* Translators: this is used only when built on a moblin platform */
1746 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1747 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1750 priv->combobox_protocol = empathy_protocol_chooser_new ();
1751 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1752 priv->combobox_protocol,
1754 gtk_widget_show (priv->combobox_protocol);
1755 g_signal_connect (priv->combobox_protocol, "changed",
1756 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1759 if (priv->parent_window)
1760 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1761 priv->parent_window);
1763 /* set up spinner */
1764 priv->throbber = ephy_spinner_new ();
1765 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1767 priv->infobar = gtk_info_bar_new ();
1768 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1770 gtk_widget_show (priv->infobar);
1772 priv->image_status = gtk_image_new_from_icon_name (
1773 empathy_icon_name_for_presence (
1774 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1776 priv->label_status = gtk_label_new (NULL);
1778 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1779 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1781 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1783 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1787 do_dispose (GObject *obj)
1789 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1790 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1792 /* Disconnect signals */
1793 g_signal_handlers_disconnect_by_func (priv->account_manager,
1794 accounts_dialog_account_validity_changed_cb,
1796 g_signal_handlers_disconnect_by_func (priv->account_manager,
1797 accounts_dialog_account_removed_cb,
1799 g_signal_handlers_disconnect_by_func (priv->account_manager,
1800 accounts_dialog_account_enabled_cb,
1802 g_signal_handlers_disconnect_by_func (priv->account_manager,
1803 accounts_dialog_account_disabled_cb,
1805 g_signal_handlers_disconnect_by_func (priv->account_manager,
1806 accounts_dialog_manager_ready_cb,
1809 if (priv->connecting_id)
1810 g_source_remove (priv->connecting_id);
1812 if (priv->account_manager != NULL)
1814 g_object_unref (priv->account_manager);
1815 priv->account_manager = NULL;
1818 if (priv->cms != NULL)
1820 g_object_unref (priv->cms);
1824 if (priv->initial_selection != NULL)
1825 g_object_unref (priv->initial_selection);
1826 priv->initial_selection = NULL;
1828 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1832 do_constructor (GType type,
1834 GObjectConstructParam *props)
1838 if (dialog_singleton)
1840 retval = G_OBJECT (dialog_singleton);
1841 g_object_ref (retval);
1846 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1847 (type, n_props, props);
1849 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1850 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1851 /* We add an extra reference that we'll release when the dialog is
1852 * destroyed (accounts_dialog_destroy_cb) */
1853 g_object_ref (retval);
1860 do_get_property (GObject *object,
1865 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1867 switch (property_id)
1870 g_value_set_object (value, priv->parent_window);
1873 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1878 do_set_property (GObject *object,
1880 const GValue *value,
1883 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1885 switch (property_id)
1888 priv->parent_window = g_value_get_object (value);
1891 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1896 do_constructed (GObject *object)
1898 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1899 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1900 gboolean import_asked;
1902 accounts_dialog_build_ui (dialog);
1903 accounts_dialog_model_setup (dialog);
1905 /* Set up signalling */
1906 priv->account_manager = tp_account_manager_dup ();
1908 tp_account_manager_prepare_async (priv->account_manager, NULL,
1909 accounts_dialog_manager_ready_cb, dialog);
1911 empathy_conf_get_bool (empathy_conf_get (),
1912 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1914 if (empathy_import_accounts_to_import ())
1916 gtk_widget_show (priv->button_import);
1920 GtkWidget *import_dialog;
1922 empathy_conf_set_bool (empathy_conf_get (),
1923 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1924 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1926 gtk_widget_show (import_dialog);
1932 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1934 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1935 GParamSpec *param_spec;
1937 oclass->constructor = do_constructor;
1938 oclass->dispose = do_dispose;
1939 oclass->constructed = do_constructed;
1940 oclass->set_property = do_set_property;
1941 oclass->get_property = do_get_property;
1943 param_spec = g_param_spec_object ("parent",
1944 "parent", "The parent window",
1946 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1947 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1949 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1953 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1955 EmpathyAccountsDialogPriv *priv;
1957 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1958 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1959 EmpathyAccountsDialogPriv);
1960 dialog->priv = priv;
1963 /* public methods */
1966 empathy_accounts_dialog_show (GtkWindow *parent,
1967 TpAccount *selected_account)
1969 EmpathyAccountsDialog *dialog;
1970 EmpathyAccountsDialogPriv *priv;
1972 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1973 "parent", parent, NULL);
1975 priv = GET_PRIV (dialog);
1977 if (selected_account)
1979 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1980 accounts_dialog_set_selected_account (dialog, selected_account);
1982 /* save the selection to set it later when the cms
1985 priv->initial_selection = g_object_ref (selected_account);
1988 gtk_window_present (GTK_WINDOW (priv->window));
1989 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1990 * destroyed so we can release the ref returned by the constructor now. */
1991 g_object_unref (dialog);
1993 return priv->window;