• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Generic Shell
 

KDevelop Generic Shell

  • src
plugincontroller.cpp
1 #include <tqfile.h>
2 #include <tqvbox.h>
3 
4 #include <tdecmdlineargs.h>
5 #include <tdeapplication.h>
6 #include <klibloader.h>
7 #include <kservice.h>
8 #include <ktrader.h>
9 #include <tdemessagebox.h>
10 #include <tdeconfig.h>
11 #include <tdelocale.h>
12 #include <tdemainwindow.h>
13 #include <tdeparts/componentfactory.h>
14 #include <assert.h>
15 #include <kdebug.h>
16 #include <kdialogbase.h>
17 #include <tdecmdlineargs.h>
18 #include <kstandarddirs.h>
19 #include <kstatusbar.h>
20 #include <kiconloader.h>
21 
22 #include <kdevapi.h>
23 #include <kdevplugin.h>
24 #include <kdevmakefrontend.h>
25 #include <kdevappfrontend.h>
26 #include <kdevdifffrontend.h>
27 #include <kdevsourceformatter.h>
28 #include <kdevcreatefile.h>
29 #include <kdevplugininfo.h>
30 #include <tdeaction.h>
31 
32 #include <profileengine.h>
33 
34 #include "core.h"
35 #include "api.h"
36 #include "toplevel.h"
37 #include "projectmanager.h"
38 //#include "partselectwidget.h"
39 #include "domutil.h"
40 #include "plugincontroller.h"
41 #include "pluginselectdialog.h"
42 
43 #include "shellextension.h"
44 
45 // a separate method in this anonymous namespace to avoid having it all
46 // inline in plugincontroller.h
47 namespace
48 {
49  template <class ComponentType>
50  ComponentType *loadDefaultPart( const TQString &serviceType )
51  {
52  TDETrader::OfferList offers = TDETrader::self()->query(serviceType, TQString("[X-TDevelop-Version] == %1").arg(TDEVELOP_PLUGIN_VERSION));
53  TDETrader::OfferList::ConstIterator serviceIt = offers.begin();
54  for ( ; serviceIt != offers.end(); ++serviceIt ) {
55  KService::Ptr service = *serviceIt;
56 
57  ComponentType *part = KParts::ComponentFactory
58  ::createInstanceFromService< ComponentType >( service, API::getInstance(), 0,
59  PluginController::argumentsFromService( service ) );
60 
61  if ( part )
62  return part;
63  }
64  return 0;
65  }
66 }
67 
68 PluginController *PluginController::s_instance = 0;
69 
70 
71 PluginController *PluginController::getInstance()
72 {
73  if (!s_instance)
74  s_instance = new PluginController();
75  return s_instance;
76 }
77 
78 
79 PluginController::PluginController()
80  : KDevPluginController()
81 {
82 /* m_defaultProfile = TQString::fromLatin1( "FullIDE" );
83  m_defaultProfilePath = kapp->dirs()->localtdedir() + "/" +
84  TDEStandardDirs::kde_default( "data" ) +
85  TQString::fromLatin1("/tdevelop/profiles/FullIDE");*/
86 
87  TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs();
88  if( args->isSet("profile") ){
89  m_profile = TQString::fromLocal8Bit( args->getOption("profile") );
90  } else {
91  m_profile = ShellExtension::getInstance()->defaultProfile();
92  }
93 
94 }
95 
96 
97 void PluginController::loadInitialPlugins()
98 {
99  loadCorePlugins();
100 
101  TQStringList disableList;
102  Profile * profile = engine().findProfile( currentProfile() );
103  if( profile )
104  {
105  Profile::EntryList disableEntryList = profile->list( Profile::ExplicitDisable );
106  for ( Profile::EntryList::const_iterator it = disableEntryList.constBegin(); it != disableEntryList.constEnd(); ++it )
107  {
108  disableList << (*it).name;
109  }
110  }
111  loadGlobalPlugins( disableList );
112 }
113 
114 
115 PluginController::~PluginController()
116 {
117  unloadPlugins();
118 }
119 
120 void PluginController::loadCorePlugins()
121 {
122  TDETrader::OfferList coreOffers = m_engine.offers(m_profile, ProfileEngine::Core);
123  loadPlugins( coreOffers );
124 }
125 
126 void PluginController::loadGlobalPlugins( const TQStringList & ignorePlugins )
127 {
128  TDETrader::OfferList globalOffers = m_engine.offers(m_profile, ProfileEngine::Global);
129  loadPlugins( globalOffers, ignorePlugins );
130 }
131 
132 void PluginController::loadProjectPlugins( const TQStringList & ignorePlugins )
133 {
134  TDETrader::OfferList projectOffers = m_engine.offers(m_profile, ProfileEngine::Project);
135  loadPlugins( projectOffers, ignorePlugins );
136 }
137 
138 void PluginController::loadPlugins( TDETrader::OfferList offers, const TQStringList & ignorePlugins )
139 {
140 
141  TopLevel::getInstance()->main()->setFocus();
142  for (TDETrader::OfferList::ConstIterator it = offers.begin(); it != offers.end(); ++it)
143  {
144  TQString name = (*it)->desktopEntryName();
145 
146  // Check if it is already loaded or shouldn't be
147  if( m_parts[ name ] != 0 || ignorePlugins.contains( name ) )
148  continue;
149 
150  emit loadingPlugin(i18n("Loading: %1").arg((*it)->genericName()));
151 
152  KDevPlugin *plugin = loadPlugin( *it );
153  if ( plugin )
154  {
155  m_parts.insert( name, plugin );
156  integratePart( plugin );
157  }
158  }
159 }
160 
161 void PluginController::unloadPlugins()
162 {
163  for( TQDictIterator<KDevPlugin> it( m_parts ); !it.isEmpty(); )
164  {
165  KDevPlugin* part = it.current();
166  removePart( part );
167  m_parts.remove( it.currentKey() );
168  delete part;
169  }
170 }
171 
172 void PluginController::unloadProjectPlugins( )
173 {
174  // this is nasty, but we need to unload the version control plugin too, and the
175  // right moment to do this is here
176  TDETrader::OfferList offers = TDETrader::self()->query("TDevelop/VersionControl", "");
177 
178  offers += m_engine.offers(m_profile, ProfileEngine::Project);
179  for (TDETrader::OfferList::ConstIterator it = offers.begin(); it != offers.end(); ++it)
180  {
181  TQString name = (*it)->desktopEntryName();
182 
183  if ( KDevPlugin * plugin = m_parts[ name ] )
184  {
185  kdDebug(9000) << " *** Removing: " << name << endl;
186  removeAndForgetPart( name, plugin );
187  delete plugin;
188  }
189  }
190 }
191 
192 void PluginController::unloadPlugins( TQStringList const & unloadParts )
193 {
194  TQStringList::ConstIterator it = unloadParts.begin();
195  while ( it != unloadParts.end() )
196  {
197  KDevPlugin* part = m_parts[ *it ];
198  if( part )
199  {
200  kdDebug(9000) << " *** Removing: " << *it << endl;
201  removePart( part );
202  m_parts.remove( *it );
203  delete part;
204  }
205  ++it;
206  }
207 }
208 
209 KDevPlugin *PluginController::loadPlugin( const KService::Ptr &service )
210 {
211  int err = 0;
212  KDevPlugin * pl = KParts::ComponentFactory
213  ::createInstanceFromService<KDevPlugin>( service, API::getInstance(), 0,
214  argumentsFromService( service ), &err );
215  if (!pl)
216  {
217  KMessageBox::error(
218  0,
219  i18n("<b>Could not load plugin</b><br>"
220  "Plugin %1 could not be loaded<br>"
221  "Library loader error: %2").arg(service->name()).
222  arg(KLibLoader::self()->lastErrorMessage()),
223  i18n("Could not load plugin"));
224  }
225 // kdDebug() << "ERR: " << err << endl;
226  return pl;
227 }
228 
229 TQStringList PluginController::argumentsFromService( const KService::Ptr &service )
230 {
231  TQStringList args;
232  if ( !service )
233  // service is a reference to a pointer, so a check whether it is 0 is still required
234  return args;
235  TQVariant prop = service->property( "X-TDevelop-Args" );
236  if ( prop.isValid() )
237  args = TQStringList::split( " ", prop.toString() );
238  return args;
239 }
240 
241 void PluginController::integratePart(KXMLGUIClient *part)
242 {
243  if ( ! part ) return;
244  Core::setupShourtcutTips(part);
245 
246  TopLevel::getInstance()->main()->guiFactory()->addClient(part);
247  connect( part->actionCollection(), TQT_SIGNAL( actionStatusText( const TQString & ) ),
248  TopLevel::getInstance()->main()->actionCollection(), TQT_SIGNAL( actionStatusText( const TQString & ) ) );
249 }
250 
251 void PluginController::integrateAndRememberPart(const TQString &name, KDevPlugin *part)
252 {
253  m_parts.insert(name, part);
254  integratePart(part);
255 }
256 
257 void PluginController::removePart(KXMLGUIClient *part)
258 {
259  if (TopLevel::mainWindowValid()) // is 0 when window was already closed
260  TopLevel::getInstance()->main()->guiFactory()->removeClient(part);
261 }
262 
263 void PluginController::removeAndForgetPart(const TQString &name, KDevPlugin *part)
264 {
265  kdDebug() << "removing: " << name << endl;
266  m_parts.remove(name);
267  removePart(part);
268 }
269 
270 const TQValueList<KDevPlugin*> PluginController::loadedPlugins()
271 {
272  TQValueList<KDevPlugin*> plugins;
273  TQDictIterator<KDevPlugin> itt(m_parts);
274  while( itt.current() )
275  {
276  plugins.append( itt.current() );
277  ++itt;
278  }
279  return plugins;
280 }
281 
282 KDevPlugin * PluginController::extension( const TQString & serviceType, const TQString & constraint )
283 {
284  TDETrader::OfferList offers = KDevPluginController::query(serviceType, constraint);
285  for (TDETrader::OfferList::const_iterator it = offers.constBegin(); it != offers.end(); ++it)
286  {
287  KDevPlugin *ext = m_parts[(*it)->desktopEntryName()];
288  if (ext) return ext;
289  }
290  return 0;
291 }
292 
293 KDevPlugin * PluginController::loadPlugin( const TQString & serviceType, const TQString & constraint )
294 {
295  TDETrader::OfferList offers = KDevPluginController::query( serviceType, constraint );
296  if ( !offers.size() == 1 ) return 0;
297 
298  TDETrader::OfferList::const_iterator it = offers.constBegin();
299  TQString name = (*it)->desktopEntryName();
300 
301  KDevPlugin * plugin = 0;
302  if ( plugin = m_parts[ name ] )
303  {
304  return plugin;
305  }
306 
307  if ( plugin = loadPlugin( *it ) )
308  {
309  m_parts.insert( name, plugin );
310  integratePart( plugin );
311  }
312 
313  return plugin;
314 }
315 
316 void PluginController::unloadPlugin( const TQString & plugin )
317 {
318  TQStringList pluginList;
319  pluginList << plugin;
320  unloadPlugins( pluginList );
321 }
322 
323 KURL::List PluginController::profileResources(const TQString &nameFilter)
324 {
325  return m_engine.resources(currentProfile(), nameFilter);
326 }
327 
328 KURL::List PluginController::profileResourcesRecursive(const TQString &nameFilter)
329 {
330  return m_engine.resourcesRecursive(currentProfile(), nameFilter);
331 }
332 
333 TQString PluginController::changeProfile(const TQString &newProfile)
334 {
335  kdDebug() << "CHANGING PROFILE: from " << currentProfile() << " to " << newProfile << endl;
336  TQStringList unload;
337  TDETrader::OfferList coreLoad;
338  TDETrader::OfferList globalLoad;
339  m_engine.diffProfiles(ProfileEngine::Core, currentProfile(), newProfile, unload, coreLoad);
340  m_engine.diffProfiles(ProfileEngine::Global, currentProfile(), newProfile, unload, globalLoad);
341 
342  TQString oldProfile = m_profile;
343  m_profile = newProfile;
344 
345  unloadPlugins(unload);
346  loadPlugins( coreLoad );
347  loadPlugins( globalLoad );
348 
349  return oldProfile;
350 }
351 
352 void PluginController::selectPlugins( )
353 {
354  kdDebug(9000) << k_funcinfo << endl;
355 
356  PluginSelectDialog dlg;
357  if ( dlg.exec() == TQDialog::Accepted )
358  {
359  TQStringList unselectedPlugins = dlg.unselectedPluginNames();
360 
361  kdDebug(9000) << unselectedPlugins << endl;
362 
363  unloadPlugins( unselectedPlugins );
364  loadGlobalPlugins( unselectedPlugins );
365 
366  if ( ProjectManager::getInstance()->projectLoaded() )
367  {
368  loadProjectPlugins( unselectedPlugins );
369  DomUtil::writeListEntry( *API::getInstance()->projectDom(), "/general/ignoreparts", "part", unselectedPlugins );
370  }
371  }
372 }
373 
374 /*
375 KDevPlugin * PluginController::getPlugin( const KService::Ptr & service )
376 {
377  KDevPlugin * plugin = m_parts[ (*it)->name() ];
378  if ( !plugin )
379  {
380  KDevPlugin * plugin = loadPlugin( *it );
381  if ( plugin )
382  {
383  integratePart( plugin );
384  m_parts.insert( (*it)->name(), plugin );
385  }
386  }
387  return plugin;
388 }
389 */
390 #include "plugincontroller.moc"
391 
PluginController
Plugin controller implementation.
Definition: plugincontroller.h:23
Core::setupShourtcutTips
static void setupShourtcutTips(KXMLGUIClient *client=0)
Setup shourtcut tips.
Definition: core.cpp:32
ShellExtension::defaultProfile
virtual TQString defaultProfile()=0
Reimplement to set a default profile for the shell.
TopLevel::getInstance
static KDevMainWindow * getInstance()
Get a pointer to the single KDevTopLevel object.
Definition: toplevel.cpp:18
ShellExtension::getInstance
static ShellExtension * getInstance()
Returns an instance of a shell.
Definition: shellextension.h:42

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Generic Shell

Skip menu "KDevelop Generic Shell"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Generic Shell by doxygen 1.8.13
This website is maintained by Timothy Pearson.