[gnome-software/1409-add-available-for-fedora-section-to-the-explore-page: 1237/1241] gs-appstream: Add gs_appstream_add_deployment_featured()




commit 802ec25fe724907c30863247fc95678054815379
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 6 11:51:30 2022 +0200

    gs-appstream: Add gs_appstream_add_deployment_featured()
    
    To be used to get featured apps in given deployments.

 lib/gs-appstream.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
 lib/gs-appstream.h |  5 +++++
 2 files changed, 45 insertions(+), 9 deletions(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index d8e9ba5ac..962e985d7 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -1779,20 +1779,18 @@ gs_appstream_add_alternates (XbSilo *silo,
        return TRUE;
 }
 
-gboolean
-gs_appstream_add_featured (XbSilo *silo,
-                          GsAppList *list,
-                          GCancellable *cancellable,
-                          GError **error)
+static gboolean
+gs_appstream_add_featured_with_query (XbSilo *silo,
+                                     const gchar *query,
+                                     GsAppList *list,
+                                     GCancellable *cancellable,
+                                     GError **error)
 {
        g_autoptr(GError) error_local = NULL;
        g_autoptr(GPtrArray) array = NULL;
 
        /* find out how many packages are in each category */
-       array = xb_silo_query (silo,
-                              "components/component/custom/value[@key='GnomeSoftware::FeatureTile']/../..|"
-                              
"components/component/custom/value[@key='GnomeSoftware::FeatureTile-css']/../..",
-                              0, &error_local);
+       array = xb_silo_query (silo, query, 0, &error_local);
        if (array == NULL) {
                if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
                        return TRUE;
@@ -1816,6 +1814,39 @@ gs_appstream_add_featured (XbSilo *silo,
        return TRUE;
 }
 
+gboolean
+gs_appstream_add_featured (XbSilo *silo,
+                          GsAppList *list,
+                          GCancellable *cancellable,
+                          GError **error)
+{
+       const gchar *query = "components/component/custom/value[@key='GnomeSoftware::FeatureTile']/../..|"
+                            "components/component/custom/value[@key='GnomeSoftware::FeatureTile-css']/../..";
+       return gs_appstream_add_featured_with_query (silo, query, list, cancellable, error);
+}
+
+gboolean
+gs_appstream_add_deployment_featured (XbSilo *silo,
+                                     const gchar * const *deployments,
+                                     GsAppList *list,
+                                     GCancellable *cancellable,
+                                     GError **error)
+{
+       g_autoptr(GString) query = g_string_new (NULL);
+       g_return_val_if_fail (deployments != NULL, FALSE);
+       for (guint ii = 0; deployments[ii] != NULL; ii++) {
+               g_autofree gchar *escaped = xb_string_escape (deployments[ii]);
+               if (escaped != NULL && *escaped != '\0') {
+                       xb_string_append_union (query,
+                               
"components/component/custom/value[@key='GnomeSoftware::DeploymentFeatured'][text()='%s']/../..",
+                               escaped);
+               }
+       }
+       if (!query->len)
+               return TRUE;
+       return gs_appstream_add_featured_with_query (silo, query->str, list, cancellable, error);
+}
+
 gboolean
 gs_appstream_url_to_app (GsPlugin *plugin,
                         XbSilo *silo,
diff --git a/lib/gs-appstream.h b/lib/gs-appstream.h
index 2900a0c64..d82a3f889 100644
--- a/lib/gs-appstream.h
+++ b/lib/gs-appstream.h
@@ -47,6 +47,11 @@ gboolean      gs_appstream_add_featured              (XbSilo         *silo,
                                                         GsAppList      *list,
                                                         GCancellable   *cancellable,
                                                         GError         **error);
+gboolean        gs_appstream_add_deployment_featured   (XbSilo         *silo,
+                                                        const gchar * const *deployments,
+                                                        GsAppList      *list,
+                                                        GCancellable   *cancellable,
+                                                        GError         **error);
 gboolean        gs_appstream_add_alternates            (XbSilo         *silo,
                                                         GsApp          *app,
                                                         GsAppList      *list,


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