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/util.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-account-manager.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"
54 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
55 #include <libempathy/empathy-debug.h>
57 /* Flashing delay for icons (milliseconds). */
58 #define FLASH_TIMEOUT 500
60 /* The primary text of the dialog shown to the user when he is about to lose
62 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
63 _("There are unsaved modification regarding your %s account.")
65 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
66 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
68 static EmpathyAccountsDialog *dialog_singleton = NULL;
73 GtkWidget *alignment_settings;
75 GtkWidget *vbox_details;
76 GtkWidget *frame_no_protocol;
80 GtkWidget *button_add;
82 GtkWidget *frame_new_account;
83 GtkWidget *combobox_protocol;
85 GtkWidget *button_create;
86 GtkWidget *button_back;
87 GtkWidget *radiobutton_reuse;
88 GtkWidget *radiobutton_register;
90 GtkWidget *image_type;
91 GtkWidget *label_name;
92 GtkWidget *label_type;
93 GtkWidget *settings_widget;
95 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
96 * his GtkWidget. It is the only reliable source we can query to know if
97 * there are any unsaved changes to the currently selected account. We can't
98 * look at the account settings because it does not contain everything that
99 * can be changed using the EmpathyAccountWidget. For instance, it does not
100 * contain the state of the "Enabled" checkbox. */
101 EmpathyAccountWidget *setting_widget_object;
103 gboolean connecting_show;
106 gulong settings_ready_id;
107 EmpathyAccountSettings *settings_ready;
109 EmpathyAccountManager *account_manager;
110 EmpathyConnectionManagers *cms;
112 GtkWindow *parent_window;
113 EmpathyAccount *initial_selection;
115 /* Those are needed when changing the selected row. When a user selects
116 * another account and there are unsaved changes on the currently selected
117 * one, a confirmation message box is presented to him. Since his answer
118 * is retrieved asynchronously, we keep some information as member of the
119 * EmpathyAccountsDialog object. */
120 gboolean force_change_row;
121 GtkTreeRowReference *destination_row;
124 } EmpathyAccountsDialogPriv;
130 COL_ACCOUNT_SETTINGS_POINTER,
138 static void accounts_dialog_account_display_name_changed_cb (
139 EmpathyAccount *account,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
160 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
161 const gchar *display_name)
164 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
166 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
167 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
173 empathy_account_dialog_widget_cancelled_cb (EmpathyAccountWidget *widget_object,
174 EmpathyAccountsDialog *dialog)
178 GtkTreeSelection *selection;
180 EmpathyAccountSettings *settings;
181 EmpathyAccount *account;
182 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
184 view = GTK_TREE_VIEW (priv->treeview);
185 selection = gtk_tree_view_get_selection (view);
187 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
190 gtk_tree_model_get (model, &iter,
191 COL_ACCOUNT_SETTINGS_POINTER, &settings,
192 COL_ACCOUNT_POINTER, &account, -1);
194 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
198 /* We were creating an account. We remove the selected row */
199 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
203 /* We were modifying an account. We discard the changes by reloading the
204 * settings and the UI. */
205 accounts_dialog_update_settings (dialog, settings);
206 g_object_unref (account);
209 if (settings != NULL)
210 g_object_unref (settings);
214 get_default_display_name (EmpathyAccountSettings *settings)
216 const gchar *login_id;
217 const gchar *protocol;
218 gchar *default_display_name;
220 login_id = empathy_account_settings_get_string (settings, "account");
221 protocol = empathy_account_settings_get_protocol (settings);
223 if (login_id != NULL)
225 if (!tp_strdiff (protocol, "irc"))
228 server = empathy_account_settings_get_string (settings, "server");
230 /* To translators: The first parameter is the login id and the
231 * second one is the server. The resulting string will be something
232 * like: "MyUserName on chat.freenode.net".
233 * You should reverse the order of these arguments if the
234 * server should come before the login id in your locale.*/
235 default_display_name = g_strdup_printf (_("%1$s on %2$s"),
240 default_display_name = g_strdup (login_id);
243 else if (protocol != NULL)
245 /* To translators: The parameter is the protocol name. The resulting
246 * string will be something like: "Jabber Account" */
247 default_display_name = g_strdup_printf (_("%s Account"), protocol);
251 default_display_name = g_strdup (_("New account"));
254 return default_display_name;
258 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
259 EmpathyAccountsDialog *dialog)
262 EmpathyAccountSettings *settings =
263 accounts_dialog_model_get_selected_settings (dialog);
265 display_name = get_default_display_name (settings);
267 empathy_account_settings_set_display_name_async (settings,
268 display_name, NULL, NULL);
270 g_free (display_name);
272 accounts_dialog_update_settings (dialog, settings);
275 g_object_unref (settings);
279 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
280 EmpathyAccountSettings *settings)
282 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
285 priv->setting_widget_object =
286 empathy_account_widget_new_for_protocol (settings, FALSE);
288 priv->settings_widget =
289 empathy_account_widget_get_widget (priv->setting_widget_object);
291 priv->settings_widget =
292 empathy_account_widget_get_widget (priv->setting_widget_object);
293 g_signal_connect (priv->setting_widget_object, "account-created",
294 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
295 g_signal_connect (priv->setting_widget_object, "cancelled",
296 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
298 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
299 priv->settings_widget);
300 gtk_widget_show (priv->settings_widget);
302 icon_name = empathy_account_settings_get_icon_name (settings);
304 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
305 icon_name, GTK_ICON_SIZE_DIALOG);
306 gtk_widget_set_tooltip_text (priv->image_type,
307 empathy_protocol_name_to_display_name
308 (empathy_account_settings_get_protocol (settings)));
310 accounts_dialog_update_name_label (dialog,
311 empathy_account_settings_get_display_name (settings));
315 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
317 EmpathyAccountsDialog *dialog)
319 if (empathy_account_settings_is_ready (settings))
320 account_dialog_create_settings_widget (dialog, settings);
324 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
328 GtkTreeSelection *selection;
330 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
333 view = GTK_TREE_VIEW (priv->treeview);
334 model = gtk_tree_view_get_model (view);
336 if (gtk_tree_model_get_iter_first (model, &iter))
338 selection = gtk_tree_view_get_selection (view);
339 gtk_tree_selection_select_iter (selection, &iter);
343 accounts_dialog_update_settings (dialog, NULL);
348 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
349 EmpathyAccount **account)
353 GtkTreeSelection *selection;
354 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
356 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
358 if (gtk_tree_selection_get_selected (selection, &model, &iter))
359 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
361 return *account != NULL && priv->setting_widget_object != NULL
362 && empathy_account_widget_contains_pending_changes (
363 priv->setting_widget_object);
367 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
368 EmpathyAccountsDialog *dialog)
370 TpConnectionManager *cm;
371 TpConnectionManagerProtocol *proto;
372 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
374 cm = empathy_protocol_chooser_dup_selected (
375 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
386 if (tp_connection_manager_protocol_can_register (proto))
388 gtk_widget_show (priv->radiobutton_register);
389 gtk_widget_show (priv->radiobutton_reuse);
393 gtk_widget_hide (priv->radiobutton_register);
394 gtk_widget_hide (priv->radiobutton_reuse);
400 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
404 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
406 view = GTK_TREE_VIEW (priv->treeview);
407 model = gtk_tree_view_get_model (view);
409 gtk_widget_set_sensitive (priv->button_add, FALSE);
410 gtk_widget_hide (priv->vbox_details);
411 gtk_widget_hide (priv->frame_no_protocol);
412 gtk_widget_show (priv->frame_new_account);
414 /* If we have no account, no need of a back button */
415 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
416 gtk_widget_show (priv->button_back);
418 gtk_widget_hide (priv->button_back);
420 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
421 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
423 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
424 gtk_widget_grab_focus (priv->combobox_protocol);
428 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
430 gchar *secondary_text,
431 GCallback response_callback,
433 const gchar *first_button_text,
437 GtkWidget *message_dialog;
438 const gchar *button_text;
439 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
441 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
442 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
443 GTK_MESSAGE_QUESTION,
447 gtk_message_dialog_format_secondary_text (
448 GTK_MESSAGE_DIALOG (message_dialog), secondary_text);
450 va_start (button_args, first_button_text);
451 for (button_text = first_button_text;
453 button_text = va_arg (button_args, const gchar *))
456 response_id = va_arg (button_args, gint);
458 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text, response_id);
460 va_end (button_args);
462 g_signal_connect (message_dialog, "response", response_callback, user_data);
464 gtk_widget_show (message_dialog);
468 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
472 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
473 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
475 gtk_widget_destroy (GTK_WIDGET (message_dialog));
477 if (response_id == GTK_RESPONSE_YES)
479 empathy_account_widget_discard_pending_changes (
480 priv->setting_widget_object);
481 accounts_dialog_setup_ui_to_add_account (dialog);
486 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
487 EmpathyAccountsDialog *dialog)
489 EmpathyAccount *account = NULL;
491 if (accounts_dialog_has_pending_change (dialog, &account))
493 gchar *question_dialog_primary_text = g_strdup_printf (
494 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
495 empathy_account_get_display_name (account));
497 accounts_dialog_show_question_dialog (dialog,
498 question_dialog_primary_text,
499 _("You are about to create a new account, which will discard\n"
500 "your changes. Are you sure you want to proceed?"),
501 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
503 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
504 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
506 g_free (question_dialog_primary_text);
510 accounts_dialog_setup_ui_to_add_account (dialog);
515 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
516 EmpathyAccountSettings *settings)
518 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
520 if (priv->settings_ready != NULL)
522 g_signal_handler_disconnect (priv->settings_ready,
523 priv->settings_ready_id);
524 priv->settings_ready = NULL;
525 priv->settings_ready_id = 0;
533 view = GTK_TREE_VIEW (priv->treeview);
534 model = gtk_tree_view_get_model (view);
536 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
538 /* We have configured accounts, select the first one */
539 accounts_dialog_model_select_first (dialog);
542 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
544 /* We have no account configured but we have some
545 * profiles installed. The user obviously wants to add
546 * an account. Click on the Add button for him. */
547 accounts_dialog_button_add_clicked_cb (priv->button_add,
552 /* No account and no profile, warn the user */
553 gtk_widget_hide (priv->vbox_details);
554 gtk_widget_hide (priv->frame_new_account);
555 gtk_widget_show (priv->frame_no_protocol);
556 gtk_widget_set_sensitive (priv->button_add, FALSE);
560 /* We have an account selected, destroy old settings and create a new
561 * one for the account selected */
562 gtk_widget_hide (priv->frame_new_account);
563 gtk_widget_hide (priv->frame_no_protocol);
564 gtk_widget_show (priv->vbox_details);
565 gtk_widget_set_sensitive (priv->button_add, TRUE);
567 if (priv->settings_widget)
569 gtk_widget_destroy (priv->settings_widget);
570 priv->settings_widget = NULL;
573 if (empathy_account_settings_is_ready (settings))
575 account_dialog_create_settings_widget (dialog, settings);
579 priv->settings_ready = settings;
580 priv->settings_ready_id =
581 g_signal_connect (settings, "notify::ready",
582 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
588 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
589 GtkCellEditable *editable,
591 EmpathyAccountsDialog *dialog)
593 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
595 if (priv->connecting_id)
596 g_source_remove (priv->connecting_id);
598 DEBUG ("Editing account name started; stopping flashing");
602 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
603 GtkCellRenderer *cell,
606 EmpathyAccountsDialog *dialog)
608 EmpathyAccountSettings *settings;
611 TpConnectionStatus status;
612 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
614 gtk_tree_model_get (model, iter,
616 COL_ACCOUNT_SETTINGS_POINTER, &settings,
619 icon_name = empathy_account_settings_get_icon_name (settings);
620 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
624 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
625 (status == TP_CONNECTION_STATUS_CONNECTING &&
626 !priv->connecting_show))
628 GdkPixbuf *modded_pixbuf;
630 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
633 gdk_pixbuf_get_width (pixbuf),
634 gdk_pixbuf_get_height (pixbuf));
636 gdk_pixbuf_saturate_and_pixelate (pixbuf,
640 g_object_unref (pixbuf);
641 pixbuf = modded_pixbuf;
650 g_object_unref (settings);
653 g_object_unref (pixbuf);
657 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
662 gtk_tree_model_row_changed (model, path, iter);
668 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
672 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
674 priv->connecting_show = !priv->connecting_show;
676 view = GTK_TREE_VIEW (priv->treeview);
677 model = gtk_tree_view_get_model (view);
679 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
685 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
688 EmpathyAccountsDialog *dialog)
690 EmpathyAccountSettings *settings;
692 GtkTreePath *treepath;
694 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
696 if (empathy_account_manager_get_connecting_accounts
697 (priv->account_manager) > 0)
699 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
700 (GSourceFunc) accounts_dialog_flash_connecting_cb,
704 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
705 treepath = gtk_tree_path_new_from_string (path);
706 gtk_tree_model_get_iter (model, &iter, treepath);
707 gtk_tree_model_get (model, &iter,
708 COL_ACCOUNT_SETTINGS_POINTER, &settings,
710 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
713 gtk_tree_path_free (treepath);
715 empathy_account_settings_set_display_name_async (settings, new_text,
717 g_object_set (settings, "display-name-overridden", TRUE, NULL);
718 g_object_unref (settings);
722 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
726 EmpathyAccount *account;
729 GtkTreeSelection *selection;
730 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
731 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
733 if (response_id == GTK_RESPONSE_YES)
735 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
737 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
740 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
744 g_signal_handlers_disconnect_by_func (account,
745 accounts_dialog_account_display_name_changed_cb, account_dialog);
746 empathy_account_remove_async (account, NULL, NULL);
747 g_object_unref (account);
751 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
752 accounts_dialog_model_select_first (account_dialog);
755 gtk_widget_destroy (GTK_WIDGET (message_dialog));
759 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
760 const gchar *path_string,
761 EmpathyAccountsDialog *dialog)
763 EmpathyAccount *account;
766 gchar *question_dialog_primary_text;
767 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
769 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
771 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
774 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
776 if (account == NULL || !empathy_account_is_valid (account))
778 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
779 accounts_dialog_model_select_first (dialog);
783 question_dialog_primary_text = g_strdup_printf (
784 _("You are about to remove your %s account!\n"
785 "Are you sure you want to proceed?"),
786 empathy_account_get_display_name (account));
788 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
789 _("Any associated conversations and chat rooms will NOT be "
790 "removed if you decide to proceed.\n"
792 "Should you decide to add the account back at a later time, "
793 "they will still be available."),
794 G_CALLBACK (accounts_dialog_delete_account_response_cb),
796 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
797 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
799 g_free (question_dialog_primary_text);
803 g_object_unref (account);
809 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
812 GtkTreeViewColumn *column;
813 GtkCellRenderer *cell;
814 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
816 view = GTK_TREE_VIEW (priv->treeview);
817 gtk_tree_view_set_headers_visible (view, FALSE);
820 column = gtk_tree_view_column_new ();
821 gtk_tree_view_column_set_expand (column, TRUE);
822 gtk_tree_view_append_column (view, column);
825 cell = gtk_cell_renderer_pixbuf_new ();
826 gtk_tree_view_column_pack_start (column, cell, FALSE);
827 gtk_tree_view_column_set_cell_data_func (column, cell,
828 (GtkTreeCellDataFunc)
829 accounts_dialog_model_pixbuf_data_func,
834 cell = gtk_cell_renderer_text_new ();
836 "ellipsize", PANGO_ELLIPSIZE_END,
840 gtk_tree_view_column_pack_start (column, cell, TRUE);
841 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
842 g_signal_connect (cell, "edited",
843 G_CALLBACK (accounts_dialog_name_edited_cb),
845 g_signal_connect (cell, "editing-started",
846 G_CALLBACK (accounts_dialog_name_editing_started_cb),
850 cell = empathy_cell_renderer_activatable_new ();
851 gtk_tree_view_column_pack_start (column, cell, FALSE);
853 "icon-name", GTK_STOCK_DELETE,
856 g_signal_connect (cell, "path-activated",
857 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
861 static EmpathyAccountSettings *
862 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
866 GtkTreeSelection *selection;
868 EmpathyAccountSettings *settings;
869 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
871 view = GTK_TREE_VIEW (priv->treeview);
872 selection = gtk_tree_view_get_selection (view);
874 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
877 gtk_tree_model_get (model, &iter,
878 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
884 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
885 EmpathyAccountsDialog *dialog)
887 EmpathyAccountSettings *settings;
890 gboolean is_selection;
892 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
894 settings = accounts_dialog_model_get_selected_settings (dialog);
895 accounts_dialog_update_settings (dialog, settings);
897 if (settings != NULL)
898 g_object_unref (settings);
902 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
906 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
907 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
909 gtk_widget_destroy (GTK_WIDGET (message_dialog));
911 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
913 /* The user wants to lose unsaved changes to the currently selected
914 * account and select another account. We discard the changes and
915 * select the other account. */
917 GtkTreeSelection *selection;
919 priv->force_change_row = TRUE;
920 empathy_account_widget_discard_pending_changes (
921 priv->setting_widget_object);
923 path = gtk_tree_row_reference_get_path (priv->destination_row);
924 selection = gtk_tree_view_get_selection (
925 GTK_TREE_VIEW (priv->treeview));
929 /* This will trigger a call to
930 * accounts_dialog_account_selection_change() */
931 gtk_tree_selection_select_path (selection, path);
932 gtk_tree_path_free (path);
935 gtk_tree_row_reference_free (priv->destination_row);
939 priv->force_change_row = FALSE;
944 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
947 gboolean path_currently_selected,
950 EmpathyAccount *account = NULL;
951 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
952 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
954 if (priv->force_change_row)
956 /* We came back here because the user wants to discard changes to his
957 * modified account. The changes have already been discarded so we
958 * just change the selected row. */
959 priv->force_change_row = FALSE;
963 if (accounts_dialog_has_pending_change (dialog, &account))
965 /* The currently selected account has some unsaved changes. We ask
966 * the user if he really wants to lose his changes and select another
968 gchar *question_dialog_primary_text;
969 priv->destination_row = gtk_tree_row_reference_new (model, path);
971 question_dialog_primary_text = g_strdup_printf (
972 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
973 empathy_account_get_display_name (account));
975 accounts_dialog_show_question_dialog (dialog,
976 question_dialog_primary_text,
977 _("You are about to select another account, which will discard\n"
978 "your changes. Are you sure you want to proceed?"),
979 G_CALLBACK (accounts_dialog_selection_change_response_cb),
981 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
982 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
984 g_free (question_dialog_primary_text);
995 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
998 GtkTreeSelection *selection;
999 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1001 store = gtk_list_store_new (COL_COUNT,
1002 G_TYPE_STRING, /* name */
1003 G_TYPE_UINT, /* status */
1004 EMPATHY_TYPE_ACCOUNT, /* account */
1005 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1007 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1008 GTK_TREE_MODEL (store));
1010 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1011 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1012 gtk_tree_selection_set_select_function (selection,
1013 accounts_dialog_account_selection_change, dialog, NULL);
1015 g_signal_connect (selection, "changed",
1016 G_CALLBACK (accounts_dialog_model_selection_changed),
1019 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1020 COL_NAME, GTK_SORT_ASCENDING);
1022 accounts_dialog_model_add_columns (dialog);
1024 g_object_unref (store);
1028 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1029 EmpathyAccountSettings *settings,
1033 GtkTreeSelection *selection;
1034 GtkTreeModel *model;
1036 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1038 /* Update the status in the model */
1039 view = GTK_TREE_VIEW (priv->treeview);
1040 selection = gtk_tree_view_get_selection (view);
1041 model = gtk_tree_view_get_model (view);
1043 for (ok = gtk_tree_model_get_iter_first (model, iter);
1045 ok = gtk_tree_model_iter_next (model, iter))
1047 EmpathyAccountSettings *this_settings;
1050 gtk_tree_model_get (model, iter,
1051 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1054 equal = (this_settings == settings);
1055 g_object_unref (this_settings);
1065 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1066 EmpathyAccount *account,
1070 GtkTreeSelection *selection;
1071 GtkTreeModel *model;
1073 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1075 /* Update the status in the model */
1076 view = GTK_TREE_VIEW (priv->treeview);
1077 selection = gtk_tree_view_get_selection (view);
1078 model = gtk_tree_view_get_model (view);
1080 for (ok = gtk_tree_model_get_iter_first (model, iter);
1082 ok = gtk_tree_model_iter_next (model, iter))
1084 EmpathyAccountSettings *settings;
1087 gtk_tree_model_get (model, iter,
1088 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1091 equal = empathy_account_settings_has_account (settings, account);
1092 g_object_unref (settings);
1102 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1103 EmpathyAccountSettings *settings)
1105 GtkTreeSelection *selection;
1107 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1109 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1110 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1111 gtk_tree_selection_select_iter (selection, &iter);
1114 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1115 EmpathyAccountSettings *settings)
1117 GtkTreeModel *model;
1120 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1122 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1123 name = empathy_account_settings_get_display_name (settings);
1125 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1127 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1129 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1130 COL_ACCOUNT_SETTINGS_POINTER, settings,
1135 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1136 EmpathyAccount *account,
1137 TpConnectionStatusReason reason,
1138 TpConnectionStatus current,
1139 TpConnectionStatus previous,
1140 EmpathyAccountsDialog *dialog)
1142 GtkTreeModel *model;
1145 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1147 /* Update the status in the model */
1148 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1150 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1154 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1155 COL_STATUS, current,
1158 path = gtk_tree_model_get_path (model, &iter);
1159 gtk_tree_model_row_changed (model, path, &iter);
1160 gtk_tree_path_free (path);
1163 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1165 if (!found && priv->connecting_id)
1167 g_source_remove (priv->connecting_id);
1168 priv->connecting_id = 0;
1171 if (found && !priv->connecting_id)
1172 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1173 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1178 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1182 const gchar *display_name;
1184 GtkTreeModel *model;
1185 EmpathyAccountSettings *settings;
1186 EmpathyAccount *selected_account;
1187 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1188 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1190 display_name = empathy_account_get_display_name (account);
1191 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1192 settings = accounts_dialog_model_get_selected_settings (dialog);
1193 selected_account = empathy_account_settings_get_account (settings);
1195 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1197 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1198 COL_NAME, display_name,
1202 if (selected_account == account)
1203 accounts_dialog_update_name_label (dialog, display_name);
1205 g_object_unref (settings);
1209 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1210 EmpathyAccount *account)
1212 EmpathyAccountSettings *settings;
1213 GtkTreeModel *model;
1215 TpConnectionStatus status;
1218 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1220 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1221 g_object_get (account, "connection-status", &status, NULL);
1222 name = empathy_account_get_display_name (account);
1223 enabled = empathy_account_is_enabled (account);
1225 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1226 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1228 settings = empathy_account_settings_new_for_account (account);
1230 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1233 COL_ACCOUNT_POINTER, account,
1234 COL_ACCOUNT_SETTINGS_POINTER, settings,
1237 accounts_dialog_connection_changed_cb (priv->account_manager,
1239 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1241 TP_CONNECTION_STATUS_DISCONNECTED,
1244 g_signal_connect (account, "notify::display-name",
1245 G_CALLBACK (accounts_dialog_account_display_name_changed_cb), dialog);
1247 g_object_unref (settings);
1251 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1252 EmpathyAccountSettings *settings)
1254 GtkTreeModel *model;
1256 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1258 gboolean enabled = FALSE;
1259 EmpathyAccount *account;
1260 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1262 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1263 name = empathy_account_settings_get_display_name (settings);
1265 account = empathy_account_settings_get_account (settings);
1266 if (account != NULL)
1268 enabled = empathy_account_is_enabled (account);
1269 g_object_get (account, "connection-status", &status, NULL);
1272 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1273 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1276 COL_ACCOUNT_POINTER, account,
1277 COL_ACCOUNT_SETTINGS_POINTER, settings,
1282 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1283 EmpathyAccount *account,
1284 EmpathyAccountsDialog *dialog)
1286 accounts_dialog_add_account (dialog, account);
1291 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1292 EmpathyAccount *account,
1293 EmpathyAccountsDialog *dialog)
1296 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1298 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1300 g_signal_handlers_disconnect_by_func (account,
1301 accounts_dialog_account_display_name_changed_cb, dialog);
1302 gtk_list_store_remove (GTK_LIST_STORE (
1303 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1308 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1309 EmpathyAccount *account,
1312 GtkTreeModel *model;
1313 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1315 /* Update the status in the model */
1316 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1318 DEBUG ("Account %s is now %s",
1319 empathy_account_get_display_name (account),
1320 enabled ? "enabled" : "disabled");
1324 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1325 EmpathyAccount *account,
1326 EmpathyAccountsDialog *dialog)
1328 enable_or_disable_account (dialog, account, FALSE);
1332 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1333 EmpathyAccount *account,
1334 EmpathyAccountsDialog *dialog)
1336 enable_or_disable_account (dialog, account, TRUE);
1340 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1341 EmpathyAccount *account,
1342 EmpathyAccountsDialog *dialog)
1344 EmpathyAccountSettings *settings, *selected_settings;
1345 GtkTreeModel *model;
1347 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1349 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1351 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1354 gtk_tree_model_get (model, &iter,
1355 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1358 accounts_dialog_update (dialog, settings);
1359 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1361 if (settings == selected_settings)
1362 accounts_dialog_update_name_label (dialog,
1363 empathy_account_settings_get_display_name (settings));
1366 g_object_unref (settings);
1368 if (selected_settings)
1369 g_object_unref (selected_settings);
1373 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1374 EmpathyAccountsDialog *dialog)
1376 EmpathyAccountSettings *settings;
1378 const gchar *display_name;
1379 TpConnectionManager *cm;
1380 TpConnectionManagerProtocol *proto;
1381 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1383 cm = empathy_protocol_chooser_dup_selected (
1384 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto);
1385 display_name = empathy_protocol_name_to_display_name (proto->name);
1387 if (display_name == NULL)
1388 display_name = proto->name;
1390 /* Create account */
1391 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1394 str = g_strdup_printf (_("New %s account"), display_name);
1395 settings = empathy_account_settings_new (cm->name, proto->name, str);
1399 if (tp_connection_manager_protocol_can_register (proto))
1403 active = gtk_toggle_button_get_active
1404 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1406 empathy_account_settings_set_boolean (settings, "register", TRUE);
1409 accounts_dialog_add (dialog, settings);
1410 accounts_dialog_model_set_selected (dialog, settings);
1412 g_object_unref (settings);
1413 g_object_unref (cm);
1417 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1418 EmpathyAccountsDialog *dialog)
1420 EmpathyAccountSettings *settings;
1422 settings = accounts_dialog_model_get_selected_settings (dialog);
1423 accounts_dialog_update_settings (dialog, settings);
1426 g_object_unref (settings);
1430 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1431 EmpathyAccountsDialog *dialog)
1433 empathy_url_show (button, "ghelp:empathy?accounts-window");
1437 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1441 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1443 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1445 if (response_id == GTK_RESPONSE_YES)
1446 gtk_widget_destroy (account_dialog);
1450 accounts_dialog_response_cb (GtkWidget *widget,
1452 EmpathyAccountsDialog *dialog)
1454 EmpathyAccount *account = NULL;
1456 if (accounts_dialog_has_pending_change (dialog, &account))
1458 gchar *question_dialog_primary_text;
1459 question_dialog_primary_text = g_strdup_printf (
1460 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1461 empathy_account_get_display_name (account));
1463 accounts_dialog_show_question_dialog (dialog,
1464 question_dialog_primary_text,
1465 _("You are about to close the window, which will discard\n"
1466 "your changes. Are you sure you want to proceed?"),
1467 G_CALLBACK (accounts_dialog_close_response_cb),
1469 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1470 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1472 g_free (question_dialog_primary_text);
1474 else if (response == GTK_RESPONSE_CLOSE)
1475 gtk_widget_destroy (widget);
1479 accounts_dialog_destroy_cb (GtkObject *obj,
1480 EmpathyAccountsDialog *dialog)
1484 g_object_unref (dialog);
1488 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1489 EmpathyAccount *account)
1491 GtkTreeSelection *selection;
1493 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1495 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1496 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1497 gtk_tree_selection_select_iter (selection, &iter);
1501 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1503 EmpathyAccountsDialog *dialog)
1505 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1507 if (empathy_connection_managers_is_ready (cms))
1509 accounts_dialog_update_settings (dialog, NULL);
1511 if (priv->initial_selection != NULL)
1513 accounts_dialog_set_selected_account
1514 (dialog, priv->initial_selection);
1515 g_object_unref (priv->initial_selection);
1516 priv->initial_selection = NULL;
1522 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1526 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1528 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1530 gui = empathy_builder_get_file (filename,
1531 "accounts_dialog", &priv->window,
1532 "vbox_details", &priv->vbox_details,
1533 "frame_no_protocol", &priv->frame_no_protocol,
1534 "alignment_settings", &priv->alignment_settings,
1535 "treeview", &priv->treeview,
1536 "frame_new_account", &priv->frame_new_account,
1537 "hbox_type", &priv->hbox_type,
1538 "button_create", &priv->button_create,
1539 "button_back", &priv->button_back,
1540 "radiobutton_reuse", &priv->radiobutton_reuse,
1541 "radiobutton_register", &priv->radiobutton_register,
1542 "image_type", &priv->image_type,
1543 "label_name", &priv->label_name,
1544 "button_add", &priv->button_add,
1548 empathy_builder_connect (gui, dialog,
1549 "accounts_dialog", "response", accounts_dialog_response_cb,
1550 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1551 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1552 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1553 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1554 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1557 g_object_unref (gui);
1559 priv->combobox_protocol = empathy_protocol_chooser_new ();
1560 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1561 priv->combobox_protocol,
1563 gtk_widget_show (priv->combobox_protocol);
1564 g_signal_connect (priv->combobox_protocol, "changed",
1565 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1568 if (priv->parent_window)
1569 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1570 priv->parent_window);
1574 do_dispose (GObject *obj)
1576 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1577 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1579 /* Disconnect signals */
1580 g_signal_handlers_disconnect_by_func (priv->account_manager,
1581 accounts_dialog_account_added_cb,
1583 g_signal_handlers_disconnect_by_func (priv->account_manager,
1584 accounts_dialog_account_removed_cb,
1586 g_signal_handlers_disconnect_by_func (priv->account_manager,
1587 accounts_dialog_account_enabled_cb,
1589 g_signal_handlers_disconnect_by_func (priv->account_manager,
1590 accounts_dialog_account_disabled_cb,
1592 g_signal_handlers_disconnect_by_func (priv->account_manager,
1593 accounts_dialog_account_changed_cb,
1595 g_signal_handlers_disconnect_by_func (priv->account_manager,
1596 accounts_dialog_connection_changed_cb,
1599 if (priv->connecting_id)
1600 g_source_remove (priv->connecting_id);
1602 if (priv->account_manager != NULL)
1604 g_object_unref (priv->account_manager);
1605 priv->account_manager = NULL;
1608 if (priv->cms != NULL)
1610 g_object_unref (priv->cms);
1614 if (priv->initial_selection != NULL)
1615 g_object_unref (priv->initial_selection);
1616 priv->initial_selection = NULL;
1618 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1622 do_constructor (GType type,
1624 GObjectConstructParam *props)
1628 if (dialog_singleton)
1630 retval = G_OBJECT (dialog_singleton);
1631 g_object_ref (retval);
1636 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1637 (type, n_props, props);
1639 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1640 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1647 do_get_property (GObject *object,
1652 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1654 switch (property_id)
1657 g_value_set_object (value, priv->parent_window);
1660 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1665 do_set_property (GObject *object,
1667 const GValue *value,
1670 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1672 switch (property_id)
1675 priv->parent_window = g_value_get_object (value);
1678 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1683 do_constructed (GObject *object)
1685 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1686 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1687 GList *accounts, *l;
1688 gboolean import_asked;
1690 accounts_dialog_build_ui (dialog);
1692 /* Set up signalling */
1693 priv->account_manager = empathy_account_manager_dup_singleton ();
1695 g_signal_connect (priv->account_manager, "account-created",
1696 G_CALLBACK (accounts_dialog_account_added_cb),
1698 g_signal_connect (priv->account_manager, "account-deleted",
1699 G_CALLBACK (accounts_dialog_account_removed_cb),
1701 g_signal_connect (priv->account_manager, "account-enabled",
1702 G_CALLBACK (accounts_dialog_account_enabled_cb),
1704 g_signal_connect (priv->account_manager, "account-disabled",
1705 G_CALLBACK (accounts_dialog_account_disabled_cb),
1707 g_signal_connect (priv->account_manager, "account-changed",
1708 G_CALLBACK (accounts_dialog_account_changed_cb),
1710 g_signal_connect (priv->account_manager, "account-connection-changed",
1711 G_CALLBACK (accounts_dialog_connection_changed_cb),
1714 accounts_dialog_model_setup (dialog);
1716 /* Add existing accounts */
1717 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1718 for (l = accounts; l; l = l->next)
1720 accounts_dialog_add_account (dialog, l->data);
1721 g_object_unref (l->data);
1723 g_list_free (accounts);
1725 priv->cms = empathy_connection_managers_dup_singleton ();
1726 if (!empathy_connection_managers_is_ready (priv->cms))
1727 g_signal_connect (priv->cms, "notify::ready",
1728 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1730 accounts_dialog_model_select_first (dialog);
1732 empathy_conf_get_bool (empathy_conf_get (),
1733 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1736 if (empathy_import_accounts_to_import ())
1741 GtkWidget *import_dialog;
1743 empathy_conf_set_bool (empathy_conf_get (),
1744 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1745 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1747 gtk_widget_show (import_dialog);
1753 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1755 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1756 GParamSpec *param_spec;
1758 oclass->constructor = do_constructor;
1759 oclass->dispose = do_dispose;
1760 oclass->constructed = do_constructed;
1761 oclass->set_property = do_set_property;
1762 oclass->get_property = do_get_property;
1764 param_spec = g_param_spec_object ("parent",
1765 "parent", "The parent window",
1767 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1768 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1770 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1774 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1776 EmpathyAccountsDialogPriv *priv;
1778 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1779 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1780 EmpathyAccountsDialogPriv);
1781 dialog->priv = priv;
1784 /* public methods */
1787 empathy_accounts_dialog_show (GtkWindow *parent,
1788 EmpathyAccount *selected_account)
1790 EmpathyAccountsDialog *dialog;
1791 EmpathyAccountsDialogPriv *priv;
1793 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1794 "parent", parent, NULL);
1796 priv = GET_PRIV (dialog);
1798 if (selected_account)
1800 if (empathy_connection_managers_is_ready (priv->cms))
1801 accounts_dialog_set_selected_account (dialog, selected_account);
1803 /* save the selection to set it later when the cms
1806 priv->initial_selection = g_object_ref (selected_account);
1809 gtk_window_present (GTK_WINDOW (priv->window));
1811 return priv->window;