2020-01-04 00:18:51 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-09-22 16:24:38 +00:00
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
2021-07-23 15:14:25 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2017-09-22 16:24:38 +00:00
|
|
|
local DocSettings = require("docsettings")
|
2022-03-12 10:26:11 +00:00
|
|
|
local FFIUtil = require("ffi/util")
|
2017-07-01 10:11:44 +00:00
|
|
|
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
|
2017-04-25 16:49:39 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-08-14 11:49:42 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2017-04-25 16:49:39 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2017-09-22 16:24:38 +00:00
|
|
|
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
2022-09-27 23:10:50 +00:00
|
|
|
local lfs = require("libs/libkoreader-lfs")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2022-03-15 15:16:04 +00:00
|
|
|
local C_ = _.pgettext
|
2022-03-12 10:26:11 +00:00
|
|
|
local T = FFIUtil.template
|
2017-04-25 16:49:39 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local FileManagerHistory = InputContainer:extend{
|
2014-03-13 13:52:43 +00:00
|
|
|
hist_menu_title = _("History"),
|
2013-08-14 09:29:05 +00:00
|
|
|
}
|
|
|
|
|
2022-03-12 10:26:11 +00:00
|
|
|
local status_text = {
|
2022-03-15 15:16:04 +00:00
|
|
|
all = C_("Book status filter", "All"),
|
|
|
|
reading = C_("Book status filter", "Reading"),
|
|
|
|
abandoned = C_("Book status filter", "On hold"),
|
|
|
|
complete = C_("Book status filter", "Finished"),
|
|
|
|
deleted = C_("Book status filter", "Deleted"),
|
|
|
|
new = C_("Book status filter", "New"),
|
2022-03-12 10:26:11 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 09:29:05 +00:00
|
|
|
function FileManagerHistory:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function FileManagerHistory:addToMainMenu(menu_items)
|
2017-02-25 10:58:39 +00:00
|
|
|
-- insert table to main tab of filemanager menu
|
2017-03-04 13:46:38 +00:00
|
|
|
menu_items.history = {
|
2016-02-17 07:10:23 +00:00
|
|
|
text = self.hist_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowHist()
|
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2016-02-17 07:10:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:updateItemTable()
|
2017-09-22 16:24:38 +00:00
|
|
|
-- try to stay on current page
|
|
|
|
local select_number = nil
|
2022-03-12 10:26:11 +00:00
|
|
|
if self.hist_menu.page and self.hist_menu.perpage and self.hist_menu.page > 0 then
|
2017-09-22 16:24:38 +00:00
|
|
|
select_number = (self.hist_menu.page - 1) * self.hist_menu.perpage + 1
|
|
|
|
end
|
2022-03-12 10:26:11 +00:00
|
|
|
self.count = { all = #require("readhistory").hist,
|
|
|
|
reading = 0, abandoned = 0, complete = 0, deleted = 0, new = 0, }
|
|
|
|
local item_table = {}
|
|
|
|
for _, v in ipairs(require("readhistory").hist) do
|
|
|
|
if not self.filter or v.status == self.filter then
|
|
|
|
table.insert(item_table, v)
|
|
|
|
end
|
|
|
|
if self.statuses_fetched then
|
|
|
|
self.count[v.status] = self.count[v.status] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local title = self.hist_menu_title
|
|
|
|
if self.filter then
|
|
|
|
title = title .. " (" .. status_text[self.filter] .. ")"
|
|
|
|
end
|
|
|
|
self.hist_menu:switchItemTable(title, item_table, select_number)
|
2016-02-17 07:10:23 +00:00
|
|
|
end
|
|
|
|
|
2013-08-14 09:29:05 +00:00
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = dimen
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onMenuHold(item)
|
2017-11-19 08:12:53 +00:00
|
|
|
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
|
2021-05-18 16:20:34 +00:00
|
|
|
local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file
|
2017-09-22 16:24:38 +00:00
|
|
|
self.histfile_dialog = nil
|
|
|
|
local buttons = {
|
|
|
|
{
|
2014-03-13 13:52:43 +00:00
|
|
|
{
|
2021-10-21 20:43:05 +00:00
|
|
|
text = _("Reset settings"),
|
2022-03-12 10:26:11 +00:00
|
|
|
enabled = item.file ~= currently_opened_file and DocSettings:hasSidecarFile(FFIUtil.realpath(item.file)),
|
2017-09-22 16:24:38 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2022-03-12 10:26:11 +00:00
|
|
|
text = T(_("Reset settings for this document?\n\n%1\n\nAny highlights or bookmarks will be permanently lost."),
|
|
|
|
BD.filepath(item.file)),
|
2021-10-21 20:43:05 +00:00
|
|
|
ok_text = _("Reset"),
|
2017-09-22 16:24:38 +00:00
|
|
|
ok_callback = function()
|
|
|
|
filemanagerutil.purgeSettings(item.file)
|
2020-05-06 19:11:34 +00:00
|
|
|
require("readhistory"):fileSettingsPurged(item.file)
|
2017-09-22 16:24:38 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2016-10-30 22:24:50 +00:00
|
|
|
{
|
2017-09-22 16:24:38 +00:00
|
|
|
text = _("Remove from history"),
|
|
|
|
callback = function()
|
|
|
|
require("readhistory"):removeItem(item)
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
2016-10-30 22:24:50 +00:00
|
|
|
},
|
2017-09-22 16:24:38 +00:00
|
|
|
},
|
|
|
|
{
|
2017-02-25 18:22:04 +00:00
|
|
|
{
|
2017-09-22 16:24:38 +00:00
|
|
|
text = _("Delete"),
|
2017-11-19 08:12:53 +00:00
|
|
|
enabled = (item.file ~= currently_opened_file and lfs.attributes(item.file, "mode")) and true or false,
|
2017-09-22 16:24:38 +00:00
|
|
|
callback = function()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2022-03-12 10:26:11 +00:00
|
|
|
text = T(_("Are you sure that you want to delete this document?\n\n%1\n\nIf you delete a file, it is permanently lost."),
|
|
|
|
BD.filepath(item.file)),
|
2017-09-22 16:24:38 +00:00
|
|
|
ok_text = _("Delete"),
|
|
|
|
ok_callback = function()
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
FileManager:deleteFile(item.file)
|
2020-05-06 19:11:34 +00:00
|
|
|
require("readhistory"):fileDeleted(item.file) -- (will update "lastfile" if needed)
|
2017-09-22 16:24:38 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
2017-02-25 18:22:04 +00:00
|
|
|
},
|
2017-09-22 16:24:38 +00:00
|
|
|
{
|
|
|
|
text = _("Book information"),
|
|
|
|
enabled = FileManagerBookInfo:isSupported(item.file),
|
|
|
|
callback = function()
|
|
|
|
FileManagerBookInfo:show(item.file)
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2017-09-22 16:24:38 +00:00
|
|
|
self.histfile_dialog = ButtonDialogTitle:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
title = BD.filename(item.text:match("([^/]+)$")),
|
2017-09-22 16:24:38 +00:00
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(self.histfile_dialog)
|
|
|
|
return true
|
2014-01-22 18:03:44 +00:00
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2021-04-09 21:12:15 +00:00
|
|
|
-- Can't *actually* name it onSetRotationMode, or it also fires in FM itself ;).
|
|
|
|
function FileManagerHistory:MenuSetRotationModeHandler(rotation)
|
|
|
|
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
|
|
|
|
UIManager:close(self._manager.hist_menu)
|
|
|
|
-- Also re-layout ReaderView or FileManager itself
|
|
|
|
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
|
|
|
|
self._manager.ui.view:onSetRotationMode(rotation)
|
|
|
|
elseif self._manager.ui.onSetRotationMode then
|
|
|
|
self._manager.ui:onSetRotationMode(rotation)
|
|
|
|
else
|
|
|
|
Screen:setRotationMode(rotation)
|
|
|
|
end
|
|
|
|
self._manager:onShowHist()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onShowHist()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
ui = self.ui,
|
2017-08-14 11:15:12 +00:00
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
2018-03-17 22:02:32 +00:00
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
2017-08-14 11:15:12 +00:00
|
|
|
is_borderless = true,
|
2017-09-24 12:46:50 +00:00
|
|
|
is_popout = false,
|
2022-03-12 10:26:11 +00:00
|
|
|
title_bar_left_icon = "appbar.menu",
|
|
|
|
onLeftButtonTap = function() self:showHistDialog() end,
|
2014-03-13 13:52:43 +00:00
|
|
|
onMenuHold = self.onMenuHold,
|
2021-04-09 21:12:15 +00:00
|
|
|
onSetRotationMode = self.MenuSetRotationModeHandler,
|
2014-03-13 13:52:43 +00:00
|
|
|
_manager = self,
|
|
|
|
}
|
2021-04-09 17:38:17 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self:updateItemTable()
|
|
|
|
self.hist_menu.close_callback = function()
|
2022-03-12 10:26:11 +00:00
|
|
|
self.statuses_fetched = nil
|
|
|
|
self.filter = nil
|
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
2021-05-01 16:53:04 +00:00
|
|
|
UIManager:close(self.hist_menu)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2017-08-18 08:02:11 +00:00
|
|
|
UIManager:show(self.hist_menu)
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2022-03-12 10:26:11 +00:00
|
|
|
function FileManagerHistory:showHistDialog()
|
|
|
|
if not self.statuses_fetched then
|
|
|
|
local status
|
|
|
|
for _, v in ipairs(require("readhistory").hist) do
|
|
|
|
if v.dim then
|
|
|
|
status = "deleted"
|
|
|
|
else
|
|
|
|
if DocSettings:hasSidecarFile(v.file) then
|
|
|
|
local docinfo = DocSettings:open(v.file) -- no io handles created, do not close
|
|
|
|
if docinfo.data.summary and docinfo.data.summary.status
|
|
|
|
and docinfo.data.summary.status ~= "" then
|
|
|
|
status = docinfo.data.summary.status
|
|
|
|
else
|
|
|
|
status = "reading"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
status = "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
v.status = status
|
|
|
|
self.count[status] = self.count[status] + 1
|
|
|
|
end
|
|
|
|
self.statuses_fetched = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local hist_dialog
|
|
|
|
local buttons = {}
|
|
|
|
local function genFilterButton(status)
|
|
|
|
return {
|
|
|
|
text = T(_("%1 (%2)"), status_text[status], self.count[status]),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
self.filter = status ~= "all" and status
|
|
|
|
self:updateItemTable()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
table.insert(buttons, {
|
|
|
|
genFilterButton("reading"),
|
|
|
|
genFilterButton("abandoned"),
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
genFilterButton("complete"),
|
|
|
|
genFilterButton("deleted"),
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
genFilterButton("all"),
|
|
|
|
genFilterButton("new"),
|
|
|
|
})
|
|
|
|
if self.count.deleted > 0 then
|
|
|
|
table.insert(buttons, {})
|
|
|
|
table.insert(buttons, {
|
|
|
|
{
|
|
|
|
text = _("Clear history of deleted files"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("Clear history of deleted files?"),
|
|
|
|
ok_text = _("Clear"),
|
|
|
|
ok_callback = function()
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
require("readhistory"):clearMissing()
|
|
|
|
self:updateItemTable()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
hist_dialog = ButtonDialogTitle:new{
|
|
|
|
title = _("Filter by book status"),
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
|
|
|
UIManager:show(hist_dialog)
|
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
return FileManagerHistory
|