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