2013-03-12 17:18:53 +00:00
|
|
|
require "ui/widget/config"
|
2012-12-14 10:20:04 +00:00
|
|
|
|
2013-01-03 14:24:38 +00:00
|
|
|
Configurable = {}
|
|
|
|
|
|
|
|
function Configurable:hash(sep)
|
|
|
|
local hash = ""
|
|
|
|
local excluded = {multi_threads = true,}
|
|
|
|
for key,value in pairs(self) do
|
|
|
|
if type(value) == "number" and not excluded[key] then
|
|
|
|
hash = hash..sep..value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return hash
|
|
|
|
end
|
|
|
|
|
2013-01-06 05:53:36 +00:00
|
|
|
function Configurable:loadDefaults(config_options)
|
|
|
|
for i=1,#config_options do
|
|
|
|
local options = config_options[i].options
|
|
|
|
for j=1,#config_options[i].options do
|
|
|
|
local key = config_options[i].options[j].name
|
|
|
|
self[key] = config_options[i].options[j].default_value
|
2013-01-07 17:07:06 +00:00
|
|
|
if not self[key] then
|
|
|
|
self[key] = config_options[i].options[j].default_arg
|
|
|
|
end
|
2013-01-03 14:24:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function Configurable:loadSettings(settings, prefix)
|
|
|
|
for key,value in pairs(self) do
|
|
|
|
if type(value) == "number" then
|
|
|
|
saved_value = settings:readSetting(prefix..key)
|
|
|
|
self[key] = (saved_value == nil) and self[key] or saved_value
|
|
|
|
--Debug("Configurable:loadSettings", "key", key, "saved value", saved_value,"Configurable.key", self[key])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
--Debug("loaded config:", dump(Configurable))
|
|
|
|
end
|
|
|
|
|
|
|
|
function Configurable:saveSettings(settings, prefix)
|
|
|
|
for key,value in pairs(self) do
|
|
|
|
if type(value) == "number" then
|
|
|
|
settings:saveSetting(prefix..key, value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-14 10:20:04 +00:00
|
|
|
ReaderConfig = InputContainer:new{
|
|
|
|
dimen = Geom:new{
|
2013-03-13 02:43:15 +00:00
|
|
|
x = 0,
|
2012-12-14 10:20:04 +00:00
|
|
|
y = 7*Screen:getHeight()/8,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight()/8,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderConfig:init()
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:hasKeyboard() then
|
2012-12-14 10:20:04 +00:00
|
|
|
self.key_events = {
|
|
|
|
ShowConfigMenu = { { "AA" }, doc = "show config dialog" },
|
|
|
|
}
|
|
|
|
end
|
2013-02-02 06:36:29 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self:initGesListener()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:initGesListener()
|
|
|
|
self.ges_events = {
|
|
|
|
TapShowConfigMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2013-02-02 08:14:15 +00:00
|
|
|
range = self.dimen,
|
2013-02-02 06:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onShowConfigMenu()
|
2013-02-02 20:42:59 +00:00
|
|
|
self.config_dialog = ConfigDialog:new{
|
2012-12-14 10:20:04 +00:00
|
|
|
dimen = self.dimen:copy(),
|
2012-12-23 23:54:44 +00:00
|
|
|
ui = self.ui,
|
|
|
|
configurable = self.configurable,
|
2013-01-06 05:53:36 +00:00
|
|
|
config_options = self.options,
|
2013-03-13 02:43:15 +00:00
|
|
|
close_callback = function()
|
2013-03-12 12:28:01 +00:00
|
|
|
self.ui:handleEvent(Event:new("RestoreHinting"))
|
|
|
|
end,
|
2012-12-14 10:20:04 +00:00
|
|
|
}
|
2013-03-12 12:28:01 +00:00
|
|
|
self.ui:handleEvent(Event:new("DisableHinting"))
|
2013-02-02 20:42:59 +00:00
|
|
|
UIManager:show(self.config_dialog)
|
2012-12-14 10:20:04 +00:00
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onTapShowConfigMenu()
|
|
|
|
self:onShowConfigMenu()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onSetDimensions(dimen)
|
2013-02-02 08:14:15 +00:00
|
|
|
self.dimen.x = 0
|
|
|
|
self.dimen.y = 7 * Screen:getHeight() / 8
|
|
|
|
self.dimen.w = Screen:getWidth()
|
|
|
|
self.dimen.h = Screen:getHeight() / 8
|
2013-02-03 05:13:46 +00:00
|
|
|
-- since we cannot redraw config_dialog with new size, we close
|
|
|
|
-- the old one on screen size change
|
2013-02-02 09:02:36 +00:00
|
|
|
if self.config_dialog then
|
2013-02-04 07:03:17 +00:00
|
|
|
self.config_dialog:closeDialog()
|
2013-02-02 09:02:36 +00:00
|
|
|
end
|
2012-12-14 10:20:04 +00:00
|
|
|
end
|
2012-12-24 09:36:52 +00:00
|
|
|
|
2013-02-02 20:42:59 +00:00
|
|
|
function ReaderConfig:onCloseConfig()
|
|
|
|
self.config_dialog:closeDialog()
|
|
|
|
end
|
|
|
|
|
2012-12-24 09:36:52 +00:00
|
|
|
function ReaderConfig:onReadSettings(config)
|
2013-01-06 05:53:36 +00:00
|
|
|
self.configurable:loadSettings(config, self.options.prefix..'_')
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderConfig:onCloseDocument()
|
2013-01-06 05:53:36 +00:00
|
|
|
self.configurable:saveSettings(self.ui.doc_settings, self.options.prefix..'_')
|
2012-12-24 09:36:52 +00:00
|
|
|
end
|