[gnome-builder] flatpak: use dialog to handle confirm request from peer
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] flatpak: use dialog to handle confirm request from peer
- Date: Wed, 5 May 2021 04:10:29 +0000 (UTC)
commit 881c3ce3e4f206cc0784f4ada9c01e0e232e8abd
Author: Christian Hergert <chergert redhat com>
Date: Tue May 4 11:28:17 2021 -0700
flatpak: use dialog to handle confirm request from peer
.../daemon/org.gnome.Builder.Flatpak.Transfer.xml | 3 +
src/plugins/flatpak/gbp-flatpak-install-dialog.c | 105 ++-------------------
src/plugins/flatpak/gbp-flatpak-install-dialog.h | 11 +--
src/plugins/flatpak/gbp-flatpak-runtime-provider.c | 90 ++++++++++++++++++
src/plugins/flatpak/gbp-flatpak-util.c | 24 ++++-
5 files changed, 121 insertions(+), 112 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
index 4f5762c87..fc12a5259 100644
--- a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
+++ b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
@@ -23,5 +23,8 @@
<interface name="org.gnome.Builder.Flatpak.Transfer">
<property name="Fraction" type="d" access="readwrite"/>
<property name="Message" type="s" access="readwrite"/>
+ <method name="Confirm">
+ <arg name="refs" type="as" direction="in"/>
+ </method>
</interface>
</node>
diff --git a/src/plugins/flatpak/gbp-flatpak-install-dialog.c
b/src/plugins/flatpak/gbp-flatpak-install-dialog.c
index 939e37b26..a52e7da1b 100644
--- a/src/plugins/flatpak/gbp-flatpak-install-dialog.c
+++ b/src/plugins/flatpak/gbp-flatpak-install-dialog.c
@@ -33,12 +33,10 @@
struct _GbpFlatpakInstallDialog
{
- GtkDialog parent_instance;
- GtkListStore *liststore1;
- IdeTask *close_task;
- gchar **saved_runtimes;
- gchar *sdk;
- gint response_id;
+ GtkDialog parent_instance;
+ GtkListStore *liststore1;
+ IdeTask *close_task;
+ gint response_id;
};
G_DEFINE_TYPE (GbpFlatpakInstallDialog, gbp_flatpak_install_dialog, GTK_TYPE_DIALOG)
@@ -55,46 +53,6 @@ gbp_flatpak_install_dialog_new (GtkWindow *transient_for)
NULL);
}
-static gchar **
-get_runtimes (GbpFlatpakInstallDialog *self)
-{
- GPtrArray *ar = NULL;
- GtkTreeIter iter;
-
- g_assert (GBP_IS_FLATPAK_INSTALL_DIALOG (self));
-
- ar = g_ptr_array_new ();
-
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->liststore1), &iter))
- {
- do
- {
- g_autofree gchar *name = NULL;
- g_autofree gchar *arch = NULL;
- g_autofree gchar *branch = NULL;
-
- gtk_tree_model_get (GTK_TREE_MODEL (self->liststore1), &iter,
- 0, &name,
- 1, &arch,
- 2, &branch,
- -1);
-
- if (arch == NULL)
- arch = g_strdup (flatpak_get_default_arch ());
-
- if (branch == NULL)
- branch = g_strdup ("");
-
- g_ptr_array_add (ar, g_strdup_printf ("%s/%s/%s", name, arch, branch));
- }
- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->liststore1), &iter));
- }
-
- g_ptr_array_add (ar, NULL);
-
- return (gchar **)g_ptr_array_free (ar, FALSE);
-}
-
static void
gbp_flatpak_install_dialog_response (GtkDialog *dialog,
gint response_id)
@@ -105,9 +63,6 @@ gbp_flatpak_install_dialog_response (GtkDialog *dialog,
self->response_id = response_id;
- g_clear_pointer (&self->saved_runtimes, g_strfreev);
- self->saved_runtimes = get_runtimes (self);
-
if (self->close_task && response_id == GTK_RESPONSE_OK)
ide_task_return_boolean (self->close_task, TRUE);
@@ -123,8 +78,6 @@ gbp_flatpak_install_dialog_finalize (GObject *object)
GbpFlatpakInstallDialog *self = (GbpFlatpakInstallDialog *)object;
g_clear_object (&self->close_task);
- g_clear_pointer (&self->saved_runtimes, g_strfreev);
- g_clear_pointer (&self->sdk, g_free);
G_OBJECT_CLASS (gbp_flatpak_install_dialog_parent_class)->finalize (object);
}
@@ -298,52 +251,10 @@ gbp_flatpak_install_dialog_add_runtime (GbpFlatpakInstallDialog *self,
}
}
-gchar **
-gbp_flatpak_install_dialog_get_runtimes (GbpFlatpakInstallDialog *self)
-{
- g_assert (GBP_IS_FLATPAK_INSTALL_DIALOG (self));
-
- if (self->saved_runtimes != NULL)
- return g_strdupv (self->saved_runtimes);
-
- return get_runtimes (self);
-}
-
-void
-gbp_flatpak_install_dialog_add_runtime_full (GbpFlatpakInstallDialog *self,
- const gchar *name,
- const gchar *arch,
- const gchar *branch)
-{
- g_autofree gchar *runtime_id = NULL;
-
- g_return_if_fail (GBP_IS_FLATPAK_INSTALL_DIALOG (self));
- g_return_if_fail (name != NULL);
-
- if (arch == NULL)
- arch = flatpak_get_default_arch ();
-
- runtime_id = g_strdup_printf ("%s/%s/%s", name, arch, branch ?: "");
- gbp_flatpak_install_dialog_add_runtime (self, runtime_id);
-}
-
-void
-gbp_flatpak_install_dialog_set_sdk (GbpFlatpakInstallDialog *self,
- const gchar *sdk)
-{
- g_return_if_fail (GBP_IS_FLATPAK_INSTALL_DIALOG (self));
-
- if (g_strcmp0 (sdk, self->sdk) != 0)
- {
- g_free (self->sdk);
- self->sdk = g_strdup (sdk);
- }
-}
-
-const gchar *
-gbp_flatpak_install_dialog_get_sdk (GbpFlatpakInstallDialog *self)
+gboolean
+gbp_flatpak_install_dialog_is_empty (GbpFlatpakInstallDialog *self)
{
- g_return_val_if_fail (GBP_IS_FLATPAK_INSTALL_DIALOG (self), NULL);
+ g_return_val_if_fail (GBP_IS_FLATPAK_INSTALL_DIALOG (self), FALSE);
- return self->sdk;
+ return gtk_tree_model_iter_n_children (GTK_TREE_MODEL (self->liststore1), NULL) == 0;
}
diff --git a/src/plugins/flatpak/gbp-flatpak-install-dialog.h
b/src/plugins/flatpak/gbp-flatpak-install-dialog.h
index 823e3f4ab..213569f8e 100644
--- a/src/plugins/flatpak/gbp-flatpak-install-dialog.h
+++ b/src/plugins/flatpak/gbp-flatpak-install-dialog.h
@@ -29,18 +29,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GbpFlatpakInstallDialog, gbp_flatpak_install_dialog, GBP, FLATPAK_INSTALL_DIALOG,
GtkDialog)
GbpFlatpakInstallDialog *gbp_flatpak_install_dialog_new (GtkWindow
*transient_for);
-const gchar *gbp_flatpak_install_dialog_get_sdk (GbpFlatpakInstallDialog *self);
-void gbp_flatpak_install_dialog_set_sdk (GbpFlatpakInstallDialog *self,
- const gchar *sdk);
+gboolean gbp_flatpak_install_dialog_is_empty (GbpFlatpakInstallDialog *self);
void gbp_flatpak_install_dialog_add_runtime (GbpFlatpakInstallDialog *self,
const gchar *runtime_id);
-void gbp_flatpak_install_dialog_add_runtime_full (GbpFlatpakInstallDialog *self,
- const gchar *name,
- const gchar *arch,
- const gchar *branch);
-gchar **gbp_flatpak_install_dialog_get_runtimes (GbpFlatpakInstallDialog *self);
-gboolean gbp_flatpak_install_dialog_has_runtime (GbpFlatpakInstallDialog *self,
- const gchar *runtime_id);
void gbp_flatpak_install_dialog_run_async (GbpFlatpakInstallDialog *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index df6f4c202..f1b24a6ab 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -24,8 +24,10 @@
#include <glib/gi18n.h>
#include <libide-foundry.h>
+#include <libide-gui.h>
#include "gbp-flatpak-client.h"
+#include "gbp-flatpak-install-dialog.h"
#include "gbp-flatpak-manifest.h"
#include "gbp-flatpak-runtime.h"
#include "gbp-flatpak-runtime-provider.h"
@@ -197,6 +199,13 @@ gbp_flatpak_runtime_provider_unload (IdeRuntimeProvider *provider,
g_ptr_array_remove_range (self->runtimes, 0, self->runtimes->len);
}
+typedef struct
+{
+ GbpFlatpakRuntimeProvider *self;
+ GDBusMethodInvocation *invocation;
+ IpcFlatpakTransfer *transfer;
+} Confirm;
+
typedef struct
{
char *runtime_id;
@@ -219,6 +228,82 @@ bootstrap_free (Bootstrap *b)
g_slice_free (Bootstrap, b);
}
+static void
+gbp_flatpak_runtime_provider_handle_confirm_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GbpFlatpakInstallDialog *dialog = (GbpFlatpakInstallDialog *)object;
+ Confirm *state = user_data;
+ g_autoptr(GError) error = NULL;
+
+ g_assert (GBP_IS_FLATPAK_INSTALL_DIALOG (dialog));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (state != NULL);
+ g_assert (G_IS_DBUS_METHOD_INVOCATION (state->invocation));
+ g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (state->self));
+ g_assert (IPC_IS_FLATPAK_TRANSFER (state->transfer));
+
+ if (!gbp_flatpak_install_dialog_run_finish (dialog, result, &error))
+ g_dbus_method_invocation_return_error (g_steal_pointer (&state->invocation),
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_FAILED,
+ "Unconfirmed request");
+ else
+ ipc_flatpak_transfer_complete_confirm (state->transfer,
+ g_steal_pointer (&state->invocation));
+
+ g_clear_object (&state->invocation);
+ g_clear_object (&state->transfer);
+ g_clear_object (&state->self);
+ g_slice_free (Confirm, state);
+}
+
+static gboolean
+gbp_flatpak_runtime_provider_handle_confirm (GbpFlatpakRuntimeProvider *self,
+ GDBusMethodInvocation *invocation,
+ const char * const *refs,
+ IpcFlatpakTransfer *transfer)
+{
+ g_autoptr(IdeContext) context = NULL;
+ GbpFlatpakInstallDialog *dialog;
+ IdeWorkbench *workbench;
+ IdeWorkspace *workspace;
+ Confirm *state;
+
+ g_assert (GBP_IS_FLATPAK_RUNTIME_PROVIDER (self));
+ g_assert (G_IS_DBUS_METHOD_INVOCATION (invocation));
+ g_assert (refs != NULL);
+ g_assert (IPC_IS_FLATPAK_TRANSFER (transfer));
+
+ context = ide_object_ref_context (IDE_OBJECT (self));
+ workbench = ide_workbench_from_context (context);
+ workspace = ide_workbench_get_current_workspace (workbench);
+ dialog = gbp_flatpak_install_dialog_new (GTK_WINDOW (workspace));
+
+ for (guint i = 0; refs[i]; i++)
+ gbp_flatpak_install_dialog_add_runtime (dialog, refs[i]);
+
+ if (gbp_flatpak_install_dialog_is_empty (dialog))
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ ipc_flatpak_transfer_complete_confirm (transfer, g_steal_pointer (&invocation));
+ return TRUE;
+ }
+
+ state = g_slice_new0 (Confirm);
+ state->self = g_object_ref (self);
+ state->transfer = g_object_ref (transfer);
+ state->invocation = g_object_ref (invocation);
+
+ gbp_flatpak_install_dialog_run_async (dialog,
+ NULL,
+ gbp_flatpak_runtime_provider_handle_confirm_cb,
+ state);
+
+ return TRUE;
+}
+
static IdeRuntime *
find_runtime (GbpFlatpakRuntimeProvider *self,
const char *runtime_id)
@@ -370,6 +455,11 @@ gbp_flatpak_runtime_provider_bootstrap (IdeTask *task,
ide_notification_set_progress_is_imprecise (notif, FALSE);
transfer = ipc_flatpak_transfer_skeleton_new ();
+ g_signal_connect_object (transfer,
+ "handle-confirm",
+ G_CALLBACK (gbp_flatpak_runtime_provider_handle_confirm),
+ source_object,
+ G_CONNECT_SWAPPED);
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (transfer),
g_dbus_proxy_get_connection (G_DBUS_PROXY (service)),
transfer_path,
diff --git a/src/plugins/flatpak/gbp-flatpak-util.c b/src/plugins/flatpak/gbp-flatpak-util.c
index 8479ecc94..7def8ed4e 100644
--- a/src/plugins/flatpak/gbp-flatpak-util.c
+++ b/src/plugins/flatpak/gbp-flatpak-util.c
@@ -80,11 +80,11 @@ gbp_flatpak_is_ignored (const gchar *name)
strstr (name, ".PlatformTheme") != NULL;
}
-gboolean
-gbp_flatpak_split_id (const gchar *str,
- gchar **id,
- gchar **arch,
- gchar **branch)
+static gboolean
+_gbp_flatpak_split_id (const gchar *str,
+ gchar **id,
+ gchar **arch,
+ gchar **branch)
{
g_auto(GStrv) parts = g_strsplit (str, "/", 0);
guint i = 0;
@@ -130,6 +130,20 @@ gbp_flatpak_split_id (const gchar *str,
return TRUE;
}
+gboolean
+gbp_flatpak_split_id (const gchar *str,
+ gchar **id,
+ gchar **arch,
+ gchar **branch)
+{
+ if (g_str_has_prefix (str, "runtime/"))
+ str += strlen ("runtime/");
+ else if (g_str_has_prefix (str, "app/"))
+ str += strlen ("app/");
+
+ return _gbp_flatpak_split_id (str, id, arch, branch);
+}
+
static const char *
_gbp_flatpak_get_default_arch (IdeObject *object)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]