From: Matthias Clasen Date: Thu, 16 Mar 2023 20:06:49 +0000 (-0400) Subject: label: Use GtkFileLauncher for file URI X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~4^2~10^2~79 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=28e56d0dde37679db6372408fa6e71e3f8c7f190;p=gtk4.git label: Use GtkFileLauncher for file URI The GtkUriLauncher calls into the openuri portal, which distinguishes between files, directories, and URI. The GtkFileLauncher contains logic to deal with this, because it can already handle the file and folder differences. If we have a file:// URI it's easier to create a GFile out of it, and use the GtkFileLauncher API, while leaving the GtkUriLauncher API for every other URI scheme. Same fix as de3c1d0c73987225869908, for GtkLabel. Fixes: #5671 --- diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 19a8b8f027..49908566dc 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -29,10 +29,10 @@ #include "gtkbuildable.h" #include "gtkeventcontrollermotion.h" #include "gtkeventcontrollerfocus.h" +#include "gtkfilelauncher.h" #include "gtkgesturedrag.h" #include "gtkgestureclick.h" #include "gtkgesturesingle.h" -#include #include "gtkmarshalers.h" #include "gtknotebook.h" #include "gtkpangoprivate.h" @@ -59,6 +59,7 @@ #include #include #include +#include /** * GtkLabel: @@ -2102,14 +2103,31 @@ gtk_label_activate_link (GtkLabel *self, { GtkWidget *widget = GTK_WIDGET (self); GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); - GtkUriLauncher *launcher; + const char *uri_scheme; if (!GTK_IS_WINDOW (toplevel)) return FALSE; - launcher = gtk_uri_launcher_new (uri); - gtk_uri_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, NULL, NULL); - g_object_unref (launcher); + uri_scheme = g_uri_peek_scheme (uri); + if (g_strcmp0 (uri_scheme, "file") == 0) + { + GFile *file; + GtkFileLauncher *launcher; + + file = g_file_new_for_uri (uri); + launcher = gtk_file_launcher_new (file); + gtk_file_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, NULL, NULL); + g_object_unref (launcher); + g_object_unref (file); + } + else + { + GtkUriLauncher *launcher; + + launcher = gtk_uri_launcher_new (uri); + gtk_uri_launcher_launch (launcher, GTK_WINDOW (toplevel), NULL, NULL, NULL); + g_object_unref (launcher); + } return TRUE; }