filemanagerbookinfo: proper text_type of description (#11260)

reviewable/pr11272/r1
hius07 6 months ago committed by GitHub
parent 9ba66ac382
commit b949d07f4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,6 +24,7 @@ local N_ = _.ngettext
local T = require("ffi/util").template local T = require("ffi/util").template
local BookInfo = WidgetContainer:extend{ local BookInfo = WidgetContainer:extend{
title = _("Book information"),
props = { props = {
"title", "title",
"authors", "authors",
@ -54,7 +55,7 @@ end
function BookInfo:addToMainMenu(menu_items) function BookInfo:addToMainMenu(menu_items)
menu_items.book_info = { menu_items.book_info = {
text = _("Book information"), text = self.title,
callback = function() callback = function()
self:onShowBookInfo() self:onShowBookInfo()
end, end,
@ -107,7 +108,7 @@ function BookInfo:show(file, book_props)
self.custom_doc_settings = DocSettings.openSettingsFile(custom_metadata_file) self.custom_doc_settings = DocSettings.openSettingsFile(custom_metadata_file)
custom_props = self.custom_doc_settings:readSetting("custom_props") custom_props = self.custom_doc_settings:readSetting("custom_props")
end end
local values_lang local values_lang, callback
for _i, prop_key in ipairs(self.props) do for _i, prop_key in ipairs(self.props) do
local prop = book_props[prop_key] local prop = book_props[prop_key]
if prop == nil or prop == "" then if prop == nil or prop == "" then
@ -131,12 +132,16 @@ function BookInfo:show(file, book_props)
elseif prop_key == "description" then elseif prop_key == "description" then
-- Description may (often in EPUB, but not always) or may not (rarely in PDF) be HTML -- Description may (often in EPUB, but not always) or may not (rarely in PDF) be HTML
prop = util.htmlToPlainTextIfHtml(prop) prop = util.htmlToPlainTextIfHtml(prop)
callback = function() -- proper text_type in TextViewer
self:showBookProp("description", prop)
end
end end
key_text = self.prop_text[prop_key] key_text = self.prop_text[prop_key]
if custom_props and custom_props[prop_key] then -- customized if custom_props and custom_props[prop_key] then -- customized
key_text = "\u{F040} " .. key_text key_text = "\u{F040} " .. key_text
end end
table.insert(kv_pairs, { key_text, prop, table.insert(kv_pairs, { key_text, prop,
callback = callback,
hold_callback = function() hold_callback = function()
self:showCustomDialog(file, book_props, prop_key) self:showCustomDialog(file, book_props, prop_key)
end, end,
@ -159,7 +164,7 @@ function BookInfo:show(file, book_props)
local KeyValuePage = require("ui/widget/keyvaluepage") local KeyValuePage = require("ui/widget/keyvaluepage")
self.kvp_widget = KeyValuePage:new{ self.kvp_widget = KeyValuePage:new{
title = _("Book information"), title = self.title,
value_overflow_align = "right", value_overflow_align = "right",
kv_pairs = kv_pairs, kv_pairs = kv_pairs,
values_lang = values_lang, values_lang = values_lang,
@ -295,15 +300,10 @@ function BookInfo:onShowBookInfo()
end end
function BookInfo:showBookProp(prop_key, prop_text) function BookInfo:showBookProp(prop_key, prop_text)
local text_type
if prop_key == "description" then
prop_text = util.htmlToPlainTextIfHtml(prop_text)
text_type = "book_info"
end
UIManager:show(TextViewer:new{ UIManager:show(TextViewer:new{
title = self.prop_text[prop_key], title = self.prop_text[prop_key],
text = prop_text, text = prop_text,
text_type = text_type, text_type = prop_key == "description" and "book_info" or nil,
}) })
end end
@ -316,7 +316,7 @@ function BookInfo:onShowBookDescription(description, file)
end end
end end
if description then if description then
self:showBookProp("description", description) self:showBookProp("description", util.htmlToPlainTextIfHtml(description))
else else
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("No book description available."), text = _("No book description available."),

Loading…
Cancel
Save