[gimp] plug-ins: cleanups in screenshot



commit fac99b6a18e7bec2659b5c3dc556826c4a81301b
Author: Michael Natterer <mitch gimp org>
Date:   Wed Mar 30 21:03:00 2016 +0200

    plug-ins: cleanups in screenshot
    
    - only open the temp PNG if the screenshot didn't fail
    - remove the temp file

 plug-ins/screenshot/screenshot-gnome-shell.c |    8 ++++-
 plug-ins/screenshot/screenshot-osx.c         |   41 +++++++++++++++++--------
 2 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/plug-ins/screenshot/screenshot-gnome-shell.c b/plug-ins/screenshot/screenshot-gnome-shell.c
index 7f4ce87..9d65da7 100644
--- a/plug-ins/screenshot/screenshot-gnome-shell.c
+++ b/plug-ins/screenshot/screenshot-gnome-shell.c
@@ -22,6 +22,9 @@
 
 #include "config.h"
 
+#include <glib.h>
+#include <glib/gstdio.h> /* g_unlink() */
+
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
@@ -67,7 +70,7 @@ screenshot_gnome_shell_shoot (ScreenshotValues *shootvals,
   if (shootvals->select_delay > 0)
     screenshot_delay (shootvals->select_delay);
 
-  filename = g_strdup ("/tmp/gimp-screenshot.png");
+  filename = gimp_temp_name ("png");
 
   switch (shootvals->shoot_type)
     {
@@ -131,10 +134,13 @@ screenshot_gnome_shell_shoot (ScreenshotValues *shootvals,
                                   filename, filename);
       gimp_image_set_filename (*image_ID, "screenshot.png");
 
+      g_unlink (filename);
       g_free (filename);
 
       return GIMP_PDB_SUCCESS;
     }
 
+  g_free (filename);
+
   return GIMP_PDB_EXECUTION_ERROR;
 }
diff --git a/plug-ins/screenshot/screenshot-osx.c b/plug-ins/screenshot/screenshot-osx.c
index 9042aeb..36cf7eb 100644
--- a/plug-ins/screenshot/screenshot-osx.c
+++ b/plug-ins/screenshot/screenshot-osx.c
@@ -27,6 +27,9 @@
 #include <stdlib.h> /* for system() on OSX */
 #include <string.h>
 
+#include <glib.h>
+#include <glib/gstdio.h> /* g_unlink() */
+
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
@@ -37,7 +40,7 @@
 /*
  * Mac OS X uses a rootless X server. This won't let us use
  * gdk_pixbuf_get_from_drawable() and similar function on the root
- * window to get the entire screen contents. With a nytive OS X build
+ * window to get the entire screen contents. With a native OS X build
  * we have to do this without X as well.
  *
  * Since Mac OS X 10.2 a system utility for screencapturing is
@@ -71,10 +74,11 @@ screenshot_osx_shoot (ScreenshotValues *shootvals,
                       GdkScreen        *screen,
                       gint32           *image_ID)
 {
-  gchar *mode    = " ";
-  gchar *delay   = NULL;
-  gchar *cursor  = " ";
-  gchar *command = NULL;
+  const gchar *mode    = " ";
+  const gchar *cursor  = " ";
+  gchar       *delay   = NULL;
+  gchar       *filename;
+  gchar       *command = NULL;
 
   switch (shootvals->shoot_type)
     {
@@ -101,24 +105,35 @@ screenshot_osx_shoot (ScreenshotValues *shootvals,
   if (shootvals->show_cursor)
     cursor = "-C";
 
+  filename = gimp_temp_name ("png");
+
   command = g_strjoin (" ",
                        "/usr/sbin/screencapture",
                        mode,
                        cursor,
                        delay,
-                       "/tmp/screenshot.png",
+                       filename,
                        NULL);
 
-  system ((const char *) command);
-
-  g_free (command);
   g_free (delay);
 
-  *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
-                              "/tmp/screenshot.png", "/tmp/screenshot.png");
-  gimp_image_set_filename (*image_ID, "screenshot.png");
+  if (system ((const char *) command) == EXIT_SUCCESS)
+    {
+      *image_ID = gimp_file_load (GIMP_RUN_NONINTERACTIVE,
+                                  filename, filename);
+      gimp_image_set_filename (*image_ID, "screenshot.png");
+
+      g_unlink (filename);
+      g_free (filename);
+      g_free (command);
+
+      return GIMP_PDB_SUCCESS;
+   }
+
+  g_free (command);
+  g_free (filename);
 
-  return GIMP_PDB_SUCCESS;
+  return GIMP_PDB_EXECUTION_ERROR;
 }
 
 #endif /* PLATFORM_OSX */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]