diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-account-assistant.c | 6 | ||||
-rw-r--r-- | src/empathy-accounts-dialog.c | 218 | ||||
-rw-r--r-- | src/empathy-accounts-dialog.h | 4 | ||||
-rw-r--r-- | src/empathy-chat-window.c | 27 | ||||
-rw-r--r-- | src/empathy-chat-window.h | 5 | ||||
-rw-r--r-- | src/empathy-chatrooms-window.c | 4 | ||||
-rw-r--r-- | src/empathy-event-manager.c | 15 | ||||
-rw-r--r-- | src/empathy-import-mc4-accounts.c | 10 | ||||
-rw-r--r-- | src/empathy-import-widget.c | 62 | ||||
-rw-r--r-- | src/empathy-main-window.c | 138 | ||||
-rw-r--r-- | src/empathy-new-chatroom-dialog.c | 6 | ||||
-rw-r--r-- | src/empathy-status-icon.c | 60 | ||||
-rw-r--r-- | src/empathy.c | 223 |
13 files changed, 408 insertions, 370 deletions
diff --git a/src/empathy-account-assistant.c b/src/empathy-account-assistant.c index d9834f38b..08cf025d3 100644 --- a/src/empathy-account-assistant.c +++ b/src/empathy-account-assistant.c @@ -225,7 +225,7 @@ account_assistant_account_enabled_cb (GObject *source, EmpathyAccountAssistant *self = user_data; EmpathyAccountAssistantPriv *priv = GET_PRIV (self); - empathy_account_set_enabled_finish (EMPATHY_ACCOUNT (source), + tp_account_set_enabled_finish (TP_ACCOUNT (source), result, &error); if (error) @@ -249,7 +249,7 @@ account_assistant_apply_account_cb (GObject *source, EmpathyAccountAssistant *self = user_data; EmpathyAccountAssistantPriv *priv = GET_PRIV (self); EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); - EmpathyAccount *account; + TpAccount *account; empathy_account_settings_apply_finish (settings, result, &error); @@ -265,7 +265,7 @@ account_assistant_apply_account_cb (GObject *source, /* enable the newly created account */ account = empathy_account_settings_get_account (settings); - empathy_account_set_enabled_async (account, TRUE, + tp_account_set_enabled_async (account, TRUE, account_assistant_account_enabled_cb, self); } diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index e877e632f..460ea9023 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -32,10 +32,10 @@ #include <glib/gi18n.h> #include <dbus/dbus-glib.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-connection-managers.h> #include <libempathy-gtk/empathy-ui-utils.h> @@ -107,11 +107,11 @@ typedef struct { gulong settings_ready_id; EmpathyAccountSettings *settings_ready; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; EmpathyConnectionManagers *cms; GtkWindow *parent_window; - EmpathyAccount *initial_selection; + TpAccount *initial_selection; /* Those are needed when changing the selected row. When a user selects * another account and there are unsaved changes on the currently selected @@ -146,9 +146,6 @@ static gboolean accounts_dialog_get_settings_iter ( static void accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog); -static void accounts_dialog_update (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings); - static void accounts_dialog_update_settings (EmpathyAccountsDialog *dialog, EmpathyAccountSettings *settings); @@ -175,7 +172,7 @@ empathy_account_dialog_widget_cancelled_cb ( GtkTreeSelection *selection; GtkTreeIter iter; EmpathyAccountSettings *settings; - EmpathyAccount *account; + TpAccount *account; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); view = GTK_TREE_VIEW (priv->treeview); @@ -354,7 +351,7 @@ accounts_dialog_model_select_first (EmpathyAccountsDialog *dialog) static gboolean accounts_dialog_has_pending_change (EmpathyAccountsDialog *dialog, - EmpathyAccount **account) + TpAccount **account) { GtkTreeIter iter; GtkTreeModel *model; @@ -502,13 +499,13 @@ static void accounts_dialog_button_add_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account = NULL; + TpAccount *account = NULL; if (accounts_dialog_has_pending_change (dialog, &account)) { gchar *question_dialog_primary_text = g_strdup_printf ( PENDING_CHANGES_QUESTION_PRIMARY_TEXT, - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text, @@ -708,9 +705,11 @@ accounts_dialog_name_edited_cb (GtkCellRendererText *renderer, GtkTreePath *treepath; GtkTreeIter iter; EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + gboolean connecting; - if (empathy_account_manager_get_connecting_accounts - (priv->account_manager) > 0) + empathy_account_manager_get_accounts_connected (&connecting); + + if (connecting) { priv->connecting_id = g_timeout_add (FLASH_TIMEOUT, (GSourceFunc) accounts_dialog_flash_connecting_cb, @@ -739,7 +738,7 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog, gint response_id, gpointer user_data) { - EmpathyAccount *account; + TpAccount *account; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; @@ -757,7 +756,7 @@ accounts_dialog_delete_account_response_cb (GtkDialog *message_dialog, if (account != NULL) { - empathy_account_remove_async (account, NULL, NULL); + tp_account_remove_async (account, NULL, NULL); g_object_unref (account); account = NULL; } @@ -774,7 +773,7 @@ accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell, const gchar *path_string, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account; + TpAccount *account; GtkTreeModel *model; GtkTreeIter iter; gchar *question_dialog_primary_text; @@ -787,7 +786,7 @@ accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell, gtk_tree_model_get (model, &iter, COL_ACCOUNT_POINTER, &account, -1); - if (account == NULL || !empathy_account_is_valid (account)) + if (account == NULL || !tp_account_is_valid (account)) { gtk_list_store_remove (GTK_LIST_STORE (model), &iter); accounts_dialog_model_select_first (dialog); @@ -802,7 +801,7 @@ accounts_dialog_view_delete_activated_cb (EmpathyCellRendererActivatable *cell, /* Translators: this is used only when built on a moblin platform */ _("Do you want to remove %s from your computer?"), #endif /* HAVE_MOBLIN */ - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text, #ifndef HAVE_MOBLIN @@ -977,7 +976,7 @@ accounts_dialog_account_selection_change (GtkTreeSelection *selection, gboolean path_currently_selected, gpointer data) { - EmpathyAccount *account = NULL; + TpAccount *account = NULL; EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (data); EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); @@ -1000,7 +999,7 @@ accounts_dialog_account_selection_change (GtkTreeSelection *selection, question_dialog_primary_text = g_strdup_printf ( PENDING_CHANGES_QUESTION_PRIMARY_TEXT, - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text, @@ -1031,7 +1030,7 @@ accounts_dialog_model_setup (EmpathyAccountsDialog *dialog) store = gtk_list_store_new (COL_COUNT, G_TYPE_STRING, /* name */ G_TYPE_UINT, /* status */ - EMPATHY_TYPE_ACCOUNT, /* account */ + TP_TYPE_ACCOUNT, /* account */ EMPATHY_TYPE_ACCOUNT_SETTINGS); /* settings */ gtk_tree_view_set_model (GTK_TREE_VIEW (priv->treeview), @@ -1093,7 +1092,7 @@ accounts_dialog_get_settings_iter (EmpathyAccountsDialog *dialog, static gboolean accounts_dialog_get_account_iter (EmpathyAccountsDialog *dialog, - EmpathyAccount *account, + TpAccount *account, GtkTreeIter *iter) { GtkTreeView *view; @@ -1162,11 +1161,12 @@ accounts_dialog_add (EmpathyAccountsDialog *dialog, } static void -accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus current, - TpConnectionStatus previous, +accounts_dialog_connection_changed_cb (TpAccount *account, + guint old_status, + guint current, + guint reason, + gchar *dbus_error_name, + GHashTable *details, EmpathyAccountsDialog *dialog) { GtkTreeModel *model; @@ -1190,7 +1190,7 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, gtk_tree_path_free (path); } - found = (empathy_account_manager_get_connecting_accounts (manager) > 0); + empathy_account_manager_get_accounts_connected (&found); if (!found && priv->connecting_id) { @@ -1205,7 +1205,7 @@ accounts_dialog_connection_changed_cb (EmpathyAccountManager *manager, } static void -accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account, +accounts_dialog_account_display_name_changed_cb (TpAccount *account, GParamSpec *pspec, gpointer user_data) { @@ -1213,11 +1213,11 @@ accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account, GtkTreeIter iter; GtkTreeModel *model; EmpathyAccountSettings *settings; - EmpathyAccount *selected_account; + TpAccount *selected_account; EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (user_data); EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - display_name = empathy_account_get_display_name (account); + display_name = tp_account_get_display_name (account); model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); settings = accounts_dialog_model_get_selected_settings (dialog); if (settings == NULL) @@ -1240,7 +1240,7 @@ accounts_dialog_account_display_name_changed_cb (EmpathyAccount *account, static void accounts_dialog_add_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + TpAccount *account) { EmpathyAccountSettings *settings; GtkTreeModel *model; @@ -1251,9 +1251,9 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - g_object_get (account, "connection-status", &status, NULL); - name = empathy_account_get_display_name (account); - enabled = empathy_account_is_enabled (account); + status = tp_account_get_connection_status (account, NULL); + name = tp_account_get_display_name (account); + enabled = tp_account_is_enabled (account); settings = empathy_account_settings_new_for_account (account); @@ -1267,11 +1267,12 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, COL_ACCOUNT_SETTINGS_POINTER, settings, -1); - accounts_dialog_connection_changed_cb (priv->account_manager, - account, - TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED, + accounts_dialog_connection_changed_cb (account, + 0, status, TP_CONNECTION_STATUS_DISCONNECTED, + NULL, + NULL, dialog); empathy_signal_connect_weak (account, "notify::display-name", @@ -1282,48 +1283,16 @@ accounts_dialog_add_account (EmpathyAccountsDialog *dialog, } static void -accounts_dialog_update (EmpathyAccountsDialog *dialog, - EmpathyAccountSettings *settings) -{ - GtkTreeModel *model; - GtkTreeIter iter; - TpConnectionStatus status = TP_CONNECTION_STATUS_DISCONNECTED; - const gchar *name; - gboolean enabled = FALSE; - EmpathyAccount *account; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - name = empathy_account_settings_get_display_name (settings); - - account = empathy_account_settings_get_account (settings); - if (account != NULL) - { - enabled = empathy_account_is_enabled (account); - g_object_get (account, "connection-status", &status, NULL); - } - - accounts_dialog_get_settings_iter (dialog, settings, &iter); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, - COL_NAME, name, - COL_STATUS, status, - COL_ACCOUNT_POINTER, account, - COL_ACCOUNT_SETTINGS_POINTER, settings, - -1); -} - -static void -accounts_dialog_account_added_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +accounts_dialog_account_validity_changed_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountsDialog *dialog) { accounts_dialog_add_account (dialog, account); } - static void -accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +accounts_dialog_account_removed_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountsDialog *dialog) { GtkTreeIter iter; @@ -1338,7 +1307,7 @@ accounts_dialog_account_removed_cb (EmpathyAccountManager *manager, static void enable_or_disable_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account, + TpAccount *account, gboolean enabled) { GtkTreeModel *model; @@ -1348,60 +1317,27 @@ enable_or_disable_account (EmpathyAccountsDialog *dialog, model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); DEBUG ("Account %s is now %s", - empathy_account_get_display_name (account), + tp_account_get_display_name (account), enabled ? "enabled" : "disabled"); } static void -accounts_dialog_account_disabled_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +accounts_dialog_account_disabled_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountsDialog *dialog) { enable_or_disable_account (dialog, account, FALSE); } static void -accounts_dialog_account_enabled_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, +accounts_dialog_account_enabled_cb (TpAccountManager *manager, + TpAccount *account, EmpathyAccountsDialog *dialog) { enable_or_disable_account (dialog, account, TRUE); } static void -accounts_dialog_account_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyAccountsDialog *dialog) -{ - EmpathyAccountSettings *settings, *selected_settings; - GtkTreeModel *model; - GtkTreeIter iter; - EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); - - if (!accounts_dialog_get_account_iter (dialog, account, &iter)) - return; - - gtk_tree_model_get (model, &iter, - COL_ACCOUNT_SETTINGS_POINTER, &settings, - -1); - - accounts_dialog_update (dialog, settings); - selected_settings = accounts_dialog_model_get_selected_settings (dialog); - - if (settings == selected_settings) - accounts_dialog_update_name_label (dialog, - empathy_account_settings_get_display_name (settings)); - - if (settings) - g_object_unref (settings); - - if (selected_settings) - g_object_unref (selected_settings); -} - -static void accounts_dialog_button_create_clicked_cb (GtkWidget *button, EmpathyAccountsDialog *dialog) { @@ -1504,14 +1440,14 @@ accounts_dialog_response_cb (GtkWidget *widget, gint response, EmpathyAccountsDialog *dialog) { - EmpathyAccount *account = NULL; + TpAccount *account = NULL; if (accounts_dialog_has_pending_change (dialog, &account)) { gchar *question_dialog_primary_text; question_dialog_primary_text = g_strdup_printf ( PENDING_CHANGES_QUESTION_PRIMARY_TEXT, - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); accounts_dialog_show_question_dialog (dialog, question_dialog_primary_text, @@ -1549,7 +1485,7 @@ accounts_dialog_destroy_cb (GtkObject *obj, static void accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog, - EmpathyAccount *account) + TpAccount *account) { GtkTreeSelection *selection; GtkTreeIter iter; @@ -1587,10 +1523,10 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog) EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); GList *accounts, *l; - g_signal_connect (priv->account_manager, "account-created", - G_CALLBACK (accounts_dialog_account_added_cb), + g_signal_connect (priv->account_manager, "account-validity-changed", + G_CALLBACK (accounts_dialog_account_validity_changed_cb), dialog); - g_signal_connect (priv->account_manager, "account-deleted", + g_signal_connect (priv->account_manager, "account-removed", G_CALLBACK (accounts_dialog_account_removed_cb), dialog); g_signal_connect (priv->account_manager, "account-enabled", @@ -1599,19 +1535,15 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog) g_signal_connect (priv->account_manager, "account-disabled", G_CALLBACK (accounts_dialog_account_disabled_cb), dialog); - g_signal_connect (priv->account_manager, "account-changed", - G_CALLBACK (accounts_dialog_account_changed_cb), - dialog); - g_signal_connect (priv->account_manager, "account-connection-changed", - G_CALLBACK (accounts_dialog_connection_changed_cb), - dialog); /* Add existing accounts */ - accounts = empathy_account_manager_dup_accounts (priv->account_manager); + accounts = tp_account_manager_get_valid_accounts (priv->account_manager); for (l = accounts; l; l = l->next) { accounts_dialog_add_account (dialog, l->data); - g_object_unref (l->data); + + empathy_signal_connect_weak (l->data, "status-changed", + G_CALLBACK (accounts_dialog_connection_changed_cb), G_OBJECT (dialog)); } g_list_free (accounts); @@ -1624,12 +1556,19 @@ accounts_dialog_accounts_setup (EmpathyAccountsDialog *dialog) } static void -accounts_dialog_manager_ready_cb (EmpathyAccountManager *manager, - GParamSpec *pspec, +accounts_dialog_manager_ready_cb (GObject *source_object, + GAsyncResult *result, gpointer user_data) { - if (!empathy_account_manager_is_ready (manager)) - return; + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } accounts_dialog_accounts_setup (user_data); } @@ -1709,7 +1648,7 @@ do_dispose (GObject *obj) /* Disconnect signals */ g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_added_cb, + accounts_dialog_account_validity_changed_cb, dialog); g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_account_removed_cb, @@ -1721,12 +1660,6 @@ do_dispose (GObject *obj) accounts_dialog_account_disabled_cb, dialog); g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_account_changed_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, - accounts_dialog_connection_changed_cb, - dialog); - g_signal_handlers_disconnect_by_func (priv->account_manager, accounts_dialog_manager_ready_cb, dialog); @@ -1827,13 +1760,10 @@ do_constructed (GObject *object) accounts_dialog_model_setup (dialog); /* Set up signalling */ - priv->account_manager = empathy_account_manager_dup_singleton (); + priv->account_manager = tp_account_manager_dup (); - if (!empathy_account_manager_is_ready (priv->account_manager)) - g_signal_connect (priv->account_manager, "notify::ready", - G_CALLBACK (accounts_dialog_manager_ready_cb), dialog); - else - accounts_dialog_accounts_setup (dialog); + tp_account_manager_prepare_async (priv->account_manager, NULL, + accounts_dialog_manager_ready_cb, dialog); empathy_conf_get_bool (empathy_conf_get (), EMPATHY_PREFS_IMPORT_ASKED, &import_asked); @@ -1891,7 +1821,7 @@ empathy_accounts_dialog_init (EmpathyAccountsDialog *dialog) GtkWidget * empathy_accounts_dialog_show (GtkWindow *parent, - EmpathyAccount *selected_account) + TpAccount *selected_account) { EmpathyAccountsDialog *dialog; EmpathyAccountsDialogPriv *priv; diff --git a/src/empathy-accounts-dialog.h b/src/empathy-accounts-dialog.h index aa8f7c06b..2d9d60c2b 100644 --- a/src/empathy-accounts-dialog.h +++ b/src/empathy-accounts-dialog.h @@ -26,7 +26,7 @@ #include <gtk/gtk.h> -#include <libempathy/empathy-account.h> +#include <telepathy-glib/account.h> G_BEGIN_DECLS @@ -55,7 +55,7 @@ typedef struct { GType empathy_accounts_dialog_get_type (void); GtkWidget *empathy_accounts_dialog_show (GtkWindow *parent, - EmpathyAccount *selected_account); + TpAccount *selected_account); G_END_DECLS diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 7b81d7a43..69469815e 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -35,13 +35,13 @@ #include <glib/gi18n.h> #include <libnotify/notification.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-contact.h> #include <libempathy/empathy-message.h> #include <libempathy/empathy-dispatcher.h> #include <libempathy/empathy-chatroom-manager.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-utils.h> #include <libempathy-gtk/empathy-images.h> @@ -434,7 +434,7 @@ chat_window_update_chat_tab (EmpathyChat *chat) EmpathyContact *remote_contact; const gchar *name; const gchar *id; - EmpathyAccount *account; + TpAccount *account; const gchar *subject; const gchar *status = NULL; GtkWidget *widget; @@ -457,7 +457,7 @@ chat_window_update_chat_tab (EmpathyChat *chat) remote_contact = empathy_chat_get_remote_contact (chat); DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p", - name, empathy_account_get_unique_name (account), subject, remote_contact); + name, tp_proxy_get_object_path (account), subject, remote_contact); /* Update tab image */ if (empathy_chat_get_tp_chat (chat) == NULL) { @@ -501,7 +501,7 @@ chat_window_update_chat_tab (EmpathyChat *chat) append_markup_printf (tooltip, "<b>%s</b><small> (%s)</small>", id, - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); if (!EMP_STR_EMPTY (status)) { append_markup_printf (tooltip, "\n<i>%s</i>", status); @@ -596,7 +596,7 @@ chat_window_conv_activate_cb (GtkAction *action, is_room = empathy_chat_is_room (priv->current_chat); if (is_room) { const gchar *room; - EmpathyAccount *account; + TpAccount *account; gboolean found = FALSE; EmpathyChatroom *chatroom; @@ -645,7 +645,7 @@ chat_window_favorite_toggled_cb (GtkToggleAction *toggle_action, { EmpathyChatWindowPriv *priv = GET_PRIV (window); gboolean active; - EmpathyAccount *account; + TpAccount *account; const gchar *room; EmpathyChatroom *chatroom; @@ -1346,15 +1346,18 @@ chat_window_drag_data_received (GtkWidget *widget, if (info == DND_DRAG_TYPE_CONTACT_ID) { EmpathyChat *chat = NULL; EmpathyChatWindow *old_window; - EmpathyAccount *account = NULL; - EmpathyAccountManager *account_manager; + TpAccount *account = NULL; + TpAccountManager *account_manager; const gchar *id; gchar **strv; const gchar *account_id; const gchar *contact_id; id = (const gchar*) gtk_selection_data_get_data (selection); - account_manager = empathy_account_manager_dup_singleton (); + + /* FIXME: Perhaps should be sure that the account manager is + * prepared before calling _ensure_account on it. */ + account_manager = tp_account_manager_dup (); DEBUG ("DND contact from roster with id:'%s'", id); @@ -1363,7 +1366,7 @@ chat_window_drag_data_received (GtkWidget *widget, account_id = strv[0]; contact_id = strv[1]; account = - empathy_account_manager_get_account (account_manager, account_id); + tp_account_manager_ensure_account (account_manager, account_id); if (account != NULL) chat = empathy_chat_window_find_chat (account, contact_id); } @@ -1377,7 +1380,7 @@ chat_window_drag_data_received (GtkWidget *widget, if (!chat) { TpConnection *connection; - connection = empathy_account_get_connection (account); + connection = tp_account_get_connection (account); if (connection) { empathy_dispatcher_chat_with_contact_id ( @@ -1855,7 +1858,7 @@ empathy_chat_window_has_focus (EmpathyChatWindow *window) } EmpathyChat * -empathy_chat_window_find_chat (EmpathyAccount *account, +empathy_chat_window_find_chat (TpAccount *account, const gchar *id) { GList *l; diff --git a/src/empathy-chat-window.h b/src/empathy-chat-window.h index 6f3d21fca..1e4a001e5 100644 --- a/src/empathy-chat-window.h +++ b/src/empathy-chat-window.h @@ -31,7 +31,8 @@ #include <glib-object.h> #include <gtk/gtk.h> -#include <libempathy/empathy-account.h> +#include <telepathy-glib/account.h> + #include <libempathy-gtk/empathy-chat.h> G_BEGIN_DECLS @@ -69,7 +70,7 @@ void empathy_chat_window_move_chat (EmpathyChatWindow *old_wi void empathy_chat_window_switch_to_chat (EmpathyChatWindow *window, EmpathyChat *chat); gboolean empathy_chat_window_has_focus (EmpathyChatWindow *window); -EmpathyChat * empathy_chat_window_find_chat (EmpathyAccount *account, +EmpathyChat * empathy_chat_window_find_chat (TpAccount *account, const gchar *id); void empathy_chat_window_present_chat (EmpathyChat *chat); diff --git a/src/empathy-chatrooms-window.c b/src/empathy-chatrooms-window.c index 4ec71ec49..278a1d686 100644 --- a/src/empathy-chatrooms-window.c +++ b/src/empathy-chatrooms-window.c @@ -308,7 +308,7 @@ chatrooms_window_model_refresh_data (EmpathyChatroomsWindow *window, GtkTreeIter iter; GtkTreeViewColumn *column; EmpathyAccountChooser *account_chooser; - EmpathyAccount *account; + TpAccount *account; GList *chatrooms, *l; view = GTK_TREE_VIEW (window->treeview); @@ -506,7 +506,7 @@ chatrooms_window_chatroom_added_cb (EmpathyChatroomManager *manager, EmpathyChatroomsWindow *window) { EmpathyAccountChooser *account_chooser; - EmpathyAccount *account; + TpAccount *account; account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser); account = empathy_account_chooser_dup_account (account_chooser); diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index c68458d69..f3eb2992d 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -24,11 +24,12 @@ #include <string.h> #include <glib/gi18n.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <telepathy-glib/interfaces.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-dispatcher.h> +#include <libempathy/empathy-idle.h> #include <libempathy/empathy-tp-contact-factory.h> #include <libempathy/empathy-contact-manager.h> #include <libempathy/empathy-tp-chat.h> @@ -918,13 +919,16 @@ event_manager_presence_changed_cb (EmpathyContactMonitor *monitor, TpConnectionPresenceType previous, EmpathyEventManager *manager) { - EmpathyAccount *account; + TpAccount *account; gchar *header = NULL; gboolean preference = FALSE; + EmpathyIdle *idle; account = empathy_contact_get_account (contact); - if (empathy_account_is_just_connected (account)) - return; + idle = empathy_idle_dup_singleton (); + + if (empathy_idle_account_is_just_connected (idle, account)) + goto out; if (tp_connection_presence_type_cmp_availability (previous, TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) @@ -960,6 +964,9 @@ event_manager_presence_changed_cb (EmpathyContactMonitor *monitor, } } g_free (header); + +out: + g_object_unref (idle); } diff --git a/src/empathy-import-mc4-accounts.c b/src/empathy-import-mc4-accounts.c index 0a72c4929..b4bca6fdb 100644 --- a/src/empathy-import-mc4-accounts.c +++ b/src/empathy-import-mc4-accounts.c @@ -24,11 +24,11 @@ #include <glib.h> #include <glib/gi18n.h> #include <gconf/gconf-client.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <telepathy-glib/defs.h> #include <dbus/dbus-protocol.h> #include <gnome-keyring.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-account-settings.h> #include <libempathy/empathy-connection-managers.h> @@ -189,12 +189,12 @@ _move_contents (const gchar *old, const gchar *new) } static void -_move_logs (EmpathyAccount *account, const gchar *account_name) +_move_logs (TpAccount *account, const gchar *account_name) { gchar *old_path, *new_path, *escaped; const gchar *name; - name = empathy_account_get_unique_name (account); + name = tp_proxy_get_object_path (account); if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); @@ -215,7 +215,7 @@ _create_account_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - EmpathyAccount *account; + TpAccount *account; GError *error = NULL; Misc *misc = (Misc *) user_data; @@ -233,7 +233,7 @@ _create_account_cb (GObject *source, _move_logs (account, misc->account_name); - empathy_account_set_enabled_async (account, + tp_account_set_enabled_async (account, misc->enable, NULL, NULL); g_free (misc->account_name); diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 2dc810b0a..5a0d82c8c 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -28,13 +28,12 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include <libempathy/empathy-debug.h> -#include <libempathy/empathy-account.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-connection-managers.h> #include <libempathy/empathy-utils.h> #include <libempathy-gtk/empathy-ui-utils.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <glib/gi18n.h> @@ -77,24 +76,12 @@ import_widget_account_id_in_list (GList *accounts, for (l = accounts; l; l = l->next) { - EmpathyAccount *account = l->data; - const gchar *account_string; - GValue *value; - gboolean result; + TpAccount *account = l->data; const GHashTable *parameters; - parameters = empathy_account_get_parameters (account); - - value = g_hash_table_lookup ((GHashTable *) parameters, "account"); - - if (value == NULL) - continue; - - account_string = g_value_get_string (value); - - result = tp_strdiff (account_string, account_id); + parameters = tp_account_get_parameters (account); - if (!result) + if (!tp_strdiff (tp_asv_get_string (parameters, "account"), account_id)) return TRUE; } @@ -102,13 +89,24 @@ import_widget_account_id_in_list (GList *accounts, } static void -import_widget_add_accounts_to_model (EmpathyImportWidget *self) +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyImportWidget *self = user_data; GtkTreeModel *model; GtkTreeIter iter; GList *l; EmpathyImportWidgetPriv *priv = GET_PRIV (self); - EmpathyAccountManager *manager = empathy_account_manager_dup_singleton (); + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); @@ -128,14 +126,13 @@ import_widget_add_accounts_to_model (EmpathyImportWidget *self) value = g_hash_table_lookup (data->settings, "account"); - accounts = empathy_account_manager_dup_accounts (manager); + accounts = tp_account_manager_get_valid_accounts (manager); /* Only set the "Import" cell to be active if there isn't already an * account set up with the same account id. */ import = !import_widget_account_id_in_list (accounts, g_value_get_string (value)); - g_list_foreach (accounts, (GFunc) g_object_unref, NULL); g_list_free (accounts); gtk_list_store_append (GTK_LIST_STORE (model), &iter); @@ -148,6 +145,17 @@ import_widget_add_accounts_to_model (EmpathyImportWidget *self) COL_ACCOUNT_DATA, data, -1); } +} + +static void +import_widget_add_accounts_to_model (EmpathyImportWidget *self) +{ + TpAccountManager *manager; + + manager = tp_account_manager_dup (); + + tp_account_manager_prepare_async (manager, NULL, + account_manager_prepared_cb, self); g_object_unref (manager); } @@ -157,12 +165,12 @@ import_widget_create_account_cb (GObject *source, GAsyncResult *result, gpointer user_data) { - EmpathyAccount *account; + TpAccount *account; GError *error = NULL; EmpathyImportWidget *self = user_data; - account = empathy_account_manager_create_account_finish ( - EMPATHY_ACCOUNT_MANAGER (source), result, &error); + account = tp_account_manager_create_account_finish ( + TP_ACCOUNT_MANAGER (source), result, &error); if (account == NULL) { @@ -181,12 +189,12 @@ static void import_widget_add_account (EmpathyImportWidget *self, EmpathyImportAccountData *data) { - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; gchar *display_name; GHashTable *properties; GValue *username; - account_manager = empathy_account_manager_dup_singleton (); + account_manager = tp_account_manager_dup (); DEBUG ("connection_manager: %s\n", data->connection_manager); @@ -200,7 +208,7 @@ import_widget_add_account (EmpathyImportWidget *self, properties = g_hash_table_new (NULL, NULL); - empathy_account_manager_create_account_async (account_manager, + tp_account_manager_create_account_async (account_manager, (const gchar*) data->connection_manager, data->protocol, display_name, data->settings, properties, import_widget_create_account_cb, g_object_ref (self)); diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 83daac08d..a2f9dde13 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -27,9 +27,11 @@ #include <gtk/gtk.h> #include <glib/gi18n.h> +#include <telepathy-glib/account-manager.h> + #include <libempathy/empathy-contact.h> +#include <libempathy/empathy-idle.h> #include <libempathy/empathy-utils.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-dispatcher.h> #include <libempathy/empathy-chatroom-manager.h> #include <libempathy/empathy-chatroom.h> @@ -79,7 +81,7 @@ typedef struct { EmpathyContactListView *list_view; EmpathyContactListStore *list_store; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; EmpathyChatroomManager *chatroom_manager; EmpathyEventManager *event_manager; guint flash_timeout_id; @@ -305,7 +307,7 @@ static void main_window_error_edit_clicked_cb (GtkButton *button, EmpathyMainWindow *window) { - EmpathyAccount *account; + TpAccount *account; GtkWidget *error_widget; account = g_object_get_data (G_OBJECT (button), "account"); @@ -320,7 +322,7 @@ static void main_window_error_clear_clicked_cb (GtkButton *button, EmpathyMainWindow *window) { - EmpathyAccount *account; + TpAccount *account; GtkWidget *error_widget; account = g_object_get_data (G_OBJECT (button), "account"); @@ -331,7 +333,7 @@ main_window_error_clear_clicked_cb (GtkButton *button, static void main_window_error_display (EmpathyMainWindow *window, - EmpathyAccount *account, + TpAccount *account, const gchar *message) { GtkWidget *child; @@ -352,7 +354,7 @@ main_window_error_display (EmpathyMainWindow *window, /* Just set the latest error and return */ str = g_markup_printf_escaped ("<b>%s</b>\n%s", - empathy_account_get_display_name (account), + tp_account_get_display_name (account), message); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); @@ -433,7 +435,7 @@ main_window_error_display (EmpathyMainWindow *window, gtk_misc_set_alignment (GTK_MISC (label), 0, 0); str = g_markup_printf_escaped ("<b>%s</b>\n%s", - empathy_account_get_display_name (account), + tp_account_get_display_name (account), message); gtk_label_set_markup (GTK_LABEL (label), str); g_free (str); @@ -460,18 +462,15 @@ main_window_error_display (EmpathyMainWindow *window, } static void -main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *manager) +main_window_update_status (EmpathyMainWindow *window) { - int connected; - int connecting; + gboolean connected, connecting; GList *l; - /* Count number of connected/connecting/disconnected accounts */ - connected = empathy_account_manager_get_connected_accounts (manager); - connecting = empathy_account_manager_get_connecting_accounts (manager); + connected = empathy_account_manager_get_accounts_connected (&connecting); /* Update the spinner state */ - if (connecting > 0) { + if (connecting) { ephy_spinner_start (EPHY_SPINNER (window->throbber)); } else { ephy_spinner_stop (EPHY_SPINNER (window->throbber)); @@ -479,19 +478,20 @@ main_window_update_status (EmpathyMainWindow *window, EmpathyAccountManager *man /* Update widgets sensibility */ for (l = window->actions_connected; l; l = l->next) { - gtk_action_set_sensitive (l->data, (connected > 0)); + gtk_action_set_sensitive (l->data, connected); } } static void -main_window_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus current, - TpConnectionStatus previous, +main_window_connection_changed_cb (TpAccount *account, + guint old_status, + guint current, + guint reason, + gchar *dbus_error_name, + GHashTable *details, EmpathyMainWindow *window) { - main_window_update_status (window, manager); + main_window_update_status (window); if (current == TP_CONNECTION_STATUS_DISCONNECTED && reason != TP_CONNECTION_STATUS_REASON_REQUESTED) { @@ -572,15 +572,17 @@ main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor, TpConnectionPresenceType previous, EmpathyMainWindow *window) { - EmpathyAccount *account; - gboolean should_play; + TpAccount *account; + gboolean should_play = FALSE; + EmpathyIdle *idle; - account = empathy_contact_get_account (contact); - should_play = !empathy_account_is_just_connected (account); + account = empathy_contact_get_account (contact); + idle = empathy_idle_dup_singleton (); - if (!should_play) { - return; - } + should_play = !empathy_idle_account_is_just_connected (idle, account); + + if (!should_play) + goto out; if (tp_connection_presence_type_cmp_availability (previous, TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0) @@ -601,6 +603,9 @@ main_window_contact_presence_changed_cb (EmpathyContactMonitor *monitor, empathy_sound_play (GTK_WIDGET (window->window), EMPATHY_SOUND_CONTACT_CONNECTED); } + +out: + g_object_unref (idle); } static void @@ -641,10 +646,6 @@ main_window_destroy_cb (GtkWidget *widget, /* Save user-defined accelerators. */ main_window_accels_save (); - g_signal_handlers_disconnect_by_func (window->account_manager, - main_window_connection_changed_cb, - window); - if (window->size_timeout_id) { g_source_remove (window->size_timeout_id); } @@ -845,12 +846,12 @@ main_window_view_show_map_cb (GtkCheckMenuItem *item, static void main_window_favorite_chatroom_join (EmpathyChatroom *chatroom) { - EmpathyAccount *account; + TpAccount *account; TpConnection *connection; const gchar *room; account = empathy_chatroom_get_account (chatroom); - connection = empathy_account_get_connection (account); + connection = tp_account_get_connection (account); room = empathy_chatroom_get_room (chatroom); if (connection != NULL) { @@ -1121,12 +1122,27 @@ main_window_configure_event_cb (GtkWidget *widget, } static void -main_window_account_created_or_deleted_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - EmpathyMainWindow *window) +main_window_account_removed_cb (TpAccountManager *manager, + TpAccount *account, + EmpathyMainWindow *window) { + GList *a; + + a = tp_account_manager_get_valid_accounts (manager); + gtk_action_set_sensitive (window->view_history, - empathy_account_manager_get_count (manager) > 0); + g_list_length (a) > 0); + + g_list_free (a); +} + +static void +main_window_account_validity_changed_cb (TpAccountManager *manager, + TpAccount *account, + gboolean valid, + EmpathyMainWindow *window) +{ + main_window_account_removed_cb (manager, account, window); } static void @@ -1169,6 +1185,33 @@ empathy_main_window_get (void) return main_window != NULL ? main_window->window : NULL; } +static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GList *accounts, *j; + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyMainWindow *window = user_data; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (window->account_manager); + for (j = accounts; j != NULL; j = j->next) { + TpAccount *account = TP_ACCOUNT (j->data); + + g_signal_connect (account, "status-changed", + G_CALLBACK (main_window_connection_changed_cb), + window); + } + g_list_free (accounts); +} + GtkWidget * empathy_main_window_show (void) { @@ -1250,11 +1293,10 @@ empathy_main_window_show (void) gtk_action_set_visible (show_map_widget, FALSE); #endif - window->account_manager = empathy_account_manager_dup_singleton (); + window->account_manager = tp_account_manager_dup (); - g_signal_connect (window->account_manager, - "account-connection-changed", - G_CALLBACK (main_window_connection_changed_cb), window); + tp_account_manager_prepare_async (window->account_manager, NULL, + account_manager_prepared_cb, window); window->errors = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -1352,13 +1394,13 @@ empathy_main_window_show (void) G_CALLBACK (main_window_event_removed_cb), window); - g_signal_connect (window->account_manager, "account-created", - G_CALLBACK (main_window_account_created_or_deleted_cb), + g_signal_connect (window->account_manager, "account-validity-changed", + G_CALLBACK (main_window_account_validity_changed_cb), window); - g_signal_connect (window->account_manager, "account-deleted", - G_CALLBACK (main_window_account_created_or_deleted_cb), + g_signal_connect (window->account_manager, "account-removed", + G_CALLBACK (main_window_account_removed_cb), window); - main_window_account_created_or_deleted_cb (window->account_manager, NULL, window); + main_window_account_removed_cb (window->account_manager, NULL, window); l = empathy_event_manager_get_events (window->event_manager); while (l) { @@ -1404,7 +1446,7 @@ empathy_main_window_show (void) EMPATHY_PREFS_UI_SHOW_AVATARS, window); - main_window_update_status (window, window->account_manager); + main_window_update_status (window); return window->window; } diff --git a/src/empathy-new-chatroom-dialog.c b/src/empathy-new-chatroom-dialog.c index 219be371d..8ea65adf2 100644 --- a/src/empathy-new-chatroom-dialog.c +++ b/src/empathy-new-chatroom-dialog.c @@ -354,7 +354,7 @@ static void new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog) { EmpathyAccountChooser *account_chooser; - EmpathyAccount *account; + TpAccount *account; const gchar *protocol; const gchar *room; @@ -364,7 +364,7 @@ new_chatroom_dialog_update_widgets (EmpathyNewChatroomDialog *dialog) if (account == NULL) return; - protocol = empathy_account_get_protocol (account); + protocol = tp_account_get_protocol (account); gtk_entry_set_text (GTK_ENTRY (dialog->entry_server), ""); @@ -396,7 +396,7 @@ new_chatroom_dialog_account_changed_cb (GtkComboBox *combobox, EmpathyNewChatroomDialog *dialog) { EmpathyAccountChooser *account_chooser; - EmpathyAccount *account; + TpAccount *account; gboolean listing = FALSE; gboolean expanded = FALSE; diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index a2a6f54fb..21cb2dd3d 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -32,11 +32,11 @@ #include <libnotify/notification.h> #include <libnotify/notify.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <libempathy/empathy-utils.h> #include <libempathy/empathy-idle.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy-gtk/empathy-presence-chooser.h> #include <libempathy-gtk/empathy-conf.h> @@ -60,7 +60,7 @@ typedef struct { GtkStatusIcon *icon; EmpathyIdle *idle; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; gboolean showing_event_icon; guint blink_timeout; EmpathyEventManager *event_manager; @@ -511,20 +511,18 @@ status_icon_create_menu (EmpathyStatusIcon *icon) } static void -status_icon_connection_changed_cb (EmpathyAccountManager *manager, - EmpathyAccount *account, - TpConnectionStatusReason reason, - TpConnectionStatus current, - TpConnectionStatus previous, - EmpathyStatusIcon *icon) +status_icon_status_changed_cb (TpAccount *account, + TpConnectionStatus current, + TpConnectionStatus previous, + TpConnectionStatusReason reason, + gchar *dbus_error_name, + GHashTable *details, + EmpathyStatusIcon *icon) { EmpathyStatusIconPriv *priv = GET_PRIV (icon); - int connected_accounts; - /* Check for a connected account */ - connected_accounts = empathy_account_manager_get_connected_accounts (manager); - - gtk_action_set_sensitive (priv->new_message_item, connected_accounts > 0); + gtk_action_set_sensitive (priv->new_message_item, + empathy_account_manager_get_accounts_connected (NULL)); } static void @@ -536,10 +534,6 @@ status_icon_finalize (GObject *object) g_source_remove (priv->blink_timeout); } - g_signal_handlers_disconnect_by_func (priv->account_manager, - status_icon_connection_changed_cb, - object); - if (priv->notification) { notify_notification_close (priv->notification, NULL); g_object_unref (priv->notification); @@ -564,6 +558,31 @@ empathy_status_icon_class_init (EmpathyStatusIconClass *klass) } static void +account_manager_prepared_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GList *list, *l; + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyStatusIcon *icon = user_data; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + list = tp_account_manager_get_valid_accounts (account_manager); + for (l = list; l != NULL; l = l->next) { + empathy_signal_connect_weak (l->data, "status-changed", + G_CALLBACK (status_icon_status_changed_cb), + G_OBJECT (icon)); + } + g_list_free (list); +} + +static void empathy_status_icon_init (EmpathyStatusIcon *icon) { EmpathyStatusIconPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (icon, @@ -572,13 +591,12 @@ empathy_status_icon_init (EmpathyStatusIcon *icon) icon->priv = priv; priv->icon = gtk_status_icon_new (); - priv->account_manager = empathy_account_manager_dup_singleton (); + priv->account_manager = tp_account_manager_dup (); priv->idle = empathy_idle_dup_singleton (); priv->event_manager = empathy_event_manager_dup_singleton (); - g_signal_connect (priv->account_manager, - "account-connection-changed", - G_CALLBACK (status_icon_connection_changed_cb), icon); + tp_account_manager_prepare_async (priv->account_manager, NULL, + account_manager_prepared_cb, icon); /* make icon listen and respond to MAIN_WINDOW_HIDDEN changes */ empathy_conf_notify_add (empathy_conf_get (), diff --git a/src/empathy.c b/src/empathy.c index 69210760e..72b691c16 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -38,6 +38,7 @@ #include <libebook/e-book.h> #include <libnotify/notify.h> +#include <telepathy-glib/account-manager.h> #include <telepathy-glib/dbus.h> #include <telepathy-glib/util.h> #include <telepathy-glib/connection-manager.h> @@ -49,7 +50,6 @@ #include <libempathy/empathy-chatroom-manager.h> #include <libempathy/empathy-account-settings.h> #include <libempathy/empathy-connectivity.h> -#include <libempathy/empathy-account-manager.h> #include <libempathy/empathy-connection-managers.h> #include <libempathy/empathy-debugger.h> #include <libempathy/empathy-dispatcher.h> @@ -105,16 +105,12 @@ dispatch_cb (EmpathyDispatcher *dispatcher, id = empathy_tp_chat_get_id (tp_chat); if (!EMP_STR_EMPTY (id)) { - EmpathyAccountManager *manager; TpConnection *connection; - EmpathyAccount *account; + TpAccount *account; - manager = empathy_account_manager_dup_singleton (); connection = empathy_tp_chat_get_connection (tp_chat); - account = empathy_account_manager_get_account_for_connection ( - manager, connection); + account = empathy_get_account_for_connection (connection); chat = empathy_chat_window_find_chat (account, id); - g_object_unref (manager); } if (chat) @@ -155,11 +151,11 @@ dispatch_cb (EmpathyDispatcher *dispatcher, } } -/* Salut account creation */ +/* Salut account creation. The TpAccountManager first argument + * must already be prepared when calling this function. */ static gboolean -should_create_salut_account (void) +should_create_salut_account (TpAccountManager *manager) { - EmpathyAccountManager *manager; gboolean salut_created = FALSE; GList *accounts, *l; @@ -174,20 +170,20 @@ should_create_salut_account (void) return FALSE; } - manager = empathy_account_manager_dup_singleton (); - accounts = empathy_account_manager_dup_accounts (manager); + accounts = tp_account_manager_get_valid_accounts (manager); for (l = accounts; l != NULL; l = g_list_next (l)) { - EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); + TpAccount *account = TP_ACCOUNT (l->data); - if (!tp_strdiff (empathy_account_get_protocol (account), "local-xmpp")) - salut_created = TRUE; - - g_object_unref (account); + if (!tp_strdiff (tp_account_get_protocol (account), "local-xmpp")) + { + salut_created = TRUE; + break; + } } - g_object_unref (manager); + g_list_free (accounts); if (salut_created) { @@ -206,7 +202,7 @@ salut_account_created (GObject *source, gpointer user_data) { EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source); - EmpathyAccount *account; + TpAccount *account; GError *error = NULL; if (!empathy_account_settings_apply_finish (settings, result, &error)) @@ -218,7 +214,7 @@ salut_account_created (GObject *source, account = empathy_account_settings_get_account (settings); - empathy_account_set_enabled_async (account, TRUE, NULL, NULL); + tp_account_set_enabled_async (account, TRUE, NULL, NULL); empathy_conf_set_bool (empathy_conf_get (), EMPATHY_PREFS_SALUT_ACCOUNT_CREATED, TRUE); @@ -239,8 +235,12 @@ use_conn_notify_cb (EmpathyConf *conf, } static void -create_salut_account_if_needed (EmpathyConnectionManagers *managers) +create_salut_account_am_ready_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyConnectionManagers *managers = user_data; EmpathyAccountSettings *settings; TpConnectionManager *manager; const TpConnectionManagerProtocol *protocol; @@ -253,22 +253,28 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) gchar *jid = NULL; GError *error = NULL; + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + goto out; + } - if (!should_create_salut_account ()) - return; + if (!should_create_salut_account (account_manager)) + goto out; manager = empathy_connection_managers_get_cm (managers, "salut"); if (manager == NULL) { DEBUG ("Salut not installed, not making a salut account"); - return; + goto out; } protocol = tp_connection_manager_get_protocol (manager, "local-xmpp"); if (protocol == NULL) { DEBUG ("Salut doesn't support local-xmpp!!"); - return; + goto out; } DEBUG ("Trying to add a salut account..."); @@ -279,7 +285,7 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) DEBUG ("Failed to get self econtact: %s", error ? error->message : "No error given"); g_clear_error (&error); - return; + goto out; } settings = empathy_account_settings_new ("salut", "local-xmpp", @@ -321,24 +327,39 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) g_object_unref (settings); g_object_unref (contact); g_object_unref (book); + + out: + g_object_unref (managers); +} + +static void +create_salut_account_if_needed (EmpathyConnectionManagers *managers) +{ + TpAccountManager *manager; + + manager = tp_account_manager_dup (); + + tp_account_manager_prepare_async (manager, NULL, + create_salut_account_am_ready_cb, g_object_ref (managers)); + + g_object_unref (manager); } static gboolean -has_non_salut_accounts (EmpathyAccountManager *manager) +has_non_salut_accounts (TpAccountManager *manager) { gboolean ret = FALSE; GList *accounts, *l; - accounts = empathy_account_manager_dup_accounts (manager); + accounts = tp_account_manager_get_valid_accounts (manager); for (l = accounts ; l != NULL; l = g_list_next (l)) { - EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); - - if (tp_strdiff (empathy_account_get_protocol (l->data), "local-xmpp")) - ret = TRUE; - - g_object_unref (account); + if (tp_strdiff (tp_account_get_protocol (l->data), "local-xmpp")) + { + ret = TRUE; + break; + } } g_list_free (accounts); @@ -349,11 +370,13 @@ has_non_salut_accounts (EmpathyAccountManager *manager) static void maybe_show_account_assistant (void) { - EmpathyAccountManager *manager; - manager = empathy_account_manager_dup_singleton (); + TpAccountManager *manager; + manager = tp_account_manager_dup (); if (!has_non_salut_accounts (manager)) empathy_account_assistant_show (GTK_WINDOW (empathy_main_window_get ())); + + g_object_unref (manager); } static gboolean @@ -450,7 +473,7 @@ migrate_config_to_xdg_dir (void) static void do_show_accounts_ui (GtkWindow *window, - EmpathyAccountManager *manager) + TpAccountManager *manager) { GtkWidget *ui; @@ -466,12 +489,19 @@ do_show_accounts_ui (GtkWindow *window, } static void -account_manager_ready_for_accounts_cb (EmpathyAccountManager *manager, - GParamSpec *spec, +account_manager_ready_for_accounts_cb (GObject *source_object, + GAsyncResult *result, gpointer user_data) { - if (!empathy_account_manager_is_ready (manager)) - return; + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } do_show_accounts_ui (user_data, manager); } @@ -480,24 +510,15 @@ static void show_accounts_ui (GtkWindow *window, gboolean force) { - EmpathyAccountManager *manager; + TpAccountManager *manager; - manager = empathy_account_manager_dup_singleton (); - if (empathy_account_manager_is_ready (manager)) - { - if (force) - do_show_accounts_ui (window, manager); - else - maybe_show_account_assistant (); - } - else if (force) - { - /* Only if we we're forced to show the widget connect to ready, otherwise - * the initial readyness will cause the accounts ui to be shown when - * needed */ - g_signal_connect (manager, "notify::ready", - G_CALLBACK (account_manager_ready_for_accounts_cb), window); - } + if (!force) + return; + + manager = tp_account_manager_dup (); + + tp_account_manager_prepare_async (manager, NULL, + account_manager_ready_for_accounts_cb, window); g_object_unref (manager); } @@ -615,14 +636,22 @@ default_log_handler (const gchar *log_domain, #endif /* ENABLE_DEBUG */ static void -account_manager_ready_cb (EmpathyAccountManager *manager, - GParamSpec *spec, +account_manager_ready_cb (GObject *source_object, + GAsyncResult *result, gpointer user_data) { - if (!empathy_account_manager_is_ready (manager)) - return; + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } - if (should_create_salut_account () || !empathy_import_mc4_has_imported ()) + if (should_create_salut_account (manager) + || !empathy_import_mc4_has_imported ()) { EmpathyConnectionManagers *managers; managers = empathy_connection_managers_dup_singleton (); @@ -730,37 +759,48 @@ setup_dispatcher (void) } static void -account_connection_notify_cb (EmpathyAccount *account, - GParamSpec *pspec, +account_status_changed_cb (TpAccount *account, + guint old_status, + guint new_status, + guint reason, + gchar *dbus_error_name, + GHashTable *details, EmpathyChatroom *room) { TpConnection *conn; - conn = empathy_account_get_connection (account); - - if (conn == NULL) - return; + conn = tp_account_get_connection (account); empathy_dispatcher_join_muc (conn, empathy_chatroom_get_room (room), NULL, NULL); } static void -account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager, - GParamSpec *pspec, - EmpathyChatroomManager *chatroom_manager) +account_manager_chatroom_ready_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) { + TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); + EmpathyChatroomManager *chatroom_manager = user_data; GList *accounts, *l; + GError *error = NULL; - accounts = empathy_account_manager_dup_accounts (account_manager); + if (!tp_account_manager_prepare_finish (account_manager, result, &error)) + { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); + return; + } + + accounts = tp_account_manager_get_valid_accounts (account_manager); for (l = accounts; l != NULL; l = g_list_next (l)) { - EmpathyAccount *account = EMPATHY_ACCOUNT (l->data); + TpAccount *account = TP_ACCOUNT (l->data); TpConnection *conn; GList *chatrooms, *p; - conn = empathy_account_get_connection (account); + conn = tp_account_get_connection (account); chatrooms = empathy_chatroom_manager_get_chatrooms ( chatroom_manager, account); @@ -774,8 +814,8 @@ account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager, if (conn == NULL) { - g_signal_connect (G_OBJECT (account), "notify::connection", - G_CALLBACK (account_connection_notify_cb), room); + g_signal_connect (G_OBJECT (account), "status-changed", + G_CALLBACK (account_status_changed_cb), room); } else { @@ -787,29 +827,18 @@ account_manager_chatroom_ready_cb (EmpathyAccountManager *account_manager, g_list_free (chatrooms); } - g_list_foreach (accounts, (GFunc) g_object_unref, NULL); g_list_free (accounts); } static void chatroom_manager_ready_cb (EmpathyChatroomManager *chatroom_manager, GParamSpec *pspec, - EmpathyAccountManager *account_manager) + gpointer user_data) { - gboolean ready; + TpAccountManager *account_manager = user_data; - g_object_get (G_OBJECT (account_manager), "ready", &ready, NULL); - - if (ready) - { - account_manager_chatroom_ready_cb (account_manager, NULL, - chatroom_manager); - } - else - { - g_signal_connect (account_manager, "notify::ready", - G_CALLBACK (account_manager_chatroom_ready_cb), chatroom_manager); - } + tp_account_manager_prepare_async (account_manager, NULL, + account_manager_chatroom_ready_cb, chatroom_manager); } int @@ -820,7 +849,7 @@ main (int argc, char *argv[]) #endif EmpathyStatusIcon *icon; EmpathyDispatcher *dispatcher; - EmpathyAccountManager *account_manager; + TpAccountManager *account_manager; EmpathyLogManager *log_manager; EmpathyChatroomManager *chatroom_manager; EmpathyCallFactory *call_factory; @@ -923,7 +952,7 @@ main (int argc, char *argv[]) if (account_dialog_only) { - account_manager = empathy_account_manager_dup_singleton (); + account_manager = tp_account_manager_dup (); show_accounts_ui (NULL, TRUE); gtk_main (); @@ -955,9 +984,9 @@ main (int argc, char *argv[]) empathy_idle_set_state (idle, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE); /* account management */ - account_manager = empathy_account_manager_dup_singleton (); - g_signal_connect (account_manager, "notify::ready", - G_CALLBACK (account_manager_ready_cb), NULL); + account_manager = tp_account_manager_dup (); + tp_account_manager_prepare_async (account_manager, NULL, + account_manager_ready_cb, NULL); /* Handle channels */ dispatcher = setup_dispatcher (); |