2013-03-24 14:08:42 +00:00
|
|
|
#!./koreader-base
|
2012-06-11 16:37:58 +00:00
|
|
|
|
2012-06-10 15:38:16 +00:00
|
|
|
package.path = "./frontend/?.lua"
|
2013-04-21 08:49:00 +00:00
|
|
|
package.cpath = "/usr/lib/lua/?.so"
|
2013-03-12 17:18:53 +00:00
|
|
|
require "ui/uimanager"
|
|
|
|
require "ui/widget/filechooser"
|
|
|
|
require "ui/widget/infomessage"
|
2012-06-10 15:38:16 +00:00
|
|
|
require "ui/readerui"
|
|
|
|
require "document/document"
|
2013-03-12 17:18:53 +00:00
|
|
|
require "settings"
|
|
|
|
require "dbg"
|
2013-04-07 08:13:08 +00:00
|
|
|
require "gettext"
|
2013-02-02 19:41:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
HomeMenu = InputContainer:new{
|
|
|
|
item_table = {},
|
2013-03-12 15:28:55 +00:00
|
|
|
key_events = {
|
2013-04-08 06:45:04 +00:00
|
|
|
TapShowMenu = { {"Home"}, doc = _("Show Home Menu")},
|
2013-03-12 15:28:55 +00:00
|
|
|
},
|
2013-02-02 19:41:35 +00:00
|
|
|
ges_events = {
|
|
|
|
TapShowMenu = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = 25,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2013-03-16 01:54:49 +00:00
|
|
|
function exitReader()
|
|
|
|
G_reader_settings:close()
|
|
|
|
|
|
|
|
input.closeAll()
|
|
|
|
|
2013-03-17 11:33:59 +00:00
|
|
|
if util.isEmulated() == 0 then
|
2013-03-16 01:54:49 +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
|
2013-03-17 11:33:59 +00:00
|
|
|
if Device:isTouchDevice() and Device.survive_screen_saver then
|
|
|
|
-- hack the swipe to unlock screen
|
|
|
|
local dev = Device:getTouchInputDev()
|
|
|
|
if dev then
|
|
|
|
local width, height = Screen:getWidth(), Screen:getHeight()
|
2013-04-07 08:13:08 +00:00
|
|
|
input.fakeTapInput(dev,
|
2013-03-17 11:33:59 +00:00
|
|
|
math.min(width, height)/2,
|
|
|
|
math.max(width, height)-30
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2013-03-16 01:54:49 +00:00
|
|
|
end
|
2013-04-07 08:13:08 +00:00
|
|
|
|
2013-03-23 09:22:49 +00:00
|
|
|
os.exit(0)
|
2013-03-16 01:54:49 +00:00
|
|
|
end
|
|
|
|
|
2013-02-02 19:41:35 +00:00
|
|
|
function HomeMenu:setUpdateItemTable()
|
2013-03-12 04:51:00 +00:00
|
|
|
function readHistDir(order_arg, re)
|
|
|
|
local pipe_out = io.popen("ls "..order_arg.." -1 ./history")
|
|
|
|
for f in pipe_out:lines() do
|
|
|
|
table.insert(re, {
|
|
|
|
dir = DocSettings:getPathFromHistory(f),
|
|
|
|
name = DocSettings:getNameFromHistory(f),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local hist_sub_item_table = {}
|
|
|
|
local last_files = {}
|
|
|
|
readHistDir("-c", last_files)
|
|
|
|
for _,v in pairs(last_files) do
|
|
|
|
table.insert(hist_sub_item_table, {
|
|
|
|
text = v.name,
|
|
|
|
callback = function()
|
|
|
|
showReader(v.dir .. "/" .. v.name)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
table.insert(self.item_table, {
|
2013-04-07 08:13:08 +00:00
|
|
|
text = _("Last documents"),
|
2013-03-12 04:51:00 +00:00
|
|
|
sub_item_table = hist_sub_item_table,
|
|
|
|
})
|
|
|
|
|
2013-02-02 19:41:35 +00:00
|
|
|
table.insert(self.item_table, {
|
2013-04-07 08:13:08 +00:00
|
|
|
text = _("Exit"),
|
2013-02-02 19:41:35 +00:00
|
|
|
callback = function()
|
2013-03-16 01:54:49 +00:00
|
|
|
exitReader()
|
2013-02-02 19:41:35 +00:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function HomeMenu:onTapShowMenu()
|
2013-03-12 04:51:00 +00:00
|
|
|
self.item_table = {}
|
|
|
|
self:setUpdateItemTable()
|
2013-02-02 19:41:35 +00:00
|
|
|
|
2013-03-16 18:17:42 +00:00
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
ignore = "height",
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
|
|
|
|
2013-02-02 19:41:35 +00:00
|
|
|
local home_menu = Menu:new{
|
2013-03-16 18:17:42 +00:00
|
|
|
show_parent = menu_container,
|
2013-04-07 08:13:08 +00:00
|
|
|
title = _("Home menu"),
|
2013-02-02 19:41:35 +00:00
|
|
|
item_table = self.item_table,
|
|
|
|
width = Screen:getWidth() - 100,
|
|
|
|
}
|
|
|
|
|
2013-03-16 18:17:42 +00:00
|
|
|
menu_container[1] = home_menu
|
|
|
|
|
2013-03-12 17:18:53 +00:00
|
|
|
home_menu.close_callback = function ()
|
2013-02-02 19:41:35 +00:00
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:show(menu_container)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
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
|
2013-04-07 08:13:08 +00:00
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("No reader engine for this file")
|
|
|
|
})
|
2012-06-10 15:38:16 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-03-16 01:54:49 +00:00
|
|
|
G_reader_settings:saveSetting("lastfile", file)
|
2012-06-10 15:38:16 +00:00
|
|
|
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
|
|
|
|
|
2013-02-02 19:41:35 +00:00
|
|
|
function showHomePage(path)
|
2013-02-19 13:30:35 +00:00
|
|
|
local exclude_dirs = {"%.sdr$"}
|
2013-03-16 18:17:42 +00:00
|
|
|
|
|
|
|
local HomePage = InputContainer:new{
|
|
|
|
}
|
|
|
|
|
2012-06-10 15:38:16 +00:00
|
|
|
local FileManager = FileChooser:new{
|
2013-03-16 18:17:42 +00:00
|
|
|
show_parent = HomePage,
|
2013-04-07 08:13:08 +00:00
|
|
|
title = _("FileManager"),
|
2012-06-10 15:38:16 +00:00
|
|
|
path = path,
|
2013-02-02 19:41:35 +00:00
|
|
|
width = Screen:getWidth(),
|
|
|
|
height = Screen:getHeight(),
|
2012-06-12 06:38:52 +00:00
|
|
|
is_borderless = true,
|
2013-04-07 07:22:01 +00:00
|
|
|
has_close_button = true,
|
2013-02-19 13:30:35 +00:00
|
|
|
dir_filter = function(dirname)
|
|
|
|
for _, pattern in ipairs(exclude_dirs) do
|
|
|
|
if dirname:match(pattern) then return end
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end,
|
2013-03-12 17:18:53 +00:00
|
|
|
file_filter = function(filename)
|
2012-06-12 06:38:52 +00:00
|
|
|
if DocumentRegistry:getProvider(filename) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2012-06-10 15:38:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 18:17:42 +00:00
|
|
|
table.insert(HomePage, FileManager)
|
|
|
|
table.insert(HomePage, HomeMenu)
|
2013-02-02 19:41:35 +00:00
|
|
|
|
2012-06-10 15:38:16 +00:00
|
|
|
function FileManager:onFileSelect(file)
|
|
|
|
showReader(file)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManager:onClose()
|
2013-04-07 07:22:01 +00:00
|
|
|
exitReader()
|
2013-02-02 19:41:35 +00:00
|
|
|
--UIManager:quit()
|
2012-06-10 15:38:16 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-02-02 19:41:35 +00:00
|
|
|
UIManager:show(HomePage)
|
2012-06-10 15:38:16 +00:00
|
|
|
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()
|
2013-04-07 08:13:08 +00:00
|
|
|
print(_("usage: ./reader.lua [OPTION] ... path"))
|
|
|
|
print(_("Read all the books on your E-Ink reader"))
|
2012-06-11 16:37:58 +00:00
|
|
|
print("")
|
2013-04-07 08:13:08 +00:00
|
|
|
print(_("-d start in debug mode"))
|
|
|
|
print(_("-h show this usage help"))
|
2012-06-11 16:37:58 +00:00
|
|
|
print("")
|
2013-04-07 08:13:08 +00:00
|
|
|
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"))
|
2012-06-11 16:37:58 +00:00
|
|
|
print("")
|
2013-04-07 08:13:08 +00:00
|
|
|
print(_("If you don't pass any path, the last viewed document will be opened"))
|
2012-06-11 16:37:58 +00:00
|
|
|
print("")
|
2013-04-07 08:13:08 +00:00
|
|
|
print(_("This software is licensed under the GPLv3."))
|
|
|
|
print(_("See http://github.com/koreader/kindlepdfviewer for more info."))
|
2012-06-11 16:37:58 +00:00
|
|
|
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
|
2013-03-12 17:18:53 +00:00
|
|
|
Dbg:turnOn()
|
|
|
|
argidx = argidx + 1
|
2012-11-01 02:02:53 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-03-16 02:12:19 +00:00
|
|
|
if ARGV[argidx] and ARGV[argidx] ~= "" then
|
2012-11-01 02:02:53 +00:00
|
|
|
if lfs.attributes(ARGV[argidx], "mode") == "directory" then
|
2013-02-02 19:41:35 +00:00
|
|
|
showHomePage(ARGV[argidx])
|
2012-11-01 02:02:53 +00:00
|
|
|
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
|
|
|
|
|
2013-03-16 02:02:08 +00:00
|
|
|
exitReader()
|