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 *combobox_protocol;
95 GtkWidget *hbox_protocol;
97 GtkWidget *image_type;
98 GtkWidget *label_name;
99 GtkWidget *label_type;
100 GtkWidget *settings_widget;
102 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
103 * his GtkWidget. It is the only reliable source we can query to know if
104 * there are any unsaved changes to the currently selected account. We can't
105 * look at the account settings because it does not contain everything that
106 * can be changed using the EmpathyAccountWidget. For instance, it does not
107 * contain the state of the "Enabled" checkbox. */
108 EmpathyAccountWidget *setting_widget_object;
110 gboolean connecting_show;
113 gulong settings_ready_id;
114 EmpathyAccountSettings *settings_ready;
116 TpAccountManager *account_manager;
117 EmpathyConnectionManagers *cms;
119 GtkWindow *parent_window;
120 TpAccount *initial_selection;
122 /* Those are needed when changing the selected row. When a user selects
123 * another account and there are unsaved changes on the currently selected
124 * one, a confirmation message box is presented to him. Since his answer
125 * is retrieved asynchronously, we keep some information as member of the
126 * EmpathyAccountsDialog object. */
127 gboolean force_change_row;
128 GtkTreeRowReference *destination_row;
131 } EmpathyAccountsDialogPriv;
137 COL_ACCOUNT_SETTINGS_POINTER,
145 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
146 EmpathyAccountsDialog *dialog);
148 static gboolean accounts_dialog_get_settings_iter (
149 EmpathyAccountsDialog *dialog,
150 EmpathyAccountSettings *settings,
153 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
155 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
156 EmpathyAccountSettings *settings);
158 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
159 EmpathyAccountSettings *settings);
161 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
162 EmpathyAccountSettings *settings);
165 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
166 const gchar *display_name)
169 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
171 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
172 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
178 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
181 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
182 const gchar *message;
183 gchar *status_message = NULL;
187 EmpathyConnectivity *connectivity;
190 GtkTreeSelection *selection;
192 TpAccount *selected_account;
193 gboolean account_enabled;
194 gboolean creating_account;
196 view = GTK_TREE_VIEW (priv->treeview);
197 selection = gtk_tree_view_get_selection (view);
199 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
202 gtk_tree_model_get (model, &iter,
203 COL_ACCOUNT_POINTER, &selected_account, -1);
205 /* do not update the infobar when the account is not selected */
206 if (account != selected_account)
211 status = tp_account_get_connection_status (account, &reason);
212 presence = tp_account_get_current_presence (account, NULL, &status_message);
213 account_enabled = tp_account_is_enabled (account);
214 creating_account = FALSE;
218 status = TP_CONNECTION_STATUS_DISCONNECTED;
219 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
220 account_enabled = FALSE;
221 creating_account = TRUE;
224 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
225 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
231 case TP_CONNECTION_STATUS_CONNECTING:
232 message = _("Connecting…");
233 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
236 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
237 gtk_widget_show (priv->throbber);
238 gtk_widget_hide (priv->image_status);
240 case TP_CONNECTION_STATUS_CONNECTED:
241 if (g_strcmp0 (status_message, "") == 0)
243 message = g_strdup_printf ("%s",
244 empathy_presence_get_default_message (presence));
248 message = g_strdup_printf ("%s — %s",
249 empathy_presence_get_default_message (presence),
252 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
255 gtk_widget_show (priv->image_status);
256 gtk_widget_hide (priv->throbber);
258 case TP_CONNECTION_STATUS_DISCONNECTED:
259 message = g_strdup_printf (_("Disconnected — %s"),
260 empathy_status_reason_get_default_message (reason));
262 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
264 message = g_strdup_printf (_("Offline — %s"),
265 empathy_status_reason_get_default_message (reason));
266 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
267 GTK_MESSAGE_WARNING);
271 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
275 connectivity = empathy_connectivity_dup_singleton ();
276 if (!empathy_connectivity_is_online (connectivity))
277 message = _("Offline — No Network Connection");
279 g_object_unref (connectivity);
280 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
281 gtk_widget_show (priv->image_status);
282 gtk_widget_hide (priv->throbber);
285 message = _("Unknown Status");
286 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
287 GTK_MESSAGE_WARNING);
289 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
290 gtk_widget_hide (priv->image_status);
291 gtk_widget_hide (priv->throbber);
296 message = _("Offline — Account Disabled");
298 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
299 GTK_MESSAGE_WARNING);
300 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
301 gtk_widget_show (priv->image_status);
302 gtk_widget_hide (priv->throbber);
305 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
306 gtk_widget_show (priv->label_status);
308 if (!creating_account)
309 gtk_widget_show (priv->infobar);
311 gtk_widget_hide (priv->infobar);
313 g_free (status_message);
317 empathy_account_dialog_widget_cancelled_cb (
318 EmpathyAccountWidget *widget_object,
319 EmpathyAccountsDialog *dialog)
323 GtkTreeSelection *selection;
325 EmpathyAccountSettings *settings;
327 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
329 view = GTK_TREE_VIEW (priv->treeview);
330 selection = gtk_tree_view_get_selection (view);
332 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
335 gtk_tree_model_get (model, &iter,
336 COL_ACCOUNT_SETTINGS_POINTER, &settings,
337 COL_ACCOUNT_POINTER, &account, -1);
339 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
343 /* We were creating an account. We remove the selected row */
344 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
348 /* We were modifying an account. We discard the changes by reloading the
349 * settings and the UI. */
350 accounts_dialog_update_settings (dialog, settings);
351 g_object_unref (account);
354 if (settings != NULL)
355 g_object_unref (settings);
359 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
360 EmpathyAccountsDialog *dialog)
363 EmpathyAccountSettings *settings =
364 accounts_dialog_model_get_selected_settings (dialog);
366 display_name = empathy_account_widget_get_default_display_name (
369 empathy_account_settings_set_display_name_async (settings,
370 display_name, NULL, NULL);
372 g_free (display_name);
374 accounts_dialog_update_settings (dialog, settings);
375 accounts_dialog_update_status_infobar (dialog,
376 empathy_account_settings_get_account (settings));
379 g_object_unref (settings);
383 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
384 EmpathyAccountSettings *settings)
386 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
390 priv->setting_widget_object =
391 empathy_account_widget_new_for_protocol (settings, FALSE);
393 priv->settings_widget =
394 empathy_account_widget_get_widget (priv->setting_widget_object);
396 g_signal_connect (priv->setting_widget_object, "account-created",
397 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
398 g_signal_connect (priv->setting_widget_object, "cancelled",
399 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
401 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
402 priv->settings_widget);
403 gtk_widget_show (priv->settings_widget);
405 icon_name = empathy_account_settings_get_icon_name (settings);
407 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
409 /* show the default icon; keep this in sync with the default
410 * one in empathy-accounts-dialog.ui.
412 icon_name = GTK_STOCK_CUT;
414 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
415 icon_name, GTK_ICON_SIZE_DIALOG);
416 gtk_widget_set_tooltip_text (priv->image_type,
417 empathy_protocol_name_to_display_name
418 (empathy_account_settings_get_protocol (settings)));
419 gtk_widget_show (priv->image_type);
421 accounts_dialog_update_name_label (dialog,
422 empathy_account_settings_get_display_name (settings));
424 account = empathy_account_settings_get_account (settings);
425 accounts_dialog_update_status_infobar (dialog, account);
429 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
431 EmpathyAccountsDialog *dialog)
433 if (empathy_account_settings_is_ready (settings))
434 account_dialog_create_settings_widget (dialog, settings);
438 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
442 GtkTreeSelection *selection;
444 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
447 view = GTK_TREE_VIEW (priv->treeview);
448 model = gtk_tree_view_get_model (view);
450 if (gtk_tree_model_get_iter_first (model, &iter))
452 selection = gtk_tree_view_get_selection (view);
453 gtk_tree_selection_select_iter (selection, &iter);
457 accounts_dialog_update_settings (dialog, NULL);
462 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
467 GtkTreeSelection *selection;
468 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
470 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
472 if (gtk_tree_selection_get_selected (selection, &model, &iter))
473 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
475 return priv->setting_widget_object != NULL
476 && empathy_account_widget_contains_pending_changes (
477 priv->setting_widget_object);
481 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
483 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
484 EmpathyAccountSettings *settings;
486 const gchar *display_name;
487 TpConnectionManager *cm;
488 TpConnectionManagerProtocol *proto;
491 cm = empathy_protocol_chooser_dup_selected (
492 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
496 display_name = empathy_protocol_name_to_display_name (
497 is_gtalk ? "gtalk" : proto->name);
499 if (display_name == NULL)
500 display_name = proto->name;
503 /* To translator: %s is the name of the protocol, such as "Google Talk" or
506 str = g_strdup_printf (_("New %s account"), display_name);
507 settings = empathy_account_settings_new (cm->name, proto->name, str);
512 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
515 accounts_dialog_add (dialog, settings);
516 accounts_dialog_model_set_selected (dialog, settings);
518 gtk_widget_show_all (priv->hbox_protocol);
520 g_object_unref (settings);
525 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
526 EmpathyAccountsDialog *dialog)
528 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
529 GtkTreeSelection *selection;
534 /* The "changed" signal is fired during the initiation of the
535 * EmpathyProtocolChooser while populating the widget. Such signals should
536 * be ignored so we check if we are actually creating a new account. */
537 if (priv->setting_widget_object == NULL)
540 g_object_get (priv->setting_widget_object,
541 "creating-account", &creating, NULL);
545 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
547 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
550 /* We are creating a new widget to replace the current one, don't ask
551 * confirmation to the user. */
552 priv->force_change_row = TRUE;
553 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
555 accounts_dialog_setup_ui_to_add_account (dialog);
559 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
560 const gchar *primary_text,
561 const gchar *secondary_text,
562 GCallback response_callback,
564 const gchar *first_button_text,
568 GtkWidget *message_dialog;
569 const gchar *button_text;
570 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
572 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
573 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
574 GTK_MESSAGE_QUESTION,
578 gtk_message_dialog_format_secondary_text (
579 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
581 va_start (button_args, first_button_text);
582 for (button_text = first_button_text;
584 button_text = va_arg (button_args, const gchar *))
587 response_id = va_arg (button_args, gint);
589 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
592 va_end (button_args);
594 g_signal_connect (message_dialog, "response", response_callback, user_data);
596 gtk_widget_show (message_dialog);
600 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
604 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
605 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
607 gtk_widget_destroy (GTK_WIDGET (message_dialog));
609 if (response_id == GTK_RESPONSE_YES)
611 empathy_account_widget_discard_pending_changes (
612 priv->setting_widget_object);
613 accounts_dialog_setup_ui_to_add_account (dialog);
618 get_dialog_primary_text (TpAccount *account)
622 /* Existing account */
623 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
624 tp_account_get_display_name (account));
628 /* Newly created account */
629 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
634 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
635 EmpathyAccountsDialog *dialog)
637 TpAccount *account = NULL;
639 if (accounts_dialog_has_pending_change (dialog, &account))
641 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
643 accounts_dialog_show_question_dialog (dialog,
644 question_dialog_primary_text,
645 _("You are about to create a new account, which will discard\n"
646 "your changes. Are you sure you want to proceed?"),
647 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
649 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
650 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
652 g_free (question_dialog_primary_text);
656 accounts_dialog_setup_ui_to_add_account (dialog);
661 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
662 EmpathyAccountSettings *settings)
664 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
666 if (priv->settings_ready != NULL)
668 g_signal_handler_disconnect (priv->settings_ready,
669 priv->settings_ready_id);
670 priv->settings_ready = NULL;
671 priv->settings_ready_id = 0;
678 GtkTreeSelection *selection;
680 view = GTK_TREE_VIEW (priv->treeview);
681 model = gtk_tree_view_get_model (view);
682 selection = gtk_tree_view_get_selection (view);
684 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
686 /* We have configured accounts, select the first one if there
687 * is no other account selected already. */
688 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
689 accounts_dialog_model_select_first (dialog);
693 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
695 /* We have no account configured but we have some
696 * profiles installed. The user obviously wants to add
697 * an account. Click on the Add button for him. */
698 accounts_dialog_button_add_clicked_cb (priv->button_add,
703 /* No account and no profile, warn the user */
704 gtk_widget_hide (priv->vbox_details);
705 gtk_widget_show (priv->frame_no_protocol);
706 gtk_widget_set_sensitive (priv->button_add, FALSE);
710 /* We have an account selected, destroy old settings and create a new
711 * one for the account selected */
712 gtk_widget_hide (priv->frame_no_protocol);
713 gtk_widget_show (priv->vbox_details);
714 gtk_widget_set_sensitive (priv->button_add, TRUE);
715 gtk_widget_hide (priv->hbox_protocol);
717 if (priv->settings_widget)
719 gtk_widget_destroy (priv->settings_widget);
720 priv->settings_widget = NULL;
723 if (empathy_account_settings_is_ready (settings))
725 account_dialog_create_settings_widget (dialog, settings);
729 priv->settings_ready = settings;
730 priv->settings_ready_id =
731 g_signal_connect (settings, "notify::ready",
732 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
738 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
739 GtkCellEditable *editable,
741 EmpathyAccountsDialog *dialog)
743 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
745 if (priv->connecting_id)
746 g_source_remove (priv->connecting_id);
748 DEBUG ("Editing account name started; stopping flashing");
752 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
753 GtkCellRenderer *cell,
756 EmpathyAccountsDialog *dialog)
758 EmpathyAccountSettings *settings;
761 TpConnectionStatus status;
762 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
764 gtk_tree_model_get (model, iter,
766 COL_ACCOUNT_SETTINGS_POINTER, &settings,
769 icon_name = empathy_account_settings_get_icon_name (settings);
770 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
774 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
775 (status == TP_CONNECTION_STATUS_CONNECTING &&
776 !priv->connecting_show))
778 GdkPixbuf *modded_pixbuf;
780 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
783 gdk_pixbuf_get_width (pixbuf),
784 gdk_pixbuf_get_height (pixbuf));
786 gdk_pixbuf_saturate_and_pixelate (pixbuf,
790 g_object_unref (pixbuf);
791 pixbuf = modded_pixbuf;
800 g_object_unref (settings);
803 g_object_unref (pixbuf);
807 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
812 gtk_tree_model_row_changed (model, path, iter);
818 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
822 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
824 priv->connecting_show = !priv->connecting_show;
826 view = GTK_TREE_VIEW (priv->treeview);
827 model = gtk_tree_view_get_model (view);
829 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
835 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
838 EmpathyAccountsDialog *dialog)
840 EmpathyAccountSettings *settings;
842 GtkTreePath *treepath;
844 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
847 empathy_account_manager_get_accounts_connected (&connecting);
851 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
852 (GSourceFunc) accounts_dialog_flash_connecting_cb,
856 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
857 treepath = gtk_tree_path_new_from_string (path);
858 gtk_tree_model_get_iter (model, &iter, treepath);
859 gtk_tree_model_get (model, &iter,
860 COL_ACCOUNT_SETTINGS_POINTER, &settings,
862 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
865 gtk_tree_path_free (treepath);
867 empathy_account_settings_set_display_name_async (settings, new_text,
869 g_object_set (settings, "display-name-overridden", TRUE, NULL);
870 g_object_unref (settings);
874 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
881 GtkTreeSelection *selection;
882 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
883 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
885 if (response_id == GTK_RESPONSE_YES)
887 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
889 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
892 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
896 tp_account_remove_async (account, NULL, NULL);
897 g_object_unref (account);
901 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
902 accounts_dialog_model_select_first (account_dialog);
905 gtk_widget_destroy (GTK_WIDGET (message_dialog));
909 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
910 const gchar *path_string,
911 EmpathyAccountsDialog *dialog)
916 gchar *question_dialog_primary_text;
917 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
919 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
921 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
924 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
926 if (account == NULL || !tp_account_is_valid (account))
928 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
929 accounts_dialog_model_select_first (dialog);
933 question_dialog_primary_text = g_strdup_printf (
934 _("Do you want to remove %s from your computer?"),
935 tp_account_get_display_name (account));
937 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
938 _("This will not remove your account on the server."),
939 G_CALLBACK (accounts_dialog_delete_account_response_cb),
941 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
942 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
944 g_free (question_dialog_primary_text);
948 g_object_unref (account);
954 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
957 GtkTreeViewColumn *column;
958 GtkCellRenderer *cell;
959 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
961 view = GTK_TREE_VIEW (priv->treeview);
962 gtk_tree_view_set_headers_visible (view, FALSE);
965 column = gtk_tree_view_column_new ();
966 gtk_tree_view_column_set_expand (column, TRUE);
967 gtk_tree_view_append_column (view, column);
970 cell = gtk_cell_renderer_pixbuf_new ();
971 gtk_tree_view_column_pack_start (column, cell, FALSE);
972 gtk_tree_view_column_set_cell_data_func (column, cell,
973 (GtkTreeCellDataFunc)
974 accounts_dialog_model_pixbuf_data_func,
979 cell = gtk_cell_renderer_text_new ();
981 "ellipsize", PANGO_ELLIPSIZE_END,
985 gtk_tree_view_column_pack_start (column, cell, TRUE);
986 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
987 g_signal_connect (cell, "edited",
988 G_CALLBACK (accounts_dialog_name_edited_cb),
990 g_signal_connect (cell, "editing-started",
991 G_CALLBACK (accounts_dialog_name_editing_started_cb),
993 g_object_set (cell, "ypad", 4, NULL);
996 cell = empathy_cell_renderer_activatable_new ();
997 gtk_tree_view_column_pack_start (column, cell, FALSE);
999 "icon-name", GTK_STOCK_DELETE,
1000 "show-on-select", TRUE,
1003 g_signal_connect (cell, "path-activated",
1004 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1008 static EmpathyAccountSettings *
1009 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1012 GtkTreeModel *model;
1013 GtkTreeSelection *selection;
1015 EmpathyAccountSettings *settings;
1016 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1018 view = GTK_TREE_VIEW (priv->treeview);
1019 selection = gtk_tree_view_get_selection (view);
1021 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1024 gtk_tree_model_get (model, &iter,
1025 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1031 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1032 EmpathyAccountsDialog *dialog)
1034 EmpathyAccountSettings *settings;
1035 GtkTreeModel *model;
1037 gboolean is_selection;
1039 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1041 settings = accounts_dialog_model_get_selected_settings (dialog);
1042 accounts_dialog_update_settings (dialog, settings);
1044 if (settings != NULL)
1045 g_object_unref (settings);
1049 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1051 gpointer *user_data)
1053 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1054 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1056 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1058 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1060 /* The user wants to lose unsaved changes to the currently selected
1061 * account and select another account. We discard the changes and
1062 * select the other account. */
1064 GtkTreeSelection *selection;
1066 priv->force_change_row = TRUE;
1067 empathy_account_widget_discard_pending_changes (
1068 priv->setting_widget_object);
1070 path = gtk_tree_row_reference_get_path (priv->destination_row);
1071 selection = gtk_tree_view_get_selection (
1072 GTK_TREE_VIEW (priv->treeview));
1076 /* This will trigger a call to
1077 * accounts_dialog_account_selection_change() */
1078 gtk_tree_selection_select_path (selection, path);
1079 gtk_tree_path_free (path);
1082 gtk_tree_row_reference_free (priv->destination_row);
1086 priv->force_change_row = FALSE;
1091 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1092 GtkTreeModel *model,
1094 gboolean path_currently_selected,
1097 TpAccount *account = NULL;
1098 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1099 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1101 if (priv->force_change_row)
1103 /* We came back here because the user wants to discard changes to his
1104 * modified account. The changes have already been discarded so we
1105 * just change the selected row. */
1106 priv->force_change_row = FALSE;
1110 if (accounts_dialog_has_pending_change (dialog, &account))
1112 /* The currently selected account has some unsaved changes. We ask
1113 * the user if he really wants to lose his changes and select another
1115 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1116 priv->destination_row = gtk_tree_row_reference_new (model, path);
1118 accounts_dialog_show_question_dialog (dialog,
1119 question_dialog_primary_text,
1120 _("You are about to select another account, which will discard\n"
1121 "your changes. Are you sure you want to proceed?"),
1122 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1124 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1125 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1127 g_free (question_dialog_primary_text);
1138 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1140 GtkListStore *store;
1141 GtkTreeSelection *selection;
1142 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1144 store = gtk_list_store_new (COL_COUNT,
1145 G_TYPE_STRING, /* name */
1146 G_TYPE_UINT, /* status */
1147 TP_TYPE_ACCOUNT, /* account */
1148 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1150 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1151 GTK_TREE_MODEL (store));
1153 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1154 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1155 gtk_tree_selection_set_select_function (selection,
1156 accounts_dialog_account_selection_change, dialog, NULL);
1158 g_signal_connect (selection, "changed",
1159 G_CALLBACK (accounts_dialog_model_selection_changed),
1162 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1163 COL_NAME, GTK_SORT_ASCENDING);
1165 accounts_dialog_model_add_columns (dialog);
1167 g_object_unref (store);
1171 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1172 EmpathyAccountSettings *settings,
1176 GtkTreeSelection *selection;
1177 GtkTreeModel *model;
1179 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1181 /* Update the status in the model */
1182 view = GTK_TREE_VIEW (priv->treeview);
1183 selection = gtk_tree_view_get_selection (view);
1184 model = gtk_tree_view_get_model (view);
1186 for (ok = gtk_tree_model_get_iter_first (model, iter);
1188 ok = gtk_tree_model_iter_next (model, iter))
1190 EmpathyAccountSettings *this_settings;
1193 gtk_tree_model_get (model, iter,
1194 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1197 equal = (this_settings == settings);
1198 g_object_unref (this_settings);
1208 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1213 GtkTreeSelection *selection;
1214 GtkTreeModel *model;
1216 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1218 /* Update the status in the model */
1219 view = GTK_TREE_VIEW (priv->treeview);
1220 selection = gtk_tree_view_get_selection (view);
1221 model = gtk_tree_view_get_model (view);
1223 for (ok = gtk_tree_model_get_iter_first (model, iter);
1225 ok = gtk_tree_model_iter_next (model, iter))
1227 EmpathyAccountSettings *settings;
1230 gtk_tree_model_get (model, iter,
1231 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1234 equal = empathy_account_settings_has_account (settings, account);
1235 g_object_unref (settings);
1245 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1246 EmpathyAccountSettings *settings)
1248 GtkTreeSelection *selection;
1250 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1252 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1253 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1254 gtk_tree_selection_select_iter (selection, &iter);
1257 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1258 EmpathyAccountSettings *settings)
1260 GtkTreeModel *model;
1263 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1265 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1266 name = empathy_account_settings_get_display_name (settings);
1268 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1270 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1272 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1273 COL_ACCOUNT_SETTINGS_POINTER, settings,
1278 accounts_dialog_connection_changed_cb (TpAccount *account,
1282 gchar *dbus_error_name,
1283 GHashTable *details,
1284 EmpathyAccountsDialog *dialog)
1286 GtkTreeModel *model;
1289 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1291 /* Update the status-infobar in the details view */
1292 accounts_dialog_update_status_infobar (dialog, account);
1294 /* Update the status in the model */
1295 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1297 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1301 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1302 COL_STATUS, current,
1305 path = gtk_tree_model_get_path (model, &iter);
1306 gtk_tree_model_row_changed (model, path, &iter);
1307 gtk_tree_path_free (path);
1310 empathy_account_manager_get_accounts_connected (&found);
1312 if (!found && priv->connecting_id)
1314 g_source_remove (priv->connecting_id);
1315 priv->connecting_id = 0;
1318 if (found && !priv->connecting_id)
1319 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1320 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1325 accounts_dialog_presence_changed_cb (TpAccount *account,
1328 gchar *status_message,
1329 EmpathyAccountsDialog *dialog)
1331 /* Update the status-infobar in the details view */
1332 accounts_dialog_update_status_infobar (dialog, account);
1336 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1340 const gchar *display_name;
1342 GtkTreeModel *model;
1343 EmpathyAccountSettings *settings;
1344 TpAccount *selected_account;
1345 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1346 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1348 display_name = tp_account_get_display_name (account);
1349 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1350 settings = accounts_dialog_model_get_selected_settings (dialog);
1351 if (settings == NULL)
1354 selected_account = empathy_account_settings_get_account (settings);
1356 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1358 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1359 COL_NAME, display_name,
1363 if (selected_account == account)
1364 accounts_dialog_update_name_label (dialog, display_name);
1366 g_object_unref (settings);
1370 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1373 EmpathyAccountSettings *settings;
1374 GtkTreeModel *model;
1376 TpConnectionStatus status;
1379 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1381 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1382 status = tp_account_get_connection_status (account, NULL);
1383 name = tp_account_get_display_name (account);
1384 enabled = tp_account_is_enabled (account);
1386 settings = empathy_account_settings_new_for_account (account);
1388 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1389 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1391 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1394 COL_ACCOUNT_POINTER, account,
1395 COL_ACCOUNT_SETTINGS_POINTER, settings,
1398 accounts_dialog_connection_changed_cb (account,
1401 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1406 empathy_signal_connect_weak (account, "notify::display-name",
1407 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1410 g_object_unref (settings);
1414 account_prepare_cb (GObject *source_object,
1415 GAsyncResult *result,
1418 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1419 TpAccount *account = TP_ACCOUNT (source_object);
1420 GError *error = NULL;
1422 if (!tp_account_prepare_finish (account, result, &error))
1424 DEBUG ("Failed to prepare account: %s", error->message);
1425 g_error_free (error);
1429 accounts_dialog_add_account (dialog, account);
1433 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1436 EmpathyAccountsDialog *dialog)
1438 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1442 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1444 EmpathyAccountsDialog *dialog)
1447 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1449 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1451 gtk_list_store_remove (GTK_LIST_STORE (
1452 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1457 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1461 GtkTreeModel *model;
1462 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1464 /* Update the status in the model */
1465 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1467 /* Update the status-infobar in the details view when disabling */
1469 accounts_dialog_update_status_infobar (dialog, account);
1471 DEBUG ("Account %s is now %s",
1472 tp_account_get_display_name (account),
1473 enabled ? "enabled" : "disabled");
1477 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1479 EmpathyAccountsDialog *dialog)
1481 enable_or_disable_account (dialog, account, FALSE);
1485 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1487 EmpathyAccountsDialog *dialog)
1489 enable_or_disable_account (dialog, account, TRUE);
1493 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1494 EmpathyAccountsDialog *dialog)
1496 empathy_url_show (button, "ghelp:empathy?accounts-window");
1500 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1501 EmpathyAccountsDialog *dialog)
1503 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1504 GtkWidget *import_dialog;
1506 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1508 gtk_widget_show (import_dialog);
1512 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1516 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1518 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1520 if (response_id == GTK_RESPONSE_YES)
1521 gtk_widget_destroy (account_dialog);
1525 accounts_dialog_response_cb (GtkWidget *widget,
1527 EmpathyAccountsDialog *dialog)
1529 TpAccount *account = NULL;
1531 if (accounts_dialog_has_pending_change (dialog, &account))
1533 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1535 accounts_dialog_show_question_dialog (dialog,
1536 question_dialog_primary_text,
1537 _("You are about to close the window, which will discard\n"
1538 "your changes. Are you sure you want to proceed?"),
1539 G_CALLBACK (accounts_dialog_close_response_cb),
1541 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1542 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1544 g_free (question_dialog_primary_text);
1546 else if (response == GTK_RESPONSE_CLOSE ||
1547 response == GTK_RESPONSE_DELETE_EVENT)
1548 gtk_widget_destroy (widget);
1552 accounts_dialog_delete_event_cb (GtkWidget *widget,
1554 EmpathyAccountsDialog *dialog)
1556 /* we maunally handle responses to delete events */
1561 accounts_dialog_destroy_cb (GtkObject *obj,
1562 EmpathyAccountsDialog *dialog)
1566 g_object_unref (dialog);
1570 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1573 GtkTreeSelection *selection;
1575 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1577 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1578 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1579 gtk_tree_selection_select_iter (selection, &iter);
1583 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1585 EmpathyAccountsDialog *dialog)
1587 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1589 if (empathy_connection_managers_is_ready (cms))
1591 accounts_dialog_update_settings (dialog, NULL);
1593 if (priv->initial_selection != NULL)
1595 accounts_dialog_set_selected_account
1596 (dialog, priv->initial_selection);
1597 g_object_unref (priv->initial_selection);
1598 priv->initial_selection = NULL;
1604 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1606 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1607 GList *accounts, *l;
1609 g_signal_connect (priv->account_manager, "account-validity-changed",
1610 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1612 g_signal_connect (priv->account_manager, "account-removed",
1613 G_CALLBACK (accounts_dialog_account_removed_cb),
1615 g_signal_connect (priv->account_manager, "account-enabled",
1616 G_CALLBACK (accounts_dialog_account_enabled_cb),
1618 g_signal_connect (priv->account_manager, "account-disabled",
1619 G_CALLBACK (accounts_dialog_account_disabled_cb),
1622 /* Add existing accounts */
1623 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1624 for (l = accounts; l; l = l->next)
1626 accounts_dialog_add_account (dialog, l->data);
1628 empathy_signal_connect_weak (l->data, "status-changed",
1629 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1630 empathy_signal_connect_weak (l->data, "presence-changed",
1631 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1633 g_list_free (accounts);
1635 priv->cms = empathy_connection_managers_dup_singleton ();
1636 if (!empathy_connection_managers_is_ready (priv->cms))
1637 g_signal_connect (priv->cms, "notify::ready",
1638 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1640 accounts_dialog_model_select_first (dialog);
1644 accounts_dialog_manager_ready_cb (GObject *source_object,
1645 GAsyncResult *result,
1648 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1649 GError *error = NULL;
1651 if (!tp_account_manager_prepare_finish (manager, result, &error))
1653 DEBUG ("Failed to prepare account manager: %s", error->message);
1654 g_error_free (error);
1658 accounts_dialog_accounts_setup (user_data);
1662 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1666 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1667 GtkWidget *content_area;
1669 GtkWidget *action_area;
1672 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1674 gui = empathy_builder_get_file (filename,
1675 "accounts_dialog", &priv->window,
1676 "vbox_details", &priv->vbox_details,
1677 "frame_no_protocol", &priv->frame_no_protocol,
1678 "alignment_settings", &priv->alignment_settings,
1679 "alignment_infobar", &priv->alignment_infobar,
1680 "treeview", &priv->treeview,
1681 "image_type", &priv->image_type,
1682 "label_name", &priv->label_name,
1683 "button_add", &priv->button_add,
1684 "button_import", &priv->button_import,
1685 "hbox_protocol", &priv->hbox_protocol,
1689 empathy_builder_connect (gui, dialog,
1690 "accounts_dialog", "response", accounts_dialog_response_cb,
1691 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1692 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1693 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1694 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1695 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1698 g_object_unref (gui);
1701 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1702 gtk_widget_hide (action_area);
1705 priv->combobox_protocol = empathy_protocol_chooser_new ();
1706 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
1708 g_signal_connect (priv->combobox_protocol, "changed",
1709 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1712 if (priv->parent_window)
1713 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1714 priv->parent_window);
1716 /* set up spinner */
1717 priv->throbber = ephy_spinner_new ();
1718 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1720 priv->infobar = gtk_info_bar_new ();
1721 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1723 gtk_widget_show (priv->infobar);
1725 priv->image_status = gtk_image_new_from_icon_name (
1726 empathy_icon_name_for_presence (
1727 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1729 priv->label_status = gtk_label_new (NULL);
1731 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1732 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1734 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1736 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1740 do_dispose (GObject *obj)
1742 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1743 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1745 /* Disconnect signals */
1746 g_signal_handlers_disconnect_by_func (priv->account_manager,
1747 accounts_dialog_account_validity_changed_cb,
1749 g_signal_handlers_disconnect_by_func (priv->account_manager,
1750 accounts_dialog_account_removed_cb,
1752 g_signal_handlers_disconnect_by_func (priv->account_manager,
1753 accounts_dialog_account_enabled_cb,
1755 g_signal_handlers_disconnect_by_func (priv->account_manager,
1756 accounts_dialog_account_disabled_cb,
1758 g_signal_handlers_disconnect_by_func (priv->account_manager,
1759 accounts_dialog_manager_ready_cb,
1762 if (priv->connecting_id)
1763 g_source_remove (priv->connecting_id);
1765 if (priv->account_manager != NULL)
1767 g_object_unref (priv->account_manager);
1768 priv->account_manager = NULL;
1771 if (priv->cms != NULL)
1773 g_object_unref (priv->cms);
1777 if (priv->initial_selection != NULL)
1778 g_object_unref (priv->initial_selection);
1779 priv->initial_selection = NULL;
1781 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1785 do_constructor (GType type,
1787 GObjectConstructParam *props)
1791 if (dialog_singleton)
1793 retval = G_OBJECT (dialog_singleton);
1794 g_object_ref (retval);
1799 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1800 (type, n_props, props);
1802 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1803 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1804 /* We add an extra reference that we'll release when the dialog is
1805 * destroyed (accounts_dialog_destroy_cb) */
1806 g_object_ref (retval);
1813 do_get_property (GObject *object,
1818 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1820 switch (property_id)
1823 g_value_set_object (value, priv->parent_window);
1826 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1831 do_set_property (GObject *object,
1833 const GValue *value,
1836 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1838 switch (property_id)
1841 priv->parent_window = g_value_get_object (value);
1844 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1849 do_constructed (GObject *object)
1851 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1852 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1853 gboolean import_asked;
1855 accounts_dialog_build_ui (dialog);
1856 accounts_dialog_model_setup (dialog);
1858 /* Set up signalling */
1859 priv->account_manager = tp_account_manager_dup ();
1861 tp_account_manager_prepare_async (priv->account_manager, NULL,
1862 accounts_dialog_manager_ready_cb, dialog);
1864 empathy_conf_get_bool (empathy_conf_get (),
1865 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1867 if (empathy_import_accounts_to_import ())
1869 gtk_widget_show (priv->button_import);
1873 GtkWidget *import_dialog;
1875 empathy_conf_set_bool (empathy_conf_get (),
1876 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1877 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1879 gtk_widget_show (import_dialog);
1885 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1887 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1888 GParamSpec *param_spec;
1890 oclass->constructor = do_constructor;
1891 oclass->dispose = do_dispose;
1892 oclass->constructed = do_constructed;
1893 oclass->set_property = do_set_property;
1894 oclass->get_property = do_get_property;
1896 param_spec = g_param_spec_object ("parent",
1897 "parent", "The parent window",
1899 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1900 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1902 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1906 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1908 EmpathyAccountsDialogPriv *priv;
1910 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1911 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1912 EmpathyAccountsDialogPriv);
1913 dialog->priv = priv;
1916 /* public methods */
1919 empathy_accounts_dialog_show (GtkWindow *parent,
1920 TpAccount *selected_account)
1922 EmpathyAccountsDialog *dialog;
1923 EmpathyAccountsDialogPriv *priv;
1925 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1926 "parent", parent, NULL);
1928 priv = GET_PRIV (dialog);
1930 if (selected_account)
1932 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1933 accounts_dialog_set_selected_account (dialog, selected_account);
1935 /* save the selection to set it later when the cms
1938 priv->initial_selection = g_object_ref (selected_account);
1941 gtk_window_present (GTK_WINDOW (priv->window));
1942 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1943 * destroyed so we can release the ref returned by the constructor now. */
1944 g_object_unref (dialog);
1946 return priv->window;