[gnome-boxes/wip/feborges/no-filesystem-access: 1/5] wizard: Use GtkFileChooserNative



commit d0ac0ef1d82e0e7a00a0063ec3ba9e8ade93933e
Author: Felipe Borges <felipeborges gnome org>
Date:   Fri Oct 26 13:36:21 2018 +0200

    wizard: 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 introduce some minor regressions such:
    
    * We can no longer embed the file chooser into an Wizard page:
    For that we perform a little trick of hiding the wizard whenever
    the file chooser is visible and vice-versa.
    
    * We can't use file filters or custom filters:
    This is a bit inconvenient but we do handle unsupported file formats
    by throwing a notification whenever they aren't supported.

 data/ui/wizard-toolbar.ui | 47 -----------------------------------------------
 data/ui/wizard-window.ui  | 13 +++----------
 src/wizard-toolbar.vala   | 33 ---------------------------------
 src/wizard-window.vala    | 24 ++++++++++++------------
 4 files changed, 15 insertions(+), 102 deletions(-)
---
diff --git a/data/ui/wizard-toolbar.ui b/data/ui/wizard-toolbar.ui
index c27eb090..34bc3e82 100644
--- a/data/ui/wizard-toolbar.ui
+++ b/data/ui/wizard-toolbar.ui
@@ -151,53 +151,6 @@
         <style>
           <class name="titlebar"/>
         </style>
-
-        <child>
-          <object class="GtkButton">
-            <property name="visible">True</property>
-            <signal name="clicked" handler="on_back_button_clicked"/>
-            <style>
-              <class name="image-button"/>
-            </style>
-
-             <child internal-child="accessible">
-               <object class="AtkObject">
-                <property name="accessible-name" translatable="yes">Back</property>
-               </object>
-             </child>
-
-             <child>
-               <object class="GtkImage">
-                 <property name="visible">True</property>
-                 <property name="icon-name">go-previous-symbolic</property>
-               </object>
-             </child>
-          </object>
-
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
-        </child>
-
-        <child>
-          <object class="GtkButton" id="file_chooser_open_button">
-            <property name="visible">True</property>
-            <property name="sensitive">False</property>
-            <property name="valign">center</property>
-            <property name="use-underline">True</property>
-            <property name="label" translatable="yes">_Open</property>
-            <signal name="clicked" handler="on_file_chooser_open_clicked"/>
-            <style>
-              <class name="text-button"/>
-            </style>
-
-          </object>
-
-          <packing>
-            <property name="pack-type">end</property>
-          </packing>
-        </child>
-
       </object>
 
       <packing>
diff --git a/data/ui/wizard-window.ui b/data/ui/wizard-window.ui
index 51b64781..bd0497da 100644
--- a/data/ui/wizard-window.ui
+++ b/data/ui/wizard-window.ui
@@ -118,12 +118,10 @@
               </packing>
             </child>
 
-            <child>
-              <object class="GtkFileChooserWidget" id="file_chooser">
+            <!-- Let's show an empty page when the GtkFileChooserNative is showing -->
+             <child>
+              <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="show-hidden">False</property>
-                <property name="local-only">False</property>
-                <property name="filter">supported_files_filter</property>
               </object>
 
               <packing>
@@ -154,9 +152,4 @@
     </child>
   </template>
 
-  <object class="GtkFileFilter" id="supported_files_filter">
-    <mime-types>
-      <mime-type>application/x-cd-image</mime-type>
-    </mime-types>
-  </object>
 </interface>
diff --git a/src/wizard-toolbar.vala b/src/wizard-toolbar.vala
index d97bf02a..69e4c158 100644
--- a/src/wizard-toolbar.vala
+++ b/src/wizard-toolbar.vala
@@ -33,9 +33,6 @@
     [GtkChild]
     public SearchEntry downloads_search;
 
-    [GtkChild]
-    private Button file_chooser_open_button;
-
     private unowned WizardWindow wizard_window;
 
     public string title {
@@ -45,13 +42,6 @@
 
     public void setup_ui (WizardWindow wizard_window) {
         this.wizard_window = wizard_window;
-
-        var file_chooser = wizard_window.file_chooser;
-        file_chooser.selection_changed.connect (() => {
-            var path = file_chooser.get_filename ();
-
-            file_chooser_open_button.sensitive = (path != null);
-        });
     }
 
     public void click_back_button () {
@@ -74,27 +64,4 @@ private void on_back_button_clicked () {
 
         wizard_window.page = WizardWindowPage.MAIN;
     }
-
-    [GtkCallback]
-    private void on_file_chooser_open_clicked () requires (page == WizardWindowPage.FILE_CHOOSER) {
-        var file_chooser = wizard_window.file_chooser;
-        var file = file_chooser.get_file ();
-        assert (file != null);
-        var file_type = file.query_file_type (FileQueryInfoFlags.NONE, null);
-
-        switch (file_type) {
-        case GLib.FileType.REGULAR:
-        case GLib.FileType.SYMBOLIC_LINK:
-            file_chooser.file_activated ();
-            break;
-
-        case GLib.FileType.DIRECTORY:
-            file_chooser.set_current_folder (file.get_path ());
-            break;
-
-        default:
-            debug ("Unknown file type selected");
-            break;
-        }
-    }
 }
diff --git a/src/wizard-window.vala b/src/wizard-window.vala
index cd0f36ee..bee36f89 100644
--- a/src/wizard-window.vala
+++ b/src/wizard-window.vala
@@ -46,8 +46,8 @@
     public WizardDownloadsPage downloads_page;
     [GtkChild]
     public Gtk.Grid customization_grid;
-    [GtkChild]
-    public Gtk.FileChooserWidget file_chooser;
+
+    public Gtk.FileChooserNative file_chooser;
     [GtkChild]
     public WizardToolbar topbar;
     [GtkChild]
@@ -64,8 +64,11 @@ public WizardWindow (AppWindow app_window) {
             page = WizardWindowPage.MAIN;
         }
 
-        foreach (var extension in InstalledMedia.supported_extensions)
-            file_chooser.filter.add_pattern ("*" + extension);
+        file_chooser = new Gtk.FileChooserNative (_("Select a device or ISO file"),
+                                                  app_window,
+                                                  Gtk.FileChooserAction.OPEN,
+                                                  _("Open"), _("Cancel"));
+        file_chooser.bind_property ("visible", this, "visible", BindingFlags.INVERT_BOOLEAN);
 
         set_transient_for (app_window);
 
@@ -127,15 +130,12 @@ public void show_customization_page (LibvirtMachine machine) {
     }
 
     public void show_file_chooser (owned FileChosenFunc file_chosen_func) {
-        ulong activated_id = 0;
-        activated_id = file_chooser.file_activated.connect (() => {
-            var uri = file_chooser.get_uri ();
-            file_chosen_func (uri);
-            file_chooser.disconnect (activated_id);
-
-            page = WizardWindowPage.MAIN;
-        });
         page = WizardWindowPage.FILE_CHOOSER;
+        var res = file_chooser.run ();
+        if (res == Gtk.ResponseType.ACCEPT) {
+            file_chosen_func (file_chooser.get_uri ());
+        }
+        page = WizardWindowPage.MAIN;
     }
 
     public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc download_chosen_func) {


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