mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Custom metadata: event (#10869)
This commit is contained in:
@@ -1204,6 +1204,10 @@ function FileManager:onRefreshContent()
|
||||
self:onRefresh()
|
||||
end
|
||||
|
||||
function FileManager:onBookMetadataChanged()
|
||||
self:onRefresh()
|
||||
end
|
||||
|
||||
function FileManager:onShowFolderMenu()
|
||||
local button_dialog
|
||||
local function genButton(button_text, button_path)
|
||||
|
||||
@@ -9,6 +9,7 @@ local Device = require("device")
|
||||
local DocSettings = require("docsettings")
|
||||
local Document = require("document/document")
|
||||
local DocumentRegistry = require("document/documentregistry")
|
||||
local Event = require("ui/event")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local TextViewer = require("ui/widget/textviewer")
|
||||
@@ -58,7 +59,7 @@ function BookInfo:addToMainMenu(menu_items)
|
||||
end
|
||||
|
||||
-- Shows book information.
|
||||
function BookInfo:show(file, book_props, metadata_updated_caller_callback)
|
||||
function BookInfo:show(file, book_props)
|
||||
self.prop_updated = nil
|
||||
local kv_pairs = {}
|
||||
|
||||
@@ -92,7 +93,7 @@ function BookInfo:show(file, book_props, metadata_updated_caller_callback)
|
||||
self:onShowBookCover(file)
|
||||
end,
|
||||
hold_callback = function()
|
||||
self:showCustomDialog(file, book_props, metadata_updated_caller_callback)
|
||||
self:showCustomDialog(file, book_props)
|
||||
end,
|
||||
separator = true,
|
||||
})
|
||||
@@ -134,7 +135,7 @@ function BookInfo:show(file, book_props, metadata_updated_caller_callback)
|
||||
end
|
||||
table.insert(kv_pairs, { key_text, prop,
|
||||
hold_callback = function()
|
||||
self:showCustomDialog(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
self:showCustomDialog(file, book_props, prop_key)
|
||||
end,
|
||||
})
|
||||
end
|
||||
@@ -163,24 +164,11 @@ function BookInfo:show(file, book_props, metadata_updated_caller_callback)
|
||||
self.custom_doc_settings = nil
|
||||
self.custom_book_cover = nil
|
||||
if self.prop_updated then
|
||||
local ui, fm_ui
|
||||
if self.ui then
|
||||
if self.prop_updated == "title" then
|
||||
self.ui.view.footer:updateFooterText() -- in case the title changed
|
||||
end
|
||||
else
|
||||
fm_ui = require("apps/filemanager/filemanager").instance
|
||||
end
|
||||
ui = self.ui or fm_ui
|
||||
local ui = self.ui or require("apps/filemanager/filemanager").instance
|
||||
if ui.coverbrowser then -- refresh cache db
|
||||
ui.coverbrowser:deleteBookInfo(file)
|
||||
end
|
||||
if fm_ui then
|
||||
fm_ui:onRefresh()
|
||||
end
|
||||
if metadata_updated_caller_callback then
|
||||
metadata_updated_caller_callback()
|
||||
end
|
||||
UIManager:broadcastEvent(Event:new("BookMetadataChanged", self.prop_updated))
|
||||
end
|
||||
end,
|
||||
}
|
||||
@@ -355,20 +343,26 @@ function BookInfo:getCoverImage(doc, file, force_orig)
|
||||
return cover_bb
|
||||
end
|
||||
|
||||
function BookInfo:updateBookInfo(file, book_props, metadata_updated_caller_callback, prop_updated)
|
||||
function BookInfo:updateBookInfo(file, book_props, prop_updated, prop_value_old)
|
||||
if prop_updated == "cover" and self.ui then
|
||||
self.ui.doc_settings:getCoverFile(true) -- reset cover file cache
|
||||
end
|
||||
self.prop_updated = prop_updated
|
||||
self.prop_updated = {
|
||||
filepath = file,
|
||||
doc_props = book_props,
|
||||
metadata_key_updated = prop_updated,
|
||||
metadata_value_old = prop_value_old,
|
||||
metadata_value_new = book_props[prop_updated],
|
||||
}
|
||||
self.kvp_widget:onClose()
|
||||
self:show(file, book_props, metadata_updated_caller_callback)
|
||||
self:show(file, book_props)
|
||||
end
|
||||
|
||||
function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_callback)
|
||||
function BookInfo:setCustomBookCover(file, book_props)
|
||||
if self.custom_book_cover then -- reset custom cover
|
||||
if os.remove(self.custom_book_cover) then
|
||||
DocSettings:removeSidecarDir(file, util.splitFilePathName(self.custom_book_cover))
|
||||
self:updateBookInfo(file, book_props, metadata_updated_caller_callback, "cover")
|
||||
self:updateBookInfo(file, book_props, "cover")
|
||||
end
|
||||
else -- choose an image and set custom cover
|
||||
local PathChooser = require("ui/widget/pathchooser")
|
||||
@@ -379,7 +373,7 @@ function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_c
|
||||
end,
|
||||
onConfirm = function(image_file)
|
||||
if DocSettings:flushCustomCover(file, image_file) then
|
||||
self:updateBookInfo(file, book_props, metadata_updated_caller_callback, "cover")
|
||||
self:updateBookInfo(file, book_props, "cover")
|
||||
end
|
||||
end,
|
||||
}
|
||||
@@ -387,7 +381,7 @@ function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_c
|
||||
end
|
||||
end
|
||||
|
||||
function BookInfo:setCustomMetadata(file, book_props, metadata_updated_caller_callback, prop_key, prop_value)
|
||||
function BookInfo:setCustomMetadata(file, book_props, prop_key, prop_value)
|
||||
-- in file
|
||||
local custom_doc_settings, custom_props, display_title
|
||||
if self.custom_doc_settings then
|
||||
@@ -400,6 +394,7 @@ function BookInfo:setCustomMetadata(file, book_props, metadata_updated_caller_ca
|
||||
book_props.display_title = nil
|
||||
custom_doc_settings:saveSetting("doc_props", book_props) -- save a copy of original props
|
||||
end
|
||||
local prop_value_old = custom_props[prop_key] or book_props[prop_key]
|
||||
custom_props[prop_key] = prop_value -- nil when resetting a custom prop
|
||||
if next(custom_props) == nil then -- no more custom metadata
|
||||
os.remove(custom_doc_settings.custom_metadata_file)
|
||||
@@ -418,13 +413,13 @@ function BookInfo:setCustomMetadata(file, book_props, metadata_updated_caller_ca
|
||||
self.ui.doc_props.display_title = prop_value or filemanagerutil.splitFileNameType(file)
|
||||
end
|
||||
end
|
||||
self:updateBookInfo(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
self:updateBookInfo(file, book_props, prop_key, prop_value_old)
|
||||
end
|
||||
|
||||
function BookInfo:showCustomEditDialog(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
function BookInfo:showCustomEditDialog(file, book_props, prop_key)
|
||||
local input_dialog
|
||||
input_dialog = InputDialog:new{
|
||||
title = _("Edit book property:") .. " " .. self.prop_text[prop_key]:gsub(":", ""),
|
||||
title = _("Edit book metadata:") .. " " .. self.prop_text[prop_key]:gsub(":", ""),
|
||||
input = book_props[prop_key],
|
||||
input_type = prop_key == "series_index" and "number",
|
||||
allow_newline = prop_key == "authors" or prop_key == "keywords" or prop_key == "description",
|
||||
@@ -443,7 +438,7 @@ function BookInfo:showCustomEditDialog(file, book_props, metadata_updated_caller
|
||||
local prop_value = input_dialog:getInputValue()
|
||||
if prop_value and prop_value ~= "" then
|
||||
UIManager:close(input_dialog)
|
||||
self:setCustomMetadata(file, book_props, metadata_updated_caller_callback, prop_key, prop_value)
|
||||
self:setCustomMetadata(file, book_props, prop_key, prop_value)
|
||||
end
|
||||
end,
|
||||
},
|
||||
@@ -454,7 +449,7 @@ function BookInfo:showCustomEditDialog(file, book_props, metadata_updated_caller
|
||||
input_dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function BookInfo:showCustomDialog(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
function BookInfo:showCustomDialog(file, book_props, prop_key)
|
||||
local original_prop, custom_prop, prop_is_cover
|
||||
if prop_key then -- metadata
|
||||
if self.custom_doc_settings then
|
||||
@@ -502,14 +497,14 @@ function BookInfo:showCustomDialog(file, book_props, metadata_updated_caller_cal
|
||||
callback = function()
|
||||
local confirm_box = ConfirmBox:new{
|
||||
text = prop_is_cover and _("Reset custom cover?\nImage file will be deleted.")
|
||||
or _("Reset custom book property?"),
|
||||
or _("Reset custom book metadata field?"),
|
||||
ok_text = _("Reset"),
|
||||
ok_callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
if prop_is_cover then
|
||||
self:setCustomBookCover(file, book_props, metadata_updated_caller_callback)
|
||||
self:setCustomBookCover(file, book_props)
|
||||
else
|
||||
self:setCustomMetadata(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
self:setCustomMetadata(file, book_props, prop_key)
|
||||
end
|
||||
end,
|
||||
}
|
||||
@@ -522,16 +517,16 @@ function BookInfo:showCustomDialog(file, book_props, metadata_updated_caller_cal
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
if prop_is_cover then
|
||||
self:setCustomBookCover(file, book_props, metadata_updated_caller_callback)
|
||||
self:setCustomBookCover(file, book_props)
|
||||
else
|
||||
self:showCustomEditDialog(file, book_props, metadata_updated_caller_callback, prop_key)
|
||||
self:showCustomEditDialog(file, book_props, prop_key)
|
||||
end
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
button_dialog = ButtonDialog:new{
|
||||
title = _("Book property:") .. " " .. self.prop_text[prop_key]:gsub(":", ""),
|
||||
title = _("Book metadata:") .. " " .. self.prop_text[prop_key]:gsub(":", ""),
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
}
|
||||
|
||||
@@ -208,4 +208,10 @@ function FileManagerCollection:sortCollection()
|
||||
UIManager:show(sort_widget)
|
||||
end
|
||||
|
||||
function FileManagerCollection:onBookMetadataChanged()
|
||||
if self.coll_menu then
|
||||
self.coll_menu:updateItems()
|
||||
end
|
||||
end
|
||||
|
||||
return FileManagerCollection
|
||||
|
||||
@@ -259,4 +259,10 @@ function FileManagerHistory:showHistDialog()
|
||||
UIManager:show(hist_dialog)
|
||||
end
|
||||
|
||||
function FileManagerHistory:onBookMetadataChanged()
|
||||
if self.hist_menu then
|
||||
self.hist_menu:updateItems()
|
||||
end
|
||||
end
|
||||
|
||||
return FileManagerHistory
|
||||
|
||||
@@ -146,7 +146,7 @@ function filemanagerutil.genResetSettingsButton(file, caller_callback, button_di
|
||||
local check_button_settings, check_button_cover, check_button_metadata
|
||||
local confirmbox = ConfirmBox:new{
|
||||
text = T(_("Reset this document?") .. "\n\n%1\n\n" ..
|
||||
_("Resetted information will be permanently lost."),
|
||||
_("Information will be permanently lost."),
|
||||
BD.filepath(file)),
|
||||
ok_text = _("Reset"),
|
||||
ok_callback = function()
|
||||
|
||||
@@ -2514,6 +2514,12 @@ function ReaderFooter:onTimeFormatChanged()
|
||||
self:refreshFooter(true, true)
|
||||
end
|
||||
|
||||
function ReaderFooter:onBookMetadataChanged(prop_updated)
|
||||
if prop_updated.metadata_key_updated == "title" then
|
||||
self:updateFooterText()
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderFooter:onCloseWidget()
|
||||
self:free()
|
||||
end
|
||||
|
||||
@@ -466,11 +466,8 @@ function CoverMenu:onHistoryMenuHold(item)
|
||||
|
||||
-- Replace the "Book information" button callback to use directly our bookinfo
|
||||
button = self.histfile_dialog:getButtonById("book_information")
|
||||
local function when_updated_callback()
|
||||
self:updateItems()
|
||||
end
|
||||
button.callback = function()
|
||||
FileManagerBookInfo:show(file, bookinfo, when_updated_callback)
|
||||
FileManagerBookInfo:show(file, bookinfo)
|
||||
UIManager:close(self.histfile_dialog)
|
||||
end
|
||||
|
||||
@@ -589,11 +586,8 @@ function CoverMenu:onCollectionsMenuHold(item)
|
||||
|
||||
-- Replace the "Book information" button callback to use directly our bookinfo
|
||||
button = self.collfile_dialog:getButtonById("book_information")
|
||||
local function when_updated_callback()
|
||||
self:updateItems()
|
||||
end
|
||||
button.callback = function()
|
||||
FileManagerBookInfo:show(file, bookinfo, when_updated_callback)
|
||||
FileManagerBookInfo:show(file, bookinfo)
|
||||
UIManager:close(self.collfile_dialog)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user