Bug 422340 - Portal FileChooser incorrectly handles mnemonics
Summary: Portal FileChooser incorrectly handles mnemonics
Status: RESOLVED FIXED
Alias: None
Product: xdg-desktop-portal-kde
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Jan Grulich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-01 19:16 UTC by Michael Weghorn
Modified: 2020-07-27 13:47 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Screenshot of the portal-native KF5 file save dialog used with simple-scan (136.12 KB, image/png)
2020-06-01 19:16 UTC, Michael Weghorn
Details
Sample Gtk program to demonstrate the issue. (1.27 KB, text/x-c++src)
2020-06-01 19:17 UTC, Michael Weghorn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Weghorn 2020-06-01 19:16:43 UTC
Created attachment 128978 [details]
Screenshot of the portal-native KF5 file save dialog used with simple-scan

SUMMARY

The FileChooser portal API for 'accept_label' parameter says:

> accept_label s
>
>     The label for the accept button. Mnemonic underlines are allowed.

However, it seems like xdg-desktop-portal-kde does not properly handle this, but shows literal underscores instead of applying the mnemonics.

This can be seen e.g. when using simple-scan (a Gtk application). For the "Save" button, the text "_Save" is shown instead (s. attached screenshot).

I'll also attach a small sample Gtk application to reproduce.

STEPS TO REPRODUCE
1. compile the attached sample Gtk application that sets the accept label to "S_ave & Done & Finished":

    gcc -g -O0 -o main_set_save_label $(shell pkg-config --cflags gtk+-3.0) main_set_save_label.cpp $(shell pkg-config --libs gtk+-3.0)

2. run it, using native KF5 file chooser via portal:

    GTK_USE_PORTAL=1 ./main_set_save_label

3. check the text shown for the confirmation button

4. Press Alt to see what character is being used for the mnemonic for the confirmation button

5. Press Alt+A to confirm (since the mnemonic was supposed to be set for the "a" in the label).

OBSERVED RESULT

at step 3: The text is "S_ave Done Finished" (with an extra underscore after the 's' and the literal ampersands having gone missing.)
at step 4: The "S" is being underlined to indicate that it is the mnemonic.
at step 5: An "a" is inserted in the file name box.

EXPECTED RESULT

at step 3: The text should be is "Save & Done & Finished" (without any extra underscore and containing 2 literal '&'s)
at step 4: The "a" should be underlined to indicate that it is the mnemonic.
at step 5: The dialog should close.

SOFTWARE/OS VERSIONS+

Operating System: Debian GNU/Linux 
KDE Plasma Version: 5.17.5
KDE Frameworks Version: 5.70.0
Qt Version: 5.12.5
Kernel Version: 5.6.0-2-amd64
OS Type: 64-bit
Processors: 4 × Intel® Core™ i5-5300U CPU @ 2.30GHz
Memory: 15.4 GiB of RAM


ADDITIONAL INFORMATION

xdg-desktop-portal-kde 5.17.5-2 is used.
Comment 1 Michael Weghorn 2020-06-01 19:17:43 UTC
Created attachment 128979 [details]
Sample Gtk program to demonstrate the issue.
Comment 2 Michael Weghorn 2020-06-01 19:24:49 UTC
I have a potential fix at [1]. I did not submit a merge request right away, since that commit is on a branch [2] that has more changes for the FileChooser portal, and I think it makes sense to handle the underlying commits first to avoid merge conflicts in the merge requests.

For the first two commits, those pending merge requests are [3] and [4].

Please let me know if you want me to submit a merge request for this bug right away instead, and I'll rearrange those commits then.

[1] https://invent.kde.org/michaelweghorn/xdg-desktop-portal-kde/-/commit/211b31cad57f332948617cee2d9613e80693169e
[2] https://invent.kde.org/michaelweghorn/xdg-desktop-portal-kde/-/tree/michaelweghorn/filechooser_properly_handle_mnemonics_in_accept_label
[3] https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/2
[4] https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/3
Comment 3 Jan Grulich 2020-07-14 19:47:47 UTC
(In reply to Michael Weghorn from comment #2)
> I have a potential fix at [1]. I did not submit a merge request right away,
> since that commit is on a branch [2] that has more changes for the
> FileChooser portal, and I think it makes sense to handle the underlying
> commits first to avoid merge conflicts in the merge requests.
> 
> For the first two commits, those pending merge requests are [3] and [4].
> 
> Please let me know if you want me to submit a merge request for this bug
> right away instead, and I'll rearrange those commits then.
> 
> [1]
> https://invent.kde.org/michaelweghorn/xdg-desktop-portal-kde/-/commit/
> 211b31cad57f332948617cee2d9613e80693169e
> [2]
> https://invent.kde.org/michaelweghorn/xdg-desktop-portal-kde/-/tree/
> michaelweghorn/filechooser_properly_handle_mnemonics_in_accept_label
> [3] https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/2
> [4] https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/3

Do you plan to submit your change now?
Comment 4 Michael Weghorn 2020-07-15 18:43:57 UTC
(In reply to Jan Grulich from comment #3)
> Do you plan to submit your change now?

Yes; thanks for all the reviews.
I've submitted an MR now: https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/merge_requests/7
Comment 5 Michael Weghorn 2020-07-27 13:47:16 UTC
Git commit daab5c525e7aa14fbd63f678adc5f900e627a839 by Michael Weghorn.
Committed on 25/07/2020 at 20:15.
Pushed by grulich into branch 'master'.

FileChooser: Properly handle mnemonics in 'accept_label'

The FileChooser portal doc [1] for 'accept_label' says:

> accept_label s
>
>     The label for the accept button. Mnemonic underlines are allowed.

Since Qt does not use underscores/underlines, but the ampersand
character ('&') for mnemonics, convert the retrieved
text accordingly, to make the mnemonic applied at the correct
position and preserve literal '&'s.

[1] https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.impl.portal.FileChooser

M  +18   -8    src/filechooser.cpp
M  +2    -0    src/filechooser.h

https://invent.kde.org/plasma/xdg-desktop-portal-kde/commit/daab5c525e7aa14fbd63f678adc5f900e627a839