[gnome-software] Parse the keywords in the AppStream metadata
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Parse the keywords in the AppStream metadata
- Date: Fri, 13 Sep 2013 08:32:18 +0000 (UTC)
commit 1b2f555c66c48689e20753373719937582c9ad8c
Author: Richard Hughes <richard hughsie com>
Date: Fri Sep 13 09:30:31 2013 +0100
Parse the keywords in the AppStream metadata
src/plugins/appstream-app.c | 15 +++++++++++++++
src/plugins/appstream-app.h | 3 +++
src/plugins/appstream-cache.c | 25 +++++++++++++++++++++++++
3 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index 9e6afab..a60a79e 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -39,6 +39,7 @@ struct AppstreamApp
gchar *icon;
AppstreamAppIconKind icon_kind;
GPtrArray *appcategories;
+ GPtrArray *keywords;
gpointer userdata;
GDestroyNotify userdata_destroy_func;
};
@@ -82,6 +83,7 @@ appstream_app_free (AppstreamApp *app)
g_free (app->summary);
g_free (app->description);
g_ptr_array_unref (app->appcategories);
+ g_ptr_array_unref (app->keywords);
if (app->userdata_destroy_func != NULL)
app->userdata_destroy_func (app->userdata);
g_slice_free (AppstreamApp, app);
@@ -117,6 +119,7 @@ appstream_app_new (void)
AppstreamApp *app;
app = g_slice_new0 (AppstreamApp);
app->appcategories = g_ptr_array_new_with_free_func (g_free);
+ app->keywords = g_ptr_array_new_with_free_func (g_free);
app->name_value = G_MAXUINT;
app->summary_value = G_MAXUINT;
app->description_value = G_MAXUINT;
@@ -327,6 +330,18 @@ appstream_app_add_category (AppstreamApp *app,
}
/**
+ * appstream_app_add_keyword:
+ */
+void
+appstream_app_add_keyword (AppstreamApp *app,
+ const gchar *keyword,
+ gsize length)
+{
+ g_ptr_array_add (app->keywords,
+ g_strndup (keyword, length));
+}
+
+/**
* appstream_app_set_icon_kind:
*/
void
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index c963da2..df8dcaf 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -76,6 +76,9 @@ void appstream_app_set_icon (AppstreamApp *app,
void appstream_app_add_category (AppstreamApp *app,
const gchar *category,
gsize length);
+void appstream_app_add_keyword (AppstreamApp *app,
+ const gchar *keyword,
+ gsize length);
void appstream_app_set_icon_kind (AppstreamApp *app,
AppstreamAppIconKind icon_kind);
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 774138f..8f3d9a4 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -40,6 +40,8 @@ typedef enum {
APPSTREAM_CACHE_SECTION_ICON,
APPSTREAM_CACHE_SECTION_APPCATEGORIES,
APPSTREAM_CACHE_SECTION_APPCATEGORY,
+ APPSTREAM_CACHE_SECTION_KEYWORDS,
+ APPSTREAM_CACHE_SECTION_KEYWORD,
APPSTREAM_CACHE_SECTION_LAST
} AppstreamCacheSection;
@@ -133,6 +135,10 @@ appstream_cache_selection_from_string (const gchar *element_name)
return APPSTREAM_CACHE_SECTION_APPCATEGORIES;
if (g_strcmp0 (element_name, "appcategory") == 0)
return APPSTREAM_CACHE_SECTION_APPCATEGORY;
+ if (g_strcmp0 (element_name, "keywords") == 0)
+ return APPSTREAM_CACHE_SECTION_KEYWORDS;
+ if (g_strcmp0 (element_name, "keyword") == 0)
+ return APPSTREAM_CACHE_SECTION_KEYWORD;
return APPSTREAM_CACHE_SECTION_UNKNOWN;
}
@@ -164,6 +170,10 @@ appstream_cache_selection_to_string (AppstreamCacheSection section)
return "appcategories";
if (section == APPSTREAM_CACHE_SECTION_APPCATEGORY)
return "appcategory";
+ if (section == APPSTREAM_CACHE_SECTION_KEYWORDS)
+ return "keywords";
+ if (section == APPSTREAM_CACHE_SECTION_KEYWORD)
+ return "keyword";
return NULL;
}
@@ -210,6 +220,8 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
case APPSTREAM_CACHE_SECTION_APPLICATIONS:
case APPSTREAM_CACHE_SECTION_APPCATEGORIES:
case APPSTREAM_CACHE_SECTION_APPCATEGORY:
+ case APPSTREAM_CACHE_SECTION_KEYWORDS:
+ case APPSTREAM_CACHE_SECTION_KEYWORD:
/* ignore */
break;
case APPSTREAM_CACHE_SECTION_APPLICATION:
@@ -309,6 +321,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
switch (section_new) {
case APPSTREAM_CACHE_SECTION_APPLICATIONS:
case APPSTREAM_CACHE_SECTION_APPCATEGORY:
+ case APPSTREAM_CACHE_SECTION_KEYWORD:
/* ignore */
break;
case APPSTREAM_CACHE_SECTION_APPLICATION:
@@ -334,6 +347,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
case APPSTREAM_CACHE_SECTION_ID:
case APPSTREAM_CACHE_SECTION_PKGNAME:
case APPSTREAM_CACHE_SECTION_APPCATEGORIES:
+ case APPSTREAM_CACHE_SECTION_KEYWORDS:
case APPSTREAM_CACHE_SECTION_URL:
case APPSTREAM_CACHE_SECTION_ICON:
helper->section = APPSTREAM_CACHE_SECTION_APPLICATION;
@@ -369,6 +383,7 @@ appstream_cache_text_cb (GMarkupParseContext *context,
case APPSTREAM_CACHE_SECTION_APPLICATIONS:
case APPSTREAM_CACHE_SECTION_APPLICATION:
case APPSTREAM_CACHE_SECTION_APPCATEGORIES:
+ case APPSTREAM_CACHE_SECTION_KEYWORDS:
/* ignore */
break;
case APPSTREAM_CACHE_SECTION_APPCATEGORY:
@@ -381,6 +396,16 @@ appstream_cache_text_cb (GMarkupParseContext *context,
}
appstream_app_add_category (helper->item_temp, text, text_len);
break;
+ case APPSTREAM_CACHE_SECTION_KEYWORD:
+ if (helper->item_temp == NULL) {
+ g_set_error_literal (error,
+ APPSTREAM_CACHE_ERROR,
+ APPSTREAM_CACHE_ERROR_FAILED,
+ "item_temp category invalid");
+ return;
+ }
+ appstream_app_add_keyword (helper->item_temp, text, text_len);
+ break;
case APPSTREAM_CACHE_SECTION_ID:
if (helper->item_temp == NULL ||
appstream_app_get_id (helper->item_temp) != NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]