changeset 2639:18460ea0ceef

Fix #269: External image marks - (--remote --lua) https://github.com/BestImageViewer/geeqie/issues/269 Additional lua fn: Image:get_marks() Additional command line option: --remote --lua:<file>,<lua_script>
author Colin Clark <colin.clark@cclark.uk>
date Sun, 22 Oct 2017 19:39:44 +0100
parents 9f7b291d76a4
children 5978ed05163b
files doc/docbook/GuideReferenceCommandLine.xml doc/docbook/GuideReferenceLua.xml src/lua.c src/remote.c
diffstat 4 files changed, 61 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/doc/docbook/GuideReferenceCommandLine.xml	Wed Oct 18 17:49:46 2017 +0100
+++ b/doc/docbook/GuideReferenceCommandLine.xml	Sun Oct 22 19:39:44 2017 +0100
@@ -4,7 +4,8 @@
   <para>
     Geeqie is called by the command:
     <programlisting>
-      geeqie [options] [path_to_file_or_collection] <footnote id='ref1'>The name of a collection, with or without either path or extension (.gqv) may be used. If a path is not used and there is a name conflict with a file or folder, that will take precedence.</footnote>
+      geeqie [options] [path_to_file_or_collection]
+      <footnote id='ref1'>The name of a collection, with or without either path or extension (.gqv) may be used. If a path is not used and there is a name conflict with a file or folder, that will take precedence.</footnote>
     </programlisting>
   </para>
   <para>These are the command line options available to Geeqie:</para>
@@ -276,6 +277,11 @@
             </entry>
           </row>
           <row>
+            <entry />
+            <entry>--lua:&lt;file&gt;,&lt;lua script&gt;</entry>
+            <entry>run lua script on file</entry>
+          </row>
+          <row>
             <entry>-crsr:&lt;folder&gt;</entry>
             <entry>--cache-render-shared-recurse:&lt;folder&gt;</entry>
             <entry>render thumbnails recursively</entry>
--- a/doc/docbook/GuideReferenceLua.xml	Wed Oct 18 17:49:46 2017 +0100
+++ b/doc/docbook/GuideReferenceLua.xml	Sun Oct 22 19:39:44 2017 +0100
@@ -4,7 +4,9 @@
   <para>
     Lua scripts allow the functionality of Geeqie to be extended. Lua scripts may only be used in conjunction with the
     <link linkend="OverlayScreenDisplay">Overlay Screen Display</link>
-    .
+    and the
+    <programlisting xml:space="preserve">geeqie --remote --lua:</programlisting>
+    command line option.
   </para>
   <para />
   <para>Some knowledge of the Lua programming language is required.</para>
@@ -63,6 +65,10 @@
               <entry>The file size in bytes</entry>
             </row>
             <row>
+              <entry>Image:get_marks()</entry>
+              <entry>An integer representing the marks set for the file</entry>
+            </row>
+            <row>
               <entry>Image:get_exif()</entry>
               <entry>A data structure containing the entire exif data</entry>
             </row>
@@ -101,6 +107,8 @@
   </section>
   <section id="Warning">
     <title>Warning</title>
-    <warning><para>Lua is a powerful programming language. Errors in script files, besides having undesirable side-effects, may cause Geeqie to crash.</para></warning>
+    <warning>
+      <para>Lua is a powerful programming language. Errors in script files, besides having undesirable side-effects, may cause Geeqie to crash.</para>
+    </warning>
   </section>
-</section>
+</section>
--- a/src/lua.c	Wed Oct 18 17:49:46 2017 +0100
+++ b/src/lua.c	Sun Oct 22 19:39:44 2017 +0100
@@ -113,6 +113,15 @@
 	return 1;
 }
 
+static int lua_image_get_marks(lua_State *L)
+{
+	FileData *fd;
+
+	fd = lua_check_image(L, 1);
+	lua_pushnumber(L, fd->marks);
+	return 1;
+}
+
 static ExifData *lua_check_exif(lua_State *L, int index)
 {
 	ExifData **exif;
@@ -184,6 +193,7 @@
 			{"get_date", lua_image_get_date},
 			{"get_size", lua_image_get_size},
 			{"get_exif", lua_image_get_exif},
+			{"get_marks", lua_image_get_marks},
 			{NULL, NULL}
 	};
 	luaL_register(L, "Image", image_methods);
--- a/src/remote.c	Wed Oct 18 17:49:46 2017 +0100
+++ b/src/remote.c	Sun Oct 22 19:39:44 2017 +0100
@@ -39,6 +39,7 @@
 #include <signal.h>
 #include <errno.h>
 
+#include "glua.h"
 
 #define SERVER_MAX_CLIENTS 8
 
@@ -698,6 +699,37 @@
 		}
 }
 
+static void gr_lua(const gchar *text, GIOChannel *channel, gpointer data)
+{
+	gchar *result = NULL;
+	gchar **lua_command;
+
+	lua_command = g_strsplit(text, ",", 2);
+
+	if (lua_command[0] && lua_command[1])
+		{
+		FileData *fd = file_data_new_group(lua_command[0]);
+		result = g_strdup(lua_callvalue(fd, lua_command[1], NULL));
+		if (result)
+			{
+			g_io_channel_write_chars(channel, result, -1, NULL, NULL);
+			}
+		else
+			{
+			g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
+			}
+		}
+	else
+		{
+		g_io_channel_write_chars(channel, N_("lua error: no data"), -1, NULL, NULL);
+		}
+
+	g_io_channel_write_chars(channel, "\n", -1, NULL, NULL);
+
+	g_strfreev(lua_command);
+	g_free(result);
+}
+
 typedef struct _RemoteCommandEntry RemoteCommandEntry;
 struct _RemoteCommandEntry {
 	gchar *opt_s;
@@ -743,6 +775,7 @@
 	{ "-crr:", "--cache-render-recurse:", gr_cache_render_recurse, TRUE, FALSE, N_("<folder> "), N_("render thumbnails recursively") },
 	{ "-crs:", "--cache-render-shared:", gr_cache_render_standard, TRUE, FALSE, N_("<folder> "), N_(" render thumbnails (see Help)") },
 	{ "-crsr:", "--cache-render-shared-recurse:", gr_cache_render_standard_recurse, TRUE, FALSE, N_("<folder>"), N_(" render thumbnails recursively (see Help)") },
+	{ NULL, "--lua:",               gr_lua,                 TRUE, FALSE, N_("<FILE>,<lua script>"), N_("run lua script on FILE") },
 	{ NULL, NULL, NULL, FALSE, FALSE, NULL, NULL }
 };