• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

katepartpluginmanager.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright 2001 Joseph Wenninger <jowenn@kde.org>
00004    Copyright 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005    Copyright 2007 Dominik Haumann <dhaumann kde org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "katepartpluginmanager.h"
00023 #include "katepartpluginmanager.moc"
00024 
00025 #include "kateglobal.h"
00026 
00027 #include <ktexteditor/plugin.h>
00028 #include <ktexteditor/document.h>
00029 #include <ktexteditor/view.h>
00030 #include <kconfig.h>
00031 #include <kconfiggroup.h>
00032 #include <kxmlguifactory.h>
00033 
00034 #include <kservicetypetrader.h>
00035 #include <kdebug.h>
00036 
00037 QString KatePartPluginInfo::saveName() const
00038 {
00039   QString saveName = service->property("X-KDE-PluginInfo-Name").toString();
00040 
00041   if (saveName.isEmpty())
00042     saveName = service->library();
00043   return saveName;
00044 }
00045 
00046 KatePartPluginManager::KatePartPluginManager()
00047   : QObject(),
00048     m_config(new KConfig("katepartpluginsrc", KConfig::NoGlobals))
00049 {
00050   setupPluginList ();
00051   loadConfig ();
00052 }
00053 
00054 KatePartPluginManager::~KatePartPluginManager()
00055 {
00056   writeConfig();
00057   // than unload the plugins
00058   unloadAllPlugins ();
00059   delete m_config;
00060   m_config = 0;
00061 }
00062 
00063 KatePartPluginManager *KatePartPluginManager::self()
00064 {
00065   return KateGlobal::self()->pluginManager ();
00066 }
00067 
00068 void KatePartPluginManager::setupPluginList ()
00069 {
00070   // NOTE: adapt the interval each minor KDE version
00071   KService::List traderList = KServiceTypeTrader::self()->
00072       query("KTextEditor/Plugin", "([X-KDE-Version] >= 4.0) and ([X-KDE-Version] <= 4.1)");
00073 
00074   foreach(const KService::Ptr &ptr, traderList)
00075   {
00076     KatePartPluginInfo info;
00077 
00078     info.load = false;
00079     info.service = ptr;
00080     info.plugin = 0L;
00081 
00082     m_pluginList.push_back (info);
00083   }
00084 }
00085 
00086 void KatePartPluginManager::addDocument(KTextEditor::Document *doc)
00087 {
00088   //kDebug() << doc;
00089   for (KatePartPluginList::iterator it = m_pluginList.begin();
00090       it != m_pluginList.end(); ++it)
00091   {
00092     if (it->load) {
00093       it->plugin->addDocument(doc);
00094     }
00095   }
00096 }
00097 
00098 void KatePartPluginManager::removeDocument(KTextEditor::Document *doc)
00099 {
00100   //kDebug() << doc;
00101   for (KatePartPluginList::iterator it = m_pluginList.begin();
00102       it != m_pluginList.end(); ++it)
00103   {
00104     if (it->load) {
00105       it->plugin->removeDocument(doc);
00106     }
00107   }
00108 }
00109 
00110 void KatePartPluginManager::addView(KTextEditor::View *view)
00111 {
00112   //kDebug() << view;
00113   for (KatePartPluginList::iterator it = m_pluginList.begin();
00114       it != m_pluginList.end(); ++it)
00115   {
00116     if (it->load) {
00117       it->plugin->addView(view);
00118     }
00119   }
00120 }
00121 
00122 void KatePartPluginManager::removeView(KTextEditor::View *view)
00123 {
00124   //kDebug() << view;
00125   for (KatePartPluginList::iterator it = m_pluginList.begin();
00126       it != m_pluginList.end(); ++it)
00127   {
00128     if (it->load) {
00129       it->plugin->removeView(view);
00130     }
00131   }
00132 }
00133 
00134 void KatePartPluginManager::loadConfig ()
00135 {
00136   // first: unload the plugins
00137   unloadAllPlugins ();
00138 
00139   KConfigGroup cg = KConfigGroup(m_config, "Kate Part Plugins");
00140 
00141   // disable all plugin if no config...
00142   foreach (const KatePartPluginInfo &plugin, m_pluginList)
00143     plugin.load = cg.readEntry (plugin.service->library(), false)
00144                || cg.readEntry (plugin.service->property("X-KDE-PluginInfo-Name").toString(), false);
00145 
00146   loadAllPlugins();
00147 }
00148 
00149 void KatePartPluginManager::writeConfig()
00150 {
00151   KConfigGroup cg = KConfigGroup( m_config, "Kate Part Plugins" );
00152   foreach(const KatePartPluginInfo &it, m_pluginList)
00153   {
00154     cg.writeEntry (it.saveName(), it.load);
00155   }
00156 }
00157 
00158 void KatePartPluginManager::loadAllPlugins ()
00159 {
00160   for (KatePartPluginList::iterator it = m_pluginList.begin();
00161       it != m_pluginList.end(); ++it)
00162   {
00163     if (it->load)
00164     {
00165       loadPlugin(*it);
00166       enablePlugin(*it);
00167     }
00168   }
00169 }
00170 
00171 void KatePartPluginManager::unloadAllPlugins ()
00172 {
00173   for (KatePartPluginList::iterator it = m_pluginList.begin();
00174        it != m_pluginList.end(); ++it)
00175   {
00176     if (it->plugin) {
00177       disablePlugin(*it);
00178       unloadPlugin(*it);
00179     }
00180   }
00181 }
00182 
00183 void KatePartPluginManager::loadPlugin (KatePartPluginInfo &item)
00184 {
00185   if (item.plugin) return;
00186 
00187   item.plugin = KTextEditor::createPlugin (item.service, this);
00188   Q_ASSERT(item.plugin);
00189   item.load = (item.plugin != 0);
00190 }
00191 
00192 void KatePartPluginManager::unloadPlugin (KatePartPluginInfo &item)
00193 {
00194   delete item.plugin;
00195   item.plugin = 0L;
00196   item.load = false;
00197 }
00198 
00199 void KatePartPluginManager::enablePlugin (KatePartPluginInfo &item)
00200 {
00201   // plugin around at all?
00202   if (!item.plugin || !item.load)
00203     return;
00204 
00205   // register docs and views
00206   foreach (KTextEditor::Document *doc, KateGlobal::self()->documents()) {
00207     if (!doc)
00208       continue;
00209 
00210     foreach (KTextEditor::View *view, doc->views()) {
00211       if (!view)
00212         continue;
00213 
00214       KXMLGUIFactory *viewFactory = view->factory();
00215       if (viewFactory)
00216         viewFactory->removeClient(view);
00217 
00218       item.plugin->addView(view);
00219 
00220       if (viewFactory)
00221         viewFactory->addClient(view);
00222     }
00223   }
00224 }
00225 
00226 void KatePartPluginManager::disablePlugin (KatePartPluginInfo &item)
00227 {
00228   // plugin around at all?
00229   if (!item.plugin || !item.load)
00230     return;
00231 
00232   // de-register docs and views
00233   foreach (KTextEditor::Document *doc, KateGlobal::self()->documents()) {
00234     if (!doc)
00235       continue;
00236 
00237     foreach (KTextEditor::View *view, doc->views()) {
00238       if (!view)
00239         continue;
00240 
00241       KXMLGUIFactory *viewFactory = view->factory();
00242       if (viewFactory)
00243         viewFactory->removeClient(view);
00244 
00245       item.plugin->removeView(view);
00246 
00247       if (viewFactory)
00248         viewFactory->addClient(view);
00249     }
00250   }
00251 }
00252 
00253 // kate: space-indent on; indent-width 2; replace-tabs on;

Kate

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs 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