Author: benny
Date: 2006-08-04 12:03:37 +0000 (Fri, 04 Aug 2006)
New Revision: 22648
Modified:
thunar/trunk/ChangeLog
thunar/trunk/thunar/thunar-file.c
thunar/trunk/thunar/thunar-util.c
thunar/trunk/thunar/thunar-util.h
Log:
2006-08-04 Benedikt Meurer <[EMAIL PROTECTED]>
* thunar/thunar-file.c, thunar/thunar-util.{c,h}: Add new helper method
thunar_util_time_from_rfc3339(), which parses a date string to a time
value, using strptime() if available. Use the method to parse the
deletion date string for trashed resources, so the deletion date will
be displayed properly even on systems that lack strptime().
* thunar/thunar-util.c(thunar_util_humanize_file_time): Use
g_date_set_time() to enable compilation with GLib 2.6/2.8.
Hopefully nobody will still use GLib 2.6/2.8 in 2038.
Modified: thunar/trunk/ChangeLog
===================================================================
--- thunar/trunk/ChangeLog 2006-08-03 21:42:40 UTC (rev 22647)
+++ thunar/trunk/ChangeLog 2006-08-04 12:03:37 UTC (rev 22648)
@@ -1,3 +1,14 @@
+2006-08-04 Benedikt Meurer <[EMAIL PROTECTED]>
+
+ * thunar/thunar-file.c, thunar/thunar-util.{c,h}: Add new helper method
+ thunar_util_time_from_rfc3339(), which parses a date string to a time
+ value, using strptime() if available. Use the method to parse the
+ deletion date string for trashed resources, so the deletion date will
+ be displayed properly even on systems that lack strptime().
+ * thunar/thunar-util.c(thunar_util_humanize_file_time): Use
+ g_date_set_time() to enable compilation with GLib 2.6/2.8.
+ Hopefully nobody will still use GLib 2.6/2.8 in 2038.
+
2006-07-31 Benedikt Meurer <[EMAIL PROTECTED]>
* configure.in.in, thunar-vfs/thunar-vfs-io-local-xfer.c,
Modified: thunar/trunk/thunar/thunar-file.c
===================================================================
--- thunar/trunk/thunar/thunar-file.c 2006-08-03 21:42:40 UTC (rev 22647)
+++ thunar/trunk/thunar/thunar-file.c 2006-08-04 12:03:37 UTC (rev 22648)
@@ -1354,11 +1354,8 @@
gchar*
thunar_file_get_deletion_date (const ThunarFile *file)
{
-#ifdef HAVE_STRPTIME
- struct tm tm;
-#endif
- time_t time;
- gchar *date;
+ time_t time;
+ gchar *date;
g_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
@@ -1367,12 +1364,8 @@
if (G_UNLIKELY (date == NULL))
return NULL;
- /* try to parse the DeletionDate (ISO date string) */
-#ifdef HAVE_STRPTIME
- time = (strptime (date, "%FT%T", &tm) != NULL) ? mktime (&tm) : 0;
-#else
- time = 0;
-#endif
+ /* try to parse the DeletionDate (RFC 3339 string) */
+ time = thunar_util_time_from_rfc3339 (date);
/* release the DeletionDate */
g_free (date);
Modified: thunar/trunk/thunar/thunar-util.c
===================================================================
--- thunar/trunk/thunar/thunar-util.c 2006-08-03 21:42:40 UTC (rev 22647)
+++ thunar/trunk/thunar/thunar-util.c 2006-08-04 12:03:37 UTC (rev 22648)
@@ -21,6 +21,19 @@
#include <config.h>
#endif
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
#include <thunar/thunar-util.h>
@@ -78,8 +91,13 @@
if (G_LIKELY (file_time != 0))
{
/* setup the GDate's */
+#if GLIB_CHECK_VERSION(2,10,0)
g_date_set_time_t (&dfile, file_time);
g_date_set_time_t (&dnow, time (NULL));
+#else
+ g_date_set_time (&dfile, (GTime) file_time);
+ g_date_set_time (&dnow, (GTime) time (NULL));
+#endif
/* determine the difference in days */
diff = g_date_get_julian (&dnow) - g_date_get_julian (&dfile);
@@ -172,3 +190,70 @@
return screen;
}
+
+
+/**
+ * thunar_util_time_from_rfc3339:
+ * @date_string : an RFC 3339 encoded date string.
+ *
+ * Decodes the @date_string, which must be in the special RFC 3339
+ * format <literal>YYYY-MM-DDThh:mm:ss</literal>. This method is
+ * used to decode deletion dates of files in the trash. See the
+ * Trash Specification for details.
+ *
+ * Return value: the time value matching the @date_string or
+ * %0 if the @date_string could not be parsed.
+ **/
+time_t
+thunar_util_time_from_rfc3339 (const gchar *date_string)
+{
+ struct tm tm;
+
+#ifndef HAVE_STRPTIME
+ /* using strptime() its easy to parse the date string */
+ if (G_UNLIKELY (strptime (date_string, "%FT%T", &tm) == NULL))
+ return 0;
+#else
+ gulong val;
+
+ /* be sure to start with a clean tm */
+ memset (&tm, 0, sizeof (tm));
+
+ /* parsing by hand is also doable for RFC 3339 dates */
+ val = strtoul (date_string, (gchar **) &date_string, 10);
+ if (G_UNLIKELY (*date_string != '-'))
+ return 0;
+
+ /* YYYY-MM-DD */
+ tm.tm_year = val - 1900;
+ date_string++;
+ tm.tm_mon = strtoul (date_string, (gchar **) &date_string, 10) - 1;
+
+ if (G_UNLIKELY (*date_string++ != '-'))
+ return 0;
+
+ tm.tm_mday = strtoul (date_string, (gchar **) &date_string, 10);
+
+ if (G_UNLIKELY (*date_string++ != 'T'))
+ return 0;
+
+ val = strtoul (date_string, (gchar **) &date_string, 10);
+ if (G_UNLIKELY (*date_string != ':'))
+ return 0;
+
+ /* hh:mm:ss */
+ tm.tm_hour = val;
+ date_string++;
+ tm.tm_min = strtoul (date_string, (gchar **) &date_string, 10);
+
+ if (G_UNLIKELY (*date_string++ != ':'))
+ return 0;
+
+ tm.tm_sec = strtoul (date_string, (gchar **) &date_string, 10);
+#endif /* !HAVE_STRPTIME */
+
+ /* translate tm to time_t */
+ return mktime (&tm);
+}
+
+
Modified: thunar/trunk/thunar/thunar-util.h
===================================================================
--- thunar/trunk/thunar/thunar-util.h 2006-08-03 21:42:40 UTC (rev 22647)
+++ thunar/trunk/thunar/thunar-util.h 2006-08-04 12:03:37 UTC (rev 22648)
@@ -31,6 +31,8 @@
GdkScreen *thunar_util_parse_parent (gpointer parent,
GtkWindow **window_return)
G_GNUC_INTERNAL G_GNUC_WARN_UNUSED_RESULT;
+time_t thunar_util_time_from_rfc3339 (const gchar *date_string)
G_GNUC_INTERNAL G_GNUC_WARN_UNUSED_RESULT;
+
G_END_DECLS;
#endif /* !__THUNAR_UTIL_H__ */
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits