From cea353323eae7f3fd04f9eef8844203fc3670f37 Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Mon, 5 Aug 2013 23:06:26 +0200 Subject: [PATCH 01/24] Initial light control widget; final fixes for kobo light --- frontend/ui/device.lua | 7 +++ frontend/ui/reader/readerfrontlight.lua | 70 ++++++++++++++++++++++++- frontend/ui/reader/readermenu.lua | 9 +++- frontend/ui/readerui.lua | 4 +- frontend/ui/widget/menu.lua | 1 + 5 files changed, 86 insertions(+), 5 deletions(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 34d859365..997954401 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -105,6 +105,13 @@ function Device:isTouchDevice() return (self.model == "KindlePaperWhite") or (self.model == "KindleTouch") or self:isKobo() or util.isEmulated() end +function Device:hasFrontlight() + if not self.model then + self.model = self:getModel() + end + return (self.model == "KindlePaperWhite") or (self.model == "Kobo_dragon") or (self.model == "Kobo_kraken") or (self.model == "Kobo_phoenix") or util.isEmulated() +end + function Device:setTouchInputDev(dev) self.touch_dev = dev end diff --git a/frontend/ui/reader/readerfrontlight.lua b/frontend/ui/reader/readerfrontlight.lua index 93f1f75b5..3ab2d2555 100644 --- a/frontend/ui/reader/readerfrontlight.lua +++ b/frontend/ui/reader/readerfrontlight.lua @@ -1,7 +1,10 @@ require "ui/widget/container" +require "ui/widget/inputdialog" require "ui/device" ReaderFrontLight = InputContainer:new{ + fldial_menu_title = ("Frontlight Settings"), + fl_dialog_title = ("Frontlight Level"), steps = {0,1,2,3,4,5,6,7,8,9,10}, intensity = nil, fl = nil, @@ -31,7 +34,11 @@ function ReaderFrontLight:init() end if Device:isKobo() then self.fl = kobolight.open() - self.intensity = 20 + self.intensity = G_reader_settings:readSetting("frontlight_intensity") + if not self.intensity then + self.intensity = 20 + end + self:setIntensity(self.intensity, "Set intensity") end end @@ -54,7 +61,7 @@ function ReaderFrontLight:onAdjust(arg, ges) end function ReaderFrontLight:setIntensity(intensity, msg) - if self.lipc_handle then + if self.lipc_handle then intensity = intensity < 0 and 0 or intensity intensity = intensity > 24 and 24 or intensity self.intensity = intensity @@ -65,6 +72,8 @@ function ReaderFrontLight:setIntensity(intensity, msg) }) end if Device:isKobo() then + intensity = intensity < 1 and 1 or intensity + intensity = intensity > 100 and 100 or intensity if self.fl == nil then ReaderFrontLight:init() end @@ -87,3 +96,60 @@ function ReaderFrontLight:toggle() end return true end + +function ReaderFrontLight:addToMainMenu(tab_item_table) + -- insert fldial command to main reader menu + table.insert(tab_item_table.main, { + text = self.fldial_menu_title, + callback = function() + self:onShowFlDialog() + end, + }) +end + +function ReaderFrontLight:onShowFlDialog() + DEBUG("show fldial dialog") + self.fl_dialog = InputDialog:new{ + title = self.fl_dialog_title, + input_hint = "(1 - 100)", + buttons = { + { + { + text = _("Apply"), + enabled = true, + callback = function() + self:fldialIntensity() + end, + }, + { + text = _("OK"), + enabled = true, + callback = function() + self:fldialIntensity() + self:close() + end, + }, + + }, + }, + input_type = "number", + width = Screen:getWidth() * 0.8, + height = Screen:getHeight() * 0.2, + } + self.fl_dialog:onShowKeyboard() + UIManager:show(self.fl_dialog) +end + +function ReaderFrontLight:close() + self.fl_dialog:onClose() + G_reader_settings:saveSetting("frontlight_intensity", self.intensity) + UIManager:close(self.fl_dialog) +end + +function ReaderFrontLight:fldialIntensity() + local number = tonumber(self.fl_dialog:getInputText()) + if number then + self:setIntensity(number, "Set intensity") + end + return true +end diff --git a/frontend/ui/reader/readermenu.lua b/frontend/ui/reader/readermenu.lua index e0d297a56..35055b663 100644 --- a/frontend/ui/reader/readermenu.lua +++ b/frontend/ui/reader/readermenu.lua @@ -56,7 +56,14 @@ function ReaderMenu:setUpdateItemTable() for _, widget in pairs(self.registered_widgets) do widget:addToMainMenu(self.tab_item_table) end - + if Device:hasFrontlight() then + table.insert(self.tab_item_table.main, { + text = _("Frontlight settings"), + callback = function() + ReaderFrontLight:onShowFlDialog() + end + }) + end table.insert(self.tab_item_table.main, { text = _("Help"), callback = function() diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index 96b8fd079..877ccb200 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -129,14 +129,14 @@ function ReaderUI:init() view = self[1], ui = self } + table.insert(self.active_widgets, reader_ss) -- frontlight controller local reader_fl = ReaderFrontLight:new{ dialog = self.dialog, view = self[1], ui = self } - table.insert(self.active_widgets, reader_ss) - table.insert(self.active_widgets, reader_fl) + table.insert(self, reader_fl) if self.document.info.has_pages then -- for page specific controller diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index fc157a2df..4b3cbdd86 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -1,6 +1,7 @@ require "ui/widget/container" require "ui/widget/focusmanager" require "ui/widget/infomessage" +require "ui/widget/frontlight" require "ui/widget/button" require "ui/widget/text" require "ui/widget/group" From 1be83abede5f12834015bca641bb7272412f92c9 Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Tue, 6 Aug 2013 09:01:44 +0200 Subject: [PATCH 02/24] update koreader-base. --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index 698fb1764..b5625d48e 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 698fb1764ffc0eafbd5cdb2dcc6d8165cca8d8f0 +Subproject commit b5625d48e91016b9ac33bf15c9d662d7bcb17bcd From 1201b64d180bd2eeb2d824982bea8613e960bc7b Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Tue, 6 Aug 2013 12:03:10 +0200 Subject: [PATCH 03/24] Add an option "make koboupdate" --- Makefile | 35 +++++++++++++++++++++++++++++++++++ fmon/koreader.sh | 1 + koreader_kobo.sh | 2 +- resources/koreader.png | Bin 0 -> 2250 bytes 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 fmon/koreader.sh create mode 100644 resources/koreader.png diff --git a/Makefile b/Makefile index 845b40bb5..5728bf89c 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ VERSION=$(shell git describe HEAD) # subdirectory we use to build the installation bundle INSTALL_DIR=koreader +INSTALL_DIR_KOBO=mnt/onboard/.kobo/koreader # subdirectory we use to setup emulation environment EMU_DIR=emu @@ -90,6 +91,40 @@ customupdate: all rm -rf $(INSTALL_DIR) # @TODO write an installation script for KUAL (houqp) +koboupdate: all + # ensure that the binaries were built for ARM + file $(KOR_BASE)/koreader-base | grep ARM || exit 1 + file $(KOR_BASE)/extr | grep ARM || exit 1 + # remove old package and dir if any + rm -f koreader-kobo-$(VERSION).zip + rm -rf $(INSTALL_DIR_KOBO) + # create new dir for package + mkdir -p $(INSTALL_DIR_KOBO)/{history,screenshots,clipboard,libs} + cp -p README.md COPYING $(KOR_BASE)/{koreader-base,extr,sdcv} koreader.sh koreader_kobo.sh $(LUA_FILES) $(INSTALL_DIR_KOBO) + $(STRIP) --strip-unneeded $(INSTALL_DIR_KOBO)/koreader-base $(INSTALL_DIR_KOBO)/extr $(INSTALL_DIR_KOBO)/sdcv + mkdir $(INSTALL_DIR_KOBO)/data $(INSTALL_DIR_KOBO)/data/dict $(INSTALL_DIR_KOBO)/data/tessdata + cp -L koreader-base/$(DJVULIB) $(KOR_BASE)/$(CRELIB) \ + $(KOR_BASE)/$(LUALIB) $(KOR_BASE)/$(K2PDFOPTLIB) \ + $(KOR_BASE)/$(LEPTONICALIB) $(KOR_BASE)/$(TESSERACTLIB) \ + $(INSTALL_DIR_KOBO)/libs + $(STRIP) --strip-unneeded $(INSTALL_DIR_KOBO)/libs/* + cp -rpL $(KOR_BASE)/data/*.css $(INSTALL_DIR_KOBO)/data + cp -rpL $(KOR_BASE)/data/hyph $(INSTALL_DIR_KOBO)/data/hyph + cp -rpL $(KOR_BASE)/fonts $(INSTALL_DIR_KOBO) + cp -rp $(MO_DIR) $(INSTALL_DIR_KOBO) + rm $(INSTALL_DIR_KOBO)/fonts/droid/DroidSansFallbackFull.ttf + echo $(VERSION) > git-rev + cp -r git-rev resources $(INSTALL_DIR_KOBO) + rm -r $(INSTALL_DIR_KOBO)/resources/fonts + cp -rpL frontend $(INSTALL_DIR_KOBO) + cp defaults.lua $(INSTALL_DIR_KOBO) + mkdir $(INSTALL_DIR_KOBO)/fonts/host + cp -rpL fmon $(INSTALL_DIR_KOBO)/.. + cp -p resources/koreader.png $(INSTALL_DIR_KOBO)/../.. + tar -zcvf KoboRoot.tgz mnt/ + zip -9 -r koreader-kobo-$(VERSION).zip KoboRoot.tgz + rm KoboRoot.tgz + rm -rf mnt/ pot: $(XGETTEXT_BIN) reader.lua `find frontend -iname "*.lua"` \ diff --git a/fmon/koreader.sh b/fmon/koreader.sh new file mode 100644 index 000000000..03ba8f433 --- /dev/null +++ b/fmon/koreader.sh @@ -0,0 +1 @@ +$root/.kobo/fmon/fmon $root/koreader.png $root/.kobo/koreader/koreader_kobo.sh & diff --git a/koreader_kobo.sh b/koreader_kobo.sh index 16e7b1dfb..2cd418578 100644 --- a/koreader_kobo.sh +++ b/koreader_kobo.sh @@ -14,7 +14,7 @@ export STARDICT_DATA_DIR="data/dict" killall nickel # finally call reader -./reader.lua "$1" 2> crash.log +./reader.lua /mnt/onboard 2> crash.log # continue with nickel diff --git a/resources/koreader.png b/resources/koreader.png new file mode 100644 index 0000000000000000000000000000000000000000..1e60432478065bb5c5cb4d2300d89dbf7c324a40 GIT binary patch literal 2250 zcmV;*2sQVKP)Px#22e~?MgRZ*00010!qa{L000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i*t; z2r3JK#r0GG000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}000OjNklk58&0HuB*wh!VExEPQ9rn>&IEZv8Yf_`Vw=5#crx6LnVP=#acR=QuPeL ztP4!joN8wN6Z&E)15J+AegJ$7eJy>pIL02Pp_M*1&%c>owqil^{9(Fm#VU4=u-S~4 z%|Zb3t+YYIXveE&A*BqK9_{>9BS9&HsEq7)N9s6VQw0Hu$8E9 zSTZ%^r$-5V(3QF-o+oVZ+aCGA>&te8zG2uZ&A3T`n1ROR%+leEoi&= z&9o3}EmN>={c_J3Ev~{GVS2@kV5Zz(S`3|-e*Ll)Y^d#AFtdIc1nYM&J<&sw1iT?E zsxPgOFqdZgC|FmY8o}0CGYh76F}=>ZkT6%;FRmi$v0rrvQ^M>XHY6SD4KtNe8MC*d z!vV&G4SSgDMLB3iC$OHdMT>GQsD$;Ei4gW7YT5N8rgyNL(8<%>@)UMU`%7zcamBjI zk_fx=`0330C2W?b#oQD8gc#7OSd%khi--`*BOWPS7*bZkKsF?nzAWmQk0-q;FowTc zmtmb?Y_4j<9#NZ1j%mS0GPEQ1Fk{%V*hHmukYoLZnQ+9==3q3tm>pR> z!RQp`*sx*FiybjW$8pH9$q3eg$}r`o0(;53jhF;vvts;}BX(fjA;y9hSYLRDPOu>) z7x*+L?#-UWlwd6AQgOFSHkb(d6lVC;&#SY45_9pBu;eQ@%#k;q z%P5PdKKaTOBPn;Vo7D*>49y08S%cjspXZY5DM=b~kECb9?vj^UF^vCnfek>|8ps4w z4-pSqff=|FEN0jv0x;yh*NP8G5h`IMk9}WakAgvt;qI8bJT8c z;BAS;6n<;$`xImti$jpx%bJvTXL#XdTHgz2}|z1z~&ZHD~1k#R1z1$4(3wGigd7dFiocAQ%XRN z6#q_N>tgnel3eC zLHk9DG)e~{WjRfGiYkpReS6bZQz(+IKEj4AThUnys_f(X5=q2dTL5MSA9!Vx>uSo$ zV`U3#aw&CfBWQPAi-GA_oO;z3?6MZlLDR-9dkqZ7M#ed4dVDPb$1gd`{TiTmB#@Ia z2zD%qeZ6f{G80_pvgL>M(v(Z|xOHB-op-K18meKt`BcwDsn65CsN`T;7v7BN(|SpN zJ-5@&<2=seJkH~H8Qk#k&tlZt(Bre1#lYN;P2_CCGe%F7g~%^XT%=%bVM7zH>*1-g z%COg`78kobL$oKPHcOFj+7nU_%V3u}G1=MQ5NE>?i+CaY4Q&=3b{KPJ&uz%*5 zfm7IbdGXkTKY<j{g-sXa;4_d$`7n>GjR`yN^9=Mz3r+_*g+Z3^(bba7l_@DR8B&9%l8#x zFGWJce!!>yGUDcS&=;-2pAdV+ZE$s<^!cp=k9n|$qNdc}BKA4=rqqSOA~bTf7kYS~ zt8E}jF{?C>i@NAx9%dBP-QmxFIl<7IEI)#y`SC{?gZ^dc~N3fwnu$ zny^K|hg<|ej5q%t#uv&U)**I7EvJ}QA2)Dd1q9p##t?AdQ``DF$8baFn3&+g5&M88 zpU+kA9^pWmH^F948>I=Tp4ONCtHJ2V5VqvlypPSwL~_q778-1j<81H& zZ#Qh(#n2(p^}-Pw8>~NK%QKi+eoJg%ta}R6gu#D;-zlFUtc6_wQh|)S>_JJ#}gDjE13u`>Aepyn~-D^d26~ zM+*yL@lvDHtQ#F2L+<2=seJpT9b YD`1U&!|k(<9RL6T07*qoM6N<$f&vFYZ2$lO literal 0 HcmV?d00001 From cc9f9cce4d361fe470dc719e2615221aac6a46f3 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Tue, 6 Aug 2013 11:53:44 -0300 Subject: [PATCH 04/24] Added LuaJIT profiling support (lulip), better cmdline option handling. --- frontend/lulip.lua | 190 +++++++++++++++++++++++++++++++++++++++++++++ koreader.sh | 2 +- koreader_kobo.sh | 2 +- reader.lua | 43 ++++++++-- 4 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 frontend/lulip.lua diff --git a/frontend/lulip.lua b/frontend/lulip.lua new file mode 100644 index 000000000..aee1c65a5 --- /dev/null +++ b/frontend/lulip.lua @@ -0,0 +1,190 @@ +-- lulip: LuaJIT line level profiler +-- +-- Copyright (c) 2013 John Graham-Cumming +-- +-- License: http://opensource.org/licenses/MIT + +local io_lines = io.lines +local io_open = io.open +local pairs = pairs +local print = print +local debug = debug +local tonumber = tonumber +local setmetatable = setmetatable +local table_sort = table.sort +local table_insert = table.insert +local string_find = string.find +local string_sub = string.sub +local string_gsub = string.gsub +local string_format = string.format +local ffi = require("ffi") + +ffi.cdef[[ + typedef long time_t; + + typedef struct timeval { + time_t tv_sec; + time_t tv_usec; + } timeval; + + int gettimeofday(struct timeval* t, void* tzp); +]] + +module(...) + +local gettimeofday_struct = ffi.new("timeval") +local function gettimeofday() + ffi.C.gettimeofday(gettimeofday_struct, nil) + return tonumber(gettimeofday_struct.tv_sec) * 1000000 + tonumber(gettimeofday_struct.tv_usec) +end + +local mt = { __index = _M } + +-- new: create new profiler object +function new(self) + return setmetatable({ + + -- Time when start() and stop() were called in microseconds + + start_time = 0, + stop_time = 0, + + -- Per line timing information + + lines = {}, + + -- The current line being processed and when it was startd + + current_line = nil, + current_start = 0, + + -- List of files to ignore. Set patterns using dont() + + ignore = {}, + + -- List of short file names used as a cache + + short = {}, + + -- Maximum number of rows of output data, set using maxrows() + + rows = 20, + }, mt) +end + +-- event: called when a line is executed +function event(self, event, line) + local now = gettimeofday() + + local f = string_sub(debug.getinfo(3).source,2) + for i=1,#self.ignore do + if string_find(f, self.ignore[i], 1, true) then + return + end + end + + local short = self.short[f] + if not short then + local start = string_find(f, "[^/]+$") + self.short[f] = string_sub(f, start) + short = self.short[f] + end + + if self.current_line ~= nil then + self.lines[self.current_line][1] = + self.lines[self.current_line][1] + 1 + self.lines[self.current_line][2] = + self.lines[self.current_line][2] + (now - self.current_start) + end + + self.current_line = short .. ':' .. line + + if self.lines[self.current_line] == nil then + self.lines[self.current_line] = {0, 0.0, f} + end + + self.current_start = gettimeofday() +end + +-- dont: tell the profiler to ignore files that match these patterns +function dont(self, file) + table_insert(self.ignore, file) +end + +-- maxrows: set the maximum number of rows of output +function maxrows(self, max) + self.rows = max +end + +-- start: begin profiling +function start(self) + self:dont('lulip.lua') + self.start_time = gettimeofday() + self.current_line = nil + self.current_start = 0 + debug.sethook(function(e,l) self:event(e, l) end, "l") +end + +-- stop: end profiling +function stop(self) + self.stop_time = gettimeofday() + debug.sethook() +end + +-- readfile: turn a file into an array for line-level access +local function readfile(file) + local lines = {} + local ln = 1 + for line in io_lines(file) do + lines[ln] = string_gsub(line, "^%s*(.-)%s*$", "%1") + ln = ln + 1 + end + return lines +end + +-- dump: dump profile information to the named file +function dump(self, file) + local t = {} + for l,d in pairs(self.lines) do + table_insert(t, {line=l, data=d}) + end + table_sort(t, function(a,b) return a["data"][2] > b["data"][2] end) + + local files = {} + + local f = io_open(file, "w") + if not f then + print("Failed to open output file " .. file) + return + end + f:write([[ + + + + + + + + + + + +]]) + + for j=1,self.rows do + if not t[j] then break end + local l = t[j]["line"] + local d = t[j]["data"] + if not files[d[3]] then + files[d[3]] = readfile(d[3]) + end + local ln = tonumber(string_sub(l, string_find(l, ":", 1, true)+1)) + f:write(string_format([[ + +]], +l, d[1], d[2]/1000, files[d[3]][ln])) + end + f:write('
file:linecountelapsed (ms)line
%s%i%.3f%s
crash.log +./reader.lua "$@" 2> crash.log # clean up forked process in case the reader crashed killall reader.lua diff --git a/koreader_kobo.sh b/koreader_kobo.sh index 16e7b1dfb..31f0aa257 100644 --- a/koreader_kobo.sh +++ b/koreader_kobo.sh @@ -14,7 +14,7 @@ export STARDICT_DATA_DIR="data/dict" killall nickel # finally call reader -./reader.lua "$1" 2> crash.log +./reader.lua "$@" 2> crash.log # continue with nickel diff --git a/reader.lua b/reader.lua index e90860bab..596b3ba02 100755 --- a/reader.lua +++ b/reader.lua @@ -12,6 +12,7 @@ require "settings" require "dbg" require "gettext" +Profiler = nil HomeMenu = InputContainer:new{ item_table = {}, @@ -33,6 +34,11 @@ HomeMenu = InputContainer:new{ } function exitReader() + if Profiler ~= nil then + Profiler:stop() + Profiler:dump("./profile.html") + end + G_reader_settings:close() input.closeAll() @@ -189,6 +195,7 @@ end -- option parsing: longopts = { debug = "d", + profile = "p", help = "h", } @@ -197,6 +204,7 @@ function showusage() print(_("Read all the books on your E-Ink reader")) print("") print(_("-d start in debug mode")) + print(_("-p [rows] enable Lua code profiling")) print(_("-h show this usage help")) print("") print(_("If you give the name of a directory instead of a file path, a file")) @@ -209,16 +217,37 @@ function showusage() return end -if ARGV[1] == "-h" then - return showusage() -end +DEBUG = function() end local argidx = 1 -if ARGV[1] == "-d" then - Dbg:turnOn() +while argidx <= #ARGV do + local arg = ARGV[argidx] argidx = argidx + 1 -else - DEBUG = function() end + if arg == "--" then break end + -- parse longopts + if arg:sub(1,2) == "--" then + local opt = longopts[arg:sub(3)] + if opt ~= nil then arg = "-"..opt end + end + -- code for each option + if arg == "-h" then + return showusage() + elseif arg == "-d" then + Dbg:turnOn() + elseif arg == "-p" then + require "lulip" + Profiler = lulip:new() + pcall(function() + -- set maxrows only if the optional arg is numeric + Profiler:maxrows(ARGV[argidx] + 0) + argidx = argidx + 1 + end) + Profiler:start() + else + -- not a recognized option, should be a filename + argidx = argidx - 1 + break + end end if Device:hasNoKeyboard() then From fae698102300dd807368a0fe3c9f4e7e1482d81b Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Tue, 6 Aug 2013 14:26:24 -0300 Subject: [PATCH 05/24] Solve conflict with pull req #201 --- koreader_kobo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader_kobo.sh b/koreader_kobo.sh index 31f0aa257..a6ce4f918 100644 --- a/koreader_kobo.sh +++ b/koreader_kobo.sh @@ -14,7 +14,7 @@ export STARDICT_DATA_DIR="data/dict" killall nickel # finally call reader -./reader.lua "$@" 2> crash.log +./reader.lua /mnt/onboard 2> crash.log # continue with nickel From d9b210c315096e7b9eb7845c01d034f561506520 Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Thu, 8 Aug 2013 12:07:40 +0200 Subject: [PATCH 06/24] Changed "koboupdate" to be more reliable as an installation mean. --- Makefile | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 5728bf89c..fb149b127 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ VERSION=$(shell git describe HEAD) # subdirectory we use to build the installation bundle INSTALL_DIR=koreader -INSTALL_DIR_KOBO=mnt/onboard/.kobo/koreader +INSTALL_DIR_KOBO=mnt/onboard/.kobo # subdirectory we use to setup emulation environment EMU_DIR=emu @@ -97,34 +97,36 @@ koboupdate: all file $(KOR_BASE)/extr | grep ARM || exit 1 # remove old package and dir if any rm -f koreader-kobo-$(VERSION).zip - rm -rf $(INSTALL_DIR_KOBO) + rm -rf $(INSTALL_DIR) # create new dir for package - mkdir -p $(INSTALL_DIR_KOBO)/{history,screenshots,clipboard,libs} - cp -p README.md COPYING $(KOR_BASE)/{koreader-base,extr,sdcv} koreader.sh koreader_kobo.sh $(LUA_FILES) $(INSTALL_DIR_KOBO) - $(STRIP) --strip-unneeded $(INSTALL_DIR_KOBO)/koreader-base $(INSTALL_DIR_KOBO)/extr $(INSTALL_DIR_KOBO)/sdcv - mkdir $(INSTALL_DIR_KOBO)/data $(INSTALL_DIR_KOBO)/data/dict $(INSTALL_DIR_KOBO)/data/tessdata + mkdir -p $(INSTALL_DIR)/{history,screenshots,clipboard,libs} + cp -p README.md COPYING $(KOR_BASE)/{koreader-base,extr,sdcv} koreader.sh koreader_kobo.sh $(LUA_FILES) $(INSTALL_DIR) + $(STRIP) --strip-unneeded $(INSTALL_DIR)/koreader-base $(INSTALL_DIR)/extr $(INSTALL_DIR)/sdcv + mkdir $(INSTALL_DIR)/data $(INSTALL_DIR)/data/dict $(INSTALL_DIR)/data/tessdata cp -L koreader-base/$(DJVULIB) $(KOR_BASE)/$(CRELIB) \ $(KOR_BASE)/$(LUALIB) $(KOR_BASE)/$(K2PDFOPTLIB) \ $(KOR_BASE)/$(LEPTONICALIB) $(KOR_BASE)/$(TESSERACTLIB) \ - $(INSTALL_DIR_KOBO)/libs - $(STRIP) --strip-unneeded $(INSTALL_DIR_KOBO)/libs/* - cp -rpL $(KOR_BASE)/data/*.css $(INSTALL_DIR_KOBO)/data - cp -rpL $(KOR_BASE)/data/hyph $(INSTALL_DIR_KOBO)/data/hyph - cp -rpL $(KOR_BASE)/fonts $(INSTALL_DIR_KOBO) - cp -rp $(MO_DIR) $(INSTALL_DIR_KOBO) - rm $(INSTALL_DIR_KOBO)/fonts/droid/DroidSansFallbackFull.ttf + $(INSTALL_DIR)/libs + $(STRIP) --strip-unneeded $(INSTALL_DIR)/libs/* + cp -rpL $(KOR_BASE)/data/*.css $(INSTALL_DIR)/data + cp -rpL $(KOR_BASE)/data/hyph $(INSTALL_DIR)/data/hyph + cp -rpL $(KOR_BASE)/fonts $(INSTALL_DIR) + cp -rp $(MO_DIR) $(INSTALL_DIR) + rm $(INSTALL_DIR)/fonts/droid/DroidSansFallbackFull.ttf echo $(VERSION) > git-rev - cp -r git-rev resources $(INSTALL_DIR_KOBO) - rm -r $(INSTALL_DIR_KOBO)/resources/fonts - cp -rpL frontend $(INSTALL_DIR_KOBO) - cp defaults.lua $(INSTALL_DIR_KOBO) - mkdir $(INSTALL_DIR_KOBO)/fonts/host - cp -rpL fmon $(INSTALL_DIR_KOBO)/.. - cp -p resources/koreader.png $(INSTALL_DIR_KOBO)/../.. + cp -r git-rev resources $(INSTALL_DIR) + rm -r $(INSTALL_DIR)/resources/fonts + cp -rpL frontend $(INSTALL_DIR) + cp defaults.lua $(INSTALL_DIR) + mkdir $(INSTALL_DIR)/fonts/host + mkdir -p $(INSTALL_DIR_KOBO)/fmon + cp -rpL fmon $(INSTALL_DIR_KOBO) + cp -p resources/koreader.png $(INSTALL_DIR_KOBO)/.. tar -zcvf KoboRoot.tgz mnt/ - zip -9 -r koreader-kobo-$(VERSION).zip KoboRoot.tgz + zip -9 -r koreader-kobo-$(VERSION).zip $(INSTALL_DIR) KoboRoot.tgz rm KoboRoot.tgz rm -rf mnt/ + rm -rf $(INSTALL_DIR) pot: $(XGETTEXT_BIN) reader.lua `find frontend -iname "*.lua"` \ From a145ee19aae5c8be1d0db2c50135d86c214099a8 Mon Sep 17 00:00:00 2001 From: Giorgio Micotti Date: Thu, 8 Aug 2013 12:09:43 +0200 Subject: [PATCH 07/24] Add firmware detection for kobo, adjust input accordingly. --- frontend/ui/device.lua | 11 +++++++++++ frontend/ui/inputevent.lua | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 997954401..e16e789a6 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -4,6 +4,7 @@ Device = { survive_screen_saver = false, touch_dev = nil, model = nil, + firmware_rev = nil, } function Device:getModel() @@ -37,6 +38,9 @@ function Device:getModel() local std_out = io.popen("/bin/kobo_config.sh", "r") local codename = std_out:read() self.model = "Kobo_" .. codename + local version_file = io.open("/mnt/onboard/.kobo/version", "r") + self.firmware_rev = string.sub(version_file:read(),24,28) + version_file:close() elseif kt_test_fd then self.model = "KindleTouch" else @@ -53,6 +57,13 @@ function Device:getModel() return self.model end +function Device:getFirmVer() + if not self.model then + self.model = self:getModel() + end + return self.firmware_rev +end + function Device:isKindle4() return (self:getModel() == "Kindle4") end diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index a6bcaee9c..e6c384f9e 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -316,12 +316,14 @@ function Input:init() end print(_("Auto-detected Kindle Touch")) elseif Device:isKobo() then + firm_rev = Device:getFirmVer() input.open("/dev/input/event1") Device:setTouchInputDev("/dev/input/event1") input.open("/dev/input/event0") -- Light button and sleep slider print(_("Auto-detected Kobo")) self:adjustKoboEventMap() - if dev_mod ~= 'Kobo_trilogy' then + if dev_mod ~= 'Kobo_trilogy' and firm_rev == "2.6.1" + or dev_mod == 'Kobo_dragon' then function Input:eventAdjustHook(ev) if ev.type == EV_ABS then if ev.code == ABS_X then @@ -339,6 +341,19 @@ function Input:init() end return ev end + else + function Input:eventAdjustHook(ev) + if ev.code == ABS_X then + -- We always have to substract from the physical x, + -- regardless of the orientation + if (Screen.width Date: Sat, 10 Aug 2013 02:07:01 -0400 Subject: [PATCH 08/24] fix unnecessary frontlight module require --- frontend/ui/widget/menu.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 4b3cbdd86..fc157a2df 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -1,7 +1,6 @@ require "ui/widget/container" require "ui/widget/focusmanager" require "ui/widget/infomessage" -require "ui/widget/frontlight" require "ui/widget/button" require "ui/widget/text" require "ui/widget/group" From aaa646aa56c0e49013019b0072c4877c49bd5a1c Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Sat, 10 Aug 2013 11:16:02 -0300 Subject: [PATCH 09/24] Only assign DEBUG to a no-op function if Dbg.is_on==false --- reader.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/reader.lua b/reader.lua index 596b3ba02..a21cd7c0d 100755 --- a/reader.lua +++ b/reader.lua @@ -217,8 +217,6 @@ function showusage() return end -DEBUG = function() end - local argidx = 1 while argidx <= #ARGV do local arg = ARGV[argidx] @@ -250,6 +248,10 @@ while argidx <= #ARGV do end end +if not Dbg.is_on then + DEBUG = function() end +end + if Device:hasNoKeyboard() then -- remove menu item shortcut for K4 Menu.is_enable_shortcut = false From 82e4863827c76f8f7847ff01fa781f2e5a9f2a26 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 11 Aug 2013 20:04:04 -0400 Subject: [PATCH 10/24] move emu_event to /tmp because virtualbox cannot create fifo file in shared folders --- frontend/ui/inputevent.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index e6c384f9e..a0a3c56f0 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -273,9 +273,9 @@ function Input:init() if util.isEmulated() == 1 then self:initKeyMap() - os.remove("emu_event") - os.execute("mkfifo emu_event") - input.open("emu_event") + os.remove("/tmp/emu_event") + os.execute("mkfifo /tmp/emu_event") + input.open("/tmp/emu_event") -- SDL key codes self.event_map = self.sdl_event_map else From 232d8cd74a44583a8af89c34a59ec632d5818d49 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Sat, 10 Aug 2013 21:00:13 -0300 Subject: [PATCH 11/24] Fix multiple ReaderFrontLight instances, i18n issues, and refactor event handling to follow codebase patterns --- frontend/ui/inputevent.lua | 7 ------ frontend/ui/reader/readerfrontlight.lua | 33 ++++++++++--------------- frontend/ui/reader/readermenu.lua | 8 ------ 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index e6c384f9e..085d71836 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -3,7 +3,6 @@ require "ui/device" require "ui/time" require "ui/gesturedetector" require "ui/geometry" -require "ui/reader/readerfrontlight" -- constants from EV_SYN = 0 @@ -425,12 +424,6 @@ function Input:handleKeyBoardEv(ev) return keycode end - if keycode == "Light" then - if ev.value == EVENT_VALUE_KEY_RELEASE then - ReaderFrontLight:toggle() - end - end - -- handle modifier keys if self.modifiers[keycode] ~= nil then if ev.value == EVENT_VALUE_KEY_PRESS then diff --git a/frontend/ui/reader/readerfrontlight.lua b/frontend/ui/reader/readerfrontlight.lua index 3ab2d2555..2b3b4f82d 100644 --- a/frontend/ui/reader/readerfrontlight.lua +++ b/frontend/ui/reader/readerfrontlight.lua @@ -3,14 +3,15 @@ require "ui/widget/inputdialog" require "ui/device" ReaderFrontLight = InputContainer:new{ - fldial_menu_title = ("Frontlight Settings"), - fl_dialog_title = ("Frontlight Level"), + fldial_menu_title = _("Frontlight settings"), + fl_dialog_title = _("Frontlight Level"), steps = {0,1,2,3,4,5,6,7,8,9,10}, intensity = nil, fl = nil, } function ReaderFrontLight:init() + if not Device:hasFrontlight() then return end local dev_mod = Device:getModel() if dev_mod == "KindlePaperWhite" then require "liblipclua" @@ -31,15 +32,16 @@ function ReaderFrontLight:init() } }, } - end - if Device:isKobo() then + elseif Device:isKobo() then self.fl = kobolight.open() self.intensity = G_reader_settings:readSetting("frontlight_intensity") if not self.intensity then self.intensity = 20 end - self:setIntensity(self.intensity, "Set intensity") + self:setIntensity(self.intensity, _("Set intensity ")) + self.key_events.Toggle = { {"Light"}, doc = _("Toggle light") } end + self.ui.menu:registerToMainMenu(self) end function ReaderFrontLight:onAdjust(arg, ges) @@ -70,13 +72,9 @@ function ReaderFrontLight:setIntensity(intensity, msg) text = msg..intensity, timeout = 1 }) - end - if Device:isKobo() then + elseif Device:isKobo() then intensity = intensity < 1 and 1 or intensity intensity = intensity > 100 and 100 or intensity - if self.fl == nil then - ReaderFrontLight:init() - end if self.fl ~= nil then self.fl:setBrightness(intensity) self.intensity = intensity @@ -85,14 +83,9 @@ function ReaderFrontLight:setIntensity(intensity, msg) return true end -function ReaderFrontLight:toggle() - if Device:isKobo() then - if self.fl == nil then - ReaderFrontLight:init() - end - if self.fl ~= nil then - self.fl:toggle() - end +function ReaderFrontLight:onToggle() + if Device:isKobo() and self.fl ~= nil then + self.fl:toggle() end return true end @@ -111,7 +104,7 @@ function ReaderFrontLight:onShowFlDialog() DEBUG("show fldial dialog") self.fl_dialog = InputDialog:new{ title = self.fl_dialog_title, - input_hint = "(1 - 100)", + input_hint = Device:isKobo() and "(1 - 100)" or "(0 - 24)", buttons = { { { @@ -149,7 +142,7 @@ end function ReaderFrontLight:fldialIntensity() local number = tonumber(self.fl_dialog:getInputText()) if number then - self:setIntensity(number, "Set intensity") + self:setIntensity(number, _("Set intensity ")) end return true end diff --git a/frontend/ui/reader/readermenu.lua b/frontend/ui/reader/readermenu.lua index 35055b663..157c17f3e 100644 --- a/frontend/ui/reader/readermenu.lua +++ b/frontend/ui/reader/readermenu.lua @@ -56,14 +56,6 @@ function ReaderMenu:setUpdateItemTable() for _, widget in pairs(self.registered_widgets) do widget:addToMainMenu(self.tab_item_table) end - if Device:hasFrontlight() then - table.insert(self.tab_item_table.main, { - text = _("Frontlight settings"), - callback = function() - ReaderFrontLight:onShowFlDialog() - end - }) - end table.insert(self.tab_item_table.main, { text = _("Help"), callback = function() From 3f3fba2fdfc2288a75750d90b11ce07d0aab2631 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Mon, 12 Aug 2013 02:11:54 -0300 Subject: [PATCH 12/24] Big refactoring: Device handles frontlight device, ReaderFrontLight now only GUI --- frontend/ui/device.lua | 127 +++++++++++++++++------- frontend/ui/inputevent.lua | 5 + frontend/ui/reader/readerfrontlight.lua | 84 +++++----------- frontend/ui/uimanager.lua | 3 + 4 files changed, 122 insertions(+), 97 deletions(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index e16e789a6..da9d2ed4c 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -5,6 +5,18 @@ Device = { touch_dev = nil, model = nil, firmware_rev = nil, + frontlight = nil, +} + +KindleFrontLight = { + kpw_fl = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity", + intensity = nil, + lipc_handle = nil, +} + +KoboFrontLight = { + intensity = nil, + fl = nil, } function Device:getModel() @@ -25,7 +37,7 @@ function Device:getModel() end if cpu_mod == "MX50" then -- for KPW - local pw_test_fd = lfs.attributes("/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity") + local pw_test_fd = lfs.attributes(KindleFrontLight.kpw_fl) -- for Kobo local kg_test_fd = lfs.attributes("/bin/kobo_config.sh") -- for KT @@ -58,9 +70,7 @@ function Device:getModel() end function Device:getFirmVer() - if not self.model then - self.model = self:getModel() - end + if not self.model then self:getModel() end return self.firmware_rev end @@ -69,40 +79,19 @@ function Device:isKindle4() end function Device:isKindle3() - re_val = os.execute("cat /proc/cpuinfo | grep MX35") - if re_val == 0 then - return true - else - return false - end + return (self:getModel() == "Kindle3") end function Device:isKindle2() - re_val = os.execute("cat /proc/cpuinfo | grep MX3") - if re_val == 0 then - return true - else - return false - end + return (self:getModel() == "Kindle2") end function Device:isKobo() - if not self.model then - self.model = self:getModel() - end - re_val = string.find(self.model,"Kobo_") - if re_val == 1 then - return true - else - return false - end + return string.find(self:getModel(),"Kobo_") == 1 end function Device:hasNoKeyboard() - if not self.model then - self.model = self:getModel() - end - return self:isTouchDevice() or (self.model == "Kindle4") + return self:isTouchDevice() or (self:getModel() == "Kindle4") end function Device:hasKeyboard() @@ -110,17 +99,13 @@ function Device:hasKeyboard() end function Device:isTouchDevice() - if not self.model then - self.model = self:getModel() - end - return (self.model == "KindlePaperWhite") or (self.model == "KindleTouch") or self:isKobo() or util.isEmulated() + local model = self:getModel() + return (model == "KindlePaperWhite") or (model == "KindleTouch") or self:isKobo() or util.isEmulated() end function Device:hasFrontlight() - if not self.model then - self.model = self:getModel() - end - return (self.model == "KindlePaperWhite") or (self.model == "Kobo_dragon") or (self.model == "Kobo_kraken") or (self.model == "Kobo_phoenix") or util.isEmulated() + local model = self:getModel() + return (model == "KindlePaperWhite") or (model == "Kobo_dragon") or (model == "Kobo_kraken") or (model == "Kobo_phoenix") or util.isEmulated() end function Device:setTouchInputDev(dev) @@ -185,3 +170,71 @@ function Device:usbPlugOut() --@TODO signal filemanager for file changes 13.06 2012 (houqp) self.charging_mode = false end + +function Device:getFrontlight() + if self.frontlight ~= nil then + return self.frontlight + elseif self:hasFrontlight() then + if self:getModel() == "KindlePaperWhite" then + self.frontlight = KindleFrontLight + elseif self:isKobo() then + self.frontlight = KoboFrontLight + end + if self.frontlight ~= nil then + self.frontlight:init() + end + end + return self.frontlight +end + +function KindleFrontLight:init() + require "liblipclua" + self.lipc_handle = lipc.init("com.github.koreader") + if self.lipc_handle then + self.intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity") + end +end + +function KindleFrontLight:toggle() + local f = io.open(self.kpw_fl, "r") + local sysint = tonumber(f:read("*all"):match("%d+")) + f:close() + if sysint == 0 then + self:setIntensity(self.intensity) + else + os.execute("echo -n 0 > " .. self.kpw_fl) + end +end + +function KindleFrontLight:setIntensity(intensity) + if self.lipc_handle ~= nil then + intensity = intensity < 0 and 0 or intensity + intensity = intensity > 24 and 24 or intensity + self.intensity = intensity + self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity) + end +end + +function KoboFrontLight:init() + self.fl = kobolight.open() + self.intensity = G_reader_settings:readSetting("frontlight_intensity") + if not self.intensity then + self.intensity = 20 + end + self:setIntensity(self.intensity) +end + +function KoboFrontLight:toggle() + if self.fl ~= nil then + self.fl:toggle() + end +end + +function KoboFrontLight:setIntensity(intensity) + if self.fl ~= nil then + intensity = intensity < 1 and 1 or intensity + intensity = intensity > 100 and 100 or intensity + self.fl:setBrightness(intensity) + self.intensity = intensity + end +end diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index 085d71836..d97d152d3 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -424,6 +424,11 @@ function Input:handleKeyBoardEv(ev) return keycode end + if ev.value == EVENT_VALUE_KEY_RELEASE + and keycode == "Light" then + return keycode + end + -- handle modifier keys if self.modifiers[keycode] ~= nil then if ev.value == EVENT_VALUE_KEY_PRESS then diff --git a/frontend/ui/reader/readerfrontlight.lua b/frontend/ui/reader/readerfrontlight.lua index 2b3b4f82d..7278f06e1 100644 --- a/frontend/ui/reader/readerfrontlight.lua +++ b/frontend/ui/reader/readerfrontlight.lua @@ -3,22 +3,11 @@ require "ui/widget/inputdialog" require "ui/device" ReaderFrontLight = InputContainer:new{ - fldial_menu_title = _("Frontlight settings"), - fl_dialog_title = _("Frontlight Level"), steps = {0,1,2,3,4,5,6,7,8,9,10}, - intensity = nil, - fl = nil, } function ReaderFrontLight:init() - if not Device:hasFrontlight() then return end - local dev_mod = Device:getModel() - if dev_mod == "KindlePaperWhite" then - require "liblipclua" - self.lipc_handle = lipc.init("com.github.koreader") - if self.lipc_handle then - self.intensity = self.lipc_handle:get_int_property("com.lab126.powerd", "flIntensity") - end + if Device:getFrontlight() ~= nil then self.ges_events = { Adjust = { GestureRange:new{ @@ -32,68 +21,37 @@ function ReaderFrontLight:init() } }, } - elseif Device:isKobo() then - self.fl = kobolight.open() - self.intensity = G_reader_settings:readSetting("frontlight_intensity") - if not self.intensity then - self.intensity = 20 - end - self:setIntensity(self.intensity, _("Set intensity ")) - self.key_events.Toggle = { {"Light"}, doc = _("Toggle light") } + self.ui.menu:registerToMainMenu(self) end - self.ui.menu:registerToMainMenu(self) end function ReaderFrontLight:onAdjust(arg, ges) - if self.lipc_handle and self.intensity ~=nil then + local fl = Device.frontlight + if fl.intensity ~= nil then local rel_proportion = ges.distance / Screen:getWidth() local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps] - local msg = "" + local msg = nil if ges.direction == "north" then msg = _("Increase front light intensity to ") - self.intensity = self.intensity + delta_int - self:setIntensity(self.intensity, msg) + fl:setIntensity(fl.intensity + delta_int) elseif ges.direction == "south" then msg = _("Decrease front light intensity to ") - self.intensity = self.intensity - delta_int - self:setIntensity(self.intensity, msg) + fl:setIntensity(fl.intensity - delta_int) end - end - return true -end - -function ReaderFrontLight:setIntensity(intensity, msg) - if self.lipc_handle then - intensity = intensity < 0 and 0 or intensity - intensity = intensity > 24 and 24 or intensity - self.intensity = intensity - self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity) - UIManager:show(Notification:new{ - text = msg..intensity, - timeout = 1 - }) - elseif Device:isKobo() then - intensity = intensity < 1 and 1 or intensity - intensity = intensity > 100 and 100 or intensity - if self.fl ~= nil then - self.fl:setBrightness(intensity) - self.intensity = intensity + if msg ~= nil then + UIManager:show(Notification:new{ + text = msg..fl.intensity, + timeout = 1 + }) end end return true end -function ReaderFrontLight:onToggle() - if Device:isKobo() and self.fl ~= nil then - self.fl:toggle() - end - return true -end - function ReaderFrontLight:addToMainMenu(tab_item_table) -- insert fldial command to main reader menu table.insert(tab_item_table.main, { - text = self.fldial_menu_title, + text = _("Frontlight settings"), callback = function() self:onShowFlDialog() end, @@ -103,10 +61,17 @@ end function ReaderFrontLight:onShowFlDialog() DEBUG("show fldial dialog") self.fl_dialog = InputDialog:new{ - title = self.fl_dialog_title, + title = _("Frontlight Level"), input_hint = Device:isKobo() and "(1 - 100)" or "(0 - 24)", buttons = { { + { + text = _("Toggle"), + enabled = true, + callback = function() + Device.frontlight:toggle() + end, + }, { text = _("Apply"), enabled = true, @@ -135,14 +100,13 @@ end function ReaderFrontLight:close() self.fl_dialog:onClose() - G_reader_settings:saveSetting("frontlight_intensity", self.intensity) + G_reader_settings:saveSetting("frontlight_intensity", Device.frontlight.intensity) UIManager:close(self.fl_dialog) end function ReaderFrontLight:fldialIntensity() local number = tonumber(self.fl_dialog:getInputText()) - if number then - self:setIntensity(number, _("Set intensity ")) + if number ~= nil then + Device.frontlight:setIntensity(number) end - return true end diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index a54560616..68853b053 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -1,6 +1,7 @@ require "ui/geometry" require "ui/device" require "ui/inputevent" +require "ui/widget/container" require "ui/screen" require "debug" require "gettext" @@ -290,6 +291,8 @@ function UIManager:run() Device:usbPlugIn() elseif input_event == "NotCharging" then Device:usbPlugOut() + elseif input_event == "Light" then + Device:getFrontlight():toggle() else self:sendEvent(input_event) end From 81facc2ce9ee321f40e4d83f0a648e71a5babc4d Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Mon, 12 Aug 2013 09:37:41 -0300 Subject: [PATCH 13/24] Refactor min/max handling in BaseFrontLight; use getFrontlight() in ReaderFrontLight for consistency --- frontend/ui/device.lua | 26 +++++++++++++++++-------- frontend/ui/reader/readerfrontlight.lua | 12 ++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index da9d2ed4c..5bfd2a433 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -8,13 +8,17 @@ Device = { frontlight = nil, } +BaseFrontLight = {} + KindleFrontLight = { + min = 0, max = 24, kpw_fl = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity", intensity = nil, lipc_handle = nil, } KoboFrontLight = { + min = 1, max = 100, intensity = nil, fl = nil, } @@ -187,6 +191,12 @@ function Device:getFrontlight() return self.frontlight end +function BaseFrontLight:intensityCheckBounds(intensity) + intensity = intensity < self.min and self.min or intensity + intensity = intensity > self.max and self.max or intensity + self.intensity = intensity +end + function KindleFrontLight:init() require "liblipclua" self.lipc_handle = lipc.init("com.github.koreader") @@ -206,12 +216,12 @@ function KindleFrontLight:toggle() end end +KindleFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds + function KindleFrontLight:setIntensity(intensity) if self.lipc_handle ~= nil then - intensity = intensity < 0 and 0 or intensity - intensity = intensity > 24 and 24 or intensity - self.intensity = intensity - self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", intensity) + self:intensityCheckBounds(intensity) + self.lipc_handle:set_int_property("com.lab126.powerd", "flIntensity", self.intensity) end end @@ -230,11 +240,11 @@ function KoboFrontLight:toggle() end end +KoboFrontLight.intensityCheckBounds = BaseFrontLight.intensityCheckBounds + function KoboFrontLight:setIntensity(intensity) if self.fl ~= nil then - intensity = intensity < 1 and 1 or intensity - intensity = intensity > 100 and 100 or intensity - self.fl:setBrightness(intensity) - self.intensity = intensity + self:intensityCheckBounds(intensity) + self.fl:setBrightness(self.intensity) end end diff --git a/frontend/ui/reader/readerfrontlight.lua b/frontend/ui/reader/readerfrontlight.lua index 7278f06e1..7b60f1ec0 100644 --- a/frontend/ui/reader/readerfrontlight.lua +++ b/frontend/ui/reader/readerfrontlight.lua @@ -26,7 +26,7 @@ function ReaderFrontLight:init() end function ReaderFrontLight:onAdjust(arg, ges) - local fl = Device.frontlight + local fl = Device:getFrontlight() if fl.intensity ~= nil then local rel_proportion = ges.distance / Screen:getWidth() local delta_int = self.steps[math.ceil(#self.steps*rel_proportion)] or self.steps[#self.steps] @@ -59,17 +59,17 @@ function ReaderFrontLight:addToMainMenu(tab_item_table) end function ReaderFrontLight:onShowFlDialog() - DEBUG("show fldial dialog") + local fl = Device:getFrontlight() self.fl_dialog = InputDialog:new{ title = _("Frontlight Level"), - input_hint = Device:isKobo() and "(1 - 100)" or "(0 - 24)", + input_hint = ("(%d - %d)"):format(fl.min, fl.max), buttons = { { { text = _("Toggle"), enabled = true, callback = function() - Device.frontlight:toggle() + fl:toggle() end, }, { @@ -100,13 +100,13 @@ end function ReaderFrontLight:close() self.fl_dialog:onClose() - G_reader_settings:saveSetting("frontlight_intensity", Device.frontlight.intensity) + G_reader_settings:saveSetting("frontlight_intensity", Device:getFrontlight().intensity) UIManager:close(self.fl_dialog) end function ReaderFrontLight:fldialIntensity() local number = tonumber(self.fl_dialog:getInputText()) if number ~= nil then - Device.frontlight:setIntensity(number) + Device:getFrontlight():setIntensity(number) end end From 1c3bf6f2cb54b65efd855de275826b6a1900cdc0 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Mon, 12 Aug 2013 09:41:52 -0300 Subject: [PATCH 14/24] Update koreader-base --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index b5625d48e..2dfda0da6 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit b5625d48e91016b9ac33bf15c9d662d7bcb17bcd +Subproject commit 2dfda0da69b721c0145b174cf3e5fb578c2894e1 From 44258d4ba6bdaff155d06e5a676a6d55a0201be2 Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Mon, 12 Aug 2013 16:41:39 -0300 Subject: [PATCH 15/24] Force initialization of FrontLight in Input:init() to avoid glitches in Kobo --- frontend/ui/inputevent.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index d97d152d3..b5f8d5b65 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -264,6 +264,7 @@ function Input:init() if Device:isTouchDevice() then self:initTouchState() end + Device:getFrontlight() -- forces initialization -- set up fake event map self.event_map[10000] = "IntoSS" -- go into screen saver self.event_map[10001] = "OutOfSS" -- go out of screen saver From e45442c1f6affc7dbb0338149e1b52c03f8199dd Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Tue, 13 Aug 2013 13:56:46 -0300 Subject: [PATCH 16/24] Refactor Kobo frontlight_intensity restoration: move to reader.lua --- frontend/ui/device.lua | 8 ++------ frontend/ui/inputevent.lua | 1 - reader.lua | 8 ++++++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 5bfd2a433..2c81231e3 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -19,7 +19,8 @@ KindleFrontLight = { KoboFrontLight = { min = 1, max = 100, - intensity = nil, + intensity = 20, + restore_settings = true, fl = nil, } @@ -227,11 +228,6 @@ end function KoboFrontLight:init() self.fl = kobolight.open() - self.intensity = G_reader_settings:readSetting("frontlight_intensity") - if not self.intensity then - self.intensity = 20 - end - self:setIntensity(self.intensity) end function KoboFrontLight:toggle() diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index 8a81b3afd..eb003e594 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -264,7 +264,6 @@ function Input:init() if Device:isTouchDevice() then self:initTouchState() end - Device:getFrontlight() -- forces initialization -- set up fake event map self.event_map[10000] = "IntoSS" -- go into screen saver self.event_map[10001] = "OutOfSS" -- go out of screen saver diff --git a/reader.lua b/reader.lua index a21cd7c0d..8da196131 100755 --- a/reader.lua +++ b/reader.lua @@ -269,6 +269,14 @@ local last_file = G_reader_settings:readSetting("lastfile") --@TODO we can read version here, refer to commit in master tree: (houqp) --87712cf0e43fed624f8a9f610be42b1fe174b9fe +do + local fl = Device:getFrontlight() + if fl.restore_settings then + local intensity = G_reader_settings:readSetting("frontlight_intensity") + intensity = intensity or fl.intensity + fl:setIntensity(intensity) + end +end if ARGV[argidx] and ARGV[argidx] ~= "" then if lfs.attributes(ARGV[argidx], "mode") == "directory" then From b49a3381211a607c480a64850a6fe59b4b6da8e1 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 05:17:25 -0400 Subject: [PATCH 17/24] add extend method to widget --- frontend/ui/widget/base.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/ui/widget/base.lua b/frontend/ui/widget/base.lua index 6d4d85cb4..b66b6e49d 100644 --- a/frontend/ui/widget/base.lua +++ b/frontend/ui/widget/base.lua @@ -43,10 +43,24 @@ rather than class variables. --]] Widget = EventListener:new() -function Widget:new(o) +--[[ +Use this method to define a class that's inherited from current class. +It only setup the metabale (or prototype chain) and will not initiatie +a real instance, i.e. call self:init() +--]] +function Widget:extend(o) local o = o or {} setmetatable(o, self) self.__index = self + return o +end + +--[[ +Use this method to initiatie a instance of a class, don't use it for class +definition. +--]] +function Widget:new(o) + o = self:extend(o) -- Both o._init and o.init are called on object create. But o._init is used -- for base widget initialization (basic component used to build other -- widgets). While o.init is for higher level widgets, for example Menu From c66429c903a846b2350e057b89bc5b250bb67660 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 05:18:09 -0400 Subject: [PATCH 18/24] add is_popout and no_title to menu widget --- frontend/ui/widget/menu.lua | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index fc157a2df..41649daed 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -238,6 +238,9 @@ Menu = FocusManager:new{ -- set this to true to not paint as popup menu is_borderless = false, + -- if you want to embed the menu widget into another widget, set + -- this to false + is_popout = true, -- set this to true to add close button has_close_button = true, -- close_callback is a function, which is executed when menu is closed @@ -260,7 +263,7 @@ function Menu:_recalculateDimen() -- we need to substract border, margin and padding self.item_dimen.w = self.item_dimen.w - 14 end - self.perpage = math.floor(self.dimen.h / self.item_dimen.h) - 2 + self.perpage = math.floor((self.dimen.h - self.dimen.x) / self.item_dimen.h) - 2 self.page_num = math.ceil(#self.item_table / self.perpage) end @@ -310,12 +313,15 @@ function Menu:init() self.page_info_text, self.page_info_right_chev } + -- group for menu layout local content = VerticalGroup:new{ - self.title_bar, self.item_group, self.page_info, } + if not self.no_title then + table.insert(content, 1, self.title_bar) + end -- maintain reference to content so we can change it later self.content_group = content @@ -348,16 +354,19 @@ function Menu:init() menu = self, }) end - self.ges_events.TapCloseAllMenus = { - GestureRange:new{ - ges = "tap", - range = Geom:new{ - x = 0, y = 0, - w = Screen:getWidth(), - h = Screen:getHeight(), + -- watch for outer region if it's a self contained widget + if self.is_popout then + self.ges_events.TapCloseAllMenus = { + GestureRange:new{ + ges = "tap", + range = Geom:new{ + x = 0, y = 0, + w = Screen:getWidth(), + h = Screen:getHeight(), + } } } - } + end self.ges_events.Swipe = { GestureRange:new{ ges = "swipe", @@ -399,6 +408,11 @@ function Menu:updateItems(select_number) self.content_group:resetLayout() self:_recalculateDimen() + -- default to select the first item + if not select_number then + select_number = 1 + end + for c = 1, self.perpage do -- calculate index in item_table local i = (self.page - 1) * self.perpage + c From aef2c4123eb07a9394226df8c0b7108725aaedc8 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 05:19:01 -0400 Subject: [PATCH 19/24] fix Menu widget initialization on inheritance bug in filechooser --- frontend/ui/widget/filechooser.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 38d70bbff..fc17fd1fd 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -1,8 +1,9 @@ require "ui/widget/menu" -FileChooser = Menu:new{ +FileChooser = Menu:extend{ height = Screen:getHeight(), width = Screen:getWidth(), + no_title = true, path = lfs.currentdir(), parent = nil, show_hidden = false, @@ -10,7 +11,8 @@ FileChooser = Menu:new{ } function FileChooser:init() - self:changeToPath(self.path) + self:updateItemTableFromPath(self.path) + Menu.init(self) -- call parent's init() end function FileChooser:compressPath(item_path) @@ -22,11 +24,12 @@ function FileChooser:compressPath(item_path) return path end -function FileChooser:changeToPath(path) +function FileChooser:updateItemTableFromPath(path) path = self:compressPath(path) local dirs = {} local files = {} self.path = path + for f in lfs.dir(self.path) do if self.show_hidden or not string.match(f, "^%.[^.]") then local filename = self.path.."/"..f @@ -53,15 +56,16 @@ function FileChooser:changeToPath(path) for _, file in ipairs(files) do table.insert(self.item_table, { text = file, path = self.path.."/"..file }) end +end - Menu.init(self) -- call parent's init() +function FileChooser:changeToPath(path) + self:updateItemTableFromPath(path) + self:updateItems(1) end function FileChooser:onMenuSelect(item) if lfs.attributes(item.path, "mode") == "directory" then - UIManager:close(self) self:changeToPath(item.path) - UIManager:show(self) else self:onFileSelect(item.path) end From caf7ebb9aec04b71af8c1ce7a45d622b3a2f0712 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 05:29:05 -0400 Subject: [PATCH 20/24] bug fix & rewrite filemanager --- frontend/apps/filemanager/fm.lua | 88 +++++++++++++++ frontend/apps/filemanager/fmhistory.lua | 73 +++++++++++++ frontend/apps/filemanager/fmmenu.lua | 131 ++++++++++++++++++++++ reader.lua | 137 ++---------------------- 4 files changed, 303 insertions(+), 126 deletions(-) create mode 100644 frontend/apps/filemanager/fm.lua create mode 100644 frontend/apps/filemanager/fmhistory.lua create mode 100644 frontend/apps/filemanager/fmmenu.lua diff --git a/frontend/apps/filemanager/fm.lua b/frontend/apps/filemanager/fm.lua new file mode 100644 index 000000000..ee1aae36e --- /dev/null +++ b/frontend/apps/filemanager/fm.lua @@ -0,0 +1,88 @@ +require "ui/widget/filechooser" +require "apps/filemanager/fmhistory" +require "apps/filemanager/fmmenu" + + +FileManager = InputContainer:extend{ + title = _("FileManager"), + width = Screen:getWidth(), + height = Screen:getHeight(), + root_path = './', + -- our own size + dimen = Geom:new{ w = 400, h = 600 }, + onExit = function() end, +} + +function FileManager:init() + local exclude_dirs = {"%.sdr$"} + + self.show_parent = self.show_parent or self + + local file_chooser = FileChooser:new{ + _name = 'fuck', + is_popout = false, + is_borderless = true, + has_close_button = true, + dir_filter = function(dirname) + for _, pattern in ipairs(exclude_dirs) do + if dirname:match(pattern) then return end + end + return true + end, + file_filter = function(filename) + if DocumentRegistry:getProvider(filename) then + return true + end + end + } + + function file_chooser:onFileSelect(file) + showReaderUI(file) + return true + end + + self.banner = FrameContainer:new{ + padding = 0, + bordersize = 0, + TextWidget:new{ + face = Font:getFace("tfont", 24), + text = self.title, + } + } + + self.layout = VerticalGroup:new{ + _name = 'fm', + self.banner, + file_chooser, + } + + local fm_ui = FrameContainer:new{ + padding = 0, + bordersize = 0, + padding = self.padding, + background = 0, + self.layout, + } + + self[1] = fm_ui + + self.menu = FileManagerMenu:new{ + ui = self + } + table.insert(self, self.menu) + table.insert(self, FileManagerHistory:new{ + ui = self, + menu = self.menu + }) + + self:handleEvent(Event:new("SetDimensions", self.dimen)) +end + + +function FileManager:onClose() + UIManager:close(self) + if self.onExit then + self:onExit() + end + return true +end diff --git a/frontend/apps/filemanager/fmhistory.lua b/frontend/apps/filemanager/fmhistory.lua new file mode 100644 index 000000000..2b9dcb265 --- /dev/null +++ b/frontend/apps/filemanager/fmhistory.lua @@ -0,0 +1,73 @@ +FileManagerHistory = InputContainer:extend{ + hist_menu_title = _("History"), +} + +function FileManagerHistory:init() + self.ui.menu:registerToMainMenu(self) +end + +function FileManagerHistory:onSetDimensions(dimen) + self.dimen = dimen +end + +function FileManagerHistory:onShowHist() + self:updateItemTable() + + local menu_container = CenterContainer:new{ + dimen = Screen:getSize(), + } + + local hist_menu = Menu:new{ + title = _("History"), + item_table = self.hist, + ui = self.ui, + width = Screen:getWidth()-50, + height = Screen:getHeight()-50, + show_parent = menu_container, + } + + table.insert(menu_container, hist_menu) + + hist_menu.close_callback = function() + UIManager:close(menu_container) + end + + UIManager:show(menu_container) + return true +end + +function FileManagerHistory:addToMainMenu(tab_item_table) + -- insert table to main reader menu + table.insert(tab_item_table.main, { + text = self.hist_menu_title, + callback = function() + self:onShowHist() + end, + }) +end + +function FileManagerHistory:updateItemTable() + function readHistDir(order_arg, re) + local pipe_out = io.popen("ls "..order_arg.." -1 ./history") + for f in pipe_out:lines() do + table.insert(re, { + dir = DocSettings:getPathFromHistory(f), + name = DocSettings:getNameFromHistory(f), + }) + end + end + + self.hist = {} + local last_files = {} + readHistDir("-c", last_files) + for _,v in pairs(last_files) do + table.insert(self.hist, { + text = v.name, + callback = function() + showReaderUI(v.dir .. "/" .. v.name) + end + }) + end +end + + diff --git a/frontend/apps/filemanager/fmmenu.lua b/frontend/apps/filemanager/fmmenu.lua new file mode 100644 index 000000000..b499fd9b9 --- /dev/null +++ b/frontend/apps/filemanager/fmmenu.lua @@ -0,0 +1,131 @@ +require "ui/widget/menu" +require "ui/widget/touchmenu" + +FileManagerMenu = InputContainer:extend{ + tab_item_table = nil, + registered_widgets = {}, +} + +function FileManagerMenu:init() + self.tab_item_table = { + main = { + icon = "resources/icons/appbar.pokeball.png", + }, + home = { + icon = "resources/icons/appbar.home.png", + callback = function() + UIManager:close(self.menu_container) + self.ui:onClose() + end, + }, + } + self.registered_widgets = {} + + if Device:hasKeyboard() then + self.key_events = { + ShowMenu = { { "Menu" }, doc = _("show menu") }, + } + end +end + +function FileManagerMenu:initGesListener() + self.ges_events = { + TapShowMenu = { + GestureRange:new{ + ges = "tap", + range = Geom:new{ + x = 0, + y = 0, + w = Screen:getWidth()*3/4, + h = Screen:getHeight()/4, + } + } + }, + } +end + +function FileManagerMenu:setUpdateItemTable() + for _, widget in pairs(self.registered_widgets) do + widget:addToMainMenu(self.tab_item_table) + end + + if Device:hasFrontlight() then + table.insert(self.tab_item_table.main, { + text = _("Frontlight settings"), + callback = function() + ReaderFrontLight:onShowFlDialog() + end + }) + end + table.insert(self.tab_item_table.main, { + text = _("Help"), + callback = function() + UIManager:show(InfoMessage:new{ + text = _("Please report bugs to https://github.com/koreader/ koreader/issues, Click at the bottom of the page for more options"), + }) + end + }) +end + +function FileManagerMenu:onShowMenu() + if #self.tab_item_table.main == 0 then + self:setUpdateItemTable() + end + + local menu_container = CenterContainer:new{ + ignore = "height", + dimen = Screen:getSize(), + } + + local main_menu = nil + if Device:isTouchDevice() then + main_menu = TouchMenu:new{ + width = Screen:getWidth(), + tab_item_table = { + self.tab_item_table.main, + self.tab_item_table.home, + }, + show_parent = menu_container, + } + else + main_menu = Menu:new{ + title = _("File manager menu"), + item_table = {}, + width = Screen:getWidth() - 100, + } + + for _,item_table in pairs(self.tab_item_table) do + for k,v in ipairs(item_table) do + table.insert(main_menu.item_table, v) + end + end + end + + main_menu.close_callback = function () + UIManager:close(menu_container) + end + + menu_container[1] = main_menu + -- maintain a reference to menu_container + self.menu_container = menu_container + UIManager:show(menu_container) + + return true +end + +function FileManagerMenu:onTapShowMenu() + self:onShowMenu() + return true +end + +function FileManagerMenu:onSetDimensions(dimen) + -- update listening according to new screen dimen + if Device:isTouchDevice() then + self:initGesListener() + end +end + +function FileManagerMenu:registerToMainMenu(widget) + table.insert(self.registered_widgets, widget) +end + diff --git a/reader.lua b/reader.lua index e90860bab..1687f5b08 100755 --- a/reader.lua +++ b/reader.lua @@ -4,34 +4,15 @@ require "defaults" package.path = "./frontend/?.lua" package.cpath = "/usr/lib/lua/?.so" require "ui/uimanager" -require "ui/widget/filechooser" require "ui/widget/infomessage" require "ui/readerui" require "document/document" require "settings" require "dbg" require "gettext" +require "apps/filemanager/fm" -HomeMenu = InputContainer:new{ - item_table = {}, - key_events = { - TapShowMenu = { {"Home"}, doc = _("Show Home Menu")}, - }, - ges_events = { - TapShowMenu = { - GestureRange:new{ - ges = "tap", - range = Geom:new{ - x = 0, y = 0, - w = Screen:getWidth(), - h = 25, - } - } - }, - }, -} - function exitReader() G_reader_settings:close() @@ -58,70 +39,7 @@ function exitReader() os.exit(0) end -function HomeMenu:setUpdateItemTable() - function readHistDir(order_arg, re) - local pipe_out = io.popen("ls "..order_arg.." -1 ./history") - for f in pipe_out:lines() do - table.insert(re, { - dir = DocSettings:getPathFromHistory(f), - name = DocSettings:getNameFromHistory(f), - }) - end - end - - local hist_sub_item_table = {} - local last_files = {} - readHistDir("-c", last_files) - for _,v in pairs(last_files) do - table.insert(hist_sub_item_table, { - text = v.name, - callback = function() - showReader(v.dir .. "/" .. v.name) - end - }) - end - table.insert(self.item_table, { - text = _("Last documents"), - sub_item_table = hist_sub_item_table, - }) - - table.insert(self.item_table, { - text = _("Exit"), - callback = function() - exitReader() - end - }) -end - -function HomeMenu:onTapShowMenu() - self.item_table = {} - self:setUpdateItemTable() - - local menu_container = CenterContainer:new{ - ignore = "height", - dimen = Screen:getSize(), - } - - local home_menu = Menu:new{ - show_parent = menu_container, - title = _("Home menu"), - item_table = self.item_table, - width = Screen:getWidth() - 100, - } - - menu_container[1] = home_menu - - home_menu.close_callback = function () - UIManager:close(menu_container) - end - - UIManager:show(menu_container) - - return true -end - - -function showReader(file, pass) +function showReaderUI(file, pass) local document = DocumentRegistry:openDocument(file) if not document then UIManager:show(InfoMessage:new{ @@ -141,47 +59,14 @@ function showReader(file, pass) end function showHomePage(path) - local exclude_dirs = {"%.sdr$"} - - local HomePage = InputContainer:new{ - } - - local FileManager = FileChooser:new{ - show_parent = HomePage, - title = _("FileManager"), - path = path, - width = Screen:getWidth(), - height = Screen:getHeight(), - is_borderless = true, - has_close_button = true, - dir_filter = function(dirname) - for _, pattern in ipairs(exclude_dirs) do - if dirname:match(pattern) then return end - end - return true - end, - file_filter = function(filename) - if DocumentRegistry:getProvider(filename) then - return true - end + UIManager:show(FileManager:new{ + dimen = Screen:getSize(), + root_path = path, + onExit = function() + exitReader() + UIManager:quit() end - } - - table.insert(HomePage, FileManager) - table.insert(HomePage, HomeMenu) - - function FileManager:onFileSelect(file) - showReader(file) - return true - end - - function FileManager:onClose() - exitReader() - --UIManager:quit() - return true - end - - UIManager:show(HomePage) + }) end @@ -243,11 +128,11 @@ if ARGV[argidx] and ARGV[argidx] ~= "" then if lfs.attributes(ARGV[argidx], "mode") == "directory" then showHomePage(ARGV[argidx]) elseif lfs.attributes(ARGV[argidx], "mode") == "file" then - showReader(ARGV[argidx]) + showReaderUI(ARGV[argidx]) end UIManager:run() elseif last_file and lfs.attributes(last_file, "mode") == "file" then - showReader(last_file) + showReaderUI(last_file) UIManager:run() else return showusage() From f65ae9a2b5f36aa53a8f6a992f56a34ec4c78812 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 06:34:12 -0400 Subject: [PATCH 21/24] check frontlight before setting intensity --- reader.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reader.lua b/reader.lua index 8da196131..b06ec77a8 100755 --- a/reader.lua +++ b/reader.lua @@ -271,7 +271,7 @@ local last_file = G_reader_settings:readSetting("lastfile") do local fl = Device:getFrontlight() - if fl.restore_settings then + if fl and fl.restore_settings then local intensity = G_reader_settings:readSetting("frontlight_intensity") intensity = intensity or fl.intensity fl:setIntensity(intensity) From ce4d62802864eb8e5829513d639e7c8d5328a9e3 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 06:52:39 -0400 Subject: [PATCH 22/24] only insert frontlight menu item if frontlight is detected --- frontend/ui/readerui.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontend/ui/readerui.lua b/frontend/ui/readerui.lua index 877ccb200..171283245 100644 --- a/frontend/ui/readerui.lua +++ b/frontend/ui/readerui.lua @@ -108,13 +108,12 @@ function ReaderUI:init() } table.insert(self, highlight) -- goto - local goto = ReaderGoto:new{ + table.insert(self, ReaderGoto:new{ dialog = self.dialog, view = self[1], ui = self, document = self.document, - } - table.insert(self, goto) + }) -- dictionary local dict = ReaderDictionary:new{ dialog = self.dialog, @@ -130,13 +129,14 @@ function ReaderUI:init() ui = self } table.insert(self.active_widgets, reader_ss) - -- frontlight controller - local reader_fl = ReaderFrontLight:new{ - dialog = self.dialog, - view = self[1], - ui = self - } - table.insert(self, reader_fl) + if Device:getFrontlight() then + -- frontlight controller + table.insert(self, ReaderFrontLight:new{ + dialog = self.dialog, + view = self[1], + ui = self + }) + end if self.document.info.has_pages then -- for page specific controller From 94e89e8e38e08b533fa80ed71d35a06655edd015 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Wed, 14 Aug 2013 12:13:48 -0400 Subject: [PATCH 23/24] add missing import for group widget in readerview --- frontend/ui/reader/readerview.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/ui/reader/readerview.lua b/frontend/ui/reader/readerview.lua index 1967790a0..b6d1b652d 100644 --- a/frontend/ui/reader/readerview.lua +++ b/frontend/ui/reader/readerview.lua @@ -1,3 +1,4 @@ +require "ui/widget/group" require "ui/reader/readerflip" require "ui/reader/readerfooter" require "ui/reader/readerdogear" From 656f02c7f67949096a538353786079e2a9aa6dfe Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Thu, 15 Aug 2013 08:28:18 +0800 Subject: [PATCH 24/24] fix out-of-bound bug in filemanager --- frontend/apps/filemanager/fm.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/frontend/apps/filemanager/fm.lua b/frontend/apps/filemanager/fm.lua index ee1aae36e..4396f2c00 100644 --- a/frontend/apps/filemanager/fm.lua +++ b/frontend/apps/filemanager/fm.lua @@ -18,8 +18,18 @@ function FileManager:init() self.show_parent = self.show_parent or self + self.banner = FrameContainer:new{ + padding = 0, + bordersize = 0, + TextWidget:new{ + face = Font:getFace("tfont", 24), + text = self.title, + } + } + local file_chooser = FileChooser:new{ - _name = 'fuck', + -- remeber to adjust the height when new item is added to the group + height = Screen:getHeight() - self.banner:getSize().h, is_popout = false, is_borderless = true, has_close_button = true, @@ -41,17 +51,7 @@ function FileManager:init() return true end - self.banner = FrameContainer:new{ - padding = 0, - bordersize = 0, - TextWidget:new{ - face = Font:getFace("tfont", 24), - text = self.title, - } - } - self.layout = VerticalGroup:new{ - _name = 'fm', self.banner, file_chooser, } @@ -59,7 +59,6 @@ function FileManager:init() local fm_ui = FrameContainer:new{ padding = 0, bordersize = 0, - padding = self.padding, background = 0, self.layout, }