2012-06-11 16:37:58 +00:00
|
|
|
#!./kpdfview
|
|
|
|
|
2012-06-10 15:38:16 +00:00
|
|
|
package.path = "./frontend/?.lua"
|
|
|
|
require "ui/ui"
|
|
|
|
require "ui/readerui"
|
|
|
|
require "ui/filechooser"
|
2012-06-10 15:52:09 +00:00
|
|
|
require "ui/infomessage"
|
2012-06-10 15:38:16 +00:00
|
|
|
require "document/document"
|
2012-06-11 16:37:58 +00:00
|
|
|
|
|
|
|
function showReader(file, pass)
|
2012-06-12 06:38:52 +00:00
|
|
|
local document = DocumentRegistry:openDocument(file)
|
2012-06-10 15:38:16 +00:00
|
|
|
if not document then
|
|
|
|
UIManager:show(InfoMessage:new{ text = "No reader engine for this file" })
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local reader = ReaderUI:new{
|
|
|
|
dialog = readerwindow,
|
|
|
|
dimen = Screen:getSize(),
|
2012-06-11 16:37:58 +00:00
|
|
|
document = document,
|
|
|
|
password = pass
|
2012-06-10 15:38:16 +00:00
|
|
|
}
|
2012-12-15 01:31:03 +00:00
|
|
|
UIManager:show(reader)
|
2012-06-10 15:38:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function showFileManager(path)
|
|
|
|
local FileManager = FileChooser:new{
|
|
|
|
path = path,
|
|
|
|
dimen = Screen:getSize(),
|
2012-06-12 06:38:52 +00:00
|
|
|
is_borderless = true,
|
|
|
|
filter = function(filename)
|
|
|
|
if DocumentRegistry:getProvider(filename) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2012-06-10 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function FileManager:onFileSelect(file)
|
|
|
|
showReader(file)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManager:onClose()
|
|
|
|
UIManager:quit()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:show(FileManager)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-11 16:37:58 +00:00
|
|
|
|
|
|
|
-- option parsing:
|
|
|
|
longopts = {
|
|
|
|
debug = "d",
|
2012-09-25 12:11:21 +00:00
|
|
|
help = "h",
|
2012-06-11 16:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showusage()
|
|
|
|
print("usage: ./reader.lua [OPTION] ... path")
|
|
|
|
print("Read all the books on your E-Ink reader")
|
|
|
|
print("")
|
2012-11-01 02:02:53 +00:00
|
|
|
print("-d start in debug mode")
|
|
|
|
print("-h show this usage help")
|
2012-06-11 16:37:58 +00:00
|
|
|
print("")
|
|
|
|
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 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
|
|
|
|
|
2012-11-01 02:02:53 +00:00
|
|
|
if ARGV[1] == "-h" then
|
2012-06-11 16:37:58 +00:00
|
|
|
return showusage()
|
|
|
|
end
|
|
|
|
|
2012-11-01 02:02:53 +00:00
|
|
|
local argidx = 1
|
|
|
|
if ARGV[1] == "-d" then
|
|
|
|
argidx = argidx + 1
|
|
|
|
else
|
2012-06-11 16:37:58 +00:00
|
|
|
DEBUG = function() end
|
|
|
|
end
|
|
|
|
|
2012-12-11 00:01:32 +00:00
|
|
|
if Device:hasNoKeyboard() then
|
2012-06-27 08:26:06 +00:00
|
|
|
-- remove menu item shortcut for K4
|
|
|
|
Menu.is_enable_shortcut = false
|
|
|
|
end
|
|
|
|
|
2012-06-12 04:10:44 +00:00
|
|
|
-- set up reader's setting: font
|
|
|
|
G_reader_settings = DocSettings:open(".reader")
|
|
|
|
fontmap = G_reader_settings:readSetting("fontmap")
|
|
|
|
if fontmap ~= nil then
|
|
|
|
Font.fontmap = fontmap
|
|
|
|
end
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
|
|
|
|
2012-06-11 16:37:58 +00:00
|
|
|
Screen:updateRotationMode()
|
|
|
|
Screen.native_rotation_mode = Screen.cur_rotation_mode
|
|
|
|
|
2012-10-09 20:14:09 +00:00
|
|
|
--@TODO we can read version here, refer to commit in master tree: (houqp)
|
|
|
|
--87712cf0e43fed624f8a9f610be42b1fe174b9fe
|
2012-06-11 16:37:58 +00:00
|
|
|
|
|
|
|
|
2012-11-01 02:02:53 +00:00
|
|
|
if ARGV[argidx] then
|
|
|
|
if lfs.attributes(ARGV[argidx], "mode") == "directory" then
|
|
|
|
showFileManager(ARGV[argidx])
|
|
|
|
elseif lfs.attributes(ARGV[argidx], "mode") == "file" then
|
2012-11-04 03:20:28 +00:00
|
|
|
showReader(ARGV[argidx])
|
2012-06-11 16:37:58 +00:00
|
|
|
end
|
|
|
|
UIManager:run()
|
|
|
|
elseif last_file and lfs.attributes(last_file, "mode") == "file" then
|
2012-11-04 03:20:28 +00:00
|
|
|
showReader(last_file)
|
2012-10-02 22:45:45 +00:00
|
|
|
UIManager:run()
|
|
|
|
else
|
|
|
|
return showusage()
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-11 16:37:58 +00:00
|
|
|
-- @TODO dirty workaround, find a way to force native system poll
|
|
|
|
-- screen orientation and upside down mode 09.03 2012
|
2012-06-12 04:13:51 +00:00
|
|
|
Screen:setRotationMode(Screen.native_rotation_mode)
|
2012-06-11 16:37:58 +00:00
|
|
|
|
2012-06-12 14:48:57 +00:00
|
|
|
input.closeAll()
|
2012-06-11 16:37:58 +00:00
|
|
|
if util.isEmulated()==0 then
|
|
|
|
os.execute("killall -cont cvm")
|
2012-12-12 02:02:32 +00:00
|
|
|
if Device:isKindle3() or (Device:getModel() == "KindleDXG") then
|
|
|
|
-- send double menu key press events to trigger screen refresh
|
|
|
|
os.execute("echo 'send 139' > /proc/keypad;echo 'send 139' > /proc/keypad")
|
|
|
|
end
|
2012-06-11 16:37:58 +00:00
|
|
|
end
|