Skip to content

Commit

Permalink
CoverImage: custom cover support (koreader#10553)
Browse files Browse the repository at this point in the history
  • Loading branch information
hius07 committed Jun 9, 2023
1 parent 976284e commit fc71814
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 3 additions & 6 deletions frontend/apps/filemanager/filemanagerbookinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function BookInfo:show(file, book_props, metadata_updated_caller_callback)
kv_pairs = kv_pairs,
values_lang = values_lang,
close_callback = function()
self.custom_book_cover = nil
if self.updated then
local FileManager = require("apps/filemanager/filemanager")
local fm_ui = FileManager.instance
Expand Down Expand Up @@ -293,7 +294,7 @@ function BookInfo:getCoverImage(doc, file, force_orig)
if cover_doc then
cover_bb = cover_doc:getCoverPageImage()
cover_doc:close()
return cover_bb
return cover_bb, custom_cover
end
end
end
Expand Down Expand Up @@ -321,11 +322,7 @@ function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_c
end
self.updated = true
self.kvp_widget:onClose()
if self.document then
self:onShowBookInfo()
else
self:show(file, book_props, metadata_updated_caller_callback)
end
self:show(file, book_props, metadata_updated_caller_callback)
end
if self.custom_book_cover then -- reset custom cover
local ConfirmBox = require("ui/widget/confirmbox")
Expand Down
12 changes: 7 additions & 5 deletions plugins/coverimage.koplugin/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local A, android = pcall(require, "android") -- luacheck: ignore
local Blitbuffer = require("ffi/blitbuffer")
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog")
local PathChooser = require("ui/widget/pathchooser")
Expand Down Expand Up @@ -110,9 +111,9 @@ end

function CoverImage:createCoverImage(doc_settings)
if self:coverEnabled() and doc_settings:nilOrFalse("exclude_cover_image") then
local cover_image = self.ui.document:getCoverPageImage()
local cover_image, custom_cover = FileManagerBookInfo:getCoverImage(self.ui.document)
if cover_image then
local cache_file = self:getCacheFile()
local cache_file = self:getCacheFile(custom_cover)
if lfs.attributes(cache_file, "mode") == "file" then
ffiutil.copyFile(cache_file, self.cover_image_path)
lfs.touch(cache_file) -- update date
Expand Down Expand Up @@ -210,11 +211,12 @@ end
-- cache handling functions
---------------------------

function CoverImage:getCacheFile()
function CoverImage:getCacheFile(custom_cover)
local custom_cover_mtime = custom_cover and lfs.attributes(custom_cover, "modification") or ""
local dummy, document_name = util.splitFilePathName(self.ui.document.file)
-- use document_name here. Title may contain characters not allowed on every filesystem (esp. vfat on /sdcard)
local key = document_name .. "_" .. self.cover_image_quality .. "_" .. self.cover_image_stretch_limit .. "_"
.. self.cover_image_background .. "_" .. self.cover_image_format .. "_" .. tostring(self.cover_image_grayscale)
local key = document_name .. custom_cover_mtime .. self.cover_image_quality .. self.cover_image_stretch_limit
.. self.cover_image_background .. self.cover_image_format .. tostring(self.cover_image_grayscale)

return self.cover_image_cache_path .. self.cover_image_cache_prefix .. md5(key) .. "." .. getExtension(self.cover_image_path)
end
Expand Down

0 comments on commit fc71814

Please sign in to comment.