simplify a bit the Feature system: move it to the base Generator class, and add a protected method to switch a feature on and off easily - no more need to copy&paste hasFeature() anymore

svn path=/trunk/playground/graphics/okular/; revision=627450
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 59f8fa67e5
commit 55dfb87f3f
  1. 16
      core/generator.cpp
  2. 7
      core/generator.h
  3. 13
      core/textdocumentgenerator.cpp
  4. 2
      core/textdocumentgenerator.h
  5. 13
      generators/chm/generator_chm.cpp
  6. 2
      generators/chm/generator_chm.h
  7. 5
      generators/comicbook/generator_comicbook.cpp
  8. 2
      generators/comicbook/generator_comicbook.h
  9. 12
      generators/dvi/generator_dvi.cpp
  10. 2
      generators/dvi/generator_dvi.h
  11. 12
      generators/ghostview/generator_ghostview.cpp
  12. 2
      generators/ghostview/generator_ghostview.h
  13. 6
      generators/kimgio/generator_kimgio.cpp
  14. 2
      generators/kimgio/generator_kimgio.h
  15. 18
      generators/poppler/generator_pdf.cpp
  16. 2
      generators/poppler/generator_pdf.h

@ -7,6 +7,8 @@
* (at your option) any later version. * * (at your option) any later version. *
***************************************************************************/ ***************************************************************************/
#include <qset.h>
#include <kdebug.h> #include <kdebug.h>
#include <kicon.h> #include <kicon.h>
@ -24,6 +26,7 @@ class Generator::Private
} }
Document * m_document; Document * m_document;
QSet< GeneratorFeature > m_features;
}; };
Generator::Generator() Generator::Generator()
@ -138,9 +141,9 @@ void Generator::setDocument( Document *document )
d->m_document = document; d->m_document = document;
} }
bool Generator::hasFeature( GeneratorFeature ) const bool Generator::hasFeature( GeneratorFeature feature ) const
{ {
return false; return d->m_features.contains( feature );
} }
@ -157,6 +160,15 @@ Document * Generator::document() const
return d->m_document; return d->m_document;
} }
void Generator::setFeature( GeneratorFeature feature, bool on )
{
if ( on )
d->m_features.insert( feature );
else
d->m_features.remove( feature );
}
class PixmapRequest::Private class PixmapRequest::Private
{ {
public: public:

@ -305,7 +305,7 @@ class OKULAR_EXPORT Generator : public QObject
/** /**
* Query for the specified @p feature. * Query for the specified @p feature.
*/ */
virtual bool hasFeature( GeneratorFeature feature ) const; bool hasFeature( GeneratorFeature feature ) const;
Q_SIGNALS: Q_SIGNALS:
/** /**
@ -370,6 +370,11 @@ class OKULAR_EXPORT Generator : public QObject
*/ */
Document * document() const; Document * document() const;
/**
* Toggle the @p feature .
*/
void setFeature( GeneratorFeature feature, bool on = true );
private: private:
class Private; class Private;
Private* const d; Private* const d;

@ -186,6 +186,8 @@ void TextDocumentGenerator::Private::generateTitleInfos()
TextDocumentGenerator::TextDocumentGenerator( TextDocumentConverter *converter ) TextDocumentGenerator::TextDocumentGenerator( TextDocumentConverter *converter )
: Okular::Generator(), d( new Private( this, converter ) ) : Okular::Generator(), d( new Private( this, converter ) )
{ {
setFeature( TextExtraction );
connect( converter, SIGNAL( addLink( Link*, int, int ) ), connect( converter, SIGNAL( addLink( Link*, int, int ) ),
this, SLOT( addLink( Link*, int, int ) ) ); this, SLOT( addLink( Link*, int, int ) ) );
connect( converter, SIGNAL( addAnnotation( Annotation*, int, int ) ), connect( converter, SIGNAL( addAnnotation( Annotation*, int, int ) ),
@ -313,17 +315,6 @@ void TextDocumentGenerator::generateSyncTextPage( Okular::Page * page )
page->setTextPage( d->createTextPage( page->number() ) ); page->setTextPage( d->createTextPage( page->number() ) );
} }
bool TextDocumentGenerator::hasFeature( GeneratorFeature feature ) const
{
switch ( feature )
{
case TextExtraction:
return true;
default: ;
}
return false;
}
bool TextDocumentGenerator::print( KPrinter& printer ) bool TextDocumentGenerator::print( KPrinter& printer )
{ {
if ( !d->mDocument ) if ( !d->mDocument )

@ -93,8 +93,6 @@ class OKULAR_EXPORT TextDocumentGenerator : public Generator
bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector ); bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
bool closeDocument(); bool closeDocument();
bool hasFeature( GeneratorFeature feature ) const;
// [INHERITED] print document using already configured kprinter // [INHERITED] print document using already configured kprinter
bool print( KPrinter& printer ); bool print( KPrinter& printer );

@ -32,6 +32,8 @@ OKULAR_EXPORT_PLUGIN(CHMGenerator)
CHMGenerator::CHMGenerator() CHMGenerator::CHMGenerator()
: Okular::Generator() : Okular::Generator()
{ {
setFeature( TextExtraction );
m_syncGen=0; m_syncGen=0;
m_file=0; m_file=0;
m_state=-1; m_state=-1;
@ -364,17 +366,6 @@ void CHMGenerator::generateSyncTextPage( Okular::Page * page )
syncLock.unlock(); syncLock.unlock();
} }
bool CHMGenerator::hasFeature( GeneratorFeature feature ) const
{
switch ( feature )
{
case TextExtraction:
return true;
default: ;
}
return false;
}
QVariant CHMGenerator::metaData( const QString &key, const QVariant &option ) const QVariant CHMGenerator::metaData( const QString &key, const QVariant &option ) const
{ {
if ( key == "NamedViewport" && !option.toString().isEmpty() ) if ( key == "NamedViewport" && !option.toString().isEmpty() )

@ -38,8 +38,6 @@ class CHMGenerator : public Okular::Generator
const Okular::DocumentSynopsis * generateDocumentSynopsis(); const Okular::DocumentSynopsis * generateDocumentSynopsis();
const Okular::DocumentFonts * generateDocumentFonts(); const Okular::DocumentFonts * generateDocumentFonts();
bool hasFeature( GeneratorFeature feature ) const;
QVariant metaData( const QString & key, const QVariant & option ) const; QVariant metaData( const QString & key, const QVariant & option ) const;
public slots: public slots:

@ -81,10 +81,5 @@ bool ComicBookGenerator::print( KPrinter& printer )
return true; return true;
} }
bool ComicBookGenerator::hasFeature( GeneratorFeature ) const
{
return false;
}
#include "generator_comicbook.moc" #include "generator_comicbook.moc"

@ -29,8 +29,6 @@ class ComicBookGenerator : public Okular::ThreadedGenerator
// [INHERITED] print document using already configured kprinter // [INHERITED] print document using already configured kprinter
bool print( KPrinter& printer ); bool print( KPrinter& printer );
bool hasFeature( GeneratorFeature feature ) const;
protected: protected:
QImage image( Okular::PixmapRequest * request ); QImage image( Okular::PixmapRequest * request );

@ -35,6 +35,7 @@ OKULAR_EXPORT_PLUGIN(DviGenerator)
DviGenerator::DviGenerator() : Okular::Generator(), DviGenerator::DviGenerator() : Okular::Generator(),
m_docInfo( 0 ), m_docSynopsis( 0 ), ready( false ), m_dviRenderer( 0 ) m_docInfo( 0 ), m_docSynopsis( 0 ), ready( false ), m_dviRenderer( 0 )
{ {
setFeature( TextExtraction );
} }
bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page * > &pagesVector ) bool DviGenerator::loadDocument( const QString & fileName, QVector< Okular::Page * > &pagesVector )
@ -369,17 +370,6 @@ const Okular::DocumentSynopsis *DviGenerator::generateDocumentSynopsis()
return m_docSynopsis; return m_docSynopsis;
} }
bool DviGenerator::hasFeature( GeneratorFeature feature ) const
{
switch ( feature )
{
case TextExtraction:
return true;
default: ;
}
return false;
}
void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orientation ) void DviGenerator::loadPages( QVector< Okular::Page * > &pagesVector, int orientation )
{ {
QSize pageRequiredSize; QSize pageRequiredSize;

@ -35,8 +35,6 @@ class DviGenerator : public Okular::Generator
// table of contents // table of contents
const Okular::DocumentSynopsis *generateDocumentSynopsis(); const Okular::DocumentSynopsis *generateDocumentSynopsis();
bool hasFeature( GeneratorFeature feature ) const;
protected: protected:
bool canGeneratePixmap() const; bool canGeneratePixmap() const;
void generatePixmap( Okular::PixmapRequest * request ); void generatePixmap( Okular::PixmapRequest * request );

@ -47,6 +47,7 @@ GSGenerator::GSGenerator() :
Okular::Generator(), Okular::Generator(),
m_converted(false) m_converted(false)
{ {
setFeature( PageSizes );
pixGenerator = 0; pixGenerator = 0;
asyncGenerator = 0; asyncGenerator = 0;
internalDoc = 0; internalDoc = 0;
@ -479,15 +480,4 @@ const Okular::DocumentInfo * GSGenerator::generateDocumentInfo()
return internalDoc->generateDocumentInfo(); return internalDoc->generateDocumentInfo();
} }
bool GSGenerator::hasFeature( GeneratorFeature feature ) const
{
switch ( feature )
{
case PageSizes:
return true;
default: ;
}
return false;
}
#include "generator_ghostview.moc" #include "generator_ghostview.moc"

@ -50,8 +50,6 @@ class GSGenerator : public Okular::Generator, public Okular::ConfigInterface, pu
bool print( KPrinter& /*printer*/ ); bool print( KPrinter& /*printer*/ );
QString fileName() const; QString fileName() const;
bool hasFeature( GeneratorFeature feature ) const;
bool reparseConfig(); bool reparseConfig();
void addPages( KConfigDialog* dlg ); void addPages( KConfigDialog* dlg );

@ -19,6 +19,7 @@ OKULAR_EXPORT_PLUGIN(KIMGIOGenerator)
KIMGIOGenerator::KIMGIOGenerator() KIMGIOGenerator::KIMGIOGenerator()
: ThreadedGenerator() : ThreadedGenerator()
{ {
setFeature( ReadRawData );
} }
KIMGIOGenerator::~KIMGIOGenerator() KIMGIOGenerator::~KIMGIOGenerator()
@ -76,10 +77,5 @@ bool KIMGIOGenerator::print( KPrinter& printer )
return true; return true;
} }
bool KIMGIOGenerator::hasFeature( GeneratorFeature feature ) const
{
return feature == Okular::Generator::ReadRawData;
}
#include "generator_kimgio.moc" #include "generator_kimgio.moc"

@ -29,8 +29,6 @@ class KIMGIOGenerator : public Okular::ThreadedGenerator
// [INHERITED] print document using already configured kprinter // [INHERITED] print document using already configured kprinter
bool print( KPrinter& printer ); bool print( KPrinter& printer );
bool hasFeature( GeneratorFeature feature ) const;
protected: protected:
QImage image( Okular::PixmapRequest * request ); QImage image( Okular::PixmapRequest * request );

@ -226,6 +226,10 @@ PDFGenerator::PDFGenerator()
pixmapRequest( 0 ), docInfoDirty( true ), docSynopsisDirty( true ), pixmapRequest( 0 ), docInfoDirty( true ), docSynopsisDirty( true ),
docFontsDirty( true ), docEmbeddedFilesDirty( true ) docFontsDirty( true ), docEmbeddedFilesDirty( true )
{ {
setFeature( TextExtraction );
#ifdef HAVE_POPPLER_HEAD
setFeature( ReadRawData );
#endif
// update the configuration // update the configuration
reparseConfig(); reparseConfig();
// generate the pixmapGeneratorThread // generate the pixmapGeneratorThread
@ -770,20 +774,6 @@ bool PDFGenerator::print( KPrinter& printer )
return false; return false;
} }
bool PDFGenerator::hasFeature( GeneratorFeature feature ) const
{
switch ( feature )
{
case TextExtraction:
#ifdef HAVE_POPPLER_HEAD
case ReadRawData:
#endif
return true;
default: ;
}
return false;
}
QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) const QVariant PDFGenerator::metaData( const QString & key, const QVariant & option ) const
{ {
if ( key == "StartFullScreen" ) if ( key == "StartFullScreen" )

@ -73,8 +73,6 @@ class PDFGenerator : public Okular::Generator, public Okular::ConfigInterface
// [INHERITED] print page using an already configured kprinter // [INHERITED] print page using an already configured kprinter
bool print( KPrinter& printer ); bool print( KPrinter& printer );
bool hasFeature( GeneratorFeature feature ) const;
// [INHERITED] reply to some metadata requests // [INHERITED] reply to some metadata requests
QVariant metaData( const QString & key, const QVariant & option ) const; QVariant metaData( const QString & key, const QVariant & option ) const;

Loading…
Cancel
Save