summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-09-12 13:19:57 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-09-12 14:22:50 +0100
commitfb470a3a8bde4e2bf07cf93722daa016a6344c2c (patch)
treee31f4ba076dadc3bde4f850a43b34b02eca4d253
parent7975d386c95469d2e5aa7626524dc906dfeb64ef (diff)
mcp_account_manager_escape_variant_for_keyfile: add to plugin API
-rw-r--r--mission-control-plugins/account.c30
-rw-r--r--mission-control-plugins/account.h4
-rw-r--r--mission-control-plugins/implementation.h3
-rw-r--r--src/mcd-storage.c8
4 files changed, 45 insertions, 0 deletions
diff --git a/mission-control-plugins/account.c b/mission-control-plugins/account.c
index 931ed621..32f60332 100644
--- a/mission-control-plugins/account.c
+++ b/mission-control-plugins/account.c
@@ -267,6 +267,36 @@ mcp_account_manager_escape_value_for_keyfile (const McpAccountManager *mcpa,
}
/**
+ * mcp_account_manager_escape_variant_for_keyfile:
+ * @mcpa: a #McpAccountManager
+ * @variant: a #GVariant with a supported #GVariantType
+ *
+ * Escape @variant so it could be passed to g_key_file_set_value().
+ * For instance, escaping the boolean value TRUE returns "true",
+ * and escaping the string value containing one space returns "\s".
+ *
+ * It is a programming error to use an unsupported type.
+ * The supported types are currently %G_VARIANT_TYPE_STRING,
+ * %G_VARIANT_TYPE_BOOLEAN, %G_VARIANT_TYPE_INT32, %G_VARIANT_TYPE_UINT32,
+ * %G_VARIANT_TYPE_INT64, %G_VARIANT_TYPE_UINT64, %G_VARIANT_TYPE_BYTE,
+ * %G_VARIANT_TYPE_STRING_ARRAY, %G_VARIANT_TYPE_OBJECT_PATH and
+ * %G_VARIANT_TYPE_OBJECT_PATH_ARRAY.
+ *
+ * Returns: (transfer full): the escaped form of @variant
+ */
+gchar *
+mcp_account_manager_escape_variant_for_keyfile (const McpAccountManager *mcpa,
+ GVariant *variant)
+{
+ McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa);
+
+ g_return_val_if_fail (iface != NULL, NULL);
+ g_return_val_if_fail (iface->escape_variant_for_keyfile != NULL, NULL);
+
+ return iface->escape_variant_for_keyfile (mcpa, variant);
+}
+
+/**
* mcp_account_manager_unescape_value_from_keyfile:
* @mcpa: a #McpAccountManager
* @escaped: an escaped string as returned by g_key_file_get_value()
diff --git a/mission-control-plugins/account.h b/mission-control-plugins/account.h
index 05f30057..4536ab18 100644
--- a/mission-control-plugins/account.h
+++ b/mission-control-plugins/account.h
@@ -74,6 +74,10 @@ gchar *mcp_account_manager_escape_value_for_keyfile (
const McpAccountManager *mcpa,
const GValue *value);
+gchar *mcp_account_manager_escape_variant_for_keyfile (
+ const McpAccountManager *mcpa,
+ GVariant *variant);
+
gboolean mcp_account_manager_unescape_value_from_keyfile (
const McpAccountManager *mcpa,
const gchar *escaped,
diff --git a/mission-control-plugins/implementation.h b/mission-control-plugins/implementation.h
index 6cbf7a9b..eb857205 100644
--- a/mission-control-plugins/implementation.h
+++ b/mission-control-plugins/implementation.h
@@ -116,6 +116,9 @@ struct _McpAccountManagerIface {
gboolean (* init_value_for_attribute) (const McpAccountManager *mcpa,
GValue *value,
const gchar *attribute);
+
+ gchar * (* escape_variant_for_keyfile) (const McpAccountManager *mcpa,
+ GVariant *variant);
};
G_END_DECLS
diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index 0117f6e2..6b5e5e67 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -1568,6 +1568,13 @@ mcd_keyfile_escape_value (const GValue *value)
return ret;
}
+static gchar *
+mcpa_escape_variant_for_keyfile (const McpAccountManager *unused G_GNUC_UNUSED,
+ GVariant *variant)
+{
+ return mcd_keyfile_escape_variant (variant);
+}
+
/*
* mcd_keyfile_set_value:
* @keyfile: a keyfile
@@ -1936,6 +1943,7 @@ plugin_iface_init (McpAccountManagerIface *iface,
iface->unique_name = unique_name;
iface->list_keys = list_keys;
iface->escape_value_for_keyfile = mcpa_escape_value_for_keyfile;
+ iface->escape_variant_for_keyfile = mcpa_escape_variant_for_keyfile;
iface->unescape_value_from_keyfile = mcpa_unescape_value_from_keyfile;
iface->init_value_for_attribute = mcpa_init_value_for_attribute;
}