From 8ff3217712c88e590602fc3497b52eec8d5163d0 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 29 Nov 2022 14:11:26 -0500 Subject: [PATCH] gtk: Stop using gtk_show_uri Replace all uses of gtk_show_uri with GtkFileLauncher. --- gtk/gtkaboutdialog.c | 18 +++++++--- gtk/gtkfilechooserwidget.c | 64 +++------------------------------- gtk/gtkfilelauncher.c | 2 +- gtk/gtklabel.c | 12 +++++-- gtk/gtklinkbutton.c | 15 +++++--- gtk/gtkprintoperation-portal.c | 15 ++++---- gtk/gtkprintoperation-unix.c | 15 ++++---- 7 files changed, 58 insertions(+), 83 deletions(-) diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c index 739f8607f9..5227a14f67 100644 --- a/gtk/gtkaboutdialog.c +++ b/gtk/gtkaboutdialog.c @@ -44,7 +44,7 @@ #include "gtkorientable.h" #include "gtkscrolledwindow.h" #include "gtktextview.h" -#include "gtkshow.h" +#include "gtkfilelauncher.h" #include "gtkmain.h" #include "gtktogglebutton.h" #include "gtktypebuiltins.h" @@ -78,7 +78,7 @@ * ![An example GtkAboutDialog](aboutdialog.png) * * About dialogs often contain links and email addresses. `GtkAboutDialog` - * displays these as clickable links. By default, it calls [func@Gtk.show_uri] + * displays these as clickable links. By default, it calls [method@Gtk.FileLauncher.launch] * when a user clicks one. The behaviour can be overridden with the * [signal@Gtk.AboutDialog::activate-link] signal. * @@ -361,7 +361,7 @@ gtk_about_dialog_class_init (GtkAboutDialogClass *klass) * Emitted every time a URL is activated. * * Applications may connect to it to override the default behaviour, - * which is to call [func@Gtk.show_uri]. + * which is to call [method@Gtk.FileLauncher.launch]. * * Returns: `TRUE` if the link has been activated */ @@ -932,7 +932,17 @@ static gboolean gtk_about_dialog_activate_link (GtkAboutDialog *about, const char *uri) { - gtk_show_uri (GTK_WINDOW (about), uri, GDK_CURRENT_TIME); + GtkFileLauncher *launcher; + GFile *file; + + launcher = gtk_file_launcher_new (); + file = g_file_new_for_uri (uri); + + gtk_file_launcher_launch (launcher, GTK_WINDOW (about), file, NULL, NULL, NULL); + + g_object_unref (launcher); + g_object_unref (file); + return TRUE; } diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 29b3f4ba37..5e3c7a91f8 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -64,7 +64,7 @@ #include "gtkcheckbutton.h" #include "gtkwindowgroup.h" #include -#include "gtkshow.h" +#include "gtkfilelauncher.h" #include "gtkmain.h" #include "gtkscrollable.h" #include "gtkpopover.h" @@ -1370,68 +1370,14 @@ open_folder_cb (GSimpleAction *action, GtkWindow *toplevel = GTK_IS_WINDOW (root) ? GTK_WINDOW (root) : NULL; GFileInfo *info; GFile *file; - char *uri; + GtkFileLauncher *launcher; info = g_list_model_get_item (G_LIST_MODEL (impl->selection_model), impl->browse_files_popover_item); file = _gtk_file_info_get_file (info); -#ifdef G_OS_WIN32 - - uri = g_file_get_uri (file); - gtk_show_uri (toplevel, uri, GDK_CURRENT_TIME); - g_free (uri); - -#else - - if (gdk_should_use_portal ()) - { - g_openuri_portal_open_async (file, TRUE, toplevel, NULL, NULL, NULL); - } - else - { - GDBusConnection *bus; - GVariantBuilder uris_builder; - GVariant *result; - GError *error = NULL; - - uri = g_file_get_uri (file); - - bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); - - g_variant_builder_init (&uris_builder, G_VARIANT_TYPE ("as")); - g_variant_builder_add (&uris_builder, "s", uri); - - result = g_dbus_connection_call_sync (bus, - FILE_MANAGER_DBUS_NAME, - FILE_MANAGER_DBUS_PATH, - FILE_MANAGER_DBUS_IFACE, - "ShowFolders", - g_variant_new ("(ass)", &uris_builder, ""), - NULL, /* ignore returned type */ - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error); - if (error) - { - if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER) || - g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) - g_debug ("No " FILE_MANAGER_DBUS_NAME " available"); - else - g_warning ("Failed to call ShowFolders: %s", error->message); - - g_error_free (error); - } - - if (result) - g_variant_unref (result); - else - gtk_show_uri (toplevel, uri, GDK_CURRENT_TIME); - - g_free (uri); - } - -#endif + launcher = gtk_file_launcher_new (); + gtk_file_launcher_open_containing_folder (launcher, toplevel, file, NULL, NULL, NULL); + g_object_unref (launcher); g_clear_object (&info); } diff --git a/gtk/gtkfilelauncher.c b/gtk/gtkfilelauncher.c index d37fcc90a9..5d4acc1192 100644 --- a/gtk/gtkfilelauncher.c +++ b/gtk/gtkfilelauncher.c @@ -255,7 +255,7 @@ gtk_file_launcher_launch (GtkFileLauncher *self, char *uri = g_file_get_uri (file); G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_show_uri_full (parent, uri, self->timestamp, cancellable, show_uri_done, task); + gtk_show_uri_full (parent, uri, GDK_CURRENT_TIME, cancellable, show_uri_done, task); G_GNUC_END_IGNORE_DEPRECATIONS g_free (uri); diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 6119728040..98e7d3da70 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -40,7 +40,7 @@ #include "gtkshortcut.h" #include "gtkshortcutcontroller.h" #include "gtkshortcuttrigger.h" -#include "gtkshow.h" +#include "gtkfilelauncher.h" #include "gtksnapshot.h" #include "gtkrenderbackgroundprivate.h" #include "gtkrenderborderprivate.h" @@ -2102,11 +2102,17 @@ gtk_label_activate_link (GtkLabel *self, { GtkWidget *widget = GTK_WIDGET (self); GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (widget)); + GFile *file; + GtkFileLauncher *launcher; if (!GTK_IS_WINDOW (toplevel)) return FALSE; - gtk_show_uri (GTK_WINDOW (toplevel), uri, GDK_CURRENT_TIME); + file = g_file_new_for_uri (uri); + launcher = gtk_file_launcher_new (); + gtk_file_launcher_launch (launcher, GTK_WINDOW (toplevel), file, NULL, NULL, NULL); + g_object_unref (launcher); + g_object_unref (file); return TRUE; } @@ -2281,7 +2287,7 @@ gtk_label_class_init (GtkLabelClass *class) * Gets emitted to activate a URI. * * Applications may connect to it to override the default behaviour, - * which is to call gtk_show_uri(). + * which is to call [method@Gtk.FileLauncher.launch]. * * Returns: %TRUE if the link has been activated */ diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index f2794e1258..f991e192b6 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -37,7 +37,7 @@ * The URI bound to a `GtkLinkButton` can be set specifically using * [method@Gtk.LinkButton.set_uri]. * - * By default, `GtkLinkButton` calls [func@Gtk.show_uri] when the button + * By default, `GtkLinkButton` calls [method@Gtk.FileLauncher.launch] when the button * is clicked. This behaviour can be overridden by connecting to the * [signal@Gtk.LinkButton::activate-link] signal and returning %TRUE from * the signal handler. @@ -65,7 +65,7 @@ #include "gtkmarshalers.h" #include "gtkpopovermenu.h" #include "gtkprivate.h" -#include "gtkshow.h" +#include "gtkfilelauncher.h" #include "gtksizerequest.h" #include "gtktooltip.h" #include "gtkwidgetprivate.h" @@ -198,7 +198,7 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass) * * Emitted each time the `GtkLinkButton` is clicked. * - * The default handler will call [func@Gtk.show_uri] with the URI + * The default handler will call [method@Gtk.FileLauncher.launch] with the URI * stored inside the [property@Gtk.LinkButton:uri] property. * * To override the default behavior, you can connect to the @@ -479,10 +479,17 @@ static gboolean gtk_link_button_activate_link (GtkLinkButton *link_button) { GtkWidget *toplevel; + GFile *file; + GtkFileLauncher *launcher; toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (link_button))); - gtk_show_uri (GTK_WINDOW (toplevel), link_button->uri, GDK_CURRENT_TIME); + file = g_file_new_for_uri (link_button->uri); + launcher = gtk_file_launcher_new (); + gtk_file_launcher_launch (launcher, GTK_WINDOW (toplevel), file, NULL, NULL, NULL); + g_object_unref (launcher); + g_object_unref (file); + gtk_link_button_set_visited (link_button, TRUE); return TRUE; diff --git a/gtk/gtkprintoperation-portal.c b/gtk/gtkprintoperation-portal.c index d2defb56b6..b003143982 100644 --- a/gtk/gtkprintoperation-portal.c +++ b/gtk/gtkprintoperation-portal.c @@ -34,7 +34,7 @@ #include "gtkprintsettings.h" #include "gtkpagesetup.h" #include "gtkprintbackendprivate.h" -#include "gtkshow.h" +#include "gtkfilelauncher.h" #include #include "gtkwindowprivate.h" #include "gtkprivate.h" @@ -677,9 +677,12 @@ gtk_print_operation_portal_launch_preview (GtkPrintOperation *op, GtkWindow *parent, const char *filename) { - char *uri; - - uri = g_filename_to_uri (filename, NULL, NULL); - gtk_show_uri (parent, uri, GDK_CURRENT_TIME); - g_free (uri); + GFile *file; + GtkFileLauncher *launcher; + + file = g_file_new_for_path (filename); + launcher = gtk_file_launcher_new (); + gtk_file_launcher_launch (launcher, parent, file, NULL, NULL, NULL); + g_object_unref (launcher); + g_object_unref (file); } diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index 4fbcd77c1c..2cc6eb5c1f 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -41,6 +41,7 @@ #include "gtkprinter.h" #include "gtkprintjob.h" #include "gtklabel.h" +#include "gtkfilelauncher.h" #include @@ -304,15 +305,17 @@ gtk_print_operation_unix_launch_preview (GtkPrintOperation *op, if (error != NULL) { - char * uri; + GFile *file; + GtkFileLauncher *launcher; g_warning ("Error launching preview: %s", error->message); + g_clear_error (&error); - g_error_free (error); - error = NULL; - uri = g_filename_to_uri (filename, NULL, NULL); - gtk_show_uri (parent, uri, GDK_CURRENT_TIME); - g_free (uri); + file = g_file_new_for_path (filename); + launcher = gtk_file_launcher_new (); + gtk_file_launcher_launch (launcher, parent, file, NULL, NULL, NULL); + g_object_unref (launcher); + g_object_unref (file); } out: -- 2.30.2