mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
factored out settings into own class
also started using OO paradigm
This commit is contained in:
38
settings.lua
Normal file
38
settings.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
DocSettings = {}
|
||||
DocSettings_mt = { __index = DocSettings }
|
||||
|
||||
function DocSettings:open(docfile)
|
||||
local new = {}
|
||||
new.docdb, errno, errstr = sqlite3.open(docfile..".kpdfview")
|
||||
if new.docdb ~= nil then
|
||||
new.docdb:exec("CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT);")
|
||||
new.stmt_readsetting = new.docdb:prepare("SELECT value FROM settings WHERE key = ?;")
|
||||
new.stmt_savesetting = new.docdb:prepare("INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?);")
|
||||
end
|
||||
return setmetatable(new, DocSettings_mt)
|
||||
end
|
||||
|
||||
function DocSettings:readsetting(key)
|
||||
if self.docdb ~= nil then
|
||||
self.stmt_readsetting:reset()
|
||||
self.stmt_readsetting:bind_values(key)
|
||||
local result = self.stmt_readsetting:step()
|
||||
if result == sqlite3.ROW then
|
||||
return self.stmt_readsetting:get_value(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function DocSettings:savesetting(key, value)
|
||||
if self.docdb ~= nil then
|
||||
self.stmt_savesetting:reset()
|
||||
self.stmt_savesetting:bind_values(key, value)
|
||||
self.stmt_savesetting:step()
|
||||
end
|
||||
end
|
||||
|
||||
function DocSettings:close()
|
||||
if self.docdb ~= nil then
|
||||
self.docdb:close()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user