summaryrefslogtreecommitdiff
path: root/qt4
diff options
context:
space:
mode:
authorBrad Hards <bradh@frogmouth.net>2005-08-06 01:53:06 +0000
committerBrad Hards <bradh@frogmouth.net>2005-08-06 01:53:06 +0000
commitf43a6f1d1c27c042f5736746c94430083baa4c1d (patch)
treeab9403a29a428b68d5fbd23506e652ecc3fb0a8c /qt4
parent2ec26afaf80864b023899b890b8e229448da9bed (diff)
Add new test code for encrypted files.
Diffstat (limited to 'qt4')
-rw-r--r--qt4/tests/.cvsignore1
-rw-r--r--qt4/tests/Makefile.am7
-rw-r--r--qt4/tests/test-password-qt4.cpp135
3 files changed, 142 insertions, 1 deletions
diff --git a/qt4/tests/.cvsignore b/qt4/tests/.cvsignore
index d98c4247..3629c90b 100644
--- a/qt4/tests/.cvsignore
+++ b/qt4/tests/.cvsignore
@@ -6,6 +6,7 @@ Makefile
Makefile.in
stress-poppler-qt4
test-poppler-qt4
+test-password-qt4
poppler-fonts
check_orientation
check_author
diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am
index 535504ea..6206673c 100644
--- a/qt4/tests/Makefile.am
+++ b/qt4/tests/Makefile.am
@@ -10,7 +10,7 @@ LDADDS = \
$(POPPLER_QT4_LIBS)
noinst_PROGRAMS = test-poppler-qt4 stress-poppler-qt4 \
- poppler-fonts
+ poppler-fonts test-password-qt4
test_poppler_qt4_SOURCES = \
@@ -18,6 +18,11 @@ test_poppler_qt4_SOURCES = \
test_poppler_qt4_LDADD = $(LDADDS)
+test_password_qt4_SOURCES = \
+ test-password-qt4.cpp
+
+test_password_qt4_LDADD = $(LDADDS)
+
poppler_fonts_SOURCES = \
poppler-fonts.cpp
diff --git a/qt4/tests/test-password-qt4.cpp b/qt4/tests/test-password-qt4.cpp
new file mode 100644
index 00000000..2d7a80b0
--- /dev/null
+++ b/qt4/tests/test-password-qt4.cpp
@@ -0,0 +1,135 @@
+#include <stdlib.h>
+#include <QtCore/QtCore>
+#include <QtGui/QtGui>
+#include <ctype.h>
+
+#define UNSTABLE_POPPLER_QT4
+#include <poppler-qt4.h>
+
+class PDFDisplay : public QWidget // picture display widget
+{
+public:
+ PDFDisplay( Poppler::Document *d );
+ ~PDFDisplay();
+protected:
+ void paintEvent( QPaintEvent * );
+ void keyPressEvent( QKeyEvent * );
+private:
+ void display();
+ int m_currentPage;
+ QPixmap *pixmap;
+ Poppler::Document *doc;
+};
+
+PDFDisplay::PDFDisplay( Poppler::Document *d )
+{
+ doc = d;
+ m_currentPage = 0;
+ display();
+}
+
+void PDFDisplay::display()
+{
+ if (doc) {
+ Poppler::Page *page = doc->page(m_currentPage);
+ if (page) {
+ qDebug() << "Displaying page: " << m_currentPage;
+ pixmap = new QPixmap(page->pageSize());
+ page->renderToPixmap(pixmap);
+ update();
+ delete page;
+ }
+ } else {
+ qWarning() << "doc not loaded";
+ }
+}
+
+PDFDisplay::~PDFDisplay()
+{
+ delete doc;
+ delete pixmap;
+}
+
+void PDFDisplay::paintEvent( QPaintEvent *e )
+{
+ QPainter paint( this ); // paint widget
+ if (pixmap) {
+ paint.drawPixmap(0, 0, *pixmap);
+ } else {
+ qWarning() << "no pixmap";
+ }
+}
+
+void PDFDisplay::keyPressEvent( QKeyEvent *e )
+{
+ if (e->key() == Qt::Key_Down)
+ {
+ if (m_currentPage + 1 < doc->numPages())
+ {
+ m_currentPage++;
+ display();
+ }
+ }
+ else if (e->key() == Qt::Key_Up)
+ {
+ if (m_currentPage > 0)
+ {
+ m_currentPage--;
+ display();
+ }
+ }
+ else if (e->key() == Qt::Key_Q)
+ {
+ exit(0);
+ }
+}
+
+int main( int argc, char **argv )
+{
+ QApplication a( argc, argv ); // QApplication required!
+
+ if ( argc != 3)
+ {
+ qWarning() << "usage: test-password-qt4 owner-password filename";
+ exit(1);
+ }
+
+ Poppler::Document *doc = Poppler::Document::load(argv[2], argv[1]);
+ if (!doc)
+ {
+ qWarning() << "doc not loaded";
+ exit(1);
+ }
+
+ // output some meta-data
+ qDebug() << " PDF Version: " << doc->pdfVersion();
+ qDebug() << " Title: " << doc->info("Title");
+ qDebug() << " Subject: " << doc->info("Subject");
+ qDebug() << " Author: " << doc->info("Author");
+ qDebug() << " Key words: " << doc->info("Keywords");
+ qDebug() << " Creator: " << doc->info("Creator");
+ qDebug() << " Producer: " << doc->info("Producer");
+ qDebug() << " Date created: " << doc->date("CreationDate").toString();
+ qDebug() << " Date modified: " << doc->date("ModDate").toString();
+ qDebug() << "Number of pages: " << doc->numPages();
+ qDebug() << " Linearised: " << doc->isLinearized();
+ qDebug() << " Encrypted: " << doc->isEncrypted();
+ qDebug() << " OK to print: " << doc->okToPrint();
+ qDebug() << " OK to copy: " << doc->okToCopy();
+ qDebug() << " OK to change: " << doc->okToChange();
+ qDebug() << "OK to add notes: " << doc->okToAddNotes();
+ qDebug() << " Page mode: " << doc->pageMode();
+ QStringList fontNameList;
+ foreach( Poppler::FontInfo font, doc->fonts() )
+ fontNameList += font.name();
+ qDebug() << " Fonts: " << fontNameList.join( ", " );
+
+ Poppler::Page *page = doc->page(0);
+ qDebug() << " Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
+
+ PDFDisplay test( doc ); // create picture display
+ test.setWindowTitle("Poppler-Qt4 Test");
+ test.show(); // show it
+
+ return a.exec(); // start event loop
+}