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,
177 TpAccount *account, guint status, guint reason)
179 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
180 const gchar *message;
183 presence = tp_account_get_current_presence (account, NULL, NULL);
185 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
186 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
188 if (tp_account_is_enabled (account))
192 case TP_CONNECTION_STATUS_CONNECTING:
193 message = _("Connecting...");
194 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
197 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
198 gtk_widget_show (priv->throbber);
199 gtk_widget_hide (priv->image_status);
201 case TP_CONNECTION_STATUS_CONNECTED:
202 message = g_strdup_printf (_("Connected with status %s"),
203 empathy_presence_get_default_message (presence));
205 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
208 gtk_widget_show (priv->image_status);
209 gtk_widget_hide (priv->throbber);
211 case TP_CONNECTION_STATUS_DISCONNECTED:
214 case TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED:
215 message = _("Disconnected - No error specified");
217 case TP_CONNECTION_STATUS_REASON_NETWORK_ERROR:
218 message = _("Disconnected - Network error");
220 case TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED:
221 message = _("Disconnected - Authentication failed");
223 case TP_CONNECTION_STATUS_REASON_ENCRYPTION_ERROR:
224 message = _("Disconnected - Encryption error");
226 case TP_CONNECTION_STATUS_REASON_NAME_IN_USE:
227 message = _("Disconnected - Name in use");
229 case TP_CONNECTION_STATUS_REASON_CERT_NOT_PROVIDED:
230 message = _("Disconnected - Certificate not provided");
232 case TP_CONNECTION_STATUS_REASON_CERT_UNTRUSTED:
233 message = _("Disconnected - Certificate untrusted");
235 case TP_CONNECTION_STATUS_REASON_CERT_EXPIRED:
236 message = _("Disconnected - Certificate expired");
238 case TP_CONNECTION_STATUS_REASON_CERT_NOT_ACTIVATED:
239 message = _("Disconnected - Certificate not activated");
241 case TP_CONNECTION_STATUS_REASON_CERT_HOSTNAME_MISMATCH:
242 message = _("Disconnected - Certificate hostname mismatch");
244 case TP_CONNECTION_STATUS_REASON_CERT_FINGERPRINT_MISMATCH:
245 message = _("Disconnected - Certificate fingerprint mismatch");
247 case TP_CONNECTION_STATUS_REASON_CERT_SELF_SIGNED:
248 message = _("Disconnected - Certificate self-signed");
250 case TP_CONNECTION_STATUS_REASON_CERT_OTHER_ERROR:
251 message = _("Disconnected - Certificate error");
254 message = _("Disconnected - Unknown reason");
258 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
261 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
262 gtk_widget_show (priv->image_status);
263 gtk_widget_hide (priv->throbber);
266 message = _("Unknown Status");
267 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
268 GTK_MESSAGE_WARNING);
270 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
271 gtk_widget_hide (priv->image_status);
272 gtk_widget_hide (priv->throbber);
277 message = _("Disconnected - Account disabled");
278 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
279 GTK_MESSAGE_WARNING);
280 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
281 gtk_widget_show (priv->image_status);
282 gtk_widget_hide (priv->throbber);
285 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
286 gtk_widget_show (priv->label_status);
287 gtk_widget_show (priv->infobar);
291 empathy_account_dialog_widget_cancelled_cb (
292 EmpathyAccountWidget *widget_object,
293 EmpathyAccountsDialog *dialog)
297 GtkTreeSelection *selection;
299 EmpathyAccountSettings *settings;
301 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
303 view = GTK_TREE_VIEW (priv->treeview);
304 selection = gtk_tree_view_get_selection (view);
306 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
309 gtk_tree_model_get (model, &iter,
310 COL_ACCOUNT_SETTINGS_POINTER, &settings,
311 COL_ACCOUNT_POINTER, &account, -1);
313 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
317 /* We were creating an account. We remove the selected row */
318 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
322 /* We were modifying an account. We discard the changes by reloading the
323 * settings and the UI. */
324 accounts_dialog_update_settings (dialog, settings);
325 g_object_unref (account);
328 if (settings != NULL)
329 g_object_unref (settings);
333 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
334 EmpathyAccountsDialog *dialog)
337 EmpathyAccountSettings *settings =
338 accounts_dialog_model_get_selected_settings (dialog);
340 display_name = empathy_account_widget_get_default_display_name (
343 empathy_account_settings_set_display_name_async (settings,
344 display_name, NULL, NULL);
346 g_free (display_name);
348 accounts_dialog_update_settings (dialog, settings);
351 g_object_unref (settings);
355 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
356 EmpathyAccountSettings *settings)
358 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
364 priv->setting_widget_object =
365 empathy_account_widget_new_for_protocol (settings, FALSE);
367 priv->settings_widget =
368 empathy_account_widget_get_widget (priv->setting_widget_object);
370 priv->settings_widget =
371 empathy_account_widget_get_widget (priv->setting_widget_object);
372 g_signal_connect (priv->setting_widget_object, "account-created",
373 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
374 g_signal_connect (priv->setting_widget_object, "cancelled",
375 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
377 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
378 priv->settings_widget);
379 gtk_widget_show (priv->settings_widget);
381 icon_name = empathy_account_settings_get_icon_name (settings);
383 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
385 /* show the default icon; keep this in sync with the default
386 * one in empathy-accounts-dialog.ui.
388 icon_name = GTK_STOCK_CUT;
390 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
391 icon_name, GTK_ICON_SIZE_DIALOG);
392 gtk_widget_set_tooltip_text (priv->image_type,
393 empathy_protocol_name_to_display_name
394 (empathy_account_settings_get_protocol (settings)));
395 gtk_widget_show (priv->image_type);
397 accounts_dialog_update_name_label (dialog,
398 empathy_account_settings_get_display_name (settings));
400 account = empathy_account_settings_get_account (settings);
402 status = tp_account_get_connection_status (account, &reason);
403 accounts_dialog_update_status_infobar (dialog, account, status, reason);
407 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
409 EmpathyAccountsDialog *dialog)
411 if (empathy_account_settings_is_ready (settings))
412 account_dialog_create_settings_widget (dialog, settings);
416 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
420 GtkTreeSelection *selection;
422 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
425 view = GTK_TREE_VIEW (priv->treeview);
426 model = gtk_tree_view_get_model (view);
428 if (gtk_tree_model_get_iter_first (model, &iter))
430 selection = gtk_tree_view_get_selection (view);
431 gtk_tree_selection_select_iter (selection, &iter);
435 accounts_dialog_update_settings (dialog, NULL);
440 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
445 GtkTreeSelection *selection;
446 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
448 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
450 if (gtk_tree_selection_get_selected (selection, &model, &iter))
451 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
453 return priv->setting_widget_object != NULL
454 && empathy_account_widget_contains_pending_changes (
455 priv->setting_widget_object);
459 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
460 EmpathyAccountsDialog *dialog)
462 TpConnectionManager *cm;
463 TpConnectionManagerProtocol *proto;
465 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
467 cm = empathy_protocol_chooser_dup_selected (
468 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
480 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
482 gtk_widget_show (priv->radiobutton_register);
483 gtk_widget_show (priv->radiobutton_reuse);
487 gtk_widget_hide (priv->radiobutton_register);
488 gtk_widget_hide (priv->radiobutton_reuse);
491 gtk_widget_hide (priv->radiobutton_register);
492 gtk_widget_hide (priv->radiobutton_reuse);
499 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
503 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
505 view = GTK_TREE_VIEW (priv->treeview);
506 model = gtk_tree_view_get_model (view);
508 gtk_widget_set_sensitive (priv->button_add, FALSE);
509 gtk_widget_hide (priv->vbox_details);
510 gtk_widget_hide (priv->frame_no_protocol);
511 gtk_widget_show (priv->frame_new_account);
513 /* If we have no account, no need of a back button */
514 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
515 gtk_widget_show (priv->button_back);
517 gtk_widget_hide (priv->button_back);
519 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
520 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
522 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
523 gtk_widget_grab_focus (priv->combobox_protocol);
527 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
528 const gchar *primary_text,
529 const gchar *secondary_text,
530 GCallback response_callback,
532 const gchar *first_button_text,
536 GtkWidget *message_dialog;
537 const gchar *button_text;
538 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
540 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
541 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
542 GTK_MESSAGE_QUESTION,
546 gtk_message_dialog_format_secondary_text (
547 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
549 va_start (button_args, first_button_text);
550 for (button_text = first_button_text;
552 button_text = va_arg (button_args, const gchar *))
555 response_id = va_arg (button_args, gint);
557 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
560 va_end (button_args);
562 g_signal_connect (message_dialog, "response", response_callback, user_data);
564 gtk_widget_show (message_dialog);
568 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
572 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
573 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
575 gtk_widget_destroy (GTK_WIDGET (message_dialog));
577 if (response_id == GTK_RESPONSE_YES)
579 empathy_account_widget_discard_pending_changes (
580 priv->setting_widget_object);
581 accounts_dialog_setup_ui_to_add_account (dialog);
586 get_dialog_primary_text (TpAccount *account)
590 /* Existing account */
591 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
592 tp_account_get_display_name (account));
596 /* Newly created account */
597 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
602 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
603 EmpathyAccountsDialog *dialog)
605 TpAccount *account = NULL;
607 if (accounts_dialog_has_pending_change (dialog, &account))
609 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
611 accounts_dialog_show_question_dialog (dialog,
612 question_dialog_primary_text,
613 _("You are about to create a new account, which will discard\n"
614 "your changes. Are you sure you want to proceed?"),
615 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
617 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
618 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
620 g_free (question_dialog_primary_text);
624 accounts_dialog_setup_ui_to_add_account (dialog);
629 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
630 EmpathyAccountSettings *settings)
632 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
634 if (priv->settings_ready != NULL)
636 g_signal_handler_disconnect (priv->settings_ready,
637 priv->settings_ready_id);
638 priv->settings_ready = NULL;
639 priv->settings_ready_id = 0;
646 GtkTreeSelection *selection;
648 view = GTK_TREE_VIEW (priv->treeview);
649 model = gtk_tree_view_get_model (view);
650 selection = gtk_tree_view_get_selection (view);
652 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
654 /* We have configured accounts, select the first one if there
655 * is no other account selected already. */
656 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
657 accounts_dialog_model_select_first (dialog);
661 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
663 /* We have no account configured but we have some
664 * profiles installed. The user obviously wants to add
665 * an account. Click on the Add button for him. */
666 accounts_dialog_button_add_clicked_cb (priv->button_add,
671 /* No account and no profile, warn the user */
672 gtk_widget_hide (priv->vbox_details);
673 gtk_widget_hide (priv->frame_new_account);
674 gtk_widget_show (priv->frame_no_protocol);
675 gtk_widget_set_sensitive (priv->button_add, FALSE);
679 /* We have an account selected, destroy old settings and create a new
680 * one for the account selected */
681 gtk_widget_hide (priv->frame_new_account);
682 gtk_widget_hide (priv->frame_no_protocol);
683 gtk_widget_show (priv->vbox_details);
684 gtk_widget_set_sensitive (priv->button_add, TRUE);
686 if (priv->settings_widget)
688 gtk_widget_destroy (priv->settings_widget);
689 priv->settings_widget = NULL;
692 if (empathy_account_settings_is_ready (settings))
694 account_dialog_create_settings_widget (dialog, settings);
698 priv->settings_ready = settings;
699 priv->settings_ready_id =
700 g_signal_connect (settings, "notify::ready",
701 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
707 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
708 GtkCellEditable *editable,
710 EmpathyAccountsDialog *dialog)
712 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
714 if (priv->connecting_id)
715 g_source_remove (priv->connecting_id);
717 DEBUG ("Editing account name started; stopping flashing");
721 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
722 GtkCellRenderer *cell,
725 EmpathyAccountsDialog *dialog)
727 EmpathyAccountSettings *settings;
730 TpConnectionStatus status;
731 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
733 gtk_tree_model_get (model, iter,
735 COL_ACCOUNT_SETTINGS_POINTER, &settings,
738 icon_name = empathy_account_settings_get_icon_name (settings);
739 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
743 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
744 (status == TP_CONNECTION_STATUS_CONNECTING &&
745 !priv->connecting_show))
747 GdkPixbuf *modded_pixbuf;
749 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
752 gdk_pixbuf_get_width (pixbuf),
753 gdk_pixbuf_get_height (pixbuf));
755 gdk_pixbuf_saturate_and_pixelate (pixbuf,
759 g_object_unref (pixbuf);
760 pixbuf = modded_pixbuf;
769 g_object_unref (settings);
772 g_object_unref (pixbuf);
776 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
781 gtk_tree_model_row_changed (model, path, iter);
787 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
791 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
793 priv->connecting_show = !priv->connecting_show;
795 view = GTK_TREE_VIEW (priv->treeview);
796 model = gtk_tree_view_get_model (view);
798 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
804 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
807 EmpathyAccountsDialog *dialog)
809 EmpathyAccountSettings *settings;
811 GtkTreePath *treepath;
813 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
816 empathy_account_manager_get_accounts_connected (&connecting);
820 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
821 (GSourceFunc) accounts_dialog_flash_connecting_cb,
825 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
826 treepath = gtk_tree_path_new_from_string (path);
827 gtk_tree_model_get_iter (model, &iter, treepath);
828 gtk_tree_model_get (model, &iter,
829 COL_ACCOUNT_SETTINGS_POINTER, &settings,
831 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
834 gtk_tree_path_free (treepath);
836 empathy_account_settings_set_display_name_async (settings, new_text,
838 g_object_set (settings, "display-name-overridden", TRUE, NULL);
839 g_object_unref (settings);
843 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
850 GtkTreeSelection *selection;
851 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
852 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
854 if (response_id == GTK_RESPONSE_YES)
856 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
858 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
861 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
865 tp_account_remove_async (account, NULL, NULL);
866 g_object_unref (account);
870 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
871 accounts_dialog_model_select_first (account_dialog);
874 gtk_widget_destroy (GTK_WIDGET (message_dialog));
878 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
879 const gchar *path_string,
880 EmpathyAccountsDialog *dialog)
885 gchar *question_dialog_primary_text;
886 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
888 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
890 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
893 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
895 if (account == NULL || !tp_account_is_valid (account))
897 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
898 accounts_dialog_model_select_first (dialog);
902 question_dialog_primary_text = g_strdup_printf (
903 _("Do you want to remove %s from your computer?"),
904 tp_account_get_display_name (account));
906 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
907 _("This will not remove your account on the server."),
908 G_CALLBACK (accounts_dialog_delete_account_response_cb),
910 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
911 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
913 g_free (question_dialog_primary_text);
917 g_object_unref (account);
923 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
926 GtkTreeViewColumn *column;
927 GtkCellRenderer *cell;
928 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
930 view = GTK_TREE_VIEW (priv->treeview);
931 gtk_tree_view_set_headers_visible (view, FALSE);
934 column = gtk_tree_view_column_new ();
935 gtk_tree_view_column_set_expand (column, TRUE);
936 gtk_tree_view_append_column (view, column);
939 cell = gtk_cell_renderer_pixbuf_new ();
940 gtk_tree_view_column_pack_start (column, cell, FALSE);
941 gtk_tree_view_column_set_cell_data_func (column, cell,
942 (GtkTreeCellDataFunc)
943 accounts_dialog_model_pixbuf_data_func,
948 cell = gtk_cell_renderer_text_new ();
950 "ellipsize", PANGO_ELLIPSIZE_END,
954 gtk_tree_view_column_pack_start (column, cell, TRUE);
955 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
956 g_signal_connect (cell, "edited",
957 G_CALLBACK (accounts_dialog_name_edited_cb),
959 g_signal_connect (cell, "editing-started",
960 G_CALLBACK (accounts_dialog_name_editing_started_cb),
962 g_object_set (cell, "ypad", 4, NULL);
965 cell = empathy_cell_renderer_activatable_new ();
966 gtk_tree_view_column_pack_start (column, cell, FALSE);
968 "icon-name", GTK_STOCK_DELETE,
969 "show-on-select", TRUE,
972 g_signal_connect (cell, "path-activated",
973 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
977 static EmpathyAccountSettings *
978 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
982 GtkTreeSelection *selection;
984 EmpathyAccountSettings *settings;
985 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
987 view = GTK_TREE_VIEW (priv->treeview);
988 selection = gtk_tree_view_get_selection (view);
990 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
993 gtk_tree_model_get (model, &iter,
994 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1000 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1001 EmpathyAccountsDialog *dialog)
1003 EmpathyAccountSettings *settings;
1004 GtkTreeModel *model;
1006 gboolean is_selection;
1008 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1010 settings = accounts_dialog_model_get_selected_settings (dialog);
1011 accounts_dialog_update_settings (dialog, settings);
1013 if (settings != NULL)
1014 g_object_unref (settings);
1018 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1020 gpointer *user_data)
1022 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1023 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1025 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1027 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1029 /* The user wants to lose unsaved changes to the currently selected
1030 * account and select another account. We discard the changes and
1031 * select the other account. */
1033 GtkTreeSelection *selection;
1035 priv->force_change_row = TRUE;
1036 empathy_account_widget_discard_pending_changes (
1037 priv->setting_widget_object);
1039 path = gtk_tree_row_reference_get_path (priv->destination_row);
1040 selection = gtk_tree_view_get_selection (
1041 GTK_TREE_VIEW (priv->treeview));
1045 /* This will trigger a call to
1046 * accounts_dialog_account_selection_change() */
1047 gtk_tree_selection_select_path (selection, path);
1048 gtk_tree_path_free (path);
1051 gtk_tree_row_reference_free (priv->destination_row);
1055 priv->force_change_row = FALSE;
1060 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1061 GtkTreeModel *model,
1063 gboolean path_currently_selected,
1066 TpAccount *account = NULL;
1067 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1068 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1070 if (priv->force_change_row)
1072 /* We came back here because the user wants to discard changes to his
1073 * modified account. The changes have already been discarded so we
1074 * just change the selected row. */
1075 priv->force_change_row = FALSE;
1079 if (accounts_dialog_has_pending_change (dialog, &account))
1081 /* The currently selected account has some unsaved changes. We ask
1082 * the user if he really wants to lose his changes and select another
1084 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1085 priv->destination_row = gtk_tree_row_reference_new (model, path);
1087 accounts_dialog_show_question_dialog (dialog,
1088 question_dialog_primary_text,
1089 _("You are about to select another account, which will discard\n"
1090 "your changes. Are you sure you want to proceed?"),
1091 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1093 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1094 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1096 g_free (question_dialog_primary_text);
1107 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1109 GtkListStore *store;
1110 GtkTreeSelection *selection;
1111 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1113 store = gtk_list_store_new (COL_COUNT,
1114 G_TYPE_STRING, /* name */
1115 G_TYPE_UINT, /* status */
1116 TP_TYPE_ACCOUNT, /* account */
1117 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1119 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1120 GTK_TREE_MODEL (store));
1122 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1123 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1124 gtk_tree_selection_set_select_function (selection,
1125 accounts_dialog_account_selection_change, dialog, NULL);
1127 g_signal_connect (selection, "changed",
1128 G_CALLBACK (accounts_dialog_model_selection_changed),
1131 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1132 COL_NAME, GTK_SORT_ASCENDING);
1134 accounts_dialog_model_add_columns (dialog);
1136 g_object_unref (store);
1140 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1141 EmpathyAccountSettings *settings,
1145 GtkTreeSelection *selection;
1146 GtkTreeModel *model;
1148 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1150 /* Update the status in the model */
1151 view = GTK_TREE_VIEW (priv->treeview);
1152 selection = gtk_tree_view_get_selection (view);
1153 model = gtk_tree_view_get_model (view);
1155 for (ok = gtk_tree_model_get_iter_first (model, iter);
1157 ok = gtk_tree_model_iter_next (model, iter))
1159 EmpathyAccountSettings *this_settings;
1162 gtk_tree_model_get (model, iter,
1163 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1166 equal = (this_settings == settings);
1167 g_object_unref (this_settings);
1177 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1182 GtkTreeSelection *selection;
1183 GtkTreeModel *model;
1185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1187 /* Update the status in the model */
1188 view = GTK_TREE_VIEW (priv->treeview);
1189 selection = gtk_tree_view_get_selection (view);
1190 model = gtk_tree_view_get_model (view);
1192 for (ok = gtk_tree_model_get_iter_first (model, iter);
1194 ok = gtk_tree_model_iter_next (model, iter))
1196 EmpathyAccountSettings *settings;
1199 gtk_tree_model_get (model, iter,
1200 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1203 equal = empathy_account_settings_has_account (settings, account);
1204 g_object_unref (settings);
1214 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1215 EmpathyAccountSettings *settings)
1217 GtkTreeSelection *selection;
1219 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1221 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1222 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1223 gtk_tree_selection_select_iter (selection, &iter);
1226 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1227 EmpathyAccountSettings *settings)
1229 GtkTreeModel *model;
1232 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1234 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1235 name = empathy_account_settings_get_display_name (settings);
1237 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1239 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1241 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1242 COL_ACCOUNT_SETTINGS_POINTER, settings,
1247 accounts_dialog_connection_changed_cb (TpAccount *account,
1251 gchar *dbus_error_name,
1252 GHashTable *details,
1253 EmpathyAccountsDialog *dialog)
1255 GtkTreeModel *model;
1258 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1260 /* Update the status-infobar in the details view*/
1261 accounts_dialog_update_status_infobar (dialog, account, current, reason);
1263 /* Update the status in the model */
1264 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1266 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1270 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1271 COL_STATUS, current,
1274 path = gtk_tree_model_get_path (model, &iter);
1275 gtk_tree_model_row_changed (model, path, &iter);
1276 gtk_tree_path_free (path);
1279 empathy_account_manager_get_accounts_connected (&found);
1281 if (!found && priv->connecting_id)
1283 g_source_remove (priv->connecting_id);
1284 priv->connecting_id = 0;
1287 if (found && !priv->connecting_id)
1288 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1289 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1294 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1298 const gchar *display_name;
1300 GtkTreeModel *model;
1301 EmpathyAccountSettings *settings;
1302 TpAccount *selected_account;
1303 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1304 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1306 display_name = tp_account_get_display_name (account);
1307 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1308 settings = accounts_dialog_model_get_selected_settings (dialog);
1309 if (settings == NULL)
1312 selected_account = empathy_account_settings_get_account (settings);
1314 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1316 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1317 COL_NAME, display_name,
1321 if (selected_account == account)
1322 accounts_dialog_update_name_label (dialog, display_name);
1324 g_object_unref (settings);
1328 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1331 EmpathyAccountSettings *settings;
1332 GtkTreeModel *model;
1334 TpConnectionStatus status;
1337 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1339 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1340 status = tp_account_get_connection_status (account, NULL);
1341 name = tp_account_get_display_name (account);
1342 enabled = tp_account_is_enabled (account);
1344 settings = empathy_account_settings_new_for_account (account);
1346 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1347 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1349 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1352 COL_ACCOUNT_POINTER, account,
1353 COL_ACCOUNT_SETTINGS_POINTER, settings,
1356 accounts_dialog_connection_changed_cb (account,
1359 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1364 empathy_signal_connect_weak (account, "notify::display-name",
1365 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1368 g_object_unref (settings);
1372 account_prepare_cb (GObject *source_object,
1373 GAsyncResult *result,
1376 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1377 TpAccount *account = TP_ACCOUNT (source_object);
1378 GError *error = NULL;
1380 if (!tp_account_prepare_finish (account, result, &error))
1382 DEBUG ("Failed to prepare account: %s", error->message);
1383 g_error_free (error);
1387 accounts_dialog_add_account (dialog, account);
1391 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1394 EmpathyAccountsDialog *dialog)
1396 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1400 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1402 EmpathyAccountsDialog *dialog)
1405 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1407 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1409 gtk_list_store_remove (GTK_LIST_STORE (
1410 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1415 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1419 GtkTreeModel *model;
1420 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1422 /* Update the status in the model */
1423 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1425 /* Update the status-infobar in the details view when disabling*/
1427 accounts_dialog_update_status_infobar (dialog, account,
1428 TP_CONNECTION_STATUS_DISCONNECTED,
1429 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED);
1431 DEBUG ("Account %s is now %s",
1432 tp_account_get_display_name (account),
1433 enabled ? "enabled" : "disabled");
1437 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1439 EmpathyAccountsDialog *dialog)
1441 enable_or_disable_account (dialog, account, FALSE);
1445 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1447 EmpathyAccountsDialog *dialog)
1449 enable_or_disable_account (dialog, account, TRUE);
1453 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1454 EmpathyAccountsDialog *dialog)
1456 EmpathyAccountSettings *settings;
1458 const gchar *display_name;
1459 TpConnectionManager *cm;
1460 TpConnectionManagerProtocol *proto;
1461 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1464 cm = empathy_protocol_chooser_dup_selected (
1465 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1467 display_name = empathy_protocol_name_to_display_name (
1468 is_gtalk ? "gtalk" : proto->name);
1470 if (display_name == NULL)
1471 display_name = proto->name;
1473 /* Create account */
1474 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1477 str = g_strdup_printf (_("New %s account"), display_name);
1478 settings = empathy_account_settings_new (cm->name, proto->name, str);
1483 if (tp_connection_manager_protocol_can_register (proto))
1487 active = gtk_toggle_button_get_active
1488 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1490 empathy_account_settings_set_boolean (settings, "register", TRUE);
1495 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1498 accounts_dialog_add (dialog, settings);
1499 accounts_dialog_model_set_selected (dialog, settings);
1501 g_object_unref (settings);
1502 g_object_unref (cm);
1506 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1507 EmpathyAccountsDialog *dialog)
1509 EmpathyAccountSettings *settings;
1511 settings = accounts_dialog_model_get_selected_settings (dialog);
1512 accounts_dialog_update_settings (dialog, settings);
1515 g_object_unref (settings);
1519 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1520 EmpathyAccountsDialog *dialog)
1522 empathy_url_show (button, "ghelp:empathy?accounts-window");
1526 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1527 EmpathyAccountsDialog *dialog)
1529 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1530 GtkWidget *import_dialog;
1532 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1534 gtk_widget_show (import_dialog);
1538 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1542 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1544 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1546 if (response_id == GTK_RESPONSE_YES)
1547 gtk_widget_destroy (account_dialog);
1551 accounts_dialog_response_cb (GtkWidget *widget,
1553 EmpathyAccountsDialog *dialog)
1555 TpAccount *account = NULL;
1557 if (accounts_dialog_has_pending_change (dialog, &account))
1559 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1561 accounts_dialog_show_question_dialog (dialog,
1562 question_dialog_primary_text,
1563 _("You are about to close the window, which will discard\n"
1564 "your changes. Are you sure you want to proceed?"),
1565 G_CALLBACK (accounts_dialog_close_response_cb),
1567 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1568 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1570 g_free (question_dialog_primary_text);
1572 else if (response == GTK_RESPONSE_CLOSE ||
1573 response == GTK_RESPONSE_DELETE_EVENT)
1574 gtk_widget_destroy (widget);
1578 accounts_dialog_delete_event_cb (GtkWidget *widget,
1580 EmpathyAccountsDialog *dialog)
1582 /* we maunally handle responses to delete events */
1587 accounts_dialog_destroy_cb (GtkObject *obj,
1588 EmpathyAccountsDialog *dialog)
1592 g_object_unref (dialog);
1596 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1599 GtkTreeSelection *selection;
1601 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1603 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1604 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1605 gtk_tree_selection_select_iter (selection, &iter);
1609 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1611 EmpathyAccountsDialog *dialog)
1613 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1615 if (empathy_connection_managers_is_ready (cms))
1617 accounts_dialog_update_settings (dialog, NULL);
1619 if (priv->initial_selection != NULL)
1621 accounts_dialog_set_selected_account
1622 (dialog, priv->initial_selection);
1623 g_object_unref (priv->initial_selection);
1624 priv->initial_selection = NULL;
1630 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1632 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1633 GList *accounts, *l;
1635 g_signal_connect (priv->account_manager, "account-validity-changed",
1636 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1638 g_signal_connect (priv->account_manager, "account-removed",
1639 G_CALLBACK (accounts_dialog_account_removed_cb),
1641 g_signal_connect (priv->account_manager, "account-enabled",
1642 G_CALLBACK (accounts_dialog_account_enabled_cb),
1644 g_signal_connect (priv->account_manager, "account-disabled",
1645 G_CALLBACK (accounts_dialog_account_disabled_cb),
1648 /* Add existing accounts */
1649 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1650 for (l = accounts; l; l = l->next)
1652 accounts_dialog_add_account (dialog, l->data);
1654 empathy_signal_connect_weak (l->data, "status-changed",
1655 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1657 g_list_free (accounts);
1659 priv->cms = empathy_connection_managers_dup_singleton ();
1660 if (!empathy_connection_managers_is_ready (priv->cms))
1661 g_signal_connect (priv->cms, "notify::ready",
1662 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1664 accounts_dialog_model_select_first (dialog);
1668 accounts_dialog_manager_ready_cb (GObject *source_object,
1669 GAsyncResult *result,
1672 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1673 GError *error = NULL;
1675 if (!tp_account_manager_prepare_finish (manager, result, &error))
1677 DEBUG ("Failed to prepare account manager: %s", error->message);
1678 g_error_free (error);
1682 accounts_dialog_accounts_setup (user_data);
1686 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1690 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1691 GtkWidget *content_area;
1693 GtkWidget *action_area;
1696 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1698 gui = empathy_builder_get_file (filename,
1699 "accounts_dialog", &priv->window,
1700 "vbox_details", &priv->vbox_details,
1701 "frame_no_protocol", &priv->frame_no_protocol,
1702 "alignment_settings", &priv->alignment_settings,
1703 "alignment_infobar", &priv->alignment_infobar,
1704 "treeview", &priv->treeview,
1705 "frame_new_account", &priv->frame_new_account,
1706 "hbox_type", &priv->hbox_type,
1707 "button_create", &priv->button_create,
1708 "button_back", &priv->button_back,
1709 "radiobutton_reuse", &priv->radiobutton_reuse,
1710 "radiobutton_register", &priv->radiobutton_register,
1711 "image_type", &priv->image_type,
1712 "label_name", &priv->label_name,
1713 "button_add", &priv->button_add,
1714 "button_import", &priv->button_import,
1718 empathy_builder_connect (gui, dialog,
1719 "accounts_dialog", "response", accounts_dialog_response_cb,
1720 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1721 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1722 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1723 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1724 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1725 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1726 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1729 g_object_unref (gui);
1732 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1733 gtk_widget_hide (action_area);
1735 /* Translators: this is used only when built on a moblin platform */
1736 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1737 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1740 priv->combobox_protocol = empathy_protocol_chooser_new ();
1741 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1742 priv->combobox_protocol,
1744 gtk_widget_show (priv->combobox_protocol);
1745 g_signal_connect (priv->combobox_protocol, "changed",
1746 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1749 if (priv->parent_window)
1750 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1751 priv->parent_window);
1753 /* set up spinner */
1754 priv->throbber = ephy_spinner_new ();
1755 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1757 priv->infobar = gtk_info_bar_new ();
1758 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1760 gtk_widget_show (priv->infobar);
1762 priv->image_status = gtk_image_new_from_icon_name (
1763 empathy_icon_name_for_presence (
1764 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1766 priv->label_status = gtk_label_new (NULL);
1768 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1769 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1771 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1773 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1777 do_dispose (GObject *obj)
1779 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1780 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1782 /* Disconnect signals */
1783 g_signal_handlers_disconnect_by_func (priv->account_manager,
1784 accounts_dialog_account_validity_changed_cb,
1786 g_signal_handlers_disconnect_by_func (priv->account_manager,
1787 accounts_dialog_account_removed_cb,
1789 g_signal_handlers_disconnect_by_func (priv->account_manager,
1790 accounts_dialog_account_enabled_cb,
1792 g_signal_handlers_disconnect_by_func (priv->account_manager,
1793 accounts_dialog_account_disabled_cb,
1795 g_signal_handlers_disconnect_by_func (priv->account_manager,
1796 accounts_dialog_manager_ready_cb,
1799 if (priv->connecting_id)
1800 g_source_remove (priv->connecting_id);
1802 if (priv->account_manager != NULL)
1804 g_object_unref (priv->account_manager);
1805 priv->account_manager = NULL;
1808 if (priv->cms != NULL)
1810 g_object_unref (priv->cms);
1814 if (priv->initial_selection != NULL)
1815 g_object_unref (priv->initial_selection);
1816 priv->initial_selection = NULL;
1818 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1822 do_constructor (GType type,
1824 GObjectConstructParam *props)
1828 if (dialog_singleton)
1830 retval = G_OBJECT (dialog_singleton);
1831 g_object_ref (retval);
1836 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1837 (type, n_props, props);
1839 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1840 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1841 /* We add an extra reference that we'll release when the dialog is
1842 * destroyed (accounts_dialog_destroy_cb) */
1843 g_object_ref (retval);
1850 do_get_property (GObject *object,
1855 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1857 switch (property_id)
1860 g_value_set_object (value, priv->parent_window);
1863 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1868 do_set_property (GObject *object,
1870 const GValue *value,
1873 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1875 switch (property_id)
1878 priv->parent_window = g_value_get_object (value);
1881 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1886 do_constructed (GObject *object)
1888 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1889 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1890 gboolean import_asked;
1892 accounts_dialog_build_ui (dialog);
1893 accounts_dialog_model_setup (dialog);
1895 /* Set up signalling */
1896 priv->account_manager = tp_account_manager_dup ();
1898 tp_account_manager_prepare_async (priv->account_manager, NULL,
1899 accounts_dialog_manager_ready_cb, dialog);
1901 empathy_conf_get_bool (empathy_conf_get (),
1902 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1904 if (empathy_import_accounts_to_import ())
1906 gtk_widget_show (priv->button_import);
1910 GtkWidget *import_dialog;
1912 empathy_conf_set_bool (empathy_conf_get (),
1913 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1914 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1916 gtk_widget_show (import_dialog);
1922 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1924 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1925 GParamSpec *param_spec;
1927 oclass->constructor = do_constructor;
1928 oclass->dispose = do_dispose;
1929 oclass->constructed = do_constructed;
1930 oclass->set_property = do_set_property;
1931 oclass->get_property = do_get_property;
1933 param_spec = g_param_spec_object ("parent",
1934 "parent", "The parent window",
1936 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1937 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1939 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1943 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1945 EmpathyAccountsDialogPriv *priv;
1947 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1948 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1949 EmpathyAccountsDialogPriv);
1950 dialog->priv = priv;
1953 /* public methods */
1956 empathy_accounts_dialog_show (GtkWindow *parent,
1957 TpAccount *selected_account)
1959 EmpathyAccountsDialog *dialog;
1960 EmpathyAccountsDialogPriv *priv;
1962 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1963 "parent", parent, NULL);
1965 priv = GET_PRIV (dialog);
1967 if (selected_account)
1969 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1970 accounts_dialog_set_selected_account (dialog, selected_account);
1972 /* save the selection to set it later when the cms
1975 priv->initial_selection = g_object_ref (selected_account);
1978 gtk_window_present (GTK_WINDOW (priv->window));
1979 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1980 * destroyed so we can release the ref returned by the constructor now. */
1981 g_object_unref (dialog);
1983 return priv->window;