update a bit with the recent API changes

(still missing the kdeprint removal, though)

svn path=/trunk/KDE/kdegraphics/okular/; revision=744193
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent d1b62bbe5e
commit a7d2563d31
  1. 69
      Mainpage.dox

@ -174,15 +174,17 @@ The API of the Generator looks like the following:
class MagicGenerator : public Okular::Generator class MagicGenerator : public Okular::Generator
{ {
public: public:
MagicGenerator(); MagicGenerator( QObject *parent, const QVariantList &args );
~MagicGenerator(); ~MagicGenerator();
bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages ); bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages );
bool closeDocument();
bool canGeneratePixmap() const; bool canGeneratePixmap() const;
void generatePixmap( Okular::PixmapRequest *request ); void generatePixmap( Okular::PixmapRequest *request );
protected:
bool doCloseDocument();
private: private:
MagicDocument mMagicDocument; MagicDocument mMagicDocument;
}; };
@ -195,10 +197,17 @@ The implementation of the Generator looks like this:
#include "magicgenerator.h" #include "magicgenerator.h"
OKULAR_EXPORT_PLUGIN(MagicGenerator) static KAboutData createAboutData()
{
KAboutData aboutData(...);
// fill the about data
return aboutData;
}
OKULAR_EXPORT_PLUGIN(MagicGenerator, createAboutData())
MagicGenerator::MagicGenerator() MagicGenerator::MagicGenerator( QObject *parent, const QVariantList &args )
: Okular::Generator() : Okular::Generator( parent, args )
{ {
} }
@ -225,7 +234,7 @@ bool MagicGenerator::loadDocument( const QString &fileName, QVector<Okular::Page
return true; return true;
} }
bool MagicGenerator::closeDocument() bool MagicGenerator::doCloseDocument()
{ {
return true; return true;
} }
@ -255,7 +264,7 @@ These page objects will be stored in the document object and act as a container
of the pages. This code is the same for nearly every Generator. On an failure the error() signal can be emitted of the pages. This code is the same for nearly every Generator. On an failure the error() signal can be emitted
to inform the user about the issue. This code is the same for nearly every Generator. to inform the user about the issue. This code is the same for nearly every Generator.
In the closeDocument() method you should close the document and free all resources you have allocated in openDocument(). In the doCloseDocument() method you should close the document and free all resources you have allocated in openDocument().
Now we come to the picture creation methods. The canGeneratorPixmap() method returns whether the Generator is currently Now we come to the picture creation methods. The canGeneratorPixmap() method returns whether the Generator is currently
able to handle a new pixmap generation request. For a simple Generator like our one that's always the case as it works able to handle a new pixmap generation request. For a simple Generator like our one that's always the case as it works
@ -298,7 +307,7 @@ Comment=Magic Document backend for okular
Comment[x-test]=xxMagic Document backend for okularxx Comment[x-test]=xxMagic Document backend for okularxx
ServiceTypes=okular/Generator ServiceTypes=okular/Generator
MimeType=application/x-magic MimeType=application/x-magic
X-KDE-Library=libokularGenerator_magic X-KDE-Library=okularGenerator_magic
X-KDE-Priority=1 X-KDE-Priority=1
X-KDE-okularAPIVersion=1 X-KDE-okularAPIVersion=1
X-KDE-okularHasInternalSettings=false X-KDE-okularHasInternalSettings=false
@ -365,9 +374,7 @@ include_directories( ${OKULAR_INCLUDE_DIR} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} )
set( okularGenerator_magic_SRCS generator_magic.cpp ) set( okularGenerator_magic_SRCS generator_magic.cpp )
kde4_automoc( ${okularGenerator_magic_SRCS} ) kde4_add_plugin( okularGenerator_magic ${okularGenerator_magic_SRCS} )
kde4_add_plugin( okularGenerator_magic WITH_PREFIX ${okularGenerator_magic_SRCS} )
target_link_libraries( okularGenerator_magic ${OKULAR_LIBRARIES} ${KDE4_KDEUI_LIBS} ) target_link_libraries( okularGenerator_magic ${OKULAR_LIBRARIES} ${KDE4_KDEUI_LIBS} )
@ -445,11 +452,10 @@ With the extension of our helper class we can continue on extending our Generato
class MagicGenerator : public Okular::Generator class MagicGenerator : public Okular::Generator
{ {
public: public:
MagicGenerator(); MagicGenerator( QObject *parent, const QVariantList &args );
~MagicGenerator(); ~MagicGenerator();
bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages ); bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages );
bool closeDocument();
bool canGeneratePixmap() const; bool canGeneratePixmap() const;
void generatePixmap( Okular::PixmapRequest *request ); void generatePixmap( Okular::PixmapRequest *request );
@ -457,6 +463,9 @@ class MagicGenerator : public Okular::Generator
virtual bool canGenerateTextPage() const; virtual bool canGenerateTextPage() const;
virtual void generateTextPage( Okular::Page *page, enum Okular::GenerationType type = Okular::Synchronous ); virtual void generateTextPage( Okular::Page *page, enum Okular::GenerationType type = Okular::Synchronous );
protected:
bool doCloseDocument();
private: private:
MagicDocument mMagicDocument; MagicDocument mMagicDocument;
}; };
@ -478,7 +487,8 @@ Let us take a look at the implementation of these methods in our MagicGenerator:
... ...
MagicGenerator::MagicGenerator() MagicGenerator::MagicGenerator( QObject *parent, const QVariantList &args )
: Okular::Generator( parent, args )
{ {
setFeature( TextExtraction ); setFeature( TextExtraction );
} }
@ -558,13 +568,14 @@ The new MagicGenerator API looks like the following:
class MagicGenerator : public Okular::Generator class MagicGenerator : public Okular::Generator
{ {
public: public:
MagicGenerator(); MagicGenerator( QObject *parent, const QVariantList &args );
~MagicGenerator(); ~MagicGenerator();
bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages ); bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages );
bool closeDocument();
proteced: protected:
bool doCloseDocument();
virtual QImage image( Okular::PixmapRequest *request ); virtual QImage image( Okular::PixmapRequest *request );
virtual Okular::TextPage* textPage( Okular::Page *page ); virtual Okular::TextPage* textPage( Okular::Page *page );
@ -581,7 +592,8 @@ Before explaining why, we'll take a look at the implementation:
\code \code
MagicGenerator::MagicGenerator() MagicGenerator::MagicGenerator( QObject *parent, const QVariantList &args )
: Okular::Generator( parent, args )
{ {
setFeature( TextExtraction ); setFeature( TextExtraction );
setFeature( Threaded ); setFeature( Threaded );
@ -644,11 +656,10 @@ The API of our HTMLGenerator looks like the following:
class HTMLGenerator : public Okular::Generator class HTMLGenerator : public Okular::Generator
{ {
public: public:
HTMLGenerator(); HTMLGenerator( QObject *parent, const QVariantList &args );
~HTMLGenerator(); ~HTMLGenerator();
bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages ); bool loadDocument( const QString &fileName, QVector<Okular::Page*> &pages );
bool closeDocument();
bool canGeneratePixmap() const; bool canGeneratePixmap() const;
void generatePixmap( Okular::PixmapRequest *request ); void generatePixmap( Okular::PixmapRequest *request );
@ -663,6 +674,9 @@ class HTMLGenerator : public Okular::Generator
virtual bool exportTo( const QString &fileName, const Okular::ExportFormat &format ); virtual bool exportTo( const QString &fileName, const Okular::ExportFormat &format );
protected:
bool doCloseDocument();
private: private:
QTextDocument *mTextDocument; QTextDocument *mTextDocument;
Okular::DocumentInfo mDocumentInfo; Okular::DocumentInfo mDocumentInfo;
@ -696,10 +710,17 @@ Now that you know what the methods are supposed to do, let's take a look at the
#include "htmlgenerator.h" #include "htmlgenerator.h"
OKULAR_EXPORT_PLUGIN(HTMLGenerator) static KAboutData createAboutData()
{
KAboutData aboutData(...);
// fill the about data
return aboutData;
}
OKULAR_EXPORT_PLUGIN(HTMLGenerator, createAboutData())
HTMLGenerator::HTMLGenerator() HTMLGenerator::HTMLGenerator( QObject *parent, const QVariantList &args )
: Okular::Generator(), : Okular::Generator( parent, args ),
mTextDocument( 0 ) mTextDocument( 0 )
{ {
} }
@ -750,7 +771,7 @@ bool HTMLGenerator::loadDocument( const QString &fileName, QVector<Okular::Page*
return true; return true;
} }
bool HTMLGenerator::closeDocument() bool HTMLGenerator::doCloseDocument()
{ {
delete mTextDocument; delete mTextDocument;
mTextDocument = 0; mTextDocument = 0;

Loading…
Cancel
Save