#include <libmissioncontrol/mc-account.h>
#include <libmissioncontrol/mc-profile.h>
-#include <libmissioncontrol/mission-control.h>
-#include <libmissioncontrol/mc-account-monitor.h>
#include <telepathy-glib/util.h>
#include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-account-manager.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include <libempathy-gtk/empathy-profile-chooser.h>
#include <libempathy-gtk/empathy-account-widget.h>
#include <libempathy-gtk/empathy-account-widget-irc.h>
#include <libempathy-gtk/empathy-account-widget-sip.h>
+#include <libempathy-gtk/empathy-conf.h>
#include "empathy-accounts-dialog.h"
+#include "empathy-import-dialog.h"
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
#include <libempathy/empathy-debug.h>
GtkWidget *button_add;
GtkWidget *button_remove;
+ GtkWidget *button_import;
GtkWidget *frame_new_account;
GtkWidget *combobox_profile;
gboolean connecting_show;
guint connecting_id;
- gboolean account_changed;
- MissionControl *mc;
- McAccountMonitor *monitor;
- gpointer token;
+ EmpathyAccountManager *account_manager;
+ MissionControl *mc;
} EmpathyAccountsDialog;
enum {
static gboolean accounts_dialog_model_remove_selected (EmpathyAccountsDialog *dialog);
static void accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
EmpathyAccountsDialog *dialog);
-static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
+static void accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
McAccount *account);
-static void accounts_dialog_account_added_cb (McAccountMonitor *monitor,
- gchar *unique_name,
+static void accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountsDialog *dialog);
-static void accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
- gchar *unique_name,
+static void accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountsDialog *dialog);
static gboolean accounts_dialog_row_changed_foreach (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
gpointer user_data);
static gboolean accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog);
-static gboolean accounts_dialog_are_accounts_connecting (MissionControl *mc);
-static void accounts_dialog_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
+static void accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
TpConnectionStatusReason reason,
- const gchar *unique_name,
+ TpConnectionStatus current,
+ TpConnectionStatus previous,
EmpathyAccountsDialog *dialog);
static void accounts_dialog_button_create_clicked_cb (GtkWidget *button,
EmpathyAccountsDialog *dialog);
EmpathyAccountsDialog *dialog);
static void accounts_dialog_button_remove_clicked_cb (GtkWidget *button,
EmpathyAccountsDialog *dialog);
+static void accounts_dialog_button_import_clicked_cb (GtkWidget *button,
+ EmpathyAccountsDialog *dialog);
static void accounts_dialog_response_cb (GtkWidget *widget,
gint response,
EmpathyAccountsDialog *dialog);
static void accounts_dialog_destroy_cb (GtkWidget *widget,
EmpathyAccountsDialog *dialog);
+static void
+accounts_dialog_update_name_label (EmpathyAccountsDialog *dialog,
+ McAccount *account)
+{
+ gchar *text;
+
+ text = g_markup_printf_escaped ("<big><b>%s</b></big>",
+ mc_account_get_display_name (account));
+ gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
+
+ g_free (text);
+}
+
static void
accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
McAccount *account)
{
McProfile *profile;
const gchar *config_ui;
- gchar *text;
if (!account) {
GtkTreeView *view;
gtk_widget_set_tooltip_text (dialog->image_type,
mc_profile_get_display_name (profile));
- text = g_markup_printf_escaped ("<big><b>%s</b></big>",
- mc_account_get_display_name (account));
- gtk_label_set_markup (GTK_LABEL (dialog->label_name), text);
+ accounts_dialog_update_name_label (dialog, account);
- g_free (text);
g_object_unref (profile);
}
GtkTreePath *treepath;
GtkTreeIter iter;
- if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
+ if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
(GSourceFunc) accounts_dialog_flash_connecting_cb,
dialog);
}
static void
-accounts_dialog_add_account (EmpathyAccountsDialog *dialog,
- McAccount *account)
+accounts_dialog_add_or_update_account (EmpathyAccountsDialog *dialog,
+ McAccount *account)
{
GtkTreeModel *model;
GtkTreeIter iter;
const gchar *name;
gboolean enabled;
- if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
- return;
- }
-
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
status = mission_control_get_connection_status (dialog->mc, account, NULL);
name = mc_account_get_display_name (account);
enabled = mc_account_is_enabled (account);
- g_return_if_fail (name != NULL);
+ if (!accounts_dialog_get_account_iter (dialog, account, &iter)) {
+ DEBUG ("Adding new account");
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ }
- DEBUG ("Adding new account: %s", name);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ COL_ENABLED, enabled,
+ COL_NAME, name,
+ COL_STATUS, status,
+ COL_ACCOUNT_POINTER, account,
+ -1);
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
- gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter,
- -1,
- COL_ENABLED, enabled,
- COL_NAME, name,
- COL_STATUS, status,
- COL_ACCOUNT_POINTER, account,
- -1);
- accounts_dialog_status_changed_cb (dialog->mc,
- status,
- MC_PRESENCE_UNSET,
- TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
- mc_account_get_unique_name (account),
- dialog);
+ accounts_dialog_connection_changed_cb (dialog->account_manager,
+ account,
+ TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
+ status,
+ TP_CONNECTION_STATUS_DISCONNECTED,
+ dialog);
}
static void
-accounts_dialog_account_added_cb (McAccountMonitor *monitor,
- gchar *unique_name,
+accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountsDialog *dialog)
{
- McAccount *account;
-
- account = mc_account_lookup (unique_name);
- accounts_dialog_add_account (dialog, account);
- g_object_unref (account);
+ const gchar *current_name;
+ gchar *account_param = NULL;
+
+ accounts_dialog_add_or_update_account (dialog, account);
+
+ /* Change the display name to "%s (%s)" % (protocol, account).
+ * - The protocol is the display name of the profile.
+ * - The account should be the normalized name of the McAccount but
+ * it's not set until first connection, so we get the "account"
+ * parameter for CM that have it. */
+ current_name = mc_account_get_display_name (account);
+ mc_account_get_param_string (account, "account", &account_param);
+ if (!EMP_STR_EMPTY (account_param)) {
+ McProfile *profile;
+ const gchar *profile_name;
+ gchar *new_name;
+
+ profile = mc_account_get_profile (account);
+ profile_name = mc_profile_get_display_name (profile);
+ new_name = g_strdup_printf ("%s (%s)", profile_name,
+ account_param);
+
+ DEBUG ("Setting new display name for account %s: '%s'",
+ mc_account_get_unique_name (account), new_name);
+
+ mc_account_set_display_name (account, new_name);
+ g_free (new_name);
+ g_object_unref (profile);
+ } else {
+ /* FIXME: This CM has no account parameter, what can be done? */
+ }
+ g_free (account_param);
}
static void
-accounts_dialog_account_removed_cb (McAccountMonitor *monitor,
- gchar *unique_name,
+accounts_dialog_account_removed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
EmpathyAccountsDialog *dialog)
{
- McAccount *account;
-
- account = mc_account_lookup (unique_name);
accounts_dialog_model_set_selected (dialog, account);
accounts_dialog_model_remove_selected (dialog);
-
- g_object_unref (account);
}
static gboolean
return TRUE;
}
-static gboolean
-accounts_dialog_are_accounts_connecting (MissionControl *mc)
-{
- GList *accounts, *l;
- gboolean found = FALSE;
-
- /* Check if there is still accounts in CONNECTING state */
- accounts = mc_accounts_list_by_enabled (TRUE);
- for (l = accounts; l; l = l->next) {
- McAccount *this_account = l->data;
- TpConnectionStatus status;
-
- status = mission_control_get_connection_status (mc, this_account,
- NULL);
- if (status == TP_CONNECTION_STATUS_CONNECTING) {
- found = TRUE;
- break;
- }
- }
- mc_accounts_list_free (accounts);
-
- return found;
-}
-
static void
-accounts_dialog_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
- TpConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyAccountsDialog *dialog)
+accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
+ TpConnectionStatusReason reason,
+ TpConnectionStatus current,
+ TpConnectionStatus previous,
+ EmpathyAccountsDialog *dialog)
{
GtkTreeModel *model;
GtkTreeIter iter;
- McAccount *account;
- gboolean found = FALSE;
+ gboolean found;
/* Update the status in the model */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
- account = mc_account_lookup (unique_name);
-
- DEBUG ("Status changed for account %s: status=%d presence=%d",
- unique_name, status, presence);
if (accounts_dialog_get_account_iter (dialog, account, &iter)) {
GtkTreePath *path;
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- COL_STATUS, status,
+ COL_STATUS, current,
-1);
path = gtk_tree_model_get_path (model, &iter);
gtk_tree_model_row_changed (model, path, &iter);
gtk_tree_path_free (path);
}
- g_object_unref (account);
- found = accounts_dialog_are_accounts_connecting (mc);
+ found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
if (!found && dialog->connecting_id) {
g_source_remove (dialog->connecting_id);
dialog->connecting_id = 0;
}
+
if (found && !dialog->connecting_id) {
dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
(GSourceFunc) accounts_dialog_flash_connecting_cb,
}
static void
-accounts_dialog_account_enabled_cb (McAccountMonitor *monitor,
- gchar *unique_name,
- EmpathyAccountsDialog *dialog)
+enable_or_disable_account (EmpathyAccountsDialog *dialog,
+ McAccount *account,
+ gboolean enabled)
{
GtkTreeModel *model;
GtkTreeIter iter;
- McAccount *account;
- gboolean enabled;
/* Update the status in the model */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview));
- account = mc_account_lookup (unique_name);
- enabled = mc_account_is_enabled (account);
DEBUG ("Account %s is now %s",
mc_account_get_display_name (account),
COL_ENABLED, enabled,
-1);
}
+}
- g_object_unref (account);
+static void
+accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager,
+ McAccount *account,
+ EmpathyAccountsDialog *dialog)
+{
+ enable_or_disable_account (dialog, account, FALSE);
+}
+
+static void
+accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager,
+ McAccount *account,
+ EmpathyAccountsDialog *dialog)
+{
+ enable_or_disable_account (dialog, account, TRUE);
+}
+
+static void
+accounts_dialog_account_changed_cb (EmpathyAccountManager *manager,
+ McAccount *account,
+ EmpathyAccountsDialog *dialog)
+{
+ McAccount *selected_account;
+
+ accounts_dialog_add_or_update_account (dialog, account);
+ selected_account = accounts_dialog_model_get_selected (dialog);
+ if (empathy_account_equal (account, selected_account)) {
+ accounts_dialog_update_name_label (dialog, account);
+ }
}
static void
accounts_dialog_button_create_clicked_cb (GtkWidget *button,
EmpathyAccountsDialog *dialog)
{
- McProfile *profile;
- McAccount *account;
- const gchar *str;
+ McProfile *profile;
+ McAccount *account;
+ gchar *str;
McProfileCapabilityFlags cap;
profile = empathy_profile_chooser_get_selected (dialog->combobox_profile);
/* Create account */
account = mc_account_create (profile);
- str = mc_account_get_unique_name (account);
+ if (account == NULL) {
+ /* We can't display an error to the user as MC doesn't give us
+ * any clue about the reason of the failure... */
+ return;
+ }
+
+ /* To translator: %s is the protocol name */
+ str = g_strdup_printf (_("New %s account"),
+ mc_profile_get_display_name (profile));
mc_account_set_display_name (account, str);
+ g_free (str);
cap = mc_profile_get_capabilities (profile);
if (cap & MC_PROFILE_CAPABILITY_REGISTRATION_UI) {
}
}
- accounts_dialog_add_account (dialog, account);
+ accounts_dialog_add_or_update_account (dialog, account);
accounts_dialog_model_set_selected (dialog, account);
g_object_unref (account);
accounts_dialog_button_help_clicked_cb (GtkWidget *button,
EmpathyAccountsDialog *dialog)
{
- empathy_url_show ("ghelp:empathy?empathy-create-account");
+ empathy_url_show (button, "ghelp:empathy?empathy-create-account");
}
static void
gtk_widget_destroy (message_dialog);
}
+static void
+accounts_dialog_button_import_clicked_cb (GtkWidget *button,
+ EmpathyAccountsDialog *dialog)
+{
+ empathy_import_dialog_show (GTK_WINDOW (dialog->window), TRUE);
+}
+
static void
accounts_dialog_response_cb (GtkWidget *widget,
gint response,
GList *accounts, *l;
/* Disconnect signals */
- g_signal_handlers_disconnect_by_func (dialog->monitor,
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
accounts_dialog_account_added_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->monitor,
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
accounts_dialog_account_removed_cb,
dialog);
- g_signal_handlers_disconnect_by_func (dialog->monitor,
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
accounts_dialog_account_enabled_cb,
dialog);
- empathy_disconnect_account_status_changed (dialog->token);
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ accounts_dialog_account_disabled_cb,
+ dialog);
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ accounts_dialog_account_changed_cb,
+ dialog);
+ g_signal_handlers_disconnect_by_func (dialog->account_manager,
+ accounts_dialog_connection_changed_cb,
+ dialog);
/* Delete incomplete accounts */
accounts = mc_accounts_list ();
g_source_remove (dialog->connecting_id);
}
+ g_object_unref (dialog->account_manager);
g_object_unref (dialog->mc);
- g_object_unref (dialog->monitor);
g_free (dialog);
}
GladeXML *glade;
gchar *filename;
GList *accounts, *l;
+ gboolean import_asked;
if (dialog) {
gtk_window_present (GTK_WINDOW (dialog->window));
"label_name", &dialog->label_name,
"button_add", &dialog->button_add,
"button_remove", &dialog->button_remove,
+ "button_import", &dialog->button_import,
NULL);
g_free (filename);
"button_back", "clicked", accounts_dialog_button_back_clicked_cb,
"button_add", "clicked", accounts_dialog_button_add_clicked_cb,
"button_remove", "clicked", accounts_dialog_button_remove_clicked_cb,
+ "button_import", "clicked", accounts_dialog_button_import_clicked_cb,
"button_help", "clicked", accounts_dialog_button_help_clicked_cb,
NULL);
dialog);
/* Set up signalling */
- dialog->mc = empathy_mission_control_new ();
- dialog->monitor = mc_account_monitor_new ();
+ dialog->account_manager = empathy_account_manager_dup_singleton ();
+ dialog->mc = empathy_mission_control_dup_singleton ();
- g_signal_connect (dialog->monitor, "account-created",
+ g_signal_connect (dialog->account_manager, "account-created",
G_CALLBACK (accounts_dialog_account_added_cb),
dialog);
- g_signal_connect (dialog->monitor, "account-deleted",
+ g_signal_connect (dialog->account_manager, "account-deleted",
G_CALLBACK (accounts_dialog_account_removed_cb),
dialog);
- g_signal_connect (dialog->monitor, "account-enabled",
+ g_signal_connect (dialog->account_manager, "account-enabled",
G_CALLBACK (accounts_dialog_account_enabled_cb),
dialog);
- g_signal_connect (dialog->monitor, "account-disabled",
- G_CALLBACK (accounts_dialog_account_enabled_cb),
+ g_signal_connect (dialog->account_manager, "account-disabled",
+ G_CALLBACK (accounts_dialog_account_disabled_cb),
+ dialog);
+ g_signal_connect (dialog->account_manager, "account-changed",
+ G_CALLBACK (accounts_dialog_account_changed_cb),
+ dialog);
+ g_signal_connect (dialog->account_manager, "account-connection-changed",
+ G_CALLBACK (accounts_dialog_connection_changed_cb),
dialog);
- dialog->token = empathy_connect_to_account_status_changed (dialog->mc,
- G_CALLBACK (accounts_dialog_status_changed_cb),
- dialog, NULL);
accounts_dialog_model_setup (dialog);
/* Add existing accounts */
accounts = mc_accounts_list ();
for (l = accounts; l; l = l->next) {
- accounts_dialog_add_account (dialog, l->data);
+ accounts_dialog_add_or_update_account (dialog, l->data);
g_object_unref (l->data);
}
g_list_free (accounts);
gtk_widget_show (dialog->window);
+ empathy_conf_get_bool (empathy_conf_get (),
+ EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
+
+ if (!import_asked) {
+ empathy_conf_set_bool (empathy_conf_get (),
+ EMPATHY_PREFS_IMPORT_ASKED, TRUE);
+ empathy_import_dialog_show (GTK_WINDOW (dialog->window),
+ FALSE);
+ }
+
return dialog->window;
}