[gnome-boxes/show-logos-while-dowloading: 2/2] wizard: Show logo while downloading image



commit de46e6ebcb9b9c1961d7cefbc38ce88cf36949b2
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Feb 26 14:50:18 2018 +0100

    wizard: Show logo while downloading image
    
    This fixes a regression introduced with the "Download an OS"
    feature.
    
    When introducing the option to download RHEL we were populating a
    media_urls_store which was later queried to provide a Osinfo.Os
    given a download URL.
    
    The media_urls_store was removed when the URL completion was dropped
    in the Enter a URL view, since it was made obsolete by the "Download
    an OS" page.

 src/wizard-source.vala | 40 ----------------------------------------
 src/wizard-window.vala |  9 +++++++++
 src/wizard.vala        |  2 +-
 3 files changed, 10 insertions(+), 41 deletions(-)
---
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 76202b68..8830e18a 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -306,10 +306,7 @@ private void on_notify_estimated_load_progress () {
     private Gtk.ListBox media_vbox;
     private Gtk.ListBox downloads_vbox;
 
-    private Gtk.ListStore? media_urls_store;
-
     private Cancellable? rhel_cancellable;
-    private Gtk.TreeRowReference? rhel_os_row_reference;
     private Osinfo.Os? rhel_os;
 
     public MediaManager media_manager;
@@ -330,20 +327,6 @@ private void on_notify_estimated_load_progress () {
         }
     }
 
-    public Osinfo.Os? get_os_from_uri (string uri) {
-        Osinfo.Os? os = null;
-
-        media_urls_store.foreach ((store, path, iter) => {
-            string? os_uri;
-            media_urls_store.get (iter,
-                                  OSDatabase.MediaURLsColumns.URL, out os_uri,
-                                  OSDatabase.MediaURLsColumns.OS, out os);
-            return os_uri == uri;
-        });
-
-        return os;
-    }
-
     private SourcePage _page;
     public SourcePage page {
         get { return _page; }
@@ -667,29 +650,6 @@ private bool on_rhel_web_view_decide_policy (WebKit.WebView web_view,
 
         debug ("RHEL ISO download URI: %s", download_uri);
 
-        if (rhel_os != null) {
-            Gtk.TreeIter iter;
-            Gtk.TreePath? path;
-            bool iter_is_valid = false;
-
-            if (rhel_os_row_reference == null) {
-                media_urls_store.append (out iter);
-                iter_is_valid = true;
-
-                path = media_urls_store.get_path (iter);
-                rhel_os_row_reference = new Gtk.TreeRowReference (media_urls_store, path);
-            } else {
-                path = rhel_os_row_reference.get_path ();
-                iter_is_valid = media_urls_store.get_iter (out iter, path);
-            }
-
-            if (iter_is_valid) {
-                media_urls_store.set (iter,
-                                      OSDatabase.MediaURLsColumns.URL, download_uri,
-                                      OSDatabase.MediaURLsColumns.OS, rhel_os);
-            }
-        }
-
         var soup_download_uri = new Soup.URI (download_uri);
         var download_path = soup_download_uri.get_path ();
 
diff --git a/src/wizard-window.vala b/src/wizard-window.vala
index b10d9b04..be48e244 100644
--- a/src/wizard-window.vala
+++ b/src/wizard-window.vala
@@ -16,6 +16,8 @@
     public delegate void DownloadChosenFunc (string uri);
     public delegate void CustomDownloadChosenFunc ();
 
+    private HashTable<string,Osinfo.Os> logos_table;
+
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
@@ -71,6 +73,8 @@ public WizardWindow (AppWindow app_window) {
         topbar.downloads_search.search_changed.connect (() => {
             downloads_list.invalidate_filter ();
         });
+
+        logos_table = new HashTable<string, Osinfo.Os> (str_hash, str_equal);
     }
 
     public void show_customization_page (LibvirtMachine machine) {
@@ -158,6 +162,7 @@ public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc down
                     var entry = new WizardDownloadableEntry (media);
 
                     downloads_list.insert (entry, -1);
+                    logos_table.insert (media.url, media.os);
                 }
             } catch (OSDatabaseError error) {
                 debug ("Failed to populate the list of downloadable OSes: %s", error.message);
@@ -165,6 +170,10 @@ public void show_downloads_page (OSDatabase os_db, owned DownloadChosenFunc down
         });
     }
 
+    public Osinfo.Os? get_os_from_uri (string uri) {
+       return logos_table.lookup (uri);
+    }
+
     private bool downloads_filter_func (Gtk.ListBoxRow row) {
         if (topbar.downloads_search.get_text_length () == 0)
             return true;
diff --git a/src/wizard.vala b/src/wizard.vala
index dfc7b287..ed452246 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -439,7 +439,7 @@ private bool prepare (ActivityProgress progress) {
             continue_button.sensitive = false;
             download_media.begin (wizard_source.uri, wizard_source.filename, progress);
 
-            var os = wizard_source.get_os_from_uri (wizard_source.uri);
+            var os = wizard_window.get_os_from_uri (wizard_source.uri);
             if (os == null)
                 debug ("Failed to find Osinfo.Os for %s", wizard_source.uri);
             else


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