|
|
@ -1,6 +1,7 @@
|
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local Screen = require("device").screen
|
|
|
|
local Device = require("device")
|
|
|
|
|
|
|
|
local Screen = Device.screen
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local DEBUG = require("dbg")
|
|
|
|
local DEBUG = require("dbg")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local _ = require("gettext")
|
|
|
@ -8,85 +9,74 @@ local _ = require("gettext")
|
|
|
|
local Screensaver = {
|
|
|
|
local Screensaver = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function Screensaver:getCoverImage(file)
|
|
|
|
local function createWidgetFromImage(image_widget)
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
if image_widget then
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local AlphaContainer = require("ui/widget/container/alphacontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local AlphaContainer = require("ui/widget/container/alphacontainer")
|
|
|
|
return AlphaContainer:new{
|
|
|
|
local image_height
|
|
|
|
alpha = 1,
|
|
|
|
local image_width
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
local screen_height = Screen:getHeight()
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
local screen_width = Screen:getWidth()
|
|
|
|
CenterContainer:new{
|
|
|
|
local doc = DocumentRegistry:openDocument(file)
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
if doc then
|
|
|
|
image_widget,
|
|
|
|
local image = doc:getCoverPageImage()
|
|
|
|
|
|
|
|
doc:close()
|
|
|
|
|
|
|
|
local lastfile = G_reader_settings:readSetting("lastfile")
|
|
|
|
|
|
|
|
local data = DocSettings:open(lastfile)
|
|
|
|
|
|
|
|
local proportional_cover = data:readSetting("proportional_screensaver")
|
|
|
|
|
|
|
|
if image then
|
|
|
|
|
|
|
|
if proportional_cover then
|
|
|
|
|
|
|
|
image_height = image:getHeight()
|
|
|
|
|
|
|
|
image_width = image:getWidth()
|
|
|
|
|
|
|
|
local image_ratio = image_width / image_height
|
|
|
|
|
|
|
|
if image_ratio < 1 then
|
|
|
|
|
|
|
|
image_height = screen_height
|
|
|
|
|
|
|
|
image_width = image_height * image_ratio
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
image_width = screen_width
|
|
|
|
|
|
|
|
image_height = image_width / image_ratio
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
image_height = screen_height
|
|
|
|
|
|
|
|
image_width = screen_width
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local image_widget = ImageWidget:new{
|
|
|
|
|
|
|
|
image = image,
|
|
|
|
|
|
|
|
width = image_width,
|
|
|
|
|
|
|
|
height = image_height,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return AlphaContainer:new{
|
|
|
|
|
|
|
|
alpha = 1,
|
|
|
|
|
|
|
|
height = screen_height,
|
|
|
|
|
|
|
|
width = screen_width,
|
|
|
|
|
|
|
|
CenterContainer:new{
|
|
|
|
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
|
|
|
|
FrameContainer:new{
|
|
|
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
|
|
|
padding = 0,
|
|
|
|
|
|
|
|
height = screen_height,
|
|
|
|
|
|
|
|
width = screen_width,
|
|
|
|
|
|
|
|
image_widget
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Screensaver:getRandomImage(dir)
|
|
|
|
local function createWidgetFromFile(file)
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
if lfs.attributes(file, "mode") == "file" then
|
|
|
|
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
|
|
|
|
return createWidgetFromImage(
|
|
|
|
|
|
|
|
ImageWidget:new{
|
|
|
|
|
|
|
|
file = file,
|
|
|
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
|
|
|
autostretch = true,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function getRandomImage(dir)
|
|
|
|
|
|
|
|
if string.sub(dir, string.len(dir)) ~= "/" then
|
|
|
|
|
|
|
|
dir = dir .. "/"
|
|
|
|
|
|
|
|
end
|
|
|
|
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 =
|
|
|
|
if extension == "jpg" or extension == "jpeg" or extension == "png" then
|
|
|
|
string.lower(string.match(entry, ".+%.([^.]+)") or "")
|
|
|
|
|
|
|
|
if extension == "jpg"
|
|
|
|
|
|
|
|
or extension == "jpeg"
|
|
|
|
|
|
|
|
or extension == "png" then
|
|
|
|
i = i + 1
|
|
|
|
i = i + 1
|
|
|
|
pics[i] = entry
|
|
|
|
pics[i] = entry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local image = pics[math.random(i)]
|
|
|
|
return createWidgetFromFile(dir .. pics[math.random(i)])
|
|
|
|
if image then
|
|
|
|
end
|
|
|
|
image = dir .. image
|
|
|
|
|
|
|
|
if lfs.attributes(image, "mode") == "file" then
|
|
|
|
function Screensaver:getCoverImage(file)
|
|
|
|
return ImageWidget:new{
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
file = image,
|
|
|
|
local doc = DocumentRegistry:openDocument(file)
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
if doc then
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
local image = doc:getCoverPageImage()
|
|
|
|
}
|
|
|
|
doc:close()
|
|
|
|
|
|
|
|
local lastfile = G_reader_settings:readSetting("lastfile")
|
|
|
|
|
|
|
|
local data = DocSettings:open(lastfile)
|
|
|
|
|
|
|
|
local proportional_cover = data:readSetting("proportional_screensaver")
|
|
|
|
|
|
|
|
if image then
|
|
|
|
|
|
|
|
return createWidgetFromImage(
|
|
|
|
|
|
|
|
ImageWidget:new{
|
|
|
|
|
|
|
|
image = image,
|
|
|
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
|
|
|
autostretch = proportional_cover,
|
|
|
|
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -95,7 +85,9 @@ function Screensaver:show()
|
|
|
|
DEBUG("show screensaver")
|
|
|
|
DEBUG("show screensaver")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
-- first check book cover image
|
|
|
|
-- first check book cover image
|
|
|
|
if KOBO_SCREEN_SAVER_LAST_BOOK then
|
|
|
|
screen_saver_last_book =
|
|
|
|
|
|
|
|
G_reader_settings:readSetting("use_lastfile_as_screensaver")
|
|
|
|
|
|
|
|
if screen_saver_last_book == nil or screen_saver_last_book then
|
|
|
|
local lastfile = G_reader_settings:readSetting("lastfile")
|
|
|
|
local lastfile = G_reader_settings:readSetting("lastfile")
|
|
|
|
if lastfile then
|
|
|
|
if lastfile then
|
|
|
|
local data = DocSettings:open(lastfile)
|
|
|
|
local data = DocSettings:open(lastfile)
|
|
|
@ -107,20 +99,19 @@ function Screensaver:show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- then screensaver directory or file image
|
|
|
|
-- then screensaver directory or file image
|
|
|
|
if not self.suspend_msg then
|
|
|
|
if not self.suspend_msg then
|
|
|
|
if type(KOBO_SCREEN_SAVER) == "string" then
|
|
|
|
local screen_saver_folder =
|
|
|
|
local file = KOBO_SCREEN_SAVER
|
|
|
|
G_reader_settings:readSetting("screensaver_folder")
|
|
|
|
|
|
|
|
if screen_saver_folder == nil
|
|
|
|
|
|
|
|
and Device.internal_storage_mount_point ~= nil then
|
|
|
|
|
|
|
|
screen_saver_folder =
|
|
|
|
|
|
|
|
Device.internal_storage_mount_point .. "screensaver"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if screen_saver_folder then
|
|
|
|
|
|
|
|
local file = screen_saver_folder
|
|
|
|
if lfs.attributes(file, "mode") == "directory" then
|
|
|
|
if lfs.attributes(file, "mode") == "directory" then
|
|
|
|
if string.sub(file,string.len(file)) ~= "/" then
|
|
|
|
self.suspend_msg = getRandomImage(file)
|
|
|
|
file = file .. "/"
|
|
|
|
else
|
|
|
|
end
|
|
|
|
self.suspend_msg = createWidgetFromFile(file)
|
|
|
|
self.suspend_msg = self:getRandomImage(file)
|
|
|
|
|
|
|
|
elseif lfs.attributes(file, "mode") == "file" then
|
|
|
|
|
|
|
|
local ImageWidget = require("ui/widget/imagewidget")
|
|
|
|
|
|
|
|
self.suspend_msg = ImageWidget:new{
|
|
|
|
|
|
|
|
file = file,
|
|
|
|
|
|
|
|
width = Screen:getWidth(),
|
|
|
|
|
|
|
|
height = Screen:getHeight(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|