mirror of
https://github.com/koreader/koreader.git
synced 2026-12-01 17:53:53 +00:00
Book authors/title handling (#16148)
This commit is contained in:
1 parent
0563d799a6
commit
f73fe5cd00
8 files changed
+51
-64
No files matched your search
@@ -145,15 +145,7 @@ function BookInfo:show(doc_settings_or_file, book_props)
|
||||
elseif prop_key == "title" then
|
||||
prop = BD.auto(prop)
|
||||
elseif prop_key == "authors" or prop_key == "keywords" then
|
||||
if prop:find("\n") then -- BD auto isolate each entry
|
||||
prop = util.splitToArray(prop, "\n")
|
||||
for i = 1, #prop do
|
||||
prop[i] = BD.auto(prop[i])
|
||||
end
|
||||
prop = table.concat(prop, "\n")
|
||||
else
|
||||
prop = BD.auto(prop)
|
||||
end
|
||||
prop = self.prettifyAuthors(prop) -- BD auto isolate each entry
|
||||
elseif prop_key == "language" then
|
||||
-- Get a chance to have title, authors... rendered with alternate
|
||||
-- glyphs for the book language (e.g. japanese book in chinese UI)
|
||||
@@ -292,6 +284,28 @@ Source (print edition):
|
||||
UIManager:show(self.kvp_widget)
|
||||
end
|
||||
|
||||
function BookInfo.prettifyAuthors(authors, max_lines_nb)
|
||||
if type(authors) ~= "string" or authors == "" then
|
||||
return
|
||||
elseif not authors:find("\n") then
|
||||
return BD.auto(authors)
|
||||
end
|
||||
local t = util.splitToArray(authors, "\n")
|
||||
for i = 1, #t do
|
||||
t[i] = BD.auto(t[i])
|
||||
end
|
||||
if max_lines_nb and max_lines_nb < #t then
|
||||
t[max_lines_nb] = T(_("%1 et al."), t[max_lines_nb])
|
||||
return table.concat(t, "\n", 1, max_lines_nb), true
|
||||
end
|
||||
return table.concat(t, "\n"), true
|
||||
end
|
||||
|
||||
function BookInfo.combineAuthorsTitle(authors, title, separate_lines)
|
||||
return authors and T(separate_lines and "%1\n%2" or _("%1 • %2"), BookInfo.prettifyAuthors(authors, 1), title)
|
||||
or title
|
||||
end
|
||||
|
||||
function BookInfo.getCustomProp(prop_key, filepath)
|
||||
local custom_metadata_file = DocSettings:findCustomMetadataFile(filepath)
|
||||
return custom_metadata_file
|
||||
|
||||
@@ -318,8 +318,9 @@ function FileManagerCollection:onMenuHold(item)
|
||||
end
|
||||
end
|
||||
|
||||
local title = book_props and (book_props.title or book_props.display_title)
|
||||
self.file_dialog = ButtonDialog:new{
|
||||
title = BD.filename(item.text),
|
||||
title = title and self.ui.bookinfo.combineAuthorsTitle(book_props.authors, title, true) or BD.filename(item.text),
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
}
|
||||
|
||||
@@ -277,8 +277,9 @@ function FileManagerHistory:onMenuHold(item)
|
||||
end
|
||||
end
|
||||
|
||||
local title = book_props and (book_props.title or book_props.display_title)
|
||||
self.file_dialog = ButtonDialog:new{
|
||||
title = BD.filename(item.text),
|
||||
title = title and self.ui.bookinfo.combineAuthorsTitle(book_props.authors, title, true) or BD.filename(item.text),
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
}
|
||||
|
||||
@@ -1178,7 +1178,8 @@ function ReaderBookmark:getBookmarkDetailsText(bookmark, book)
|
||||
table.insert(t, 1,
|
||||
T(_("%1: %2"), TextBoxWidget.PTF_BOLD_START.._("Title")..TextBoxWidget.PTF_BOLD_END, book.doc_props.display_title))
|
||||
table.insert(t, 2,
|
||||
T(_("%1: %2"), TextBoxWidget.PTF_BOLD_START.._("Author(s)")..TextBoxWidget.PTF_BOLD_END, book.authors))
|
||||
T(_("%1: %2"), TextBoxWidget.PTF_BOLD_START.._("Author(s)")..TextBoxWidget.PTF_BOLD_END,
|
||||
self.ui.bookinfo.prettifyAuthors(book.doc_props.authors, 1)))
|
||||
end
|
||||
return TextBoxWidget.PTF_HEADER .. table.concat(t, "\n")
|
||||
end
|
||||
|
||||
@@ -358,7 +358,6 @@ function BookmarkBrowser:getBookList(files)
|
||||
doc_props = self.ui.bookinfo.extendProps(doc_props, file)
|
||||
end
|
||||
doc_props.has_cover = true -- enable "Book cover" button in the book dialog
|
||||
local authors = doc_props.authors and doc_props.authors:gsub("\n.*", " et al.") or _("Unknown author")
|
||||
table.insert(books, {
|
||||
enabled = true, -- start with showing all books from the source
|
||||
file = file,
|
||||
@@ -367,8 +366,7 @@ function BookmarkBrowser:getBookList(files)
|
||||
doc_settings = doc_settings,
|
||||
doc_props = doc_props,
|
||||
annotations = annotations,
|
||||
authors = authors,
|
||||
text = util.stringLower(authors .. doc_props.display_title),
|
||||
text = util.stringLower((doc_props.authors or "") .. doc_props.display_title), -- for sorting
|
||||
-- will be filled when building item table
|
||||
item_table_idx = nil,
|
||||
bookmarks_nb = nil,
|
||||
@@ -449,7 +447,7 @@ function BookmarkBrowser:getItemTable()
|
||||
mandatory = "\u{e28b} " .. mandatory
|
||||
end
|
||||
table.insert(item_table, { -- book entry
|
||||
text = T(_("%1 • %2"), book.authors, book.doc_props.display_title),
|
||||
text = self.ui.bookinfo.combineAuthorsTitle(book.doc_props.authors, book.doc_props.display_title),
|
||||
bold = true,
|
||||
mandatory = mandatory,
|
||||
self_books_idx = self_books_idx,
|
||||
@@ -458,7 +456,6 @@ function BookmarkBrowser:getItemTable()
|
||||
is_deleted = book.is_deleted,
|
||||
doc_props = book.doc_props,
|
||||
doc_settings = book.doc_settings,
|
||||
authors = book.authors,
|
||||
bookmarks_nb = annotations_nb,
|
||||
})
|
||||
if date_sort_func and annotations_nb > 1 then
|
||||
@@ -522,7 +519,7 @@ function BookmarkBrowser:showBookDialog(item)
|
||||
},
|
||||
}
|
||||
book_dialog = ButtonDialog:new{
|
||||
title = item.authors .. "\n" .. item.doc_props.display_title,
|
||||
title = self.ui.bookinfo.combineAuthorsTitle(item.doc_props.authors, item.doc_props.display_title, true),
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
}
|
||||
@@ -787,7 +784,7 @@ function BookmarkBrowser:showBookList(multi_choice)
|
||||
for i, book in ipairs(self.books) do
|
||||
books_enabled[i] = book.enabled
|
||||
item_table[i] = {
|
||||
text = T(_("%1 • %2"), book.authors, book.doc_props.display_title),
|
||||
text = self.ui.bookinfo.combineAuthorsTitle(book.doc_props.authors, book.doc_props.display_title),
|
||||
bold = book.is_current_file,
|
||||
mandatory = book.enabled and self.checkmark,
|
||||
}
|
||||
|
||||
@@ -5,18 +5,16 @@ local DocSettings = require("docsettings")
|
||||
local LuaSettings = require("luasettings")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local ffiUtil = require("ffi/util")
|
||||
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
local T = ffiUtil.template
|
||||
|
||||
local BookMetadataArchive = WidgetContainer:extend{
|
||||
}
|
||||
|
||||
function BookMetadataArchive:showBookList(ui)
|
||||
self.ui = ui or require("apps/filemanager/filemanager").instance or require("apps/reader/readerui").instance
|
||||
self.books = self.getBookList()
|
||||
self.books = self:getBookList()
|
||||
self.book_list = BookList:new{
|
||||
onMenuSelect = function(self_menu, item)
|
||||
self:showBookDialog(item)
|
||||
@@ -39,13 +37,13 @@ function BookMetadataArchive:updateBookList()
|
||||
self.book_list:switchItemTable(title, self.books, -1)
|
||||
end
|
||||
|
||||
function BookMetadataArchive.getBookList()
|
||||
function BookMetadataArchive:getBookList()
|
||||
local book_list = {}
|
||||
util.findFiles(G_reader_settings:readSetting("document_metadata_arc_folder"), function(fullpath, filename)
|
||||
if filename:match("%.lua$") then
|
||||
local doc_settings = LuaSettings:open(fullpath)
|
||||
if doc_settings:has("metadata_arc") then
|
||||
table.insert(book_list, BookMetadataArchive.buildItem(doc_settings))
|
||||
table.insert(book_list, self:buildItem(doc_settings))
|
||||
end
|
||||
end
|
||||
end, false)
|
||||
@@ -55,7 +53,7 @@ function BookMetadataArchive.getBookList()
|
||||
return book_list
|
||||
end
|
||||
|
||||
function BookMetadataArchive.buildItem(doc_settings)
|
||||
function BookMetadataArchive:buildItem(doc_settings)
|
||||
local doc_props = doc_settings:readSetting("doc_props")
|
||||
local metadata_arc = doc_settings:readSetting("metadata_arc")
|
||||
if metadata_arc.custom_props then
|
||||
@@ -63,13 +61,13 @@ function BookMetadataArchive.buildItem(doc_settings)
|
||||
doc_props[prop_key] = prop_value
|
||||
end
|
||||
end
|
||||
doc_props.display_title = doc_props.title
|
||||
doc_props.display_title = doc_props.display_title or doc_props.title
|
||||
or filemanagerutil.splitFileNameType(doc_settings:readSetting("doc_path"))
|
||||
local authors = doc_props.authors and doc_props.authors:gsub("\n.*", " et al.") or _("Unknown author")
|
||||
return {
|
||||
text = T(_("%1 • %2"), authors, doc_props.display_title),
|
||||
mandatory = BookMetadataArchive.getItemMandatory(doc_settings),
|
||||
text = self.ui.bookinfo.combineAuthorsTitle(doc_props.authors, doc_props.display_title),
|
||||
mandatory = self.getItemMandatory(doc_settings),
|
||||
doc_settings = doc_settings,
|
||||
doc_props = doc_props,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -138,11 +136,11 @@ function BookMetadataArchive:showBookDialog(item)
|
||||
})
|
||||
end,
|
||||
},
|
||||
filemanagerutil.genBookInformationButton(doc_settings, doc_settings:readSetting("doc_props"), close_dialog_callback),
|
||||
filemanagerutil.genBookInformationButton(doc_settings, item.doc_props, close_dialog_callback),
|
||||
},
|
||||
}
|
||||
book_dialog = ButtonDialog:new{
|
||||
title = item.text:gsub(" • ", "\n"),
|
||||
title = self.ui.bookinfo.combineAuthorsTitle(item.doc_props.authors, item.doc_props.display_title, true),
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
}
|
||||
|
||||
@@ -446,26 +446,12 @@ function ListMenuItem:update()
|
||||
authors = nil
|
||||
else
|
||||
title = bookinfo.title or filename_without_suffix
|
||||
authors = bookinfo.authors
|
||||
-- If multiple authors (crengine separates them with \n), we
|
||||
-- can display them on multiple lines, but limit to 2, and
|
||||
-- append "et al." to the 2nd if there are more
|
||||
if authors and authors:find("\n") then
|
||||
authors = util.splitToArray(authors, "\n")
|
||||
for i=1, #authors do
|
||||
authors[i] = BD.auto(authors[i])
|
||||
end
|
||||
if #authors > 1 and bookinfo.series and series_mode == "series_in_separate_line" then
|
||||
authors = { T(_("%1 et al."), authors[1]) }
|
||||
elseif #authors > 2 then
|
||||
authors = { authors[1], T(_("%1 et al."), authors[2]) }
|
||||
end
|
||||
authors = table.concat(authors, "\n")
|
||||
-- as we'll fit 3 lines instead of 2, we can avoid some loops by starting from a lower font size
|
||||
reduce_font_size = true
|
||||
elseif authors then
|
||||
authors = BD.auto(authors)
|
||||
end
|
||||
-- append "et al." to the 2nd if there are more.
|
||||
-- If we'll fit 3 lines instead of 2, we can avoid some loops by starting from a lower font size.
|
||||
local lines_nb = (bookinfo.series and series_mode == "series_in_separate_line") and 1 or 2
|
||||
authors, reduce_font_size = self.menu.ui.bookinfo.prettifyAuthors(bookinfo.authors, lines_nb)
|
||||
end
|
||||
title = BD.auto(title)
|
||||
-- add Series metadata if requested
|
||||
|
||||
@@ -22,10 +22,8 @@ local UnderlineContainer = require("ui/widget/container/underlinecontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
local _ = require("gettext")
|
||||
local Screen = Device.screen
|
||||
local T = require("ffi/util").template
|
||||
local getMenuText = require("ui/widget/menu").getMenuText
|
||||
|
||||
local BookInfoManager = require("bookinfomanager")
|
||||
@@ -133,19 +131,8 @@ function FakeCover:init()
|
||||
end
|
||||
-- If multiple authors (crengine separates them with \n), we
|
||||
-- can display them on multiple lines, but limit to 3, and
|
||||
-- append "et al." on a 4th line if there are more
|
||||
if authors and authors:find("\n") then
|
||||
authors = util.splitToArray(authors, "\n")
|
||||
for i=1, #authors do
|
||||
authors[i] = BD.auto(authors[i])
|
||||
end
|
||||
if #authors > 3 then
|
||||
authors = { authors[1], authors[2], T(_("%1 et al."), authors[3]) }
|
||||
end
|
||||
authors = table.concat(authors, "\n")
|
||||
elseif authors then
|
||||
authors = BD.auto(authors)
|
||||
end
|
||||
-- append "et al." on the 3rd line if there are more
|
||||
authors = self.menu.ui.bookinfo.prettifyAuthors(authors, 3)
|
||||
-- Add any _add, which must be already BD wrapped if needed
|
||||
if self.filename_add then
|
||||
filename = (filename and filename or "") .. self.filename_add
|
||||
@@ -582,6 +569,7 @@ function MosaicMenuItem:update()
|
||||
file_deleted = self.file_deleted,
|
||||
bottom_pad = bottom_pad,
|
||||
bottom_right_compensate = not self.show_progress_bar and self.do_hint_opened,
|
||||
menu = self.menu,
|
||||
}
|
||||
}
|
||||
end
|
||||
@@ -621,6 +609,7 @@ function MosaicMenuItem:update()
|
||||
filename_add = "\n" .. hint,
|
||||
initial_sizedec = 4, -- start with a smaller font when filenames only
|
||||
file_deleted = self.file_deleted,
|
||||
menu = self.menu,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user