changeset 1483:7cb24fdf07c0

re-added possibility to display basic file info (size, mode, date)
author nadvornik
date Sun, 29 Mar 2009 10:36:13 +0000
parents dac747d99394
children 9c16a93a0fdf
files src/exif-common.c src/exif.h src/metadata.c
diffstat 3 files changed, 79 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/exif-common.c	Sat Mar 28 15:51:21 2009 +0000
+++ b/src/exif-common.c	Sun Mar 29 10:36:13 2009 +0000
@@ -524,6 +524,9 @@
 	EXIF_FORMATTED_TAG(ColorProfile,	N_("Color profile")),
 	EXIF_FORMATTED_TAG(GPSPosition,		N_("GPS position")),
 	EXIF_FORMATTED_TAG(GPSAltitude,		N_("GPS altitude")),
+	{"file.size",				N_("File size"), 	NULL},
+	{"file.date",				N_("File date"), 	NULL},
+	{"file.mode",				N_("File mode"), 	NULL},
 	{ NULL, NULL, NULL }
 };
 
@@ -537,7 +540,7 @@
 
 		key += EXIF_FORMATTED_LEN;
 		for (i = 0; ExifFormattedList[i].key; i++)
-			if (strcmp(key, ExifFormattedList[i].key + EXIF_FORMATTED_LEN) == 0)
+			if (ExifFormattedList[i].build_func && strcmp(key, ExifFormattedList[i].key + EXIF_FORMATTED_LEN) == 0)
 				return ExifFormattedList[i].build_func(exif);
 		}
 
@@ -549,13 +552,13 @@
 {
 	if (!key) return NULL;
 
-	if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0)
+	if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 ||
+	    strncmp(key, "file.", 5) == 0)
 		{
 		gint i;
 
-		key += EXIF_FORMATTED_LEN;
 		for (i = 0; ExifFormattedList[i].key; i++)
-			if (strcmp(key, ExifFormattedList[i].key + EXIF_FORMATTED_LEN) == 0)
+			if (strcmp(key, ExifFormattedList[i].key) == 0)
 				return g_strdup(_(ExifFormattedList[i].description));
 		}
 
@@ -769,4 +772,70 @@
 
 	return FALSE;
 }
+
+/*
+ *-------------------------------------------------------------------
+ * file info
+ * it is here because it shares tag neming infrastructure with exif
+ * we should probably not invest too much effort into this because
+ * new exiv2 will support the same functionality
+ * http://dev.exiv2.org/issues/show/505
+ *-------------------------------------------------------------------
+ */
+
+static gchar *mode_number(mode_t m)
+{
+	gint mb, mu, mg, mo;
+	gchar pbuf[12];
+
+	mb = mu = mg = mo = 0;
+
+	if (m & S_ISUID) mb |= 4;
+	if (m & S_ISGID) mb |= 2;
+	if (m & S_ISVTX) mb |= 1;
+
+	if (m & S_IRUSR) mu |= 4;
+	if (m & S_IWUSR) mu |= 2;
+	if (m & S_IXUSR) mu |= 1;
+
+	if (m & S_IRGRP) mg |= 4;
+	if (m & S_IWGRP) mg |= 2;
+	if (m & S_IXGRP) mg |= 1;
+
+	if (m & S_IROTH) mo |= 4;
+	if (m & S_IWOTH) mo |= 2;
+	if (m & S_IXOTH) mo |= 1;
+
+	pbuf[0] = (m & S_IRUSR) ? 'r' : '-';
+	pbuf[1] = (m & S_IWUSR) ? 'w' : '-';
+	pbuf[2] = (m & S_IXUSR) ? 'x' : '-';
+	pbuf[3] = (m & S_IRGRP) ? 'r' : '-';
+	pbuf[4] = (m & S_IWGRP) ? 'w' : '-';
+	pbuf[5] = (m & S_IXGRP) ? 'x' : '-';
+	pbuf[6] = (m & S_IROTH) ? 'r' : '-';
+	pbuf[7] = (m & S_IWOTH) ? 'w' : '-';
+	pbuf[8] = (m & S_IXOTH) ? 'x' : '-';
+	pbuf[9] = '\0';
+
+	return g_strdup_printf("%s (%d%d%d%d)", pbuf, mb, mu, mg, mo);
+}
+
+gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format)
+{
+	if (strcmp(key, "file.size") == 0)
+		{
+		return g_strdup_printf("%ld", (long)fd->size);
+		}
+	if (strcmp(key, "file.date") == 0)
+		{
+		return g_strdup(text_from_time(fd->date));
+		}
+	if (strcmp(key, "file.mode") == 0)
+		{
+		return mode_number(fd->mode);
+		}
+	return g_strdup("");
+}
+
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/exif.h	Sat Mar 28 15:51:21 2009 +0000
+++ b/src/exif.h	Sun Mar 29 10:36:13 2009 +0000
@@ -170,6 +170,7 @@
 guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width, gint requested_height);
 void exif_free_preview(guchar *buf);
 
+gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/metadata.c	Sat Mar 28 15:51:21 2009 +0000
+++ b/src/metadata.c	Sun Mar 29 10:36:13 2009 +0000
@@ -480,6 +480,11 @@
 	        if (metadata_legacy_read(fd, NULL, &comment)) return g_list_append(NULL, comment);
 	        }
 	
+	if (strncmp(key, "file.", 5) == 0)
+		{
+	        return g_list_append(NULL, metadata_file_info(fd, key, format));
+		}
+	
 	exif = exif_read_fd(fd); /* this is cached, thus inexpensive */
 	if (!exif) return NULL;
 	list = exif_get_metadata(exif, key, format);