From fbd549bcfdf8fe0c36b61206124b57b076af1190 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 13 May 2018 13:07:23 +0200 Subject: [PATCH] End of document action (#3943) * End of document action * Rev1 * Rev2 * Rev3 * File browser --- .../apps/reader/modules/readerrolling.lua | 4 +- frontend/apps/reader/modules/readerstatus.lua | 106 +++++++++++++++++- .../elements/common_settings_menu_table.lua | 70 ++++++++++-- frontend/ui/widget/filechooser.lua | 18 +++ 4 files changed, 186 insertions(+), 12 deletions(-) diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 6dabf2cc6..51ae55254 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -517,7 +517,9 @@ function ReaderRolling:onGotoViewRel(diff) self.ui:handleEvent(Event:new("EndOfBook")) end end - self.xpointer = self.ui.document:getXPointer() + if self.ui.document ~= nil then + self.xpointer = self.ui.document:getXPointer() + end return true end diff --git a/frontend/apps/reader/modules/readerstatus.lua b/frontend/apps/reader/modules/readerstatus.lua index 032e7930e..6ba0a6c1c 100644 --- a/frontend/apps/reader/modules/readerstatus.lua +++ b/frontend/apps/reader/modules/readerstatus.lua @@ -1,6 +1,7 @@ -local InputContainer = require("ui/widget/container/inputcontainer") local BookStatusWidget = require("ui/widget/bookstatuswidget") - +local ButtonDialogTitle = require("ui/widget/buttondialogtitle") +local InfoMessage = require("ui/widget/infomessage") +local InputContainer = require("ui/widget/container/inputcontainer") local UIManager = require("ui/uimanager") local _ = require("gettext") @@ -36,12 +37,106 @@ function ReaderStatus:addToMainMenu(menu_items) end function ReaderStatus:onEndOfBook() - if G_reader_settings:nilOrTrue("auto_book_status") then + local settings = G_reader_settings:readSetting("end_document_action") + local choose_action + local collate = true + if G_reader_settings:readSetting("collate") == "access" then + collate = false + end + if settings == "pop-up" or settings == nil then + local buttons = { + { + { + text = _("Cancel"), + callback = function() + UIManager:close(choose_action) + end, + }, + { + text = _("Book status"), + callback = function() + self:showStatus() + UIManager:close(choose_action) + end, + }, + + }, + { + { + text = _("Open next file"), + enabled = collate, + callback = function() + self:openNextFile(self.document.file) + UIManager:close(choose_action) + end, + }, + { + text = _("File browser"), + callback = function() + self:openFileBrowser() + UIManager:close(choose_action) + end, + }, + }, + } + 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 self:showStatus() + 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 + elseif settings == "file_browser" then + self:openFileBrowser() + elseif settings == "book_status_file_browser" then + local before_show_callback = function() self:openFileBrowser() end + self:showStatus(before_show_callback) end end -function ReaderStatus:showStatus() +function ReaderStatus:openFileBrowser() + local FileManager = require("apps/filemanager/filemanager") + if not FileManager.instance then + self.ui:showFileManager() + end + self.ui:onClose() + 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() + local ReaderUI = require("apps/reader/readerui") + if next_file then + ReaderUI:showReader(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:showStatus(before_show_callback) local status_page = BookStatusWidget:new { thumbnail = self.document:getCoverPageImage(), props = self.document:getProps(), @@ -49,6 +144,9 @@ function ReaderStatus:showStatus() settings = self.settings, view = self.view, } + if before_show_callback then + before_show_callback() + end UIManager:show(status_page) end diff --git a/frontend/ui/elements/common_settings_menu_table.lua b/frontend/ui/elements/common_settings_menu_table.lua index a6f201f8f..d9a527112 100644 --- a/frontend/ui/elements/common_settings_menu_table.lua +++ b/frontend/ui/elements/common_settings_menu_table.lua @@ -206,13 +206,69 @@ common_settings.document = { }, }, { - text = _("Show book status at end of document "), - checked_func = function() - return G_reader_settings:nilOrTrue("auto_book_status") - end, - callback = function() - G_reader_settings:flipNilOrTrue("auto_book_status") - end, + text = _("End of document action"), + sub_item_table = { + { + text = _("Ask with pop-up dialog"), + checked_func = function() + local setting = G_reader_settings:readSetting("end_document_action") + return setting == "pop-up" or setting == nil + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "pop-up") + end, + }, + { + text = _("Do nothing"), + checked_func = function() + return G_reader_settings:readSetting("end_document_action") == "nothing" + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "nothing") + end, + }, + { + text = _("Book status"), + checked_func = function() + return G_reader_settings:readSetting("end_document_action") == "book_status" + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "book_status") + end, + }, + { + text = _("Open next file"), + enabled_func = function() + return G_reader_settings:readSetting("collate") + ~= "access" + end, + checked_func = function() + return G_reader_settings:readSetting("end_document_action") == "next_file" + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "next_file") + end, + }, + { + text = _("Return to file browser"), + checked_func = function() + return G_reader_settings:readSetting("end_document_action") == "file_browser" + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "file_browser") + end, + }, + { + text = _("Book status and return to file browser"), + checked_func = function() + return G_reader_settings:readSetting("end_document_action") == "book_status_file_browser" + end, + callback = function() + G_reader_settings:saveSetting("end_document_action", "book_status_file_browser") + end, + }, + + } }, }, } diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index f89bcfef1..35af00f49 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -1,5 +1,6 @@ local Device = require("device") local DocSettings = require("docsettings") +local DocumentRegistry = require("document/documentregistry") local Font = require("ui/font") local Menu = require("ui/widget/menu") local UIManager = require("ui/uimanager") @@ -345,4 +346,21 @@ function FileChooser:onPathChanged(path) return true end +function FileChooser:getNextFile(curr_file) + local next_file + for index, data in pairs(self.item_table) do + if data.path == curr_file then + if index+1 <= #self.item_table then + next_file = self.item_table[index+1].path + if lfs.attributes(next_file, "mode") == "file" and DocumentRegistry:hasProvider(next_file) then + break + else + next_file = nil + end + end + end + end + return next_file +end + return FileChooser