After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 770467 - Port to GtkFileChooserNative, drop Flatpak filesystem perms
Port to GtkFileChooserNative, drop Flatpak filesystem perms
Status: RESOLVED FIXED
Product: geary
Classification: Other
Component: client
master
Other Linux
: Normal normal
: 0.12.0
Assigned To: Geary Maintainers
Geary Maintainers
flatpak
Depends on:
Blocks: 766479
 
 
Reported: 2016-08-27 04:15 UTC by Michael Gratton
Modified: 2017-02-07 13:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch proposal v1 (10.86 KB, patch)
2016-09-15 13:49 UTC, Gautier Pelloux-Prayer
none Details | Review
patch proposal v2 (10.87 KB, patch)
2016-09-15 15:05 UTC, Gautier Pelloux-Prayer
none Details | Review
patch proposal v3 (6.04 KB, patch)
2016-09-27 07:38 UTC, Gautier Pelloux-Prayer
none Details | Review
patch proposal v4 (5.58 KB, patch)
2016-10-03 17:45 UTC, Gautier Pelloux-Prayer
committed Details | Review
fix invalid gtk3 detection (714 bytes, patch)
2016-10-04 08:34 UTC, Gautier Pelloux-Prayer
committed Details | Review
fix save/save all filechooser (2.12 KB, patch)
2016-10-05 08:26 UTC, Gautier Pelloux-Prayer
committed Details | Review

Description Michael Gratton 2016-08-27 04:15:40 UTC
Geary should use GtkFileChooserNative for opening/saving files (mostly attachments) so that its file system access can be reduced under Flatpak, per this discussion: https://lists.freedesktop.org/archives/xdg-app/2016-August/000373.html

Since GtkFileChooserNative was introduced in GTK 3.20, we can't depend on it being available, but it would be worth adding conditional compilation for this (and other GTK 3.20 features.
Comment 1 Gautier Pelloux-Prayer 2016-09-15 13:48:19 UTC
Here is an attempt to fix this issue. Any feedbacks appreciated.
Comment 2 Gautier Pelloux-Prayer 2016-09-15 13:49:25 UTC
Created attachment 335641 [details] [review]
patch proposal v1
Comment 3 Gautier Pelloux-Prayer 2016-09-15 15:05:34 UTC
Created attachment 335652 [details] [review]
patch proposal v2
Comment 4 Michael Gratton 2016-09-18 05:27:50 UTC
Review of attachment 335652 [details] [review]:

This is a good first cut - the general approach is sound, there's just some details that need sorting out.

::: CMakeLists.txt
@@ +63,1 @@
 

I'm not sure if this is something we want to make a compile time option.

When compiling against GTK+ < 3.20, we have to use GtkFileChooserDialog since the native one isn't available, hence the compile time option is redundant.

When compiling against GTK+ >= 3.20 we do have the option, but we should just chose one and then use that. I think it's reasonable to always use GtkFileChooserNative in this case, since it's one less avenue for bugs to creep in, and one less thing to remember to ask about when debugging problems.

@@ +87,3 @@
 
+pkg_check_modules(GTK3 QUIET gtk+-3.0>=3.14.0)
+

We already have this check in src/CMakeLists.txt - do we need it twice? If so, the desired minimum version should be set as a variable and used both here and there.

::: src/CMakeLists.txt
@@ +457,3 @@
+            ${EXTRA_VALA_OPTIONS}
+            -D USE_NATIVE_FILECHOOSER
+        )

I would prefer to set a define such as "GTK_3_20" rather than USE_NATIVE_FILECHOOSER since there will be other 3.20 features that we'd like to be able to include in the future.

::: src/client/dialogs/attachment-dialog.vala
@@ +41,1 @@
+        chooser.update_preview.connect(on_update_preview);

My reading of the FileChooserNative docs is that if we hook anything up to the update-preview signal like this, it means that the chooser will fall back to using a non-native chooser implementation. So when packaged for Flatpak, users won't be able to select attachments from outside the sandbox, which is a problem. The only solution to that would then be to not use previews when FileChooserNative is in use, which makes this class mostly redundant.

