[gnome-boxes/download-oses-page: 6/12] wizard: Stop grouping downloadable operating systems



commit 7ff6a36e40c0eb060cbb5b33e4cfb70487eb6bd1
Author: Felipe Borges <felipeborges gnome org>
Date:   Tue Jan 23 16:22:08 2018 +0100

    wizard: Stop grouping downloadable operating systems
    
    Since we now have a whole dedicate page for Downloading operating
    systems, we can show individual entries for each Media.

 data/ui/wizard-downloadable-entry.ui |  13 ----
 src/os-database.vala                 |  35 ++---------
 src/wizard-source.vala               | 119 +++++++++--------------------------
 3 files changed, 37 insertions(+), 130 deletions(-)
---
diff --git a/data/ui/wizard-downloadable-entry.ui b/data/ui/wizard-downloadable-entry.ui
index 1a993403..7e897dda 100644
--- a/data/ui/wizard-downloadable-entry.ui
+++ b/data/ui/wizard-downloadable-entry.ui
@@ -75,19 +75,6 @@
           </object>
         </child>
 
-        <child>
-          <object class="GtkRevealer" id="revealer">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <child>
-              <object class="GtkListBox" id="medias_listbox">
-                <property name="visible">True</property>
-                <signal name="row-activated" handler="on_media_listbox_activated"/>
-              </object>
-            </child>
-          </object>
-        </child>
-
       </object>
     </child>
   </template>
diff --git a/src/os-database.vala b/src/os-database.vala
index bcfbad34..3d0959ec 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -101,46 +101,23 @@ public async Os get_os_by_id (string id) throws OSDatabaseError {
         return os;
     }
 
-    public async HashTable<string,Os> list_latest_downloadable_oses () throws OSDatabaseError {
+    public async GLib.List<Osinfo.Media> list_downloadable_oses () throws OSDatabaseError {
         if (!yield ensure_db_loaded ())
             throw new OSDatabaseError.DB_LOADING_FAILED ("Failed to load OS database");
 
-        var os_list = db.get_os_list ();
-        var table = new HashTable<string,Os> (str_hash, str_equal);
-        foreach (var entity in os_list.get_elements ()) {
+        var after_list = new GLib.List<Osinfo.Media> ();
+        foreach (var entity in db.get_os_list ().get_elements ()) {
             var os = entity as Os;
 
-            var has_url = false;
             foreach (var media_entity in os.get_media_list ().get_elements ()) {
                 var media = media_entity as Media;
 
-                has_url = (media.url != null);
-            }
-
-            if (!has_url)
-                continue;
-
-            if (os.get_media_list ().get_length () == 0)
-                continue;
-
-            string os_distro = os.get_distro();
-            var distro = table.lookup (os_distro);
-            if (distro == null) {
-                table.insert (os_distro, os);
-                continue;
+                if (media.url != null && os.get_release_date () != null)
+                    after_list.append (media);
             }
-
-            var release_a = os.get_release_date ();
-            var release_b = distro.get_release_date ();
-
-            if ((release_a == null) || (release_b == null))
-                continue;
-
-            if (release_a.compare (release_b) > 0)
-                table.replace (os_distro, os);
         }
 
-        return table;
+        return after_list;
     }
 
     // Returned list is in ascending order by release dates. If release date is
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 514f73cb..a0cf0e99 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -58,27 +58,30 @@ public override void get_preferred_height (out int minimum_height, out int natur
     }
 }
 
-private class Boxes.WizardDownloadableMediaEntry : Gtk.ListBoxRow {
-    public Osinfo.Media media;
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-downloadable-entry.ui")]
+private class Boxes.WizardDownloadableEntry : Gtk.ListBoxRow {
+    [GtkChild]
+    private Gtk.Image media_image;
+    [GtkChild]
+    private Gtk.Label title_label;
+    [GtkChild]
+    private Gtk.Label details_label;
 
-    private Gtk.Label label;
+    public string url;
 
-    public WizardDownloadableMediaEntry (Osinfo.Media media) {
-        this.media = media;
+    public WizardDownloadableEntry (Osinfo.Media media) {
+        Downloader.fetch_os_logo.begin (media_image, media.os, 64);
 
-        setup_label ();
-        add (label);
+        setup_label (media);
+        details_label.label = media.os.vendor;
 
-        this.get_style_context ().add_class ("boxes-menu-row");
-        this.get_style_context ().add_class ("boxes-menu-subrow");
+        url = media.url;
     }
 
-    private void setup_label () {
+    private void setup_label (Osinfo.Media media) {
         /* Libosinfo lacks some OS variant names, so we do some
            parsing here to compose a unique human-readable media
            identifier. */
-        label = new Gtk.Label ("");
-
         var variant = "";
         var variants = media.get_os_variants ();
         if (variants.get_length () > 0)
@@ -90,7 +93,7 @@ else if ((media.os as Osinfo.Product).name != null) {
         } else {
             var file = File.new_for_uri (media.url);
 
-            label.label = file.get_basename ().replace ("_", "");
+            title_label.label = file.get_basename ().replace ("_", "");
         }
 
         var subvariant = "";
@@ -103,64 +106,12 @@ else if (media.url.contains ("dvd"))
 
         var is_live = media.live ? " (" + _("Live") + ")" : "";
 
-        label.label = @"$variant $(media.architecture) $subvariant $is_live";
+        title_label.label = @"$variant $(media.architecture) $subvariant $is_live";
 
         /* Strip consequent whitespaces */
-        label.label = label.label.replace ("  ", "");
-
-        label.halign = Gtk.Align.START;
-    }
-}
-
-[GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-downloadable-entry.ui")]
-private class Boxes.WizardDownloadableEntry : Gtk.ListBoxRow {
-    [GtkChild]
-    private Gtk.Image media_image;
-    [GtkChild]
-    private Gtk.Label title_label;
-    [GtkChild]
-    private Gtk.Label details_label;
-    [GtkChild]
-    private Gtk.Revealer revealer;
-    [GtkChild]
-    private Gtk.ListBox medias_listbox;
-
-    public Osinfo.Media single_media;
-
-    public signal void activated (Osinfo.Media media);
-
-    public WizardDownloadableEntry (Osinfo.Os os) {
-        Downloader.fetch_os_logo.begin (media_image, os, 64);
-
-        title_label.label = os.name;
-        details_label.label = os.vendor;
-
-        var media_list = os.get_media_list () as Osinfo.List;
-        if (media_list.get_length () == 1)
-            single_media = media_list.get_nth (0) as Osinfo.Media;
-        else
-            populate_media_listbox (media_list);
-    }
-
-    private void populate_media_listbox (Osinfo.List media_list) {
-        foreach (var media_entity in media_list.get_elements()) {
-            var media = (media_entity as Osinfo.Media);
-
-            medias_listbox.insert (new WizardDownloadableMediaEntry (media), -1);
-        }
+        title_label.label = title_label.label.replace ("  ", "");
 
-        medias_listbox.show_all ();
-    }
-
-    [GtkCallback]
-    private void on_media_listbox_activated (Gtk.ListBoxRow row) {
-        var entry = row as WizardDownloadableMediaEntry;
-
-        activated (entry.media);
-    }
-
-    public void toggle () {
-        revealer.set_reveal_child (!revealer.child_revealed);
+        title_label.halign = Gtk.Align.START;
     }
 }
 
@@ -457,23 +408,23 @@ public void setup_ui (AppWindow window) {
 
         var os_db = media_manager.os_db;
 
-        var available_downloads_model = new GLib.ListStore (typeof (Osinfo.Os));
+        var available_downloads_model = new GLib.ListStore (typeof (Osinfo.Media));
         downloads_vbox.bind_model (available_downloads_model, create_downloadable_entry);
         downloads_vbox.row_activated.connect (on_downloadable_entry_clicked);
 
         downloads_list.bind_model (available_downloads_model, create_downloadable_entry);
         downloads_list.row_activated.connect (on_downloadable_entry_clicked);
 
-        os_db.list_latest_downloadable_oses.begin ((db, result) => {
+        os_db.list_downloadable_oses.begin ((db, result) => {
             try {
-                var table = os_db.list_latest_downloadable_oses.end (result);
+                var media_list = os_db.list_downloadable_oses.end (result);
 
-                foreach (var os in table.get_values ()) {
-                    available_downloads_model.insert_sorted (os, (a, b) => {
-                        var os1 = a as Osinfo.Product;
-                        var os2 = b as Osinfo.Product;
+                foreach (var media in media_list) {
+                    available_downloads_model.insert_sorted (media, (a, b) => {
+                        var os1 = a as Osinfo.Media;
+                        var os2 = b as Osinfo.Media;
 
-                        return os2.get_release_date ().compare (os1.get_release_date ());
+                        return os2.os.get_release_date ().compare (os1.os.get_release_date ());
                     });
                 }
             } catch (OSDatabaseError error) {
@@ -511,13 +462,9 @@ public void setup_ui (AppWindow window) {
     }
 
     private Gtk.Widget create_downloadable_entry (Object item) {
-        var os = item as Osinfo.Os;
+        var media = item as Osinfo.Media;
 
-        var entry = new WizardDownloadableEntry (os);
-        entry.activated.connect ((media) => {
-            this.uri = media.url;
-        activated ();
-        });
+        var entry = new WizardDownloadableEntry (media);
 
         return entry;
     }
@@ -526,13 +473,9 @@ private void on_downloadable_entry_clicked (Gtk.ListBoxRow row) {
         var entry = (row as WizardDownloadableEntry);
 
         selected = entry;
-        if (entry.single_media != null) {
-           this.uri = entry.single_media.url;
+        this.uri = entry.url;
 
-           activated ();
-        } else {
-            entry.toggle();
-        }
+        activated ();
     }
 
     public void cleanup () {


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