diff --git a/contrib/CollectHelper.lua b/contrib/CollectHelper.lua new file mode 100644 index 0000000..5996592 --- /dev/null +++ b/contrib/CollectHelper.lua @@ -0,0 +1,221 @@ +--[[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" +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("CollectHelper",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")) + 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) + end +end +local function CollectOnFolder(all_rules, all_active) + local images = dt.gui.selection() + if CheckSingleImage(images) then + return + end + 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" + table.insert(rules, rule) + if all_active then + 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(all_rules, all_active) + local images = dt.gui.selection() + 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 + 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 + 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 + 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 + 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 + 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" + table.insert(rules, purple_rule) + end + if all_active then + 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 +end +local function CollectOnAll_AND() + local images = dt.gui.selection() + if CheckSingleImage(images) then + return + end + local rules = {} + if dt.preferences.read('module_CollectHelper','folder','bool') then + rules = CollectOnFolder(rules, true) + end + if dt.preferences.read('module_CollectHelper','colors','bool') then + rules = CollectOnColors(rules, true) + end + previous = dt.gui.libs.collect.filter(rules) +end + +-- GUI -- +dt.gui.libs.image.register_action( + _("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: folder"), + 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(_ , false) 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: 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 +) diff --git a/contrib/OpenInExplorer.lua b/contrib/OpenInExplorer.lua index 380838b..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,47 +36,78 @@ 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 - proper_install = true +if dt.configuration.running_os ~= "macos" then + 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 and Linux 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 + +-- 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..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) + end + else + dt.print('please select fewer images (max 15)') + 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, - "Opens File Explorer at the selected image's location" - ) + dt.gui.libs.image.register_action( + "show in file explorer", + function() open_in_filemanager() end, + "Opens File Explorer at the selected image's location" + ) end diff --git a/contrib/kml_export.lua b/contrib/kml_export.lua index b091c4f..279ad76 100644 --- a/contrib/kml_export.lua +++ b/contrib/kml_export.lua @@ -78,6 +78,7 @@ local function create_kml_file(storage, image_table, extra_data) else magickPath = dt.preferences.read("kml_export","magickPath","string") end + if not df.check_if_bin_exists(magickPath) then dt.print_error(_("magick not found")) return @@ -127,6 +128,7 @@ local function create_kml_file(storage, image_table, extra_data) df.file_copy(exported_image, exportDirectory..PS..imageFoldername..filename.."."..filetype) end dsys.external_command(convertToThumbCommand) + else -- Remove exported image if it has no GPS data os.remove(exported_image) diff --git a/contrib/video_ffmpeg.lua b/contrib/video_ffmpeg.lua index d561d55..6755e5c 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(tmp_dir)) if result ~= 0 then dt.print(_("ERROR: cannot create temp directory")) end local images = extra_data["images"] @@ -441,11 +441,11 @@ 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 - df.rmdir(tmp_dir) + df.rmdir(df.sanitize_filename(tmp_dir)) end dt.register_storage( 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 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 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 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