[gnome-boxes/use-portal-for-cddvd] properties-window: Use GtkFileChooserNative



commit d09995c700f5f8768c76803bf843db3bed4d05ae
Author: Felipe Borges <felipeborges gnome org>
Date:   Fri Oct 26 14:14:29 2018 +0200

    properties-window: 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 a Properties page:
    For that we perform a little trick of hiding the wizard whenever
    the file chooser is visible and vice-versa.
    
    Fixes #351

 data/ui/properties-toolbar.ui | 38 --------------------------------------
 data/ui/properties-window.ui  |  7 ++-----
 src/properties-toolbar.vala   | 37 -------------------------------------
 src/properties-window.vala    | 25 +++++++++++++++----------
 4 files changed, 17 insertions(+), 90 deletions(-)
---
diff --git a/data/ui/properties-toolbar.ui b/data/ui/properties-toolbar.ui
index b8d76c4d..3d096ba3 100644
--- a/data/ui/properties-toolbar.ui
+++ b/data/ui/properties-toolbar.ui
@@ -107,44 +107,6 @@
         <style>
           <class name="titlebar"/>
         </style>
-
-        <child>
-          <object class="GtkButton" id="file_chooser_cancel_button">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="use-underline">True</property>
-            <property name="label" translatable="yes">_Cancel</property>
-            <signal name="clicked" handler="on_file_chooser_cancel_clicked"/>
-            <style>
-              <class name="text-button"/>
-            </style>
-
-          </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/properties-window.ui b/data/ui/properties-window.ui
index 6ae19eba..f8e2dd1e 100644
--- a/data/ui/properties-window.ui
+++ b/data/ui/properties-window.ui
@@ -16,7 +16,7 @@
         |         |
         |         |-> troubleshoot_log = new Boxes.TroubleshootLog ();
         |         |
-        |         |-> file_chooser = new Gtk.FileChooserWidget ();
+        |         |-> file_chooser = new Gtk.FileChooserNative ();
         |
         |-> topbar = new Boxes.PropertiesToolbar (); // as titlebar
   -->
@@ -71,11 +71,8 @@
             </child>
 
             <child>
-              <object class="GtkFileChooserWidget" id="file_chooser">
+              <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="show-hidden">False</property>
-                <property name="local-only">True</property>
-                <property name="filter">supported_files_filter</property>
               </object>
 
               <packing>
diff --git a/src/properties-toolbar.vala b/src/properties-toolbar.vala
index ab9478b7..6d15cfa3 100644
--- a/src/properties-toolbar.vala
+++ b/src/properties-toolbar.vala
@@ -21,8 +21,6 @@
 
     [GtkChild]
     private EditableEntry title_entry;
-    [GtkChild]
-    private Button file_chooser_open_button;
 
     private AppWindow window;
     private unowned PropertiesWindow props_window;
@@ -39,13 +37,6 @@ public void setup_ui (AppWindow window, PropertiesWindow props_window) {
         this.window = window;
         this.props_window = props_window;
 
-        var file_chooser = props_window.file_chooser;
-        file_chooser.selection_changed.connect (() => {
-            var path = file_chooser.get_filename ();
-
-            file_chooser_open_button.sensitive = (path != null);
-        });
-
         window.notify["ui-state"].connect (ui_state_changed);
     }
 
@@ -66,34 +57,6 @@ private void on_copy_clipboard_clicked () requires (page == PropsWindowPage.TROU
         props_window.copy_troubleshoot_log_to_clipboard ();
     }
 
-    [GtkCallback]
-    private void on_file_chooser_cancel_clicked () requires (page == PropsWindowPage.FILE_CHOOSER) {
-        props_window.page = PropsWindowPage.MAIN;
-    }
-
-    [GtkCallback]
-    private void on_file_chooser_open_clicked () requires (page == PropsWindowPage.FILE_CHOOSER) {
-        var file_chooser = props_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;
-        }
-    }
-
     [GtkCallback]
     private void on_title_entry_changed () {
         window.current_item.name = title_entry.text;
diff --git a/src/properties-window.vala b/src/properties-window.vala
index b356e3b4..09adb2cf 100644
--- a/src/properties-window.vala
+++ b/src/properties-window.vala
@@ -33,8 +33,8 @@
     public Properties properties;
     [GtkChild]
     public TroubleshootLog troubleshoot_log;
-    [GtkChild]
-    public Gtk.FileChooserWidget file_chooser;
+
+    public Gtk.FileChooserNative file_chooser;
     [GtkChild]
     public PropertiesToolbar topbar;
     [GtkChild]
@@ -51,6 +51,13 @@ public PropertiesWindow (AppWindow app_window) {
         set_transient_for (app_window);
 
         notify["ui-state"].connect (ui_state_changed);
+
+        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);
+
     }
 
     public void show_troubleshoot_log (string log) {
@@ -59,15 +66,13 @@ public void show_troubleshoot_log (string log) {
     }
 
     public void show_file_chooser (owned FileChosenFunc file_chosen_func) {
-        ulong activated_id = 0;
-        activated_id = file_chooser.file_activated.connect (() => {
-            var path = file_chooser.get_filename ();
-            file_chosen_func (path);
-            file_chooser.disconnect (activated_id);
-
-            page = PropsWindowPage.MAIN;
-        });
         page = PropsWindowPage.FILE_CHOOSER;
+        var res = file_chooser.run ();
+        if (res == Gtk.ResponseType.ACCEPT) {
+            file_chosen_func (file_chooser.get_filename ());
+        }
+
+        page = PropsWindowPage.MAIN;
     }
 
     public void copy_troubleshoot_log_to_clipboard () {


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