• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

interfaces

iplugin.cpp

00001 /* This file is part of the KDE project
00002  Copyright 2002 Simon Hausmann <hausmann@kde.org>
00003  Copyright 2002 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
00004  Copyright 2002 Harald Fernengel <harry@kdevelop.org>
00005  Copyright 2002 Falk Brettschneider <falkbr@kdevelop.org>
00006  Copyright 2003 Julian Rockey <linux@jrockey.com>
00007  Copyright 2003 Roberto Raggi <roberto@kdevelop.org>
00008  Copyright 2003 Jens Dagerbo <jens.dagerbo@swipnet.se>
00009  Copyright 2003 Mario Scalas <mario.scalas@libero.it>
00010  Copyright 2003-2004,2007 Alexander Dymo <adymo@kdevelop.org>
00011  Copyright 2006 Adam Treat <treat@kde.org>
00012  Copyright 2007 Andreas Pakulat <apaku@gmx.de>
00013 
00014  This library is free software; you can redistribute it and/or
00015  modify it under the terms of the GNU Library General Public
00016  License as published by the Free Software Foundation; either
00017  version 2 of the License, or (at your option) any later version.
00018 
00019  This library is distributed in the hope that it will be useful,
00020  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  Library General Public License for more details.
00023 
00024  You should have received a copy of the GNU Library General Public License
00025  along with this library; see the file COPYING.LIB.  If not, write to
00026  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00027  Boston, MA 02110-1301, USA.
00028 */
00029 #include "iplugin.h"
00030 #include <kglobal.h>
00031 #include <kglobalsettings.h>
00032 #include <kcomponentdata.h>
00033 #include <kiconloader.h>
00034 #include <kmainwindow.h>
00035 #include <kxmlguiwindow.h>
00036 #include <kxmlguifactory.h>
00037 #include <kdebug.h>
00038 #include "icore.h"
00039 #include "iplugincontroller.h"
00040 #include "iprojectcontroller.h"
00041 #include "contextmenuextension.h"
00042 #include <QtDesigner/QExtensionFactory>
00043 #include <QtDesigner/QExtensionManager>
00044 
00045 namespace KDevelop
00046 {
00047 
00048 class PluginExtensionFactory : public QExtensionFactory {
00049 public:
00050     PluginExtensionFactory( const QStringList& extensions, QExtensionManager *parent = 0 )
00051         :QExtensionFactory( parent ), m_extensions( extensions )
00052     {
00053     }
00054     protected:
00055     virtual QObject *createExtension(QObject* object, const QString& iid, QObject* parent ) const
00056     {
00057         Q_UNUSED(parent)
00058         if( !m_extensions.contains( iid ) )
00059             return 0;
00060         IPlugin* p = qobject_cast<IPlugin *>(object);
00061         if( !p )
00062             return 0;
00063         return object;
00064     }
00065     private:
00066         QStringList m_extensions;
00067 };
00068 
00069 class IPluginPrivate
00070 {
00071 public:
00072     IPluginPrivate(IPlugin *q)
00073         : q(q), iconLoader(0), m_factory(0)
00074     {}
00075 
00076     ~IPluginPrivate()
00077     {
00078         delete iconLoader;
00079     }
00080 
00081     void _k_guiClientAdded(KXMLGUIClient *client)
00082     {
00083     if (client != q)
00084         return;
00085 
00086     q->initializeGuiState();
00087     _k_updateState();
00088     }
00089 
00090     void _k_updateState()
00091     {
00092     const int projectCount =
00093         ICore::self()->projectController()->projectCount();
00094     
00095     IPlugin::ReverseStateChange reverse = IPlugin::StateNoReverse;
00096     if (! projectCount)
00097         reverse = IPlugin::StateReverse;
00098 
00099     q->stateChanged(QLatin1String("has_project"), reverse);
00100     }
00101 
00102     IPlugin *q;
00103     ICore *core;
00104     KIconLoader* iconLoader;
00105     PluginExtensionFactory* m_factory;
00106     QStringList m_extensions;
00107 };
00108 
00109 IPlugin::IPlugin( const KComponentData &instance, QObject *parent )
00110         : QObject( parent ),
00111       KXMLGUIClient(), d( new IPluginPrivate(this) )
00112 {
00113     // The following cast is safe, there's no component in KDevPlatform that
00114     // creates plugins except the plugincontroller. The controller passes
00115     // Core::self() as parent to KServiceTypeTrader::createInstanceFromQuery
00116     // so we know the parent is always a Core* pointer.
00117     // This is the only way to pass the Core pointer to the plugin during its
00118     // creation so plugins have access to ICore during their creation.
00119     d->core = static_cast<KDevelop::ICore*>(parent);
00120     setComponentData( instance );
00121 
00122     foreach (KMainWindow* mw, KMainWindow::memberList()) {
00123         KXmlGuiWindow* guiWindow = qobject_cast<KXmlGuiWindow*>(mw);
00124         if (! guiWindow)
00125             continue;
00126 
00127         connect(guiWindow->guiFactory(), SIGNAL(clientAdded(KXMLGUIClient *)),
00128         this, SLOT(_k_guiClientAdded(KXMLGUIClient *)));
00129     }
00130 
00131     connect(ICore::self()->projectController(),
00132         SIGNAL(projectOpened(KDevelop::IProject *)),
00133         this, SLOT(_k_updateState()));
00134 
00135     connect(ICore::self()->projectController(),
00136         SIGNAL(projectClosed(KDevelop::IProject *)),
00137         this, SLOT(_k_updateState()));
00138 }
00139 
00140 IPlugin::~IPlugin()
00141 {
00142     delete d;
00143 }
00144 
00145 void IPlugin::unload()
00146 {
00147     ICore::self()->pluginController()->pluginUnloading(this);
00148 }
00149 
00150 KIconLoader *IPlugin::iconLoader() const
00151 {
00152     if ( d->iconLoader == 0 ) {
00153         d->iconLoader = new KIconLoader( componentData().componentName(), componentData().dirs() );
00154         d->iconLoader->addAppDir( "kdevelop" );
00155         connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
00156                 this, SLOT(newIconLoader()));
00157     }
00158 
00159     return d->iconLoader;
00160 }
00161 
00162 void IPlugin::newIconLoader() const
00163 {
00164     if (d->iconLoader) {
00165         d->iconLoader->reconfigure( componentData().componentName(), componentData().dirs() );
00166     }
00167 }
00168 
00169 ICore *IPlugin::core() const
00170 {
00171     return d->core;
00172 }
00173 
00174 QExtensionManager* IPlugin::extensionManager()
00175 {
00176     return core()->pluginController()->extensionManager();
00177 }
00178 
00179 }
00180 
00181 QStringList KDevelop::IPlugin::extensions( ) const
00182 {
00183   return d->m_extensions;
00184 }
00185 
00186 void KDevelop::IPlugin::registerExtensions( )
00187 {
00188     if( extensions().isEmpty() )
00189         return;
00190     if( !d->m_factory )
00191         d->m_factory = new PluginExtensionFactory( extensions(), extensionManager() );
00192     Q_FOREACH( QString ext, extensions() )
00193     {
00194         extensionManager()->registerExtensions( d->m_factory, ext );
00195     }
00196 }
00197 
00198 void KDevelop::IPlugin::unregisterExtensions( )
00199 {
00200     if( extensions().isEmpty() )
00201         return;
00202     if( !d->m_factory )
00203         return;
00204     Q_FOREACH( QString ext, extensions() )
00205     {
00206         extensionManager()->unregisterExtensions( d->m_factory, ext );
00207     }
00208 
00209 }
00210 
00211 void KDevelop::IPlugin::addExtension( const QString& ext )
00212 {
00213     d->m_extensions << ext;
00214 }
00215 
00216 KDevelop::ContextMenuExtension KDevelop::IPlugin::contextMenuExtension(
00217         KDevelop::Context* )
00218 {
00219     return KDevelop::ContextMenuExtension();
00220 }
00221 
00222 void KDevelop::IPlugin::initializeGuiState()
00223 { }
00224 
00225 #include "iplugin.moc"
00226 
00227 

interfaces

Skip menu "interfaces"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal