2020-01-04 00:18:51 +00:00
|
|
|
local BD = require("ui/bidi")
|
2016-03-07 05:38:20 +00:00
|
|
|
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
2018-05-13 11:07:23 +00:00
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
2019-09-29 13:42:05 +00:00
|
|
|
local Device = require("device")
|
2020-02-05 07:19:35 +00:00
|
|
|
local Event = require("ui/event")
|
2018-05-13 11:07:23 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2016-02-02 17:38:14 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local _ = require("gettext")
|
2019-07-05 08:35:23 +00:00
|
|
|
local T = require("ffi/util").template
|
2016-02-02 17:38:14 +00:00
|
|
|
|
|
|
|
local ReaderStatus = InputContainer:new {
|
|
|
|
document = nil,
|
|
|
|
summary = {
|
|
|
|
rating = 0,
|
|
|
|
note = nil,
|
|
|
|
status = "",
|
|
|
|
modified = "",
|
|
|
|
},
|
|
|
|
enabled = true,
|
2016-02-09 12:51:55 +00:00
|
|
|
total_pages = 0
|
2016-02-02 17:38:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderStatus:init()
|
2016-07-15 14:58:41 +00:00
|
|
|
if self.ui.document.is_pic then
|
2016-02-02 17:38:14 +00:00
|
|
|
self.enabled = false
|
|
|
|
return
|
2016-03-07 05:52:53 +00:00
|
|
|
else
|
|
|
|
self.total_pages = self.document:getPageCount()
|
2016-02-10 07:17:53 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2016-03-07 05:52:53 +00:00
|
|
|
end
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function ReaderStatus:addToMainMenu(menu_items)
|
|
|
|
menu_items.book_status = {
|
2016-03-07 05:52:53 +00:00
|
|
|
text = _("Book status"),
|
2016-02-02 17:38:14 +00:00
|
|
|
callback = function()
|
2019-03-06 17:50:32 +00:00
|
|
|
self:onShowBookStatus()
|
2016-02-02 17:38:14 +00:00
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2018-01-30 11:12:52 +00:00
|
|
|
function ReaderStatus:onEndOfBook()
|
2019-09-29 13:42:05 +00:00
|
|
|
Device:performHapticFeedback("CONTEXT_CLICK")
|
2018-05-13 11:07:23 +00:00
|
|
|
local settings = G_reader_settings:readSetting("end_document_action")
|
|
|
|
local choose_action
|
|
|
|
local collate = true
|
2018-06-13 19:43:50 +00:00
|
|
|
local QuickStart = require("ui/quickstart")
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
|
|
|
if last_file and last_file == QuickStart.quickstart_filename then
|
|
|
|
self:openFileBrowser()
|
|
|
|
return
|
|
|
|
end
|
2018-05-13 11:07:23 +00:00
|
|
|
if G_reader_settings:readSetting("collate") == "access" then
|
|
|
|
collate = false
|
|
|
|
end
|
2020-06-11 09:37:14 +00:00
|
|
|
|
|
|
|
-- Should we start by marking the book as read?
|
|
|
|
if G_reader_settings:isTrue("end_document_auto_mark") then
|
|
|
|
self:onMarkBook(true)
|
|
|
|
end
|
|
|
|
|
2018-05-13 11:07:23 +00:00
|
|
|
if settings == "pop-up" or settings == nil then
|
|
|
|
local buttons = {
|
|
|
|
{
|
|
|
|
{
|
2019-11-16 13:51:21 +00:00
|
|
|
text_func = function()
|
|
|
|
if self.settings.data.summary and self.settings.data.summary.status == "complete" then
|
|
|
|
return _("Mark as reading")
|
|
|
|
else
|
|
|
|
return _("Mark as read")
|
|
|
|
end
|
|
|
|
end,
|
2018-05-13 11:07:23 +00:00
|
|
|
callback = function()
|
2019-11-16 13:51:21 +00:00
|
|
|
self:onMarkBook()
|
2018-05-13 11:07:23 +00:00
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Book status"),
|
|
|
|
callback = function()
|
2019-03-07 15:35:05 +00:00
|
|
|
self:onShowBookStatus()
|
2018-05-13 11:07:23 +00:00
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
2019-07-05 08:35:23 +00:00
|
|
|
{
|
2020-02-05 07:19:35 +00:00
|
|
|
text = _("Go to beginning"),
|
2019-07-05 08:35:23 +00:00
|
|
|
callback = function()
|
2020-02-05 07:19:35 +00:00
|
|
|
self.ui:handleEvent(Event:new("GoToBeginning"))
|
2019-07-05 08:35:23 +00:00
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
{
|
|
|
|
text = _("Open next file"),
|
|
|
|
enabled = collate,
|
|
|
|
callback = function()
|
|
|
|
self:openNextFile(self.document.file)
|
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
2019-07-05 08:35:23 +00:00
|
|
|
},
|
|
|
|
{
|
2019-11-16 13:51:21 +00:00
|
|
|
{
|
2020-02-05 07:19:35 +00:00
|
|
|
text = _("Delete file"),
|
2019-11-16 13:51:21 +00:00
|
|
|
callback = function()
|
2020-02-05 07:19:35 +00:00
|
|
|
self:deleteFile(self.document.file, false)
|
2019-11-16 13:51:21 +00:00
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
{
|
|
|
|
text = _("File browser"),
|
|
|
|
callback = function()
|
|
|
|
self:openFileBrowser()
|
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2020-02-05 07:19:35 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Cancel"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(choose_action)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
}
|
|
|
|
choose_action = ButtonDialogTitle:new{
|
|
|
|
title = _("You've reached the end of the document.\nWhat would you like to do?"),
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
|
|
|
|
|
|
|
UIManager:show(choose_action)
|
|
|
|
elseif settings == "book_status" then
|
2019-03-07 15:35:05 +00:00
|
|
|
self:onShowBookStatus()
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "next_file" then
|
|
|
|
if G_reader_settings:readSetting("collate") ~= "access" then
|
|
|
|
local info = InfoMessage:new{
|
|
|
|
text = _("Searching next file…"),
|
|
|
|
}
|
|
|
|
UIManager:show(info)
|
|
|
|
UIManager:forceRePaint()
|
|
|
|
self:openNextFile(self.document.file)
|
|
|
|
UIManager:close(info)
|
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Could not open next file. Sort by last read date does not support this feature."),
|
|
|
|
})
|
|
|
|
end
|
2020-02-05 07:19:35 +00:00
|
|
|
elseif settings == "goto_beginning" then
|
|
|
|
self.ui:handleEvent(Event:new("GoToBeginning"))
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "file_browser" then
|
|
|
|
self:openFileBrowser()
|
2019-11-16 13:51:21 +00:00
|
|
|
elseif settings == "mark_read" then
|
|
|
|
self:onMarkBook(true)
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("You've reached the end of the document.\nThe current book is marked as read."),
|
|
|
|
timeout = 3
|
|
|
|
})
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "book_status_file_browser" then
|
|
|
|
local before_show_callback = function() self:openFileBrowser() end
|
2019-03-07 15:35:05 +00:00
|
|
|
self:onShowBookStatus(before_show_callback)
|
2019-07-05 08:35:23 +00:00
|
|
|
elseif settings == "delete_file" then
|
|
|
|
self:deleteFile(self.document.file, true)
|
2018-01-30 11:12:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-13 11:07:23 +00:00
|
|
|
function ReaderStatus:openFileBrowser()
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
2019-06-09 13:19:38 +00:00
|
|
|
self.ui:onClose()
|
2018-05-13 11:07:23 +00:00
|
|
|
if not FileManager.instance then
|
|
|
|
self.ui:showFileManager()
|
|
|
|
end
|
|
|
|
self.document = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderStatus:openNextFile(next_file)
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
if not FileManager.instance then
|
|
|
|
self.ui:showFileManager()
|
|
|
|
end
|
|
|
|
next_file = FileManager.instance.file_chooser:getNextFile(next_file)
|
|
|
|
FileManager.instance:onClose()
|
|
|
|
if next_file then
|
2018-07-11 16:05:30 +00:00
|
|
|
self.ui:switchDocument(next_file)
|
2018-05-13 11:07:23 +00:00
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("This is the last file in the current folder. No next file to open."),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-05 08:35:23 +00:00
|
|
|
function ReaderStatus:deleteFile(file, text_end_book)
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local message_end_book = ""
|
|
|
|
if text_end_book then
|
|
|
|
message_end_book = "You've reached the end of the document.\n"
|
|
|
|
end
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T(_("%1Are you sure that you want to delete this file?\n%2\nIf you delete a file, it is permanently lost."), message_end_book, BD.filepath(file)),
|
2019-07-05 08:35:23 +00:00
|
|
|
ok_text = _("Delete"),
|
|
|
|
ok_callback = function()
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
2020-05-05 16:12:58 +00:00
|
|
|
self.ui:onClose()
|
2019-07-05 08:35:23 +00:00
|
|
|
FileManager:deleteFile(file)
|
2020-05-06 19:11:34 +00:00
|
|
|
require("readhistory"):fileDeleted(file) -- (will update "lastfile")
|
2019-12-12 17:49:11 +00:00
|
|
|
if FileManager.instance then
|
|
|
|
FileManager.instance.file_chooser:refreshPath()
|
2020-05-05 16:12:58 +00:00
|
|
|
else
|
|
|
|
FileManager:showFiles()
|
2019-12-12 17:49:11 +00:00
|
|
|
end
|
2019-07-05 08:35:23 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-03-06 17:50:32 +00:00
|
|
|
function ReaderStatus:onShowBookStatus(before_show_callback)
|
2016-03-07 05:38:20 +00:00
|
|
|
local status_page = BookStatusWidget:new {
|
2016-02-02 17:38:14 +00:00
|
|
|
thumbnail = self.document:getCoverPageImage(),
|
|
|
|
props = self.document:getProps(),
|
|
|
|
document = self.document,
|
|
|
|
settings = self.settings,
|
2016-02-12 14:55:02 +00:00
|
|
|
view = self.view,
|
2016-02-02 17:38:14 +00:00
|
|
|
}
|
2018-05-13 11:07:23 +00:00
|
|
|
if before_show_callback then
|
|
|
|
before_show_callback()
|
|
|
|
end
|
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
|
|
|
status_page.dithered = true
|
|
|
|
UIManager:show(status_page, "full")
|
2019-03-06 17:50:32 +00:00
|
|
|
return true
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2019-11-16 13:51:21 +00:00
|
|
|
-- If mark_read is true then we change status only from reading/abandoned to read (complete).
|
|
|
|
-- Otherwise we change status from reading/abandoned to read or from read to reading.
|
|
|
|
function ReaderStatus:onMarkBook(mark_read)
|
|
|
|
if self.settings.data.summary and self.settings.data.summary.status then
|
|
|
|
local current_status = self.settings.data.summary.status
|
|
|
|
if current_status == "complete" then
|
|
|
|
if mark_read then
|
|
|
|
-- Keep mark as read.
|
|
|
|
self.settings.data.summary.status = "complete"
|
|
|
|
else
|
|
|
|
-- Change current status from read (complete) to reading
|
|
|
|
self.settings.data.summary.status = "reading"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.settings.data.summary.status = "complete"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.settings.data.summary = {status = "complete"}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-02 17:38:14 +00:00
|
|
|
function ReaderStatus:onReadSettings(config)
|
|
|
|
self.settings = config
|
|
|
|
end
|
|
|
|
|
|
|
|
return ReaderStatus
|