[gnome-boxes/wip/image-import: 7/9] Add InstalledMedia class



commit 3d7a95f3c8b28a65e775ae363e39e5ef07404bfb
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Jun 5 04:21:02 2013 +0300

    Add InstalledMedia class
    
    A new subclass of InstallerMedia that represents ready-made/installed
    media in the form of raw or qcow2 images.

 src/Makefile.am          |    1 +
 src/installed-media.vala |   44 ++++++++++++++++++++++++++++++++++++++++++++
 src/installer-media.vala |    4 ++--
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 3c1b7c1..5035778 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,6 +87,7 @@ gnome_boxes_SOURCES =                         \
        editable-entry.vala                     \
        i-properties-provider.vala              \
        installer-media.vala                    \
+       installed-media.vala                    \
        iso-extractor.vala                      \
        libvirt-broker.vala                     \
        libvirt-machine.vala                    \
diff --git a/src/installed-media.vala b/src/installed-media.vala
new file mode 100644
index 0000000..015b30a
--- /dev/null
+++ b/src/installed-media.vala
@@ -0,0 +1,44 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+using GVirConfig;
+
+private class Boxes.InstalledMedia : Boxes.InstallerMedia {
+    public override bool need_user_input_for_vm_creation { get { return false; } }
+    public override bool ready_to_create { get { return true; } }
+    public override bool live { get { return false; } }
+
+    public string format { get { return device_file.has_suffix (".qcow2")? "qcow2" : "raw"; } }
+
+    private string architecture = "x86_64"; // FIXME: Hardcode for now
+
+    public InstalledMedia (string path) throws GLib.Error {
+        if (!path.has_suffix (".qcow2") && !path.has_suffix (".img"))
+            throw new Boxes.Error.INVALID (_("Only QEMU QCOW Image (v2) and raw formats supported."));
+
+        device_file = path;
+        label = Path.get_basename (path);
+        from_image = true;
+
+        resources = OSDatabase.get_default_resources ();
+    }
+
+    public override void setup_domain_config (Domain domain) {}
+
+    public override GLib.List<Pair<string,string>> get_vm_properties () {
+        var properties = new GLib.List<Pair<string,string>> ();
+
+        properties.append (new Pair<string,string> (_("System"), label));
+
+        return properties;
+    }
+
+    public override bool is_architecture_compatible (string architecture) {
+        var compatibility = compare_cpu_architectures (architecture, this.architecture);
+
+        return compatibility != CPUArchCompatibility.INCOMPATIBLE;
+    }
+
+    public override VMCreator get_vm_creator () {
+        return new VMImporter (this);
+    }
+}
diff --git a/src/installer-media.vala b/src/installer-media.vala
index e8e6929..6d5db5b 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -32,7 +32,7 @@ private class Boxes.InstallerMedia : GLib.Object {
         }
     }
 
-    public bool live { get { return os_media == null || os_media.live; } }
+    public virtual bool live { get { return os_media == null || os_media.live; } }
 
     public InstallerMedia.from_iso_info (string           path,
                                          string           label,
@@ -97,7 +97,7 @@ private class Boxes.InstallerMedia : GLib.Object {
         return properties;
     }
 
-    public bool is_architecture_compatible (string architecture) {
+    public virtual bool is_architecture_compatible (string architecture) {
         if (os_media == null) // Unknown media
             return true;
 


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