[gnome-software] Support some more Kudos set from the AppStream metadata



commit 8bccd0c1ac0aa03ef9d7f3c8d5d8fb8744113ebb
Author: Richard Hughes <richard hughsie com>
Date:   Thu Feb 27 11:44:31 2014 +0000

    Support some more Kudos set from the AppStream metadata

 src/gs-app.c                      |   14 ++++++++++-
 src/gs-app.h                      |    7 +++++-
 src/org.gnome.Software.desktop.in |    1 +
 src/plugins/appstream-app.c       |   26 ++++++++++++++++++++++
 src/plugins/appstream-app.h       |    6 +++++
 src/plugins/appstream-cache.c     |   42 +++++++++++++++++++++++++++++++++++++
 src/plugins/appstream-common.c    |    8 +++++++
 src/plugins/appstream-common.h    |    2 +
 src/plugins/gs-plugin-appstream.c |   19 ++++++++++++++--
 9 files changed, 119 insertions(+), 6 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index bddb77a..9b173d8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -231,8 +231,18 @@ gs_app_to_string (GsApp *app)
                g_string_append (str, "\tkudo:\trecent-release\n");
        if ((priv->kudos & GS_APP_KUDO_FEATURED_RECOMMENDED) > 0)
                g_string_append (str, "\tkudo:\tfeatured-recommended\n");
-       if ((priv->kudos & GS_APP_KUDO_INTEGRATION) > 0)
-               g_string_append (str, "\tkudo:\tintegration\n");
+       if ((priv->kudos & GS_APP_KUDO_MODERN_TOOLKIT) > 0)
+               g_string_append (str, "\tkudo:\tmodern-toolkit\n");
+       if ((priv->kudos & GS_APP_KUDO_SEARCH_PROVIDER) > 0)
+               g_string_append (str, "\tkudo:\tsearch-provider\n");
+       if ((priv->kudos & GS_APP_KUDO_INSTALLS_USER_DOCS) > 0)
+               g_string_append (str, "\tkudo:\tinstalls-user-docs\n");
+       if ((priv->kudos & GS_APP_KUDO_USES_NOTIFICATIONS) > 0)
+               g_string_append (str, "\tkudo:\tuses-notifications\n");
+       if ((priv->kudos & GS_APP_KUDO_USES_APP_MENU) > 0)
+               g_string_append (str, "\tkudo:\tuses-app-menu\n");
+       if ((priv->kudos & GS_APP_KUDO_HAS_KEYWORDS) > 0)
+               g_string_append (str, "\tkudo:\thas-keywords\n");
        if (priv->name != NULL)
                g_string_append_printf (str, "\tname:\t%s\n", priv->name);
        if (priv->icon != NULL)
diff --git a/src/gs-app.h b/src/gs-app.h
index d18106c..755c056 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -101,7 +101,12 @@ typedef enum {
        GS_APP_KUDO_MY_LANGUAGE                 = 1 << 0,
        GS_APP_KUDO_RECENT_RELEASE              = 1 << 1,
        GS_APP_KUDO_FEATURED_RECOMMENDED        = 1 << 2,
-       GS_APP_KUDO_INTEGRATION                 = 1 << 3,
+       GS_APP_KUDO_MODERN_TOOLKIT              = 1 << 3,
+       GS_APP_KUDO_SEARCH_PROVIDER             = 1 << 4,
+       GS_APP_KUDO_INSTALLS_USER_DOCS          = 1 << 5,
+       GS_APP_KUDO_USES_NOTIFICATIONS          = 1 << 6,
+       GS_APP_KUDO_HAS_KEYWORDS                = 1 << 7,
+       GS_APP_KUDO_USES_APP_MENU               = 1 << 8,
        GS_APP_KUDO_LAST
 } GsAppKudo;
 
diff --git a/src/org.gnome.Software.desktop.in b/src/org.gnome.Software.desktop.in
index b2660ad..5ef3480 100644
--- a/src/org.gnome.Software.desktop.in
+++ b/src/org.gnome.Software.desktop.in
@@ -10,4 +10,5 @@ StartupNotify=true
 X-GNOME-Bugzilla-Bugzilla=GNOME
 X-GNOME-Bugzilla-Product=gnome-software
 X-GNOME-Bugzilla-Component=gnome-software
+X-GNOME-UsesNotifications=true
 DBusActivatable=true
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index f131b9e..eda0cf5 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -42,6 +42,7 @@ struct AppstreamApp
        gchar                   *description_lang;
        GHashTable              *urls;
        GHashTable              *languages;
