|
|
@ -1,10 +1,12 @@
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
|
|
|
local Screen = require("ui/screen")
|
|
|
|
|
|
|
|
local DEBUG = require("dbg")
|
|
|
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
|
|
|
|
local UIToolbox = InputContainer:new{
|
|
|
|
local Screensaver = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function UIToolbox:getPicture(file)
|
|
|
|
function Screensaver:getCoverPicture(file)
|
|
|
|
|
|
|
|
|
|
|
|
local contentopf
|
|
|
|
local contentopf
|
|
|
|
local contentpath
|
|
|
|
local contentpath
|
|
|
|
local epub_folder = "temp/epub"
|
|
|
|
local epub_folder = "temp/epub"
|
|
|
@ -69,13 +71,13 @@ function UIToolbox:getPicture(file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return check_extension(cover)
|
|
|
|
return check_extension(cover)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function checkoldfile(cover)
|
|
|
|
local function checkoldfile(cover)
|
|
|
|
if io.open(cover) then
|
|
|
|
if io.open(cover) then
|
|
|
|
return cover
|
|
|
|
return cover
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local cover
|
|
|
|
local cover
|
|
|
|
|
|
|
|
|
|
|
|
local oldfile = "temp/" .. file:gsub("/","#") .. "."
|
|
|
|
local oldfile = "temp/" .. file:gsub("/","#") .. "."
|
|
|
@ -104,13 +106,13 @@ function UIToolbox:getPicture(file)
|
|
|
|
contentpath = ""
|
|
|
|
contentpath = ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pcall(os.execute("unzip \"" .. file .. "\" \"" .. contentopf .. "\" -oq -d " .. epub_folder)) -- read content.opf
|
|
|
|
pcall(os.execute("unzip \"" .. file .. "\" \"" .. contentopf .. "\" -oq -d " .. epub_folder)) -- read content.opf
|
|
|
|
|
|
|
|
|
|
|
|
cover = try_content_opf("^%s*<meta name=\"cover\"","content=",true) -- Make Room
|
|
|
|
cover = try_content_opf("^%s*<meta name=\"cover\"","content=",true) -- Make Room
|
|
|
|
if not cover then cover = try_content_opf('id="cover',"item href=",false) end -- Kishon
|
|
|
|
if not cover then cover = try_content_opf('id="cover',"item href=",false) end -- Kishon
|
|
|
|
if not cover then cover = try_content_opf("cover","href=",true) end
|
|
|
|
if not cover then cover = try_content_opf("cover","href=",true) end
|
|
|
|
if not cover then cover = try_content_opf("cover","=",true) end
|
|
|
|
if not cover then cover = try_content_opf("cover","=",true) end
|
|
|
|
if not cover then cover = try_content_opf("cover","=",false) end
|
|
|
|
if not cover then cover = try_content_opf("cover","=",false) end
|
|
|
|
|
|
|
|
|
|
|
|
if not cover then guess("jpg") end
|
|
|
|
if not cover then guess("jpg") end
|
|
|
|
if not cover then guess("jpeg") end
|
|
|
|
if not cover then guess("jpeg") end
|
|
|
|
if not cover then guess("png") end
|
|
|
|
if not cover then guess("png") end
|
|
|
@ -129,10 +131,10 @@ function UIToolbox:getPicture(file)
|
|
|
|
return cover
|
|
|
|
return cover
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function UIToolbox:getRandomPicture(dir)
|
|
|
|
function Screensaver:getRandomPicture(dir)
|
|
|
|
local pics = {}
|
|
|
|
local pics = {}
|
|
|
|
local i = 0
|
|
|
|
local i = 0
|
|
|
|
math.randomseed( os.time() )
|
|
|
|
math.randomseed(os.time())
|
|
|
|
for entry in lfs.dir(dir) do
|
|
|
|
for entry in lfs.dir(dir) do
|
|
|
|
if lfs.attributes(dir .. entry, "mode") == "file" then
|
|
|
|
if lfs.attributes(dir .. entry, "mode") == "file" then
|
|
|
|
local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "")
|
|
|
|
local extension = string.lower(string.match(entry, ".+%.([^.]+)") or "")
|
|
|
@ -145,4 +147,45 @@ function UIToolbox:getRandomPicture(dir)
|
|
|
|
return pics[math.random(i)]
|
|
|
|
return pics[math.random(i)]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return UIToolbox
|
|
|
|
function Screensaver:show()
|
|
|
|
|
|
|
|
DEBUG("show screensaver")
|
|
|
|
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
|
|
|
|
local file = nil
|
|
|
|
|
|
|
|
-- first check book cover image
|
|
|
|
|
|
|
|
if KOBO_SCREEN_SAVER_LAST_BOOK then
|
|
|
|
|
|
|
|
file = self:getCoverPicture(G_reader_settings:readSetting("lastfile"))
|
|
|
|
|
|
|
|
-- then screensaver image
|
|
|
|
|
|
|
|
elseif type(KOBO_SCREEN_SAVER) == "string" 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 = self:getRandomPicture(file)
|
|
|
|
|
|
|
|
if dummy then file = file .. dummy end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if file and lfs.attributes(file, "mode") == "file" then
|
|
|
|
|
|
|
|
self.suspend_msg = ImageWidget:new{
|
|
|
|
|
|
|
|
file = file,
|
|
|
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-- fallback to suspended message
|
|
|
|
|
|
|
|
if not self.suspend_msg then
|
|
|
|
|
|
|
|
self.suspend_msg = InfoMessage:new{ text = _("Suspended") }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:show(self.suspend_msg)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Screensaver:close()
|
|
|
|
|
|
|
|
DEBUG("close screensaver")
|
|
|
|
|
|
|
|
if self.suspend_msg then
|
|
|
|
|
|
|
|
UIManager:close(self.suspend_msg)
|
|
|
|
|
|
|
|
self.suspend_msg = nil
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Screensaver
|