Minimize DocSettings:open() calls (#11437)

reviewable/pr11449/r1
hius07 3 months ago committed by GitHub
parent c3bb2263b7
commit b8090c641c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -269,14 +269,26 @@ function FileManager:setupLayout()
} }
if is_file then if is_file then
self.bookinfo = nil self.book_props = nil -- in 'self' to provide access to it in CoverBrowser
local has_provider = DocumentRegistry:hasProvider(file) local has_provider = DocumentRegistry:hasProvider(file)
if has_provider or DocSettings:hasSidecarFile(file) then local has_sidecar = DocSettings:hasSidecarFile(file)
self.bookinfo = file_manager.coverbrowser and file_manager.coverbrowser:getBookInfo(file) if has_provider or has_sidecar then
table.insert(buttons, filemanagerutil.genStatusButtonsRow(file, close_dialog_refresh_callback)) self.book_props = file_manager.coverbrowser and file_manager.coverbrowser:getBookInfo(file)
local doc_settings_or_file
if has_sidecar then
doc_settings_or_file = DocSettings:open(file)
if not self.book_props then
local props = doc_settings_or_file:readSetting("doc_props")
self.book_props = FileManagerBookInfo.extendProps(props, file)
self.book_props.has_cover = true -- to enable "Book cover" button, we do not know if cover exists
end
else
doc_settings_or_file = file
end
table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_refresh_callback))
table.insert(buttons, {}) -- separator table.insert(buttons, {}) -- separator
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_refresh_callback), filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_refresh_callback),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback), filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback),
}) })
end end
@ -288,12 +300,12 @@ function FileManager:setupLayout()
file_manager:showOpenWithDialog(file) file_manager:showOpenWithDialog(file)
end, end,
}, },
filemanagerutil.genBookInformationButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookInformationButton(file, self.book_props, close_dialog_callback),
}) })
if has_provider then if has_provider then
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genBookCoverButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookCoverButton(file, self.book_props, close_dialog_callback),
filemanagerutil.genBookDescriptionButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookDescriptionButton(file, self.book_props, close_dialog_callback),
}) })
end end
if Device:canExecuteScript(file) then if Device:canExecuteScript(file) then
@ -1414,13 +1426,14 @@ function FileManager:showOpenWithDialog(file)
end end
end end
local t = {} local t = {}
for extension, provider_key in BaseUtil.orderedPairs(associated_providers) do for extension, provider_key in pairs(associated_providers) do
local provider = DocumentRegistry:getProviderFromKey(provider_key) local provider = DocumentRegistry:getProviderFromKey(provider_key)
if provider then if provider then
local space = string.rep(" ", max_len - #extension) local space = string.rep(" ", max_len - #extension)
table.insert(t, T("%1%2: %3", extension, space, provider.provider_name)) table.insert(t, T("%1%2: %3", extension, space, provider.provider_name))
end end
end end
table.sort(t)
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = table.concat(t, "\n"), text = table.concat(t, "\n"),
monospace_font = true, monospace_font = true,
@ -1479,11 +1492,10 @@ function FileManager:showOpenWithDialog(file)
end end
function FileManager:openFile(file, provider, doc_caller_callback, aux_caller_callback) function FileManager:openFile(file, provider, doc_caller_callback, aux_caller_callback)
if not provider then -- check associated if provider == nil then
local provider_key = DocumentRegistry:getAssociatedProviderKey(file) provider = DocumentRegistry:getProvider(file, true) -- include auxiliary
provider = provider_key and DocumentRegistry:getProviderFromKey(provider_key)
end end
if provider and provider.order then -- auxiliary if provider.order then -- auxiliary
if aux_caller_callback then if aux_caller_callback then
aux_caller_callback() aux_caller_callback()
end end

@ -1,7 +1,9 @@
local BD = require("ui/bidi") local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog") local ButtonDialog = require("ui/widget/buttondialog")
local Device = require("device") local Device = require("device")
local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry") local DocumentRegistry = require("document/documentregistry")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local Menu = require("ui/widget/menu") local Menu = require("ui/widget/menu")
local ReadCollection = require("readcollection") local ReadCollection = require("readcollection")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
@ -49,7 +51,7 @@ end
function FileManagerCollection:onMenuHold(item) function FileManagerCollection:onMenuHold(item)
local file = item.file local file = item.file
self.collfile_dialog = nil self.collfile_dialog = nil
self.bookinfo = self.ui.coverbrowser and self.ui.coverbrowser:getBookInfo(file) self.book_props = self.ui.coverbrowser and self.ui.coverbrowser:getBookInfo(file)
local function close_dialog_callback() local function close_dialog_callback()
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)
@ -66,11 +68,29 @@ function FileManagerCollection:onMenuHold(item)
local is_currently_opened = file == (self.ui.document and self.ui.document.file) local is_currently_opened = file == (self.ui.document and self.ui.document.file)
local buttons = {} local buttons = {}
local doc_settings_or_file = is_currently_opened and self.ui.doc_settings or file local doc_settings_or_file
if is_currently_opened then
doc_settings_or_file = self.ui.doc_settings
if not self.book_props then
self.book_props = self.ui.doc_props
self.book_props.has_cover = true
end
else
if DocSettings:hasSidecarFile(file) then
doc_settings_or_file = DocSettings:open(file)
if not self.book_props then
local props = doc_settings_or_file:readSetting("doc_props")
self.book_props = FileManagerBookInfo.extendProps(props, file)
self.book_props.has_cover = true
end
else
doc_settings_or_file = file
end
end
table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_update_callback)) table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_update_callback))
table.insert(buttons, {}) -- separator table.insert(buttons, {}) -- separator
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_update_callback, is_currently_opened), filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_update_callback, is_currently_opened),
{ {
text = _("Remove from favorites"), text = _("Remove from favorites"),
callback = function() callback = function()
@ -82,11 +102,11 @@ function FileManagerCollection:onMenuHold(item)
}) })
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback), filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback),
filemanagerutil.genBookInformationButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookInformationButton(file, self.book_props, close_dialog_callback),
}) })
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genBookCoverButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookCoverButton(file, self.book_props, close_dialog_callback),
filemanagerutil.genBookDescriptionButton(file, self.bookinfo, close_dialog_callback), filemanagerutil.genBookDescriptionButton(file, self.book_props, close_dialog_callback),
}) })
if Device:canExecuteScript(file) then if Device:canExecuteScript(file) then

