Merge pull request #36 from traycold/master

some small bugfix and some improvements (filechooser, "single file mode")
This commit is contained in:
HW
2012-03-05 15:16:53 -08:00
6 changed files with 97 additions and 51 deletions

6
.gitignore vendored
View File

@@ -8,5 +8,11 @@ djvulibre/
luafilesystem/
.reader.kpdfview.lua
kpdfview
djvulibre*
/.cproject
/.project
/.reader.kpdfview
/luafilesystem
/mupdf

View File

@@ -13,6 +13,10 @@ LFSDIR=luafilesystem
CC:=arm-unknown-linux-gnueabi-gcc
CXX:=arm-unknown-linux-gnueabi-g++
ifdef SBOX_UNAME_MACHINE
CC:=gcc
CXX:=g++
endif
HOSTCC:=gcc
HOSTCXX:=g++
@@ -26,18 +30,17 @@ ARM_CFLAGS:=-march=armv6
# in that case.
ifdef EMULATE_READER
CC:=$(HOSTCC)
CXX:=$(HOSTCXX)
EMULATE_READER_W?=824
EMULATE_READER_H?=1200
EMU_CFLAGS?=$(shell sdl-config --cflags)
EMU_CFLAGS+= -DEMULATE_READER \
-DEMULATE_READER_W=$(EMULATE_READER_W) \
-DEMULATE_READER_H=$(EMULATE_READER_H) \
EMU_LDFLAGS?=$(shell sdl-config --libs)
CC:=$(HOSTCC)
CXX:=$(HOSTCXX)
EMULATE_READER_W?=824
EMULATE_READER_H?=1200
EMU_CFLAGS?=$(shell sdl-config --cflags)
EMU_CFLAGS+= -DEMULATE_READER \
-DEMULATE_READER_W=$(EMULATE_READER_W) \
-DEMULATE_READER_H=$(EMULATE_READER_H) \
EMU_LDFLAGS?=$(shell sdl-config --libs)
else
CFLAGS+= $(ARM_CFLAGS)
CFLAGS+= $(ARM_CFLAGS)
endif
# standard includes
@@ -138,7 +141,7 @@ endif
$(LUALIB):
make -C lua/src CC="$(CC)" CFLAGS="$(CFLAGS)" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E" liblua.a
thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIBS) $(DJVULIBS)
thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS)
INSTALL_DIR=kindlepdfviewer

View File

