[gnome-boxes] Add support for changing the CDROM iso



commit f34ce3b8c40d4d579743b8f9c0ac39230531b1d4
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Nov 13 19:34:03 2012 +0100

    Add support for changing the CDROM iso
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686778

 src/libvirt-machine.vala |   78 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 1a42e5e..e11efaa 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -456,6 +456,84 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             break;
 
         case PropertiesPage.DEVICES:
+            foreach (var device_config in domain_config.get_devices ()) {
+                if (!(device_config is GVirConfig.DomainDisk))
+                    continue;
+                var disk_config = device_config as GVirConfig.DomainDisk;
+                var disk_type = disk_config.get_guest_device_type ();
+                if (disk_type == GVirConfig.DomainDiskGuestDeviceType.CDROM) {
+                    var grid = new Gtk.Grid ();
+                    grid.set_orientation (Gtk.Orientation.HORIZONTAL);
+                    grid.set_column_spacing (12);
+
+                    var label = new Gtk.Label ("");
+                    grid.add (label);
+
+                    var source = disk_config.get_source ();
+                    bool empty = (source == null || source == "");
+
+                    var button_label = new Gtk.Label ("");
+                    var button = new Gtk.Button ();
+                    button.add (button_label);
+
+                    grid.add (button);
+
+                    if (empty) {
+                        // Translators: This is the text on the button to select an iso for the cd
+                        button_label.set_text (_("Select"));
+                        // Translators: empty is listed as the filename for a non-mounted CD
+                        label.set_markup (Markup.printf_escaped ("<i>%s</i>", _("empty")));
+                    } else {
+                        // Translators: Remove is the label on the button to remove an iso from a cdrom drive
+                        button_label.set_text (_("Remove"));
+                        label.set_text (get_utf8_basename (source));
+                    }
+
+                    button.clicked.connect ( () => {
+                        if (empty) {
+                            var dialog = new Gtk.FileChooserDialog (_("Select a device or ISO file"),
+                                                                    App.app.window,
+                                                                    Gtk.FileChooserAction.OPEN,
+                                                                    Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
+                                                                    Gtk.Stock.OPEN, Gtk.ResponseType.ACCEPT);
+                            dialog.modal = true;
+                            dialog.show_hidden = false;
+                            dialog.local_only = true;
+                            dialog.filter = new Gtk.FileFilter ();
+                            dialog.filter.add_mime_type ("application/x-cd-image");
+                            dialog.response.connect ( (response) => {
+                                if (response == Gtk.ResponseType.ACCEPT) {
+                                    var path = dialog.get_filename ();
+                                    disk_config.set_source (path);
+                                    try {
+                                        domain.update_device (disk_config, DomainUpdateDeviceFlags.CURRENT);
+                                        button_label.set_text (_("Remove"));
+                                        label.set_text (get_utf8_basename (path));
+                                        empty = false;
+                                    } catch (GLib.Error e) {
+                                        got_error (e.message);
+                                    }
+                                }
+                                dialog.destroy ();
+                            });
+                            dialog.show_all ();
+                        } else {
+                            disk_config.set_source ("");
+                            try {
+                                domain.update_device (disk_config, DomainUpdateDeviceFlags.CURRENT);
+                                empty = true;
+                                button_label.set_text (_("Select"));
+                                label.set_markup (Markup.printf_escaped ("<i>%s</i>", _("empty")));
+                            } catch (GLib.Error e) {
+                                got_error (e.message);
+                            }
+                        }
+                    });
+
+                    add_property (ref list, _("CD/DVD"), grid);
+                }
+            }
+
             bool has_usb_redir = false;
             // We look at the INACTIVE config here, because we want to show the usb
             // widgetry if usb has been added already but we have not rebooted



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