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 modifications to 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, GTK_TYPE_DIALOG);
74 static EmpathyAccountsDialog *dialog_singleton = NULL;
77 GtkWidget *alignment_settings;
78 GtkWidget *alignment_infobar;
80 GtkWidget *vbox_details;
82 GtkWidget *label_status;
83 GtkWidget *image_status;
85 GtkWidget *frame_no_protocol;
89 GtkWidget *button_add;
90 GtkWidget *button_import;
92 GtkWidget *combobox_protocol;
93 GtkWidget *hbox_protocol;
95 GtkWidget *image_type;
96 GtkWidget *label_name;
97 GtkWidget *label_type;
98 GtkWidget *settings_widget;
100 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
101 * his GtkWidget. It is the only reliable source we can query to know if
102 * there are any unsaved changes to the currently selected account. We can't
103 * look at the account settings because it does not contain everything that
104 * can be changed using the EmpathyAccountWidget. For instance, it does not
105 * contain the state of the "Enabled" checkbox. */
106 EmpathyAccountWidget *setting_widget_object;
108 gboolean connecting_show;
111 gulong settings_ready_id;
112 EmpathyAccountSettings *settings_ready;
114 TpAccountManager *account_manager;
115 EmpathyConnectionManagers *cms;
117 GtkWindow *parent_window;
118 TpAccount *initial_selection;
120 /* Those are needed when changing the selected row. When a user selects
121 * another account and there are unsaved changes on the currently selected
122 * one, a confirmation message box is presented to him. Since his answer
123 * is retrieved asynchronously, we keep some information as member of the
124 * EmpathyAccountsDialog object. */
125 gboolean force_change_row;
126 GtkTreeRowReference *destination_row;
128 gboolean dispose_has_run;
129 } EmpathyAccountsDialogPriv;
135 COL_ACCOUNT_SETTINGS_POINTER,
143 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
144 EmpathyAccountsDialog *dialog);
146 static gboolean accounts_dialog_get_settings_iter (
147 EmpathyAccountsDialog *dialog,
148 EmpathyAccountSettings *settings,
151 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
153 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
154 EmpathyAccountSettings *settings);
156 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
157 EmpathyAccountSettings *settings);
159 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
160 EmpathyAccountSettings *settings);
162 static void accounts_dialog_connection_changed_cb (TpAccount *account,
166 gchar *dbus_error_name,
168 EmpathyAccountsDialog *dialog);
170 static void accounts_dialog_presence_changed_cb (TpAccount *account,
173 gchar *status_message,
174 EmpathyAccountsDialog *dialog);
177 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
178 const gchar *display_name)
181 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
183 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
184 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
190 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
193 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
194 const gchar *message;
195 gchar *status_message = NULL;
199 EmpathyConnectivity *connectivity;
202 GtkTreeSelection *selection;
204 TpAccount *selected_account;
205 gboolean account_enabled;
206 gboolean creating_account;
208 view = GTK_TREE_VIEW (priv->treeview);
209 selection = gtk_tree_view_get_selection (view);
211 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
214 gtk_tree_model_get (model, &iter,
215 COL_ACCOUNT_POINTER, &selected_account, -1);
217 /* do not update the infobar when the account is not selected */
218 if (account != selected_account)
223 status = tp_account_get_connection_status (account, &reason);
224 presence = tp_account_get_current_presence (account, NULL, &status_message);
225 account_enabled = tp_account_is_enabled (account);
226 creating_account = FALSE;
230 status = TP_CONNECTION_STATUS_DISCONNECTED;
231 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
232 account_enabled = FALSE;
233 creating_account = TRUE;
236 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
237 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
243 case TP_CONNECTION_STATUS_CONNECTING:
244 message = _("Connecting…");
245 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
248 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
249 gtk_widget_show (priv->throbber);
250 gtk_widget_hide (priv->image_status);
252 case TP_CONNECTION_STATUS_CONNECTED:
253 if (g_strcmp0 (status_message, "") == 0)
255 message = g_strdup_printf ("%s",
256 empathy_presence_get_default_message (presence));
260 message = g_strdup_printf ("%s — %s",
261 empathy_presence_get_default_message (presence),
264 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
267 gtk_widget_show (priv->image_status);
268 gtk_widget_hide (priv->throbber);
270 case TP_CONNECTION_STATUS_DISCONNECTED:
271 message = g_strdup_printf (_("Disconnected — %s"),
272 empathy_status_reason_get_default_message (reason));
274 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
276 message = g_strdup_printf (_("Offline — %s"),
277 empathy_status_reason_get_default_message (reason));
278 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
279 GTK_MESSAGE_WARNING);
283 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
287 connectivity = empathy_connectivity_dup_singleton ();
288 if (!empathy_connectivity_is_online (connectivity))
289 message = _("Offline — No Network Connection");
291 g_object_unref (connectivity);
292 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
293 gtk_widget_show (priv->image_status);
294 gtk_widget_hide (priv->throbber);
297 message = _("Unknown Status");
298 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
299 GTK_MESSAGE_WARNING);
301 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
302 gtk_widget_hide (priv->image_status);
303 gtk_widget_hide (priv->throbber);
308 message = _("Offline — Account Disabled");
310 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
311 GTK_MESSAGE_WARNING);
312 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
313 gtk_widget_show (priv->image_status);
314 gtk_widget_hide (priv->throbber);
317 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
318 gtk_widget_show (priv->label_status);
320 if (!creating_account)
321 gtk_widget_show (priv->infobar);
323 gtk_widget_hide (priv->infobar);
325 g_free (status_message);
329 empathy_account_dialog_widget_cancelled_cb (
330 EmpathyAccountWidget *widget_object,
331 EmpathyAccountsDialog *dialog)
335 GtkTreeSelection *selection;
337 EmpathyAccountSettings *settings;
339 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
341 view = GTK_TREE_VIEW (priv->treeview);
342 selection = gtk_tree_view_get_selection (view);
344 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
347 gtk_tree_model_get (model, &iter,
348 COL_ACCOUNT_SETTINGS_POINTER, &settings,
349 COL_ACCOUNT_POINTER, &account, -1);
351 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
355 /* We were creating an account. We remove the selected row */
356 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
360 /* We were modifying an account. We discard the changes by reloading the
361 * settings and the UI. */
362 accounts_dialog_update_settings (dialog, settings);
363 g_object_unref (account);
366 gtk_widget_set_sensitive (priv->treeview, TRUE);
367 gtk_widget_set_sensitive (priv->button_add, TRUE);
368 gtk_widget_set_sensitive (priv->button_import, TRUE);
370 if (settings != NULL)
371 g_object_unref (settings);
375 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
377 EmpathyAccountsDialog *dialog)
380 EmpathyAccountSettings *settings =
381 accounts_dialog_model_get_selected_settings (dialog);
382 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
384 display_name = empathy_account_widget_get_default_display_name (
387 empathy_account_settings_set_display_name_async (settings,
388 display_name, NULL, NULL);
390 g_free (display_name);
392 accounts_dialog_update_settings (dialog, settings);
393 accounts_dialog_update_status_infobar (dialog,
394 empathy_account_settings_get_account (settings));
396 gtk_widget_set_sensitive (priv->treeview, TRUE);
397 gtk_widget_set_sensitive (priv->button_add, TRUE);
398 gtk_widget_set_sensitive (priv->button_import, TRUE);
400 empathy_signal_connect_weak (account, "status-changed",
401 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
402 empathy_signal_connect_weak (account, "presence-changed",
403 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
406 g_object_unref (settings);
410 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
411 EmpathyAccountSettings *settings)
413 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
417 priv->setting_widget_object =
418 empathy_account_widget_new_for_protocol (settings, FALSE);
420 priv->settings_widget =
421 empathy_account_widget_get_widget (priv->setting_widget_object);
423 g_signal_connect (priv->setting_widget_object, "account-created",
424 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
425 g_signal_connect (priv->setting_widget_object, "cancelled",
426 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
428 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
429 priv->settings_widget);
430 gtk_widget_show (priv->settings_widget);
432 icon_name = empathy_account_settings_get_icon_name (settings);
434 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
436 /* show the default icon; keep this in sync with the default
437 * one in empathy-accounts-dialog.ui.
439 icon_name = GTK_STOCK_CUT;
441 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
442 icon_name, GTK_ICON_SIZE_DIALOG);
443 gtk_widget_set_tooltip_text (priv->image_type,
444 empathy_protocol_name_to_display_name
445 (empathy_account_settings_get_protocol (settings)));
446 gtk_widget_show (priv->image_type);
448 accounts_dialog_update_name_label (dialog,
449 empathy_account_settings_get_display_name (settings));
451 account = empathy_account_settings_get_account (settings);
452 accounts_dialog_update_status_infobar (dialog, account);
456 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
458 EmpathyAccountsDialog *dialog)
460 if (empathy_account_settings_is_ready (settings))
461 account_dialog_create_settings_widget (dialog, settings);
465 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
469 GtkTreeSelection *selection;
471 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
474 view = GTK_TREE_VIEW (priv->treeview);
475 model = gtk_tree_view_get_model (view);
477 if (gtk_tree_model_get_iter_first (model, &iter))
479 selection = gtk_tree_view_get_selection (view);
480 gtk_tree_selection_select_iter (selection, &iter);
484 accounts_dialog_update_settings (dialog, NULL);
489 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
494 GtkTreeSelection *selection;
495 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
497 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
499 if (gtk_tree_selection_get_selected (selection, &model, &iter))
500 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
502 return priv->setting_widget_object != NULL
503 && empathy_account_widget_contains_pending_changes (
504 priv->setting_widget_object);
508 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
510 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
511 EmpathyAccountSettings *settings;
513 const gchar *display_name;
514 TpConnectionManager *cm;
515 TpConnectionManagerProtocol *proto;
518 cm = empathy_protocol_chooser_dup_selected (
519 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
523 display_name = empathy_protocol_name_to_display_name (
524 is_gtalk ? "gtalk" : proto->name);
526 if (display_name == NULL)
527 display_name = proto->name;
530 /* To translator: %s is the name of the protocol, such as "Google Talk" or
533 str = g_strdup_printf (_("New %s account"), display_name);
534 settings = empathy_account_settings_new (cm->name, proto->name, str);
539 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
542 accounts_dialog_add (dialog, settings);
543 accounts_dialog_model_set_selected (dialog, settings);
545 gtk_widget_show_all (priv->hbox_protocol);
547 g_object_unref (settings);
552 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
553 EmpathyAccountsDialog *dialog)
555 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
556 GtkTreeSelection *selection;
561 /* The "changed" signal is fired during the initiation of the
562 * EmpathyProtocolChooser while populating the widget. Such signals should
563 * be ignored so we check if we are actually creating a new account. */
564 if (priv->setting_widget_object == NULL)
567 g_object_get (priv->setting_widget_object,
568 "creating-account", &creating, NULL);
572 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
574 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
577 /* We are creating a new widget to replace the current one, don't ask
578 * confirmation to the user. */
579 priv->force_change_row = TRUE;
580 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
582 accounts_dialog_setup_ui_to_add_account (dialog);
586 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
587 const gchar *primary_text,
588 const gchar *secondary_text,
589 GCallback response_callback,
591 const gchar *first_button_text,
595 GtkWidget *message_dialog;
596 const gchar *button_text;
598 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
599 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
600 GTK_MESSAGE_QUESTION,
604 gtk_message_dialog_format_secondary_text (
605 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
607 va_start (button_args, first_button_text);
608 for (button_text = first_button_text;
610 button_text = va_arg (button_args, const gchar *))
613 response_id = va_arg (button_args, gint);
615 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
618 va_end (button_args);
620 g_signal_connect (message_dialog, "response", response_callback, user_data);
622 gtk_widget_show (message_dialog);
626 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
630 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
631 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
633 gtk_widget_destroy (GTK_WIDGET (message_dialog));
635 if (response_id == GTK_RESPONSE_YES)
637 empathy_account_widget_discard_pending_changes (
638 priv->setting_widget_object);
639 accounts_dialog_setup_ui_to_add_account (dialog);
644 get_dialog_primary_text (TpAccount *account)
648 /* Existing account */
649 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
650 tp_account_get_display_name (account));
654 /* Newly created account */
655 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
660 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
661 EmpathyAccountsDialog *dialog)
663 TpAccount *account = NULL;
664 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
666 if (accounts_dialog_has_pending_change (dialog, &account))
668 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
670 accounts_dialog_show_question_dialog (dialog,
671 question_dialog_primary_text,
672 _("You are about to create a new account, which will discard\n"
673 "your changes. Are you sure you want to proceed?"),
674 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
676 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
677 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
679 g_free (question_dialog_primary_text);
683 accounts_dialog_setup_ui_to_add_account (dialog);
684 gtk_widget_set_sensitive (priv->treeview, FALSE);
685 gtk_widget_set_sensitive (priv->button_add, FALSE);
686 gtk_widget_set_sensitive (priv->button_import, FALSE);
691 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
692 EmpathyAccountSettings *settings)
694 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
696 if (priv->settings_ready != NULL)
698 g_signal_handler_disconnect (priv->settings_ready,
699 priv->settings_ready_id);
700 priv->settings_ready = NULL;
701 priv->settings_ready_id = 0;
708 GtkTreeSelection *selection;
710 view = GTK_TREE_VIEW (priv->treeview);
711 model = gtk_tree_view_get_model (view);
712 selection = gtk_tree_view_get_selection (view);
714 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
716 /* We have configured accounts, select the first one if there
717 * is no other account selected already. */
718 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
719 accounts_dialog_model_select_first (dialog);
723 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
725 /* We have no account configured but we have some
726 * profiles installed. The user obviously wants to add
727 * an account. Click on the Add button for him. */
728 accounts_dialog_button_add_clicked_cb (priv->button_add,
733 /* No account and no profile, warn the user */
734 gtk_widget_hide (priv->vbox_details);
735 gtk_widget_show (priv->frame_no_protocol);
736 gtk_widget_set_sensitive (priv->button_add, FALSE);
740 /* We have an account selected, destroy old settings and create a new
741 * one for the account selected */
742 gtk_widget_hide (priv->frame_no_protocol);
743 gtk_widget_show (priv->vbox_details);
744 gtk_widget_hide (priv->hbox_protocol);
746 if (priv->settings_widget)
748 gtk_widget_destroy (priv->settings_widget);
749 priv->settings_widget = NULL;
752 if (empathy_account_settings_is_ready (settings))
754 account_dialog_create_settings_widget (dialog, settings);
758 priv->settings_ready = settings;
759 priv->settings_ready_id =
760 g_signal_connect (settings, "notify::ready",
761 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
767 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
768 GtkCellEditable *editable,
770 EmpathyAccountsDialog *dialog)
772 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
774 if (priv->connecting_id)
775 g_source_remove (priv->connecting_id);
777 DEBUG ("Editing account name started; stopping flashing");
781 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
782 GtkCellRenderer *cell,
785 EmpathyAccountsDialog *dialog)
787 EmpathyAccountSettings *settings;
790 TpConnectionStatus status;
791 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
793 gtk_tree_model_get (model, iter,
795 COL_ACCOUNT_SETTINGS_POINTER, &settings,
798 icon_name = empathy_account_settings_get_icon_name (settings);
799 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
803 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
804 (status == TP_CONNECTION_STATUS_CONNECTING &&
805 !priv->connecting_show))
807 GdkPixbuf *modded_pixbuf;
809 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
812 gdk_pixbuf_get_width (pixbuf),
813 gdk_pixbuf_get_height (pixbuf));
815 gdk_pixbuf_saturate_and_pixelate (pixbuf,
819 g_object_unref (pixbuf);
820 pixbuf = modded_pixbuf;
829 g_object_unref (settings);
832 g_object_unref (pixbuf);
836 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
841 gtk_tree_model_row_changed (model, path, iter);
847 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
851 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
853 priv->connecting_show = !priv->connecting_show;
855 view = GTK_TREE_VIEW (priv->treeview);
856 model = gtk_tree_view_get_model (view);
858 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
864 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
867 EmpathyAccountsDialog *dialog)
869 EmpathyAccountSettings *settings;
871 GtkTreePath *treepath;
873 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
876 empathy_account_manager_get_accounts_connected (&connecting);
880 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
881 (GSourceFunc) accounts_dialog_flash_connecting_cb,
885 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
886 treepath = gtk_tree_path_new_from_string (path);
887 gtk_tree_model_get_iter (model, &iter, treepath);
888 gtk_tree_model_get (model, &iter,
889 COL_ACCOUNT_SETTINGS_POINTER, &settings,
891 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
894 gtk_tree_path_free (treepath);
896 empathy_account_settings_set_display_name_async (settings, new_text,
898 g_object_set (settings, "display-name-overridden", TRUE, NULL);
899 g_object_unref (settings);
903 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
910 GtkTreeSelection *selection;
911 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
912 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
914 if (response_id == GTK_RESPONSE_YES)
916 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
918 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
921 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
925 tp_account_remove_async (account, NULL, NULL);
926 g_object_unref (account);
930 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
931 accounts_dialog_model_select_first (account_dialog);
934 gtk_widget_destroy (GTK_WIDGET (message_dialog));
938 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
939 const gchar *path_string,
940 EmpathyAccountsDialog *dialog)
945 gchar *question_dialog_primary_text;
946 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
948 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
950 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
953 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
955 if (account == NULL || !tp_account_is_valid (account))
957 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
958 accounts_dialog_model_select_first (dialog);
962 question_dialog_primary_text = g_strdup_printf (
963 _("Do you want to remove %s from your computer?"),
964 tp_account_get_display_name (account));
966 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
967 _("This will not remove your account on the server."),
968 G_CALLBACK (accounts_dialog_delete_account_response_cb),
970 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
971 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
973 g_free (question_dialog_primary_text);
977 g_object_unref (account);
983 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
986 GtkTreeViewColumn *column;
987 GtkCellRenderer *cell;
988 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
990 view = GTK_TREE_VIEW (priv->treeview);
991 gtk_tree_view_set_headers_visible (view, FALSE);
994 column = gtk_tree_view_column_new ();
995 gtk_tree_view_column_set_expand (column, TRUE);
996 gtk_tree_view_append_column (view, column);
999 cell = gtk_cell_renderer_pixbuf_new ();
1000 gtk_tree_view_column_pack_start (column, cell, FALSE);
1001 gtk_tree_view_column_set_cell_data_func (column, cell,
1002 (GtkTreeCellDataFunc)
1003 accounts_dialog_model_pixbuf_data_func,
1008 cell = gtk_cell_renderer_text_new ();
1010 "ellipsize", PANGO_ELLIPSIZE_END,
1014 gtk_tree_view_column_pack_start (column, cell, TRUE);
1015 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1016 g_signal_connect (cell, "edited",
1017 G_CALLBACK (accounts_dialog_name_edited_cb),
1019 g_signal_connect (cell, "editing-started",
1020 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1022 g_object_set (cell, "ypad", 4, NULL);
1025 cell = empathy_cell_renderer_activatable_new ();
1026 gtk_tree_view_column_pack_start (column, cell, FALSE);
1028 "icon-name", GTK_STOCK_DELETE,
1029 "show-on-select", TRUE,
1032 g_signal_connect (cell, "path-activated",
1033 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1037 static EmpathyAccountSettings *
1038 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1041 GtkTreeModel *model;
1042 GtkTreeSelection *selection;
1044 EmpathyAccountSettings *settings;
1045 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1047 view = GTK_TREE_VIEW (priv->treeview);
1048 selection = gtk_tree_view_get_selection (view);
1050 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1053 gtk_tree_model_get (model, &iter,
1054 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1060 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1061 EmpathyAccountsDialog *dialog)
1063 EmpathyAccountSettings *settings;
1064 GtkTreeModel *model;
1066 gboolean is_selection;
1068 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1070 settings = accounts_dialog_model_get_selected_settings (dialog);
1071 accounts_dialog_update_settings (dialog, settings);
1073 if (settings != NULL)
1074 g_object_unref (settings);
1078 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1080 gpointer *user_data)
1082 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1083 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1085 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1087 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1089 /* The user wants to lose unsaved changes to the currently selected
1090 * account and select another account. We discard the changes and
1091 * select the other account. */
1093 GtkTreeSelection *selection;
1095 priv->force_change_row = TRUE;
1096 empathy_account_widget_discard_pending_changes (
1097 priv->setting_widget_object);
1099 path = gtk_tree_row_reference_get_path (priv->destination_row);
1100 selection = gtk_tree_view_get_selection (
1101 GTK_TREE_VIEW (priv->treeview));
1105 /* This will trigger a call to
1106 * accounts_dialog_account_selection_change() */
1107 gtk_tree_selection_select_path (selection, path);
1108 gtk_tree_path_free (path);
1111 gtk_tree_row_reference_free (priv->destination_row);
1115 priv->force_change_row = FALSE;
1120 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1121 GtkTreeModel *model,
1123 gboolean path_currently_selected,
1126 TpAccount *account = NULL;
1127 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1128 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1130 if (priv->force_change_row)
1132 /* We came back here because the user wants to discard changes to his
1133 * modified account. The changes have already been discarded so we
1134 * just change the selected row. */
1135 priv->force_change_row = FALSE;
1139 if (accounts_dialog_has_pending_change (dialog, &account))
1141 /* The currently selected account has some unsaved changes. We ask
1142 * the user if he really wants to lose his changes and select another
1144 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1145 priv->destination_row = gtk_tree_row_reference_new (model, path);
1147 accounts_dialog_show_question_dialog (dialog,
1148 question_dialog_primary_text,
1149 _("You are about to select another account, which will discard\n"
1150 "your changes. Are you sure you want to proceed?"),
1151 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1153 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1154 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1156 g_free (question_dialog_primary_text);
1167 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1169 GtkListStore *store;
1170 GtkTreeSelection *selection;
1171 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1173 store = gtk_list_store_new (COL_COUNT,
1174 G_TYPE_STRING, /* name */
1175 G_TYPE_UINT, /* status */
1176 TP_TYPE_ACCOUNT, /* account */
1177 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1179 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1180 GTK_TREE_MODEL (store));
1182 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1183 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1184 gtk_tree_selection_set_select_function (selection,
1185 accounts_dialog_account_selection_change, dialog, NULL);
1187 g_signal_connect (selection, "changed",
1188 G_CALLBACK (accounts_dialog_model_selection_changed),
1191 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1192 COL_NAME, GTK_SORT_ASCENDING);
1194 accounts_dialog_model_add_columns (dialog);
1196 g_object_unref (store);
1200 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1201 EmpathyAccountSettings *settings,
1205 GtkTreeSelection *selection;
1206 GtkTreeModel *model;
1208 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1210 /* Update the status in the model */
1211 view = GTK_TREE_VIEW (priv->treeview);
1212 selection = gtk_tree_view_get_selection (view);
1213 model = gtk_tree_view_get_model (view);
1215 for (ok = gtk_tree_model_get_iter_first (model, iter);
1217 ok = gtk_tree_model_iter_next (model, iter))
1219 EmpathyAccountSettings *this_settings;
1222 gtk_tree_model_get (model, iter,
1223 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1226 equal = (this_settings == settings);
1227 g_object_unref (this_settings);
1237 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1242 GtkTreeSelection *selection;
1243 GtkTreeModel *model;
1245 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1247 /* Update the status in the model */
1248 view = GTK_TREE_VIEW (priv->treeview);
1249 selection = gtk_tree_view_get_selection (view);
1250 model = gtk_tree_view_get_model (view);
1252 for (ok = gtk_tree_model_get_iter_first (model, iter);
1254 ok = gtk_tree_model_iter_next (model, iter))
1256 EmpathyAccountSettings *settings;
1259 gtk_tree_model_get (model, iter,
1260 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1263 equal = empathy_account_settings_has_account (settings, account);
1264 g_object_unref (settings);
1274 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1275 EmpathyAccountSettings *settings)
1277 GtkTreeSelection *selection;
1279 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1281 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1282 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1283 gtk_tree_selection_select_iter (selection, &iter);
1286 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1287 EmpathyAccountSettings *settings)
1289 GtkTreeModel *model;
1292 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1294 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1295 name = empathy_account_settings_get_display_name (settings);
1297 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1299 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1301 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1302 COL_ACCOUNT_SETTINGS_POINTER, settings,
1307 accounts_dialog_connection_changed_cb (TpAccount *account,
1311 gchar *dbus_error_name,
1312 GHashTable *details,
1313 EmpathyAccountsDialog *dialog)
1315 GtkTreeModel *model;
1318 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1320 /* Update the status-infobar in the details view */
1321 accounts_dialog_update_status_infobar (dialog, account);
1323 /* Update the status in the model */
1324 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1326 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1330 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1331 COL_STATUS, current,
1334 path = gtk_tree_model_get_path (model, &iter);
1335 gtk_tree_model_row_changed (model, path, &iter);
1336 gtk_tree_path_free (path);
1339 empathy_account_manager_get_accounts_connected (&found);
1341 if (!found && priv->connecting_id)
1343 g_source_remove (priv->connecting_id);
1344 priv->connecting_id = 0;
1347 if (found && !priv->connecting_id)
1348 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1349 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1354 accounts_dialog_presence_changed_cb (TpAccount *account,
1357 gchar *status_message,
1358 EmpathyAccountsDialog *dialog)
1360 /* Update the status-infobar in the details view */
1361 accounts_dialog_update_status_infobar (dialog, account);
1365 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1369 const gchar *display_name;
1371 GtkTreeModel *model;
1372 EmpathyAccountSettings *settings;
1373 TpAccount *selected_account;
1374 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1375 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1377 display_name = tp_account_get_display_name (account);
1378 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1379 settings = accounts_dialog_model_get_selected_settings (dialog);
1380 if (settings == NULL)
1383 selected_account = empathy_account_settings_get_account (settings);
1385 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1387 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1388 COL_NAME, display_name,
1392 if (selected_account == account)
1393 accounts_dialog_update_name_label (dialog, display_name);
1395 g_object_unref (settings);
1399 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1402 EmpathyAccountSettings *settings;
1403 GtkTreeModel *model;
1405 TpConnectionStatus status;
1408 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1410 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1411 status = tp_account_get_connection_status (account, NULL);
1412 name = tp_account_get_display_name (account);
1413 enabled = tp_account_is_enabled (account);
1415 settings = empathy_account_settings_new_for_account (account);
1417 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1418 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1420 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1423 COL_ACCOUNT_POINTER, account,
1424 COL_ACCOUNT_SETTINGS_POINTER, settings,
1427 accounts_dialog_connection_changed_cb (account,
1430 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1435 empathy_signal_connect_weak (account, "notify::display-name",
1436 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1439 g_object_unref (settings);
1443 account_prepare_cb (GObject *source_object,
1444 GAsyncResult *result,
1447 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1448 TpAccount *account = TP_ACCOUNT (source_object);
1449 GError *error = NULL;
1451 if (!tp_account_prepare_finish (account, result, &error))
1453 DEBUG ("Failed to prepare account: %s", error->message);
1454 g_error_free (error);
1458 accounts_dialog_add_account (dialog, account);
1462 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1465 EmpathyAccountsDialog *dialog)
1467 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1471 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1473 EmpathyAccountsDialog *dialog)
1476 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1478 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1480 gtk_list_store_remove (GTK_LIST_STORE (
1481 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1486 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1490 GtkTreeModel *model;
1491 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1493 /* Update the status in the model */
1494 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1496 /* Update the status-infobar in the details view when disabling */
1498 accounts_dialog_update_status_infobar (dialog, account);
1500 DEBUG ("Account %s is now %s",
1501 tp_account_get_display_name (account),
1502 enabled ? "enabled" : "disabled");
1506 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1508 EmpathyAccountsDialog *dialog)
1510 enable_or_disable_account (dialog, account, FALSE);
1514 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1516 EmpathyAccountsDialog *dialog)
1518 enable_or_disable_account (dialog, account, TRUE);
1522 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1523 EmpathyAccountsDialog *dialog)
1525 GtkWidget *import_dialog;
1527 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1529 gtk_widget_show (import_dialog);
1533 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1537 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1539 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1541 if (response_id == GTK_RESPONSE_YES)
1542 gtk_widget_destroy (account_dialog);
1546 accounts_dialog_delete_event_cb (GtkWidget *widget,
1548 EmpathyAccountsDialog *dialog)
1550 /* we maunally handle responses to delete events */
1555 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1558 GtkTreeSelection *selection;
1560 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1562 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1563 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1564 gtk_tree_selection_select_iter (selection, &iter);
1568 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1570 EmpathyAccountsDialog *dialog)
1572 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1574 if (empathy_connection_managers_is_ready (cms))
1576 accounts_dialog_update_settings (dialog, NULL);
1578 if (priv->initial_selection != NULL)
1580 accounts_dialog_set_selected_account
1581 (dialog, priv->initial_selection);
1582 g_object_unref (priv->initial_selection);
1583 priv->initial_selection = NULL;
1589 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1591 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1592 GList *accounts, *l;
1594 g_signal_connect (priv->account_manager, "account-validity-changed",
1595 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1597 g_signal_connect (priv->account_manager, "account-removed",
1598 G_CALLBACK (accounts_dialog_account_removed_cb),
1600 g_signal_connect (priv->account_manager, "account-enabled",
1601 G_CALLBACK (accounts_dialog_account_enabled_cb),
1603 g_signal_connect (priv->account_manager, "account-disabled",
1604 G_CALLBACK (accounts_dialog_account_disabled_cb),
1607 /* Add existing accounts */
1608 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1609 for (l = accounts; l; l = l->next)
1611 accounts_dialog_add_account (dialog, l->data);
1613 empathy_signal_connect_weak (l->data, "status-changed",
1614 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1615 empathy_signal_connect_weak (l->data, "presence-changed",
1616 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1618 g_list_free (accounts);
1620 priv->cms = empathy_connection_managers_dup_singleton ();
1621 if (!empathy_connection_managers_is_ready (priv->cms))
1622 g_signal_connect (priv->cms, "notify::ready",
1623 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1625 accounts_dialog_model_select_first (dialog);
1629 accounts_dialog_manager_ready_cb (GObject *source_object,
1630 GAsyncResult *result,
1633 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1634 GError *error = NULL;
1636 if (!tp_account_manager_prepare_finish (manager, result, &error))
1638 DEBUG ("Failed to prepare account manager: %s", error->message);
1639 g_error_free (error);
1643 accounts_dialog_accounts_setup (user_data);
1647 dialog_response_cb (GtkWidget *widget,
1651 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1653 if (response_id == GTK_RESPONSE_HELP)
1655 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1657 else if (response_id == GTK_RESPONSE_CLOSE ||
1658 response_id == GTK_RESPONSE_DELETE_EVENT)
1660 TpAccount *account = NULL;
1662 if (accounts_dialog_has_pending_change (dialog, &account))
1664 gchar *question_dialog_primary_text = get_dialog_primary_text (
1667 accounts_dialog_show_question_dialog (dialog,
1668 question_dialog_primary_text,
1669 _("You are about to close the window, which will discard\n"
1670 "your changes. Are you sure you want to proceed?"),
1671 G_CALLBACK (accounts_dialog_close_response_cb),
1673 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1674 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1676 g_free (question_dialog_primary_text);
1680 gtk_widget_destroy (widget);
1686 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1688 GtkWidget *top_hbox;
1691 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1692 GtkWidget *content_area;
1693 GtkWidget *action_area;
1695 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1697 gui = empathy_builder_get_file (filename,
1698 "accounts_dialog_hbox", &top_hbox,
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 "image_type", &priv->image_type,
1705 "label_name", &priv->label_name,
1706 "button_add", &priv->button_add,
1707 "button_import", &priv->button_import,
1708 "hbox_protocol", &priv->hbox_protocol,
1712 empathy_builder_connect (gui, dialog,
1713 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1714 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1717 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1719 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
1721 g_object_unref (gui);
1723 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
1726 gtk_widget_hide (action_area);
1729 priv->combobox_protocol = empathy_protocol_chooser_new ();
1730 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
1732 g_signal_connect (priv->combobox_protocol, "changed",
1733 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1736 if (priv->parent_window)
1737 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1738 priv->parent_window);
1740 /* set up spinner */
1741 priv->throbber = ephy_spinner_new ();
1742 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1744 priv->infobar = gtk_info_bar_new ();
1745 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1747 gtk_widget_show (priv->infobar);
1749 priv->image_status = gtk_image_new_from_icon_name (
1750 empathy_icon_name_for_presence (
1751 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1753 priv->label_status = gtk_label_new (NULL);
1755 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1756 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1758 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1760 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1762 /* Tweak the dialog */
1763 gtk_window_set_title (GTK_WINDOW (dialog), _("Accounts"));
1764 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
1766 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, -1);
1768 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
1770 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
1772 /* add dialog buttons */
1773 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
1775 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1776 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1777 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1780 g_signal_connect (dialog, "response",
1781 G_CALLBACK (dialog_response_cb), dialog);
1783 g_signal_connect (dialog, "delete-event",
1784 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
1788 do_dispose (GObject *obj)
1790 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1791 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1793 if (priv->dispose_has_run)
1796 priv->dispose_has_run = TRUE;
1798 /* Disconnect signals */
1799 g_signal_handlers_disconnect_by_func (priv->account_manager,
1800 accounts_dialog_account_validity_changed_cb,
1802 g_signal_handlers_disconnect_by_func (priv->account_manager,
1803 accounts_dialog_account_removed_cb,
1805 g_signal_handlers_disconnect_by_func (priv->account_manager,
1806 accounts_dialog_account_enabled_cb,
1808 g_signal_handlers_disconnect_by_func (priv->account_manager,
1809 accounts_dialog_account_disabled_cb,
1811 g_signal_handlers_disconnect_by_func (priv->account_manager,
1812 accounts_dialog_manager_ready_cb,
1815 if (priv->connecting_id)
1816 g_source_remove (priv->connecting_id);
1818 if (priv->account_manager != NULL)
1820 g_object_unref (priv->account_manager);
1821 priv->account_manager = NULL;
1824 if (priv->cms != NULL)
1826 g_object_unref (priv->cms);
1830 if (priv->initial_selection != NULL)
1831 g_object_unref (priv->initial_selection);
1832 priv->initial_selection = NULL;
1834 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1838 do_constructor (GType type,
1840 GObjectConstructParam *props)
1844 if (dialog_singleton)
1846 retval = G_OBJECT (dialog_singleton);
1851 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1852 (type, n_props, props);
1854 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1855 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1862 do_get_property (GObject *object,
1867 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1869 switch (property_id)
1872 g_value_set_object (value, priv->parent_window);
1875 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1880 do_set_property (GObject *object,
1882 const GValue *value,
1885 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1887 switch (property_id)
1890 priv->parent_window = g_value_get_object (value);
1893 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1898 do_constructed (GObject *object)
1900 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1901 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1902 gboolean import_asked;
1904 accounts_dialog_build_ui (dialog);
1905 accounts_dialog_model_setup (dialog);
1907 /* Set up signalling */
1908 priv->account_manager = tp_account_manager_dup ();
1910 tp_account_manager_prepare_async (priv->account_manager, NULL,
1911 accounts_dialog_manager_ready_cb, dialog);
1913 empathy_conf_get_bool (empathy_conf_get (),
1914 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1916 if (empathy_import_accounts_to_import ())
1918 gtk_widget_show (priv->button_import);
1922 GtkWidget *import_dialog;
1924 empathy_conf_set_bool (empathy_conf_get (),
1925 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1926 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1928 gtk_widget_show (import_dialog);
1934 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1936 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1937 GParamSpec *param_spec;
1939 oclass->constructor = do_constructor;
1940 oclass->dispose = do_dispose;
1941 oclass->constructed = do_constructed;
1942 oclass->set_property = do_set_property;
1943 oclass->get_property = do_get_property;
1945 param_spec = g_param_spec_object ("parent",
1946 "parent", "The parent window",
1948 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1949 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1951 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1955 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1957 EmpathyAccountsDialogPriv *priv;
1959 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1960 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1961 EmpathyAccountsDialogPriv);
1962 dialog->priv = priv;
1965 /* public methods */
1968 empathy_accounts_dialog_show (GtkWindow *parent,
1969 TpAccount *selected_account)
1971 EmpathyAccountsDialog *dialog;
1972 EmpathyAccountsDialogPriv *priv;
1974 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1975 "parent", parent, NULL);
1977 priv = GET_PRIV (dialog);
1979 if (selected_account)
1981 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1982 accounts_dialog_set_selected_account (dialog, selected_account);
1984 /* save the selection to set it later when the cms
1987 priv->initial_selection = g_object_ref (selected_account);
1990 gtk_window_present (GTK_WINDOW (dialog));
1992 return GTK_WIDGET (dialog);