mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
improved filechooser; enable "single file" mode of kindlepdfviewer
with this mode it's possible to start kindlepdfviewer opening last viewed file, bypassing filechooser
This commit is contained in:
29
reader.lua
29
reader.lua
@@ -39,20 +39,21 @@ function openFile(filename)
|
||||
page_num = DJVUReader.settings:readsetting("last_page") or 1
|
||||
DJVUReader:goto(tonumber(page_num))
|
||||
DJVUReader:inputloop()
|
||||
reader_settings:savesetting("lastfile", filename)
|
||||
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))
|
||||
PDFReader:inputloop()
|
||||
reader_settings:savesetting("lastfile", filename)
|
||||
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,9 +124,10 @@ PDFReader:init()
|
||||
DJVUReader:init()
|
||||
|
||||
-- display directory or open file
|
||||
if lfs.attributes(ARGV[optind], "mode") == "directory" then
|
||||
local patharg = ARGV[optind] or reader_settings:readsetting("lastfile")
|
||||
if patharg and lfs.attributes(patharg, "mode") == "directory" then
|
||||
local running = true
|
||||
FileChooser:setPath(ARGV[optind])
|
||||
FileChooser:setPath(patharg)
|
||||
while running do
|
||||
local file = FileChooser:choose(0,height)
|
||||
if file ~= nil then
|
||||
@@ -127,8 +136,10 @@ if lfs.attributes(ARGV[optind], "mode") == "directory" then
|
||||
running = false
|
||||
end
|
||||
end
|
||||
elseif patharg then
|
||||
openFile(patharg, optarg["p"])
|
||||
else
|
||||
openFile(ARGV[optind], optarg["p"])
|
||||
return showusage()
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user