changeset 2878:8b1c451c8ff2

Additional remote commands --get-filelist:[<FOLDER>] Get list of files and class --get-filelist-recurse:[<FOLDER>] Get list of files and class recursive --get-collection:<COLLECTION> Get collection content --get-collection-list Get list of collections Changed command: --tell Print filename of current image [and Collection, if collection being displayed]
author Colin Clark <colin.clark@cclark.uk>
date Fri, 04 Jan 2019 13:44:58 +0000
parents 92494a7432e9
children c8147f1d5fc3
files geeqie.1 src/collect.c src/collect.h src/remote.c
diffstat 4 files changed, 232 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/geeqie.1	Thu Dec 20 11:45:20 2018 +0000
+++ b/geeqie.1	Fri Jan 04 13:44:58 2019 +0000
@@ -165,13 +165,37 @@
 .br
 .B
 .IP \-\-tell
-Print filename of current image.
+Print filename [and Collection] of current image.
 .br
 .B
 .IP \-\-pixel\-info
 Print X, Y and RGB of mouse pointer on current image.
 .br
 .B
+.IP \-\-get\-rectangle
+Get rectangle co-ordinates.
+.br
+.B
+.IP \-\-get\-render\-intent
+Get render intent.
+.br
+.B
+.IP \-\-get\-filelist:[<FOLDER>]
+Get list of files and class.
+.br
+.B
+.IP \-\-get\-filelist-recurse:[<FOLDER>]
+Get list of file and class recursive.
+.br
+.B
+.IP \-\-get\-collection:<COLLECTION>
+Get collection content.
+.br
+.B
+.IP \-\-get\-collection\-list
+Get collection list.
+.br
+.B
 .IP \-\-view:<FILE>
 Open FILE in new window.
 .br
--- a/src/collect.c	Thu Dec 20 11:45:20 2018 +0000
+++ b/src/collect.c	Fri Jan 04 13:44:58 2019 +0000
@@ -345,7 +345,7 @@
  * 
  * Return value must be freed with g_free()
  */
