From 79ea3b4ad24160ad2d0a32b24adcd4fb526f9eca Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 27 Aug 2012 14:22:37 +0200 Subject: try installing missing account-plugin-* https://bugzilla.gnome.org/show_bug.cgi?id=682802 --- src/empathy-sanity-cleaning.c | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/empathy-sanity-cleaning.c b/src/empathy-sanity-cleaning.c index 12fdb2413..03ceb8ef2 100644 --- a/src/empathy-sanity-cleaning.c +++ b/src/empathy-sanity-cleaning.c @@ -32,6 +32,15 @@ #include +#ifdef HAVE_UOA +#include +#include + +#include +#include +#include +#endif + #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include #include @@ -372,13 +381,90 @@ migrate_account_to_uoa (TpAccountManager *am, g_object_unref (ar); } +static void +uoa_plugin_install_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpAccount *account = user_data; + GError *error = NULL; + TpAccountManager *am; + + if (!empathy_pkg_kit_install_packages_finish (result, &error)) + { + DEBUG ("Failed to install plugin: %s", error->message); + g_error_free (error); + goto out; + } + + DEBUG ("Plugin for account '%s' has been installed; migrate account", + tp_account_get_path_suffix (account)); + + am = tp_account_manager_dup (); + migrate_account_to_uoa (am, account); + g_object_unref (am); + +out: + g_object_unref (account); +} + +static gchar * +dup_plugin_name_for_protocol (const gchar *protocol) +{ + if (!tp_strdiff (protocol, "local-xmpp")) + return g_strdup ("account-plugin-salut"); + + return g_strdup_printf ("account-plugin-%s", protocol); +} + +static gboolean +uoa_plugin_installed (AgManager *manager, + TpAccount *account) +{ + AgAccount *ag_account; + const gchar *protocol; + GList *l; + + protocol = tp_account_get_protocol_name (account); + ag_account = ag_manager_create_account (manager, protocol); + + l = ag_account_list_services_by_type (ag_account, EMPATHY_UOA_SERVICE_TYPE); + if (l == NULL) + { + const gchar *packages[2]; + gchar *pkg; + + pkg = dup_plugin_name_for_protocol (protocol); + + DEBUG ("%s is not installed; try to install it", pkg); + + packages[0] = pkg; + packages[1] = NULL; + + empathy_pkg_kit_install_packages_async (0, packages, NULL, + NULL, uoa_plugin_install_cb, g_object_ref (account)); + + g_free (pkg); + g_object_unref (ag_account); + return FALSE; + } + + ag_service_list_free (l); + + g_object_unref (ag_account); + return TRUE; +} + static void migrate_accounts_to_uoa (TpAccountManager *am) { GList *accounts, *l; + AgManager *manager; DEBUG ("Start migrating accounts to UOA"); + manager = empathy_uoa_manager_dup (); + accounts = tp_account_manager_get_valid_accounts (am); for (l = accounts; l != NULL; l = g_list_next (l)) { @@ -391,8 +477,13 @@ migrate_accounts_to_uoa (TpAccountManager *am) if (!tp_str_empty (tp_account_get_storage_provider (account))) continue; + if (!uoa_plugin_installed (manager, account)) + continue; + migrate_account_to_uoa (am, account); } + + g_object_unref (manager); } #endif -- cgit v1.2.3