summaryrefslogtreecommitdiff
path: root/libappstream-glib
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-06-13 09:43:57 +0100
committerRichard Hughes <richard@hughsie.com>2014-06-13 09:49:12 +0100
commita05b7d19441c828f659486ba9a698579dab1d751 (patch)
tree42a364bba06eb5aa6dc1e6c73a7d2dc15267d065 /libappstream-glib
parent5c661f0920941ff2a81f9eca3ee9b7295e4044d8 (diff)
downloadappstream-glib-a05b7d19441c828f659486ba9a698579dab1d751.tar.gz
Add <developer_name> from the draft AppStream 0.7 specification
Diffstat (limited to 'libappstream-glib')
-rw-r--r--libappstream-glib/as-app.c82
-rw-r--r--libappstream-glib/as-app.h7
-rw-r--r--libappstream-glib/as-self-test.c8
-rw-r--r--libappstream-glib/as-tag.c1
-rw-r--r--libappstream-glib/as-tag.gperf1
-rw-r--r--libappstream-glib/as-tag.h2
6 files changed, 98 insertions, 3 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 2073167..5fe2cc0 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -54,6 +54,7 @@ struct _AsAppPrivate
AsIconKind icon_kind;
AsIdKind id_kind;
GHashTable *comments; /* of locale:string */
+ GHashTable *developer_names; /* of locale:string */
GHashTable *descriptions; /* of locale:string */
GHashTable *languages; /* of locale:string */
GHashTable *metadata; /* of key:value */
@@ -128,6 +129,7 @@ as_app_finalize (GObject *object)
g_free (priv->metadata_license);
g_free (priv->update_contact);
g_hash_table_unref (priv->comments);
+ g_hash_table_unref (priv->developer_names);
g_hash_table_unref (priv->descriptions);
g_hash_table_unref (priv->languages);
g_hash_table_unref (priv->metadata);
@@ -181,6 +183,7 @@ as_app_init (AsApp *app)
priv->token_cache = g_ptr_array_new_with_free_func ((GDestroyNotify) as_app_token_item_free);
priv->comments = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ priv->developer_names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->descriptions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
priv->languages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
priv->metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -398,6 +401,23 @@ as_app_get_comments (AsApp *app)
}
/**
+ * as_app_get_developer_names:
+ * @app: a #AsApp instance.
+ *
+ * Gets the developer_names set for the application.
+ *
+ * Returns: (transfer none): hash table of developer_names
+ *
+ * Since: 0.1.8
+ **/
+GHashTable *
+as_app_get_developer_names (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->developer_names;
+}
+
+/**
* as_app_get_metadata:
* @app: a #AsApp instance.
*
@@ -708,6 +728,24 @@ as_app_get_comment (AsApp *app, const gchar *locale)
}
/**
+ * as_app_get_developer_name:
+ * @app: a #AsApp instance.
+ * @locale: the locale, or %NULL. e.g. "en_GB"
+ *
+ * Gets the application developer name for a specific locale.
+ *
+ * Returns: string, or %NULL if unset
+ *
+ * Since: 0.1.8
+ **/
+const gchar *
+as_app_get_developer_name (AsApp *app, const gchar *locale)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return as_hash_lookup_by_locale (priv->developer_names, locale);
+}
+
+/**
* as_app_get_description:
* @app: a #AsApp instance.
* @locale: the locale, or %NULL. e.g. "en_GB"
@@ -1211,6 +1249,32 @@ as_app_set_comment (AsApp *app,
}
/**
+ * as_app_set_developer_name:
+ * @app: a #AsApp instance.
+ * @locale: the locale, or %NULL. e.g. "en_GB"
+ * @developer_name: the application developer name.
+ * @developer_name_len: the size of @developer_name, or -1 if %NULL-terminated.
+ *
+ * Sets the application developer name for a specific locale.
+ *
+ * Since: 0.1.0
+ **/
+void
+as_app_set_developer_name (AsApp *app,
+ const gchar *locale,
+ const gchar *developer_name,
+ gssize developer_name_len)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ g_return_if_fail (developer_name != NULL);
+ if (locale == NULL)
+ locale = "C";
+ g_hash_table_insert (priv->developer_names,
+ g_strdup (locale),
+ as_strndup (developer_name, developer_name_len));
+}
+
+/**
* as_app_set_description:
* @app: a #AsApp instance.
* @locale: the locale, or %NULL. e.g. "en_GB"
@@ -1647,6 +1711,7 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
/* dictionaries */
as_app_subsume_dict (papp->names, priv->names, overwrite);
as_app_subsume_dict (papp->comments, priv->comments, overwrite);
+ as_app_subsume_dict (papp->developer_names, priv->developer_names, overwrite);
as_app_subsume_dict (papp->descriptions, priv->descriptions, overwrite);
as_app_subsume_dict (papp->metadata, priv->metadata, overwrite);
as_app_subsume_dict (papp->urls, priv->urls, overwrite);
@@ -1813,6 +1878,13 @@ as_app_node_insert (AsApp *app, GNode *parent, gdouble api_version)
priv->comments,
AS_NODE_INSERT_FLAG_DEDUPE_LANG);
+ /* <developer_name> */
+ if (api_version >= 0.7) {
+ as_node_insert_localized (node_app, "developer_name",
+ priv->developer_names,
+ AS_NODE_INSERT_FLAG_DEDUPE_LANG);
+ }
+
/* <description> */
if (api_version < 0.6) {
as_node_insert_localized (node_app, "description",
@@ -2009,6 +2081,16 @@ as_app_node_parse_child (AsApp *app, GNode *n, GError **error)
as_node_take_data (n));
break;
+ /* <developer_name> */
+ case AS_TAG_DEVELOPER_NAME:
+ taken = as_node_take_attribute (n, "xml:lang");
+ if (taken == NULL)
+ taken = g_strdup ("C");
+ g_hash_table_insert (priv->developer_names,
+ taken,
+ as_node_take_data (n));
+ break;
+
/* <description> */
case AS_TAG_DESCRIPTION:
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index f6d9eb6..37cbf64 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -172,6 +172,7 @@ GPtrArray *as_app_get_provides (AsApp *app);
GPtrArray *as_app_get_screenshots (AsApp *app);
GHashTable *as_app_get_names (AsApp *app);
GHashTable *as_app_get_comments (AsApp *app);
+GHashTable *as_app_get_developer_names (AsApp *app);
GHashTable *as_app_get_metadata (AsApp *app);
GHashTable *as_app_get_descriptions (AsApp *app);
GHashTable *as_app_get_urls (AsApp *app);
@@ -187,6 +188,8 @@ const gchar *as_app_get_name (AsApp *app,
const gchar *locale);
const gchar *as_app_get_comment (AsApp *app,
const gchar *locale);
+const gchar *as_app_get_developer_name (AsApp *app,
+ const gchar *locale);
const gchar *as_app_get_description (AsApp *app,
const gchar *locale);
gint as_app_get_priority (AsApp *app);
@@ -235,6 +238,10 @@ void as_app_set_comment (AsApp *app,
const gchar *locale,
const gchar *comment,
gssize comment_len);
+void as_app_set_developer_name (AsApp *app,
+ const gchar *locale,
+ const gchar *developer_name,
+ gssize developer_name_len);
void as_app_set_description (AsApp *app,
const gchar *locale,
const gchar *description,
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 2fd6630..c0cfa3c 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -319,13 +319,13 @@ ch_test_app_func (void)
GString *xml;
gboolean ret;
const gchar *src =
- "<component type=\"desktop\">"
+ "<component priority=\"-4\" type=\"desktop\">"
"<id>org.gnome.Software.desktop</id>"
- "<priority>-4</priority>"
"<pkgname>gnome-software</pkgname>"
"<name>Software</name>"
"<name xml:lang=\"pl\">Oprogramowanie</name>"
"<summary>Application manager</summary>"
+ "<developer_name>GNOME Foundation</developer_name>"
"<description><p>Software allows you to find stuff</p></description>"
"<description xml:lang=\"pt_BR\"><p>O aplicativo Software.</p></description>"
"<icon type=\"cached\">org.gnome.Software.png</icon>"
@@ -383,12 +383,14 @@ ch_test_app_func (void)
g_assert_cmpstr (as_app_get_id (app), ==, "org.gnome.Software");
g_assert_cmpstr (as_app_get_name (app, "pl"), ==, "Oprogramowanie");
g_assert_cmpstr (as_app_get_comment (app, NULL), ==, "Application manager");
+ g_assert_cmpstr (as_app_get_developer_name (app, NULL), ==, "GNOME Foundation");
g_assert_cmpstr (as_app_get_icon (app), ==, "org.gnome.Software.png");
g_assert_cmpint (as_app_get_icon_kind (app), ==, AS_ICON_KIND_CACHED);
g_assert_cmpint (as_app_get_source_kind (app), ==, AS_APP_SOURCE_KIND_UNKNOWN);
g_assert_cmpstr (as_app_get_project_group (app), ==, "GNOME");
g_assert_cmpstr (as_app_get_project_license (app), ==, "GPLv2+");
g_assert_cmpint (as_app_get_categories(app)->len, ==, 1);
+ g_assert_cmpint (as_app_get_priority (app), ==, -4);
g_assert_cmpint (as_app_get_screenshots(app)->len, ==, 2);
g_assert_cmpint (as_app_get_releases(app)->len, ==, 1);
g_assert_cmpint (as_app_get_provides(app)->len, ==, 1);
@@ -400,7 +402,7 @@ ch_test_app_func (void)
/* back to node */
root = as_node_new ();
- n = as_app_node_insert (app, root, 0.6);
+ n = as_app_node_insert (app, root, 0.7);
xml = as_node_to_xml (n, AS_NODE_TO_XML_FLAG_NONE);
g_assert_cmpstr (xml->str, ==, src);
g_string_free (xml, TRUE);
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index ea8a3da..f9909f0 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -169,6 +169,7 @@ as_tag_to_string (AsTag tag)
"metadata_license",
"provides",
"extends",
+ "developer_name",
NULL };
if (tag > AS_TAG_LAST)
tag = AS_TAG_LAST;
diff --git a/libappstream-glib/as-tag.gperf b/libappstream-glib/as-tag.gperf
index e5ec2c3..4c7c8ea 100644
--- a/libappstream-glib/as-tag.gperf
+++ b/libappstream-glib/as-tag.gperf
@@ -43,3 +43,4 @@ arch, AS_TAG_ARCH
metadata_license, AS_TAG_METADATA_LICENSE
provides, AS_TAG_PROVIDES
extends, AS_TAG_EXTENDS
+developer_name, AS_TAG_DEVELOPER_NAME
diff --git a/libappstream-glib/as-tag.h b/libappstream-glib/as-tag.h
index 8f074d4..89d736c 100644
--- a/libappstream-glib/as-tag.h
+++ b/libappstream-glib/as-tag.h
@@ -66,6 +66,7 @@
* @AS_TAG_METADATA_LICENSE: `metadata_license`
* @AS_TAG_PROVIDES: `provides`
* @AS_TAG_EXTENDS: `extends`
+ * @AS_TAG_DEVELOPER_NAME: `developer_name`
*
* The tag type.
**/
@@ -106,6 +107,7 @@ typedef enum {
AS_TAG_METADATA_LICENSE, /* Since: 0.1.4 */
AS_TAG_PROVIDES, /* Since: 0.1.6 */
AS_TAG_EXTENDS, /* Since: 0.1.7 */
+ AS_TAG_DEVELOPER_NAME, /* Since: 0.1.8 */
/*< private >*/
AS_TAG_LAST
} AsTag;