2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-22 15:11:31 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
2014-01-22 18:03:44 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2014-08-14 11:49:42 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Screen = require("device").screen
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2016-10-30 22:24:50 +00:00
|
|
|
local KeyValuePage = require("ui/widget/keyvaluepage")
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local T = require("ffi/util").template
|
2016-11-08 18:05:34 +00:00
|
|
|
local RenderText = require("ui/rendertext")
|
|
|
|
local Font = require("ui/font")
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-02-01 14:24:21 +00:00
|
|
|
self.hist_menu:switchItemTable(self.hist_menu_title,
|
2016-04-18 22:38:14 +00:00
|
|
|
require("readhistory").hist)
|
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
|
|
|
|
|
2016-10-30 22:24:50 +00:00
|
|
|
function FileManagerHistory:buildBookInformationTable(book_props)
|
|
|
|
if book_props == nil then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if book_props.authors == "" or book_props.authors == nil then
|
|
|
|
book_props.authors = _("N/A")
|
|
|
|
end
|
|
|
|
|
|
|
|
if book_props.title == "" or book_props.title == nil then
|
|
|
|
book_props.title = _("N/A")
|
|
|
|
end
|
|
|
|
|
|
|
|
if book_props.series == "" or book_props.series == nil then
|
|
|
|
book_props.series = _("N/A")
|
|
|
|
end
|
|
|
|
|
|
|
|
if book_props.pages == "" or book_props.pages == nil then
|
|
|
|
book_props.pages = _("N/A")
|
|
|
|
end
|
|
|
|
|
|
|
|
if book_props.language == "" or book_props.language == nil then
|
|
|
|
book_props.language = _("N/A")
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
{ T(_("Title: %1"), book_props.title), "" },
|
|
|
|
{ T(_("Authors: %1"), book_props.authors), "" },
|
|
|
|
{ T(_("Series: %1"), book_props.series), "" },
|
|
|
|
{ T(_("Pages: %1"), book_props.pages), "" },
|
|
|
|
{ T(_("Language: %1"), string.upper(book_props.language)), "" },
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:bookInformation(file)
|
|
|
|
local file_mode = lfs.attributes(file, "mode")
|
|
|
|
if file_mode ~= "file" then return false end
|
|
|
|
local book_stats = DocSettings:open(file):readSetting('stats')
|
|
|
|
if book_stats == nil then return false end
|
|
|
|
return self:buildBookInformationTable(book_stats)
|
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onMenuHold(item)
|
2016-11-08 18:05:34 +00:00
|
|
|
local font_size = Font:getFace("tfont")
|
|
|
|
local text_remove_hist = _("Remove \"%1\" from history")
|
|
|
|
local text_remove_without_item = T(text_remove_hist, "")
|
|
|
|
local text_remove_hist_width = (RenderText:sizeUtf8Text(
|
|
|
|
0, self.width, font_size, text_remove_without_item).x )
|
|
|
|
local text_item_width = (RenderText:sizeUtf8Text(
|
|
|
|
0, self.width , font_size, item.text).x )
|
|
|
|
|
|
|
|
local item_trun
|
|
|
|
if self.width < text_remove_hist_width + text_item_width then
|
|
|
|
item_trun = RenderText:truncateTextByWidth(item.text, font_size, 1.2 * self.width - text_remove_hist_width)
|
|
|
|
else
|
|
|
|
item_trun = item.text
|
|
|
|
end
|
|
|
|
local text_remove = T(text_remove_hist, item_trun)
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.histfile_dialog = ButtonDialog:new{
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
2016-11-08 18:05:34 +00:00
|
|
|
text = text_remove,
|
2014-03-13 13:52:43 +00:00
|
|
|
callback = function()
|
2016-04-18 22:38:14 +00:00
|
|
|
require("readhistory"):removeItem(item)
|
2014-03-13 13:52:43 +00:00
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2016-10-30 22:24:50 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Book information"),
|
|
|
|
callback = function()
|
|
|
|
local book_info_metadata = FileManagerHistory:bookInformation(item.file)
|
|
|
|
if book_info_metadata then
|
|
|
|
UIManager:show(KeyValuePage:new{
|
|
|
|
title = _("Book information"),
|
|
|
|
kv_pairs = book_info_metadata,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Cannot fetch information for a selected book"),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2017-02-25 18:22:04 +00:00
|
|
|
{},
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Clear history of deleted files"),
|
|
|
|
callback = function()
|
|
|
|
require("readhistory"):clearMissing()
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
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
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onShowHist()
|
2014-03-13 13:52:43 +00:00
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
ui = self.ui,
|
|
|
|
width = Screen:getWidth()-50,
|
|
|
|
height = Screen:getHeight()-50,
|
|
|
|
show_parent = menu_container,
|
|
|
|
onMenuHold = self.onMenuHold,
|
|
|
|
_manager = self,
|
|
|
|
}
|
|
|
|
self:updateItemTable()
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(menu_container, self.hist_menu)
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.hist_menu.close_callback = function()
|
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:show(menu_container)
|
|
|
|
return true
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
return FileManagerHistory
|