[gnome-boxes] spice-display: Clean-up USB redir properties code
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] spice-display: Clean-up USB redir properties code
- Date: Sat, 8 Nov 2014 21:47:52 +0000 (UTC)
commit 29c042d3ccbe139c3913e70f7d92ddd0e1a68ab2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sat Nov 8 21:44:55 2014 +0000
spice-display: Clean-up USB redir properties code
Lets make the code a bit more readable by taking large blocks of code
out into the outer scope and therefore making it less indented.
src/spice-display.vala | 105 ++++++++++++++++++++++++------------------------
1 files changed, 52 insertions(+), 53 deletions(-)
---
diff --git a/src/spice-display.vala b/src/spice-display.vala
index 61f639e..defd785 100644
--- a/src/spice-display.vala
+++ b/src/spice-display.vala
@@ -280,72 +280,71 @@ private class Boxes.SpiceDisplay: Boxes.Display {
break;
case PropertiesPage.DEVICES:
- if (!(PropertyCreationFlag.NO_USB in flags) && Config.HAVE_USBREDIR) {
- if (connected) {
- bool found_dev = false;
- Boxes.Property usb_property = null;
- try {
- var manager = UsbDeviceManager.get (session);
- var devs = manager.get_devices ();
- devs.sort ( (a, b) => {
- string str_a = a.get_description (" %1$s %2$s");
- string str_b = b.get_description (" %1$s %2$s");
-
- return strcmp (str_a, str_b);
- });
- 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)
- usb_property = add_property (ref list, _("USB devices"), new Gtk.Label (""));
- found_dev = true;
- usb_property = 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;
- var device_desc = dev.get_description ("%1$s %2$s");
- var box_name = get_box_name ();
- var msg = _("Redirection of USB device '%s' for '%s' failed");
- got_error (msg.printf (device_desc, box_name));
- debug ("Error connecting %s to %s: %s",
- device_desc,
- box_name, err.message);
- }
- });
- } else {
- manager.disconnect_device (dev);
+ if (PropertyCreationFlag.NO_USB in flags || !Config.HAVE_USBREDIR|| !connected)
+ break;
+
+ bool found_dev = false;
+ Boxes.Property usb_property = null;
+ try {
+ var manager = UsbDeviceManager.get (session);
+ var devs = manager.get_devices ();
+ devs.sort ( (a, b) => {
+ string str_a = a.get_description (" %1$s %2$s");
+ string str_b = b.get_description (" %1$s %2$s");
+
+ return strcmp (str_a, str_b);
+ });
+ 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)
+ usb_property = add_property (ref list, _("USB devices"), new Gtk.Label (""));
+ found_dev = true;
+ usb_property = 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;
+ var device_desc = dev.get_description ("%1$s %2$s");
+ var box_name = get_box_name ();
+ var msg = _("Redirection of USB device '%s' for '%s' failed");
+ got_error (msg.printf (device_desc, box_name));
+ debug ("Error connecting %s to %s: %s",
+ device_desc,
+ box_name, err.message);
}
});
+ } else {
+ manager.disconnect_device (dev);
}
+ });
+ }
- if (usb_property == null)
- break;
+ if (usb_property == null)
+ break;
- manager.device_added.connect ((manager, dev) => {
- usb_property.refresh_properties ();
+ manager.device_added.connect ((manager, dev) => {
+ usb_property.refresh_properties ();
});
- manager.device_removed.connect ((manager, dev) => {
- Idle.add (() => {
+ manager.device_removed.connect ((manager, dev) => {
+ Idle.add (() => {
// FIXME: This is done in an idle to workaround a bug in spice-gtk 0.18
where calling
// UsbDeviceManager.get_devices() from the "device-removed" signal callback
will
// return a list of devices which still contains the removed device.
// This is fixed in spice-gtk by 09124ecc50.
usb_property.refresh_properties ();
return false;
- });
+ });
});
- } catch (GLib.Error error) {
- }
- }
+ } catch (GLib.Error error) {
}
break;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]