chore: fix all luacheck issues

pull/2245/head
Qingping Hou 8 years ago
parent 252100891f
commit d6c48b06f9

@ -6,6 +6,4 @@ source "${CI_DIR}/common.sh"
travis_retry make fetchthirdparty travis_retry make fetchthirdparty
make all make all
make testfront make testfront
set +o pipefail luajit $(which luacheck) --no-color -q frontend
luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out
test $(grep Total ./luacheck.out | awk '{print $2}') -le 17

@ -78,14 +78,14 @@ read_globals = {
"DDICT_FONT_SIZE", "DDICT_FONT_SIZE",
"FRONTLIGHT_SENSITIVITY_DECREASE", "FRONTLIGHT_SENSITIVITY_DECREASE",
"DALPHA_SORT_CASE_INSENSITIVE", "DALPHA_SORT_CASE_INSENSITIVE",
"SEARCH_LIBRARY_PATH",
"SEARCH_LIBRARY_PATH2",
"SEARCH_CASESENSITIVE", "SEARCH_CASESENSITIVE",
"SEARCH_AUTHORS", "SEARCH_AUTHORS",
"SEARCH_TITLE", "SEARCH_TITLE",
"SEARCH_TAGS", "SEARCH_TAGS",
"SEARCH_SERIES", "SEARCH_SERIES",
"SEARCH_PATH", "SEARCH_PATH",
"SEARCH_LIBRARY_PATH",
"SEARCH_LIBRARY_PATH2",
"KOBO_LIGHT_ON_START", "KOBO_LIGHT_ON_START",
"NETWORK_PROXY", "NETWORK_PROXY",
"DUSE_TURBO_LIB", "DUSE_TURBO_LIB",

@ -36,8 +36,8 @@ function FileManagerMenu:init()
home = { home = {
icon = "resources/icons/appbar.home.png", icon = "resources/icons/appbar.home.png",
callback = function() callback = function()
if settings_changed then if SetDefaults.settings_changed then
settings_changed = false SetDefaults.settings_changed = false
UIManager:show(ConfirmBox:new{ UIManager:show(ConfirmBox:new{
text = _("You have unsaved default settings. Save them now?"), text = _("You have unsaved default settings. Save them now?"),
ok_callback = function() ok_callback = function()

@ -12,6 +12,7 @@ local Font = require("ui/font")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local T = require("ffi/util").template local T = require("ffi/util").template
local _ = require("gettext") local _ = require("gettext")
local SetDefaults = require("apps/filemanager/filemanagersetdefaults")
local calibre = "metadata.calibre" local calibre = "metadata.calibre"
local koreaderfile = "temp/metadata.koreader" local koreaderfile = "temp/metadata.koreader"
@ -75,11 +76,11 @@ function Search:getCalibre()
if not self.metafile_1 then if not self.metafile_1 then
self.error = _("SEARCH_LIBRARY_PATH should be defined in DEFAULTS.LUA.") self.error = _("SEARCH_LIBRARY_PATH should be defined in DEFAULTS.LUA.")
else else
settings_changed = true SetDefaults.settings_changed = true
end end
else else
if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then if string.sub(SEARCH_LIBRARY_PATH,string.len(SEARCH_LIBRARY_PATH)) ~= "/" then
SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/" SEARCH_LIBRARY_PATH = SEARCH_LIBRARY_PATH .. "/" -- luacheck: ignore
end end
if io.open(SEARCH_LIBRARY_PATH .. calibre,"r") == nil then if io.open(SEARCH_LIBRARY_PATH .. calibre,"r") == nil then
if io.open(SEARCH_LIBRARY_PATH .. "." .. calibre,"r") == nil then if io.open(SEARCH_LIBRARY_PATH .. "." .. calibre,"r") == nil then
@ -98,7 +99,7 @@ function Search:getCalibre()
elseif self.metafile_1 == nil then elseif self.metafile_1 == nil then
self.metafile_1 = findcalibre("/mnt") self.metafile_1 = findcalibre("/mnt")
if self.metafile_1 then if self.metafile_1 then
settings_changed = true SetDefaults.settings_changed = true
end end
end end
end end
@ -106,7 +107,7 @@ function Search:getCalibre()
local dummy local dummy
if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then if string.sub(SEARCH_LIBRARY_PATH2,string.len(SEARCH_LIBRARY_PATH2)) ~= "/" then
SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/" SEARCH_LIBRARY_PATH2 = SEARCH_LIBRARY_PATH2 .. "/" -- luacheck: ignore
end end
if io.open(SEARCH_LIBRARY_PATH2 .. calibre,"r") == nil then if io.open(SEARCH_LIBRARY_PATH2 .. calibre,"r") == nil then
if io.open(SEARCH_LIBRARY_PATH2 .. "." .. calibre,"r") ~= nil then if io.open(SEARCH_LIBRARY_PATH2 .. "." .. calibre,"r") ~= nil then
@ -152,7 +153,7 @@ function Search:ShowSearch()
enabled = true, enabled = true,
callback = function() callback = function()
self.search_value = self.search_dialog:getInputText() self.search_value = self.search_dialog:getInputText()
if not settings_changed and self.search_value == dummy and self.lastsearch == "series" then if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "series" then
self.use_previous_search_results = true self.use_previous_search_results = true
else else
self.use_previous_search_results = false self.use_previous_search_results = false
@ -166,7 +167,7 @@ function Search:ShowSearch()
enabled = true, enabled = true,
callback = function() callback = function()
self.search_value = self.search_dialog:getInputText() self.search_value = self.search_dialog:getInputText()
if not settings_changed and self.search_value == dummy and self.lastsearch == "tags" then if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "tags" then
self.use_previous_search_results = true self.use_previous_search_results = true
else else
self.use_previous_search_results = false self.use_previous_search_results = false
@ -190,7 +191,7 @@ function Search:ShowSearch()
enabled = true, enabled = true,
callback = function() callback = function()
self.search_value = self.search_dialog:getInputText() self.search_value = self.search_dialog:getInputText()
if not settings_changed and self.search_value == dummy and self.lastsearch == "find" then if not SetDefaults.settings_changed and self.search_value == dummy and self.lastsearch == "find" then
self.use_previous_search_results = true self.use_previous_search_results = true
else else
self.use_previous_search_results = false self.use_previous_search_results = false
@ -235,7 +236,6 @@ function Search:find(option)
local line local line
local i = 1 local i = 1
local upsearch local upsearch
local dummy
local firstrun local firstrun
-- removes leading and closing characters and converts hex-unicodes -- removes leading and closing characters and converts hex-unicodes
@ -269,10 +269,10 @@ function Search:find(option)
if s == self.authors then if s == self.authors then
self.data[i][self.authors2] = self.data[i][self.authors2] .. " & " .. ReplaceHexChars(line,8,3) self.data[i][self.authors2] = self.data[i][self.authors2] .. " & " .. ReplaceHexChars(line,8,3)
elseif s == self.tags then elseif s == self.tags then
local dummy = ReplaceHexChars(line,8,3) local tags_line = ReplaceHexChars(line,8,3)
self.data[i][self.tags2] = self.data[i][self.tags2] .. " & " .. dummy self.data[i][self.tags2] = self.data[i][self.tags2] .. " & " .. tags_line
self.data[i][self.tags3] = self.data[i][self.tags3] .. "\t" .. dummy self.data[i][self.tags3] = self.data[i][self.tags3] .. "\t" .. tags_line
self.browse_tags[dummy] = (self.browse_tags[dummy] or 0) + 1 self.browse_tags[tags_line] = (self.browse_tags[tags_line] or 0) + 1
end end
end end
end end
@ -318,16 +318,24 @@ function Search:find(option)
line = g:read() line = g:read()
end end
local dummy = "" local search_content = ""
if option == "find" and SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end if option == "find" and SEARCH_AUTHORS then
if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end search_content = search_content .. self.data[i][self.authors] .. "\n"
if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end end
if option == "find" and SEARCH_TITLE then
search_content = search_content .. self.data[i][self.title] .. "\n"
end
if option == "find" and SEARCH_PATH then
search_content = search_content .. self.data[i][self.path] .. "\n"
end
if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then
dummy = dummy .. self.data[i][self.series] .. "\n" search_content = search_content .. self.data[i][self.series] .. "\n"
self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1 self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1
end end
if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end if option == "tags" or SEARCH_TAGS then
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end search_content = search_content .. self.data[i][self.tags] .. "\n"
end
if not SEARCH_CASESENSITIVE then search_content = string.upper(search_content) end
for j in string.gmatch(self.data[i][self.tags3],"\t[^\t]+") do for j in string.gmatch(self.data[i][self.tags3],"\t[^\t]+") do
if j~="\t" then if j~="\t" then
@ -336,7 +344,7 @@ function Search:find(option)
end end
if DocumentRegistry:getProvider(self.data[i][self.path]) then if DocumentRegistry:getProvider(self.data[i][self.path]) then
if upsearch ~= "" then if upsearch ~= "" then
if string.find(dummy,upsearch,nil,true) then if string.find(search_content,upsearch,nil,true) then
i = i + 1 i = i + 1
end end
else else
@ -372,23 +380,23 @@ function Search:find(option)
if line == " }, " or line == " }" then if line == " }, " or line == " }" then
-- new calibre data set -- new calibre data set
dummy = "" local search_content = ""
if option == "find" and SEARCH_AUTHORS then dummy = dummy .. self.data[i][self.authors] .. "\n" end if option == "find" and SEARCH_AUTHORS then search_content = search_content .. self.data[i][self.authors] .. "\n" end
if option == "find" and SEARCH_TITLE then dummy = dummy .. self.data[i][self.title] .. "\n" end if option == "find" and SEARCH_TITLE then search_content = search_content .. self.data[i][self.title] .. "\n" end
if option == "find" and SEARCH_PATH then dummy = dummy .. self.data[i][self.path] .. "\n" end if option == "find" and SEARCH_PATH then search_content = search_content .. self.data[i][self.path] .. "\n" end
if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then if (option == "series" or SEARCH_SERIES) and self.data[i][self.series] ~= "-" then
dummy = dummy .. self.data[i][self.series] .. "\n" search_content = search_content .. self.data[i][self.series] .. "\n"
self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1 self.browse_series[self.data[i][self.series]] = (self.browse_series[self.data[i][self.series]] or 0) + 1
end end
if option == "tags" or SEARCH_TAGS then dummy = dummy .. self.data[i][self.tags] .. "\n" end if option == "tags" or SEARCH_TAGS then search_content = search_content .. self.data[i][self.tags] .. "\n" end
if not SEARCH_CASESENSITIVE then dummy = string.upper(dummy) end if not SEARCH_CASESENSITIVE then search_content = string.upper(search_content) end
for j = 1,9 do for j = 1,9 do
g:write(self.data[i][j] .. "\n") g:write(self.data[i][j] .. "\n")
end end
if upsearch ~= "" then if upsearch ~= "" then
if string.find(dummy,upsearch,nil,true) then if string.find(search_content,upsearch,nil,true) then
i = i + 1 i = i + 1
end end
else else
@ -464,8 +472,7 @@ function Search:find(option)
self:browse(option,1) self:browse(option,1)
end end
else else
dummy = _("No match for") .. " " .. self.search_value UIManager:show(InfoMessage:new{text = T(_("No match for %1."), self.search_value)})
UIManager:show(InfoMessage:new{text = dummy})
end end
end end
@ -616,14 +623,14 @@ function Search:browse(option, run, chosen)
local i = 1 local i = 1
while i <= self.count do while i <= self.count do
if (option == "tags" and self.data[i][self.tags3]:find("\t" .. chosen .. "\t",nil,true)) or (option == "series" and chosen == self.data[i][self.series]) then if (option == "tags" and self.data[i][self.tags3]:find("\t" .. chosen .. "\t",nil,true)) or (option == "series" and chosen == self.data[i][self.series]) then
local dummy = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" .. local entry = _("Title: ") .. (self.data[i][self.title] or "-") .. "\n \n" ..
_("Author(s):") .. " " .. (self.data[i][self.authors2] or "-") .. "\n \n" .. _("Author(s):") .. " " .. (self.data[i][self.authors2] or "-") .. "\n \n" ..
_("Tags:") .. " " .. (self.data[i][self.tags2] or "-") .. "\n \n" .. _("Tags:") .. " " .. (self.data[i][self.tags2] or "-") .. "\n \n" ..
_("Series:") .. " " .. (self.data[i][self.series] or "-") _("Series:") .. " " .. (self.data[i][self.series] or "-")
if self.data[i][self.series] ~= "-" then if self.data[i][self.series] ~= "-" then
dummy = dummy .. " (" .. tostring(self.data[i][self.series_index]):gsub(".0$","") .. ")" entry = entry .. " (" .. tostring(self.data[i][self.series_index]):gsub(".0$","") .. ")"
end end
dummy = dummy .. "\n \n" .. _("Path: ") entry = entry .. "\n \n" .. _("Path: ")
local book = self.data[i][self.path] local book = self.data[i][self.path]
local text local text
if option == "series" then if option == "series" then
@ -637,7 +644,7 @@ function Search:browse(option, run, chosen)
end end
table.insert(self.results, { table.insert(self.results, {
text = text, text = text,
info = dummy, info = entry,
notchecked = true, notchecked = true,
path = self.data[i][self.path], path = self.data[i][self.path],
callback = function() callback = function()

@ -24,7 +24,8 @@ local SetDefaults = InputContainer:new{
results = {}, results = {},
defaults_menu = {}, defaults_menu = {},
initialized = false, initialized = false,
changed = {} changed = {},
settings_changed = false,
} }
function SetDefaults:ConfirmEdit() function SetDefaults:ConfirmEdit()
@ -118,7 +119,7 @@ function SetDefaults:init()
callback = function() callback = function()
self.defaults_value[i] = true self.defaults_value[i] = true
_G[setting_name] = true _G[setting_name] = true
settings_changed = true self.settings_changed = true
self.changed[i] = true self.changed[i] = true
self.results[i].text = self:build_setting(i) self.results[i].text = self:build_setting(i)
self:close() self:close()
@ -132,7 +133,7 @@ function SetDefaults:init()
callback = function() callback = function()
self.defaults_value[i] = false self.defaults_value[i] = false
_G[setting_name] = false _G[setting_name] = false
settings_changed = true self.settings_changed = true
self.changed[i] = true self.changed[i] = true
self.results[i].text = self:build_setting(i) self.results[i].text = self:build_setting(i)
self.defaults_menu:swithItemTable("Defaults", self.results, i) self.defaults_menu:swithItemTable("Defaults", self.results, i)
@ -180,7 +181,7 @@ function SetDefaults:init()
_G[setting_name] = new_table _G[setting_name] = new_table
self.defaults_value[i] = _G[setting_name] self.defaults_value[i] = _G[setting_name]
settings_changed = true self.settings_changed = true
self.changed[i] = true self.changed[i] = true
self.results[i].text = self:build_setting(i) self.results[i].text = self:build_setting(i)
@ -221,7 +222,7 @@ function SetDefaults:init()
if _G[setting_name] ~= new_value then if _G[setting_name] ~= new_value then
_G[setting_name] = new_value _G[setting_name] = new_value
self.defaults_value[i] = new_value self.defaults_value[i] = new_value
settings_changed = true self.settings_changed = true
self.changed[i] = true self.changed[i] = true
self.results[i].text = self:build_setting(i) self.results[i].text = self:build_setting(i)
end end
@ -338,7 +339,7 @@ function SetDefaults:saveSettings()
text = _("Default settings saved."), text = _("Default settings saved."),
}) })
end end
settings_changed = false self.settings_changed = false
end end
return SetDefaults return SetDefaults

Loading…
Cancel
Save