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;
185 EmpathyConnectivity *connectivity;
187 status = tp_account_get_connection_status (account, &reason);
188 presence = tp_account_get_current_presence (account, NULL, NULL);
190 connectivity = empathy_connectivity_dup_singleton ();
192 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
193 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
195 if (tp_account_is_enabled (account))
199 case TP_CONNECTION_STATUS_CONNECTING:
200 message = _("Connecting...");
201 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
204 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
205 gtk_widget_show (priv->throbber);
206 gtk_widget_hide (priv->image_status);
208 case TP_CONNECTION_STATUS_CONNECTED:
209 message = g_strdup_printf (_("Connected with status %s"),
210 empathy_presence_get_default_message (presence));
212 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
215 gtk_widget_show (priv->image_status);
216 gtk_widget_hide (priv->throbber);
218 case TP_CONNECTION_STATUS_DISCONNECTED:
219 message = g_strdup_printf (_("Offline - %s"),
220 empathy_status_reason_get_default_message (reason));
222 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
224 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
225 GTK_MESSAGE_WARNING);
229 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
233 if (!empathy_connectivity_is_online (connectivity))
234 message = _("Offline - No Network Connection");
236 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
237 gtk_widget_show (priv->image_status);
238 gtk_widget_hide (priv->throbber);
241 message = _("Unknown Status");
242 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
243 GTK_MESSAGE_WARNING);
245 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
246 gtk_widget_hide (priv->image_status);
247 gtk_widget_hide (priv->throbber);
252 message = _("Offline - Account disabled");
253 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
254 GTK_MESSAGE_WARNING);
255 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
256 gtk_widget_show (priv->image_status);
257 gtk_widget_hide (priv->throbber);
260 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
261 gtk_widget_show (priv->label_status);
262 gtk_widget_show (priv->infobar);
264 g_object_unref (connectivity);
268 empathy_account_dialog_widget_cancelled_cb (
269 EmpathyAccountWidget *widget_object,
270 EmpathyAccountsDialog *dialog)
274 GtkTreeSelection *selection;
276 EmpathyAccountSettings *settings;
278 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
280 view = GTK_TREE_VIEW (priv->treeview);
281 selection = gtk_tree_view_get_selection (view);
283 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
286 gtk_tree_model_get (model, &iter,
287 COL_ACCOUNT_SETTINGS_POINTER, &settings,
288 COL_ACCOUNT_POINTER, &account, -1);
290 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
294 /* We were creating an account. We remove the selected row */
295 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
299 /* We were modifying an account. We discard the changes by reloading the
300 * settings and the UI. */
301 accounts_dialog_update_settings (dialog, settings);
302 g_object_unref (account);
305 if (settings != NULL)
306 g_object_unref (settings);
310 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
311 EmpathyAccountsDialog *dialog)
314 EmpathyAccountSettings *settings =
315 accounts_dialog_model_get_selected_settings (dialog);
317 display_name = empathy_account_widget_get_default_display_name (
320 empathy_account_settings_set_display_name_async (settings,
321 display_name, NULL, NULL);
323 g_free (display_name);
325 accounts_dialog_update_settings (dialog, settings);
328 g_object_unref (settings);
332 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
333 EmpathyAccountSettings *settings)
335 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
339 priv->setting_widget_object =
340 empathy_account_widget_new_for_protocol (settings, FALSE);
342 priv->settings_widget =
343 empathy_account_widget_get_widget (priv->setting_widget_object);
345 priv->settings_widget =
346 empathy_account_widget_get_widget (priv->setting_widget_object);
347 g_signal_connect (priv->setting_widget_object, "account-created",
348 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
349 g_signal_connect (priv->setting_widget_object, "cancelled",
350 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
352 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
353 priv->settings_widget);
354 gtk_widget_show (priv->settings_widget);
356 icon_name = empathy_account_settings_get_icon_name (settings);
358 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
360 /* show the default icon; keep this in sync with the default
361 * one in empathy-accounts-dialog.ui.
363 icon_name = GTK_STOCK_CUT;
365 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
366 icon_name, GTK_ICON_SIZE_DIALOG);
367 gtk_widget_set_tooltip_text (priv->image_type,
368 empathy_protocol_name_to_display_name
369 (empathy_account_settings_get_protocol (settings)));
370 gtk_widget_show (priv->image_type);
372 accounts_dialog_update_name_label (dialog,
373 empathy_account_settings_get_display_name (settings));
375 account = empathy_account_settings_get_account (settings);
376 accounts_dialog_update_status_infobar (dialog, account);
380 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
382 EmpathyAccountsDialog *dialog)
384 if (empathy_account_settings_is_ready (settings))
385 account_dialog_create_settings_widget (dialog, settings);
389 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
393 GtkTreeSelection *selection;
395 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
398 view = GTK_TREE_VIEW (priv->treeview);
399 model = gtk_tree_view_get_model (view);
401 if (gtk_tree_model_get_iter_first (model, &iter))
403 selection = gtk_tree_view_get_selection (view);
404 gtk_tree_selection_select_iter (selection, &iter);
408 accounts_dialog_update_settings (dialog, NULL);
413 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
418 GtkTreeSelection *selection;
419 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
421 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
423 if (gtk_tree_selection_get_selected (selection, &model, &iter))
424 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
426 return priv->setting_widget_object != NULL
427 && empathy_account_widget_contains_pending_changes (
428 priv->setting_widget_object);
432 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
433 EmpathyAccountsDialog *dialog)
435 TpConnectionManager *cm;
436 TpConnectionManagerProtocol *proto;
438 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
440 cm = empathy_protocol_chooser_dup_selected (
441 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
453 if (tp_connection_manager_protocol_can_register (proto) && !is_gtalk)
455 gtk_widget_show (priv->radiobutton_register);
456 gtk_widget_show (priv->radiobutton_reuse);
460 gtk_widget_hide (priv->radiobutton_register);
461 gtk_widget_hide (priv->radiobutton_reuse);
464 gtk_widget_hide (priv->radiobutton_register);
465 gtk_widget_hide (priv->radiobutton_reuse);
472 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
476 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
478 view = GTK_TREE_VIEW (priv->treeview);
479 model = gtk_tree_view_get_model (view);
481 gtk_widget_set_sensitive (priv->button_add, FALSE);
482 gtk_widget_hide (priv->vbox_details);
483 gtk_widget_hide (priv->frame_no_protocol);
484 gtk_widget_show (priv->frame_new_account);
486 /* If we have no account, no need of a back button */
487 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
488 gtk_widget_show (priv->button_back);
490 gtk_widget_hide (priv->button_back);
492 accounts_dialog_protocol_changed_cb (priv->radiobutton_register, dialog);
493 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->radiobutton_reuse),
495 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
496 gtk_widget_grab_focus (priv->combobox_protocol);
500 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
501 const gchar *primary_text,
502 const gchar *secondary_text,
503 GCallback response_callback,
505 const gchar *first_button_text,
509 GtkWidget *message_dialog;
510 const gchar *button_text;
511 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
513 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
514 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
515 GTK_MESSAGE_QUESTION,
519 gtk_message_dialog_format_secondary_text (
520 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
522 va_start (button_args, first_button_text);
523 for (button_text = first_button_text;
525 button_text = va_arg (button_args, const gchar *))
528 response_id = va_arg (button_args, gint);
530 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
533 va_end (button_args);
535 g_signal_connect (message_dialog, "response", response_callback, user_data);
537 gtk_widget_show (message_dialog);
541 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
545 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
546 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
548 gtk_widget_destroy (GTK_WIDGET (message_dialog));
550 if (response_id == GTK_RESPONSE_YES)
552 empathy_account_widget_discard_pending_changes (
553 priv->setting_widget_object);
554 accounts_dialog_setup_ui_to_add_account (dialog);
559 get_dialog_primary_text (TpAccount *account)
563 /* Existing account */
564 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
565 tp_account_get_display_name (account));
569 /* Newly created account */
570 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
575 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
576 EmpathyAccountsDialog *dialog)
578 TpAccount *account = NULL;
580 if (accounts_dialog_has_pending_change (dialog, &account))
582 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
584 accounts_dialog_show_question_dialog (dialog,
585 question_dialog_primary_text,
586 _("You are about to create a new account, which will discard\n"
587 "your changes. Are you sure you want to proceed?"),
588 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
590 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
591 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
593 g_free (question_dialog_primary_text);
597 accounts_dialog_setup_ui_to_add_account (dialog);
602 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
603 EmpathyAccountSettings *settings)
605 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
607 if (priv->settings_ready != NULL)
609 g_signal_handler_disconnect (priv->settings_ready,
610 priv->settings_ready_id);
611 priv->settings_ready = NULL;
612 priv->settings_ready_id = 0;
619 GtkTreeSelection *selection;
621 view = GTK_TREE_VIEW (priv->treeview);
622 model = gtk_tree_view_get_model (view);
623 selection = gtk_tree_view_get_selection (view);
625 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
627 /* We have configured accounts, select the first one if there
628 * is no other account selected already. */
629 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
630 accounts_dialog_model_select_first (dialog);
634 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
636 /* We have no account configured but we have some
637 * profiles installed. The user obviously wants to add
638 * an account. Click on the Add button for him. */
639 accounts_dialog_button_add_clicked_cb (priv->button_add,
644 /* No account and no profile, warn the user */
645 gtk_widget_hide (priv->vbox_details);
646 gtk_widget_hide (priv->frame_new_account);
647 gtk_widget_show (priv->frame_no_protocol);
648 gtk_widget_set_sensitive (priv->button_add, FALSE);
652 /* We have an account selected, destroy old settings and create a new
653 * one for the account selected */
654 gtk_widget_hide (priv->frame_new_account);
655 gtk_widget_hide (priv->frame_no_protocol);
656 gtk_widget_show (priv->vbox_details);
657 gtk_widget_set_sensitive (priv->button_add, TRUE);
659 if (priv->settings_widget)
661 gtk_widget_destroy (priv->settings_widget);
662 priv->settings_widget = NULL;
665 if (empathy_account_settings_is_ready (settings))
667 account_dialog_create_settings_widget (dialog, settings);
671 priv->settings_ready = settings;
672 priv->settings_ready_id =
673 g_signal_connect (settings, "notify::ready",
674 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
680 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
681 GtkCellEditable *editable,
683 EmpathyAccountsDialog *dialog)
685 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
687 if (priv->connecting_id)
688 g_source_remove (priv->connecting_id);
690 DEBUG ("Editing account name started; stopping flashing");
694 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
695 GtkCellRenderer *cell,
698 EmpathyAccountsDialog *dialog)
700 EmpathyAccountSettings *settings;
703 TpConnectionStatus status;
704 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
706 gtk_tree_model_get (model, iter,
708 COL_ACCOUNT_SETTINGS_POINTER, &settings,
711 icon_name = empathy_account_settings_get_icon_name (settings);
712 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
716 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
717 (status == TP_CONNECTION_STATUS_CONNECTING &&
718 !priv->connecting_show))
720 GdkPixbuf *modded_pixbuf;
722 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
725 gdk_pixbuf_get_width (pixbuf),
726 gdk_pixbuf_get_height (pixbuf));
728 gdk_pixbuf_saturate_and_pixelate (pixbuf,
732 g_object_unref (pixbuf);
733 pixbuf = modded_pixbuf;
742 g_object_unref (settings);
745 g_object_unref (pixbuf);
749 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
754 gtk_tree_model_row_changed (model, path, iter);
760 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
764 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
766 priv->connecting_show = !priv->connecting_show;
768 view = GTK_TREE_VIEW (priv->treeview);
769 model = gtk_tree_view_get_model (view);
771 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
777 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
780 EmpathyAccountsDialog *dialog)
782 EmpathyAccountSettings *settings;
784 GtkTreePath *treepath;
786 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
789 empathy_account_manager_get_accounts_connected (&connecting);
793 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
794 (GSourceFunc) accounts_dialog_flash_connecting_cb,
798 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
799 treepath = gtk_tree_path_new_from_string (path);
800 gtk_tree_model_get_iter (model, &iter, treepath);
801 gtk_tree_model_get (model, &iter,
802 COL_ACCOUNT_SETTINGS_POINTER, &settings,
804 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
807 gtk_tree_path_free (treepath);
809 empathy_account_settings_set_display_name_async (settings, new_text,
811 g_object_set (settings, "display-name-overridden", TRUE, NULL);
812 g_object_unref (settings);
816 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
823 GtkTreeSelection *selection;
824 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
825 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
827 if (response_id == GTK_RESPONSE_YES)
829 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
831 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
834 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
838 tp_account_remove_async (account, NULL, NULL);
839 g_object_unref (account);
843 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
844 accounts_dialog_model_select_first (account_dialog);
847 gtk_widget_destroy (GTK_WIDGET (message_dialog));
851 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
852 const gchar *path_string,
853 EmpathyAccountsDialog *dialog)
858 gchar *question_dialog_primary_text;
859 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
861 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
863 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
866 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
868 if (account == NULL || !tp_account_is_valid (account))
870 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
871 accounts_dialog_model_select_first (dialog);
875 question_dialog_primary_text = g_strdup_printf (
876 _("Do you want to remove %s from your computer?"),
877 tp_account_get_display_name (account));
879 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
880 _("This will not remove your account on the server."),
881 G_CALLBACK (accounts_dialog_delete_account_response_cb),
883 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
884 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
886 g_free (question_dialog_primary_text);
890 g_object_unref (account);
896 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
899 GtkTreeViewColumn *column;
900 GtkCellRenderer *cell;
901 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
903 view = GTK_TREE_VIEW (priv->treeview);
904 gtk_tree_view_set_headers_visible (view, FALSE);
907 column = gtk_tree_view_column_new ();
908 gtk_tree_view_column_set_expand (column, TRUE);
909 gtk_tree_view_append_column (view, column);
912 cell = gtk_cell_renderer_pixbuf_new ();
913 gtk_tree_view_column_pack_start (column, cell, FALSE);
914 gtk_tree_view_column_set_cell_data_func (column, cell,
915 (GtkTreeCellDataFunc)
916 accounts_dialog_model_pixbuf_data_func,
921 cell = gtk_cell_renderer_text_new ();
923 "ellipsize", PANGO_ELLIPSIZE_END,
927 gtk_tree_view_column_pack_start (column, cell, TRUE);
928 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
929 g_signal_connect (cell, "edited",
930 G_CALLBACK (accounts_dialog_name_edited_cb),
932 g_signal_connect (cell, "editing-started",
933 G_CALLBACK (accounts_dialog_name_editing_started_cb),
935 g_object_set (cell, "ypad", 4, NULL);
938 cell = empathy_cell_renderer_activatable_new ();
939 gtk_tree_view_column_pack_start (column, cell, FALSE);
941 "icon-name", GTK_STOCK_DELETE,
942 "show-on-select", TRUE,
945 g_signal_connect (cell, "path-activated",
946 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
950 static EmpathyAccountSettings *
951 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
955 GtkTreeSelection *selection;
957 EmpathyAccountSettings *settings;
958 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
960 view = GTK_TREE_VIEW (priv->treeview);
961 selection = gtk_tree_view_get_selection (view);
963 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
966 gtk_tree_model_get (model, &iter,
967 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
973 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
974 EmpathyAccountsDialog *dialog)
976 EmpathyAccountSettings *settings;
979 gboolean is_selection;
981 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
983 settings = accounts_dialog_model_get_selected_settings (dialog);
984 accounts_dialog_update_settings (dialog, settings);
986 if (settings != NULL)
987 g_object_unref (settings);
991 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
995 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
996 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
998 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1000 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1002 /* The user wants to lose unsaved changes to the currently selected
1003 * account and select another account. We discard the changes and
1004 * select the other account. */
1006 GtkTreeSelection *selection;
1008 priv->force_change_row = TRUE;
1009 empathy_account_widget_discard_pending_changes (
1010 priv->setting_widget_object);
1012 path = gtk_tree_row_reference_get_path (priv->destination_row);
1013 selection = gtk_tree_view_get_selection (
1014 GTK_TREE_VIEW (priv->treeview));
1018 /* This will trigger a call to
1019 * accounts_dialog_account_selection_change() */
1020 gtk_tree_selection_select_path (selection, path);
1021 gtk_tree_path_free (path);
1024 gtk_tree_row_reference_free (priv->destination_row);
1028 priv->force_change_row = FALSE;
1033 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1034 GtkTreeModel *model,
1036 gboolean path_currently_selected,
1039 TpAccount *account = NULL;
1040 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1041 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1043 if (priv->force_change_row)
1045 /* We came back here because the user wants to discard changes to his
1046 * modified account. The changes have already been discarded so we
1047 * just change the selected row. */
1048 priv->force_change_row = FALSE;
1052 if (accounts_dialog_has_pending_change (dialog, &account))
1054 /* The currently selected account has some unsaved changes. We ask
1055 * the user if he really wants to lose his changes and select another
1057 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1058 priv->destination_row = gtk_tree_row_reference_new (model, path);
1060 accounts_dialog_show_question_dialog (dialog,
1061 question_dialog_primary_text,
1062 _("You are about to select another account, which will discard\n"
1063 "your changes. Are you sure you want to proceed?"),
1064 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1066 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1067 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1069 g_free (question_dialog_primary_text);
1080 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1082 GtkListStore *store;
1083 GtkTreeSelection *selection;
1084 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1086 store = gtk_list_store_new (COL_COUNT,
1087 G_TYPE_STRING, /* name */
1088 G_TYPE_UINT, /* status */
1089 TP_TYPE_ACCOUNT, /* account */
1090 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1092 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1093 GTK_TREE_MODEL (store));
1095 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1096 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1097 gtk_tree_selection_set_select_function (selection,
1098 accounts_dialog_account_selection_change, dialog, NULL);
1100 g_signal_connect (selection, "changed",
1101 G_CALLBACK (accounts_dialog_model_selection_changed),
1104 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1105 COL_NAME, GTK_SORT_ASCENDING);
1107 accounts_dialog_model_add_columns (dialog);
1109 g_object_unref (store);
1113 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1114 EmpathyAccountSettings *settings,
1118 GtkTreeSelection *selection;
1119 GtkTreeModel *model;
1121 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1123 /* Update the status in the model */
1124 view = GTK_TREE_VIEW (priv->treeview);
1125 selection = gtk_tree_view_get_selection (view);
1126 model = gtk_tree_view_get_model (view);
1128 for (ok = gtk_tree_model_get_iter_first (model, iter);
1130 ok = gtk_tree_model_iter_next (model, iter))
1132 EmpathyAccountSettings *this_settings;
1135 gtk_tree_model_get (model, iter,
1136 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1139 equal = (this_settings == settings);
1140 g_object_unref (this_settings);
1150 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1155 GtkTreeSelection *selection;
1156 GtkTreeModel *model;
1158 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1160 /* Update the status in the model */
1161 view = GTK_TREE_VIEW (priv->treeview);
1162 selection = gtk_tree_view_get_selection (view);
1163 model = gtk_tree_view_get_model (view);
1165 for (ok = gtk_tree_model_get_iter_first (model, iter);
1167 ok = gtk_tree_model_iter_next (model, iter))
1169 EmpathyAccountSettings *settings;
1172 gtk_tree_model_get (model, iter,
1173 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1176 equal = empathy_account_settings_has_account (settings, account);
1177 g_object_unref (settings);
1187 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1188 EmpathyAccountSettings *settings)
1190 GtkTreeSelection *selection;
1192 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1194 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1195 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1196 gtk_tree_selection_select_iter (selection, &iter);
1199 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1200 EmpathyAccountSettings *settings)
1202 GtkTreeModel *model;
1205 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1207 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1208 name = empathy_account_settings_get_display_name (settings);
1210 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1212 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1214 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1215 COL_ACCOUNT_SETTINGS_POINTER, settings,
1220 accounts_dialog_connection_changed_cb (TpAccount *account,
1224 gchar *dbus_error_name,
1225 GHashTable *details,
1226 EmpathyAccountsDialog *dialog)
1228 GtkTreeModel *model;
1231 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1233 /* Update the status-infobar in the details view*/
1234 accounts_dialog_update_status_infobar (dialog, account);
1236 /* Update the status in the model */
1237 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1239 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1243 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1244 COL_STATUS, current,
1247 path = gtk_tree_model_get_path (model, &iter);
1248 gtk_tree_model_row_changed (model, path, &iter);
1249 gtk_tree_path_free (path);
1252 empathy_account_manager_get_accounts_connected (&found);
1254 if (!found && priv->connecting_id)
1256 g_source_remove (priv->connecting_id);
1257 priv->connecting_id = 0;
1260 if (found && !priv->connecting_id)
1261 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1262 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1267 accounts_dialog_presence_changed_cb (TpAccount *account,
1270 gchar *status_message,
1271 EmpathyAccountsDialog *dialog)
1273 /* Update the status-infobar in the details view*/
1274 accounts_dialog_update_status_infobar (dialog, account);
1278 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1282 const gchar *display_name;
1284 GtkTreeModel *model;
1285 EmpathyAccountSettings *settings;
1286 TpAccount *selected_account;
1287 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1288 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1290 display_name = tp_account_get_display_name (account);
1291 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1292 settings = accounts_dialog_model_get_selected_settings (dialog);
1293 if (settings == NULL)
1296 selected_account = empathy_account_settings_get_account (settings);
1298 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1300 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1301 COL_NAME, display_name,
1305 if (selected_account == account)
1306 accounts_dialog_update_name_label (dialog, display_name);
1308 g_object_unref (settings);
1312 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1315 EmpathyAccountSettings *settings;
1316 GtkTreeModel *model;
1318 TpConnectionStatus status;
1321 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1324 status = tp_account_get_connection_status (account, NULL);
1325 name = tp_account_get_display_name (account);
1326 enabled = tp_account_is_enabled (account);
1328 settings = empathy_account_settings_new_for_account (account);
1330 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1331 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1333 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1336 COL_ACCOUNT_POINTER, account,
1337 COL_ACCOUNT_SETTINGS_POINTER, settings,
1340 accounts_dialog_connection_changed_cb (account,
1343 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1348 empathy_signal_connect_weak (account, "notify::display-name",
1349 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1352 g_object_unref (settings);
1356 account_prepare_cb (GObject *source_object,
1357 GAsyncResult *result,
1360 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1361 TpAccount *account = TP_ACCOUNT (source_object);
1362 GError *error = NULL;
1364 if (!tp_account_prepare_finish (account, result, &error))
1366 DEBUG ("Failed to prepare account: %s", error->message);
1367 g_error_free (error);
1371 accounts_dialog_add_account (dialog, account);
1375 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1378 EmpathyAccountsDialog *dialog)
1380 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1384 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1386 EmpathyAccountsDialog *dialog)
1389 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1391 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1393 gtk_list_store_remove (GTK_LIST_STORE (
1394 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1399 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1403 GtkTreeModel *model;
1404 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1406 /* Update the status in the model */
1407 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1409 /* Update the status-infobar in the details view when disabling*/
1411 accounts_dialog_update_status_infobar (dialog, account);
1413 DEBUG ("Account %s is now %s",
1414 tp_account_get_display_name (account),
1415 enabled ? "enabled" : "disabled");
1419 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1421 EmpathyAccountsDialog *dialog)
1423 enable_or_disable_account (dialog, account, FALSE);
1427 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1429 EmpathyAccountsDialog *dialog)
1431 enable_or_disable_account (dialog, account, TRUE);
1435 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1436 EmpathyAccountsDialog *dialog)
1438 EmpathyAccountSettings *settings;
1440 const gchar *display_name;
1441 TpConnectionManager *cm;
1442 TpConnectionManagerProtocol *proto;
1443 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1446 cm = empathy_protocol_chooser_dup_selected (
1447 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1449 display_name = empathy_protocol_name_to_display_name (
1450 is_gtalk ? "gtalk" : proto->name);
1452 if (display_name == NULL)
1453 display_name = proto->name;
1455 /* Create account */
1456 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1459 str = g_strdup_printf (_("New %s account"), display_name);
1460 settings = empathy_account_settings_new (cm->name, proto->name, str);
1465 if (tp_connection_manager_protocol_can_register (proto))
1469 active = gtk_toggle_button_get_active
1470 (GTK_TOGGLE_BUTTON (priv->radiobutton_register));
1472 empathy_account_settings_set_boolean (settings, "register", TRUE);
1477 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1480 accounts_dialog_add (dialog, settings);
1481 accounts_dialog_model_set_selected (dialog, settings);
1483 g_object_unref (settings);
1484 g_object_unref (cm);
1488 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1489 EmpathyAccountsDialog *dialog)
1491 EmpathyAccountSettings *settings;
1493 settings = accounts_dialog_model_get_selected_settings (dialog);
1494 accounts_dialog_update_settings (dialog, settings);
1497 g_object_unref (settings);
1501 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1502 EmpathyAccountsDialog *dialog)
1504 empathy_url_show (button, "ghelp:empathy?accounts-window");
1508 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1509 EmpathyAccountsDialog *dialog)
1511 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1512 GtkWidget *import_dialog;
1514 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1516 gtk_widget_show (import_dialog);
1520 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1524 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1526 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1528 if (response_id == GTK_RESPONSE_YES)
1529 gtk_widget_destroy (account_dialog);
1533 accounts_dialog_response_cb (GtkWidget *widget,
1535 EmpathyAccountsDialog *dialog)
1537 TpAccount *account = NULL;
1539 if (accounts_dialog_has_pending_change (dialog, &account))
1541 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1543 accounts_dialog_show_question_dialog (dialog,
1544 question_dialog_primary_text,
1545 _("You are about to close the window, which will discard\n"
1546 "your changes. Are you sure you want to proceed?"),
1547 G_CALLBACK (accounts_dialog_close_response_cb),
1549 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1550 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1552 g_free (question_dialog_primary_text);
1554 else if (response == GTK_RESPONSE_CLOSE ||
1555 response == GTK_RESPONSE_DELETE_EVENT)
1556 gtk_widget_destroy (widget);
1560 accounts_dialog_delete_event_cb (GtkWidget *widget,
1562 EmpathyAccountsDialog *dialog)
1564 /* we maunally handle responses to delete events */
1569 accounts_dialog_destroy_cb (GtkObject *obj,
1570 EmpathyAccountsDialog *dialog)
1574 g_object_unref (dialog);
1578 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1581 GtkTreeSelection *selection;
1583 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1585 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1586 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1587 gtk_tree_selection_select_iter (selection, &iter);
1591 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1593 EmpathyAccountsDialog *dialog)
1595 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1597 if (empathy_connection_managers_is_ready (cms))
1599 accounts_dialog_update_settings (dialog, NULL);
1601 if (priv->initial_selection != NULL)
1603 accounts_dialog_set_selected_account
1604 (dialog, priv->initial_selection);
1605 g_object_unref (priv->initial_selection);
1606 priv->initial_selection = NULL;
1612 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1614 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1615 GList *accounts, *l;
1617 g_signal_connect (priv->account_manager, "account-validity-changed",
1618 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1620 g_signal_connect (priv->account_manager, "account-removed",
1621 G_CALLBACK (accounts_dialog_account_removed_cb),
1623 g_signal_connect (priv->account_manager, "account-enabled",
1624 G_CALLBACK (accounts_dialog_account_enabled_cb),
1626 g_signal_connect (priv->account_manager, "account-disabled",
1627 G_CALLBACK (accounts_dialog_account_disabled_cb),
1630 /* Add existing accounts */
1631 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1632 for (l = accounts; l; l = l->next)
1634 accounts_dialog_add_account (dialog, l->data);
1636 empathy_signal_connect_weak (l->data, "status-changed",
1637 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1638 empathy_signal_connect_weak (l->data, "presence-changed",
1639 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1641 g_list_free (accounts);
1643 priv->cms = empathy_connection_managers_dup_singleton ();
1644 if (!empathy_connection_managers_is_ready (priv->cms))
1645 g_signal_connect (priv->cms, "notify::ready",
1646 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1648 accounts_dialog_model_select_first (dialog);
1652 accounts_dialog_manager_ready_cb (GObject *source_object,
1653 GAsyncResult *result,
1656 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1657 GError *error = NULL;
1659 if (!tp_account_manager_prepare_finish (manager, result, &error))
1661 DEBUG ("Failed to prepare account manager: %s", error->message);
1662 g_error_free (error);
1666 accounts_dialog_accounts_setup (user_data);
1670 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1674 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1675 GtkWidget *content_area;
1677 GtkWidget *action_area;
1680 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1682 gui = empathy_builder_get_file (filename,
1683 "accounts_dialog", &priv->window,
1684 "vbox_details", &priv->vbox_details,
1685 "frame_no_protocol", &priv->frame_no_protocol,
1686 "alignment_settings", &priv->alignment_settings,
1687 "alignment_infobar", &priv->alignment_infobar,
1688 "treeview", &priv->treeview,
1689 "frame_new_account", &priv->frame_new_account,
1690 "hbox_type", &priv->hbox_type,
1691 "button_create", &priv->button_create,
1692 "button_back", &priv->button_back,
1693 "radiobutton_reuse", &priv->radiobutton_reuse,
1694 "radiobutton_register", &priv->radiobutton_register,
1695 "image_type", &priv->image_type,
1696 "label_name", &priv->label_name,
1697 "button_add", &priv->button_add,
1698 "button_import", &priv->button_import,
1702 empathy_builder_connect (gui, dialog,
1703 "accounts_dialog", "response", accounts_dialog_response_cb,
1704 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1705 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1706 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1707 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1708 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1709 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1710 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1713 g_object_unref (gui);
1716 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1717 gtk_widget_hide (action_area);
1719 /* Translators: this is used only when built on a moblin platform */
1720 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1721 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1724 priv->combobox_protocol = empathy_protocol_chooser_new ();
1725 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1726 priv->combobox_protocol,
1728 gtk_widget_show (priv->combobox_protocol);
1729 g_signal_connect (priv->combobox_protocol, "changed",
1730 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1733 if (priv->parent_window)
1734 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1735 priv->parent_window);
1737 /* set up spinner */
1738 priv->throbber = ephy_spinner_new ();
1739 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1741 priv->infobar = gtk_info_bar_new ();
1742 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1744 gtk_widget_show (priv->infobar);
1746 priv->image_status = gtk_image_new_from_icon_name (
1747 empathy_icon_name_for_presence (
1748 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1750 priv->label_status = gtk_label_new (NULL);
1752 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1753 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1755 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1757 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1761 do_dispose (GObject *obj)
1763 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1764 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1766 /* Disconnect signals */
1767 g_signal_handlers_disconnect_by_func (priv->account_manager,
1768 accounts_dialog_account_validity_changed_cb,
1770 g_signal_handlers_disconnect_by_func (priv->account_manager,
1771 accounts_dialog_account_removed_cb,
1773 g_signal_handlers_disconnect_by_func (priv->account_manager,
1774 accounts_dialog_account_enabled_cb,
1776 g_signal_handlers_disconnect_by_func (priv->account_manager,
1777 accounts_dialog_account_disabled_cb,
1779 g_signal_handlers_disconnect_by_func (priv->account_manager,
1780 accounts_dialog_manager_ready_cb,
1783 if (priv->connecting_id)
1784 g_source_remove (priv->connecting_id);
1786 if (priv->account_manager != NULL)
1788 g_object_unref (priv->account_manager);
1789 priv->account_manager = NULL;
1792 if (priv->cms != NULL)
1794 g_object_unref (priv->cms);
1798 if (priv->initial_selection != NULL)
1799 g_object_unref (priv->initial_selection);
1800 priv->initial_selection = NULL;
1802 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1806 do_constructor (GType type,
1808 GObjectConstructParam *props)
1812 if (dialog_singleton)
1814 retval = G_OBJECT (dialog_singleton);
1815 g_object_ref (retval);
1820 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1821 (type, n_props, props);
1823 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1824 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1825 /* We add an extra reference that we'll release when the dialog is
1826 * destroyed (accounts_dialog_destroy_cb) */
1827 g_object_ref (retval);
1834 do_get_property (GObject *object,
1839 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1841 switch (property_id)
1844 g_value_set_object (value, priv->parent_window);
1847 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1852 do_set_property (GObject *object,
1854 const GValue *value,
1857 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1859 switch (property_id)
1862 priv->parent_window = g_value_get_object (value);
1865 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1870 do_constructed (GObject *object)
1872 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1873 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1874 gboolean import_asked;
1876 accounts_dialog_build_ui (dialog);
1877 accounts_dialog_model_setup (dialog);
1879 /* Set up signalling */
1880 priv->account_manager = tp_account_manager_dup ();
1882 tp_account_manager_prepare_async (priv->account_manager, NULL,
1883 accounts_dialog_manager_ready_cb, dialog);
1885 empathy_conf_get_bool (empathy_conf_get (),
1886 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1888 if (empathy_import_accounts_to_import ())
1890 gtk_widget_show (priv->button_import);
1894 GtkWidget *import_dialog;
1896 empathy_conf_set_bool (empathy_conf_get (),
1897 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1898 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1900 gtk_widget_show (import_dialog);
1906 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1908 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1909 GParamSpec *param_spec;
1911 oclass->constructor = do_constructor;
1912 oclass->dispose = do_dispose;
1913 oclass->constructed = do_constructed;
1914 oclass->set_property = do_set_property;
1915 oclass->get_property = do_get_property;
1917 param_spec = g_param_spec_object ("parent",
1918 "parent", "The parent window",
1920 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1921 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1923 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1927 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1929 EmpathyAccountsDialogPriv *priv;
1931 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1932 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1933 EmpathyAccountsDialogPriv);
1934 dialog->priv = priv;
1937 /* public methods */
1940 empathy_accounts_dialog_show (GtkWindow *parent,
1941 TpAccount *selected_account)
1943 EmpathyAccountsDialog *dialog;
1944 EmpathyAccountsDialogPriv *priv;
1946 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1947 "parent", parent, NULL);
1949 priv = GET_PRIV (dialog);
1951 if (selected_account)
1953 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1954 accounts_dialog_set_selected_account (dialog, selected_account);
1956 /* save the selection to set it later when the cms
1959 priv->initial_selection = g_object_ref (selected_account);
1962 gtk_window_present (GTK_WINDOW (priv->window));
1963 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1964 * destroyed so we can release the ref returned by the constructor now. */
1965 g_object_unref (dialog);
1967 return priv->window;