Blame SOURCES/0044-Report-errors-when-saving-screenshot.patch

48c875
From e327a522719e5bc2237a3e8c4064e40b41fb9d15 Mon Sep 17 00:00:00 2001
48c875
From: Jonathon Jongsma <jjongsma@redhat.com>
48c875
Date: Mon, 17 Jul 2017 16:15:12 -0500
48c875
Subject: [PATCH] Report errors when saving screenshot
48c875
48c875
Currently, the user gets no feedback if the screenshot fails (e.g. if
48c875
they don't have permission to write in the chosen directory, etc). This
48c875
patch adds a simple dialog showing the error message when a screenshot
48c875
fails.
48c875
---
48c875
 src/virt-viewer-window.c | 24 ++++++++++++++++--------
48c875
 1 file changed, 16 insertions(+), 8 deletions(-)
48c875
48c875
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
48c875
index ef40ec7..41794a6 100644
48c875
--- a/src/virt-viewer-window.c
48c875
+++ b/src/virt-viewer-window.c
48c875
@@ -936,34 +936,37 @@ static GdkPixbufFormat *get_image_format(const char *filename)
48c875
     return g_hash_table_lookup(image_formats_once.retval, ext);
48c875
 }
48c875
 
48c875
-static void
48c875
+static gboolean
48c875
 virt_viewer_window_save_screenshot(VirtViewerWindow *self,
48c875
-                                   const char *file)
48c875
+                                   const char *file,
48c875
+                                   GError **error)
48c875
 {
48c875
     VirtViewerWindowPrivate *priv = self->priv;
48c875
     GdkPixbuf *pix = virt_viewer_display_get_pixbuf(VIRT_VIEWER_DISPLAY(priv->display));
48c875
     GdkPixbufFormat *format = get_image_format(file);
48c875
+    gboolean result;
48c875
 
48c875
     if (format == NULL) {
48c875
         g_debug("unknown file extension, falling back to png");
48c875
         if (!g_str_has_suffix(file, ".png")) {
48c875
             char *png_filename;
48c875
             png_filename = g_strconcat(file, ".png", NULL);
48c875
-            gdk_pixbuf_save(pix, png_filename, "png", NULL,
48c875
-                            "tEXt::Generator App", PACKAGE, NULL);
48c875
+            result = gdk_pixbuf_save(pix, png_filename, "png", error,
48c875
+                                     "tEXt::Generator App", PACKAGE, NULL);
48c875
             g_free(png_filename);
48c875
         } else {
48c875
-            gdk_pixbuf_save(pix, file, "png", NULL,
48c875
-                            "tEXt::Generator App", PACKAGE, NULL);
48c875
+            result = gdk_pixbuf_save(pix, file, "png", error,
48c875
+                                     "tEXt::Generator App", PACKAGE, NULL);
48c875
         }
48c875
     } else {
48c875
         char *type = gdk_pixbuf_format_get_name(format);
48c875
         g_debug("saving to %s", type);
48c875
-        gdk_pixbuf_save(pix, file, type, NULL, NULL);
48c875
+        result = gdk_pixbuf_save(pix, file, type, error, NULL);
48c875
         g_free(type);
48c875
     }
48c875
 
48c875
     g_object_unref(pix);
48c875
+    return result;
48c875
 }
48c875
 
48c875
 G_MODULE_EXPORT void
48c875
@@ -992,9 +995,14 @@ virt_viewer_window_menu_file_screenshot(GtkWidget *menu G_GNUC_UNUSED,
48c875
 
48c875
     if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
48c875
         char *filename;
48c875
+        GError *error = NULL;
48c875
 
48c875
         filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (dialog));
48c875
-        virt_viewer_window_save_screenshot(self, filename);
48c875
+        if (!virt_viewer_window_save_screenshot(self, filename, &error)) {
48c875
+            virt_viewer_app_simple_message_dialog(self->priv->app,
48c875
+                                                  error->message);
48c875
+            g_error_free(error);
48c875
+        }
48c875
         g_free(filename);
48c875
     }
48c875
 
48c875
-- 
48c875
2.13.6
48c875