From 4d6dfea3a5e977264c914bdb3ccde983fc4073a9 Mon Sep 17 00:00:00 2001
From: BzKevin <36381472+BzKevin@users.noreply.github.com>
Date: Wed, 13 Feb 2019 12:23:34 -0500
Subject: [PATCH 01/15] Add CollectHelper
---
contrib/CollectHelper.lua | 199 ++++++++++++++++++++++++++++++++++++++
1 file changed, 199 insertions(+)
create mode 100644 contrib/CollectHelper.lua
diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua
new file mode 100644
index 0000000..37e9a8e
--- /dev/null
+++ b/contrib/CollectHelper.lua
@@ -0,0 +1,199 @@
+--[[Collect Helper plugin for darktable
+
+ copyright (c) 2019 Kevin Ertel
+
+ darktable is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ darktable is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with darktable. If not, see .
+]]
+
+--[[About this plugin
+This plugin adds the button(s) to the "Selected Images" module:
+1) Return to Previous Collection
+2) Collect on image's Folder
+3) Collect on image's Color Label(s)
+4) Collect on All (AND)
+
+It also adds 3 preferences to the lua options dialog box which allow the user to activate/deactivate the 3 "Collect on" buttons.
+
+Button Behavior:
+1) Return to Previous Collection - Will reset the collect parameters to the previously active settings
+2) Collect on image's Folder - Will change the collect parameters to be "Folder" with a value of the selected image's folder location
+3) Collect on image's Color Label(s) - Will change the collect parameter to be "Color" with a value of the selected images color labels, will apply multiple parameters with AND logic if multiple exist
+4) Collect on All (AND) - Will collect on all parameters activated by the preferences dialog, as such this button is redundant if you only have one of the two other options enabled
+
+----REQUIRED SOFTWARE----
+NA
+
+----USAGE----
+Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
+ 1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
+ 2) Require this file in your luarc file, as with any other dt plug-in
+
+Select the photo you wish to change you collection based on.
+In the "Selected Images" module click on "Collect on this Image"
+
+----KNOWN ISSUES----
+]]
+
+local dt = require "darktable"
+previous = nil
+all_active = false
+
+-- FUNCTION --
+local function CheckSingleImage(selection)
+ if #selection ~= 1 then
+ dt.print("Please select a single image")
+ return 1
+ end
+ return 0
+end
+local function PreviousCollection()
+ if previous ~= nil then
+ previous = dt.gui.libs.collect.filter(previous)
+ end
+end
+local function CollectOnFolder()
+ local images = dt.gui.selection()
+ if CheckSingleImage(images) == 1 then
+ return
+ end
+ rules = {}
+ all_rules = {}
+ rule = dt.gui.libs.collect.new_rule()
+ rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ rule.data = images[1].path
+ rule.item = "DT_COLLECTION_PROP_FOLDERS"
+ table.insert(rules, rule)
+ if all_active then
+ for _,active_rule in pairs(rules) do
+ table.insert(all_rules, active_rule)
+ end
+ else
+ previous = dt.gui.libs.collect.filter(rules)
+ end
+end
+local function CollectOnColors()
+ local images = dt.gui.selection()
+ if CheckSingleImage(images) == 1 then
+ return
+ end
+ for _,image in pairs(images) do
+ rules = {}
+ if image.red then
+ red_rule = dt.gui.libs.collect.new_rule()
+ red_rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ red_rule.data = "red"
+ red_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
+ table.insert(rules, red_rule)
+ end
+ if image.blue then
+ blue_rule = dt.gui.libs.collect.new_rule()
+ blue_rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ blue_rule.data = "blue"
+ blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
+ table.insert(rules, blue_rule)
+ end
+ if image.green then
+ green_rule = dt.gui.libs.collect.new_rule()
+ green_rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ green_rule.data = "green"
+ green_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
+ table.insert(rules, green_rule)
+ end
+ if image.yellow then
+ yellow_rule = dt.gui.libs.collect.new_rule()
+ yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ yellow_rule.data = "yellow"
+ yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
+ table.insert(rules, yellow_rule)
+ end
+ if image.purple then
+ purple_rule = dt.gui.libs.collect.new_rule()
+ purple_rule.mode = "DT_LIB_COLLECT_MODE_AND"
+ purple_rule.data = "purple"
+ purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
+ table.insert(rules, purple_rule)
+ end
+ if all_active then
+ for _,active_rule in pairs(rules) do
+ table.insert(all_rules, active_rule)
+ end
+ else
+ previous = dt.gui.libs.collect.filter(rules)
+ end
+ end
+end
+local function CollectOnAll_AND()
+ local images = dt.gui.selection()
+ if CheckSingleImage(images) == 1 then
+ return
+ end
+ all_rules = {}
+ all_active = true
+ if dt.preferences.read('module_CollectHelper','folder','bool') then
+ CollectOnFolder()
+ end
+ if dt.preferences.read('module_CollectHelper','colors','bool') then
+ CollectOnColors()
+ end
+ all_active = false
+ previous = dt.gui.libs.collect.filter(all_rules)
+end
+
+-- GUI --
+dt.gui.libs.image.register_action(
+ "Return to Previous Collection",
+ function() PreviousCollection() end,
+ "Sets the Collect parameters to be the previously active parameters"
+)
+if dt.preferences.read('module_CollectHelper','folder','bool') then
+ dt.gui.libs.image.register_action(
+ "Collect on image's Folder",
+ function() CollectOnFolder() end,
+ "Sets the Collect parameters to be the selected images's folder"
+ )
+end
+if dt.preferences.read('module_CollectHelper','colors','bool') then
+ dt.gui.libs.image.register_action(
+ "Collect on image's Color Label(s)",
+ function() CollectOnColors() end,
+ "Sets the Collect parameters to be the selected images's color label(s)"
+ )
+end
+if dt.preferences.read('module_CollectHelper','all_and','bool') then
+ dt.gui.libs.image.register_action(
+ "Collect on All (AND)",
+ function() CollectOnAll_AND() end,
+ "Sets the Collect parameters based on all activated CollectHelper options"
+ )
+end
+
+-- PREFERENCES --
+dt.preferences.register("module_CollectHelper", "all_and", -- name
+ "bool", -- type
+ 'CollectHelper: All', -- label
+ 'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip
+ true -- default
+)
+dt.preferences.register("module_CollectHelper", "colors", -- name
+ "bool", -- type
+ 'CollectHelper: Color Label(s)', -- label
+ 'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip
+ true -- default
+)
+dt.preferences.register("module_CollectHelper", "folder", -- name
+ "bool", -- type
+ 'CollectHelper: Folder', -- label
+ 'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
+ true -- default
+)
\ No newline at end of file
From ff0352cfe644c568e720f876b2f758049007edd5 Mon Sep 17 00:00:00 2001
From: BzKevin <36381472+BzKevin@users.noreply.github.com>
Date: Wed, 13 Feb 2019 13:42:54 -0500
Subject: [PATCH 02/15] Updated version of Collect Helper
Reworded the button text to better match with the rest of darktable's buttons
---
contrib/CollectHelper.lua | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua
index 37e9a8e..fabe4c9 100644
--- a/contrib/CollectHelper.lua
+++ b/contrib/CollectHelper.lua
@@ -152,27 +152,27 @@ end
-- GUI --
dt.gui.libs.image.register_action(
- "Return to Previous Collection",
+ "collect: previous",
function() PreviousCollection() end,
"Sets the Collect parameters to be the previously active parameters"
)
if dt.preferences.read('module_CollectHelper','folder','bool') then
dt.gui.libs.image.register_action(
- "Collect on image's Folder",
+ "collect: folder",
function() CollectOnFolder() end,
"Sets the Collect parameters to be the selected images's folder"
)
end
if dt.preferences.read('module_CollectHelper','colors','bool') then
dt.gui.libs.image.register_action(
- "Collect on image's Color Label(s)",
+ "collect: color label(s)",
function() CollectOnColors() end,
"Sets the Collect parameters to be the selected images's color label(s)"
)
end
if dt.preferences.read('module_CollectHelper','all_and','bool') then
dt.gui.libs.image.register_action(
- "Collect on All (AND)",
+ "collect: all (AND)",
function() CollectOnAll_AND() end,
"Sets the Collect parameters based on all activated CollectHelper options"
)
From b682284a2a8433ec856a52601b26d8b945df9778 Mon Sep 17 00:00:00 2001
From: BzKevin <36381472+BzKevin@users.noreply.github.com>
Date: Fri, 15 Feb 2019 14:08:04 -0500
Subject: [PATCH 03/15] Update with 'local' variable designation
Updated variable definitions with 'local' designation. Doing so slightly broke the script so I modified the function calls a tad to pass variables in and out as needed for "CollectOnAll" function to work.
---
contrib/CollectHelper.lua | 53 +++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua
index fabe4c9..3684686 100644
--- a/contrib/CollectHelper.lua
+++ b/contrib/CollectHelper.lua
@@ -46,30 +46,29 @@ In the "Selected Images" module click on "Collect on this Image"
]]
local dt = require "darktable"
-previous = nil
-all_active = false
+local previous = nil
+local all_active = false
-- FUNCTION --
local function CheckSingleImage(selection)
if #selection ~= 1 then
dt.print("Please select a single image")
- return 1
+ return true
end
- return 0
+ return false
end
local function PreviousCollection()
if previous ~= nil then
previous = dt.gui.libs.collect.filter(previous)
end
end
-local function CollectOnFolder()
+local function CollectOnFolder(all_rules, all_active)
local images = dt.gui.selection()
- if CheckSingleImage(images) == 1 then
+ if CheckSingleImage(images) then
return
end
- rules = {}
- all_rules = {}
- rule = dt.gui.libs.collect.new_rule()
+ local rules = {}
+ local rule = dt.gui.libs.collect.new_rule()
rule.mode = "DT_LIB_COLLECT_MODE_AND"
rule.data = images[1].path
rule.item = "DT_COLLECTION_PROP_FOLDERS"
@@ -78,47 +77,48 @@ local function CollectOnFolder()
for _,active_rule in pairs(rules) do
table.insert(all_rules, active_rule)
end
+ return all_rules
else
previous = dt.gui.libs.collect.filter(rules)
end
end
-local function CollectOnColors()
+local function CollectOnColors(all_rules, all_active)
local images = dt.gui.selection()
- if CheckSingleImage(images) == 1 then
+ if CheckSingleImage(images) then
return
end
for _,image in pairs(images) do
- rules = {}
+ local rules = {}
if image.red then
- red_rule = dt.gui.libs.collect.new_rule()
+ local red_rule = dt.gui.libs.collect.new_rule()
red_rule.mode = "DT_LIB_COLLECT_MODE_AND"
red_rule.data = "red"
red_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
table.insert(rules, red_rule)
end
if image.blue then
- blue_rule = dt.gui.libs.collect.new_rule()
+ local blue_rule = dt.gui.libs.collect.new_rule()
blue_rule.mode = "DT_LIB_COLLECT_MODE_AND"
blue_rule.data = "blue"
blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
table.insert(rules, blue_rule)
end
if image.green then
- green_rule = dt.gui.libs.collect.new_rule()
+ local green_rule = dt.gui.libs.collect.new_rule()
green_rule.mode = "DT_LIB_COLLECT_MODE_AND"
green_rule.data = "green"
green_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
table.insert(rules, green_rule)
end
if image.yellow then
- yellow_rule = dt.gui.libs.collect.new_rule()
+ local yellow_rule = dt.gui.libs.collect.new_rule()
yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND"
yellow_rule.data = "yellow"
yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
table.insert(rules, yellow_rule)
end
if image.purple then
- purple_rule = dt.gui.libs.collect.new_rule()
+ local purple_rule = dt.gui.libs.collect.new_rule()
purple_rule.mode = "DT_LIB_COLLECT_MODE_AND"
purple_rule.data = "purple"
purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
@@ -128,6 +128,7 @@ local function CollectOnColors()
for _,active_rule in pairs(rules) do
table.insert(all_rules, active_rule)
end
+ return all_rules
else
previous = dt.gui.libs.collect.filter(rules)
end
@@ -135,19 +136,17 @@ local function CollectOnColors()
end
local function CollectOnAll_AND()
local images = dt.gui.selection()
- if CheckSingleImage(images) == 1 then
+ if CheckSingleImage(images) then
return
end
- all_rules = {}
- all_active = true
+ local rules = {}
if dt.preferences.read('module_CollectHelper','folder','bool') then
- CollectOnFolder()
+ rules = CollectOnFolder(rules, true)
end
if dt.preferences.read('module_CollectHelper','colors','bool') then
- CollectOnColors()
+ rules = CollectOnColors(rules, true)
end
- all_active = false
- previous = dt.gui.libs.collect.filter(all_rules)
+ previous = dt.gui.libs.collect.filter(rules)
end
-- GUI --
@@ -159,14 +158,14 @@ dt.gui.libs.image.register_action(
if dt.preferences.read('module_CollectHelper','folder','bool') then
dt.gui.libs.image.register_action(
"collect: folder",
- function() CollectOnFolder() end,
+ function() CollectOnFolder(_ , false) end,
"Sets the Collect parameters to be the selected images's folder"
)
end
if dt.preferences.read('module_CollectHelper','colors','bool') then
dt.gui.libs.image.register_action(
"collect: color label(s)",
- function() CollectOnColors() end,
+ function() CollectOnColors(_ , false) end,
"Sets the Collect parameters to be the selected images's color label(s)"
)
end
@@ -196,4 +195,4 @@ dt.preferences.register("module_CollectHelper", "folder", -- name
'CollectHelper: Folder', -- label
'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
true -- default
-)
\ No newline at end of file
+)
From 5ff36fe2ec6d55f94f60d424fd149eb60d486f0a Mon Sep 17 00:00:00 2001
From: Bill Ferguson
Date: Tue, 26 Feb 2019 12:03:04 -0500
Subject: [PATCH 04/15] Added a space after the commands and removed quotes in
the command invocation.
---
lib/dtutils/system.lua | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/dtutils/system.lua b/lib/dtutils/system.lua
index 418a59d..69a7f69 100644
--- a/lib/dtutils/system.lua
+++ b/lib/dtutils/system.lua
@@ -120,13 +120,13 @@ dtutils_system.libdoc.functions["launch_default_app"] = {
Copyright = [[]],
}
function dtutils_system.launch_default_app(path)
- local open_cmd = "xdg-open"
+ local open_cmd = "xdg-open "
if (dt.configuration.running_os == "windows") then
- open_cmd = "start"
+ open_cmd = "start "
elseif (dt.configuration.running_os == "macos") then
- open_cmd = "open"
+ open_cmd = "open "
end
- return dtutils_system.external_command(open_cmd..' "'..path..'"')
+ return dtutils_system.external_command(open_cmd .. path)
end
From 9e0490d37158118858251dedaa10e2e7aef6578e Mon Sep 17 00:00:00 2001
From: BzKevin <36381472+BzKevin@users.noreply.github.com>
Date: Tue, 26 Feb 2019 14:30:11 -0500
Subject: [PATCH 05/15] Add gettext, check for color label
Add translate-ability. Also adds a check that the selected image has an active color label and displays a message if it does not
---
contrib/CollectHelper.lua | 53 ++++++++++++++++++++++++++++-----------
1 file changed, 38 insertions(+), 15 deletions(-)
diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua
index 3684686..bd58ce7 100644
--- a/contrib/CollectHelper.lua
+++ b/contrib/CollectHelper.lua
@@ -46,17 +46,36 @@ In the "Selected Images" module click on "Collect on this Image"
]]
local dt = require "darktable"
+local gettext = dt.gettext
local previous = nil
local all_active = false
+-- Tell gettext where to find the .mo file translating messages for a particular domain
+gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")
+
+local function _(msgid)
+ return gettext.dgettext("CollectHelper", msgid)
+end
+
-- FUNCTION --
local function CheckSingleImage(selection)
if #selection ~= 1 then
- dt.print("Please select a single image")
+ dt.print(_("Please select a single image"))
return true
end
return false
end
+local function CheckHasColorLabel(selection)
+ local ret = false
+ for _,image in pairs(selection) do
+ if image.red then ret = true end
+ if image.blue then ret = true end
+ if image.green then ret = true end
+ if image.yellow then ret = true end
+ if image.purple then ret = true end
+ end
+ return ret
+end
local function PreviousCollection()
if previous ~= nil then
previous = dt.gui.libs.collect.filter(previous)
@@ -87,6 +106,10 @@ local function CollectOnColors(all_rules, all_active)
if CheckSingleImage(images) then
return
end
+ if not CheckHasColorLabel(images) then
+ dt.print(_('select an image with an active color label'))
+ return
+ end
for _,image in pairs(images) do
local rules = {}
if image.red then
@@ -151,48 +174,48 @@ end
-- GUI --
dt.gui.libs.image.register_action(
- "collect: previous",
+ _("collect: previous"),
function() PreviousCollection() end,
- "Sets the Collect parameters to be the previously active parameters"
+ _("Sets the Collect parameters to be the previously active parameters")
)
if dt.preferences.read('module_CollectHelper','folder','bool') then
dt.gui.libs.image.register_action(
- "collect: folder",
+ _("collect: folder"),
function() CollectOnFolder(_ , false) end,
- "Sets the Collect parameters to be the selected images's folder"
+ _("Sets the Collect parameters to be the selected images's folder")
)
end
if dt.preferences.read('module_CollectHelper','colors','bool') then
dt.gui.libs.image.register_action(
- "collect: color label(s)",
+ _("collect: color label(s)"),
function() CollectOnColors(_ , false) end,
- "Sets the Collect parameters to be the selected images's color label(s)"
+ _("Sets the Collect parameters to be the selected images's color label(s)")
)
end
if dt.preferences.read('module_CollectHelper','all_and','bool') then
dt.gui.libs.image.register_action(
- "collect: all (AND)",
+ _("collect: all (AND)"),
function() CollectOnAll_AND() end,
- "Sets the Collect parameters based on all activated CollectHelper options"
+ _("Sets the Collect parameters based on all activated CollectHelper options")
)
end
-- PREFERENCES --
dt.preferences.register("module_CollectHelper", "all_and", -- name
"bool", -- type
- 'CollectHelper: All', -- label
- 'Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)', -- tooltip
+ _('CollectHelper: All'), -- label
+ _('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip
true -- default
)
dt.preferences.register("module_CollectHelper", "colors", -- name
"bool", -- type
- 'CollectHelper: Color Label(s)', -- label
- 'Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)', -- tooltip
+ _('CollectHelper: Color Label(s)'), -- label
+ _('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip
true -- default
)
dt.preferences.register("module_CollectHelper", "folder", -- name
"bool", -- type
- 'CollectHelper: Folder', -- label
- 'Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location', -- tooltip
+ _('CollectHelper: Folder'), -- label
+ _('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip
true -- default
)
From 9183beeed4d9a4960fb973a2c35abba5bff12b86 Mon Sep 17 00:00:00 2001
From: supertobi
Date: Wed, 27 Feb 2019 09:57:36 +0100
Subject: [PATCH 06/15] video_ffmpeg add df.sanitize_filename()
I'm not 100% sure, but I think we need the df.sanitize_filename() here.
---
contrib/video_ffmpeg.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/video_ffmpeg.lua b/contrib/video_ffmpeg.lua
index d561d55..af797e5 100644
--- a/contrib/video_ffmpeg.lua
+++ b/contrib/video_ffmpeg.lua
@@ -441,7 +441,7 @@ local function finalize_export(storage, images_table, extra_data)
else
dt.print(_("SUCCESS"))
if extra_data["open_after_export"] then
- dsys.launch_default_app(path)
+ dsys.launch_default_app(df.sanitize_filename(path))
end
end
From 11881b3b73229b4742687781a54db40cdbd17811 Mon Sep 17 00:00:00 2001
From: Bill Ferguson
Date: Wed, 27 Feb 2019 13:29:29 -0500
Subject: [PATCH 07/15] removed sanitize_filename wrapper from path argument
---
lib/dtutils/file.lua | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/dtutils/file.lua b/lib/dtutils/file.lua
index e9fc36f..69243e9 100644
--- a/lib/dtutils/file.lua
+++ b/lib/dtutils/file.lua
@@ -576,13 +576,13 @@ dtutils_file.libdoc.functions["mkdir"] = {
function dtutils_file.mkdir(path)
if not dtutils_file.check_if_file_exists(path) then
local mkdir_cmd = dt.configuration.running_os == "windows" and "mkdir" or "mkdir -p"
- return dsys.external_command(mkdir_cmd.." "..dtutils_file.sanitize_filename(path))
+ return dsys.external_command(mkdir_cmd.." "..path)
else
return 0
end
end
-dtutils_file.libdoc.functions["rm"] = {
+dtutils_file.libdoc.functions["rmdir"] = {
Name = [[rmdir]],
Synopsis = [[recursively remove a directory]],
Usage = [[local df = require "lib/dtutils.file"
@@ -601,7 +601,7 @@ dtutils_file.libdoc.functions["rm"] = {
function dtutils_file.rmdir(path)
local rm_cmd = dt.configuration.running_os == "windows" and "rmdir /S /Q" or "rm -r"
- return dsys.external_command(rm_cmd.." "..dtutils_file.sanitize_filename(path))
+ return dsys.external_command(rm_cmd.." "..path)
end
From 24862a26f23fe18e971283f60f8e0e23e7a1b16b Mon Sep 17 00:00:00 2001
From: supertobi
Date: Thu, 28 Feb 2019 11:41:56 +0100
Subject: [PATCH 08/15] viedeo_ffmpeg df.sanitize_filename()
viedeo_ffmpeg df.sanitize_filename() for mkdir and rmdir
---
contrib/video_ffmpeg.lua | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/video_ffmpeg.lua b/contrib/video_ffmpeg.lua
index af797e5..4fbce4a 100644
--- a/contrib/video_ffmpeg.lua
+++ b/contrib/video_ffmpeg.lua
@@ -412,7 +412,7 @@ local function export(extra_data)
local img_ext = extra_data["img_ext"]
local output_file = extra_data["output_file"]
- local dir_create_result = df.mkdir(df.get_path(output_file))
+ local dir_create_result = df.mkdir(df.sanitize_filename(df.get_path(output_file)))
if dir_create_result ~= 0 then return dir_create_result end
local cmd = ffmpeg_path.." -y -r "..fps.." -i "..dir..PS.."%d"..img_ext.." -s:v "..res.." -c:v "..codec.." -crf 18 -preset veryslow "..df.sanitize_filename(output_file)
@@ -424,7 +424,7 @@ local function finalize_export(storage, images_table, extra_data)
dt.print(_("prepare merge process"))
- local result = df.mkdir(tmp_dir)
+ local result = df.mkdir(df.sanitize_filename())
if result ~= 0 then dt.print(_("ERROR: cannot create temp directory")) end
local images = extra_data["images"]
@@ -445,7 +445,7 @@ local function finalize_export(storage, images_table, extra_data)
end
end
- df.rmdir(tmp_dir)
+ df.rmdir(df.sanitize_filename(tmp_dir))
end
dt.register_storage(
From 287d9e94cf791fe2e81ca7e8807e53ebaaca5de5 Mon Sep 17 00:00:00 2001
From: supertobi
Date: Thu, 28 Feb 2019 13:22:10 +0100
Subject: [PATCH 09/15] video_ffmpeg
I forgot the argument
---
contrib/video_ffmpeg.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/video_ffmpeg.lua b/contrib/video_ffmpeg.lua
index 4fbce4a..6755e5c 100644
--- a/contrib/video_ffmpeg.lua
+++ b/contrib/video_ffmpeg.lua
@@ -424,7 +424,7 @@ local function finalize_export(storage, images_table, extra_data)
dt.print(_("prepare merge process"))
- local result = df.mkdir(df.sanitize_filename())
+ local result = df.mkdir(df.sanitize_filename(tmp_dir))
if result ~= 0 then dt.print(_("ERROR: cannot create temp directory")) end
local images = extra_data["images"]
From bd3a74954c14bd7d4200c8a74350aec3b1538b50 Mon Sep 17 00:00:00 2001
From: BzKevin <36381472+BzKevin@users.noreply.github.com>
Date: Thu, 28 Feb 2019 15:08:57 -0500
Subject: [PATCH 10/15] gettext incorrectly pointed to "gimp"
---
contrib/CollectHelper.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua
index bd58ce7..5996592 100644
--- a/contrib/CollectHelper.lua
+++ b/contrib/CollectHelper.lua
@@ -51,7 +51,7 @@ local previous = nil
local all_active = false
-- Tell gettext where to find the .mo file translating messages for a particular domain
-gettext.bindtextdomain("gimp",dt.configuration.config_dir.."/lua/locale/")
+gettext.bindtextdomain("CollectHelper",dt.configuration.config_dir.."/lua/locale/")
local function _(msgid)
return gettext.dgettext("CollectHelper", msgid)
From fa25ec4a2690fa3048a4489c31e0df726742dc6f Mon Sep 17 00:00:00 2001
From: supertobi
Date: Fri, 1 Mar 2019 23:27:26 +0100
Subject: [PATCH 11/15] OpenInExplorer Tap to Space
---
contrib/OpenInExplorer.lua | 52 +++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/contrib/OpenInExplorer.lua b/contrib/OpenInExplorer.lua
index 380838b..edab7b6 100644
--- a/contrib/OpenInExplorer.lua
+++ b/contrib/OpenInExplorer.lua
@@ -43,39 +43,39 @@ du.check_min_api_version("5.0.0", "OpenInExplorer")
--Detect OS and modify accordingly--
local proper_install = false
if dt.configuration.running_os == "windows" then
- proper_install = true
+ proper_install = true
else
- dt.print_error('OpenInExplorer plug-in only supports Windows OS at this time')
- return
+ dt.print_error('OpenInExplorer plug-in only supports Windows OS at this time')
+ return
end
-- FUNCTION --
local function OpenInExplorer() --Open in Explorer
- --Inits--
- if not proper_install then
- return
- end
- local images = dt.gui.selection()
- local curr_image = ""
- if #images == 0 then
- dt.print('please select an image')
- elseif #images <= 15 then
- for _,image in pairs(images) do
- curr_image = image.path..'\\'..image.filename
- local run_cmd = "explorer.exe /select, "..curr_image
- dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
- resp = dsys.external_command(run_cmd)
- end
- else
- dt.print('please select fewer images (max 15)')
- end
+ --Inits--
+ if not proper_install then
+ return
+ end
+ local images = dt.gui.selection()
+ local curr_image = ""
+ if #images == 0 then
+ dt.print('please select an image')
+ elseif #images <= 15 then
+ for _,image in pairs(images) do
+ curr_image = image.path..'\\'..image.filename
+ local run_cmd = "explorer.exe /select, "..curr_image
+ dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
+ resp = dsys.external_command(run_cmd)
+ end
+ else
+ dt.print('please select fewer images (max 15)')
+ end
end
-- GUI --
if proper_install then
- dt.gui.libs.image.register_action(
- "show in file explorer",
- function() OpenInExplorer() end,
- "Opens File Explorer at the selected image's location"
- )
+ dt.gui.libs.image.register_action(
+ "show in file explorer",
+ function() OpenInExplorer() end,
+ "Opens File Explorer at the selected image's location"
+ )
end
From 2e5e2e9f0de493cb525aee8f7ebe337331fdaef5 Mon Sep 17 00:00:00 2001
From: supertobi
Date: Fri, 1 Mar 2019 23:30:58 +0100
Subject: [PATCH 12/15] OpenInExplorer added Nautilus support
---
contrib/OpenInExplorer.lua | 56 ++++++++++++++++++++++++++++++--------
1 file changed, 44 insertions(+), 12 deletions(-)
diff --git a/contrib/OpenInExplorer.lua b/contrib/OpenInExplorer.lua
index edab7b6..1dbe4d6 100644
--- a/contrib/OpenInExplorer.lua
+++ b/contrib/OpenInExplorer.lua
@@ -1,4 +1,5 @@
---[[OpenInExplorer plugin for darktable
+--[[
+OpenInExplorer plugin for darktable
copyright (c) 2018 Kevin Ertel
@@ -20,7 +21,7 @@
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
----REQUIRED SOFTWARE----
-Microsoft Windows Operating System
+Microsoft Windows or Linux with installed Nautilus
----USAGE----
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
@@ -35,33 +36,34 @@ A file explorer window will be opened for each selected file at the file's locat
local dt = require "darktable"
local du = require "lib/dtutils"
+local df = require "lib/dtutils.file"
local dsys = require "lib/dtutils.system"
--Check API version
du.check_min_api_version("5.0.0", "OpenInExplorer")
+local PS = dt.configuration.running_os == "windows" and "\\" or "/"
+
--Detect OS and modify accordingly--
local proper_install = false
-if dt.configuration.running_os == "windows" then
+if dt.configuration.running_os ~= "macos" then
proper_install = true
else
- dt.print_error('OpenInExplorer plug-in only supports Windows OS at this time')
+ dt.print_error('OpenInExplorer plug-in only supports Windows and Linux at this time')
return
end
--- FUNCTION --
-local function OpenInExplorer() --Open in Explorer
- --Inits--
- if not proper_install then
- return
- end
+
+-- FUNCTIONS --
+
+local function open_in_explorer() --Open in Explorer
local images = dt.gui.selection()
local curr_image = ""
if #images == 0 then
dt.print('please select an image')
elseif #images <= 15 then
for _,image in pairs(images) do
- curr_image = image.path..'\\'..image.filename
+ curr_image = image.path..PS..image.filename
local run_cmd = "explorer.exe /select, "..curr_image
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
resp = dsys.external_command(run_cmd)
@@ -71,11 +73,41 @@ local function OpenInExplorer() --Open in Explorer
end
end
+local function open_in_nautilus() --Open in Nautilus
+ local images = dt.gui.selection()
+ local curr_image = ""
+ if #images == 0 then
+ dt.print('please select an image')
+ elseif #images <= 15 then
+ for _,image in pairs(images) do
+ curr_image = image.path..PS..image.filename
+ local run_cmd = "nautilus --select " .. df.sanitize_filename(curr_image)
+ dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
+ resp = dsys.external_command(run_cmd)
+ end
+ else
+ dt.print('please select fewer images (max 15)')
+ end
+end
+
+local function open_in_filemanager() --Open
+ --Inits--
+ if not proper_install then
+ return
+ end
+
+ if (dt.configuration.running_os == "windows") then
+ open_in_explorer()
+ elseif (dt.configuration.running_os == "linux") then
+ open_in_nautilus()
+ end
+end
+
-- GUI --
if proper_install then
dt.gui.libs.image.register_action(
"show in file explorer",
- function() OpenInExplorer() end,
+ function() open_in_filemanager() end,
"Opens File Explorer at the selected image's location"
)
end
From 49c4406bb43c3b8dc265f25f2dc3c27afb929252 Mon Sep 17 00:00:00 2001
From: supertobi
Date: Sun, 3 Mar 2019 17:41:04 +0100
Subject: [PATCH 13/15] Update video_mencoder.lua
fix linebrakes
---
contrib/video_mencoder.lua | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contrib/video_mencoder.lua b/contrib/video_mencoder.lua
index 93b2792..71c8a4d 100644
--- a/contrib/video_mencoder.lua
+++ b/contrib/video_mencoder.lua
@@ -51,9 +51,9 @@ end
local function create_video_mencoder(storage, image_table, extra_data)
dt.print("video_mencoder is deprecated. Please use video_ffmpeg instead. Please see the log for more details.")
- dt.print_log("The mencoder executable is no longer distributed as part of most distributions,\n
- therefore video_mencoder is deprecated. video_ffmpeg should be used in it's place. video_mencoder\n
- will be removed when darktable 2.8 is released.")
+ dt.print_log("The mencoder executable is no longer distributed as part of most distributions,")
+ dt.print_log("therefore video_mencoder is deprecated. video_ffmpeg should be used in it's place. video_mencoder")
+ dt.print_log("will be removed when darktable 2.8 is released.")
if not df.check_if_bin_exists("mencoder") then
dt.print_error(_("mencoder not found"))
return
From bf6e180291551f7d1b0e60605b8ab83de39b4762 Mon Sep 17 00:00:00 2001
From: Bill Ferguson
Date: Thu, 28 Mar 2019 20:13:08 -0400
Subject: [PATCH 14/15] Fixed bug that caused the lua executale path to not
split correctly on windows. Preferences are stored internally with forward
slashes, not O/S specific path separators.
---
tools/executable_manager.lua | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/executable_manager.lua b/tools/executable_manager.lua
index 5f79074..03e35f6 100644
--- a/tools/executable_manager.lua
+++ b/tools/executable_manager.lua
@@ -112,7 +112,7 @@ local exec_table = {}
for _,pref in ipairs(matches) do
local parts = du.split(pref, "=")
- local tmp = du.split(parts[1], PS)
+ local tmp = du.split(parts[1], "/") -- preferences are stored with forward slashes
table.insert(exec_table, tmp[#tmp])
end
From a383d1ebf8b7195a6e0ea449b0e926f16c4eb5e2 Mon Sep 17 00:00:00 2001
From: supertobi
Date: Mon, 15 Apr 2019 15:48:31 +0200
Subject: [PATCH 15/15] Update kml_export.lua
Works with Windows
---
contrib/kml_export.lua | 323 +++++++++++++----------------------------
1 file changed, 102 insertions(+), 221 deletions(-)
diff --git a/contrib/kml_export.lua b/contrib/kml_export.lua
index 7ba7dbf..4a1d5e2 100644
--- a/contrib/kml_export.lua
+++ b/contrib/kml_export.lua
@@ -20,17 +20,14 @@
darktable KML export script
ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
-* mkdir
-* zip (only if you create KMZ files)
-* convert (ImageMagick)
-* xdg-open
-* xdg-user-dir
+* zip (at the moment Linux only and only if you create KMZ files)
+* magick (ImageMagick)
+* xdg-user-dir (Linux)
WARNING
This script is only tested with Linux
USAGE
-* require script "official/yield" from your main Lua file in the first line
* require this script from your main Lua file
* when choosing file format, pick JPEG or PNG as Google Earth doesn't support other formats
@@ -39,12 +36,14 @@ USAGE
local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"
-require "official/yield"
+local ds = require "lib/dtutils.string"
+local dsys = require "lib/dtutils.system"
+
local gettext = dt.gettext
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
-du.check_min_api_version("3.0.0", kml_export)
+du.check_min_api_version("5.0.0", kml_export)
-- Tell gettext where to find the .mo file translating messages for a particular domain
gettext.bindtextdomain("kml_export",dt.configuration.config_dir.."/lua/locale/")
@@ -53,168 +52,10 @@ local function _(msgid)
return gettext.dgettext("kml_export", msgid)
end
--- Sort a table
-local function spairs(_table, order) -- Code copied from http://stackoverflow.com/questions/15706270/sort-a-table-in-lua
- -- collect the keys
- local keys = {}
- for _key in pairs(_table) do keys[#keys + 1] = _key end
-
- -- if order function given, sort by it by passing the table and keys a, b,
- -- otherwise just sort the keys
- if order then
- table.sort(keys, function(a,b) return order(_table, a, b) end)
- else
- table.sort(keys)
- end
-
- -- return the iterator function
- local i = 0
- return function()
- i = i + 1
- if keys[i] then
- return keys[i], _table[keys[i]]
- end
- end
-end
-
local function show_status(storage, image, format, filename, number, total, high_quality, extra_data)
dt.print(string.format(_("Export Image %i/%i"), number, total))
end
--- Strip accents from a string
--- Copied from https://forums.coronalabs.com/topic/43048-remove-special-characters-from-string/
-function string.stripAccents( str )
- local tableAccents = {}
- -- A
- tableAccents["à"] = "a"
- tableAccents["À"] = "A"
- tableAccents["á"] = "a"
- tableAccents["Á"] = "A"
- tableAccents["â"] = "a"
- tableAccents["Â"] = "A"
- tableAccents["ã"] = "a"
- tableAccents["Ã"] = "A"
- tableAccents["ä"] = "a"
- tableAccents["Ä"] = "A"
- -- B
- -- C
- tableAccents["ç"] = "c"
- tableAccents["Ç"] = "C"
- tableAccents["č"] = "c"
- tableAccents["Č"] = "C"
- -- D
- tableAccents["ď"] = "d"
- tableAccents["Ď"] = "d"
- -- E
- tableAccents["è"] = "e"
- tableAccents["È"] = "E"
- tableAccents["é"] = "e"
- tableAccents["É"] = "E"
- tableAccents["ê"] = "e"
- tableAccents["Ê"] = "E"
- tableAccents["ë"] = "e"
- tableAccents["Ë"] = "E"
- tableAccents["ě"] = "e"
- tableAccents["Ě"] = "E"
- -- F
- -- G
- -- H
- -- I
- tableAccents["ì"] = "i"
- tableAccents["Ì"] = "I"
- tableAccents["í"] = "i"
- tableAccents["Í"] = "I"
- tableAccents["î"] = "i"
- tableAccents["Î"] = "I"
- tableAccents["ï"] = "i"
- tableAccents["Ï"] = "I"
- -- J
- -- K
- -- L
- tableAccents["ĺ"] = "l"
- tableAccents["Ĺ"] = "L"
- tableAccents["ľ"] = "l"
- tableAccents["Ľ"] = "L"
- -- M
- -- N
- tableAccents["ñ"] = "n"
- tableAccents["Ñ"] = "N"
- tableAccents["ň"] = "n"
- tableAccents["Ň"] = "N"
- -- O
- tableAccents["ò"] = "o"
- tableAccents["Ò"] = "O"
- tableAccents["ó"] = "o"
- tableAccents["Ó"] = "O"
- tableAccents["ô"] = "o"
- tableAccents["Ô"] = "O"
- tableAccents["õ"] = "o"
- tableAccents["Õ"] = "O"
- tableAccents["ö"] = "o"
- tableAccents["Ö"] = "O"
- -- P
- -- Q
- -- R
- tableAccents["ŕ"] = "r"
- tableAccents["Ŕ"] = "R"
- tableAccents["ř"] = "r"
- tableAccents["Ř"] = "R"
- -- S
- tableAccents["š"] = "s"
- tableAccents["Š"] = "S"
- -- T
- tableAccents["ť"] = "t"
- tableAccents["Ť"] = "T"
- -- U
- tableAccents["ù"] = "u"
- tableAccents["Ù"] = "U"
- tableAccents["ú"] = "u"
- tableAccents["Ú"] = "U"
- tableAccents["û"] = "u"
- tableAccents["Û"] = "U"
- tableAccents["ü"] = "u"
- tableAccents["Ü"] = "U"
- tableAccents["ů"] = "u"
- tableAccents["Ů"] = "U"
- -- V
- -- W
- -- X
- -- Y
- tableAccents["ý"] = "y"
- tableAccents["Ý"] = "Y"
- tableAccents["ÿ"] = "y"
- tableAccents["Ÿ"] = "Y"
- -- Z
- tableAccents["ž"] = "z"
- tableAccents["Ž"] = "Z"
-
- local normalizedString = ""
-
- for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
- if tableAccents[strChar] ~= nil then
- normalizedString = normalizedString..tableAccents[strChar]
- else
- normalizedString = normalizedString..strChar
- end
- end
-
- return normalizedString
-end
-
--- Escape XML characters
--- Keep & first, otherwise it will double escape other characters
--- https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
-function string.escapeXmlCharacters( str )
-
- str = string.gsub(str,"&", "&")
- str = string.gsub(str,"\"", """)
- str = string.gsub(str,"'", "'")
- str = string.gsub(str,"<", "<")
- str = string.gsub(str,">", ">")
-
- return str
-end
-
-- Add duplicate index to filename
-- image.filename does not have index, exported_image has index
function addDuplicateIndex( index, filename )
@@ -230,41 +71,34 @@ function addDuplicateIndex( index, filename )
end
local function create_kml_file(storage, image_table, extra_data)
- if not df.check_if_bin_exists("mkdir") then
- dt.print_error(_("mkdir not found"))
- return
- end
- if not df.check_if_bin_exists("convert") then
- dt.print_error(_("convert not found"))
- return
- end
- if not df.check_if_bin_exists("xdg-open") then
- dt.print_error(_("xdg-open not found"))
- return
- end
- if not df.check_if_bin_exists("xdg-user-dir") then
- dt.print_error(_("xdg-user-dir not found"))
- return
- end
- dt.print_error("Will try to export KML file now")
+ local magickPath = dt.preferences.read("kml_export","magickPath","string")
+ if not df.check_if_bin_exists(magickPath) then
+ dt.print_error(_("magick not found"))
+ return
+ end
+ if dt.configuration.running_os == "linux" then
+ if not df.check_if_bin_exists("xdg-user-dir") then
+ dt.print_error(_("xdg-user-dir not found"))
+ return
+ end
+ end
+ dt.print_log("Will try to export KML file now")
local imageFoldername
- if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
+ if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true
+ and dt.configuration.running_os == "linux") then
if not df.check_if_bin_exists("zip") then
dt.print_error(_("zip not found"))
return
end
-
exportDirectory = dt.configuration.tmp_dir
imageFoldername = ""
else
exportDirectory = dt.preferences.read("kml_export","ExportDirectory","string")
-
-- Creates dir if not exsists
imageFoldername = "files"..PS
- local mkdirCommand = "mkdir -p "..exportDirectory..PS..imageFoldername
- dt.control.execute(mkdirCommand)
+ df.mkdir(df.sanitize_filename(exportDirectory..PS..imageFoldername))
end
-- Create the thumbnails
@@ -275,15 +109,17 @@ local function create_kml_file(storage, image_table, extra_data)
local path, filename, filetype = string.match(exported_image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
filename = string.upper(string.gsub(filename,"%.%w*", ""))
- -- convert -size 92x92 filename.jpg -resize 92x92 +profile "*" thumbnail.jpg
+ -- magick -size 92x92 filename.jpg -resize 92x92 +profile "*" thumbnail.jpg
-- In this example, '-size 120x120' gives a hint to the JPEG decoder that the image is going to be downscaled to
-- 120x120, allowing it to run faster by avoiding returning full-resolution images to GraphicsMagick for the
-- subsequent resizing operation. The '-resize 120x120' specifies the desired dimensions of the output image. It
-- will be scaled so its largest dimension is 120 pixels. The '+profile "*"' removes any ICM, EXIF, IPTC, or other
-- profiles that might be present in the input and aren't needed in the thumbnail.
- local convertToThumbCommand = "convert -size 96x96 "..exported_image.." -resize 92x92 -mattecolor \"#FFFFFF\" -frame 2x2 +profile \"*\" "..exportDirectory..PS..imageFoldername.."thumb_"..filename..".jpg"
- dt.control.execute(convertToThumbCommand)
+ local convertToThumbCommand = ds.sanitize(magickPath) .. " -size 96x96 "..exported_image.." -resize 92x92 -mattecolor \"#FFFFFF\" -frame 2x2 +profile \"*\" "..exportDirectory..PS..imageFoldername.."thumb_"..filename..".jpg"
+
+ df.file_copy(exported_image, exportDirectory..PS..imageFoldername..filename.."."..filetype)
+ dsys.external_command(convertToThumbCommand)
else
-- Remove exported image if it has no GPS data
os.remove(exported_image)
@@ -294,7 +130,19 @@ local function create_kml_file(storage, image_table, extra_data)
-- Strip accents from the filename, because GoogleEarth can't open them
-- https://github.com/darktable-org/lua-scripts/issues/54
- filmName = string.stripAccents(filmName)
+ filmName = ds.strip_accents(filmName)
+
+ -- Remove chars we don't like to have in filenames
+ filmName = string.gsub(filmName, [[\]], "")
+ filmName = string.gsub(filmName, [[/]], "")
+ filmName = string.gsub(filmName, [[:]], "")
+ filmName = string.gsub(filmName, [["]], "")
+ filmName = string.gsub(filmName, "<", "")
+ filmName = string.gsub(filmName, ">", "")
+ filmName = string.gsub(filmName, "|", "")
+ filmName = string.gsub(filmName, "*", "")
+ filmName = string.gsub(filmName, "?", "")
+ filmName = string.gsub(filmName,'[.]', "") -- At least Windwows has problems with the "." and the start command
end
exportKMLFilename = filmName..".kml"
@@ -324,12 +172,12 @@ local function create_kml_file(storage, image_table, extra_data)
local image_title, image_description
if (image.title and image.title ~= "") then
- image_title = string.escapeXmlCharacters(image.title)
+ image_title = ds.escape_xml_characters(image.title)
else
image_title = filename..extension
end
-- Characters should not be escaped in CDATA, but we are using HTML fragment, so we must escape them
- image_description = string.escapeXmlCharacters(image.description)
+ image_description = ds.escape_xml_characters(image.description)
kml_file = kml_file.." "..image_title.."\n"
kml_file = kml_file.." "..image_description.."\n"
@@ -374,7 +222,7 @@ local function create_kml_file(storage, image_table, extra_data)
kml_file = kml_file.." \n"
kml_file = kml_file.." \n"
- for image,exported_image in spairs(image_table, function(t,a,b) return b.exif_datetime_taken > a.exif_datetime_taken end) do
+ for image,exported_image in du.spairs(image_table, function(t,a,b) return b.exif_datetime_taken > a.exif_datetime_taken end) do
if ((image.longitude and image.latitude) and
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
) then
@@ -397,13 +245,15 @@ local function create_kml_file(storage, image_table, extra_data)
kml_file = kml_file..""
local file = io.open(exportDirectory..PS..exportKMLFilename, "w")
+
file:write(kml_file)
file:close()
dt.print("KML file created in "..exportDirectory)
-- Compress the files to create a KMZ file
- if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
+ if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true
+ and dt.configuration.running_os == "linux") then
exportDirectory = dt.preferences.read("kml_export","ExportDirectory","string")
local createKMZCommand = "zip --test --move --junk-paths "
@@ -428,40 +278,65 @@ local function create_kml_file(storage, image_table, extra_data)
-- Open the file with the standard programm
if ( dt.preferences.read("kml_export","OpenKmlFile","bool") == true ) then
- local kmlFileOpenCommand
+ local path
- if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true ) then
- kmlFileOpenCommand = "xdg-open "..exportDirectory..PS.."\""..exportKMZFilename.."\""
+ if ( dt.preferences.read("kml_export","CreateKMZ","bool") == true
+ and dt.configuration.running_os == "linux") then
+ path = exportDirectory..PS..exportKMZFilename
else
- kmlFileOpenCommand = "xdg-open "..exportDirectory..PS.."\""..exportKMLFilename.."\""
+ path = exportDirectory..PS..exportKMLFilename
end
- dt.control.execute(kmlFileOpenCommand)
+
+ dsys.launch_default_app(df.sanitize_filename(path))
end
end
-- Preferences
-dt.preferences.register("kml_export",
- "OpenKmlFile",
- "bool",
- _("KML export: Open KML/KMZ file after export"),
- _("Opens the KML file after the export with the standard program for KML files"),
- false )
-
-local handle = io.popen("xdg-user-dir DESKTOP")
-local result = handle:read()
-if (result == nil) then
- result = ""
+if dt.configuration.running_os == "windows" then
+ dt.preferences.register("kml_export",
+ "OpenKmlFile",
+ "bool",
+ _("KML export: Open KML file after export"),
+ _("Opens the KML file after the export with the standard program for KML files"),
+ false )
+else
+ dt.preferences.register("kml_export",
+ "OpenKmlFile",
+ "bool",
+ _("KML export: Open KML/KMZ file after export"),
+ _("Opens the KML file after the export with the standard program for KML files"),
+ false )
end
-handle:close()
+
+local defaultDir = ''
+if dt.configuration.running_os == "windows" then
+ defaultDir = os.getenv("USERPROFILE")
+elseif dt.configuration.running_os == "macos" then
+ defaultDir = os.getenv("home")
+else
+ local handle = io.popen("xdg-user-dir DESKTOP")
+ defaultDir = handle:read()
+ handle:close()
+end
+
dt.preferences.register("kml_export",
"ExportDirectory",
"directory",
_("KML export: Export directory"),
_("A directory that will be used to export the KML/KMZ files"),
- result )
+ defaultDir )
+if dt.configuration.running_os ~= "linux" then
+ dt.preferences.register("kml_export",
+ "magickPath", -- name
+ "file", -- type
+ _("KML export: ImageMagick binary Location"), -- label
+ _("Install location of magick[.exe]. Requires restart to take effect."), -- tooltip
+ "magick") -- default
+end
+
dt.preferences.register("kml_export",
"CreatePath",
"bool",
@@ -469,15 +344,21 @@ dt.preferences.register("kml_export",
_("connect all images with a path"),
false )
-dt.preferences.register("kml_export",
- "CreateKMZ",
- "bool",
- _("KML export: Create KMZ file"),
- _("Compress all imeges to one KMZ file"),
- true )
+if dt.configuration.running_os == "linux" then
+ dt.preferences.register("kml_export",
+ "CreateKMZ",
+ "bool",
+ _("KML export: Create KMZ file"),
+ _("Compress all imeges to one KMZ file"),
+ true )
+end
-- Register
-dt.register_storage("kml_export", _("KML/KMZ Export"), nil, create_kml_file)
+if dt.configuration.running_os == "windows" then
+ dt.register_storage("kml_export", _("KML Export"), nil, create_kml_file)
+else
+ dt.register_storage("kml_export", _("KML/KMZ Export"), nil, create_kml_file)
+end
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
-- kate: hl Lua;