[gnome-builder/wip/gtk4-port] plugins/flatpak: add run command provider
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] plugins/flatpak: add run command provider
- Date: Sat, 21 May 2022 20:20:20 +0000 (UTC)
commit ecabf3f4120ed27ba300275f41f3f8da6e58dc04
Author: Christian Hergert <chergert redhat com>
Date: Sat May 21 13:19:13 2022 -0700
plugins/flatpak: add run command provider
There isn't anything using this yet, but the goal is to change all of the
build system plugins to use this so that we can drop "run" stuff from the
IdeBuildTarget infrastructure.
Once that is done, we can drop GbpFlatpakBuildTargetProvider too.
src/plugins/flatpak/flatpak-plugin.c | 4 +
.../flatpak/gbp-flatpak-run-command-provider.c | 147 +++++++++++++++++++++
.../flatpak/gbp-flatpak-run-command-provider.h | 31 +++++
src/plugins/flatpak/meson.build | 1 +
4 files changed, 183 insertions(+)
---
diff --git a/src/plugins/flatpak/flatpak-plugin.c b/src/plugins/flatpak/flatpak-plugin.c
index 094e23552..d8e2b5113 100644
--- a/src/plugins/flatpak/flatpak-plugin.c
+++ b/src/plugins/flatpak/flatpak-plugin.c
@@ -34,6 +34,7 @@
#include "gbp-flatpak-config-provider.h"
#include "gbp-flatpak-dependency-updater.h"
#include "gbp-flatpak-pipeline-addin.h"
+#include "gbp-flatpak-run-command-provider.h"
#include "gbp-flatpak-runtime-provider.h"
_IDE_EXTERN void
@@ -47,6 +48,9 @@ _gbp_flatpak_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_BUILD_TARGET_PROVIDER,
GBP_TYPE_FLATPAK_BUILD_TARGET_PROVIDER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_RUN_COMMAND_PROVIDER,
+ GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_CONFIG_PROVIDER,
GBP_TYPE_FLATPAK_CONFIG_PROVIDER);
diff --git a/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
b/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
new file mode 100644
index 000000000..b66a9da01
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-run-command-provider.c
@@ -0,0 +1,147 @@
+/* gbp-flatpak-run-command-provider.c
+ *
+ * Copyright 2017-2022 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-run-command-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-threading.h>
+
+#include "gbp-flatpak-run-command-provider.h"
+#include "gbp-flatpak-manifest.h"
+
+struct _GbpFlatpakRunCommandProvider
+{
+ IdeObject parent_instance;
+};
+
+static char **
+join_args (const char *argv0,
+ const char * const *x_run_args)
+{
+ GPtrArray *ar = g_ptr_array_new ();
+
+ g_ptr_array_add (ar, g_strdup (argv0));
+ if (x_run_args)
+ {
+ for (guint i = 0; x_run_args[i]; i++)
+ g_ptr_array_add (ar, g_strdup (x_run_args[i]));
+ }
+ g_ptr_array_add (ar, NULL);
+
+ return (char **)(gpointer)g_ptr_array_free (ar, FALSE);
+}
+
+static void
+gbp_flatpak_run_command_provider_list_commands_async (IdeRunCommandProvider *provider,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpFlatpakRunCommandProvider *self = (GbpFlatpakRunCommandProvider *)provider;
+ g_autoptr(GListStore) store = NULL;
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(IdeRunCommand) command = NULL;
+ g_auto(GStrv) argv = NULL;
+ IdeConfigManager *config_manager;
+ const char * const *x_run_args;
+ const char *argv0;
+ IdeContext *context;
+ IdeConfig *config;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUN_COMMAND_PROVIDER (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_flatpak_run_command_provider_list_commands_async);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ config_manager = ide_config_manager_from_context (context);
+ config = ide_config_manager_get_current (config_manager);
+
+ if (!GBP_IS_FLATPAK_MANIFEST (config))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Project is not configured with flatpak, cannot list commands");
+ IDE_EXIT;
+ }
+
+ argv0 = gbp_flatpak_manifest_get_command (GBP_FLATPAK_MANIFEST (config));
+ x_run_args = gbp_flatpak_manifest_get_x_run_args (GBP_FLATPAK_MANIFEST (config));
+
+ store = g_list_store_new (IDE_TYPE_RUN_COMMAND);
+ argv = join_args (argv0, x_run_args);
+
+ command = ide_run_command_new ();
+ ide_run_command_set_id (command, "flatpak:");
+ ide_run_command_set_priority (command, -1000);
+ ide_run_command_set_display_name (command, _("Flatpak Application"));
+ ide_run_command_set_argv (command, (const char * const *)x_run_args);
+ g_list_store_append (store, command);
+
+ ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
+
+ IDE_EXIT;
+}
+
+static GListModel *
+gbp_flatpak_run_command_provider_list_commands_finish (IdeRunCommandProvider *provider,
+ GAsyncResult *result,
+ GError **error)
+{
+ GListModel *ret;
+
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_FLATPAK_RUN_COMMAND_PROVIDER (provider));
+ g_assert (IDE_IS_TASK (result));
+ g_assert (ide_task_is_valid (IDE_TASK (result), provider));
+
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
+
+static void
+run_command_provider_iface_init (IdeRunCommandProviderInterface *iface)
+{
+ iface->list_commands_async = gbp_flatpak_run_command_provider_list_commands_async;
+ iface->list_commands_finish = gbp_flatpak_run_command_provider_list_commands_finish;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpFlatpakRunCommandProvider, gbp_flatpak_run_command_provider,
IDE_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_RUN_COMMAND_PROVIDER,
run_command_provider_iface_init))
+
+static void
+gbp_flatpak_run_command_provider_class_init (GbpFlatpakRunCommandProviderClass *klass)
+{
+}
+
+static void
+gbp_flatpak_run_command_provider_init (GbpFlatpakRunCommandProvider *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-run-command-provider.h
b/src/plugins/flatpak/gbp-flatpak-run-command-provider.h
new file mode 100644
index 000000000..9ea12ccf9
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-run-command-provider.h
@@ -0,0 +1,31 @@
+/* gbp-flatpak-build-target-provider.h
+ *
+ * Copyright 2017-2022 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_RUN_COMMAND_PROVIDER (gbp_flatpak_run_command_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakRunCommandProvider, gbp_flatpak_run_command_provider, GBP,
FLATPAK_RUN_COMMAND_PROVIDER, IdeObject)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index c5be574b0..d86282625 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -26,6 +26,7 @@ plugins_sources += files([
'gbp-flatpak-install-dialog.c',
'gbp-flatpak-manifest.c',
'gbp-flatpak-pipeline-addin.c',
+ 'gbp-flatpak-run-command-provider.c',
'gbp-flatpak-runner.c',
'gbp-flatpak-runtime-provider.c',
'gbp-flatpak-runtime.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]