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;
81 GtkWidget *button_import;
83 GtkWidget *frame_new_account;
84 GtkWidget *combobox_protocol;
86 GtkWidget *button_create;
87 GtkWidget *button_back;
88 GtkWidget *radiobutton_reuse;
89 GtkWidget *radiobutton_register;
91 GtkWidget *image_type;
92 GtkWidget *label_name;
93 GtkWidget *label_type;
94 GtkWidget *settings_widget;
96 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
97 * his GtkWidget. It is the only reliable source we can query to know if
98 * there are any unsaved changes to the currently selected account. We can't
99 * look at the account settings because it does not contain everything that
100 * can be changed using the EmpathyAccountWidget. For instance, it does not
101 * contain the state of the "Enabled" checkbox. */
102 EmpathyAccountWidget *setting_widget_object;
104 gboolean connecting_show;
107 gulong settings_ready_id;
108 EmpathyAccountSettings *settings_ready;
110 EmpathyAccountManager *account_manager;
111 EmpathyConnectionManagers *cms;
113 GtkWindow *parent_window;
114 EmpathyAccount *initial_selection;
116 /* Those are needed when changing the selected row. When a user selects
117 * another account and there are unsaved changes on the currently selected
118 * one, a confirmation message box is presented to him. Since his answer
119 * is retrieved asynchronously, we keep some information as member of the
120 * EmpathyAccountsDialog object. */
121 gboolean force_change_row;
122 GtkTreeRowReference *destination_row;
125 } EmpathyAccountsDialogPriv;
131 COL_ACCOUNT_SETTINGS_POINTER,
139 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
140 EmpathyAccountsDialog *dialog);
142 static gboolean accounts_dialog_get_settings_iter (
143 EmpathyAccountsDialog *dialog,
144 EmpathyAccountSettings *settings,
147 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
149 static void accounts_dialog_update (EmpathyAccountsDialog *dialog,
150 EmpathyAccountSettings *settings);
152 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
153 EmpathyAccountSettings *settings);
156 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
157 const gchar *display_name)
160 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
162 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
163 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
169 empathy_account_dialog_widget_cancelled_cb (
170 EmpathyAccountWidget *widget_object,
171 EmpathyAccountsDialog *dialog)
175 GtkTreeSelection *selection;
177 EmpathyAccountSettings *settings;
178 EmpathyAccount *account;
179 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
181 view = GTK_TREE_VIEW (priv->treeview);
182 selection = gtk_tree_view_get_selection (view);
184 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
187 gtk_tree_model_get (model, &iter,
188 COL_ACCOUNT_SETTINGS_POINTER, &settings,
189 COL_ACCOUNT_POINTER, &account, -1);
191 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
195 /* We were creating an account. We remove the selected row */
196 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
200 /* We were modifying an account. We discard the changes by reloading the
201 * settings and the UI. */
202 accounts_dialog_update_settings (dialog, settings);
203 g_object_unref (account);
206 if (settings != NULL)
207 g_object_unref (settings);
211 get_default_display_name (EmpathyAccountSettings *settings)
213 const gchar *login_id;
214 const gchar *protocol, *p;
215 gchar *default_display_name;
217 login_id = empathy_account_settings_get_string (settings, "account");
218 protocol = empathy_account_settings_get_protocol (settings);
220 if ((p = empathy_protocol_name_to_display_name (protocol)) != NULL)
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 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
306 /* show the default icon; keep this in sync with the default
307 * one in empathy-accounts-dialog.ui.
309 icon_name = GTK_STOCK_CUT;
311 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
312 icon_name, GTK_ICON_SIZE_DIALOG);
313 gtk_widget_set_tooltip_text (priv->image_type,
314 empathy_protocol_name_to_display_name
315 (empathy_account_settings_get_protocol (settings)));
316 gtk_widget_show (priv->image_type);
318 accounts_dialog_update_name_label (dialog,
319 empathy_account_settings_get_display_name (settings));
323 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
325 EmpathyAccountsDialog *dialog)
327 if (empathy_account_settings_is_ready (settings))
328 account_dialog_create_settings_widget (dialog, settings);
332 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
336 GtkTreeSelection *selection;
338 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
341 view = GTK_TREE_VIEW (priv->treeview);
342 model = gtk_tree_view_get_model (view);
344 if (gtk_tree_model_get_iter_first (model, &iter))
346 selection = gtk_tree_view_get_selection (view);
347 gtk_tree_selection_select_iter (selection, &iter);
351 accounts_dialog_update_settings (dialog, NULL);
356 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
357 EmpathyAccount **account)
361 GtkTreeSelection *selection;
362 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
364 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
366 if (gtk_tree_selection_get_selected (selection, &model, &iter))
367 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
369 return *account != NULL && priv->setting_widget_object != NULL
370 && empathy_account_widget_contains_pending_changes (
371 priv->setting_widget_object);
375 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
376 EmpathyAccountsDialog *dialog)
378 TpConnectionManager *cm;
379 TpConnectionManagerProtocol *proto;
381 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
383 cm = empathy_protocol_chooser_dup_selected (
384 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
396 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
398 gtk_widget_show (priv->radiobutton_register);
399 gtk_widget_show (priv->radiobutton_reuse);
403 gtk_widget_hide (priv->radiobutton_register);
404 gtk_widget_hide (priv->radiobutton_reuse);
407 gtk_widget_hide (priv->radiobutton_register);
408 gtk_widget_hide (priv->radiobutton_reuse);
415 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
419 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
421 view = GTK_TREE_VIEW (priv->treeview);
422 model = gtk_tree_view_get_model (view);
424 gtk_widget_set_sensitive (priv->button_add, FALSE);
425 gtk_widget_hide (priv->vbox_details);
426 gtk_widget_hide (priv->frame_no_protocol);
427 gtk_widget_show (priv->frame_new_account);
429 /* If we have no account, no need of a back button */
430 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
431 gtk_widget_show (priv->button_back);
433 gtk_widget_hide (priv->button_back);
435 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
436 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
438 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
439 gtk_widget_grab_focus (priv->combobox_protocol);
443 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
444 const gchar *primary_text,
445 const gchar *secondary_text,
446 GCallback response_callback,
448 const gchar *first_button_text,
452 GtkWidget *message_dialog;
453 const gchar *button_text;
454 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
456 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
457 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
458 GTK_MESSAGE_QUESTION,
462 gtk_message_dialog_format_secondary_text (
463 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
465 va_start (button_args, first_button_text);
466 for (button_text = first_button_text;
468 button_text = va_arg (button_args, const gchar *))
471 response_id = va_arg (button_args, gint);
473 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
476 va_end (button_args);
478 g_signal_connect (message_dialog, "response", response_callback, user_data);
480 gtk_widget_show (message_dialog);
484 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
488 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
489 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
491 gtk_widget_destroy (GTK_WIDGET (message_dialog));
493 if (response_id == GTK_RESPONSE_YES)
495 empathy_account_widget_discard_pending_changes (
496 priv->setting_widget_object);
497 accounts_dialog_setup_ui_to_add_account (dialog);
502 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
503 EmpathyAccountsDialog *dialog)
505 EmpathyAccount *account = NULL;
507 if (accounts_dialog_has_pending_change (dialog, &account))
509 gchar *question_dialog_primary_text = g_strdup_printf (
510 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
511 empathy_account_get_display_name (account));
513 accounts_dialog_show_question_dialog (dialog,
514 question_dialog_primary_text,
515 _("You are about to create a new account, which will discard\n"
516 "your changes. Are you sure you want to proceed?"),
517 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
519 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
520 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
522 g_free (question_dialog_primary_text);
526 accounts_dialog_setup_ui_to_add_account (dialog);
531 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
532 EmpathyAccountSettings *settings)
534 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
536 if (priv->settings_ready != NULL)
538 g_signal_handler_disconnect (priv->settings_ready,
539 priv->settings_ready_id);
540 priv->settings_ready = NULL;
541 priv->settings_ready_id = 0;
549 view = GTK_TREE_VIEW (priv->treeview);
550 model = gtk_tree_view_get_model (view);
552 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
554 /* We have configured accounts, select the first one */
555 accounts_dialog_model_select_first (dialog);
558 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
560 /* We have no account configured but we have some
561 * profiles installed. The user obviously wants to add
562 * an account. Click on the Add button for him. */
563 accounts_dialog_button_add_clicked_cb (priv->button_add,
568 /* No account and no profile, warn the user */
569 gtk_widget_hide (priv->vbox_details);
570 gtk_widget_hide (priv->frame_new_account);
571 gtk_widget_show (priv->frame_no_protocol);
572 gtk_widget_set_sensitive (priv->button_add, FALSE);
576 /* We have an account selected, destroy old settings and create a new
577 * one for the account selected */
578 gtk_widget_hide (priv->frame_new_account);
579 gtk_widget_hide (priv->frame_no_protocol);
580 gtk_widget_show (priv->vbox_details);
581 gtk_widget_set_sensitive (priv->button_add, TRUE);
583 if (priv->settings_widget)
585 gtk_widget_destroy (priv->settings_widget);
586 priv->settings_widget = NULL;
589 if (empathy_account_settings_is_ready (settings))
591 account_dialog_create_settings_widget (dialog, settings);
595 priv->settings_ready = settings;
596 priv->settings_ready_id =
597 g_signal_connect (settings, "notify::ready",
598 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
604 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
605 GtkCellEditable *editable,
607 EmpathyAccountsDialog *dialog)
609 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
611 if (priv->connecting_id)
612 g_source_remove (priv->connecting_id);
614 DEBUG ("Editing account name started; stopping flashing");
618 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
619 GtkCellRenderer *cell,
622 EmpathyAccountsDialog *dialog)
624 EmpathyAccountSettings *settings;
627 TpConnectionStatus status;
628 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
630 gtk_tree_model_get (model, iter,
632 COL_ACCOUNT_SETTINGS_POINTER, &settings,
635 icon_name = empathy_account_settings_get_icon_name (settings);
636 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
640 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
641 (status == TP_CONNECTION_STATUS_CONNECTING &&
642 !priv->connecting_show))
644 GdkPixbuf *modded_pixbuf;
646 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
649 gdk_pixbuf_get_width (pixbuf),
650 gdk_pixbuf_get_height (pixbuf));
652 gdk_pixbuf_saturate_and_pixelate (pixbuf,
656 g_object_unref (pixbuf);
657 pixbuf = modded_pixbuf;
666 g_object_unref (settings);
669 g_object_unref (pixbuf);
673 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
678 gtk_tree_model_row_changed (model, path, iter);
684 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
688 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
690 priv->connecting_show = !priv->connecting_show;
692 view = GTK_TREE_VIEW (priv->treeview);
693 model = gtk_tree_view_get_model (view);
695 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
701 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
704 EmpathyAccountsDialog *dialog)
706 EmpathyAccountSettings *settings;
708 GtkTreePath *treepath;
710 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
712 if (empathy_account_manager_get_connecting_accounts
713 (priv->account_manager) > 0)
715 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
716 (GSourceFunc) accounts_dialog_flash_connecting_cb,
720 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
721 treepath = gtk_tree_path_new_from_string (path);
722 gtk_tree_model_get_iter (model, &iter, treepath);
723 gtk_tree_model_get (model, &iter,
724 COL_ACCOUNT_SETTINGS_POINTER, &settings,
726 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
729 gtk_tree_path_free (treepath);
731 empathy_account_settings_set_display_name_async (settings, new_text,
733 g_object_set (settings, "display-name-overridden", TRUE, NULL);
734 g_object_unref (settings);
738 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
742 EmpathyAccount *account;
745 GtkTreeSelection *selection;
746 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
747 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
749 if (response_id == GTK_RESPONSE_YES)
751 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
753 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
756 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
760 empathy_account_remove_async (account, NULL, NULL);
761 g_object_unref (account);
765 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
766 accounts_dialog_model_select_first (account_dialog);
769 gtk_widget_destroy (GTK_WIDGET (message_dialog));
773 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
774 const gchar *path_string,
775 EmpathyAccountsDialog *dialog)
777 EmpathyAccount *account;
780 gchar *question_dialog_primary_text;
781 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
783 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
785 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
788 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
790 if (account == NULL || !empathy_account_is_valid (account))
792 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
793 accounts_dialog_model_select_first (dialog);
797 question_dialog_primary_text = g_strdup_printf (
799 _("You are about to remove your %s account!\n"
800 "Are you sure you want to proceed?"),
802 /* Translators: this is used only when built on a moblin platform */
803 _("Do you want to remove %s from your computer?"),
804 #endif /* HAVE_MOBLIN */
805 empathy_account_get_display_name (account));
807 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
809 _("Any associated conversations and chat rooms will NOT be "
810 "removed if you decide to proceed.\n"
812 "Should you decide to add the account back at a later time, "
813 "they will still be available."),
815 /* Translators: this is used only when built on a moblin platform */
816 _("This will not remove your account on the server."),
817 #endif /* HAVE_MOBLIN */
818 G_CALLBACK (accounts_dialog_delete_account_response_cb),
820 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
821 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
823 g_free (question_dialog_primary_text);
827 g_object_unref (account);
833 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
836 GtkTreeViewColumn *column;
837 GtkCellRenderer *cell;
838 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
840 view = GTK_TREE_VIEW (priv->treeview);
841 gtk_tree_view_set_headers_visible (view, FALSE);
844 column = gtk_tree_view_column_new ();
845 gtk_tree_view_column_set_expand (column, TRUE);
846 gtk_tree_view_append_column (view, column);
849 cell = gtk_cell_renderer_pixbuf_new ();
850 gtk_tree_view_column_pack_start (column, cell, FALSE);
851 gtk_tree_view_column_set_cell_data_func (column, cell,
852 (GtkTreeCellDataFunc)
853 accounts_dialog_model_pixbuf_data_func,
857 g_object_set (cell, "ypad", 4, NULL);
861 cell = gtk_cell_renderer_text_new ();
863 "ellipsize", PANGO_ELLIPSIZE_END,
867 gtk_tree_view_column_pack_start (column, cell, TRUE);
868 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
869 g_signal_connect (cell, "edited",
870 G_CALLBACK (accounts_dialog_name_edited_cb),
872 g_signal_connect (cell, "editing-started",
873 G_CALLBACK (accounts_dialog_name_editing_started_cb),
877 cell = empathy_cell_renderer_activatable_new ();
878 gtk_tree_view_column_pack_start (column, cell, FALSE);
880 "icon-name", GTK_STOCK_DELETE,
882 "show-on-select", TRUE,
886 g_signal_connect (cell, "path-activated",
887 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
891 static EmpathyAccountSettings *
892 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
896 GtkTreeSelection *selection;
898 EmpathyAccountSettings *settings;
899 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
901 view = GTK_TREE_VIEW (priv->treeview);
902 selection = gtk_tree_view_get_selection (view);
904 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
907 gtk_tree_model_get (model, &iter,
908 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
914 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
915 EmpathyAccountsDialog *dialog)
917 EmpathyAccountSettings *settings;
920 gboolean is_selection;
922 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
924 settings = accounts_dialog_model_get_selected_settings (dialog);
925 accounts_dialog_update_settings (dialog, settings);
927 if (settings != NULL)
928 g_object_unref (settings);
932 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
936 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
937 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
939 gtk_widget_destroy (GTK_WIDGET (message_dialog));
941 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
943 /* The user wants to lose unsaved changes to the currently selected
944 * account and select another account. We discard the changes and
945 * select the other account. */
947 GtkTreeSelection *selection;
949 priv->force_change_row = TRUE;
950 empathy_account_widget_discard_pending_changes (
951 priv->setting_widget_object);
953 path = gtk_tree_row_reference_get_path (priv->destination_row);
954 selection = gtk_tree_view_get_selection (
955 GTK_TREE_VIEW (priv->treeview));
959 /* This will trigger a call to
960 * accounts_dialog_account_selection_change() */
961 gtk_tree_selection_select_path (selection, path);
962 gtk_tree_path_free (path);
965 gtk_tree_row_reference_free (priv->destination_row);
969 priv->force_change_row = FALSE;
974 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
977 gboolean path_currently_selected,
980 EmpathyAccount *account = NULL;
981 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
982 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
984 if (priv->force_change_row)
986 /* We came back here because the user wants to discard changes to his
987 * modified account. The changes have already been discarded so we
988 * just change the selected row. */
989 priv->force_change_row = FALSE;
993 if (accounts_dialog_has_pending_change (dialog, &account))
995 /* The currently selected account has some unsaved changes. We ask
996 * the user if he really wants to lose his changes and select another
998 gchar *question_dialog_primary_text;
999 priv->destination_row = gtk_tree_row_reference_new (model, path);
1001 question_dialog_primary_text = g_strdup_printf (
1002 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1003 empathy_account_get_display_name (account));
1005 accounts_dialog_show_question_dialog (dialog,
1006 question_dialog_primary_text,
1007 _("You are about to select another account, which will discard\n"
1008 "your changes. Are you sure you want to proceed?"),
1009 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1011 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1012 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1014 g_free (question_dialog_primary_text);
1025 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1027 GtkListStore *store;
1028 GtkTreeSelection *selection;
1029 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1031 store = gtk_list_store_new (COL_COUNT,
1032 G_TYPE_STRING, /* name */
1033 G_TYPE_UINT, /* status */
1034 EMPATHY_TYPE_ACCOUNT, /* account */
1035 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1037 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1038 GTK_TREE_MODEL (store));
1040 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1041 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1042 gtk_tree_selection_set_select_function (selection,
1043 accounts_dialog_account_selection_change, dialog, NULL);
1045 g_signal_connect (selection, "changed",
1046 G_CALLBACK (accounts_dialog_model_selection_changed),
1049 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1050 COL_NAME, GTK_SORT_ASCENDING);
1052 accounts_dialog_model_add_columns (dialog);
1054 g_object_unref (store);
1058 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1059 EmpathyAccountSettings *settings,
1063 GtkTreeSelection *selection;
1064 GtkTreeModel *model;
1066 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1068 /* Update the status in the model */
1069 view = GTK_TREE_VIEW (priv->treeview);
1070 selection = gtk_tree_view_get_selection (view);
1071 model = gtk_tree_view_get_model (view);
1073 for (ok = gtk_tree_model_get_iter_first (model, iter);
1075 ok = gtk_tree_model_iter_next (model, iter))
1077 EmpathyAccountSettings *this_settings;
1080 gtk_tree_model_get (model, iter,
1081 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1084 equal = (this_settings == settings);
1085 g_object_unref (this_settings);
1095 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1096 EmpathyAccount *account,
1100 GtkTreeSelection *selection;
1101 GtkTreeModel *model;
1103 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1105 /* Update the status in the model */
1106 view = GTK_TREE_VIEW (priv->treeview);
1107 selection = gtk_tree_view_get_selection (view);
1108 model = gtk_tree_view_get_model (view);
1110 for (ok = gtk_tree_model_get_iter_first (model, iter);
1112 ok = gtk_tree_model_iter_next (model, iter))
1114 EmpathyAccountSettings *settings;
1117 gtk_tree_model_get (model, iter,
1118 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1121 equal = empathy_account_settings_has_account (settings, account);
1122 g_object_unref (settings);
1132 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1133 EmpathyAccountSettings *settings)
1135 GtkTreeSelection *selection;
1137 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1139 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1140 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1141 gtk_tree_selection_select_iter (selection, &iter);
1144 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1145 EmpathyAccountSettings *settings)
1147 GtkTreeModel *model;
1150 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1152 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1153 name = empathy_account_settings_get_display_name (settings);
1155 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1157 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1159 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1160 COL_ACCOUNT_SETTINGS_POINTER, settings,
1165 accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
1166 EmpathyAccount *account,
1167 TpConnectionStatusReason reason,
1168 TpConnectionStatus current,
1169 TpConnectionStatus previous,
1170 EmpathyAccountsDialog *dialog)
1172 GtkTreeModel *model;
1175 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1177 /* Update the status in the model */
1178 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1180 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1184 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1185 COL_STATUS, current,
1188 path = gtk_tree_model_get_path (model, &iter);
1189 gtk_tree_model_row_changed (model, path, &iter);
1190 gtk_tree_path_free (path);
1193 found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
1195 if (!found && priv->connecting_id)
1197 g_source_remove (priv->connecting_id);
1198 priv->connecting_id = 0;
1201 if (found && !priv->connecting_id)
1202 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1203 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1208 accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account,
1212 const gchar *display_name;
1214 GtkTreeModel *model;
1215 EmpathyAccountSettings *settings;
1216 EmpathyAccount *selected_account;
1217 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1218 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1220 display_name = empathy_account_get_display_name (account);
1221 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1222 settings = accounts_dialog_model_get_selected_settings (dialog);
1223 if (settings == NULL)
1226 selected_account = empathy_account_settings_get_account (settings);
1228 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1230 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1231 COL_NAME, display_name,
1235 if (selected_account == account)
1236 accounts_dialog_update_name_label (dialog, display_name);
1238 g_object_unref (settings);
1242 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1243 EmpathyAccount *account)
1245 EmpathyAccountSettings *settings;
1246 GtkTreeModel *model;
1248 TpConnectionStatus status;
1251 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1253 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1254 g_object_get (account, "connection-status", &status, NULL);
1255 name = empathy_account_get_display_name (account);
1256 enabled = empathy_account_is_enabled (account);
1258 settings = empathy_account_settings_new_for_account (account);
1260 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1261 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1263 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1266 COL_ACCOUNT_POINTER, account,
1267 COL_ACCOUNT_SETTINGS_POINTER, settings,
1270 accounts_dialog_connection_changed_cb (priv->account_manager,
1272 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1274 TP_CONNECTION_STATUS_DISCONNECTED,
1277 empathy_signal_connect_weak (account, "notify::display-name",
1278 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1281 g_object_unref (settings);
1285 accounts_dialog_update (EmpathyAccountsDialog *dialog,
1286 EmpathyAccountSettings *settings)
1288 GtkTreeModel *model;
1290 TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED;
1292 gboolean enabled = FALSE;
1293 EmpathyAccount *account;
1294 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1296 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1297 name = empathy_account_settings_get_display_name (settings);
1299 account = empathy_account_settings_get_account (settings);
1300 if (account != NULL)
1302 enabled = empathy_account_is_enabled (account);
1303 g_object_get (account, "connection-status", &status, NULL);
1306 accounts_dialog_get_settings_iter (dialog, settings, &iter);
1307 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1310 COL_ACCOUNT_POINTER, account,
1311 COL_ACCOUNT_SETTINGS_POINTER, settings,
1316 accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
1317 EmpathyAccount *account,
1318 EmpathyAccountsDialog *dialog)
1320 accounts_dialog_add_account (dialog, account);
1325 accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
1326 EmpathyAccount *account,
1327 EmpathyAccountsDialog *dialog)
1330 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1332 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1334 gtk_list_store_remove (GTK_LIST_STORE (
1335 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1340 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1341 EmpathyAccount *account,
1344 GtkTreeModel *model;
1345 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1347 /* Update the status in the model */
1348 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1350 DEBUG ("Account %s is now %s",
1351 empathy_account_get_display_name (account),
1352 enabled ? "enabled" : "disabled");
1356 accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
1357 EmpathyAccount *account,
1358 EmpathyAccountsDialog *dialog)
1360 enable_or_disable_account (dialog, account, FALSE);
1364 accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
1365 EmpathyAccount *account,
1366 EmpathyAccountsDialog *dialog)
1368 enable_or_disable_account (dialog, account, TRUE);
1372 accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
1373 EmpathyAccount *account,
1374 EmpathyAccountsDialog *dialog)
1376 EmpathyAccountSettings *settings, *selected_settings;
1377 GtkTreeModel *model;
1379 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1381 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1383 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1386 gtk_tree_model_get (model, &iter,
1387 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1390 accounts_dialog_update (dialog, settings);
1391 selected_settings = accounts_dialog_model_get_selected_settings (dialog);
1393 if (settings == selected_settings)
1394 accounts_dialog_update_name_label (dialog,
1395 empathy_account_settings_get_display_name (settings));
1398 g_object_unref (settings);
1400 if (selected_settings)
1401 g_object_unref (selected_settings);
1405 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1406 EmpathyAccountsDialog *dialog)
1408 EmpathyAccountSettings *settings;
1410 const gchar *display_name;
1411 TpConnectionManager *cm;
1412 TpConnectionManagerProtocol *proto;
1413 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1416 cm = empathy_protocol_chooser_dup_selected (
1417 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1419 display_name = empathy_protocol_name_to_display_name (
1420 is_gtalk ? "gtalk" : proto->name);
1422 if (display_name == NULL)
1423 display_name = proto->name;
1425 /* Create account */
1426 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1429 str = g_strdup_printf (_("New %s account"), display_name);
1430 settings = empathy_account_settings_new (cm->name, proto->name, str);
1435 if (tp_connection_manager_protocol_can_register (proto))
1439 active = gtk_toggle_button_get_active
1440 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1442 empathy_account_settings_set_boolean (settings, "register", TRUE);
1447 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1450 accounts_dialog_add (dialog, settings);
1451 accounts_dialog_model_set_selected (dialog, settings);
1453 g_object_unref (settings);
1454 g_object_unref (cm);
1458 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1459 EmpathyAccountsDialog *dialog)
1461 EmpathyAccountSettings *settings;
1463 settings = accounts_dialog_model_get_selected_settings (dialog);
1464 accounts_dialog_update_settings (dialog, settings);
1467 g_object_unref (settings);
1471 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1472 EmpathyAccountsDialog *dialog)
1474 empathy_url_show (button, "ghelp:empathy?accounts-window");
1478 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1479 EmpathyAccountsDialog *dialog)
1481 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1482 GtkWidget *import_dialog;
1484 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1486 gtk_widget_show (import_dialog);
1490 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1494 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1496 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1498 if (response_id == GTK_RESPONSE_YES)
1499 gtk_widget_destroy (account_dialog);
1503 accounts_dialog_response_cb (GtkWidget *widget,
1505 EmpathyAccountsDialog *dialog)
1507 EmpathyAccount *account = NULL;
1509 if (accounts_dialog_has_pending_change (dialog, &account))
1511 gchar *question_dialog_primary_text;
1512 question_dialog_primary_text = g_strdup_printf (
1513 PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
1514 empathy_account_get_display_name (account));
1516 accounts_dialog_show_question_dialog (dialog,
1517 question_dialog_primary_text,
1518 _("You are about to close the window, which will discard\n"
1519 "your changes. Are you sure you want to proceed?"),
1520 G_CALLBACK (accounts_dialog_close_response_cb),
1522 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1523 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1525 g_free (question_dialog_primary_text);
1527 else if (response == GTK_RESPONSE_CLOSE ||
1528 response == GTK_RESPONSE_DELETE_EVENT)
1529 gtk_widget_destroy (widget);
1533 accounts_dialog_delete_event_cb (GtkWidget *widget,
1535 EmpathyAccountsDialog *dialog)
1537 /* we maunally handle responses to delete events */
1542 accounts_dialog_destroy_cb (GtkObject *obj,
1543 EmpathyAccountsDialog *dialog)
1547 g_object_unref (dialog);
1551 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1552 EmpathyAccount *account)
1554 GtkTreeSelection *selection;
1556 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1558 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1559 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1560 gtk_tree_selection_select_iter (selection, &iter);
1564 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1566 EmpathyAccountsDialog *dialog)
1568 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1570 if (empathy_connection_managers_is_ready (cms))
1572 accounts_dialog_update_settings (dialog, NULL);
1574 if (priv->initial_selection != NULL)
1576 accounts_dialog_set_selected_account
1577 (dialog, priv->initial_selection);
1578 g_object_unref (priv->initial_selection);
1579 priv->initial_selection = NULL;
1585 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1587 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1588 GList *accounts, *l;
1590 g_signal_connect (priv->account_manager, "account-created",
1591 G_CALLBACK (accounts_dialog_account_added_cb),
1593 g_signal_connect (priv->account_manager, "account-deleted",
1594 G_CALLBACK (accounts_dialog_account_removed_cb),
1596 g_signal_connect (priv->account_manager, "account-enabled",
1597 G_CALLBACK (accounts_dialog_account_enabled_cb),
1599 g_signal_connect (priv->account_manager, "account-disabled",
1600 G_CALLBACK (accounts_dialog_account_disabled_cb),
1602 g_signal_connect (priv->account_manager, "account-changed",
1603 G_CALLBACK (accounts_dialog_account_changed_cb),
1605 g_signal_connect (priv->account_manager, "account-connection-changed",
1606 G_CALLBACK (accounts_dialog_connection_changed_cb),
1609 /* Add existing accounts */
1610 accounts = empathy_account_manager_dup_accounts (priv->account_manager);
1611 for (l = accounts; l; l = l->next)
1613 accounts_dialog_add_account (dialog, l->data);
1614 g_object_unref (l->data);
1616 g_list_free (accounts);
1618 priv->cms = empathy_connection_managers_dup_singleton ();
1619 if (!empathy_connection_managers_is_ready (priv->cms))
1620 g_signal_connect (priv->cms, "notify::ready",
1621 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1623 accounts_dialog_model_select_first (dialog);
1627 accounts_dialog_manager_ready_cb (EmpathyAccountManager *manager,
1631 if (!empathy_account_manager_is_ready (manager))
1634 accounts_dialog_accounts_setup (user_data);
1638 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1642 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1644 GtkWidget *action_area;
1647 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1649 gui = empathy_builder_get_file (filename,
1650 "accounts_dialog", &priv->window,
1651 "vbox_details", &priv->vbox_details,
1652 "frame_no_protocol", &priv->frame_no_protocol,
1653 "alignment_settings", &priv->alignment_settings,
1654 "treeview", &priv->treeview,
1655 "frame_new_account", &priv->frame_new_account,
1656 "hbox_type", &priv->hbox_type,
1657 "button_create", &priv->button_create,
1658 "button_back", &priv->button_back,
1659 "radiobutton_reuse", &priv->radiobutton_reuse,
1660 "radiobutton_register", &priv->radiobutton_register,
1661 "image_type", &priv->image_type,
1662 "label_name", &priv->label_name,
1663 "button_add", &priv->button_add,
1664 "button_import", &priv->button_import,
1668 empathy_builder_connect (gui, dialog,
1669 "accounts_dialog", "response", accounts_dialog_response_cb,
1670 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1671 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1672 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1673 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1674 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1675 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1676 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1679 g_object_unref (gui);
1682 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1683 gtk_widget_hide (action_area);
1685 /* Translators: this is used only when built on a moblin platform */
1686 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1687 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1690 priv->combobox_protocol = empathy_protocol_chooser_new ();
1691 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1692 priv->combobox_protocol,
1694 gtk_widget_show (priv->combobox_protocol);
1695 g_signal_connect (priv->combobox_protocol, "changed",
1696 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1699 if (priv->parent_window)
1700 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1701 priv->parent_window);
1705 do_dispose (GObject *obj)
1707 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1708 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1710 /* Disconnect signals */
1711 g_signal_handlers_disconnect_by_func (priv->account_manager,
1712 accounts_dialog_account_added_cb,
1714 g_signal_handlers_disconnect_by_func (priv->account_manager,
1715 accounts_dialog_account_removed_cb,
1717 g_signal_handlers_disconnect_by_func (priv->account_manager,
1718 accounts_dialog_account_enabled_cb,
1720 g_signal_handlers_disconnect_by_func (priv->account_manager,
1721 accounts_dialog_account_disabled_cb,
1723 g_signal_handlers_disconnect_by_func (priv->account_manager,
1724 accounts_dialog_account_changed_cb,
1726 g_signal_handlers_disconnect_by_func (priv->account_manager,
1727 accounts_dialog_connection_changed_cb,
1729 g_signal_handlers_disconnect_by_func (priv->account_manager,
1730 accounts_dialog_manager_ready_cb,
1733 if (priv->connecting_id)
1734 g_source_remove (priv->connecting_id);
1736 if (priv->account_manager != NULL)
1738 g_object_unref (priv->account_manager);
1739 priv->account_manager = NULL;
1742 if (priv->cms != NULL)
1744 g_object_unref (priv->cms);
1748 if (priv->initial_selection != NULL)
1749 g_object_unref (priv->initial_selection);
1750 priv->initial_selection = NULL;
1752 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1756 do_constructor (GType type,
1758 GObjectConstructParam *props)
1762 if (dialog_singleton)
1764 retval = G_OBJECT (dialog_singleton);
1765 g_object_ref (retval);
1770 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1771 (type, n_props, props);
1773 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1774 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1781 do_get_property (GObject *object,
1786 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1788 switch (property_id)
1791 g_value_set_object (value, priv->parent_window);
1794 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1799 do_set_property (GObject *object,
1801 const GValue *value,
1804 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1806 switch (property_id)
1809 priv->parent_window = g_value_get_object (value);
1812 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1817 do_constructed (GObject *object)
1819 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1820 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1821 gboolean import_asked;
1823 accounts_dialog_build_ui (dialog);
1824 accounts_dialog_model_setup (dialog);
1826 /* Set up signalling */
1827 priv->account_manager = empathy_account_manager_dup_singleton ();
1829 if (!empathy_account_manager_is_ready (priv->account_manager))
1830 g_signal_connect (priv->account_manager, "notify::ready",
1831 G_CALLBACK (accounts_dialog_manager_ready_cb), dialog);
1833 accounts_dialog_accounts_setup (dialog);
1835 empathy_conf_get_bool (empathy_conf_get (),
1836 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1838 if (empathy_import_accounts_to_import ())
1840 gtk_widget_show (priv->button_import);
1844 GtkWidget *import_dialog;
1846 empathy_conf_set_bool (empathy_conf_get (),
1847 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1848 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1850 gtk_widget_show (import_dialog);
1856 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1858 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1859 GParamSpec *param_spec;
1861 oclass->constructor = do_constructor;
1862 oclass->dispose = do_dispose;
1863 oclass->constructed = do_constructed;
1864 oclass->set_property = do_set_property;
1865 oclass->get_property = do_get_property;
1867 param_spec = g_param_spec_object ("parent",
1868 "parent", "The parent window",
1870 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1871 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1873 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1877 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1879 EmpathyAccountsDialogPriv *priv;
1881 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1882 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1883 EmpathyAccountsDialogPriv);
1884 dialog->priv = priv;
1887 /* public methods */
1890 empathy_accounts_dialog_show (GtkWindow *parent,
1891 EmpathyAccount *selected_account)
1893 EmpathyAccountsDialog *dialog;
1894 EmpathyAccountsDialogPriv *priv;
1896 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1897 "parent", parent, NULL);
1899 priv = GET_PRIV (dialog);
1901 if (selected_account)
1903 if (empathy_connection_managers_is_ready (priv->cms))
1904 accounts_dialog_set_selected_account (dialog, selected_account);
1906 /* save the selection to set it later when the cms
1909 priv->initial_selection = g_object_ref (selected_account);
1912 gtk_window_present (GTK_WINDOW (priv->window));
1914 return priv->window;