[Spice-devel] [spice-gtk] usb: Add info message when USB dialog is empty

Christophe Fergeau cfergeau at redhat.com
Thu Sep 27 09:01:56 PDT 2012


>From rh bug #804187:
« The redirection dialog can feel a bit strange when there is no device to
redirect.

It could be useful to provide a help message indicating that there is no
device to redirect yet, and that the user can insert a USB device to
redirect, and some related guidance. »

This commit adds a "No USB devices detected" infobar in the USB
dialog below the 'Select USB devices to redirect" label.
Content could probably be improved, but this is a step in the right
direction ;)

This can be tested with
diff --git a/gtk/usb-device-widget.c b/gtk/usb-device-widget.c
index 2261fd6..089b040 100644
--- a/gtk/usb-device-widget.c
+++ b/gtk/usb-device-widget.c
@@ -219,6 +219,11 @@ static GObject *spice_usb_device_widget_constructor(
                      G_CALLBACK(device_error_cb), self);

     devices = spice_usb_device_manager_get_devices(priv->manager);
+    if (devices) {
+        g_ptr_array_unref(devices);
+        devices = NULL;
+    }
+
     if (!devices) {
         spice_usb_device_widget_show_info_bar(self, _("No USB devices detected"),
                                               GTK_MESSAGE_INFO,
---
 gtk/usb-device-widget.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/gtk/usb-device-widget.c b/gtk/usb-device-widget.c
index 3ed81e4..089b040 100644
--- a/gtk/usb-device-widget.c
+++ b/gtk/usb-device-widget.c
@@ -219,8 +219,17 @@ static GObject *spice_usb_device_widget_constructor(
                      G_CALLBACK(device_error_cb), self);
 
     devices = spice_usb_device_manager_get_devices(priv->manager);
-    if (!devices)
+    if (devices) {
+        g_ptr_array_unref(devices);
+        devices = NULL;
+    }
+
+    if (!devices) {
+        spice_usb_device_widget_show_info_bar(self, _("No USB devices detected"),
+                                              GTK_MESSAGE_INFO,
+                                              GTK_STOCK_DIALOG_INFO);
         goto end;
+    }
 
     for (i = 0; i < devices->len; i++)
         device_added_cb(NULL, g_ptr_array_index(devices, i), self);
@@ -508,6 +517,23 @@ static void destroy_widget_by_usb_device(GtkWidget *widget, gpointer user_data)
         gtk_widget_destroy(widget);
 }
 
+static gsize has_usb_devices(SpiceUsbDeviceWidget *self)
+{
+    GList *children;
+    GList *it;
+
+    children = gtk_container_get_children(GTK_CONTAINER(self));
+
+    for (it = children; it != NULL; it = it->next) {
+        if (get_usb_device(it->data) != NULL)
+            break;
+    }
+    if (it == NULL)
+    g_list_free(children);
+
+    return (it != NULL);
+}
+
 static void device_removed_cb(SpiceUsbDeviceManager *manager,
     SpiceUsbDevice *device, gpointer user_data)
 {
@@ -515,8 +541,11 @@ static void device_removed_cb(SpiceUsbDeviceManager *manager,
 
     gtk_container_foreach(GTK_CONTAINER(self),
                           destroy_widget_by_usb_device, device);
-
     spice_usb_device_widget_update_status(self);
+    if (!has_usb_devices(self))
+        spice_usb_device_widget_show_info_bar(self, _("No USB devices detected"),
+                                              GTK_MESSAGE_INFO,
+                                              GTK_STOCK_DIALOG_INFO);
 }
 
 static void set_inactive_by_usb_device(GtkWidget *widget, gpointer user_data)
-- 
1.7.11.4



More information about the Spice-devel mailing list