From b8ee33871f6cbed6748b3401d29f3c545605b009 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Feb 2016 23:01:19 -0800 Subject: [PATCH 1/7] style: clean up statuswidget a bit --- frontend/ui/widget/statuswidget.lua | 144 ++++++++++++++-------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/frontend/ui/widget/statuswidget.lua b/frontend/ui/widget/statuswidget.lua index 39ae094a2..3c0916527 100644 --- a/frontend/ui/widget/statuswidget.lua +++ b/frontend/ui/widget/statuswidget.lua @@ -1,7 +1,6 @@ local InputContainer = require("ui/widget/container/inputcontainer") local FrameContainer = require("ui/widget/container/framecontainer") local CenterContainer = require("ui/widget/container/centercontainer") -local RightContainer = require("ui/widget/container/rightcontainer") local LeftContainer = require("ui/widget/container/leftcontainer") local HorizontalGroup = require("ui/widget/horizontalgroup") local VerticalGroup = require("ui/widget/verticalgroup") @@ -27,8 +26,6 @@ local Font = require("ui/font") local TimeVal = require("ui/timeval") local RenderText = require("ui/rendertext") -local DocSettings = require("docsettings") -local DEBUG = require("dbg") local util = require("util") local _ = require("gettext") @@ -40,7 +37,7 @@ local _ = require("gettext") ["status"] = "Reading" ["modified"] = "24.01.2016" },]] -local StatusWidget = InputContainer:new { +local StatusWidget = InputContainer:new{ settings = nil, thumbnail = nil, props = nil, @@ -69,7 +66,7 @@ function StatusWidget:init() self.medium_font_face = Font:getFace("ffont", 20) self.large_font_face = Font:getFace("ffont", 25) - self.star = Button:new { + self.star = Button:new{ icon = "resources/icons/stats.star.empty.png", bordersize = 0, radius = 0, @@ -78,7 +75,7 @@ function StatusWidget:init() show_parent = self, } - local statusContainer = FrameContainer:new { + local statusContainer = FrameContainer:new{ dimen = Screen:getSize(), background = Blitbuffer.COLOR_WHITE, bordersize = 0, @@ -89,7 +86,7 @@ function StatusWidget:init() end function StatusWidget:showStatus() - local main_group = VerticalGroup:new { align = "left" } + local main_group = VerticalGroup:new{ align = "left" } local img_width = Screen:scaleBySize(132 * 1.5) local img_height = Screen:scaleBySize(184 * 1.5) @@ -101,7 +98,7 @@ function StatusWidget:showStatus() local thumb = nil if self.thumbnail then - thumb = ImageWidget:new { + thumb = ImageWidget:new{ image = self.thumbnail, width = img_width, height = img_height, @@ -111,13 +108,13 @@ function StatusWidget:showStatus() local screen_width = Screen:getWidth() - local cover_with_title_and_author_container = CenterContainer:new { - dimen = Geom:new { w = screen_width, h = img_height }, + local cover_with_title_and_author_container = CenterContainer:new{ + dimen = Geom:new{ w = screen_width, h = img_height }, } - local cover_with_title_and_author_group = HorizontalGroup:new { align = "top" } + local cover_with_title_and_author_group = HorizontalGroup:new{ align = "top" } - local span = HorizontalSpan:new { width = screen_width * 0.05 } + local span = HorizontalSpan:new{ width = screen_width * 0.05 } table.insert(cover_with_title_and_author_group, span) @@ -145,10 +142,10 @@ function StatusWidget:showStatus() statusHeight = Screen:scaleBySize(60) end - local header_group = HorizontalGroup:new { + local header_group = HorizontalGroup:new{ align = "center", self:addHeader(screen_width * 0.95, Screen:scaleBySize(15), _("Progress")), - CloseButton:new { window = self } + CloseButton:new{ window = self } } table.insert(main_group, header_group) @@ -193,14 +190,14 @@ function StatusWidget:getReadPages(stats) end function StatusWidget:addHeader(width, height, title) - local group = HorizontalGroup:new { + local group = HorizontalGroup:new{ align = "center", - bordersize = 0 + bordersize = 0, } local bold = false - local titleWidget = TextWidget:new { + local titleWidget = TextWidget:new{ text = title, face = self.large_font_face, bold = bold, @@ -208,19 +205,19 @@ function StatusWidget:addHeader(width, height, title) local titleSize = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.large_font_face, title, true, bold) local lineWidth = ((width - titleSize.x) * 0.5) - local line_container = LeftContainer:new { - dimen = Geom:new { w = lineWidth, h = height }, - LineWidget:new { + local line_container = LeftContainer:new{ + dimen = Geom:new{ w = lineWidth, h = height }, + LineWidget:new{ background = Blitbuffer.gray(0.2), - dimen = Geom:new { + dimen = Geom:new{ w = lineWidth, h = 2, } } } - local text_container = CenterContainer:new { - dimen = Geom:new { w = titleSize.x, h = height }, + local text_container = CenterContainer:new{ + dimen = Geom:new{ w = titleSize.x, h = height }, titleWidget, } @@ -231,8 +228,8 @@ function StatusWidget:addHeader(width, height, title) end function StatusWidget:generateSwitchGroup(width, height, book_status) - local switch_container = CenterContainer:new { - dimen = Geom:new { w = width, h = height }, + local switch_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = height }, } local args = { @@ -268,7 +265,7 @@ function StatusWidget:generateSwitchGroup(width, height, book_status) enabled = true, } - local switch = ToggleSwitch:new { + local switch = ToggleSwitch:new{ width = width * 0.6, default_value = config.default_value, name = config.name, @@ -321,7 +318,7 @@ end function StatusWidget:generateSummaryGroup(width, height, text) - self.input_note = InputText:new { + self.input_note = InputText:new{ text = text, face = self.medium_font_face, width = width * 0.95, @@ -334,16 +331,16 @@ function StatusWidget:generateSummaryGroup(width, height, text) hint = _("A few words about the book"), } - local note_container = CenterContainer:new { - dimen = Geom:new { w = width, h = height }, + local note_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = height }, self.input_note } return note_container end function StatusWidget:generateRateGroup(width, height, rating) - self.stars_container = CenterContainer:new { - dimen = Geom:new { w = width, h = height }, + self.stars_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = height }, } self:setStar(rating) @@ -354,20 +351,23 @@ function StatusWidget:setStar(num) --clear previous data self.stars_container:clear() - local stars_group = HorizontalGroup:new { align = "center" } + local stars_group = HorizontalGroup:new{ align = "center" } if num then self.summary.rating = num self:saveSummary() for i = 1, num do - table.insert(stars_group, self.star:new { icon = "resources/icons/stats.star.full.png", callback = function() self:setStar(i) end }) + table.insert(stars_group, self.star:new{ + icon = "resources/icons/stats.star.full.png", + callback = function() self:setStar(i) end + }) end else num = 0 end for i = num + 1, 5 do - table.insert(stars_group, self.star:new { callback = function() self:setStar(i) end }) + table.insert(stars_group, self.star:new{ callback = function() self:setStar(i) end }) end table.insert(self.stars_container, stars_group) @@ -377,34 +377,34 @@ function StatusWidget:setStar(num) end function StatusWidget:generateStatisticsGroup(width, height, days, average, pages) - local statistics_container = CenterContainer:new { - dimen = Geom:new { w = width, h = height }, + local statistics_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = height }, } - local statistics_group = VerticalGroup:new { align = "left" } + local statistics_group = VerticalGroup:new{ align = "left" } local tile_width = width / 3 local tile_height = height / 2 - local titles_group = HorizontalGroup:new { + local titles_group = HorizontalGroup:new{ align = "center", - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = _("Days"), face = self.small_font_face, }, }, - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = _("Time"), face = self.small_font_face, }, }, - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = _("Read pages"), face = self.small_font_face, } @@ -412,25 +412,25 @@ function StatusWidget:generateStatisticsGroup(width, height, days, average, page } - local data_group = HorizontalGroup:new { + local data_group = HorizontalGroup:new{ align = "center", - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = days, face = self.medium_font_face, }, }, - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = average, face = self.medium_font_face, }, }, - CenterContainer:new { - dimen = Geom:new { w = tile_width, h = tile_height }, - TextWidget:new { + CenterContainer:new{ + dimen = Geom:new{ w = tile_width, h = tile_height }, + TextWidget:new{ text = pages, face = self.medium_font_face, } @@ -446,34 +446,34 @@ end function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, authors, current_page, total_pages) - local title_author_container = CenterContainer:new { - dimen = Geom:new { w = width, h = height }, + local title_author_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = height }, } - local title_author_progressbar_group = VerticalGroup:new { + local title_author_progressbar_group = VerticalGroup:new{ align = "center", - VerticalSpan:new { width = height * 0.2 }, - TextBoxWidget:new { + VerticalSpan:new{ width = height * 0.2 }, + TextBoxWidget:new{ text = title, width = width, face = self.medium_font_face, alignment = "center", } } - local text_author = TextWidget:new { + local text_author = TextWidget:new{ text = authors, face = self.small_font_face, padding = 2, } - local author_container = CenterContainer:new { - dimen = Geom:new { w = width, h = text_author:getSize().h }, + local author_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = text_author:getSize().h }, text_author } table.insert(title_author_progressbar_group, author_container) - local progressWidget = ProgressWidget:new { + local progressWidget = ProgressWidget:new{ width = width * 0.7, height = Screen:scaleBySize(10), percentage = current_page / total_pages, @@ -482,19 +482,19 @@ function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, aut last = total_pages, } - local progress_bar_container = CenterContainer:new { - dimen = Geom:new { w = width, h = progressWidget:getSize().h }, + local progress_bar_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = progressWidget:getSize().h }, progressWidget } table.insert(title_author_progressbar_group, progress_bar_container) - local text_complete = TextWidget:new { + local text_complete = TextWidget:new{ text = string.format("%1.f", progressWidget.percentage * 100) .. "% " .. _("Completed"), face = self.small_font_face, } - local progress_bar_text_container = CenterContainer:new { - dimen = Geom:new { w = width, h = text_complete:getSize().h }, + local progress_bar_text_container = CenterContainer:new{ + dimen = Geom:new{ w = width, h = text_complete:getSize().h }, text_complete } @@ -529,7 +529,7 @@ end function StatusWidget:onSwitchFocus(inputbox) - self.note_dialog = InputDialog:new { + self.note_dialog = InputDialog:new{ title = "Note", input = self.input_note:getText(), input_hint = "", From 9bd2d428340004cfb6fcdc1bc900b02bd0c8ff1d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Feb 2016 23:01:52 -0800 Subject: [PATCH 2/7] build: enforce luacheck in travis build --- .luacheckrc | 4 ++++ .travis.yml | 3 +++ frontend/MD5.lua | 2 +- frontend/apps/reader/modules/readerwikipedia.lua | 4 ---- frontend/configurable.lua | 15 +++++++-------- frontend/device.lua | 7 ++++--- frontend/docsettings.lua | 4 ++-- frontend/httpclient.lua | 1 - 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 39cb9bfa1..f6c991513 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -90,3 +90,7 @@ read_globals = { "lfs", "lipc", } + +exclude_files = { + "frontend/luxl.lua", +} diff --git a/.travis.yml b/.travis.yml index 9a0838e74..65d729d6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -61,6 +61,7 @@ install: # luasec doesn't automatically detect 64-bit libs - travis_retry luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu - travis_retry luarocks --local install luacov-coveralls --server=http://rocks.moonscript.org/dev + - travis_retry luarocks --local install luacheck # add local rocks to $PATH - eval $(luarocks path --bin) @@ -68,6 +69,8 @@ script: - travis_retry make fetchthirdparty - make all - travis_retry make testfront + - luacheck --no-color -q frontend | tee ./luacheck.out + - test $(grep Total ./luacheck.out | awk '{print $2}') -le 250 after_success: - make coverage diff --git a/frontend/MD5.lua b/frontend/MD5.lua index 0e0bbed46..9754f5f9d 100644 --- a/frontend/MD5.lua +++ b/frontend/MD5.lua @@ -144,7 +144,7 @@ local function MD5Update(ctx, buf, len) t = band(rshift(t, 3), 0x3f) if (t > 0) then - p = ffi.cast("unsigned char *", ctx.input + t) + local p = ffi.cast("unsigned char *", ctx.input + t) t = 64 - t if (len < t) then diff --git a/frontend/apps/reader/modules/readerwikipedia.lua b/frontend/apps/reader/modules/readerwikipedia.lua index 87587e286..241351c09 100644 --- a/frontend/apps/reader/modules/readerwikipedia.lua +++ b/frontend/apps/reader/modules/readerwikipedia.lua @@ -1,10 +1,6 @@ local ReaderDictionary = require("apps/reader/modules/readerdictionary") -local EventListener = require("ui/widget/eventlistener") -local NetworkMgr = require("ui/networkmgr") local Translator = require("ui/translator") local Wikipedia = require("ui/wikipedia") -local UIManager = require("ui/uimanager") -local Geom = require("ui/geometry") local Screen = require("device").screen local DEBUG = require("dbg") local _ = require("gettext") diff --git a/frontend/configurable.lua b/frontend/configurable.lua index 8b154bd42..5f1116110 100644 --- a/frontend/configurable.lua +++ b/frontend/configurable.lua @@ -10,16 +10,15 @@ end function Configurable:reset() for key,value in pairs(self) do if type(value) == "number" or type(value) == "string" then - self[key] = nil + self[key] = nil end end end function Configurable:hash(sep) local hash = "" - local excluded = {multi_threads = true,} for key,value in pairs(self) do - if type(value) == "number" or type(value) == "string" then + if type(value) == "number" or type(value) == "string" then hash = hash..sep..value end end @@ -31,13 +30,13 @@ function Configurable:loadDefaults(config_options) self:reset() for i=1,#config_options do local options = config_options[i].options - for j=1,#config_options[i].options do - local key = config_options[i].options[j].name + for j=1,#options do + local key = options[j].name local settings_key = config_options.prefix.."_"..key local default = G_reader_settings:readSetting(settings_key) - self[key] = default or config_options[i].options[j].default_value + self[key] = default or options[j].default_value if not self[key] then - self[key] = config_options[i].options[j].default_arg + self[key] = options[j].default_arg end end end @@ -49,7 +48,7 @@ function Configurable:loadSettings(settings, prefix) or type(value) == "table" then local saved_value = settings:readSetting(prefix..key) self[key] = (saved_value == nil) and self[key] or saved_value - --Debug("Configurable:loadSettings", "key", key, "saved value", + --Debug("Configurable:loadSettings", "key", key, "saved value", --saved_value,"Configurable.key", self[key]) end end diff --git a/frontend/device.lua b/frontend/device.lua index 540ed945e..11d3c73ac 100644 --- a/frontend/device.lua +++ b/frontend/device.lua @@ -27,9 +27,10 @@ local function probeDevice() end -- add new ports here: - if --[[ implement a proper test instead --]] false then - return require("device/newport/device") - end + -- + -- if --[[ implement a proper test instead --]] false then + -- return require("device/newport/device") + -- end error("did not find a hardware abstraction for this platform") end diff --git a/frontend/docsettings.lua b/frontend/docsettings.lua index b43386efe..60461ac2f 100644 --- a/frontend/docsettings.lua +++ b/frontend/docsettings.lua @@ -30,8 +30,8 @@ function DocSettings:getNameFromHistory(hist_name) end function DocSettings:open(docfile) - local history_path = nil - local sidecar_path = nil + local history_path + local sidecar_path if docfile == ".reader" then -- we handle reader setting as special case history_path = DataStorage:getDataDir() .. "/settings.reader.lua" diff --git a/frontend/httpclient.lua b/frontend/httpclient.lua index 56458a400..3cf91aa73 100644 --- a/frontend/httpclient.lua +++ b/frontend/httpclient.lua @@ -1,5 +1,4 @@ local UIManager = require("ui/uimanager") -local DEBUG = require("dbg") local HTTPClient = { input_timeouts = 0, From ba1ef91df283a010568920aa92887c98cd6aee7d Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Feb 2016 23:10:37 -0800 Subject: [PATCH 3/7] minor: translate progress bar text with template --- frontend/ui/widget/statuswidget.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/ui/widget/statuswidget.lua b/frontend/ui/widget/statuswidget.lua index 3c0916527..721a00dcd 100644 --- a/frontend/ui/widget/statuswidget.lua +++ b/frontend/ui/widget/statuswidget.lua @@ -26,6 +26,7 @@ local Font = require("ui/font") local TimeVal = require("ui/timeval") local RenderText = require("ui/rendertext") +local template = require("ffi/util").template local util = require("util") local _ = require("gettext") @@ -473,23 +474,27 @@ function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, aut table.insert(title_author_progressbar_group, author_container) - local progressWidget = ProgressWidget:new{ + local read_percentage = current_page / total_pages + local progress_height = Screen:scaleBySize(10) + + local progress_bar = ProgressWidget:new{ width = width * 0.7, - height = Screen:scaleBySize(10), - percentage = current_page / total_pages, + height = progress_height, + percentage = read_percentage, ticks = {}, tick_width = 0, last = total_pages, } - local progress_bar_container = CenterContainer:new{ - dimen = Geom:new{ w = width, h = progressWidget:getSize().h }, - progressWidget - } - - table.insert(title_author_progressbar_group, progress_bar_container) + table.insert(title_author_progressbar_group, + CenterContainer:new{ + dimen = Geom:new{ w = width, h = progress_bar:getSize().h }, + progress_bar + } + ) local text_complete = TextWidget:new{ - text = string.format("%1.f", progressWidget.percentage * 100) .. "% " .. _("Completed"), + text = template(_("%1% Completed"), + string.format("%1.f", read_percentage * 100)), face = self.small_font_face, } From 8e707da616336d96546c76dcdbc9d78f866d371e Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Feb 2016 23:17:53 -0800 Subject: [PATCH 4/7] reader(status): append status item to the end of menu properly --- frontend/apps/reader/modules/readerstatus.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerstatus.lua b/frontend/apps/reader/modules/readerstatus.lua index 580203bba..c181b24be 100644 --- a/frontend/apps/reader/modules/readerstatus.lua +++ b/frontend/apps/reader/modules/readerstatus.lua @@ -22,7 +22,9 @@ function ReaderStatus:init() return end self.total_pages = self.document:getPageCount() - UIManager:scheduleIn(0.1, function() self.ui.menu:registerToMainMenu(self) end) + self.ui:registerPostInitCallback(function() + self.ui.menu:registerToMainMenu(self) + end) end function ReaderStatus:addToMainMenu(tab_item_table) From ad3b2dad1a37fec40b8c517a638ad5f3726167a6 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Tue, 9 Feb 2016 23:42:32 -0800 Subject: [PATCH 5/7] build: fix luacheck in travis build --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 65d729d6b..044de2586 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ install: - git clone https://github.com/torch/luajit-rocks.git - pushd luajit-rocks - git checkout 6529891 - - cmake . -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/install + - cmake . -DWITH_LUAJIT21=ON -DCMAKE_INSTALL_PREFIX=${TRAVIS_BUILD_DIR}/install - make install - popd - export PATH=$PATH:${TRAVIS_BUILD_DIR}/install/bin @@ -62,6 +62,7 @@ install: - travis_retry luarocks --local install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu - travis_retry luarocks --local install luacov-coveralls --server=http://rocks.moonscript.org/dev - travis_retry luarocks --local install luacheck + - travis_retry luarocks --local install lanes # for parallel luacheck # add local rocks to $PATH - eval $(luarocks path --bin) @@ -69,7 +70,7 @@ script: - travis_retry make fetchthirdparty - make all - travis_retry make testfront - - luacheck --no-color -q frontend | tee ./luacheck.out + - luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out - test $(grep Total ./luacheck.out | awk '{print $2}') -le 250 after_success: From 8203ba2ec6443ba5c2c56ffd8dd45800fa8a6b77 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 10 Feb 2016 01:46:18 -0800 Subject: [PATCH 6/7] doc: update readme --- README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3a637a9db..cc069a50e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Highlights for developers * running on multi-platform with only one code-base maintained * developing koreader in any editor without compilation * high runtime efficiency by LuaJIT acceleration - * light-weight widget toolkit for small memory footprint + * light-weight self-contained widget toolkit with small memory footprint * extensible with plugin system * interfaced backends for documents parsing and rendering * high quality document backend libraries like MuPDF, DjvuLibre and CREngine @@ -51,7 +51,7 @@ Highlights for developers * in active development * contributed by developers around the world * continuous integration with Travis CI - * with unit tests and code coverage test + * with unit tests, static analysis and code coverage test * automatic release of nightly builds * free as in free speech * licensed under Affero GPL v3 @@ -147,8 +147,8 @@ package from scratch. For Android devices ------------------- -Make sure the "android" and "ndk-build" tools are in your PATH variable -and the NDK variable points to the root directory of the Android NDK. +Make sure the "android" and "ndk-build" tools are in your PATH environment +variable and the NDK variable points to the root directory of the Android NDK. Then, run this command to build installable package for Android: ``` @@ -163,22 +163,23 @@ To build an emulator on current Linux machine just run: ./kodev build ``` -If you want to compile the emulator for Windows you need to run: +If you want to compile the emulator for Windows run: ``` ./kodev build win32 ``` -To run Koreader on your developing machine +To run Koreader on your developing machine: ``` -./kodev run ./test +./kodev run ``` To run unit tests: ``` -make test +./kodev test base +./kodev test front ``` -To run Lua static-analysis for KOReader: +To run Lua static analysis: ``` make static-check ``` @@ -203,7 +204,7 @@ modifications with kroeader frontend. NOTE: only support relative path for now. Translation -======== +=========== Please refer to [l10n's README][l10n-readme] to grab the latest translations from [the Koreader project on Transifex][koreader-transifex] with this command: From 8f4fae7a098ae4c285890b7e9d573ee510fe64af Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 10 Feb 2016 10:30:05 -0800 Subject: [PATCH 7/7] minore: more static check fixes --- .travis.yml | 2 +- Makefile | 2 +- frontend/ui/widget/buttontable.lua | 1 - frontend/ui/widget/confirmbox.lua | 5 +---- frontend/ui/widget/container/bottomcontainer.lua | 5 +++-- frontend/ui/widget/container/centercontainer.lua | 5 +++-- frontend/ui/widget/container/leftcontainer.lua | 5 +++-- frontend/ui/widget/container/rightcontainer.lua | 5 +++-- frontend/ui/widget/dictquicklookup.lua | 1 - frontend/ui/widget/eventlistener.lua | 4 ++-- frontend/ui/widget/opdsbrowser.lua | 16 ++++++++-------- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 044de2586..12740b491 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,7 +71,7 @@ script: - make all - travis_retry make testfront - luajit $(which luacheck) --no-color -q frontend | tee ./luacheck.out - - test $(grep Total ./luacheck.out | awk '{print $2}') -le 250 + - test $(grep Total ./luacheck.out | awk '{print $2}') -le 238 after_success: - make coverage diff --git a/Makefile b/Makefile index c1cbf572e..20c0a9d07 100644 --- a/Makefile +++ b/Makefile @@ -321,7 +321,7 @@ po: $(MAKE) -i -C l10n bootstrap pull static-check: - @if which luacheck > /dev/null; then luacheck frontend; else \ + @if which luacheck > /dev/null; then luacheck -q frontend; else \ echo "[!] luacheck not found. "\ "you can install it with 'luarocks install luacheck'"; fi diff --git a/frontend/ui/widget/buttontable.lua b/frontend/ui/widget/buttontable.lua index cd3fb0392..562edbbe3 100644 --- a/frontend/ui/widget/buttontable.lua +++ b/frontend/ui/widget/buttontable.lua @@ -5,7 +5,6 @@ local FocusManager = require("ui/widget/focusmanager") local LineWidget = require("ui/widget/linewidget") local Blitbuffer = require("ffi/blitbuffer") local Button = require("ui/widget/button") -local UIManager = require("ui/uimanager") local Geom = require("ui/geometry") local Device = require("device") local Screen = Device.screen diff --git a/frontend/ui/widget/confirmbox.lua b/frontend/ui/widget/confirmbox.lua index 2ff70e6b0..af075aaa3 100644 --- a/frontend/ui/widget/confirmbox.lua +++ b/frontend/ui/widget/confirmbox.lua @@ -7,12 +7,9 @@ local ImageWidget = require("ui/widget/imagewidget") local TextBoxWidget = require("ui/widget/textboxwidget") local HorizontalSpan = require("ui/widget/horizontalspan") local ButtonTable = require("ui/widget/buttontable") -local GestureRange = require("ui/gesturerange") local UIManager = require("ui/uimanager") local Device = require("device") -local Geom = require("ui/geometry") -local Input = require("device").input -local Screen = require("device").screen +local Screen = Device.screen local Font = require("ui/font") local DEBUG = require("dbg") local _ = require("gettext") diff --git a/frontend/ui/widget/container/bottomcontainer.lua b/frontend/ui/widget/container/bottomcontainer.lua index 123b4be29..9bc4fede9 100644 --- a/frontend/ui/widget/container/bottomcontainer.lua +++ b/frontend/ui/widget/container/bottomcontainer.lua @@ -9,10 +9,11 @@ local BottomContainer = WidgetContainer:new() function BottomContainer:paintTo(bb, x, y) local contentSize = self[1]:getSize() - if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then + -- FIXME + -- if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then -- throw error? paint to scrap buffer and blit partially? -- for now, we ignore this - end + -- end self[1]:paintTo(bb, x + math.floor((self.dimen.w - contentSize.w)/2), y + (self.dimen.h - contentSize.h)) diff --git a/frontend/ui/widget/container/centercontainer.lua b/frontend/ui/widget/container/centercontainer.lua index ff7b90034..2b080b5f5 100644 --- a/frontend/ui/widget/container/centercontainer.lua +++ b/frontend/ui/widget/container/centercontainer.lua @@ -7,10 +7,11 @@ local CenterContainer = WidgetContainer:new() function CenterContainer:paintTo(bb, x, y) local content_size = self[1]:getSize() - if content_size.w > self.dimen.w or content_size.h > self.dimen.h then + -- FIXME + -- if content_size.w > self.dimen.w or content_size.h > self.dimen.h then -- throw error? paint to scrap buffer and blit partially? -- for now, we ignore this - end + -- end local x_pos = x local y_pos = y if self.ignore ~= "height" then diff --git a/frontend/ui/widget/container/leftcontainer.lua b/frontend/ui/widget/container/leftcontainer.lua index 227845c09..8f4ac1e73 100644 --- a/frontend/ui/widget/container/leftcontainer.lua +++ b/frontend/ui/widget/container/leftcontainer.lua @@ -7,10 +7,11 @@ local LeftContainer = WidgetContainer:new() function LeftContainer:paintTo(bb, x, y) local contentSize = self[1]:getSize() - if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then + -- FIXME + -- if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then -- throw error? paint to scrap buffer and blit partially? -- for now, we ignore this - end + -- end self[1]:paintTo(bb, x , y + math.floor((self.dimen.h - contentSize.h)/2)) end diff --git a/frontend/ui/widget/container/rightcontainer.lua b/frontend/ui/widget/container/rightcontainer.lua index 51b96df1f..b92948264 100644 --- a/frontend/ui/widget/container/rightcontainer.lua +++ b/frontend/ui/widget/container/rightcontainer.lua @@ -7,10 +7,11 @@ local RightContainer = WidgetContainer:new() function RightContainer:paintTo(bb, x, y) local contentSize = self[1]:getSize() - if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then + -- FIXME + -- if contentSize.w > self.dimen.w or contentSize.h > self.dimen.h then -- throw error? paint to scrap buffer and blit partially? -- for now, we ignore this - end + -- end self[1]:paintTo(bb, x + (self.dimen.w - contentSize.w), y + math.floor((self.dimen.h - contentSize.h)/2)) diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 0e78d35ed..76e262721 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -5,7 +5,6 @@ local CenterContainer = require("ui/widget/container/centercontainer") local LeftContainer = require("ui/widget/container/leftcontainer") local ScrollTextWidget = require("ui/widget/scrolltextwidget") local VerticalGroup = require("ui/widget/verticalgroup") -local TextBoxWidget = require("ui/widget/textboxwidget") local OverlapGroup = require("ui/widget/overlapgroup") local CloseButton = require("ui/widget/closebutton") local ButtonTable = require("ui/widget/buttontable") diff --git a/frontend/ui/widget/eventlistener.lua b/frontend/ui/widget/eventlistener.lua index c4e1d1522..88aaaeea7 100644 --- a/frontend/ui/widget/eventlistener.lua +++ b/frontend/ui/widget/eventlistener.lua @@ -7,8 +7,8 @@ will call a method "onEventName" for an event with name --]] local EventListener = {} -function EventListener:new(o) - local o = o or {} +function EventListener:new(new_o) + local o = new_o or {} setmetatable(o, self) self.__index = self if o.init then o:init() end diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua index 0d77f0be1..0f5685a3b 100644 --- a/frontend/ui/widget/opdsbrowser.lua +++ b/frontend/ui/widget/opdsbrowser.lua @@ -168,7 +168,7 @@ end function OPDSBrowser:genItemTableFromRoot() local item_table = {} - for i, server in ipairs(self.opds_servers) do + for _, server in ipairs(self.opds_servers) do table.insert(item_table, { text = server.title, content = server.subtitle, @@ -176,7 +176,7 @@ function OPDSBrowser:genItemTableFromRoot() }) end local added_servers = G_reader_settings:readSetting("opds_servers") or {} - for i, server in ipairs(added_servers) do + for _, server in ipairs(added_servers) do table.insert(item_table, { text = server.title, content = server.subtitle, @@ -375,7 +375,7 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) end local hrefs = {} if feed.link then - for i, link in ipairs(feed.link) do + for _, link in ipairs(feed.link) do if link.type:find(self.catalog_type) or link.type:find(self.search_type) then if link.rel and link.href then @@ -386,11 +386,11 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) end item_table.hrefs = hrefs if feed.entry then - for i, entry in ipairs(feed.entry) do + for _, entry in ipairs(feed.entry) do local item = {} item.acquisitions = {} if entry.link then - for i, link in ipairs(entry.link) do + for _, link in ipairs(entry.link) do if link.type:find(self.catalog_type) and (not link.rel or link.rel == "subsection" or link.rel == "http://opds-spec.org/sort/popular" or link.rel == "http://opds-spec.org/sort/new") then item.url = build_href(link.href) end @@ -451,7 +451,7 @@ end function OPDSBrowser:appendCatalog(item_table_url) local new_table = self:genItemTableFromURL(item_table_url) - for i, item in ipairs(new_table) do + for _, item in ipairs(new_table) do table.insert(self.item_table, item) end self.item_table.hrefs = new_table.hrefs @@ -566,7 +566,7 @@ end function OPDSBrowser:editServerFromInput(item, fields) DEBUG("input catalog", fields) local servers = {} - for i, server in ipairs(G_reader_settings:readSetting("opds_servers") or {}) do + for _, server in ipairs(G_reader_settings:readSetting("opds_servers") or {}) do if server.title == item.text or server.url == item.url then server.title = fields[1] server.url = (fields[2]:match("^%a+://") and fields[2] or "http://" .. fields[2]) @@ -620,7 +620,7 @@ end function OPDSBrowser:deleteOPDSServer(item) DEBUG("delete", item) local servers = {} - for i, server in ipairs(G_reader_settings:readSetting("opds_servers") or {}) do + for _, server in ipairs(G_reader_settings:readSetting("opds_servers") or {}) do if server.title ~= item.text or server.url ~= item.url then table.insert(servers, server) end