[gnome-software/wip/jrocha/flatpak-appstream-fixes: 2/2] Implement add_popular and add_featured in the Flatpak plugins



commit c23df9dc63dbe977ec135d81cca8371d14e2065f
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Wed Oct 26 15:10:10 2016 +0200

    Implement add_popular and add_featured in the Flatpak plugins
    
    This method had been the responsibility of the AppStream plugin before
    the Flatpak plugins started using appstream-glib directly, thus we need
    to implement this feature, otherwise we miss popular Flatpak apps.

 src/plugins/gs-appstream.c             |   62 ++++++++++++++++++++++++++++++++
 src/plugins/gs-appstream.h             |   10 +++++
 src/plugins/gs-flatpak.c               |   20 ++++++++++
 src/plugins/gs-flatpak.h               |    8 ++++
 src/plugins/gs-plugin-appstream.c      |   48 ++----------------------
 src/plugins/gs-plugin-flatpak-system.c |   26 +++++++++++++
 src/plugins/gs-plugin-flatpak-user.c   |   26 +++++++++++++
 7 files changed, 156 insertions(+), 44 deletions(-)
---
diff --git a/src/plugins/gs-appstream.c b/src/plugins/gs-appstream.c
index b1ddfd1..1546ee0 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -966,3 +966,65 @@ gs_appstream_store_add_categories (GsPlugin *plugin,
        }
        return TRUE;
 }
+
+gboolean
+gs_appstream_add_popular (GsPlugin *plugin,
+                         AsStore *store,
+                         GsAppList *list,
+                         GCancellable *cancellable,
+                         GError **error)
+{
+       AsApp *item;
+       GPtrArray *array;
+       guint i;
+       g_autoptr(AsProfileTask) ptask = NULL;
+
+       /* find out how many packages are in each category */
+       ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+                                         "appstream::add-popular");
+       g_assert (ptask != NULL);
+       array = as_store_get_apps (store);
+       for (i = 0; i < array->len; i++) {
+               g_autoptr(GsApp) app = NULL;
+               item = g_ptr_array_index (array, i);
+               if (as_app_get_id (item) == NULL)
+                       continue;
+               if (!as_app_has_kudo (item, "GnomeSoftware::popular"))
+                       continue;
+               app = gs_app_new (as_app_get_id (item));
+               gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+               gs_app_list_add (list, app);
+       }
+       return TRUE;
+}
+
+gboolean
+gs_appstream_add_featured (GsPlugin *plugin,
+                          AsStore *store,
+                          GsAppList *list,
+                          GCancellable *cancellable,
+                          GError **error)
+{
+       AsApp *item;
+       GPtrArray *array;
+       guint i;
+       g_autoptr(AsProfileTask) ptask = NULL;
+
+       /* find out how many packages are in each category */
+       ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+                                         "appstream::add-featured");
+       g_assert (ptask != NULL);
+       array = as_store_get_apps (store);
+       for (i = 0; i < array->len; i++) {
+               g_autoptr(GsApp) app = NULL;
+               item = g_ptr_array_index (array, i);
+               if (as_app_get_id (item) == NULL)
+                       continue;
+               if (as_app_get_metadata_item (item, "GnomeSoftware::FeatureTile-css") == NULL)
+                       continue;
+               app = gs_app_new (as_app_get_id (item));
+               gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
+               gs_app_list_add (list, app);
+       }
+       return TRUE;
+}
diff --git a/src/plugins/gs-appstream.h b/src/plugins/gs-appstream.h
index 88e8afc..d8651bd 100644
--- a/src/plugins/gs-appstream.h
+++ b/src/plugins/gs-appstream.h
@@ -53,6 +53,16 @@ gboolean      gs_appstream_store_add_category_apps   (GsPlugin       *plugin,
                                                         GsAppList      *list,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+gboolean        gs_appstream_add_popular               (GsPlugin       *plugin,
+                                                        AsStore        *store,
+                                                        GsAppList      *list,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
+gboolean        gs_appstream_add_featured              (GsPlugin       *plugin,
+                                                        AsStore        *store,
+                                                        GsAppList      *list,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index b7fa07f..94fafc3 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -2645,6 +2645,26 @@ gs_flatpak_add_categories (GsFlatpak *self,
                                                  list, cancellable, error);
 }
 
+gboolean
+gs_flatpak_add_popular (GsFlatpak *self,
+                       GsAppList *list,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+       return gs_appstream_add_popular (self->plugin, self->store, list,
+                                        cancellable, error);
+}
+
+gboolean
+gs_flatpak_add_featured (GsFlatpak *self,
+                        GsAppList *list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       return gs_appstream_add_featured (self->plugin, self->store, list,
+                                         cancellable, error);
+}
+
 static void
 gs_flatpak_finalize (GObject *object)
 {
diff --git a/src/plugins/gs-flatpak.h b/src/plugins/gs-flatpak.h
index 90f36a5..39edc25 100644
--- a/src/plugins/gs-flatpak.h
+++ b/src/plugins/gs-flatpak.h
@@ -114,6 +114,14 @@ gboolean   gs_flatpak_add_category_apps    (GsFlatpak              *self,
                                                 GsAppList              *list,
                                                 GCancellable           *cancellable,
                                                 GError                 **error);
+gboolean       gs_flatpak_add_popular          (GsFlatpak              *self,
+                                                GsAppList              *list,
+                                                GCancellable           *cancellable,
+                                                GError                 **error);
+gboolean       gs_flatpak_add_featured         (GsFlatpak              *self,
+                                                GsAppList              *list,
+                                                GCancellable           *cancellable,
+                                                GError                 **error);
 
 G_END_DECLS
 
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 2711ad2..745a6d9 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -583,28 +583,8 @@ gs_plugin_add_popular (GsPlugin *plugin,
                       GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       AsApp *item;
-       GPtrArray *array;
-       guint i;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       /* find out how many packages are in each category */
-       ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
-                                         "appstream::add-popular");
-       g_assert (ptask != NULL);
-       array = as_store_get_apps (priv->store);
-       for (i = 0; i < array->len; i++) {
-               g_autoptr(GsApp) app = NULL;
-               item = g_ptr_array_index (array, i);
-               if (as_app_get_id (item) == NULL)
-                       continue;
-               if (!as_app_has_kudo (item, "GnomeSoftware::popular"))
-                       continue;
-               app = gs_app_new (as_app_get_id (item));
-               gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
-               gs_app_list_add (list, app);
-       }
-       return TRUE;
+       return gs_appstream_add_popular (plugin, priv->store, list, cancellable,
+                                        error);
 }
 
 gboolean
@@ -614,26 +594,6 @@ gs_plugin_add_featured (GsPlugin *plugin,
                        GError **error)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
-       AsApp *item;
-       GPtrArray *array;
-       guint i;
-       g_autoptr(AsProfileTask) ptask = NULL;
-
-       /* find out how many packages are in each category */
-       ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
-                                         "appstream::add-featured");
-       g_assert (ptask != NULL);
-       array = as_store_get_apps (priv->store);
-       for (i = 0; i < array->len; i++) {
-               g_autoptr(GsApp) app = NULL;
-               item = g_ptr_array_index (array, i);
-               if (as_app_get_id (item) == NULL)
-                       continue;
-               if (as_app_get_metadata_item (item, "GnomeSoftware::FeatureTile-css") == NULL)
-                       continue;
-               app = gs_app_new (as_app_get_id (item));
-               gs_app_add_quirk (app, AS_APP_QUIRK_MATCH_ANY_PREFIX);
-               gs_app_list_add (list, app);
-       }
-       return TRUE;
+       return gs_appstream_add_featured (plugin, priv->store, list, cancellable,
+                                         error);
 }
