From 6230d14f6d542149f4b066355a1a74fd88ed1da8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Guelfucci?= <jeromeg@xfce.org>
Date: Sat, 8 Aug 2009 23:04:25 +0200
Subject: [PATCH] Split the function to get the date and the time.

---
 ChangeLog                   |  4 ++++
 lib/screenshooter-dialogs.c |  7 ++++---
 lib/screenshooter-utils.c   | 40 +++++++++++++++++++++++++++----------
 lib/screenshooter-utils.h   |  3 ++-
 4 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f0aed25b..4aafc890 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-08-08 jeromeg
 
+Split the function to get the date and the time.
+
+2009-08-08 jeromeg
+
 Use the XDG pictures directory as the default save location.
 
 If it does not exist, use the home directory as a fallback.
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index 92b6d7eb..20aae37e 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -231,7 +231,8 @@ static gchar *generate_filename_for_uri (const gchar *uri,
   GFile *directory;
   GFile *file;
   gchar *base_name;
-  const gchar *date_hour = screenshooter_get_date_hour ();
+  const gchar *date = screenshooter_get_date ();
+  const gchar *current_time = screenshooter_get_time ();
   gint i;
 
   if (G_UNLIKELY (uri == NULL))
@@ -246,7 +247,7 @@ static gchar *generate_filename_for_uri (const gchar *uri,
   if (!horodate)
     base_name = g_strconcat (title, ".png", NULL);
   else
-    base_name = g_strconcat (title, " - ", date_hour, ".png", NULL);
+    base_name = g_strconcat (title, " - ", date, " - ", current_time, ".png", NULL);
 
   file = g_file_get_child (directory, base_name);
 
@@ -269,7 +270,7 @@ static gchar *generate_filename_for_uri (const gchar *uri,
       if (!horodate)
          base_name = g_strconcat (title, extension, NULL);
        else
-         base_name = g_strconcat (title, " - ", date_hour, extension, NULL);
+         base_name = g_strconcat (title, " - ", date, " - ", current_time, extension, NULL);
 
       file = g_file_get_child (directory, base_name);
 
diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c
index 95965671..6e80741a 100644
--- a/lib/screenshooter-utils.c
+++ b/lib/screenshooter-utils.c
@@ -280,18 +280,17 @@ void screenshooter_error (const gchar *format, ...)
   g_free (message);
 }
 
-gchar *screenshooter_get_date_hour (void)
+gchar *screenshooter_get_time (void)
 {
   time_t now = time (0);
-  struct tm *tm;
-  gchar *tmp, *result, *converted;
-  gchar **split;
+  const struct tm *tm;
+  gchar *result, *converted;
   gsize length;
   gchar buffer[512];
 
   tm = localtime (&now);
 
-  converted = g_locale_from_utf8 ("%x - %X", -1, NULL, NULL, NULL);
+  converted = g_locale_from_utf8 ("%X", -1, NULL, NULL, NULL);
   if (G_UNLIKELY (converted == NULL))
     converted = g_strdup ("");
 
@@ -303,15 +302,36 @@ gchar *screenshooter_get_date_hour (void)
       buffer[0] = '\0';
     }
 
-  tmp = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
-  split = g_strsplit (tmp, "/", 0);
-  result = g_strjoinv (NULL, split);
+  result = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
 
-  g_strfreev (split);
   g_free (converted);
-  g_free (tmp);
 
   return result;
 }
 
+gchar *screenshooter_get_date (void)
+{
+  GDate *date = g_date_new ();
+  gchar *result;
+  gchar **split;
+  gchar buffer[512];
+  gsize length;
+
+  g_date_set_time_t (date, time (NULL));
+
+  length = g_date_strftime (buffer, sizeof (buffer), "%x", date);
+
+  if (G_UNLIKELY (length == 0))
+    {
+      TRACE ("Buffer is NULL");
+      buffer[0] = '\0';
+    }
 
+  split = g_strsplit (buffer, "/", 0);
+  result = g_strjoinv (NULL, split);
+
+  g_strfreev (split);
+  g_free (date);
+
+  return result;
+}
diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h
index d32933f0..90d6e537 100644
--- a/lib/screenshooter-utils.h
+++ b/lib/screenshooter-utils.h
@@ -48,7 +48,8 @@ gboolean screenshooter_is_remote_uri       (const gchar    *uri);
 gchar *rot13                               (gchar          *string);
 void screenshooter_error                   (const gchar    *format,
                                             ...);
-gchar *screenshooter_get_date_hour         (void);
+gchar *screenshooter_get_date              (void);
+gchar *screenshooter_get_time              (void);
 
 
 #endif
-- 
GitLab