Skip to content

FileChooser: Implement 'options' - 'choices'

This implements the 'options' - 'choices' parameter for the FileChooser portal which can be used to specify additional options to offer in the file dialog.

From the FileChooser spec:

choices a(ssa(ss)s)

    List of serialized combo boxes to add to the file chooser.

    For each element, the first string is an ID that will be returned with the response, te second string is a user-visible label. The a(ss) is the list of choices, each being a is an ID and a user-visible label. The final string is the initial selection, or "", to let the portal decide which choice will be initially selected. None of the strings, except for the initial selection, should be empty.

    As a special case, passing an empty array for the list of choices indicates a boolean choice that is typically displayed as a check button, using "true" and "false" as the choices.

    Example: [('encoding', 'Encoding', [('utf8', 'Unicode (UTF-8)'), ('latin15', 'Western')], 'latin15'), ('reencode', 'Reencode', [], 'false')] 

Attached is a gtk sample program that can be used to test the functionality (I have tested it on Debian testing with libgtk-3-0:amd64 3.24.20-1 and +xdg-desktop-portal 1.6.0-1): main_options.cpp

  1. Compile sample program:
gcc -o main_options main_options.cpp
  1. Run sample program using portal in a KDE Plasma session (so that Plasma-native file chooser is actually used):
GTK_USE_PORTAL=1 ./main_options
  1. verify that the two options can be set in the file dialog:
  • one checkbox for the option "Sample boolean choice" that is selected by default
  • one combobox to choose one of the greek letters "Alpha", "Beta", "Gamma", with "Gamma" preselected
  1. adapt selection for the two options as desired

  2. select any file in the file system and press "OK"

  3. verify that the program outputs the IDs of the choices that were made in step 4, e.g. the following (if checkbox was unselected and "Beta" was selected in the combobox):

selected booleanChoice: false
selected letter: beta

NOTE: In order to avoid merge conflicts, this merge request also includes the commit from !2 (merged), since they touch the same code area. I'll be happy to drop that commit again from this merge request once !2 (merged) has been handled. (or let me know how to best handle this otherwise)

Edited by Michael Weghorn

Merge request reports