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-lib.h>
33 #include <dbus/dbus-glib.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/defs.h>
37 #include <telepathy-glib/util.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-connection-managers.h>
41 #include <libempathy/empathy-connectivity.h>
43 #include <libempathy-gtk/empathy-ui-utils.h>
44 #include <libempathy-gtk/empathy-protocol-chooser.h>
45 #include <libempathy-gtk/empathy-account-widget.h>
46 #include <libempathy-gtk/empathy-account-widget-irc.h>
47 #include <libempathy-gtk/empathy-account-widget-sip.h>
48 #include <libempathy-gtk/empathy-cell-renderer-activatable.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"
55 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
56 #include <libempathy/empathy-debug.h>
58 /* Flashing delay for icons (milliseconds). */
59 #define FLASH_TIMEOUT 500
61 /* The primary text of the dialog shown to the user when he is about to lose
63 #define PENDING_CHANGES_QUESTION_PRIMARY_TEXT \
64 _("There are unsaved modifications to your %s account.")
65 /* The primary text of the dialog shown to the user when he is about to lose
66 * an unsaved new account */
67 #define UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT \
68 _("Your new account has not been saved yet.")
70 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
71 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
75 NOTEBOOK_PAGE_ACCOUNT = 0,
80 GtkWidget *alignment_settings;
81 GtkWidget *alignment_infobar;
83 GtkWidget *vbox_details;
85 GtkWidget *label_status;
86 GtkWidget *image_status;
88 GtkWidget *frame_no_protocol;
92 GtkWidget *button_add;
93 GtkWidget *button_remove;
94 GtkWidget *button_import;
96 GtkWidget *combobox_protocol;
97 GtkWidget *hbox_protocol;
99 GtkWidget *image_type;
100 GtkWidget *label_name;
101 GtkWidget *label_type;
102 GtkWidget *settings_widget;
104 GtkWidget *notebook_account;
108 /* We have to keep a reference on the actual EmpathyAccountWidget, not just
109 * his GtkWidget. It is the only reliable source we can query to know if
110 * there are any unsaved changes to the currently selected account. We can't
111 * look at the account settings because it does not contain everything that
112 * can be changed using the EmpathyAccountWidget. For instance, it does not
113 * contain the state of the "Enabled" checkbox. */
114 EmpathyAccountWidget *setting_widget_object;
116 gboolean connecting_show;
119 gulong settings_ready_id;
120 EmpathyAccountSettings *settings_ready;
122 TpAccountManager *account_manager;
123 EmpathyConnectionManagers *cms;
124 EmpathyConnectivity *connectivity;
126 GtkWindow *parent_window;
127 TpAccount *initial_selection;
129 /* Those are needed when changing the selected row. When a user selects
130 * another account and there are unsaved changes on the currently selected
131 * one, a confirmation message box is presented to him. Since his answer
132 * is retrieved asynchronously, we keep some information as member of the
133 * EmpathyAccountsDialog object. */
134 gboolean force_change_row;
135 GtkTreeRowReference *destination_row;
136 } EmpathyAccountsDialogPriv;
142 COL_ACCOUNT_SETTINGS,
150 static EmpathyAccountSettings * accounts_dialog_model_get_selected_settings (
151 EmpathyAccountsDialog *dialog);
153 static gboolean accounts_dialog_get_settings_iter (
154 EmpathyAccountsDialog *dialog,
155 EmpathyAccountSettings *settings,
158 static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog);
160 static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
161 EmpathyAccountSettings *settings);
163 static void accounts_dialog_add (EmpathyAccountsDialog *dialog,
164 EmpathyAccountSettings *settings);
166 static void accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
167 EmpathyAccountSettings *settings);
169 static void accounts_dialog_connection_changed_cb (TpAccount *account,
173 gchar *dbus_error_name,
175 EmpathyAccountsDialog *dialog);
177 static void accounts_dialog_presence_changed_cb (TpAccount *account,
180 gchar *status_message,
181 EmpathyAccountsDialog *dialog);
183 static void accounts_dialog_model_selection_changed (
184 GtkTreeSelection *selection,
185 EmpathyAccountsDialog *dialog);
188 accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
189 const gchar *display_name)
192 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
194 text = g_markup_printf_escaped ("<b>%s</b>", display_name);
195 gtk_label_set_markup (GTK_LABEL (priv->label_name), text);
201 accounts_dialog_status_infobar_set_message (EmpathyAccountsDialog *dialog,
202 const gchar *message)
204 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
205 gchar *message_markup;
207 message_markup = g_markup_printf_escaped ("<i>%s</i>", message);
208 gtk_label_set_markup (GTK_LABEL (priv->label_status), message_markup);
209 g_free (message_markup);
213 accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog,
216 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
217 gchar *status_message = NULL;
223 GtkTreeSelection *selection;
225 TpAccount *selected_account;
226 gboolean account_enabled;
227 gboolean creating_account;
229 view = GTK_TREE_VIEW (priv->treeview);
230 selection = gtk_tree_view_get_selection (view);
232 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
235 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1);
236 if (selected_account != NULL)
237 g_object_unref (selected_account);
239 /* do not update the infobar when the account is not selected */
240 if (account != selected_account)
245 status = tp_account_get_connection_status (account, &reason);
246 presence = tp_account_get_current_presence (account, NULL, &status_message);
247 account_enabled = tp_account_is_enabled (account);
248 creating_account = FALSE;
250 if (status == TP_CONNECTION_STATUS_CONNECTED &&
251 (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
252 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET))
253 /* If presence is Unset (CM doesn't implement SimplePresence) but we
254 * are connected, consider ourself as Available.
255 * We also check Offline because of this MC5 bug: fd.o #26060 */
256 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
258 /* set presence to offline if account is disabled
259 * (else no icon is shown in infobar)*/
260 if (!account_enabled)
261 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
265 status = TP_CONNECTION_STATUS_DISCONNECTED;
266 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
267 account_enabled = FALSE;
268 creating_account = TRUE;
271 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_status),
272 empathy_icon_name_for_presence (presence), GTK_ICON_SIZE_SMALL_TOOLBAR);
278 case TP_CONNECTION_STATUS_CONNECTING:
279 accounts_dialog_status_infobar_set_message (dialog,
281 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
284 gtk_spinner_start (GTK_SPINNER (priv->throbber));
285 gtk_widget_show (priv->throbber);
286 gtk_widget_hide (priv->image_status);
288 case TP_CONNECTION_STATUS_CONNECTED:
289 if (g_strcmp0 (status_message, "") == 0)
293 message = g_strdup_printf ("%s",
294 empathy_presence_get_default_message (presence));
296 accounts_dialog_status_infobar_set_message (dialog, message);
303 message = g_strdup_printf ("%s — %s",
304 empathy_presence_get_default_message (presence),
307 accounts_dialog_status_infobar_set_message (dialog, message);
310 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
313 gtk_widget_show (priv->image_status);
314 gtk_widget_hide (priv->throbber);
316 case TP_CONNECTION_STATUS_DISCONNECTED:
317 if (reason == TP_CONNECTION_STATUS_REASON_REQUESTED)
321 message = g_strdup_printf (_("Offline — %s"),
322 empathy_account_get_error_message (account, NULL));
323 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
324 GTK_MESSAGE_WARNING);
326 accounts_dialog_status_infobar_set_message (dialog, message);
333 message = g_strdup_printf (_("Disconnected — %s"),
334 empathy_account_get_error_message (account, NULL));
335 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
338 accounts_dialog_status_infobar_set_message (dialog, message);
342 if (!empathy_connectivity_is_online (priv->connectivity))
343 accounts_dialog_status_infobar_set_message (dialog,
344 _("Offline — No Network Connection"));
346 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
347 gtk_widget_show (priv->image_status);
348 gtk_widget_hide (priv->throbber);
351 accounts_dialog_status_infobar_set_message (dialog, _("Unknown Status"));
352 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
353 GTK_MESSAGE_WARNING);
355 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
356 gtk_widget_hide (priv->image_status);
357 gtk_widget_hide (priv->throbber);
362 accounts_dialog_status_infobar_set_message (dialog,
363 _("Offline — Account Disabled"));
365 gtk_info_bar_set_message_type (GTK_INFO_BAR (priv->infobar),
366 GTK_MESSAGE_WARNING);
367 gtk_spinner_stop (GTK_SPINNER (priv->throbber));
368 gtk_widget_show (priv->image_status);
369 gtk_widget_hide (priv->throbber);
372 gtk_widget_show (priv->label_status);
374 if (!creating_account)
375 gtk_widget_show (priv->infobar);
377 gtk_widget_hide (priv->infobar);
379 g_free (status_message);
383 empathy_account_dialog_cancel (EmpathyAccountsDialog *dialog)
387 GtkTreeSelection *selection;
389 EmpathyAccountSettings *settings;
391 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
393 view = GTK_TREE_VIEW (priv->treeview);
394 selection = gtk_tree_view_get_selection (view);
396 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
399 gtk_tree_model_get (model, &iter,
400 COL_ACCOUNT_SETTINGS, &settings,
401 COL_ACCOUNT, &account, -1);
403 empathy_account_widget_discard_pending_changes (priv->setting_widget_object);
407 /* We were creating an account. We remove the selected row */
408 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
412 /* We were modifying an account. We discard the changes by reloading the
413 * settings and the UI. */
414 accounts_dialog_update_settings (dialog, settings);
415 g_object_unref (account);
418 gtk_widget_set_sensitive (priv->treeview, TRUE);
419 gtk_widget_set_sensitive (priv->button_add, TRUE);
420 gtk_widget_set_sensitive (priv->button_remove, TRUE);
421 gtk_widget_set_sensitive (priv->button_import, TRUE);
423 if (settings != NULL)
424 g_object_unref (settings);
428 empathy_account_dialog_widget_cancelled_cb (
429 EmpathyAccountWidget *widget_object,
430 EmpathyAccountsDialog *dialog)
432 empathy_account_dialog_cancel (dialog);
436 empathy_account_dialog_account_created_cb (EmpathyAccountWidget *widget_object,
438 EmpathyAccountsDialog *dialog)
440 EmpathyAccountSettings *settings =
441 accounts_dialog_model_get_selected_settings (dialog);
442 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
444 accounts_dialog_update_settings (dialog, settings);
445 accounts_dialog_update_status_infobar (dialog,
446 empathy_account_settings_get_account (settings));
448 gtk_widget_set_sensitive (priv->treeview, TRUE);
449 gtk_widget_set_sensitive (priv->button_add, TRUE);
450 gtk_widget_set_sensitive (priv->button_remove, TRUE);
451 gtk_widget_set_sensitive (priv->button_import, TRUE);
454 g_object_unref (settings);
458 accounts_dialog_has_valid_accounts (EmpathyAccountsDialog *dialog)
460 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
465 g_object_get (priv->setting_widget_object,
466 "creating-account", &creating, NULL);
471 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
473 if (gtk_tree_model_get_iter_first (model, &iter))
474 return gtk_tree_model_iter_next (model, &iter);
480 account_dialog_create_settings_widget (EmpathyAccountsDialog *dialog,
481 EmpathyAccountSettings *settings)
483 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
484 const gchar *icon_name;
487 priv->setting_widget_object =
488 empathy_account_widget_new_for_protocol (settings, FALSE);
490 if (accounts_dialog_has_valid_accounts (dialog))
491 empathy_account_widget_set_other_accounts_exist (
492 priv->setting_widget_object, TRUE);
494 priv->settings_widget =
495 empathy_account_widget_get_widget (priv->setting_widget_object);
497 g_signal_connect (priv->setting_widget_object, "account-created",
498 G_CALLBACK (empathy_account_dialog_account_created_cb), dialog);
499 g_signal_connect (priv->setting_widget_object, "cancelled",
500 G_CALLBACK (empathy_account_dialog_widget_cancelled_cb), dialog);
502 gtk_container_add (GTK_CONTAINER (priv->alignment_settings),
503 priv->settings_widget);
504 gtk_widget_show (priv->settings_widget);
506 icon_name = empathy_account_settings_get_icon_name (settings);
508 if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
510 /* show the default icon; keep this in sync with the default
511 * one in empathy-accounts-dialog.ui.
513 icon_name = GTK_STOCK_CUT;
515 gtk_image_set_from_icon_name (GTK_IMAGE (priv->image_type),
516 icon_name, GTK_ICON_SIZE_DIALOG);
517 gtk_widget_set_tooltip_text (priv->image_type,
518 empathy_protocol_name_to_display_name
519 (empathy_account_settings_get_protocol (settings)));
520 gtk_widget_show (priv->image_type);
522 accounts_dialog_update_name_label (dialog,
523 empathy_account_settings_get_display_name (settings));
525 account = empathy_account_settings_get_account (settings);
526 accounts_dialog_update_status_infobar (dialog, account);
530 account_dialog_settings_ready_cb (EmpathyAccountSettings *settings,
532 EmpathyAccountsDialog *dialog)
534 if (empathy_account_settings_is_ready (settings))
535 account_dialog_create_settings_widget (dialog, settings);
539 accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog)
543 GtkTreeSelection *selection;
545 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
548 view = GTK_TREE_VIEW (priv->treeview);
549 model = gtk_tree_view_get_model (view);
551 if (gtk_tree_model_get_iter_first (model, &iter))
553 selection = gtk_tree_view_get_selection (view);
554 gtk_tree_selection_select_iter (selection, &iter);
558 accounts_dialog_update_settings (dialog, NULL);
563 accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog,
568 GtkTreeSelection *selection;
569 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
571 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
573 if (gtk_tree_selection_get_selected (selection, &model, &iter))
574 gtk_tree_model_get (model, &iter, COL_ACCOUNT, account, -1);
576 return priv->setting_widget_object != NULL
577 && empathy_account_widget_contains_pending_changes (
578 priv->setting_widget_object);
582 accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
584 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
585 EmpathyAccountSettings *settings;
587 settings = empathy_protocol_chooser_create_account_settings (
588 EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol));
589 if (settings == NULL)
592 accounts_dialog_add (dialog, settings);
593 accounts_dialog_model_set_selected (dialog, settings);
595 gtk_widget_show_all (priv->hbox_protocol);
597 g_object_unref (settings);
601 accounts_dialog_protocol_changed_cb (GtkWidget *widget,
602 EmpathyAccountsDialog *dialog)
604 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
605 GtkTreeSelection *selection;
609 EmpathyAccountSettings *settings;
610 gchar *account = NULL, *password = NULL;
612 /* The "changed" signal is fired during the initiation of the
613 * EmpathyProtocolChooser while populating the widget. Such signals should
614 * be ignored so we check if we are actually creating a new account. */
615 if (priv->setting_widget_object == NULL)
618 g_object_get (priv->setting_widget_object,
619 "creating-account", &creating, NULL);
623 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
625 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
628 /* Save "account" and "password" parameters */
629 g_object_get (priv->setting_widget_object, "settings", &settings, NULL);
631 if (settings != NULL)
633 account = g_strdup (empathy_account_settings_get_string (settings,
635 password = g_strdup (empathy_account_settings_get_string (settings,
637 g_object_unref (settings);
640 /* We are creating a new widget to replace the current one, don't ask
641 * confirmation to the user. */
642 priv->force_change_row = TRUE;
644 /* We'll update the selection after we create the new account widgets;
645 * updating it right now causes problems for the # of accounts = zero case */
646 g_signal_handlers_block_by_func (selection,
647 accounts_dialog_model_selection_changed, dialog);
649 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
651 g_signal_handlers_unblock_by_func (selection,
652 accounts_dialog_model_selection_changed, dialog);
654 accounts_dialog_setup_ui_to_add_account (dialog);
656 /* Restore "account" and "password" parameters in the new widget */
659 empathy_account_widget_set_account_param (priv->setting_widget_object,
664 if (password != NULL)
666 empathy_account_widget_set_password_param (priv->setting_widget_object,
673 accounts_dialog_show_question_dialog (EmpathyAccountsDialog *dialog,
674 const gchar *primary_text,
675 const gchar *secondary_text,
676 GCallback response_callback,
678 const gchar *first_button_text,
682 GtkWidget *message_dialog;
683 const gchar *button_text;
685 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
686 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
687 GTK_MESSAGE_QUESTION,
691 gtk_message_dialog_format_secondary_text (
692 GTK_MESSAGE_DIALOG (message_dialog), "%s", secondary_text);
694 va_start (button_args, first_button_text);
695 for (button_text = first_button_text;
697 button_text = va_arg (button_args, const gchar *))
700 response_id = va_arg (button_args, gint);
702 gtk_dialog_add_button (GTK_DIALOG (message_dialog), button_text,
705 va_end (button_args);
707 g_signal_connect (message_dialog, "response", response_callback, user_data);
709 gtk_widget_show (message_dialog);
713 accounts_dialog_add_pending_changes_response_cb (GtkDialog *message_dialog,
717 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
718 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
720 gtk_widget_destroy (GTK_WIDGET (message_dialog));
722 if (response_id == GTK_RESPONSE_YES)
724 empathy_account_widget_discard_pending_changes (
725 priv->setting_widget_object);
726 accounts_dialog_setup_ui_to_add_account (dialog);
731 get_dialog_primary_text (TpAccount *account)
735 /* Existing account */
736 return g_strdup_printf (PENDING_CHANGES_QUESTION_PRIMARY_TEXT,
737 tp_account_get_display_name (account));
741 /* Newly created account */
742 return g_strdup (UNSAVED_NEW_ACCOUNT_QUESTION_PRIMARY_TEXT);
747 accounts_dialog_button_add_clicked_cb (GtkWidget *button,
748 EmpathyAccountsDialog *dialog)
750 TpAccount *account = NULL;
751 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
753 if (accounts_dialog_has_pending_change (dialog, &account))
755 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
757 accounts_dialog_show_question_dialog (dialog,
758 question_dialog_primary_text,
759 _("You are about to create a new account, which will discard\n"
760 "your changes. Are you sure you want to proceed?"),
761 G_CALLBACK (accounts_dialog_add_pending_changes_response_cb),
763 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
764 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
766 g_free (question_dialog_primary_text);
770 accounts_dialog_setup_ui_to_add_account (dialog);
771 gtk_widget_set_sensitive (priv->treeview, FALSE);
772 gtk_widget_set_sensitive (priv->button_add, FALSE);
773 gtk_widget_set_sensitive (priv->button_remove, FALSE);
774 gtk_widget_set_sensitive (priv->button_import, FALSE);
778 g_object_unref (account);
782 accounts_dialog_update_settings (EmpathyAccountsDialog *dialog,
783 EmpathyAccountSettings *settings)
785 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
787 if (priv->settings_ready != NULL)
789 g_signal_handler_disconnect (priv->settings_ready,
790 priv->settings_ready_id);
791 priv->settings_ready = NULL;
792 priv->settings_ready_id = 0;
799 GtkTreeSelection *selection;
801 view = GTK_TREE_VIEW (priv->treeview);
802 model = gtk_tree_view_get_model (view);
803 selection = gtk_tree_view_get_selection (view);
805 if (gtk_tree_model_iter_n_children (model, NULL) > 0)
807 /* We have configured accounts, select the first one if there
808 * is no other account selected already. */
809 if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
810 accounts_dialog_model_select_first (dialog);
814 if (empathy_connection_managers_get_cms_num (priv->cms) > 0)
816 /* We have no account configured but we have some
817 * profiles installed. The user obviously wants to add
818 * an account. Click on the Add button for him. */
819 accounts_dialog_button_add_clicked_cb (priv->button_add,
824 /* No account and no profile, warn the user */
825 gtk_widget_hide (priv->vbox_details);
826 gtk_widget_show (priv->frame_no_protocol);
827 gtk_widget_set_sensitive (priv->button_add, FALSE);
831 /* We have an account selected, destroy old settings and create a new
832 * one for the account selected */
833 gtk_widget_hide (priv->frame_no_protocol);
834 gtk_widget_show (priv->vbox_details);
835 gtk_widget_hide (priv->hbox_protocol);
837 if (priv->settings_widget)
839 gtk_widget_destroy (priv->settings_widget);
840 priv->settings_widget = NULL;
843 if (empathy_account_settings_is_ready (settings))
845 account_dialog_create_settings_widget (dialog, settings);
849 priv->settings_ready = settings;
850 priv->settings_ready_id =
851 g_signal_connect (settings, "notify::ready",
852 G_CALLBACK (account_dialog_settings_ready_cb), dialog);
858 accounts_dialog_name_editing_started_cb (GtkCellRenderer *renderer,
859 GtkCellEditable *editable,
861 EmpathyAccountsDialog *dialog)
863 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
865 if (priv->connecting_id)
866 g_source_remove (priv->connecting_id);
868 DEBUG ("Editing account name started; stopping flashing");
872 get_status_icon_for_account (EmpathyAccountsDialog *self,
875 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
876 TpConnectionStatus status;
877 TpConnectionStatusReason reason;
878 TpConnectionPresenceType presence;
881 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
883 if (!tp_account_is_enabled (account))
884 return empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
886 status = tp_account_get_connection_status (account, &reason);
888 if (status == TP_CONNECTION_STATUS_DISCONNECTED)
890 if (reason != TP_CONNECTION_STATUS_REASON_REQUESTED)
891 /* An error occured */
892 return GTK_STOCK_DIALOG_ERROR;
894 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
896 else if (status == TP_CONNECTION_STATUS_CONNECTING)
898 /* Account is connecting. Display a blinking account alternating between
899 * the offline icon and the requested presence. */
900 if (priv->connecting_show)
901 presence = tp_account_get_requested_presence (account, NULL, NULL);
903 presence = TP_CONNECTION_PRESENCE_TYPE_OFFLINE;
907 /* status == TP_CONNECTION_STATUS_CONNECTED */
908 presence = tp_account_get_current_presence (account, NULL, NULL);
910 /* If presence is Unset (CM doesn't implement SimplePresence),
911 * display the 'available' icon.
912 * We also check Offline because of this MC5 bug: fd.o #26060 */
913 if (presence == TP_CONNECTION_PRESENCE_TYPE_OFFLINE ||
914 presence == TP_CONNECTION_PRESENCE_TYPE_UNSET)
915 presence = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
918 return empathy_icon_name_for_presence (presence);
922 accounts_dialog_model_status_pixbuf_data_func (GtkTreeViewColumn *tree_column,
923 GtkCellRenderer *cell,
926 EmpathyAccountsDialog *dialog)
930 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
933 "icon-name", get_status_icon_for_account (dialog, account),
937 g_object_unref (account);
941 accounts_dialog_model_protocol_pixbuf_data_func (GtkTreeViewColumn *tree_column,
942 GtkCellRenderer *cell,
945 EmpathyAccountsDialog *dialog)
947 EmpathyAccountSettings *settings;
950 TpConnectionStatus status;
952 gtk_tree_model_get (model, iter,
954 COL_ACCOUNT_SETTINGS, &settings,
957 icon_name = empathy_account_settings_get_icon_name (settings);
958 pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
965 g_object_unref (settings);
968 g_object_unref (pixbuf);
972 accounts_dialog_row_changed_foreach (GtkTreeModel *model,
977 gtk_tree_model_row_changed (model, path, iter);
983 accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
987 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
989 priv->connecting_show = !priv->connecting_show;
991 view = GTK_TREE_VIEW (priv->treeview);
992 model = gtk_tree_view_get_model (view);
994 gtk_tree_model_foreach (model, accounts_dialog_row_changed_foreach, NULL);
1000 accounts_dialog_name_edited_cb (GtkCellRendererText *renderer,
1003 EmpathyAccountsDialog *dialog)
1005 EmpathyAccountSettings *settings;
1006 GtkTreeModel *model;
1007 GtkTreePath *treepath;
1009 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1010 gboolean connecting;
1012 empathy_account_manager_get_accounts_connected (&connecting);
1016 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1017 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1021 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1022 treepath = gtk_tree_path_new_from_string (path);
1023 gtk_tree_model_get_iter (model, &iter, treepath);
1024 gtk_tree_model_get (model, &iter,
1025 COL_ACCOUNT_SETTINGS, &settings,
1027 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1030 gtk_tree_path_free (treepath);
1032 empathy_account_settings_set_display_name_async (settings, new_text,
1034 g_object_set (settings, "display-name-overridden", TRUE, NULL);
1035 g_object_unref (settings);
1039 accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog,
1044 GtkTreeModel *model;
1046 GtkTreeSelection *selection;
1047 EmpathyAccountsDialog *account_dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1048 EmpathyAccountsDialogPriv *priv = GET_PRIV (account_dialog);
1050 if (response_id == GTK_RESPONSE_YES)
1052 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1054 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1057 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1059 if (account != NULL)
1061 tp_account_remove_async (account, NULL, NULL);
1062 g_object_unref (account);
1066 /* No need to call accounts_dialog_model_selection_changed while
1067 * removing as we are going to call accounts_dialog_model_select_first
1068 * right after which will update the selection. */
1069 g_signal_handlers_block_by_func (selection,
1070 accounts_dialog_model_selection_changed, account_dialog);
1072 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1074 g_signal_handlers_unblock_by_func (selection,
1075 accounts_dialog_model_selection_changed, account_dialog);
1077 accounts_dialog_model_select_first (account_dialog);
1080 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1084 accounts_dialog_remove_account_iter (EmpathyAccountsDialog *dialog,
1087 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1089 GtkTreeModel *model;
1090 gchar *question_dialog_primary_text;
1092 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1094 gtk_tree_model_get (model, iter, COL_ACCOUNT, &account, -1);
1096 if (account == NULL || !tp_account_is_valid (account))
1098 if (account != NULL)
1099 g_object_unref (account);
1100 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1101 accounts_dialog_model_select_first (dialog);
1105 question_dialog_primary_text = g_strdup_printf (
1106 _("Do you want to remove %s from your computer?"),
1107 tp_account_get_display_name (account));
1109 accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text,
1110 _("This will not remove your account on the server."),
1111 G_CALLBACK (accounts_dialog_delete_account_response_cb),
1113 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1114 GTK_STOCK_REMOVE, GTK_RESPONSE_YES, NULL);
1116 g_free (question_dialog_primary_text);
1117 g_object_unref (account);
1121 accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
1122 EmpathyAccountsDialog *dialog)
1124 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1126 GtkTreeModel *model;
1127 GtkTreeSelection *selection;
1130 view = GTK_TREE_VIEW (priv->treeview);
1131 model = gtk_tree_view_get_model (view);
1132 selection = gtk_tree_view_get_selection (view);
1133 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
1136 accounts_dialog_remove_account_iter (dialog, &iter);
1141 accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell,
1142 const gchar *path_string,
1143 EmpathyAccountsDialog *dialog)
1145 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1146 GtkTreeModel *model;
1149 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1150 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1153 accounts_dialog_remove_account_iter (dialog, &iter);
1155 #endif /* HAVE_MEEGO */
1158 accounts_dialog_model_add_columns (EmpathyAccountsDialog *dialog)
1161 GtkTreeViewColumn *column;
1162 GtkCellRenderer *cell;
1163 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1165 view = GTK_TREE_VIEW (priv->treeview);
1166 gtk_tree_view_set_headers_visible (view, FALSE);
1168 /* Account column */
1169 column = gtk_tree_view_column_new ();
1170 gtk_tree_view_column_set_expand (column, TRUE);
1171 gtk_tree_view_append_column (view, column);
1173 /* Status icon renderer */
1174 cell = gtk_cell_renderer_pixbuf_new ();
1175 gtk_tree_view_column_pack_start (column, cell, FALSE);
1176 gtk_tree_view_column_set_cell_data_func (column, cell,
1177 (GtkTreeCellDataFunc)
1178 accounts_dialog_model_status_pixbuf_data_func,
1182 /* Protocol icon renderer */
1183 cell = gtk_cell_renderer_pixbuf_new ();
1184 gtk_tree_view_column_pack_start (column, cell, FALSE);
1185 gtk_tree_view_column_set_cell_data_func (column, cell,
1186 (GtkTreeCellDataFunc)
1187 accounts_dialog_model_protocol_pixbuf_data_func,
1192 cell = gtk_cell_renderer_text_new ();
1194 "ellipsize", PANGO_ELLIPSIZE_END,
1198 gtk_tree_view_column_pack_start (column, cell, TRUE);
1199 gtk_tree_view_column_add_attribute (column, cell, "text", COL_NAME);
1200 g_signal_connect (cell, "edited",
1201 G_CALLBACK (accounts_dialog_name_edited_cb),
1203 g_signal_connect (cell, "editing-started",
1204 G_CALLBACK (accounts_dialog_name_editing_started_cb),
1206 g_object_set (cell, "ypad", 4, NULL);
1210 cell = empathy_cell_renderer_activatable_new ();
1211 gtk_tree_view_column_pack_start (column, cell, FALSE);
1213 "icon-name", GTK_STOCK_DELETE,
1214 "show-on-select", TRUE,
1217 g_signal_connect (cell, "path-activated",
1218 G_CALLBACK (accounts_dialog_view_delete_activated_cb),
1220 #endif /* HAVE_MEEGO */
1223 static EmpathyAccountSettings *
1224 accounts_dialog_model_get_selected_settings (EmpathyAccountsDialog *dialog)
1227 GtkTreeModel *model;
1228 GtkTreeSelection *selection;
1230 EmpathyAccountSettings *settings;
1231 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1233 view = GTK_TREE_VIEW (priv->treeview);
1234 selection = gtk_tree_view_get_selection (view);
1236 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1239 gtk_tree_model_get (model, &iter,
1240 COL_ACCOUNT_SETTINGS, &settings, -1);
1246 accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
1247 EmpathyAccountsDialog *dialog)
1249 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1250 EmpathyAccountSettings *settings;
1251 GtkTreeModel *model;
1253 gboolean is_selection;
1254 gboolean creating = FALSE;
1256 is_selection = gtk_tree_selection_get_selected (selection, &model, &iter);
1258 settings = accounts_dialog_model_get_selected_settings (dialog);
1259 accounts_dialog_update_settings (dialog, settings);
1261 if (settings != NULL)
1262 g_object_unref (settings);
1264 if (priv->setting_widget_object != NULL)
1266 g_object_get (priv->setting_widget_object,
1267 "creating-account", &creating, NULL);
1270 /* Update remove button sensitivity */
1271 gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
1276 accounts_dialog_selection_change_response_cb (GtkDialog *message_dialog,
1278 gpointer *user_data)
1280 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1281 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1283 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1285 if (response_id == GTK_RESPONSE_YES && priv->destination_row != NULL)
1287 /* The user wants to lose unsaved changes to the currently selected
1288 * account and select another account. We discard the changes and
1289 * select the other account. */
1291 GtkTreeSelection *selection;
1293 priv->force_change_row = TRUE;
1294 empathy_account_widget_discard_pending_changes (
1295 priv->setting_widget_object);
1297 path = gtk_tree_row_reference_get_path (priv->destination_row);
1298 selection = gtk_tree_view_get_selection (
1299 GTK_TREE_VIEW (priv->treeview));
1303 /* This will trigger a call to
1304 * accounts_dialog_account_selection_change() */
1305 gtk_tree_selection_select_path (selection, path);
1306 gtk_tree_path_free (path);
1309 gtk_tree_row_reference_free (priv->destination_row);
1313 priv->force_change_row = FALSE;
1318 accounts_dialog_account_selection_change (GtkTreeSelection *selection,
1319 GtkTreeModel *model,
1321 gboolean path_currently_selected,
1324 TpAccount *account = NULL;
1325 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data);
1326 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1329 if (priv->force_change_row)
1331 /* We came back here because the user wants to discard changes to his
1332 * modified account. The changes have already been discarded so we
1333 * just change the selected row. */
1334 priv->force_change_row = FALSE;
1338 if (accounts_dialog_has_pending_change (dialog, &account))
1340 /* The currently selected account has some unsaved changes. We ask
1341 * the user if he really wants to lose his changes and select another
1343 gchar *question_dialog_primary_text = get_dialog_primary_text (account);
1344 priv->destination_row = gtk_tree_row_reference_new (model, path);
1346 accounts_dialog_show_question_dialog (dialog,
1347 question_dialog_primary_text,
1348 _("You are about to select another account, which will discard\n"
1349 "your changes. Are you sure you want to proceed?"),
1350 G_CALLBACK (accounts_dialog_selection_change_response_cb),
1352 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
1353 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
1355 g_free (question_dialog_primary_text);
1363 if (account != NULL)
1364 g_object_unref (account);
1370 accounts_dialog_model_setup (EmpathyAccountsDialog *dialog)
1372 GtkListStore *store;
1373 GtkTreeSelection *selection;
1374 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1376 store = gtk_list_store_new (COL_COUNT,
1377 G_TYPE_STRING, /* name */
1378 G_TYPE_UINT, /* status */
1379 TP_TYPE_ACCOUNT, /* account */
1380 EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */
1382 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview),
1383 GTK_TREE_MODEL (store));
1385 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1386 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
1387 gtk_tree_selection_set_select_function (selection,
1388 accounts_dialog_account_selection_change, dialog, NULL);
1390 g_signal_connect (selection, "changed",
1391 G_CALLBACK (accounts_dialog_model_selection_changed),
1394 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
1395 COL_NAME, GTK_SORT_ASCENDING);
1397 accounts_dialog_model_add_columns (dialog);
1399 g_object_unref (store);
1403 accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog,
1404 EmpathyAccountSettings *settings,
1408 GtkTreeSelection *selection;
1409 GtkTreeModel *model;
1411 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1413 /* Update the status in the model */
1414 view = GTK_TREE_VIEW (priv->treeview);
1415 selection = gtk_tree_view_get_selection (view);
1416 model = gtk_tree_view_get_model (view);
1418 for (ok = gtk_tree_model_get_iter_first (model, iter);
1420 ok = gtk_tree_model_iter_next (model, iter))
1422 EmpathyAccountSettings *this_settings;
1425 gtk_tree_model_get (model, iter,
1426 COL_ACCOUNT_SETTINGS, &this_settings,
1429 equal = (this_settings == settings);
1430 g_object_unref (this_settings);
1440 accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog,
1445 GtkTreeSelection *selection;
1446 GtkTreeModel *model;
1448 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1450 /* Update the status in the model */
1451 view = GTK_TREE_VIEW (priv->treeview);
1452 selection = gtk_tree_view_get_selection (view);
1453 model = gtk_tree_view_get_model (view);
1455 for (ok = gtk_tree_model_get_iter_first (model, iter);
1457 ok = gtk_tree_model_iter_next (model, iter))
1459 EmpathyAccountSettings *settings;
1462 gtk_tree_model_get (model, iter,
1463 COL_ACCOUNT_SETTINGS, &settings,
1466 equal = empathy_account_settings_has_account (settings, account);
1467 g_object_unref (settings);
1477 accounts_dialog_model_set_selected (EmpathyAccountsDialog *dialog,
1478 EmpathyAccountSettings *settings)
1480 GtkTreeSelection *selection;
1482 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1484 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1485 if (accounts_dialog_get_settings_iter (dialog, settings, &iter))
1486 gtk_tree_selection_select_iter (selection, &iter);
1490 accounts_dialog_treeview_enabled_cb (GtkMenuItem *item,
1495 enabled = tp_account_is_enabled (account);
1496 tp_account_set_enabled_async (account, !enabled, NULL, NULL);
1500 accounts_dialog_treeview_button_press_event_cb (GtkTreeView *view,
1501 GdkEventButton *event,
1502 EmpathyAccountsDialog *dialog)
1504 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1505 TpAccount *account = NULL;
1506 GtkTreeModel *model = NULL;
1507 GtkTreePath *path = NULL;
1510 GtkWidget *item_enable, *item_disable;
1511 GtkWidget *image_enable, *image_disable;
1513 /* ignore multiple clicks */
1514 if (event->type != GDK_BUTTON_PRESS)
1517 if (event->button != 3)
1520 /* Selection is not yet set, so we have to get account from event position */
1521 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1522 if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->treeview),
1523 event->x, event->y, &path, NULL, NULL, NULL))
1526 if (!gtk_tree_model_get_iter (model, &iter, path))
1529 gtk_tree_model_get (model, &iter, COL_ACCOUNT, &account, -1);
1531 /* Create the menu */
1532 menu = gtk_menu_new ();
1534 /* Get images for menu items */
1535 image_enable = gtk_image_new_from_icon_name (empathy_icon_name_for_presence (
1536 tp_account_manager_get_most_available_presence (
1537 priv->account_manager, NULL, NULL)),
1538 GTK_ICON_SIZE_MENU);
1539 image_disable = gtk_image_new_from_icon_name (
1540 empathy_icon_name_for_presence (TP_CONNECTION_PRESENCE_TYPE_OFFLINE),
1541 GTK_ICON_SIZE_MENU);
1543 /* Menu items: to enabled/disable the account */
1544 item_enable = gtk_image_menu_item_new_with_mnemonic (_("_Enable"));
1545 item_disable = gtk_image_menu_item_new_with_mnemonic (_("_Disable"));
1546 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_enable),
1548 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item_disable),
1551 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_enable);
1552 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item_disable);
1554 if (tp_account_is_enabled (account))
1556 tp_g_signal_connect_object (item_disable, "activate",
1557 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1558 gtk_widget_set_sensitive (item_enable, FALSE);
1562 tp_g_signal_connect_object (item_enable, "activate",
1563 G_CALLBACK (accounts_dialog_treeview_enabled_cb), account, 0);
1564 gtk_widget_set_sensitive (item_disable, FALSE);
1567 gtk_widget_show (item_enable);
1568 gtk_widget_show (item_disable);
1570 /* FIXME: Add here presence items, to be able to set per-account presence */
1573 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1574 event->button, event->time);
1577 tp_clear_object (&account);
1578 gtk_tree_path_free (path);
1584 accounts_dialog_add (EmpathyAccountsDialog *dialog,
1585 EmpathyAccountSettings *settings)
1587 GtkTreeModel *model;
1590 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1592 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1593 name = empathy_account_settings_get_display_name (settings);
1595 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1597 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1599 COL_STATUS, TP_CONNECTION_STATUS_DISCONNECTED,
1600 COL_ACCOUNT_SETTINGS, settings,
1605 accounts_dialog_connection_changed_cb (TpAccount *account,
1609 gchar *dbus_error_name,
1610 GHashTable *details,
1611 EmpathyAccountsDialog *dialog)
1613 GtkTreeModel *model;
1616 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1618 /* Update the status-infobar in the details view */
1619 accounts_dialog_update_status_infobar (dialog, account);
1621 /* Update the status in the model */
1622 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1624 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1628 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1629 COL_STATUS, current,
1632 path = gtk_tree_model_get_path (model, &iter);
1633 gtk_tree_model_row_changed (model, path, &iter);
1634 gtk_tree_path_free (path);
1637 empathy_account_manager_get_accounts_connected (&found);
1639 if (!found && priv->connecting_id)
1641 g_source_remove (priv->connecting_id);
1642 priv->connecting_id = 0;
1645 if (found && !priv->connecting_id)
1646 priv->connecting_id = g_timeout_add (FLASH_TIMEOUT,
1647 (GSourceFunc) accounts_dialog_flash_connecting_cb,
1652 update_account_in_treeview (EmpathyAccountsDialog *self,
1655 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1657 GtkTreeModel *model;
1659 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1660 if (accounts_dialog_get_account_iter (self, account, &iter))
1664 path = gtk_tree_model_get_path (model, &iter);
1665 gtk_tree_model_row_changed (model, path, &iter);
1666 gtk_tree_path_free (path);
1671 accounts_dialog_presence_changed_cb (TpAccount *account,
1674 gchar *status_message,
1675 EmpathyAccountsDialog *dialog)
1677 /* Update the status-infobar in the details view */
1678 accounts_dialog_update_status_infobar (dialog, account);
1680 update_account_in_treeview (dialog, account);
1684 accounts_dialog_account_display_name_changed_cb (TpAccount *account,
1688 const gchar *display_name;
1690 GtkTreeModel *model;
1691 EmpathyAccountSettings *settings;
1692 TpAccount *selected_account;
1693 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1694 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1696 display_name = tp_account_get_display_name (account);
1697 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1698 settings = accounts_dialog_model_get_selected_settings (dialog);
1699 if (settings == NULL)
1702 selected_account = empathy_account_settings_get_account (settings);
1704 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1706 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1707 COL_NAME, display_name,
1711 if (selected_account == account)
1712 accounts_dialog_update_name_label (dialog, display_name);
1714 g_object_unref (settings);
1718 accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
1721 EmpathyAccountSettings *settings;
1722 GtkTreeModel *model;
1724 TpConnectionStatus status;
1727 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1729 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1730 status = tp_account_get_connection_status (account, NULL);
1731 name = tp_account_get_display_name (account);
1732 enabled = tp_account_is_enabled (account);
1734 settings = empathy_account_settings_new_for_account (account);
1736 if (!accounts_dialog_get_account_iter (dialog, account, &iter))
1737 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
1739 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
1742 COL_ACCOUNT, account,
1743 COL_ACCOUNT_SETTINGS, settings,
1746 accounts_dialog_connection_changed_cb (account,
1749 TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
1754 tp_g_signal_connect_object (account, "notify::display-name",
1755 G_CALLBACK (accounts_dialog_account_display_name_changed_cb),
1758 tp_g_signal_connect_object (account, "status-changed",
1759 G_CALLBACK (accounts_dialog_connection_changed_cb), dialog, 0);
1760 tp_g_signal_connect_object (account, "presence-changed",
1761 G_CALLBACK (accounts_dialog_presence_changed_cb), dialog, 0);
1763 g_object_unref (settings);
1767 account_prepare_cb (GObject *source_object,
1768 GAsyncResult *result,
1771 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data);
1772 TpAccount *account = TP_ACCOUNT (source_object);
1773 GError *error = NULL;
1775 if (!tp_account_prepare_finish (account, result, &error))
1777 DEBUG ("Failed to prepare account: %s", error->message);
1778 g_error_free (error);
1782 accounts_dialog_add_account (dialog, account);
1786 accounts_dialog_account_validity_changed_cb (TpAccountManager *manager,
1789 EmpathyAccountsDialog *dialog)
1791 tp_account_prepare_async (account, NULL, account_prepare_cb, dialog);
1795 accounts_dialog_accounts_model_row_inserted_cb (GtkTreeModel *model,
1798 EmpathyAccountsDialog *dialog)
1800 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1802 if (priv->setting_widget_object != NULL &&
1803 accounts_dialog_has_valid_accounts (dialog))
1805 empathy_account_widget_set_other_accounts_exist (
1806 priv->setting_widget_object, TRUE);
1811 accounts_dialog_accounts_model_row_deleted_cb (GtkTreeModel *model,
1813 EmpathyAccountsDialog *dialog)
1815 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1817 if (priv->setting_widget_object != NULL &&
1818 !accounts_dialog_has_valid_accounts (dialog))
1820 empathy_account_widget_set_other_accounts_exist (
1821 priv->setting_widget_object, FALSE);
1826 accounts_dialog_account_removed_cb (TpAccountManager *manager,
1828 EmpathyAccountsDialog *dialog)
1831 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1833 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1835 gtk_list_store_remove (GTK_LIST_STORE (
1836 gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview))), &iter);
1841 enable_or_disable_account (EmpathyAccountsDialog *dialog,
1845 GtkTreeModel *model;
1846 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1848 /* Update the status in the model */
1849 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
1851 /* Update the status-infobar in the details view */
1852 accounts_dialog_update_status_infobar (dialog, account);
1854 DEBUG ("Account %s is now %s",
1855 tp_account_get_display_name (account),
1856 enabled ? "enabled" : "disabled");
1860 accounts_dialog_account_disabled_cb (TpAccountManager *manager,
1862 EmpathyAccountsDialog *dialog)
1864 enable_or_disable_account (dialog, account, FALSE);
1865 update_account_in_treeview (dialog, account);
1869 accounts_dialog_account_enabled_cb (TpAccountManager *manager,
1871 EmpathyAccountsDialog *dialog)
1873 enable_or_disable_account (dialog, account, TRUE);
1877 accounts_dialog_button_import_clicked_cb (GtkWidget *button,
1878 EmpathyAccountsDialog *dialog)
1880 GtkWidget *import_dialog;
1882 import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
1884 gtk_widget_show (import_dialog);
1888 accounts_dialog_close_response_cb (GtkDialog *message_dialog,
1892 GtkWidget *account_dialog = GTK_WIDGET (user_data);
1894 gtk_widget_destroy (GTK_WIDGET (message_dialog));
1896 if (response_id == GTK_RESPONSE_YES)
1897 gtk_widget_destroy (account_dialog);
1901 accounts_dialog_delete_event_cb (GtkWidget *widget,
1903 EmpathyAccountsDialog *dialog)
1905 /* we maunally handle responses to delete events */
1910 accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
1913 GtkTreeSelection *selection;
1915 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1917 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1918 if (accounts_dialog_get_account_iter (dialog, account, &iter))
1919 gtk_tree_selection_select_iter (selection, &iter);
1923 finished_loading (EmpathyAccountsDialog *self)
1925 EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
1926 GtkTreeSelection *selection;
1927 gboolean has_selected;
1929 priv->loading = FALSE;
1931 gtk_widget_set_sensitive (priv->button_add, TRUE);
1932 gtk_widget_set_sensitive (priv->button_import, TRUE);
1933 gtk_widget_set_sensitive (priv->treeview, TRUE);
1935 /* Sensitive the remove button if there is an account selected */
1936 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
1937 has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
1938 gtk_widget_set_sensitive (priv->button_remove, has_selected);
1940 gtk_spinner_stop (GTK_SPINNER (priv->spinner));
1941 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
1942 NOTEBOOK_PAGE_ACCOUNT);
1946 accounts_dialog_cms_prepare_cb (GObject *source,
1947 GAsyncResult *result,
1950 EmpathyConnectionManagers *cms = EMPATHY_CONNECTION_MANAGERS (source);
1951 EmpathyAccountsDialog *dialog = user_data;
1952 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1954 if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
1957 accounts_dialog_update_settings (dialog, NULL);
1959 if (priv->initial_selection != NULL)
1961 accounts_dialog_set_selected_account (dialog, priv->initial_selection);
1962 g_object_unref (priv->initial_selection);
1963 priv->initial_selection = NULL;
1967 finished_loading (dialog);
1971 accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog)
1973 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
1974 GList *accounts, *l;
1976 g_signal_connect (priv->account_manager, "account-validity-changed",
1977 G_CALLBACK (accounts_dialog_account_validity_changed_cb),
1979 g_signal_connect (priv->account_manager, "account-removed",
1980 G_CALLBACK (accounts_dialog_account_removed_cb),
1982 g_signal_connect (priv->account_manager, "account-enabled",
1983 G_CALLBACK (accounts_dialog_account_enabled_cb),
1985 g_signal_connect (priv->account_manager, "account-disabled",
1986 G_CALLBACK (accounts_dialog_account_disabled_cb),
1989 /* Add existing accounts */
1990 accounts = tp_account_manager_get_valid_accounts (priv->account_manager);
1991 for (l = accounts; l; l = l->next)
1993 accounts_dialog_add_account (dialog, l->data);
1995 g_list_free (accounts);
1997 priv->cms = empathy_connection_managers_dup_singleton ();
1999 empathy_connection_managers_prepare_async (priv->cms,
2000 accounts_dialog_cms_prepare_cb, dialog);
2002 accounts_dialog_model_select_first (dialog);
2006 accounts_dialog_manager_ready_cb (GObject *source_object,
2007 GAsyncResult *result,
2010 TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
2011 GError *error = NULL;
2013 if (!tp_account_manager_prepare_finish (manager, result, &error))
2015 DEBUG ("Failed to prepare account manager: %s", error->message);
2016 g_error_free (error);
2020 accounts_dialog_accounts_setup (user_data);
2024 dialog_response_cb (GtkWidget *widget,
2028 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (widget);
2030 if (response_id == GTK_RESPONSE_HELP)
2032 empathy_url_show (widget, "ghelp:empathy?accounts-window");
2034 else if (response_id == GTK_RESPONSE_CLOSE ||
2035 response_id == GTK_RESPONSE_DELETE_EVENT)
2037 TpAccount *account = NULL;
2039 if (accounts_dialog_has_pending_change (dialog, &account))
2041 gchar *question_dialog_primary_text = get_dialog_primary_text (
2044 accounts_dialog_show_question_dialog (dialog,
2045 question_dialog_primary_text,
2046 _("You are about to close the window, which will discard\n"
2047 "your changes. Are you sure you want to proceed?"),
2048 G_CALLBACK (accounts_dialog_close_response_cb),
2050 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2051 GTK_STOCK_DISCARD, GTK_RESPONSE_YES, NULL);
2053 g_free (question_dialog_primary_text);
2057 gtk_widget_destroy (widget);
2060 if (account != NULL)
2061 g_object_unref (account);
2066 accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
2068 GtkWidget *top_hbox;
2071 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2072 GtkWidget *content_area;
2073 GtkWidget *action_area, *vbox, *hbox, *align;
2076 filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
2078 gui = empathy_builder_get_file (filename,
2079 "accounts_dialog_hbox", &top_hbox,
2080 "vbox_details", &priv->vbox_details,
2081 "frame_no_protocol", &priv->frame_no_protocol,
2082 "alignment_settings", &priv->alignment_settings,
2083 "alignment_infobar", &priv->alignment_infobar,
2084 "treeview", &priv->treeview,
2085 "button_add", &priv->button_add,
2086 "button_remove", &priv->button_remove,
2087 "button_import", &priv->button_import,
2088 "hbox_protocol", &priv->hbox_protocol,
2089 "notebook_account", &priv->notebook_account,
2090 "alignment_loading", &alig,
2094 gtk_widget_set_no_show_all (priv->frame_no_protocol, TRUE);
2096 empathy_builder_connect (gui, dialog,
2097 "button_add", "clicked", accounts_dialog_button_add_clicked_cb,
2098 "button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
2099 "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
2100 "treeview", "button-press-event",
2101 accounts_dialog_treeview_button_press_event_cb,
2104 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
2106 gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
2108 g_object_unref (gui);
2110 action_area = gtk_dialog_get_action_area (GTK_DIALOG (dialog));
2113 gtk_widget_hide (action_area);
2114 gtk_widget_hide (priv->button_remove);
2115 #endif /* HAVE_MEEGO */
2117 /* Display loading page */
2118 priv->loading = TRUE;
2120 priv->spinner = gtk_spinner_new ();
2122 gtk_spinner_start (GTK_SPINNER (priv->spinner));
2123 gtk_widget_show (priv->spinner);
2125 gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
2127 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
2128 NOTEBOOK_PAGE_LOADING);
2130 /* Remove button is insensitive until we have a selected account */
2131 gtk_widget_set_sensitive (priv->button_remove, FALSE);
2133 /* Add and Import buttons and treeview are insensitive while the dialog
2135 gtk_widget_set_sensitive (priv->button_add, FALSE);
2136 gtk_widget_set_sensitive (priv->button_import, FALSE);
2137 gtk_widget_set_sensitive (priv->treeview, FALSE);
2139 priv->combobox_protocol = empathy_protocol_chooser_new ();
2140 gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
2142 g_signal_connect (priv->combobox_protocol, "changed",
2143 G_CALLBACK (accounts_dialog_protocol_changed_cb),
2146 if (priv->parent_window)
2147 gtk_window_set_transient_for (GTK_WINDOW (dialog),
2148 priv->parent_window);
2150 priv->infobar = gtk_info_bar_new ();
2151 gtk_container_add (GTK_CONTAINER (priv->alignment_infobar),
2153 gtk_widget_show (priv->infobar);
2155 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (priv->infobar));
2157 priv->image_type = gtk_image_new_from_stock (GTK_STOCK_CUT,
2158 GTK_ICON_SIZE_DIALOG);
2159 gtk_misc_set_alignment (GTK_MISC (priv->image_type), 0.0, 0.5);
2160 gtk_box_pack_start (GTK_BOX (content_area), priv->image_type, FALSE, FALSE, 0);
2161 gtk_widget_show (priv->image_type);
2163 vbox = gtk_vbox_new (FALSE, 6);
2164 gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
2165 gtk_widget_show (vbox);
2168 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2169 gtk_widget_show (align);
2171 priv->label_name = gtk_label_new (NULL);
2172 gtk_container_add (GTK_CONTAINER (align), priv->label_name);
2173 gtk_widget_show (priv->label_name);
2175 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2178 align = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
2179 gtk_widget_show (align);
2180 hbox = gtk_hbox_new (FALSE, 6);
2181 gtk_widget_show (hbox);
2182 gtk_container_add (GTK_CONTAINER (align), hbox);
2184 gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0);
2186 /* set up spinner */
2187 priv->throbber = gtk_spinner_new ();
2189 priv->image_status = gtk_image_new_from_icon_name (
2190 empathy_icon_name_for_presence (
2191 TP_CONNECTION_PRESENCE_TYPE_OFFLINE), GTK_ICON_SIZE_SMALL_TOOLBAR);
2193 priv->label_status = gtk_label_new (NULL);
2194 gtk_label_set_line_wrap (GTK_LABEL (priv->label_status), TRUE);
2195 gtk_widget_show (priv->label_status);
2197 gtk_box_pack_start (GTK_BOX (hbox), priv->throbber, FALSE, FALSE, 0);
2198 gtk_box_pack_start (GTK_BOX (hbox), priv->image_status, FALSE, FALSE, 3);
2199 gtk_box_pack_start (GTK_BOX (hbox), priv->label_status, TRUE, TRUE, 0);
2201 /* Tweak the dialog */
2202 gtk_window_set_title (GTK_WINDOW (dialog), _("Messaging and VoIP Accounts"));
2203 gtk_window_set_role (GTK_WINDOW (dialog), "accounts");
2205 gtk_window_set_default_size (GTK_WINDOW (dialog), 640, 450);
2207 gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
2209 /* add dialog buttons */
2210 gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
2212 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2213 GTK_STOCK_HELP, GTK_RESPONSE_HELP,
2214 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2217 g_signal_connect (dialog, "response",
2218 G_CALLBACK (dialog_response_cb), dialog);
2220 g_signal_connect (dialog, "delete-event",
2221 G_CALLBACK (accounts_dialog_delete_event_cb), dialog);
2225 do_dispose (GObject *obj)
2227 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (obj);
2228 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2230 if (priv->connecting_id != 0)
2232 g_source_remove (priv->connecting_id);
2233 priv->connecting_id = 0;
2236 if (priv->account_manager != NULL)
2238 g_object_unref (priv->account_manager);
2239 priv->account_manager = NULL;
2242 if (priv->cms != NULL)
2244 g_object_unref (priv->cms);
2248 if (priv->connectivity)
2250 g_object_unref (priv->connectivity);
2251 priv->connectivity = NULL;
2254 if (priv->initial_selection != NULL)
2256 g_object_unref (priv->initial_selection);
2257 priv->initial_selection = NULL;
2260 G_OBJECT_CLASS (empathy_accounts_dialog_parent_class)->dispose (obj);
2264 do_get_property (GObject *object,
2269 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2271 switch (property_id)
2274 g_value_set_object (value, priv->parent_window);
2277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2282 do_set_property (GObject *object,
2284 const GValue *value,
2287 EmpathyAccountsDialogPriv *priv = GET_PRIV (object);
2289 switch (property_id)
2292 priv->parent_window = g_value_get_object (value);
2295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2300 do_constructed (GObject *object)
2302 EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
2303 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2304 GtkTreeModel *model;
2306 accounts_dialog_build_ui (dialog);
2307 accounts_dialog_model_setup (dialog);
2309 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview));
2310 g_signal_connect (model, "row-inserted",
2311 (GCallback) accounts_dialog_accounts_model_row_inserted_cb, dialog);
2312 g_signal_connect (model, "row-deleted",
2313 (GCallback) accounts_dialog_accounts_model_row_deleted_cb, dialog);
2315 /* Set up signalling */
2316 priv->account_manager = tp_account_manager_dup ();
2318 tp_account_manager_prepare_async (priv->account_manager, NULL,
2319 accounts_dialog_manager_ready_cb, dialog);
2321 priv->connectivity = empathy_connectivity_dup_singleton ();
2325 empathy_accounts_dialog_class_init (EmpathyAccountsDialogClass *klass)
2327 GObjectClass *oclass = G_OBJECT_CLASS (klass);
2328 GParamSpec *param_spec;
2330 oclass->dispose = do_dispose;
2331 oclass->constructed = do_constructed;
2332 oclass->set_property = do_set_property;
2333 oclass->get_property = do_get_property;
2335 param_spec = g_param_spec_object ("parent",
2336 "parent", "The parent window",
2338 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
2339 g_object_class_install_property (oclass, PROP_PARENT, param_spec);
2341 g_type_class_add_private (klass, sizeof (EmpathyAccountsDialogPriv));
2345 empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog)
2347 EmpathyAccountsDialogPriv *priv;
2349 priv = G_TYPE_INSTANCE_GET_PRIVATE ((dialog),
2350 EMPATHY_TYPE_ACCOUNTS_DIALOG,
2351 EmpathyAccountsDialogPriv);
2352 dialog->priv = priv;
2355 /* public methods */
2358 empathy_accounts_dialog_show (GtkWindow *parent,
2359 TpAccount *selected_account)
2361 EmpathyAccountsDialog *dialog;
2362 EmpathyAccountsDialogPriv *priv;
2364 dialog = g_object_new (EMPATHY_TYPE_ACCOUNTS_DIALOG,
2365 "parent", parent, NULL);
2367 priv = GET_PRIV (dialog);
2369 if (selected_account)
2371 if (priv->cms != NULL && empathy_connection_managers_is_ready (priv->cms))
2372 accounts_dialog_set_selected_account (dialog, selected_account);
2374 /* save the selection to set it later when the cms
2377 priv->initial_selection = g_object_ref (selected_account);
2380 gtk_window_present (GTK_WINDOW (dialog));
2382 return GTK_WIDGET (dialog);
2386 empathy_accounts_dialog_show_application (GdkScreen *screen,
2387 TpAccount *selected_account,
2391 GError *error = NULL;
2392 GdkDisplay *display;
2396 GdkAppLaunchContext *context = NULL;
2398 g_return_if_fail (GDK_IS_SCREEN (screen));
2399 g_return_if_fail (!selected_account || TP_IS_ACCOUNT (selected_account));
2401 /* Try to run from source directory if possible */
2402 path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
2403 "empathy-accounts", NULL);
2405 if (!g_file_test (path, G_FILE_TEST_EXISTS))
2408 path = g_build_filename (BIN_DIR, "empathy-accounts", NULL);
2411 cmd = g_string_new (path);
2414 if (selected_account != NULL)
2416 g_string_append_printf (cmd, " --select-account=%s",
2417 tp_account_get_path_suffix (selected_account));
2421 g_string_append_printf (cmd, " --if-needed");
2424 g_string_append_printf (cmd, " --hidden");
2426 DEBUG ("Launching empathy-accounts (if_needed: %d, hidden: %d, account: %s)",
2428 selected_account == NULL ? "<none selected>" :
2429 tp_proxy_get_object_path (TP_PROXY (selected_account)));
2431 app_info = g_app_info_create_from_commandline (cmd->str, NULL, 0, &error);
2432 if (app_info == NULL)
2434 DEBUG ("Failed to create app info: %s", error->message);
2435 g_error_free (error);
2439 display = gdk_screen_get_display (screen);
2440 context = gdk_display_get_app_launch_context (display);
2442 if (!g_app_info_launch (app_info, NULL, (GAppLaunchContext *) context,
2445 g_warning ("Failed to open accounts dialog: %s", error->message);
2446 g_error_free (error);
2450 tp_clear_object (&app_info);
2451 tp_clear_object (&context);
2452 g_string_free (cmd, TRUE);
2456 empathy_accounts_dialog_is_creating (EmpathyAccountsDialog *dialog)
2458 EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
2459 gboolean result = FALSE;
2461 if (priv->setting_widget_object == NULL)
2464 g_object_get (priv->setting_widget_object,
2465 "creating-account", &result, NULL);