I would consider removing this class completely, and simply use either FileChooserNative or FileChooserDialog in its place. This means getting rid of previews altogether, but that's fine since the platform should really should be handling that anyway, not Geary.
Comment 5 Michael Gratton 2016-09-18 05:29:35 UTC
Err, the first review comment referred to the addition of the USE_NATIVE_FILECHOOSER CMake option - not sure what it is missing from the comment.
Comment 6 Gautier Pelloux-Prayer 2016-09-18 15:09:44 UTC
Actually update-preview can be used with FileChooserNative, but not everywhere: on windows it will automatically fall backs to FileChooserDialog in place of IFileDialog, but for other platforms it's OK.
Having the preview is actually quite cool, hence the compilation option:
- we should use FileChooserNative only with Flatpak and/or on Windows for better system integration (and probably because IFileDialog has a preview but I did not check that).
- however on gtk builds, there is no interest in using FileChooserNative since this is actually a FileChooserDialog (without preview) - we don't gain much here I believe (we actually lose the color of the confirmation button). As Emmanuele Bassi stated "FileChooserNative" is a limited version of "FileChooserDialog", so in my opinion we should stuck with a FileChooserDialog as much as possible?

Anyway all my assumptions are based on the fact that image preview is cool; if we drop that then I agree with the rest of your arguments; that's up to you :).
Comment 7 Michael Gratton 2016-09-19 01:18:46 UTC
Yep, I like the preview as well, but my understanding is that we'll have a similar problem under Flatpak as under Win32: Using FileChooserNative will invoke a DBus call to a portal, which is what displays the FileChooserDialog and passes the chosen file back to the sandbox via a shared file handle. Hence Geary won't have access to the portal's FileChooserDialog, and won't be able to display a preview. More details here https://blogs.gnome.org/mclasen/2016/07/08/portals-using-gtk-in-a-flatpak/

The question is then - will GTK+ in this case fall back to using FileChooserDialog under Flatpak as it does for Win32, or will it just ignore the preview? I'm not sure, but the former seems more sensible from an implementation perspective.

I guess we could find out by simply landing this as-is on master and waiting for the Flatpak nightly build to occur, then test it out, or maybe you could ask on the Flatpak list (xdg-apps)? Do you have a preference? Where did you hear ebassi mention this?
Comment 8 Gautier Pelloux-Prayer 2016-09-22 22:54:45 UTC
I am actually quite discovering flatpak and trying to build Geary yet so I could not check both theories; maybe landing it to master would be faster but otherwise I should be able to build it anytime soon.
Comment 9 Michael Gratton 2016-09-22 23:35:58 UTC
No problem, I'd rather know what the complete story is before changing things.

Geary has a flatpak-builder config in https://git.gnome.org/browse/gnome-apps-nightly/ you can use, if that help. It currently takes a while to build since we need to also build WebKitGTK, but that will be a lot better once the WebKit2 port lands since we can use that from the Platform.
Comment 10 Gautier Pelloux-Prayer 2016-09-26 19:12:41 UTC
Actually I don't know why I did not reply to this question earlier, because it's clearly stated in the documentation:

(section Portail details of https://developer.gnome.org/gtk3/unstable/gtk3-GtkFileChooserNative.html):
In this situation, the following things are not supported and will be silently ignored:
    Extra widgets added with gtk_file_chooser_set_extra_widget().
    Use of custom previews by connecting to “update-preview”.
    Any GtkFileFilter added with a custom filter.



Anyway, I finally succeeded to build a flatpak geary, using the following (for reference :)).

git clone git://git.gnome.org/gnome-apps-nightly
cd gnome-apps-nightly/
flatpak install gnome org.gnome.Platform 3.22
flatpak install gnome org.gnome.Sdk 3.22
sed -i 's/runtime_version": "master"/runtime_version": "3.22"/' org.gnome.Geary.json
# I also modified org.gnome.Geary.json to use my git branch
flatpak-builder --repo=repo gearybuild org.gnome.Geary.json 3.22
# wait a few hours for webkitgtk to compile...
flatpak remote-add --no-gpg-verify repo file://$PWD/repo
flatpak install repo org.gnome.Geary
# there is a bug in the binary generated by flatpak, so I hacked by doing this:
mkdir ~/.var/app/org.gnome.Geary/config/geary 
flatpak run org.gnome.Geary

