Hook up gtk_show_uri_full () to gtk_show_uri_win32 ()

On Windows, always use gtk_show_uri_win32 () instead of going through
GAppInfo.  Hook up gtk_file_launcher_launch () to gtk_show_uri_win32 ()
as well, always extracting the file path (and not a URI) and propagating
the always-ask flag.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
This commit is contained in:
Sergey Bugaev
2024-08-05 17:50:32 +03:00
parent 8d41ecff3e
commit b33b679b13
2 changed files with 48 additions and 1 deletions

View File

@@ -27,8 +27,13 @@
#include "gtkalertdialog.h"
#include <glib/gi18n-lib.h>
#ifdef G_OS_WIN32
#include "gtkshowwin32.h"
#endif
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
#ifndef G_OS_WIN32
typedef struct {
GtkWindow *parent;
char *handle;
@@ -86,6 +91,24 @@ window_handle_exported (GtkWindow *window,
data);
}
#else /* G_OS_WIN32 */
static void
show_win32_done (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GTask *task = user_data;
GError *error = NULL;
if (gtk_show_uri_win32_finish (GTK_WINDOW (source), result, &error))
g_task_return_boolean (task, TRUE);
else
g_task_return_error (task, error);
g_object_unref (task);
}
#endif
/**
* gtk_show_uri_full:
* @parent: (nullable): parent window
@@ -114,6 +137,7 @@ gtk_show_uri_full (GtkWindow *parent,
GAsyncReadyCallback callback,
gpointer user_data)
{
#ifndef G_OS_WIN32
GtkShowUriData *data;
GdkAppLaunchContext *context;
GdkDisplay *display;
@@ -138,6 +162,17 @@ gtk_show_uri_full (GtkWindow *parent,
if (!parent || !gtk_window_export_handle (parent, window_handle_exported, data))
window_handle_exported (parent, NULL, data);
#else /* G_OS_WIN32 */
GTask *task;
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
g_return_if_fail (uri != NULL);
task = g_task_new (parent, cancellable, callback, user_data);
g_task_set_source_tag (task, gtk_show_uri_full);
gtk_show_uri_win32 (parent, uri, FALSE, cancellable, show_win32_done, task);
#endif
}
/**

View File

@@ -26,6 +26,10 @@
#include "deprecated/gtkshow.h"
#include <glib/gi18n-lib.h>
#ifdef G_OS_WIN32
#include "gtkshowwin32.h"
#endif
/**
* GtkFileLauncher:
*
@@ -432,7 +436,11 @@ show_uri_done (GObject *source,
GTask *task = G_TASK (data);
GError *error = NULL;
#ifndef G_OS_WIN32
if (!gtk_show_uri_full_finish (parent, result, &error))
#else
if (!gtk_show_uri_win32_finish (parent, result, &error))
#endif
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_task_return_new_error (task, GTK_DIALOG_ERROR, GTK_DIALOG_ERROR_CANCELLED, "Cancelled by user");
@@ -503,7 +511,6 @@ gtk_file_launcher_launch (GtkFileLauncher *self,
gtk_openuri_portal_open_async (self->file, FALSE, flags, parent, cancellable, open_done, task);
}
else
#endif
{
char *uri = g_file_get_uri (self->file);
@@ -513,6 +520,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS
g_free (uri);
}
#else /* G_OS_WIN32 */
char *path = g_file_get_path (self->file);
gtk_show_uri_win32 (parent, path, self->always_ask, cancellable, show_uri_done, task);
g_free (path);
#endif
}
/**