2017-04-29 08:38:09 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local DataStorage = require("datastorage")
|
2019-09-26 21:13:35 +00:00
|
|
|
local Device = require("device")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Font = require("ui/font")
|
2014-08-11 08:39:49 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Menu = require("ui/widget/menu")
|
2014-08-25 16:03:10 +00:00
|
|
|
local MultiInputDialog = require("ui/widget/multiinputdialog")
|
[RFC] Pagination UI shenanigans (#7335)
* Menu/KeyValuePage/ReaderGoTo: Unify the dialogs. (Generally, "Enter page number" as title, and "Go to page" as OK button).
* Allow *tapping* on pagination buttons, too. Added spacers around the text to accommodate for that.
* Disable input handlers when <= 1 pages, while still printing the label in black.
* Always display both the label and the chevrons, even on single page content. (Menu being an exception, because it can handle showing no content at all, in which case we hide the chevrons).
* KVP: Tweak the pagination buttons layout in order to have consistent centering, regardless of whether the return arrow is enabled or not. (Also, match Menu's layout, more or less).
* Menu: Minor layout tweaks to follow the KVP tweaks above. Fixes, among possibly other things, buttons in (non-FM) "List" menus overlapping the final entry (e.g., OPDS), and popout menus with a border being misaligned (e.g., Calibre, Find a file).
* CalendarView: Minor layout tweaks to follow the KVP tweaks. Ensures the pagination buttons are laid out in the same way as everywhere else (they used to be a wee bit higher).
2021-02-25 04:15:23 +00:00
|
|
|
local Size = require("ui/size")
|
2015-06-15 08:46:43 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2017-04-29 08:38:09 +00:00
|
|
|
local dump = require("dump")
|
2017-08-09 16:57:22 +00:00
|
|
|
local isAndroid, android = pcall(require, "android")
|
2019-09-26 21:13:35 +00:00
|
|
|
local logger = require("logger")
|
2014-08-26 00:59:24 +00:00
|
|
|
local util = require("ffi/util")
|
2014-09-05 13:05:20 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-29 08:38:09 +00:00
|
|
|
local Screen = require("device").screen
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2018-04-12 14:39:36 +00:00
|
|
|
local is_appimage = os.getenv("APPIMAGE")
|
|
|
|
|
2017-08-09 16:57:22 +00:00
|
|
|
local function getDefaultsPath()
|
|
|
|
local defaults_path = DataStorage:getDataDir() .. "/defaults.lua"
|
|
|
|
if isAndroid then
|
|
|
|
defaults_path = android.dir .. "/defaults.lua"
|
2018-04-12 14:39:36 +00:00
|
|
|
elseif is_appimage then
|
|
|
|
defaults_path = "defaults.lua"
|
2017-08-09 16:57:22 +00:00
|
|
|
end
|
|
|
|
return defaults_path
|
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2017-08-09 16:57:22 +00:00
|
|
|
local defaults_path = getDefaultsPath()
|
|
|
|
local persistent_defaults_path = DataStorage:getDataDir() .. "/defaults.persistent.lua"
|
2014-08-11 08:39:49 +00:00
|
|
|
|
|
|
|
local SetDefaults = InputContainer:new{
|
2014-08-16 20:31:32 +00:00
|
|
|
defaults_name = {},
|
|
|
|
defaults_value = {},
|
2014-08-11 08:39:49 +00:00
|
|
|
results = {},
|
|
|
|
defaults_menu = {},
|
2016-09-22 07:36:09 +00:00
|
|
|
changed = {},
|
|
|
|
settings_changed = false,
|
2014-08-11 08:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SetDefaults:ConfirmEdit()
|
2014-08-11 18:03:03 +00:00
|
|
|
if not SetDefaults.EditConfirmed then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2014-11-14 21:01:32 +00:00
|
|
|
text = _("Some changes will not work until the next restart. Be careful; the wrong settings might crash KOReader!\nAre you sure you want to continue?"),
|
2014-08-11 18:03:03 +00:00
|
|
|
ok_callback = function()
|
|
|
|
self.EditConfirmed = true
|
|
|
|
self:init()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
else
|
|
|
|
self:init()
|
|
|
|
end
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function SetDefaults:init()
|
2021-09-17 17:36:57 +00:00
|
|
|
self.screen_width = Screen:getWidth()
|
|
|
|
self.screen_height = Screen:getHeight()
|
|
|
|
self.dialog_width = math.floor(math.min(self.screen_width, self.screen_height) * 0.95)
|
|
|
|
|
2014-08-11 08:39:49 +00:00
|
|
|
self.results = {}
|
|
|
|
|
2019-09-26 21:13:35 +00:00
|
|
|
local defaults = {}
|
|
|
|
local load_defaults = loadfile(defaults_path)
|
|
|
|
setfenv(load_defaults, defaults)
|
|
|
|
load_defaults()
|
|
|
|
|
|
|
|
local file = io.open(persistent_defaults_path, "r")
|
|
|
|
if file ~= nil then
|
|
|
|
file:close()
|
|
|
|
load_defaults = loadfile(persistent_defaults_path)
|
2016-05-02 02:39:31 +00:00
|
|
|
setfenv(load_defaults, defaults)
|
|
|
|
load_defaults()
|
2019-09-26 21:13:35 +00:00
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2019-09-26 21:13:35 +00:00
|
|
|
local idx = 1
|
|
|
|
for n, v in util.orderedPairs(defaults) do
|
|
|
|
self.defaults_name[idx] = n
|
|
|
|
self.defaults_value[idx] = v
|
|
|
|
idx = idx + 1
|
2014-08-20 08:47:08 +00:00
|
|
|
end
|
2014-08-11 08:39:49 +00:00
|
|
|
|
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
2019-08-23 17:53:53 +00:00
|
|
|
--- @fixme
|
2016-07-17 05:46:17 +00:00
|
|
|
-- in this use case (an input dialog is closed and the menu container is
|
|
|
|
-- opened immediately) we need to set the full screen dirty because
|
|
|
|
-- otherwise only the input dialog part of the screen is refreshed.
|
2014-12-04 02:09:09 +00:00
|
|
|
menu_container.onShow = function()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
UIManager:setDirty(nil, "ui")
|
2014-12-04 02:09:09 +00:00
|
|
|
end
|
2014-08-11 08:39:49 +00:00
|
|
|
|
|
|
|
self.defaults_menu = Menu:new{
|
2021-09-17 17:36:57 +00:00
|
|
|
width = self.screen_width - (Size.margin.fullscreen_popout * 2),
|
|
|
|
height = self.screen_height - (Size.margin.fullscreen_popout * 2),
|
2017-04-29 08:38:09 +00:00
|
|
|
cface = Font:getFace("smallinfofont"),
|
2014-08-11 08:39:49 +00:00
|
|
|
show_parent = menu_container,
|
|
|
|
_manager = self,
|
|
|
|
}
|
2019-09-26 21:13:35 +00:00
|
|
|
-- Prevent menu from closing when editing a value
|
|
|
|
function self.defaults_menu:onMenuSelect(item)
|
|
|
|
item.callback()
|
|
|
|
end
|
|
|
|
|
2014-08-11 08:39:49 +00:00
|
|
|
table.insert(menu_container, self.defaults_menu)
|
|
|
|
self.defaults_menu.close_callback = function()
|
2019-09-26 21:13:35 +00:00
|
|
|
logger.dbg("Closing defaults menu")
|
|
|
|
self:saveBeforeExit()
|
2014-08-11 08:39:49 +00:00
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
|
|
|
|
2016-05-02 02:39:31 +00:00
|
|
|
local cancel_button = {
|
|
|
|
text = _("Cancel"),
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self:close()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
for i=1, #self.defaults_name do
|
2014-08-20 06:51:07 +00:00
|
|
|
self.changed[i] = false
|
2016-05-02 02:39:31 +00:00
|
|
|
local setting_name = self.defaults_name[i]
|
|
|
|
local setting_type = type(_G[setting_name])
|
|
|
|
if setting_type == "boolean" then
|
|
|
|
local editBoolean = function()
|
|
|
|
self.set_dialog = InputDialog:new{
|
|
|
|
title = setting_name,
|
|
|
|
input = tostring(self.defaults_value[i]),
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
cancel_button,
|
|
|
|
{
|
|
|
|
text = "true",
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self.defaults_value[i] = true
|
|
|
|
_G[setting_name] = true
|
2016-09-22 07:36:09 +00:00
|
|
|
self.settings_changed = true
|
2016-05-02 02:39:31 +00:00
|
|
|
self.changed[i] = true
|
|
|
|
self.results[i].text = self:build_setting(i)
|
|
|
|
self:close()
|
2017-02-01 14:24:21 +00:00
|
|
|
self.defaults_menu:switchItemTable("Defaults", self.results, i)
|
2016-05-02 02:39:31 +00:00
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = "false",
|
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
|
|
|
self.defaults_value[i] = false
|
|
|
|
_G[setting_name] = false
|
2016-09-22 07:36:09 +00:00
|
|
|
self.settings_changed = true
|
2016-05-02 02:39:31 +00:00
|
|
|
self.changed[i] = true
|
|
|
|
self.results[i].text = self:build_setting(i)
|
2017-02-01 14:24:21 +00:00
|
|
|
self.defaults_menu:switchItemTable("Defaults", self.results, i)
|
2016-05-02 02:39:31 +00:00
|
|
|
self:close()
|
|
|
|
end
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
input_type = setting_type,
|
2021-09-17 17:36:57 +00:00
|
|
|
width = self.dialog_width,
|
2016-05-02 02:39:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.set_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.set_dialog:onShowKeyboard()
|
2016-05-02 02:39:31 +00:00
|
|
|
end
|
|
|
|
|
2014-08-16 20:31:32 +00:00
|
|
|
table.insert(self.results, {
|
2014-08-19 20:50:20 +00:00
|
|
|
text = self:build_setting(i),
|
2016-05-02 02:39:31 +00:00
|
|
|
callback = editBoolean
|
|
|
|
})
|
|
|
|
elseif setting_type == "table" then
|
|
|
|
local editTable = function()
|
|
|
|
local fields = {}
|
|
|
|
for k, v in util.orderedPairs(_G[setting_name]) do
|
|
|
|
table.insert(fields, {
|
|
|
|
text = tostring(k) .. " = " .. tostring(v),
|
|
|
|
hint = "",
|
2018-07-07 22:45:27 +00:00
|
|
|
padding = Screen:scaleBySize(2),
|
|
|
|
margin = Screen:scaleBySize(2),
|
2016-05-02 02:39:31 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
self.set_dialog = MultiInputDialog:new{
|
|
|
|
title = setting_name,
|
|
|
|
fields = fields,
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
cancel_button,
|
2014-08-16 20:31:32 +00:00
|
|
|
{
|
2016-05-02 02:39:31 +00:00
|
|
|
text = _("OK"),
|
|
|
|
enabled = true,
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2016-05-02 02:39:31 +00:00
|
|
|
callback = function()
|
|
|
|
local new_table = {}
|
|
|
|
for _, field in ipairs(MultiInputDialog:getFields()) do
|
2016-10-15 00:03:44 +00:00
|
|
|
local key, value = field:match("^[^= ]+"), field:match("[^= ]+$")
|
|
|
|
new_table[tonumber(key) or key] = tonumber(value) or value
|
2014-08-26 00:59:24 +00:00
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
_G[setting_name] = new_table
|
|
|
|
|
|
|
|
self.defaults_value[i] = _G[setting_name]
|
2016-09-22 07:36:09 +00:00
|
|
|
self.settings_changed = true
|
2016-05-02 02:39:31 +00:00
|
|
|
self.changed[i] = true
|
|
|
|
|
|
|
|
self.results[i].text = self:build_setting(i)
|
|
|
|
|
|
|
|
self:close()
|
2017-02-01 14:24:21 +00:00
|
|
|
self.defaults_menu:switchItemTable("Defaults", self.results, i)
|
2016-05-02 02:39:31 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-17 17:36:57 +00:00
|
|
|
width = self.dialog_width,
|
2016-05-02 02:39:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.set_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.set_dialog:onShowKeyboard()
|
2016-05-02 02:39:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(self.results, {
|
|
|
|
text = self:build_setting(i),
|
|
|
|
callback = editTable
|
|
|
|
})
|
|
|
|
else
|
|
|
|
local editNumStr = function()
|
|
|
|
self.set_dialog = InputDialog:new{
|
|
|
|
title = setting_name,
|
|
|
|
input = tostring(self.defaults_value[i]),
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
cancel_button,
|
|
|
|
{
|
|
|
|
text = _("OK"),
|
2016-05-26 06:09:49 +00:00
|
|
|
is_enter_default = true,
|
2016-05-02 02:39:31 +00:00
|
|
|
enabled = true,
|
|
|
|
callback = function()
|
2016-09-22 06:52:40 +00:00
|
|
|
local new_value = self.set_dialog:getInputValue()
|
2016-05-02 02:39:31 +00:00
|
|
|
if _G[setting_name] ~= new_value then
|
|
|
|
_G[setting_name] = new_value
|
|
|
|
self.defaults_value[i] = new_value
|
2016-09-22 07:36:09 +00:00
|
|
|
self.settings_changed = true
|
2014-08-20 06:51:07 +00:00
|
|
|
self.changed[i] = true
|
2014-08-19 20:50:20 +00:00
|
|
|
self.results[i].text = self:build_setting(i)
|
2014-08-16 20:31:32 +00:00
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
self:close()
|
2017-02-01 14:24:21 +00:00
|
|
|
self.defaults_menu:switchItemTable("Defaults", self.results, i)
|
2016-05-02 02:39:31 +00:00
|
|
|
end,
|
2014-08-11 08:39:49 +00:00
|
|
|
},
|
2014-08-16 20:31:32 +00:00
|
|
|
},
|
2016-05-02 02:39:31 +00:00
|
|
|
},
|
|
|
|
input_type = setting_type,
|
2021-09-17 17:36:57 +00:00
|
|
|
width = self.dialog_width,
|
2016-05-02 02:39:31 +00:00
|
|
|
}
|
|
|
|
UIManager:show(self.set_dialog)
|
2018-03-30 10:46:36 +00:00
|
|
|
self.set_dialog:onShowKeyboard()
|
2014-08-26 00:59:24 +00:00
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
|
|
|
|
table.insert(self.results, {
|
|
|
|
text = self:build_setting(i),
|
|
|
|
callback = editNumStr
|
|
|
|
})
|
2014-08-16 20:31:32 +00:00
|
|
|
end
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
2017-02-01 14:24:21 +00:00
|
|
|
self.defaults_menu:switchItemTable("Defaults", self.results)
|
2014-08-11 08:39:49 +00:00
|
|
|
UIManager:show(menu_container)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SetDefaults:close()
|
|
|
|
UIManager:close(self.set_dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SetDefaults:ConfirmSave()
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2016-05-02 02:39:31 +00:00
|
|
|
text = _('Are you sure you want to save the settings to "defaults.persistent.lua"?'),
|
2014-08-11 08:39:49 +00:00
|
|
|
ok_callback = function()
|
2016-07-17 05:46:17 +00:00
|
|
|
self:saveSettings()
|
2014-08-11 08:39:49 +00:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-08-19 20:50:20 +00:00
|
|
|
function SetDefaults:build_setting(j)
|
2016-05-02 02:39:31 +00:00
|
|
|
local setting_name = self.defaults_name[j]
|
|
|
|
local ret = setting_name .. " = "
|
|
|
|
if type(_G[setting_name]) == "boolean" then
|
|
|
|
return ret .. tostring(self.defaults_value[j])
|
|
|
|
elseif type(_G[setting_name]) == "table" then
|
|
|
|
return ret .. "{...}"
|
2014-08-19 20:50:20 +00:00
|
|
|
elseif tonumber(self.defaults_value[j]) then
|
2016-05-02 02:39:31 +00:00
|
|
|
return ret .. tostring(tonumber(self.defaults_value[j]))
|
2014-08-19 20:50:20 +00:00
|
|
|
else
|
2016-05-02 02:39:31 +00:00
|
|
|
return ret .. "\"" .. tostring(self.defaults_value[j]) .. "\""
|
2014-08-19 20:50:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-17 05:46:17 +00:00
|
|
|
function SetDefaults:saveSettings()
|
2016-05-02 02:39:31 +00:00
|
|
|
self.results = {}
|
|
|
|
local persisted_defaults = {}
|
2016-09-22 07:10:40 +00:00
|
|
|
local file = io.open(persistent_defaults_path, "r")
|
2016-05-02 02:39:31 +00:00
|
|
|
if file ~= nil then
|
2014-08-11 08:39:49 +00:00
|
|
|
file:close()
|
2016-09-22 07:10:40 +00:00
|
|
|
local load_defaults = loadfile(persistent_defaults_path)
|
2016-05-02 02:39:31 +00:00
|
|
|
setfenv(load_defaults, persisted_defaults)
|
|
|
|
load_defaults()
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
|
|
|
|
2016-05-02 02:39:31 +00:00
|
|
|
local checked = {}
|
|
|
|
for j=1, #self.defaults_name do
|
|
|
|
if not self.changed[j] then checked[j] = true end
|
2014-08-20 06:51:07 +00:00
|
|
|
end
|
|
|
|
|
2016-05-26 07:44:42 +00:00
|
|
|
-- load default value for defaults
|
|
|
|
local defaults = {}
|
|
|
|
local load_defaults = loadfile(defaults_path)
|
|
|
|
setfenv(load_defaults, defaults)
|
|
|
|
load_defaults()
|
|
|
|
-- handle case "found in persistent" and changed, replace/delete it
|
2016-05-02 02:39:31 +00:00
|
|
|
for k, v in pairs(persisted_defaults) do
|
|
|
|
for j=1, #self.defaults_name do
|
|
|
|
if not checked[j]
|
|
|
|
and k == self.defaults_name[j] then
|
2016-05-26 07:44:42 +00:00
|
|
|
-- remove from persist if value got reverted back to the
|
|
|
|
-- default one
|
|
|
|
if defaults[k] == self.defaults_value[j] then
|
|
|
|
persisted_defaults[k] = nil
|
|
|
|
else
|
|
|
|
persisted_defaults[k] = self.defaults_value[j]
|
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
checked[j] = true
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-02 02:39:31 +00:00
|
|
|
-- handle case "not in persistent and different in non-persistent", add to
|
|
|
|
-- persistent
|
|
|
|
for j=1, #self.defaults_name do
|
|
|
|
if not checked[j] then
|
|
|
|
persisted_defaults[self.defaults_name[j]] = self.defaults_value[j]
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-22 07:10:40 +00:00
|
|
|
file = io.open(persistent_defaults_path, "w")
|
2015-06-15 08:46:43 +00:00
|
|
|
if file then
|
2016-05-02 02:39:31 +00:00
|
|
|
file:write("-- For configuration changes that persists between updates\n")
|
|
|
|
for k, v in pairs(persisted_defaults) do
|
|
|
|
local line = {}
|
|
|
|
table.insert(line, k)
|
|
|
|
table.insert(line, " = ")
|
|
|
|
table.insert(line, dump(v))
|
|
|
|
table.insert(line, "\n")
|
|
|
|
file:write(table.concat(line))
|
2015-06-15 08:46:43 +00:00
|
|
|
end
|
|
|
|
file:close()
|
|
|
|
UIManager:show(InfoMessage:new{
|
2016-04-15 13:04:41 +00:00
|
|
|
text = _("Default settings saved."),
|
2015-06-15 08:46:43 +00:00
|
|
|
})
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
2016-09-22 07:36:09 +00:00
|
|
|
self.settings_changed = false
|
2014-08-11 08:39:49 +00:00
|
|
|
end
|
2016-05-02 02:39:31 +00:00
|
|
|
|
2019-09-26 21:13:35 +00:00
|
|
|
function SetDefaults:saveBeforeExit(callback)
|
|
|
|
local save_text = _("Save and quit")
|
|
|
|
if Device:canRestart() then
|
|
|
|
save_text = _("Save and restart")
|
|
|
|
end
|
|
|
|
if self.settings_changed then
|
|
|
|
UIManager:show(ConfirmBox:new{
|
|
|
|
text = _("KOReader needs to be restarted to apply the new default settings."),
|
|
|
|
ok_text = save_text,
|
|
|
|
ok_callback = function()
|
|
|
|
self.settings_changed = false
|
|
|
|
self:saveSettings()
|
|
|
|
if Device:canRestart() then
|
|
|
|
UIManager:restartKOReader()
|
|
|
|
else
|
|
|
|
UIManager:quit()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
cancel_text = _("Discard changes"),
|
|
|
|
cancel_callback = function()
|
|
|
|
logger.info("discard defaults")
|
|
|
|
pcall(dofile, defaults_path)
|
|
|
|
pcall(dofile, persistent_defaults_path)
|
|
|
|
self.settings_changed = false
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-11 08:39:49 +00:00
|
|
|
return SetDefaults
|