[gnome-boxes/download-oses-page] wizard: Make downloadable list searchable



commit c1e4d6450723d6159ffcc3d60bca3051e9506792
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Jan 24 15:42:12 2018 +0100

    wizard: Make downloadable list searchable

 data/ui/wizard-source.ui  | 32 --------------------
 data/ui/wizard-toolbar.ui | 42 ++++++++++++++++++++++++++
 data/ui/wizard-window.ui  | 31 +++++++++++++++++++
 src/wizard-source.vala    | 40 ++++++++++---------------
 src/wizard-toolbar.vala   |  7 +++++
 src/wizard-window.vala    | 76 ++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 170 insertions(+), 58 deletions(-)
---
diff --git a/data/ui/wizard-source.ui b/data/ui/wizard-source.ui
index 7565317c..1cf199ab 100644
--- a/data/ui/wizard-source.ui
+++ b/data/ui/wizard-source.ui
@@ -260,38 +260,6 @@
       </packing>
     </child>
 
-    <!-- Download an OS page -->
-    <child>
-      <object class="GtkBox" id="download_an_os_page">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkScrolledWindow">
-            <property name="visible">True</property>
-            <property name="expand">True</property>
-            <child>
-              <object class="GtkBox">
-                <property name="visible">True</property>
-                <property name="orientation">vertical</property>
-                <property name="border-width">20</property>
-                <property name="margin-start">20</property>
-                <property name="margin-end">20</property>
-
-                <child>
-                  <object class="GtkListBox" id="downloads_list">
-                    <property name="visible">True</property>
-                    <signal name="row-activated" handler="on_downloadable_entry_clicked"/>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="name">download-an-os-page</property>
-      </packing>
-    </child>
-
     <!-- RHEL web view page -->
     <child>
       <object class="BoxesWizardWebView" id="rhel_web_view">
diff --git a/data/ui/wizard-toolbar.ui b/data/ui/wizard-toolbar.ui
index 2db34701..9927b7f8 100644
--- a/data/ui/wizard-toolbar.ui
+++ b/data/ui/wizard-toolbar.ui
@@ -185,6 +185,48 @@
       </packing>
     </child>
 
+    <child>
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <style>
+          <class name="titlebar"/>
+        </style>
+
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <signal name="clicked" handler="on_downloads_search_back_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>
+        </child>
+
+        <child type="title">
+          <object class="GtkSearchEntry" id="downloads_search">
+            <property name="visible">True</property>
+            <property name="width-chars">50</property>
+          </object>
+        </child>
+
+      </object>
+      <packing>
+        <property name="name">downloads</property>
+      </packing>
+    </child>
 
   </template>
 
diff --git a/data/ui/wizard-window.ui b/data/ui/wizard-window.ui
index f9ddfa91..de73368d 100644
--- a/data/ui/wizard-window.ui
+++ b/data/ui/wizard-window.ui
@@ -88,6 +88,37 @@
               </packing>
             </child>
 
