2020-01-04 00:18:51 +00:00
local BD = require ( " ui/bidi " )
2017-12-17 17:27:24 +00:00
local Blitbuffer = require ( " ffi/blitbuffer " )
local ButtonDialogTitle = require ( " ui/widget/buttondialogtitle " )
local BookStatusWidget = require ( " ui/widget/bookstatuswidget " )
2018-07-23 08:37:24 +00:00
local DataStorage = require ( " datastorage " )
2016-04-18 05:30:46 +00:00
local Device = require ( " device " )
2014-09-17 10:24:33 +00:00
local DocSettings = require ( " docsettings " )
2017-09-05 07:01:46 +00:00
local DocumentRegistry = require ( " document/documentregistry " )
2017-12-17 17:27:24 +00:00
local InfoMessage = require ( " ui/widget/infomessage " )
local ImageWidget = require ( " ui/widget/imagewidget " )
2019-07-19 03:52:12 +00:00
local Math = require ( " optmath " )
2017-12-17 17:27:24 +00:00
local ScreenSaverWidget = require ( " ui/widget/screensaverwidget " )
2017-09-05 07:01:46 +00:00
local UIManager = require ( " ui/uimanager " )
2017-12-17 17:27:24 +00:00
local lfs = require ( " libs/libkoreader-lfs " )
2016-12-29 08:10:38 +00:00
local logger = require ( " logger " )
2017-12-17 17:27:24 +00:00
local _ = require ( " gettext " )
2017-09-05 07:01:46 +00:00
local Screen = Device.screen
2017-12-17 17:27:24 +00:00
local T = require ( " ffi/util " ) . template
2014-08-22 07:05:00 +00:00
2018-09-30 18:29:43 +00:00
local screensaver_provider = {
[ " jpg " ] = true ,
[ " jpeg " ] = true ,
[ " png " ] = true ,
[ " gif " ] = true ,
[ " tif " ] = true ,
[ " tiff " ] = true ,
}
2017-12-17 17:27:24 +00:00
local default_screensaver_message = _ ( " Sleeping " )
local Screensaver = { }
2016-04-15 00:42:54 +00:00
local function getRandomImage ( dir )
if string.sub ( dir , string.len ( dir ) ) ~= " / " then
dir = dir .. " / "
end
2014-08-22 07:05:00 +00:00
local pics = { }
local i = 0
2014-08-26 10:10:26 +00:00
math.randomseed ( os.time ( ) )
2018-06-16 21:05:20 +00:00
local ok , iter , dir_obj = pcall ( lfs.dir , dir )
if ok then
for entry in iter , dir_obj do
if lfs.attributes ( dir .. entry , " mode " ) == " file " then
2018-09-30 18:29:43 +00:00
local extension = string.lower ( string.match ( entry , " .+%.([^.]+) " ) or " " )
if screensaver_provider [ extension ] then
2018-06-16 21:05:20 +00:00
i = i + 1
pics [ i ] = entry
end
2014-08-22 07:05:00 +00:00
end
end
2018-06-16 21:05:20 +00:00
if i == 0 then
return nil
end
else
2016-11-17 13:12:31 +00:00
return nil
end
2017-12-17 17:27:24 +00:00
return dir .. pics [ math.random ( i ) ]
2016-04-15 20:21:39 +00:00
end
2017-12-17 17:27:24 +00:00
function Screensaver : chooseFolder ( )
local buttons = { }
table.insert ( buttons , {
{
2018-09-13 11:20:09 +00:00
text = _ ( " Choose screensaver directory " ) ,
2017-12-17 17:27:24 +00:00
callback = function ( )
UIManager : close ( self.choose_dialog )
require ( " ui/downloadmgr " ) : new {
onConfirm = function ( path )
logger.dbg ( " set screensaver directory to " , path )
G_reader_settings : saveSetting ( " screensaver_dir " , path )
UIManager : show ( InfoMessage : new {
2020-01-04 00:18:51 +00:00
text = T ( _ ( " Screensaver directory set to: \n %1 " ) , BD.dirpath ( path ) ) ,
2017-12-17 17:27:24 +00:00
timeout = 3 ,
} )
end ,
} : chooseDir ( )
end ,
}
} )
table.insert ( buttons , {
{
text = _ ( " Close " ) ,
callback = function ( )
UIManager : close ( self.choose_dialog )
end ,
}
} )
local screensaver_dir = G_reader_settings : readSetting ( " screensaver_dir " )
if screensaver_dir == nil then
screensaver_dir = DataStorage : getDataDir ( ) .. " /screenshots/ "
end
self.choose_dialog = ButtonDialogTitle : new {
2020-01-04 00:18:51 +00:00
title = T ( _ ( " Current screensaver image directory: \n %1 " ) , BD.dirpath ( screensaver_dir ) ) ,
2017-12-17 17:27:24 +00:00
buttons = buttons
}
UIManager : show ( self.choose_dialog )
2016-08-01 01:26:26 +00:00
end
2019-09-16 13:27:49 +00:00
function Screensaver : chooseFile ( document_cover )
local text = document_cover and _ ( " Choose document cover " ) or _ ( " Choose screensaver image " )
2018-07-23 08:37:24 +00:00
local buttons = { }
table.insert ( buttons , {
{
2019-09-16 13:27:49 +00:00
text = text ,
2018-07-23 08:37:24 +00:00
callback = function ( )
UIManager : close ( self.choose_dialog )
2019-03-15 13:14:53 +00:00
local util = require ( " util " )
local PathChooser = require ( " ui/widget/pathchooser " )
local path_chooser = PathChooser : new {
select_directory = false ,
select_file = true ,
2018-07-23 08:37:24 +00:00
file_filter = function ( filename )
local suffix = util.getFileNameSuffix ( filename )
2019-09-16 13:27:49 +00:00
if document_cover and DocumentRegistry : hasProvider ( filename ) then
return true
elseif screensaver_provider [ suffix ] then
2018-07-23 08:37:24 +00:00
return true
end
end ,
2019-03-15 13:14:53 +00:00
detailed_file_info = true ,
path = self.root_path ,
onConfirm = function ( file_path )
2019-09-16 13:27:49 +00:00
if document_cover then
G_reader_settings : saveSetting ( " screensaver_document_cover " , file_path )
UIManager : show ( InfoMessage : new {
2020-01-04 00:18:51 +00:00
text = T ( _ ( " Screensaver document cover set to: \n %1 " ) , BD.filepath ( file_path ) ) ,
2019-09-16 13:27:49 +00:00
timeout = 3 ,
} )
else
G_reader_settings : saveSetting ( " screensaver_image " , file_path )
UIManager : show ( InfoMessage : new {
2020-01-04 00:18:51 +00:00
text = T ( _ ( " Screensaver image set to: \n %1 " ) , BD.filepath ( file_path ) ) ,
2019-09-16 13:27:49 +00:00
timeout = 3 ,
} )
end
2019-03-15 13:14:53 +00:00
end
2018-07-23 08:37:24 +00:00
}
2019-03-15 13:14:53 +00:00
UIManager : show ( path_chooser )
2018-07-23 08:37:24 +00:00
end ,
}
} )
table.insert ( buttons , {
{
text = _ ( " Close " ) ,
callback = function ( )
UIManager : close ( self.choose_dialog )
end ,
}
} )
local screensaver_image = G_reader_settings : readSetting ( " screensaver_image " )
2019-09-16 13:27:49 +00:00
local screensaver_document_cover = G_reader_settings : readSetting ( " screensaver_document_cover " )
2018-07-23 08:37:24 +00:00
if screensaver_image == nil then
screensaver_image = DataStorage : getDataDir ( ) .. " /resources/koreader.png "
end
2020-01-04 00:18:51 +00:00
local title = document_cover and T ( _ ( " Current screensaver document cover: \n %1 " ) , BD.filepath ( screensaver_document_cover ) )
or T ( _ ( " Current screensaver image: \n %1 " ) , BD.filepath ( screensaver_image ) )
2018-07-23 08:37:24 +00:00
self.choose_dialog = ButtonDialogTitle : new {
2019-09-16 13:27:49 +00:00
title = title ,
2018-07-23 08:37:24 +00:00
buttons = buttons
}
UIManager : show ( self.choose_dialog )
end
2018-01-21 18:44:12 +00:00
function Screensaver : stretchImages ( )
return G_reader_settings : isTrue ( " screensaver_stretch_images " )
end
function Screensaver : whiteBackground ( )
return G_reader_settings : isTrue ( " screensaver_white_background " )
2017-12-17 17:27:24 +00:00
end
2016-08-01 01:26:26 +00:00
2019-03-14 19:58:45 +00:00
function Screensaver : noBackground ( )
return G_reader_settings : isTrue ( " screensaver_no_background " )
end
2017-12-17 17:27:24 +00:00
function Screensaver : excluded ( )
2016-08-01 01:26:26 +00:00
local lastfile = G_reader_settings : readSetting ( " lastfile " )
2017-12-17 17:27:24 +00:00
local exclude_ss = false -- consider it not excluded if there's no docsetting
if DocSettings : hasSidecarFile ( lastfile ) then
local doc_settings = DocSettings : open ( lastfile )
exclude_ss = doc_settings : readSetting ( " exclude_screensaver " )
end
return exclude_ss or false
end
function Screensaver : setMessage ( )
local InputDialog = require ( " ui/widget/inputdialog " )
local screensaver_message = G_reader_settings : readSetting ( " screensaver_message " )
if screensaver_message == nil then
screensaver_message = default_screensaver_message
2014-08-27 03:07:25 +00:00
end
2017-12-17 17:27:24 +00:00
self.input_dialog = InputDialog : new {
title = " Screensaver message " ,
2019-07-18 12:11:21 +00:00
description = _ ( " Enter the message to be displayed by the screensaver. The following escape sequences can be used: \n %p percentage read \n %c current page number \n %t total number of pages \n %T title " ) ,
2017-12-17 17:27:24 +00:00
input = screensaver_message ,
buttons = {
{
{
text = _ ( " Cancel " ) ,
callback = function ( )
UIManager : close ( self.input_dialog )
end ,
} ,
{
text = _ ( " Set message " ) ,
is_enter_default = true ,
callback = function ( )
G_reader_settings : saveSetting ( " screensaver_message " , self.input_dialog : getInputText ( ) )
UIManager : close ( self.input_dialog )
end ,
} ,
} ,
} ,
}
UIManager : show ( self.input_dialog )
2018-03-30 10:46:36 +00:00
self.input_dialog : onShowKeyboard ( )
2014-08-22 07:05:00 +00:00
end
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
function Screensaver : show ( event , fallback_message )
-- These 2 (optional) parameters are to support poweroff and reboot actions
-- on Kobo (see uimanager.lua)
2017-12-17 17:27:24 +00:00
if self.left_msg then
UIManager : close ( self.left_msg )
self.left_msg = nil
end
2018-03-17 22:02:32 +00:00
local covers_fullscreen = true -- hint for UIManager:_repaint()
2018-01-21 18:44:12 +00:00
local overlay_message
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
local prefix = event and event .. " _ " or " " -- "", "poweroff_" or "reboot_"
local screensaver_type = G_reader_settings : readSetting ( prefix .. " screensaver_type " )
2018-01-21 18:44:12 +00:00
if prefix and not screensaver_type then
-- No manually added setting for poweroff/reboot, fallback to using the
-- same settings as for suspend that could be set via menus
screensaver_type = G_reader_settings : readSetting ( " screensaver_type " )
prefix = " "
-- And display fallback_message over the common screensaver,
-- so user can distinguish between suspend (no message) and
-- poweroff (overlay message)
overlay_message = fallback_message
end
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
if screensaver_type == nil then
screensaver_type = " message "
end
if screensaver_type == " disable " then
2017-12-17 17:27:24 +00:00
return
end
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
local widget = nil
2019-03-14 19:58:45 +00:00
local background = Blitbuffer.COLOR_BLACK
if self : whiteBackground ( ) then
background = Blitbuffer.COLOR_WHITE
elseif self : noBackground ( ) then
background = nil
end
2019-09-16 13:27:49 +00:00
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
2017-12-17 17:27:24 +00:00
if screensaver_type == " cover " then
2019-09-16 13:27:49 +00:00
lastfile = lastfile ~= nil and lastfile or G_reader_settings : readSetting ( " lastfile " )
2017-12-17 17:27:24 +00:00
local exclude = false -- consider it not excluded if there's no docsetting
if DocSettings : hasSidecarFile ( lastfile ) then
2016-08-01 01:26:26 +00:00
local doc_settings = DocSettings : open ( lastfile )
2017-12-17 17:27:24 +00:00
exclude = doc_settings : readSetting ( " exclude_screensaver " )
2014-09-17 10:24:33 +00:00
end
2017-12-17 17:27:24 +00:00
if exclude ~= true then
2019-11-24 15:18:23 +00:00
if lastfile and lfs.attributes ( lastfile , " mode " ) == " file " then
2017-12-17 17:27:24 +00:00
local doc = DocumentRegistry : openDocument ( lastfile )
2018-11-20 20:07:59 +00:00
if doc.loadDocument then -- CreDocument
doc : loadDocument ( false ) -- load only metadata
end
2017-12-17 17:27:24 +00:00
local image = doc : getCoverPageImage ( )
doc : close ( )
if image ~= nil then
widget = ImageWidget : new {
image = image ,
image_disposable = true ,
height = Screen : getHeight ( ) ,
width = Screen : getWidth ( ) ,
2018-01-21 18:44:12 +00:00
scale_factor = not self : stretchImages ( ) and 0 or nil ,
2017-12-17 17:27:24 +00:00
}
2016-11-16 10:49:34 +00:00
else
2017-12-17 17:27:24 +00:00
screensaver_type = " random_image "
2016-11-16 10:49:34 +00:00
end
2017-12-17 17:27:24 +00:00
else
screensaver_type = " random_image "
2014-08-26 10:10:26 +00:00
end
2017-12-17 17:27:24 +00:00
else --fallback to random images if this book cover is excluded
screensaver_type = " random_image "
2014-08-26 10:10:26 +00:00
end
end
2017-12-17 17:27:24 +00:00
if screensaver_type == " bookstatus " then
2019-11-24 15:18:23 +00:00
if lastfile and lfs.attributes ( lastfile , " mode " ) == " file " then
2017-12-17 17:27:24 +00:00
local doc = DocumentRegistry : openDocument ( lastfile )
local doc_settings = DocSettings : open ( lastfile )
local instance = require ( " apps/reader/readerui " ) : _getRunningInstance ( )
if instance ~= nil then
widget = BookStatusWidget : new {
thumbnail = doc : getCoverPageImage ( ) ,
props = doc : getProps ( ) ,
document = doc ,
settings = doc_settings ,
view = instance.view ,
readonly = true ,
}
else
screensaver_type = " message "
end
doc : close ( )
else
screensaver_type = " message "
2017-04-08 21:21:03 +00:00
end
2017-12-17 17:27:24 +00:00
end
if screensaver_type == " random_image " then
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
local screensaver_dir = G_reader_settings : readSetting ( prefix .. " screensaver_dir " )
2018-07-23 08:37:24 +00:00
if screensaver_dir == nil and prefix ~= " " then
screensaver_dir = G_reader_settings : readSetting ( " screensaver_dir " )
end
2017-12-17 17:27:24 +00:00
if screensaver_dir == nil then
screensaver_dir = DataStorage : getDataDir ( ) .. " /screenshots/ "
end
local image_file = getRandomImage ( screensaver_dir )
if image_file == nil then
screensaver_type = " message "
else
widget = ImageWidget : new {
file = image_file ,
2018-01-21 18:44:12 +00:00
file_do_cache = false ,
2017-12-17 17:27:24 +00:00
alpha = true ,
height = Screen : getHeight ( ) ,
width = Screen : getWidth ( ) ,
2018-01-21 18:44:12 +00:00
scale_factor = not self : stretchImages ( ) and 0 or nil ,
2017-12-17 17:27:24 +00:00
}
end
end
2018-07-23 08:37:24 +00:00
if screensaver_type == " image_file " then
local screensaver_image = G_reader_settings : readSetting ( prefix .. " screensaver_image " )
if screensaver_image == nil and prefix ~= " " then
screensaver_image = G_reader_settings : readSetting ( " screensaver_image " )
end
if screensaver_image == nil then
screensaver_image = DataStorage : getDataDir ( ) .. " /resources/koreader.png "
end
if lfs.attributes ( screensaver_image , " mode " ) ~= " file " then
screensaver_type = " message "
else
widget = ImageWidget : new {
file = screensaver_image ,
file_do_cache = false ,
alpha = true ,
height = Screen : getHeight ( ) ,
width = Screen : getWidth ( ) ,
scale_factor = not self : stretchImages ( ) and 0 or nil ,
}
end
end
2017-12-17 17:27:24 +00:00
if screensaver_type == " readingprogress " then
if Screensaver.getReaderProgress ~= nil then
widget = Screensaver.getReaderProgress ( )
else
screensaver_type = " message "
end
end
if screensaver_type == " message " then
Screensaver: change default & show messages on reboot and poweroff (#3572)
Use "message" as the default for screensaver (instead of "disable") (https://github.com/koreader/koreader/pull/3535#issuecomment-353337143)
On Kobo
Fix: display message on poweroff or reboot (https://github.com/koreader/koreader/pull/3535#issuecomment-352355865)
Allows for overwritting these default messages with the classic screensaver settings, by just prepending "poweroff_" or "reboot_" to them. (https://github.com/koreader/koreader/pull/3535#issuecomment-352498497)
So one can manually add to its settings.reader.lua:
```
"poweroff_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"poweroff_screensaver_dir" = "path to same as screensaver_dir or alternate dir for poweroff image(s)",
"poweroff_screensaver_message" = "message to use instead of Powered off",
```
```
"reboot_screensaver_type" = "random_image" or "message", "cover", "bookstatus", "readingprogress", "disable",
"reboot_screensaver_dir" = "path to same as screensaver_dir or alternate dir for reboot image(s)",
"reboot_screensaver_message" = "message to use instead of Rebooting...",
```
2018-01-06 12:21:26 +00:00
local screensaver_message = G_reader_settings : readSetting ( prefix .. " screensaver_message " )
2018-01-21 18:44:12 +00:00
if not self : whiteBackground ( ) then
background = nil -- no background filling, let book text visible
2018-03-17 22:02:32 +00:00
covers_fullscreen = false
2017-12-17 17:27:24 +00:00
end
2018-07-23 08:37:24 +00:00
if screensaver_message == nil and prefix ~= " " then
screensaver_message = G_reader_settings : readSetting ( " screensaver_message " )
end
2019-07-18 12:11:21 +00:00
local fallback = fallback_message or default_screensaver_message
2017-12-17 17:27:24 +00:00
if screensaver_message == nil then
2019-07-18 12:11:21 +00:00
screensaver_message = fallback
else
screensaver_message = self : expandSpecial ( screensaver_message , fallback )
2017-12-17 17:27:24 +00:00
end
2019-07-18 12:11:21 +00:00
2017-12-17 17:27:24 +00:00
widget = InfoMessage : new {
text = screensaver_message ,
readonly = true ,
}
2018-01-21 18:44:12 +00:00
-- No overlay needed as we just displayed the message
overlay_message = nil
end
if overlay_message then
widget = self : addOverlayMessage ( widget , overlay_message )
2017-12-17 17:27:24 +00:00
end
if widget then
self.left_msg = ScreenSaverWidget : new {
widget = widget ,
background = background ,
2018-03-17 22:02:32 +00:00
covers_fullscreen = covers_fullscreen ,
2017-12-17 17:27:24 +00:00
}
2017-09-05 07:01:46 +00:00
self.left_msg . modal = true
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
-- Refresh whole screen for other types
self.left_msg . dithered = true
2016-11-16 10:49:34 +00:00
UIManager : show ( self.left_msg , " full " )
2014-08-26 10:10:26 +00:00
end
end
2019-07-18 12:11:21 +00:00
function Screensaver : expandSpecial ( message , fallback )
-- Expand special character sequences in given message. Use fallback string if there is no document instance
-- %p percentage read
-- %c current page
-- %t total pages
-- %T document title
local ret = message
local lastfile = G_reader_settings : readSetting ( " lastfile " )
local instance = require ( " apps/reader/readerui " ) : _getRunningInstance ( )
2019-11-24 15:18:23 +00:00
if lastfile and lfs.attributes ( lastfile , " mode " ) == " file " and instance ~= nil then
local doc = DocumentRegistry : openDocument ( lastfile )
2019-07-18 12:11:21 +00:00
local currentpage = instance.view . state.page
ret = string.gsub ( ret , " %%c " , currentpage )
local totalpages = doc : getPageCount ( )
ret = string.gsub ( ret , " %%t " , totalpages )
2019-07-19 03:52:12 +00:00
local percent = Math.round ( ( currentpage * 100 ) / totalpages )
2019-07-18 12:11:21 +00:00
ret = string.gsub ( ret , " %%p " , percent )
local props = doc : getProps ( )
ret = string.gsub ( ret , " %%T " , props.title )
2019-11-24 15:18:23 +00:00
doc : close ( )
2019-07-18 12:11:21 +00:00
else
ret = fallback
end
return ret
end
2014-08-26 10:10:26 +00:00
function Screensaver : close ( )
2017-12-17 17:27:24 +00:00
if self.left_msg == nil then return end
local screensaver_delay = G_reader_settings : readSetting ( " screensaver_delay " )
local screensaver_delay_number = tonumber ( screensaver_delay )
if screensaver_delay_number then
UIManager : scheduleIn ( screensaver_delay_number , function ( )
logger.dbg ( " close screensaver " )
if self.left_msg then
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
UIManager : close ( self.left_msg , " full " )
2017-12-17 17:27:24 +00:00
self.left_msg = nil
end
end )
elseif screensaver_delay == " disable " or screensaver_delay == nil then
logger.dbg ( " close screensaver " )
if self.left_msg then
2019-02-19 17:17:58 +00:00
UIManager : close ( self.left_msg , " full " )
2017-12-17 17:27:24 +00:00
self.left_msg = nil
end
else
logger.dbg ( " tap to exit from screensaver " )
2014-08-26 10:10:26 +00:00
end
end
2018-01-21 18:44:12 +00:00
function Screensaver : addOverlayMessage ( widget , text )
local Font = require ( " ui/font " )
local FrameContainer = require ( " ui/widget/container/framecontainer " )
local OverlapGroup = require ( " ui/widget/overlapgroup " )
local RightContainer = require ( " ui/widget/container/rightcontainer " )
local Size = require ( " ui/size " )
local TextBoxWidget = require ( " ui/widget/textboxwidget " )
local TextWidget = require ( " ui/widget/textwidget " )
local face = Font : getFace ( " infofont " )
local screen_w , screen_h = Screen : getWidth ( ) , Screen : getHeight ( )
2019-10-21 13:20:40 +00:00
local textw = TextWidget : new {
text = text ,
face = face ,
}
2018-01-21 18:44:12 +00:00
-- Don't make our message reach full screen width
2019-10-21 13:20:40 +00:00
if textw : getWidth ( ) > screen_w * 0.9 then
-- Text too wide: use TextBoxWidget for multi lines display
2018-01-21 18:44:12 +00:00
textw = TextBoxWidget : new {
text = text ,
face = face ,
width = math.floor ( screen_w * 0.9 )
}
end
textw = FrameContainer : new {
background = Blitbuffer.COLOR_WHITE ,
bordersize = Size.border . default ,
margin = 0 ,
textw ,
}
textw = RightContainer : new {
dimen = {
w = screen_w ,
h = textw : getSize ( ) . h ,
} ,
textw ,
}
widget = OverlapGroup : new {
dimen = {
h = screen_w ,
w = screen_h ,
} ,
widget ,
textw ,
}
return widget
end
2014-08-26 10:10:26 +00:00
return Screensaver