As a result, the attach button opens a dbus portal as expected (don't forget to install xdg-desktop-portal-gtk and xdg-desktop-portal!), and preview is silently ignored.
It was a week-long experience, but still interesting to see flatpak in action.
Comment 11 Gautier Pelloux-Prayer 2016-09-26 19:15:41 UTC
Also I forgot to mention that if xdg-desktop-portal is missing, filechoosernative should fallback automatically to filechooserdialog instead, but it is not yet available in gtk+ (see https://mail.gnome.org/archives/commits-list/2016-June/msg02349.html). 
So for now if you have no portal available, the attach button won't do anything.
Comment 12 Michael Gratton 2016-09-27 00:01:04 UTC
Oh, good news! Okay, so I'm happy to keep the preview then. A compile-time option is still overkill however, so if you can drop that and address the other two points in comment 4 above, then we can get this committed.
Comment 13 Gautier Pelloux-Prayer 2016-09-27 07:38:34 UTC
Created attachment 336314 [details] [review]
patch proposal v3

Hopefully I addressed all concerns!
Comment 14 Gautier Pelloux-Prayer 2016-09-30 15:09:17 UTC
Hello, any news on this Michael (just bumping in case you missed it ;)).
Comment 15 Michael Gratton 2016-09-30 22:11:44 UTC
Review of attachment 336314 [details] [review]:

Oh, thanks for the reminder, I had indeed missed it. Just one thing that wasn't addressed from v2:

::: CMakeLists.txt
@@ +86,3 @@
 
+pkg_check_modules(GTK3 QUIET gtk+-3.0>=3.14.0)
+

We already have this check in src/CMakeLists.txt - do we need it twice? If so, the desired minimum version should be set as a variable similar to TARGET_GLIB and used both here and there.
Comment 16 Gautier Pelloux-Prayer 2016-10-03 17:45:40 UTC
Created attachment 336833 [details] [review]
patch proposal v4

My bad, I thought I already fixed that issue but I actually did not commit it.
Comment 17 Michael Gratton 2016-10-03 23:27:23 UTC
Review of attachment 336833 [details] [review]:

No probs. This has been pushed to master as 65fed2c. Thanks again!
Comment 18 Michael Gratton 2016-10-03 23:34:13 UTC
The last thing to do here is to try dropping the RO/RW perms for host and home in the org.gnome.Geary.json builder conf in gnome-apps-nightly and see if anything breaks as a result.
Comment 19 Michael Gratton 2016-10-03 23:54:36 UTC
In particular, the way Bug 712995 has been implemented may be problematic in terms of how inserted images are displayed in the composer and subsequently attached when sent. I'll test that out when I have a moment.
Comment 20 Gautier Pelloux-Prayer 2016-10-04 08:34:26 UTC
Created attachment 336857 [details] [review]
fix invalid gtk3 detection

Oops, pkg_check_modules does not use cmake proper syntax when exporting variables resulting in GTK_3_20 never being declared... please find the fix attached.

In the mean time I tested without read/write permissions and it works! (Though the native filechooser hangs when you try to type '/usr' in the path bar and become unresponsive - but this is not related to geary I believe).
Comment 21 Michael Gratton 2016-10-04 10:34:07 UTC
Review of attachment 336857 [details] [review]:

Thanks for following that up. I was just starting to wonder why my Flatpak build's file choosers were't showing anything. :)

Pushed to master as a8930e5.
Comment 22 Michael Gratton 2016-10-05 05:04:27 UTC
Oh, you know what else we both forgot? The Save/Save All attachments dialogs.

I was running a local Flatpak build, and Attach and Insert Image were both working fine (the latter needs this xdg-desktop-portal PR to work however: https://github.com/flatpak/xdg-desktop-portal/pull/69), however neither saving attachments or saving all attachments is working.

I think these were in an earlier version of the patch, can you see if you still have those changes lying around?
Comment 23 Gautier Pelloux-Prayer 2016-10-05 08:26:04 UTC
Created attachment 336966 [details] [review]
fix save/save all filechooser

You are right; it has been removed between version 2 and 3, when I tried to fix my white-spaces mess…
Comment 24 Michael Gratton 2016-10-07 11:11:52 UTC
Review of attachment 336966 [details] [review]:

Cheers, I just pushed this as acb6b70.

I only noticed afterwards, but do you get the Save/Cancelled button text labels swapped? I'm on GTK+ 3.20 here and the Save button is on the left, but acts as a Cancel, and vice versa.
Comment 25 Michael Gratton 2017-02-07 13:58:34 UTC
This is looking pretty solid under Flatpak now, so closing as fixed.