[gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 148/156] gs-app-query: Add 'other-apps' property




commit 0fdede2ea5c5abcf9694b8ba1ac27777e2a5e5c9
Author: Milan Crha <mcrha redhat com>
Date:   Fri May 6 10:28:13 2022 +0200

    gs-app-query: Add 'other-apps' property
    
    Will be used to search for other apps of a given developer or project group.

 lib/gs-app-query.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/gs-app-query.h |  1 +
 2 files changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/lib/gs-app-query.c b/lib/gs-app-query.c
index ec07757b5..84952282b 100644
--- a/lib/gs-app-query.c
+++ b/lib/gs-app-query.c
@@ -73,6 +73,8 @@ struct _GsAppQuery
        /* This is guaranteed to either be %NULL, or a non-empty array */
        gchar **provides_files;  /* (owned) (nullable) (array zero-terminated=1) */
        GDateTime *released_since;  /* (owned) (nullable) */
+       /* This is guaranteed to either be %NULL, or a non-empty array */
+       gchar **other_apps;  /* (owned) (nullable) (array zero-terminated=1) */
 };
 
 G_DEFINE_TYPE (GsAppQuery, gs_app_query, G_TYPE_OBJECT)
@@ -89,9 +91,10 @@ typedef enum {
        PROP_FILTER_USER_DATA_NOTIFY,
        PROP_PROVIDES_FILES,
        PROP_RELEASED_SINCE,
+       PROP_OTHER_APPS,
 } GsAppQueryProperty;
 
-static GParamSpec *props[PROP_RELEASED_SINCE + 1] = { NULL, };
+static GParamSpec *props[PROP_OTHER_APPS + 1] = { NULL, };
 
 static void
 gs_app_query_get_property (GObject    *object,
@@ -135,6 +138,9 @@ gs_app_query_get_property (GObject    *object,
        case PROP_RELEASED_SINCE:
                g_value_set_boxed (value, self->released_since);
                break;
+       case PROP_OTHER_APPS:
+               g_value_set_boxed (value, self->other_apps);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -209,6 +215,16 @@ gs_app_query_set_property (GObject      *object,
                /* Construct only. */
                g_assert (self->released_since == NULL);
                self->released_since = g_value_dup_boxed (value);
+               break;
+       case PROP_OTHER_APPS:
+               /* Construct only. */
+               g_assert (self->other_apps == NULL);
+               self->other_apps  = g_value_dup_boxed (value);
+
+               /* Squash empty arrays to %NULL. */
+               if (self->other_apps != NULL && self->other_apps[0] == NULL)
+                       g_clear_pointer (&self->other_apps, g_strfreev);
+
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -241,6 +257,7 @@ gs_app_query_finalize (GObject *object)
 
        g_clear_pointer (&self->provides_files, g_strfreev);
        g_clear_pointer (&self->released_since, g_date_time_unref);
+       g_clear_pointer (&self->other_apps, g_strfreev);
 
        G_OBJECT_CLASS (gs_app_query_parent_class)->finalize (object);
 }
@@ -429,6 +446,25 @@ gs_app_query_class_init (GsAppQueryClass *klass)
                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                    G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+       /**
+        * GsAppQuery:other_apps: (nullable)
+        *
+        * A list of developers to search the apps for.
+        *
+        * Used to search for apps which are provided by given developers.
+        *
+        * This may be %NULL to not filter on by them. An empty array is
+        * considered equivalent to %NULL.
+        *
+        * Since: 43
+        */
+       props[PROP_OTHER_APPS] =
+               g_param_spec_boxed ("other-apps", "Other Apps",
+                                   "A list of developers, whom provide the apps.",
+                                   G_TYPE_STRV,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+                                   G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
        g_object_class_install_properties (object_class, G_N_ELEMENTS (props), props);
 }
 
@@ -598,3 +634,24 @@ gs_app_query_get_released_since (GsAppQuery *self)
 
        return self->released_since;
 }
+
+/**
+ * gs_app_query_get_other_apps:
+ * @self: a #GsAppQuery
+ *
+ * Get the value of #GsAppQuery:other-apps.
+ *
+ * Returns: (nullable): a list of developers, whom provide the apps,
+ *   or %NULL to not filter by it
+ * Since: 43
+ */
+const gchar * const *
+gs_app_query_get_other_apps (GsAppQuery *self)
+{
+       g_return_val_if_fail (GS_IS_APP_QUERY (self), NULL);
+
+       /* Always return %NULL or a non-empty array */
+       g_assert (self->other_apps == NULL || self->other_apps[0] != NULL);
+
+       return (const gchar * const *) self->other_apps;
+}
diff --git a/lib/gs-app-query.h b/lib/gs-app-query.h
index 23e1c95ab..2ad0548e3 100644
--- a/lib/gs-app-query.h
+++ b/lib/gs-app-query.h
@@ -36,5 +36,6 @@ GsAppListFilterFunc    gs_app_query_get_filter_func   (GsAppQuery *self,
 
 const gchar * const    *gs_app_query_get_provides_files (GsAppQuery *self);
 GDateTime              *gs_app_query_get_released_since (GsAppQuery *self);
+const gchar * const    *gs_app_query_get_other_apps    (GsAppQuery *self);
 
 G_END_DECLS


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