|
|
07c63d |
From 522cca5ac1473405d325fce4fef0d6e0343f6257 Mon Sep 17 00:00:00 2001
|
|
|
07c63d |
From: Frediano Ziglio <freddy77@gmail.com>
|
|
|
07c63d |
Date: Wed, 10 Jun 2020 13:27:36 +0100
|
|
|
07c63d |
Subject: [PATCH] virt-viewer-file-transfer-dialog: Reports detailed errors
|
|
|
07c63d |
|
|
|
07c63d |
Instead of showing just a generic error with a list of files group
|
|
|
07c63d |
files by error and show them.
|
|
|
07c63d |
|
|
|
07c63d |
This solves https://bugzilla.redhat.com/show_bug.cgi?id=1753563
|
|
|
07c63d |
|
|
|
07c63d |
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
|
|
|
07c63d |
---
|
|
|
07c63d |
src/virt-viewer-file-transfer-dialog.c | 47 +++++++++++++++++++++++---
|
|
|
07c63d |
1 file changed, 43 insertions(+), 4 deletions(-)
|
|
|
07c63d |
|
|
|
07c63d |
diff --git a/src/virt-viewer-file-transfer-dialog.c b/src/virt-viewer-file-transfer-dialog.c
|
|
|
07c63d |
index b510d8e..975346f 100644
|
|
|
07c63d |
--- a/src/virt-viewer-file-transfer-dialog.c
|
|
|
07c63d |
+++ b/src/virt-viewer-file-transfer-dialog.c
|
|
|
07c63d |
@@ -188,6 +188,23 @@ error_dialog_response(GtkDialog *dialog,
|
|
|
07c63d |
gtk_widget_destroy(GTK_WIDGET(dialog));
|
|
|
07c63d |
}
|
|
|
07c63d |
|
|
|
07c63d |
+static const gchar*
|
|
|
07c63d |
+file_error_message(GError *err)
|
|
|
07c63d |
+{
|
|
|
07c63d |
+ if (err && err->message) {
|
|
|
07c63d |
+ return err->message;
|
|
|
07c63d |
+ }
|
|
|
07c63d |
+ return _("Unspecified error");
|
|
|
07c63d |
+}
|
|
|
07c63d |
+
|
|
|
07c63d |
+static gint
|
|
|
07c63d |
+compare_file_error(gconstpointer a, gconstpointer b)
|
|
|
07c63d |
+{
|
|
|
07c63d |
+ GError *error_a = g_object_get_data(G_OBJECT(a), "virt-viewer-error");
|
|
|
07c63d |
+ GError *error_b = g_object_get_data(G_OBJECT(b), "virt-viewer-error");
|
|
|
07c63d |
+ return g_strcmp0(file_error_message(error_a), file_error_message(error_b));
|
|
|
07c63d |
+}
|
|
|
07c63d |
+
|
|
|
07c63d |
static gboolean hide_transfer_dialog(gpointer data)
|
|
|
07c63d |
{
|
|
|
07c63d |
VirtViewerFileTransferDialog *self = data;
|
|
|
07c63d |
@@ -202,10 +219,26 @@ static gboolean hide_transfer_dialog(gpointer data)
|
|
|
07c63d |
GString *msg = g_string_new("");
|
|
|
07c63d |
GtkWidget *dialog, *files_label, *scrolled_window, *area;
|
|
|
07c63d |
GtkRequisition files_label_sz;
|
|
|
07c63d |
+ const gchar *last_error = NULL;
|
|
|
07c63d |
+ const gchar *group_separator = "";
|
|
|
07c63d |
+
|
|
|
07c63d |
+ self->priv->failed = g_slist_sort(self->priv->failed, compare_file_error);
|
|
|
07c63d |
|
|
|
07c63d |
for (sl = self->priv->failed; sl != NULL; sl = g_slist_next(sl)) {
|
|
|
07c63d |
SpiceFileTransferTask *failed_task = sl->data;
|
|
|
07c63d |
gchar *filename = spice_file_transfer_task_get_filename(failed_task);
|
|
|
07c63d |
+
|
|
|
07c63d |
+ const gchar *error_message =
|
|
|
07c63d |
+ file_error_message(g_object_get_data(G_OBJECT(failed_task), "virt-viewer-error"));
|
|
|
07c63d |
+ if (g_strcmp0(error_message, last_error) != 0) {
|
|
|
07c63d |
+ // add error message
|
|
|
07c63d |
+ gchar *header = g_markup_printf_escaped("%s%s:", group_separator, error_message);
|
|
|
07c63d |
+ g_string_append(msg, header);
|
|
|
07c63d |
+ g_free(header);
|
|
|
07c63d |
+ last_error = error_message;
|
|
|
07c63d |
+ group_separator = "\n\n";
|
|
|
07c63d |
+ }
|
|
|
07c63d |
+
|
|
|
07c63d |
if (filename == NULL) {
|
|
|
07c63d |
guint id;
|
|
|
07c63d |
|
|
|
07c63d |
@@ -214,15 +247,16 @@ static gboolean hide_transfer_dialog(gpointer data)
|
|
|
07c63d |
filename = g_strdup_printf("(task #%u)", id);
|
|
|
07c63d |
}
|
|
|
07c63d |
|
|
|
07c63d |
- g_string_append_printf(msg, "\n%s", filename);
|
|
|
07c63d |
+ gchar *escaped_filename = g_markup_printf_escaped("\n%s", filename);
|
|
|
07c63d |
+ g_string_append(msg, escaped_filename);
|
|
|
07c63d |
+ g_free(escaped_filename);
|
|
|
07c63d |
g_free(filename);
|
|
|
07c63d |
}
|
|
|
07c63d |
g_slist_free_full(self->priv->failed, g_object_unref);
|
|
|
07c63d |
self->priv->failed = NULL;
|
|
|
07c63d |
|
|
|
07c63d |
dialog = gtk_message_dialog_new(GTK_WINDOW(self), 0, GTK_MESSAGE_ERROR,
|
|
|
07c63d |
- GTK_BUTTONS_OK,
|
|
|
07c63d |
- _("An error caused the following file transfers to fail:"));
|
|
|
07c63d |
+ GTK_BUTTONS_OK, NULL);
|
|
|
07c63d |
gtk_window_set_title(GTK_WINDOW(dialog), "Transfer error");
|
|
|
07c63d |
|
|
|
07c63d |
scrolled_window = gtk_scrolled_window_new(NULL, NULL);
|
|
|
07c63d |
@@ -232,8 +266,9 @@ static gboolean hide_transfer_dialog(gpointer data)
|
|
|
07c63d |
area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
|
|
|
07c63d |
gtk_container_add(GTK_CONTAINER(area), scrolled_window);
|
|
|
07c63d |
|
|
|
07c63d |
- files_label = gtk_label_new(msg->str + 1); /* skip the initial '\n' */
|
|
|
07c63d |
+ files_label = gtk_label_new(NULL);
|
|
|
07c63d |
gtk_label_set_selectable(GTK_LABEL(files_label), TRUE);
|
|
|
07c63d |
+ gtk_label_set_markup(GTK_LABEL(files_label), msg->str);
|
|
|
07c63d |
gtk_container_add(GTK_CONTAINER(scrolled_window), files_label);
|
|
|
07c63d |
|
|
|
07c63d |
g_string_free(msg, TRUE);
|
|
|
07c63d |
@@ -242,6 +277,8 @@ static gboolean hide_transfer_dialog(gpointer data)
|
|
|
07c63d |
|
|
|
07c63d |
/* adjust panel to file_label height */
|
|
|
07c63d |
gtk_widget_get_preferred_size(files_label, NULL, &files_label_sz);
|
|
|
07c63d |
+ gtk_scrolled_window_set_min_content_width(GTK_SCROLLED_WINDOW(scrolled_window),
|
|
|
07c63d |
+ MIN(files_label_sz.width, 500));
|
|
|
07c63d |
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolled_window),
|
|
|
07c63d |
MIN(files_label_sz.height, 170));
|
|
|
07c63d |
}
|
|
|
07c63d |
@@ -256,6 +293,8 @@ static void task_finished(SpiceFileTransferTask *task,
|
|
|
07c63d |
VirtViewerFileTransferDialog *self = VIRT_VIEWER_FILE_TRANSFER_DIALOG(user_data);
|
|
|
07c63d |
|
|
|
07c63d |
if (error && !g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
|
|
07c63d |
+ g_object_set_data_full(G_OBJECT(task), "virt-viewer-error",
|
|
|
07c63d |
+ g_error_copy(error), (GDestroyNotify) g_error_free);
|
|
|
07c63d |
self->priv->failed = g_slist_prepend(self->priv->failed, g_object_ref(task));
|
|
|
07c63d |
g_warning("File transfer task %p failed: %s", task, error->message);
|
|
|
07c63d |
}
|
|
|
07c63d |
--
|
|
|
07c63d |
2.28.0
|
|
|
07c63d |
|