]> git.0d.be Git - empathy.git/blob - ubuntu-online-accounts/cc-plugins/account-plugins/empathy-accounts-plugin.c
6f79f87cf9dfd789dc6e27a9f211d66c6f3755bb
[empathy.git] / ubuntu-online-accounts / cc-plugins / account-plugins / empathy-accounts-plugin.c
1 /*
2  * empathy-accounts-plugin.c
3  *
4  * Copyright (C) 2012 Collabora Ltd. <http://www.collabora.co.uk/>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <tp-account-widgets/tpaw-uoa-utils.h>
24
25 #include "empathy-accounts-plugin.h"
26
27 #include "empathy-client-factory.h"
28
29 #include "empathy-accounts-plugin-widget.h"
30
31 G_DEFINE_TYPE (EmpathyAccountsPlugin, empathy_accounts_plugin, AP_TYPE_PLUGIN)
32
33 static void
34 widget_done_cb (EmpathyAccountsPluginWidget *widget,
35     ApPlugin *plugin)
36 {
37   ap_plugin_emit_finished (plugin);
38 }
39
40 static GtkWidget *
41 empathy_accounts_plugin_build_widget (ApPlugin *plugin)
42 {
43   AgAccount *account;
44   GtkWidget *widget;
45
46   account = ap_plugin_get_account (plugin);
47   tpaw_uoa_manager_set_default (ag_account_get_manager (account));
48
49   widget = empathy_accounts_plugin_widget_new (account);
50
51   g_signal_connect (widget, "done",
52       G_CALLBACK (widget_done_cb), plugin);
53
54   return widget;
55 }
56
57 static void
58 store_delete_cb (AgAccount *account,
59     const GError *error,
60     gpointer user_data)
61 {
62   GSimpleAsyncResult *result = user_data;
63
64   if (error != NULL)
65     {
66       g_debug ("Failed to delete account with ID '%u': %s",
67           account->id, error->message);
68
69       g_simple_async_result_set_from_error (result, error);
70     }
71
72   g_simple_async_result_complete (result);
73   g_object_unref (result);
74 }
75
76 static void
77 empathy_accounts_plugin_delete_account (ApPlugin *plugin,
78     GAsyncReadyCallback callback,
79     gpointer user_data)
80 {
81   AgAccount *account;
82   GSimpleAsyncResult *result;
83
84   result = g_simple_async_result_new (G_OBJECT (plugin),
85       callback, user_data, ap_plugin_delete_account);
86
87   account = ap_plugin_get_account (plugin);
88
89   ag_account_delete (account);
90   ag_account_store (account, store_delete_cb, result);
91 }
92
93 static void
94 empathy_accounts_plugin_act_headless (ApPlugin *plugin)
95 {
96 }
97
98 static void
99 empathy_accounts_plugin_class_init (
100     EmpathyAccountsPluginClass *klass)
101 {
102   ApPluginClass *pclass = AP_PLUGIN_CLASS (klass);
103
104   pclass->build_widget = empathy_accounts_plugin_build_widget;
105   pclass->delete_account = empathy_accounts_plugin_delete_account;
106   pclass->act_headless = empathy_accounts_plugin_act_headless;
107 }
108
109 static void
110 empathy_accounts_plugin_init (EmpathyAccountsPlugin *self)
111 {
112   if (tp_account_manager_can_set_default ())
113     {
114       EmpathyClientFactory *factory;
115       TpAccountManager *am;
116
117       factory = empathy_client_factory_dup ();
118       am = tp_account_manager_new_with_factory (
119           TP_SIMPLE_CLIENT_FACTORY (factory));
120       tp_account_manager_set_default (am);
121
122       g_object_unref (factory);
123       g_object_unref (am);
124     }
125
126 }
127
128 GType
129 ap_module_get_object_type (void)
130 {
131   return EMPATHY_TYPE_ACCOUNTS_PLUGIN;
132 }