2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/apps/reader/modules/readerstatus.lua

274 lines
9.2 KiB
Lua
Raw Normal View History

local BD = require("ui/bidi")
local BookStatusWidget = require("ui/widget/bookstatuswidget")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local Device = require("device")
local Event = require("ui/event")
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 util = require("util")
2016-02-02 17:38:14 +00:00
local _ = require("gettext")
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()
if self.ui.document.is_pic then
2016-02-02 17:38:14 +00:00
self.enabled = false
return
else
self.total_pages = self.document:getPageCount()
self.ui.menu:registerToMainMenu(self)
end
2016-02-02 17:38:14 +00:00
end
function ReaderStatus:addToMainMenu(menu_items)
menu_items.book_status = {
text = _("Book status"),
2016-02-02 17:38:14 +00:00
callback = function()
self:onShowBookStatus()
2016-02-02 17:38:14 +00:00
end,
}
2016-02-02 17:38:14 +00:00
end
function ReaderStatus:onEndOfBook()
Device:performHapticFeedback("CONTEXT_CLICK")
local settings = G_reader_settings:readSetting("end_document_action")
local choose_action
local collate = true
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
if G_reader_settings:readSetting("collate") == "access" then
collate = false
end
-- Should we start by marking the book as read?
if G_reader_settings:isTrue("end_document_auto_mark") then
self:onMarkBook(true)
end
if (settings == "pop-up" or settings == nil) and UIManager:getTopWidget() ~= "end_document" then
local buttons = {
{
{
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,
callback = function()
self:onMarkBook()
UIManager:close(choose_action)
end,
},
{
text = _("Book status"),
callback = function()
self:onShowBookStatus()
UIManager:close(choose_action)
end,
},
},
{
{
text = _("Go to beginning"),
callback = function()
self.ui:handleEvent(Event:new("GoToBeginning"))
UIManager:close(choose_action)
end,
},
{
text = _("Open next file"),
enabled = collate,
callback = function()
self:openNextFile(self.document.file)
UIManager:close(choose_action)
end,
},
},
{
{
text = _("Delete file"),
callback = function()
self:deleteFile(self.document.file, false)
UIManager:close(choose_action)
end,
},
{
text = _("File browser"),
callback = function()
self:openFileBrowser()
UIManager:close(choose_action)
end,
},
},
{
{
text = _("Cancel"),
callback = function()
UIManager:close(choose_action)
end,
},
},
}
choose_action = ButtonDialogTitle:new{
name = "end_document",
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
self:onShowBookStatus()
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()
UIManager:close(info)
-- Delay until the next tick, as this will destroy the Document instance, but we may not be the final Event caught by said Document...
UIManager:nextTick(function()
self:openNextFile(self.document.file)
end)
else
UIManager:show(InfoMessage:new{
text = _("Could not open next file. Sort by last read date does not support this feature."),
})
end
elseif settings == "goto_beginning" then
self.ui:handleEvent(Event:new("GoToBeginning"))
elseif settings == "file_browser" then
-- Ditto
UIManager:nextTick(function()
self:openFileBrowser()
end)
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
})
elseif settings == "book_status_file_browser" then
-- Ditto
UIManager:nextTick(function()
local before_show_callback = function() self:openFileBrowser() end
self:onShowBookStatus(before_show_callback)
end)
elseif settings == "delete_file" then
-- Ditto
UIManager:nextTick(function()
self:deleteFile(self.document.file, true)
end)
end
end
function ReaderStatus:openFileBrowser()
local FileManager = require("apps/filemanager/filemanager")
self.ui:onClose()
if not FileManager.instance then
self.ui:showFileManager()
end
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
self.ui:switchDocument(next_file)
else
UIManager:show(InfoMessage:new{
text = _("This is the last file in the current folder. No next file to open."),
})
end
end
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{
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)),
ok_text = _("Delete"),
ok_callback = function()
local FileManager = require("apps/filemanager/filemanager")
self.ui:onClose()
FileManager:deleteFile(file)
require("readhistory"):fileDeleted(file) -- (will update "lastfile")
if FileManager.instance then
FileManager.instance.file_chooser:refreshPath()
else
local path = util.splitFilePathName(file)
FileManager:showFiles(path)
end
end,
})
end
function ReaderStatus:onShowBookStatus(before_show_callback)
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,
ui = self.ui,
2016-02-02 17:38:14 +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")
return true
2016-02-02 17:38:14 +00:00
end
-- 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 then
if self.settings.data.summary.status and self.settings.data.summary.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