Additional file info parameters
authorColin Clark <colin.clark@cclark.uk>
Fri, 6 Jul 2018 18:44:10 +0000 (19:44 +0100)
committerColin Clark <colin.clark@cclark.uk>
Fri, 6 Jul 2018 18:44:10 +0000 (19:44 +0100)
Additional parameters which can be displayed in the info sidebar or
overlay screen display:

file owner (file.owner)
file group (file.group)
file class (file.class) e.g. RAW image etc.
file symbolic link (file.link)

src/exif-common.c
src/filedata.c
src/misc.c
src/misc.h
src/typedefs.h
web/help/GuideSidebarsInfo.html

index e07058c..55455e0 100644 (file)
@@ -888,6 +888,10 @@ ExifFormattedText ExifFormattedList[] = {
        {"file.date",                           N_("File date"),        NULL},
        {"file.mode",                           N_("File mode"),        NULL},
        {"file.ctime",                          N_("File ctime"),       NULL},
+       {"file.owner",                          N_("File owner"),       NULL},
+       {"file.group",                          N_("File group"),       NULL},
+       {"file.link",                           N_("File link"),        NULL},
+       {"file.class",                          N_("File class"),       NULL},
        { NULL, NULL, NULL }
 };
 
@@ -1152,6 +1156,22 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format)
                {
                return g_strdup(text_from_time(fd->cdate));
                }
+       if (strcmp(key, "file.class") == 0)
+               {
+               return g_strdup(format_class_list[fd->format_class]);
+               }
+       if (strcmp(key, "file.owner") == 0)
+               {
+               return g_strdup(fd->owner);
+               }
+       if (strcmp(key, "file.group") == 0)
+               {
+               return g_strdup(fd->group);
+               }
+       if (strcmp(key, "file.link") == 0)
+               {
+               return g_strdup(fd->sym_link);
+               }
        return g_strdup("");
 }
 
index 876cb80..0461755 100644 (file)
 #include "secure_save.h"
 
 #include "exif.h"
+#include "misc.h"
 
 #include <errno.h>
+#include <grp.h>
 
 #ifdef DEBUG_FILEDATA
 gint global_file_data_count = 0;
@@ -370,6 +372,8 @@ static void file_data_set_path(FileData *fd, const gchar *path)
 static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean disable_sidecars)
 {
        FileData *fd;
+       struct passwd *user;
+       struct group *group;
 
        DEBUG_2("file_data_new: '%s' %d", path_utf8, disable_sidecars);
 
@@ -432,6 +436,28 @@ static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean
        fd->rating = STAR_RATING_NOT_READ;
        fd->format_class = filter_file_get_class(path_utf8);
 
+       user = getpwuid(st->st_uid);
+       if (!user)
+               {
+               fd->owner = g_strdup_printf("%u", st->st_uid);
+               }
+       else
+               {
+               fd->owner = g_strdup(user->pw_name);
+               }
+
+       group = getgrgid(st->st_gid);
+       if (!group)
+               {
+               fd->group = g_strdup_printf("%u", st->st_gid);
+               }
+       else
+               {
+               fd->group = g_strdup(group->gr_name);
+               }
+
+       fd->sym_link = get_symbolic_link(path_utf8);
+
        if (disable_sidecars) fd->disable_grouping = TRUE;
 
        file_data_set_path(fd, path_utf8); /* set path, name, collate_key_*, original_path */
@@ -681,7 +707,9 @@ static void file_data_free(FileData *fd)
        g_free(fd->extended_extension);
        if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
        histmap_free(fd->histmap);
-
+       g_free(fd->owner);
+       g_free(fd->group);
+       g_free(fd->sym_link);
        g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */
 
        file_data_change_info_free(NULL, fd);
index 70b01ef..d780795 100644 (file)
@@ -323,4 +323,37 @@ gchar *convert_rating_to_stars(gint rating)
        return ret;
 }
 
+gchar *get_symbolic_link(const gchar *path_utf8)
+{
+       gchar *sl;
+       struct stat st;
+       gchar *ret = g_strdup("");
+
+       sl = path_from_utf8(path_utf8);
+
+       if (lstat(sl, &st) == 0 && S_ISLNK(st.st_mode))
+               {
+               gchar *buf;
+               gint l;
+
+               buf = g_malloc(st.st_size + 1);
+               l = readlink(sl, buf, st.st_size);
+
+               if (l == st.st_size)
+                       {
+                       buf[l] = '\0';
+
+                       ret = buf;
+                       }
+               else
+                       {
+                       g_free(buf);
+                       }
+               }
+
+       g_free(sl);
+
+       return ret;
+}
+
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 103f6a6..1071062 100644 (file)
@@ -30,5 +30,6 @@ gchar *decode_geo_parameters(const gchar *input_text);
 gint date_get_first_day_of_week();
 gchar *date_get_abbreviated_day_name(gint day);
 gchar *convert_rating_to_stars(gint rating);
+gchar *get_symbolic_link(const gchar *path_utf8);
 #endif /* MISC_H */
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 7137f4e..b23e575 100644 (file)
@@ -598,6 +598,10 @@ struct _FileData {
        gint rating;
        gboolean metadata_in_idle_loaded;
 
+       gchar *owner;
+       gchar *group;
+       gchar *sym_link;
+
        SelectionType selected;  // Used by view_file_icon.
 };
 
index b8d709e..02c64b1 100644 (file)
@@ -734,8 +734,24 @@ dd.answer div.label { float: left; }
 <td class="td-rowsep">file mode flags</td>
 </tr>
 <tr>
-<td class="td-colsep">file.ctime</td>
-<td>refer to operating system documentation for the meaning of ctime</td>
+<td class="td-colsep td-rowsep">file.ctime</td>
+<td class="td-rowsep">refer to operating system documentation for the meaning of ctime</td>
+</tr>
+<tr class="tr-shade">
+<td class="td-colsep td-rowsep">file.owner</td>
+<td class="td-rowsep">the file's owner. Refer to operating system documentation for the meaning of file permissions</td>
+</tr>
+<tr>
+<td class="td-colsep td-rowsep">file.group</td>
+<td class="td-rowsep">the file's group. Refer to operating system documentation for the meaning of file permissions</td>
+</tr>
+<tr class="tr-shade">
+<td class="td-colsep td-rowsep">file.class</td>
+<td class="td-rowsep">the file's class e.g. Image, RAW image etc.</td>
+</tr>
+<tr>
+<td class="td-colsep">file.link</td>
+<td>if the file is a symbolic link, shows the path of the source file</td>
 </tr>
 </tbody></table>
 </div>