[gnome-screenshot] Allow customising the "from..." part of the name



commit 83de453a714bda4b21161c3fea96524cc9306b86
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jun 28 11:31:15 2012 +0100

    Allow customising the "from..." part of the name
    
    So that application can insert a better name for the screenshot.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=679056

 src/screenshot-application.c      |    2 +-
 src/screenshot-filename-builder.c |   28 ++++++++++++++++++++--------
 src/screenshot-filename-builder.h |    1 +
 3 files changed, 22 insertions(+), 9 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index a225ec3..1c5545b 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -446,7 +446,7 @@ finish_prepare_screenshot (ScreenshotApplication *self,
       screenshot_save_to_file (self);
     }
   else
-    screenshot_build_filename_async (screenshot_config->save_dir, build_filename_ready_cb, self);
+    screenshot_build_filename_async (screenshot_config->save_dir, NULL, build_filename_ready_cb, self);
 }
 
 static void
diff --git a/src/screenshot-filename-builder.c b/src/screenshot-filename-builder.c
index 844ebb9..1cc3d50 100644
--- a/src/screenshot-filename-builder.c
+++ b/src/screenshot-filename-builder.c
@@ -37,6 +37,7 @@ typedef enum
 typedef struct 
 {
   char *base_paths[NUM_TESTS];
+  char *screenshot_origin;
   int iteration;
   TestType type;
 
@@ -117,8 +118,7 @@ build_path (AsyncExistenceJob *job)
 {
   const gchar *base_path;
   char *retval, *file_name;
-  char *timestamp;
-  GDateTime *d;
+  char *origin;
 
   base_path = job->base_paths[job->type];
 
@@ -126,27 +126,34 @@ build_path (AsyncExistenceJob *job)
       base_path[0] == '\0')
     return NULL;
 
-  d = g_date_time_new_now_local ();
-  timestamp = g_date_time_format (d, "%Y-%m-%d %H:%M:%S");
-  g_date_time_unref (d);
+  if (job->screenshot_origin == NULL)
+    {
+      GDateTime *d;
+
+      d = g_date_time_new_now_local ();
+      origin = g_date_time_format (d, "%Y-%m-%d %H:%M:%S");
+      g_date_time_unref (d);
+    }
+  else
+    origin = g_strdup (job->screenshot_origin);
 
   if (job->iteration == 0)
     {
       /* translators: this is the name of the file that gets made up
        * with the screenshot if the entire screen is taken */
-      file_name = g_strdup_printf (_("Screenshot from %s.png"), timestamp);
+      file_name = g_strdup_printf (_("Screenshot from %s.png"), origin);
     }
   else
     {
       /* translators: this is the name of the file that gets
        * made up with the screenshot if the entire screen is
        * taken */
-      file_name = g_strdup_printf (_("Screenshot from %s - %d.png"), timestamp, job->iteration);
+      file_name = g_strdup_printf (_("Screenshot from %s - %d.png"), origin, job->iteration);
     }
 
   retval = g_build_filename (base_path, file_name, NULL);
   g_free (file_name);
-  g_free (timestamp);
+  g_free (origin);
 
   return retval;
 }
@@ -159,6 +166,8 @@ async_existence_job_free (AsyncExistenceJob *job)
   for (idx = 0; idx < NUM_TESTS; idx++)
     g_free (job->base_paths[idx]);
 
+  g_free (job->screenshot_origin);
+
   g_clear_object (&job->async_result);
 
   g_slice_free (AsyncExistenceJob, job);
@@ -293,6 +302,7 @@ out:
 
 void
 screenshot_build_filename_async (const char *save_dir,
+				 const char *screenshot_origin,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
 {
@@ -306,6 +316,8 @@ screenshot_build_filename_async (const char *save_dir,
   job->iteration = 0;
   job->type = TEST_SAVED_DIR;
 
+  job->screenshot_origin = g_strdup (screenshot_origin);
+
   job->async_result = g_simple_async_result_new (NULL,
                                                  callback, user_data,
                                                  screenshot_build_filename_async);
diff --git a/src/screenshot-filename-builder.h b/src/screenshot-filename-builder.h
index 9d0c96f..2b0868f 100644
--- a/src/screenshot-filename-builder.h
+++ b/src/screenshot-filename-builder.h
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 
 void screenshot_build_filename_async (const char *save_dir,
+                                      const char *screenshot_origin,
                                       GAsyncReadyCallback callback,
                                       gpointer user_data);
 gchar *screenshot_build_filename_finish (GAsyncResult *result,



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