FileChooser portal adds directories read-only
Directories added through the FileChooser portal are not writable. In my case, the portal is called with a Gtk.FileChooserNative
with an action of Gtk.FileChooserAction.SELECT_FOLDER
.
The read-only choice is only added for the OPEN
action, and I guess it defaults to false otherwise. From what I understand, in the GTK portal, it defaults to writable.
Here's a small reproducer in Python:
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gio, GLib, Gtk
Gtk.init()
loop = GLib.MainLoop()
win = Gtk.Window()
win.connect("close-request", lambda _: loop.quit())
# When we have a response from the file chooser, print if the directory
# is writable
def on_file_chooser_response(dialog, response):
dialog.hide()
if response == Gtk.ResponseType.ACCEPT:
for f in dialog.get_files():
info = f.query_info("access::*", Gio.FileQueryInfoFlags.NONE, None)
print(
"Writable: ",
info.get_attribute_as_string("access::can-write"))
# Create the file chooser
file_chooser = Gtk.FileChooserNative(
action=Gtk.FileChooserAction.SELECT_FOLDER,
select_multiple=True,
modal=True,
transient_for=win
)
file_chooser.connect("response", on_file_chooser_response)
# Show the file chooser when the button is clicked
button = Gtk.Button(label="Open File Chooser")
button.connect("clicked", lambda _: file_chooser.show())
win.set_child(button)
win.present()
loop.run()
I run it with flatpak run --command=python --filesystem=$(pwd) --socket=wayland org.gnome.Platform//42 test.py