diff --git a/src/plugins/gs-plugin-flatpak-system.c b/src/plugins/gs-plugin-flatpak-system.c
index f2c8d5a..e12086c 100644
--- a/src/plugins/gs-plugin-flatpak-system.c
+++ b/src/plugins/gs-plugin-flatpak-system.c
@@ -257,3 +257,29 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
                                             cancellable,
                                             error);
 }
+
+gboolean
+gs_plugin_add_popular (GsPlugin *plugin,
+                      GsAppList *list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       return gs_flatpak_add_popular (priv->flatpak,
+                                      list,
+                                      cancellable,
+                                      error);
+}
+
+gboolean
+gs_plugin_add_featured (GsPlugin *plugin,
+                       GsAppList *list,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       return gs_flatpak_add_featured (priv->flatpak,
+                                       list,
+                                       cancellable,
+                                       error);
+}
diff --git a/src/plugins/gs-plugin-flatpak-user.c b/src/plugins/gs-plugin-flatpak-user.c
index 902f34f..6080fd6 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -259,3 +259,29 @@ gs_plugin_add_category_apps (GsPlugin *plugin,
                                             cancellable,
                                             error);
 }
+
+gboolean
+gs_plugin_add_popular (GsPlugin *plugin,
+                      GsAppList *list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       return gs_flatpak_add_popular (priv->flatpak,
+                                      list,
+                                      cancellable,
+                                      error);
+}
+
+gboolean
+gs_plugin_add_featured (GsPlugin *plugin,
+                       GsAppList *list,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       return gs_flatpak_add_featured (priv->flatpak,
+                                       list,
+                                       cancellable,
+                                       error);
+}


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