diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-09-10 19:01:14 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-09-12 14:24:11 +0100 |
commit | 8b602c52b9e2007740309ad1c84eaf2966143135 (patch) | |
tree | 85b104c10456dfc6ea49e46c2c39f7000d45ecf0 | |
parent | 4efea11d2ed33a92f6ef05a954acfb180083531d (diff) |
Let storage plugins receive new values as GVariants
-rw-r--r-- | mission-control-plugins/account-storage.c | 133 | ||||
-rw-r--r-- | mission-control-plugins/account-storage.h | 35 | ||||
-rw-r--r-- | mission-control-plugins/mission-control-plugins.h | 1 | ||||
-rw-r--r-- | src/mcd-storage.c | 21 |
4 files changed, 186 insertions, 4 deletions
diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c index 59871d5b..92af6de3 100644 --- a/mission-control-plugins/account-storage.c +++ b/mission-control-plugins/account-storage.c @@ -68,6 +68,8 @@ * iface->get_restrictions = foo_plugin_get_restrictions; * iface->create = foo_plugin_create; * iface->owns = foo_plugin_owns; + * iface->set_attribute = foo_plugin_set_attribute; + * iface->set_parameter = foo_plugin_set_parameter; * } * </programlisting></example> * @@ -112,6 +114,38 @@ enum static guint signals[NO_SIGNAL] = { 0 }; static gboolean +default_set (const McpAccountStorage *storage, + const McpAccountManager *am, + const gchar *account, + const gchar *key, + const gchar *val) +{ + return FALSE; +} + +static gboolean +default_set_attribute (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *attribute, + GVariant *value, + McpAttributeFlags flags) +{ + return FALSE; +} + +static gboolean +default_set_parameter (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *parameter, + GVariant *value, + McpParameterFlags flags) +{ + return FALSE; +} + +static gboolean default_owns (McpAccountStorage *storage, McpAccountManager *am, const gchar *account) @@ -132,6 +166,9 @@ class_init (gpointer klass, McpAccountStorageIface *iface = klass; iface->owns = default_owns; + iface->set = default_set; + iface->set_attribute = default_set_attribute; + iface->set_parameter = default_set_parameter; if (signals[CREATED] != 0) { @@ -525,7 +562,7 @@ mcp_account_storage_get (const McpAccountStorage *storage, * @account: the unique name of the account * @key: the non-%NULL setting whose value we wish to store: either an * attribute like "DisplayName", or "param-" plus a parameter like "account" - * @value: a non-%NULL value to associate with @key + * @value: a value to associate with @key, escaped as if for a #GKeyFile * * The plugin is expected to either quickly and synchronously * update its internal cache of values with @value, or to @@ -536,7 +573,11 @@ mcp_account_storage_get (const McpAccountStorage *storage, * mcp_account_storage_commit() or mcp_account_storage_commit_one() * after a short delay. * - * Returns: %TRUE if the setting was claimed, %FALSE otherwise + * Plugins that implement mcp_storage_set_attribute() and + * mcp_account_storage_set_parameter() can just return %FALSE here. + * There is a default implementation, which just returns %FALSE. + * + * Returns: %TRUE if the attribute was claimed, %FALSE otherwise */ gboolean mcp_account_storage_set (const McpAccountStorage *storage, @@ -554,6 +595,94 @@ mcp_account_storage_set (const McpAccountStorage *storage, } /** + * mcp_account_storage_set_attribute: + * @storage: an #McpAccountStorage instance + * @am: an #McpAccountManager instance + * @account: the unique name of the account + * @attribute: the name of an attribute, e.g. "DisplayName" + * @value: a value to associate with @attribute + * @flags: flags influencing how the attribute is to be stored + * + * Store an attribute. + * + * The plugin is expected to either quickly and synchronously + * update its internal cache of values with @value, or to + * decline to store the attribute. + * + * The plugin is not expected to write to its long term storage + * at this point. + * + * There is a default implementation, which just returns %FALSE. + * Mission Control will call mcp_account_storage_set() instead, + * using a keyfile-escaped version of @value. + * + * Returns: %TRUE if the attribute was claimed, %FALSE otherwise + * + * Since: 5.13.UNRELEASED + */ +gboolean +mcp_account_storage_set_attribute (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *attribute, + GVariant *value, + McpAttributeFlags flags) +{ + McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage); + + SDEBUG (storage, ""); + g_return_val_if_fail (iface != NULL, FALSE); + g_return_val_if_fail (iface->set_attribute != NULL, FALSE); + + return iface->set_attribute (storage, am, account, attribute, value, flags); +} + +/** + * mcp_account_storage_set_parameter: + * @storage: an #McpAccountStorage instance + * @am: an #McpAccountManager instance + * @account: the unique name of the account + * @parameter: the name of a parameter, e.g. "account" (note that there + * is no "param-" prefix here) + * @value: a value to associate with @parameter + * @flags: flags influencing how the parameter is to be stored + * + * Store a parameter. + * + * The plugin is expected to either quickly and synchronously + * update its internal cache of values with @value, or to + * decline to store the parameter. + * + * The plugin is not expected to write to its long term storage + * at this point. + * + * There is a default implementation, which just returns %FALSE. + * Mission Control will call mcp_account_storage_set() instead, + * using "param-" + @parameter as key and a keyfile-escaped version + * of @value as value. + * + * Returns: %TRUE if the parameter was claimed, %FALSE otherwise + * + * Since: 5.13.UNRELEASED + */ +gboolean +mcp_account_storage_set_parameter (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *parameter, + GVariant *value, + McpParameterFlags flags) +{ + McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage); + + SDEBUG (storage, ""); + g_return_val_if_fail (iface != NULL, FALSE); + g_return_val_if_fail (iface->set_parameter != NULL, FALSE); + + return iface->set_parameter (storage, am, account, parameter, value, flags); +} + +/** * McpAccountStorageCreate: * @storage: an #McpAccountStorage instance * @am: an object which can be used to call back into the account manager diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h index ef19fd62..a0054112 100644 --- a/mission-control-plugins/account-storage.h +++ b/mission-control-plugins/account-storage.h @@ -32,6 +32,15 @@ G_BEGIN_DECLS #define MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_NORMAL 100 #define MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_KEYRING 10000 +typedef enum { + MCP_PARAMETER_FLAG_NONE = 0, + MCP_PARAMETER_FLAG_SECRET = TP_CONN_MGR_PARAM_FLAG_SECRET +} McpParameterFlags; + +typedef enum { + MCP_ATTRIBUTE_FLAG_NONE = 0 +} McpAttributeFlags; + /* API for plugins to implement */ typedef struct _McpAccountStorage McpAccountStorage; typedef struct _McpAccountStorageIface McpAccountStorageIface; @@ -132,6 +141,18 @@ struct _McpAccountStorageIface gboolean (*owns) (McpAccountStorage *storage, McpAccountManager *am, const gchar *account); + gboolean (*set_attribute) (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *attribute, + GVariant *val, + McpAttributeFlags flags); + gboolean (*set_parameter) (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *parameter, + GVariant *val, + McpParameterFlags flags); }; #ifndef __GTK_DOC_IGNORE__ @@ -256,6 +277,20 @@ const gchar *mcp_account_storage_provider (const McpAccountStorage *storage); gboolean mcp_account_storage_owns (McpAccountStorage *storage, McpAccountManager *am, const gchar *account); + +gboolean mcp_account_storage_set_attribute (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *attribute, + GVariant *value, + McpAttributeFlags flags); +gboolean mcp_account_storage_set_parameter (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account, + const gchar *parameter, + GVariant *value, + McpParameterFlags flags); + void mcp_account_storage_emit_created (McpAccountStorage *storage, const gchar *account); G_DEPRECATED_FOR (something that is actually implemented) diff --git a/mission-control-plugins/mission-control-plugins.h b/mission-control-plugins/mission-control-plugins.h index 8b6d9c8e..fe0d8afb 100644 --- a/mission-control-plugins/mission-control-plugins.h +++ b/mission-control-plugins/mission-control-plugins.h @@ -23,6 +23,7 @@ #define MCP_MISSION_CONTROL_PLUGINS_H #include <glib-object.h> +#include <telepathy-glib/telepathy-glib.h> #define _MCP_IN_MISSION_CONTROL_PLUGINS_H #include <mission-control-plugins/account.h> diff --git a/src/mcd-storage.c b/src/mcd-storage.c index 6b5e5e67..4306a2fd 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -1316,11 +1316,13 @@ static void update_storage (McdStorage *self, const gchar *account, const gchar *key, + GVariant *variant, const gchar *escaped, gboolean secret) { GList *store; gboolean done = FALSE; + gboolean parameter = g_str_has_prefix (key, "param-"); McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); if (secret) @@ -1341,6 +1343,21 @@ update_storage (McdStorage *self, DEBUG ("MCP:%s -> delete %s.%s", pn, account, key); mcp_account_storage_delete (plugin, ma, account, key); } + else if (variant != NULL && !parameter && + mcp_account_storage_set_attribute (plugin, ma, account, key, variant, + MCP_ATTRIBUTE_FLAG_NONE)) + { + done = TRUE; + DEBUG ("MCP:%s -> store attribute %s.%s", pn, account, key); + } + else if (variant != NULL && parameter && + mcp_account_storage_set_parameter (plugin, ma, account, key + 6, + variant, + secret ? MCP_PARAMETER_FLAG_SECRET : MCP_PARAMETER_FLAG_NONE)) + { + done = TRUE; + DEBUG ("MCP:%s -> store parameter %s.%s", pn, account, key); + } else { done = mcp_account_storage_set (plugin, ma, account, key, escaped); @@ -1453,7 +1470,7 @@ mcd_storage_set_attribute (McdStorage *self, if (value != NULL) escaped = mcd_keyfile_escape_value (value); - update_storage (self, account, attribute, escaped, FALSE); + update_storage (self, account, attribute, new_v, escaped, FALSE); g_free (escaped); updated = TRUE; } @@ -1528,7 +1545,7 @@ mcd_storage_set_parameter (McdStorage *self, g_variant_ref (new_v)); g_snprintf (key, sizeof (key), "param-%s", parameter); - update_storage (self, account, key, new_escaped, secret); + update_storage (self, account, key, new_v, new_escaped, secret); return TRUE; } |