+            <!-- Download an OS page -->
+            <child>
+              <object class="GtkBox" id="download_an_os_page">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkScrolledWindow">
+                    <property name="visible">True</property>
+                    <property name="expand">True</property>
+                    <child>
+                      <object class="GtkBox">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <property name="border-width">20</property>
+                        <property name="margin-start">20</property>
+                        <property name="margin-end">20</property>
+
+                        <child>
+                          <object class="GtkListBox" id="downloads_list">
+                            <property name="visible">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="name">downloads</property>
+              </packing>
+            </child>
+
           </object>
         </child>
 
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index c13d045e..2fa1ddb9 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -67,6 +67,12 @@ public override void get_preferred_height (out int minimum_height, out int natur
     [GtkChild]
     private Gtk.Label details_label;
 
+    public string title {
+        get {
+            return title_label.get_text ();
+        }
+    }
+
     public string url;
 
     public WizardDownloadableEntry (Osinfo.Media media) {
@@ -294,8 +300,6 @@ private void on_notify_estimated_load_progress () {
     private Gtk.Image install_rhel_image;
     [GtkChild]
     private Boxes.WizardWebView rhel_web_view;
-    [GtkChild]
-    private Gtk.ListBox downloads_list;
 
     private AppWindow window;
 
@@ -493,7 +497,6 @@ private void on_downloads_scrolled_shown () {
         return entry;
     }
 
-    [GtkCallback]
     private void on_downloadable_entry_clicked (Gtk.ListBoxRow row) {
         var entry = (row as WizardDownloadableEntry);
 
@@ -623,31 +626,18 @@ private void on_media_selected (InstallerMedia media) {
 
     [GtkCallback]
     private void on_download_an_os_button_clicked () {
-        page = SourcePage.DOWNLOADS;
-
-        if (downloads_list.get_children ().length () != 0)
-            return;
-
-        var os_db = media_manager.os_db;
-        os_db.list_downloadable_oses.begin ((db, result) => {
-            try {
-                var media_list = os_db.list_downloadable_oses.end (result);
-
-                foreach (var media in media_list) {
-                    var entry = new WizardDownloadableEntry (media);
+        window.wizard_window.show_downloads_page (media_manager.os_db, (uri) => {
+            this.uri = uri;
 
-                    downloads_list.insert (entry, -1);
-                }
-            } catch (OSDatabaseError error) {
-                debug ("Failed to populate the list of downloadable OSes: %s", error.message);
-            }
+            activated ();
         });
 
-        /* We manually add the custom download entries.
-         * custom download entries are items which require
-         * special handling such as an authentication page
-         * before we obtain a direct image URL. */
-        downloads_list.insert (install_rhel_button, 0);
+        // We manually add the custom download entries. Custom download entries
+        // are items which require special handling such as an authentication
+        // page before we obtain a direct image URL.
+        window.wizard_window.add_custom_download (install_rhel_button, () => {
+            on_install_rhel_button_clicked ();
+        });
     }
 
     [GtkCallback]
diff --git a/src/wizard-toolbar.vala b/src/wizard-toolbar.vala
index 38c510f5..77c3e853 100644
--- a/src/wizard-toolbar.vala
+++ b/src/wizard-toolbar.vala
@@ -30,6 +30,8 @@
     public Button continue_btn;
     [GtkChild]
     public Button create_btn;
+    [GtkChild]
+    public SearchEntry downloads_search;
 
     [GtkChild]
     private Button file_chooser_open_button;
@@ -71,6 +73,11 @@ private void on_file_chooser_cancel_clicked () requires (page == WizardWindowPag
         wizard_window.page = WizardWindowPage.MAIN;
     }
 
+    [GtkCallback]
+    private void on_downloads_search_back_clicked () requires (page == WizardWindowPage.DOWNLOADS) {
+        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;
diff --git a/src/wizard-window.vala b/src/wizard-window.vala
index 4d845d8a..b10d9b04 100644
--- a/src/wizard-window.vala
+++ b/src/wizard-window.vala
@@ -5,13 +5,16 @@
     MAIN,
     CUSTOMIZATION,
     FILE_CHOOSER,
+    DOWNLOADS,
 }
 
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-window.ui")]
 private class Boxes.WizardWindow : Gtk.Window, Boxes.UI {
-    public const string[] page_names = { "main", "customization", "file_chooser" };
+    public const string[] page_names = { "main", "customization", "file_chooser", "downloads" };
 
     public delegate void FileChosenFunc (string uri);
+    public delegate void DownloadChosenFunc (string uri);
+    public delegate void CustomDownloadChosenFunc ();
 
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
@@ -48,6 +51,8 @@
     public WizardToolbar topbar;
     [GtkChild]
     public Notificationbar notificationbar;
+    [GtkChild]
+    private Gtk.ListBox downloads_list;
 
     private GLib.List<Boxes.Property> resource_properties;
 
@@ -61,6 +66,11 @@ public WizardWindow (AppWindow app_window) {
         set_transient_for (app_window);
 
         notify["ui-state"].connect (ui_state_changed);
+
+        downloads_list.set_filter_func (downloads_filter_func);
+        topbar.downloads_search.search_changed.connect (() => {
+            downloads_list.invalidate_filter ();
+        });
     }
 
     public void show_customization_page (LibvirtMachine machine) {
@@ -105,6 +115,70 @@ public void show_file_chooser (owned FileChosenFunc file_chosen_func) {
         page = WizardWindowPage.FILE_CHOOSER;
     }
 
+    public void add_custom_download (Gtk.ListBoxRow row, owned CustomDownloadChosenFunc 
custom_download_chosen_func) {
+        if (row.get_parent () != null)
+            return;
+
+        // TODO: insert sorted based on release date.
+        downloads_list.insert (row, -1);
+
+        var button = row.get_child () as Gtk.Button;
+
+        ulong activated_id = 0;
+        activated_id = button.clicked.connect (() => {
+            custom_download_chosen_func ();
+            button.disconnect (activated_id);
+
+            page = WizardWindowPage.MAIN;
+        });
+    }
+
+    public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc download_chosen_func) {
+        page = WizardWindowPage.DOWNLOADS;
+
+        ulong activated_id = 0;
+        activated_id = downloads_list.row_activated.connect ((row) => {
+            var entry = row as WizardDownloadableEntry;
+
+            download_chosen_func (entry.url);
+            downloads_list.disconnect (activated_id);
+
+            page = WizardWindowPage.MAIN;
+        });
+        page = WizardWindowPage.DOWNLOADS;
+        topbar.downloads_search.grab_focus ();
+
+        return_if_fail (downloads_list.get_children ().length () == 0);
+
+        os_db.list_downloadable_oses.begin ((db, result) => {
+            try {
+                var media_list = os_db.list_downloadable_oses.end (result);
+
+                foreach (var media in media_list) {
+                    var entry = new WizardDownloadableEntry (media);
+
+                    downloads_list.insert (entry, -1);
+                }
+            } catch (OSDatabaseError error) {
+                debug ("Failed to populate the list of downloadable OSes: %s", error.message);
+            }
+        });
+    }
+
+    private bool downloads_filter_func (Gtk.ListBoxRow row) {
+        if (topbar.downloads_search.get_text_length () == 0)
+            return true;
+
+        // FIXME: custom items should also be searchable.
+        if (!(row is WizardDownloadableEntry))
+            return false;
+
+        var entry = row as WizardDownloadableEntry;
+        var text = canonicalize_for_search (topbar.downloads_search.get_text ());
+
+        return text in canonicalize_for_search (entry.title);
+    }
+
     private void ui_state_changed () {
         wizard.set_state (ui_state);
 


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