diff --git a/core/document.cpp b/core/document.cpp index 42f6dc47c..1bf094ac0 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -542,8 +542,9 @@ Generator * DocumentPrivate::loadGeneratorLibrary( const QString& name, const QS GeneratorInfo info; info.generator = generator; info.library = lib; - if ( generator->componentData() && generator->componentData()->aboutData() ) - info.catalogName = generator->componentData()->aboutData()->catalogName(); + const KComponentData* compData = m_parent->componentData(); + if ( compData && compData->aboutData() ) + info.catalogName = compData->aboutData()->catalogName(); m_loadedGenerators.insert( name, info ); return generator; } @@ -1343,25 +1344,15 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi } -QString Document::xmlFile() const +KXMLGUIClient* Document::guiClient() { if ( d->m_generator ) - { - Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( d->m_generator ); - return iface ? iface->xmlFile() : QString(); - } - else - return QString(); -} - -void Document::setupGui( KActionCollection *ac, QToolBox *tBox ) -{ - if ( d->m_generator && ac && tBox ) { Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( d->m_generator ); if ( iface ) - iface->setupGui( ac, tBox ); + return iface->guiClient(); } + return 0; } void Document::closeDocument() @@ -1389,9 +1380,6 @@ void Document::closeDocument() if ( d->m_generator ) { - Okular::GuiInterface * iface = qobject_cast< Okular::GuiInterface * >( d->m_generator ); - if ( iface ) - iface->freeGui(); // disconnect the generator from this document ... d->m_generator->d->m_document = 0; // .. and this document from the generator signals @@ -2590,7 +2578,7 @@ QStringList Document::supportedMimeTypes() const const KComponentData* Document::componentData() const { - return d->m_generator ? d->m_generator->componentData() : 0; + return d->m_generator ? d->m_generator->ownComponentData() : 0; } void Document::requestDone( PixmapRequest * req ) diff --git a/core/document.h b/core/document.h index ca4953ebd..1a69da82d 100644 --- a/core/document.h +++ b/core/document.h @@ -26,11 +26,10 @@ class KComponentData; class KBookmark; class KConfigDialog; +class KXMLGUIClient; class KPrinter; class KPrintDialogPage; class KUrl; -class KActionCollection; -class QToolBox; namespace Okular { @@ -279,16 +278,9 @@ class OKULAR_EXPORT Document : public QObject QString pageSizeString( int page ) const; /** - * Returns the gui description file of the document that shall be merged with - * Okulars menu/tool bar. + * Returns the gui client of the generator, if it provides one. */ - QString xmlFile() const; - - /** - * Calling this method allows the document to add custom actions to the gui - * and extend Okulars side pane via @p toolbox. - */ - void setupGui( KActionCollection *collection, QToolBox *toolbox ); + KXMLGUIClient* guiClient(); /** * Sets the current document viewport to the given @p page. diff --git a/core/generator.cpp b/core/generator.cpp index 1ddb5e34e..84c5fa02a 100644 --- a/core/generator.cpp +++ b/core/generator.cpp @@ -232,7 +232,7 @@ bool Generator::hasFeature( GeneratorFeature feature ) const return d->m_features.contains( feature ); } -const KComponentData* Generator::componentData() const +const KComponentData* Generator::ownComponentData() const { return d->m_componentData; } diff --git a/core/generator.h b/core/generator.h index 0feb08cf6..a43e10d4c 100644 --- a/core/generator.h +++ b/core/generator.h @@ -351,7 +351,7 @@ class OKULAR_EXPORT Generator : public QObject /** * Returns the component data associated with the generator. May be null. */ - const KComponentData* componentData() const; + const KComponentData* ownComponentData() const; Q_SIGNALS: /** diff --git a/interfaces/guiinterface.h b/interfaces/guiinterface.h index efa175f85..6f105970a 100644 --- a/interfaces/guiinterface.h +++ b/interfaces/guiinterface.h @@ -14,8 +14,7 @@ #include -class QToolBox; -class KActionCollection; +#include namespace Okular { @@ -37,7 +36,7 @@ namespace Okular { * @endcode * and - of course - implementing its methods. */ -class OKULAR_EXPORT GuiInterface +class OKULAR_EXPORT GuiInterface : protected KXMLGUIClient { public: /** @@ -46,28 +45,9 @@ class OKULAR_EXPORT GuiInterface virtual ~GuiInterface() {} /** - * Returns the name of the gui description file that shall - * be merged with the Okular menu. + * This method requests the XML GUI Client provided by the interface. */ - virtual QString xmlFile() const = 0; - - /** - * This method is called when the Okular gui is set up. - * - * You can insert the action which are listed in the file returned by - * @p xmlFile() into the given @p collection to make them appear in the - * menu bar. - * - * The @p toolbox pointer allows you to add new custom widgets to Okulars left - * side pane. - */ - virtual void setupGui( KActionCollection *collection, QToolBox *toolbox ) = 0; - - /** - * This method is called when the Okular gui is cleaned up. - * You should free all the gui elements created in @p setupGui() here. - */ - virtual void freeGui() = 0; + KXMLGUIClient* guiClient() { return this; } }; } diff --git a/part.cpp b/part.cpp index 627d0f7ad..c96777436 100644 --- a/part.cpp +++ b/part.cpp @@ -120,7 +120,7 @@ QObject *parent, const QStringList &args ) : KParts::ReadOnlyPart(parent), m_tempfile( 0 ), m_showMenuBarAction( 0 ), m_showFullScreenAction( 0 ), m_actionsSearched( false ), -m_searchStarted(false), m_cliPresentation(false) +m_searchStarted(false), m_cliPresentation(false), m_generatorGuiClient(0) { // first necessary step: copy the configuration from kpdf, if available QString newokularconffile = KStandardDirs::locateLocal( "config", "okularpartrc" ); @@ -793,9 +793,9 @@ bool Part::openFile() m_cliPresentation = false; QMetaObject::invokeMethod(this, "slotShowPresentation", Qt::QueuedConnection); } - /* if (m_document->getXMLFile() != QString()) - setXMLFile(m_document->getXMLFile(),true);*/ - m_document->setupGui( actionCollection(), 0 ); + m_generatorGuiClient = factory() ? m_document->guiClient() : 0; + if ( m_generatorGuiClient ) + factory()->addClient( m_generatorGuiClient ); return true; } @@ -847,6 +847,9 @@ bool Part::closeUrl() m_searchStarted = false; m_realUrl = KUrl(); if (!localFilePath().isEmpty()) m_watcher->removeFile(localFilePath()); + if ( m_generatorGuiClient ) + factory()->removeClient( m_generatorGuiClient ); + m_generatorGuiClient = 0; m_document->closeDocument(); updateViewActions(); m_searchWidget->clearText(); diff --git a/part.h b/part.h index 0451cd6e7..93037ff4d 100644 --- a/part.h +++ b/part.h @@ -244,6 +244,8 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi KUrl m_realUrl; + KXMLGUIClient *m_generatorGuiClient; + private slots: void slotGeneratorPreferences(); };