Skip to content

Commit

Permalink
mod: add closePage and demo for filechooser
Browse files Browse the repository at this point in the history
  • Loading branch information
houqp committed Mar 3, 2012
1 parent 4a1a523 commit e258371
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
8 changes: 4 additions & 4 deletions djvu.c
Expand Up @@ -265,10 +265,10 @@ static int getPageSize(lua_State *L) {

static int closePage(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
/*if(page->page != NULL) {*/
/*pdf_free_page(page->doc->xref, page->page);*/
/*page->page = NULL;*/
/*}*/
if(page->page_ref != NULL) {
ddjvu_page_release(page->page_ref);
page->page_ref = NULL;
}
return 0;
}

Expand Down
34 changes: 13 additions & 21 deletions djvureader.lua
Expand Up @@ -334,30 +334,27 @@ end
function DJVUReader:inputloop()
while 1 do
local ev = input.waitForEvent()
ev.code = adjustKeyEvents(ev)
if ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_PRESS then
local secs, usecs = util.gettime()
if ev.code == KEY_SHIFT then
self.shiftmode = true
elseif ev.code == KEY_ALT then
self.altmode = true
elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then
if self.shiftmode then
if ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then
if Keys.shiftmode then
self:setglobalzoom(self.globalzoom + 0.2)
elseif self.altmode then
elseif Keys.altmode then
self:setglobalzoom(self.globalzoom + 0.1)
else
self:goto(self.pageno + 1)
end
elseif ev.code == KEY_PGBCK or ev.code == KEY_LPGBCK then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoom(self.globalzoom - 0.2)
elseif self.altmode then
elseif Keys.altmode then
self:setglobalzoom(self.globalzoom - 0.1)
else
self:goto(self.pageno - 1)
end
elseif ev.code == KEY_BACK then
if self.altmode then
if Keys.altmode then
-- altmode, exit djvureader
self:clearcache()
if self.doc ~= nil then
Expand All @@ -380,19 +377,19 @@ function DJVUReader:inputloop()
elseif ev.code == KEY_VMINUS then
self:modify_gamma( 0.8 )
elseif ev.code == KEY_A then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE)
end
elseif ev.code == KEY_S then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_WIDTH)
end
elseif ev.code == KEY_D then
if self.shiftmode then
if Keys.shiftmode then
self:setglobalzoommode(self.ZOOM_FIT_TO_CONTENT_HEIGHT)
else
self:setglobalzoommode(self.ZOOM_FIT_TO_PAGE_HEIGHT)
Expand All @@ -411,10 +408,10 @@ function DJVUReader:inputloop()
local x
local y
if self.shiftmode then -- shift always moves in small steps
if Keys.shiftmode then -- shift always moves in small steps
x = self.shift_x / 2
y = self.shift_y / 2
elseif self.altmode then
elseif Keys.altmode then
x = self.shift_x / 5
y = self.shift_y / 5
elseif self.pan_by_page then
Expand Down Expand Up @@ -450,7 +447,7 @@ function DJVUReader:inputloop()
self.offset_y = self.min_offset_y
end
elseif ev.code == KEY_FW_PRESS then
if self.shiftmode then
if Keys.shiftmode then
self.offset_x = 0
self.offset_y = 0
else
Expand All @@ -466,11 +463,6 @@ function DJVUReader:inputloop()
local nsecs, nusecs = util.gettime()
local dur = (nsecs - secs) * 1000000 + nusecs - usecs
print("E: T="..ev.type.." V="..ev.value.." C="..ev.code.." DUR="..dur)
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_SHIFT then
print "shift haha"
self.shiftmode = false
elseif ev.type == EV_KEY and ev.value == EVENT_VALUE_KEY_RELEASE and ev.code == KEY_ALT then
self.altmode = false
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion filechooser.lua
Expand Up @@ -41,7 +41,9 @@ function FileChooser:readdir()
for f in lfs.dir(self.path) do
if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then
table.insert(self.dirs, f)
elseif string.match(f, ".+%.[pP][dD][fF]$") then
--elseif string.match(f, ".+%.[pP][dD][fF]$") or string.match(f, ".+%.[dD][jJ][vV][uU]$")then
--@TODO search for all files 03.03 2012
elseif string.match(f, ".+%.[dD][jJ][vV][uU]$")then
table.insert(self.files, f)
end
end
Expand Down
23 changes: 19 additions & 4 deletions reader.lua
Expand Up @@ -93,9 +93,25 @@ if r_cfont ~=nil then
FontChooser.cfont = r_cfont
end

DJVUReader:open("/home/dave/documents/code/kindle/djvu/test-djvu/test.djvu")
DJVUReader:goto(1)
DJVUReader:inputloop()
if lfs.attributes(ARGV[optind], "mode") == "directory" then
local running = true
FileChooser:setPath(ARGV[optind])
while running do
local pdffile = FileChooser:choose(0,height)
if pdffile ~= nil then
if DJVUReader:open(pdffile,"") then
DJVUReader:goto(1)
DJVUReader:inputloop()
end
else
running = false
end
end
else
DJVUReader:open(ARGV[optind], optarg["p"])
DJVUReader:goto(tonumber(optarg["g"]) or tonumber(PDFReader.settings:readsetting("last_page") or 1))
DJVUReader:inputloop()
end


--[[if lfs.attributes(ARGV[optind], "mode") == "directory" then]]
Expand All @@ -122,7 +138,6 @@ DJVUReader:inputloop()
--reader_settings:savesetting("cfont", FontChooser.cfont)
--reader_settings:close()
--input.closeAll()
input.closeAll()
--os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ')
if optarg["d"] ~= "emu" then
Expand Down

0 comments on commit e258371

Please sign in to comment.