• 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 <tdeconfig.h>
30 #include <tqstringlist.h>
31 #include <tdemessagebox.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= TDETrader::self()->query("Kate/Plugin", "(not ('Kate/ProjectPlugin' in ServiceTypes)) and (not ('Kate/InitPlugin' in ServiceTypes))");
61 
62  for(TDETrader::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")
69  {
70  KatePluginInfo info;
71 
72  info.load = false;
73  info.service = ptr;
74  info.plugin = 0L;
75 
76  m_pluginList.push_back (info);
77  }
78  }
79 }
80 
81 void KatePluginManager::loadConfig ()
82 {
83  KateApp::self()->config()->setGroup("Kate Plugins");
84 
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);
88 }
89 
90 void KatePluginManager::writeConfig ()
91 {
92  KateApp::self()->config()->setGroup("Kate Plugins");
93 
94  for (unsigned int i=0; i < m_pluginList.size(); ++i)
95  {
96  TQString saveName=m_pluginList[i].service->property("X-Kate-PluginName").toString();
97 
98  if (saveName.isEmpty())
99  saveName = m_pluginList[i].service->library();
100 
101  KateApp::self()->config()->writeEntry (saveName, m_pluginList[i].load);
102  }
103 }
104 
105 void KatePluginManager::loadAllEnabledPlugins ()
106 {
107  for (unsigned int i=0; i < m_pluginList.size(); ++i)
108  {
109  if (m_pluginList[i].load)
110  loadPlugin (&m_pluginList[i]);
111  else
112  unloadPlugin (&m_pluginList[i]);
113  }
114 }
115 
116 void KatePluginManager::unloadAllPlugins ()
117 {
118  for (unsigned int i=0; i < m_pluginList.size(); ++i)
119  {
120  if (m_pluginList[i].plugin)
121  unloadPlugin (&m_pluginList[i]);
122  }
123 }
124 
125 void KatePluginManager::enableAllPluginsGUI (KateMainWindow *win)
126 {
127  for (unsigned int i=0; i < m_pluginList.size(); ++i)
128  {
129  if (m_pluginList[i].load)
130  enablePluginGUI (&m_pluginList[i], win);
131  }
132 }
133 
134 void KatePluginManager::disableAllPluginsGUI (KateMainWindow *win)
135 {
136  for (unsigned int i=0; i < m_pluginList.size(); ++i)
137  {
138  if (m_pluginList[i].load)
139  disablePluginGUI (&m_pluginList[i], win);
140  }
141 }
142 
143 void KatePluginManager::loadPlugin (KatePluginInfo *item)
144 {
145  TQString pluginName=item->service->property("X-Kate-PluginName").toString();
146 
147  if (pluginName.isEmpty())
148  pluginName=item->service->library();
149 
150  item->load = (item->plugin = Kate::createPlugin (TQFile::encodeName(item->service->library()), Kate::application(), 0, pluginName));
151 }
152 
153 void KatePluginManager::unloadPlugin (KatePluginInfo *item)
154 {
155  disablePluginGUI (item);
156  if (item->plugin) delete item->plugin;
157  item->plugin = 0L;
158  item->load = false;
159 }
160 
161 void KatePluginManager::enablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
162 {
163  if (!item->plugin) return;
164  if (!Kate::pluginViewInterface(item->plugin)) return;
165 
166  Kate::pluginViewInterface(item->plugin)->addView(win->mainWindow());
167 }
168 
169 void KatePluginManager::enablePluginGUI (KatePluginInfo *item)
170 {
171  if (!item->plugin) return;
172  if (!Kate::pluginViewInterface(item->plugin)) return;
173 
174  for (uint i=0; i< KateApp::self()->mainWindows(); i++)
175  {
176  Kate::pluginViewInterface(item->plugin)->addView(KateApp::self()->mainWindow(i)->mainWindow());
177  }
178 }
179 
180 void KatePluginManager::disablePluginGUI (KatePluginInfo *item, KateMainWindow *win)
181 {
182  if (!item->plugin) return;
183  if (!Kate::pluginViewInterface(item->plugin)) return;
184 
185  Kate::pluginViewInterface(item->plugin)->removeView(win->mainWindow());
186 }
187 
188 void KatePluginManager::disablePluginGUI (KatePluginInfo *item)
189 {
190  if (!item->plugin) return;
191  if (!Kate::pluginViewInterface(item->plugin)) return;
192 
193  for (uint i=0; i< KateApp::self()->mainWindows(); i++)
194  {
195  Kate::pluginViewInterface(item->plugin)->removeView(KateApp::self()->mainWindow(i)->mainWindow());
196  }
197 }
198 
199 Kate::Plugin *KatePluginManager::plugin(const TQString &name)
200 {
201  for (unsigned int i=0; i < m_pluginList.size(); ++i)
202  {
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)
208  {
209  if (info->plugin)
210  return info->plugin;
211  else
212  break;
213  }
214  }
215  return 0;
216 }
217 
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){;}
KateApp::self
static KateApp * self()
static accessor to avoid casting ;)
Definition: kateapp.cpp:114
KateApp::pluginManager
KatePluginManager * pluginManager()
other accessors for global unique instances
Definition: kateapp.cpp:367
KateApp::mainWindows
uint mainWindows() const
give back number of existing main windows
Definition: kateapp.cpp:470
Kate::PluginManager
This interface provides access to the Kate Plugin Manager.
Definition: pluginmanager.h:31
Kate::application
Application * application()
Returns the application object.
Definition: application.cpp:91

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
  • libkonq
  • twin
  •   lib
Generated for kate by doxygen 1.9.1
This website is maintained by Timothy Pearson.