21 #include "katepluginmanager.h"
22 #include "katepluginmanager.moc"
25 #include "katemainwindow.h"
27 #include "../interfaces/application.h"
29 #include <tdeconfig.h>
30 #include <tqstringlist.h>
31 #include <tdemessagebox.h>
35 KatePluginManager::KatePluginManager(TQObject *parent) : TQObject (parent)
41 loadAllEnabledPlugins ();
44 KatePluginManager::~KatePluginManager()
53 KatePluginManager *KatePluginManager::self()
58 void KatePluginManager::setupPluginList ()
60 TQValueList<KService::Ptr> traderList= TDETrader::self()->query(
"Kate/Plugin",
"(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))");
62 for(TDETrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it)
64 KService::Ptr ptr = (*it);
66 TQString pVersion = ptr->property(
"X-Kate-Version").toString();
68 if (pVersion ==
"2.5")
76 m_pluginList.push_back (info);
81 void KatePluginManager::loadConfig ()
85 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
86 m_pluginList[i].load =
KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->library(),
false) ||
87 KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->property(
"X-Kate-PluginName").toString(),
false);
90 void KatePluginManager::writeConfig ()
94 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
96 TQString saveName=m_pluginList[i].service->property(
"X-Kate-PluginName").toString();
98 if (saveName.isEmpty())
99 saveName = m_pluginList[i].service->library();
101 KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load);
105 void KatePluginManager::loadAllEnabledPlugins ()
107 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
109 if (m_pluginList[i].load)
110 loadPlugin (&m_pluginList[i]);
112 unloadPlugin (&m_pluginList[i]);
116 void KatePluginManager::unloadAllPlugins ()
118 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
120 if (m_pluginList[i].plugin)
121 unloadPlugin (&m_pluginList[i]);
125 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win)
127 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
129 if (m_pluginList[i].load)
130 enablePluginGUI (&m_pluginList[i], win);
134 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win)
136 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
138 if (m_pluginList[i].load)
139 disablePluginGUI (&m_pluginList[i], win);
143 void KatePluginManager::loadPlugin (KatePluginInfo *item)
145 TQString pluginName=item->service->property(
"X-Kate-PluginName").toString();
147 if (pluginName.isEmpty())
148 pluginName=item->service->library();
150 item->load = (item->plugin = Kate::createPlugin (TQFile::encodeName(item->service->library()),
Kate::application(), 0, pluginName));
153 void KatePluginManager::unloadPlugin (KatePluginInfo *item)
155 disablePluginGUI (item);
156 if (item->plugin)
delete item->plugin;
161 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
163 if (!item->plugin)
return;
164 if (!Kate::pluginViewInterface(item->plugin))
return;
166 Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow());
169 void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
171 if (!item->plugin)
return;
172 if (!Kate::pluginViewInterface(item->plugin))
return;
176 Kate::pluginViewInterface(item->plugin)->addView(
KateApp::self()->mainWindow(i)->mainWindow());
180 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
182 if (!item->plugin)
return;
183 if (!Kate::pluginViewInterface(item->plugin))
return;
185 Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow());
188 void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
190 if (!item->plugin)
return;
191 if (!Kate::pluginViewInterface(item->plugin))
return;
195 Kate::pluginViewInterface(item->plugin)->removeView(
KateApp::self()->mainWindow(i)->mainWindow());
199 Kate::Plugin *KatePluginManager::plugin(
const TQString &name)
201 for (
unsigned int i=0; i < m_pluginList.size(); ++i)
203 KatePluginInfo *info = &m_pluginList[i];
204 TQString pluginName=info->service->property(
"X-Kate-PluginName").toString();
205 if (pluginName.isEmpty())
206 pluginName=info->service->library();
207 if (pluginName==name)
218 bool KatePluginManager::pluginAvailable(
const TQString &){
return false;}
219 class Kate::Plugin *KatePluginManager::loadPlugin(
const TQString &,
bool ){
return 0;}
220 void KatePluginManager::unloadPlugin(
const TQString &,
bool){;}
static KateApp * self()
static accessor to avoid casting ;)
KatePluginManager * pluginManager()
other accessors for global unique instances
uint mainWindows() const
give back number of existing main windows
This interface provides access to the Kate Plugin Manager.
Application * application()
Returns the application object.