mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
Merge pull request #811 from WS64/master
Reuser earlie search and minor bugfixes
This commit is contained in:
commit
0145bf217e
@ -150,7 +150,8 @@ function FileManagerMenu:setUpdateItemTable()
|
|||||||
table.insert(self.tab_item_table.tools, {
|
table.insert(self.tab_item_table.tools, {
|
||||||
text = _("Search books"),
|
text = _("Search books"),
|
||||||
callback = function()
|
callback = function()
|
||||||
Search:init()
|
Search:getCalibre(1)
|
||||||
|
Search:ShowSearch()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
-- home tab
|
-- home tab
|
||||||
|
@ -9,6 +9,8 @@ local Screen = require("ui/screen")
|
|||||||
local _ = require("gettext")
|
local _ = require("gettext")
|
||||||
local Font = require("ui/font")
|
local Font = require("ui/font")
|
||||||
|
|
||||||
|
local calibre = "metadata.calibre"
|
||||||
|
|
||||||
local Search = InputContainer:new{
|
local Search = InputContainer:new{
|
||||||
calibrefile = nil,
|
calibrefile = nil,
|
||||||
search_dialog = nil,
|
search_dialog = nil,
|
||||||
@ -25,7 +27,9 @@ local Search = InputContainer:new{
|
|||||||
results = {},
|
results = {},
|
||||||
libraries = {},
|
libraries = {},
|
||||||
browse_tags = {},
|
browse_tags = {},
|
||||||
browse_series = {}
|
browse_series = {},
|
||||||
|
error = nil,
|
||||||
|
use_previous_search_results = false
|
||||||
}
|
}
|
||||||
|
|
||||||
local function unichar (value)
|
local function unichar (value)
|
||||||
@ -63,7 +67,7 @@ local function findcalibre(root)
|
|||||||
local fullPath=root .. "/" .. entity
|
local fullPath=root .. "/" .. entity
|
||||||
local mode = lfs.attributes(fullPath,"mode")
|
local mode = lfs.attributes(fullPath,"mode")
|
||||||
if mode == "file" then
|
if mode == "file" then
|
||||||
if entity == "metadata.calibre" or entity == ".metadata.calibre" then
|
if entity == calibre or entity == "." .. calibre then
|
||||||
t = root .. "/" .. entity
|
t = root .. "/" .. entity
|
||||||
end
|
end
|
||||||
elseif mode == "directory" then
|
elseif mode == "directory" then
|
||||||
@ -75,16 +79,13 @@ local function findcalibre(root)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
function Search:init()
|
function Search:getCalibre(number)
|
||||||
local error = nil
|
|
||||||
self.data = {}
|
|
||||||
self.results = {}
|
|
||||||
|
|
||||||
-- check if we find the calibre file
|
-- check if we find the calibre file
|
||||||
|
if number == 1 then
|
||||||
if SEARCH_LIBRARY_PATH == nil then
|
if SEARCH_LIBRARY_PATH == nil then
|
||||||
self.calibrefile = findcalibre("/mnt")
|
self.calibrefile = findcalibre("/mnt")
|
||||||
if not self.calibrefile then
|
if not self.calibrefile then
|
||||||
error = "SEARCH_LIBRARY_PATH in DEFAULTS.LUA is not set!"
|
self.error = "SEARCH_LIBRARY_PATH in DEFAULTS.LUA is not set!"
|
||||||
else
|
else
|
||||||
settings_changed = true
|
settings_changed = true
|
||||||
end
|
end
|
||||||
@ -92,14 +93,14 @@ function Search:init()
|
|||||||
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
|
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
|
||||||
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/"
|
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/"
|
||||||
end
|
end
|
||||||
if io.open(SEARCH_LIBRARY_PATH .. "metadata.calibre","r") == nil then
|
if io.open(SEARCH_LIBRARY_PATH .. calibre,"r") == nil then
|
||||||
if io.open(SEARCH_LIBRARY_PATH .. ".metadata.calibre","r") == nil then
|
if io.open(SEARCH_LIBRARY_PATH .. "." .. calibre,"r") == nil then
|
||||||
error = SEARCH_LIBRARY_PATH .. "metadata.calibre not found!"
|
self.error = SEARCH_LIBRARY_PATH .. calibre .. " not found!"
|
||||||
else
|
else
|
||||||
self.calibrefile = SEARCH_LIBRARY_PATH .. ".metadata.calibre"
|
self.calibrefile = SEARCH_LIBRARY_PATH .. "." .. calibre
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.calibrefile = SEARCH_LIBRARY_PATH .. "metadata.calibre"
|
self.calibrefile = SEARCH_LIBRARY_PATH .. calibre
|
||||||
end
|
end
|
||||||
|
|
||||||
if not (SEARCH_AUTHORS or SEARCH_TITLE or SEARCH_PATH or SEARCH_SERIES or SEARCH_TAGS) then
|
if not (SEARCH_AUTHORS or SEARCH_TITLE or SEARCH_PATH or SEARCH_SERIES or SEARCH_TAGS) then
|
||||||
@ -112,7 +113,28 @@ function Search:init()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local dummy
|
||||||
|
|
||||||
|
if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then
|
||||||
|
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/"
|
||||||
|
end
|
||||||
|
if io.open(SEARCH_LIBRARY_PATH2 .. calibre,"r") == nil then
|
||||||
|
if io.open(SEARCH_LIBRARY_PATH2 .. "." .. calibre,"r") ~= nil then
|
||||||
|
dummy = SEARCH_LIBRARY_PATH2 .. "." .. calibre
|
||||||
|
end
|
||||||
|
else
|
||||||
|
dummy = SEARCH_LIBRARY_PATH2 .. calibre
|
||||||
|
end
|
||||||
|
if dummy and dummy ~= self.calibrefile then
|
||||||
|
self.calibrefile = dummy
|
||||||
|
else
|
||||||
|
self.calibrefile = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Search:ShowSearch()
|
||||||
if self.calibrefile ~= nil then
|
if self.calibrefile ~= nil then
|
||||||
SEARCH_LIBRARY_PATH = string.gsub(self.calibrefile,"/[^/]*$","")
|
SEARCH_LIBRARY_PATH = string.gsub(self.calibrefile,"/[^/]*$","")
|
||||||
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
|
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
|
||||||
@ -120,6 +142,7 @@ function Search:init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
GLOBAL_INPUT_VALUE = self.search_value
|
GLOBAL_INPUT_VALUE = self.search_value
|
||||||
|
local dummy = GLOBAL_INPUT_VALUE
|
||||||
self.search_dialog = InputDialog:new{
|
self.search_dialog = InputDialog:new{
|
||||||
title = _("Search Books"),
|
title = _("Search Books"),
|
||||||
buttons = {
|
buttons = {
|
||||||
@ -129,6 +152,11 @@ function Search:init()
|
|||||||
enabled = true,
|
enabled = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
self.search_value = self.search_dialog:getInputText()
|
self.search_value = self.search_dialog:getInputText()
|
||||||
|
if not settings_changed and self.search_value == dummy then
|
||||||
|
self.use_previous_search_results = true
|
||||||
|
else
|
||||||
|
self.use_previous_search_results = false
|
||||||
|
end
|
||||||
self:close()
|
self:close()
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@ -142,12 +170,18 @@ function Search:init()
|
|||||||
self.search_dialog:onShowKeyboard()
|
self.search_dialog:onShowKeyboard()
|
||||||
UIManager:show(self.search_dialog)
|
UIManager:show(self.search_dialog)
|
||||||
else
|
else
|
||||||
if error then
|
if self.error then
|
||||||
UIManager:show(InfoMessage:new{text = _(error .. " A search for a metadata.calibre file was not successful!"),})
|
UIManager:show(InfoMessage:new{text = self.error .. _( " A search for a " .. calibre .. " file was not successful!"),})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Search:init()
|
||||||
|
self.error = nil
|
||||||
|
self.data = {}
|
||||||
|
self.results = {}
|
||||||
|
end
|
||||||
|
|
||||||
function Search:close()
|
function Search:close()
|
||||||
self.search_dialog:onClose()
|
self.search_dialog:onClose()
|
||||||
UIManager:close(self.search_dialog)
|
UIManager:close(self.search_dialog)
|
||||||
@ -206,6 +240,10 @@ function Search:find()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not self.use_previous_search_results then
|
||||||
|
self.reults = {}
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
if SEARCH_CASESENSITIVE then
|
if SEARCH_CASESENSITIVE then
|
||||||
upsearch = self.search_value
|
upsearch = self.search_value
|
||||||
else
|
else
|
||||||
@ -222,15 +260,15 @@ function Search:find()
|
|||||||
-- new calibre data set
|
-- new calibre data set
|
||||||
|
|
||||||
dummy = ""
|
dummy = ""
|
||||||
if SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] end
|
if SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end
|
||||||
if SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] end
|
if SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end
|
||||||
if SEARCH_PATH then dummy = dummy .. self.data[i][self.path] end
|
if SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end
|
||||||
if SEARCH_SERIES then
|
if SEARCH_SERIES then
|
||||||
dummy = dummy .. self.data[i][self.series]
|
dummy = dummy .. self.data[i][self.series] .. "\n"
|
||||||
self.browse_series[self.data[i][self.series]] = true
|
self.browse_series[self.data[i][self.series]] = true
|
||||||
end
|
end
|
||||||
if SEARCH_TAGS then
|
if SEARCH_TAGS then
|
||||||
dummy = dummy .. self.data[i][self.tags]
|
dummy = dummy .. self.data[i][self.tags] .. "\n"
|
||||||
self.browse_tags[self.data[i][self.tags]] = true
|
self.browse_tags[self.data[i][self.tags]] = true
|
||||||
end
|
end
|
||||||
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end
|
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end
|
||||||
@ -259,32 +297,21 @@ function Search:find()
|
|||||||
end
|
end
|
||||||
line = f:read()
|
line = f:read()
|
||||||
|
|
||||||
if not line and firstrun and SEARCH_LIBRARY_PATH2 then
|
if not line and firstrun then
|
||||||
local dummy
|
|
||||||
firstrun = false
|
|
||||||
if f ~= nil then f:close() end
|
if f ~= nil then f:close() end
|
||||||
|
firstrun = false
|
||||||
if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then
|
self:getCalibre(2)
|
||||||
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/"
|
if self.calibrefile then
|
||||||
end
|
|
||||||
if io.open(SEARCH_LIBRARY_PATH2 .. "metadata.calibre","r") == nil then
|
|
||||||
if io.open(SEARCH_LIBRARY_PATH2 .. ".metadata.calibre","r") ~= nil then
|
|
||||||
dummy = SEARCH_LIBRARY_PATH2 .. ".metadata.calibre"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
dummy = SEARCH_LIBRARY_PATH2 .. "metadata.calibre"
|
|
||||||
end
|
|
||||||
if dummy and dummy ~= self.calibrefile then
|
|
||||||
self.calibrefile = dummy
|
|
||||||
f = io.open(self.calibrefile)
|
f = io.open(self.calibrefile)
|
||||||
line = f:read()
|
line = f:read()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
i = i - 1
|
i = i - 1
|
||||||
if i > 0 then
|
|
||||||
self.data[i + 1] = nil
|
|
||||||
self.count = i
|
self.count = i
|
||||||
|
end
|
||||||
|
if self.count > 0 then
|
||||||
|
self.data[self.count + 1] = nil
|
||||||
self:showresults()
|
self:showresults()
|
||||||
else
|
else
|
||||||
UIManager:show(InfoMessage:new{text = _("No match for " .. self.search_value)})
|
UIManager:show(InfoMessage:new{text = _("No match for " .. self.search_value)})
|
||||||
@ -322,7 +349,8 @@ function Search:showresults()
|
|||||||
self.search_menu.close_callback = function()
|
self.search_menu.close_callback = function()
|
||||||
UIManager:close(menu_container)
|
UIManager:close(menu_container)
|
||||||
end
|
end
|
||||||
|
if not self.use_previous_search_results then
|
||||||
|
self.results = {}
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= self.count do
|
while i <= self.count do
|
||||||
local dummy = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" ..
|
local dummy = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" ..
|
||||||
@ -353,7 +381,7 @@ function Search:showresults()
|
|||||||
})
|
})
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
end
|
||||||
self.search_menu:swithItemTable("Search Results", self.results)
|
self.search_menu:swithItemTable("Search Results", self.results)
|
||||||
UIManager:show(menu_container)
|
UIManager:show(menu_container)
|
||||||
end
|
end
|
||||||
|
@ -130,6 +130,14 @@ function SetDefaults:init()
|
|||||||
title = self.defaults_name[i] .. ":",
|
title = self.defaults_name[i] .. ":",
|
||||||
buttons = {
|
buttons = {
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
text = _("Cancel"),
|
||||||
|
enabled = true,
|
||||||
|
callback = function()
|
||||||
|
self:close()
|
||||||
|
UIManager:show(menu_container)
|
||||||
|
end
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text = "true",
|
text = "true",
|
||||||
enabled = true,
|
enabled = true,
|
||||||
@ -160,14 +168,6 @@ function SetDefaults:init()
|
|||||||
UIManager:show(menu_container)
|
UIManager:show(menu_container)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
|
||||||
text = _("Cancel"),
|
|
||||||
enabled = true,
|
|
||||||
callback = function()
|
|
||||||
self:close()
|
|
||||||
UIManager:show(menu_container)
|
|
||||||
end
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
input_type = settings_type,
|
input_type = settings_type,
|
||||||
@ -188,21 +188,6 @@ function SetDefaults:init()
|
|||||||
title = self.defaults_name[i] .. ":",
|
title = self.defaults_name[i] .. ":",
|
||||||
buttons = {
|
buttons = {
|
||||||
{
|
{
|
||||||
{
|
|
||||||
text = _("OK"),
|
|
||||||
enabled = true,
|
|
||||||
callback = function()
|
|
||||||
self.defaults_value[i] = _G[self.defaults_name[i]]
|
|
||||||
if _G[self.defaults_name[i]] ~= settype(self.set_dialog:getInputText(),settings_type) then
|
|
||||||
_G[self.defaults_name[i]] = settype(self.set_dialog:getInputText(),settings_type)
|
|
||||||
settings_changed = true
|
|
||||||
end
|
|
||||||
self.results[i].text = setdisplayname(i)
|
|
||||||
self:close()
|
|
||||||
self.defaults_menu:swithItemTable("Defaults", self.results, i)
|
|
||||||
UIManager:show(menu_container)
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
text = _("Cancel"),
|
text = _("Cancel"),
|
||||||
enabled = true,
|
enabled = true,
|
||||||
@ -211,6 +196,21 @@ function SetDefaults:init()
|
|||||||
UIManager:show(menu_container)
|
UIManager:show(menu_container)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text = _("OK"),
|
||||||
|
enabled = true,
|
||||||
|
callback = function()
|
||||||
|
if _G[self.defaults_name[i]] ~= settype(self.set_dialog:getInputText(),settings_type) then
|
||||||
|
_G[self.defaults_name[i]] = settype(self.set_dialog:getInputText(),settings_type)
|
||||||
|
settings_changed = true
|
||||||
|
end
|
||||||
|
self.defaults_value[i] = _G[self.defaults_name[i]]
|
||||||
|
self.results[i].text = setdisplayname(i)
|
||||||
|
self:close()
|
||||||
|
self.defaults_menu:swithItemTable("Defaults", self.results, i)
|
||||||
|
UIManager:show(menu_container)
|
||||||
|
end,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
input_type = settings_type,
|
input_type = settings_type,
|
||||||
@ -329,5 +329,6 @@ function SetDefaults:SaveSettings()
|
|||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
UIManager:show(InfoMessage:new{text = _("Default settings successfully saved!")})
|
UIManager:show(InfoMessage:new{text = _("Default settings successfully saved!")})
|
||||||
|
settings_changed = false
|
||||||
end
|
end
|
||||||
return SetDefaults
|
return SetDefaults
|
||||||
|
Loading…
Reference in New Issue
Block a user