Enable lua scripts to be called from Info sidebar
authorColin Clark <colin.clark@cclark.uk>
Sun, 30 Jun 2019 11:22:19 +0000 (12:22 +0100)
committerKlaus Ethgen <Klaus@Ethgen.de>
Fri, 26 Jul 2019 17:54:44 +0000 (18:54 +0100)
A lua script can be called from any of the List Panes in the Info
sidebar.

Add a new entry and in the Key field use:
lua.<lua script name>

The output of the script should of course be text.

doc/docbook/GuideReferenceLua.xml
doc/docbook/GuideSidebarsInfo.xml
src/exif-common.c
src/exif.h
src/metadata.c

index cb6542d..4a2e887 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
-    and the\r
+    ,\r
+    <link linkend="GuideSidebarsInfo" endterm="Listpanes-ExifFileinfoCopyrightLocationandGPS">List panes</link>\r
+    on the Info Sidebar, and the\r
     <programlisting xml:space="preserve">geeqie --remote --lua:</programlisting>\r
     command line option.\r
   </para>\r
index 498d155..6e110fd 100644 (file)
       <link linkend="GuideOtherWindowsExif" endterm="titleGuideOtherWindowsExif" />\r
       onto any pane.\r
     </para>\r
-    <para>As an aide, in addition to standard metadata tags, Geeqie provides certain pre-formatted tags. These are:</para>\r
+    <para>As an aide, in addition to standard metadata tags, Geeqie can call lua scripts and also provides certain pre-formatted tags. These tags are:</para>\r
     <table id="formatted_exif">\r
       <tgroup cols="2" rowsep="1" colsep="1">\r
         <tbody>\r
             <entry>file.link</entry>\r
             <entry>if the file is a symbolic link, shows the path of the source file</entry>\r
           </row>\r
+          <row>\r
+            <entry>lua.&lt;lua script&gt;</entry>\r
+            <entry>\r
+              Call a lua script\r
+              <footnote id='lua_ref1'>The output is expected to be text.</footnote>\r
+            </entry>\r
+          </row>\r
         </tbody>\r
       </tgroup>\r
     </table>\r
index 9463a5b..fd2c6a3 100644 (file)
@@ -53,6 +53,7 @@
 #include "filefilter.h"
 #include "filecache.h"
 #include "format_raw.h"
+#include "glua.h"
 #include "ui_fileops.h"
 #include "cache.h"
 #include "jpeg_parser.h"
@@ -1218,5 +1219,28 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format)
        return g_strdup("");
 }
 
+#ifdef HAVE_LUA
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat format)
+{
+       gchar *script_name;
+       gchar *script_name_utf8;
+       gchar *data;
+       gchar *raw_data;
+       gchar *valid_data;
+
+       script_name_utf8 = g_strdup(key + 4);
+       script_name = path_from_utf8(script_name_utf8);
+
+       raw_data = lua_callvalue(fd, script_name, NULL);
+       valid_data = g_utf8_make_valid(raw_data, -1);
+       data = g_utf8_substring(valid_data, 0, 150);
 
+       g_free(script_name);
+       g_free(script_name_utf8);
+       g_free(raw_data);
+       g_free(valid_data);
+
+       return data;
+}
+#endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index 06dec25..6e2ca06 100644 (file)
@@ -167,6 +167,7 @@ guchar *exif_get_preview(ExifData *exif, guint *data_len, gint requested_width,
 void exif_free_preview(guchar *buf);
 
 gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format);
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat format);
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
index c3ffdbc..e2e3611 100644 (file)
@@ -709,6 +709,12 @@ GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format)
                {
                return g_list_append(NULL, metadata_file_info(fd, key, format));
                }
+#ifdef HAVE_LUA
+       else if (strncmp(key, "lua.", 4) == 0)
+               {
+               return g_list_append(NULL, metadata_lua_info(fd, key, format));
+               }
+#endif
 
        exif = exif_read_fd(fd); /* this is cached, thus inexpensive */
        if (!exif) return NULL;