diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 3f9d40a0d..f04c7c889 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -23,7 +23,9 @@ local util = require("ffi/util") local Font = require("ui/font") local DEBUG = require("dbg") local _ = require("gettext") - +local KeyValuePage = require("ui/widget/keyvaluepage") +local ReaderUI = require("apps/reader/readerui") +local InfoMessage = require("ui/widget/infomessage") local function getDefaultDir() if Device:isKindle() then @@ -112,7 +114,6 @@ function FileManager:init() function file_chooser:onFileSelect(file) -- luacheck: ignore FileManager.instance:onClose() - local ReaderUI = require("apps/reader/readerui") ReaderUI:showReader(file) return true end @@ -197,6 +198,26 @@ function FileManager:init() end, } }, + { + { + text = _("Book information"), + enabled = lfs.attributes(file, "mode") == "file" and true or false, + callback = function() + local book_info_metadata = FileManager:bookInformation(file) + if book_info_metadata then + UIManager:show(KeyValuePage:new{ + title = _("Book information"), + kv_pairs = book_info_metadata, + }) + else + UIManager:show(InfoMessage:new{ + text = _("Cannot fetch information for a selected book"), + }) + end + UIManager:close(self.file_dialog) + end, + }, + }, } if lfs.attributes(file, "mode") == "directory" then local realpath = util.realpath(file) @@ -248,6 +269,23 @@ function FileManager:init() self:handleEvent(Event:new("SetDimensions", self.dimen)) end +function FileManager:bookInformation(file) + local file_mode = lfs.attributes(file, "mode") + if file_mode ~= "file" then return false end + local book_stats = DocSettings:open(file):readSetting('stats') + if book_stats ~= nil then + return FileManagerHistory:buildBookInformationTable(book_stats) + end + local document = DocumentRegistry:openDocument(file) + if document.loadDocument then + document:loadDocument() + document:render() + end + book_stats = document:getProps() + book_stats.pages = document:getPageCount() + return FileManagerHistory:buildBookInformationTable(book_stats) +end + function FileManager:reinit(path) self.dimen = Screen:getSize() -- backup the root path and path items @@ -318,7 +356,6 @@ end function FileManager:deleteFile(file) local ok, err - local InfoMessage = require("ui/widget/infomessage") local file_abs_path = util.realpath(file) if file_abs_path == nil then UIManager:show(InfoMessage:new{ @@ -345,7 +382,6 @@ function FileManager:deleteFile(file) end function FileManager:renameFile(file) - local InfoMessage = require("ui/widget/infomessage") if util.basename(file) ~= self.rename_dialog:getInputText() then local dest = util.joinPath(util.dirname(file), self.rename_dialog:getInputText()) if self:moveFile(file, dest) then diff --git a/frontend/apps/filemanager/filemanagerhistory.lua b/frontend/apps/filemanager/filemanagerhistory.lua index 17bd81968..bbef52f16 100644 --- a/frontend/apps/filemanager/filemanagerhistory.lua +++ b/frontend/apps/filemanager/filemanagerhistory.lua @@ -6,6 +6,11 @@ local Menu = require("ui/widget/menu") local Screen = require("device").screen local util = require("ffi/util") local _ = require("gettext") +local KeyValuePage = require("ui/widget/keyvaluepage") +local DocSettings = require("docsettings") +local InfoMessage = require("ui/widget/infomessage") +local T = require("ffi/util").template + local FileManagerHistory = InputContainer:extend{ hist_menu_title = _("History"), @@ -34,6 +39,48 @@ function FileManagerHistory:onSetDimensions(dimen) self.dimen = dimen end +function FileManagerHistory:buildBookInformationTable(book_props) + if book_props == nil then + return false + end + + if book_props.authors == "" or book_props.authors == nil then + book_props.authors = _("N/A") + end + + if book_props.title == "" or book_props.title == nil then + book_props.title = _("N/A") + end + + if book_props.series == "" or book_props.series == nil then + book_props.series = _("N/A") + end + + if book_props.pages == "" or book_props.pages == nil then + book_props.pages = _("N/A") + end + + if book_props.language == "" or book_props.language == nil then + book_props.language = _("N/A") + end + + return { + { T(_("Title: %1"), book_props.title), "" }, + { T(_("Authors: %1"), book_props.authors), "" }, + { T(_("Series: %1"), book_props.series), "" }, + { T(_("Pages: %1"), book_props.pages), "" }, + { T(_("Language: %1"), string.upper(book_props.language)), "" }, + } +end + +function FileManagerHistory:bookInformation(file) + local file_mode = lfs.attributes(file, "mode") + if file_mode ~= "file" then return false end + local book_stats = DocSettings:open(file):readSetting('stats') + if book_stats == nil then return false end + return self:buildBookInformationTable(book_stats) +end + function FileManagerHistory:onMenuHold(item) self.histfile_dialog = ButtonDialog:new{ buttons = { @@ -48,6 +95,25 @@ function FileManagerHistory:onMenuHold(item) end, }, }, + { + { + text = _("Book information"), + callback = function() + local book_info_metadata = FileManagerHistory:bookInformation(item.file) + if book_info_metadata then + UIManager:show(KeyValuePage:new{ + title = _("Book information"), + kv_pairs = book_info_metadata, + }) + else + UIManager:show(InfoMessage:new{ + text = _("Cannot fetch information for a selected book"), + }) + end + UIManager:close(self.histfile_dialog) + end, + }, + }, }, } UIManager:show(self.histfile_dialog)