From: Alexander Nezhinsky <anezhins@xxxxxxxxxx> This is common function for adding an error status message. If an old message exists, checks if the new message is not already contained in the old one. The new message is ignored if it is, added if it's not. New message string should be dynamically allocated, it's always g_free-ed. Signed-off-by: Alexander Nezhinsky <anezhins@xxxxxxxxxx> --- src/usb-device-widget.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/usb-device-widget.c b/src/usb-device-widget.c index 55a9687..6e7a267 100644 --- a/src/usb-device-widget.c +++ b/src/usb-device-widget.c @@ -131,6 +131,25 @@ static void spice_usb_device_widget_set_property(GObject *gobject, } } +static void spice_usb_device_widget_add_err_msg(SpiceUsbDeviceWidget *self, + gchar *new_err_msg) +{ + SpiceUsbDeviceWidgetPrivate *priv = self->priv; + + if (priv->err_msg) { + /* Append the new error message to err_msg, + but only if it's *not* already there! */ + if (!strstr(priv->err_msg, new_err_msg)) { + gchar *old_err_msg = priv->err_msg; + priv->err_msg = g_strdup_printf("%s\n%s", old_err_msg, new_err_msg); + g_free(old_err_msg); + g_free(new_err_msg); + } + } else { + priv->err_msg = new_err_msg; + } +} + static void spice_usb_device_widget_hide_info_bar(SpiceUsbDeviceWidget *self) { SpiceUsbDeviceWidgetPrivate *priv = self->priv; @@ -359,19 +378,10 @@ static void check_can_redirect(GtkWidget *widget, gpointer user_data) } else { can_redirect = spice_usb_device_manager_can_redirect_device(priv->manager, device, &err); - /* If we cannot redirect this device, append the error message to - err_msg, but only if it is *not* already there! */ + if (!can_redirect) { - if (priv->err_msg) { - if (!strstr(priv->err_msg, err->message)) { - gchar *old_err_msg = priv->err_msg; - priv->err_msg = g_strdup_printf("%s\n%s", priv->err_msg, - err->message); - g_free(old_err_msg); - } - } else { - priv->err_msg = g_strdup(err->message); - } + gchar *err_msg = g_strdup_printf("Can't redirect: %s", err->message); + spice_usb_device_widget_add_err_msg(self, err_msg); } g_clear_error(&err); } -- 2.20.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel