mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
added exemplary storing of last read page
This commit is contained in:
33
reader.lua
33
reader.lua
@@ -96,6 +96,14 @@ if optarg["G"] ~= nil then
|
||||
end
|
||||
|
||||
doc = pdf.openDocument(ARGV[optind], optarg["p"] or "")
|
||||
docdb, errno, errstr = sqlite3.open(ARGV[optind]..".kpdfview")
|
||||
if docdb == nil then
|
||||
print(errstr)
|
||||
else
|
||||
docdb:exec("CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT);")
|
||||
stmt_readsetting = docdb:prepare("SELECT value FROM settings WHERE key = ?;")
|
||||
stmt_savesetting = docdb:prepare("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?);")
|
||||
end
|
||||
|
||||
print("pdf has "..doc:getPages().." pages.")
|
||||
|
||||
@@ -104,6 +112,25 @@ width, height = fb:getSize()
|
||||
|
||||
nulldc = pdf.newDC()
|
||||
|
||||
function readsetting(key)
|
||||
if docdb ~= nil then
|
||||
stmt_readsetting:reset()
|
||||
stmt_readsetting:bind_values(key)
|
||||
result = stmt_readsetting:step()
|
||||
if result == sqlite3.ROW then
|
||||
return stmt_readsetting:get_value(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function savesetting(key, value)
|
||||
if docdb ~= nil then
|
||||
stmt_savesetting:reset()
|
||||
stmt_savesetting:bind_values(key, value)
|
||||
stmt_savesetting:step()
|
||||
end
|
||||
end
|
||||
|
||||
function setzoom(page, cacheslot)
|
||||
local dc = pdf.newDC()
|
||||
local pwidth, pheight = page:getSize(nulldc)
|
||||
@@ -239,6 +266,10 @@ function mainloop()
|
||||
goto(pageno - 1)
|
||||
end
|
||||
elseif ev.code == KEY_BACK then
|
||||
if docdb ~= nil then
|
||||
savesetting("last_page", pageno)
|
||||
docdb:close()
|
||||
end
|
||||
return
|
||||
elseif ev.code == KEY_VPLUS then
|
||||
modify_gamma( 1.25 )
|
||||
@@ -318,6 +349,6 @@ function mainloop()
|
||||
end
|
||||
end
|
||||
|
||||
goto(tonumber(optarg["g"]) or 1)
|
||||
goto(tonumber(optarg["g"]) or tonumber(readsetting("last_page") or 1))
|
||||
|
||||
mainloop()
|
||||
|
||||
Reference in New Issue
Block a user