kate
katepluginmanager.cpp
Go to the documentation of this file.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 "../interfaces/application.h"
00028
00029 #include <kconfig.h>
00030 #include <qstringlist.h>
00031 #include <kmessagebox.h>
00032 #include <kdebug.h>
00033 #include <qfile.h>
00034
00035 KatePluginManager::KatePluginManager(QObject *parent) : QObject (parent)
00036 {
00037 m_pluginManager = new Kate::PluginManager (this);
00038 setupPluginList ();
00039
00040 loadConfig ();
00041 loadAllEnabledPlugins ();
00042 }
00043
00044 KatePluginManager::~KatePluginManager()
00045 {
00046
00047 writeConfig ();
00048
00049
00050 unloadAllPlugins ();
00051 }
00052
00053 KatePluginManager *KatePluginManager::self()
00054 {
00055 return KateApp::self()->pluginManager ();
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
00069 if (pVersion == "2.5")
00070 {
00071 KatePluginInfo info;
00072
00073 info.load = false;
00074 info.service = ptr;
00075 info.plugin = 0L;
00076
00077 m_pluginList.push_back (info);
00078 }
00079 }
00080 }
00081
00082 void KatePluginManager::loadConfig ()
00083 {
00084 KateApp::self()->config()->setGroup("Kate Plugins");
00085
00086 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00087 m_pluginList[i].load = KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->library(), false) ||
00088 KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->property("X-Kate-PluginName").toString(),false);
00089 }
00090
00091 void KatePluginManager::writeConfig ()
00092 {
00093 KateApp::self()->config()->setGroup("Kate Plugins");
00094
00095 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00096 {
00097 QString saveName=m_pluginList[i].service->property("X-Kate-PluginName").toString();
00098
00099 if (saveName.isEmpty())
00100 saveName = m_pluginList[i].service->library();
00101
00102 KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load);
00103 }
00104 }
00105
00106 void KatePluginManager::loadAllEnabledPlugins ()
00107 {
00108 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00109 {
00110 if (m_pluginList[i].load)
00111 loadPlugin (&m_pluginList[i]);
00112 else
00113 unloadPlugin (&m_pluginList[i]);
00114 }
00115 }
00116
00117 void KatePluginManager::unloadAllPlugins ()
00118 {
00119 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00120 {
00121 if (m_pluginList[i].plugin)
00122 unloadPlugin (&m_pluginList[i]);
00123 }
00124 }
00125
00126 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win)
00127 {
00128 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00129 {
00130 if (m_pluginList[i].load)
00131 enablePluginGUI (&m_pluginList[i], win);
00132 }
00133 }
00134
00135 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win)
00136 {
00137 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00138 {
00139 if (m_pluginList[i].load)
00140 disablePluginGUI (&m_pluginList[i], win);
00141 }
00142 }
00143
00144 void KatePluginManager::loadPlugin (KatePluginInfo *item)
00145 {
00146 QString pluginName=item->service->property("X-Kate-PluginName").toString();
00147
00148 if (pluginName.isEmpty())
00149 pluginName=item->service->library();
00150
00151 item->load = (item->plugin = Kate::createPlugin (QFile::encodeName(item->service->library()), Kate::application(), 0, pluginName));
00152 }
00153
00154 void KatePluginManager::unloadPlugin (KatePluginInfo *item)
00155 {
00156 disablePluginGUI (item);
00157 if (item->plugin) delete item->plugin;
00158 item->plugin = 0L;
00159 item->load = false;
00160 }
00161
00162 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
00163 {
00164 if (!item->plugin) return;
00165 if (!Kate::pluginViewInterface(item->plugin)) return;
00166
00167 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow());
00168 }
00169
00170 void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
00171 {
00172 if (!item->plugin) return;
00173 if (!Kate::pluginViewInterface(item->plugin)) return;
00174
00175 for (uint i=0; i< KateApp::self()->mainWindows(); i++)
00176 {
00177 Kate::pluginViewInterface(item->plugin)->addView(KateApp::self()->mainWindow(i)->mainWindow());
00178 }
00179 }
00180
00181 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
00182 {
00183 if (!item->plugin) return;
00184 if (!Kate::pluginViewInterface(item->plugin)) return;
00185
00186 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow());
00187 }
00188
00189 void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
00190 {
00191 if (!item->plugin) return;
00192 if (!Kate::pluginViewInterface(item->plugin)) return;
00193
00194 for (uint i=0; i< KateApp::self()->mainWindows(); i++)
00195 {
00196 Kate::pluginViewInterface(item->plugin)->removeView(KateApp::self()->mainWindow(i)->mainWindow());
00197 }
00198 }
00199
00200 Kate::Plugin *KatePluginManager::plugin(const QString &name)
00201 {
00202 for (unsigned int i=0; i < m_pluginList.size(); ++i)
00203 {
00204 KatePluginInfo *info = &m_pluginList[i];
00205 QString pluginName=info->service->property("X-Kate-PluginName").toString();
00206 if (pluginName.isEmpty())
00207 pluginName=info->service->library();
00208 if (pluginName==name)
00209 {
00210 if (info->plugin)
00211 return info->plugin;
00212 else
00213 break;
00214 }
00215 }
00216 return 0;
00217 }
00218
00219 bool KatePluginManager::pluginAvailable(const QString &){return false;}
00220 class Kate::Plugin *KatePluginManager::loadPlugin(const QString &,bool ){return 0;}
00221 void KatePluginManager::unloadPlugin(const QString &,bool){;}