[Spice-devel] [PATCH v2 3/6] UsbWidget update widget on redirection flow

Christophe Fergeau cfergeau at redhat.com
Tue Jul 7 03:52:28 PDT 2015


On Mon, Jul 06, 2015 at 08:59:03PM +0300, Kirill Moizik wrote:
> expose functions to control usb widget sensitivity during  redirection flow
> 
> Signed-off-by: Kirill Moizik <kmoizik at redhat.com>
> ---
>  src/usb-device-widget.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 48 insertions(+)
> 
> diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c
> index 1ec30e3..72f3b34 100644
> --- a/src/usb-device-widget.c
> +++ b/src/usb-device-widget.c
> @@ -52,6 +52,11 @@ static gboolean spice_usb_device_widget_update_status(gpointer user_data);
>  /* ------------------------------------------------------------------ */
>  /* gobject glue                                                       */
>  
> +
> +#ifdef USE_USBREDIR
> +static void set_sensitive_all(GtkWidget *widget, gpointer user_data);
> +#endif
> +
>  #define SPICE_USB_DEVICE_WIDGET_GET_PRIVATE(obj) \
>      (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_USB_DEVICE_WIDGET, \
>                                   SpiceUsbDeviceWidgetPrivate))
> @@ -425,6 +430,29 @@ typedef struct _connect_cb_data {
>      SpiceUsbDeviceWidget *self;
>  } connect_cb_data;
>  
> +static void set_redirecting(SpiceUsbDeviceWidget *self, gboolean val)
> +{
> +#ifdef USE_USBREDIR
> +    g_object_set(self->priv->manager,"redirecting", val, NULL);
> +#ifndef USE_LIBUSB_HOTPLUG
> +    spice_g_udev_set_redirecting(val);
> +#endif
> +    gboolean sensitive = !val;
> +    if (val == TRUE) {
> +        spice_usb_device_widget_show_info_bar(self, _("Redirecting Usb Device"),
> +                                     GTK_MESSAGE_INFO,
> +                                     GTK_STOCK_DIALOG_INFO);
> +    } else {
> +#ifndef USE_LIBUSB_HOTPLUG
> +        spice_g_udev_handle_device_change();
> +#endif
> +        spice_usb_device_widget_hide_info_bar(self);
> +    }
> +    gtk_container_foreach(GTK_CONTAINER(self),
> +                          set_sensitive_all, (gpointer) &sensitive);
> +#endif
> +}
> +

I think the overall code would be more readable with 2 separate
functions,
static void spice_usb_device_manager_redirecting_start(SpiceUsbDeviceWidget *self);
static void spice_usb_device_manager_redirecting_end(SpiceUsbDeviceWidget *self);
(or similar names)

>  static void connect_cb(GObject *gobject, GAsyncResult *res, gpointer user_data)
>  {
>      SpiceUsbDeviceManager *manager = SPICE_USB_DEVICE_MANAGER(gobject);
> @@ -435,6 +463,7 @@ static void connect_cb(GObject *gobject, GAsyncResult *res, gpointer user_data)
>      GError *err = NULL;
>      gchar *desc;
>  
> +    set_redirecting (self,FALSE);

space before comma


>      spice_usb_device_manager_connect_device_finish(manager, res, &err);
>      if (err) {
>          device = g_object_get_data(G_OBJECT(data->check), "usb-device");
> @@ -502,6 +531,10 @@ static void device_added_cb(SpiceUsbDeviceManager *manager,
>                                                       device))
>          gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), TRUE);
>  
> +
> +    if (redirecting) {
> +        gtk_widget_set_sensitive(check, FALSE);
> +    }

missing 'redirecting' declaration (it's done in one of the next
commits). However, have you tried having the 'redirecting' check only in
check_can_redirect() and get rid of set_sensitive_all(), and the early
exit in spice_usb_device_widget_update_status() ? this would fit better
in the existing code.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20150707/5b5d77bc/attachment.sig>


More information about the Spice-devel mailing list