[gnome-software] Allow the AppStream metadata to enforce core applications



commit 73d59ebf22c1061effd845dfcfdd4ca41831b42c
Author: Richard Hughes <richard hughsie com>
Date:   Mon Oct 14 18:04:52 2013 +0100

    Allow the AppStream metadata to enforce core applications

 src/plugins/appstream-app.c       |   31 +++++++++++++++++++++++++++++++
 src/plugins/appstream-app.h       |    5 +++++
 src/plugins/appstream-cache.c     |   12 ++++++++++++
 src/plugins/appstream-common.c    |    4 ++++
 src/plugins/appstream-common.h    |    1 +
 src/plugins/gs-plugin-appstream.c |    5 +++++
 6 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index e56cd88..0c18fa1 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -44,6 +44,7 @@ struct AppstreamApp
        AppstreamAppIconKind     icon_kind;
        GPtrArray               *appcategories; /* of gchar* */
        GPtrArray               *keywords;
+       GPtrArray               *desktop_core;
        gpointer                 userdata;
        GDestroyNotify           userdata_destroy_func;
        GPtrArray               *screenshots; /* of AppstreamScreenshot */
@@ -66,6 +67,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->desktop_core);
        g_ptr_array_unref (app->screenshots);
        if (app->userdata_destroy_func != NULL)
                app->userdata_destroy_func (app->userdata);
@@ -103,6 +105,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->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->name_value = G_MAXUINT;
        app->summary_value = G_MAXUINT;
@@ -219,6 +222,34 @@ appstream_app_has_category (AppstreamApp *app, const gchar *category)
 }
 
 /**
+ * appstream_app_get_desktop_core:
+ */
+gboolean
+appstream_app_get_desktop_core (AppstreamApp *app, const gchar *desktop)
+{
+       const gchar *tmp;
+       guint i;
+
+       for (i = 0; i < app->desktop_core->len; i++) {
+               tmp = g_ptr_array_index (app->desktop_core, i);
+               if (g_strcmp0 (tmp, desktop) == 0)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+/**
+ * appstream_app_add_desktop_core:
+ */
+void
+appstream_app_add_desktop_core (AppstreamApp *app,
+                               const gchar *desktop,
+                               gsize length)
+{
+       g_ptr_array_add (app->desktop_core, g_strndup (desktop, length));
+}
+
+/**
  * appstream_app_set_id:
  */
 void
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index 2c4973b..9c47b1e 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -51,6 +51,8 @@ const gchar   *appstream_app_get_description          (AppstreamApp   *app);
 const gchar    *appstream_app_get_icon                 (AppstreamApp   *app);
 gboolean        appstream_app_has_category             (AppstreamApp   *app,
                                                         const gchar    *category);
+gboolean        appstream_app_get_desktop_core         (AppstreamApp   *app,
+                                                        const gchar    *desktop);
 AppstreamAppIconKind   appstream_app_get_icon_kind     (AppstreamApp   *app);
 
 void            appstream_app_set_id                   (AppstreamApp   *app,
@@ -89,6 +91,9 @@ void           appstream_app_add_category             (AppstreamApp   *app,
 void            appstream_app_add_keyword              (AppstreamApp   *app,
                                                         const gchar    *keyword,
                                                         gsize           length);
+void            appstream_app_add_desktop_core         (AppstreamApp   *app,
+                                                        const gchar    *desktop,
+                                                        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 e372dbc..feac444 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -143,6 +143,7 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_APPLICATIONS:
        case APPSTREAM_TAG_APPCATEGORIES:
        case APPSTREAM_TAG_APPCATEGORY:
+       case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
        case APPSTREAM_TAG_KEYWORDS:
        case APPSTREAM_TAG_KEYWORD:
                /* ignore */
@@ -366,6 +367,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_ID:
        case APPSTREAM_TAG_PKGNAME:
        case APPSTREAM_TAG_APPCATEGORIES:
+       case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
        case APPSTREAM_TAG_KEYWORDS:
        case APPSTREAM_TAG_URL:
        case APPSTREAM_TAG_LICENCE:
@@ -427,6 +429,16 @@ appstream_cache_text_cb (GMarkupParseContext *context,
                }
                appstream_app_add_keyword (helper->item_temp, text, text_len);
                break;
+       case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
+               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_desktop_core (helper->item_temp, text, text_len);
+               break;
        case APPSTREAM_TAG_ID:
                if (helper->item_temp == NULL ||
                    appstream_app_get_id (helper->item_temp) != NULL) {
diff --git a/src/plugins/appstream-common.c b/src/plugins/appstream-common.c
index 3140473..4d17114 100644
--- a/src/plugins/appstream-common.c
+++ b/src/plugins/appstream-common.c
@@ -70,6 +70,8 @@ appstream_tag_from_string (const gchar *element_name)
                return APPSTREAM_TAG_UPDATECONTACT;
        if (g_strcmp0 (element_name, "image") == 0)
                return APPSTREAM_TAG_IMAGE;
+       if (g_strcmp0 (element_name, "compulsory_for_desktop") == 0)
+               return APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP;
        return APPSTREAM_TAG_UNKNOWN;
 }
 
@@ -117,6 +119,8 @@ appstream_tag_to_string (AppstreamTag tag)
                return "updatecontact";
        if (tag == APPSTREAM_TAG_IMAGE)
                return "image";
+       if (tag == APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP)
+               return "compulsory_for_desktop";
        return NULL;
 }
 
diff --git a/src/plugins/appstream-common.h b/src/plugins/appstream-common.h
index a9e1107..7f97da8 100644
--- a/src/plugins/appstream-common.h
+++ b/src/plugins/appstream-common.h
@@ -47,6 +47,7 @@ typedef enum {
        APPSTREAM_TAG_SCREENSHOTS,
        APPSTREAM_TAG_UPDATECONTACT,
        APPSTREAM_TAG_IMAGE,
+       APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP,
        APPSTREAM_TAG_LAST
 } AppstreamTag;
 
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index f0d593e..429495f 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -471,6 +471,11 @@ gs_plugin_refine_item (GsPlugin *plugin,
            gs_app_get_project_group (app) == NULL)
                gs_app_set_project_group (app, appstream_app_get_project_group (item));
 
+       /* this is a core application for the desktop and cannot be removed */
+       if (appstream_app_get_desktop_core (item, "GNOME") &&
+           gs_app_get_kind (app) == GS_APP_KIND_NORMAL)
+               gs_app_set_kind (app, GS_APP_KIND_SYSTEM);
+
        /* set package name */
        if (appstream_app_get_pkgname (item) != NULL && gs_app_get_source (app) == NULL)
                gs_app_set_source (app, appstream_app_get_pkgname (item));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]