@@ -33,13 +33,37 @@ FileChooser = {
page = 1,
current = 1,
oldcurrent = 0,
exception_message = nil
}
function getAbsolutePath(aPath)
local abs_path
if not aPath then
abs_path = aPath
elseif aPath:match('^//') then
abs_path = aPath:sub(2)
elseif aPath:match('^/') then
abs_path = aPath
elseif #aPath == 0 then
abs_path = '/'
else
local curr_dir = lfs.currentdir()
abs_path = aPath
if lfs.chdir(aPath) then
abs_path = lfs.currentdir()
lfs.chdir(curr_dir)
end
--print("rel: '"..aPath.."' abs:'"..abs_path.."'")
end
return abs_path
end
function FileChooser:readdir()
self.dirs = {}
self.files = {}
for f in lfs.dir(self.path) do
if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then
if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not (f==".." and self.path=="/") and not string.match(f, "^%.[^.]") then
--print(self.path.." -> adding: '"..f.."'")
table.insert(self.dirs, f)
elseif string.match(f, ".+%.[pP][dD][fF]$") or string.match(f, ".+%.[dD][jJ][vV][uU]$") then
table.insert(self.files, f)
@@ -51,15 +75,22 @@ function FileChooser:readdir()
end
function FileChooser:setPath(newPath)
self.path = newPath
self:readdir()
self.items = #self.dirs + #self.files
if self.items == 0 then
return nil
local curr_path = self.path
self.path = getAbsolutePath(newPath)
local readdir_ok, exc = pcall(self.readdir,self)
if(not readdir_ok) then
print("readdir error: "..tostring(exc))
self.exception_message = exc
return self:setPath(curr_path)
else
self.items = #self.dirs + #self.files
if self.items == 0 then
return nil
end
self.page = 1
self.current = 1
return true
end
self.page = 1
self.current = 1
return true
end
function FileChooser:updateFont()
@@ -74,7 +105,7 @@ function FileChooser:updateFont()
end
function FileChooser:choose(ypos, height)
local perpage = math.floor(height / self.spacing) - 1
local perpage = math.floor(height / self.spacing) - 2
local pagedirty = true
local markerdirty = false
@@ -122,8 +153,11 @@ function FileChooser:choose(ypos, height)
renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, self.face, self.fhash, self.files[i-#self.dirs], true)
end
end
renderUtf8Text(fb.bb, 39, ypos + self.spacing * perpage + 32, self.fface, self.ffhash,
"Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true)
renderUtf8Text(fb.bb, 5, ypos + self.spacing * perpage + 42, self.fface, self.ffhash,
"Page "..self.page.." of "..(math.floor(self.items / perpage)+1), true)
local msg = self.exception_message and self.exception_message:match("[^%:]+:%d+: (.*)") or "Path: "..self.path
self.exception_message = nil
renderUtf8Text(fb.bb, 5, ypos + self.spacing * (perpage+1) + 27, self.fface, self.ffhash, msg, true)
markerdirty = true
end
if markerdirty then
@@ -146,7 +180,7 @@ function FileChooser:choose(ypos, height)
end
local ev = input.waitForEvent()
print("key code:"..ev.code)
--print("key code:"..ev.code)
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
if ev.code == KEY_FW_UP then

View File

@@ -2,5 +2,5 @@
echo unlock > /proc/keypad
echo unlock > /proc/fiveway
cd /mnt/us/kindlepdfviewer/
./reader.lua /mnt/us/documents
./reader.lua $1
echo 1 > /proc/eink_fb/update_display

View File

@@ -38,21 +38,22 @@ function openFile(filename)
if DJVUReader:open(filename) then
page_num = DJVUReader.settings:readsetting("last_page") or 1
DJVUReader:goto(tonumber(page_num))
reader_settings:savesetting("lastfile", filename)
return DJVUReader:inputloop()
end
elseif file_type == "pdf" then
if PDFReader:open(filename,"") then -- TODO: query for password
page_num = PDFReader.settings:readsetting("last_page") or 1
PDFReader:goto(tonumber(page_num))
reader_settings:savesetting("lastfile", filename)
return PDFReader:inputloop()
end
end
end
optarg, optind = alt_getopt.get_opts(ARGV, "p:G:hg:d:", longopts)
if optarg["h"] or ARGV[optind] == nil then
print("usage: ./reader.lua [OPTION] ... DOCUMENT.PDF")
print("Read PDFs on your E-Ink reader")
function showusage()
print("usage: ./reader.lua [OPTION] ... path")
print("Read PDFs and DJVUs on your E-Ink reader")
print("")
print("-p, --password=PASSWORD set password for reading PDF document")
print("-g, --goto=page start reading on page")
@@ -63,14 +64,21 @@ if optarg["h"] or ARGV[optind] == nil then
print(" \"emu\" (DXG emulation)")
print("-h, --help show this usage help")
print("")
print("If you give the name of a directory instead of a path, a file")
print("chooser will show up and let you select a PDF file")
print("If you give the name of a directory instead of a file path, a file")
print("chooser will show up and let you select a PDF|DJVU file")
print("")
print("If you don't pass any path, the last viewed document will be opened")
print("")
print("This software is licensed under the GPLv3.")
print("See http://github.com/hwhw/kindlepdfviewer for more info.")
return
end
optarg, optind = alt_getopt.get_opts(ARGV, "p:G:hg:d:", longopts)
if optarg["h"] then
return showusage()
end
if optarg["d"] == "k3" then
-- for now, the only difference is the additional input device
@@ -116,7 +124,8 @@ PDFReader:init()
DJVUReader:init()
-- display directory or open file
if lfs.attributes(ARGV[optind], "mode") == "directory" then
local patharg = reader_settings:readsetting("lastfile")
if ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "directory" then
local running = true
FileChooser:setPath(ARGV[optind])
while running do
@@ -127,8 +136,10 @@ if lfs.attributes(ARGV[optind], "mode") == "directory" then
running = false
end
end
elseif patharg and lfs.attributes(patharg, "mode") == "file" then
openFile(patharg, optarg["p"])
else
openFile(ARGV[optind], optarg["p"])
return showusage()
end

View File

@@ -440,10 +440,16 @@ function UniReader:showTOC()
self:fillTOC()
end
local menu_items = {}
local filtered_toc = {}
local curr_page = -1
-- build menu items
for _k,_v in ipairs(self.toc) do
table.insert(menu_items,
(" "):rep(_v.depth-1)..self:cleanUpTOCTitle(_v.title))
if(_v.page >= curr_page) then
table.insert(menu_items,
(" "):rep(_v.depth-1)..self:cleanUpTOCTitle(_v.title))
table.insert(filtered_toc,_v.page)
curr_page = _v.page
end
end
toc_menu = SelectMenu:new{
menu_title = "Table of Contents",
@@ -452,7 +458,7 @@ function UniReader:showTOC()
}
item_no = toc_menu:choose(0, fb.bb:getHeight())
if item_no then
self:goto(self.toc[item_no].page)
self:goto(filtered_toc[item_no])
else
self:goto(self.pageno)
end
@@ -673,17 +679,3 @@ function UniReader:inputloop()
return keep_running
end