• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kate
 

kate

  • kate
  • app
katepluginmanager.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
3  Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
4  Copyright (C) 2001 Anders Lund <anders.lund@lund.tdcadsl.dk>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "katepluginmanager.h"
22 #include "katepluginmanager.moc"
23 
24 #include "kateapp.h"
25 #include "katemainwindow.h"
26 
27 #include "../interfaces/application.h"
28 
29 #include <kconfig.h>
30 #include <tqstringlist.h>
31 #include <kmessagebox.h>
32 #include <kdebug.h>
33 #include <tqfile.h>
34 
35 KatePluginManager::KatePluginManager(TQObject *parent) : TQObject (parent)
36 {
37  m_pluginManager = new Kate::PluginManager (this);
38  setupPluginList ();
39 
40  loadConfig ();
41  loadAllEnabledPlugins ();
42 }
43 
44 KatePluginManager::~KatePluginManager()
45 {
46  // first write config
47  writeConfig ();
48 
49  // than unload the plugins
50  unloadAllPlugins ();
51 }
52 
53 KatePluginManager *KatePluginManager::self()
54 {
55  return KateApp::self()->pluginManager ();
56 }
57 
58 void KatePluginManager::setupPluginList ()
59 {
60  TQValueList<KService::Ptr> traderList= KTrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))");
61 
62  for(KTrader::OfferList::Iterator it(traderList.begin()); it != traderList.end(); ++it)
63  {
64  KService::Ptr ptr = (*it);
65 
66  TQString pVersion = ptr->property("X-Kate-Version").toString();
67 
68 // if ((pVersion >= "2.5") && (pVersion <= KateApp::kateVersion(false)))
69  if (pVersion == "2.5")
70  {
71  KatePluginInfo info;
72 
73  info.load = false;
74  info.service = ptr;
75  info.plugin = 0L;
76 
77  m_pluginList.push_back (info);
78  }
79  }
80 }
81 
82 void KatePluginManager::loadConfig ()
83 {
84  KateApp::self()->config()->setGroup("Kate Plugins");
85 
86  for (unsigned int i=0; i < m_pluginList.size(); ++i)
87  m_pluginList[i].load = KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->library(), false) ||
88  KateApp::self()->config()->readBoolEntry (m_pluginList[i].service->property("X-Kate-PluginName").toString(),false);
89 }
90 
91 void KatePluginManager::writeConfig ()
92 {
93  KateApp::self()->config()->setGroup("Kate Plugins");
94 
95  for (unsigned int i=0; i < m_pluginList.size(); ++i)
96  {
97  TQString saveName=m_pluginList[i].service->property("X-Kate-PluginName").toString();
98 
99  if (saveName.isEmpty())
100  saveName = m_pluginList[i].service->library();
101 
102  KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load);
103  }
104 }
105 
106 void KatePluginManager::loadAllEnabledPlugins ()
107 {
108  for (unsigned int i=0; i < m_pluginList.size(); ++i)
109  {
110  if (m_pluginList[i].load)
111  loadPlugin (&m_pluginList[i]);
112  else
113  unloadPlugin (&m_pluginList[i]);
114  }
115 }
116 
117 void KatePluginManager::unloadAllPlugins ()
118 {
119  for (unsigned int i=0; i < m_pluginList.size(); ++i)
120  {
121  if (m_pluginList[i].plugin)
122  unloadPlugin (&m_pluginList[i]);
123  }
124 }
125 
126 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win)
127 {
128  for (unsigned int i=0; i < m_pluginList.size(); ++i)
129  {
130  if (m_pluginList[i].load)
131  enablePluginGUI (&m_pluginList[i], win);
132  }
133 }
134 
135 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win)
136 {
137  for (unsigned int i=0; i < m_pluginList.size(); ++i)
138  {
139  if (m_pluginList[i].load)
140  disablePluginGUI (&m_pluginList[i], win);
141  }
142 }
143 
144 void KatePluginManager::loadPlugin (KatePluginInfo *item)
145 {
146  TQString pluginName=item->service->property("X-Kate-PluginName").toString();
147 
148  if (pluginName.isEmpty())
149  pluginName=item->service->library();
150 
151  item->load = (item->plugin = Kate::createPlugin (TQFile::encodeName(item->service->library()), Kate::application(), 0, pluginName));
152 }
153 
154 void KatePluginManager::unloadPlugin (KatePluginInfo *item)
155 {
156  disablePluginGUI (item);
157  if (item->plugin) delete item->plugin;
158  item->plugin = 0L;
159  item->load = false;
160 }
161 
162 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
163 {
164  if (!item->plugin) return;
165  if (!Kate::pluginViewInterface(item->plugin)) return;
166 
167  Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow());
168 }
169 
170 void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
171 {
172  if (!item->plugin) return;
173  if (!Kate::pluginViewInterface(item->plugin)) return;
174 
175  for (uint i=0; i< KateApp::self()->mainWindows(); i++)
176  {
177  Kate::pluginViewInterface(item->plugin)->addView(KateApp::self()->mainWindow(i)->mainWindow());
178  }
179 }
180 
181 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
182 {
183  if (!item->plugin) return;
184  if (!Kate::pluginViewInterface(item->plugin)) return;
185 
186  Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow());
187 }
188 
189 void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
190 {
191  if (!item->plugin) return;
192  if (!Kate::pluginViewInterface(item->plugin)) return;
193 
194  for (uint i=0; i< KateApp::self()->mainWindows(); i++)
195  {
196  Kate::pluginViewInterface(item->plugin)->removeView(KateApp::self()->mainWindow(i)->mainWindow());
197  }
198 }
199 
200 Kate::Plugin *KatePluginManager::plugin(const TQString &name)
201 {
202  for (unsigned int i=0; i < m_pluginList.size(); ++i)
203  {
204  KatePluginInfo *info = &m_pluginList[i];
205  TQString pluginName=info->service->property("X-Kate-PluginName").toString();
206  if (pluginName.isEmpty())
207  pluginName=info->service->library();
208  if (pluginName==name)
209  {
210  if (info->plugin)
211  return info->plugin;
212  else
213  break;
214  }
215  }
216  return 0;
217 }
218 
219 bool KatePluginManager::pluginAvailable(const TQString &){return false;}
220 class Kate::Plugin *KatePluginManager::loadPlugin(const TQString &,bool ){return 0;}
221 void KatePluginManager::unloadPlugin(const TQString &,bool){;}

kate

Skip menu "kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kate

Skip menu "kate"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kate by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |