2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
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")
|
|
|
|
|
|
|
|
local ReaderView = require("ui/reader/readerview")
|
|
|
|
local ReaderZooming = require("ui/reader/readerzooming")
|
|
|
|
local ReaderPanning = require("ui/reader/readerpanning")
|
|
|
|
local ReaderRotation = require("ui/reader/readerrotation")
|
|
|
|
local ReaderPaging = require("ui/reader/readerpaging")
|
|
|
|
local ReaderRolling = require("ui/reader/readerrolling")
|
|
|
|
local ReaderToc = require("ui/reader/readertoc")
|
|
|
|
local ReaderBookmark = require("ui/reader/readerbookmark")
|
|
|
|
local ReaderFont = require("ui/reader/readerfont")
|
|
|
|
local ReaderTypeset = require("ui/reader/readertypeset")
|
|
|
|
local ReaderMenu = require("ui/reader/readermenu")
|
|
|
|
local ReaderGoto = require("ui/reader/readergoto")
|
|
|
|
local ReaderConfig = require("ui/reader/readerconfig")
|
|
|
|
local ReaderCropping = require("ui/reader/readercropping")
|
|
|
|
local ReaderKoptListener = require("ui/reader/readerkoptlistener")
|
|
|
|
local ReaderCoptListener = require("ui/reader/readercoptlistener")
|
|
|
|
local ReaderHinting = require("ui/reader/readerhinting")
|
|
|
|
local ReaderHighlight = require("ui/reader/readerhighlight")
|
|
|
|
local ReaderScreenshot = require("ui/reader/readerscreenshot")
|
|
|
|
local ReaderFrontLight = require("ui/reader/readerfrontlight")
|
|
|
|
local ReaderDictionary = require("ui/reader/readerdictionary")
|
|
|
|
local ReaderHyphenation = require("ui/reader/readerhyphenation")
|
|
|
|
local ReaderActivityIndicator = require("ui/reader/readeractivityindicator")
|
2014-01-15 15:35:26 +00:00
|
|
|
local ReaderLink = require("ui/reader/readerlink")
|
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{
|
2012-05-18 22:50:26 +00:00
|
|
|
key_events = {
|
2013-04-08 07:21:59 +00:00
|
|
|
Close = { { "Home" },
|
|
|
|
doc = _("close document"), event = "Close" },
|
2012-05-18 22:50:26 +00:00
|
|
|
},
|
2013-03-07 10:06:18 +00:00
|
|
|
active_widgets = {},
|
2012-05-18 22:50:26 +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,
|
|
|
|
|
|
|
|
-- the document interface
|
|
|
|
document = nil,
|
2012-06-11 16:35:13 +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
|
|
|
|
2013-01-13 03:24:42 +00:00
|
|
|
postInitCallback = nil,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderUI:init()
|
2013-01-13 03:24:42 +00:00
|
|
|
self.postInitCallback = {}
|
2012-05-18 22:50:26 +00:00
|
|
|
-- 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
|
|
|
|
2013-01-01 02:22:45 +00:00
|
|
|
if Device:hasKeyboard() then
|
2013-04-08 07:21:59 +00:00
|
|
|
self.key_events.Back = {
|
|
|
|
{ "Back" }, doc = _("close document"),
|
2013-01-01 02:22:45 +00:00
|
|
|
event = "Close" }
|
|
|
|
end
|
|
|
|
|
2012-06-26 09:05:09 +00:00
|
|
|
self.doc_settings = DocSettings:open(self.document.file)
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
-- a view container (so it must be child #1!)
|
|
|
|
self[1] = ReaderView:new{
|
|
|
|
dialog = self.dialog,
|
2012-06-12 16:14:23 +00:00
|
|
|
dimen = self.dimen,
|
2012-12-13 04:41:48 +00:00
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2012-05-18 22:50:26 +00:00
|
|
|
}
|
2014-01-17 19:05:17 +00:00
|
|
|
-- reader menu controller
|
|
|
|
-- hold reference to menu widget
|
|
|
|
self.menu = ReaderMenu:new{
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2014-01-15 15:35:26 +00:00
|
|
|
-- 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,
|
|
|
|
})
|
2014-01-17 19:05:17 +00:00
|
|
|
-- 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)
|
2012-05-18 22:50:26 +00:00
|
|
|
-- rotation controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderRotation:new{
|
2012-05-18 22:50:26 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2013-01-01 19:38:29 +00:00
|
|
|
-- Table of content controller
|
2014-01-17 19:05:17 +00:00
|
|
|
-- hold reference to bm widget
|
2014-01-15 15:35:26 +00:00
|
|
|
self.toc = ReaderToc:new{
|
2012-12-31 00:13:46 +00:00
|
|
|
dialog = self.dialog,
|
2012-06-10 18:14:29 +00:00
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2014-01-17 19:05:17 +00:00
|
|
|
table.insert(self, self.toc)
|
2013-01-01 19:38:29 +00:00
|
|
|
-- bookmark controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderBookmark:new{
|
2013-01-01 02:22:45 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
|
|
|
-- reader goto controller
|
2013-08-14 10:52:39 +00:00
|
|
|
table.insert(self, ReaderGoto:new{
|
2013-07-30 15:09:08 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2013-08-14 10:52:39 +00:00
|
|
|
})
|
2013-07-28 06:35:46 +00:00
|
|
|
-- dictionary
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderDictionary:new{
|
2013-04-23 22:59:52 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2013-03-06 14:36:51 +00:00
|
|
|
-- screenshot controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self.active_widgets, ReaderScreenshot:new{
|
2013-03-06 14:36:51 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2013-12-15 09:02:52 +00:00
|
|
|
-- frontlight controller
|
2014-01-04 13:38:07 +00:00
|
|
|
if Device:hasFrontlight() then
|
2013-08-14 10:52:39 +00:00
|
|
|
table.insert(self, ReaderFrontLight:new{
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
})
|
|
|
|
end
|
2014-01-03 03:22:27 +00:00
|
|
|
-- configuable controller
|
2013-12-15 09:02:52 +00:00
|
|
|
if self.document.info.configurable then
|
2014-01-03 03:22:27 +00:00
|
|
|
-- config panel controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderConfig:new{
|
2013-12-15 09:02:52 +00:00
|
|
|
configurable = self.document.configurable,
|
|
|
|
options = self.document.options,
|
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2014-01-03 11:32:21 +00:00
|
|
|
if not self.document.info.has_pages then
|
|
|
|
-- cre option controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderCoptListener:new{
|
2014-01-03 11:32:21 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2014-01-03 11:32:21 +00:00
|
|
|
end
|
2013-12-15 09:02:52 +00:00
|
|
|
end
|
|
|
|
-- for page specific controller
|
2012-05-18 22:50:26 +00:00
|
|
|
if self.document.info.has_pages then
|
2014-02-16 12:57:36 +00:00
|
|
|
-- cropping controller
|
|
|
|
table.insert(self, ReaderCropping:new{
|
2012-12-04 07:19:50 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
2014-02-16 12:57:36 +00:00
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2012-06-05 07:23:36 +00:00
|
|
|
-- zooming controller
|
2014-02-16 12:57:36 +00:00
|
|
|
local zoom = ReaderZooming:new{
|
2012-06-05 07:23:36 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
|
|
|
}
|
2014-02-16 12:57:36 +00:00
|
|
|
table.insert(self, zoom)
|
|
|
|
-- paging controller
|
|
|
|
table.insert(self, ReaderPaging:new{
|
2012-06-05 07:23:36 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2014-02-16 12:57:36 +00:00
|
|
|
-- panning controller
|
|
|
|
table.insert(self, ReaderPanning:new{
|
2013-02-02 20:42:59 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
2014-02-16 12:57:36 +00:00
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2013-03-12 12:28:01 +00:00
|
|
|
-- hinting controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderHinting:new{
|
2013-03-12 12:28:01 +00:00
|
|
|
dialog = self.dialog,
|
2014-02-16 12:57:36 +00:00
|
|
|
zoom = zoom,
|
2013-03-12 12:28:01 +00:00
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2012-06-05 07:23:36 +00:00
|
|
|
else
|
2013-01-13 02:22:33 +00:00
|
|
|
-- make sure we load document first before calling any callback
|
|
|
|
table.insert(self.postInitCallback, function()
|
|
|
|
self.document:loadDocument()
|
|
|
|
end)
|
2014-01-03 03:22:27 +00:00
|
|
|
-- typeset controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderTypeset:new{
|
2012-06-05 07:23:36 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2012-06-12 09:42:02 +00:00
|
|
|
-- font menu
|
2014-01-21 17:33:06 +00:00
|
|
|
self.font = ReaderFont:new{
|
2012-06-12 09:42:02 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-21 17:33:06 +00:00
|
|
|
}
|
|
|
|
table.insert(self, self.font) -- hold reference to font menu
|
2014-01-22 14:02:42 +00:00
|
|
|
-- hyphenation menu
|
|
|
|
self.hyphenation = ReaderHyphenation:new{
|
2013-01-17 22:12:50 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-22 14:02:42 +00:00
|
|
|
}
|
|
|
|
table.insert(self, self.hyphenation) -- hold reference to hyphenation menu
|
2014-01-03 03:22:27 +00:00
|
|
|
-- rolling controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderRolling:new{
|
2013-04-16 17:11:28 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
2014-01-03 03:22:27 +00:00
|
|
|
-- configuable controller
|
2012-12-14 10:20:04 +00:00
|
|
|
if self.document.info.configurable then
|
2014-01-03 11:32:21 +00:00
|
|
|
if self.document.info.has_pages then
|
|
|
|
-- kopt option controller
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderKoptListener:new{
|
2014-01-03 11:32:21 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2014-01-03 11:32:21 +00:00
|
|
|
end
|
2013-04-21 08:54:59 +00:00
|
|
|
-- activity indicator
|
2014-01-15 15:35:26 +00:00
|
|
|
table.insert(self, ReaderActivityIndicator:new{
|
2013-04-21 08:54:59 +00:00
|
|
|
dialog = self.dialog,
|
|
|
|
view = self[1],
|
|
|
|
ui = self,
|
|
|
|
document = self.document,
|
2014-01-15 15:35:26 +00:00
|
|
|
})
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
2012-06-26 16:59:22 +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
|
|
|
|
|
|
|
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)
|
|
|
|
self.dimen = dimen
|
|
|
|
end
|
|
|
|
|
2013-12-27 15:18:16 +00:00
|
|
|
function ReaderUI:saveSettings()
|
|
|
|
self:handleEvent(Event:new("SaveSettings"))
|
|
|
|
self.doc_settings:flush()
|
|
|
|
end
|
|
|
|
|
2012-05-18 22:50:26 +00:00
|
|
|
function ReaderUI:onClose()
|
2012-05-28 16:59:16 +00:00
|
|
|
DEBUG("closing reader")
|
2013-12-27 15:18:16 +00:00
|
|
|
self:saveSettings()
|
2012-12-15 01:30:48 +00:00
|
|
|
if self.document ~= nil then
|
2012-05-18 22:50:26 +00:00
|
|
|
self.document:close()
|
2012-12-15 01:30:48 +00:00
|
|
|
self.document = nil
|
|
|
|
self.start_pos = nil
|
2012-05-18 22:50:26 +00:00
|
|
|
end
|
|
|
|
UIManager:close(self.dialog)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderUI
|