diff --git a/core/Makefile.am b/core/Makefile.am index a21198b3a..fe7184480 100644 --- a/core/Makefile.am +++ b/core/Makefile.am @@ -1,10 +1,10 @@ -SUBDIRS = generator_pdf +SUBDIRS = generator_pdf generator_kimgio INCLUDES = -I$(srcdir)/generator_pdf -I$(srcdir)/.. -I$(srcdir)/../xpdf -I$(srcdir)/../xpdf/goo -I$(top_builddir)/kpdf $(all_includes) METASOURCES = AUTO -libkpdfcore_la_LIBADD = ./generator_pdf/libgeneratorpdf.la +libkpdfcore_la_LIBADD = ./generator_pdf/libgeneratorpdf.la ./generator_kimgio/libgeneratorkimgio.la libkpdfcore_la_SOURCES = page.cpp document.cpp link.cpp annotations.cpp \ pagetransition.cpp diff --git a/core/document.cpp b/core/document.cpp index 75465ba0b..e8b8ba28e 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -12,11 +12,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -31,7 +33,8 @@ #include "observer.h" #include "page.h" #include "link.h" -#include "generator_pdf/generator_pdf.h" // PDF generator +#include "generator_pdf/generator_pdf.h" // PDF generator +#include "generator_kimgio/generator_kimgio.h" // Images generator #include "conf/settings.h" // structures used internally by KPDFDocument for local variables storage @@ -51,6 +54,9 @@ class KPDFDocumentPrivate QString docFileName; QString xmlFileName; + // list of the mimetypes 'generator_kimgio' can understand + QStringList kimgioMimes; + // viewport stuff QValueList< DocumentViewport > viewportHistory; QValueList< DocumentViewport >::iterator viewportIterator; @@ -139,15 +145,40 @@ bool KPDFDocument::openDocument( const QString & docFile, const KURL & url ) // create the generator based on the file's mimetype KMimeType::Ptr mime = KMimeType::findByPath( docFile ); - QString mimeName = mime->name(); - if ( mimeName == "application/pdf" || - mimeName == "application/x-pdf" ) + // a.1. check for mimetypes supported by generator_pdf + if ( (*mime).is( "application/pdf" ) || (*mime).is( "application/x-pdf" ) ) generator = new PDFGenerator( this ); -/* else if ( mimeName == "application/postscript" ) - kdError() << "PS generator not available" << endl;*/ - else + // a.2. check for mimetypes supported by generator_kimgio + if ( !generator ) { - kdWarning() << "Unknown mimetype '" << mimeName << "'." << endl; + // build the mimetypes list the first time + if ( d->kimgioMimes.isEmpty() ) + { + KImageIO::registerFormats(); + QStringList list = QImage::inputFormatList(); + QStringList::Iterator it = list.begin(), end = list.end(); + for ( ; it != end; ++it ) + d->kimgioMimes << KMimeType::findByPath( QString("foo.%1").arg(*it), 0, true )->name(); + } + // scan over the list + QStringList::Iterator it = d->kimgioMimes.begin(), end = d->kimgioMimes.end(); + for ( ; it != end; ++it ) + { + kdDebug() << *it << endl; + if ( (*mime).is( *it ) ) + { + generator = new KIMGIOGenerator( this ); + break; + } + } + } + // a.3. no supported mimetype + if ( !generator ) + { + if ( (*mime).is( "application/postscript" ) ) + kdWarning() << "PS generator not available" << endl; + else + kdWarning() << "Unknown mimetype '" << mime->name() << "'." << endl; return false; } @@ -384,6 +415,11 @@ bool KPDFDocument::isAllowed( int flags ) const return generator ? generator->isAllowed( flags ) : false; } +bool KPDFDocument::supportsSearching() const +{ + return generator ? generator->canGenerateTextPage() : false; +} + bool KPDFDocument::historyAtBegin() const { return d->viewportIterator == d->viewportHistory.begin(); diff --git a/core/document.h b/core/document.h index 13f069e33..a06eacccd 100644 --- a/core/document.h +++ b/core/document.h @@ -76,6 +76,7 @@ class KPDFDocument : public QObject uint pages() const; KURL currentDocument() const; bool isAllowed( int /*Document::Permisison(s)*/ ) const; + bool supportsSearching() const; bool historyAtBegin() const; bool historyAtEnd() const; QString getMetaData( const QString & key, const QString & option = QString() ) const; diff --git a/core/generator.h b/core/generator.h index ae1bddcd6..5d45e24de 100644 --- a/core/generator.h +++ b/core/generator.h @@ -57,6 +57,7 @@ class Generator : public QObject // page contents generation virtual bool canGeneratePixmap() = 0; virtual void generatePixmap( PixmapRequest * request ) = 0; + virtual bool canGenerateTextPage() = 0; virtual void generateSyncTextPage( KPDFPage * page ) = 0; // print document using already configured kprinter diff --git a/core/generator_kimgio/Makefile.am b/core/generator_kimgio/Makefile.am new file mode 100644 index 000000000..5a93221d1 --- /dev/null +++ b/core/generator_kimgio/Makefile.am @@ -0,0 +1,6 @@ +INCLUDES = -I$(srcdir)/../../ $(all_includes) + +libgeneratorkimgio_la_LDFLAGS = $(all_libraries) +libgeneratorkimgio_la_SOURCES = generator_kimgio.cpp + +noinst_LTLIBRARIES = libgeneratorkimgio.la diff --git a/core/generator_kimgio/generator_kimgio.cpp b/core/generator_kimgio/generator_kimgio.cpp new file mode 100644 index 000000000..69a2aa1dc --- /dev/null +++ b/core/generator_kimgio/generator_kimgio.cpp @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2005 by Albert Astals Cid * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include +#include + +#include "core/page.h" +#include "generator_kimgio.h" + +KIMGIOGenerator::KIMGIOGenerator( KPDFDocument * document ) : Generator( document ) +{ +} + +KIMGIOGenerator::~KIMGIOGenerator() +{ + delete m_pix; +} + +bool KIMGIOGenerator::loadDocument( const QString & fileName, QValueVector & pagesVector ) +{ + m_pix = new QPixmap(fileName); + + pagesVector.resize( 1 ); + + KPDFPage * page = new KPDFPage( 0, m_pix->width(), m_pix->height(), 0 ); + pagesVector[0] = page; + + return true; +} + +bool KIMGIOGenerator::canGeneratePixmap() +{ + return true; +} + +void KIMGIOGenerator::generatePixmap( PixmapRequest * request ) +{ + QPixmap *p = new QPixmap(*m_pix); + request->page->setPixmap(request->id, p); + signalRequestDone(request); +} + +bool KIMGIOGenerator::canGenerateTextPage() +{ + return false; +} + +void KIMGIOGenerator::generateSyncTextPage( KPDFPage * /*page*/ ) +{ +} + +bool KIMGIOGenerator::print( KPrinter& printer ) +{ + QPainter p(&printer); + p.drawPixmap(0, 0, *m_pix); + return true; +} diff --git a/core/generator_kimgio/generator_kimgio.h b/core/generator_kimgio/generator_kimgio.h new file mode 100644 index 000000000..e749851fc --- /dev/null +++ b/core/generator_kimgio/generator_kimgio.h @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2005 by Albert Astals Cid * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef _KPDF_GENERATOR_PNG_H_ +#define _KPDF_GENERATOR_PNG_H_ + +#include "core/generator.h" + +class KIMGIOGenerator : public Generator +{ + public: + KIMGIOGenerator( KPDFDocument * document ); + virtual ~KIMGIOGenerator(); + + // [INHERITED] load a document and fill up the pagesVector + bool loadDocument( const QString & fileName, QValueVector & pagesVector ); + + // [INHERITED] perform actions on document / pages + bool canGeneratePixmap(); + void generatePixmap( PixmapRequest * request ); + bool canGenerateTextPage(); + void generateSyncTextPage( KPDFPage * page ); + + // [INHERITED] print document using already configured kprinter + bool print( KPrinter& printer ); + + private: + QPixmap *m_pix; +}; + +#endif diff --git a/core/generator_pdf/generator_pdf.cpp b/core/generator_pdf/generator_pdf.cpp index cba47f2ae..0b58f7c20 100644 --- a/core/generator_pdf/generator_pdf.cpp +++ b/core/generator_pdf/generator_pdf.cpp @@ -387,6 +387,11 @@ void PDFGenerator::generatePixmap( PixmapRequest * request ) signalRequestDone( request ); } +bool PDFGenerator::canGenerateTextPage() +{ + return true; +} + void PDFGenerator::generateSyncTextPage( KPDFPage * page ) { // build a TextPage using the lightweight KPDFTextDev generator.. diff --git a/core/generator_pdf/generator_pdf.h b/core/generator_pdf/generator_pdf.h index 493410735..5a7d07f08 100644 --- a/core/generator_pdf/generator_pdf.h +++ b/core/generator_pdf/generator_pdf.h @@ -64,6 +64,7 @@ class PDFGenerator : public Generator // [INHERITED] perform actions on document / pages bool canGeneratePixmap(); void generatePixmap( PixmapRequest * request ); + bool canGenerateTextPage(); void generateSyncTextPage( KPDFPage * page ); // [INHERITED] print page using an already configured kprinter diff --git a/part.cpp b/part.cpp index a99561e78..e32aa4cf7 100644 --- a/part.cpp +++ b/part.cpp @@ -344,10 +344,11 @@ KAboutData* Part::createAboutData() bool Part::openFile() { bool ok = m_document->openDocument( m_file, url() ); + bool canSearch = m_document->supportsSearching(); // update one-time actions - m_find->setEnabled( ok ); - m_findNext->setEnabled( ok ); + m_find->setEnabled( ok && canSearch ); + m_findNext->setEnabled( ok && canSearch ); m_saveAs->setEnabled( ok ); m_printPreview->setEnabled( ok ); m_showProperties->setEnabled( ok ); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 1826311a4..a3b937a4c 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -656,7 +656,7 @@ void PageView::keyPressEvent( QKeyEvent * e ) } return; } - else if( e->key() == '/' && d->document->isOpened() ) + else if( e->key() == '/' && d->document->isOpened() && d->document->supportsSearching() ) { // stop scrolling the page (if doing it) if ( d->autoScrollTimer )