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