changeset 2791:7061c1eacc20

Additional file info parameters 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)
author Colin Clark <colin.clark@cclark.uk>
date Fri, 06 Jul 2018 19:44:10 +0100
parents 4b0c49aa8c7b
children dc7c069a2745
files src/exif-common.c src/filedata.c src/misc.c src/misc.h src/typedefs.h web/help/GuideSidebarsInfo.html
diffstat 6 files changed, 105 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/exif-common.c	Sat Jun 30 22:18:19 2018 +0100
+++ b/src/exif-common.c	Fri Jul 06 19:44:10 2018 +0100
@@ -888,6 +888,10 @@
 	{"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 @@
 		{
 		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("");
 }
 
--- a/src/filedata.c	Sat Jun 30 22:18:19 2018 +0100
+++ b/src/filedata.c	Fri Jul 06 19:44:10 2018 +0100
@@ -32,8 +32,10 @@
 #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 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 @@
 	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 @@
 	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);
--- a/src/misc.c	Sat Jun 30 22:18:19 2018 +0100
+++ b/src/misc.c	Fri Jul 06 19:44:10 2018 +0100
@@ -323,4 +323,37 @@
 	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: */
--- a/src/misc.h	Sat Jun 30 22:18:19 2018 +0100
+++ b/src/misc.h	Fri Jul 06 19:44:10 2018 +0100
@@ -30,5 +30,6 @@
 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: */
--- a/src/typedefs.h	Sat Jun 30 22:18:19 2018 +0100
+++ b/src/typedefs.h	Fri Jul 06 19:44:10 2018 +0100
@@ -598,6 +598,10 @@
 	gint rating;
 	gboolean metadata_in_idle_loaded;
 
+	gchar *owner;
+	gchar *group;
+	gchar *sym_link;
+
 	SelectionType selected;  // Used by view_file_icon.
 };
 
--- a/web/help/GuideSidebarsInfo.html	Sat Jun 30 22:18:19 2018 +0100
+++ b/web/help/GuideSidebarsInfo.html	Fri Jul 06 19:44:10 2018 +0100
@@ -734,8 +734,24 @@
 <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>