summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-08-13 18:53:18 +0100
committerRichard Hughes <richard@hughsie.com>2014-08-18 10:43:10 +0100
commit086751082375a2ecf46bae73bb8f50cedea245a7 (patch)
treee90ea112a00952aea2bcf199fa368bc5f4d04bce
parentf824a84eb9bf58666fe0a0ef9403fd234f6fb81d (diff)
downloadappstream-glib-086751082375a2ecf46bae73bb8f50cedea245a7.tar.gz
Allow desktop->addon demotion with an AppData file
We might want to do this for Adobe Flash, which isn't really an application.
-rw-r--r--data/tests/Makefile.am1
-rw-r--r--data/tests/example.appdata.xml9
-rw-r--r--libappstream-glib/as-app.c6
-rw-r--r--libappstream-glib/as-self-test.c52
-rw-r--r--libappstream-glib/as-store.c3
5 files changed, 70 insertions, 1 deletions
diff --git a/data/tests/Makefile.am b/data/tests/Makefile.am
index bb8f3e7..8ec67b3 100644
--- a/data/tests/Makefile.am
+++ b/data/tests/Makefile.am
@@ -5,6 +5,7 @@ test_files = \
alpha-internal2.png \
alpha-vert.png \
broken.appdata.xml \
+ example.appdata.xml \
example.desktop \
example.metainfo.xml \
example-v04.xml.gz \
diff --git a/data/tests/example.appdata.xml b/data/tests/example.appdata.xml
new file mode 100644
index 0000000..753b431
--- /dev/null
+++ b/data/tests/example.appdata.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2014 Richard Hughes <richard@hughsie.com> -->
+<application>
+ <id type="addon">example.desktop</id>
+ <metadata_license>CC0 and CC-BY-3.0</metadata_license>
+ <project_license>GPL-2.0+ and GFDL-1.3</project_license>
+ <description><p>Demote application to addon.</p></description>
+ <extends>firefox.desktop</extends>
+</application>
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index e6aa8e8..725c829 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -2293,6 +2293,12 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
if (papp->id_kind == AS_ID_KIND_UNKNOWN)
as_app_set_id_kind (app, priv->id_kind);
+ /* AppData or AppStream can overwrite the id-kind of desktop files */
+ if ((priv->source_kind == AS_APP_SOURCE_KIND_APPDATA ||
+ priv->source_kind == AS_APP_SOURCE_KIND_APPSTREAM) &&
+ papp->source_kind == AS_APP_SOURCE_KIND_DESKTOP)
+ as_app_set_id_kind (app, priv->id_kind);
+
/* state */
if (papp->state == AS_APP_STATE_UNKNOWN)
as_app_set_state (app, priv->state);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index bc1bd5c..cf9dfce 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1556,6 +1556,57 @@ as_test_app_search_func (void)
g_assert_cmpint (as_app_search_matches_all (app, (gchar**) mime), ==, 5);
}
+/* demote the .desktop "application" to an addon */
+static void
+as_test_store_demote_func (void)
+{
+ AsApp *app;
+ GError *error = NULL;
+ gboolean ret;
+ _cleanup_free_ gchar *filename = NULL;
+ _cleanup_object_unref_ AsApp *app_appdata = NULL;
+ _cleanup_object_unref_ AsApp *app_desktop = NULL;
+ _cleanup_object_unref_ AsStore *store = NULL;
+ _cleanup_string_free_ GString *xml = NULL;
+
+ /* load example desktop file */
+ app_desktop = as_app_new ();
+ filename = as_test_get_filename ("example.desktop");
+ ret = as_app_parse_file (app_desktop, filename,
+ AS_APP_PARSE_FLAG_ALLOW_VETO, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpint (as_app_get_id_kind (app_desktop), ==, AS_ID_KIND_DESKTOP);
+
+ /* load example appdata file */
+ app_appdata = as_app_new ();
+ filename = as_test_get_filename ("example.appdata.xml");
+ ret = as_app_parse_file (app_appdata, filename,
+ AS_APP_PARSE_FLAG_ALLOW_VETO, &error);
+ g_assert_no_error (error);
+ g_assert (ret);
+ g_assert_cmpint (as_app_get_id_kind (app_appdata), ==, AS_ID_KIND_ADDON);
+
+ /* add apps */
+ store = as_store_new ();
+ as_store_set_api_version (store, 0.8);
+ as_store_add_app (store, app_desktop);
+ as_store_add_app (store, app_appdata);
+
+ /* check we demoted */
+ g_assert_cmpint (as_store_get_size (store), ==, 1);
+ app = as_store_get_app_by_id (store, "example.desktop");
+ g_assert (app != NULL);
+ g_assert_cmpint (as_app_get_id_kind (app), ==, AS_ID_KIND_ADDON);
+ g_assert_cmpint (as_app_get_extends(app)->len, >, 0);
+
+ /* dump */
+ xml = as_store_to_xml (store,
+ AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE |
+ AS_NODE_TO_XML_FLAG_FORMAT_INDENT);
+ g_debug ("%s", xml->str);
+}
+
static void
as_test_store_merges_func (void)
{
@@ -2326,6 +2377,7 @@ main (int argc, char **argv)
g_test_add_func ("/AppStream/utils{icons}", as_test_utils_icons_func);
g_test_add_func ("/AppStream/utils{spdx-token}", as_test_utils_spdx_token_func);
g_test_add_func ("/AppStream/store", as_test_store_func);
+ g_test_add_func ("/AppStream/store{demote}", as_test_store_demote_func);
g_test_add_func ("/AppStream/store{merges}", as_test_store_merges_func);
g_test_add_func ("/AppStream/store{merges-local}", as_test_store_merges_local_func);
g_test_add_func ("/AppStream/store{addons}", as_test_store_addons_func);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 318cb55..75400b2 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1182,7 +1182,8 @@ as_store_load_installed (AsStore *store,
continue;
if ((priv->add_flags & AS_STORE_ADD_FLAG_PREFER_LOCAL) == 0) {
app_tmp = as_store_get_app_by_id (store, tmp);
- if (app_tmp != NULL) {
+ if (app_tmp != NULL &&
+ as_app_get_source_kind (app_tmp) == AS_APP_SOURCE_KIND_DESKTOP) {
as_app_set_state (app_tmp, AS_APP_STATE_INSTALLED);
g_debug ("not parsing %s as %s already exists",
filename, tmp);