gnome-utils r8031 - trunk/gnome-screenshot



Author: cosimoc
Date: Thu Aug 28 19:02:43 2008
New Revision: 8031
URL: http://svn.gnome.org/viewvc/gnome-utils?rev=8031&view=rev

Log:
2008-08-28  Cosimo Cecchi  <cosimoc gnome org>

	* gnome-screenshot.c: (finish_prepare_screenshot),
	(check_file_done), (try_check_file), (find_current_window),
	(prepare_screenshot):
	* screenshot-save.c: (screenshot_sanitize_filename):
	Make guessing screenshot filename from window title work again
	(#549736).


Modified:
   trunk/gnome-screenshot/ChangeLog
   trunk/gnome-screenshot/gnome-screenshot.c
   trunk/gnome-screenshot/screenshot-save.c

Modified: trunk/gnome-screenshot/gnome-screenshot.c
==============================================================================
--- trunk/gnome-screenshot/gnome-screenshot.c	(original)
+++ trunk/gnome-screenshot/gnome-screenshot.c	Thu Aug 28 19:02:43 2008
@@ -86,6 +86,7 @@
   char *retval;
   int iteration;
   TestType type;
+  GdkWindow *window;
 } AsyncExistenceJob;
 
 static GdkPixbuf *screenshot = NULL;
@@ -699,36 +700,9 @@
 }
 
 static void
-finish_prepare_screenshot (char *initial_uri)
+finish_prepare_screenshot (char *initial_uri, GdkWindow *window)
 {  
   ScreenshotDialog *dialog;
-  GdkWindow *window;
-
-  if (!screenshot_grab_lock ())
-    exit (0);
-
-  if (take_window_shot)
-    {
-      window = screenshot_find_current_window ();
-      if (!window)
-	{
-	  take_window_shot = FALSE;
-	  window = gdk_get_default_root_window ();
-	}
-      else
-	{
-	  gchar *tmp;
-
-	  window_title = screenshot_get_window_title (window);
-	  tmp = screenshot_sanitize_filename (window_title);
-	  g_free (window_title);
-	  window_title = tmp;
-	}
-    }
-  else
-    {
-      window = gdk_get_default_root_window ();
-    }
 
   screenshot = screenshot_get_pixbuf (window, include_pointer, include_border);
 
@@ -747,6 +721,7 @@
       }
   }
 
+  /* release now the lock, it was acquired when we were finding the window */
   screenshot_release_lock ();
 
   if (screenshot == NULL)
@@ -769,13 +744,15 @@
 check_file_done (gpointer user_data)
 {
   char *retval;
+  GdkWindow *window;
   AsyncExistenceJob *job = user_data;
 
+  window = job->window;
   retval = job->retval;
   g_free (job->base_uris[1]);
   g_slice_free (AsyncExistenceJob, job);
   
-  finish_prepare_screenshot (retval);
+  finish_prepare_screenshot (retval, window);
   
   return FALSE;
 }
@@ -840,7 +817,7 @@
   error = NULL;
   uri = build_uri (job);
   file = g_file_new_for_uri (uri);
-  
+
   info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE,
 			    G_FILE_QUERY_INFO_NONE, cancellable, &error);
   if (info != NULL)
@@ -848,6 +825,8 @@
       /* file already exists, iterate again */
       g_object_unref (info);
       g_object_unref (file);
+      g_error_free (error);
+
       (job->iteration)++;
 
       goto retry;
@@ -888,7 +867,7 @@
 out:
   g_error_free (error);
   g_object_unref (file);
-    
+
   g_io_scheduler_job_send_to_mainloop_async (io_job,
                                              check_file_done,
                                              job,
@@ -896,6 +875,40 @@
   return FALSE;
 }
 
+static GdkWindow *
+find_current_window (char **window_title)
+{
+  GdkWindow *window;
+
+  if (!screenshot_grab_lock ())
+    exit (0);
+
+  if (take_window_shot)
+    {
+      window = screenshot_find_current_window ();
+      if (!window)
+	{
+	  take_window_shot = FALSE;
+	  window = gdk_get_default_root_window ();
+	}
+      else
+	{
+	  gchar *tmp, *sanitized;
+
+	  tmp = screenshot_get_window_title (window);
+	  sanitized = screenshot_sanitize_filename (tmp);
+	  g_free (tmp);
+	  *window_title = sanitized;
+	}
+    }
+  else
+    {
+      window = gdk_get_default_root_window ();
+    }
+
+  return window;
+}
+
 static void
 prepare_screenshot (void)
 {
@@ -908,6 +921,7 @@
   job->base_uris[2] = (char *) g_get_tmp_dir ();
   job->iteration = 0;
   job->type = TEST_LAST_DIR;
+  job->window = find_current_window (&window_title);
 
   g_io_scheduler_push_job (try_check_file,
                            job,

Modified: trunk/gnome-screenshot/screenshot-save.c
==============================================================================
--- trunk/gnome-screenshot/screenshot-save.c	(original)
+++ trunk/gnome-screenshot/screenshot-save.c	Thu Aug 28 19:02:43 2008
@@ -272,7 +272,7 @@
   g_assert (g_utf8_validate (filename, -1, NULL));
 
   retval = g_uri_escape_string (filename,
-                                NULL,
+                                "/",
                                 TRUE);
 
   for (p = retval; *p != '\000'; p = g_utf8_next_char (p))



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