Browse Source

LuaSettings: Add a method to initialize a setting properly (#7371)

* LuaSettings/DocSettings: Updated readSetting API to allow proper initialization to default.
Use it to initialize tables, e.g., fixing corner-cases in readerFooter that could prevent settings from being saved.
(Fixes an issue reported on Gitter).
* LuaSettings/DocSettings: Add simpler API than the the flip* ones to toggle boolean settings.
* Update LuaSettings/DocSettigns usage throughout the codebase to use the dedicated boolean methods wher appropriate, and clean up some of the more mind-bending uses.
* FileChooser: Implement an extended default exclusion list (fix #2360)
* ScreenSaver: Refactor to avoid the pile of kludges this was threatening to become. Code should be easier to follow and use, and fallbacks now behave as expected (fix #4418).
reviewable/pr7393/r1
NiLuJe 8 months ago
committed by GitHub
parent
commit
bf6c0cdd6c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 1273 additions and 1067 deletions
  1. +1
    -0
      frontend/apps/cloudstorage/cloudstorage.lua
  2. +8
    -4
      frontend/apps/filemanager/filemanager.lua
  3. +9
    -9
      frontend/apps/filemanager/filemanagerbookinfo.lua
  4. +1
    -4
      frontend/apps/filemanager/filemanagerfilesearcher.lua
  5. +12
    -12
      frontend/apps/filemanager/filemanagermenu.lua
  6. +11
    -16
      frontend/apps/filemanager/filemanagershortcuts.lua
  7. +6
    -6
      frontend/apps/reader/modules/readerbookmark.lua
  8. +3
    -2
      frontend/apps/reader/modules/readerconfig.lua
  9. +3
    -2
      frontend/apps/reader/modules/readercoptlistener.lua
  10. +18
    -27
      frontend/apps/reader/modules/readerdictionary.lua
  11. +9
    -9
      frontend/apps/reader/modules/readerdogear.lua
  12. +24
    -17
      frontend/apps/reader/modules/readerfont.lua
  13. +6
    -10
      frontend/apps/reader/modules/readerfooter.lua
  14. +14
    -12
      frontend/apps/reader/modules/readerhighlight.lua
  15. +7
    -5
      frontend/apps/reader/modules/readerkoptlistener.lua
  16. +1
    -1
      frontend/apps/reader/modules/readerlink.lua
  17. +8
    -7
      frontend/apps/reader/modules/readermenu.lua
  18. +13
    -11
      frontend/apps/reader/modules/readerpagemap.lua
  19. +9
    -7
      frontend/apps/reader/modules/readerpaging.lua
  20. +27
    -19
      frontend/apps/reader/modules/readerrolling.lua
  21. +2
    -2
      frontend/apps/reader/modules/readerstyletweak.lua
  22. +4
    -4
      frontend/apps/reader/modules/readertoc.lua
  23. +41
    -33
      frontend/apps/reader/modules/readertypeset.lua
  24. +58
    -57
      frontend/apps/reader/modules/readertypography.lua
  25. +12
    -9
      frontend/apps/reader/modules/readerview.lua
  26. +5
    -5
      frontend/apps/reader/modules/readerwikipedia.lua
  27. +7
    -7
      frontend/apps/reader/modules/readerzooming.lua
  28. +1
    -1
      frontend/apps/reader/readerui.lua
  29. +1
    -0
      frontend/device/cervantes/device.lua
  30. +1
    -1
      frontend/device/devicelistener.lua
  31. +10
    -12
      frontend/device/generic/device.lua
  32. +5
    -7
      frontend/device/kindle/device.lua
  33. +2
    -4
      frontend/device/kobo/device.lua
  34. +1
    -7
      frontend/device/sdl/device.lua
  35. +1
    -0
      frontend/device/sony-prstux/device.lua
  36. +120
    -3
      frontend/docsettings.lua
  37. +3
    -3
      frontend/document/credocument.lua
  38. +4
    -6
      frontend/document/documentregistry.lua
  39. +58
    -6
      frontend/luasettings.lua
  40. +2
    -2
      frontend/readhistory.lua
  41. +3
    -3
      frontend/ui/data/settings_migration.lua
  42. +6
    -7
      frontend/ui/elements/common_settings_menu_table.lua
  43. +2
    -2
      frontend/ui/elements/flash_keyboard.lua
  44. +2
    -2
      frontend/ui/elements/screen_disable_double_tap_table.lua
  45. +49
    -87
      frontend/ui/elements/screensaver_menu.lua
  46. +9
    -9
      frontend/ui/network/manager.lua
  47. +372
    -322
      frontend/ui/screensaver.lua
  48. +2
    -2
      frontend/ui/translator.lua
  49. +8
    -4
      frontend/ui/uimanager.lua
  50. +1
    -1
      frontend/ui/widget/configdialog.lua
  51. +3
    -3
      frontend/ui/widget/dictquicklookup.lua
  52. +69
    -21
      frontend/ui/widget/filechooser.lua
  53. +1
    -1
      frontend/ui/widget/pathchooser.lua
  54. +1
    -1
      frontend/ui/widget/virtualkeyboard.lua
  55. +40
    -0
      frontend/util.lua
  56. +13
    -40
      plugins/autosuspend.koplugin/main.lua
  57. +2
    -2
      plugins/autoturn.koplugin/main.lua
  58. +3
    -4
      plugins/calibre.koplugin/main.lua
  59. +5
    -6
      plugins/calibre.koplugin/metadata.lua
  60. +1
    -1
      plugins/calibre.koplugin/search.lua
  61. +1
    -1
      plugins/calibre.koplugin/wireless.lua
  62. +1
    -1
      plugins/coverbrowser.koplugin/main.lua
  63. +5
    -5
      plugins/coverimage.koplugin/main.lua
  64. +5
    -5
      plugins/gestures.koplugin/main.lua
  65. +1
    -1
      plugins/gestures.koplugin/migration.lua
  66. +2
    -1
      plugins/kosync.koplugin/main.lua
  67. +4
    -6
      plugins/newsdownloader.koplugin/main.lua
  68. +54
    -64
      plugins/opds.koplugin/opdsbrowser.lua
  69. +1
    -1
      plugins/perceptionexpander.koplugin/main.lua
  70. +61
    -85
      plugins/statistics.koplugin/main.lua
  71. +5
    -7
      plugins/terminal.koplugin/main.lua
  72. +4
    -3
      plugins/texteditor.koplugin/main.lua
  73. +1
    -1
      plugins/zsync.koplugin/main.lua
  74. +1
    -1
      reader.lua
  75. +1
    -1
      spec/unit/autofrontlight_spec.lua
  76. +2
    -2
      spec/unit/luadata_spec.lua
  77. +2
    -2
      spec/unit/luasettings_spec.lua
  78. +2
    -2
      spec/unit/readhistory_spec.lua

+ 1
- 0
frontend/apps/cloudstorage/cloudstorage.lua View File

@ -32,6 +32,7 @@ local CloudStorage = Menu:extend{
}
function CloudStorage:init()
--- @todo: Probably a good candidate for the new readSetting API
self.cs_settings = self:readSettings()
self.show_parent = self
if self.item then

+ 8
- 4
frontend/apps/filemanager/filemanager.lua View File

@ -169,9 +169,13 @@ function FileManager:setupLayout()
}
}
local g_show_hidden = G_reader_settings:readSetting("show_hidden")
local show_hidden = g_show_hidden == nil and DSHOWHIDDENFILES or g_show_hidden
local show_unsupported = G_reader_settings:readSetting("show_unsupported")
local show_hidden
if G_reader_settings:has("show_hidden") then
show_hidden = G_reader_settings:isTrue("show_hidden")
else
show_hidden = DSHOWHIDDENFILES
end
local show_unsupported = G_reader_settings:isTrue("show_unsupported")
local file_chooser = FileChooser:new{
-- remember to adjust the height when new item is added to the group
path = self.root_path,
@ -760,7 +764,7 @@ end
function FileManager:goHome()
local home_dir = G_reader_settings:readSetting("home_dir")
if not home_dir or lfs.attributes(home_dir, "mode") ~= "directory" then
if not home_dir or lfs.attributes(home_dir, "mode") ~= "directory" then
-- Try some sane defaults, depending on platform
home_dir = Device.home_dir
end

+ 9
- 9
frontend/apps/filemanager/filemanagerbookinfo.lua View File

@ -67,7 +67,7 @@ function BookInfo:show(file, book_props)
table.insert(kv_pairs, { _("Folder:"), BD.dirpath(filemanagerutil.abbreviate(directory)), separator = true })
-- book_props may be provided if caller already has them available
-- but it may lack 9;pages';, that we may get from sidecar file
-- but it may lack 4;pages";, that we may get from sidecar file
if not book_props or not book_props.pages then
-- check there is actually a sidecar file before calling DocSettings:open()
-- that would create an empty sidecar directory
@ -75,24 +75,24 @@ function BookInfo:show(file, book_props)
local doc_settings = DocSettings:open(file)
if doc_settings then
if not book_props then
-- Files opened after 20170701 have a 9;doc_props'; setting with
-- complete metadata and 9;doc_pages'; with accurate nb of pages
book_props = doc_settings:readSetting('doc_props';)
-- Files opened after 20170701 have a 4;doc_props"; setting with
-- complete metadata and 4;doc_pages"; with accurate nb of pages
book_props = doc_settings:readSetting("doc_props";)
end
if not book_props then
-- File last opened before 20170701 may have a 9;stats' setting
-- File last opened before 20170701 may have a 4;stats" setting.
-- with partial metadata, or empty metadata if statistics plugin
-- was not enabled when book was read (we can guess that from
-- the fact that stats.page = 0)
local stats = doc_settings:readSetting('stats';)
local stats = doc_settings:readSetting("stats";)
if stats and stats.pages ~= 0 then
-- Let's use them as is (which was what was done before), even if
-- incomplete, to avoid expensive book opening
book_props = stats
end
end
-- Files opened after 20170701 have an accurate 9;doc_pages' setting
local doc_pages = doc_settings:readSetting('doc_pages';)
-- Files opened after 20170701 have an accurate 4;doc_pages" setting.
local doc_pages = doc_settings:readSetting("doc_pages";)
if doc_pages and book_props then
book_props.pages = doc_pages
end
@ -100,7 +100,7 @@ function BookInfo:show(file, book_props)
end
end
-- If still no book_props (book never opened or empty 9;stats';), open the
-- If still no book_props (book never opened or empty 4;stats";), open the
-- document to get them
if not book_props then
local document = DocumentRegistry:openDocument(file)

+ 1
- 4
frontend/apps/filemanager/filemanagerfilesearcher.lua View File

@ -95,10 +95,7 @@ end
function FileSearcher:onShowFileSearch()
local dummy = self.search_value
local enabled_search_home_dir = true
if not G_reader_settings:readSetting("home_dir") then
enabled_search_home_dir = false
end
local enabled_search_home_dir = G_reader_settings:has("home_dir")
self.search_dialog = InputDialog:new{
title = _("Search for books by filename"),
input = self.search_value,

+ 12
- 12
frontend/apps/filemanager/filemanagermenu.lua View File

@ -236,18 +236,18 @@ function FileManagerMenu:setUpdateItemTable()
local current_state = _("Show new files in bold")
if G_reader_settings:readSetting("show_file_in_bold") == "opened" then
current_state = _("Show opened files in bold")
elseif G_reader_settings:readSetting("show_file_in_bold") == false then
elseif G_reader_settings:isFalse("show_file_in_bold") then
current_state = _("Show files in bold") -- with checkmark unchecked
end
-- Inform that this settings applies only to classic file chooser
current_state = T(_("(Classic file browser) %1"), current_state)
return current_state
end,
checked_func = function() return G_reader_settings:readSetting("show_file_in_bold") ~= false end,
checked_func = function() return not G_reader_settings:isFalse("show_file_in_bold") end,
sub_item_table = {
{
text = _("Don't show files in bold"),
checked_func = function() return G_reader_settings:readSetting("show_file_in_bold") == false end,
checked_func = function() return G_reader_settings:isFalse("show_file_in_bold") end,
callback = function()
G_reader_settings:saveSetting("show_file_in_bold", false)
self.ui:onRefresh()
@ -264,7 +264,7 @@ function FileManagerMenu:setUpdateItemTable()
{
text = _("Show new (not yet opened) files in bold"),
checked_func = function()
return G_reader_settings:readSetting("show_file_in_bold") ~= false and G_reader_settings:readSetting("show_file_in_bold") ~= "opened"
return not G_reader_settings:isFalse("show_file_in_bold") and G_reader_settings:readSetting("show_file_in_bold") ~= "opened"
end,
callback = function()
G_reader_settings:delSetting("show_file_in_bold")
@ -296,12 +296,12 @@ To:
},
{
text = _("Show filename in Open last/previous menu items"),
checked_func = function() return G_reader_settings:readSetting("open_last_menu_show_filename") end,
checked_func = function() return G_reader_settings:isTrue("open_last_menu_show_filename") end,
callback = function() G_reader_settings:flipNilOrFalse("open_last_menu_show_filename") end,
},
{
text = _("Auto-remove deleted or purged items from history"),
checked_func = function() return G_reader_settings:readSetting("autoremove_deleted_items_from_history") end,
checked_func = function() return G_reader_settings:isTrue("autoremove_deleted_items_from_history") end,
callback = function() G_reader_settings:flipNilOrFalse("autoremove_deleted_items_from_history") end,
separator = true,
},
@ -413,7 +413,7 @@ To:
else
dbg:setVerbose(false)
dbg:turnOff()
G_reader_settings:flipFalse("debug_verbose")
G_reader_settings:makeFalse("debug_verbose")
end
end,
},
@ -494,7 +494,7 @@ To:
G_reader_settings:saveSetting("dev_no_hw_dither", not Device.screen.hw_dithering)
-- Make sure SW dithering gets disabled when we enable HW dithering
if Device.screen.hw_dithering and Device.screen.sw_dithering then
G_reader_settings:saveSetting("dev_no_sw_dither", true)
G_reader_settings:makeTrue("dev_no_sw_dither")
Device.screen:toggleSWDithering(false)
end
UIManager:setDirty("all", "full")
@ -515,7 +515,7 @@ To:
G_reader_settings:saveSetting("dev_no_sw_dither", not Device.screen.sw_dithering)
-- Make sure HW dithering gets disabled when we enable SW dithering
if Device.screen.hw_dithering and Device.screen.sw_dithering then
G_reader_settings:saveSetting("dev_no_hw_dither", true)
G_reader_settings:makeTrue("dev_no_hw_dither")
Device.screen:toggleHWDithering(false)
end
UIManager:setDirty("all", "full")
@ -621,15 +621,15 @@ To:
-- main menu tab
self.menu_items.open_last_document = {
text_func = function()
if not G_reader_settings:isTrue("open_last_menu_show_filename") or not G_reader_settings:readSetting("lastfile") then
if not G_reader_settings:isTrue("open_last_menu_show_filename") or G_reader_settings:hasNot("lastfile") then
return _("Open last document")
end
local last_file = G_reader_settings:readSetting("lastfile")
local path, file_name = util.splitFilePathName(last_file); -- luacheck: no unused
local path, file_name = util.splitFilePathName(last_file) -- luacheck: no unused
return T(_("Last: %1"), BD.filename(file_name))
end,
enabled_func = function()
return G_reader_settings:readSetting("lastfile") ~= nil
return G_reader_settings:has("lastfile")
end,
callback = function()
self:onOpenLastDoc()

+ 11
- 16
frontend/apps/filemanager/filemanagershortcuts.lua View File

@ -11,12 +11,13 @@ local util = require("ffi/util")
local _ = require("gettext")
local T = util.template
local FileManagerShortcuts = InputContainer:extend{}
local FileManagerShortcuts = InputContainer:extend{
folder_shortcuts = G_reader_settings:readSetting("folder_shortcuts", {}),
}
function FileManagerShortcuts:updateItemTable()
local item_table = {}
local folder_shortcuts = G_reader_settings:readSetting("folder_shortcuts") or {}
for _, item in ipairs(folder_shortcuts) do
for _, item in ipairs(self.folder_shortcuts) do
table.insert(item_table, {
text = string.format("%s (%s)", item.text, item.folder),
folder = item.folder,
@ -107,7 +108,7 @@ function FileManagerShortcuts:addNewFolder()
end
function FileManagerShortcuts:addFolderFromInput(friendly_name, folder)
for __, item in ipairs(G_reader_settings:readSetting("folder_shortcuts") or {}) do
for __, item in ipairs(self.folder_shortcuts) do
if item.text == friendly_name and item.folder == folder then
UIManager:show(InfoMessage:new{
text = _("A shortcut to this folder already exists."),
@ -115,12 +116,10 @@ function FileManagerShortcuts:addFolderFromInput(friendly_name, folder)
return
end
end
local folder_shortcuts = G_reader_settings:readSetting("folder_shortcuts") or {}
table.insert(folder_shortcuts, {
table.insert(self.folder_shortcuts, {
text = friendly_name,
folder = folder,
})
G_reader_settings:saveSetting("folder_shortcuts", folder_shortcuts)
self:updateItemTable()
end
@ -193,25 +192,21 @@ function FileManagerShortcuts:editFolderShortcut(item)
end
function FileManagerShortcuts:renameFolderShortcut(item, new_name)
local folder_shortcuts = {}
for _, element in ipairs(G_reader_settings:readSetting("folder_shortcuts") or {}) do
for _, element in ipairs(self.folder_shortcuts) do
if element.text == item.friendly_name and element.folder == item.folder then
element.text = new_name
end
table.insert(folder_shortcuts, element)
end
G_reader_settings:saveSetting("folder_shortcuts", folder_shortcuts)
self:updateItemTable()
end
function FileManagerShortcuts:deleteFolderShortcut(item)
local folder_shortcuts = {}
for _, element in ipairs(G_reader_settings:readSetting("folder_shortcuts") or {}) do
if element.text ~= item.friendly_name or element.folder ~= item.folder then
table.insert(folder_shortcuts, element)
for i = #self.folder_shortcuts, 1, -1 do
local element = self.folder_shortcuts[i]
if element.text == item.friendly_name and element.folder == item.folder then
table.remove(self.folder_shortcuts, i)
end
end
G_reader_settings:saveSetting("folder_shortcuts", folder_shortcuts)
self:updateItemTable()
end

+ 6
- 6
frontend/apps/reader/modules/readerbookmark.lua View File

@ -32,12 +32,12 @@ function ReaderBookmark:init()
}
end
if not G_reader_settings:readSetting("bookmarks_items_per_page") then
if G_reader_settings:hasNot("bookmarks_items_per_page") then
-- The Bookmarks items per page and items' font size can now be
-- configured. Previously, the ones set for the file browser
-- were used. Initialize them from these ones.
local items_per_page = G_reader_settings:readSetting("items_per_page")
or self.bookmarks_items_per_page_default
or self.bookmarks_items_per_page_default
G_reader_settings:saveSetting("bookmarks_items_per_page", items_per_page)
local items_font_size = G_reader_settings:readSetting("items_font_size")
if items_font_size and items_font_size ~= Menu.getItemFontSize(items_per_page) then
@ -186,7 +186,7 @@ end
function ReaderBookmark:fixBookmarkSort(config)
-- for backward compatibility, since previously bookmarks for credocuments
-- are not well sorted. We need to do a whole sorting for at least once.
if not config:readSetting("bookmarks_sorted") then
if config:hasNot("bookmarks_sorted") then
table.sort(self.bookmarks, function(a, b)
return self:isBookmarkInPageOrder(a, b)
end)
@ -197,7 +197,7 @@ function ReaderBookmark:importSavedHighlight(config)
local textmarks = config:readSetting("highlight") or {}
-- import saved highlight once, because from now on highlight are added to
-- bookmarks when they are created.
if not config:readSetting("highlights_imported") then
if config:hasNot("highlights_imported") then
for page, marks in pairs(textmarks) do
for _, mark in ipairs(marks) do
page = self.ui.document.info.has_pages and page or mark.pos0
@ -228,8 +228,8 @@ end
function ReaderBookmark:onSaveSettings()
self.ui.doc_settings:saveSetting("bookmarks", self.bookmarks)
self.ui.doc_settings:saveSetting("bookmarks_sorted", true)
self.ui.doc_settings:saveSetting("highlights_imported", true)
self.ui.doc_settings:makeTrue("bookmarks_sorted")
self.ui.doc_settings:makeTrue("highlights_imported")
end
function ReaderBookmark:isCurrentPageBookmarked()

+ 3
- 2
frontend/apps/reader/modules/readerconfig.lua View File

@ -29,8 +29,9 @@ function ReaderConfig:init()
if Device:isTouchDevice() then
self:initGesListener()
end
self.activation_menu = G_reader_settings:readSetting("activate_menu")
if self.activation_menu == nil then
if G_reader_settings:has("activate_menu") then
self.activation_menu = G_reader_settings:readSetting("activate_menu")
else
self.activation_menu = "swipe_tap"
end
end

+ 3
- 2
frontend/apps/reader/modules/readercoptlistener.lua View File

@ -11,8 +11,9 @@ local _ = require("gettext")
local ReaderCoptListener = EventListener:new{}
function ReaderCoptListener:onReadSettings(config)
local view_mode = config:readSetting("copt_view_mode") or
G_reader_settings:readSetting("copt_view_mode") or 0 -- default to "page" mode
local view_mode = config:readSetting("copt_view_mode")
or G_reader_settings:readSetting("copt_view_mode")
or 0 -- default to "page" mode
local view_mode_name = view_mode == 0 and "page" or "scroll"
-- Let crengine know of the view mode before rendering, as it can
-- cause a rendering change (2-pages would become 1-page in

+ 18
- 27
frontend/apps/reader/modules/readerdictionary.lua View File

@ -58,7 +58,6 @@ end
local ReaderDictionary = InputContainer:new{
data_dir = nil,
dict_window_list = {},
disable_lookup_history = G_reader_settings:isTrue("disable_lookup_history"),
lookup_msg = _("Searching dictionary for:\n%1"),
}
@ -96,6 +95,10 @@ local function getDictionaryFixHtmlFunc(path)
end
function ReaderDictionary:init()
self.disable_lookup_history = G_reader_settings:isTrue("disable_lookup_history")
self.dicts_order = G_reader_settings:readSetting("dicts_order", {})
self.dicts_disabled = G_reader_settings:readSetting("dicts_disabled", {})
self.ui.menu:registerToMainMenu(self)
self.data_dir = STARDICT_DATA_DIR or
os.getenv("STARDICT_DATA_DIR") or
@ -140,19 +143,7 @@ function ReaderDictionary:init()
end
end
logger.dbg("found", #available_ifos, "dictionaries")
if not G_reader_settings:readSetting("dicts_order") then
G_reader_settings:saveSetting("dicts_order", {})
end
self:sortAvailableIfos()
if not G_reader_settings:readSetting("dicts_disabled") then
-- Create an empty dict for this setting, so that we can
-- access and update it directly through G_reader_settings
-- and it will automatically be saved.
G_reader_settings:saveSetting("dicts_disabled", {})
end
end
-- Prepare the -u options to give to sdcv the dictionary order and if some are disabled
self:updateSdcvDictNamesOptions()
@ -163,11 +154,9 @@ function ReaderDictionary:init()
end
function ReaderDictionary:sortAvailableIfos()
local dicts_order = G_reader_settings:readSetting("dicts_order")
table.sort(available_ifos, function(lifo, rifo)
local lord = dicts_order[lifo.file]
local rord = dicts_order[rifo.file]
local lord = self.dicts_order[lifo.file]
local rord = self.dicts_order[rifo.file]
-- Both ifos without an explicit position -> lexical comparison
if lord == rord then
@ -468,9 +457,8 @@ function ReaderDictionary:getNumberOfDictionaries()
local nb_available = #available_ifos
local nb_enabled = 0
local nb_disabled = 0
local dicts_disabled = G_reader_settings:readSetting("dicts_disabled")
for _, ifo in pairs(available_ifos) do
if dicts_disabled[ifo.file] then
if self.dicts_disabled[ifo.file] then
nb_disabled = nb_disabled + 1
else
nb_enabled = nb_enabled + 1
@ -526,7 +514,7 @@ end
function ReaderDictionary:showDictionariesMenu(changed_callback)
-- Work on local copy, save to settings only when SortWidget is closed with the accept button
local dicts_disabled = util.tableDeepCopy(G_reader_settings:readSetting("dicts_disabled"))
local dicts_disabled = util.tableDeepCopy(self.dicts_disabled)
local sort_items = {}
for _, ifo in pairs(available_ifos) do
@ -550,15 +538,17 @@ function ReaderDictionary:showDictionariesMenu(changed_callback)
title = _("Manage installed dictionaries"),
item_table = sort_items,
callback = function()
-- Save local copy of dicts_disabled
G_reader_settings:saveSetting("dicts_disabled", dicts_disabled)
-- Update both references to point to that new object
self.dicts_disabled = dicts_disabled
G_reader_settings:saveSetting("dicts_disabled", self.dicts_disabled)
-- Write back the sorted items to dicts_order
local dicts_order = {}
for i, sort_item in pairs(sort_items) do
dicts_order[sort_item.ifo.file] = i
end
G_reader_settings:saveSetting("dicts_order", dicts_order)
self.dicts_order = dicts_order
G_reader_settings:saveSetting("dicts_order", self.dicts_order)
self:sortAvailableIfos()
@ -1058,8 +1048,9 @@ function ReaderDictionary:onReadSettings(config)
if #self.preferred_dictionaries > 0 then
self:updateSdcvDictNamesOptions()
end
self.disable_fuzzy_search = config:readSetting("disable_fuzzy_search")
if self.disable_fuzzy_search == nil then
if config:has("disable_fuzzy_search") then
self.disable_fuzzy_search = config:isTrue("disable_fuzzy_search")
else
self.disable_fuzzy_search = G_reader_settings:isTrue("disable_fuzzy_search")
end
end
@ -1118,13 +1109,13 @@ The current default (★) is enabled.]])
return disable_fuzzy_search and _("Disable (★)") or _("Disable")
end,
choice1_callback = function()
G_reader_settings:saveSetting("disable_fuzzy_search", true)
G_reader_settings:makeTrue("disable_fuzzy_search")
end,
choice2_text_func = function()
return disable_fuzzy_search and _("Enable") or _("Enable (★)")
end,
choice2_callback = function()
G_reader_settings:saveSetting("disable_fuzzy_search", false)
G_reader_settings:makeFalse("disable_fuzzy_search")
end,
})
end

+ 9
- 9
frontend/apps/reader/modules/readerdogear.lua View File

@ -56,15 +56,15 @@ end
function ReaderDogear:onReadSettings(config)
if not self.ui.document.info.has_pages then
-- Adjust to CreDocument margins (as done in ReaderTypeset)
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin") or
G_reader_settings:readSetting("copt_t_page_margin") or
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin") or
G_reader_settings:readSetting("copt_b_page_margin") or
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin")
or G_reader_settings:readSetting("copt_t_page_margin")
or DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin")
or G_reader_settings:readSetting("copt_b_page_margin")
or DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
local margins = { h_margins[1], t_margin, h_margins[2], b_margin }
self:onSetPageMargins(margins)
end

+ 24
- 17
frontend/apps/reader/modules/readerfont.lua View File

@ -108,48 +108,55 @@ end
function ReaderFont:onReadSettings(config)
self.font_face = config:readSetting("font_face")
or G_reader_settings:readSetting("cre_font")
or self.ui.document.default_font
or G_reader_settings:readSetting("cre_font")
or self.ui.document.default_font
self.ui.document:setFontFace(self.font_face)
self.header_font_face = config:readSetting("header_font_face")
or G_reader_settings:readSetting("header_font")
or self.ui.document.header_font
or G_reader_settings:readSetting("header_font")
or self.ui.document.header_font
self.ui.document:setHeaderFont(self.header_font_face)
self.font_size = config:readSetting("font_size")
or G_reader_settings:readSetting("copt_font_size")
or DCREREADER_CONFIG_DEFAULT_FONT_SIZE or 22
or G_reader_settings:readSetting("copt_font_size")
or DCREREADER_CONFIG_DEFAULT_FONT_SIZE
or 22
self.ui.document:setFontSize(Screen:scaleBySize(self.font_size))
self.font_embolden = config:readSetting("font_embolden")
or G_reader_settings:readSetting("copt_font_weight") or 0
or G_reader_settings:readSetting("copt_font_weight")
or 0
self.ui.document:toggleFontBolder(self.font_embolden)
self.font_hinting = config:readSetting("font_hinting")
or G_reader_settings:readSetting("copt_font_hinting") or 2 -- auto (default in cre.cpp)
or G_reader_settings:readSetting("copt_font_hinting")
or 2 -- auto (default in cre.cpp)
self.ui.document:setFontHinting(self.font_hinting)
self.font_kerning = config:readSetting("font_kerning")
or G_reader_settings:readSetting("copt_font_kerning") or 3 -- harfbuzz (slower, but needed for proper arabic)
or G_reader_settings:readSetting("copt_font_kerning")
or 3 -- harfbuzz (slower, but needed for proper arabic)
self.ui.document:setFontKerning(self.font_kerning)
self.word_spacing = config:readSetting("word_spacing")
or G_reader_settings:readSetting("copt_word_spacing") or {95, 75}
or G_reader_settings:readSetting("copt_word_spacing")
or {95, 75}
self.ui.document:setWordSpacing(self.word_spacing)
self.word_expansion = config:readSetting("word_expansion")
or G_reader_settings:readSetting("copt_word_expansion") or 0
or G_reader_settings:readSetting("copt_word_expansion")
or 0
self.ui.document:setWordExpansion(self.word_expansion)
self.line_space_percent = config:readSetting("line_space_percent")
or G_reader_settings:readSetting("copt_line_spacing")
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
or G_reader_settings:readSetting("copt_line_spacing")
or DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM
self.ui.document:setInterlineSpacePercent(self.line_space_percent)
self.gamma_index = config:readSetting("gamma_index")
or G_reader_settings:readSetting("copt_font_gamma")
or DCREREADER_CONFIG_DEFAULT_FONT_GAMMA or 15 -- gamma = 1.0
or G_reader_settings:readSetting("copt_font_gamma")
or DCREREADER_CONFIG_DEFAULT_FONT_GAMMA
or 15 -- gamma = 1.0
self.ui.document:setGammaIndex(self.gamma_index)
-- Dirty hack: we have to add following call in order to set
@ -439,8 +446,8 @@ function ReaderFont:buildFontsTestDocument()
f:close()
end
local dir = G_reader_settings:readSetting("home_dir")
if not dir then dir = require("apps/filemanager/filemanagerutil").getDefaultDir() end
if not dir then dir = "." end
or require("apps/filemanager/filemanagerutil").getDefaultDir()
or "."
local font_test_final_path = dir .. "/" .. FONT_TEST_FINAL_FILENAME
f = io.open(font_test_final_path, "w")
if not f then return end

+ 6
- 10
frontend/apps/reader/modules/readerfooter.lua View File

@ -387,7 +387,7 @@ local ReaderFooter = WidgetContainer:extend{
}
function ReaderFooter:init()
self.settings = G_reader_settings:readSetting("footer") or {
self.settings = G_reader_settings:readSetting("footer", {
-- enable progress bar by default
-- disable_progress_bar = true,
disabled = false,
@ -414,7 +414,7 @@ function ReaderFooter:init()
text_font_bold = false,
container_height = DMINIBAR_CONTAINER_HEIGHT,
container_bottom_padding = 1, -- unscaled_size_check: ignore
}
})
-- Remove items not supported by the current device
if not Device:hasFastWifiStatusQuery() then
@ -889,7 +889,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings[option] = not self.settings[option]
G_reader_settings:saveSetting("footer", self.settings)
-- We only need to send a SetPageBottomMargin event when we truly affect the margin
local should_signal = false
-- only case that we don't need a UI update is enable/disable
@ -976,7 +975,6 @@ function ReaderFooter:addToMainMenu(menu_items)
self.mode_index[i] = sort_item.item_table[i].label
end
self.settings.order = self.mode_index
G_reader_settings:saveSetting("footer", self.settings)
self:updateFooterTextGenerator()
self:onUpdateFooter()
UIManager:setDirty(nil, "ui")
@ -994,7 +992,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings.auto_refresh_time = not self.settings.auto_refresh_time
G_reader_settings:saveSetting("footer", self.settings)
self:rescheduleFooterAutoRefreshIfNeeded()
end
},
@ -1035,7 +1032,6 @@ function ReaderFooter:addToMainMenu(menu_items)
end,
callback = function()
self.settings.skim_widget_on_hold = not self.settings.skim_widget_on_hold
G_reader_settings:saveSetting("footer", self.settings)
end,
},
{
@ -1857,7 +1853,7 @@ function ReaderFooter:getAvgTimePerPage()
end
function ReaderFooter:getDataFromStatistics(title, pages)
local sec = "N/A"
local sec = _("N/A")
local average_time_per_page = self:getAvgTimePerPage()
if average_time_per_page then
if self.settings.duration_format == "classic" then
@ -2065,9 +2061,9 @@ end
function ReaderFooter:onReadSettings(config)
if not self.ui.document.info.has_pages then
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
self.book_margins_footer_width = math.floor((h_margins[1] + h_margins[2])/2)
end
end

+ 14
- 12
frontend/apps/reader/modules/readerhighlight.lua View File

@ -1175,13 +1175,13 @@ function ReaderHighlight:onCycleHighlightAction()
dictionary = "search",
search = nil,
}
local current_action = G_reader_settings:readSetting("default_highlight_action")
if not current_action then
if G_reader_settings:hasNot("default_highlight_action") then
G_reader_settings:saveSetting("default_highlight_action", "highlight")
UIManager:show(Notification:new{
text = _("Default highlight action changed to 'highlight'."),
})
else
local current_action = G_reader_settings:readSetting("default_highlight_action")
local next_action = next_actions[current_action]
G_reader_settings:saveSetting("default_highlight_action", next_action)
UIManager:show(Notification:new{
@ -1446,23 +1446,25 @@ end
function ReaderHighlight:onReadSettings(config)
self.view.highlight.saved_drawer = config:readSetting("highlight_drawer") or self.view.highlight.saved_drawer
local disable_highlight = config:readSetting("highlight_disabled")
if disable_highlight == nil then
disable_highlight = G_reader_settings:readSetting("highlight_disabled") or false
if config:has("highlight_disabled") then
self.view.highlight.disabled = config:isTrue("highlight_disabled")
else
self.view.highlight.disabled = G_reader_settings:isTrue("highlight_disabled")
end
self.view.highlight.disabled = disable_highlight
-- panel zoom settings isn't supported in EPUB
if self.document.info.has_pages then
local ext = util.getFileNameSuffix(self.ui.document.file)
G_reader_settings:initializeExtSettings("panel_zoom_enabled", {cbz = true, cbt = true})
G_reader_settings:initializeExtSettings("panel_zoom_fallback_to_text_selection", {pdf = true})
self.panel_zoom_enabled = config:readSetting("panel_zoom_enabled")
if self.panel_zoom_enabled == nil then
if config:has("panel_zoom_enabled") then
self.panel_zoom_enabled = config:isTrue("panel_zoom_enabled")
else
self.panel_zoom_enabled = G_reader_settings:getSettingForExt("panel_zoom_enabled", ext) or false
end
self.panel_zoom_fallback_to_text_selection = config:readSetting("panel_zoom_fallback_to_text_selection")
if self.panel_zoom_fallback_to_text_selection == nil then
if config:has("panel_zoom_fallback_to_text_selection") then
self.panel_zoom_fallback_to_text_selection = config:isTrue("panel_zoom_fallback_to_text_selection")
else
self.panel_zoom_fallback_to_text_selection = G_reader_settings:getSettingForExt("panel_zoom_fallback_to_text_selection", ext) or false
end
end
@ -1493,13 +1495,13 @@ function ReaderHighlight:toggleDefault()
return highlight_disabled and _("Disable (★)") or _("Disable")
end,
choice1_callback = function()
G_reader_settings:saveSetting("highlight_disabled", true)
G_reader_settings:makeTrue("highlight_disabled")
end,
choice2_text_func = function()
return highlight_disabled and _("Enable") or _("Enable (★)")
end,
choice2_callback = function()
G_reader_settings:saveSetting("highlight_disabled", false)
G_reader_settings:makeFalse("highlight_disabled")
end,
})
end

+ 7
- 5
frontend/apps/reader/modules/readerkoptlistener.lua View File

@ -16,15 +16,17 @@ end
function ReaderKoptListener:onReadSettings(config)
-- normal zoom mode is zoom mode used in non-reflow mode.
local normal_zoom_mode = config:readSetting("normal_zoom_mode") or
G_reader_settings:readSetting("zoom_mode") or "page"
local normal_zoom_mode = config:readSetting("normal_zoom_mode")
or G_reader_settings:readSetting("zoom_mode")
or "page"
normal_zoom_mode = util.arrayContains(ReaderZooming.available_zoom_modes, normal_zoom_mode)
and normal_zoom_mode
and normal_zoom_mode
or "page"
self.normal_zoom_mode = normal_zoom_mode
self:setZoomMode(normal_zoom_mode)
self.document.configurable.contrast = config:readSetting("kopt_contrast") or
G_reader_settings:readSetting("kopt_contrast") or 1.0
self.document.configurable.contrast = config:readSetting("kopt_contrast")
or G_reader_settings:readSetting("kopt_contrast")
or 1.0
self.ui:handleEvent(Event:new("GammaUpdate", 1/self.document.configurable.contrast))
-- since K2pdfopt v2.21 negative value of word spacing is also used, for config
-- compatability we should manually change previous -1 to a more reasonable -0.2

+ 1
- 1
frontend/apps/reader/modules/readerlink.lua View File

@ -326,7 +326,7 @@ The recommended value is -2.]]),
end
return spin_widget
end
local show_absolute_font_size_widget = G_reader_settings:readSetting("footnote_popup_absolute_font_size") ~= nil
local show_absolute_font_size_widget = G_reader_settings:has("footnote_popup_absolute_font_size")
spin_widget = get_font_size_widget(show_absolute_font_size_widget)
UIManager:show(spin_widget)
end,

+ 8
- 7
frontend/apps/reader/modules/readermenu.lua View File

@ -71,8 +71,9 @@ function ReaderMenu:init()
end
end
end
self.activation_menu = G_reader_settings:readSetting("activate_menu")
if self.activation_menu == nil then
if G_reader_settings:has("activate_menu") then
self.activation_menu = G_reader_settings:readSetting("activate_menu")
else
self.activation_menu = "swipe_tap"
end
end
@ -190,16 +191,16 @@ function ReaderMenu:setUpdateItemTable()
text = _("Exclude this book's cover from screensaver"),
enabled_func = function()
return not (self.ui == nil or self.ui.document == nil)
and G_reader_settings:readSetting('screensaver_type';) == "cover"
and G_reader_settings:readSetting("screensaver_type";) == "cover"
end,
checked_func = function()
return self.ui and self.ui.doc_settings and self.ui.doc_settings:readSetting("exclude_screensaver") == true
return self.ui and self.ui.doc_settings and self.ui.doc_settings:isTrue("exclude_screensaver")
end,
callback = function()
if Screensaver:excluded() then
self.ui.doc_settings:saveSetting("exclude_screensaver", false)
if Screensaver:isExcluded() then
self.ui.doc_settings:makeFalse("exclude_screensaver")
else
self.ui.doc_settings:saveSetting("exclude_screensaver", true)
self.ui.doc_settings:makeTrue("exclude_screensaver")
end
self.ui:saveSettings()
end,

+ 13
- 11
frontend/apps/reader/modules/readerpagemap.lua View File

@ -88,18 +88,20 @@ function ReaderPageMap:resetLayout()
end
function ReaderPageMap:onReadSettings(config)
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
self.max_left_label_width = Screen:scaleBySize(h_margins[1])
self.max_right_label_width = Screen:scaleBySize(h_margins[2])
self.show_page_labels = config:readSetting("pagemap_show_page_labels")
if self.show_page_labels == nil then
if config:has("pagemap_show_page_labels") then
self.show_page_labels = config:isTrue("pagemap_show_page_labels")
else
self.show_page_labels = G_reader_settings:nilOrTrue("pagemap_show_page_labels")
end
self.use_page_labels = config:readSetting("pagemap_use_page_labels")
if self.use_page_labels == nil then
if config:has("pagemap_use_page_labels") then
self.use_page_labels = config:isTrue("pagemap_use_page_labels")
else
self.use_page_labels = G_reader_settings:isTrue("pagemap_use_page_labels")
end
end
@ -352,14 +354,14 @@ function ReaderPageMap:addToMainMenu(menu_items)
return use_page_labels and _("Renderer") or _("Renderer (★)")
end,
choice1_callback = function()
G_reader_settings:saveSetting("pagemap_use_page_labels", false)
G_reader_settings:makeFalse("pagemap_use_page_labels")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return use_page_labels and _("Reference (★)") or _("Reference")
end,
choice2_callback = function()
G_reader_settings:saveSetting("pagemap_use_page_labels", true)
G_reader_settings:makeTrue("pagemap_use_page_labels")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
@ -385,14 +387,14 @@ function ReaderPageMap:addToMainMenu(menu_items)
return show_page_labels and _("Hide") or _("Hide (★)")
end,
choice1_callback = function()
G_reader_settings:saveSetting("pagemap_show_page_labels", false)
G_reader_settings:makeFalse("pagemap_show_page_labels")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return show_page_labels and _("Show (★)") or _("Show")
end,
choice2_callback = function()
G_reader_settings:saveSetting("pagemap_show_page_labels", true)
G_reader_settings:makeTrue("pagemap_show_page_labels")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})

+ 9
- 7
frontend/apps/reader/modules/readerpaging.lua View File

@ -184,14 +184,16 @@ end
function ReaderPaging:onReadSettings(config)
self.page_positions = config:readSetting("page_positions") or {}
self:_gotoPage(config:readSetting("last_page") or 1)
self.show_overlap_enable = config:readSetting("show_overlap_enable")
if self.show_overlap_enable == nil then
if config:has("show_overlap_enable") then
self.show_overlap_enable = config:isTrue("show_overlap_enable")
else
self.show_overlap_enable = DSHOWOVERLAP
end
self.flipping_zoom_mode = config:readSetting("flipping_zoom_mode") or "page"
self.flipping_scroll_mode = config:readSetting("flipping_scroll_mode") or false
self.inverse_reading_order = config:readSetting("inverse_reading_order")
if self.inverse_reading_order == nil then
self.flipping_scroll_mode = config:isTrue("flipping_scroll_mode")
if config:has("inverse_reading_order") then
self.inverse_reading_order = config:isTrue("inverse_reading_order")
else
self.inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
end
for _, v in ipairs(ReaderZooming.zoom_pan_settings) do
@ -266,14 +268,14 @@ function ReaderPaging:addToMainMenu(menu_items)
return inverse_reading_order and _("LTR") or _("LTR (★)")
end,
choice1_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", false)
G_reader_settings:makeFalse("inverse_reading_order")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return inverse_reading_order and _("RTL (★)") or _("RTL")
end,
choice2_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", true)
G_reader_settings:makeTrue("inverse_reading_order")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})

+ 27
- 19
frontend/apps/reader/modules/readerrolling.lua View File

@ -139,9 +139,9 @@ function ReaderRolling:onReadSettings(config)
-- and highlights with old XPATHs.
-- (EPUB will use the same correct DOM code no matter what DOM version
-- we request here.)
if not config:readSetting("cre_dom_version") then
if config:hasNot("cre_dom_version") then
-- Not previously set, guess which DOM version to use
if config:readSetting("last_xpointer") then
if config:has("last_xpointer") then
-- We have a last_xpointer: this book was previously opened
-- with possibly a very old version: request the oldest
config:saveSetting("cre_dom_version", self.ui.document:getOldestDomVersion())
@ -166,7 +166,7 @@ function ReaderRolling:onReadSettings(config)
self.ui.typeset:ensureSanerBlockRenderingFlags()
-- And check if we can migrate to a newest DOM version after
-- the book is loaded (unless the user told us not to).
if not config:readSetting("cre_keep_old_dom_version") then
if config:nilOrFalse("cre_keep_old_dom_version") then
self.ui:registerPostReadyCallback(function()
self:checkXPointersAndProposeDOMVersionUpgrade()
end)
@ -209,13 +209,15 @@ function ReaderRolling:onReadSettings(config)
end
end
end
self.show_overlap_enable = config:readSetting("show_overlap_enable")
if self.show_overlap_enable == nil then
if config:has("show_overlap_enable") then
self.show_overlap_enable = config:isTrue("show_overlap_enable")
else
self.show_overlap_enable = DSHOWOVERLAP
end
self.inverse_reading_order = config:readSetting("inverse_reading_order")
if self.inverse_reading_order == nil then
if config:has("inverse_reading_order") then
self.inverse_reading_order = config:isTrue("inverse_reading_order")
else
self.inverse_reading_order = G_reader_settings:isTrue("inverse_reading_order")
end
@ -229,8 +231,9 @@ function ReaderRolling:onReadSettings(config)
G_reader_settings:readSetting("copt_visible_pages") or 1
self.ui.document:setVisiblePageCount(self.visible_pages)
self.hide_nonlinear_flows = config:readSetting("hide_nonlinear_flows")
if self.hide_nonlinear_flows == nil then
if config:has("hide_nonlinear_flows") then
self.hide_nonlinear_flows = config:isTrue("hide_nonlinear_flows")
else
self.hide_nonlinear_flows = G_reader_settings:isTrue("hide_nonlinear_flows")
end
self.ui.document:setHideNonlinearFlows(self.hide_nonlinear_flows)
@ -296,7 +299,7 @@ end
function ReaderRolling:onSaveSettings()
-- remove last_percent config since its deprecated
self.ui.doc_settings:saveSetting("last_percent", nil)
self.ui.doc_settings:delSetting("last_percent")
self.ui.doc_settings:saveSetting("last_xpointer", self.xpointer)
-- in scrolling mode, the document may already be closed,
-- so we have to check the condition to avoid crash function self:getLastPercent()
@ -395,14 +398,14 @@ function ReaderRolling:addToMainMenu(menu_items)
return inverse_reading_order and _("LTR") or _("LTR (★)")
end,
choice1_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", false)
G_reader_settings:makeFalse("inverse_reading_order")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
choice2_text_func = function()
return inverse_reading_order and _("RTL (★)") or _("RTL")
end,
choice2_callback = function()
G_reader_settings:saveSetting("inverse_reading_order", true)
G_reader_settings:makeTrue("inverse_reading_order")
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
@ -644,8 +647,10 @@ function ReaderRolling:onGotoXPointer(xp, marker_xp)
-- followed_link_marker = true: maker shown and not auto removed
-- followed_link_marker = <number>: removed after <number> seconds
-- (no real need for a menu item, the default is the finest)
local marker_setting = G_reader_settings:readSetting("followed_link_marker")
if marker_setting == nil then
local marker_setting
if G_reader_settings:has("followed_link_marker") then
marker_setting = G_reader_settings:readSetting("followed_link_marker")
else
marker_setting = 1 -- default is: shown and removed after 1 second
end
@ -1279,11 +1284,14 @@ function ReaderRolling:checkXPointersAndProposeDOMVersionUpgrade()
-- Switch to default block rendering mode if this book has it set to "legacy",
-- unless the user had set the global mode to be "legacy".
-- (see ReaderTypeset:onReadSettings() for the logic of block_rendering_mode)
local g_block_rendering_mode = G_reader_settings:readSetting("copt_block_rendering_mode")
local g_block_rendering_mode
if G_reader_settings:has("copt_block_rendering_mode") then
g_block_rendering_mode = G_reader_settings:readSetting("copt_block_rendering_mode")
else
-- nil means: use default
g_block_rendering_mode = 3 -- default in ReaderTypeset:onReadSettings()
end
if g_block_rendering_mode ~= 0 then -- default is not "legacy"
if not g_block_rendering_mode then -- nil means: use default
g_block_rendering_mode = 3 -- default in ReaderTypeset:onReadSettings()
end
-- This setting is actually saved by self.ui.document.configurable
local block_rendering_mode = self.ui.document.configurable.block_rendering_mode
if block_rendering_mode == 0 then
@ -1343,7 +1351,7 @@ Note that %1 (out of %2) xpaths from your bookmarks and highlights have been nor
}},
cancel_text = _("Not for this book"),
cancel_callback = function()
self.ui.doc_settings:saveSetting("cre_keep_old_dom_version", true)
self.ui.doc_settings:makeTrue("cre_keep_old_dom_version")
end,
ok_text = _("Upgrade now"),
ok_callback = function()

