[gnome-software: 5/24] gs-plugin-helpers: Add helpers for list_apps




commit dd9bbf6bc6aa108840c9c8d98887bf4d2760d28a
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Apr 13 22:49:05 2022 +0100

    gs-plugin-helpers: Add helpers for list_apps
    
    These will be used in upcoming commits.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #1472

 lib/gs-plugin-helpers.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gs-plugin-helpers.h | 16 ++++++++++++
 2 files changed, 85 insertions(+)
---
diff --git a/lib/gs-plugin-helpers.c b/lib/gs-plugin-helpers.c
index ab409ec3f..753e9415e 100644
--- a/lib/gs-plugin-helpers.c
+++ b/lib/gs-plugin-helpers.c
@@ -130,3 +130,72 @@ gs_plugin_refresh_metadata_data_free (GsPluginRefreshMetadataData *data)
 {
        g_free (data);
 }
+
+/**
+ * gs_plugin_list_apps_data_new:
+ * @query: (nullable) (transfer none): a query to filter apps, or %NULL for
+ *   no filtering
+ * @flags: list apps flags
+ *
+ * Context data for a call to #GsPluginClass.list_apps_async.
+ *
+ * Returns: (transfer full): context data structure
+ * Since: 43
+ */
+GsPluginListAppsData *
+gs_plugin_list_apps_data_new (GsAppQuery            *query,
+                              GsPluginListAppsFlags  flags)
+{
+       g_autoptr(GsPluginListAppsData) data = g_new0 (GsPluginListAppsData, 1);
+       data->query = (query != NULL) ? g_object_ref (query) : NULL;
+       data->flags = flags;
+
+       return g_steal_pointer (&data);
+}
+
+/**
+ * gs_plugin_list_apps_data_new_task:
+ * @source_object: task source object
+ * @query: (nullable) (transfer none): a query to filter apps, or %NULL for
+ *   no filtering
+ * @flags: list apps flags
+ * @cancellable: (nullable): a #GCancellable, or %NULL
+ * @callback: function to call once asynchronous operation is finished
+ * @user_data: data to pass to @callback
+ *
+ * Create a #GTask for a list apps operation with the given arguments. The task
+ * data will be set to a #GsPluginListAppsData containing the given context.
+ *
+ * This is essentially a combination of gs_plugin_list_apps_data_new(),
+ * g_task_new() and g_task_set_task_data().
+ *
+ * Returns: (transfer full): new #GTask with the given context data
+ * Since: 43
+ */
+GTask *
+gs_plugin_list_apps_data_new_task (gpointer               source_object,
+                                   GsAppQuery            *query,
+                                   GsPluginListAppsFlags  flags,
+                                   GCancellable          *cancellable,
+                                   GAsyncReadyCallback    callback,
+                                   gpointer               user_data)
+{
+       g_autoptr(GTask) task = g_task_new (source_object, cancellable, callback, user_data);
+       g_task_set_task_data (task, gs_plugin_list_apps_data_new (query, flags), (GDestroyNotify) 
gs_plugin_list_apps_data_free);
+       return g_steal_pointer (&task);
+}
+
+/**
+ * gs_plugin_list_apps_data_free:
+ * @data: (transfer full): a #GsPluginListAppsData
+ *
+ * Free the given @data.
+ *
+ * Since: 43
+ */
+void
+gs_plugin_list_apps_data_free (GsPluginListAppsData *data)
+{
+       g_clear_object (&data->query);
+       g_free (data);
+}
diff --git a/lib/gs-plugin-helpers.h b/lib/gs-plugin-helpers.h
index c061ee198..3d7f2347b 100644
--- a/lib/gs-plugin-helpers.h
+++ b/lib/gs-plugin-helpers.h
@@ -44,4 +44,20 @@ GsPluginRefreshMetadataData *gs_plugin_refresh_metadata_data_new (guint64
 void gs_plugin_refresh_metadata_data_free (GsPluginRefreshMetadataData *data);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GsPluginRefreshMetadataData, gs_plugin_refresh_metadata_data_free)
 
+typedef struct {
+       GsAppQuery *query;  /* (owned) (nullable) */
+       GsPluginListAppsFlags flags;
+} GsPluginListAppsData;
+
+GsPluginListAppsData *gs_plugin_list_apps_data_new (GsAppQuery            *query,
+                                                    GsPluginListAppsFlags  flags);
+GTask *gs_plugin_list_apps_data_new_task (gpointer               source_object,
+                                          GsAppQuery            *query,
+                                          GsPluginListAppsFlags  flags,
+                                          GCancellable          *cancellable,
+                                          GAsyncReadyCallback    callback,
+                                          gpointer               user_data);
+void gs_plugin_list_apps_data_free (GsPluginListAppsData *data);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (GsPluginListAppsData, gs_plugin_list_apps_data_free)
+
 G_END_DECLS


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