[gnome-boxes/wip/feborges/no-filesystem-access: 4/5] shared-folder-popover: Use GtkFileChooserNative



commit bf43d92a0e1304ed38cd4ec245041e4c8e3fba68
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Oct 30 19:28:56 2018 +0100

    shared-folder-popover: Use GtkFileChooserNative
    
    These changes are necessary in order to make Boxes consume the
    Flatpak file chooser portal.
    
    FileChooserNative is an abstraction of a file chooser dialog that
    uses the running platform's native file chooser dialog. Although
    Boxes is Linux-exclusive, we need FileChooserNative in order to
    consume the org.freedesktop.portal.FileChooser portal whenever it
    is available on the session bus.
    
    This way we bring up an out-of-process file chooser that enables
    the user to select a file to be used in Boxes without giving us
    access to the filesystem out of the Flatpak sandbox.
    
    These changes introduced some minor regressions in UX, such as
    having a "dialog in a dialog", by having a button that opens the
    file chooser instead of a file chooser button as we used to have.
    Still, this is compatible with the shared folders mockups available
    at https://raw.githubusercontent.com/gnome-design-team/
    gnome-mockups/master/boxes/wires/file-sharing.png

 data/ui/shared-folder-popover.ui | 177 ++++++++++++++++-----------------------
 src/shared-folder-popover.vala   |  24 ++++--
 src/spice-display.vala           |   2 +-
 3 files changed, 93 insertions(+), 110 deletions(-)
---
diff --git a/data/ui/shared-folder-popover.ui b/data/ui/shared-folder-popover.ui
index a92a0e23..e77e3b5e 100644
--- a/data/ui/shared-folder-popover.ui
+++ b/data/ui/shared-folder-popover.ui
@@ -7,132 +7,101 @@
     <property name="modal">True</property>
     <property name="position">bottom</property>
     <child>
-      <object class="GtkBox">
+      <object class="GtkGrid">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="margin_left">36</property>
-        <property name="margin_right">16</property>
-        <property name="margin_top">12</property>
-        <property name="margin_bottom">12</property>
-        <property name="spacing">23</property>
+        <property name="border-width">12</property>
+        <property name="column-spacing">12</property>
+        <property name="row-spacing">12</property>
         <child>
-          <object class="GtkBox">
+          <object class="GtkLabel">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">end</property>
-                <property name="valign">start</property>
-                <property name="margin_top">6</property>
-                <property name="label" translatable="yes">Local Folder</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="halign">end</property>
-                <property name="valign">center</property>
-                <property name="margin_top">20</property>
-                <property name="label" translatable="yes">Name</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
+            <property name="halign">end</property>
+            <property name="label" translatable="yes">Local Folder</property>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
+            <property name="left-attach">0</property>
+            <property name="top-attach">0</property>
           </packing>
         </child>
         <child>
-          <object class="GtkBox">
+          <object class="GtkEntry" id="path_entry">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">6</property>
-            <child>
-              <object class="GtkFileChooserButton" id="file_chooser_button">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="action">select-folder</property>
-                <property name="title" translatable="yes">Select Shared Folder</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
+            <property name="editable">False</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">0</property>
+            <property name="width">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Browse…</property>
+            <signal name="clicked" handler="on_browse_button_clicked"/>
+          </object>
+          <packing>
+            <property name="left-attach">3</property>
+            <property name="top-attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">end</property>
+            <property name="label" translatable="yes">Name</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="name_entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+            <property name="width">3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="spacing">12</property>
             <child>
-              <object class="GtkEntry" id="name_entry">
+              <object class="GtkButton">
+                <property name="label" translatable="yes">Cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="hexpand">True</property>
+                <signal name="clicked" handler="on_cancel"/>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
+              <object class="GtkButton">
+                <property name="label" translatable="yes">Save</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="spacing">6</property>
-                <property name="homogeneous">True</property>
-                <child>
-                  <object class="GtkButton">
-                    <property name="label" translatable="yes">Cancel</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <signal name="clicked" handler="on_cancel"/>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkButton">
-                    <property name="label" translatable="yes">Save</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <signal name="clicked" handler="on_save"/>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
-                </child>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="hexpand">True</property>
+                <signal name="clicked" handler="on_save"/>
+                <style>
+                  <class name="suggested-action"/>
+                </style>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+            <property name="width">3</property>
           </packing>
         </child>
       </object>
diff --git a/src/shared-folder-popover.vala b/src/shared-folder-popover.vala
index 32e9af67..a95f13da 100644
--- a/src/shared-folder-popover.vala
+++ b/src/shared-folder-popover.vala
@@ -5,16 +5,22 @@
 private class Boxes.SharedFolderPopover: Gtk.Popover {
     public signal void saved (string local_folder, string name, int target_position);
 
-    [GtkChild]
-    public Gtk.FileChooserButton file_chooser_button;
+    public Gtk.FileChooserNative file_chooser;
+
     [GtkChild]
     public Gtk.Entry name_entry;
+    [GtkChild]
+    public Gtk.Entry path_entry;
 
     public int target_position;
 
     construct {
-        var default_path = Environment.get_user_special_dir (UserDirectory.PUBLIC_SHARE);
-        file_chooser_button.set_current_folder (default_path);
+        file_chooser = new Gtk.FileChooserNative (
+            _("Select Shared Folder"),
+            App.app.main_window,
+            Gtk.FileChooserAction.SELECT_FOLDER,
+            _("Select"), _("Cancel")
+        );
     }
 
     [GtkCallback]
@@ -24,7 +30,7 @@ public void on_cancel (Gtk.Button cancel_button) {
 
     [GtkCallback]
     public void on_save (Gtk.Button save_button) {
-        var uri = file_chooser_button.get_uri ();
+        var uri = path_entry.get_text ();
         File file = File.new_for_uri (uri);
         var name = name_entry.get_text ();
 
@@ -37,4 +43,12 @@ public void on_save (Gtk.Button save_button) {
 
         popdown ();
     }
+
+    [GtkCallback]
+    public void on_browse_button_clicked () {
+        if (file_chooser.run () == Gtk.ResponseType.ACCEPT) {
+            var uri = file_chooser.get_uri ();
+            path_entry.set_text (uri);
+        }
+    }
 }
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 5dc7af29..3026b143 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -704,7 +704,7 @@ public override void send_keys (uint[] keyvals) {
             popover.target_position = row.get_index ();
 
             var folder_row = row as SharedFolderRow;
-            popover.file_chooser_button.set_uri ("file://" + folder_row.folder_path);
+            popover.path_entry.set_text (folder_row.folder_path);
             popover.name_entry.set_text (folder_row.folder_name);
 
             popover.popup ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]