MosaicMenu: correct access to doc settings (#10140)

reviewable/pr10147/r1
hius07 1 year ago committed by GitHub
parent 54b3b5a8cc
commit 5cf72b6eea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,5 @@
local BD = require("ui/bidi")
local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local ImageViewer = require("ui/widget/imageviewer")
@ -45,12 +46,31 @@ local CoverMenu = {}
local book_statuses = {"reading", "abandoned", "complete"}
function CoverMenu:updateCache(file, status)
if self.cover_info_cache and self.cover_info_cache[file] then
if status then
self.cover_info_cache[file][3] = status
function CoverMenu:updateCache(file, status, do_create, pages)
if do_create then -- create new cache entry if absent
if self.cover_info_cache[file] then return end
local doc_settings = DocSettings:open(file)
-- We can get nb of page in the new 'doc_pages' setting, or from the old 'stats.page'
local doc_pages = doc_settings:readSetting("doc_pages")
if doc_pages then
pages = doc_pages
else
self.cover_info_cache[file] = nil
local stats = doc_settings:readSetting("stats")
if stats and stats.pages and stats.pages ~= 0 then -- crengine with statistics disabled stores 0
pages = stats.pages
end
end
local percent_finished = doc_settings:readSetting("percent_finished")
local summary = doc_settings:readSetting("summary")
status = summary and summary.status
self.cover_info_cache[file] = {pages, percent_finished, status}
else
if self.cover_info_cache and self.cover_info_cache[file] then
if status then
self.cover_info_cache[file][3] = status
else
self.cover_info_cache[file] = nil
end
end
end
end

@ -390,25 +390,8 @@ function ListMenuItem:update()
local percent_finished, status
if DocSettings:hasSidecarFile(self.filepath) then
self.been_opened = true
if self.menu.cover_info_cache[self.filepath] then
pages, percent_finished, status = unpack(self.menu.cover_info_cache[self.filepath])
else
local doc_settings = DocSettings:open(self.filepath)
-- We can get nb of page in the new 'doc_pages' setting, or from the old 'stats.page'
local doc_pages = doc_settings:readSetting("doc_pages")
if doc_pages then
pages = doc_pages
else
local stats = doc_settings:readSetting("stats")
if stats and stats.pages and stats.pages ~= 0 then -- crengine with statistics disabled stores 0
pages = stats.pages
end
end
percent_finished = doc_settings:readSetting("percent_finished")
local summary = doc_settings:readSetting("summary")
status = summary and summary.status
self.menu.cover_info_cache[self.filepath] = {pages, percent_finished, status}
end
self.menu:updateCache(self.filepath, nil, true, pages) -- create new cache entry if absent
pages, percent_finished, status = unpack(self.menu.cover_info_cache[self.filepath])
end
if status == "complete" or status == "abandoned" then
-- Display these instead of the read %

@ -574,27 +574,10 @@ function MosaicMenuItem:update()
self.menu.cover_info_cache = {}
end
local percent_finished, status
local pages = bookinfo.pages
if DocSettings:hasSidecarFile(self.filepath) then
self.been_opened = true
if self.menu.cover_info_cache[self.filepath] then
pages, percent_finished, status = unpack(self.menu.cover_info_cache[self.filepath]) -- luacheck: no unused
else
local docinfo = DocSettings:open(self.filepath)
-- We can get nb of page in the new 'doc_pages' setting, or from the old 'stats.page'
if docinfo.data.doc_pages then
pages = docinfo.data.doc_pages
elseif docinfo.data.stats and docinfo.data.stats.pages then
if docinfo.data.stats.pages ~= 0 then -- crengine with statistics disabled stores 0
pages = docinfo.data.stats.pages
end
end
if docinfo.data.summary and docinfo.data.summary.status then
status = docinfo.data.summary.status
end
percent_finished = docinfo.data.percent_finished
self.menu.cover_info_cache[self.filepath] = {pages, percent_finished, status}
end
self.menu:updateCache(self.filepath, nil, true, bookinfo.pages) -- create new cache entry if absent
_, percent_finished, status = unpack(self.menu.cover_info_cache[self.filepath])
end
self.percent_finished = percent_finished
self.status = status

Loading…
Cancel
Save