[gnome-software/wip/kalev/gnome-3-22: 19/96] Merge the flatpak-system and flatpak-user plugins



commit d15aebd0f63550b041ab422c66ad274addd0e141
Author: Richard Hughes <richard hughsie com>
Date:   Mon Nov 28 12:28:17 2016 +0000

    Merge the flatpak-system and flatpak-user plugins
    
    This is a first step towards supporting more than one installation target per
    scope.

 contrib/gnome-software.spec.in         |    3 +-
 src/gs-self-test.c                     |   12 +-
 src/plugins/Makefile.am                |   25 +--
 src/plugins/gs-flatpak.c               |   42 +--
 src/plugins/gs-flatpak.h               |    3 +-
 src/plugins/gs-plugin-flatpak-system.c |  295 ---------------------
 src/plugins/gs-plugin-flatpak-user.c   |  279 --------------------
 src/plugins/gs-plugin-flatpak.c        |  445 ++++++++++++++++++++++++++++++++
 8 files changed, 474 insertions(+), 630 deletions(-)
---
diff --git a/contrib/gnome-software.spec.in b/contrib/gnome-software.spec.in
index 54a46bd..3adf6fe 100644
--- a/contrib/gnome-software.spec.in
+++ b/contrib/gnome-software.spec.in
@@ -157,8 +157,7 @@ glib-compile-schemas %{_datadir}/glib-2.0/schemas &> /dev/null || :
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_epiphany.so
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_fedora-distro-upgrades.so
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_fedora-tagger-usage.so
-%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_flatpak-system.so
-%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_flatpak-user.so
+%{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_flatpak.so
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_fwupd.so
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_hardcoded-blacklist.so
 %{_libdir}/gs-plugins-%{gs_plugin_version}/libgs_plugin_hardcoded-featured.so
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index ac6b6fd..4bb6ee7 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -887,7 +887,7 @@ gs_plugin_loader_flatpak_repo_func (GsPluginLoader *plugin_loader)
        g_autoptr(GsApp) app = NULL;
 
        /* no flatpak, abort */
-       if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak-user"))
+       if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
                return;
 
        /* load local file */
@@ -904,7 +904,7 @@ gs_plugin_loader_flatpak_repo_func (GsPluginLoader *plugin_loader)
        g_assert_cmpint (gs_app_get_kind (app), ==, AS_APP_KIND_SOURCE);
        g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
        g_assert_cmpstr (gs_app_get_id (app), ==, "example");
-       g_assert_cmpstr (gs_app_get_management_plugin (app), ==, "flatpak-user");
+       g_assert_cmpstr (gs_app_get_management_plugin (app), ==, "flatpak");
        g_assert_cmpstr (gs_app_get_origin_hostname(app), ==, "foo.bar");
        g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://foo.bar";);
        g_assert_cmpstr (gs_app_get_name (app), ==, "foo-bar");
@@ -984,7 +984,7 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
        g_autoptr(GsAppList) sources = NULL;
 
        /* no flatpak, abort */
-       if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak-user"))
+       if (!gs_plugin_loader_get_enabled (plugin_loader, "flatpak"))
                return;
 
        /* no files to use */
@@ -1016,7 +1016,7 @@ gs_plugin_loader_flatpak_func (GsPluginLoader *plugin_loader)
                return;
        testdir_repourl = g_strdup_printf ("file://%s/repo", testdir);
        gs_app_set_kind (app_source, AS_APP_KIND_SOURCE);
-       gs_app_set_management_plugin (app_source, "flatpak-user");
+       gs_app_set_management_plugin (app_source, "flatpak");
        gs_app_set_state (app_source, AS_APP_STATE_AVAILABLE);
        gs_app_set_metadata (app_source, "flatpak::url", testdir_repourl);
        ret = gs_plugin_loader_app_action (plugin_loader, app_source,
@@ -1303,7 +1303,7 @@ main (int argc, char **argv)
                "dpkg",
                "dummy",
                "epiphany",
-               "flatpak-user",
+               "flatpak",
                "fwupd",
                "hardcoded-blacklist",
                "desktop-categories",
@@ -1413,7 +1413,7 @@ main (int argc, char **argv)
                "      <keyword>Bingo</keyword>\n"
                "    </keywords>\n"
                "    <metadata>\n"
-               "      <value key=\"GnomeSoftware::Plugin\">flatpak-user</value>\n"
+               "      <value key=\"GnomeSoftware::Plugin\">flatpak</value>\n"
                "    </metadata>\n"
                "    <project_license>GPL-2.0+</project_license>\n"
                "    <url type=\"homepage\">http://127.0.0.1/</url>\n"
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index 555536c..dc17c2d 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -87,8 +87,7 @@ plugin_LTLIBRARIES += libgs_plugin_fwupd.la
 endif
 
 if HAVE_FLATPAK
-plugin_LTLIBRARIES += libgs_plugin_flatpak-system.la
-plugin_LTLIBRARIES += libgs_plugin_flatpak-user.la
+plugin_LTLIBRARIES += libgs_plugin_flatpak.la
 endif
 
 if HAVE_OSTREE
@@ -186,29 +185,17 @@ libgs_plugin_limba_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 endif
 
 if HAVE_FLATPAK
-libgs_plugin_flatpak_system_la_SOURCES =               \
+libgs_plugin_flatpak_la_SOURCES =                      \
        gs-appstream.c                                  \
        gs-appstream.h                                  \
        gs-flatpak.c                                    \
        gs-flatpak.h                                    \
        gs-flatpak-symlinks.c                           \
        gs-flatpak-symlinks.h                           \
-       gs-plugin-flatpak-system.c
-libgs_plugin_flatpak_system_la_LIBADD = $(GS_PLUGIN_LIBS) $(FLATPAK_LIBS)
-libgs_plugin_flatpak_system_la_LDFLAGS = -module -avoid-version
-libgs_plugin_flatpak_system_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
-
-libgs_plugin_flatpak_user_la_SOURCES =                 \
-       gs-appstream.c                                  \
-       gs-appstream.h                                  \
-       gs-flatpak.c                                    \
-       gs-flatpak.h                                    \
-       gs-flatpak-symlinks.c                           \
-       gs-flatpak-symlinks.h                           \
-       gs-plugin-flatpak-user.c
-libgs_plugin_flatpak_user_la_LIBADD = $(GS_PLUGIN_LIBS) $(FLATPAK_LIBS)
-libgs_plugin_flatpak_user_la_LDFLAGS = -module -avoid-version
-libgs_plugin_flatpak_user_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
+       gs-plugin-flatpak.c
+libgs_plugin_flatpak_la_LIBADD = $(GS_PLUGIN_LIBS) $(FLATPAK_LIBS)
+libgs_plugin_flatpak_la_LDFLAGS = -module -avoid-version
+libgs_plugin_flatpak_la_CFLAGS = $(GS_PLUGIN_CFLAGS) $(WARN_CFLAGS)
 endif
 
 if HAVE_OSTREE
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 5a0cf3c..75b6282 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -359,9 +359,12 @@ gs_flatpak_rescan_appstream_store (GsFlatpak *self,
 gboolean
 gs_flatpak_setup (GsFlatpak *self, GCancellable *cancellable, GError **error)
 {
-       const gchar *destdir;
        g_autoptr(AsProfileTask) ptask = NULL;
 
+       ptask = as_profile_start_literal (gs_plugin_get_profile (self->plugin),
+                                         "flatpak::setup");
+       g_assert (ptask != NULL);
+
        /* load just the wildcards */
        if (!as_store_load (self->store,
                            AS_STORE_LOAD_FLAG_ONLY_MERGE_APPS |
@@ -372,31 +375,6 @@ gs_flatpak_setup (GsFlatpak *self, GCancellable *cancellable, GError **error)
                return FALSE;
        }
 
-       /* we use a permissions helper to elevate privs */
-       ptask = as_profile_start_literal (gs_plugin_get_profile (self->plugin),
-                                         "flatpak::setup");
-       g_assert (ptask != NULL);
-       destdir = g_getenv ("GS_SELF_TEST_FLATPACK_DATADIR");
-       if (destdir != NULL) {
-               g_autofree gchar *full_path = g_build_filename (destdir,
-                                                               "flatpak",
-                                                               NULL);
-               g_autoptr(GFile) file = g_file_new_for_path (full_path);
-               g_debug ("using custom flatpak path %s", full_path);
-               self->installation = flatpak_installation_new_for_path (file, TRUE,
-                                                                       cancellable,
-                                                                       error);
-       } else if (self->scope == AS_APP_SCOPE_SYSTEM) {
-               self->installation = flatpak_installation_new_system (cancellable,
-                                                                     error);
-       } else if (self->scope == AS_APP_SCOPE_USER) {
-               self->installation = flatpak_installation_new_user (cancellable,
-                                                                   error);
-       }
-       if (self->installation == NULL) {
-               return FALSE;
-       }
-
        /* watch for changes */
        self->monitor = flatpak_installation_create_monitor (self->installation,
                                                             cancellable,
@@ -2649,6 +2627,12 @@ gs_flatpak_store_app_removed_cb (AsStore *store, AsApp *app, GsFlatpak *self)
        gs_plugin_cache_remove (self->plugin, as_app_get_unique_id (app));
 }
 
+AsAppScope
+gs_flatpak_get_scope (GsFlatpak *self)
+{
+       return self->scope;
+}
+
 static void
 gs_flatpak_finalize (GObject *object)
 {
@@ -2687,11 +2671,13 @@ gs_flatpak_init (GsFlatpak *self)
 }
 
 GsFlatpak *
-gs_flatpak_new (GsPlugin *plugin, AsAppScope scope)
+gs_flatpak_new (GsPlugin *plugin, FlatpakInstallation *installation)
 {
        GsFlatpak *self;
        self = g_object_new (GS_TYPE_FLATPAK, NULL);
-       self->scope = scope;
+       self->installation = g_object_ref (installation);
+       self->scope = flatpak_installation_get_is_user (installation)
+                               ? AS_APP_SCOPE_USER : AS_APP_SCOPE_SYSTEM;
        self->plugin = g_object_ref (plugin);
        return GS_FLATPAK (self);
 }
diff --git a/src/plugins/gs-flatpak.h b/src/plugins/gs-flatpak.h
index f2dc4ef..5eb13ed 100644
--- a/src/plugins/gs-flatpak.h
+++ b/src/plugins/gs-flatpak.h
@@ -45,7 +45,8 @@ G_DECLARE_FINAL_TYPE (GsFlatpak, gs_flatpak, GS, FLATPAK, GObject)
 #define        gs_app_set_flatpak_file_type(app,val)   gs_app_set_metadata(app,"flatpak::file-type",val)
 
 GsFlatpak      *gs_flatpak_new                 (GsPlugin               *plugin,
-                                                AsAppScope              scope);
+                                                FlatpakInstallation    *installation);
+AsAppScope     gs_flatpak_get_scope            (GsFlatpak              *self);
 gboolean       gs_flatpak_setup                (GsFlatpak              *self,
                                                 GCancellable           *cancellable,
                                                 GError                 **error);
diff --git a/src/plugins/gs-plugin-flatpak.c b/src/plugins/gs-plugin-flatpak.c
new file mode 100644
index 0000000..05e7ae9
--- /dev/null
+++ b/src/plugins/gs-plugin-flatpak.c
@@ -0,0 +1,445 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Joaquim Rocha <jrocha endlessm com>
+ * Copyright (C) 2016 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/* Notes:
+ *
+ * All GsApp's created have management-plugin set to flatpak
+ * Some GsApp's created have have flatpak::kind of app or runtime
+ * The GsApp:origin is the remote name, e.g. test-repo
+ */
+
+#include <config.h>
+
+#include <flatpak.h>
+#include <gnome-software.h>
+
+#include "gs-appstream.h"
+#include "gs-flatpak.h"
+
+struct GsPluginData {
+       GPtrArray               *flatpaks; /* of GsFlatpak */
+       gboolean                 has_system_helper;
+       const gchar             *destdir_for_tests;
+};
+
+void
+gs_plugin_initialize (GsPlugin *plugin)
+{
+       GsPluginData *priv = gs_plugin_alloc_data (plugin, sizeof(GsPluginData));
+       const gchar *action_id = "org.freedesktop.Flatpak.appstream-update";
+       g_autoptr(GPermission) permission = NULL;
+
+       priv->flatpaks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+
+       /* old names */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "flatpak-system");
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_CONFLICTS, "flatpak-session");
+
+       /* set plugin flags */
+       gs_plugin_add_flags (plugin, GS_PLUGIN_FLAGS_GLOBAL_CACHE);
+
+       /* getting app properties from appstream is quicker */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_RUN_AFTER, "appstream");
+
+       /* prioritize over packages */
+       gs_plugin_add_rule (plugin, GS_PLUGIN_RULE_BETTER_THAN, "packagekit");
+
+       /* if we can't update the AppStream database system-wide don't even
+        * pull the data as we can't do anything with it */
+       permission = gs_utils_get_permission (action_id);
+       if (permission != NULL) {
+               priv->has_system_helper = g_permission_get_allowed (permission) ||
+                                         g_permission_get_can_acquire (permission);
+       }
+
+       /* used for self tests */
+       priv->destdir_for_tests = g_getenv ("GS_SELF_TEST_FLATPACK_DATADIR");
+}
+
+void
+gs_plugin_destroy (GsPlugin *plugin)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_ptr_array_unref (priv->flatpaks);
+}
+
+void
+gs_plugin_adopt_app (GsPlugin *plugin, GsApp *app)
+{
+       if (gs_app_get_bundle_kind (app) == AS_BUNDLE_KIND_FLATPAK)
+               gs_app_set_management_plugin (app, gs_plugin_get_name (plugin));
+}
+
+static gboolean
+gs_plugin_flatpak_add_installation (GsPlugin *plugin,
+                                   FlatpakInstallation *installation,
+                                   GCancellable *cancellable,
+                                   GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       g_autoptr(AsProfileTask) ptask = NULL;
+       g_autoptr(GsFlatpak) flatpak = NULL;
+
+       ptask = as_profile_start_literal (gs_plugin_get_profile (plugin),
+                                         "flatpak::add-installation");
+       g_assert (ptask != NULL);
+
+       /* create and set up */
+       flatpak = gs_flatpak_new (plugin, installation);
+       if (!gs_flatpak_setup (flatpak, cancellable, error))
+               return FALSE;
+
+       /* add objects that set up correctly */
+       g_ptr_array_add (priv->flatpaks, g_steal_pointer (&flatpak));
+       return TRUE;
+}
+
+gboolean
+gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+
+       /* we use a permissions helper to elevate privs */
+       if (priv->has_system_helper && priv->destdir_for_tests == NULL) {
+               g_autoptr(FlatpakInstallation) installation = NULL;
+               installation = flatpak_installation_new_system (cancellable, error);
+               if (installation == NULL) {
+                       return FALSE;
+               }
+               if (!gs_plugin_flatpak_add_installation (plugin, installation,
+                                                        cancellable, error)) {
+                       return FALSE;
+               }
+       }
+
+       /* in gs-self-test */
+       if (priv->destdir_for_tests != NULL) {
+               g_autofree gchar *full_path = g_build_filename (priv->destdir_for_tests,
+                                                               "flatpak",
+                                                               NULL);
+               g_autoptr(GFile) file = g_file_new_for_path (full_path);
+               g_autoptr(FlatpakInstallation) installation = NULL;
+               g_debug ("using custom flatpak path %s", full_path);
+               installation = flatpak_installation_new_for_path (file, TRUE,
+                                                                 cancellable,
+                                                                 error);
+               if (installation == NULL) {
+                       return FALSE;
+               }
+               if (!gs_plugin_flatpak_add_installation (plugin, installation,
+                                                        cancellable, error)) {
+                       return FALSE;
+               }
+       }
+
+       /* per-user instalations always available when not in self tests */
+       if (priv->destdir_for_tests == NULL) {
+               g_autoptr(FlatpakInstallation) installation = NULL;
+               installation = flatpak_installation_new_user (cancellable, error);
+               if (installation == NULL) {
+                       return FALSE;
+               }
+               if (!gs_plugin_flatpak_add_installation (plugin, installation,
+                                                        cancellable, error)) {
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_installed (GsPlugin *plugin,
+                        GsAppList *list,
+                        GCancellable *cancellable,
+                        GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_installed (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_sources (GsPlugin *plugin,
+                      GsAppList *list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_sources (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_updates (GsPlugin *plugin,
+                      GsAppList *list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_updates (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_refresh (GsPlugin *plugin,
+                  guint cache_age,
+                  GsPluginRefreshFlags flags,
+                  GCancellable *cancellable,
+                  GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_refresh (flatpak, cache_age, flags,
+                                        cancellable, error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_refine_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GsPluginRefineFlags flags,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_refine_app (flatpak, app, flags,
+                                           cancellable, error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_refine_wildcard (GsPlugin *plugin,
+                          GsApp *app,
+                          GsAppList *list,
+                          GsPluginRefineFlags flags,
+                          GCancellable *cancellable,
+                          GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_refine_wildcard (flatpak, app, list, flags,
+                                                cancellable, error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_launch (GsPlugin *plugin,
+                 GsApp *app,
+                 GCancellable *cancellable,
+                 GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_launch (flatpak, app, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_app_remove (GsPlugin *plugin,
+                     GsApp *app,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_app_remove (flatpak, app, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_app_install (GsPlugin *plugin,
+                      GsApp *app,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_app_install (flatpak, app, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_update_app (GsPlugin *plugin,
+                     GsApp *app,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_update_app (flatpak, app, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_file_to_app (GsPlugin *plugin,
+                      GsAppList *list,
+                      GFile *file,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       AsAppScope scope = AS_APP_SCOPE_UNKNOWN;
+
+       /* get the policy for handling of local files when the helper is available */
+       if (priv->has_system_helper && priv->destdir_for_tests == NULL) {
+               g_autoptr(GSettings) settings = g_settings_new ("org.gnome.software");
+               scope = g_settings_get_boolean (settings, "install-bundles-system-wide") ?
+                               AS_APP_SCOPE_SYSTEM : AS_APP_SCOPE_USER;
+       }
+
+       /* run any objects with the corrext scope */
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (scope != AS_APP_SCOPE_UNKNOWN &&
+                   scope != gs_flatpak_get_scope (flatpak)) {
+                       g_debug ("not handling bundle as scope incorrect");
+                       continue;
+               }
+               if (!gs_flatpak_file_to_app (flatpak, list, file,
+                                            cancellable, error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_search (GsPlugin *plugin,
+                     gchar **values,
+                     GsAppList *list,
+                     GCancellable *cancellable,
+                     GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_search (flatpak, values, list,
+                                       cancellable, error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_categories (GsPlugin *plugin,
+                         GPtrArray *list,
+                         GCancellable *cancellable,
+                         GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_categories (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_category_apps (GsPlugin *plugin,
+                            GsCategory *category,
+                            GsAppList *list,
+                            GCancellable *cancellable,
+                            GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_category_apps (flatpak,
+                                                  category,
+                                                  list,
+                                                  cancellable,
+                                                  error)) {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_popular (GsPlugin *plugin,
+                      GsAppList *list,
+                      GCancellable *cancellable,
+                      GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_popular (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+gboolean
+gs_plugin_add_featured (GsPlugin *plugin,
+                       GsAppList *list,
+                       GCancellable *cancellable,
+                       GError **error)
+{
+       GsPluginData *priv = gs_plugin_get_data (plugin);
+       for (guint i = 0; i < priv->flatpaks->len; i++) {
+               GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, i);
+               if (!gs_flatpak_add_featured (flatpak, list, cancellable, error))
+                       return FALSE;
+       }
+       return TRUE;
+}


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