Skip to content

Commit 53d6b54

Browse files
authored
Merge branch 'master' into supertobi-patch-1
2 parents ffd6abb + a383d1e commit 53d6b54

8 files changed

+301
-46
lines changed

contrib/CollectHelper.lua

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
--[[Collect Helper plugin for darktable
2+
3+
copyright (c) 2019 Kevin Ertel
4+
5+
darktable is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
darktable is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with darktable. If not, see <http://www.gnu.org/licenses/>.
17+
]]
18+
19+
--[[About this plugin
20+
This plugin adds the button(s) to the "Selected Images" module:
21+
1) Return to Previous Collection
22+
2) Collect on image's Folder
23+
3) Collect on image's Color Label(s)
24+
4) Collect on All (AND)
25+
26+
It also adds 3 preferences to the lua options dialog box which allow the user to activate/deactivate the 3 "Collect on" buttons.
27+
28+
Button Behavior:
29+
1) Return to Previous Collection - Will reset the collect parameters to the previously active settings
30+
2) Collect on image's Folder - Will change the collect parameters to be "Folder" with a value of the selected image's folder location
31+
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
32+
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
33+
34+
----REQUIRED SOFTWARE----
35+
NA
36+
37+
----USAGE----
38+
Install: (see here for more detail: https://github.com/darktable-org/lua-scripts )
39+
1) Copy this file in to your "lua/contrib" folder where all other scripts reside.
40+
2) Require this file in your luarc file, as with any other dt plug-in
41+
42+
Select the photo you wish to change you collection based on.
43+
In the "Selected Images" module click on "Collect on this Image"
44+
45+
----KNOWN ISSUES----
46+
]]
47+
48+
local dt = require "darktable"
49+
local gettext = dt.gettext
50+
local previous = nil
51+
local all_active = false
52+
53+
-- Tell gettext where to find the .mo file translating messages for a particular domain
54+
gettext.bindtextdomain("CollectHelper",dt.configuration.config_dir.."/lua/locale/")
55+
56+
local function _(msgid)
57+
return gettext.dgettext("CollectHelper", msgid)
58+
end
59+
60+
-- FUNCTION --
61+
local function CheckSingleImage(selection)
62+
if #selection ~= 1 then
63+
dt.print(_("Please select a single image"))
64+
return true
65+
end
66+
return false
67+
end
68+
local function CheckHasColorLabel(selection)
69+
local ret = false
70+
for _,image in pairs(selection) do
71+
if image.red then ret = true end
72+
if image.blue then ret = true end
73+
if image.green then ret = true end
74+
if image.yellow then ret = true end
75+
if image.purple then ret = true end
76+
end
77+
return ret
78+
end
79+
local function PreviousCollection()
80+
if previous ~= nil then
81+
previous = dt.gui.libs.collect.filter(previous)
82+
end
83+
end
84+
local function CollectOnFolder(all_rules, all_active)
85+
local images = dt.gui.selection()
86+
if CheckSingleImage(images) then
87+
return
88+
end
89+
local rules = {}
90+
local rule = dt.gui.libs.collect.new_rule()
91+
rule.mode = "DT_LIB_COLLECT_MODE_AND"
92+
rule.data = images[1].path
93+
rule.item = "DT_COLLECTION_PROP_FOLDERS"
94+
table.insert(rules, rule)
95+
if all_active then
96+
for _,active_rule in pairs(rules) do
97+
table.insert(all_rules, active_rule)
98+
end
99+
return all_rules
100+
else
101+
previous = dt.gui.libs.collect.filter(rules)
102+
end
103+
end
104+
local function CollectOnColors(all_rules, all_active)
105+
local images = dt.gui.selection()
106+
if CheckSingleImage(images) then
107+
return
108+
end
109+
if not CheckHasColorLabel(images) then
110+
dt.print(_('select an image with an active color label'))
111+
return
112+
end
113+
for _,image in pairs(images) do
114+
local rules = {}
115+
if image.red then
116+
local red_rule = dt.gui.libs.collect.new_rule()
117+
red_rule.mode = "DT_LIB_COLLECT_MODE_AND"
118+
red_rule.data = "red"
119+
red_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
120+
table.insert(rules, red_rule)
121+
end
122+
if image.blue then
123+
local blue_rule = dt.gui.libs.collect.new_rule()
124+
blue_rule.mode = "DT_LIB_COLLECT_MODE_AND"
125+
blue_rule.data = "blue"
126+
blue_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
127+
table.insert(rules, blue_rule)
128+
end
129+
if image.green then
130+
local green_rule = dt.gui.libs.collect.new_rule()
131+
green_rule.mode = "DT_LIB_COLLECT_MODE_AND"
132+
green_rule.data = "green"
133+
green_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
134+
table.insert(rules, green_rule)
135+
end
136+
if image.yellow then
137+
local yellow_rule = dt.gui.libs.collect.new_rule()
138+
yellow_rule.mode = "DT_LIB_COLLECT_MODE_AND"
139+
yellow_rule.data = "yellow"
140+
yellow_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
141+
table.insert(rules, yellow_rule)
142+
end
143+
if image.purple then
144+
local purple_rule = dt.gui.libs.collect.new_rule()
145+
purple_rule.mode = "DT_LIB_COLLECT_MODE_AND"
146+
purple_rule.data = "purple"
147+
purple_rule.item = "DT_COLLECTION_PROP_COLORLABEL"
148+
table.insert(rules, purple_rule)
149+
end
150+
if all_active then
151+
for _,active_rule in pairs(rules) do
152+
table.insert(all_rules, active_rule)
153+
end
154+
return all_rules
155+
else
156+
previous = dt.gui.libs.collect.filter(rules)
157+
end
158+
end
159+
end
160+
local function CollectOnAll_AND()
161+
local images = dt.gui.selection()
162+
if CheckSingleImage(images) then
163+
return
164+
end
165+
local rules = {}
166+
if dt.preferences.read('module_CollectHelper','folder','bool') then
167+
rules = CollectOnFolder(rules, true)
168+
end
169+
if dt.preferences.read('module_CollectHelper','colors','bool') then
170+
rules = CollectOnColors(rules, true)
171+
end
172+
previous = dt.gui.libs.collect.filter(rules)
173+
end
174+
175+
-- GUI --
176+
dt.gui.libs.image.register_action(
177+
_("collect: previous"),
178+
function() PreviousCollection() end,
179+
_("Sets the Collect parameters to be the previously active parameters")
180+
)
181+
if dt.preferences.read('module_CollectHelper','folder','bool') then
182+
dt.gui.libs.image.register_action(
183+
_("collect: folder"),
184+
function() CollectOnFolder(_ , false) end,
185+
_("Sets the Collect parameters to be the selected images's folder")
186+
)
187+
end
188+
if dt.preferences.read('module_CollectHelper','colors','bool') then
189+
dt.gui.libs.image.register_action(
190+
_("collect: color label(s)"),
191+
function() CollectOnColors(_ , false) end,
192+
_("Sets the Collect parameters to be the selected images's color label(s)")
193+
)
194+
end
195+
if dt.preferences.read('module_CollectHelper','all_and','bool') then
196+
dt.gui.libs.image.register_action(
197+
_("collect: all (AND)"),
198+
function() CollectOnAll_AND() end,
199+
_("Sets the Collect parameters based on all activated CollectHelper options")
200+
)
201+
end
202+
203+
-- PREFERENCES --
204+
dt.preferences.register("module_CollectHelper", "all_and", -- name
205+
"bool", -- type
206+
_('CollectHelper: All'), -- label
207+
_('Will create a collect parameter set that utelizes all enabled CollectHelper types (AND)'), -- tooltip
208+
true -- default
209+
)
210+
dt.preferences.register("module_CollectHelper", "colors", -- name
211+
"bool", -- type
212+
_('CollectHelper: Color Label(s)'), -- label
213+
_('Enable the button that allows you to swap to a collection based on selected image\'s COLOR LABEL(S)'), -- tooltip
214+
true -- default
215+
)
216+
dt.preferences.register("module_CollectHelper", "folder", -- name
217+
"bool", -- type
218+
_('CollectHelper: Folder'), -- label
219+
_('Enable the button that allows you to swap to a collection based on selected image\'s FOLDER location'), -- tooltip
220+
true -- default
221+
)

