aboutsummaryrefslogtreecommitdiffstats
path: root/src/empathy.c
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2009-11-02 18:41:20 +0800
committerJonny Lamb <jonnylamb@gnome.org>2009-11-02 18:41:20 +0800
commit8c4fe70aad3622138957c49732fa612b1e2e9eb7 (patch)
tree2f80938787489bc774bf8849a14a2ad24354f978 /src/empathy.c
parent1b4acf8fcf47d928f525a4640f27323e13fd25ea (diff)
parentb6bb173fe0840ec0857a145e265853e2a9083ee6 (diff)
downloadgsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar.gz
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar.bz2
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar.lz
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar.xz
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.tar.zst
gsoc2013-empathy-8c4fe70aad3622138957c49732fa612b1e2e9eb7.zip
Merge branch 'accountz'
Diffstat (limited to 'src/empathy.c')
-rw-r--r--src/empathy.c223
1 files changed, 126 insertions, 97 deletions
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 ();