[feat] Allow setting any document cover as screensaver (#5369)

Cf. suggestion by @KenMaltby in <https://github.com/koreader/koreader/issues/3033#issuecomment-526657352>.
pull/5390/head
Frans de Jonge 5 years ago committed by GitHub
parent 788e6d90df
commit 5bc9700c24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -56,6 +56,19 @@ return {
G_reader_settings:saveSetting("screensaver_type", "random_image") G_reader_settings:saveSetting("screensaver_type", "random_image")
end end
}, },
{
text = _("Use document cover as screensaver"),
checked_func = function()
if screensaverType() == "document_cover" then
return true
else
return false
end
end,
callback = function()
G_reader_settings:saveSetting("screensaver_type", "document_cover")
end
},
{ {
text = _("Use image as screensaver"), text = _("Use image as screensaver"),
checked_func = function() checked_func = function()
@ -126,6 +139,13 @@ return {
Screensaver:chooseFile() Screensaver:chooseFile()
end, end,
}, },
{
text = _("Document cover"),
keep_menu_open = true,
callback = function()
Screensaver:chooseFile(true)
end,
},
{ {
text = _("Screensaver message"), text = _("Screensaver message"),
keep_menu_open = true, keep_menu_open = true,

@ -93,11 +93,12 @@ function Screensaver:chooseFolder()
UIManager:show(self.choose_dialog) UIManager:show(self.choose_dialog)
end end
function Screensaver:chooseFile() function Screensaver:chooseFile(document_cover)
local text = document_cover and _("Choose document cover") or _("Choose screensaver image")
local buttons = {} local buttons = {}
table.insert(buttons, { table.insert(buttons, {
{ {
text = _("Choose screensaver image"), text = text,
callback = function() callback = function()
UIManager:close(self.choose_dialog) UIManager:close(self.choose_dialog)
local util = require("util") local util = require("util")
@ -107,18 +108,28 @@ function Screensaver:chooseFile()
select_file = true, select_file = true,
file_filter = function(filename) file_filter = function(filename)
local suffix = util.getFileNameSuffix(filename) local suffix = util.getFileNameSuffix(filename)
if screensaver_provider[suffix] then if document_cover and DocumentRegistry:hasProvider(filename) then
return true
elseif screensaver_provider[suffix] then
return true return true
end end
end, end,
detailed_file_info = true, detailed_file_info = true,
path = self.root_path, path = self.root_path,
onConfirm = function(file_path) onConfirm = function(file_path)
G_reader_settings:saveSetting("screensaver_image", file_path) if document_cover then
UIManager:show(InfoMessage:new{ G_reader_settings:saveSetting("screensaver_document_cover", file_path)
text = T(_("Screensaver image set to:\n%1"), file_path), UIManager:show(InfoMessage:new{
timeout = 3, text = T(_("Screensaver document cover set to:\n%1"), file_path),
}) timeout = 3,
})
else
G_reader_settings:saveSetting("screensaver_image", file_path)
UIManager:show(InfoMessage:new{
text = T(_("Screensaver image set to:\n%1"), file_path),
timeout = 3,
})
end
end end
} }
UIManager:show(path_chooser) UIManager:show(path_chooser)
@ -134,11 +145,14 @@ function Screensaver:chooseFile()
} }
}) })
local screensaver_image = G_reader_settings:readSetting("screensaver_image") local screensaver_image = G_reader_settings:readSetting("screensaver_image")
local screensaver_document_cover = G_reader_settings:readSetting("screensaver_document_cover")
if screensaver_image == nil then if screensaver_image == nil then
screensaver_image = DataStorage:getDataDir() .. "/resources/koreader.png" screensaver_image = DataStorage:getDataDir() .. "/resources/koreader.png"
end end
local title = document_cover and T(_("Current screensaver document cover:\n %1"), screensaver_document_cover)
or T(_("Current screensaver image:\n %1"), screensaver_image)
self.choose_dialog = ButtonDialogTitle:new{ self.choose_dialog = ButtonDialogTitle:new{
title = T(_("Current screensaver image:\n %1"), screensaver_image), title = title,
buttons = buttons buttons = buttons
} }
UIManager:show(self.choose_dialog) UIManager:show(self.choose_dialog)
@ -234,8 +248,14 @@ function Screensaver:show(event, fallback_message)
elseif self:noBackground() then elseif self:noBackground() then
background = nil background = nil
end end
local lastfile = G_reader_settings:readSetting("lastfile")
if screensaver_type == "document_cover" then
-- Set lastfile to the document of which we want to show the cover.
lastfile = G_reader_settings:readSetting("screensaver_document_cover")
screensaver_type = "cover"
end
if screensaver_type == "cover" then if screensaver_type == "cover" then
local lastfile = G_reader_settings:readSetting("lastfile") lastfile = lastfile ~= nil and lastfile or G_reader_settings:readSetting("lastfile")
local exclude = false -- consider it not excluded if there's no docsetting local exclude = false -- consider it not excluded if there's no docsetting
if DocSettings:hasSidecarFile(lastfile) then if DocSettings:hasSidecarFile(lastfile) then
local doc_settings = DocSettings:open(lastfile) local doc_settings = DocSettings:open(lastfile)
@ -269,7 +289,6 @@ function Screensaver:show(event, fallback_message)
end end
end end
if screensaver_type == "bookstatus" then if screensaver_type == "bookstatus" then
local lastfile = G_reader_settings:readSetting("lastfile")
if lfs.attributes(lastfile, "mode") == "file" then if lfs.attributes(lastfile, "mode") == "file" then
local doc = DocumentRegistry:openDocument(lastfile) local doc = DocumentRegistry:openDocument(lastfile)
local doc_settings = DocSettings:open(lastfile) local doc_settings = DocSettings:open(lastfile)

Loading…
Cancel
Save