re-added possibility to display basic file info (size, mode, date)
authorVladimir Nadvornik <nadvornik@suse.cz>
Sun, 29 Mar 2009 10:36:13 +0000 (10:36 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sun, 29 Mar 2009 10:36:13 +0000 (10:36 +0000)
src/exif-common.c
src/exif.h
src/metadata.c

index 555abc9..6535a4c 100644 (file)
@@ -524,6 +524,9 @@ ExifFormattedText ExifFormattedList[] = {
        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 @@ gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gboolean *key
 
                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 @@ gchar *exif_get_description_by_key(const gchar *key)
 {
        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 @@ gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size)
 
        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: */
index 3bb4183..678d64e 100644 (file)
@@ -170,6 +170,7 @@ gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size);
 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: */
index 180a44a..417617e 100644 (file)
@@ -480,6 +480,11 @@ GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format)
                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);