fileinfo: Add _get_deletion_date() helper
authorBastien Nocera <hadess@hadess.net>
Tue, 27 Nov 2012 15:59:28 +0000 (16:59 +0100)
committerBastien Nocera <hadess@hadess.net>
Tue, 27 Nov 2012 15:59:28 +0000 (16:59 +0100)
For use in gnome-settings-daemon, so that callers don't have
to parse the deletion date by hand.

gio/gfileinfo.c
gio/gfileinfo.h
gio/gio.symbols

index 0fd76da..34ee1c3 100644 (file)
@@ -1440,6 +1440,42 @@ g_file_info_set_attribute_int64  (GFileInfo  *info,
 
 /* Helper getters */
 /**
+ * g_file_info_get_deletion_date:
+ * @info: a #GFileInfo.
+ *
+ * Returns the #GDateTime representing the deletion date of the file, as
+ * available in G_FILE_ATTRIBUTE_TRASH_DELETION_DATE. If the
+ * G_FILE_ATTRIBUTE_TRASH_DELETION_DATE attribute is unset, %NULL is returned.
+ *
+ * Returns: a #GDateTime, or %NULL.
+ *
+ * Since: 2.36
+ **/
+GDateTime *
+g_file_info_get_get_deletion_date (GFileInfo *info)
+{
+  static guint32 attr = 0;
+  GFileAttributeValue *value;
+  const char *date_str;
+  GTimeVal tv;
+
+  g_return_val_if_fail (G_IS_FILE_INFO (info), FALSE);
+
+  if (attr == 0)
+    attr = lookup_attribute (G_FILE_ATTRIBUTE_TRASH_DELETION_DATE);
+
+  value = g_file_info_find_value (info, attr);
+  date_str = _g_file_attribute_value_get_string (value);
+  if (!date_str)
+    return NULL;
+
+  if (g_time_val_from_iso8601 (date_str, &tv) == FALSE)
+    return NULL;
+
+  return g_date_time_new_from_timeval_local (&tv);
+}
+
+/**
  * g_file_info_get_file_type:
  * @info: a #GFileInfo.
  *
index 9399e53..e90e034 100644 (file)
@@ -911,6 +911,7 @@ void               g_file_info_set_attribute_stringv     (GFileInfo  *info,
 void               g_file_info_clear_status              (GFileInfo  *info);
 
 /* Helper getters: */
+GDateTime *       g_file_info_get_get_deletion_date  (GFileInfo         *info);
 GFileType         g_file_info_get_file_type          (GFileInfo         *info);
 gboolean          g_file_info_get_is_hidden          (GFileInfo         *info);
 gboolean          g_file_info_get_is_backup          (GFileInfo         *info);
index d214cd1..afffd7d 100644 (file)
@@ -423,6 +423,7 @@ g_file_info_set_attribute_int64
 g_file_info_set_attribute_object
 g_file_info_set_attribute_stringv
 g_file_info_clear_status
+g_file_info_get_get_deletion_date
 g_file_info_get_file_type
 g_file_info_get_is_hidden
 g_file_info_get_is_backup