summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Pouget <kpouget@redhat.com>2019-08-01 17:31:20 +0200
committerVictor Toso <me@victortoso.com>2019-08-08 15:54:46 +0200
commita2a372ac2d33893cf1bc76aa0dc0612ebc950d77 (patch)
tree9b7ba24815b6605c02f5a68b12b4042dbf4e9d16
parent898f972d534480b35f5a74aa41d0e9abc94f302f (diff)
virt-viewer-file-transfer-dialog: improve error message
This patch improves the error shown to the user when a file transfer fails. The previous behavior was to create a simple message dialog box, with the error description and the full list of the files that failed to be transferred. When the list of files was long, the dialog box would grow bigger than the screen. Now, the file list is inserted inside a scrollable widget, whose height is limited to 170px. NB: these two calls would be more adapted, but they require GTK >= 3.22: > gtk_scrolled_window_set_max_content_height(GTK_SCROLLED_WINDOW(scrolled_window), 170); > gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolled_window), TRUE); Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1496356 Signed-off-by: Kevin Pouget <kpouget@redhat.com> Acked-by: Victor Toso <victortoso@redhat.com>
-rw-r--r--src/virt-viewer-file-transfer-dialog.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/virt-viewer-file-transfer-dialog.c b/src/virt-viewer-file-transfer-dialog.c
index a82d01a..b510d8e 100644
--- a/src/virt-viewer-file-transfer-dialog.c
+++ b/src/virt-viewer-file-transfer-dialog.c
@@ -200,7 +200,8 @@ static gboolean hide_transfer_dialog(gpointer data)
if (self->priv->failed) {
GSList *sl;
GString *msg = g_string_new("");
- GtkWidget *dialog;
+ GtkWidget *dialog, *files_label, *scrolled_window, *area;
+ GtkRequisition files_label_sz;
for (sl = self->priv->failed; sl != NULL; sl = g_slist_next(sl)) {
SpiceFileTransferTask *failed_task = sl->data;
@@ -221,11 +222,28 @@ static gboolean hide_transfer_dialog(gpointer data)
dialog = gtk_message_dialog_new(GTK_WINDOW(self), 0, GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
- _("An error caused the following file transfers to fail:%s"),
- msg->str);
+ _("An error caused the following file transfers to fail:"));
+ gtk_window_set_title(GTK_WINDOW(dialog), "Transfer error");
+
+ scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+ area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(dialog));
+ gtk_container_add(GTK_CONTAINER(area), scrolled_window);
+
+ files_label = gtk_label_new(msg->str + 1); /* skip the initial '\n' */
+ gtk_label_set_selectable(GTK_LABEL(files_label), TRUE);
+ gtk_container_add(GTK_CONTAINER(scrolled_window), files_label);
+
g_string_free(msg, TRUE);
g_signal_connect(dialog, "response", G_CALLBACK(error_dialog_response), NULL);
- gtk_widget_show(dialog);
+ gtk_widget_show_all(dialog);
+
+ /* adjust panel to file_label height */
+ gtk_widget_get_preferred_size(files_label, NULL, &files_label_sz);
+ gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrolled_window),
+ MIN(files_label_sz.height, 170));
}
return G_SOURCE_REMOVE;