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

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