Merge pull request #293 from tigran123/master

Cleanup: use util.isEmulated() == 1 instead of looking at KEY_FW_DOWN value.
This commit is contained in:
{Qingping,Dave} Hou
2012-09-18 20:02:52 -07:00
4 changed files with 26 additions and 29 deletions

View File

@@ -55,15 +55,12 @@ function getProperTitleLength(txt,font_face,max_width)
end
function BatteryLevel()
local fn, battery = "/tmp/kindle-battery-info", "?"
-- NuPogodi, 18.05.12: This command seems to work even without Amazon Kindle framework
os.execute("gasgauge-info -s 2> /dev/null > "..fn)
if io.open(fn,"r") then
for lines in io.lines(fn) do battery = " " .. lines end
else
battery = ""
end
return battery
local cmd="gasgauge-info -s 2> /dev/null"
local p = assert(io.popen(cmd, "r"))
local battery = assert(p:read("*a"))
p:close()
return string.gsub(battery, "[\n\r]+", "")
end
function DrawTitle(text,lmargin,y,height,color,font_face)

View File

@@ -217,7 +217,7 @@ function FileHistory:addAllCommands()
function(self)
file_entry = self.result[self.perpage*(self.page-1)+self.current]
local file_to_del = file_entry.dir .. "/" .. file_entry.name
os.execute("rm \""..DocToHistory(file_to_del).."\"")
os.remove(DocToHistory(file_to_del))
-- to avoid showing just deleted file
self:init()
self:setSearchResult(self.keywords)

View File

@@ -30,6 +30,15 @@ function FileInfo:FileSize(size)
end
end
function getUnpackedZipSize(zipfile)
local cmd='unzip -l '..zipfile..' | tail -1 | sed -e "s/^ *\\([0-9][0-9]*\\) *.*/\\1/"'
local p = assert(io.popen(cmd, "r"))
local res = assert(p:read("*a"))
p:close()
res = string.gsub(res, "[\n\r]+", "")
return tonumber(res)
end
function FileInfo:init(path, fname)
self.pathfile = path.."/"..fname
self.result = {}
@@ -45,25 +54,16 @@ function FileInfo:init(path, fname)
info_entry = {dir = "Size", name = FileInfo:FileSize(lfs.attributes(self.pathfile, "size"))}
table.insert(self.result, info_entry)
-- size & filename of unzipped entry for zips
if string.lower(string.match(fname, ".+%.([^.]+)")) == "zip" then
local outfile = "./data/zip_content"
local l, s = 1
os.execute("unzip -l \""..self.pathfile.."\" > "..outfile)
if io.open(outfile, "r") then
for lines in io.lines(outfile) do
if l == 4 then s = lines break else l = l + 1 end
end
if s then
info_entry = { dir = "Unpacked", name = FileInfo:FileSize(tonumber(string.sub(s,1,11))) }
table.insert(self.result, info_entry)
end
--[[ TODO: When the fileentry inside zips is encoded as ANSI (codes 128-255)
any attempt to print such fileentry causes crash by drawing!!! When fileentries
are encoded as UTF8, everything seems fine
info_entry = { dir = "Content", name = string.sub(s,29,-1) }
table.insert(self.result, info_entry) ]]
end
-- total size of all unzipped entries for zips
local match = string.match(fname, ".+%.([^.]+)")
if match and string.lower(match) == "zip" then
info_entry = {dir = "Unpacked", name = FileInfo:FileSize(getUnpackedZipSize(self.pathfile))}
table.insert(self.result, info_entry)
--[[ TODO: When the fileentry inside zips is encoded as ANSI (codes 128-255)
any attempt to print such fileentry causes crash by drawing!!! When fileentries
are encoded as UTF8, everything seems fine
info_entry = { dir = "Content", name = string.sub(s,29,-1) }
table.insert(self.result, info_entry) ]]
end
info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile, "change")}

View File

@@ -67,7 +67,7 @@ function Screen:screenRotate(orien)
end
function Screen:updateRotationMode()
if KEY_FW_DOWN == 116 then -- in EMU mode always set to 0
if util.isEmulated() == 1 then -- in EMU mode always set to 0
self.cur_rotation_mode = 0
else
orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r"))