katepluginmanager.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00045 writeConfig ();
00046
00047
00048 unloadAllPlugins ();
00049 m_pluginList.setAutoDelete(true);
00050 m_pluginList.clear();
00051 }
00052
00053 KatePluginManager *KatePluginManager::self()
00054 {
00055 return KateApp::self()->katePluginManager ();
00056 }
00057
00058 void KatePluginManager::setupPluginList ()
00059 {
00060 QValueList<KService::Ptr> traderList= KTrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))");
00061
00062 for(KTrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it)
00063 {
00064 KService::Ptr ptr = (*it);
00065
00066 QString pVersion = ptr->property("X-Kate-Version").toString();
00067
00068 if ((pVersion >= "2.2") && (pVersion <= KATE_VERSION))
00069 {
00070 KatePluginInfo *info = new KatePluginInfo;
00071
00072 info->load = false;
00073 info->service = ptr;
00074 info->plugin = 0L;
00075
00076 m_pluginList.append(info);
00077 }
00078 }
00079 }
00080
00081 void KatePluginManager::loadConfig ()
00082 {
00083 kapp->config()->setGroup("Kate Plugins");
00084
00085 for (uint i=0; i<m_pluginList.count(); i++)
00086 m_pluginList.at(i)->load = kapp->config()->readBoolEntry(m_pluginList.at(i)->service->library(), false) ||
00087 kapp->config()->readBoolEntry(m_pluginList.at(i)->service->property("X-Kate-PluginName").toString(),false);
00088 }
00089
00090 void KatePluginManager::writeConfig ()
00091 {
00092 kapp->config()->setGroup("Kate Plugins");
00093
00094 for (uint i=0; i<m_pluginList.count(); i++) {
00095 KatePluginInfo *info=m_pluginList.at(i);
00096 QString saveName=info->service->property("X-Kate-PluginName").toString();
00097 if (saveName.isEmpty())
00098 saveName=info->service->library();
00099 kapp->config()->writeEntry(saveName, m_pluginList.at(i)->load);
00100 }
00101 }
00102
00103 void KatePluginManager::loadAllEnabledPlugins ()
00104 {
00105 for (uint i=0; i<m_pluginList.count(); i++)
00106 {
00107 if (m_pluginList.at(i)->load)
00108 loadPlugin (m_pluginList.at(i));
00109 else
00110 unloadPlugin (m_pluginList.at(i));
00111 }
00112 }
00113
00114 void KatePluginManager::unloadAllPlugins ()
00115 {
00116 for (uint i=0; i<m_pluginList.count(); i++)
00117 {
00118 if (m_pluginList.at(i)->plugin)
00119 unloadPlugin (m_pluginList.at(i));
00120 }
00121 }
00122
00123 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win)
00124 {
00125 for (uint i=0; i<m_pluginList.count(); i++)
00126 {
00127 if (m_pluginList.at(i)->load)
00128 enablePluginGUI (m_pluginList.at(i), win);
00129 }
00130 }
00131
00132 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win)
00133 {
00134 for (uint i=0; i<m_pluginList.count(); i++)
00135 {
00136 if (m_pluginList.at(i)->load)
00137 disablePluginGUI (m_pluginList.at(i), win);
00138 }
00139 }
00140
00141 void KatePluginManager::loadPlugin (KatePluginInfo *item)
00142 {
00143 QString pluginName=item->service->property("X-Kate-PluginName").toString();
00144 if (pluginName.isEmpty())
00145 pluginName=item->service->library();
00146 item->load = (item->plugin = Kate::createPlugin (QFile::encodeName(item->service->library()), Kate::application(),0,pluginName));
00147 }
00148
00149 void KatePluginManager::unloadPlugin (KatePluginInfo *item)
00150 {
00151 disablePluginGUI (item);
00152 if (item->plugin) delete item->plugin;
00153 item->plugin = 0L;
00154 item->load = false;
00155 }
00156
00157 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
00158 {
00159 if (!item->plugin) return;
00160 if (!Kate::pluginViewInterface(item->plugin)) return;
00161
00162 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow());
00163 }
00164
00165 void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
00166 {
00167 if (!item->plugin) return;
00168 if (!Kate::pluginViewInterface(item->plugin)) return;
00169
00170 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++)
00171 {
00172 Kate::pluginViewInterface(item->plugin)->addView(((KateApp*)parent())->mainWindow(i));
00173 }
00174 }
00175
00176 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
00177 {
00178 if (!item->plugin) return;
00179 if (!Kate::pluginViewInterface(item->plugin)) return;
00180
00181 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow());
00182 }
00183
00184 void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
00185 {
00186 if (!item->plugin) return;
00187 if (!Kate::pluginViewInterface(item->plugin)) return;
00188
00189 for (uint i=0; i< ((KateApp*)parent())->mainWindows(); i++)
00190 {
00191 Kate::pluginViewInterface(item->plugin)->removeView(((KateApp*)parent())->mainWindow(i));
00192 }
00193 }
00194
00195 Kate::Plugin *KatePluginManager::plugin(const QString &name)
00196 {
00197 for (uint i=0; i<m_pluginList.count(); i++)
00198 {
00199 KatePluginInfo *info=m_pluginList.at(i);
00200 QString pluginName=info->service->property("X-Kate-PluginName").toString();
00201 if (pluginName.isEmpty())
00202 pluginName=info->service->library();
00203 if (pluginName==name)
00204 {
00205 if (info->plugin)
00206 return info->plugin;
00207 else
00208 break;
00209 }
00210 }
00211 return 0;
00212 }
00213
00214 bool KatePluginManager::pluginAvailable(const QString &){return false;}
00215 class Kate::Plugin *KatePluginManager::loadPlugin(const QString &,bool ){return 0;}
00216 void KatePluginManager::unloadPlugin(const QString &,bool){;}
This file is part of the documentation for kate Library Version 3.4.0.