From 99a30398f7184ccbd313f5d589285f343d9eb658 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 30 Jun 2019 12:22:19 +0100 Subject: [PATCH] Enable lua scripts to be called from Info sidebar 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. The output of the script should of course be text. --- doc/docbook/GuideReferenceLua.xml | 4 +++- doc/docbook/GuideSidebarsInfo.xml | 9 ++++++++- src/exif-common.c | 24 ++++++++++++++++++++++++ src/exif.h | 1 + src/metadata.c | 6 ++++++ 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/doc/docbook/GuideReferenceLua.xml b/doc/docbook/GuideReferenceLua.xml index cb6542dc..4a2e8872 100644 --- a/doc/docbook/GuideReferenceLua.xml +++ b/doc/docbook/GuideReferenceLua.xml @@ -4,7 +4,9 @@ Lua scripts allow the functionality of Geeqie to be extended. Lua scripts may only be used in conjunction with the Overlay Screen Display - and the + , + List panes + on the Info Sidebar, and the geeqie --remote --lua: command line option. diff --git a/doc/docbook/GuideSidebarsInfo.xml b/doc/docbook/GuideSidebarsInfo.xml index 498d1550..6e110fd0 100644 --- a/doc/docbook/GuideSidebarsInfo.xml +++ b/doc/docbook/GuideSidebarsInfo.xml @@ -206,7 +206,7 @@ onto any pane. - As an aide, in addition to standard metadata tags, Geeqie provides certain pre-formatted tags. These are: + As an aide, in addition to standard metadata tags, Geeqie can call lua scripts and also provides certain pre-formatted tags. These tags are: @@ -340,6 +340,13 @@ file.linkif the file is a symbolic link, shows the path of the source file + + lua.<lua script> + + Call a lua script + The output is expected to be text. + +
diff --git a/src/exif-common.c b/src/exif-common.c index 9463a5b4..fd2c6a3a 100644 --- a/src/exif-common.c +++ b/src/exif-common.c @@ -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: */ diff --git a/src/exif.h b/src/exif.h index 06dec25a..6e2ca064 100644 --- a/src/exif.h +++ b/src/exif.h @@ -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: */ diff --git a/src/metadata.c b/src/metadata.c index c3ffdbc1..e2e36113 100644 --- a/src/metadata.c +++ b/src/metadata.c @@ -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; -- 2.20.1