diff --git a/defaults.lua b/defaults.lua index 7ede43242..040a38399 100644 --- a/defaults.lua +++ b/defaults.lua @@ -176,8 +176,9 @@ SEARCH_PATH = true -- Light parameter for Kobo KOBO_LIGHT_OFF_ON_SUSPEND = false -KOBO_LIGHT_ON_START = -1 -- -1 or 0-100. -1 leaves light as it is, other sets light on start/wake up -KOBO_SCREEN_SAVER = "" -- image or directory with pictures or "-" +KOBO_LIGHT_ON_START = -1 -- -1 or 0-100. -1 leaves light as it is, other sets light on start/wake up +KOBO_SCREEN_SAVER = "" -- image or directory with pictures or "-" +KOBO_SCREEN_SAVER_LAST_BOOK = true -- get screensaver from last book if possible -- #################################################################### -- following features are not supported right now diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index 082620644..8565a5c21 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -8,6 +8,7 @@ local Menu = require("ui/widget/menu") local Screen = require("ui/screen") local _ = require("gettext") local Font = require("ui/font") +local UIToolbox = require("ui/uitoolbox") local calibre = "metadata.calibre" local koreaderfile = "temp/metadata.koreader" @@ -541,7 +542,8 @@ function Search:onMenuHold(item) end item.notchecked = false end - UIManager:show(InfoMessage:new{text = item.info}) + UIManager:show(InfoMessage:new{text = item.info,image = UIToolbox:getPicture(item.path), image_width=240,image_height = 400}) + end end @@ -683,7 +685,11 @@ function Search:browse(option,run,chosen) local book = libpath .. self.data[i][self.path] local text if option == "series" then - text = string.format("%6.1f",self.data[i][self.series_index]):gsub(".0$","") .. ": " .. self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + if self.data[i][self.series_index] == "0.0" then + text = self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + else + text = string.format("%6.1f",self.data[i][self.series_index]:gsub(".0$","")) .. ": " .. self.data[i][self.title] .. " (" .. self.data[i][self.authors] .. ")" + end else text = self.data[i][self.authors] .. ": " .. self.data[i][self.title] end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 9d2c79ea4..2e0528ed0 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -6,6 +6,7 @@ local DEBUG = require("dbg") local _ = require("gettext") local util = require("ffi/util") local ImageWidget = require("ui/widget/imagewidget") +local UIToolbox = require("ui/uitoolbox") -- initialize output module, this must be initialized before Input Screen:init() @@ -59,22 +60,6 @@ local UIManager = { suspend_msg = nil } -function UIManager:getRandomPicture(dir) - local pics = {} - local i = 0 - math.randomseed( os.time() ) - for entry in lfs.dir(dir) do - if lfs.attributes(dir .. entry, "mode") == "file" then - local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "") - if extension == "jpg" or extension == "jpeg" or extension == "png" then - i = i + 1 - pics[i] = entry - end - end - end - return pics[math.random(i)] -end - function UIManager:init() self.event_handlers = { __default__ = function(input_event) @@ -92,14 +77,22 @@ function UIManager:init() if (input_event == "Power" or input_event == "Suspend") and not Device.screen_saver_mode then if not UIManager.suspend_msg then - if type(KOBO_SCREEN_SAVER) == "string" then - local file = KOBO_SCREEN_SAVER - if lfs.attributes(file, "mode") == "directory" then - if string.sub(file,string.len(file)) ~= "/" then - file = file .. "/" + + local file + if KOBO_SCREEN_SAVER_LAST_BOOK then + file = UIToolbox:getPicture(G_reader_settings:readSetting("lastfile")) + end + + if type(KOBO_SCREEN_SAVER) == "string" or file then + if not file then + file = KOBO_SCREEN_SAVER + if lfs.attributes(file, "mode") == "directory" then + if string.sub(file,string.len(file)) ~= "/" then + file = file .. "/" + end + local dummy = UIToolbox:getRandomPicture(file) + if dummy then file = file .. dummy end end - local dummy = self:getRandomPicture(file) - if dummy then file = file .. dummy end end if lfs.attributes(file, "mode") == "file" then UIManager.suspend_msg = ImageWidget:new{ diff --git a/frontend/ui/uitoolbox.lua b/frontend/ui/uitoolbox.lua new file mode 100644 index 000000000..11fb0320c --- /dev/null +++ b/frontend/ui/uitoolbox.lua @@ -0,0 +1,125 @@ +local InputContainer = require("ui/widget/container/inputcontainer") + +local UIToolbox = InputContainer:new{ +} + +function UIToolbox:getPicture(file) + + local contentopf + local contentpath + local epub_folder = "temp/epub" + + local function check_extension(cover) + if cover then + local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "") + if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then + cover = nil + end + end + return cover + end + + local function getValue(zipfile,which_line,to_find,excludecheck) + local f = io.open(zipfile,"r") + local i + + if f then + local line = f:read() + while line and not i do + i = line:lower():find(which_line:lower()) -- found something + if i then + f.close() + line = line:match(to_find .. "\"([^\"]+)\".*") + if not excludecheck then line = check_extension(line) end + if line then + return line + else + i = nil + end + end + if not i then line = f:read() end + end + f.close() + end + end + + local function guess(extension) + local cover = contentpath .. "Images/cover." .. extension + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then + cover = nil + end + return cover + end + + local function try_content_opf(which_line,to_find,addimage) + local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find) + local imageadd + if cover then + if addimage then + imageadd = "Images/" + else + imageadd = "" + end + cover = contentpath .. imageadd .. cover + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then cover = nil end + end + return check_extension(cover) + end + + local cover + if file then + pcall(lfs.mkdir("temp")) + pcall(os.execute("rm -rf " .. epub_folder)) + pcall(lfs.mkdir(epub_folder)) + pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder)) + if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder + cover = epub_folder .. "/cover.jpeg" -- found one + else + pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml + contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s*