2 * empathy-accounts-plugin.c
4 * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <tp-account-widgets/tpaw-uoa-utils.h>
25 #include "empathy-accounts-plugin.h"
27 #include "empathy-client-factory.h"
29 #include "empathy-accounts-plugin-widget.h"
31 G_DEFINE_TYPE (EmpathyAccountsPlugin, empathy_accounts_plugin, AP_TYPE_PLUGIN)
34 widget_done_cb (EmpathyAccountsPluginWidget *widget,
37 ap_plugin_emit_finished (plugin);
41 empathy_accounts_plugin_build_widget (ApPlugin *plugin)
46 account = ap_plugin_get_account (plugin);
47 tpaw_uoa_manager_set_default (ag_account_get_manager (account));
49 widget = empathy_accounts_plugin_widget_new (account);
51 g_signal_connect (widget, "done",
52 G_CALLBACK (widget_done_cb), plugin);
58 store_delete_cb (GObject *source,
62 AgAccount *account = (AgAccount *) source;
63 GSimpleAsyncResult *result = user_data;
66 if (!ag_account_store_finish (account, res, &error))
68 g_debug ("Failed to delete account with ID '%u': %s",
69 account->id, error->message);
71 g_simple_async_result_take_error (result, error);
74 g_simple_async_result_complete (result);
75 g_object_unref (result);
79 empathy_accounts_plugin_delete_account (ApPlugin *plugin,
80 GAsyncReadyCallback callback,
84 GSimpleAsyncResult *result;
86 result = g_simple_async_result_new (G_OBJECT (plugin),
87 callback, user_data, ap_plugin_delete_account);
89 account = ap_plugin_get_account (plugin);
91 ag_account_delete (account);
92 ag_account_store_async (account, NULL, store_delete_cb, result);
96 empathy_accounts_plugin_act_headless (ApPlugin *plugin)
101 empathy_accounts_plugin_class_init (
102 EmpathyAccountsPluginClass *klass)
104 ApPluginClass *pclass = AP_PLUGIN_CLASS (klass);
106 pclass->build_widget = empathy_accounts_plugin_build_widget;
107 pclass->delete_account = empathy_accounts_plugin_delete_account;
108 pclass->act_headless = empathy_accounts_plugin_act_headless;
112 empathy_accounts_plugin_init (EmpathyAccountsPlugin *self)
114 if (tp_account_manager_can_set_default ())
116 EmpathyClientFactory *factory;
117 TpAccountManager *am;
119 factory = empathy_client_factory_dup ();
120 am = tp_account_manager_new_with_factory (
121 TP_SIMPLE_CLIENT_FACTORY (factory));
122 tp_account_manager_set_default (am);
124 g_object_unref (factory);
131 ap_module_get_object_type (void)
133 return EMPATHY_TYPE_ACCOUNTS_PLUGIN;