Commit 92c653cf authored by Enrico Ros's avatar Enrico Ros

Leak fix encrypted document opening.

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=373695
parent 2fb64506
......@@ -81,6 +81,7 @@ More items (first items will enter 'In progress list' first):
-> investigate 'Splash' lack of smoothness at low resolutions (see lines in thumbnails)
-> add search on the toc widget (a prune on type lineedit like in thumbnails widget)
-> goto 'logical' page (usually differs from pdf's page) (req. by Luca Burrelli)
-> use wallet for storing passwords of encrypted files
Done (newest feature comes firts):
-> FIX: Memory manager (free cache if needed, avoid disk swap and oom)
......
......@@ -62,58 +62,36 @@ PDFGenerator::~PDFGenerator()
bool PDFGenerator::loadDocument( const QString & fileName, QValueVector<KPDFPage*> & pagesVector )
{
// create PDFDoc for the given file
GString *filename = new GString( QFile::encodeName( fileName ) );
delete pdfdoc;
pdfdoc = new PDFDoc( filename, 0, 0 );
pdfdoc = new PDFDoc( new GString( QFile::encodeName( fileName ) ), 0, 0 );
// if the file didn't open correctly it might be encrypted, so ask for a pass
if ( !pdfdoc->isOk() )
bool firstTry = true;
while ( !pdfdoc->isOk() && pdfdoc->getErrorCode() == errEncrypted )
{
if ( pdfdoc->getErrorCode() == errEncrypted )
{
bool first, correct;
QString prompt;
QCString pwd;
QString prompt;
if ( firstTry )
prompt = i18n( "Please insert the password to read the document:" );
else
prompt = i18n( "Incorrect password. Try again:" );
firstTry = false;
first = true;
correct = false;
while( !correct )
{
if ( first )
{
prompt = i18n( "Please insert the password to read the document:" );
first = false;
}
else prompt = i18n( "Incorrect password. Try again:" );
if ( KPasswordDialog::getPassword( pwd, prompt ) == KPasswordDialog::Accepted )
{
GString *pwd2;
pwd2 = new GString( pwd.data() );
pdfdoc = new PDFDoc( filename, pwd2, pwd2 );
delete pwd2;
correct = pdfdoc->isOk();
if ( !correct && pdfdoc->getErrorCode() != errEncrypted )
{
delete pdfdoc;
pdfdoc = 0;
return false;
}
}
else
{
delete pdfdoc;
pdfdoc = 0;
return false;
}
}
}
QCString pwd;
if ( KPasswordDialog::getPassword( pwd, prompt ) != KPasswordDialog::Accepted )
break;
else
{
GString * pwd2 = new GString( pwd.data() );
delete pdfdoc;
pdfdoc = 0;
return false;
pdfdoc = new PDFDoc( new GString( QFile::encodeName( fileName ) ), pwd2, pwd2 );
delete pwd2;
}
}
if ( !pdfdoc->isOk() )
{
delete pdfdoc;
pdfdoc = 0;
return false;
}
// initialize output device for rendering current pdf
kpdfOutputDev->startDoc( pdfdoc->getXRef() );
......
......@@ -22,6 +22,7 @@
class PDFDoc;
class GList;
class KPDFOutputDev;
class PDFGeneratorThread;
/**
* @short A generator that builds contents from a PDF document.
......@@ -68,13 +69,18 @@ class PDFGenerator : public Generator
// private function for creating the document synopsis hieracy
void addSynopsisChildren( QDomNode * parent, GList * items );
// private classes
// xpdf dependant stuff
QMutex docLock;
PDFDoc * pdfdoc;
KPDFOutputDev * kpdfOutputDev;
QColor paperColor;
// asyncronous generation related things
PDFGeneratorThread * generatorThread;
PixmapRequest * requestOnThread;
QValueList< PixmapRequest * > requestsQueue;
// misc variables for document info and synopsis caching
bool docInfoDirty;
DocumentInfo docInfo;
bool docSynopsisDirty;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment