[gnome-boxes] installer: Clean-up supported devices related code
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] installer: Clean-up supported devices related code
- Date: Fri, 1 Mar 2013 15:55:03 +0000 (UTC)
commit e69add66a4c7f07c133e543eaa9e5d11827525a7
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Feb 28 15:37:16 2013 +0200
installer: Clean-up supported devices related code
Maintain a single list for all supported devices, both for devices
supported by OS out of the box and ones added through additional drivers
by us.
https://bugzilla.gnome.org/show_bug.cgi?id=694872
src/installer-media.vala | 17 +++++++++++++++--
src/unattended-installer.vala | 39 +++++++--------------------------------
src/util-app.vala | 14 ++++++++------
src/vm-configurator.vala | 4 ++--
4 files changed, 32 insertions(+), 42 deletions(-)
---
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 69d3888..1966cb4 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -13,13 +13,16 @@ private class Boxes.InstallerMedia : GLib.Object {
public string mount_point;
public bool from_image;
+ public Osinfo.DeviceList supported_devices;
+
// FIXME: Currently this information is always unknown so practically we never show any progress for
installations.
public virtual uint64 installed_size { get { return 0; } }
public virtual bool need_user_input_for_vm_creation { get { return false; } }
public virtual bool ready_to_create { get { return true; } }
- public virtual bool supports_virtio_disk {
+
+ public bool supports_virtio_disk {
get {
- return (get_os_device_by_prop (os, DEVICE_PROP_NAME, "virtio-block") != null);
+ return (find_device_by_prop (supported_devices, DEVICE_PROP_NAME, "virtio-block") != null);
}
}
@@ -37,6 +40,7 @@ private class Boxes.InstallerMedia : GLib.Object {
from_image = true;
setup_label (label);
+ init_supported_devices ();
}
public async InstallerMedia.for_path (string path,
@@ -54,6 +58,7 @@ private class Boxes.InstallerMedia : GLib.Object {
}
setup_label ();
+ init_supported_devices ();
// FIXME: these values could be made editable somehow
var architecture = (os_media != null) ? os_media.architecture : "i686";
@@ -112,6 +117,14 @@ private class Boxes.InstallerMedia : GLib.Object {
domain.add_device (disk);
}
+ private void init_supported_devices () {
+ if (os != null) {
+ var os_devices = os.get_all_devices (null) as Osinfo.List;
+ supported_devices = os_devices.new_copy () as Osinfo.DeviceList;
+ } else
+ supported_devices = new Osinfo.DeviceList ();
+ }
+
private async GUdev.Device? get_device_from_path (string path, Client client, Cancellable? cancellable) {
try {
var mount_dir = File.new_for_commandline_arg (path);
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 23c36bb..a430b9c 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -24,12 +24,6 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
}
}
- public override bool supports_virtio_disk {
- get {
- return base.supports_virtio_disk || has_viostor_drivers;
- }
- }
-
public bool express_install {
get { return express_toggle.active; }
}
@@ -62,7 +56,6 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
public InstallConfig config;
public InstallScriptList scripts;
- private bool has_viostor_drivers;
private string? product_key_format;
private GLib.List<UnattendedFile> unattended_files;
@@ -116,6 +109,7 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
from_image = media.from_image;
mount_point = media.mount_point;
resources = media.resources;
+ supported_devices = media.supported_devices;
this.scripts = scripts;
config = new InstallConfig ("http://live.gnome.org/Boxes/unattended");
@@ -663,22 +657,7 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
if (drivers.length () != 0 && scripts.length () != 0) {
var drivers_progress = progress.add_child_activity (0.5);
- var setup_drivers = yield setup_drivers_from_list (drivers,
- drivers_progress,
- add_unattended_file,
- cancellable);
-
- foreach (var driver in setup_drivers) {
- foreach (var d in driver.get_devices ().get_elements ()) {
- var device = d as Device;
-
- if (device.get_name () == "virtio-block") {
- has_viostor_drivers = true;
-
- break;
- }
- }
- }
+ yield setup_drivers_from_list (drivers, drivers_progress, add_unattended_file, cancellable);
} else
progress.progress = 0.5;
@@ -692,27 +671,23 @@ private class Boxes.UnattendedInstaller: InstallerMedia {
progress.progress = 1.0;
}
- private async GLib.List<DeviceDriver> setup_drivers_from_list
- (GLib.List<DeviceDriver> drivers,
- ActivityProgress progress,
- AddUnattendedFileFunc add_func,
- Cancellable? cancellable = null) {
- var setup_drivers = new GLib.List<DeviceDriver> ();
+ private async void setup_drivers_from_list (GLib.List<DeviceDriver> drivers,
+ ActivityProgress progress,
+ AddUnattendedFileFunc add_func,
+ Cancellable? cancellable = null) {
var driver_progress_scale = 1d / drivers.length ();
foreach (var driver in drivers) {
var driver_progress = progress.add_child_activity (driver_progress_scale);
try {
yield setup_driver (driver, driver_progress, add_func, cancellable);
- setup_drivers.append (driver);
+ supported_devices.add_all (driver.get_devices ());
} catch (GLib.Error e) {
debug ("Failed to make use of drivers at '%s': %s", driver.get_location (), e.message);
} finally {
driver_progress.progress = 1.0; // Ensure progress reaches 100%
}
}
-
- return setup_drivers;
}
private async void setup_driver (DeviceDriver driver,
diff --git a/src/util-app.vala b/src/util-app.vala
index 89949f5..83594d0 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -144,13 +144,15 @@ namespace Boxes {
container.remove_child (actor);
}
- public Osinfo.Device? get_os_device_by_prop (Osinfo.Os? os, string prop_name, string prop_value) {
- if (os == null)
- return null;
-
- var devices = os.get_devices_by_property (prop_name, prop_value, true);
+ public Osinfo.Device? find_device_by_prop (Osinfo.DeviceList devices, string prop_name, string
prop_value) {
+ var filter = new Osinfo.Filter ();
+ filter.add_constraint (prop_name, prop_value);
- return (devices.get_length () > 0) ? devices.get_nth (0) as Osinfo.Device : null;
+ var filtered = (devices as Osinfo.List).new_filtered (filter);
+ if (filtered.get_length () > 0)
+ return filtered.get_nth (0) as Osinfo.Device;
+ else
+ return null;
}
public Gtk.Image get_os_logo (Osinfo.Os? os, int size) {
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 3764eaa..6ab335b 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -244,7 +244,7 @@ private class Boxes.VMConfigurator {
private static void set_video_config (Domain domain, InstallerMedia install_media) {
var video = new DomainVideo ();
- var device = get_os_device_by_prop (install_media.os, DEVICE_PROP_CLASS, "video");
+ var device = find_device_by_prop (install_media.supported_devices, DEVICE_PROP_CLASS, "video");
var model = (device != null)? get_enum_value (device.get_name (), typeof (DomainVideoModel)) :
DomainVideoModel.QXL;
return_if_fail (model != -1);
@@ -255,7 +255,7 @@ private class Boxes.VMConfigurator {
private static void set_sound_config (Domain domain, InstallerMedia install_media) {
var sound = new DomainSound ();
- var device = get_os_device_by_prop (install_media.os, DEVICE_PROP_CLASS, "audio");
+ var device = find_device_by_prop (install_media.supported_devices, DEVICE_PROP_CLASS, "audio");
var model = (device != null)? get_enum_value (device.get_name (), typeof (DomainSoundModel)) :
DomainSoundModel.AC97;
return_if_fail (model != -1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]