Commit a8d74774 authored by Pino Toscano's avatar Pino Toscano

Cleanup a bit the GuiInterface, and making it work.

Instead of manually requestion actions and other stuff, we just make the interface as gui client, requesting and integrating it in the part gui.
Also, rename the Generator's componentData() to ownComponentData() to avoid clashing with KXMLGUIClient.

svn path=/trunk/KDE/kdegraphics/okular/; revision=705933
parent 17e6bdfc
......@@ -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 )
......
......@@ -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.
......
......@@ -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;
}
......
......@@ -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:
/**
......
......@@ -14,8 +14,7 @@
#include <QtCore/QObject>
class QToolBox;
class KActionCollection;
#include <kxmlguiclient.h>
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; }
};
}
......
......@@ -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();
......
......@@ -244,6 +244,8 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
KUrl m_realUrl;
KXMLGUIClient *m_generatorGuiClient;
private slots:
void slotGeneratorPreferences();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment