gboolean salut_created = FALSE;
GList *accounts, *l;
- /* Check if we already created a salut account */
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- &salut_created);
-
- if (salut_created)
- {
- DEBUG ("Gconf says we already created a salut account once");
- return FALSE;
- }
-
accounts = tp_account_manager_get_valid_accounts (manager);
for (l = accounts; l != NULL; l = g_list_next (l))
g_list_free (accounts);
- if (salut_created)
- {
- DEBUG ("Existing salut account already exists, flagging so in gconf");
- empathy_conf_set_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- TRUE);
- }
-
return !salut_created;
}
-static void
-salut_account_created (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
+EmpathyAccountSettings *
+create_salut_account_settings (void)
{
- EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
- TpAccount *account;
- GError *error = NULL;
-
- if (!empathy_account_settings_apply_finish (settings, result, &error))
- {
- DEBUG ("Failed to create salut account: %s", error->message);
- g_error_free (error);
- return;
- }
-
- account = empathy_account_settings_get_account (settings);
-
- tp_account_set_enabled_async (account, TRUE, NULL, NULL);
- empathy_conf_set_bool (empathy_conf_get (),
- EMPATHY_PREFS_SALUT_ACCOUNT_CREATED,
- TRUE);
-}
-
-static void
-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;
- EBook *book;
- EContact *contact;
- gchar *nickname = NULL;
- gchar *first_name = NULL;
- gchar *last_name = NULL;
- gchar *email = NULL;
- 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 (account_manager))
- goto out;
-
- manager = empathy_connection_managers_get_cm (managers, "salut");
- if (manager == NULL)
- {
- DEBUG ("Salut not installed, not making a salut account");
- goto out;
- }
-
- protocol = tp_connection_manager_get_protocol (manager, "local-xmpp");
- if (protocol == NULL)
- {
- DEBUG ("Salut doesn't support local-xmpp!!");
- goto out;
- }
+ EBook *book;
+ EContact *contact;
+ gchar *nickname = NULL;
+ gchar *first_name = NULL;
+ gchar *last_name = NULL;
+ gchar *email = NULL;
+ gchar *jid = NULL;
+ GError *error = NULL;
- DEBUG ("Trying to add a salut account...");
+ settings = empathy_account_settings_new ("salut", "local-xmpp",
+ _("People nearby"));
/* Get self EContact from EDS */
if (!e_book_get_self (&contact, &book, &error))
{
- DEBUG ("Failed to get self econtact: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- goto out;
+ DEBUG ("Failed to get self econtact: %s", error->message);
+ g_error_free (error);
+ return settings;
}
- settings = empathy_account_settings_new ("salut", "local-xmpp",
- _("People nearby"));
-
nickname = e_contact_get (contact, E_CONTACT_NICKNAME);
first_name = e_contact_get (contact, E_CONTACT_GIVEN_NAME);
last_name = e_contact_get (contact, E_CONTACT_FAMILY_NAME);
empathy_account_settings_set_string (settings, "email", email ? email : "");
empathy_account_settings_set_string (settings, "jid", jid ? jid : "");
- empathy_account_settings_apply_async (settings,
- salut_account_created, NULL);
-
g_free (nickname);
g_free (first_name);
g_free (last_name);
g_free (email);
g_free (jid);
- g_object_unref (settings);
g_object_unref (contact);
g_object_unref (book);
- out:
- g_object_unref (managers);
-}
-
-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);
+ return settings;
}