mod: call different reader in reader.lua

call PDFReader or DJVUReader according to filetype
This commit is contained in:
Qingping Hou
2012-03-03 19:51:49 +08:00
parent e258371134
commit 516e32bc46
4 changed files with 77 additions and 104 deletions

View File

@@ -31,6 +31,22 @@ longopts = {
device = "d",
help = "h"
}
function openFile(filename)
local file_type = string.lower(string.match(filename, ".+%.(.+)"))
if file_type == "djvu" then
if DJVUReader:open(filename) then
DJVUReader:goto(tonumber(DJVUReader.settings:readsetting("last_page")) or 1)
DJVUReader:inputloop()
end
elseif file_type == "pdf" then
if PDFReader:open(filename,"") then -- TODO: query for password
PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
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")
@@ -93,50 +109,26 @@ if r_cfont ~=nil then
FontChooser.cfont = r_cfont
end
-- display directory or open file
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
local file = FileChooser:choose(0,height)
if file ~= nil then
openFile(file)
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()
openFile(ARGV[optind], optarg["p"])
end
--[[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 PDFReader:open(pdffile,"") then -- TODO: query for password
--PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
--PDFReader:inputloop()
--end
--else
--running = false
--end
--end
--else
----PDFReader:open(ARGV[optind], optarg["p"])
----PDFReader:goto(tonumber(optarg["g"]) or tonumber(PDFReader.settings:readsetting("last_page") or 1))
----PDFReader:inputloop()
--end
---- save reader settings
--reader_settings:savesetting("cfont", FontChooser.cfont)
--reader_settings:close()
-- save reader settings
reader_settings:savesetting("cfont", FontChooser.cfont)
reader_settings:close()
input.closeAll()
--os.execute('test -e /proc/keypad && echo "send '..KEY_HOME..'" > /proc/keypad ')