[gnome-boxes] Add support for manual usb redirection in properties view



commit c0cc69b3edb2fa95fbd6948f0226bd8bd76c119a
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Nov 9 16:51:26 2012 +0100

    Add support for manual usb redirection in properties view
    
    This is not designed in the mockups, but at least it has the
    basic functinallity there for now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672268

 src/spice-display.vala |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 3455660..528d5d3 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -240,6 +240,43 @@ private class Boxes.SpiceDisplay: Boxes.Display {
                                            BindingFlags.BIDIRECTIONAL | BindingFlags.SYNC_CREATE);
                 toggle.halign =  Gtk.Align.START;
                 add_property (ref list, _("Redirect new USB devices"), toggle);
+
+                if (connected) {
+                    bool found_dev = false;
+                    try {
+                        var manager = UsbDeviceManager.get (session);
+                        var devs = manager.get_devices ();
+                        for (int i = 0; i < devs.length; i++) {
+                            var dev = devs[i];
+
+                            var dev_toggle = new Gtk.Switch ();
+                            dev_toggle.halign =  Gtk.Align.START;
+
+                            if (!found_dev)
+                                add_property (ref list, "USB devices", new Gtk.Label (""));
+                            found_dev = true;
+                            add_property (ref list, dev.get_description ("    %1$s %2$s"), dev_toggle);
+                            dev_toggle.active = manager.is_device_connected (dev);
+
+                            dev_toggle.notify["active"].connect ( () => {
+                                if (dev_toggle.active) {
+                                    manager.connect_device_async.begin (dev, null, (obj, res) => {
+                                        try {
+                                            manager.connect_device_async.end (res);
+                                        } catch (GLib.Error err) {
+                                            dev_toggle.active = false;
+                                            got_error (_("Error connecting %s: %s").printf (dev.get_description ("%1$s %2$s"),
+                                                                                            err.message));
+                                        }
+                                    });
+                                } else {
+                                    manager.disconnect_device (dev);
+                                }
+                            });
+                        }
+                    } catch (GLib.Error error) {
+                    }
+                }
             }
             break;
         }



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