[Pkg-telepathy-commits] [telepathy-mission-control-6] 127/280: Revert "Remove mcp_account_storage_set()"
Simon McVittie
smcv at debian.org
Thu Mar 27 20:07:14 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository telepathy-mission-control-6.
commit bdf7c51b8ab76917a46714df784e838f323938cb
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue Nov 12 15:37:25 2013 +0000
Revert "Remove mcp_account_storage_set()"
This reverts commit e9a9dd37bd193d8ac16729671d2296a4aa96139c.
---
mission-control-plugins/account-storage.c | 78 +++++++++++++++++++++++++++++--
mission-control-plugins/account-storage.h | 13 ++++++
src/mcd-account-manager-default.c | 11 +++++
src/mcd-storage.c | 46 +++++++++++++-----
tests/twisted/dbus-account-plugin.c | 13 ++++++
tests/twisted/mcp-account-diversion.c | 48 +++----------------
6 files changed, 152 insertions(+), 57 deletions(-)
diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index a5b89f0..0d7c932 100644
--- a/mission-control-plugins/account-storage.c
+++ b/mission-control-plugins/account-storage.c
@@ -57,6 +57,7 @@
* iface->provider = "org.freedesktop.Telepathy.MissionControl5.FooStorage";
*
* iface->get = foo_plugin_get;
+ * iface->set = foo_plugin_get;
* iface->delete = foo_plugin_delete;
* iface->commit = foo_plugin_commit;
* iface->list = foo_plugin_list;
@@ -110,6 +111,16 @@ 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,
@@ -197,6 +208,7 @@ class_init (gpointer klass,
GType type = G_TYPE_FROM_CLASS (klass);
McpAccountStorageIface *iface = klass;
+ iface->set = default_set;
iface->set_attribute = default_set_attribute;
iface->set_parameter = default_set_parameter;
iface->create = default_create;
@@ -462,6 +474,59 @@ mcp_account_storage_get (const McpAccountStorage *storage,
}
/**
+ * McpAccountStorageSetFunc:
+ * @storage: an #McpAccountStorage instance
+ * @am: an #McpAccountManager instance
+ * @account: the unique name of the account
+ * @key: the setting whose value we wish to store: either an attribute
+ * like "DisplayName", or "param-" plus a parameter like "account"
+ * @val: a non-%NULL value for @key
+ *
+ * An implementation of mcp_account_storage_set().
+ *
+ * Returns: %TRUE if @storage is responsible for @account
+ */
+
+/**
+ * mcp_account_storage_set:
+ * @storage: an #McpAccountStorage instance
+ * @am: an #McpAccountManager instance
+ * @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 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
+ * decline to store the setting.
+ *
+ * The plugin is not expected to write to its long term storage
+ * at this point. It can expect Mission Control to call
+ * mcp_account_storage_commit() after a short delay.
+ *
+ * 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,
+ const McpAccountManager *am,
+ const gchar *account,
+ const gchar *key,
+ const gchar *value)
+{
+ 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 != NULL, FALSE);
+
+ return iface->set (storage, am, account, key, value);
+}
+
+/**
* mcp_account_storage_set_attribute:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
@@ -479,8 +544,9 @@ mcp_account_storage_get (const McpAccountStorage *storage,
* The plugin is not expected to write to its long term storage
* at this point.
*
- * There is a default implementation, which just returns %FALSE for read-only
- * storage plugins.
+ * 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
*
@@ -522,8 +588,10 @@ mcp_account_storage_set_attribute (McpAccountStorage *storage,
* The plugin is not expected to write to its long term storage
* at this point.
*
- * There is a default implementation, which just returns %FALSE for read-only
- * storage plugins.
+ * 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
*
@@ -958,7 +1026,7 @@ mcp_account_storage_provider (const McpAccountStorage *storage)
}
/**
- * mcp_account_storage_emit_created:
+ * mcp_account_storage_emit_create:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the created account
*
diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h
index 1a3a012..14ec577 100644
--- a/mission-control-plugins/account-storage.h
+++ b/mission-control-plugins/account-storage.h
@@ -64,6 +64,12 @@ typedef gboolean (*McpAccountStorageGetFunc) (
const McpAccountManager *am,
const gchar *account,
const gchar *key);
+typedef gboolean (*McpAccountStorageSetFunc) (
+ const McpAccountStorage *storage,
+ const McpAccountManager *am,
+ const gchar *account,
+ const gchar *key,
+ const gchar *val);
typedef gchar * (*McpAccountStorageCreate) (
const McpAccountStorage *storage,
const McpAccountManager *am,
@@ -106,6 +112,7 @@ struct _McpAccountStorageIface
const gchar *desc;
const gchar *provider;
+ McpAccountStorageSetFunc set;
McpAccountStorageGetFunc get;
McpAccountStorageDeleteFunc delete;
McpAccountStorageListFunc list;
@@ -139,6 +146,12 @@ gboolean mcp_account_storage_get (const McpAccountStorage *storage,
const gchar *account,
const gchar *key);
+gboolean mcp_account_storage_set (const McpAccountStorage *storage,
+ const McpAccountManager *am,
+ const gchar *account,
+ const gchar *key,
+ const gchar *value);
+
gchar * mcp_account_storage_create (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *manager,
diff --git a/src/mcd-account-manager-default.c b/src/mcd-account-manager-default.c
index e967b73..515cdbd 100644
--- a/src/mcd-account-manager-default.c
+++ b/src/mcd-account-manager-default.c
@@ -215,6 +215,16 @@ set_attribute (McpAccountStorage *self,
}
static gboolean
+_set (const McpAccountStorage *self,
+ const McpAccountManager *am,
+ const gchar *account,
+ const gchar *key,
+ const gchar *val)
+{
+ return FALSE;
+}
+
+static gboolean
get_parameter (const McpAccountStorage *self,
const McpAccountManager *am,
const gchar *account,
@@ -1000,6 +1010,7 @@ account_storage_iface_init (McpAccountStorageIface *iface,
iface->priority = PLUGIN_PRIORITY;
iface->get = _get;
+ iface->set = _set;
iface->set_attribute = set_attribute;
iface->set_parameter = set_parameter;
iface->create = _create;
diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index 7fc7254..c31dc2e 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -1492,7 +1492,8 @@ static void
update_storage (McdStorage *self,
const gchar *account,
const gchar *key,
- GVariant *variant)
+ GVariant *variant,
+ const gchar *escaped)
{
McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self);
gboolean parameter = g_str_has_prefix (key, "param-");
@@ -1503,22 +1504,29 @@ update_storage (McdStorage *self,
g_return_if_fail (sa != NULL);
pn = mcp_account_storage_name (sa->storage);
- if (variant == NULL)
+ if (escaped == NULL)
{
DEBUG ("MCP:%s -> delete %s.%s", pn, account, key);
mcp_account_storage_delete (sa->storage, ma, account, key);
}
- else if (parameter)
+ else if (variant != NULL && !parameter &&
+ mcp_account_storage_set_attribute (sa->storage, ma, account, key, variant,
+ MCP_ATTRIBUTE_FLAG_NONE))
{
- DEBUG ("MCP:%s -> store parameter %s.%s", pn, account, key);
+ DEBUG ("MCP:%s -> store attribute %s.%s", pn, account, key);
+ }
+ else if (variant != NULL && parameter &&
mcp_account_storage_set_parameter (sa->storage, ma, account, key + 6,
- variant, MCP_PARAMETER_FLAG_NONE);
+ variant, MCP_PARAMETER_FLAG_NONE))
+ {
+ DEBUG ("MCP:%s -> store parameter %s.%s", pn, account, key);
}
else
{
- DEBUG ("MCP:%s -> store attribute %s.%s", pn, account, key);
- mcp_account_storage_set_attribute (sa->storage, ma, account, key,
- variant, MCP_PARAMETER_FLAG_NONE);
+ gboolean done;
+
+ done = mcp_account_storage_set (sa->storage, ma, account, key, escaped);
+ DEBUG ("MCP:%s -> %s %s.%s", pn, done ? "store" : "ignore", account, key);
}
}
@@ -1612,6 +1620,8 @@ mcd_storage_set_attribute (McdStorage *self,
if (!mcd_nullable_variant_equal (old_v, new_v))
{
+ gchar *escaped = NULL;
+
/* First put it in the attributes hash table. (Watch out, this might
* invalidate old_v.) */
if (new_v == NULL)
@@ -1620,7 +1630,12 @@ mcd_storage_set_attribute (McdStorage *self,
g_hash_table_insert (sa->attributes, g_strdup (attribute),
g_variant_ref (new_v));
- update_storage (self, account, attribute, new_v);
+ /* OK now we have to escape it in a stupid way for plugins */
+ if (value != NULL)
+ escaped = mcd_keyfile_escape_value (value);
+
+ update_storage (self, account, attribute, new_v, escaped);
+ g_free (escaped);
updated = TRUE;
}
@@ -1652,6 +1667,8 @@ mcd_storage_set_parameter (McdStorage *self,
{
GVariant *old_v;
GVariant *new_v = NULL;
+ const gchar *old_escaped;
+ gchar *new_escaped = NULL;
McdStorageAccount *sa;
gboolean updated = FALSE;
@@ -1663,12 +1680,18 @@ mcd_storage_set_parameter (McdStorage *self,
g_return_val_if_fail (sa != NULL, FALSE);
if (value != NULL)
- new_v = g_variant_ref_sink (dbus_g_value_build_g_variant (value));
+ {
+ new_escaped = mcd_keyfile_escape_value (value);
+ new_v = g_variant_ref_sink (dbus_g_value_build_g_variant (value));
+ }
old_v = g_hash_table_lookup (sa->parameters, parameter);
+ old_escaped = g_hash_table_lookup (sa->escaped_parameters, parameter);
if (old_v != NULL)
updated = !mcd_nullable_variant_equal (old_v, new_v);
+ else if (old_escaped != NULL)
+ updated = tp_strdiff (old_escaped, new_escaped);
else
updated = (value != NULL);
@@ -1684,10 +1707,11 @@ 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_v);
+ update_storage (self, account, key, new_v, new_escaped);
return TRUE;
}
+ g_free (new_escaped);
tp_clear_pointer (&new_v, g_variant_unref);
return updated;
}
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c
index b2ae25b..9d79dc0 100644
--- a/tests/twisted/dbus-account-plugin.c
+++ b/tests/twisted/dbus-account-plugin.c
@@ -1087,6 +1087,18 @@ test_dbus_account_plugin_get (const McpAccountStorage *storage,
}
static gboolean
+test_dbus_account_plugin_set (const McpAccountStorage *storage,
+ const McpAccountManager *am,
+ const gchar *account_name,
+ const gchar *key,
+ const gchar *value)
+{
+ /* Now that we implement set_attribute and set_parameter, this no longer
+ * needs a real implementation. */
+ return FALSE;
+}
+
+static gboolean
test_dbus_account_plugin_set_attribute (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account_name,
@@ -1554,6 +1566,7 @@ account_storage_iface_init (McpAccountStorageIface *iface)
iface->priority = MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_NORMAL + 100;
iface->get = test_dbus_account_plugin_get;
+ iface->set = test_dbus_account_plugin_set;
iface->set_attribute = test_dbus_account_plugin_set_attribute;
iface->set_parameter = test_dbus_account_plugin_set_parameter;
iface->list = test_dbus_account_plugin_list;
diff --git a/tests/twisted/mcp-account-diversion.c b/tests/twisted/mcp-account-diversion.c
index 8707d06..c3fa55a 100644
--- a/tests/twisted/mcp-account-diversion.c
+++ b/tests/twisted/mcp-account-diversion.c
@@ -112,57 +112,24 @@ _create_config (void)
}
static gboolean
-_set (McpAccountStorage *self,
- McpAccountManager *am,
- const gchar *account,
- const gchar *key,
- GVariant *val,
- McpParameterFlags flags)
+_set (const McpAccountStorage *self,
+ const McpAccountManager *am,
+ const gchar *account,
+ const gchar *key,
+ const gchar *val)
{
AccountDiversionPlugin *adp = ACCOUNT_DIVERSION_PLUGIN (self);
- gchar *val_str;
if (g_str_has_prefix (account, DONT_DIVERT))
return FALSE;
adp->save = TRUE;
-
- val_str = mcp_account_manager_escape_variant_for_keyfile (am, val);
- g_key_file_set_value (adp->keyfile, account, key, val_str);
- g_free (val_str);
+ g_key_file_set_value (adp->keyfile, account, key, val);
return TRUE;
}
static gboolean
-_set_attribute (McpAccountStorage *self,
- McpAccountManager *am,
- const gchar *account,
- const gchar *attribute,
- GVariant *val,
- McpAttributeFlags flags)
-{
- return _set (self, am, account, attribute, val, flags);
-}
-
-static gboolean
-_set_parameter (McpAccountStorage *self,
- McpAccountManager *am,
- const gchar *account,
- const gchar *parameter,
- GVariant *val,
- McpParameterFlags flags)
-{
- gchar *param = g_strdup_printf ("param-%s", parameter);
- gboolean ret;
-
- ret = _set (self, am, account, param, val, flags);
- g_free (param);
-
- return ret;
-}
-
-static gboolean
_get (const McpAccountStorage *self,
const McpAccountManager *am,
const gchar *account,
@@ -299,8 +266,7 @@ account_storage_iface_init (McpAccountStorageIface *iface,
iface->priority = PLUGIN_PRIORITY;
iface->get = _get;
- iface->set_attribute = _set_attribute;
- iface->set_parameter = _set_parameter;
+ iface->set = _set;
iface->delete = _delete;
iface->commit = _commit;
iface->list = _list;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-mission-control-6.git
More information about the Pkg-telepathy-commits
mailing list