[gnome-software] Allow search-by-mimetype in the UI
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Allow search-by-mimetype in the UI
- Date: Thu, 17 Oct 2013 09:27:49 +0000 (UTC)
commit fce87155cf9c405bc653647675dcdd032c1f5acf
Author: Richard Hughes <richard hughsie com>
Date: Thu Oct 17 10:27:00 2013 +0100
Allow search-by-mimetype in the UI
This means you get sensible results for queries like:
$ gnome-software --mode=search --search-value="application/vnd.oasis.opendocument.text"
Resolves part of: https://bugzilla.gnome.org/show_bug.cgi?id=707320
src/plugins/appstream-app.c | 20 ++++++++++++++++++++
src/plugins/appstream-app.h | 3 +++
src/plugins/appstream-cache.c | 15 +++++++++++++++
src/plugins/appstream-common.c | 8 ++++++++
src/plugins/appstream-common.h | 2 ++
5 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index fc1ed95..bc7fab9 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -46,6 +46,7 @@ struct AppstreamApp
AppstreamAppIdKind id_kind;
GPtrArray *appcategories; /* of gchar* */
GPtrArray *keywords;
+ GPtrArray *mimetypes;
GPtrArray *desktop_core;
gpointer userdata;
GDestroyNotify userdata_destroy_func;
@@ -69,6 +70,7 @@ appstream_app_free (AppstreamApp *app)
g_free (app->description);
g_ptr_array_unref (app->appcategories);
g_ptr_array_unref (app->keywords);
+ g_ptr_array_unref (app->mimetypes);
g_ptr_array_unref (app->desktop_core);
g_ptr_array_unref (app->screenshots);
if (app->userdata_destroy_func != NULL)
@@ -107,6 +109,7 @@ appstream_app_new (void)
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->mimetypes = g_ptr_array_new_with_free_func (g_free);
app->desktop_core = g_ptr_array_new_with_free_func (g_free);
app->screenshots = g_ptr_array_new_with_free_func ((GDestroyNotify) appstream_screenshot_free);
app->urls = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -447,6 +450,18 @@ appstream_app_add_keyword (AppstreamApp *app,
}
/**
+ * appstream_app_add_mimetype:
+ */
+void
+appstream_app_add_mimetype (AppstreamApp *app,
+ const gchar *mimetype,
+ gsize length)
+{
+ g_ptr_array_add (app->mimetypes,
+ g_strndup (mimetype, length));
+}
+
+/**
* appstream_app_set_icon_kind:
*/
void
@@ -514,5 +529,10 @@ appstream_app_search_matches (AppstreamApp *app, const gchar *search)
if (strcasestr (tmp, search) != NULL)
return TRUE;
}
+ for (i = 0; i < app->mimetypes->len; i++) {
+ tmp = g_ptr_array_index (app->mimetypes, i);
+ if (strcasestr (tmp, search) != NULL)
+ return TRUE;
+ }
return FALSE;
}
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index f4d2115..2ebde1f 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -106,6 +106,9 @@ void appstream_app_add_category (AppstreamApp *app,
void appstream_app_add_keyword (AppstreamApp *app,
const gchar *keyword,
gsize length);
+void appstream_app_add_mimetype (AppstreamApp *app,
+ const gchar *mimetype,
+ gsize length);
void appstream_app_add_desktop_core (AppstreamApp *app,
const gchar *desktop,
gsize length);
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 9bebcd5..c8d0e52 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -165,6 +165,8 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
case APPSTREAM_TAG_KEYWORDS:
case APPSTREAM_TAG_KEYWORD:
+ case APPSTREAM_TAG_MIMETYPES:
+ case APPSTREAM_TAG_MIMETYPE:
case APPSTREAM_TAG_PRIORITY:
/* ignore */
break;
@@ -435,6 +437,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_APPLICATIONS:
case APPSTREAM_TAG_APPCATEGORY:
case APPSTREAM_TAG_KEYWORD:
+ case APPSTREAM_TAG_MIMETYPE:
/* ignore */
break;
case APPSTREAM_TAG_APPLICATION:
@@ -460,6 +463,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_APPCATEGORIES:
case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
case APPSTREAM_TAG_KEYWORDS:
+ case APPSTREAM_TAG_MIMETYPES:
case APPSTREAM_TAG_LICENCE:
case APPSTREAM_TAG_ICON:
helper->tag = APPSTREAM_TAG_APPLICATION;
@@ -504,6 +508,7 @@ appstream_cache_text_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_APPLICATION:
case APPSTREAM_TAG_APPCATEGORIES:
case APPSTREAM_TAG_KEYWORDS:
+ case APPSTREAM_TAG_MIMETYPES:
/* ignore */
break;
case APPSTREAM_TAG_PRIORITY:
@@ -536,6 +541,16 @@ appstream_cache_text_cb (GMarkupParseContext *context,
}
appstream_app_add_keyword (helper->item_temp, text, text_len);
break;
+ case APPSTREAM_TAG_MIMETYPE:
+ if (helper->item_temp == NULL) {
+ g_set_error_literal (error,
+ APPSTREAM_CACHE_ERROR,
+ APPSTREAM_CACHE_ERROR_FAILED,
+ "item_temp mimetype invalid");
+ return;
+ }
+ appstream_app_add_mimetype (helper->item_temp, text, text_len);
+ break;
case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
if (helper->item_temp == NULL) {
g_set_error_literal (error,
diff --git a/src/plugins/appstream-common.c b/src/plugins/appstream-common.c
index 48a0198..6e9f411 100644
--- a/src/plugins/appstream-common.c
+++ b/src/plugins/appstream-common.c
@@ -60,6 +60,10 @@ appstream_tag_from_string (const gchar *element_name)
return APPSTREAM_TAG_KEYWORDS;
if (g_strcmp0 (element_name, "keyword") == 0)
return APPSTREAM_TAG_KEYWORD;
+ if (g_strcmp0 (element_name, "mimetypes") == 0)
+ return APPSTREAM_TAG_MIMETYPES;
+ if (g_strcmp0 (element_name, "mimetype") == 0)
+ return APPSTREAM_TAG_MIMETYPE;
if (g_strcmp0 (element_name, "licence") == 0)
return APPSTREAM_TAG_LICENCE;
if (g_strcmp0 (element_name, "screenshots") == 0)
@@ -111,6 +115,10 @@ appstream_tag_to_string (AppstreamTag tag)
return "keywords";
if (tag == APPSTREAM_TAG_KEYWORD)
return "keyword";
+ if (tag == APPSTREAM_TAG_MIMETYPES)
+ return "mimetypes";
+ if (tag == APPSTREAM_TAG_MIMETYPE)
+ return "mimetype";
if (tag == APPSTREAM_TAG_LICENCE)
return "licence";
if (tag == APPSTREAM_TAG_SCREENSHOTS)
diff --git a/src/plugins/appstream-common.h b/src/plugins/appstream-common.h
index 13b68ac..7dd9b17 100644
--- a/src/plugins/appstream-common.h
+++ b/src/plugins/appstream-common.h
@@ -41,6 +41,8 @@ typedef enum {
APPSTREAM_TAG_APPCATEGORY,
APPSTREAM_TAG_KEYWORDS,
APPSTREAM_TAG_KEYWORD,
+ APPSTREAM_TAG_MIMETYPES,
+ APPSTREAM_TAG_MIMETYPE,
APPSTREAM_TAG_PROJECT_GROUP,
APPSTREAM_TAG_LICENCE,
APPSTREAM_TAG_SCREENSHOT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]