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., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "katepluginmanager.h" 00022 #include "katepluginmanager.moc" 00023 00024 #include "kateapp.h" 00025 #include "katemainwindow.h" 00026 00027 #include "../interfaces/application.h" 00028 00029 #include <tdeconfig.h> 00030 #include <tqstringlist.h> 00031 #include <tdemessagebox.h> 00032 #include <kdebug.h> 00033 #include <tqfile.h> 00034 00035 KatePluginManager::KatePluginManager(TQObject *parent) : TQObject (parent) 00036 { 00037 m_pluginManager = new Kate::PluginManager (this); 00038 setupPluginList (); 00039 00040 loadConfig (); 00041 loadAllEnabledPlugins (); 00042 } 00043 00044 KatePluginManager::~KatePluginManager() 00045 { 00046 // first write config 00047 writeConfig (); 00048 00049 // than unload the plugins 00050 unloadAllPlugins (); 00051 } 00052 00053 KatePluginManager *KatePluginManager::self() 00054 { 00055 return KateApp::self()->pluginManager (); 00056 } 00057 00058 void KatePluginManager::setupPluginList () 00059 { 00060 TQValueList<KService::Ptr> traderList= TDETrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))"); 00061 00062 for(TDETrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it) 00063 { 00064 KService::Ptr ptr = (*it); 00065 00066 TQString pVersion = ptr->property("X-Kate-Version").toString(); 00067 00068 if (pVersion == "2.5") 00069 { 00070 KatePluginInfo info; 00071 00072 info.load = false; 00073 info.service = ptr; 00074 info.plugin = 0L; 00075 00076 m_pluginList.push_back (info); 00077 } 00078 } 00079 } 00080 00081 void KatePluginManager::loadConfig () 00082 { 00083 KateApp::self()->config()->setGroup("Kate Plugins"); 00084 00085 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00086 m_pluginList[i].load = KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->library(), false) || 00087 KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->property("X-Kate-PluginName").toString(),false); 00088 } 00089 00090 void KatePluginManager::writeConfig () 00091 { 00092 KateApp::self()->config()->setGroup("Kate Plugins"); 00093 00094 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00095 { 00096 TQString saveName=m_pluginList[i].service->property("X-Kate-PluginName").toString(); 00097 00098 if (saveName.isEmpty()) 00099 saveName = m_pluginList[i].service->library(); 00100 00101 KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load); 00102 } 00103 } 00104 00105 void KatePluginManager::loadAllEnabledPlugins () 00106 { 00107 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00108 { 00109 if (m_pluginList[i].load) 00110 loadPlugin (&m_pluginList[i]); 00111 else 00112 unloadPlugin (&m_pluginList[i]); 00113 } 00114 } 00115 00116 void KatePluginManager::unloadAllPlugins () 00117 { 00118 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00119 { 00120 if (m_pluginList[i].plugin) 00121 unloadPlugin (&m_pluginList[i]); 00122 } 00123 } 00124 00125 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win) 00126 { 00127 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00128 { 00129 if (m_pluginList[i].load) 00130 enablePluginGUI (&m_pluginList[i], win); 00131 } 00132 } 00133 00134 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win) 00135 { 00136 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00137 { 00138 if (m_pluginList[i].load) 00139 disablePluginGUI (&m_pluginList[i], win); 00140 } 00141 } 00142 00143 void KatePluginManager::loadPlugin (KatePluginInfo *item) 00144 { 00145 TQString pluginName=item->service->property("X-Kate-PluginName").toString(); 00146 00147 if (pluginName.isEmpty()) 00148 pluginName=item->service->library(); 00149 00150 item->load = (item->plugin = Kate::createPlugin (TQFile::encodeName(item->service->library()), Kate::application(), 0, pluginName)); 00151 } 00152 00153 void KatePluginManager::unloadPlugin (KatePluginInfo *item) 00154 { 00155 disablePluginGUI (item); 00156 if (item->plugin) delete item->plugin; 00157 item->plugin = 0L; 00158 item->load = false; 00159 } 00160 00161 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00162 { 00163 if (!item->plugin) return; 00164 if (!Kate::pluginViewInterface(item->plugin)) return; 00165 00166 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow()); 00167 } 00168 00169 void KatePluginManager::enablePluginGUI (KatePluginInfo *item) 00170 { 00171 if (!item->plugin) return; 00172 if (!Kate::pluginViewInterface(item->plugin)) return; 00173 00174 for (uint i=0; i< KateApp::self()->mainWindows(); i++) 00175 { 00176 Kate::pluginViewInterface(item->plugin)->addView(KateApp::self()->mainWindow(i)->mainWindow()); 00177 } 00178 } 00179 00180 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win) 00181 { 00182 if (!item->plugin) return; 00183 if (!Kate::pluginViewInterface(item->plugin)) return; 00184 00185 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow()); 00186 } 00187 00188 void KatePluginManager::disablePluginGUI (KatePluginInfo *item) 00189 { 00190 if (!item->plugin) return; 00191 if (!Kate::pluginViewInterface(item->plugin)) return; 00192 00193 for (uint i=0; i< KateApp::self()->mainWindows(); i++) 00194 { 00195 Kate::pluginViewInterface(item->plugin)->removeView(KateApp::self()->mainWindow(i)->mainWindow()); 00196 } 00197 } 00198 00199 Kate::Plugin *KatePluginManager::plugin(const TQString &name) 00200 { 00201 for (unsigned int i=0; i < m_pluginList.size(); ++i) 00202 { 00203 KatePluginInfo *info = &m_pluginList[i]; 00204 TQString pluginName=info->service->property("X-Kate-PluginName").toString(); 00205 if (pluginName.isEmpty()) 00206 pluginName=info->service->library(); 00207 if (pluginName==name) 00208 { 00209 if (info->plugin) 00210 return info->plugin; 00211 else 00212 break; 00213 } 00214 } 00215 return 0; 00216 } 00217 00218 bool KatePluginManager::pluginAvailable(const TQString &){return false;} 00219 class Kate::Plugin *KatePluginManager::loadPlugin(const TQString &,bool ){return 0;} 00220 void KatePluginManager::unloadPlugin(const TQString &,bool){;}