[libpeas] Added peas_plugin_info_get_external_data()
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Added peas_plugin_info_get_external_data()
- Date: Thu, 29 Mar 2012 01:08:28 +0000 (UTC)
commit 95c25a1e7d09a15cb9eae5f1299849b80ece0c82
Author: Garrett Regier <garrettregier gmail com>
Date: Thu Mar 22 19:28:28 2012 -0700
Added peas_plugin_info_get_external_data()
https://bugzilla.gnome.org/show_bug.cgi?id=671934
libpeas/peas-plugin-info-priv.h | 2 +
libpeas/peas-plugin-info.c | 57 +++++++++++++++++++++++++++++++++++++++
libpeas/peas-plugin-info.h | 3 ++
tests/libpeas/plugin-info.c | 3 ++
tests/plugins/full-info.plugin | 1 +
5 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/libpeas/peas-plugin-info-priv.h b/libpeas/peas-plugin-info-priv.h
index 12a08ef..4a8b7a7 100644
--- a/libpeas/peas-plugin-info-priv.h
+++ b/libpeas/peas-plugin-info-priv.h
@@ -47,6 +47,8 @@ struct _PeasPluginInfo {
gchar *version;
gchar *help_uri;
+ GHashTable *external_data;
+
GError *error;
guint loaded : 1;
diff --git a/libpeas/peas-plugin-info.c b/libpeas/peas-plugin-info.c
index a71fd22..29e7c1a 100644
--- a/libpeas/peas-plugin-info.c
+++ b/libpeas/peas-plugin-info.c
@@ -95,6 +95,9 @@ _peas_plugin_info_unref (PeasPluginInfo *info)
if (info->error != NULL)
g_error_free (info->error);
+ if (info->external_data != NULL)
+ g_hash_table_unref (info->external_data);
+
g_free (info);
}
@@ -132,6 +135,8 @@ _peas_plugin_info_new (const gchar *filename,
gchar **strv;
gboolean b;
GError *error = NULL;
+ gchar **keys;
+ gsize i;
g_return_val_if_fail (filename != NULL, NULL);
@@ -252,6 +257,26 @@ _peas_plugin_info_new (const gchar *filename,
else
info->hidden = b;
+ keys = g_key_file_get_keys (plugin_file, "Plugin", NULL, NULL);
+
+ for (i = 0; keys[i] != NULL; ++i)
+ {
+ if (!g_str_has_prefix (keys[i], "X-"))
+ continue;
+
+ if (info->external_data == NULL)
+ info->external_data = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
+ g_hash_table_insert (info->external_data,
+ g_strdup (keys[i] + 2),
+ g_key_file_get_string (plugin_file, "Plugin",
+ keys[i], NULL));
+ }
+
+ g_strfreev (keys);
+
g_key_file_free (plugin_file);
info->module_dir = g_strdup (module_dir);
@@ -712,3 +737,35 @@ peas_plugin_info_get_help_uri (const PeasPluginInfo *info)
return info->help_uri;
}
+
+/**
+ * peas_plugin_info_get_external_data:
+ * @info: A #PeasPluginInfo.
+ * @key: The key to lookup.
+ *
+ * Gets external data specified for the plugin.
+ *
+ * External data is specified in the plugin info file prefixed with X-. For
+ * example, if a key/value pair X-Peas=1 is specified in the key file, you
+ * can use "Peas" for @key to retrieve the value "1".
+ *
+ * Note: that you can omit the X- prefix when retrieving the value,
+ * but not when specifying the value in the file.
+ *
+ * Returns: the external data, or %NULL if the external data could not be found.
+ */
+const gchar *
+peas_plugin_info_get_external_data (const PeasPluginInfo *info,
+ const gchar *key)
+{
+ g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
+ if (info->external_data == NULL)
+ return NULL;
+
+ if (g_str_has_prefix (key, "X-"))
+ key += 2;
+
+ return g_hash_table_lookup (info->external_data, key);
+}
diff --git a/libpeas/peas-plugin-info.h b/libpeas/peas-plugin-info.h
index 8cb7da6..4e0b0a5 100644
--- a/libpeas/peas-plugin-info.h
+++ b/libpeas/peas-plugin-info.h
@@ -95,6 +95,9 @@ const gchar *peas_plugin_info_get_copyright (const PeasPluginInfo *info);
const gchar *peas_plugin_info_get_version (const PeasPluginInfo *info);
const gchar *peas_plugin_info_get_help_uri (const PeasPluginInfo *info);
+const gchar *peas_plugin_info_get_external_data (const PeasPluginInfo *info,
+ const gchar *key);
+
G_END_DECLS
#endif /* __PEAS_PLUGIN_INFO_H__ */
diff --git a/tests/libpeas/plugin-info.c b/tests/libpeas/plugin-info.c
index 3f87bd6..227a72a 100644
--- a/tests/libpeas/plugin-info.c
+++ b/tests/libpeas/plugin-info.c
@@ -90,6 +90,9 @@ test_plugin_info_verify_full_info (PeasEngine *engine)
authors = peas_plugin_info_get_authors (info);
g_assert (authors != NULL && authors[1] == NULL);
g_assert_cmpstr (authors[0], ==, "Garrett Regier");
+
+ g_assert_cmpstr (peas_plugin_info_get_external_data (info, "External"), ==, "external data");
+ g_assert_cmpstr (peas_plugin_info_get_external_data (info, "X-External"), ==, "external data");
}
static void
diff --git a/tests/plugins/full-info.plugin b/tests/plugins/full-info.plugin
index 1595d78..a95df11 100644
--- a/tests/plugins/full-info.plugin
+++ b/tests/plugins/full-info.plugin
@@ -10,3 +10,4 @@ Website=http://live.gnome.org/Libpeas
Icon=gtk-ok
Version=1.0
Help=http://git.gnome.org/browse/libpeas
+X-External=external data
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]