1 /*
2 * storage-ag-hidden.c - account backend for "magic" hidden accounts using
3 * accounts-glib
4 * Copyright ©2011 Collabora Ltd.
5 * Copyright ©2011 Nokia Corporation
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config.h"
23
24 #include "mcd-storage-ag-hidden.h"
25
26 #include <telepathy-glib/telepathy-glib.h>
27
28 #include "mcd-debug.h"
29 /* FIXME: if we weren't in-tree, we wouldn't be able to include this header and
30 * we'd have to re-hardcode magic strings like "Hidden".
31 */
32 #include "mcd-account-config.h"
33
34 static void account_storage_iface_init (
35 McpAccountStorageIface *iface,
36 gpointer unused G_GNUC_UNUSED);
37
38 G_DEFINE_TYPE_WITH_CODE (McdStorageAgHidden, mcd_storage_ag_hidden,
39 MCD_TYPE_ACCOUNT_MANAGER_SSO,
40 G_IMPLEMENT_INTERFACE (MCP_TYPE_ACCOUNT_STORAGE,
41 account_storage_iface_init);
42 );
43
44 static void
mcd_storage_ag_hidden_init(McdStorageAgHidden * self)45 mcd_storage_ag_hidden_init (McdStorageAgHidden *self)
46 {
47 }
48
49 static void
mcd_storage_ag_hidden_class_init(McdStorageAgHiddenClass * klass)50 mcd_storage_ag_hidden_class_init (McdStorageAgHiddenClass *klass)
51 {
52 McdAccountManagerSsoClass *super = MCD_ACCOUNT_MANAGER_SSO_CLASS (klass);
53
54 super->service_type = ACCOUNTS_GLIB_HIDDEN_SERVICE_TYPE;
55 }
56
57 static gboolean
_mcd_storage_ag_hidden_get(const McpAccountStorage * self,const McpAccountManager * am,const gchar * account_suffix,const gchar * key)58 _mcd_storage_ag_hidden_get (
59 const McpAccountStorage *self,
60 const McpAccountManager *am,
61 const gchar *account_suffix,
62 const gchar *key)
63 {
64 /* Chain up to the real implementation, checking whether this is an account
65 * we care about in the process.
66 */
67 if (!_mcd_account_manager_sso_get (self, am, account_suffix, key))
68 return FALSE;
69
70 /* If the caller is looking for the "Hidden" key (or NULL, which means
71 * everything), let's fill it in. (Every account this plugin cares about
72 * should be hidden.)
73 */
74 if (key == NULL || !tp_strdiff (key, MC_ACCOUNTS_KEY_HIDDEN))
75 mcp_account_manager_set_value (am, account_suffix, MC_ACCOUNTS_KEY_HIDDEN,
76 "true");
77
78 return TRUE;
79 }
80
81 static void
account_storage_iface_init(McpAccountStorageIface * iface,gpointer unused G_GNUC_UNUSED)82 account_storage_iface_init (
83 McpAccountStorageIface *iface,
84 gpointer unused G_GNUC_UNUSED)
85 {
86 mcp_account_storage_iface_set_name (iface,
87 "maemo-libaccounts-hidden");
88 mcp_account_storage_iface_set_desc (iface,
89 "Loads accounts with service type '" ACCOUNTS_GLIB_HIDDEN_SERVICE_TYPE
90 "' from accounts-glib, and marks them as Hidden");
91 mcp_account_storage_iface_implement_get (iface,
92 _mcd_storage_ag_hidden_get);
93 }
94
95 McdStorageAgHidden *
mcd_storage_ag_hidden_new()96 mcd_storage_ag_hidden_new ()
97 {
98 return g_object_new (MCD_TYPE_STORAGE_AG_HIDDEN, NULL);
99 }
100