[gnome-software/wip/kalev/gnome-3-22-prep: 50/52] Implement add_popular and add_featured in the Flatpak plugins



commit 04f8e4b23646fd6a55881f0af630303b6584bffd
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.
    
    (cherry picked from commit 31c5699932b2476fc0d5fd8a780d394d72f729c8)

 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 c060491..1916ca8 100644
--- a/src/plugins/gs-appstream.c
+++ b/src/plugins/gs-appstream.c
@@ -930,3 +930,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 8085b0c..c37eced 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -2420,6 +2420,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 d7c4865..4a50a22 100644
--- a/src/plugins/gs-flatpak.h
+++ b/src/plugins/gs-flatpak.h
@@ -110,6 +110,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 0adf108..7804f20 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -565,28 +565,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
@@ -596,26 +576,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 240abeb..013eaa0 100644
--- a/src/plugins/gs-plugin-flatpak-system.c
+++ b/src/plugins/gs-plugin-flatpak-system.c
@@ -247,3 +247,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 9c3ff48..ee5e40c 100644
--- a/src/plugins/gs-plugin-flatpak-user.c
+++ b/src/plugins/gs-plugin-flatpak-user.c
@@ -249,3 +249,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]