gopenuriportal: Rename functions and switch to GFile as argument

We want to add the support for the activation token, to get it we use
`g_app_launch_context_get_startup_notify_id` which takes a list of
files, so that we don't have to create a GFile twice simply change the
signature of the functions. Fortunately this isn't a public API.
This commit is contained in:
Julian Sparber 2024-02-16 10:43:25 +01:00
parent 474dbd91f7
commit 6ee0389f68
3 changed files with 44 additions and 35 deletions

View File

@ -1203,6 +1203,7 @@ g_app_info_launch_default_for_uri (const char *uri,
#ifdef G_OS_UNIX
if (!res && glib_should_use_portal ())
{
GFile *file = NULL;
const char *parent_window = NULL;
/* Reset any error previously set by launch_default_for_uri */
@ -1211,7 +1212,9 @@ g_app_info_launch_default_for_uri (const char *uri,
if (launch_context && launch_context->priv->envp)
parent_window = g_environ_getenv (launch_context->priv->envp, "PARENT_WINDOW_ID");
return g_openuri_portal_open_uri (uri, parent_window, error);
file = g_file_new_for_uri (uri);
res = g_openuri_portal_open_file (file, parent_window, error);
g_object_unref (file);
}
#endif
@ -1241,7 +1244,7 @@ launch_default_for_uri_portal_open_uri_cb (GObject *object,
GTask *task = G_TASK (user_data);
GError *error = NULL;
if (g_openuri_portal_open_uri_finish (result, &error))
if (g_openuri_portal_open_file_finish (result, &error))
g_task_return_boolean (task, TRUE);
else
g_task_return_error (task, g_steal_pointer (&error));
@ -1258,6 +1261,7 @@ launch_default_for_uri_portal_open_uri (GTask *task, GError *error)
if (glib_should_use_portal ())
{
GFile *file;
const char *parent_window = NULL;
/* Reset any error previously set by launch_default_for_uri */
@ -1267,11 +1271,14 @@ launch_default_for_uri_portal_open_uri (GTask *task, GError *error)
parent_window = g_environ_getenv (data->context->priv->envp,
"PARENT_WINDOW_ID");
g_openuri_portal_open_uri_async (data->uri,
parent_window,
cancellable,
launch_default_for_uri_portal_open_uri_cb,
g_steal_pointer (&task));
file = g_file_new_for_uri (data->uri);
g_openuri_portal_open_file_async (file,
parent_window,
cancellable,
launch_default_for_uri_portal_open_uri_cb,
g_steal_pointer (&task));
g_object_unref (file);
return;
}
#endif

View File

@ -80,11 +80,10 @@ init_openuri_portal (void)
}
gboolean
g_openuri_portal_open_uri (const char *uri,
const char *parent_window,
GError **error)
g_openuri_portal_open_file (GFile *file,
const char *parent_window,
GError **error)
{
GFile *file = NULL;
GVariantBuilder opt_builder;
gboolean res;
@ -97,7 +96,6 @@ g_openuri_portal_open_uri (const char *uri,
g_variant_builder_init (&opt_builder, G_VARIANT_TYPE_VARDICT);
file = g_file_new_for_uri (uri);
if (g_file_is_native (file))
{
char *path = NULL;
@ -138,6 +136,10 @@ g_openuri_portal_open_uri (const char *uri,
}
else
{
char *uri = NULL;
uri = g_file_get_uri (file);
res = gxdp_open_uri_call_open_uri_sync (openuri,
parent_window ? parent_window : "",
uri,
@ -145,10 +147,9 @@ g_openuri_portal_open_uri (const char *uri,
NULL,
NULL,
error);
g_free (uri);
}
g_object_unref (file);
return res;
}
@ -245,15 +246,14 @@ open_call_done (GObject *source,
}
void
g_openuri_portal_open_uri_async (const char *uri,
const char *parent_window,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
g_openuri_portal_open_file_async (GFile *file,
const char *parent_window,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GDBusConnection *connection;
GTask *task;
GFile *file;
GVariant *opts = NULL;
int i;
guint signal_id;
@ -308,7 +308,6 @@ g_openuri_portal_open_uri_async (const char *uri,
else
task = NULL;
file = g_file_new_for_uri (uri);
if (g_file_is_native (file))
{
char *path = NULL;
@ -349,6 +348,10 @@ g_openuri_portal_open_uri_async (const char *uri,
}
else
{
char *uri = NULL;
uri = g_file_get_uri (file);
gxdp_open_uri_call_open_uri (openuri,
parent_window ? parent_window : "",
uri,
@ -356,14 +359,13 @@ g_openuri_portal_open_uri_async (const char *uri,
cancellable,
task ? open_call_done : NULL,
task);
g_free (uri);
}
g_object_unref (file);
}
gboolean
g_openuri_portal_open_uri_finish (GAsyncResult *result,
GError **error)
g_openuri_portal_open_file_finish (GAsyncResult *result,
GError **error)
{
return g_task_propagate_boolean (G_TASK (result), error);
}

View File

@ -25,18 +25,18 @@
G_BEGIN_DECLS
gboolean g_openuri_portal_open_uri (const char *uri,
const char *parent_window,
GError **error);
gboolean g_openuri_portal_open_file (GFile *file,
const char *parent_window,
GError **error);
void g_openuri_portal_open_uri_async (const char *uri,
const char *parent_window,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void g_openuri_portal_open_file_async (GFile *file,
const char *parent_window,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean g_openuri_portal_open_uri_finish (GAsyncResult *result,
GError **error);
gboolean g_openuri_portal_open_file_finish (GAsyncResult *result,
GError **error);
G_END_DECLS