[gnome-software] When searching for codec names, use the keyword name rather than the search term



commit 654131d9f684573952e360493271e35602dfe01b
Author: Richard Hughes <richard hughsie com>
Date:   Thu Oct 17 09:24:44 2013 +0100

    When searching for codec names, use the keyword name rather than the search term
    
    This ensures we use the correct case for the codec name, e.g. 'Mp3' -> 'MP3'.

 src/gs-app.c                      |   26 ++++++++++++++++++++++++++
 src/gs-app.h                      |    3 +++
 src/gs-plugin-loader.c            |   22 +++++++++++++++++++---
 src/plugins/appstream-app.c       |    9 +++++++++
 src/plugins/appstream-app.h       |    1 +
 src/plugins/gs-plugin-appstream.c |    5 +++++
 6 files changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index b7ff563..ddb1a9b 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -65,6 +65,7 @@ struct GsAppPrivate
        gchar                   *description;
        GPtrArray               *screenshots;
        GPtrArray               *categories;
+       GPtrArray               *keywords;
        GHashTable              *urls;
        gchar                   *licence;
        gchar                   *menu_path;
@@ -1173,6 +1174,29 @@ gs_app_set_categories (GsApp *app, GPtrArray *categories)
 }
 
 /**
+ * gs_app_get_keywords:
+ */
+GPtrArray *
+gs_app_get_keywords (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), NULL);
+       return app->priv->keywords;
+}
+
+/**
+ * gs_app_set_keywords:
+ */
+void
+gs_app_set_keywords (GsApp *app, GPtrArray *keywords)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       g_return_if_fail (keywords != NULL);
+       if (app->priv->keywords != NULL)
+               g_ptr_array_unref (app->priv->keywords);
+       app->priv->keywords = g_ptr_array_ref (keywords);
+}
+
+/**
  * gs_app_get_property:
  */
 static void
@@ -1407,6 +1431,8 @@ gs_app_finalize (GObject *object)
                g_object_unref (priv->featured_pixbuf);
        if (priv->categories != NULL)
                g_ptr_array_unref (priv->categories);
+       if (priv->keywords != NULL)
+               g_ptr_array_unref (priv->keywords);
 
        G_OBJECT_CLASS (gs_app_parent_class)->finalize (object);
 }
diff --git a/src/gs-app.h b/src/gs-app.h
index 4864255..8074050 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -194,6 +194,9 @@ void                 gs_app_set_categories          (GsApp          *app,
                                                 GPtrArray      *categories);
 gboolean        gs_app_has_category            (GsApp          *app,
                                                 const gchar    *category);
+GPtrArray      *gs_app_get_keywords            (GsApp          *app);
+void            gs_app_set_keywords            (GsApp          *app,
+                                                GPtrArray      *keywords);
 
 G_END_DECLS
 
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index bbf988e..1437c54 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -1175,10 +1175,23 @@ gs_plugin_loader_get_featured_finish (GsPluginLoader *plugin_loader,
 /**
  * gs_plugin_loader_convert_unavailable_app:
  **/
-static void
+static gboolean
 gs_plugin_loader_convert_unavailable_app (GsApp *app, const gchar *search)
 {
+       GPtrArray *keywords;
        GString *tmp;
+       const gchar *keyword;
+       guint i;
+
+       /* is the search string one of the codec keywords */
+       keywords = gs_app_get_keywords (app);
+       for (i = 0; i < keywords->len; i++) {
+               keyword = g_ptr_array_index (keywords, i);
+               if (g_ascii_strcasecmp (search, keyword) == 0) {
+                       search = keyword;
+                       break;
+               }
+       }
 
        tmp = g_string_new ("");
        /* TRANSLATORS: this is when we know about an application or
@@ -1194,6 +1207,7 @@ gs_plugin_loader_convert_unavailable_app (GsApp *app, const gchar *search)
        gs_app_set_size (app, GS_APP_SIZE_MISSING);
        gs_app_set_icon_name (app, "dialog-question-symbolic", NULL);
        g_string_free (tmp, TRUE);
+       return TRUE;
 }
 
 /**
@@ -1204,6 +1218,7 @@ gs_plugin_loader_convert_unavailable (GList *list, const gchar *search)
 {
        GList *l;
        GsApp *app;
+       gboolean ret;
 
        for (l = list; l != NULL; l = l->next) {
                app = GS_APP (l->data);
@@ -1218,8 +1233,9 @@ gs_plugin_loader_convert_unavailable (GList *list, const gchar *search)
                        continue;
 
                /* only convert the first unavailable codec */
-               gs_plugin_loader_convert_unavailable_app (app, search);
-               break;
+               ret = gs_plugin_loader_convert_unavailable_app (app, search);
+               if (ret)
+                       break;
        }
 }
 
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index 026a034..fc1ed95 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -174,6 +174,15 @@ appstream_app_get_urls (AppstreamApp *app)
 }
 
 /**
+ * appstream_app_get_keywords:
+ */
+GPtrArray *
+appstream_app_get_keywords (AppstreamApp *app)
+{
+       return app->keywords;
+}
+
+/**
  * appstream_app_get_licence:
  */
 const gchar *
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index f1a865a..f4d2115 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -56,6 +56,7 @@ const gchar   *appstream_app_get_name                 (AppstreamApp   *app);
 const gchar    *appstream_app_get_summary              (AppstreamApp   *app);
 const gchar    *appstream_app_get_project_group        (AppstreamApp   *app);
 GHashTable     *appstream_app_get_urls                 (AppstreamApp   *app);
+GPtrArray      *appstream_app_get_keywords             (AppstreamApp   *app);
 const gchar    *appstream_app_get_licence              (AppstreamApp   *app);
 const gchar    *appstream_app_get_description          (AppstreamApp   *app);
 const gchar    *appstream_app_get_icon                 (AppstreamApp   *app);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index b6581c3..47f67c6 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -470,6 +470,11 @@ gs_plugin_refine_item (GsPlugin *plugin,
        if (appstream_app_get_licence (item) != NULL && gs_app_get_licence (app) == NULL)
                gs_app_set_licence (app, appstream_app_get_licence (item));
 
+       /* set keywords */
+       if (appstream_app_get_keywords (item) != NULL &&
+           gs_app_get_keywords (app) == NULL)
+               gs_app_set_keywords (app, appstream_app_get_keywords (item));
+
        /* set description */
        if (appstream_app_get_description (item) != NULL && gs_app_get_description (app) == NULL)
                gs_app_set_description (app, appstream_app_get_description (item));


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