2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2014-05-15 11:41:10 +00:00
|
|
|
local Cache = require("cache")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local Device = require("ui/device")
|
|
|
|
local DocSettings = require("docsettings")
|
|
|
|
local Event = require("ui/event")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
2014-04-02 20:59:17 +00:00
|
|
|
local ReaderView = require("apps/reader/modules/readerview")
|
|
|
|
local ReaderZooming = require("apps/reader/modules/readerzooming")
|
|
|
|
local ReaderPanning = require("apps/reader/modules/readerpanning")
|
|
|
|
local ReaderRotation = require("apps/reader/modules/readerrotation")
|
|
|
|
local ReaderPaging = require("apps/reader/modules/readerpaging")
|
|
|
|
local ReaderRolling = require("apps/reader/modules/readerrolling")
|
|
|
|
local ReaderToc = require("apps/reader/modules/readertoc")
|
|
|
|
local ReaderBookmark = require("apps/reader/modules/readerbookmark")
|
|
|
|
local ReaderFont = require("apps/reader/modules/readerfont")
|
|
|
|
local ReaderTypeset = require("apps/reader/modules/readertypeset")
|
|
|
|
local ReaderMenu = require("apps/reader/modules/readermenu")
|
|
|
|
local ReaderGoto = require("apps/reader/modules/readergoto")
|
|
|
|
local ReaderConfig = require("apps/reader/modules/readerconfig")
|
|
|
|
local ReaderCropping = require("apps/reader/modules/readercropping")
|
|
|
|
local ReaderKoptListener = require("apps/reader/modules/readerkoptlistener")
|
|
|
|
local ReaderCoptListener = require("apps/reader/modules/readercoptlistener")
|
|
|
|
local ReaderHinting = require("apps/reader/modules/readerhinting")
|
|
|
|
local ReaderHighlight = require("apps/reader/modules/readerhighlight")
|
|
|
|
local ReaderScreenshot = require("apps/reader/modules/readerscreenshot")
|
|
|
|
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
|
|
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
|
|
|
|
local ReaderHyphenation = require("apps/reader/modules/readerhyphenation")
|
|
|
|
local ReaderActivityIndicator = require("apps/reader/modules/readeractivityindicator")
|
|
|
|
local ReaderLink = require("apps/reader/modules/readerlink")
|
2014-04-23 13:57:48 +00:00
|
|
|
local PluginLoader = require("apps/reader/pluginloader")
|
2012-05-18 22:50:26 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
This is an abstraction for a reader interface
|
|
|
|
|
|
|
|
it works using data gathered from a document interface
|
|
|
|
]]--
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderUI = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
key_events = {
|
|
|
|
Close = { { "Home" },
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "close document", event = "Close" },
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
active_widgets = {},
|
2012-05-18 22:50:26 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- our own size
|
|
|
|
dimen = Geom:new{ w = 400, h = 600 },
|
|
|
|
-- if we have a parent container, it must be referenced for now
|
|
|
|
dialog = nil,
|
2012-05-18 22:50:26 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- the document interface
|
|
|
|
document = nil,
|
2012-06-11 16:35:13 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- initial page or percent inside document on opening
|
|
|
|
start_pos = nil,
|
|
|
|
-- password for document unlock
|
|
|
|
password = nil,
|
2013-01-13 02:22:33 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
postInitCallback = nil,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderUI:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.postInitCallback = {}
|
|
|
|
-- if we are not the top level dialog ourselves, it must be given in the table
|
|
|
|
if not self.dialog then
|
|
|
|
self.dialog = self
|
|
|
|
end
|
2012-06-26 09:05:09 +00:00
|
|
|
|
2014-06-10 07:57:10 +00:00
|
|
|
if Device:hasKeys() then
|
2014-03-13 13:52:43 +00:00
|
|
|
self.key_events.Back = {
|
2014-06-05 06:58:53 +00:00
|
|
|
{ "Back" }, doc = "close document",
|
2014-03-13 13:52:43 +00:00
|
|
|
event = "Close" }
|
|
|
|
end
|
2013-01-01 02:22:45 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.doc_settings = DocSettings:open(self.document.file)
|
2012-06-26 09:05:09 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- a view container (so it must be child #1!)
|
|
|
|
self[1] = ReaderView:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
dimen = self.dimen,
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
}
|
|
|
|
-- reader menu controller
|
|
|
|
-- hold reference to menu widget
|
|
|
|
self.menu = ReaderMenu:new{
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
-- link
|
|
|
|
table.insert(self, ReaderLink:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
-- text highlight
|
|
|
|
table.insert(self, ReaderHighlight:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
-- menu widget should be registered after link widget and highlight widget
|
|
|
|
-- so that taps on link and highlight areas won't popup reader menu
|
|
|
|
table.insert(self, self.menu)
|
|
|
|
-- rotation controller
|
|
|
|
table.insert(self, ReaderRotation:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- Table of content controller
|
|
|
|
-- hold reference to bm widget
|
|
|
|
self.toc = ReaderToc:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, self.toc)
|
|
|
|
-- bookmark controller
|
|
|
|
table.insert(self, ReaderBookmark:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- reader goto controller
|
|
|
|
table.insert(self, ReaderGoto:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
-- dictionary
|
|
|
|
table.insert(self, ReaderDictionary:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
-- screenshot controller
|
|
|
|
table.insert(self.active_widgets, ReaderScreenshot:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- frontlight controller
|
|
|
|
if Device:hasFrontlight() then
|
|
|
|
table.insert(self, ReaderFrontLight:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
end
|
|
|
|
-- configuable controller
|
|
|
|
if self.document.info.configurable then
|
|
|
|
-- config panel controller
|
|
|
|
table.insert(self, ReaderConfig:new{
|
|
|
|
configurable = self.document.configurable,
|
|
|
|
options = self.document.options,
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
if not self.document.info.has_pages then
|
|
|
|
-- cre option controller
|
|
|
|
table.insert(self, ReaderCoptListener:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- for page specific controller
|
|
|
|
if self.document.info.has_pages then
|
|
|
|
-- cropping controller
|
|
|
|
table.insert(self, ReaderCropping:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
-- paging controller
|
|
|
|
table.insert(self, ReaderPaging:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- zooming controller
|
|
|
|
local zoom = ReaderZooming:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, zoom)
|
|
|
|
-- panning controller
|
|
|
|
table.insert(self, ReaderPanning:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- hinting controller
|
|
|
|
table.insert(self, ReaderHinting:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
zoom = zoom,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
-- make sure we load document first before calling any callback
|
|
|
|
table.insert(self.postInitCallback, function()
|
|
|
|
self.document:loadDocument()
|
|
|
|
end)
|
|
|
|
-- typeset controller
|
|
|
|
table.insert(self, ReaderTypeset:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
-- font menu
|
|
|
|
self.font = ReaderFont:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, self.font) -- hold reference to font menu
|
|
|
|
-- hyphenation menu
|
|
|
|
self.hyphenation = ReaderHyphenation:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
|
|
|
table.insert(self, self.hyphenation) -- hold reference to hyphenation menu
|
|
|
|
-- rolling controller
|
|
|
|
table.insert(self, ReaderRolling:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
end
|
|
|
|
-- configuable controller
|
|
|
|
if self.document.info.configurable then
|
|
|
|
if self.document.info.has_pages then
|
|
|
|
-- kopt option controller
|
|
|
|
table.insert(self, ReaderKoptListener:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
-- activity indicator
|
|
|
|
table.insert(self, ReaderActivityIndicator:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
end
|
2014-04-23 13:57:48 +00:00
|
|
|
|
|
|
|
-- koreader plugins
|
|
|
|
for _,module in ipairs(PluginLoader:loadPlugins()) do
|
|
|
|
DEBUG("Loaded plugin", module.path)
|
|
|
|
table.insert(self, module:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
--DEBUG(self.doc_settings)
|
|
|
|
-- we only read settings after all the widgets are initialized
|
|
|
|
self:handleEvent(Event:new("ReadSettings", self.doc_settings))
|
2013-01-13 02:22:33 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
for _,v in ipairs(self.postInitCallback) do
|
|
|
|
v()
|
|
|
|
end
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2012-06-12 16:14:23 +00:00
|
|
|
function ReaderUI:onSetDimensions(dimen)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen = dimen
|
2012-06-12 16:14:23 +00:00
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderUI:saveSettings()
|
2014-03-13 13:52:43 +00:00
|
|
|
self:handleEvent(Event:new("SaveSettings"))
|
|
|
|
self.doc_settings:flush()
|
2014-07-03 12:43:17 +00:00
|
|
|
G_reader_settings:flush()
|
2013-12-27 15:18:16 +00:00
|
|
|
end
|
|
|
|
|
2014-06-08 09:56:52 +00:00
|
|
|
function ReaderUI:onFlushSettings()
|
|
|
|
self:saveSettings()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderUI:onClose()
|
2014-03-13 13:52:43 +00:00
|
|
|
DEBUG("closing reader")
|
|
|
|
self:saveSettings()
|
2014-06-23 14:33:11 +00:00
|
|
|
self:handleEvent(Event:new("CloseReader"))
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.document ~= nil then
|
|
|
|
self.document:close()
|
|
|
|
self.document = nil
|
|
|
|
self.start_pos = nil
|
|
|
|
end
|
|
|
|
UIManager:close(self.dialog)
|
2014-05-15 11:41:10 +00:00
|
|
|
-- serialize last used items for later launch
|
|
|
|
Cache:serialize()
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderUI
|