Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / goa-mc-plugin / mcp-account-manager-goa.c
blobcdd3f6044e3c7f3eeec87f52701687a3b6fe4ffb
1 /*
2 * mcp-account-manager-goa.c
4 * McpAccountManagerGoa - a Mission Control plugin to expose GNOME Online
5 * Accounts with chat capabilities (e.g. Facebook) to Mission Control
7 * Copyright (C) 2010-2014 Collabora Ltd.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 * Authors:
23 * Danielle Madeley <danielle.madeley@collabora.co.uk>
26 #include "config.h"
27 #include "mcp-account-manager-goa.h"
29 #define GOA_API_IS_SUBJECT_TO_CHANGE /* awesome! */
30 #include <goa/goa.h>
32 #define DEBUG g_debug
33 #define GET_PRIVATE(self) (((McpAccountManagerGoa *) self)->priv)
34 #define DECLARE_GASYNC_CALLBACK(name) \
35 static void name (GObject *, GAsyncResult *, gpointer);
37 #define PLUGIN_NAME "goa"
38 #define PLUGIN_DESCRIPTION "Provide Telepathy Accounts from GOA"
39 #define PLUGIN_PROVIDER EMPATHY_GOA_PROVIDER
41 #define INITIAL_COMMENT "Parameters of GOA Telepathy accounts"
43 #ifdef MCP_API_VERSION_5_18
45 # define RESTRICTIONS TpStorageRestrictionFlags
46 # define WAS_CONST /* nothing */
47 /* Its historical value was based on the KEYRING priority which no longer
48 * exists. Using a large number is OK, because it uses unusual account names
49 * which are unlikely to collide. */
50 # define PLUGIN_PRIORITY (10010)
51 /* McpAccountStorageSetResult enum is defined by MC */
53 #else /* MC 5.16 or older */
55 # define RESTRICTIONS guint
56 # define WAS_CONST const
57 # define PLUGIN_PRIORITY (MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_KEYRING + 10)
59 /* we use this in helper functions */
60 typedef enum {
61 MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED,
62 MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED,
63 MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED
64 } McpAccountStorageSetResult;
66 #endif /* MC 5.16 or older */
68 static void account_storage_iface_init (McpAccountStorageIface *iface);
70 G_DEFINE_TYPE_WITH_CODE (McpAccountManagerGoa,
71 mcp_account_manager_goa,
72 G_TYPE_OBJECT,
73 G_IMPLEMENT_INTERFACE (MCP_TYPE_ACCOUNT_STORAGE,
74 account_storage_iface_init))
76 struct _McpAccountManagerGoaPrivate
78 gboolean ready;
80 GoaClient *client;
81 GHashTable *accounts; /* alloc'ed string -> ref'ed GoaObject */
83 GKeyFile *store;
84 gchar *filename;
88 static void
89 mcp_account_manager_goa_dispose (GObject *self)
91 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
93 tp_clear_object (&priv->client);
95 G_OBJECT_CLASS (mcp_account_manager_goa_parent_class)->dispose (self);
99 static void
100 mcp_account_manager_goa_finalize (GObject *self)
102 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
104 g_hash_table_unref (priv->accounts);
105 g_key_file_free (priv->store);
106 g_free (priv->filename);
108 G_OBJECT_CLASS (mcp_account_manager_goa_parent_class)->finalize (self);
112 static void
113 mcp_account_manager_goa_class_init (McpAccountManagerGoaClass *klass)
115 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
117 gobject_class->dispose = mcp_account_manager_goa_dispose;
118 gobject_class->finalize = mcp_account_manager_goa_finalize;
120 g_type_class_add_private (gobject_class,
121 sizeof (McpAccountManagerGoaPrivate));
124 static GHashTable *
125 get_tp_parameters (GoaAccount *account)
127 GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
128 NULL, g_free);
129 const char *type = goa_account_get_provider_type (account);
131 #define PARAM(key, value) g_hash_table_insert (params, key, g_strdup (value));
133 if (!tp_strdiff (type, "google"))
135 PARAM ("manager", "gabble");
136 PARAM ("protocol", "jabber");
137 PARAM ("Icon", "im-google-talk");
138 PARAM ("Service", "google-talk");
140 PARAM ("param-account", goa_account_get_identity (account));
141 PARAM ("param-server", "talk.google.com");
142 PARAM ("param-fallback-servers",
143 "talkx.l.google.com;"
144 "talkx.l.google.com:443,oldssl;"
145 "talkx.l.google.com:80");
146 PARAM ("param-extra-certificate-identities", "talk.google.com");
147 PARAM ("param-require-encryption", "true");
149 else
151 DEBUG ("Unknown account type %s", type);
152 g_hash_table_unref (params);
153 return NULL;
156 /* generic properties */
157 PARAM ("DisplayName", goa_account_get_presentation_identity (account));
159 #undef PARAM
161 return params;
165 static char *
166 get_tp_account_name (GoaAccount *account)
168 GHashTable *params = get_tp_parameters (account);
169 const char *type = goa_account_get_provider_type (account);
170 const char *id = goa_account_get_id (account);
171 char *name;
173 if (params == NULL)
174 return NULL;
176 name = g_strdup_printf ("%s/%s/goa_%s_%s",
177 (char *) g_hash_table_lookup (params, "manager"),
178 (char *) g_hash_table_lookup (params, "protocol"),
179 type, id);
181 g_hash_table_unref (params);
183 return name;
186 static void
187 object_chat_changed_cb (GoaObject *object,
188 GParamSpec *spec,
189 McpAccountManagerGoa *self)
191 GoaAccount *account = goa_object_peek_account (object);
192 char *name = get_tp_account_name (account);
193 gboolean enabled;
195 if (name == NULL)
196 return;
198 enabled = (goa_object_peek_chat (object) != NULL);
200 DEBUG ("%s %s", name, enabled ? "enabled" : "disabled");
202 if (self->priv->ready)
203 mcp_account_storage_emit_toggled (MCP_ACCOUNT_STORAGE (self),
204 name, enabled);
207 static void
208 _new_account (McpAccountManagerGoa *self,
209 GoaObject *object)
211 GoaAccount *account = goa_object_peek_account (object);
212 char *account_name = get_tp_account_name (account);
214 if (account_name == NULL)
215 return;
217 /* @account_name now is owned by the hash table */
218 g_hash_table_insert (self->priv->accounts, account_name,
219 g_object_ref (object));
221 if (self->priv->ready)
222 mcp_account_storage_emit_created (MCP_ACCOUNT_STORAGE (self),
223 account_name);
225 tp_g_signal_connect_object (object, "notify::chat",
226 G_CALLBACK (object_chat_changed_cb), self, 0);
230 DECLARE_GASYNC_CALLBACK (_goa_client_new_cb);
232 static void
233 load_store (McpAccountManagerGoa *self)
235 GError *error = NULL;
237 if (!g_key_file_load_from_file (self->priv->store, self->priv->filename,
238 G_KEY_FILE_KEEP_COMMENTS, &error))
240 gchar *dir;
242 DEBUG ("Failed to load keyfile, creating a new one: %s", error->message);
244 dir = g_path_get_dirname (self->priv->filename);
246 g_mkdir_with_parents (dir, 0700);
247 g_free (dir);
249 g_key_file_set_comment (self->priv->store, NULL, NULL, INITIAL_COMMENT,
250 NULL);
252 g_error_free (error);
256 static void
257 mcp_account_manager_goa_init (McpAccountManagerGoa *self)
259 DEBUG ("GOA MC plugin initialised");
261 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
262 MCP_TYPE_ACCOUNT_MANAGER_GOA, McpAccountManagerGoaPrivate);
264 #ifdef MCP_API_VERSION_5_18
265 /* the ready callback no longer exists, we may emit signals at any time */
266 self->priv->ready = TRUE;
267 #endif
269 self->priv->accounts = g_hash_table_new_full (g_str_hash, g_str_equal,
270 g_free, g_object_unref);
272 goa_client_new (NULL, _goa_client_new_cb, self);
274 /* key file store */
275 self->priv->store = g_key_file_new ();
276 self->priv->filename = g_build_filename (g_get_user_data_dir (), "telepathy",
277 "mission-control", "accounts-goa.cfg", NULL);
279 load_store (self);
283 static void
284 _account_added_cb (GoaClient *client,
285 GoaObject *object,
286 McpAccountManagerGoa *self)
288 _new_account (self, object);
292 static void
293 _account_removed_cb (GoaClient *client,
294 GoaObject *object,
295 McpAccountManagerGoa *self)
297 GoaAccount *account = goa_object_peek_account (object);
298 char *name = get_tp_account_name (account);
300 if (name == NULL)
301 return;
303 if (self->priv->ready)
304 mcp_account_storage_emit_deleted (MCP_ACCOUNT_STORAGE (self), name);
306 g_hash_table_remove (self->priv->accounts, name);
308 g_free (name);
311 static void
312 _goa_client_new_cb (GObject *obj,
313 GAsyncResult *result,
314 gpointer user_data)
316 McpAccountManagerGoa *self = user_data;
317 GList *accounts, *ptr;
318 GError *error = NULL;
320 self->priv->client = goa_client_new_finish (result, &error);
322 if (error != NULL)
324 DEBUG ("Failed to connect to GOA");
325 return;
328 accounts = goa_client_get_accounts (self->priv->client);
330 for (ptr = accounts; ptr != NULL; ptr = ptr->next)
332 _new_account (self, ptr->data);
335 g_list_free_full (accounts, g_object_unref);
337 g_signal_connect (self->priv->client, "account-added",
338 G_CALLBACK (_account_added_cb), self);
339 g_signal_connect (self->priv->client, "account-removed",
340 G_CALLBACK (_account_removed_cb), self);
344 static GList *
345 mcp_account_manager_goa_list (WAS_CONST McpAccountStorage *self,
346 WAS_CONST McpAccountManager *am)
348 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
349 GList *accounts = NULL;
350 GHashTableIter iter;
351 gpointer key;
353 DEBUG (G_STRFUNC);
355 g_hash_table_iter_init (&iter, priv->accounts);
356 while (g_hash_table_iter_next (&iter, &key, NULL))
357 accounts = g_list_prepend (accounts, g_strdup (key));
359 return accounts;
363 #ifdef MCP_API_VERSION_5_18
365 static GVariant *
366 get_item (McpAccountManagerGoa *self,
367 McpAccountManager *am,
368 const gchar *acc,
369 const gchar *key,
370 const GVariantType *type)
372 GoaObject *object;
373 GoaAccount *account;
374 GHashTable *bits;
375 gchar *esc;
376 GVariant *ret = NULL;
378 DEBUG ("%s: %s, %s", G_STRFUNC, acc, key);
380 object = g_hash_table_lookup (self->priv->accounts, acc);
382 g_return_val_if_fail (object != NULL, NULL);
384 account = goa_object_peek_account (object);
386 g_return_val_if_fail (account != NULL, NULL);
388 if (!tp_strdiff (key, "Enabled"))
390 return g_variant_ref_sink (g_variant_new_boolean (
391 !goa_account_get_chat_disabled (account)));
394 bits = get_tp_parameters (account);
396 esc = g_hash_table_lookup (bits, key);
398 if (esc == NULL)
399 esc = g_key_file_get_value (self->priv->store, acc, key, NULL);
400 else
401 esc = g_strdup (esc);
403 if (esc != NULL)
405 ret = mcp_account_manager_unescape_variant_from_keyfile (am,
406 esc, type, NULL);
408 g_free (esc);
411 g_hash_table_unref (bits);
412 return ret;
415 static GVariant *
416 mcp_account_manager_goa_get_attribute (McpAccountStorage *self,
417 McpAccountManager *am,
418 const gchar *acc,
419 const gchar *attribute,
420 const GVariantType *type,
421 McpAttributeFlags *flags)
423 return get_item (MCP_ACCOUNT_MANAGER_GOA (self), am, acc, attribute, type);
426 static GVariant *
427 mcp_account_manager_goa_get_parameter (McpAccountStorage *storage,
428 McpAccountManager *am,
429 const gchar *acc,
430 const gchar *parameter,
431 const GVariantType *type,
432 McpParameterFlags *flags)
434 gchar *key;
435 GVariant *ret;
437 key = g_strdup_printf ("param-%s", parameter);
439 ret = get_item (MCP_ACCOUNT_MANAGER_GOA (storage), am, acc, key, type);
440 g_free (key);
441 return ret;
444 #else /* MC 5.16 or older */
446 static void
447 get_enabled (WAS_CONST McpAccountStorage *self,
448 WAS_CONST McpAccountManager *am,
449 const gchar *acc,
450 GoaAccount *account)
452 mcp_account_manager_set_value (am, acc, "Enabled",
453 goa_account_get_chat_disabled (account) == FALSE ? "true" : "false");
456 static gboolean
457 mcp_account_manager_goa_get (WAS_CONST McpAccountStorage *self,
458 WAS_CONST McpAccountManager *am,
459 const gchar *acc,
460 const gchar *key)
462 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
463 GoaObject *object;
464 GoaAccount *account;
466 DEBUG ("%s: %s, %s", G_STRFUNC, acc, key);
468 object = g_hash_table_lookup (priv->accounts, acc);
470 if (object == NULL)
471 return FALSE;
473 account = goa_object_peek_account (object);
475 if (account == NULL)
476 return FALSE;
478 if (key == NULL)
480 /* load all keys */
481 GHashTable *params = get_tp_parameters (account);
482 GHashTableIter iter;
483 gpointer k, value;
484 GStrv keys;
485 guint i;
486 gsize nkeys = 0;
488 /* Properties from GOA */
489 g_hash_table_iter_init (&iter, params);
490 while (g_hash_table_iter_next (&iter, &k, &value))
491 mcp_account_manager_set_value (am, acc, k, value);
493 g_hash_table_unref (params);
495 /* Stored properties */
496 keys = g_key_file_get_keys (priv->store, acc, &nkeys, NULL);
498 for (i = 0; i < nkeys; i++)
500 gchar *v = g_key_file_get_value (priv->store, acc, keys[i], NULL);
502 if (v != NULL)
504 mcp_account_manager_set_value (am, acc, keys[i], v);
505 g_free (v);
509 g_strfreev (keys);
511 /* Enabled */
512 get_enabled (self, am, acc, account);
514 else if (!tp_strdiff (key, "Enabled"))
516 get_enabled (self, am, acc, account);
518 else
520 /* get a specific key */
521 GHashTable *params = get_tp_parameters (account);
522 gchar *value;
524 value = g_hash_table_lookup (params, key);
526 if (value == NULL)
527 value = g_key_file_get_value (priv->store, acc, key, NULL);
528 else
529 value = g_strdup (value);
531 mcp_account_manager_set_value (am, acc, key, value);
533 g_hash_table_unref (params);
534 g_free (value);
537 return TRUE;
540 #endif /* MC 5.16 or older */
543 static gboolean
544 account_is_in_goa (WAS_CONST McpAccountStorage *self,
545 const gchar *account)
547 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
549 return (g_hash_table_lookup (priv->accounts, account) != NULL);
552 static McpAccountStorageSetResult
553 mcp_account_manager_goa_set_enabled (McpAccountStorage *self,
554 const gchar *account,
555 gboolean enabled)
557 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
558 GoaObject *object;
559 GoaAccount *acc;
561 object = g_hash_table_lookup (priv->accounts, account);
563 if (object == NULL)
564 return MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
566 acc = goa_object_peek_account (object);
568 if (acc == NULL)
569 return MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
571 if (goa_account_get_chat_disabled (acc) == !enabled)
572 return MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED;
574 goa_account_set_chat_disabled (acc, !enabled);
575 return MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED;
578 #ifdef MCP_API_VERSION_5_18
580 static McpAccountStorageSetResult
581 mcp_account_manager_goa_set_attribute (McpAccountStorage *storage,
582 McpAccountManager *am,
583 const gchar *account_name,
584 const gchar *attribute,
585 GVariant *value,
586 McpAttributeFlags flags)
588 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (storage);
589 McpAccountStorageSetResult ret = MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
591 g_return_val_if_fail (account_is_in_goa (storage, account_name),
592 MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
594 if (!tp_strdiff (attribute, "Enabled"))
596 g_return_val_if_fail (
597 g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN,
598 MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
600 return mcp_account_manager_goa_set_enabled (storage, account_name,
601 g_variant_get_boolean (value));
603 /* FIXME: filter out manager, protocol, Icon, Service? */
604 else if (value != NULL)
606 gchar *esc = mcp_account_manager_escape_variant_for_keyfile (am,
607 value);
608 gchar *old;
610 if (esc == NULL)
611 return MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
613 old = g_key_file_get_value (priv->store, account_name, attribute, NULL);
615 if (tp_strdiff (old, esc))
617 g_key_file_set_value (priv->store, account_name, attribute, esc);
618 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED;
620 else
622 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED;
625 g_free (esc);
626 g_free (old);
628 else
630 if (g_key_file_has_key (priv->store, account_name, attribute, NULL))
632 g_key_file_remove_key (priv->store, account_name, attribute, NULL);
633 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED;
635 else
637 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED;
641 return ret;
644 static McpAccountStorageSetResult
645 mcp_account_manager_goa_set_parameter (McpAccountStorage *storage,
646 McpAccountManager *am,
647 const gchar *account_name,
648 const gchar *parameter,
649 GVariant *value,
650 McpParameterFlags flags)
652 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (storage);
653 McpAccountStorageSetResult ret = MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED;
654 gchar *key = NULL;
655 gchar *esc = NULL;
656 gchar *old = NULL;
658 g_return_val_if_fail (account_is_in_goa (storage, account_name),
659 MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED);
661 key = g_strdup_printf ("param-%s", parameter);
663 /* FIXME: filter out reserved keys for this account? */
664 if (value != NULL)
666 esc = mcp_account_manager_escape_variant_for_keyfile (am,
667 value);
669 if (esc == NULL)
670 goto out;
672 old = g_key_file_get_value (priv->store, account_name, key, NULL);
674 if (tp_strdiff (esc, old))
676 g_key_file_set_value (priv->store, account_name, key, esc);
677 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED;
679 else
681 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED;
684 else
686 if (g_key_file_has_key (priv->store, account_name, key, NULL))
688 g_key_file_remove_key (priv->store, account_name, key, NULL);
689 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_CHANGED;
691 else
693 ret = MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED;
698 out:
699 g_free (key);
700 g_free (esc);
701 g_free (old);
702 return ret;
705 #else /* MC 5.16 or older */
707 static gboolean
708 mcp_account_manager_goa_set (const McpAccountStorage *self,
709 const McpAccountManager *am,
710 const gchar *account,
711 const gchar *key,
712 const gchar *val)
714 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
716 if (!account_is_in_goa (self, account))
717 return FALSE;
719 DEBUG ("%s: (%s, %s, %s)", G_STRFUNC, account, key, val);
721 if (!tp_strdiff (key, "Enabled"))
723 if (mcp_account_manager_goa_set_enabled ((McpAccountStorage *) self,
724 account,
725 !tp_strdiff (val, "true")) != MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED)
726 return TRUE;
727 else
728 return FALSE;
731 if (val != NULL)
732 g_key_file_set_value (priv->store, account, key, val);
733 else
734 g_key_file_remove_key (priv->store, account, key, NULL);
736 /* Pretend we save everything so MC won't save this in accounts.cfg */
737 return TRUE;
740 #endif /* MC 5.16 or older */
743 static gboolean
744 mcp_account_manager_goa_delete (WAS_CONST McpAccountStorage *self,
745 WAS_CONST McpAccountManager *am,
746 const gchar *account,
747 const gchar *key)
749 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
751 if (!account_is_in_goa (self, account))
752 return FALSE;
754 DEBUG ("%s: (%s, %s)", G_STRFUNC, account, key);
756 if (key == NULL)
758 g_key_file_remove_group (priv->store, account, NULL);
760 else
762 g_key_file_remove_key (priv->store, account, key, NULL);
765 /* Pretend we deleted everything */
766 return TRUE;
770 #ifdef MCP_API_VERSION_5_18
771 static void
772 mcp_account_manager_goa_delete_async (McpAccountStorage *self,
773 McpAccountManager *am,
774 const gchar *account_name,
775 GCancellable *cancellable,
776 GAsyncReadyCallback callback,
777 gpointer user_data)
779 GTask *task = g_task_new (self, cancellable, callback, user_data);
781 if (mcp_account_manager_goa_delete (self, am, account_name, NULL))
783 g_task_return_boolean (task, TRUE);
785 else
787 g_task_return_new_error (task, TP_ERROR, TP_ERROR_DOES_NOT_EXIST,
788 "Account does not exist in GOA");
791 g_object_unref (task);
794 static gboolean
795 mcp_account_manager_goa_delete_finish (McpAccountStorage *self,
796 GAsyncResult *res,
797 GError **error)
799 return g_task_propagate_boolean (G_TASK (res), error);
801 #endif /* MC >= 5.18 API */
803 static gboolean
804 commit (McpAccountManagerGoa *self)
806 McpAccountManagerGoaPrivate *priv = self->priv;
807 gchar *data;
808 gsize len;
809 GError *error = NULL;
811 DEBUG ("Save config to %s", priv->filename);
813 data = g_key_file_to_data (priv->store, &len, &error);
814 if (data == NULL)
816 DEBUG ("Failed to get data from store: %s", error->message);
818 g_error_free (error);
819 return FALSE;
822 if (!g_file_set_contents (priv->filename, data, len, &error))
824 DEBUG ("Failed to write file: %s", error->message);
826 g_free (data);
827 g_error_free (error);
828 return FALSE;
831 g_free (data);
833 return TRUE;
836 #ifdef MCP_API_VERSION_5_18
837 static gboolean
838 mcp_account_manager_goa_commit (McpAccountStorage *self,
839 McpAccountManager *am,
840 const gchar *account)
842 return commit (MCP_ACCOUNT_MANAGER_GOA (self));
844 #else
845 static gboolean
846 mcp_account_manager_goa_commit (const McpAccountStorage *self,
847 const McpAccountManager *am)
849 return commit (MCP_ACCOUNT_MANAGER_GOA (self));
851 #endif
854 #ifndef MCP_API_VERSION_5_18
855 /* removed in 5.18, MC should now be ready to receive signals at any time */
856 static void
857 mcp_account_manager_goa_ready (WAS_CONST McpAccountStorage *self,
858 WAS_CONST McpAccountManager *am)
860 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
862 priv->ready = TRUE;
864 #endif
867 static RESTRICTIONS
868 mcp_account_manager_goa_get_restrictions (WAS_CONST McpAccountStorage *self,
869 const gchar *account)
871 return TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS |
872 TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_SERVICE;
876 static void
877 mcp_account_manager_goa_get_identifier (WAS_CONST McpAccountStorage *self,
878 const gchar *acc,
879 GValue *identifier)
881 McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
882 GoaObject *object;
883 GoaAccount *account;
885 object = g_hash_table_lookup (priv->accounts, acc);
886 g_return_if_fail (object != NULL);
888 account = goa_object_peek_account (object);
889 g_return_if_fail (account != NULL);
891 g_value_init (identifier, G_TYPE_STRING);
892 g_value_set_string (identifier, goa_account_get_id (account));
896 static void
897 account_storage_iface_init (McpAccountStorageIface *iface)
899 iface->name = PLUGIN_NAME;
900 iface->desc = PLUGIN_DESCRIPTION;
901 iface->priority = PLUGIN_PRIORITY;
902 iface->provider = PLUGIN_PROVIDER;
904 #define IMPLEMENT(x) iface->x = mcp_account_manager_goa_##x
906 IMPLEMENT (list);
907 IMPLEMENT (commit);
908 IMPLEMENT (get_restrictions);
909 IMPLEMENT (get_identifier);
911 #ifdef MCP_API_VERSION_5_18
912 IMPLEMENT (delete_async);
913 IMPLEMENT (delete_finish);
914 IMPLEMENT (get_attribute);
915 IMPLEMENT (get_parameter);
916 IMPLEMENT (set_attribute);
917 IMPLEMENT (set_parameter);
918 #else
919 IMPLEMENT (get);
920 IMPLEMENT (set);
921 IMPLEMENT (delete);
922 IMPLEMENT (ready);
923 #endif
925 #undef IMPLEMENT