@ -2,6 +2,8 @@ local BD = require("ui/bidi")
local ButtonDialog = require("ui/widget/buttondialog") local ButtonDialog = require("ui/widget/buttondialog")
local CheckButton = require("ui/widget/checkbutton") local CheckButton = require("ui/widget/checkbutton")
local ConfirmBox = require("ui/widget/confirmbox") local ConfirmBox = require("ui/widget/confirmbox")
local DocSettings = require("docsettings")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
local Menu = require("ui/widget/menu") local Menu = require("ui/widget/menu")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
@ -62,32 +64,25 @@ function FileManagerHistory:fetchStatuses(count)
end end
function FileManagerHistory:updateItemTable() function FileManagerHistory:updateItemTable()
-- try to stay on current page
local select_number = nil
if self.hist_menu.page and self.hist_menu.perpage and self.hist_menu.page > 0 then
select_number = (self.hist_menu.page - 1) * self.hist_menu.perpage + 1
end
self.count = { all = #require("readhistory").hist, self.count = { all = #require("readhistory").hist,
reading = 0, abandoned = 0, complete = 0, deleted = 0, new = 0, } reading = 0, abandoned = 0, complete = 0, deleted = 0, new = 0, }
local item_table = {} local item_table = {}
for _, v in ipairs(require("readhistory").hist) do for _, v in ipairs(require("readhistory").hist) do
if self:isItemMatch(v) then if self:isItemMatch(v) then
if self.is_frozen and v.status == "complete" then v.mandatory_dim = (self.is_frozen and v.status == "complete") and true or nil
v.mandatory_dim = true
end
table.insert(item_table, v) table.insert(item_table, v)
end end
if self.statuses_fetched then if self.statuses_fetched then
self.count[v.status] = self.count[v.status] + 1 self.count[v.status] = self.count[v.status] + 1
end end
end end
local subtitle local subtitle = ""
if self.search_string then if self.search_string then
subtitle = T(_("Search results (%1)"), #item_table) subtitle = T(_("Search results (%1)"), #item_table)
elseif self.filter ~= "all" then elseif self.filter ~= "all" then
subtitle = T(_("Status: %1 (%2)"), filter_text[self.filter]:lower(), #item_table) subtitle = T(_("Status: %1 (%2)"), filter_text[self.filter]:lower(), #item_table)
end end
self.hist_menu:switchItemTable(nil, item_table, select_number, nil, subtitle or "") self.hist_menu:switchItemTable(nil, item_table, -1, nil, subtitle)
end end
function FileManagerHistory:isItemMatch(item) function FileManagerHistory:isItemMatch(item)
@ -126,7 +121,7 @@ end
function FileManagerHistory:onMenuHold(item) function FileManagerHistory:onMenuHold(item)
local file = item.file local file = item.file
self.histfile_dialog = nil self.histfile_dialog = nil
self.bookinfo = self.ui.coverbrowser and self.ui.coverbrowser:getBookInfo(file) self.book_props = self.ui.coverbrowser and self.ui.coverbrowser:getBookInfo(file)
local function close_dialog_callback() local function close_dialog_callback()
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
@ -137,7 +132,7 @@ function FileManagerHistory:onMenuHold(item)
end end
local function close_dialog_update_callback() local function close_dialog_update_callback()
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
if self._manager.filter ~= "all" then if self._manager.filter ~= "all" or self._manager.is_frozen then
self._manager:fetchStatuses(false) self._manager:fetchStatuses(false)
else else
self._manager.statuses_fetched = false self._manager.statuses_fetched = false
@ -148,13 +143,31 @@ function FileManagerHistory:onMenuHold(item)
local is_currently_opened = file == (self.ui.document and self.ui.document.file) local is_currently_opened = file == (self.ui.document and self.ui.document.file)
local buttons = {} local buttons = {}
local doc_settings_or_file
if is_currently_opened then
doc_settings_or_file = self.ui.doc_settings
if not self.book_props then
self.book_props = self.ui.doc_props
self.book_props.has_cover = true
end
else
if DocSettings:hasSidecarFile(file) then
doc_settings_or_file = DocSettings:open(file)
if not self.book_props then
local props = doc_settings_or_file:readSetting("doc_props")
self.book_props = FileManagerBookInfo.extendProps(props, file)
self.book_props.has_cover = true
end
else
doc_settings_or_file = file
end
end
if not item.dim then if not item.dim then
local doc_settings_or_file = is_currently_opened and self.ui.doc_settings or file
table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_update_callback)) table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, close_dialog_update_callback))
table.insert(buttons, {}) -- separator table.insert(buttons, {}) -- separator
end end
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genResetSettingsButton(file, close_dialog_update_callback, is_currently_opened), filemanagerutil.genResetSettingsButton(doc_settings_or_file, close_dialog_update_callback, is_currently_opened),
filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback, item.dim), filemanagerutil.genAddRemoveFavoritesButton(file, close_dialog_callback, item.dim),
}) })
table.insert(buttons, { table.insert(buttons, {
@ -182,11 +195,11 @@ function FileManagerHistory:onMenuHold(item)
}) })
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback, item.dim), filemanagerutil.genShowFolderButton(file, close_dialog_menu_callback, item.dim),
filemanagerutil.genBookInformationButton(file, self.bookinfo, close_dialog_callback, item.dim), filemanagerutil.genBookInformationButton(file, self.book_props, close_dialog_callback, item.dim),
}) })
table.insert(buttons, { table.insert(buttons, {
filemanagerutil.genBookCoverButton(file, self.bookinfo, close_dialog_callback, item.dim), filemanagerutil.genBookCoverButton(file, self.book_props, close_dialog_callback, item.dim),
filemanagerutil.genBookDescriptionButton(file, self.bookinfo, close_dialog_callback, item.dim), filemanagerutil.genBookDescriptionButton(file, self.book_props, close_dialog_callback, item.dim),
}) })
self.histfile_dialog = ButtonDialog:new{ self.histfile_dialog = ButtonDialog:new{

@ -108,9 +108,14 @@ function filemanagerutil.getStatus(file)
end end
-- Set a document status ("reading", "complete", or "abandoned") -- Set a document status ("reading", "complete", or "abandoned")
function filemanagerutil.setStatus(file, status) function filemanagerutil.setStatus(doc_settings_or_file, status)
-- In case the book doesn't have a sidecar file, this'll create it -- In case the book doesn't have a sidecar file, this'll create it
local doc_settings = DocSettings:open(file) local doc_settings
if type(doc_settings_or_file) == "table" then
doc_settings = doc_settings_or_file
else
doc_settings = DocSettings:open(doc_settings_or_file)
end
local summary = doc_settings:readSetting("summary", {}) local summary = doc_settings:readSetting("summary", {})
summary.status = status summary.status = status
summary.modified = os.date("%Y-%m-%d", os.time()) summary.modified = os.date("%Y-%m-%d", os.time())
@ -131,9 +136,9 @@ end
-- Generate all book status file dialog buttons in a row -- Generate all book status file dialog buttons in a row
function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callback) function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callback)
local file, summary, status local file, summary, status
if type(doc_settings_or_file) == "table" then -- currently opened file if type(doc_settings_or_file) == "table" then
file = doc_settings_or_file:readSetting("doc_path") file = doc_settings_or_file:readSetting("doc_path")
summary = doc_settings_or_file:readSetting("summary") summary = doc_settings_or_file:readSetting("summary", {})
status = summary.status status = summary.status
else else
file = doc_settings_or_file file = doc_settings_or_file
@ -146,7 +151,7 @@ function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callba
enabled = status ~= to_status, enabled = status ~= to_status,
callback = function() callback = function()
summary.status = to_status summary.status = to_status
filemanagerutil.setStatus(file, to_status) filemanagerutil.setStatus(doc_settings_or_file, to_status)
UIManager:broadcastEvent(Event:new("DocSettingsItemsChanged", file, { summary = summary })) -- for CoverBrowser UIManager:broadcastEvent(Event:new("DocSettingsItemsChanged", file, { summary = summary })) -- for CoverBrowser
caller_callback() caller_callback()
end, end,
@ -160,9 +165,16 @@ function filemanagerutil.genStatusButtonsRow(doc_settings_or_file, caller_callba
end end
-- Generate "Reset" file dialog button -- Generate "Reset" file dialog button
function filemanagerutil.genResetSettingsButton(file, caller_callback, button_disabled) function filemanagerutil.genResetSettingsButton(doc_settings_or_file, caller_callback, button_disabled)
file = ffiutil.realpath(file) or file local doc_settings, file, has_sidecar_file
local has_sidecar_file = DocSettings:hasSidecarFile(file) if type(doc_settings_or_file) == "table" then
doc_settings = doc_settings_or_file
file = doc_settings_or_file:readSetting("doc_path")
has_sidecar_file = true
else
file = ffiutil.realpath(doc_settings_or_file) or doc_settings_or_file
has_sidecar_file = DocSettings:hasSidecarFile(file)
end
local custom_cover_file = DocSettings:findCustomCoverFile(file) local custom_cover_file = DocSettings:findCustomCoverFile(file)
local has_custom_cover_file = custom_cover_file and true or false local has_custom_cover_file = custom_cover_file and true or false
local custom_metadata_file = DocSettings:findCustomMetadataFile(file) local custom_metadata_file = DocSettings:findCustomMetadataFile(file)
@ -185,7 +197,7 @@ function filemanagerutil.genResetSettingsButton(file, caller_callback, button_di
custom_cover_file = check_button_cover.checked and custom_cover_file, custom_cover_file = check_button_cover.checked and custom_cover_file,
custom_metadata_file = check_button_metadata.checked and custom_metadata_file, custom_metadata_file = check_button_metadata.checked and custom_metadata_file,
} }
DocSettings:open(file):purge(nil, data_to_purge) (doc_settings or DocSettings:open(file)):purge(nil, data_to_purge)
if data_to_purge.custom_cover_file or data_to_purge.custom_metadata_file then if data_to_purge.custom_cover_file or data_to_purge.custom_metadata_file then
UIManager:broadcastEvent(Event:new("InvalidateMetadataCache", file)) UIManager:broadcastEvent(Event:new("InvalidateMetadataCache", file))
end end
@ -260,23 +272,23 @@ function filemanagerutil.genShowFolderButton(file, caller_callback, button_disab
} }
end end
function filemanagerutil.genBookInformationButton(file, bookinfo, caller_callback, button_disabled) function filemanagerutil.genBookInformationButton(file, book_props, caller_callback, button_disabled)
return { return {
text = _("Book information"), text = _("Book information"),
enabled = not button_disabled, enabled = not button_disabled,
callback = function() callback = function()
caller_callback() caller_callback()
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo") local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
FileManagerBookInfo:show(file, bookinfo and FileManagerBookInfo.extendProps(bookinfo)) FileManagerBookInfo:show(file, book_props and FileManagerBookInfo.extendProps(book_props))
end, end,
} }
end end
function filemanagerutil.genBookCoverButton(file, bookinfo, caller_callback, button_disabled) function filemanagerutil.genBookCoverButton(file, book_props, caller_callback, button_disabled)
local has_cover = bookinfo and bookinfo.has_cover local has_cover = book_props and book_props.has_cover
return { return {
text = _("Book cover"), text = _("Book cover"),
enabled = (not button_disabled and (not bookinfo or has_cover)) and true or false, enabled = (not button_disabled and (not book_props or has_cover)) and true or false,
callback = function() callback = function()
caller_callback() caller_callback()
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo") local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
@ -285,12 +297,12 @@ function filemanagerutil.genBookCoverButton(file, bookinfo, caller_callback, but
} }
end end
function filemanagerutil.genBookDescriptionButton(file, bookinfo, caller_callback, button_disabled) function filemanagerutil.genBookDescriptionButton(file, book_props, caller_callback, button_disabled)
local description = bookinfo and bookinfo.description local description = book_props and book_props.description
return { return {
text = _("Book description"), text = _("Book description"),
-- enabled for deleted books if description is kept in CoverBrowser bookinfo cache -- enabled for deleted books if description is kept in CoverBrowser bookinfo cache
enabled = (not (button_disabled or bookinfo) or description) and true or false, enabled = (not (button_disabled or book_props) or description) and true or false,
callback = function() callback = function()
caller_callback() caller_callback()
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo") local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")

@ -470,21 +470,22 @@ function ReaderUI:init()
-- And have an extended and customized copy in memory for quick access. -- And have an extended and customized copy in memory for quick access.
self.doc_props = FileManagerBookInfo.extendProps(props, self.document.file) self.doc_props = FileManagerBookInfo.extendProps(props, self.document.file)
-- Set "reading" status if there is no status. local md5 = self.doc_settings:readSetting("partial_md5_checksum")
if md5 == nil then
md5 = util.partialMD5(self.document.file)
self.doc_settings:saveSetting("partial_md5_checksum", md5)
end
local summary = self.doc_settings:readSetting("summary", {}) local summary = self.doc_settings:readSetting("summary", {})
if summary.status == nil then if summary.status == nil then
summary.status = "reading" summary.status = "reading"
summary.modified = os.date("%Y-%m-%d", os.time()) summary.modified = os.date("%Y-%m-%d", os.time())
end end
local md5 = self.doc_settings:readSetting("partial_md5_checksum") if summary.status ~= "complete" or not G_reader_settings:isTrue("history_freeze_finished_books") then
if md5 == nil then require("readhistory"):addItem(self.document.file) -- (will update "lastfile")
md5 = util.partialMD5(self.document.file)
self.doc_settings:saveSetting("partial_md5_checksum", md5)
end end
require("readhistory"):addItem(self.document.file) -- (will update "lastfile")
-- After initialisation notify that document is loaded and rendered -- After initialisation notify that document is loaded and rendered
-- CREngine only reports correct page count after rendering is done -- CREngine only reports correct page count after rendering is done
-- Need the same event for PDF document -- Need the same event for PDF document

@ -86,14 +86,15 @@ end
--- Returns the preferred registered document handler or fallback provider. --- Returns the preferred registered document handler or fallback provider.
-- @string file -- @string file
-- @bool include_aux include auxiliary (non-document) providers
-- @treturn table provider -- @treturn table provider
function DocumentRegistry:getProvider(file) function DocumentRegistry:getProvider(file, include_aux)
local providers = self:getProviders(file) local providers = self:getProviders(file)
if providers then if providers or include_aux then
-- associated provider -- associated provider
local provider_key = DocumentRegistry:getAssociatedProviderKey(file) local provider_key = DocumentRegistry:getAssociatedProviderKey(file)
local provider = provider_key and self.known_providers[provider_key] local provider = provider_key and self.known_providers[provider_key]
if provider and not provider.order then -- excluding auxiliary if provider and (not provider.order or include_aux) then -- excluding auxiliary by default
return provider return provider
end end
-- highest weighted provider -- highest weighted provider

@ -3,7 +3,6 @@ local DocSettings = require("docsettings")
local datetime = require("datetime") local datetime = require("datetime")
local dump = require("dump") local dump = require("dump")
local ffiutil = require("ffi/util") local ffiutil = require("ffi/util")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
local util = require("util") local util = require("util")
local joinPath = ffiutil.joinPath local joinPath = ffiutil.joinPath
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
@ -323,36 +322,32 @@ end
--- Adds new item (last opened document) to the top of the history list. --- Adds new item (last opened document) to the top of the history list.
-- If item time (ts) is passed, add item to the history list at this time position. -- If item time (ts) is passed, add item to the history list at this time position.
function ReadHistory:addItem(file, ts, no_flush) function ReadHistory:addItem(file, ts, no_flush)
if file ~= nil and lfs.attributes(file, "mode") == "file" then file = realpath(file)
local index = self:getIndexByFile(realpath(file)) if not file or (ts and lfs.attributes(file, "mode") ~= "file") then
if index then -- book is in the history already return -- bad legacy item
if ts and self.hist[index].time == ts then end
return -- legacy item already added local index = self:getIndexByFile(file)
end if ts and index and self.hist[index].time == ts then
if not ts and G_reader_settings:isTrue("history_freeze_finished_books") return -- legacy item already added
and filemanagerutil.getStatus(file) == "complete" then end
return -- book marked as finished, do not update timestamps of item and file local now = ts or os.time()
end local mtime = lfs.attributes(file, "modification")
end lfs.touch(file, now, mtime) -- update book access time for sorting by last read date
local now = ts or os.time() if index == 1 and not ts then -- last book, update access time only
local mtime = lfs.attributes(file, "modification") self.hist[1].time = now
lfs.touch(file, now, mtime) -- update book access time for sorting by last read date self.hist[1].mandatory = getMandatory(now)
if index == 1 and not ts then -- last book, update access time only else -- old or new book
self.hist[1].time = now if index then -- old book
self.hist[1].mandatory = getMandatory(now) table.remove(self.hist, index)
else -- old or new book
if index then -- old book
table.remove(self.hist, index)
end
index = ts and self:getIndexByTime(ts, file:gsub(".*/", "")) or 1
table.insert(self.hist, index, buildEntry(now, file))
end
if not no_flush then
self:_reduce()
self:_flush()
end end
return true -- used while adding legacy items index = ts and self:getIndexByTime(ts, file:gsub(".*/", "")) or 1
table.insert(self.hist, index, buildEntry(now, file))
end
if not no_flush then
self:_reduce()
self:_flush()
end end
return true -- used while adding legacy items
end end
--- Updates last book access time on closing the document. --- Updates last book access time on closing the document.

@ -247,7 +247,7 @@ function CoverMenu:updateItems(select_number)
-- and store it as self.file_dialog, and UIManager:show() it. -- and store it as self.file_dialog, and UIManager:show() it.
self.showFileDialog_orig(self, file) self.showFileDialog_orig(self, file)
local bookinfo = self.bookinfo -- getBookInfo(file) called by FileManager local bookinfo = self.book_props -- getBookInfo(file) called by FileManager
if not bookinfo or bookinfo._is_directory then if not bookinfo or bookinfo._is_directory then
-- If no bookinfo (yet) about this file, or it's a directory, let the original dialog be -- If no bookinfo (yet) about this file, or it's a directory, let the original dialog be
return true return true
@ -326,7 +326,7 @@ function CoverMenu:onHistoryMenuHold(item)
self.onMenuHold_orig(self, item) self.onMenuHold_orig(self, item)
local file = item.file local file = item.file
local bookinfo = self.bookinfo -- getBookInfo(file) called by FileManagerHistory local bookinfo = self.book_props -- getBookInfo(file) called by FileManagerHistory
if not bookinfo then if not bookinfo then
-- If no bookinfo (yet) about this file, let the original dialog be -- If no bookinfo (yet) about this file, let the original dialog be
return true return true
@ -397,7 +397,7 @@ function CoverMenu:onCollectionsMenuHold(item)
self.onMenuHold_orig(self, item) self.onMenuHold_orig(self, item)
local file = item.file local file = item.file
local bookinfo = self.bookinfo -- getBookInfo(file) called by FileManagerCollection local bookinfo = self.book_props -- getBookInfo(file) called by FileManagerCollection
if not bookinfo then if not bookinfo then
-- If no bookinfo (yet) about this file, let the original dialog be -- If no bookinfo (yet) about this file, let the original dialog be
return true return true

Loading…
Cancel
Save