reordered freeing of resources, error handling for doc open

pull/2/merge
HW 13 years ago
parent 78f6fa4530
commit 1af5ce3d04

@ -117,18 +117,12 @@ end
-- open a PDF file and its settings store -- open a PDF file and its settings store
function PDFReader:open(filename, password) function PDFReader:open(filename, password)
if self.doc ~= nil then
self.doc:close()
end
if self.settings ~= nil then
self.settings:close()
end
self.doc = pdf.openDocument(filename, password or "") self.doc = pdf.openDocument(filename, password or "")
if self.doc ~= nil then if self.doc ~= nil then
self.settings = DocSettings:open(filename) self.settings = DocSettings:open(filename)
self:clearcache() return true
end end
return false
end end
-- set viewer state according to zoom state -- set viewer state according to zoom state
@ -275,8 +269,14 @@ function PDFReader:inputloop()
self:goto(self.pageno - 1) self:goto(self.pageno - 1)
end end
elseif ev.code == KEY_BACK then elseif ev.code == KEY_BACK then
self.settings:savesetting("last_page", self.pageno) self:clearcache()
self.settings:close() if self.doc ~= nil then
self.doc:close()
end
if self.settings ~= nil then
self.settings:savesetting("last_page", self.pageno)
self.settings:close()
end
return return
elseif ev.code == KEY_VPLUS then elseif ev.code == KEY_VPLUS then
self:modify_gamma( 1.25 ) self:modify_gamma( 1.25 )

@ -78,9 +78,10 @@ if lfs.attributes(ARGV[optind], "mode") == "directory" then
while running do while running do
local pdffile = FileChooser:choose(0,height) local pdffile = FileChooser:choose(0,height)
if pdffile ~= nil then if pdffile ~= nil then
PDFReader:open(pdffile,"") -- TODO: query for password if PDFReader:open(pdffile,"") then -- TODO: query for password
PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1)) PDFReader:goto(tonumber(PDFReader.settings:readsetting("last_page") or 1))
PDFReader:inputloop() PDFReader:inputloop()
end
else else
running = false running = false
end end

Loading…
Cancel
Save