+       GHashTable              *metadata;
        gchar                   *project_license;
        gchar                   *project_group;
        gchar                   *icon;
@@ -85,6 +86,7 @@ appstream_app_free (AppstreamApp *app)
        g_ptr_array_unref (app->pkgnames);
        g_hash_table_unref (app->urls);
        g_hash_table_unref (app->languages);
+       g_hash_table_unref (app->metadata);
        g_free (app->project_license);
        g_free (app->project_group);
        g_free (app->icon);
@@ -143,6 +145,7 @@ appstream_app_new (void)
        app->token_cache = g_ptr_array_new_with_free_func ((GDestroyNotify) appstream_app_token_item_free);
        app->urls = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
        app->languages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+       app->metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
        app->name_value = G_MAXUINT;
        app->summary_value = G_MAXUINT;
        app->icon_kind = APPSTREAM_APP_ICON_KIND_UNKNOWN;
@@ -486,6 +489,29 @@ appstream_app_add_mimetype (AppstreamApp *app,
 }
 
 /**
+ * appstream_app_add_metadata:
+ */
+void
+appstream_app_add_metadata (AppstreamApp *app,
+                           const gchar *key,
+                           const gchar *value,
+                           gsize length)
+{
+       g_hash_table_insert (app->metadata,
+                            g_strdup (key),
+                            g_strndup (value, length));
+}
+
+/**
+ * appstream_app_get_metadata_item:
+ */
+const gchar *
+appstream_app_get_metadata_item (AppstreamApp *app, const gchar *key)
+{
+       return g_hash_table_lookup (app->metadata, key);
+}
+
+/**
  * appstream_app_add_locale:
  */
 void
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index 3f776dc..1624889 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -112,6 +112,12 @@ void                appstream_app_add_keyword              (AppstreamApp   *app,
 void            appstream_app_add_mimetype             (AppstreamApp   *app,
                                                         const gchar    *mimetype,
                                                         gsize           length);
+void            appstream_app_add_metadata             (AppstreamApp   *app,
+                                                        const gchar    *key,
+                                                        const gchar    *value,
+                                                        gsize           length);
+const gchar    *appstream_app_get_metadata_item        (AppstreamApp   *app,
+                                                        const gchar    *key);
 void            appstream_app_add_locale               (AppstreamApp   *app,
                                                         const gchar    *locale,
                                                         gsize           length,
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 5239eaf..5b0b2d0 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -198,6 +198,7 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_KEYWORDS:
        case APPSTREAM_TAG_KEYWORD:
        case APPSTREAM_TAG_MIMETYPES:
+       case APPSTREAM_TAG_METADATA:
        case APPSTREAM_TAG_MIMETYPE:
        case APPSTREAM_TAG_PRIORITY:
        case APPSTREAM_TAG_LANGUAGES:
@@ -311,6 +312,27 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
                if (!helper->lang_temp)
                        helper->lang_temp = g_strdup ("C");
 
+       case APPSTREAM_TAG_VALUE:
+               if (helper->tag != APPSTREAM_TAG_METADATA) {
+                       g_set_error (error,
+                                    APPSTREAM_CACHE_ERROR,
+                                    APPSTREAM_CACHE_ERROR_FAILED,
+                                    "XML start %s invalid, tag %s",
+                                    element_name,
+                                    appstream_tag_to_string (helper->tag));
+                       return;
+               }
+
+               /* get lang */
+               if (!g_markup_collect_attributes (element_name,
+                                                 attribute_names,
+                                                 attribute_values,
+                                                 error,
+                                                 G_MARKUP_COLLECT_STRDUP,
+                                                 "key", &helper->lang_temp,
+                                                 G_MARKUP_COLLECT_INVALID))
+                       return;
+
        case APPSTREAM_TAG_IMAGE:
                if (helper->item_temp == NULL ||
                    helper->tag != APPSTREAM_TAG_SCREENSHOT) {
@@ -603,6 +625,7 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
        case APPSTREAM_TAG_KEYWORDS:
        case APPSTREAM_TAG_MIMETYPES:
+       case APPSTREAM_TAG_METADATA:
        case APPSTREAM_TAG_PROJECT_LICENSE:
        case APPSTREAM_TAG_ICON:
                helper->tag = APPSTREAM_TAG_APPLICATION;
@@ -624,6 +647,11 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_PRIORITY:
                helper->tag = APPSTREAM_TAG_APPLICATIONS;
                break;
+       case APPSTREAM_TAG_VALUE:
+               g_free (helper->lang_temp);
+               helper->lang_temp = NULL;
+               helper->tag = APPSTREAM_TAG_METADATA;
+               break;
        default:
                /* ignore unknown entries */
                helper->tag = helper->tag_last_known;
@@ -650,6 +678,7 @@ appstream_cache_text_cb (GMarkupParseContext *context,
        case APPSTREAM_TAG_APPCATEGORIES:
        case APPSTREAM_TAG_KEYWORDS:
        case APPSTREAM_TAG_MIMETYPES:
+       case APPSTREAM_TAG_METADATA:
                /* ignore */
                break;
        case APPSTREAM_TAG_PRIORITY:
@@ -692,6 +721,19 @@ appstream_cache_text_cb (GMarkupParseContext *context,
                }
                appstream_app_add_mimetype (helper->item_temp, text, text_len);
                break;
+       case APPSTREAM_TAG_VALUE:
+               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_metadata (helper->item_temp,
+                                           helper->lang_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 3291e80..bc41a74 100644
--- a/src/plugins/appstream-common.c
+++ b/src/plugins/appstream-common.c
@@ -86,6 +86,10 @@ appstream_tag_from_string (const gchar *element_name)
                return APPSTREAM_TAG_LANGUAGES;
        if (g_strcmp0 (element_name, "lang") == 0)
                return APPSTREAM_TAG_LANG;
+       if (g_strcmp0 (element_name, "metadata") == 0)
+               return APPSTREAM_TAG_METADATA;
+       if (g_strcmp0 (element_name, "value") == 0)
+               return APPSTREAM_TAG_VALUE;
        return APPSTREAM_TAG_UNKNOWN;
 }
 
@@ -147,6 +151,10 @@ appstream_tag_to_string (AppstreamTag tag)
                return "languages";
        if (tag == APPSTREAM_TAG_LANG)
                return "lang";
+       if (tag == APPSTREAM_TAG_METADATA)
+               return "metadata";
+       if (tag == APPSTREAM_TAG_VALUE)
+               return "value";
        return NULL;
 }
 
diff --git a/src/plugins/appstream-common.h b/src/plugins/appstream-common.h
index f2188f9..ae1c58b 100644
--- a/src/plugins/appstream-common.h
+++ b/src/plugins/appstream-common.h
@@ -54,6 +54,8 @@ typedef enum {
        APPSTREAM_TAG_CAPTION,
        APPSTREAM_TAG_LANGUAGES,
        APPSTREAM_TAG_LANG,
+       APPSTREAM_TAG_METADATA,
+       APPSTREAM_TAG_VALUE,
        APPSTREAM_TAG_LAST
 } AppstreamTag;
 
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index d11b439..6bba9fc 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -580,8 +580,10 @@ gs_plugin_refine_item (GsPlugin *plugin,
 
        /* set keywords */
        if (appstream_app_get_keywords (item) != NULL &&
-           gs_app_get_keywords (app) == NULL)
+           gs_app_get_keywords (app) == NULL) {
                gs_app_set_keywords (app, appstream_app_get_keywords (item));
+               gs_app_add_kudo (app, GS_APP_KUDO_HAS_KEYWORDS);
+       }
 
        /* set description */
        if (appstream_app_get_description (item) != NULL) {
@@ -620,10 +622,21 @@ gs_plugin_refine_item (GsPlugin *plugin,
        /* set screenshots */
        gs_plugin_refine_add_screenshots (app, item);
 
-       /* is available in my language */
-       g_debug ("looking for %s", plugin->priv->locale);
+       /* add kudos */
        if (appstream_app_has_locale (item, plugin->priv->locale) > 50)
                gs_app_add_kudo (app, GS_APP_KUDO_MY_LANGUAGE);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-GTK3") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_MODERN_TOOLKIT);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-SearchProvider") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_SEARCH_PROVIDER);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-InstallsUserDocs") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_INSTALLS_USER_DOCS);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-UsesNotifications") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_USES_NOTIFICATIONS);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-RecentRelease") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_RECENT_RELEASE);
+       if (appstream_app_get_metadata_item (item, "X-Kudo-UsesAppMenu") != NULL)
+               gs_app_add_kudo (app, GS_APP_KUDO_USES_APP_MENU);
 
        return ret;
 }


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