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
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 "")
if self.doc ~= nil then
self.settings = DocSettings:open(filename)
self:clearcache()
return true
end
return false
end
-- set viewer state according to zoom state
@ -275,8 +269,14 @@ function PDFReader:inputloop()
self:goto(self.pageno - 1)
end
elseif ev.code == KEY_BACK then
self.settings:savesetting("last_page", self.pageno)
self.settings:close()
self:clearcache()
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
elseif ev.code == KEY_VPLUS then
self:modify_gamma( 1.25 )

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

Loading…
Cancel
Save