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 } 00083 00084 void KatePluginManager::writeConfig () 00085 { 00086 kapp->config()->setGroup("Kate Plugins"); 00087 00088 for (uint i=0; i<m_pluginList.count(); i++) 00089 kapp->config()->writeEntry(m_pluginList.at(i)->service->library(), m_pluginList.at(i)->load); 00090 } 00091 00092 void KatePluginManager::loadAllEnabledPlugins () 00093 { 00094 for (uint i=0; i<m_pluginList.count(); i++) 00095 { 00096 if (m_pluginList.at(i)->load) 00097 loadPlugin (m_pluginList.at(i)); 00098 else 00099 unloadPlugin (m_pluginList.at(i)); 00100 } 00101 } 00102 00103 void KatePluginManager::unloadAllPlugins () 00104 { 00105 for (uint i=0; i<m_pluginList.count(); i++) 00106 { 00107 if (m_pluginList.at(i)->plugin) 00108 unloadPlugin (m_pluginList.at(i)); 00109 } 00110 } 00111 00112 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win) 00113 { 00114 for (uint i=0; i<m_pluginList.count(); i++) 00115 { 00116 if (m_pluginList.at(i)->load) 00117 enablePluginGUI (m_pluginList.at(i), win); 00118 } 00119 } 00120 00121 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win) 00122 { 00123 for (uint i=0; i<m_pluginList.count(); i++) 00124 { 00125 if (m_pluginList.at(i)->load) 00126 disablePluginGUI (m_pluginList.at(i), win); 00127 } 00128 } 00129 00130 void KatePluginManager::loadPlugin (KatePluginInfo *item) 00131 { 00132 item->load = (item->plugin = Kate::createPlugin (QFile::encodeName(item->service->library()), Kate::application())); 00133 } 00134 00135 void KatePluginManager::unloadPlugin (KatePluginInfo *item) 00136 { 00137 disablePluginGUI (item); 00138 if (item->plugin) delete item->plugin; 00139 item->plugin = 0L; 00140 item->load = false; 00141 } 00142 00143 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00144 { 00145 if (!item->plugin) return; 00146 if (!Kate::pluginViewInterface(item->plugin)) return; 00147 00148 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow()); 00149 } 00150 00151 void KatePluginManager::enablePluginGUI (KatePluginInfo *item) 00152 { 00153 if (!item->plugin) return; 00154 if (!Kate::pluginViewInterface(item->plugin)) return; 00155 00156 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++) 00157 { 00158 Kate::pluginViewInterface(item->plugin)->addView(((KateApp*)parent())->mainWindow(i)); 00159 } 00160 } 00161 00162 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00163 { 00164 if (!item->plugin) return; 00165 if (!Kate::pluginViewInterface(item->plugin)) return; 00166 00167 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow()); 00168 } 00169 00170 void KatePluginManager::disablePluginGUI (KatePluginInfo *item) 00171 { 00172 if (!item->plugin) return; 00173 if (!Kate::pluginViewInterface(item->plugin)) return; 00174 00175 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++) 00176 { 00177 Kate::pluginViewInterface(item->plugin)->removeView(((KateApp*)parent())->mainWindow(i)); 00178 } 00179 } 00180 00181 Kate::Plugin *KatePluginManager::plugin(const QString &name) 00182 { 00183 for (uint i=0; i<m_pluginList.count(); i++) 00184 { 00185 if (m_pluginList.at(i)->service->library()==name) 00186 { 00187 if (m_pluginList.at(i)->plugin) 00188 return m_pluginList.at(i)->plugin; 00189 else 00190 break; 00191 } 00192 } 00193 return 0; 00194 } 00195 00196 bool KatePluginManager::pluginAvailable(const QString &){return false;} 00197 class Kate::Plugin *KatePluginManager::loadPlugin(const QString &,bool ){return 0;} 00198 void KatePluginManager::unloadPlugin(const QString &,bool){;}
KDE Logo
This file is part of the documentation for kate Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Dec 16 19:08:37 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003