contrib/OpenInExplorer.lua

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
--[[OpenInExplorer plugin for darktable
1+
--[[
2+
OpenInExplorer plugin for darktable
23
34
copyright (c) 2018 Kevin Ertel
45
@@ -20,7 +21,7 @@
2021
This plugin adds the module "OpenInExplorer" to darktable's lighttable view
2122
2223
----REQUIRED SOFTWARE----
23-
Microsoft Windows Operating System
24+
Microsoft Windows or Linux with installed Nautilus
2425
2526
----USAGE----
2627
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
3536

3637
local dt = require "darktable"
3738
local du = require "lib/dtutils"
39+
local df = require "lib/dtutils.file"
3840
local dsys = require "lib/dtutils.system"
3941

4042
--Check API version
4143
du.check_min_api_version("5.0.0", "OpenInExplorer")
4244

45+
local PS = dt.configuration.running_os == "windows" and "\\" or "/"
46+
4347
--Detect OS and modify accordingly--
4448
local proper_install = false
45-
if dt.configuration.running_os == "windows" then
46-
proper_install = true
49+
if dt.configuration.running_os ~= "macos" then
50+
proper_install = true
4751
else
48-
dt.print_error('OpenInExplorer plug-in only supports Windows OS at this time')
49-
return
52+
dt.print_error('OpenInExplorer plug-in only supports Windows and Linux at this time')
53+
return
54+
end
55+
56+
57+
-- FUNCTIONS --
58+
59+
local function open_in_explorer() --Open in Explorer
60+
local images = dt.gui.selection()
61+
local curr_image = ""
62+
if #images == 0 then
63+
dt.print('please select an image')
64+
elseif #images <= 15 then
65+
for _,image in pairs(images) do
66+
curr_image = image.path..PS..image.filename
67+
local run_cmd = "explorer.exe /select, "..curr_image
68+
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
69+
resp = dsys.external_command(run_cmd)
70+
end
71+
else
72+
dt.print('please select fewer images (max 15)')
73+
end
74+
end
75+
76+
local function open_in_nautilus() --Open in Nautilus
77+
local images = dt.gui.selection()
78+
local curr_image = ""
79+
if #images == 0 then
80+
dt.print('please select an image')
81+
elseif #images <= 15 then
82+
for _,image in pairs(images) do
83+
curr_image = image.path..PS..image.filename
84+
local run_cmd = "nautilus --select " .. df.sanitize_filename(curr_image)
85+
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
86+
resp = dsys.external_command(run_cmd)
87+
end
88+
else
89+
dt.print('please select fewer images (max 15)')
90+
end
5091
end
5192

52-
-- FUNCTION --
53-
local function OpenInExplorer() --Open in Explorer
54-
--Inits--
55-
if not proper_install then
56-
return
57-
end
58-
local images = dt.gui.selection()
59-
local curr_image = ""
60-
if #images == 0 then
61-
dt.print('please select an image')
62-
elseif #images <= 15 then
63-
for _,image in pairs(images) do
64-
curr_image = image.path..'\\'..image.filename
65-
local run_cmd = "explorer.exe /select, "..curr_image
66-
dt.print_log("OpenInExplorer run_cmd = "..run_cmd)
67-
resp = dsys.external_command(run_cmd)
68-
end
69-
else
70-
dt.print('please select fewer images (max 15)')
71-
end
93+
local function open_in_filemanager() --Open
94+
--Inits--
95+
if not proper_install then
96+
return
97+
end
98+
99+
if (dt.configuration.running_os == "windows") then
100+
open_in_explorer()
101+
elseif (dt.configuration.running_os == "linux") then
102+
open_in_nautilus()
103+
end
72104
end
73105

74106
-- GUI --
75107
if proper_install then
76-
dt.gui.libs.image.register_action(
77-
"show in file explorer",
78-
function() OpenInExplorer() end,
79-
"Opens File Explorer at the selected image's location"
80-
)
108+
dt.gui.libs.image.register_action(
109+
"show in file explorer",
110+
function() open_in_filemanager() end,
111+
"Opens File Explorer at the selected image's location"
112+
)
81113
end

contrib/kml_export.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ local function create_kml_file(storage, image_table, extra_data)
7878
else
7979
magickPath = dt.preferences.read("kml_export","magickPath","string")
8080
end
81+
8182
if not df.check_if_bin_exists(magickPath) then
8283
dt.print_error(_("magick not found"))
8384
return
@@ -127,6 +128,7 @@ local function create_kml_file(storage, image_table, extra_data)
127128
df.file_copy(exported_image, exportDirectory..PS..imageFoldername..filename.."."..filetype)
128129
end
129130
dsys.external_command(convertToThumbCommand)
131+
130132
else
131133
-- Remove exported image if it has no GPS data
132134
os.remove(exported_image)

contrib/video_ffmpeg.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ local function export(extra_data)
412412
local img_ext = extra_data["img_ext"]
413413
local output_file = extra_data["output_file"]
414414

415-
local dir_create_result = df.mkdir(df.get_path(output_file))
415+
local dir_create_result = df.mkdir(df.sanitize_filename(df.get_path(output_file)))
416416
if dir_create_result ~= 0 then return dir_create_result end
417417

418418
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)
424424

425425
dt.print(_("prepare merge process"))
426426

427-
local result = df.mkdir(tmp_dir)
427+
local result = df.mkdir(df.sanitize_filename(tmp_dir))
428428
if result ~= 0 then dt.print(_("ERROR: cannot create temp directory")) end
429429

430430
local images = extra_data["images"]
@@ -441,11 +441,11 @@ local function finalize_export(storage, images_table, extra_data)
441441
else
442442
dt.print(_("SUCCESS"))
443443
if extra_data["open_after_export"] then
444-
dsys.launch_default_app(path)
444+
dsys.launch_default_app(df.sanitize_filename(path))
445445
end
446446
end
447447

448-
df.rmdir(tmp_dir)
448+
df.rmdir(df.sanitize_filename(tmp_dir))
449449
end
450450

451451
dt.register_storage(

0 commit comments

Comments
 (0)