Fix #269: External image marks - (--remote --lua)
authorColin Clark <colin.clark@cclark.uk>
Sun, 22 Oct 2017 18:39:44 +0000 (19:39 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sun, 22 Oct 2017 18:39:44 +0000 (19:39 +0100)
https://github.com/BestImageViewer/geeqie/issues/269

Additional lua fn: Image:get_marks()
Additional command line option: --remote --lua:<file>,<lua_script>

doc/docbook/GuideReferenceCommandLine.xml
doc/docbook/GuideReferenceLua.xml
src/lua.c
src/remote.c

index 6c22371..977eabd 100644 (file)
@@ -4,7 +4,8 @@
   <para>\r
     Geeqie is called by the command:\r
     <programlisting>\r
-      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>\r
+      geeqie [options] [path_to_file_or_collection]\r
+      <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>\r
     </programlisting>\r
   </para>\r
   <para>These are the command line options available to Geeqie:</para>\r
               </footnote>\r
             </entry>\r
           </row>\r
+          <row>\r
+            <entry />\r
+            <entry>--lua:&lt;file&gt;,&lt;lua script&gt;</entry>\r
+            <entry>run lua script on file</entry>\r
+          </row>\r
           <row>\r
             <entry>-crsr:&lt;folder&gt;</entry>\r
             <entry>--cache-render-shared-recurse:&lt;folder&gt;</entry>\r
index a032f50..cb6542d 100644 (file)
@@ -4,7 +4,9 @@
   <para>\r
     Lua scripts allow the functionality of Geeqie to be extended. Lua scripts may only be used in conjunction with the\r
     <link linkend="OverlayScreenDisplay">Overlay Screen Display</link>\r
-    .\r
+    and the\r
+    <programlisting xml:space="preserve">geeqie --remote --lua:</programlisting>\r
+    command line option.\r
   </para>\r
   <para />\r
   <para>Some knowledge of the Lua programming language is required.</para>\r
               <entry>Image:get_size()</entry>\r
               <entry>The file size in bytes</entry>\r
             </row>\r
+            <row>\r
+              <entry>Image:get_marks()</entry>\r
+              <entry>An integer representing the marks set for the file</entry>\r
+            </row>\r
             <row>\r
               <entry>Image:get_exif()</entry>\r
               <entry>A data structure containing the entire exif data</entry>\r
   </section>\r
   <section id="Warning">\r
     <title>Warning</title>\r
-    <warning><para>Lua is a powerful programming language. Errors in script files, besides having undesirable side-effects, may cause Geeqie to crash.</para></warning>\r
+    <warning>\r
+      <para>Lua is a powerful programming language. Errors in script files, besides having undesirable side-effects, may cause Geeqie to crash.</para>\r
+    </warning>\r
   </section>\r
-</section>
+</section>\r
index 733ed58..72b02cd 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
@@ -113,6 +113,15 @@ static int lua_image_get_size(lua_State *L)
        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 @@ void lua_init(void)
                        {"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);
index 28a5be4..aa0025e 100644 (file)
@@ -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_raise(const gchar *text, GIOChannel *channel, gpointer data)
                }
 }
 
+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 @@ static RemoteCommandEntry remote_commands[] = {
        { "-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 }
 };