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

Hans de Goede hdegoede at redhat.com
Mon Oct 1 05:53:54 PDT 2012


Hi,

Looks good now, ack.

Regards,

Hans

On 10/01/2012 12:29 PM, Christophe Fergeau wrote:
>  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 b1bf090..660ea03 100644
> --- a/gtk/usb-device-widget.c
> +++ b/gtk/usb-device-widget.c
> @@ -220,6 +220,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)
>           goto end;
> ---
>   gtk/usb-device-widget.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
>
> diff --git a/gtk/usb-device-widget.c b/gtk/usb-device-widget.c
> index 3ed81e4..8621a5e 100644
> --- a/gtk/usb-device-widget.c
> +++ b/gtk/usb-device-widget.c
> @@ -47,6 +47,7 @@ static void device_removed_cb(SpiceUsbDeviceManager *manager,
>       SpiceUsbDevice *device, gpointer user_data);
>   static void device_error_cb(SpiceUsbDeviceManager *manager,
>       SpiceUsbDevice *device, GError *err, gpointer user_data);
> +static gboolean spice_usb_device_widget_update_status(gpointer user_data);
>
>   /* ------------------------------------------------------------------ */
>   /* gobject glue                                                       */
> @@ -72,6 +73,7 @@ struct _SpiceUsbDeviceWidgetPrivate {
>       SpiceUsbDeviceManager *manager;
>       GtkWidget *info_bar;
>       gchar *err_msg;
> +    gsize device_count;
>   };
>
>   static guint signals[LAST_SIGNAL] = { 0, };
> @@ -228,6 +230,8 @@ static GObject *spice_usb_device_widget_constructor(
>       g_ptr_array_unref(devices);
>
>   end:
> +    spice_usb_device_widget_update_status(self);
> +
>       return obj;
>   }
>
> @@ -363,6 +367,7 @@ static void check_can_redirect(GtkWidget *widget, gpointer user_data)
>       if (!device)
>           return; /* Non device widget, ie the info_bar */
>
> +    priv->device_count++;
>       can_redirect = spice_usb_device_manager_can_redirect_device(priv->manager,
>                                                                   device, &err);
>       gtk_widget_set_sensitive(widget, can_redirect);
> @@ -391,6 +396,7 @@ static gboolean spice_usb_device_widget_update_status(gpointer user_data)
>       SpiceUsbDeviceWidget *self = SPICE_USB_DEVICE_WIDGET(user_data);
>       SpiceUsbDeviceWidgetPrivate *priv = self->priv;
>
> +    priv->device_count = 0;
>       gtk_container_foreach(GTK_CONTAINER(self), check_can_redirect, self);
>
>       if (priv->err_msg) {
> @@ -402,6 +408,11 @@ static gboolean spice_usb_device_widget_update_status(gpointer user_data)
>       } else {
>           spice_usb_device_widget_hide_info_bar(self);
>       }
> +
> +    if (priv->device_count == 0)
> +        spice_usb_device_widget_show_info_bar(self, _("No USB devices detected"),
> +                                              GTK_MESSAGE_INFO,
> +                                              GTK_STOCK_DIALOG_INFO);
>       return FALSE;
>   }
>
>


More information about the Spice-devel mailing list