|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
local BD = require("ui/bidi")
|
|
|
|
|
local DocumentRegistry = require("document/documentregistry")
|
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
|
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
|
|
|
|
|
local ImageViewer = require("ui/widget/imageviewer")
|
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
@ -306,59 +305,8 @@ function CoverMenu:updateItems(select_number)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
table.insert(orig_buttons, {
|
|
|
|
|
{ -- Mark the book as read/unread
|
|
|
|
|
text_func = function()
|
|
|
|
|
-- If the book has a cache entry, it means it has a sidecar file, and it *may* have the info we need.
|
|
|
|
|
local status
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[file] then
|
|
|
|
|
local _, _, c_status = unpack(self.cover_info_cache[file])
|
|
|
|
|
status = c_status
|
|
|
|
|
end
|
|
|
|
|
-- NOTE: status may still be nil if the BookStatus widget was never opened in this book.
|
|
|
|
|
-- For our purposes, we assume this means reading or on hold, which is just fine.
|
|
|
|
|
-- NOTE: This also means we assume "on hold" means reading, meaning it'll be flipped to "finished",
|
|
|
|
|
-- which I'm personally okay with, too.
|
|
|
|
|
-- c.f., BookStatusWidget:generateSwitchGroup for the three possible constant values.
|
|
|
|
|
return status == "complete" and _("Mark as reading") or _("Mark as read")
|
|
|
|
|
end,
|
|
|
|
|
callback = function()
|
|
|
|
|
local status
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[file] then
|
|
|
|
|
local c_pages, c_percent_finished, c_status = unpack(self.cover_info_cache[file])
|
|
|
|
|
status = c_status == "complete" and "reading" or "complete"
|
|
|
|
|
-- Update the cache, even if it had a nil status before
|
|
|
|
|
self.cover_info_cache[file] = {c_pages, c_percent_finished, status}
|
|
|
|
|
else
|
|
|
|
|
-- We assumed earlier an empty status meant "reading", so, flip that to "complete"
|
|
|
|
|
status = "complete"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- In case the book doesn't have a sidecar file, this'll create it
|
|
|
|
|
local docinfo = DocSettings:open(file)
|
|
|
|
|
if docinfo.data.summary and docinfo.data.summary.status then
|
|
|
|
|
-- Book already had the full BookStatus table in its sidecar, easy peasy!
|
|
|
|
|
docinfo.data.summary.status = status
|
|
|
|
|
else
|
|
|
|
|
-- No BookStatus table, create a minimal one...
|
|
|
|
|
if docinfo.data.summary then
|
|
|
|
|
-- Err, a summary table with no status entry? Should never happen...
|
|
|
|
|
local summary = { status = status }
|
|
|
|
|
-- Append the status entry to the existing summary...
|
|
|
|
|
util.tableMerge(docinfo.data.summary, summary)
|
|
|
|
|
else
|
|
|
|
|
-- No summary table at all, create a minimal one
|
|
|
|
|
local summary = { status = status }
|
|
|
|
|
docinfo:saveSetting("summary", summary)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
docinfo:flush()
|
|
|
|
|
|
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
|
self:updateItems()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{ -- Allow a new extraction (multiple interruptions, book replaced)...
|
|
|
|
|
text = _("Refresh book info"),
|
|
|
|
|
text = _("Refresh cached book information"),
|
|
|
|
|
enabled = bookinfo and true or false,
|
|
|
|
|
callback = function()
|
|
|
|
|
-- Wipe the cache
|
|
|
|
@ -372,6 +320,28 @@ function CoverMenu:updateItems(select_number)
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- Fudge the setting resets (e.g. "Reset settings" button) to also trash the cover_info_cache
|
|
|
|
|
local orig_purgeSettings = filemanagerutil.purgeSettings
|
|
|
|
|
filemanagerutil.purgeSettings = function(f)
|
|
|
|
|
-- Wipe the cache
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[f] then
|
|
|
|
|
self.cover_info_cache[f] = nil
|
|
|
|
|
end
|
|
|
|
|
-- And then purge the sidecar folder as expected
|
|
|
|
|
orig_purgeSettings(f)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Fudge status changes (e.g. "Mark as read" button) to also update the cover_info_cache
|
|
|
|
|
local orig_setStatus = filemanagerutil.setStatus
|
|
|
|
|
filemanagerutil.setStatus = function(f, status)
|
|
|
|
|
-- Update the cache
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[f] then
|
|
|
|
|
self.cover_info_cache[f][3] = status
|
|
|
|
|
end
|
|
|
|
|
-- And then set the status on file as expected
|
|
|
|
|
orig_setStatus(f, status)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Create the new ButtonDialogTitle, and let UIManager show it
|
|
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
|
|
|
|
self.file_dialog = ButtonDialogTitle:new{
|
|
|
|
@ -380,20 +350,8 @@ function CoverMenu:updateItems(select_number)
|
|
|
|
|
buttons = orig_buttons,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
|
|
|
|
|
local button = self.file_dialog.button_table:getButtonById("reset_settings")
|
|
|
|
|
local orig_purge_callback = button.callback
|
|
|
|
|
button.callback = function()
|
|
|
|
|
-- Wipe the cache
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[file] then
|
|
|
|
|
self.cover_info_cache[file] = nil
|
|
|
|
|
end
|
|
|
|
|
-- And then purge the sidecar folder as expected
|
|
|
|
|
orig_purge_callback()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Replace the "Book information" button callback to use directly our bookinfo
|
|
|
|
|
button = self.file_dialog.button_table:getButtonById("book_information")
|
|
|
|
|
local button = self.file_dialog.button_table:getButtonById("book_information")
|
|
|
|
|
button.callback = function()
|
|
|
|
|
FileManagerBookInfo:show(file, bookinfo)
|
|
|
|
|
UIManager:close(self.file_dialog)
|
|
|
|
@ -511,6 +469,10 @@ function CoverMenu:onHistoryMenuHold(item)
|
|
|
|
|
text = _("Refresh cached book information"),
|
|
|
|
|
enabled = bookinfo and true or false,
|
|
|
|
|
callback = function()
|
|
|
|
|
-- Wipe the cache
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[file] then
|
|
|
|
|
self.cover_info_cache[file] = nil
|
|
|
|
|
end
|
|
|
|
|
BookInfoManager:deleteBookInfo(file)
|
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
|
self:updateItems()
|
|
|
|
@ -630,12 +592,17 @@ function CoverMenu:onCollectionsMenuHold(item)
|
|
|
|
|
text = _("Refresh cached book information"),
|
|
|
|
|
enabled = bookinfo and true or false,
|
|
|
|
|
callback = function()
|
|
|
|
|
-- Wipe the cache
|
|
|
|
|
if self.cover_info_cache and self.cover_info_cache[file] then
|
|
|
|
|
self.cover_info_cache[file] = nil
|
|
|
|
|
end
|
|
|
|
|
BookInfoManager:deleteBookInfo(file)
|
|
|
|
|
UIManager:close(self.collfile_dialog)
|
|
|
|
|
self:updateItems()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- Create the new ButtonDialog, and let UIManager show it
|
|
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
|
|
|
|
self.collfile_dialog = ButtonDialogTitle:new{
|
|
|
|
|