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;
100 GtkWidget *image_type;
101 GtkWidget *label_name;
102 GtkWidget *label_type;
103 GtkWidget *settings_widget;
105 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
106 * his GtkWidget. It is the only reliable source we can query to know if
107 * there are any unsaved changes to the currently selected account. We can't
108 * look at the account settings because it does not contain everything that
109 * can be changed using the EmpathyAccountWidget. For instance, it does not
110 * contain the state of the "Enabled" checkbox. */
111 EmpathyAccountWidget *setting_widget_object;
113 gboolean connecting_show;
116 gulong settings_ready_id;
117 EmpathyAccountSettings *settings_ready;
119 TpAccountManager *account_manager;
120 EmpathyConnectionManagers *cms;
122 GtkWindow *parent_window;
123 TpAccount *initial_selection;
125 /* Those are needed when changing the selected row. When a user selects
126 * another account and there are unsaved changes on the currently selected
127 * one, a confirmation message box is presented to him. Since his answer
128 * is retrieved asynchronously, we keep some information as member of the
129 * EmpathyAccountsDialog object. */
130 gboolean force_change_row;
131 GtkTreeRowReference *destination_row;
134 } EmpathyAccountsDialogPriv;
140 COL_ACCOUNT_SETTINGS_POINTER,
148 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
149 EmpathyAccountsDialog *dialog);
151 static gboolean accounts_dialog_get_settings_iter (
152 EmpathyAccountsDialog *dialog,
153 EmpathyAccountSettings *settings,
156 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
158 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
159 EmpathyAccountSettings *settings);
162 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
163 const gchar *display_name)
166 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
168 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
169 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
175 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
178 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
179 const gchar *message;
180 gchar *status_message = NULL;
184 EmpathyConnectivity *connectivity;
187 GtkTreeSelection *selection;
189 TpAccount *selected_account;
190 gboolean account_enabled;
191 gboolean creating_account;
193 view = GTK_TREE_VIEW (priv->treeview);
194 selection = gtk_tree_view_get_selection (view);
196 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
199 gtk_tree_model_get (model, &iter,
200 COL_ACCOUNT_POINTER, &selected_account, -1);
202 /* do not update the infobar when the account is not selected */
203 if (account != selected_account)
208 status = tp_account_get_connection_status (account, &reason);
209 presence = tp_account_get_current_presence (account, NULL, &status_message);
210 account_enabled = tp_account_is_enabled (account);
211 creating_account = FALSE;
215 status = TP_CONNECTION_STATUS_DISCONNECTED;
216 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
217 account_enabled = FALSE;
218 creating_account = TRUE;
221 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
222 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
228 case TP_CONNECTION_STATUS_CONNECTING:
229 message = _("Connecting...");
230 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
233 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
234 gtk_widget_show (priv->throbber);
235 gtk_widget_hide (priv->image_status);
237 case TP_CONNECTION_STATUS_CONNECTED:
238 if (g_strcmp0 (status_message, "") == 0)
240 message = g_strdup_printf ("%s",
241 empathy_presence_get_default_message (presence));
245 message = g_strdup_printf ("%s - %s",
246 empathy_presence_get_default_message (presence),
249 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
252 gtk_widget_show (priv->image_status);
253 gtk_widget_hide (priv->throbber);
255 case TP_CONNECTION_STATUS_DISCONNECTED:
256 message = g_strdup_printf (_("Disconnected - %s"),
257 empathy_status_reason_get_default_message (reason));
259 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
261 message = g_strdup_printf (_("Offline - %s"),
262 empathy_status_reason_get_default_message (reason));
263 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
264 GTK_MESSAGE_WARNING);
268 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
272 connectivity = empathy_connectivity_dup_singleton ();
273 if (!empathy_connectivity_is_online (connectivity))
274 message = _("Offline - No Network Connection");
276 g_object_unref (connectivity);
277 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
278 gtk_widget_show (priv->image_status);
279 gtk_widget_hide (priv->throbber);
282 message = _("Unknown Status");
283 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
284 GTK_MESSAGE_WARNING);
286 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
287 gtk_widget_hide (priv->image_status);
288 gtk_widget_hide (priv->throbber);
293 message = _("Offline - Account disabled");
295 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
296 GTK_MESSAGE_WARNING);
297 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
298 gtk_widget_show (priv->image_status);
299 gtk_widget_hide (priv->throbber);
302 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
303 gtk_widget_show (priv->label_status);
305 if (!creating_account)
306 gtk_widget_show (priv->infobar);
308 gtk_widget_hide (priv->infobar);
310 g_free (status_message);
314 empathy_account_dialog_widget_cancelled_cb (
315 EmpathyAccountWidget *widget_object,
316 EmpathyAccountsDialog *dialog)
320 GtkTreeSelection *selection;
322 EmpathyAccountSettings *settings;
324 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
326 view = GTK_TREE_VIEW (priv->treeview);
327 selection = gtk_tree_view_get_selection (view);
329 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
332 gtk_tree_model_get (model, &iter,
333 COL_ACCOUNT_SETTINGS_POINTER, &settings,
334 COL_ACCOUNT_POINTER, &account, -1);
336 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
340 /* We were creating an account. We remove the selected row */
341 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
345 /* We were modifying an account. We discard the changes by reloading the
346 * settings and the UI. */
347 accounts_dialog_update_settings (dialog, settings);
348 g_object_unref (account);
351 if (settings != NULL)
352 g_object_unref (settings);
356 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
357 EmpathyAccountsDialog *dialog)
360 EmpathyAccountSettings *settings =
361 accounts_dialog_model_get_selected_settings (dialog);
363 display_name = empathy_account_widget_get_default_display_name (
366 empathy_account_settings_set_display_name_async (settings,
367 display_name, NULL, NULL);
369 g_free (display_name);
371 accounts_dialog_update_settings (dialog, settings);
372 accounts_dialog_update_status_infobar (dialog,
373 empathy_account_settings_get_account (settings));
376 g_object_unref (settings);
380 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
381 EmpathyAccountSettings *settings)
383 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
387 priv->setting_widget_object =
388 empathy_account_widget_new_for_protocol (settings, FALSE);
390 priv->settings_widget =
391 empathy_account_widget_get_widget (priv->setting_widget_object);
393 g_signal_connect (priv->setting_widget_object, "account-created",
394 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
395 g_signal_connect (priv->setting_widget_object, "cancelled",
396 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
398 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
399 priv->settings_widget);
400 gtk_widget_show (priv->settings_widget);
402 icon_name = empathy_account_settings_get_icon_name (settings);
404 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
406 /* show the default icon; keep this in sync with the default
407 * one in empathy-accounts-dialog.ui.
409 icon_name = GTK_STOCK_CUT;
411 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
412 icon_name, GTK_ICON_SIZE_DIALOG);
413 gtk_widget_set_tooltip_text (priv->image_type,
414 empathy_protocol_name_to_display_name
415 (empathy_account_settings_get_protocol (settings)));
416 gtk_widget_show (priv->image_type);
418 accounts_dialog_update_name_label (dialog,
419 empathy_account_settings_get_display_name (settings));
421 account = empathy_account_settings_get_account (settings);
422 accounts_dialog_update_status_infobar (dialog, account);
426 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
428 EmpathyAccountsDialog *dialog)
430 if (empathy_account_settings_is_ready (settings))
431 account_dialog_create_settings_widget (dialog, settings);
435 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
439 GtkTreeSelection *selection;
441 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
444 view = GTK_TREE_VIEW (priv->treeview);
445 model = gtk_tree_view_get_model (view);
447 if (gtk_tree_model_get_iter_first (model, &iter))
449 selection = gtk_tree_view_get_selection (view);
450 gtk_tree_selection_select_iter (selection, &iter);
454 accounts_dialog_update_settings (dialog, NULL);
459 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
464 GtkTreeSelection *selection;
465 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
467 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
469 if (gtk_tree_selection_get_selected (selection, &model, &iter))
470 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
472 return priv->setting_widget_object != NULL
473 && empathy_account_widget_contains_pending_changes (
474 priv->setting_widget_object);
478 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
479 EmpathyAccountsDialog *dialog)
481 TpConnectionManager *cm;
482 TpConnectionManagerProtocol *proto;
484 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
486 cm = empathy_protocol_chooser_dup_selected (
487 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
502 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
506 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
508 view = GTK_TREE_VIEW (priv->treeview);
509 model = gtk_tree_view_get_model (view);
511 gtk_widget_set_sensitive (priv->button_add, FALSE);
512 gtk_widget_hide (priv->vbox_details);
513 gtk_widget_hide (priv->frame_no_protocol);
514 gtk_widget_show (priv->frame_new_account);
516 /* If we have no account, no need of a back button */
517 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
518 gtk_widget_show (priv->button_back);
520 gtk_widget_hide (priv->button_back);
522 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox_protocol), 0);
523 gtk_widget_grab_focus (priv->combobox_protocol);
527 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
528 const gchar *primary_text,
529 const gchar *secondary_text,
530 GCallback response_callback,
532 const gchar *first_button_text,
536 GtkWidget *message_dialog;
537 const gchar *button_text;
538 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
540 message_dialog = gtk_message_dialog_new (GTK_WINDOW (priv->window),
541 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
542 GTK_MESSAGE_QUESTION,
546 gtk_message_dialog_format_secondary_text (
547 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
549 va_start (button_args, first_button_text);
550 for (button_text = first_button_text;
552 button_text = va_arg (button_args, const gchar *))
555 response_id = va_arg (button_args, gint);
557 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
560 va_end (button_args);
562 g_signal_connect (message_dialog, "response", response_callback, user_data);
564 gtk_widget_show (message_dialog);
568 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
572 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
573 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
575 gtk_widget_destroy (GTK_WIDGET (message_dialog));
577 if (response_id == GTK_RESPONSE_YES)
579 empathy_account_widget_discard_pending_changes (
580 priv->setting_widget_object);
581 accounts_dialog_setup_ui_to_add_account (dialog);
586 get_dialog_primary_text (TpAccount *account)
590 /* Existing account */
591 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
592 tp_account_get_display_name (account));
596 /* Newly created account */
597 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
602 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
603 EmpathyAccountsDialog *dialog)
605 TpAccount *account = NULL;
607 if (accounts_dialog_has_pending_change (dialog, &account))
609 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
611 accounts_dialog_show_question_dialog (dialog,
612 question_dialog_primary_text,
613 _("You are about to create a new account, which will discard\n"
614 "your changes. Are you sure you want to proceed?"),
615 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
617 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
618 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
620 g_free (question_dialog_primary_text);
624 accounts_dialog_setup_ui_to_add_account (dialog);
629 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
630 EmpathyAccountSettings *settings)
632 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
634 if (priv->settings_ready != NULL)
636 g_signal_handler_disconnect (priv->settings_ready,
637 priv->settings_ready_id);
638 priv->settings_ready = NULL;
639 priv->settings_ready_id = 0;
646 GtkTreeSelection *selection;
648 view = GTK_TREE_VIEW (priv->treeview);
649 model = gtk_tree_view_get_model (view);
650 selection = gtk_tree_view_get_selection (view);
652 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
654 /* We have configured accounts, select the first one if there
655 * is no other account selected already. */
656 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
657 accounts_dialog_model_select_first (dialog);
661 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
663 /* We have no account configured but we have some
664 * profiles installed. The user obviously wants to add
665 * an account. Click on the Add button for him. */
666 accounts_dialog_button_add_clicked_cb (priv->button_add,
671 /* No account and no profile, warn the user */
672 gtk_widget_hide (priv->vbox_details);
673 gtk_widget_hide (priv->frame_new_account);
674 gtk_widget_show (priv->frame_no_protocol);
675 gtk_widget_set_sensitive (priv->button_add, FALSE);
679 /* We have an account selected, destroy old settings and create a new
680 * one for the account selected */
681 gtk_widget_hide (priv->frame_new_account);
682 gtk_widget_hide (priv->frame_no_protocol);
683 gtk_widget_show (priv->vbox_details);
684 gtk_widget_set_sensitive (priv->button_add, TRUE);
686 if (priv->settings_widget)
688 gtk_widget_destroy (priv->settings_widget);
689 priv->settings_widget = NULL;
692 if (empathy_account_settings_is_ready (settings))
694 account_dialog_create_settings_widget (dialog, settings);
698 priv->settings_ready = settings;
699 priv->settings_ready_id =
700 g_signal_connect (settings, "notify::ready",
701 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
707 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
708 GtkCellEditable *editable,
710 EmpathyAccountsDialog *dialog)
712 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
714 if (priv->connecting_id)
715 g_source_remove (priv->connecting_id);
717 DEBUG ("Editing account name started; stopping flashing");
721 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
722 GtkCellRenderer *cell,
725 EmpathyAccountsDialog *dialog)
727 EmpathyAccountSettings *settings;
730 TpConnectionStatus status;
731 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
733 gtk_tree_model_get (model, iter,
735 COL_ACCOUNT_SETTINGS_POINTER, &settings,
738 icon_name = empathy_account_settings_get_icon_name (settings);
739 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
743 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
744 (status == TP_CONNECTION_STATUS_CONNECTING &&
745 !priv->connecting_show))
747 GdkPixbuf *modded_pixbuf;
749 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
752 gdk_pixbuf_get_width (pixbuf),
753 gdk_pixbuf_get_height (pixbuf));
755 gdk_pixbuf_saturate_and_pixelate (pixbuf,
759 g_object_unref (pixbuf);
760 pixbuf = modded_pixbuf;
769 g_object_unref (settings);
772 g_object_unref (pixbuf);
776 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
781 gtk_tree_model_row_changed (model, path, iter);
787 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
791 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
793 priv->connecting_show = !priv->connecting_show;
795 view = GTK_TREE_VIEW (priv->treeview);
796 model = gtk_tree_view_get_model (view);
798 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
804 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
807 EmpathyAccountsDialog *dialog)
809 EmpathyAccountSettings *settings;
811 GtkTreePath *treepath;
813 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
816 empathy_account_manager_get_accounts_connected (&connecting);
820 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
821 (GSourceFunc) accounts_dialog_flash_connecting_cb,
825 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
826 treepath = gtk_tree_path_new_from_string (path);
827 gtk_tree_model_get_iter (model, &iter, treepath);
828 gtk_tree_model_get (model, &iter,
829 COL_ACCOUNT_SETTINGS_POINTER, &settings,
831 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
834 gtk_tree_path_free (treepath);
836 empathy_account_settings_set_display_name_async (settings, new_text,
838 g_object_set (settings, "display-name-overridden", TRUE, NULL);
839 g_object_unref (settings);
843 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
850 GtkTreeSelection *selection;
851 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
852 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
854 if (response_id == GTK_RESPONSE_YES)
856 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
858 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
861 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
865 tp_account_remove_async (account, NULL, NULL);
866 g_object_unref (account);
870 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
871 accounts_dialog_model_select_first (account_dialog);
874 gtk_widget_destroy (GTK_WIDGET (message_dialog));
878 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
879 const gchar *path_string,
880 EmpathyAccountsDialog *dialog)
885 gchar *question_dialog_primary_text;
886 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
888 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
890 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
893 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
895 if (account == NULL || !tp_account_is_valid (account))
897 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
898 accounts_dialog_model_select_first (dialog);
902 question_dialog_primary_text = g_strdup_printf (
903 _("Do you want to remove %s from your computer?"),
904 tp_account_get_display_name (account));
906 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
907 _("This will not remove your account on the server."),
908 G_CALLBACK (accounts_dialog_delete_account_response_cb),
910 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
911 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
913 g_free (question_dialog_primary_text);
917 g_object_unref (account);
923 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
926 GtkTreeViewColumn *column;
927 GtkCellRenderer *cell;
928 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
930 view = GTK_TREE_VIEW (priv->treeview);
931 gtk_tree_view_set_headers_visible (view, FALSE);
934 column = gtk_tree_view_column_new ();
935 gtk_tree_view_column_set_expand (column, TRUE);
936 gtk_tree_view_append_column (view, column);
939 cell = gtk_cell_renderer_pixbuf_new ();
940 gtk_tree_view_column_pack_start (column, cell, FALSE);
941 gtk_tree_view_column_set_cell_data_func (column, cell,
942 (GtkTreeCellDataFunc)
943 accounts_dialog_model_pixbuf_data_func,
948 cell = gtk_cell_renderer_text_new ();
950 "ellipsize", PANGO_ELLIPSIZE_END,
954 gtk_tree_view_column_pack_start (column, cell, TRUE);
955 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
956 g_signal_connect (cell, "edited",
957 G_CALLBACK (accounts_dialog_name_edited_cb),
959 g_signal_connect (cell, "editing-started",
960 G_CALLBACK (accounts_dialog_name_editing_started_cb),
962 g_object_set (cell, "ypad", 4, NULL);
965 cell = empathy_cell_renderer_activatable_new ();
966 gtk_tree_view_column_pack_start (column, cell, FALSE);
968 "icon-name", GTK_STOCK_DELETE,
969 "show-on-select", TRUE,
972 g_signal_connect (cell, "path-activated",
973 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
977 static EmpathyAccountSettings *
978 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
982 GtkTreeSelection *selection;
984 EmpathyAccountSettings *settings;
985 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
987 view = GTK_TREE_VIEW (priv->treeview);
988 selection = gtk_tree_view_get_selection (view);
990 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
993 gtk_tree_model_get (model, &iter,
994 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1000 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1001 EmpathyAccountsDialog *dialog)
1003 EmpathyAccountSettings *settings;
1004 GtkTreeModel *model;
1006 gboolean is_selection;
1008 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1010 settings = accounts_dialog_model_get_selected_settings (dialog);
1011 accounts_dialog_update_settings (dialog, settings);
1013 if (settings != NULL)
1014 g_object_unref (settings);
1018 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1020 gpointer *user_data)
1022 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1023 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1025 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1027 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1029 /* The user wants to lose unsaved changes to the currently selected
1030 * account and select another account. We discard the changes and
1031 * select the other account. */
1033 GtkTreeSelection *selection;
1035 priv->force_change_row = TRUE;
1036 empathy_account_widget_discard_pending_changes (
1037 priv->setting_widget_object);
1039 path = gtk_tree_row_reference_get_path (priv->destination_row);
1040 selection = gtk_tree_view_get_selection (
1041 GTK_TREE_VIEW (priv->treeview));
1045 /* This will trigger a call to
1046 * accounts_dialog_account_selection_change() */
1047 gtk_tree_selection_select_path (selection, path);
1048 gtk_tree_path_free (path);
1051 gtk_tree_row_reference_free (priv->destination_row);
1055 priv->force_change_row = FALSE;
1060 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1061 GtkTreeModel *model,
1063 gboolean path_currently_selected,
1066 TpAccount *account = NULL;
1067 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1068 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1070 if (priv->force_change_row)
1072 /* We came back here because the user wants to discard changes to his
1073 * modified account. The changes have already been discarded so we
1074 * just change the selected row. */
1075 priv->force_change_row = FALSE;
1079 if (accounts_dialog_has_pending_change (dialog, &account))
1081 /* The currently selected account has some unsaved changes. We ask
1082 * the user if he really wants to lose his changes and select another
1084 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1085 priv->destination_row = gtk_tree_row_reference_new (model, path);
1087 accounts_dialog_show_question_dialog (dialog,
1088 question_dialog_primary_text,
1089 _("You are about to select another account, which will discard\n"
1090 "your changes. Are you sure you want to proceed?"),
1091 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1093 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1094 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1096 g_free (question_dialog_primary_text);
1107 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1109 GtkListStore *store;
1110 GtkTreeSelection *selection;
1111 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1113 store = gtk_list_store_new (COL_COUNT,
1114 G_TYPE_STRING, /* name */
1115 G_TYPE_UINT, /* status */
1116 TP_TYPE_ACCOUNT, /* account */
1117 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1119 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1120 GTK_TREE_MODEL (store));
1122 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1123 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1124 gtk_tree_selection_set_select_function (selection,
1125 accounts_dialog_account_selection_change, dialog, NULL);
1127 g_signal_connect (selection, "changed",
1128 G_CALLBACK (accounts_dialog_model_selection_changed),
1131 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1132 COL_NAME, GTK_SORT_ASCENDING);
1134 accounts_dialog_model_add_columns (dialog);
1136 g_object_unref (store);
1140 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1141 EmpathyAccountSettings *settings,
1145 GtkTreeSelection *selection;
1146 GtkTreeModel *model;
1148 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1150 /* Update the status in the model */
1151 view = GTK_TREE_VIEW (priv->treeview);
1152 selection = gtk_tree_view_get_selection (view);
1153 model = gtk_tree_view_get_model (view);
1155 for (ok = gtk_tree_model_get_iter_first (model, iter);
1157 ok = gtk_tree_model_iter_next (model, iter))
1159 EmpathyAccountSettings *this_settings;
1162 gtk_tree_model_get (model, iter,
1163 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1166 equal = (this_settings == settings);
1167 g_object_unref (this_settings);
1177 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1182 GtkTreeSelection *selection;
1183 GtkTreeModel *model;
1185 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1187 /* Update the status in the model */
1188 view = GTK_TREE_VIEW (priv->treeview);
1189 selection = gtk_tree_view_get_selection (view);
1190 model = gtk_tree_view_get_model (view);
1192 for (ok = gtk_tree_model_get_iter_first (model, iter);
1194 ok = gtk_tree_model_iter_next (model, iter))
1196 EmpathyAccountSettings *settings;
1199 gtk_tree_model_get (model, iter,
1200 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1203 equal = empathy_account_settings_has_account (settings, account);
1204 g_object_unref (settings);
1214 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1215 EmpathyAccountSettings *settings)
1217 GtkTreeSelection *selection;
1219 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1221 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1222 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1223 gtk_tree_selection_select_iter (selection, &iter);
1226 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1227 EmpathyAccountSettings *settings)
1229 GtkTreeModel *model;
1232 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1234 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1235 name = empathy_account_settings_get_display_name (settings);
1237 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1239 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1241 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1242 COL_ACCOUNT_SETTINGS_POINTER, settings,
1247 accounts_dialog_connection_changed_cb (TpAccount *account,
1251 gchar *dbus_error_name,
1252 GHashTable *details,
1253 EmpathyAccountsDialog *dialog)
1255 GtkTreeModel *model;
1258 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1260 /* Update the status-infobar in the details view */
1261 accounts_dialog_update_status_infobar (dialog, account);
1263 /* Update the status in the model */
1264 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1266 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1270 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1271 COL_STATUS, current,
1274 path = gtk_tree_model_get_path (model, &iter);
1275 gtk_tree_model_row_changed (model, path, &iter);
1276 gtk_tree_path_free (path);
1279 empathy_account_manager_get_accounts_connected (&found);
1281 if (!found && priv->connecting_id)
1283 g_source_remove (priv->connecting_id);
1284 priv->connecting_id = 0;
1287 if (found && !priv->connecting_id)
1288 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1289 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1294 accounts_dialog_presence_changed_cb (TpAccount *account,
1297 gchar *status_message,
1298 EmpathyAccountsDialog *dialog)
1300 /* Update the status-infobar in the details view */
1301 accounts_dialog_update_status_infobar (dialog, account);
1305 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1309 const gchar *display_name;
1311 GtkTreeModel *model;
1312 EmpathyAccountSettings *settings;
1313 TpAccount *selected_account;
1314 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1315 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1317 display_name = tp_account_get_display_name (account);
1318 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1319 settings = accounts_dialog_model_get_selected_settings (dialog);
1320 if (settings == NULL)
1323 selected_account = empathy_account_settings_get_account (settings);
1325 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1327 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1328 COL_NAME, display_name,
1332 if (selected_account == account)
1333 accounts_dialog_update_name_label (dialog, display_name);
1335 g_object_unref (settings);
1339 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1342 EmpathyAccountSettings *settings;
1343 GtkTreeModel *model;
1345 TpConnectionStatus status;
1348 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1350 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1351 status = tp_account_get_connection_status (account, NULL);
1352 name = tp_account_get_display_name (account);
1353 enabled = tp_account_is_enabled (account);
1355 settings = empathy_account_settings_new_for_account (account);
1357 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1358 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1360 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1363 COL_ACCOUNT_POINTER, account,
1364 COL_ACCOUNT_SETTINGS_POINTER, settings,
1367 accounts_dialog_connection_changed_cb (account,
1370 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1375 empathy_signal_connect_weak (account, "notify::display-name",
1376 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1379 g_object_unref (settings);
1383 account_prepare_cb (GObject *source_object,
1384 GAsyncResult *result,
1387 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1388 TpAccount *account = TP_ACCOUNT (source_object);
1389 GError *error = NULL;
1391 if (!tp_account_prepare_finish (account, result, &error))
1393 DEBUG ("Failed to prepare account: %s", error->message);
1394 g_error_free (error);
1398 accounts_dialog_add_account (dialog, account);
1402 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1405 EmpathyAccountsDialog *dialog)
1407 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1411 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1413 EmpathyAccountsDialog *dialog)
1416 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1418 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1420 gtk_list_store_remove (GTK_LIST_STORE (
1421 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1426 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1430 GtkTreeModel *model;
1431 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1433 /* Update the status in the model */
1434 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1436 /* Update the status-infobar in the details view when disabling */
1438 accounts_dialog_update_status_infobar (dialog, account);
1440 DEBUG ("Account %s is now %s",
1441 tp_account_get_display_name (account),
1442 enabled ? "enabled" : "disabled");
1446 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1448 EmpathyAccountsDialog *dialog)
1450 enable_or_disable_account (dialog, account, FALSE);
1454 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1456 EmpathyAccountsDialog *dialog)
1458 enable_or_disable_account (dialog, account, TRUE);
1462 accounts_dialog_button_create_clicked_cb (GtkWidget *button,
1463 EmpathyAccountsDialog *dialog)
1465 EmpathyAccountSettings *settings;
1467 const gchar *display_name;
1468 TpConnectionManager *cm;
1469 TpConnectionManagerProtocol *proto;
1470 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1473 cm = empathy_protocol_chooser_dup_selected (
1474 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
1476 display_name = empathy_protocol_name_to_display_name (
1477 is_gtalk ? "gtalk" : proto->name);
1479 if (display_name == NULL)
1480 display_name = proto->name;
1482 /* Create account */
1483 /* To translator: %s is the name of the protocol, such as "Google Talk" or
1486 str = g_strdup_printf (_("New %s account"), display_name);
1487 settings = empathy_account_settings_new (cm->name, proto->name, str);
1492 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
1495 accounts_dialog_add (dialog, settings);
1496 accounts_dialog_model_set_selected (dialog, settings);
1498 g_object_unref (settings);
1499 g_object_unref (cm);
1503 accounts_dialog_button_back_clicked_cb (GtkWidget *button,
1504 EmpathyAccountsDialog *dialog)
1506 EmpathyAccountSettings *settings;
1508 settings = accounts_dialog_model_get_selected_settings (dialog);
1509 accounts_dialog_update_settings (dialog, settings);
1512 g_object_unref (settings);
1516 accounts_dialog_button_help_clicked_cb (GtkWidget *button,
1517 EmpathyAccountsDialog *dialog)
1519 empathy_url_show (button, "ghelp:empathy?accounts-window");
1523 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1524 EmpathyAccountsDialog *dialog)
1526 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1527 GtkWidget *import_dialog;
1529 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1531 gtk_widget_show (import_dialog);
1535 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1539 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1541 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1543 if (response_id == GTK_RESPONSE_YES)
1544 gtk_widget_destroy (account_dialog);
1548 accounts_dialog_response_cb (GtkWidget *widget,
1550 EmpathyAccountsDialog *dialog)
1552 TpAccount *account = NULL;
1554 if (accounts_dialog_has_pending_change (dialog, &account))
1556 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1558 accounts_dialog_show_question_dialog (dialog,
1559 question_dialog_primary_text,
1560 _("You are about to close the window, which will discard\n"
1561 "your changes. Are you sure you want to proceed?"),
1562 G_CALLBACK (accounts_dialog_close_response_cb),
1564 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1565 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1567 g_free (question_dialog_primary_text);
1569 else if (response == GTK_RESPONSE_CLOSE ||
1570 response == GTK_RESPONSE_DELETE_EVENT)
1571 gtk_widget_destroy (widget);
1575 accounts_dialog_delete_event_cb (GtkWidget *widget,
1577 EmpathyAccountsDialog *dialog)
1579 /* we maunally handle responses to delete events */
1584 accounts_dialog_destroy_cb (GtkObject *obj,
1585 EmpathyAccountsDialog *dialog)
1589 g_object_unref (dialog);
1593 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1596 GtkTreeSelection *selection;
1598 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1600 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1601 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1602 gtk_tree_selection_select_iter (selection, &iter);
1606 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1608 EmpathyAccountsDialog *dialog)
1610 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1612 if (empathy_connection_managers_is_ready (cms))
1614 accounts_dialog_update_settings (dialog, NULL);
1616 if (priv->initial_selection != NULL)
1618 accounts_dialog_set_selected_account
1619 (dialog, priv->initial_selection);
1620 g_object_unref (priv->initial_selection);
1621 priv->initial_selection = NULL;
1627 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1629 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1630 GList *accounts, *l;
1632 g_signal_connect (priv->account_manager, "account-validity-changed",
1633 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1635 g_signal_connect (priv->account_manager, "account-removed",
1636 G_CALLBACK (accounts_dialog_account_removed_cb),
1638 g_signal_connect (priv->account_manager, "account-enabled",
1639 G_CALLBACK (accounts_dialog_account_enabled_cb),
1641 g_signal_connect (priv->account_manager, "account-disabled",
1642 G_CALLBACK (accounts_dialog_account_disabled_cb),
1645 /* Add existing accounts */
1646 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1647 for (l = accounts; l; l = l->next)
1649 accounts_dialog_add_account (dialog, l->data);
1651 empathy_signal_connect_weak (l->data, "status-changed",
1652 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1653 empathy_signal_connect_weak (l->data, "presence-changed",
1654 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1656 g_list_free (accounts);
1658 priv->cms = empathy_connection_managers_dup_singleton ();
1659 if (!empathy_connection_managers_is_ready (priv->cms))
1660 g_signal_connect (priv->cms, "notify::ready",
1661 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1663 accounts_dialog_model_select_first (dialog);
1667 accounts_dialog_manager_ready_cb (GObject *source_object,
1668 GAsyncResult *result,
1671 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1672 GError *error = NULL;
1674 if (!tp_account_manager_prepare_finish (manager, result, &error))
1676 DEBUG ("Failed to prepare account manager: %s", error->message);
1677 g_error_free (error);
1681 accounts_dialog_accounts_setup (user_data);
1685 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1689 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1690 GtkWidget *content_area;
1692 GtkWidget *action_area;
1695 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1697 gui = empathy_builder_get_file (filename,
1698 "accounts_dialog", &priv->window,
1699 "vbox_details", &priv->vbox_details,
1700 "frame_no_protocol", &priv->frame_no_protocol,
1701 "alignment_settings", &priv->alignment_settings,
1702 "alignment_infobar", &priv->alignment_infobar,
1703 "treeview", &priv->treeview,
1704 "frame_new_account", &priv->frame_new_account,
1705 "hbox_type", &priv->hbox_type,
1706 "button_create", &priv->button_create,
1707 "button_back", &priv->button_back,
1708 "image_type", &priv->image_type,
1709 "label_name", &priv->label_name,
1710 "button_add", &priv->button_add,
1711 "button_import", &priv->button_import,
1715 empathy_builder_connect (gui, dialog,
1716 "accounts_dialog", "response", accounts_dialog_response_cb,
1717 "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
1718 "accounts_dialog", "delete-event", accounts_dialog_delete_event_cb,
1719 "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
1720 "button_back", "clicked", accounts_dialog_button_back_clicked_cb,
1721 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1722 "button_help", "clicked", accounts_dialog_button_help_clicked_cb,
1723 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1726 g_object_unref (gui);
1729 action_area = gtk_dialog_get_action_area (GTK_DIALOG (priv->window));
1730 gtk_widget_hide (action_area);
1732 /* Translators: this is used only when built on a moblin platform */
1733 gtk_button_set_label (GTK_BUTTON (priv->button_create), _("_Next"));
1734 gtk_button_set_use_underline (GTK_BUTTON (priv->button_create), TRUE);
1737 priv->combobox_protocol = empathy_protocol_chooser_new ();
1738 gtk_box_pack_start (GTK_BOX (priv->hbox_type),
1739 priv->combobox_protocol,
1741 gtk_widget_show (priv->combobox_protocol);
1742 g_signal_connect (priv->combobox_protocol, "changed",
1743 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1746 if (priv->parent_window)
1747 gtk_window_set_transient_for (GTK_WINDOW (priv->window),
1748 priv->parent_window);
1750 /* set up spinner */
1751 priv->throbber = ephy_spinner_new ();
1752 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1754 priv->infobar = gtk_info_bar_new ();
1755 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1757 gtk_widget_show (priv->infobar);
1759 priv->image_status = gtk_image_new_from_icon_name (
1760 empathy_icon_name_for_presence (
1761 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1763 priv->label_status = gtk_label_new (NULL);
1765 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1766 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1768 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1770 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1774 do_dispose (GObject *obj)
1776 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1777 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1779 /* Disconnect signals */
1780 g_signal_handlers_disconnect_by_func (priv->account_manager,
1781 accounts_dialog_account_validity_changed_cb,
1783 g_signal_handlers_disconnect_by_func (priv->account_manager,
1784 accounts_dialog_account_removed_cb,
1786 g_signal_handlers_disconnect_by_func (priv->account_manager,
1787 accounts_dialog_account_enabled_cb,
1789 g_signal_handlers_disconnect_by_func (priv->account_manager,
1790 accounts_dialog_account_disabled_cb,
1792 g_signal_handlers_disconnect_by_func (priv->account_manager,
1793 accounts_dialog_manager_ready_cb,
1796 if (priv->connecting_id)
1797 g_source_remove (priv->connecting_id);
1799 if (priv->account_manager != NULL)
1801 g_object_unref (priv->account_manager);
1802 priv->account_manager = NULL;
1805 if (priv->cms != NULL)
1807 g_object_unref (priv->cms);
1811 if (priv->initial_selection != NULL)
1812 g_object_unref (priv->initial_selection);
1813 priv->initial_selection = NULL;
1815 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1819 do_constructor (GType type,
1821 GObjectConstructParam *props)
1825 if (dialog_singleton)
1827 retval = G_OBJECT (dialog_singleton);
1828 g_object_ref (retval);
1833 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1834 (type, n_props, props);
1836 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1837 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1838 /* We add an extra reference that we'll release when the dialog is
1839 * destroyed (accounts_dialog_destroy_cb) */
1840 g_object_ref (retval);
1847 do_get_property (GObject *object,
1852 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1854 switch (property_id)
1857 g_value_set_object (value, priv->parent_window);
1860 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1865 do_set_property (GObject *object,
1867 const GValue *value,
1870 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1872 switch (property_id)
1875 priv->parent_window = g_value_get_object (value);
1878 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1883 do_constructed (GObject *object)
1885 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1886 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1887 gboolean import_asked;
1889 accounts_dialog_build_ui (dialog);
1890 accounts_dialog_model_setup (dialog);
1892 /* Set up signalling */
1893 priv->account_manager = tp_account_manager_dup ();
1895 tp_account_manager_prepare_async (priv->account_manager, NULL,
1896 accounts_dialog_manager_ready_cb, dialog);
1898 empathy_conf_get_bool (empathy_conf_get (),
1899 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1901 if (empathy_import_accounts_to_import ())
1903 gtk_widget_show (priv->button_import);
1907 GtkWidget *import_dialog;
1909 empathy_conf_set_bool (empathy_conf_get (),
1910 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1911 import_dialog = empathy_import_dialog_new (GTK_WINDOW (priv->window),
1913 gtk_widget_show (import_dialog);
1919 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1921 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1922 GParamSpec *param_spec;
1924 oclass->constructor = do_constructor;
1925 oclass->dispose = do_dispose;
1926 oclass->constructed = do_constructed;
1927 oclass->set_property = do_set_property;
1928 oclass->get_property = do_get_property;
1930 param_spec = g_param_spec_object ("parent",
1931 "parent", "The parent window",
1933 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1934 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1936 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1940 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1942 EmpathyAccountsDialogPriv *priv;
1944 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1945 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1946 EmpathyAccountsDialogPriv);
1947 dialog->priv = priv;
1950 /* public methods */
1953 empathy_accounts_dialog_show (GtkWindow *parent,
1954 TpAccount *selected_account)
1956 EmpathyAccountsDialog *dialog;
1957 EmpathyAccountsDialogPriv *priv;
1959 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1960 "parent", parent, NULL);
1962 priv = GET_PRIV (dialog);
1964 if (selected_account)
1966 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1967 accounts_dialog_set_selected_account (dialog, selected_account);
1969 /* save the selection to set it later when the cms
1972 priv->initial_selection = g_object_ref (selected_account);
1975 gtk_window_present (GTK_WINDOW (priv->window));
1976 /* EmpathyAccountsDialog kepts a ref on itself until the dialog is
1977 * destroyed so we can release the ref returned by the constructor now. */
1978 g_object_unref (dialog);
1980 return priv->window;