[Xfce4-commits] [apps/xfce4-screenshooter] 01/01: Use filename-friendly date format for saved files (bug 8445)
noreply at xfce.org
noreply at xfce.org
Sat Dec 20 11:06:42 CET 2014
This is an automated email from the git hooks/post-receive script.
landry pushed a commit to branch master
in repository apps/xfce4-screenshooter.
commit ed5f8942ec4e4dd216a155b498bc34fed8a4e62d
Author: Jeff Shipley <jshipley at fastmail.fm>
Date: Sat Dec 20 11:05:47 2014 +0100
Use filename-friendly date format for saved files (bug 8445)
---
lib/screenshooter-dialogs.c | 11 ++++---
lib/screenshooter-utils.c | 74 ++++++++++---------------------------------
lib/screenshooter-utils.h | 3 +-
lib/screenshooter-zimagez.c | 4 +--
4 files changed, 25 insertions(+), 67 deletions(-)
diff --git a/lib/screenshooter-dialogs.c b/lib/screenshooter-dialogs.c
index 08f88e8..f3c2535 100644
--- a/lib/screenshooter-dialogs.c
+++ b/lib/screenshooter-dialogs.c
@@ -230,8 +230,9 @@ static gchar *generate_filename_for_uri (const gchar *uri,
GFile *directory;
GFile *file;
gchar *base_name;
- const gchar *date = screenshooter_get_date (TRUE);
- const gchar *current_time = screenshooter_get_time ();
+ gchar *datetime;
+ const gchar *strftime_format = "%Y-%m-%d_%H-%M-%S";
+
gint i;
if (G_UNLIKELY (uri == NULL))
@@ -242,11 +243,12 @@ static gchar *generate_filename_for_uri (const gchar *uri,
}
TRACE ("Get the folder corresponding to the URI");
+ datetime = screenshooter_get_datetime (strftime_format);
directory = g_file_new_for_uri (uri);
if (!timestamp)
base_name = g_strconcat (title, ".png", NULL);
else
- base_name = g_strconcat (title, " - ", date, " - ", current_time, ".png", NULL);
+ base_name = g_strconcat (title, "_", datetime, ".png", NULL);
file = g_file_get_child (directory, base_name);
@@ -269,7 +271,7 @@ static gchar *generate_filename_for_uri (const gchar *uri,
if (!timestamp)
base_name = g_strconcat (title, extension, NULL);
else
- base_name = g_strconcat (title, " - ", date, " - ", current_time, extension, NULL);
+ base_name = g_strconcat (title, "_", datetime, extension, NULL);
file = g_file_get_child (directory, base_name);
@@ -282,6 +284,7 @@ static gchar *generate_filename_for_uri (const gchar *uri,
g_object_unref (file);
}
+ g_free(datetime);
g_object_unref (directory);
return base_name;
diff --git a/lib/screenshooter-utils.c b/lib/screenshooter-utils.c
index 96f6bb8..e412182 100644
--- a/lib/screenshooter-utils.c
+++ b/lib/screenshooter-utils.c
@@ -280,65 +280,23 @@ void screenshooter_error (const gchar *format, ...)
g_free (message);
}
-gchar *screenshooter_get_time (void)
-{
- time_t now = time (0);
- const struct tm *tm;
- gchar *result, *converted;
- gsize length;
- gchar buffer[512];
-
- tm = localtime (&now);
-
- converted = g_locale_from_utf8 ("%X", -1, NULL, NULL, NULL);
- if (G_UNLIKELY (converted == NULL))
- converted = g_strdup ("");
-
- length = strftime (buffer, sizeof (buffer), converted, tm);
-
- if (G_UNLIKELY (length == 0))
- {
- TRACE ("Buffer is NULL");
- buffer[0] = '\0';
- }
-
- result = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
-
- g_free (converted);
-
- return result;
-}
-
-gchar *screenshooter_get_date (gboolean strip_slashes)
+/**
+ * screenshooter_get_datetime
+ * @format - a date format string
+ *
+ * Builds a timestamp using local time.
+ * Returned string should be released with g_free()
+ **/
+gchar *screenshooter_get_datetime (const gchar *format)
{
- GDate *date = g_date_new ();
- gchar *result;
- gchar **split = NULL;
- 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';
- }
-
- if (strip_slashes)
- {
- split = g_strsplit (buffer, "/", 0);
- result = g_strjoinv (NULL, split);
- }
- else
- result = g_strdup (buffer);
-
- g_strfreev (split);
- g_free (date);
-
- return result;
+ gchar *timestamp;
+ GDateTime *now = g_date_time_new_now_local();
+ timestamp = g_date_time_format (now, format);
+
+ g_date_time_unref (now);
+ /* TODO: strip potential : and / if the format is configurable */
+ DBG("datetime is %s", timestamp);
+ return timestamp;
}
diff --git a/lib/screenshooter-utils.h b/lib/screenshooter-utils.h
index 1646a8e..4453706 100644
--- a/lib/screenshooter-utils.h
+++ b/lib/screenshooter-utils.h
@@ -49,8 +49,7 @@ gboolean screenshooter_is_remote_uri (const gchar *uri);
gchar *rot13 (gchar *string);
void screenshooter_error (const gchar *format,
...);
-gchar *screenshooter_get_date (gboolean strip_slashes);
-gchar *screenshooter_get_time (void);
+gchar *screenshooter_get_datetime (const gchar *format);
void screenshooter_open_help (GtkWindow *parent);
gboolean screenshooter_f1_key (GtkWidget *widget,
GdkEventKey *event,
diff --git a/lib/screenshooter-zimagez.c b/lib/screenshooter-zimagez.c
index 1be2b79..e777f0c 100644
--- a/lib/screenshooter-zimagez.c
+++ b/lib/screenshooter-zimagez.c
@@ -176,12 +176,10 @@ zimagez_upload_job (ScreenshooterJob *job, GValueArray *param_values, GError **e
const gchar *encoded_data;
const gchar *image_path;
const gchar *last_user;
- const gchar *date = screenshooter_get_date (FALSE);
- const gchar *current_time = screenshooter_get_time ();
const gchar *proxy_uri;
/* For translators: the first wildcard is the date, the second one the time,
* e.g. "Taken on 12/31/99, at 23:13:48". */
- gchar *comment = g_strdup_printf (_("Taken on %s, at %s"), date, current_time);
+ gchar *comment = screenshooter_get_datetime (_("Taken on %x, at %X"));
gchar *data = NULL;
gchar *encoded_password = NULL;
gchar *file_name = NULL;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list