+ 2
- 2
frontend/apps/reader/modules/readerstyletweak.lua View File

@ -327,7 +327,7 @@ function ReaderStyleTweak:updateCssText(apply)
end
function ReaderStyleTweak:onReadSettings(config)
self.enabled = not (config:readSetting("style_tweaks_enabled") == false)
self.enabled = config:nilOrTrue("style_tweaks_enabled")
self.doc_tweaks = config:readSetting("style_tweaks") or {}
-- Default globally enabled style tweaks (for new installations)
-- are defined in css_tweaks.lua
@ -342,7 +342,7 @@ function ReaderStyleTweak:onSaveSettings()
if self.enabled then
self.ui.doc_settings:delSetting("style_tweaks_enabled")
else
self.ui.doc_settings:saveSetting("style_tweaks_enabled", false)
self.ui.doc_settings:makeFalse("style_tweaks_enabled")
end
self.ui.doc_settings:saveSetting("style_tweaks", util.tableSize(self.doc_tweaks) > 0 and self.doc_tweaks or nil)
G_reader_settings:saveSetting("style_tweaks", self.global_tweaks)

+ 4
- 4
frontend/apps/reader/modules/readertoc.lua View File

@ -41,12 +41,12 @@ function ReaderToc:init()
}
end
if not G_reader_settings:readSetting("toc_items_per_page") then
if G_reader_settings:hasNot("toc_items_per_page") then
-- The TOC items per page and items' font size can now be
-- configured. Previously, the ones set for the file browser
-- were used. Initialize them from these ones.
local items_per_page = G_reader_settings:readSetting("items_per_page")
or self.toc_items_per_page_default
or self.toc_items_per_page_default
G_reader_settings:saveSetting("toc_items_per_page", items_per_page)
local items_font_size = G_reader_settings:readSetting("items_font_size")
if items_font_size and items_font_size ~= Menu.getItemFontSize(items_per_page) then
@ -137,7 +137,7 @@ end
function ReaderToc:fillToc()
if self.toc then return end
if self.ui.document:canHaveAlternativeToc() then
if self.ui.doc_settings:readSetting("alternative_toc") then
if self.ui.doc_settings:isTrue("alternative_toc") then
-- (if the document has a cache, the previously built alternative
-- TOC was saved and has been reloaded, and this will be avoided)
if not self.ui.document:isTocAlternativeToc() then
@ -900,7 +900,7 @@ See Style tweaks → Miscellaneous → Alternative ToC hints.]]),
self:resetToc()
self.toc_ticks_ignored_levels = {} -- reset this
self.ui.document:buildAlternativeToc()
self.ui.doc_settings:saveSetting("alternative_toc", true)
self.ui.doc_settings:makeTrue("alternative_toc")
self:onShowToc()
self.view.footer:setTocMarkers(true)
self.view.footer:onUpdateFooter()

