Commit f340902f authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Add the possibility of opening password protected files

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=348930
parent 81f89096
......@@ -19,6 +19,7 @@ Porting / In progress on the branch (first item comes first):
-> (store observers data into pages?)
Done (sorted by inv.time)
-> added the option to open password protected files (from head)
-> added the TOC from head (missing click and go functionality because it needs link following)
-> added a 'search bar' with prune-as-you-type feature
-> ported Albert's search and implemented case sensitive
......
......@@ -17,9 +17,11 @@
#include <klocale.h>
#include <kfinddialog.h>
#include <kmessagebox.h>
#include <kpassdlg.h>
#include <kstandarddirs.h>
// local includes
#include "ErrorCodes.h"
#include "PDFDoc.h"
#include "QOutputDev.h"
......@@ -101,9 +103,51 @@ bool KPDFDocument::openDocument( const QString & docFile )
if ( !d->pdfdoc->isOk() )
{
delete d->pdfdoc;
d->pdfdoc = 0;
return false;
if (d->pdfdoc->getErrorCode() == errEncrypted)
{
bool first, correct;
QString prompt;
QCString pwd;
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());
d->pdfdoc = new PDFDoc(filename, pwd2, pwd2);
delete pwd2;
correct = d->pdfdoc->isOk();
kdDebug() << correct << " " << (d->pdfdoc->getErrorCode() != errEncrypted) << endl;
if (!correct && d->pdfdoc->getErrorCode() != errEncrypted)
{
delete d->pdfdoc;
d->pdfdoc = 0;
return false;
}
}
else
{
delete d->pdfdoc;
d->pdfdoc = 0;
return false;
}
}
}
else
{
delete d->pdfdoc;
d->pdfdoc = 0;
return false;
}
}
// clear xpdf errors
......
......@@ -23,6 +23,7 @@
#include <qstring.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include "xpdf_errors.h"
......@@ -65,7 +66,8 @@ void CDECL error(int pos, const char *msg, ...) {
emsg += buffer;
if (!errors::exists(emsg))
{
KMessageBox::error(0, emsg);
//KMessageBox::error(0, emsg);
kdDebug() << emsg << endl;
errors::add(emsg);
}
}
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