|
| 1 | +--[[ |
| 2 | + This file is part of darktable, |
| 3 | + copyright (c) 2015 Tobias Ellinghaus |
| 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 | +IMPORT FILTER MANAGER |
| 20 | +This script adds a dropdown list with import filters to the import dialog. |
| 21 | +Scripts can add new filters by registering them with |
| 22 | + darktable.register_import_filter(name, callback) |
| 23 | +The callback has type function(event, images), i.e., it is the same as when |
| 24 | +directly registering the pre-import event. |
| 25 | +
|
| 26 | +
|
| 27 | +USAGE |
| 28 | +* require this script from your main lua file |
| 29 | +* also require some files with import filters, for example import_filters.lua. |
| 30 | + it is important to add them AFTER this one! |
| 31 | +]] |
| 32 | + |
| 33 | +local dt = require "darktable" |
| 34 | + |
| 35 | +local import_filter_list = {} |
| 36 | +local n_import_filters = 1 |
| 37 | + |
| 38 | +-- allow changing the filter from the preferences |
| 39 | +dt.preferences.register("import_filter_manager", "active_filter", "string", |
| 40 | + "import filter", "the name of the filter used for importing images", "") |
| 41 | + |
| 42 | + |
| 43 | +-- the dropdown to select the active filter from the import dialog |
| 44 | +local filter_dropdown = dt.new_widget("combobox") |
| 45 | +{ |
| 46 | + label = "import filter", |
| 47 | + editable = false, |
| 48 | + |
| 49 | + changed_callback = function(widget) |
| 50 | + dt.preferences.write("import_filter_manager", "active_filter", "string", widget.value) |
| 51 | + end, |
| 52 | + |
| 53 | + "" -- the first entry in the list is hard coded to "" so it's possible to have no filter |
| 54 | +} |
| 55 | +dt.gui.libs.import.register_widget(filter_dropdown) |
| 56 | + |
| 57 | + |
| 58 | +-- this is just a wrapper which calls the active import filter |
| 59 | +dt.register_event("pre-import", function(event, images) |
| 60 | + local active_filter = dt.preferences.read("import_filter_manager", "active_filter", "string") |
| 61 | + if active_filter == "" then return end |
| 62 | + local callback = import_filter_list[active_filter] |
| 63 | + if callback then callback(event, images) end |
| 64 | +end) |
| 65 | + |
| 66 | + |
| 67 | +-- add a new global function to register import filters |
| 68 | +dt.register_import_filter = function(name, callback) |
| 69 | + local active_filter = dt.preferences.read("import_filter_manager", "active_filter", "string") |
| 70 | + dt.print_error("registering import filter `" .. name .. "'") |
| 71 | + import_filter_list[name] = callback |
| 72 | + n_import_filters = n_import_filters + 1 |
| 73 | + filter_dropdown[n_import_filters] = name |
| 74 | + if name == active_filter then filter_dropdown.value = n_import_filters end |
| 75 | +end |
| 76 | + |
| 77 | + |
| 78 | +-- vim: shiftwidth=2 expandtab tabstop=2 cindent |
| 79 | +-- kate: tab-indents: off; indent-width 2; replace-tabs on; remove-trailing-space on; |
0 commit comments