From f4619e5b640b2f6c05ded981042da44aa5e4d29c Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 15:57:31 +0100 Subject: account-assistant: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-account-assistant.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3 From ad49c874bb6fcdd91a319f6e886846a33c4ee61e Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 15:58:25 +0100 Subject: accounts-dialog: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-accounts-dialog.c | 211 ++++++++++++++---------------------------- src/empathy-accounts-dialog.h | 4 +- 2 files changed, 70 insertions(+), 145 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 1aacaff68..cb43c972e 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -32,10 +32,10 @@ #include #include +#include #include #include -#include #include #include @@ -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,59 +1317,26 @@ 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,11 +1556,13 @@ 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)) + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + + if (!tp_account_manager_prepare_finish (manager, result, NULL)) return; accounts_dialog_accounts_setup (user_data); @@ -1709,7 +1643,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, @@ -1720,12 +1654,6 @@ do_dispose (GObject *obj) g_signal_handlers_disconnect_by_func (priv->account_manager, 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); @@ -1824,13 +1752,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); @@ -1888,7 +1813,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 -#include +#include 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 -- cgit v1.2.3 From 395e69cf663ec73e2041ab458ab3afaf862e55f4 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 15:59:03 +0100 Subject: chat-window: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-chat-window.c | 27 +++++++++++++++------------ src/empathy-chat-window.h | 5 +++-- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index f5b5d24c9..bb335033e 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -34,13 +34,13 @@ #include #include +#include #include #include #include #include #include -#include #include #include @@ -413,7 +413,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; @@ -436,7 +436,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) { @@ -480,7 +480,7 @@ chat_window_update_chat_tab (EmpathyChat *chat) append_markup_printf (tooltip, "%s (%s)", id, - empathy_account_get_display_name (account)); + tp_account_get_display_name (account)); if (!EMP_STR_EMPTY (status)) { append_markup_printf (tooltip, "\n%s", status); @@ -575,7 +575,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; @@ -624,7 +624,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; @@ -1281,15 +1281,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); @@ -1298,7 +1301,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); } @@ -1312,7 +1315,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 ( @@ -1798,7 +1801,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 #include -#include +#include + #include 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); -- cgit v1.2.3 From 8cf5bd07af7bcc53a115ff7cf7145c62b3d7dca6 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 15:59:37 +0100 Subject: chatrooms-window: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-chatrooms-window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') 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); -- cgit v1.2.3 From 94afc1026dce7dc92d12196cc61a320509080762 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:00:07 +0100 Subject: event-manager: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-event-manager.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') 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 #include +#include #include #include -#include #include +#include #include #include #include @@ -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); } -- cgit v1.2.3 From 24031b2130a2143f100588d1d62ea2d21326f664 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:00:34 +0100 Subject: import-mc4-accounts: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-import-mc4-accounts.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') 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 #include #include +#include #include #include #include #include -#include #include #include @@ -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); -- cgit v1.2.3 From 968589cc9a491fd60aeb46ba2eb8ac3f789e8b7a Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:01:06 +0100 Subject: import-widget: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-import-widget.c | 57 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 2dc810b0a..629b15162 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -28,13 +28,12 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include -#include -#include #include #include #include +#include #include #include @@ -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); + parameters = tp_account_get_parameters (account); - result = tp_strdiff (account_string, account_id); - - if (!result) + if (!tp_strdiff (tp_asv_get_string (parameters, "account"), account_id)) return TRUE; } @@ -102,13 +89,19 @@ 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 (); + + if (!tp_account_manager_prepare_finish (manager, result, NULL)) + return; model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->treeview)); @@ -128,14 +121,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 +140,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 +160,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 +184,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 +203,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)); -- cgit v1.2.3 From eb593876a497fec9d0c1fd182af5d15a29fc1194 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:01:33 +0100 Subject: main-window: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-main-window.c | 135 +++++++++++++++++++++++++++++----------------- 1 file changed, 87 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 83daac08d..dbaf399f8 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -27,9 +27,11 @@ #include #include +#include + #include +#include #include -#include #include #include #include @@ -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 ("%s\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 ("%s\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,30 @@ 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; + + if (!tp_account_manager_prepare_finish (manager, result, NULL)) { + 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 +1290,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 +1391,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 +1443,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; } -- cgit v1.2.3 From b126bcf946e65de4e061d89481166fd6894ef44a Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:01:53 +0100 Subject: new-chatroom-dialog: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-new-chatroom-dialog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') 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; -- cgit v1.2.3 From 2b7894262b4e647760477a9e8b6f8add5b321128 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:02:52 +0100 Subject: status-icon: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy-status-icon.c | 57 ++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index 3af060acf..33c2da031 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -32,11 +32,11 @@ #include #include +#include #include #include #include -#include #include #include @@ -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; @@ -506,20 +506,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 @@ -531,10 +529,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); @@ -558,6 +552,28 @@ empathy_status_icon_class_init (EmpathyStatusIconClass *klass) g_type_class_add_private (object_class, sizeof (EmpathyStatusIconPriv)); } +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; + + if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) { + 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) { @@ -567,13 +583,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 (), -- cgit v1.2.3 From 3109ed5adee0f039b9010f23ae6cd84ef464a046 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Sat, 24 Oct 2009 16:03:33 +0100 Subject: empathy: port to new tp-glib account API Signed-off-by: Jonny Lamb --- src/empathy.c | 161 +++++++++++++++++++++++++++------------------------------- 1 file changed, 76 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/empathy.c b/src/empathy.c index 9fddda22e..2acaf63df 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -49,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -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) @@ -152,7 +148,7 @@ dispatch_cb (EmpathyDispatcher *dispatcher, static gboolean should_create_salut_account (void) { - EmpathyAccountManager *manager; + TpAccountManager *manager; gboolean salut_created = FALSE; GList *accounts, *l; @@ -167,19 +163,23 @@ should_create_salut_account (void) return FALSE; } - manager = empathy_account_manager_dup_singleton (); - accounts = empathy_account_manager_dup_accounts (manager); + /* FIXME: this assumes the account manager is already prepared */ + manager = tp_account_manager_dup (); + 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_list_free (accounts); + g_object_unref (manager); if (salut_created) @@ -199,7 +199,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)) @@ -211,7 +211,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); @@ -317,21 +317,20 @@ create_salut_account_if_needed (EmpathyConnectionManagers *managers) } 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); @@ -342,11 +341,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 @@ -443,7 +444,7 @@ migrate_config_to_xdg_dir (void) static void do_show_accounts_ui (GtkWindow *window, - EmpathyAccountManager *manager) + TpAccountManager *manager) { GtkWidget *ui; @@ -459,11 +460,13 @@ 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)) + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + + if (!tp_account_manager_prepare_finish (manager, result, NULL)) return; do_show_accounts_ui (user_data, manager); @@ -473,24 +476,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); } @@ -608,11 +602,13 @@ 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)) + TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + + if (!tp_account_manager_prepare_finish (manager, result, NULL)) return; if (should_create_salut_account () || !empathy_import_mc4_has_imported ()) @@ -723,37 +719,43 @@ 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; - accounts = empathy_account_manager_dup_accounts (account_manager); + if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) + 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); @@ -767,8 +769,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 { @@ -780,29 +782,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; - - g_object_get (G_OBJECT (account_manager), "ready", &ready, NULL); + TpAccountManager *account_manager = user_data; - 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 @@ -813,7 +804,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; @@ -916,7 +907,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 (); @@ -948,9 +939,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 (); -- cgit v1.2.3 From d5f2776bacfe750f02782cef348e984ed68916af Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 30 Oct 2009 10:10:26 +0000 Subject: all: log error messages if preparing the account manager fails Signed-off-by: Jonny Lamb --- src/empathy-accounts-dialog.c | 9 +++++++-- src/empathy-import-widget.c | 9 +++++++-- src/empathy-main-window.c | 5 ++++- src/empathy-status-icon.c | 5 ++++- src/empathy.c | 27 +++++++++++++++++++++------ 5 files changed, 43 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index cb43c972e..014b73611 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -1561,9 +1561,14 @@ accounts_dialog_manager_ready_cb (GObject *source_object, gpointer user_data) { TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; - if (!tp_account_manager_prepare_finish (manager, result, NULL)) - return; + 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); } diff --git a/src/empathy-import-widget.c b/src/empathy-import-widget.c index 629b15162..5a0d82c8c 100644 --- a/src/empathy-import-widget.c +++ b/src/empathy-import-widget.c @@ -99,9 +99,14 @@ account_manager_prepared_cb (GObject *source_object, GtkTreeIter iter; GList *l; EmpathyImportWidgetPriv *priv = GET_PRIV (self); + GError *error = NULL; - if (!tp_account_manager_prepare_finish (manager, result, NULL)) - return; + 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)); diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index dbaf399f8..a2f9dde13 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -1193,8 +1193,11 @@ account_manager_prepared_cb (GObject *source_object, 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, NULL)) { + if (!tp_account_manager_prepare_finish (manager, result, &error)) { + DEBUG ("Failed to prepare account manager: %s", error->message); + g_error_free (error); return; } diff --git a/src/empathy-status-icon.c b/src/empathy-status-icon.c index 33c2da031..ba1bef1a4 100644 --- a/src/empathy-status-icon.c +++ b/src/empathy-status-icon.c @@ -560,8 +560,11 @@ account_manager_prepared_cb (GObject *source_object, 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, 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; } diff --git a/src/empathy.c b/src/empathy.c index 2acaf63df..6487058a4 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -465,9 +465,14 @@ account_manager_ready_for_accounts_cb (GObject *source_object, gpointer user_data) { TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; - if (!tp_account_manager_prepare_finish (manager, result, NULL)) - return; + 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); } @@ -607,9 +612,14 @@ account_manager_ready_cb (GObject *source_object, gpointer user_data) { TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object); + GError *error = NULL; - if (!tp_account_manager_prepare_finish (manager, result, NULL)) - return; + 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 ()) { @@ -743,9 +753,14 @@ account_manager_chatroom_ready_cb (GObject *source_object, TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); EmpathyChatroomManager *chatroom_manager = user_data; GList *accounts, *l; + GError *error = NULL; - if (!tp_account_manager_prepare_finish (account_manager, result, NULL)) - return; + 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); -- cgit v1.2.3 From 61dae5c0f483835085509792200f39da28ef38c1 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 30 Oct 2009 10:41:16 +0000 Subject: empathy: when creating salut account, be sure to wait for the account manager Signed-off-by: Jonny Lamb --- src/empathy.c | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/empathy.c b/src/empathy.c index 6487058a4..dd9fc92fe 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -144,11 +144,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) { - TpAccountManager *manager; gboolean salut_created = FALSE; GList *accounts, *l; @@ -163,8 +163,6 @@ should_create_salut_account (void) return FALSE; } - /* FIXME: this assumes the account manager is already prepared */ - manager = tp_account_manager_dup (); accounts = tp_account_manager_get_valid_accounts (manager); for (l = accounts; l != NULL; l = g_list_next (l)) @@ -180,8 +178,6 @@ should_create_salut_account (void) g_list_free (accounts); - g_object_unref (manager); - if (salut_created) { DEBUG ("Existing salut account already exists, flagging so in gconf"); @@ -232,8 +228,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; @@ -246,22 +246,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..."); @@ -272,7 +278,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", @@ -314,6 +320,22 @@ 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 @@ -621,7 +643,8 @@ account_manager_ready_cb (GObject *source_object, 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 (); -- cgit v1.2.3