CoverBrowser: speedup "View full size cover"

It was doing a full document load to get the cover. It now does
the faster "only metadata" load.
Also move the trick of setting a default font in CreDocument, so
that all callers of document:loadDocument(false) benefit from it.
Prevent crash when no cover image is available (even if the cache
says it has one, the file may have been updated and doesn't have
it anymore).
This commit is contained in:
poire-z
2019-03-14 13:59:32 +01:00
parent c060595580
commit 17f07e755f
3 changed files with 36 additions and 16 deletions

View File

@@ -177,6 +177,11 @@ function CreDocument:loadDocument(full_document)
if not self._loaded then
local only_metadata = full_document == false
logger.dbg("CreDocument: loading document...")
if only_metadata then
-- Setting a default font before loading document
-- actually do prevent some crashes
self:setFontFace(self.default_font)
end
if self._document:loadDocument(self.file, only_metadata) then
self._loaded = true
logger.dbg("CreDocument: loading done.")

View File

@@ -391,9 +391,6 @@ function BookInfoManager:extractBookInfo(filepath, cover_specs)
if document then
local pages
if document.loadDocument then -- needed for crengine
-- Setting a default font before loading document
-- actually do prevent some crashes
document:setFontFace(document.default_font)
if not document:loadDocument(false) then -- load only metadata
-- failed loading, calling other methods would segfault
loaded = false

View File

@@ -1,6 +1,7 @@
local DocumentRegistry = require("document/documentregistry")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local ImageViewer = require("ui/widget/imageviewer")
local InfoMessage = require("ui/widget/infomessage")
local Menu = require("ui/widget/menu")
local TextViewer = require("ui/widget/textviewer")
local UIManager = require("ui/uimanager")
@@ -127,7 +128,6 @@ function CoverMenu:updateItems(select_number)
UIManager:unschedule(self.items_update_action)
self.items_update_action = nil
end
local InfoMessage = require("ui/widget/infomessage")
UIManager:show(InfoMessage:new{
text = _("Start-up of background extraction job failed.\nPlease restart KOReader or your device.")
})
@@ -232,13 +232,22 @@ function CoverMenu:updateItems(select_number)
callback = function()
local document = DocumentRegistry:openDocument(file)
if document then
if document.loadDocument then -- needed for crengine
document:loadDocument(false) -- load only metadata
end
local cover_bb = document:getCoverPageImage()
local imgviewer = ImageViewer:new{
image = cover_bb,
with_title_bar = false,
fullscreen = true,
}
UIManager:show(imgviewer)
if cover_bb then
local imgviewer = ImageViewer:new{
image = cover_bb,
with_title_bar = false,
fullscreen = true,
}
UIManager:show(imgviewer)
else
UIManager:show(InfoMessage:new{
text = _("No cover image available."),
})
end
UIManager:close(self.file_dialog)
DocumentRegistry:closeDocument(file)
end
@@ -352,13 +361,22 @@ function CoverMenu:onHistoryMenuHold(item)
callback = function()
local document = DocumentRegistry:openDocument(file)
if document then
if document.loadDocument then -- needed for crengine
document:loadDocument(false) -- load only metadata
end
local cover_bb = document:getCoverPageImage()
local imgviewer = ImageViewer:new{
image = cover_bb,
with_title_bar = false,
fullscreen = true,
}
UIManager:show(imgviewer)
if cover_bb then
local imgviewer = ImageViewer:new{
image = cover_bb,
with_title_bar = false,
fullscreen = true,
}
UIManager:show(imgviewer)
else
UIManager:show(InfoMessage:new{
text = _("No cover image available."),
})
end
UIManager:close(self.histfile_dialog)
DocumentRegistry:closeDocument(file)
end