[gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 151/156] flatpak: Implement search for other apps
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1364-implement-other-apps-by-author-section-in-app-details-page: 151/156] flatpak: Implement search for other apps
- Date: Fri, 6 May 2022 08:51:37 +0000 (UTC)
commit 71e5bff4d6a3109c80c68da9f422ba4693c8dc9f
Author: Milan Crha <mcrha redhat com>
Date: Fri May 6 10:39:35 2022 +0200
flatpak: Implement search for other apps
plugins/flatpak/gs-flatpak.c | 74 +++++++++++++++++++++++++++++++++++++
plugins/flatpak/gs-flatpak.h | 6 +++
plugins/flatpak/gs-plugin-flatpak.c | 16 ++++++--
3 files changed, 93 insertions(+), 3 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index c1185413f..c915e242b 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -4012,6 +4012,80 @@ gs_flatpak_search (GsFlatpak *self,
return TRUE;
}
+gboolean
+gs_flatpak_search_other_apps (GsFlatpak *self,
+ const gchar * const *values,
+ GsAppList *list,
+ gboolean interactive,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GsAppList) list_tmp = gs_app_list_new ();
+ g_autoptr(GRWLockReaderLocker) locker = NULL;
+ g_autoptr(GMutexLocker) app_silo_locker = NULL;
+ g_autoptr(GPtrArray) silos_to_remove = g_ptr_array_new ();
+ GHashTableIter iter;
+ gpointer key, value;
+
+ if (!gs_flatpak_rescan_app_data (self, interactive, cancellable, error))
+ return FALSE;
+
+ locker = g_rw_lock_reader_locker_new (&self->silo_lock);
+ if (!gs_appstream_search_other_apps (self->plugin, self->silo, values, list_tmp,
+ cancellable, error))
+ return FALSE;
+
+ gs_flatpak_ensure_remote_title (self, interactive, cancellable);
+
+ gs_flatpak_claim_app_list (self, list_tmp, interactive);
+ gs_app_list_add_list (list, list_tmp);
+
+ /* Also search silos from installed apps which were missing from self->silo */
+ app_silo_locker = g_mutex_locker_new (&self->app_silos_mutex);
+ g_hash_table_iter_init (&iter, self->app_silos);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ g_autoptr(XbSilo) app_silo = g_object_ref (value);
+ g_autoptr(GsAppList) app_list_tmp = gs_app_list_new ();
+ const char *app_ref = (char *)key;
+ g_autoptr(FlatpakInstalledRef) installed_ref = NULL;
+ g_auto(GStrv) split = NULL;
+ FlatpakRefKind kind;
+
+ /* Ignore any silos of apps that have since been removed.
+ * FIXME: can we use self->installed_refs here? */
+ split = g_strsplit (app_ref, "/", -1);
+ g_assert (g_strv_length (split) == 4);
+ if (g_strcmp0 (split[0], "app") == 0)
+ kind = FLATPAK_REF_KIND_APP;
+ else
+ kind = FLATPAK_REF_KIND_RUNTIME;
+ installed_ref = flatpak_installation_get_installed_ref (gs_flatpak_get_installation (self,
interactive),
+ kind,
+ split[1],
+ split[2],
+ split[3],
+ NULL, NULL);
+ if (installed_ref == NULL) {
+ g_ptr_array_add (silos_to_remove, (gpointer) app_ref);
+ continue;
+ }
+
+ if (!gs_appstream_search (self->plugin, app_silo, values, app_list_tmp,
+ cancellable, error))
+ return FALSE;
+
+ gs_flatpak_claim_app_list (self, app_list_tmp, interactive);
+ gs_app_list_add_list (list, app_list_tmp);
+ }
+
+ for (guint i = 0; i < silos_to_remove->len; i++) {
+ const char *silo = g_ptr_array_index (silos_to_remove, i);
+ g_hash_table_remove (self->app_silos, silo);
+ }
+
+ return TRUE;
+}
+
gboolean
gs_flatpak_add_category_apps (GsFlatpak *self,
GsCategory *category,
diff --git a/plugins/flatpak/gs-flatpak.h b/plugins/flatpak/gs-flatpak.h
index 3c4724897..6d35c00a9 100644
--- a/plugins/flatpak/gs-flatpak.h
+++ b/plugins/flatpak/gs-flatpak.h
@@ -125,6 +125,12 @@ gboolean gs_flatpak_search (GsFlatpak *self,
gboolean interactive,
GCancellable *cancellable,
GError **error);
+gboolean gs_flatpak_search_other_apps (GsFlatpak *self,
+ const gchar * const *values,
+ GsAppList *list,
+ gboolean interactive,
+ GCancellable *cancellable,
+ GError **error);
gboolean gs_flatpak_add_categories (GsFlatpak *self,
GPtrArray *list,
gboolean interactive,
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index c8c994b6c..bbbd12c00 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -1953,19 +1953,22 @@ list_apps_thread_cb (GTask *task,
gboolean interactive = (data->flags & GS_PLUGIN_LIST_APPS_FLAGS_INTERACTIVE);
GDateTime *released_since = NULL;
guint64 age_secs = 0;
+ const gchar *const *other_apps = NULL;
g_autoptr(GError) local_error = NULL;
assert_in_worker (self);
- if (data->query != NULL)
+ if (data->query != NULL) {
released_since = gs_app_query_get_released_since (data->query);
+ other_apps = gs_app_query_get_other_apps (data->query);
+ }
if (released_since != NULL) {
g_autoptr(GDateTime) now = g_date_time_new_now_local ();
age_secs = g_date_time_difference (now, released_since) / G_TIME_SPAN_SECOND;
}
/* Currently only support released-since queries. */
- if (released_since == NULL) {
+ if (released_since == NULL && other_apps == NULL) {
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unsupported query");
return;
@@ -1974,7 +1977,14 @@ list_apps_thread_cb (GTask *task,
for (guint i = 0; i < self->installations->len; i++) {
GsFlatpak *flatpak = g_ptr_array_index (self->installations, i);
- if (!gs_flatpak_add_recent (flatpak, list, age_secs, interactive, cancellable, &local_error))
{
+ if (released_since != NULL &&
+ !gs_flatpak_add_recent (flatpak, list, age_secs, interactive, cancellable, &local_error))
{
+ g_task_return_error (task, g_steal_pointer (&local_error));
+ return;
+ }
+
+ if (other_apps != NULL &&
+ !gs_flatpak_search_other_apps (flatpak, other_apps, list, interactive, cancellable,
&local_error)) {
g_task_return_error (task, g_steal_pointer (&local_error));
return;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]