diff --git a/core/document.cpp b/core/document.cpp index 496d702e0..439b5a5ff 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -39,6 +39,7 @@ #include "page.h" #include "settings.h" #include "printinterface.h" +#include "guiinterface.h" using namespace Okular; @@ -313,18 +314,25 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi } -QString Document::getXMLFile() +QString Document::xmlFile() { - if (generator) - return generator->getXMLFile(); - - return QString(); + if ( generator ) + { + Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( generator ); + return iface ? iface->xmlFile() : QString(); + } + else + return QString(); } -void Document::setupGUI(KActionCollection* ac, QToolBox* tBox ) +void Document::setupGui( KActionCollection *ac, QToolBox *tBox ) { - if (generator) - generator->setupGUI(ac,tBox); + if ( generator && ac && tBox ) + { + Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( generator ); + if ( iface ) + iface->setupGui( ac, tBox ); + } } void Document::closeDocument() @@ -342,8 +350,12 @@ void Document::closeDocument() if ( d->saveBookmarksTimer ) d->saveBookmarksTimer->stop(); - if (generator) - generator->freeGUI(); + if ( generator ) + { + Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( generator ); + if ( iface ) + iface->freeGui(); + } if (!m_usingCachedGenerator) { // delete contents generator diff --git a/core/document.h b/core/document.h index c646b10b4..bbe2823d8 100644 --- a/core/document.h +++ b/core/document.h @@ -123,8 +123,8 @@ class OKULAR_EXPORT Document : public QObject QString pageSizeString(int page) const; // gui altering stuff - QString getXMLFile(); - void setupGUI(KActionCollection * ac , QToolBox * tBox ); + QString xmlFile(); + void setupGui( KActionCollection *ac, QToolBox *tBox ); // perform actions on document / pages void setViewportPage( int page, int excludeId = -1, bool smoothMove = false ); diff --git a/core/generator.cpp b/core/generator.cpp index 6f18d3cdd..3e177814f 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -75,19 +75,6 @@ bool Generator::isAllowed( int ) const return true; } -QString Generator::getXMLFile() const -{ - return QString(); -} - -void Generator::setupGUI( KActionCollection*, QToolBox* ) -{ -} - -void Generator::freeGUI() -{ -} - bool Generator::supportsSearching() const { return false; diff --git a/core/generator.h b/core/generator.h index 77ea15e74..fd62c701b 100644 --- a/core/generator.h +++ b/core/generator.h @@ -27,8 +27,6 @@ #include -class QToolBox; -class KActionCollection; class KConfigDialog; class KIcon; class KPrinter; @@ -239,11 +237,6 @@ class OKULAR_EXPORT Generator : public QObject */ virtual bool isAllowed( int action ) const; - // gui stuff - virtual QString getXMLFile() const; - virtual void setupGUI( KActionCollection*, QToolBox* ); - virtual void freeGUI(); - /** * This method returns whether the generator supports searching. Default is false. */ diff --git a/core/guiinterface.h b/core/guiinterface.h new file mode 100644 index 000000000..79721a843 --- /dev/null +++ b/core/guiinterface.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2007 by Pino Toscano * + * * + * 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 _OKULAR_GUIINTERFACE_H_ +#define _OKULAR_GUIINTERFACE_H_ + +#include "okular_export.h" + +class QToolBox; +class KActionCollection; + +namespace Okular { + +/** + * @short Abstract interface for user interface control + * + * This interface defines an way to interact with the Okular user interface, + * eg adding actions in the menus. + */ +class OKULAR_EXPORT GuiInterface +{ + public: + virtual ~GuiInterface() {} + + virtual QString xmlFile() const = 0; + + virtual void setupGui( KActionCollection *, QToolBox * ) = 0; + + virtual void freeGui() = 0; +}; + +} + +Q_DECLARE_INTERFACE( Okular::GuiInterface, "org.kde.okular.GuiInterface/0.1" ) + +#endif diff --git a/generators/ghostview/generator_ghostview.cpp b/generators/ghostview/generator_ghostview.cpp index 5de6ff116..86bed317b 100644 --- a/generators/ghostview/generator_ghostview.cpp +++ b/generators/ghostview/generator_ghostview.cpp @@ -267,7 +267,12 @@ void GSGenerator::setPaperSize( QVector & pagesVector, int newsiz */ } -void GSGenerator::setupGUI(KActionCollection * ac , QToolBox * tBox ) +QString GSGenerator::xmlFile() const +{ + return QString(); +} + +void GSGenerator::setupGui( KActionCollection *ac, QToolBox *tBox ) { if ( GSSettings::messages() ) { @@ -277,7 +282,7 @@ void GSGenerator::setupGUI(KActionCollection * ac , QToolBox * tBox ) m_actionCollection = ac; } -void GSGenerator::freeGUI() +void GSGenerator::freeGui() { if ( GSSettings::messages() ) { diff --git a/generators/ghostview/generator_ghostview.h b/generators/ghostview/generator_ghostview.h index d0e8ee4cb..5bb8fb3ac 100644 --- a/generators/ghostview/generator_ghostview.h +++ b/generators/ghostview/generator_ghostview.h @@ -11,6 +11,7 @@ #define _OKULAR_GENERATOR_GHOSTVIEW_H_ #include "core/generator.h" +#include "core/guiinterface.h" class GSInterpreterCMD; class GSLogWindow; @@ -19,9 +20,11 @@ class GSInternalDocument; class KTempFile; class KActionCollection; -class GSGenerator : public Okular::Generator +class GSGenerator : public Okular::Generator, public Okular::GuiInterface { Q_OBJECT + Q_INTERFACES( Okular::GuiInterface ) + public: /** virtual methods to reimplement **/ // load a document and fill up the pagesVector @@ -44,8 +47,9 @@ class GSGenerator : public Okular::Generator QStringList paperSizes() const; void setPaperSize( QVector & pagesVector, int newsize ); - void setupGUI(KActionCollection * /*ac*/ , QToolBox * /* tBox */); - void freeGUI(); + QString xmlFile() const; + void setupGui( KActionCollection *, QToolBox * ); + void freeGui(); // print document using already configured kprinter bool print( KPrinter& /*printer*/ ); diff --git a/part.cpp b/part.cpp index 3c0d75da3..076738ab0 100644 --- a/part.cpp +++ b/part.cpp @@ -650,7 +650,7 @@ bool Part::openFile() } /* if (m_document->getXMLFile() != QString::null) setXMLFile(m_document->getXMLFile(),true);*/ - m_document->setupGUI(actionCollection(),m_toolBox); + m_document->setupGui( actionCollection(), m_toolBox ); return true; }