[Xfce4-commits] <xfce4-screenshooter:master> Split the function to get the date and the time.
Jérôme Guelfucci
jeromeg at xfce.org
Fri Aug 14 00:26:20 CEST 2009
Updating branch refs/heads/master
to 6230d14f6d542149f4b066355a1a74fd88ed1da8 (commit)
from c5ad669c42f554b4f0d1b7fbd00817cb8627b605 (commit)
commit 6230d14f6d542149f4b066355a1a74fd88ed1da8
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date: Sat Aug 8 23:04:25 2009 +0200
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 f0aed25..4aafc89 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 92b6d7e..20aae37 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 9596567..6e80741 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 d32933f..90d6e53 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
More information about the Xfce4-commits
mailing list