r17851 by fschmid - PDF-Importer: allow loading of encrypted pdf files.

scribus-commit scribus-commit at lists.scribus.net
Sun Nov 4 17:03:27 UTC 2012


Author: fschmid
Date: Sun Nov  4 17:03:27 2012
New Revision: 17851

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17851
Log:
PDF-Importer: allow loading of encrypted pdf files.

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17851&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp Sun Nov  4 17:03:27 2012
@@ -9,12 +9,14 @@
 #include <QCursor>
 #include <QDrag>
 #include <QFile>
+#include <QInputDialog>
 #include <QList>
 #include <QMimeData>
 #include <QRegExp>
 #include <QStack>
 #include <QDebug>
 #include "slaoutput.h"
+#include <ErrorCodes.h>
 #include <GlobalParams.h>
 #include <ViewerPreferences.h>
 #include <poppler-config.h>
@@ -297,6 +299,7 @@
 	}
 
 	globalParams = new GlobalParams();
+	GooString *userPW = NULL;
 	if (globalParams)
 	{
 		GooString *fname = new GooString(QFile::encodeName(fn).data());
@@ -304,9 +307,37 @@
 		GBool hasOcg = gFalse;
 		QList<OptionalContentGroup*> ocgGroups;
 //		globalParams->setPrintCommands(gTrue);
-		PDFDoc *pdfDoc = new PDFDoc(fname, 0, 0, 0);
+		PDFDoc *pdfDoc = new PDFDoc(fname, NULL, NULL, NULL);
 		if (pdfDoc)
 		{
+			if (pdfDoc->getErrorCode() == errEncrypted)
+			{
+				delete pdfDoc;
+				pdfDoc = NULL;
+				if (progressDialog)
+					progressDialog->hide();
+				qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+				ScribusMainWindow* mw = (m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
+				bool ok;
+				QString text = QInputDialog::getText(mw, tr("Open PDF-File"), tr("Password"), QLineEdit::Normal, "", &ok);
+				if (ok && !text.isEmpty())
+				{
+					fname = new GooString(QFile::encodeName(fn).data());
+					userPW = new GooString(text.toLocal8Bit().data());
+					pdfDoc = new PDFDoc(fname, userPW, userPW, NULL);
+					qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+				}
+				if ((!pdfDoc) || (pdfDoc->getErrorCode() != errNone))
+				{
+					if (progressDialog)
+						progressDialog->close();
+					delete pdfDoc;
+					delete globalParams;
+					return false;
+				}
+				if (progressDialog)
+					progressDialog->show();
+			}
 			if (pdfDoc->isOk())
 			{
 				double hDPI = 72.0;




More information about the scribus-commit mailing list