[gnome-boxes] wizard-source: Compose a human-readable media label



commit f279e7f756280811ec38cb53fb3b672751cbdead
Author: Felipe Borges <felipeborges gnome org>
Date:   Fri Dec 1 14:59:06 2017 +0100

    wizard-source: Compose a human-readable media label
    
    To enumerate the medias of an operating system in a way that it
    isn't the literal file name neither a duplicated name, we should
    rely on the Osinfo.OsVariant "name" property.
    
    Unfortunately the Osinfo database doesn't contain proper names
    for OS variants. This way, these change introduce some heuristic
    to handle the most common iso file names for the operating systems
    available to download.
    
    If there will be a case not covered by this heuristics, we present
    the literal iso file name with %s/_/" "/g.
    
    This commit should be reverted when Osinfo contains distinguishable
    variant names.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790614

 src/wizard-source.vala |   48 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index f92a93f..fcf8cf4 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -60,21 +60,55 @@ private class Boxes.WizardScrolled : Gtk.ScrolledWindow {
 private class Boxes.WizardDownloadableMediaEntry : Gtk.ListBoxRow {
     public Osinfo.Media media;
 
+    private Gtk.Label label;
+
     public WizardDownloadableMediaEntry (Osinfo.Media media) {
         this.media = media;
 
-        var file = GLib.File.new_for_uri (media.url);
-        var label = new Gtk.Label (file.get_basename ());
-        label.halign = Gtk.Align.START;
-
-        if (media.live)
-            label.label += " (" + _("Live") + ")";
-
+        setup_label ();
         add (label);
 
         this.get_style_context ().add_class ("boxes-menu-row");
         this.get_style_context ().add_class ("boxes-menu-subrow");
     }
+
+    private void setup_label () {
+        /* 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)
+            variant = (variants.get_nth (0) as Osinfo.OsVariant).get_name ();
+        else if ((media.os as Osinfo.Product).name != null) {
+            variant = (media.os as Osinfo.Product).name;
+            if (media.url.contains ("server"))
+                variant += " Server";
+        } else {
+            var file = File.new_for_uri (media.url);
+
+            label.label = file.get_basename ().replace ("_", "");
+        }
+
+        var subvariant = "";
+        if (media.url.contains ("netinst"))
+            subvariant = "(netinst)";
+        else if (media.url.contains ("minimal"))
+            subvariant = "(minimal)";
+        else if (media.url.contains ("dvd"))
+            subvariant = "(DVD)";
+
+        var is_live = media.live ? " (" + _("Live") + ")" : "";
+
+        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")]


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