From 7ccb9488339211a7c47adb1660392591b7ba5034 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 10:37:38 +0200 Subject: [PATCH 1/8] Add default value --- frontend/ui/widget/virtualkeyboard.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index c030fa517..617eedf12 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -107,7 +107,7 @@ local VirtualKeyboard = InputContainer:new{ inputbox = nil, KEYS = {}, -- table to store layouts min_layout = 2, - max_layout = 13, + max_layout = 12, layout = 2, shiftmode = false, symbolmode = false, @@ -187,6 +187,11 @@ function VirtualKeyboard:init() } } self:initLayout(self.layout) + if GLOBAL_INPUT_VALUE then + for i = 1, string.len(GLOBAL_INPUT_VALUE) do + self:addChar(string.sub(GLOBAL_INPUT_VALUE,i,i)) + end + end end function VirtualKeyboard:initLayout(layout) From eada89002d1f78d947e020a48f1197e237d2a7d5 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 10:38:17 +0200 Subject: [PATCH 2/8] Remove Search Options (will be part of edit defaults) --- frontend/ui/device/screen.lua | 48 ----------------------------------- 1 file changed, 48 deletions(-) diff --git a/frontend/ui/device/screen.lua b/frontend/ui/device/screen.lua index c919fc0fe..4fa11d37e 100644 --- a/frontend/ui/device/screen.lua +++ b/frontend/ui/device/screen.lua @@ -307,53 +307,5 @@ function Screen:getDPIMenuTable() } end -function Screen:SearchOptions() - return { - text = _("Search options"), - sub_item_table = { - { - text = _("Case sensitive"), - checked_func = function() - local search_option = SEARCH_CASESENSITIVE - return search_option - end, - callback = function() SEARCH_CASESENSITIVE = not SEARCH_CASESENSITIVE end - }, - { - text = _("Search title"), - checked_func = function() - local search_option = SEARCH_TITLE - return search_option - end, - callback = function() SEARCH_TITLE = not SEARCH_TITLE end - }, - { - text = _("Search tags"), - checked_func = function() - local search_option = SEARCH_TAGS - return search_option - end, - callback = function() SEARCH_TAGS = not SEARCH_TAGS end - }, - { - text = _("Search series"), - checked_func = function() - local search_option = SEARCH_SERIES - return search_option - end, - callback = function() SEARCH_SERIES = not SEARCH_SERIES end - }, - { - text = _("Search path"), - checked_func = function() - local search_option = SEARCH_PATH - return search_option - end, - callback = function() SEARCH_PATH = not SEARCH_PATH end - }, - } - } -end - return Screen From 08809240873c5c47fa31a87d86bd5de8127ae3d1 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 10:39:08 +0200 Subject: [PATCH 3/8] Add defaults and remove search options --- frontend/apps/filemanager/filemanagermenu.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index 859a9994e..feba3064b 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -13,6 +13,7 @@ local Language = require("ui/language") local _ = require("gettext") local ReaderFrontLight = require("apps/reader/modules/readerfrontlight") local Search = require("apps/filemanager/filemanagersearch") +local SetDefaults = require("apps/filemanager/filemanagersetdefaults") local FileManagerMenu = InputContainer:extend{ tab_item_table = nil, @@ -73,6 +74,7 @@ function FileManagerMenu:setUpdateItemTable() self.ui:toggleHiddenFiles() end }) + table.insert(self.tab_item_table.setting, { text = _("Start with last opened file"), checked_func = function() return G_reader_settings:readSetting("open_last") end, @@ -102,7 +104,18 @@ function FileManagerMenu:setUpdateItemTable() end }) table.insert(self.tab_item_table.setting, Language:getLangMenuTable()) - + table.insert(self.tab_item_table.setting, { + text = _("Default settings"), + callback = function() + SetDefaults:ConfirmEdit() + end + }) + table.insert(self.tab_item_table.setting, { + text = _("Save default settings"), + callback = function() + SetDefaults:ConfirmSave() + end + }) -- info tab if Device:isKindle() or Device:isKobo() then table.insert(self.tab_item_table.info, OTAManager:getOTAMenuTable()) @@ -129,7 +142,6 @@ function FileManagerMenu:setUpdateItemTable() Search:init() end }) - table.insert(self.tab_item_table.info, Screen:SearchOptions()) end function FileManagerMenu:onShowMenu() From 9830119405fc92e6ddc682260b145961fa8a2c03 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 10:39:49 +0200 Subject: [PATCH 4/8] Add defaults editor --- .../filemanager/filemanagesetdefaults.lua | 253 ++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 frontend/apps/filemanager/filemanagesetdefaults.lua diff --git a/frontend/apps/filemanager/filemanagesetdefaults.lua b/frontend/apps/filemanager/filemanagesetdefaults.lua new file mode 100644 index 000000000..89fff824f --- /dev/null +++ b/frontend/apps/filemanager/filemanagesetdefaults.lua @@ -0,0 +1,253 @@ +local InfoMessage = require("ui/widget/infomessage") +local UIManager = require("ui/uimanager") +local _ = require("gettext") +local InputContainer = require("ui/widget/container/inputcontainer") +local InputDialog = require("ui/widget/inputdialog") +local ConfirmBox = require("ui/widget/confirmbox") +local CenterContainer = require("ui/widget/container/centercontainer") +local Screen = require("ui/screen") +local Menu = require("ui/widget/menu") + +local SetDefaults = InputContainer:new{ + bools_name = {}, + bools_value = {}, + results = {}, + defaults_menu = {}, +} + +local function settype(b,t) + if t == "boolean" then + if b == "false" then return false else return true end + else + return b + end +end + +local function __genOrderedIndex( t ) +-- this function is taken from http://lua-users.org/wiki/SortedIteration + local orderedIndex = {} + for key in pairs(t) do + table.insert( orderedIndex, key ) + end + table.sort( orderedIndex ) + return orderedIndex +end + +local function orderedNext(t, state) +-- this function is taken from http://lua-users.org/wiki/SortedIteration + + -- Equivalent of the next function, but returns the keys in the alphabetic + -- order. We use a temporary ordered key table that is stored in the + -- table being iterated. + + if state == nil then + -- the first time, generate the index + t.__orderedIndex = __genOrderedIndex( t ) + key = t.__orderedIndex[1] + return key, t[key] + end + -- fetch the next value + key = nil + for i = 1,table.getn(t.__orderedIndex) do + if t.__orderedIndex[i] == state then + key = t.__orderedIndex[i+1] + end + end + + if key then + return key, t[key] + end + + -- no more value to return, cleanup + t.__orderedIndex = nil + return +end + +local function orderedPairs(t) +-- this function is taken from http://lua-users.org/wiki/SortedIteration + -- Equivalent of the pairs() function on tables. Allows to iterate + -- in order + return orderedNext, t, nil +end + +function SetDefaults:ConfirmEdit() + UIManager:show(ConfirmBox:new{ + text = _("Wrong settings might crash Koreader! Continue?"), + ok_callback = function() + self:init() + end, + }) +end + +function SetDefaults:init() + self.bools_name = {} + self.bools_value = {} + self.results = {} + + self.fillbools() + + local menu_container = CenterContainer:new{ + dimen = Screen:getSize(), + } + + self.defaults_menu = Menu:new{ + width = Screen:getWidth()-50, + height = Screen:getHeight()-50, + show_parent = menu_container, + _manager = self, + } + table.insert(menu_container, self.defaults_menu) + self.defaults_menu.close_callback = function() + UIManager:close(menu_container) + end + + for i=1,#self.bools_name do + local dummy = self.bools_name[i] .. " = " + if type(_G[self.bools_name[i]]) == "string" and not tonumber(self.bools_value[i]) then + dummy = dummy .. "\"" .. tostring(self.bools_value[i]) .. "\"" -- add quotation marks to strings + else + dummy = dummy .. tostring(self.bools_value[i]) + end + table.insert(self.results, { + text = dummy, + callback = function() + + GLOBAL_INPUT_VALUE = tostring(self.bools_value[i]) + self.set_dialog = InputDialog:new{ + title = self.bools_name[i] .. ":", + buttons = { + { + { + text = _("Ok"), + enabled = true, + callback = function() + _G[self.bools_name[i]] = settype(self.set_dialog:getInputText(),type(_G[self.bools_name[i]])) + self:close() + end, + }, + { + text = _("cancel"), + enabled = true, + callback = function() + self:close() + end, + }, + }, + }, + width = Screen:getWidth() * 0.95, + height = Screen:getHeight() * 0.2, + } + GLOBAL_INPUT_VALUE = nil + self.set_dialog:onShowKeyboard() + UIManager:show(self.set_dialog) + end + }) + end + self.defaults_menu:swithItemTable("Defaults", self.results) + UIManager:show(menu_container) +end + +function SetDefaults:fillbools() + local i = 0 + for n,v in orderedPairs(_G) do + if (not string.find(tostring(v), "<")) and (not string.find(tostring(v), ": ")) and string.sub(n,1,1) ~= "_" and string.upper(n) == n and n ~= "GLOBAL_INPUT_VALUE" then + i = i + 1 + SetDefaults.bools_name[i] = n + SetDefaults.bools_value[i] = v + end + end +end + +function SetDefaults:close() + self.set_dialog:onClose() + UIManager:close(self.set_dialog) +end + +function SetDefaults:ConfirmSave() + UIManager:show(ConfirmBox:new{ + text = _("Are you sure to save the settings to \"defaults.persistent.lua\"?"), + ok_callback = function() + self:SaveSettings() + end, + }) +end + +function SetDefaults:SaveSettings() + + local function fileread(filename,array) + local file = io.open(filename) + local line = file:read() + local counter = 0 + while line do + counter = counter + 1 + local i = string.find(line,"[-][-]") -- remove comments from file + if (i or 0)>1 then line = string.sub(line,1,i-1) end + array[counter] = line:gsub("^%s*(.-)%s*$", "%1") -- trim + line = file:read() + end + file:close() + end + + local function build_setting(j) + local ret = SetDefaults.bools_name[j] .. " = " + if tonumber(SetDefaults.bools_value[j]) then + ret = ret .. tostring(tonumber(SetDefaults.bools_value[j])) + elseif type(_G[SetDefaults.bools_name[j]]) == "boolean" then + ret = ret .. tostring(SetDefaults.bools_value[j]) + else + ret = ret .. "\"" .. tostring(SetDefaults.bools_value[j]) .. "\"" + end + return ret + end + + local filename = "defaults.persistent.lua" + local file + if io.open(filename,"r") == nil then + file = io.open(filename, "w") + file:write("-- For configuration changes that persists between (nightly) releases\n") + file:close() + end + + local dpl = {} + fileread("defaults.persistent.lua",dpl) + local dl = {} + fileread("defaults.lua",dl) + self.bools = {} + self.results = {} + self.fillbools() + local done = {} + + -- handle case "found in persistent", replace it + for i = 1,#dpl do + for j=1,#SetDefaults.bools_name do + if string.find(dpl[i],SetDefaults.bools_name[j]) == 1 then + dpl[i] = build_setting(j) + done[j] = true + end + end + end + + -- handle case "exists identical in non-persistent", ignore it + for i = 1,#dl do + for j=1,#SetDefaults.bools_name do + if dl[i]:gsub("1024[*]1024[*]10","10485760"):gsub("1024[*]1024[*]30","31457280"):gsub("[.]0$",""):gsub("([.][0-9]+)0","%1") == build_setting(j) then + done[j] = true + end + end + end + + -- handle case "not in persistent and different in non-persistent", add to persistent + for j=1,#SetDefaults.bools_name do + if not done[j] then + dpl[#dpl+1] = build_setting(j) + end + end + + file = io.open("defaults.persistent.lua", "w") + for i = 1,#dpl do + file:write(dpl[i] .. "\n") + end + file:close() + UIManager:show(InfoMessage:new{text = _("Default settings successfully saved to \"defaults.persistent.lua\"!")}) +end +return SetDefaults From a0818bb1ab942c3b0584b96d5f287e862647941c Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 10:40:22 +0200 Subject: [PATCH 5/8] Update filemanagersearch.lua --- frontend/apps/filemanager/filemanagersearch.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/apps/filemanager/filemanagersearch.lua b/frontend/apps/filemanager/filemanagersearch.lua index d4c72811d..901965a3a 100644 --- a/frontend/apps/filemanager/filemanagersearch.lua +++ b/frontend/apps/filemanager/filemanagersearch.lua @@ -94,14 +94,14 @@ function Search:init() end if self.calibrefile ~= nil then - local dummy = "" - if SEARCH_CASESENSITIVE then - dummy = "case sensitive)" - else - dummy = "case insensitive)" + LIBRARY_PATH = string.gsub(self.calibrefile,"/[^/]*$","") + if string.sub(LIBRARY_PATH,string.len(LIBRARY_PATH)) ~= "/" then + LIBRARY_PATH = LIBRARY_PATH .. "/" end + + GLOBAL_INPUT_VALUE = self.search_value self.search_dialog = InputDialog:new{ - title = _("Search Books (" .. dummy), + title = _("Search Books"), buttons = { { { @@ -117,6 +117,7 @@ function Search:init() width = Screen:getWidth() * 0.8, height = Screen:getHeight() * 0.2, } + GLOBAL_INPUT_VALUE = nil self.search_dialog:onShowKeyboard() UIManager:show(self.search_dialog) else From 5a2b9103e967d01c8e60d46899911d7218b8919e Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 13:49:18 +0200 Subject: [PATCH 6/8] Update reader.lua --- reader.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reader.lua b/reader.lua index f0d48c46f..db9cebc0c 100755 --- a/reader.lua +++ b/reader.lua @@ -77,12 +77,12 @@ function showReaderUI(file, pass) DEBUG("opening file", file) if lfs.attributes(file, "mode") ~= "file" then UIManager:show(InfoMessage:new{ - text = _("File does not exist") + text = _("File ") .. file .. " does not exist") }) return end UIManager:show(InfoMessage:new{ - text = _("Opening file") .. file, + text = _("Opening file ") .. file, timeout = 1, }) UIManager:scheduleIn(0.1, function() doShowReaderUI(file, pass) end) From 2d72bb7e3fc557dd83abb7280b1a3357e1c211a3 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 14:03:22 +0200 Subject: [PATCH 7/8] Update reader.lua --- reader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reader.lua b/reader.lua index db9cebc0c..a1f239359 100755 --- a/reader.lua +++ b/reader.lua @@ -77,7 +77,7 @@ function showReaderUI(file, pass) DEBUG("opening file", file) if lfs.attributes(file, "mode") ~= "file" then UIManager:show(InfoMessage:new{ - text = _("File ") .. file .. " does not exist") + text = _("File ") .. file .. _(" does not exist") }) return end From bd596927dd18062e8ff6d4d9f9955a0e4e167301 Mon Sep 17 00:00:00 2001 From: WS64 Date: Mon, 11 Aug 2014 14:24:32 +0200 Subject: [PATCH 8/8] Corrected the filename --- .../{filemanagesetdefaults.lua => filemanagersetdefaults.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontend/apps/filemanager/{filemanagesetdefaults.lua => filemanagersetdefaults.lua} (100%) diff --git a/frontend/apps/filemanager/filemanagesetdefaults.lua b/frontend/apps/filemanager/filemanagersetdefaults.lua similarity index 100% rename from frontend/apps/filemanager/filemanagesetdefaults.lua rename to frontend/apps/filemanager/filemanagersetdefaults.lua