diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 9e48da81c..395eab17b 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -339,15 +339,7 @@ function FileManager:setupLayout() end if is_file then - local status = nil - if DocSettings:hasSidecarFile(file) then - local docinfo = DocSettings:open(file) -- no io handles created, do not close - if docinfo.data.summary and docinfo.data.summary.status and docinfo.data.summary.status ~= "" then - status = docinfo.data.summary.status - else - status = "reading" - end - end + local status = filemanagerutil.getStatus(file) table.insert(buttons, { { text = _("Mark as reading"), diff --git a/frontend/apps/filemanager/filemanagercollection.lua b/frontend/apps/filemanager/filemanagercollection.lua index 8f3122af4..e4b58a64c 100644 --- a/frontend/apps/filemanager/filemanagercollection.lua +++ b/frontend/apps/filemanager/filemanagercollection.lua @@ -85,6 +85,7 @@ function FileManagerCollection:onMenuHold(item) { { text = _("Book information"), + id = "book_information", -- used by covermenu enabled = FileManagerBookInfo:isSupported(item.file), callback = function() FileManagerBookInfo:show(item.file) diff --git a/frontend/apps/filemanager/filemanagerhistory.lua b/frontend/apps/filemanager/filemanagerhistory.lua index 5362a3eae..0e8613f82 100644 --- a/frontend/apps/filemanager/filemanagerhistory.lua +++ b/frontend/apps/filemanager/filemanagerhistory.lua @@ -47,17 +47,7 @@ function FileManagerHistory:fetchStatuses(count) if v.dim then status = "deleted" else - if DocSettings:hasSidecarFile(v.file) then - local docinfo = DocSettings:open(v.file) -- no io handles created, do not close - if docinfo.data.summary and docinfo.data.summary.status - and docinfo.data.summary.status ~= "" then - status = docinfo.data.summary.status - else - status = "reading" - end - else - status = "new" - end + status = filemanagerutil.getStatus(v.file) end v.status = status if count then @@ -99,7 +89,53 @@ function FileManagerHistory:onMenuHold(item) local readerui_instance = require("apps/reader/readerui"):_getRunningInstance() local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file self.histfile_dialog = nil + local status = filemanagerutil.getStatus(item.file) local buttons = { + { + { + text = _("Mark as reading"), + enabled = status ~= "reading", + callback = function() + filemanagerutil.setStatus(item.file, "reading") + if self._manager.filter ~= "all" then + self._manager:fetchStatuses(false) + else + self._manager.statuses_fetched = false + end + self._manager:updateItemTable() + UIManager:close(self.histfile_dialog) + end, + }, + { + text = _("Mark as read"), + enabled = status ~= "complete", + callback = function() + filemanagerutil.setStatus(item.file, "complete") + if self._manager.filter ~= "all" then + self._manager:fetchStatuses(false) + else + self._manager.statuses_fetched = false + end + self._manager:updateItemTable() + UIManager:close(self.histfile_dialog) + end, + }, + { + text = _("Put on hold"), + enabled = status ~= "abandoned", + callback = function() + filemanagerutil.setStatus(item.file, "abandoned") + if self._manager.filter ~= "all" then + self._manager:fetchStatuses(false) + else + self._manager.statuses_fetched = false + end + self._manager:updateItemTable() + UIManager:close(self.histfile_dialog) + end, + }, + }, + {}, { { text = _("Reset settings"), @@ -153,6 +189,7 @@ function FileManagerHistory:onMenuHold(item) }, { text = _("Book information"), + id = "book_information", -- used by covermenu enabled = FileManagerBookInfo:isSupported(item.file), callback = function() FileManagerBookInfo:show(item.file) diff --git a/frontend/apps/filemanager/filemanagerutil.lua b/frontend/apps/filemanager/filemanagerutil.lua index 1e266d7d5..af97bfd24 100644 --- a/frontend/apps/filemanager/filemanagerutil.lua +++ b/frontend/apps/filemanager/filemanagerutil.lua @@ -63,6 +63,20 @@ function filemanagerutil.resetDocumentSettings(file) end end +-- Get a document's status ("new", "reading", "complete", or "abandoned") +function filemanagerutil.getStatus(file) + local status = "new" + if DocSettings:hasSidecarFile(file) then + local docinfo = DocSettings:open(file) -- no io handles created, do not close + if docinfo.data.summary and docinfo.data.summary.status and docinfo.data.summary.status ~= "" then + status = docinfo.data.summary.status + else + status = "reading" + end + end + return status +end + -- Set a document's status function filemanagerutil.setStatus(file, status) -- In case the book doesn't have a sidecar file, this'll create it diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua index df41f4f4f..c30489742 100644 --- a/plugins/coverbrowser.koplugin/covermenu.lua +++ b/plugins/coverbrowser.koplugin/covermenu.lua @@ -392,7 +392,7 @@ function CoverMenu:onHistoryMenuHold(item) UIManager:clearRenderStack() -- Replace Book information callback to use directly our bookinfo - orig_buttons[2][2].callback = function() + self.histfile_dialog.button_table:getButtonById("book_information").callback = function() FileManagerBookInfo:show(file, bookinfo) UIManager:close(self.histfile_dialog) end @@ -480,6 +480,28 @@ function CoverMenu:onHistoryMenuHold(item) }, }) + -- Fudge the setting resets (e.g. "Reset settings" button) to also trash the cover_info_cache + local orig_purgeSettings = filemanagerutil.purgeSettings + filemanagerutil.purgeSettings = function(f) + -- Wipe the cache + if self.cover_info_cache and self.cover_info_cache[f] then + self.cover_info_cache[f] = nil + end + -- And then purge the sidecar folder as expected + orig_purgeSettings(f) + end + + -- Fudge status changes (e.g. "Mark as read" button) to also update the cover_info_cache + local orig_setStatus = filemanagerutil.setStatus + filemanagerutil.setStatus = function(f, status) + -- Update the cache + if self.cover_info_cache and self.cover_info_cache[f] then + self.cover_info_cache[f][3] = status + end + -- And then set the status on file as expected + orig_setStatus(f, status) + end + -- Create the new ButtonDialog, and let UIManager show it local ButtonDialogTitle = require("ui/widget/buttondialogtitle") self.histfile_dialog = ButtonDialogTitle:new{ @@ -515,7 +537,7 @@ function CoverMenu:onCollectionsMenuHold(item) UIManager:clearRenderStack() -- Replace Book information callback to use directly our bookinfo - orig_buttons[2][1].callback = function() + self.collfile_dialog.button_table:getButtonById("book_information").callback = function() FileManagerBookInfo:show(file, bookinfo) UIManager:close(self.collfile_dialog) end