kate Library API Documentation

katepluginmanager.cpp

00001 /* This file is part of the KDE project 00002 Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org> 00003 Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org> 00004 Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License version 2 as published by the Free Software Foundation. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include "katepluginmanager.h" 00022 #include "katepluginmanager.moc" 00023 00024 #include "kateapp.h" 00025 #include "katemainwindow.h" 00026 00027 #include <kconfig.h> 00028 #include <qstringlist.h> 00029 #include <kmessagebox.h> 00030 #include <kdebug.h> 00031 #include <qfile.h> 00032 00033 KatePluginManager::KatePluginManager(QObject *parent) : QObject (parent) 00034 { 00035 m_pluginManager = new Kate::PluginManager (this); 00036 setupPluginList (); 00037 00038 loadConfig (); 00039 loadAllEnabledPlugins (); 00040 } 00041 00042 KatePluginManager::~KatePluginManager() 00043 { 00044 // first write config 00045 writeConfig (); 00046 00047 // than unload the plugins 00048 unloadAllPlugins (); 00049 m_pluginList.setAutoDelete(true); 00050 m_pluginList.clear(); 00051 } 00052 00053 void KatePluginManager::setupPluginList () 00054 { 00055 QValueList<KService::Ptr> traderList= KTrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))"); 00056 00057 for(KTrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it) 00058 { 00059 KService::Ptr ptr = (*it); 00060 00061 QString pVersion = ptr->property("X-Kate-Version").toString(); 00062 00063 if ((pVersion >= "2.2") && (pVersion <= KATE_VERSION)) 00064 { 00065 KatePluginInfo *info = new KatePluginInfo; 00066 00067 info->load = false; 00068 info->service = ptr; 00069 info->plugin = 0L; 00070 00071 m_pluginList.append(info); 00072 } 00073 } 00074 } 00075 00076 void KatePluginManager::loadConfig () 00077 { 00078 kapp->config()->setGroup("Kate Plugins"); 00079 00080 for (uint i=0; i<m_pluginList.count(); i++) 00081 m_pluginList.at(i)->load = kapp->config()->readBoolEntry(m_pluginList.at(i)->service->library(), false) || 00082 kapp->config()->readBoolEntry(m_pluginList.at(i)->service->property("X-Kate-PluginName").toString(),false); 00083 } 00084 00085 void KatePluginManager::writeConfig () 00086 { 00087 kapp->config()->setGroup("Kate Plugins"); 00088 00089 for (uint i=0; i<m_pluginList.count(); i++) { 00090 KatePluginInfo *info=m_pluginList.at(i); 00091 QString saveName=info->service->property("X-Kate-PluginName").toString(); 00092 if (saveName.isEmpty()) 00093 saveName=info->service->library(); 00094 kapp->config()->writeEntry(saveName, m_pluginList.at(i)->load); 00095 } 00096 } 00097 00098 void KatePluginManager::loadAllEnabledPlugins () 00099 { 00100 for (uint i=0; i<m_pluginList.count(); i++) 00101 { 00102 if (m_pluginList.at(i)->load) 00103 loadPlugin (m_pluginList.at(i)); 00104 else 00105 unloadPlugin (m_pluginList.at(i)); 00106 } 00107 } 00108 00109 void KatePluginManager::unloadAllPlugins () 00110 { 00111 for (uint i=0; i<m_pluginList.count(); i++) 00112 { 00113 if (m_pluginList.at(i)->plugin) 00114 unloadPlugin (m_pluginList.at(i)); 00115 } 00116 } 00117 00118 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win) 00119 { 00120 for (uint i=0; i<m_pluginList.count(); i++) 00121 { 00122 if (m_pluginList.at(i)->load) 00123 enablePluginGUI (m_pluginList.at(i), win); 00124 } 00125 } 00126 00127 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win) 00128 { 00129 for (uint i=0; i<m_pluginList.count(); i++) 00130 { 00131 if (m_pluginList.at(i)->load) 00132 disablePluginGUI (m_pluginList.at(i), win); 00133 } 00134 } 00135 00136 void KatePluginManager::loadPlugin (KatePluginInfo *item) 00137 { 00138 QString pluginName=item->service->property("X-Kate-PluginName").toString(); 00139 if (pluginName.isEmpty()) 00140 pluginName=item->service->library(); 00141 item->load = (item->plugin = Kate::createPlugin (QFile::encodeName(item->service->library()), Kate::application(),0,pluginName)); 00142 } 00143 00144 void KatePluginManager::unloadPlugin (KatePluginInfo *item) 00145 { 00146 disablePluginGUI (item); 00147 if (item->plugin) delete item->plugin; 00148 item->plugin = 0L; 00149 item->load = false; 00150 } 00151 00152 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00153 { 00154 if (!item->plugin) return; 00155 if (!Kate::pluginViewInterface(item->plugin)) return; 00156 00157 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow()); 00158 } 00159 00160 void KatePluginManager::enablePluginGUI (KatePluginInfo *item) 00161 { 00162 if (!item->plugin) return; 00163 if (!Kate::pluginViewInterface(item->plugin)) return; 00164 00165 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++) 00166 { 00167 Kate::pluginViewInterface(item->plugin)->addView(((KateApp*)parent())->mainWindow(i)); 00168 } 00169 } 00170 00171 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00172 { 00173 if (!item->plugin) return; 00174 if (!Kate::pluginViewInterface(item->plugin)) return; 00175 00176 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow()); 00177 } 00178 00179 void KatePluginManager::disablePluginGUI (KatePluginInfo *item) 00180 { 00181 if (!item->plugin) return; 00182 if (!Kate::pluginViewInterface(item->plugin)) return; 00183 00184 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++) 00185 { 00186 Kate::pluginViewInterface(item->plugin)->removeView(((KateApp*)parent())->mainWindow(i)); 00187 } 00188 } 00189 00190 Kate::Plugin *KatePluginManager::plugin(const QString &name) 00191 { 00192 for (uint i=0; i<m_pluginList.count(); i++) 00193 { 00194 KatePluginInfo *info=m_pluginList.at(i); 00195 QString pluginName=info->service->property("X-Kate-PluginName").toString(); 00196 if (pluginName.isEmpty()) 00197 pluginName=info->service->library(); 00198 if (pluginName==name) 00199 { 00200 if (info->plugin) 00201 return info->plugin; 00202 else 00203 break; 00204 } 00205 } 00206 return 0; 00207 } 00208 00209 bool KatePluginManager::pluginAvailable(const QString &){return false;} 00210 class Kate::Plugin *KatePluginManager::loadPlugin(const QString &,bool ){return 0;} 00211 void KatePluginManager::unloadPlugin(const QString &,bool){;}
KDE Logo
This file is part of the documentation for kate Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 13 21:47:01 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003