+ 41
- 33
frontend/apps/reader/modules/readertypeset.lua View File

@ -22,13 +22,15 @@ function ReaderTypeset:init()
end
function ReaderTypeset:onReadSettings(config)
self.css = config:readSetting("css") or G_reader_settings:readSetting("copt_css")
or self.ui.document.default_css
self.css = config:readSetting("css")
or G_reader_settings:readSetting("copt_css")
or self.ui.document.default_css
local tweaks_css = self.ui.styletweak:getCssText()
self.ui.document:setStyleSheet(self.css, tweaks_css)
self.embedded_fonts = config:readSetting("embedded_fonts")
if self.embedded_fonts == nil then
if config:has("embedded_fonts") then
self.embedded_fonts = config:isTrue("embedded_fonts")
else
-- default to enable embedded fonts
-- note that it's a bit confusing here:
-- global settins store 0/1, while document settings store false/true
@ -42,11 +44,12 @@ function ReaderTypeset:onReadSettings(config)
self.ui.document:setEmbeddedFonts(0)
end
self.embedded_css = config:readSetting("embedded_css")
if self.embedded_css == nil then
if config:has("embedded_css") then
self.embedded_css = config:isTrue("embedded_css")
else
-- default to enable embedded CSS
-- note that it's a bit confusing here:
-- global settins store 0/1, while document settings store false/true
-- global settings store 0/1, while document settings store false/true
-- we leave it that way for now to maintain backwards compatibility
local global = G_reader_settings:readSetting("copt_embedded_css")
self.embedded_css = (global == nil or global == 1) and true or false
@ -56,15 +59,15 @@ function ReaderTypeset:onReadSettings(config)
-- Block rendering mode: stay with legacy rendering for books
-- previously opened so bookmarks and highlights stay valid.
-- For new books, use 'web' mode below in BLOCK_RENDERING_FLAGS
local block_rendering_default_mode = 3
self.block_rendering_mode = config:readSetting("copt_block_rendering_mode")
if not self.block_rendering_modespan> then
if config:readSetting("last_xpointer") then
if config:has("copt_block_rendering_mode") then
self.block_rendering_mode = config:readSetting("copt_block_rendering_mode")
else
if config:has("last_xpointer") then
-- We have a last_xpointer: this book was previously opened
self.block_rendering_mode = 0
else
self.block_rendering_mode = G_reader_settings:readSetting("copt_block_rendering_mode")
or block_rendering_default_mode
or 3 -- default to 'web' mode
end
-- Let ConfigDialog know so it can update it on screen and have it saved on quit
self.ui.document.configurable.block_rendering_mode = self.block_rendering_mode
@ -72,47 +75,52 @@ function ReaderTypeset:onReadSettings(config)
self:setBlockRenderingMode(self.block_rendering_mode)
-- set render DPI
self.render_dpi = config:readSetting("render_dpi") or
G_reader_settings:readSetting("copt_render_dpi") or 96
self.render_dpi = config:readSetting("render_dpi")
or G_reader_settings:readSetting("copt_render_dpi")
or 96
self:setRenderDPI(self.render_dpi)
-- uncomment if we want font size to follow DPI changes
-- self.ui.document:setRenderScaleFontWithDPI(1)
-- set page margins
local h_margins = config:readSetting("copt_h_page_margins") or
G_reader_settings:readSetting("copt_h_page_margins") or
DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin") or
G_reader_settings:readSetting("copt_t_page_margin") or
DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin") or
G_reader_settings:readSetting("copt_b_page_margin") or
DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
local h_margins = config:readSetting("copt_h_page_margins")
or G_reader_settings:readSetting("copt_h_page_margins")
or DCREREADER_CONFIG_H_MARGIN_SIZES_MEDIUM
local t_margin = config:readSetting("copt_t_page_margin")
or G_reader_settings:readSetting("copt_t_page_margin")
or DCREREADER_CONFIG_T_MARGIN_SIZES_LARGE
local b_margin = config:readSetting("copt_b_page_margin")
or G_reader_settings:readSetting("copt_b_page_margin")
or DCREREADER_CONFIG_B_MARGIN_SIZES_LARGE
self.unscaled_margins = { h_margins[1], t_margin, h_margins[2], b_margin }
self:onSetPageMargins(self.unscaled_margins)
self.sync_t_b_page_margins = config:readSetting("copt_sync_t_b_page_margins") or
G_reader_settings:readSetting("copt_sync_t_b_page_margins") or 0
self.sync_t_b_page_margins = config:readSetting("copt_sync_t_b_page_margins")
or G_reader_settings:readSetting("copt_sync_t_b_page_margins")
or 0
self.sync_t_b_page_margins = self.sync_t_b_page_margins == 1 and true or false
-- default to disable TXT formatting as it does more harm than good
self.txt_preformatted = config:readSetting("txt_preformatted") or
G_reader_settings:readSetting("txt_preformatted") or 1
self.txt_preformatted = config:readSetting("txt_preformatted")
or G_reader_settings:readSetting("txt_preformatted")
or 1
self:toggleTxtPreFormatted(self.txt_preformatted)
-- default to disable smooth scaling for now.
self.smooth_scaling = config:readSetting("smooth_scaling")
if self.smooth_scaling == nil then
if config:has("smooth_scaling") then
self.smooth_scaling = config:isTrue("smooth_scaling")
else
local global = G_reader_settings:readSetting("copt_smooth_scaling")
self.smooth_scaling = (global == nil or global == 0) and 0 or 1
self.smooth_scaling = (global == nil or global == 0) and false or true
end
self:toggleImageScaling(self.smooth_scaling)
-- default to automagic nightmode-friendly handling of images
self.nightmode_images = config:readSetting("nightmode_images")
if self.nightmode_images == nil then
if config:has("nightmode_images") then
self.nightmode_images = config:isTrue("nightmode_images")
else
local global = G_reader_settings:readSetting("copt_nightmode_images")
self.nightmode_images = (global == nil or global == 1) and 1 or 0
self.nightmode_images = (global == nil or global == 1) and true or false
end
self:toggleNightmodeImages(self.nightmode_images)
end

+ 58
- 57
frontend/apps/reader/modules/readertypography.lua View File

@ -126,7 +126,7 @@ function ReaderTypography:init()
-- Migrate old readerhyphenation settings (but keep them in case one
-- go back to a previous version)
if not G_reader_settings:readSetting("text_lang_default") and not G_reader_settings:readSetting("text_lang_fallback") then
if G_reader_settings:hasNot("text_lang_default") and G_reader_settings:hasNot("text_lang_fallback") then
local g_text_lang_set = false
local hyph_alg_default = G_reader_settings:readSetting("hyph_alg_default")
if hyph_alg_default then
@ -137,11 +137,11 @@ function ReaderTypography:init()
-- Tweak the other settings if the default hyph algo happens
-- to be one of these:
if hyph_alg_default == "@none" then
G_reader_settings:saveSetting("hyphenation", false)
G_reader_settings:makeFalse("hyphenation")
elseif hyph_alg_default == "@softhyphens" then
G_reader_settings:saveSetting("hyph_soft_hyphens_only", true)
G_reader_settings:makeTrue("hyph_soft_hyphens_only")
elseif hyph_alg_default == "@algorithm" then
G_reader_settings:saveSetting("hyph_force_algorithmic", true)
G_reader_settings:makeTrue("hyph_force_algorithmic")
end
end
end
@ -328,13 +328,13 @@ When the book's language tag is not among our presets, no specific features will
return text_lang_embedded_langs and _("Ignore") or _("Ignore (★)")
end,
choice1_callback = function()
G_reader_settings:saveSetting("text_lang_embedded_langs", false)
G_reader_settings:makeFalse("text_lang_embedded_langs")
end,
choice2_text_func = function()
return text_lang_embedded_langs and _("Respect (★)") or _("Respect")
end,
choice2_callback = function()
G_reader_settings:saveSetting("text_lang_embedded_langs", true)