[gnome-boxes] Improved detection for HW install media



commit eed02f21330e5786ac5e366e7471b9ccc330e500
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Nov 24 06:21:29 2011 +0200

    Improved detection for HW install media
    
    Now that we get the ID of the osinfo's media instance that was matched
    against the HW media, we can use that to get that instance to get more
    reliable information about media we are dealing with.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664766

 src/installer-media.vala |   14 +++++++-----
 src/os-database.vala     |   53 +++++++++++++++++++--------------------------
 2 files changed, 30 insertions(+), 37 deletions(-)
---
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 5221485..9581266 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -55,11 +55,9 @@ private class Boxes.InstallerMedia : Object {
                                        Cancellable? cancellable) throws GLib.Error {
         var device = yield get_device_from_path (path, client, cancellable);
 
-        if (device != null) {
-            get_os_and_label_from_device (device, os_db);
-            if (os != null)
-                os_media = os_db.get_prefered_media_for_os (os);
-        } else {
+        if (device != null)
+            get_media_info_from_device (device, os_db);
+        else {
             from_image = true;
             os = yield os_db.guess_os_from_install_media (device_file, out os_media, cancellable);
         }
@@ -91,7 +89,7 @@ private class Boxes.InstallerMedia : Object {
         return client.query_by_device_file (device_file);
     }
 
-    private void get_os_and_label_from_device (GUdev.Device device, OSDatabase os_db) throws OSDatabaseError {
+    private void get_media_info_from_device (GUdev.Device device, OSDatabase os_db) throws OSDatabaseError {
         if (!device.get_property_as_boolean ("OSINFO_BOOTABLE"))
             throw new OSDatabaseError.NON_BOOTABLE ("Media %s is not bootable.", device_file);
 
@@ -100,6 +98,10 @@ private class Boxes.InstallerMedia : Object {
         var os_id = device.get_property ("OSINFO_INSTALLER");
         if (os_id != null) {
             os = os_db.get_os_by_id (os_id);
+
+            var media_id = device.get_property ("OSINFO_MEDIA");
+            if (media_id != null)
+                os_media = os_db.get_media_by_id (os, media_id);
         }
     }
 }
diff --git a/src/os-database.vala b/src/os-database.vala
index 91b881b..403a4f6 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -4,7 +4,8 @@ using Osinfo;
 
 public errordomain Boxes.OSDatabaseError {
     NON_BOOTABLE,
-    UNKNOWN_OS_ID
+    UNKNOWN_OS_ID,
+    UNKNOWN_MEDIA_ID
 }
 
 private class Boxes.OSDatabase {
@@ -49,27 +50,33 @@ private class Boxes.OSDatabase {
         return os;
     }
 
+    public Media get_media_by_id (Os os, string id) throws OSDatabaseError {
+        var medias = os.get_media_list ();
+
+        var media = medias.find_by_id (id) as Media;
+        if (media == null)
+            throw new OSDatabaseError.UNKNOWN_MEDIA_ID ("Unknown media ID '%s'", id);
+
+        return media;
+    }
+
     public Resources get_resources_for_os (Os? os) {
         if (os == null)
             return get_default_resources ();
 
+        // Prefer x86_64 resources
+        string[] prefs = {"x86_64", "i686", "i386", ARCHITECTURE_ALL};
+
         // First try recommended resources
         var list = os.get_recommended_resources ();
-        var recommended = get_prefered_resources (list);
+        var recommended = get_prefered_resources (list, prefs);
 
         list = os.get_minimum_resources ();
-        var minimum = get_prefered_resources (list);
+        var minimum = get_prefered_resources (list, prefs);
 
         return get_resources_from_os_resources (minimum, recommended);
     }
 
-    // FIXME: We should be choosing the media that actually correponsds to original media (if any)
-    public Media? get_prefered_media_for_os (Os os) {
-        var medias = os.get_media_list ();
-
-        return get_prefered_media (medias);
-    }
-
     private Resources get_resources_from_os_resources (Resources? minimum, Resources? recommended) {
         var resources = get_default_resources ();
 
@@ -94,34 +101,18 @@ private class Boxes.OSDatabase {
         return resources;
     }
 
-    private Resources? get_prefered_resources (ResourcesList list) {
-        // Prefer x86_64 resources
-        string[] prefs = {"x86_64", "i686", "i386", ARCHITECTURE_ALL};
-
-        return get_prefered_entity (list.new_filtered, RESOURCES_PROP_ARCHITECTURE, prefs) as Resources;
-    }
-
-    private Media? get_prefered_media (MediaList list) {
-        // Prefer x86_64 resources
-        string[] prefs = {"x86_64", "i686", "i386", ARCHITECTURE_ALL};
-
-        return get_prefered_entity (list.new_filtered, MEDIA_PROP_ARCHITECTURE, prefs) as Media;
-    }
-
-    private Entity? get_prefered_entity (ListFilterFunc filter_func, string property, string[] prefs) {
+    private Resources? get_prefered_resources (ResourcesList list, string[] prefs) {
         if (prefs.length <= 0)
             return null;
 
         var filter = new Filter ();
-        filter.add_constraint (property, prefs[0]);
-        var filtered = filter_func (filter);
+        filter.add_constraint (RESOURCES_PROP_ARCHITECTURE, prefs[0]);
+        var filtered = list.new_filtered (filter);
         if (filtered.get_length () <= 0)
-            return get_prefered_entity (filter_func, property, prefs[1:prefs.length]);
+            return get_prefered_resources (list, prefs[1:prefs.length]);
         else
             // Assumption: There is only one resources instance of each type
             // (minimum/recommended) of each architecture for each OS.
-            return filtered.get_nth (0);
+            return filtered.get_nth (0) as Resources;
     }
-
-    private delegate Osinfo.List ListFilterFunc (Filter filter);
 }



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