diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-05-24 10:08:58 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-05-24 13:23:27 +0200 |
commit | 2c7772ef4668e2e56b5f4cbf385ac286d363537c (patch) | |
tree | 116c426d5c83995d7f4ec93f2709a2529a3ae714 /src | |
parent | 4cb04653aea84ac8a2642ea90bb48c4aa5ce4aec (diff) | |
download | totem-2c7772ef4668e2e56b5f4cbf385ac286d363537c.tar.gz |
open-directory: Use libportal to open containing folder
This should make the 'Open Containing Folder' functionality carry on
working when we've restricted filesystem access further.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/meson.build | 7 | ||||
-rw-r--r-- | src/plugins/open-directory/meson.build | 1 | ||||
-rw-r--r-- | src/plugins/open-directory/totem-open-directory.c | 85 |
3 files changed, 40 insertions, 53 deletions
diff --git a/src/plugins/meson.build b/src/plugins/meson.build index 01a2ed2ed..e78e70e28 100644 --- a/src/plugins/meson.build +++ b/src/plugins/meson.build @@ -41,7 +41,6 @@ if plugins_option != 'none' 'autoload-subtitles', 'im-status', 'mpris', - 'open-directory', 'properties', 'recent', 'rotation', @@ -62,6 +61,12 @@ if plugins_option != 'none' 'samplepython' ] endif + + if have_libportal + plugins += [ + 'open-directory' + ] + endif endif pylint_flags = ['-d', 'C0111', '-d', 'W0511', '-d', 'F0401', '-d', 'C0326' ] diff --git a/src/plugins/open-directory/meson.build b/src/plugins/open-directory/meson.build index 23cfd0ff6..604c8c1a7 100644 --- a/src/plugins/open-directory/meson.build +++ b/src/plugins/open-directory/meson.build @@ -8,6 +8,7 @@ shared_module( include_directories: plugins_incs, dependencies: plugins_deps + [ gio_dep, + libportal_dep, ], c_args: plugins_cflags, install: true, diff --git a/src/plugins/open-directory/totem-open-directory.c b/src/plugins/open-directory/totem-open-directory.c index 3106be9bc..fd316cdf7 100644 --- a/src/plugins/open-directory/totem-open-directory.c +++ b/src/plugins/open-directory/totem-open-directory.c @@ -23,6 +23,7 @@ #include <libpeas/peas-extension-base.h> #include <libpeas/peas-object-module.h> #include <libpeas/peas-activatable.h> +#include <libportal-gtk3/portal-gtk3.h> #include "totem-plugin.h" @@ -32,67 +33,45 @@ typedef struct { PeasExtensionBase parent; - TotemObject *totem; - char *mrl; + TotemObject *totem; + XdpPortal *portal; + GCancellable *cancellable; + char *mrl; GSimpleAction *action; } TotemOpenDirectoryPlugin; TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_OPEN_DIRECTORY_PLUGIN, TotemOpenDirectoryPlugin, totem_open_directory_plugin) -static char * -get_notification_id (void) +static void +open_directory_cb (GObject *object, + GAsyncResult *result, + gpointer data) { - return g_strdup_printf ("%s_TIME%ld", - "totem", - g_get_monotonic_time () / G_TIME_SPAN_SECOND); + XdpPortal *portal = XDP_PORTAL (object); + g_autoptr(GError) error = NULL; + gboolean res; + + res = xdp_portal_open_directory_finish (portal, result, &error); + if (!res) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to show directory: %s", error->message); + } } static void totem_open_directory_plugin_open (GSimpleAction *action, - GVariant *parameter, - TotemOpenDirectoryPlugin *pi) + GVariant *parameter, + TotemOpenDirectoryPlugin *pi) { - - - GError *error = NULL; - GDBusProxy *proxy; - gchar* notification_id; - GVariantBuilder *builder; - GVariant *dbus_arguments; + XdpParent *parent; g_assert (pi->mrl != NULL); - proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, /* GDBusInterfaceInfo */ - "org.freedesktop.FileManager1", - "/org/freedesktop/FileManager1", - "org.freedesktop.FileManager1", - NULL, /* GCancellable */ - &error); - if (proxy == NULL) { - g_warning ("Could not contact file manager: %s", error->message); - g_error_free (error); - return; - } - - notification_id = get_notification_id(); - - builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); - g_variant_builder_add (builder, "s", pi->mrl); - dbus_arguments = g_variant_new ("(ass)", builder, notification_id); - g_variant_builder_unref (builder); - g_free(notification_id); - - if (g_dbus_proxy_call_sync (proxy, - "ShowItems", dbus_arguments, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error) == FALSE) { - g_warning ("Could not get file manager to display file: %s", error->message); - g_error_free (error); - } - - g_object_unref (proxy); + parent = xdp_parent_new_gtk (totem_object_get_main_window (pi->totem)); + xdp_portal_open_directory (pi->portal, parent, pi->mrl, + XDP_OPEN_URI_FLAG_NONE, pi->cancellable, + open_directory_cb, NULL); + xdp_parent_free (parent); } static void @@ -157,12 +136,9 @@ impl_activate (PeasActivatable *plugin) GMenuItem *item; char *mrl; - /* FIXME: This plugin will stop working if the file is outside - * what the Flatpak has access to - if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS)) - return; */ - pi->totem = g_object_get_data (G_OBJECT (plugin), "object"); + pi->portal = xdp_portal_new (); + pi->cancellable = g_cancellable_new (); g_signal_connect (pi->totem, "file-opened", @@ -194,6 +170,11 @@ impl_deactivate (PeasActivatable *plugin) { TotemOpenDirectoryPlugin *pi = TOTEM_OPEN_DIRECTORY_PLUGIN (plugin); + if (pi->cancellable != NULL) { + g_cancellable_cancel (pi->cancellable); + g_clear_object (&pi->cancellable); + } + g_signal_handlers_disconnect_by_func (pi->totem, totem_open_directory_file_opened, plugin); g_signal_handlers_disconnect_by_func (pi->totem, totem_open_directory_file_closed, plugin); |