[gnome-software: 7/8] gs-plugin-job: Combine get_sort_func() and get_sort_func_data()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 7/8] gs-plugin-job: Combine get_sort_func() and get_sort_func_data()
- Date: Mon, 26 Apr 2021 14:50:02 +0000 (UTC)
commit ccf8b6d4058682a79a5baced7afc880281a36c30
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Apr 21 15:03:34 2021 +0100
gs-plugin-job: Combine get_sort_func() and get_sort_func_data()
It doesn’t make sense to query one without the other, most of the time.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
lib/gs-plugin-job-private.h | 4 ++--
lib/gs-plugin-job.c | 11 +++--------
lib/gs-plugin-loader.c | 30 ++++++++++++++----------------
3 files changed, 19 insertions(+), 26 deletions(-)
---
diff --git a/lib/gs-plugin-job-private.h b/lib/gs-plugin-job-private.h
index 863d89014..118578961 100644
--- a/lib/gs-plugin-job-private.h
+++ b/lib/gs-plugin-job-private.h
@@ -28,8 +28,8 @@ gboolean gs_plugin_job_get_interactive (GsPluginJob *self);
guint gs_plugin_job_get_max_results (GsPluginJob *self);
guint gs_plugin_job_get_timeout (GsPluginJob *self);
guint64 gs_plugin_job_get_age (GsPluginJob *self);
-GsAppListSortFunc gs_plugin_job_get_sort_func (GsPluginJob *self);
-gpointer gs_plugin_job_get_sort_func_data (GsPluginJob *self);
+GsAppListSortFunc gs_plugin_job_get_sort_func (GsPluginJob *self,
+ gpointer *user_data_out);
const gchar *gs_plugin_job_get_search (GsPluginJob *self);
GsApp *gs_plugin_job_get_app (GsPluginJob *self);
GsAppList *gs_plugin_job_get_list (GsPluginJob *self);
diff --git a/lib/gs-plugin-job.c b/lib/gs-plugin-job.c
index 2702f1a54..5aa1ab309 100644
--- a/lib/gs-plugin-job.c
+++ b/lib/gs-plugin-job.c
@@ -277,19 +277,14 @@ gs_plugin_job_set_sort_func (GsPluginJob *self, GsAppListSortFunc sort_func, gpo
}
GsAppListSortFunc
-gs_plugin_job_get_sort_func (GsPluginJob *self)
+gs_plugin_job_get_sort_func (GsPluginJob *self, gpointer *user_data_out)
{
g_return_val_if_fail (GS_IS_PLUGIN_JOB (self), NULL);
+ if (user_data_out != NULL)
+ *user_data_out = self->sort_func_data;
return self->sort_func;
}
-gpointer
-gs_plugin_job_get_sort_func_data (GsPluginJob *self)
-{
- g_return_val_if_fail (GS_IS_PLUGIN_JOB (self), NULL);
- return self->sort_func_data;
-}
-
void
gs_plugin_job_set_search (GsPluginJob *self, const gchar *search)
{
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 0543f40d9..f26b51582 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1061,10 +1061,9 @@ gs_plugin_loader_job_sorted_truncation_again (GsPluginLoaderHelper *helper)
return;
/* unset */
- sort_func = gs_plugin_job_get_sort_func (helper->plugin_job);
+ sort_func = gs_plugin_job_get_sort_func (helper->plugin_job, &sort_func_data);
if (sort_func == NULL)
return;
- sort_func_data = gs_plugin_job_get_sort_func_data (helper->plugin_job);
gs_app_list_sort (gs_plugin_job_get_list (helper->plugin_job), sort_func, sort_func_data);
}
@@ -1072,6 +1071,7 @@ static void
gs_plugin_loader_job_sorted_truncation (GsPluginLoaderHelper *helper)
{
GsAppListSortFunc sort_func;
+ gpointer sort_func_data;
guint max_results;
GsAppList *list = gs_plugin_job_get_list (helper->plugin_job);
@@ -1091,15 +1091,13 @@ gs_plugin_loader_job_sorted_truncation (GsPluginLoaderHelper *helper)
/* nothing set */
g_debug ("truncating results to %u from %u",
max_results, gs_app_list_length (list));
- sort_func = gs_plugin_job_get_sort_func (helper->plugin_job);
+ sort_func = gs_plugin_job_get_sort_func (helper->plugin_job, &sort_func_data);
if (sort_func == NULL) {
GsPluginAction action = gs_plugin_job_get_action (helper->plugin_job);
g_debug ("no ->sort_func() set for %s, using random!",
gs_plugin_action_to_string (action));
gs_app_list_randomize (list);
} else {
- gpointer sort_func_data;
- sort_func_data = gs_plugin_job_get_sort_func_data (helper->plugin_job);
gs_app_list_sort (list, sort_func, sort_func_data);
}
gs_app_list_truncate (list, max_results);
@@ -3272,7 +3270,7 @@ gs_plugin_loader_process_thread_cb (GTask *task,
* gs_plugin_loader_job_sorted_truncation() can do what it needs */
filter_flags = gs_plugin_job_get_filter_flags (helper->plugin_job);
max_results = gs_plugin_job_get_max_results (helper->plugin_job);
- sort_func = gs_plugin_job_get_sort_func (helper->plugin_job);
+ sort_func = gs_plugin_job_get_sort_func (helper->plugin_job, NULL);
if (filter_flags > 0 && max_results > 0 && sort_func != NULL) {
g_autoptr(GsPluginLoaderHelper) helper2 = NULL;
g_autoptr(GsPluginJob) plugin_job = NULL;
@@ -3687,33 +3685,33 @@ gs_plugin_loader_job_process_async (GsPluginLoader *plugin_loader,
/* sorting fallbacks */
switch (action) {
case GS_PLUGIN_ACTION_SEARCH:
- if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+ if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_match_value_cb);
+ gs_plugin_loader_app_sort_match_value_cb, NULL);
}
break;
case GS_PLUGIN_ACTION_GET_RECENT:
- if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+ if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_kind_cb);
+ gs_plugin_loader_app_sort_kind_cb, NULL);
}
break;
case GS_PLUGIN_ACTION_GET_CATEGORY_APPS:
- if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+ if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_name_cb);
+ gs_plugin_loader_app_sort_name_cb, NULL);
}
break;
case GS_PLUGIN_ACTION_GET_ALTERNATES:
- if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+ if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_prio_cb);
+ gs_plugin_loader_app_sort_prio_cb, NULL);
}
break;
case GS_PLUGIN_ACTION_GET_DISTRO_UPDATES:
- if (gs_plugin_job_get_sort_func (plugin_job) == NULL) {
+ if (gs_plugin_job_get_sort_func (plugin_job, NULL) == NULL) {
gs_plugin_job_set_sort_func (plugin_job,
- gs_plugin_loader_app_sort_version_cb);
+ gs_plugin_loader_app_sort_version_cb, NULL);
}
break;
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]