Skip to content

Commit

Permalink
FileChooser: Add a 'current_filter' return value
Browse files Browse the repository at this point in the history
Add a 'current_filter' element for the FileChooser
response which is used to specify which filter
was selected in the file chooser.

This will allow making Gtk's
'gtk_file_chooser_get_filter' work for the
portal native file chooser.

Bug: https://gitlab.gnome.org/GNOME/gtk/-/issues/1820
  • Loading branch information
michaelweghorn committed May 23, 2020
1 parent e7f7864 commit 35fca7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data/org.freedesktop.impl.portal.FileChooser.xml
Expand Up @@ -109,6 +109,15 @@
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para></listitem>
</varlistentry>
<varlistentry>
<term>current_filter (sa(us))</term>
<listitem>
<para>
The filter that was selected.
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>writable b</term>
<listitem><para>
Expand Down Expand Up @@ -216,6 +225,15 @@
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para></listitem>
</varlistentry>
<varlistentry>
<term>current_filter (sa(us))</term>
<listitem>
<para>
The filter that was selected.
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para>
</listitem>
</varlistentry>
</variablelist>
-->
<method name="SaveFile">
Expand Down
18 changes: 18 additions & 0 deletions data/org.freedesktop.portal.FileChooser.xml
Expand Up @@ -151,6 +151,15 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>current_filter (sa(us))</term>
<listitem>
<para>
The filter that was selected. This may match a filter in the
filter list or another filter that was applied unconditionally.
</para>
</listitem>
</varlistentry>
</variablelist>
-->
<method name="OpenFile">
Expand Down Expand Up @@ -248,6 +257,15 @@
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para></listitem>
</varlistentry>
<varlistentry>
<term>current_filter (sa(us))</term>
<listitem>
<para>
The filter that was selected.
See org.freedesktop.portal.FileChooser.OpenFile() for details.
</para>
</listitem>
</varlistentry>
</variablelist>
-->
<method name="SaveFile">
Expand Down
5 changes: 5 additions & 0 deletions src/file-chooser.c
Expand Up @@ -79,6 +79,7 @@ send_response_in_thread_func (GTask *task,
const char **uris;
GVariant *choices;
gboolean for_save;
GVariant *current_filter;

g_variant_builder_init (&results, G_VARIANT_TYPE_VARDICT);
g_variant_builder_init (&ruris, G_VARIANT_TYPE_STRING_ARRAY);
Expand All @@ -100,6 +101,10 @@ send_response_in_thread_func (GTask *task,
if (choices)
g_variant_builder_add (&results, "{sv}", "choices", choices);

current_filter = g_variant_lookup_value (options, "current_filter", G_VARIANT_TYPE ("(sa(us))"));
if (current_filter)
g_variant_builder_add (&results, "{sv}", "current_filter", current_filter);

if (g_variant_lookup (options, "uris", "^a&s", &uris))
{
int i;
Expand Down

0 comments on commit 35fca7f

Please sign in to comment.