2 * Copyright (C) 2005-2007 Imendio AB
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
23 * Jonathan Tellier <jonathan.tellier@gmail.com>
32 #include <glib/gi18n.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/util.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-connection-managers.h>
40 #include <libempathy/empathy-connectivity.h>
41 #include <libempathy-gtk/empathy-ui-utils.h>
43 #include <libempathy-gtk/empathy-protocol-chooser.h>
44 #include <libempathy-gtk/empathy-account-widget.h>
45 #include <libempathy-gtk/empathy-account-widget-irc.h>
46 #include <libempathy-gtk/empathy-account-widget-sip.h>
47 #include <libempathy-gtk/empathy-cell-renderer-activatable.h>
48 #include <libempathy-gtk/empathy-conf.h>
49 #include <libempathy-gtk/empathy-images.h>
51 #include "empathy-accounts-dialog.h"
52 #include "empathy-import-dialog.h"
53 #include "empathy-import-utils.h"
54 #include "ephy-spinner.h"
56 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
57 #include <libempathy/empathy-debug.h>
59 /* Flashing delay for icons (milliseconds). */
60 #define FLASH_TIMEOUT 500
62 /* The primary text of the dialog shown to the user when he is about to lose
64 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
65 _("There are unsaved modification regarding your %s account.")
66 /* The primary text of the dialog shown to the user when he is about to lose
67 * an unsaved new account */
68 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
69 _("Your new account has not been saved yet.")
71 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
72 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, G_TYPE_OBJECT);
74 static EmpathyAccountsDialog *dialog_singleton = NULL;
79 GtkWidget *alignment_settings;
80 GtkWidget *alignment_infobar;
82 GtkWidget *vbox_details;
84 GtkWidget *label_status;
85 GtkWidget *image_status;
87 GtkWidget *frame_no_protocol;
91 GtkWidget *button_add;
92 GtkWidget *button_import;
94 GtkWidget *frame_new_account;
95 GtkWidget *combobox_protocol;
97 GtkWidget *button_create;
98 GtkWidget *button_back;
99 GtkWidget *radiobutton_reuse;
100 GtkWidget *radiobutton_register;
102 GtkWidget *image_type;
103 GtkWidget *label_name;
104 GtkWidget *label_type;
105 GtkWidget *settings_widget;
107 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
108 * his GtkWidget. It is the only reliable source we can query to know if
109 * there are any unsaved changes to the currently selected account. We can't
110 * look at the account settings because it does not contain everything that
111 * can be changed using the EmpathyAccountWidget. For instance, it does not
112 * contain the state of the "Enabled" checkbox. */
113 EmpathyAccountWidget *setting_widget_object;
115 gboolean connecting_show;
118 gulong settings_ready_id;
119 EmpathyAccountSettings *settings_ready;
121 TpAccountManager *account_manager;
122 EmpathyConnectionManagers *cms;
124 GtkWindow *parent_window;
125 TpAccount *initial_selection;
127 /* Those are needed when changing the selected row. When a user selects
128 * another account and there are unsaved changes on the currently selected
129 * one, a confirmation message box is presented to him. Since his answer
130 * is retrieved asynchronously, we keep some information as member of the
131 * EmpathyAccountsDialog object. */
132 gboolean force_change_row;
133 GtkTreeRowReference *destination_row;
136 } EmpathyAccountsDialogPriv;
142 COL_ACCOUNT_SETTINGS_POINTER,
150 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
151 EmpathyAccountsDialog *dialog);
153 static gboolean accounts_dialog_get_settings_iter (
154 EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings,
158 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
160 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
161 EmpathyAccountSettings *settings);
164 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
165 const gchar *display_name)
168 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
170 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
171 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
177 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
180 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
181 const gchar *message;
182 gchar *status_message;
186 EmpathyConnectivity *connectivity;
189 GtkTreeSelection *selection;
191 TpAccount *selected_account;
193 view = GTK_TREE_VIEW (priv->treeview);
194 selection = gtk_tree_view_get_selection (view);
196 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
199 gtk_tree_model_get (model, &iter,
200 COL_ACCOUNT_POINTER, &selected_account, -1);
202 /* do not update the infobar when the account is not selected */
203 if (account != selected_account)
208 status = tp_account_get_connection_status (account, &reason);
209 presence = tp_account_get_current_presence (account, NULL, &status_message);
211 connectivity = empathy_connectivity_dup_singleton ();
213 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
214 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
216 if (tp_account_is_enabled (account))
220 case TP_CONNECTION_STATUS_CONNECTING:
221 message = _("Connecting...");
222 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
225 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
226 gtk_widget_show (priv->throbber);
227 gtk_widget_hide (priv->image_status);
229 case TP_CONNECTION_STATUS_CONNECTED:
230 if (g_strcmp0 (status_message, "") == 0)
232 message = g_strdup_printf ("%s",
233 empathy_presence_get_default_message (presence));
237 message = g_strdup_printf ("%s - %s",
238 empathy_presence_get_default_message (presence),
241 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
244 gtk_widget_show (priv->image_status);
245 gtk_widget_hide (priv->throbber);
247 case TP_CONNECTION_STATUS_DISCONNECTED:
248 message = g_strdup_printf (_("Disconnected - %s"),
249 empathy_status_reason_get_default_message (reason));
251 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
253 message = g_strdup_printf (_("Offline - %s"),
254 empathy_status_reason_get_default_message (reason));
255 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
256 GTK_MESSAGE_WARNING);
260 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
264 if (!empathy_connectivity_is_online (connectivity))
265 message = _("Offline - No Network Connection");
267 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
268 gtk_widget_show (priv->image_status);
269 gtk_widget_hide (priv->throbber);
272 message = _("Unknown Status");
273 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
274 GTK_MESSAGE_WARNING);
276 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
277 gtk_widget_hide (priv->image_status);
278 gtk_widget_hide (priv->throbber);
283 message = _("Offline - Account disabled");
284 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
285 GTK_MESSAGE_WARNING);
286 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
287 gtk_widget_show (priv->image_status);
288 gtk_widget_hide (priv->throbber);
291 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
292 gtk_widget_show (priv->label_status);
293 gtk_widget_show (priv->infobar);
295 g_object_unref (connectivity);
296 g_free (status_message);
300 empathy_account_dialog_widget_cancelled_cb (
301 EmpathyAccountWidget *widget_object,
302 EmpathyAccountsDialog *dialog)
306 GtkTreeSelection *selection;
308 EmpathyAccountSettings *settings;
310 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
312 view = GTK_TREE_VIEW (priv->treeview);
313 selection = gtk_tree_view_get_selection (view);
315 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
318 gtk_tree_model_get (model, &iter,
319 COL_ACCOUNT_SETTINGS_POINTER, &settings,
320 COL_ACCOUNT_POINTER, &account, -1);
322 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
326 /* We were creating an account. We remove the selected row */
327 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
331 /* We were modifying an account. We discard the changes by reloading the
332 * settings and the UI. */
333 accounts_dialog_update_settings (dialog, settings);
334 g_object_unref (account);
337 if (settings != NULL)
338 g_object_unref (settings);
342 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
343 EmpathyAccountsDialog *dialog)
346 EmpathyAccountSettings *settings =
347 accounts_dialog_model_get_selected_settings (dialog);
349 display_name = empathy_account_widget_get_default_display_name (
352 empathy_account_settings_set_display_name_async (settings,
353 display_name, NULL, NULL);
355 g_free (display_name);
357 accounts_dialog_update_settings (dialog, settings);
360 g_object_unref (settings);
364 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
365 EmpathyAccountSettings *settings)
367 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
371 priv->setting_widget_object =
372 empathy_account_widget_new_for_protocol (settings, FALSE);
374 priv->settings_widget =
375 empathy_account_widget_get_widget (priv->setting_widget_object);
377 priv->settings_widget =
378 empathy_account_widget_get_widget (priv->setting_widget_object);
379 g_signal_connect (priv->setting_widget_object, "account-created",
380 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
381 g_signal_connect (priv->setting_widget_object, "cancelled",
382 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
384 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
385 priv->settings_widget);
386 gtk_widget_show (priv->settings_widget);
388 icon_name = empathy_account_settings_get_icon_name (settings);
390 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
392 /* show the default icon; keep this in sync with the default
393 * one in empathy-accounts-dialog.ui.
395 icon_name = GTK_STOCK_CUT;
397 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
398 icon_name, GTK_ICON_SIZE_DIALOG);
399 gtk_widget_set_tooltip_text (priv->image_type,
400 empathy_protocol_name_to_display_name
401 (empathy_account_settings_get_protocol (settings)));
402 gtk_widget_show (priv->image_type);
404 accounts_dialog_update_name_label (dialog,
405 empathy_account_settings_get_display_name (settings));
407 account = empathy_account_settings_get_account (settings);
408 accounts_dialog_update_status_infobar (dialog, account);
412 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
414 EmpathyAccountsDialog *dialog)
416 if (empathy_account_settings_is_ready (settings))
417 account_dialog_create_settings_widget (dialog, settings);
421 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
425 GtkTreeSelection *selection;
427 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
430 view = GTK_TREE_VIEW (priv->treeview);
431 model = gtk_tree_view_get_model (view);
433 if (gtk_tree_model_get_iter_first (model, &iter))
435 selection = gtk_tree_view_get_selection (view);
436 gtk_tree_selection_select_iter (selection, &iter);
440 accounts_dialog_update_settings (dialog, NULL);
445 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
450 GtkTreeSelection *selection;
451 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
453 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
455 if (gtk_tree_selection_get_selected (selection, &model, &iter))
456 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
458 return priv->setting_widget_object != NULL
459 && empathy_account_widget_contains_pending_changes (
460 priv->setting_widget_object);
464 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
465 EmpathyAccountsDialog *dialog)
467 TpConnectionManager *cm;
468 TpConnectionManagerProtocol *proto;
470 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
472 cm = empathy_protocol_chooser_dup_selected (
473 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
485 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
487 gtk_widget_show (priv->radiobutton_register);
488 gtk_widget_show (priv->radiobutton_reuse);
492 gtk_widget_hide (priv->radiobutton_register);
493 gtk_widget_hide (priv->radiobutton_reuse);
496 gtk_widget_hide (priv->radiobutton_register);
497 gtk_widget_hide (priv->radiobutton_reuse);
504 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
508 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
510 view = GTK_TREE_VIEW (priv->treeview);
511 model = gtk_tree_view_get_model (view);
513 gtk_widget_set_sensitive (priv->button_add, FALSE);
514 gtk_widget_hide (priv->vbox_details);
515 gtk_widget_hide (priv->frame_no_protocol);
516 gtk_widget_show (priv->frame_new_account);
518 /* If we have no account, no need of a back button */
519 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
520 gtk_widget_show (priv->button_back);
522 gtk_widget_hide (priv->button_back);
524 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
525 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
527 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
528 gtk_widget_grab_focus (priv->combobox_protocol);
532 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
533 const gchar *primary_text,
534 const gchar *secondary_text,
535 GCallback response_callback,
537 const gchar *first_button_text,
541 GtkWidget *message_dialog;
542 const gchar *button_text;
543 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
545 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
546 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
547 GTK_MESSAGE_QUESTION,
551 gtk_message_dialog_format_secondary_text (
552 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
554 va_start (button_args, first_button_text);
555 for (button_text = first_button_text;
557 button_text = va_arg (button_args, const gchar *))
560 response_id = va_arg (button_args, gint);
562 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
565 va_end (button_args);
567 g_signal_connect (message_dialog, "response", response_callback, user_data);
569 gtk_widget_show (message_dialog);
573 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
577 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
578 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
580 gtk_widget_destroy (GTK_WIDGET (message_dialog));
582 if (response_id == GTK_RESPONSE_YES)
584 empathy_account_widget_discard_pending_changes (
585 priv->setting_widget_object);
586 accounts_dialog_setup_ui_to_add_account (dialog);
591 get_dialog_primary_text (TpAccount *account)
595 /* Existing account */
596 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
597 tp_account_get_display_name (account));
601 /* Newly created account */
602 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
607 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
608 EmpathyAccountsDialog *dialog)
610 TpAccount *account = NULL;
612 if (accounts_dialog_has_pending_change (dialog, &account))
614 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
616 accounts_dialog_show_question_dialog (dialog,
617 question_dialog_primary_text,
618 _("You are about to create a new account, which will discard\n"
619 "your changes. Are you sure you want to proceed?"),
620 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
622 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
623 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
625 g_free (question_dialog_primary_text);
629 accounts_dialog_setup_ui_to_add_account (dialog);
634 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
635 EmpathyAccountSettings *settings)
637 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
639 if (priv->settings_ready != NULL)
641 g_signal_handler_disconnect (priv->settings_ready,
642 priv->settings_ready_id);
643 priv->settings_ready = NULL;
644 priv->settings_ready_id = 0;
651 GtkTreeSelection *selection;
653 view = GTK_TREE_VIEW (priv->treeview);
654 model = gtk_tree_view_get_model (view);
655 selection = gtk_tree_view_get_selection (view);
657 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
659 /* We have configured accounts, select the first one if there
660 * is no other account selected already. */
661 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
662 accounts_dialog_model_select_first (dialog);
666 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
668 /* We have no account configured but we have some
669 * profiles installed. The user obviously wants to add
670 * an account. Click on the Add button for him. */
671 accounts_dialog_button_add_clicked_cb (priv->button_add,
676 /* No account and no profile, warn the user */
677 gtk_widget_hide (priv->vbox_details);
678 gtk_widget_hide (priv->frame_new_account);
679 gtk_widget_show (priv->frame_no_protocol);
680 gtk_widget_set_sensitive (priv->button_add, FALSE);
684 /* We have an account selected, destroy old settings and create a new
685 * one for the account selected */
686 gtk_widget_hide (priv->frame_new_account);
687 gtk_widget_hide (priv->frame_no_protocol);
688 gtk_widget_show (priv->vbox_details);
689 gtk_widget_set_sensitive (priv->button_add, TRUE);
691 if (priv->settings_widget)
693 gtk_widget_destroy (priv->settings_widget);
694 priv->settings_widget = NULL;
697 if (empathy_account_settings_is_ready (settings))
699 account_dialog_create_settings_widget (dialog, settings);
703 priv->settings_ready = settings;
704 priv->settings_ready_id =
705 g_signal_connect (settings, "notify::ready",
706 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
712 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
713 GtkCellEditable *editable,
715 EmpathyAccountsDialog *dialog)
717 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
719 if (priv->connecting_id)
720 g_source_remove (priv->connecting_id);
722 DEBUG ("Editing account name started; stopping flashing");
726 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
727 GtkCellRenderer *cell,
730 EmpathyAccountsDialog *dialog)
732 EmpathyAccountSettings *settings;
735 TpConnectionStatus status;
736 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
738 gtk_tree_model_get (model, iter,
740 COL_ACCOUNT_SETTINGS_POINTER, &settings,
743 icon_name = empathy_account_settings_get_icon_name (settings);
744 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
748 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
749 (status == TP_CONNECTION_STATUS_CONNECTING &&
750 !priv->connecting_show))
752 GdkPixbuf *modded_pixbuf;
754 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
757 gdk_pixbuf_get_width (pixbuf),
758 gdk_pixbuf_get_height (pixbuf));
760 gdk_pixbuf_saturate_and_pixelate (pixbuf,
764 g_object_unref (pixbuf);
765 pixbuf = modded_pixbuf;
774 g_object_unref (settings);
777 g_object_unref (pixbuf);
781 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
786 gtk_tree_model_row_changed (model, path, iter);
792 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
796 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
798 priv->connecting_show = !priv->connecting_show;
800 view = GTK_TREE_VIEW (priv->treeview);
801 model = gtk_tree_view_get_model (view);
803 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
809 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
812 EmpathyAccountsDialog *dialog)
814 EmpathyAccountSettings *settings;
816 GtkTreePath *treepath;
818 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
821 empathy_account_manager_get_accounts_connected (&connecting);
825 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
826 (GSourceFunc) accounts_dialog_flash_connecting_cb,
830 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
831 treepath = gtk_tree_path_new_from_string (path);
832 gtk_tree_model_get_iter (model, &iter, treepath);
833 gtk_tree_model_get (model, &iter,
834 COL_ACCOUNT_SETTINGS_POINTER, &settings,
836 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
839 gtk_tree_path_free (treepath);
841 empathy_account_settings_set_display_name_async (settings, new_text,
843 g_object_set (settings, "display-name-overridden", TRUE, NULL);
844 g_object_unref (settings);
848 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
855 GtkTreeSelection *selection;
856 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
857 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
859 if (response_id == GTK_RESPONSE_YES)
861 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
863 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
866 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
870 tp_account_remove_async (account, NULL, NULL);
871 g_object_unref (account);
875 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
876 accounts_dialog_model_select_first (account_dialog);
879 gtk_widget_destroy (GTK_WIDGET (message_dialog));
883 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
884 const gchar *path_string,
885 EmpathyAccountsDialog *dialog)
890 gchar *question_dialog_primary_text;
891 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
893 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
895 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
898 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
900 if (account == NULL || !tp_account_is_valid (account))
902 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
903 accounts_dialog_model_select_first (dialog);
907 question_dialog_primary_text = g_strdup_printf (
908 _("Do you want to remove %s from your computer?"),
909 tp_account_get_display_name (account));
911 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
912 _("This will not remove your account on the server."),
913 G_CALLBACK (accounts_dialog_delete_account_response_cb),
915 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
916 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
918 g_free (question_dialog_primary_text);
922 g_object_unref (account);
928 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
931 GtkTreeViewColumn *column;
932 GtkCellRenderer *cell;
933 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
935 view = GTK_TREE_VIEW (priv->treeview);
936 gtk_tree_view_set_headers_visible (view, FALSE);
939 column = gtk_tree_view_column_new ();
940 gtk_tree_view_column_set_expand (column, TRUE);
941 gtk_tree_view_append_column (view, column);
944 cell = gtk_cell_renderer_pixbuf_new ();
945 gtk_tree_view_column_pack_start (column, cell, FALSE);
946 gtk_tree_view_column_set_cell_data_func (column, cell,
947 (GtkTreeCellDataFunc)
948 accounts_dialog_model_pixbuf_data_func,
953 cell = gtk_cell_renderer_text_new ();
955 "ellipsize", PANGO_ELLIPSIZE_END,
959 gtk_tree_view_column_pack_start (column, cell, TRUE);
960 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
961 g_signal_connect (cell, "edited",
962 G_CALLBACK (accounts_dialog_name_edited_cb),
964 g_signal_connect (cell, "editing-started",
965 G_CALLBACK (accounts_dialog_name_editing_started_cb),
967 g_object_set (cell, "ypad", 4, NULL);
970 cell = empathy_cell_renderer_activatable_new ();
971 gtk_tree_view_column_pack_start (column, cell, FALSE);
973 "icon-name", GTK_STOCK_DELETE,
974 "show-on-select", TRUE,
977 g_signal_connect (cell, "path-activated",
978 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
982 static EmpathyAccountSettings *
983 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
987 GtkTreeSelection *selection;
989 EmpathyAccountSettings *settings;
990 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
992 view = GTK_TREE_VIEW (priv->treeview);
993 selection = gtk_tree_view_get_selection (view);
995 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
998 gtk_tree_model_get (model, &iter,
999 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1005 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1006 EmpathyAccountsDialog *dialog)
1008 EmpathyAccountSettings *settings;
1009 GtkTreeModel *model;
1011 gboolean is_selection;
1013 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1015 settings = accounts_dialog_model_get_selected_settings (dialog);
1016 accounts_dialog_update_settings (dialog, settings);
1018 if (settings != NULL)
1019 g_object_unref (settings);
1023 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1025 gpointer *user_data)
1027 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1028 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1030 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1032 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1034 /* The user wants to lose unsaved changes to the currently selected
1035 * account and select another account. We discard the changes and
1036 * select the other account. */
1038 GtkTreeSelection *selection;
1040 priv->force_change_row = TRUE;
1041 empathy_account_widget_discard_pending_changes (
1042 priv->setting_widget_object);
1044 path = gtk_tree_row_reference_get_path (priv->destination_row);
1045 selection = gtk_tree_view_get_selection (
1046 GTK_TREE_VIEW (priv->treeview));
1050 /* This will trigger a call to
1051 * accounts_dialog_account_selection_change() */
1052 gtk_tree_selection_select_path (selection, path);
1053 gtk_tree_path_free (path);
1056 gtk_tree_row_reference_free (priv->destination_row);
1060 priv->force_change_row = FALSE;
1065 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1066 GtkTreeModel *model,
1068 gboolean path_currently_selected,
1071 TpAccount *account = NULL;
1072 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1073 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1075 if (priv->force_change_row)
1077 /* We came back here because the user wants to discard changes to his
1078 * modified account. The changes have already been discarded so we
1079 * just change the selected row. */
1080 priv->force_change_row = FALSE;
1084 if (accounts_dialog_has_pending_change (dialog, &account))
1086 /* The currently selected account has some unsaved changes. We ask
1087 * the user if he really wants to lose his changes and select another
1089 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1090 priv->destination_row = gtk_tree_row_reference_new (model, path);
1092 accounts_dialog_show_question_dialog (dialog,
1093 question_dialog_primary_text,
1094 _("You are about to select another account, which will discard\n"
1095 "your changes. Are you sure you want to proceed?"),
1096 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1098 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1099 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1101 g_free (question_dialog_primary_text);
1112 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1114 GtkListStore *store;
1115 GtkTreeSelection *selection;
1116 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1118 store = gtk_list_store_new (COL_COUNT,
1119 G_TYPE_STRING, /* name */
1120 G_TYPE_UINT, /* status */
1121 TP_TYPE_ACCOUNT, /* account */
1122 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1124 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1125 GTK_TREE_MODEL (store));
1127 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1128 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1129 gtk_tree_selection_set_select_function (selection,
1130 accounts_dialog_account_selection_change, dialog, NULL);
1132 g_signal_connect (selection, "changed",
1133 G_CALLBACK (accounts_dialog_model_selection_changed),
1136 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1137 COL_NAME, GTK_SORT_ASCENDING);
1139 accounts_dialog_model_add_columns (dialog);
1141 g_object_unref (store);
1145 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1146 EmpathyAccountSettings *settings,
1150 GtkTreeSelection *selection;
1151 GtkTreeModel *model;
1153 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1155 /* Update the status in the model */
1156 view = GTK_TREE_VIEW (priv->treeview);
1157 selection = gtk_tree_view_get_selection (view);
1158 model = gtk_tree_view_get_model (view);
1160 for (ok = gtk_tree_model_get_iter_first (model, iter);
1162 ok = gtk_tree_model_iter_next (model, iter))
1164 EmpathyAccountSettings *this_settings;
1167 gtk_tree_model_get (model, iter,
1168 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1171 equal = (this_settings == settings);
1172 g_object_unref (this_settings);
1182 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1187 GtkTreeSelection *selection;
1188 GtkTreeModel *model;
1190 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1192 /* Update the status in the model */
1193 view = GTK_TREE_VIEW (priv->treeview);
1194 selection = gtk_tree_view_get_selection (view);
1195 model = gtk_tree_view_get_model (view);
1197 for (ok = gtk_tree_model_get_iter_first (model, iter);
1199 ok = gtk_tree_model_iter_next (model, iter))
1201 EmpathyAccountSettings *settings;
1204 gtk_tree_model_get (model, iter,
1205 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1208 equal = empathy_account_settings_has_account (settings, account);
1209 g_object_unref (settings);
1219 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1220 EmpathyAccountSettings *settings)
1222 GtkTreeSelection *selection;
1224 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1226 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1227 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1228 gtk_tree_selection_select_iter (selection, &iter);
1231 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1232 EmpathyAccountSettings *settings)
1234 GtkTreeModel *model;
1237 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1239 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1240 name = empathy_account_settings_get_display_name (settings);
1242 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1244 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1246 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1247 COL_ACCOUNT_SETTINGS_POINTER, settings,
1252 accounts_dialog_connection_changed_cb (TpAccount *account,
1256 gchar *dbus_error_name,
1257 GHashTable *details,
1258 EmpathyAccountsDialog *dialog)
1260 GtkTreeModel *model;
1263 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1265 /* Update the status-infobar in the details view */
1266 accounts_dialog_update_status_infobar (dialog, account);
1268 /* Update the status in the model */
1269 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1271 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1275 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1276 COL_STATUS, current,
1279 path = gtk_tree_model_get_path (model, &iter);
1280 gtk_tree_model_row_changed (model, path, &iter);
1281 gtk_tree_path_free (path);
1284 empathy_account_manager_get_accounts_connected (&found);
1286 if (!found && priv->connecting_id)
1288 g_source_remove (priv->connecting_id);
1289 priv->connecting_id = 0;
1292 if (found && !priv->connecting_id)
1293 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1294 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1299 accounts_dialog_presence_changed_cb (TpAccount *account,
1302 gchar *status_message,
1303 EmpathyAccountsDialog *dialog)
1305 /* Update the status-infobar in the details view*/
1306 accounts_dialog_update_status_infobar (dialog, account);
1310 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1314 const gchar *display_name;
1316 GtkTreeModel *model;
1317 EmpathyAccountSettings *settings;
1318 TpAccount *selected_account;
1319 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1320 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1322 display_name = tp_account_get_display_name (account);
1323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1324 settings = accounts_dialog_model_get_selected_settings (dialog);
1325 if (settings == NULL)
1328 selected_account = empathy_account_settings_get_account (settings);
1330 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1332 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1333 COL_NAME, display_name,
1337 if (selected_account == account)
1338 accounts_dialog_update_name_label (dialog, display_name);
1340 g_object_unref (settings);
1344 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1347 EmpathyAccountSettings *settings;
1348 GtkTreeModel *model;
1350 TpConnectionStatus status;
1353 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1355 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1356 status = tp_account_get_connection_status (account, NULL);
1357 name = tp_account_get_display_name (account);
1358 enabled = tp_account_is_enabled (account);
1360 settings = empathy_account_settings_new_for_account (account);
1362 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1363 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1365 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1368 COL_ACCOUNT_POINTER, account,
1369 COL_ACCOUNT_SETTINGS_POINTER, settings,
1372 accounts_dialog_connection_changed_cb (account,
1375 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1380 empathy_signal_connect_weak (account, "notify::display-name",
1381 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1384 g_object_unref (settings);
1388 account_prepare_cb (GObject *source_object,
1389 GAsyncResult *result,
1392 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1393 TpAccount *account = TP_ACCOUNT (source_object);
1394 GError *error = NULL;
1396 if (!tp_account_prepare_finish (account, result, &error))
1398 DEBUG ("Failed to prepare account: %s", error->message);
1399 g_error_free (error);
1403 accounts_dialog_add_account (dialog, account);
1407 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1410 EmpathyAccountsDialog *dialog)
1412 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1416 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1418 EmpathyAccountsDialog *dialog)
1421 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1423 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1425 gtk_list_store_remove (GTK_LIST_STORE (
1426 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1431 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1435 GtkTreeModel *model;
1436 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1438 /* Update the status in the model */
1439 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1441 /* Update the status-infobar in the details view when disabling*/
1443 accounts_dialog_update_status_infobar (dialog, account);
1445 DEBUG ("Account %s is now %s",
1446 tp_account_get_display_name (account),
1447 enabled ? "enabled" : "disabled");
1451 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1453 EmpathyAccountsDialog *dialog)
1455 enable_or_disable_account (dialog, account, FALSE);
1459 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1461 EmpathyAccountsDialog *dialog)
1463 enable_or_disable_account (dialog, account, TRUE);
1467 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1468 EmpathyAccountsDialog *dialog)
1470 EmpathyAccountSettings *settings;
1472 const gchar *display_name;
1473 TpConnectionManager *cm;
1474 TpConnectionManagerProtocol *proto;
1475 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1478 cm = empathy_protocol_chooser_dup_selected (
1479 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1481 display_name = empathy_protocol_name_to_display_name (
1482 is_gtalk ? "gtalk" : proto->name);
1484 if (display_name == NULL)
1485 display_name = proto->name;
1487 /* Create account */
1488 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1491 str = g_strdup_printf (_("New %s account"), display_name);
1492 settings = empathy_account_settings_new (cm->name, proto->name, str);
1497 if (tp_connection_manager_protocol_can_register (proto))
1501 active = gtk_toggle_button_get_active
1502 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1504 empathy_account_settings_set_boolean (settings, "register", TRUE);
1509 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1512 accounts_dialog_add (dialog, settings);
1513 accounts_dialog_model_set_selected (dialog, settings);
1515 g_object_unref (settings);
1516 g_object_unref (cm);
1520 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1521 EmpathyAccountsDialog *dialog)
1523 EmpathyAccountSettings *settings;
1525 settings = accounts_dialog_model_get_selected_settings (dialog);
1526 accounts_dialog_update_settings (dialog, settings);
1529 g_object_unref (settings);
1533 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1534 EmpathyAccountsDialog *dialog)
1536 empathy_url_show (button, "ghelp:empathy?accounts-window");
1540 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1541 EmpathyAccountsDialog *dialog)
1543 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1544 GtkWidget *import_dialog;
1546 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1548 gtk_widget_show (import_dialog);
1552 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1556 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1558 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1560 if (response_id == GTK_RESPONSE_YES)
1561 gtk_widget_destroy (account_dialog);
1565 accounts_dialog_response_cb (GtkWidget *widget,
1567 EmpathyAccountsDialog *dialog)
1569 TpAccount *account = NULL;
1571 if (accounts_dialog_has_pending_change (dialog, &account))
1573 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1575 accounts_dialog_show_question_dialog (dialog,
1576 question_dialog_primary_text,
1577 _("You are about to close the window, which will discard\n"
1578 "your changes. Are you sure you want to proceed?"),
1579 G_CALLBACK (accounts_dialog_close_response_cb),
1581 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1582 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1584 g_free (question_dialog_primary_text);
1586 else if (response == GTK_RESPONSE_CLOSE ||
1587 response == GTK_RESPONSE_DELETE_EVENT)
1588 gtk_widget_destroy (widget);
1592 accounts_dialog_delete_event_cb (GtkWidget *widget,
1594 EmpathyAccountsDialog *dialog)
1596 /* we maunally handle responses to delete events */
1601 accounts_dialog_destroy_cb (GtkObject *obj,
1602 EmpathyAccountsDialog *dialog)
1606 g_object_unref (dialog);
1610 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1613 GtkTreeSelection *selection;
1615 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1617 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1618 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1619 gtk_tree_selection_select_iter (selection, &iter);
1623 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1625 EmpathyAccountsDialog *dialog)
1627 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1629 if (empathy_connection_managers_is_ready (cms))
1631 accounts_dialog_update_settings (dialog, NULL);
1633 if (priv->initial_selection != NULL)
1635 accounts_dialog_set_selected_account
1636 (dialog, priv->initial_selection);
1637 g_object_unref (priv->initial_selection);
1638 priv->initial_selection = NULL;
1644 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1646 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1647 GList *accounts, *l;
1649 g_signal_connect (priv->account_manager, "account-validity-changed",
1650 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1652 g_signal_connect (priv->account_manager, "account-removed",
1653 G_CALLBACK (accounts_dialog_account_removed_cb),
1655 g_signal_connect (priv->account_manager, "account-enabled",
1656 G_CALLBACK (accounts_dialog_account_enabled_cb),
1658 g_signal_connect (priv->account_manager, "account-disabled",
1659 G_CALLBACK (accounts_dialog_account_disabled_cb),
1662 /* Add existing accounts */
1663 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1664 for (l = accounts; l; l = l->next)
1666 accounts_dialog_add_account (dialog, l->data);
1668 empathy_signal_connect_weak (l->data, "status-changed",
1669 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1670 empathy_signal_connect_weak (l->data, "presence-changed",
1671 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1673 g_list_free (accounts);
1675 priv->cms = empathy_connection_managers_dup_singleton ();
1676 if (!empathy_connection_managers_is_ready (priv->cms))
1677 g_signal_connect (priv->cms, "notify::ready",
1678 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1680 accounts_dialog_model_select_first (dialog);
1684 accounts_dialog_manager_ready_cb (GObject *source_object,
1685 GAsyncResult *result,
1688 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1689 GError *error = NULL;
1691 if (!tp_account_manager_prepare_finish (manager, result, &error))
1693 DEBUG ("Failed to prepare account manager: %s", error->message);
1694 g_error_free (error);
1698 accounts_dialog_accounts_setup (user_data);
1702 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1706 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1707 GtkWidget *content_area;
1709 GtkWidget *action_area;
1712 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1714 gui = empathy_builder_get_file (filename,
1715 "accounts_dialog", &priv->window,
1716 "vbox_details", &priv->vbox_details,
1717 "frame_no_protocol", &priv->frame_no_protocol,
1718 "alignment_settings", &priv->alignment_settings,
1719 "alignment_infobar", &priv->alignment_infobar,
1720 "treeview", &priv->treeview,
1721 "frame_new_account", &priv->frame_new_account,
1722 "hbox_type", &priv->hbox_type,
1723 "button_create", &priv->button_create,
1724 "button_back", &priv->button_back,
1725 "radiobutton_reuse", &priv->radiobutton_reuse,
1726 "radiobutton_register", &priv->radiobutton_register,
1727 "image_type", &priv->image_type,
1728 "label_name", &priv->label_name,
1729 "button_add", &priv->button_add,
1730 "button_import", &priv->button_import,
1734 empathy_builder_connect (gui, dialog,
1735 "accounts_dialog", "response", accounts_dialog_response_cb,
1736 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1737 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1738 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1739 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1740 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1741 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1742 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1745 g_object_unref (gui);
1748 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1749 gtk_widget_hide (action_area);
1751 /* Translators: this is used only when built on a moblin platform */
1752 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1753 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1756 priv->combobox_protocol = empathy_protocol_chooser_new ();
1757 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1758 priv->combobox_protocol,
1760 gtk_widget_show (priv->combobox_protocol);
1761 g_signal_connect (priv->combobox_protocol, "changed",
1762 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1765 if (priv->parent_window)
1766 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1767 priv->parent_window);
1769 /* set up spinner */
1770 priv->throbber = ephy_spinner_new ();
1771 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1773 priv->infobar = gtk_info_bar_new ();
1774 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1776 gtk_widget_show (priv->infobar);
1778 priv->image_status = gtk_image_new_from_icon_name (
1779 empathy_icon_name_for_presence (
1780 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1782 priv->label_status = gtk_label_new (NULL);
1784 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1785 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1787 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1789 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1793 do_dispose (GObject *obj)
1795 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1796 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1798 /* Disconnect signals */
1799 g_signal_handlers_disconnect_by_func (priv->account_manager,
1800 accounts_dialog_account_validity_changed_cb,
1802 g_signal_handlers_disconnect_by_func (priv->account_manager,
1803 accounts_dialog_account_removed_cb,
1805 g_signal_handlers_disconnect_by_func (priv->account_manager,
1806 accounts_dialog_account_enabled_cb,
1808 g_signal_handlers_disconnect_by_func (priv->account_manager,
1809 accounts_dialog_account_disabled_cb,
1811 g_signal_handlers_disconnect_by_func (priv->account_manager,
1812 accounts_dialog_manager_ready_cb,
1815 if (priv->connecting_id)
1816 g_source_remove (priv->connecting_id);
1818 if (priv->account_manager != NULL)
1820 g_object_unref (priv->account_manager);
1821 priv->account_manager = NULL;
1824 if (priv->cms != NULL)
1826 g_object_unref (priv->cms);
1830 if (priv->initial_selection != NULL)
1831 g_object_unref (priv->initial_selection);
1832 priv->initial_selection = NULL;
1834 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1838 do_constructor (GType type,
1840 GObjectConstructParam *props)
1844 if (dialog_singleton)
1846 retval = G_OBJECT (dialog_singleton);
1847 g_object_ref (retval);
1852 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1853 (type, n_props, props);
1855 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1856 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1857 /* We add an extra reference that we'll release when the dialog is
1858 * destroyed (accounts_dialog_destroy_cb) */
1859 g_object_ref (retval);
1866 do_get_property (GObject *object,
1871 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1873 switch (property_id)
1876 g_value_set_object (value, priv->parent_window);
1879 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1884 do_set_property (GObject *object,
1886 const GValue *value,
1889 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1891 switch (property_id)
1894 priv->parent_window = g_value_get_object (value);
1897 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1902 do_constructed (GObject *object)
1904 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1905 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1906 gboolean import_asked;
1908 accounts_dialog_build_ui (dialog);
1909 accounts_dialog_model_setup (dialog);
1911 /* Set up signalling */
1912 priv->account_manager = tp_account_manager_dup ();
1914 tp_account_manager_prepare_async (priv->account_manager, NULL,
1915 accounts_dialog_manager_ready_cb, dialog);
1917 empathy_conf_get_bool (empathy_conf_get (),
1918 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1920 if (empathy_import_accounts_to_import ())
1922 gtk_widget_show (priv->button_import);
1926 GtkWidget *import_dialog;
1928 empathy_conf_set_bool (empathy_conf_get (),
1929 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1930 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1932 gtk_widget_show (import_dialog);
1938 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1940 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1941 GParamSpec *param_spec;
1943 oclass->constructor = do_constructor;
1944 oclass->dispose = do_dispose;
1945 oclass->constructed = do_constructed;
1946 oclass->set_property = do_set_property;
1947 oclass->get_property = do_get_property;
1949 param_spec = g_param_spec_object ("parent",
1950 "parent", "The parent window",
1952 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1953 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1955 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1959 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1961 EmpathyAccountsDialogPriv *priv;
1963 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1964 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1965 EmpathyAccountsDialogPriv);
1966 dialog->priv = priv;
1969 /* public methods */
1972 empathy_accounts_dialog_show (GtkWindow *parent,
1973 TpAccount *selected_account)
1975 EmpathyAccountsDialog *dialog;
1976 EmpathyAccountsDialogPriv *priv;
1978 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1979 "parent", parent, NULL);
1981 priv = GET_PRIV (dialog);
1983 if (selected_account)
1985 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1986 accounts_dialog_set_selected_account (dialog, selected_account);
1988 /* save the selection to set it later when the cms
1991 priv->initial_selection = g_object_ref (selected_account);
1994 gtk_window_present (GTK_WINDOW (priv->window));
1995 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1996 * destroyed so we can release the ref returned by the constructor now. */
1997 g_object_unref (dialog);
1999 return priv->window;