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);
163 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
164 const gchar *display_name)
167 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
169 text = g_markup_printf_escaped ("<big><b>%s</b></big>", display_name);
170 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
176 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
179 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
180 const gchar *message;
181 gchar *status_message = NULL;
185 EmpathyConnectivity *connectivity;
188 GtkTreeSelection *selection;
190 TpAccount *selected_account;
191 gboolean account_enabled;
192 gboolean creating_account;
194 view = GTK_TREE_VIEW (priv->treeview);
195 selection = gtk_tree_view_get_selection (view);
197 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
200 gtk_tree_model_get (model, &iter,
201 COL_ACCOUNT_POINTER, &selected_account, -1);
203 /* do not update the infobar when the account is not selected */
204 if (account != selected_account)
209 status = tp_account_get_connection_status (account, &reason);
210 presence = tp_account_get_current_presence (account, NULL, &status_message);
211 account_enabled = tp_account_is_enabled (account);
212 creating_account = FALSE;
216 status = TP_CONNECTION_STATUS_DISCONNECTED;
217 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
218 account_enabled = FALSE;
219 creating_account = TRUE;
222 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
223 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
229 case TP_CONNECTION_STATUS_CONNECTING:
230 message = _("Connecting…");
231 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
234 ephy_spinner_start (EPHY_SPINNER (priv->throbber));
235 gtk_widget_show (priv->throbber);
236 gtk_widget_hide (priv->image_status);
238 case TP_CONNECTION_STATUS_CONNECTED:
239 if (g_strcmp0 (status_message, "") == 0)
241 message = g_strdup_printf ("%s",
242 empathy_presence_get_default_message (presence));
246 message = g_strdup_printf ("%s — %s",
247 empathy_presence_get_default_message (presence),
250 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
253 gtk_widget_show (priv->image_status);
254 gtk_widget_hide (priv->throbber);
256 case TP_CONNECTION_STATUS_DISCONNECTED:
257 message = g_strdup_printf (_("Disconnected — %s"),
258 empathy_status_reason_get_default_message (reason));
260 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
262 message = g_strdup_printf (_("Offline — %s"),
263 empathy_status_reason_get_default_message (reason));
264 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
265 GTK_MESSAGE_WARNING);
269 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
273 connectivity = empathy_connectivity_dup_singleton ();
274 if (!empathy_connectivity_is_online (connectivity))
275 message = _("Offline — No Network Connection");
277 g_object_unref (connectivity);
278 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
279 gtk_widget_show (priv->image_status);
280 gtk_widget_hide (priv->throbber);
283 message = _("Unknown Status");
284 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
285 GTK_MESSAGE_WARNING);
287 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
288 gtk_widget_hide (priv->image_status);
289 gtk_widget_hide (priv->throbber);
294 message = _("Offline — Account Disabled");
296 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
297 GTK_MESSAGE_WARNING);
298 ephy_spinner_stop (EPHY_SPINNER (priv->throbber));
299 gtk_widget_show (priv->image_status);
300 gtk_widget_hide (priv->throbber);
303 gtk_label_set_text (GTK_LABEL (priv->label_status), message);
304 gtk_widget_show (priv->label_status);
306 if (!creating_account)
307 gtk_widget_show (priv->infobar);
309 gtk_widget_hide (priv->infobar);
311 g_free (status_message);
315 empathy_account_dialog_widget_cancelled_cb (
316 EmpathyAccountWidget *widget_object,
317 EmpathyAccountsDialog *dialog)
321 GtkTreeSelection *selection;
323 EmpathyAccountSettings *settings;
325 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
327 view = GTK_TREE_VIEW (priv->treeview);
328 selection = gtk_tree_view_get_selection (view);
330 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
333 gtk_tree_model_get (model, &iter,
334 COL_ACCOUNT_SETTINGS_POINTER, &settings,
335 COL_ACCOUNT_POINTER, &account, -1);
337 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
341 /* We were creating an account. We remove the selected row */
342 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
346 /* We were modifying an account. We discard the changes by reloading the
347 * settings and the UI. */
348 accounts_dialog_update_settings (dialog, settings);
349 g_object_unref (account);
352 gtk_widget_set_sensitive (priv->treeview, TRUE);
353 gtk_widget_set_sensitive (priv->button_add, TRUE);
354 gtk_widget_set_sensitive (priv->button_import, TRUE);
356 if (settings != NULL)
357 g_object_unref (settings);
361 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
362 EmpathyAccountsDialog *dialog)
365 EmpathyAccountSettings *settings =
366 accounts_dialog_model_get_selected_settings (dialog);
367 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
369 display_name = empathy_account_widget_get_default_display_name (
372 empathy_account_settings_set_display_name_async (settings,
373 display_name, NULL, NULL);
375 g_free (display_name);
377 accounts_dialog_update_settings (dialog, settings);
378 accounts_dialog_update_status_infobar (dialog,
379 empathy_account_settings_get_account (settings));
381 gtk_widget_set_sensitive (priv->treeview, TRUE);
382 gtk_widget_set_sensitive (priv->button_add, TRUE);
383 gtk_widget_set_sensitive (priv->button_import, TRUE);
386 g_object_unref (settings);
390 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
391 EmpathyAccountSettings *settings)
393 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
397 priv->setting_widget_object =
398 empathy_account_widget_new_for_protocol (settings, FALSE);
400 priv->settings_widget =
401 empathy_account_widget_get_widget (priv->setting_widget_object);
403 g_signal_connect (priv->setting_widget_object, "account-created",
404 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
405 g_signal_connect (priv->setting_widget_object, "cancelled",
406 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
408 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
409 priv->settings_widget);
410 gtk_widget_show (priv->settings_widget);
412 icon_name = empathy_account_settings_get_icon_name (settings);
414 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
416 /* show the default icon; keep this in sync with the default
417 * one in empathy-accounts-dialog.ui.
419 icon_name = GTK_STOCK_CUT;
421 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
422 icon_name, GTK_ICON_SIZE_DIALOG);
423 gtk_widget_set_tooltip_text (priv->image_type,
424 empathy_protocol_name_to_display_name
425 (empathy_account_settings_get_protocol (settings)));
426 gtk_widget_show (priv->image_type);
428 accounts_dialog_update_name_label (dialog,
429 empathy_account_settings_get_display_name (settings));
431 account = empathy_account_settings_get_account (settings);
432 accounts_dialog_update_status_infobar (dialog, account);
436 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
438 EmpathyAccountsDialog *dialog)
440 if (empathy_account_settings_is_ready (settings))
441 account_dialog_create_settings_widget (dialog, settings);
445 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
449 GtkTreeSelection *selection;
451 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
454 view = GTK_TREE_VIEW (priv->treeview);
455 model = gtk_tree_view_get_model (view);
457 if (gtk_tree_model_get_iter_first (model, &iter))
459 selection = gtk_tree_view_get_selection (view);
460 gtk_tree_selection_select_iter (selection, &iter);
464 accounts_dialog_update_settings (dialog, NULL);
469 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
474 GtkTreeSelection *selection;
475 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
477 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
479 if (gtk_tree_selection_get_selected (selection, &model, &iter))
480 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, account, -1);
482 return priv->setting_widget_object != NULL
483 && empathy_account_widget_contains_pending_changes (
484 priv->setting_widget_object);
488 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
490 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
491 EmpathyAccountSettings *settings;
493 const gchar *display_name;
494 TpConnectionManager *cm;
495 TpConnectionManagerProtocol *proto;
498 cm = empathy_protocol_chooser_dup_selected (
499 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk);
503 display_name = empathy_protocol_name_to_display_name (
504 is_gtalk ? "gtalk" : proto->name);
506 if (display_name == NULL)
507 display_name = proto->name;
510 /* To translator: %s is the name of the protocol, such as "Google Talk" or
513 str = g_strdup_printf (_("New %s account"), display_name);
514 settings = empathy_account_settings_new (cm->name, proto->name, str);
519 empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
522 accounts_dialog_add (dialog, settings);
523 accounts_dialog_model_set_selected (dialog, settings);
525 gtk_widget_show_all (priv->hbox_protocol);
527 g_object_unref (settings);
532 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
533 EmpathyAccountsDialog *dialog)
535 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
536 GtkTreeSelection *selection;
541 /* The "changed" signal is fired during the initiation of the
542 * EmpathyProtocolChooser while populating the widget. Such signals should
543 * be ignored so we check if we are actually creating a new account. */
544 if (priv->setting_widget_object == NULL)
547 g_object_get (priv->setting_widget_object,
548 "creating-account", &creating, NULL);
552 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
554 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
557 /* We are creating a new widget to replace the current one, don't ask
558 * confirmation to the user. */
559 priv->force_change_row = TRUE;
560 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
562 accounts_dialog_setup_ui_to_add_account (dialog);
566 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
567 const gchar *primary_text,
568 const gchar *secondary_text,
569 GCallback response_callback,
571 const gchar *first_button_text,
575 GtkWidget *message_dialog;
576 const gchar *button_text;
578 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
579 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
580 GTK_MESSAGE_QUESTION,
584 gtk_message_dialog_format_secondary_text (
585 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
587 va_start (button_args, first_button_text);
588 for (button_text = first_button_text;
590 button_text = va_arg (button_args, const gchar *))
593 response_id = va_arg (button_args, gint);
595 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
598 va_end (button_args);
600 g_signal_connect (message_dialog, "response", response_callback, user_data);
602 gtk_widget_show (message_dialog);
606 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
610 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
611 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
613 gtk_widget_destroy (GTK_WIDGET (message_dialog));
615 if (response_id == GTK_RESPONSE_YES)
617 empathy_account_widget_discard_pending_changes (
618 priv->setting_widget_object);
619 accounts_dialog_setup_ui_to_add_account (dialog);
624 get_dialog_primary_text (TpAccount *account)
628 /* Existing account */
629 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
630 tp_account_get_display_name (account));
634 /* Newly created account */
635 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
640 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
641 EmpathyAccountsDialog *dialog)
643 TpAccount *account = NULL;
644 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
646 if (accounts_dialog_has_pending_change (dialog, &account))
648 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
650 accounts_dialog_show_question_dialog (dialog,
651 question_dialog_primary_text,
652 _("You are about to create a new account, which will discard\n"
653 "your changes. Are you sure you want to proceed?"),
654 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
656 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
657 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
659 g_free (question_dialog_primary_text);
663 accounts_dialog_setup_ui_to_add_account (dialog);
664 gtk_widget_set_sensitive (priv->treeview, FALSE);
665 gtk_widget_set_sensitive (priv->button_add, FALSE);
666 gtk_widget_set_sensitive (priv->button_import, FALSE);
671 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
672 EmpathyAccountSettings *settings)
674 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
676 if (priv->settings_ready != NULL)
678 g_signal_handler_disconnect (priv->settings_ready,
679 priv->settings_ready_id);
680 priv->settings_ready = NULL;
681 priv->settings_ready_id = 0;
688 GtkTreeSelection *selection;
690 view = GTK_TREE_VIEW (priv->treeview);
691 model = gtk_tree_view_get_model (view);
692 selection = gtk_tree_view_get_selection (view);
694 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
696 /* We have configured accounts, select the first one if there
697 * is no other account selected already. */
698 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
699 accounts_dialog_model_select_first (dialog);
703 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
705 /* We have no account configured but we have some
706 * profiles installed. The user obviously wants to add
707 * an account. Click on the Add button for him. */
708 accounts_dialog_button_add_clicked_cb (priv->button_add,
713 /* No account and no profile, warn the user */
714 gtk_widget_hide (priv->vbox_details);
715 gtk_widget_show (priv->frame_no_protocol);
716 gtk_widget_set_sensitive (priv->button_add, FALSE);
720 /* We have an account selected, destroy old settings and create a new
721 * one for the account selected */
722 gtk_widget_hide (priv->frame_no_protocol);
723 gtk_widget_show (priv->vbox_details);
724 gtk_widget_hide (priv->hbox_protocol);
726 if (priv->settings_widget)
728 gtk_widget_destroy (priv->settings_widget);
729 priv->settings_widget = NULL;
732 if (empathy_account_settings_is_ready (settings))
734 account_dialog_create_settings_widget (dialog, settings);
738 priv->settings_ready = settings;
739 priv->settings_ready_id =
740 g_signal_connect (settings, "notify::ready",
741 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
747 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
748 GtkCellEditable *editable,
750 EmpathyAccountsDialog *dialog)
752 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
754 if (priv->connecting_id)
755 g_source_remove (priv->connecting_id);
757 DEBUG ("Editing account name started; stopping flashing");
761 accounts_dialog_model_pixbuf_data_func (GtkTreeViewColumn *tree_column,
762 GtkCellRenderer *cell,
765 EmpathyAccountsDialog *dialog)
767 EmpathyAccountSettings *settings;
770 TpConnectionStatus status;
771 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
773 gtk_tree_model_get (model, iter,
775 COL_ACCOUNT_SETTINGS_POINTER, &settings,
778 icon_name = empathy_account_settings_get_icon_name (settings);
779 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
783 if (status == TP_CONNECTION_STATUS_DISCONNECTED ||
784 (status == TP_CONNECTION_STATUS_CONNECTING &&
785 !priv->connecting_show))
787 GdkPixbuf *modded_pixbuf;
789 modded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
792 gdk_pixbuf_get_width (pixbuf),
793 gdk_pixbuf_get_height (pixbuf));
795 gdk_pixbuf_saturate_and_pixelate (pixbuf,
799 g_object_unref (pixbuf);
800 pixbuf = modded_pixbuf;
809 g_object_unref (settings);
812 g_object_unref (pixbuf);
816 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
821 gtk_tree_model_row_changed (model, path, iter);
827 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
831 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
833 priv->connecting_show = !priv->connecting_show;
835 view = GTK_TREE_VIEW (priv->treeview);
836 model = gtk_tree_view_get_model (view);
838 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
844 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
847 EmpathyAccountsDialog *dialog)
849 EmpathyAccountSettings *settings;
851 GtkTreePath *treepath;
853 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
856 empathy_account_manager_get_accounts_connected (&connecting);
860 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
861 (GSourceFunc) accounts_dialog_flash_connecting_cb,
865 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
866 treepath = gtk_tree_path_new_from_string (path);
867 gtk_tree_model_get_iter (model, &iter, treepath);
868 gtk_tree_model_get (model, &iter,
869 COL_ACCOUNT_SETTINGS_POINTER, &settings,
871 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
874 gtk_tree_path_free (treepath);
876 empathy_account_settings_set_display_name_async (settings, new_text,
878 g_object_set (settings, "display-name-overridden", TRUE, NULL);
879 g_object_unref (settings);
883 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
890 GtkTreeSelection *selection;
891 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
892 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
894 if (response_id == GTK_RESPONSE_YES)
896 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
898 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
901 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
905 tp_account_remove_async (account, NULL, NULL);
906 g_object_unref (account);
910 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
911 accounts_dialog_model_select_first (account_dialog);
914 gtk_widget_destroy (GTK_WIDGET (message_dialog));
918 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
919 const gchar *path_string,
920 EmpathyAccountsDialog *dialog)
925 gchar *question_dialog_primary_text;
926 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
928 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
930 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
933 gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1);
935 if (account == NULL || !tp_account_is_valid (account))
937 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
938 accounts_dialog_model_select_first (dialog);
942 question_dialog_primary_text = g_strdup_printf (
943 _("Do you want to remove %s from your computer?"),
944 tp_account_get_display_name (account));
946 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
947 _("This will not remove your account on the server."),
948 G_CALLBACK (accounts_dialog_delete_account_response_cb),
950 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
951 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
953 g_free (question_dialog_primary_text);
957 g_object_unref (account);
963 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
966 GtkTreeViewColumn *column;
967 GtkCellRenderer *cell;
968 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
970 view = GTK_TREE_VIEW (priv->treeview);
971 gtk_tree_view_set_headers_visible (view, FALSE);
974 column = gtk_tree_view_column_new ();
975 gtk_tree_view_column_set_expand (column, TRUE);
976 gtk_tree_view_append_column (view, column);
979 cell = gtk_cell_renderer_pixbuf_new ();
980 gtk_tree_view_column_pack_start (column, cell, FALSE);
981 gtk_tree_view_column_set_cell_data_func (column, cell,
982 (GtkTreeCellDataFunc)
983 accounts_dialog_model_pixbuf_data_func,
988 cell = gtk_cell_renderer_text_new ();
990 "ellipsize", PANGO_ELLIPSIZE_END,
994 gtk_tree_view_column_pack_start (column, cell, TRUE);
995 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
996 g_signal_connect (cell, "edited",
997 G_CALLBACK (accounts_dialog_name_edited_cb),
999 g_signal_connect (cell, "editing-started",
1000 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1002 g_object_set (cell, "ypad", 4, NULL);
1005 cell = empathy_cell_renderer_activatable_new ();
1006 gtk_tree_view_column_pack_start (column, cell, FALSE);
1008 "icon-name", GTK_STOCK_DELETE,
1009 "show-on-select", TRUE,
1012 g_signal_connect (cell, "path-activated",
1013 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1017 static EmpathyAccountSettings *
1018 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1021 GtkTreeModel *model;
1022 GtkTreeSelection *selection;
1024 EmpathyAccountSettings *settings;
1025 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1027 view = GTK_TREE_VIEW (priv->treeview);
1028 selection = gtk_tree_view_get_selection (view);
1030 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1033 gtk_tree_model_get (model, &iter,
1034 COL_ACCOUNT_SETTINGS_POINTER, &settings, -1);
1040 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1041 EmpathyAccountsDialog *dialog)
1043 EmpathyAccountSettings *settings;
1044 GtkTreeModel *model;
1046 gboolean is_selection;
1048 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1050 settings = accounts_dialog_model_get_selected_settings (dialog);
1051 accounts_dialog_update_settings (dialog, settings);
1053 if (settings != NULL)
1054 g_object_unref (settings);
1058 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1060 gpointer *user_data)
1062 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1063 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1065 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1067 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1069 /* The user wants to lose unsaved changes to the currently selected
1070 * account and select another account. We discard the changes and
1071 * select the other account. */
1073 GtkTreeSelection *selection;
1075 priv->force_change_row = TRUE;
1076 empathy_account_widget_discard_pending_changes (
1077 priv->setting_widget_object);
1079 path = gtk_tree_row_reference_get_path (priv->destination_row);
1080 selection = gtk_tree_view_get_selection (
1081 GTK_TREE_VIEW (priv->treeview));
1085 /* This will trigger a call to
1086 * accounts_dialog_account_selection_change() */
1087 gtk_tree_selection_select_path (selection, path);
1088 gtk_tree_path_free (path);
1091 gtk_tree_row_reference_free (priv->destination_row);
1095 priv->force_change_row = FALSE;
1100 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1101 GtkTreeModel *model,
1103 gboolean path_currently_selected,
1106 TpAccount *account = NULL;
1107 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1108 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1110 if (priv->force_change_row)
1112 /* We came back here because the user wants to discard changes to his
1113 * modified account. The changes have already been discarded so we
1114 * just change the selected row. */
1115 priv->force_change_row = FALSE;
1119 if (accounts_dialog_has_pending_change (dialog, &account))
1121 /* The currently selected account has some unsaved changes. We ask
1122 * the user if he really wants to lose his changes and select another
1124 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1125 priv->destination_row = gtk_tree_row_reference_new (model, path);
1127 accounts_dialog_show_question_dialog (dialog,
1128 question_dialog_primary_text,
1129 _("You are about to select another account, which will discard\n"
1130 "your changes. Are you sure you want to proceed?"),
1131 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1133 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1134 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1136 g_free (question_dialog_primary_text);
1147 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1149 GtkListStore *store;
1150 GtkTreeSelection *selection;
1151 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1153 store = gtk_list_store_new (COL_COUNT,
1154 G_TYPE_STRING, /* name */
1155 G_TYPE_UINT, /* status */
1156 TP_TYPE_ACCOUNT, /* account */
1157 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1159 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1160 GTK_TREE_MODEL (store));
1162 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1163 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1164 gtk_tree_selection_set_select_function (selection,
1165 accounts_dialog_account_selection_change, dialog, NULL);
1167 g_signal_connect (selection, "changed",
1168 G_CALLBACK (accounts_dialog_model_selection_changed),
1171 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1172 COL_NAME, GTK_SORT_ASCENDING);
1174 accounts_dialog_model_add_columns (dialog);
1176 g_object_unref (store);
1180 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1181 EmpathyAccountSettings *settings,
1185 GtkTreeSelection *selection;
1186 GtkTreeModel *model;
1188 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1190 /* Update the status in the model */
1191 view = GTK_TREE_VIEW (priv->treeview);
1192 selection = gtk_tree_view_get_selection (view);
1193 model = gtk_tree_view_get_model (view);
1195 for (ok = gtk_tree_model_get_iter_first (model, iter);
1197 ok = gtk_tree_model_iter_next (model, iter))
1199 EmpathyAccountSettings *this_settings;
1202 gtk_tree_model_get (model, iter,
1203 COL_ACCOUNT_SETTINGS_POINTER, &this_settings,
1206 equal = (this_settings == settings);
1207 g_object_unref (this_settings);
1217 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1222 GtkTreeSelection *selection;
1223 GtkTreeModel *model;
1225 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1227 /* Update the status in the model */
1228 view = GTK_TREE_VIEW (priv->treeview);
1229 selection = gtk_tree_view_get_selection (view);
1230 model = gtk_tree_view_get_model (view);
1232 for (ok = gtk_tree_model_get_iter_first (model, iter);
1234 ok = gtk_tree_model_iter_next (model, iter))
1236 EmpathyAccountSettings *settings;
1239 gtk_tree_model_get (model, iter,
1240 COL_ACCOUNT_SETTINGS_POINTER, &settings,
1243 equal = empathy_account_settings_has_account (settings, account);
1244 g_object_unref (settings);
1254 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1255 EmpathyAccountSettings *settings)
1257 GtkTreeSelection *selection;
1259 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1261 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1262 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1263 gtk_tree_selection_select_iter (selection, &iter);
1266 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1267 EmpathyAccountSettings *settings)
1269 GtkTreeModel *model;
1272 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1274 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1275 name = empathy_account_settings_get_display_name (settings);
1277 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1279 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1281 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1282 COL_ACCOUNT_SETTINGS_POINTER, settings,
1287 accounts_dialog_connection_changed_cb (TpAccount *account,
1291 gchar *dbus_error_name,
1292 GHashTable *details,
1293 EmpathyAccountsDialog *dialog)
1295 GtkTreeModel *model;
1298 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1300 /* Update the status-infobar in the details view */
1301 accounts_dialog_update_status_infobar (dialog, account);
1303 /* Update the status in the model */
1304 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1306 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1310 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1311 COL_STATUS, current,
1314 path = gtk_tree_model_get_path (model, &iter);
1315 gtk_tree_model_row_changed (model, path, &iter);
1316 gtk_tree_path_free (path);
1319 empathy_account_manager_get_accounts_connected (&found);
1321 if (!found && priv->connecting_id)
1323 g_source_remove (priv->connecting_id);
1324 priv->connecting_id = 0;
1327 if (found && !priv->connecting_id)
1328 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1329 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1334 accounts_dialog_presence_changed_cb (TpAccount *account,
1337 gchar *status_message,
1338 EmpathyAccountsDialog *dialog)
1340 /* Update the status-infobar in the details view */
1341 accounts_dialog_update_status_infobar (dialog, account);
1345 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1349 const gchar *display_name;
1351 GtkTreeModel *model;
1352 EmpathyAccountSettings *settings;
1353 TpAccount *selected_account;
1354 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1355 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1357 display_name = tp_account_get_display_name (account);
1358 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1359 settings = accounts_dialog_model_get_selected_settings (dialog);
1360 if (settings == NULL)
1363 selected_account = empathy_account_settings_get_account (settings);
1365 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1367 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1368 COL_NAME, display_name,
1372 if (selected_account == account)
1373 accounts_dialog_update_name_label (dialog, display_name);
1375 g_object_unref (settings);
1379 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1382 EmpathyAccountSettings *settings;
1383 GtkTreeModel *model;
1385 TpConnectionStatus status;
1388 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1390 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1391 status = tp_account_get_connection_status (account, NULL);
1392 name = tp_account_get_display_name (account);
1393 enabled = tp_account_is_enabled (account);
1395 settings = empathy_account_settings_new_for_account (account);
1397 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1398 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1400 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1403 COL_ACCOUNT_POINTER, account,
1404 COL_ACCOUNT_SETTINGS_POINTER, settings,
1407 accounts_dialog_connection_changed_cb (account,
1410 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1415 empathy_signal_connect_weak (account, "notify::display-name",
1416 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1419 g_object_unref (settings);
1423 account_prepare_cb (GObject *source_object,
1424 GAsyncResult *result,
1427 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1428 TpAccount *account = TP_ACCOUNT (source_object);
1429 GError *error = NULL;
1431 if (!tp_account_prepare_finish (account, result, &error))
1433 DEBUG ("Failed to prepare account: %s", error->message);
1434 g_error_free (error);
1438 accounts_dialog_add_account (dialog, account);
1442 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1445 EmpathyAccountsDialog *dialog)
1447 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1451 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1453 EmpathyAccountsDialog *dialog)
1456 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1458 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1460 gtk_list_store_remove (GTK_LIST_STORE (
1461 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1466 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1470 GtkTreeModel *model;
1471 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1473 /* Update the status in the model */
1474 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1476 /* Update the status-infobar in the details view when disabling */
1478 accounts_dialog_update_status_infobar (dialog, account);
1480 DEBUG ("Account %s is now %s",
1481 tp_account_get_display_name (account),
1482 enabled ? "enabled" : "disabled");
1486 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1488 EmpathyAccountsDialog *dialog)
1490 enable_or_disable_account (dialog, account, FALSE);
1494 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1496 EmpathyAccountsDialog *dialog)
1498 enable_or_disable_account (dialog, account, TRUE);
1502 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1503 EmpathyAccountsDialog *dialog)
1505 GtkWidget *import_dialog;
1507 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1509 gtk_widget_show (import_dialog);
1513 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1517 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1519 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1521 if (response_id == GTK_RESPONSE_YES)
1522 gtk_widget_destroy (account_dialog);
1526 accounts_dialog_delete_event_cb (GtkWidget *widget,
1528 EmpathyAccountsDialog *dialog)
1530 /* we maunally handle responses to delete events */
1535 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1538 GtkTreeSelection *selection;
1540 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1542 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1543 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1544 gtk_tree_selection_select_iter (selection, &iter);
1548 accounts_dialog_cms_ready_cb (EmpathyConnectionManagers *cms,
1550 EmpathyAccountsDialog *dialog)
1552 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1554 if (empathy_connection_managers_is_ready (cms))
1556 accounts_dialog_update_settings (dialog, NULL);
1558 if (priv->initial_selection != NULL)
1560 accounts_dialog_set_selected_account
1561 (dialog, priv->initial_selection);
1562 g_object_unref (priv->initial_selection);
1563 priv->initial_selection = NULL;
1569 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1571 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1572 GList *accounts, *l;
1574 g_signal_connect (priv->account_manager, "account-validity-changed",
1575 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1577 g_signal_connect (priv->account_manager, "account-removed",
1578 G_CALLBACK (accounts_dialog_account_removed_cb),
1580 g_signal_connect (priv->account_manager, "account-enabled",
1581 G_CALLBACK (accounts_dialog_account_enabled_cb),
1583 g_signal_connect (priv->account_manager, "account-disabled",
1584 G_CALLBACK (accounts_dialog_account_disabled_cb),
1587 /* Add existing accounts */
1588 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1589 for (l = accounts; l; l = l->next)
1591 accounts_dialog_add_account (dialog, l->data);
1593 empathy_signal_connect_weak (l->data, "status-changed",
1594 G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog));
1595 empathy_signal_connect_weak (l->data, "presence-changed",
1596 G_CALLBACK (accounts_dialog_presence_changed_cb), G_OBJECT (dialog));
1598 g_list_free (accounts);
1600 priv->cms = empathy_connection_managers_dup_singleton ();
1601 if (!empathy_connection_managers_is_ready (priv->cms))
1602 g_signal_connect (priv->cms, "notify::ready",
1603 G_CALLBACK (accounts_dialog_cms_ready_cb), dialog);
1605 accounts_dialog_model_select_first (dialog);
1609 accounts_dialog_manager_ready_cb (GObject *source_object,
1610 GAsyncResult *result,
1613 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
1614 GError *error = NULL;
1616 if (!tp_account_manager_prepare_finish (manager, result, &error))
1618 DEBUG ("Failed to prepare account manager: %s", error->message);
1619 g_error_free (error);
1623 accounts_dialog_accounts_setup (user_data);
1627 dialog_response_cb (GtkWidget *widget,
1631 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
1633 if (response_id == GTK_RESPONSE_HELP)
1635 empathy_url_show (widget, "ghelp:empathy?accounts-window");
1637 else if (response_id == GTK_RESPONSE_CLOSE ||
1638 response_id == GTK_RESPONSE_DELETE_EVENT)
1640 TpAccount *account = NULL;
1642 if (accounts_dialog_has_pending_change (dialog, &account))
1644 gchar *question_dialog_primary_text = get_dialog_primary_text (
1647 accounts_dialog_show_question_dialog (dialog,
1648 question_dialog_primary_text,
1649 _("You are about to close the window, which will discard\n"
1650 "your changes. Are you sure you want to proceed?"),
1651 G_CALLBACK (accounts_dialog_close_response_cb),
1653 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1654 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1656 g_free (question_dialog_primary_text);
1660 gtk_widget_destroy (widget);
1666 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
1668 GtkWidget *top_hbox;
1671 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1672 GtkWidget *content_area;
1673 GtkWidget *action_area;
1675 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
1677 gui = empathy_builder_get_file (filename,
1678 "accounts_dialog_hbox", &top_hbox,
1679 "vbox_details", &priv->vbox_details,
1680 "frame_no_protocol", &priv->frame_no_protocol,
1681 "alignment_settings", &priv->alignment_settings,
1682 "alignment_infobar", &priv->alignment_infobar,
1683 "treeview", &priv->treeview,
1684 "image_type", &priv->image_type,
1685 "label_name", &priv->label_name,
1686 "button_add", &priv->button_add,
1687 "button_import", &priv->button_import,
1688 "hbox_protocol", &priv->hbox_protocol,
1692 empathy_builder_connect (gui, dialog,
1693 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
1694 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
1697 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
1699 gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
1701 g_object_unref (gui);
1703 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
1706 gtk_widget_hide (action_area);
1709 priv->combobox_protocol = empathy_protocol_chooser_new ();
1710 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
1712 g_signal_connect (priv->combobox_protocol, "changed",
1713 G_CALLBACK (accounts_dialog_protocol_changed_cb),
1716 if (priv->parent_window)
1717 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1718 priv->parent_window);
1720 /* set up spinner */
1721 priv->throbber = ephy_spinner_new ();
1722 ephy_spinner_set_size (EPHY_SPINNER (priv->throbber), GTK_ICON_SIZE_SMALL_TOOLBAR);
1724 priv->infobar = gtk_info_bar_new ();
1725 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
1727 gtk_widget_show (priv->infobar);
1729 priv->image_status = gtk_image_new_from_icon_name (
1730 empathy_icon_name_for_presence (
1731 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
1733 priv->label_status = gtk_label_new (NULL);
1735 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
1736 gtk_box_pack_start (GTK_BOX (content_area), priv->throbber,
1738 gtk_box_pack_start (GTK_BOX (content_area), priv->image_status,
1740 gtk_container_add (GTK_CONTAINER (content_area), priv->label_status);
1742 /* Tweak the dialog */
1743 gtk_window_set_title (GTK_WINDOW (dialog), _("Accounts"));
1744 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
1746 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, -1);
1748 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
1750 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
1752 /* add dialog buttons */
1753 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
1755 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1756 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
1757 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
1760 g_signal_connect (dialog, "response",
1761 G_CALLBACK (dialog_response_cb), dialog);
1763 g_signal_connect (dialog, "delete-event",
1764 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
1768 do_dispose (GObject *obj)
1770 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
1771 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1773 if (priv->dispose_has_run)
1776 priv->dispose_has_run = TRUE;
1778 /* Disconnect signals */
1779 g_signal_handlers_disconnect_by_func (priv->account_manager,
1780 accounts_dialog_account_validity_changed_cb,
1782 g_signal_handlers_disconnect_by_func (priv->account_manager,
1783 accounts_dialog_account_removed_cb,
1785 g_signal_handlers_disconnect_by_func (priv->account_manager,
1786 accounts_dialog_account_enabled_cb,
1788 g_signal_handlers_disconnect_by_func (priv->account_manager,
1789 accounts_dialog_account_disabled_cb,
1791 g_signal_handlers_disconnect_by_func (priv->account_manager,
1792 accounts_dialog_manager_ready_cb,
1795 if (priv->connecting_id)
1796 g_source_remove (priv->connecting_id);
1798 if (priv->account_manager != NULL)
1800 g_object_unref (priv->account_manager);
1801 priv->account_manager = NULL;
1804 if (priv->cms != NULL)
1806 g_object_unref (priv->cms);
1810 if (priv->initial_selection != NULL)
1811 g_object_unref (priv->initial_selection);
1812 priv->initial_selection = NULL;
1814 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
1818 do_constructor (GType type,
1820 GObjectConstructParam *props)
1824 if (dialog_singleton)
1826 retval = G_OBJECT (dialog_singleton);
1831 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->constructor
1832 (type, n_props, props);
1834 dialog_singleton = EMPATHY_ACCOUNTS_DIALOG (retval);
1835 g_object_add_weak_pointer (retval, (gpointer) &dialog_singleton);
1842 do_get_property (GObject *object,
1847 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1849 switch (property_id)
1852 g_value_set_object (value, priv->parent_window);
1855 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1860 do_set_property (GObject *object,
1862 const GValue *value,
1865 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
1867 switch (property_id)
1870 priv->parent_window = g_value_get_object (value);
1873 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1878 do_constructed (GObject *object)
1880 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
1881 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1882 gboolean import_asked;
1884 accounts_dialog_build_ui (dialog);
1885 accounts_dialog_model_setup (dialog);
1887 /* Set up signalling */
1888 priv->account_manager = tp_account_manager_dup ();
1890 tp_account_manager_prepare_async (priv->account_manager, NULL,
1891 accounts_dialog_manager_ready_cb, dialog);
1893 empathy_conf_get_bool (empathy_conf_get (),
1894 EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
1896 if (empathy_import_accounts_to_import ())
1898 gtk_widget_show (priv->button_import);
1902 GtkWidget *import_dialog;
1904 empathy_conf_set_bool (empathy_conf_get (),
1905 EMPATHY_PREFS_IMPORT_ASKED, TRUE);
1906 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1908 gtk_widget_show (import_dialog);
1914 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
1916 GObjectClass *oclass = G_OBJECT_CLASS (klass);
1917 GParamSpec *param_spec;
1919 oclass->constructor = do_constructor;
1920 oclass->dispose = do_dispose;
1921 oclass->constructed = do_constructed;
1922 oclass->set_property = do_set_property;
1923 oclass->get_property = do_get_property;
1925 param_spec = g_param_spec_object ("parent",
1926 "parent", "The parent window",
1928 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
1929 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
1931 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
1935 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
1937 EmpathyAccountsDialogPriv *priv;
1939 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
1940 EMPATHY_TYPE_ACCOUNTS_DIALOG,
1941 EmpathyAccountsDialogPriv);
1942 dialog->priv = priv;
1945 /* public methods */
1948 empathy_accounts_dialog_show (GtkWindow *parent,
1949 TpAccount *selected_account)
1951 EmpathyAccountsDialog *dialog;
1952 EmpathyAccountsDialogPriv *priv;
1954 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
1955 "parent", parent, NULL);
1957 priv = GET_PRIV (dialog);
1959 if (selected_account)
1961 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
1962 accounts_dialog_set_selected_account (dialog, selected_account);
1964 /* save the selection to set it later when the cms
1967 priv->initial_selection = g_object_ref (selected_account);
1970 gtk_window_present (GTK_WINDOW (dialog));
1972 return GTK_WIDGET (dialog);