-gchar *collection_path(gchar *param)
+gchar *collection_path(const gchar *param)
 {
 	gchar *path = NULL;
 	gchar *full_name = NULL;
@@ -377,7 +377,7 @@
  * 
  * 
  */
-gboolean is_collection(gchar *param)
+gboolean is_collection(const gchar *param)
 {
 	gchar *name = NULL;
 
@@ -390,6 +390,41 @@
 	return FALSE;
 }
 
+/**
+ * @brief Creates a text list of the image paths of the contents of a Collection
+ * @param[in] name The name of the collection, with or wihout extension
+ * @param[inout] contents A GString to which the image paths are appended
+ * 
+ * 
+ */
+void collection_contents(const gchar *name, GString **contents)
+{
+	gchar *path;
+	CollectionData *cd;
+	CollectInfo *ci;
+	GList *work;
+	FileData *fd;
+
+	if (is_collection(name))
+		{
+		path = collection_path(name);
+		cd = collection_new("");
+		collection_load(cd, path, COLLECTION_LOAD_APPEND);
+		work = cd->list;
+		while (work)
+			{
+			ci = work->data;
+			fd = ci->fd;
+			*contents = g_string_append(*contents, g_strdup(fd->path));
+			*contents = g_string_append(*contents, "\n");
+
+			work = work->next;
+			}
+		g_free(path);
+		collection_free(cd);
+		}
+}
+
 /*
  *-------------------------------------------------------------------
  * please use these to actually add/remove stuff
--- a/src/collect.h	Thu Dec 20 11:45:20 2018 +0000
+++ b/src/collect.h	Fri Jan 04 13:44:58 2019 +0000
@@ -86,7 +86,8 @@
 CollectWindow *collection_window_find_by_path(const gchar *path);
 gboolean collection_window_modified_exists(void);
 
-gboolean is_collection(gchar *param);
-gchar *collection_path(gchar *param);
+gboolean is_collection(const gchar *param);
+gchar *collection_path(const gchar *param);
+void collection_contents(const gchar *name, GString **contents);
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
--- a/src/remote.c	Thu Dec 20 11:45:20 2018 +0000
+++ b/src/remote.c	Fri Jan 04 13:44:58 2019 +0000
@@ -24,7 +24,9 @@
 
 #include "cache_maint.h"
 #include "collect.h"
+#include "collect-io.h"
 #include "filedata.h"
+#include "filefilter.h"
 #include "image.h"
 #include "img-view.h"
 #include "layout.h"
@@ -747,14 +749,173 @@
 	g_free(render_intent);
 }
 
+static void get_filelist(const gchar *text, GIOChannel *channel, gboolean recurse)
+{
+	GList *list = NULL;
+	FileFormatClass class;
+	FileData *dir_fd;
+	FileData *fd;
+	GString *out_string = g_string_new(NULL);
+	GList *work;
+
+	if (strcmp(text, "") == 0)
+		{
+		if (layout_valid(&lw_id))
+			{
+			dir_fd = file_data_new_dir(lw_id->dir_fd->path);
+			}
+		else
+			{
+			return;
+			}
+		}
+	else
+		{
+		if (isdir(text))
+			{
+			dir_fd = file_data_new_dir(text);
+			}
+		else
+			{
+			return;
+			}
+		}
+
+	if (recurse)
+		{
+		list = filelist_recursive(dir_fd);
+		}
+	else
+		{
+		filelist_read(dir_fd, &list, NULL);
+		}
+
+	work = list;
+	while (work)
+		{
+		fd = work->data;
+		g_string_append_printf(out_string, "%s", fd->path);
+		class = filter_file_get_class(fd->path);
+
+		switch (class)
+			{
+			case FORMAT_CLASS_IMAGE:
+				out_string = g_string_append(out_string, "    Class: Image");
+				break;
+			case FORMAT_CLASS_RAWIMAGE:
+				out_string = g_string_append(out_string, "    Class: RAW image");
+				break;
+			case FORMAT_CLASS_META:
+				out_string = g_string_append(out_string, "    Class: Metadata");
+				break;
+			case FORMAT_CLASS_VIDEO:
+				out_string = g_string_append(out_string, "    Class: Video");
+				break;
+			case FORMAT_CLASS_COLLECTION:
+				out_string = g_string_append(out_string, "    Class: Collection");
+				break;
+			case FORMAT_CLASS_PDF:
+				out_string = g_string_append(out_string, "    Class: PDF");
+				break;
+			case FORMAT_CLASS_UNKNOWN:
+				out_string = g_string_append(out_string, "    Class: Unknown");
+				break;
+			default:
+				out_string = g_string_append(out_string, "    Class: Unknown");
+				break;
+			}
+		out_string = g_string_append(out_string, "\n");
+		work = work->next;
+		}
+
+	g_io_channel_write_chars(channel, out_string->str, -1, NULL, NULL);
+	g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+	g_string_free(out_string, TRUE);
+	filelist_free(list);
+	file_data_unref(dir_fd);
+}
+
+static void gr_collection(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	GString *contents = g_string_new(NULL);
+
+	if (is_collection(text))
+		{
+		collection_contents(text, &contents);
+		}
+	else
+		{
+		return;
+		}
+
+	g_io_channel_write_chars(channel, contents->str, -1, NULL, NULL);
+	g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+	g_string_free(contents, TRUE);
+}
+
+static void gr_collection_list(const gchar *text, GIOChannel *channel, gpointer data)
+{
+
+	GList *collection_list = NULL;
+	GList *work;
+	GString *out_string = g_string_new(NULL);
+
+	collect_manager_list(&collection_list, NULL, NULL);
+
+	work = collection_list;
+	while (work)
+		{
+		const gchar *collection_name = work->data;
+		out_string = g_string_append(out_string, g_strdup(collection_name));
+		out_string = g_string_append(out_string, "\n");
+
+		work = work->next;
+		}
+
+	g_io_channel_write_chars(channel, out_string->str, -1, NULL, NULL);
+	g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+	string_list_free(collection_list);
+	g_string_free(out_string, TRUE);
+}
+
+
+static void gr_filelist(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	get_filelist(text, channel, FALSE);
+}
+
+static void gr_filelist_recurse(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	get_filelist(text, channel, TRUE);
+}
+
 static void gr_file_tell(const gchar *text, GIOChannel *channel, gpointer data)
 {
+	gchar *out_string;
+	gchar *collection_name = NULL;
+
 	if (!layout_valid(&lw_id)) return;
 
 	if (image_get_path(lw_id->image))
 		{
-		g_io_channel_write_chars(channel, image_get_path(lw_id->image), -1, NULL, NULL);
+		if (lw_id->image->collection && lw_id->image->collection->name)
+			{
+			collection_name = remove_extension_from_path(lw_id->image->collection->name);
+			out_string = g_strconcat(image_get_path(lw_id->image), "    Collection: ", collection_name, NULL);
+			}
+		else
+			{
+			out_string = g_strconcat(image_get_path(lw_id->image), NULL);
+			}
+
+		g_io_channel_write_chars(channel, out_string, -1, NULL, NULL);
 		g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+		g_free(collection_name);
+		g_free(out_string);
 		}
 }
 
@@ -936,10 +1097,14 @@
 	{ NULL, "--get-destination:",  	gr_get_destination,     TRUE,  FALSE, N_("<FILE>"), N_("get destination path of FILE") },
 	{ NULL, "file:",                gr_file_load,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE, bring Geeqie window to the top") },
 	{ NULL, "File:",                gr_file_load_no_raise,  TRUE,  FALSE, N_("<FILE>"), N_("open FILE, do not bring Geeqie window to the top") },
-	{ NULL, "--tell",               gr_file_tell,           FALSE, FALSE, NULL, N_("print filename of current image") },
+	{ NULL, "--tell",               gr_file_tell,           FALSE, FALSE, NULL, N_("print filename [and Collection] of current image") },
 	{ NULL, "--pixel-info",         gr_pixel_info,          FALSE, FALSE, NULL, N_("print pixel info of mouse pointer on current image") },
 	{ NULL, "--get-rectangle",      gr_rectangle,           FALSE, FALSE, NULL, N_("get rectangle co-ordinates") },
 	{ NULL, "--get-render-intent",  gr_render_intent,       FALSE, FALSE, NULL, N_("get render intent") },
+	{ NULL, "--get-filelist:",      gr_filelist,            TRUE,  FALSE, N_("[<FOLDER>]"), N_("get list of files and class") },
+	{ NULL, "--get-filelist-recurse:", gr_filelist_recurse, TRUE,  FALSE, N_("[<FOLDER>]"), N_("get list of files and class recursive") },
+	{ NULL, "--get-collection:",    gr_collection,          TRUE,  FALSE, N_("<COLLECTION>"), N_("get collection content") },
+	{ NULL, "--get-collection-list", gr_collection_list,    FALSE, FALSE, NULL, N_("get collection list") },
 	{ NULL, "view:",                gr_file_view,           TRUE,  FALSE, N_("<FILE>"), N_("open FILE in new window") },
 	{ NULL, "--list-clear",         gr_list_clear,          FALSE, FALSE, NULL, N_("clear command line collection list") },
 	{ NULL, "--list-add:",          gr_list_add,            TRUE,  FALSE, N_("<FILE>"), N_("add FILE to command line collection list") },