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

tdeutils

  • tdeutils
kpluginselector.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 
18 */
19 
20 #include "kpluginselector.h"
21 #include "kpluginselector_p.h"
22 
23 #include <tqtooltip.h>
24 #include <tqvbox.h>
25 #include <tqlabel.h>
26 #include <tqstrlist.h>
27 #include <tqfile.h>
28 #include <tqstring.h>
29 #include <tqlayout.h>
30 #include <tqptrlist.h>
31 #include <tqwidgetstack.h>
32 #include <tqcursor.h>
33 #include <tqapplication.h>
34 #include <tqobjectlist.h>
35 #include <tqcstring.h>
36 
37 #include <kdebug.h>
38 #include <tdelocale.h>
39 #include <tdelistview.h>
40 #include <ksimpleconfig.h>
41 #include <kdialog.h>
42 #include <tdeglobal.h>
43 #include <tdeglobalsettings.h>
44 #include <kstandarddirs.h>
45 #include <ktabctl.h>
46 #include <tdecmoduleinfo.h>
47 #include <tqvaluelist.h>
48 #include <kservice.h>
49 #include <ktrader.h>
50 #include <ktabwidget.h>
51 #include <kiconloader.h>
52 #include <tdecmodule.h>
53 #include "tdecmoduleinfo.h"
54 #include "tdecmoduleloader.h"
55 #include <tqsplitter.h>
56 #include <tqframe.h>
57 #include "kplugininfo.h"
58 #include <kinstance.h>
59 #include <tqptrdict.h>
60 #include <tqstringlist.h>
61 #include "tdecmoduleproxy.h"
62 
63 /*
64  QCheckListViewItem that holds a pointer to the KPluginInfo object.
65  Used in the tooltip code to access additional fields
66 */
67 class KPluginInfoLVI : public TQCheckListItem
68 {
69 public:
70  KPluginInfoLVI( KPluginInfo *pluginInfo, TDEListView *parent )
71  : TQCheckListItem( parent, pluginInfo->name(), TQCheckListItem::CheckBox ), m_pluginInfo( pluginInfo )
72  {
73  }
74 
75  KPluginInfo * pluginInfo() { return m_pluginInfo; }
76 
77 private:
78  KPluginInfo *m_pluginInfo;
79 };
80 
81 /*
82  Custom TQToolTip for the list view.
83  The decision whether or not to show tooltips is taken in
84  maybeTip(). See also the TQListView sources from Qt itself.
85 */
86 class KPluginListViewToolTip : public TQToolTip
87 {
88 public:
89  KPluginListViewToolTip( TQWidget *parent, TDEListView *lv );
90 
91  void maybeTip( const TQPoint &pos );
92 
93 private:
94  TDEListView *m_listView;
95 };
96 
97 KPluginListViewToolTip::KPluginListViewToolTip( TQWidget *parent, TDEListView *lv )
98 : TQToolTip( parent ), m_listView( lv )
99 {
100 }
101 
102 void KPluginListViewToolTip::maybeTip( const TQPoint &pos )
103 {
104  if ( !parentWidget() || !m_listView )
105  return;
106 
107  KPluginInfoLVI *item = dynamic_cast<KPluginInfoLVI *>( m_listView->itemAt( pos ) );
108  if ( !item )
109  return;
110 
111  TQString toolTip = i18n( "<qt><table>"
112  "<tr><td><b>Description:</b></td><td>%1</td></tr>"
113  "<tr><td><b>Author:</b></td><td>%2</td></tr>"
114  "<tr><td><b>Version:</b></td><td>%3</td></tr>"
115  "<tr><td><b>License:</b></td><td>%4</td></tr></table></qt>" ).arg( item->pluginInfo()->comment(),
116  item->pluginInfo()->author(), item->pluginInfo()->version(), item->pluginInfo()->license() );
117 
118  //kdDebug( 702 ) << k_funcinfo << "Adding tooltip: itemRect: " << itemRect << ", tooltip: " << toolTip << endl;
119  tip( m_listView->itemRect( item ), toolTip );
120 }
121 
122 struct KPluginSelectionWidget::KPluginSelectionWidgetPrivate
123 {
124  KPluginSelectionWidgetPrivate( KPluginSelector * _kps,
125  const TQString & _cat,
126  TDEConfigGroup * _config )
127  : widgetstack( 0 )
128  , kps( _kps )
129  , config( _config )
130  , tooltip( 0 )
131  , catname( _cat )
132  , currentplugininfo( 0 )
133  , visible( true )
134  , currentchecked( false )
135  , changed( 0 )
136  {
137  moduleParentComponents.setAutoDelete( true );
138  }
139 
140  ~KPluginSelectionWidgetPrivate()
141  {
142  delete config;
143  }
144 
145  TQMap<TQCheckListItem*, KPluginInfo*> pluginInfoMap;
146 
147  TQWidgetStack * widgetstack;
148  KPluginSelector * kps;
149  TDEConfigGroup * config;
150  KPluginListViewToolTip *tooltip;
151 
152  TQDict<TDECModuleInfo> pluginconfigmodules;
153  TQMap<TQString, int> widgetIDs;
154  TQMap<KPluginInfo*, bool> plugincheckedchanged;
155  TQString catname;
156  TQValueList<TDECModuleProxy*> modulelist;
157  TQPtrDict<TQStringList> moduleParentComponents;
158 
159  KPluginInfo * currentplugininfo;
160  bool visible;
161  bool currentchecked;
162  int changed;
163 };
164 
165 KPluginSelectionWidget::KPluginSelectionWidget(
166  const TQValueList<KPluginInfo*> & plugininfos, KPluginSelector * kps,
167  TQWidget * parent, const TQString & catname, const TQString & category,
168  TDEConfigGroup * config, const char * name )
169  : TQWidget( parent, name )
170  , d( new KPluginSelectionWidgetPrivate( kps, catname, config ) )
171 {
172  init( plugininfos, category );
173 }
174 
175 inline TQString KPluginSelectionWidget::catName() const
176 {
177  return d->catname;
178 }
179 
180 void KPluginSelectionWidget::init( const TQValueList<KPluginInfo*> & plugininfos,
181  const TQString & category )
182 {
183  // setup Widgets
184  ( new TQVBoxLayout( this, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
185  TDEListView * listview = new TDEListView( this );
186  d->tooltip = new KPluginListViewToolTip( listview->viewport(), listview );
187  connect( listview, TQT_SIGNAL( pressed( TQListViewItem * ) ), this,
188  TQT_SLOT( executed( TQListViewItem * ) ) );
189  connect( listview, TQT_SIGNAL( spacePressed( TQListViewItem * ) ), this,
190  TQT_SLOT( executed( TQListViewItem * ) ) );
191  connect( listview, TQT_SIGNAL( returnPressed( TQListViewItem * ) ), this,
192  TQT_SLOT( executed( TQListViewItem * ) ) );
193  connect( listview, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), this,
194  TQT_SLOT( executed( TQListViewItem * ) ) );
195  listview->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Preferred );
196  listview->setAcceptDrops( false );
197  listview->setFullWidth( true );
198  listview->setSelectionModeExt( TDEListView::Single );
199  listview->setAllColumnsShowFocus( true );
200  listview->addColumn( i18n( "Name" ) );
201  for( TQValueList<KPluginInfo*>::ConstIterator it = plugininfos.begin();
202  it != plugininfos.end(); ++it )
203  {
204  d->plugincheckedchanged[ *it ] = false;
205  if( !( *it )->isHidden() &&
206  ( category.isNull() || ( *it )->category() == category ) )
207  {
208  TQCheckListItem * item = new KPluginInfoLVI( *it, listview );
209  if( ! ( *it )->icon().isEmpty() )
210  item->setPixmap( 0, SmallIcon( ( *it )->icon(), IconSize( TDEIcon::Small ) ) );
211  item->setOn( ( *it )->isPluginEnabled() );
212  d->pluginInfoMap.insert( item, *it );
213  }
214  }
215 
216  // widgetstack
217  d->widgetstack = d->kps->widgetStack();
218  load();
219  // select and highlight the first item in the plugin list
220  if( listview->firstChild() )
221  listview->setSelected( listview->firstChild(), true );
222 }
223 
224 KPluginSelectionWidget::~KPluginSelectionWidget()
225 {
226  delete d->tooltip;
227  delete d;
228 }
229 
230 bool KPluginSelectionWidget::pluginIsLoaded( const TQString & pluginName ) const
231 {
232  for( TQMap<TQCheckListItem*, KPluginInfo*>::ConstIterator it =
233  d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it )
234  if( it.data()->pluginName() == pluginName )
235  return it.data()->isPluginEnabled();
236  return false;
237 }
238 
239 
240 TQWidget * KPluginSelectionWidget::insertKCM( TQWidget * parent,
241  const TDECModuleInfo & moduleinfo )
242 {
243  TDECModuleProxy * module = new TDECModuleProxy( moduleinfo, false,
244  parent );
245  if( !module->realModule() )
246  {
247  //FIXME: not very verbose
248  TQLabel * label = new TQLabel( i18n( "Error" ), parent );
249  label->setAlignment( Qt::AlignCenter );
250 
251  return label;
252  }
253  // add the KCM to the list so that we can call load/save/defaults on it
254  d->modulelist.append( module );
255  TQStringList * parentComponents = new TQStringList(
256  moduleinfo.service()->property(
257  "X-TDE-ParentComponents" ).toStringList() );
258  d->moduleParentComponents.insert( module, parentComponents );
259  connect( module, TQT_SIGNAL( changed( bool ) ), TQT_SLOT( clientChanged( bool ) ) );
260  return module;
261 }
262 
263 void KPluginSelectionWidget::embeddPluginKCMs( KPluginInfo * plugininfo, bool checked )
264 {
265  //if we have Services for the plugin we should be able to
266  //create KCM(s)
267  TQApplication::setOverrideCursor( Qt::WaitCursor );
268  if( plugininfo->kcmServices().size() > 1 )
269  {
270  // we need a tabwidget
271  KTabWidget * tabwidget = new KTabWidget( d->widgetstack );
272  tabwidget->setEnabled( checked );
273 
274  int id = d->widgetstack->addWidget( tabwidget );
275  d->kps->configPage( id );
276  d->widgetIDs[ plugininfo->pluginName() ] = id;
277 
278  for( TQValueList<KService::Ptr>::ConstIterator it =
279  plugininfo->kcmServices().begin();
280  it != plugininfo->kcmServices().end(); ++it )
281  {
282  if( !( *it )->noDisplay() )
283  {
284  TDECModuleInfo moduleinfo( *it );
285  TQWidget * module = insertKCM( tabwidget, moduleinfo );
286  tabwidget->addTab( module, moduleinfo.moduleName() );
287  }
288  }
289  }
290  else
291  {
292  if( !plugininfo->kcmServices().front()->noDisplay() )
293  {
294  TDECModuleInfo moduleinfo(
295  plugininfo->kcmServices().front() );
296  TQWidget * module = insertKCM( d->widgetstack, moduleinfo );
297  module->setEnabled( checked );
298 
299  int id = d->widgetstack->addWidget( module );
300  d->kps->configPage( id );
301  d->widgetIDs[ plugininfo->pluginName() ] = id;
302  }
303  }
304  TQApplication::restoreOverrideCursor();
305 }
306 
307 inline void KPluginSelectionWidget::updateConfigPage()
308 {
309  updateConfigPage( d->currentplugininfo, d->currentchecked );
310 }
311 
312 void KPluginSelectionWidget::updateConfigPage( KPluginInfo * plugininfo,
313  bool checked )
314 {
315  //kdDebug( 702 ) << k_funcinfo << endl;
316  d->currentplugininfo = plugininfo;
317  d->currentchecked = checked;
318 
319  // if this widget is not currently visible (meaning that it's in a tabwidget
320  // and another tab is currently opened) it's not allowed to change the
321  // widgetstack
322  if( ! d->visible )
323  return;
324 
325  if( 0 == plugininfo )
326  {
327  d->kps->configPage( 1 );
328  return;
329  }
330 
331  if( plugininfo->kcmServices().empty() )
332  d->kps->configPage( 1 );
333  else
334  {
335  if( !d->widgetIDs.contains( plugininfo->pluginName() ) )
336  // if no widget exists for the plugin create it
337  embeddPluginKCMs( plugininfo, checked );
338  else
339  {
340  // the page already exists
341  int id = d->widgetIDs[ plugininfo->pluginName() ];
342  d->kps->configPage( id );
343  d->widgetstack->widget( id )->setEnabled( checked );
344  }
345  }
346 }
347 
348 void KPluginSelectionWidget::clientChanged( bool didchange )
349 {
350  kdDebug( 702 ) << k_funcinfo << endl;
351  d->changed += didchange ? 1 : -1;
352  if( d->changed == 1 )
353  emit changed( true );
354  else if( d->changed == 0 )
355  emit changed( false );
356  else if( d->changed < 0 )
357  kdError( 702 ) << "negative changed value: " << d->changed << endl;
358 }
359 
360 void KPluginSelectionWidget::tabWidgetChanged( TQWidget * widget )
361 {
362  if( widget == this )
363  {
364  d->visible = true;
365  updateConfigPage();
366  }
367  else
368  d->visible = false;
369 }
370 
371 void KPluginSelectionWidget::executed( TQListViewItem * item )
372 {
373  kdDebug( 702 ) << k_funcinfo << endl;
374  if( item == 0 )
375  return;
376 
377  // Why not a dynamic_cast? - Martijn
378  // because this is what the Qt API suggests; and since gcc 3.x I don't
379  // trust dynamic_cast anymore - mkretz
380  if( item->rtti() != 1 ) //check for a QCheckListItem
381  return;
382 
383  TQCheckListItem * citem = static_cast<TQCheckListItem *>( item );
384  bool checked = citem->isOn();
385  //kdDebug( 702 ) << "it's a " << ( checked ? "checked" : "unchecked" )
386  // << " TQCheckListItem" << endl;
387 
388  KPluginInfo * info = d->pluginInfoMap[ citem ];
389  Q_ASSERT( !info->isHidden() );
390 
391  if ( info->isPluginEnabled() != checked )
392  {
393  kdDebug( 702 ) << "Item changed state, emitting changed()" << endl;
394 
395  if( ! d->plugincheckedchanged[ info ] )
396  {
397  ++d->changed;
398  if ( d->changed == 1 )
399  emit changed( true );
400  }
401  d->plugincheckedchanged[ info ] = true;
402 
403  checkDependencies( info );
404  }
405  else
406  {
407  if( d->plugincheckedchanged[ info ] )
408  {
409  --d->changed;
410  if ( d->changed == 0 )
411  emit changed( false );
412  }
413  d->plugincheckedchanged[ info ] = false;
414  // FIXME: plugins that depend on this plugin need to be disabled, too
415  }
416 
417  updateConfigPage( info, checked );
418 }
419 
420 void KPluginSelectionWidget::load()
421 {
422  //kdDebug( 702 ) << k_funcinfo << endl;
423 
424  for( TQMap<TQCheckListItem*, KPluginInfo*>::Iterator it =
425  d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it )
426  {
427  KPluginInfo * info = it.data();
428  info->load( d->config );
429  it.key()->setOn( info->isPluginEnabled() );
430  if( d->visible && info == d->currentplugininfo )
431  d->currentchecked = info->isPluginEnabled();
432  }
433 
434  for( TQValueList<TDECModuleProxy*>::Iterator it = d->modulelist.begin();
435  it != d->modulelist.end(); ++it )
436  if( ( *it )->changed() )
437  ( *it )->load();
438 
439  updateConfigPage();
440  // TODO: update changed state
441 }
442 
443 void KPluginSelectionWidget::save()
444 {
445  kdDebug( 702 ) << k_funcinfo << endl;
446 
447  for( TQMap<TQCheckListItem*, KPluginInfo*>::Iterator it =
448  d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it )
449  {
450  KPluginInfo * info = it.data();
451  bool checked = it.key()->isOn();
452  info->setPluginEnabled( checked );
453  info->save( d->config );
454  d->plugincheckedchanged[ info ] = false;
455  }
456  TQStringList updatedModules;
457  for( TQValueList<TDECModuleProxy*>::Iterator it = d->modulelist.begin();
458  it != d->modulelist.end(); ++it )
459  if( ( *it )->changed() )
460  {
461  ( *it )->save();
462  TQStringList * names = d->moduleParentComponents[ *it ];
463  if( names->size() == 0 )
464  names->append( TQString::null );
465  for( TQStringList::ConstIterator nameit = names->begin();
466  nameit != names->end(); ++nameit )
467  if( updatedModules.find( *nameit ) == updatedModules.end() )
468  updatedModules.append( *nameit );
469  }
470  for( TQStringList::ConstIterator it = updatedModules.begin(); it != updatedModules.end(); ++it )
471  emit configCommitted( ( *it ).latin1() );
472 
473  updateConfigPage();
474  kdDebug( 702 ) << "syncing config file" << endl;
475  d->config->sync();
476  d->changed = 0;
477  emit changed( false );
478 }
479 
480 void KPluginSelectionWidget::checkDependencies( const KPluginInfo * info )
481 {
482  if( info->dependencies().isEmpty() )
483  return;
484 
485  for( TQStringList::ConstIterator it = info->dependencies().begin();
486  it != info->dependencies().end(); ++it )
487  for( TQMap<TQCheckListItem*,
488  KPluginInfo*>::Iterator infoIt = d->pluginInfoMap.begin();
489  infoIt != d->pluginInfoMap.end(); ++infoIt )
490  if( infoIt.data()->pluginName() == *it )
491  {
492  if( !infoIt.key()->isOn() )
493  {
494  infoIt.key()->setOn( true );
495  checkDependencies( infoIt.data() );
496  }
497  continue;
498  }
499 }
500 
501 class KPluginSelector::KPluginSelectorPrivate
502 {
503  public:
504  KPluginSelectorPrivate()
505  : frame( 0 )
506  , tabwidget( 0 )
507  , widgetstack( 0 )
508  , hideconfigpage( false )
509  {
510  }
511 
512  TQFrame * frame;
513  KTabWidget * tabwidget;
514  TQWidgetStack * widgetstack;
515  TQValueList<KPluginSelectionWidget *> pswidgets;
516  bool hideconfigpage;
517 };
518 
519 KPluginSelector::KPluginSelector( TQWidget * parent, const char * name )
520 : TQWidget( parent, name )
521 , d( new KPluginSelectorPrivate )
522 {
523  TQBoxLayout * hbox = new TQHBoxLayout( this, 0, KDialog::spacingHint() );
524  hbox->setAutoAdd( true );
525 
526  TQSplitter* splitter = new TQSplitter( Qt::Horizontal, this );
527  d->frame = new TQFrame( splitter, "KPluginSelector left frame" );
528  d->frame->setFrameStyle( TQFrame::NoFrame );
529  ( new TQVBoxLayout( d->frame, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
530 
531  // widgetstack
532  d->widgetstack = new TQWidgetStack( splitter, "KPluginSelector Config Pages" );
533  d->widgetstack->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
534  d->widgetstack->setMinimumSize( 200, 200 );
535 
536  TQLabel * label = new TQLabel( i18n( "(This plugin is not configurable)" ),
537  d->widgetstack );
538  ( new TQVBoxLayout( label, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
539  label->setAlignment( Qt::AlignCenter );
540  label->setMinimumSize( 200, 200 );
541 
542  d->widgetstack->addWidget( label, 1 );
543 
544  configPage( 1 );
545 }
546 
547 KPluginSelector::~KPluginSelector()
548 {
549  delete d;
550 }
551 
552 void KPluginSelector::checkNeedForTabWidget()
553 {
554  kdDebug( 702 ) << k_funcinfo << endl;
555  if( ! d->tabwidget && d->pswidgets.size() == 1 )
556  {
557  kdDebug( 702 ) << "no TabWidget and one KPluginSelectionWidget" << endl;
558  // there's only one KPluginSelectionWidget yet, we need a TabWidget
559  KPluginSelectionWidget * w = d->pswidgets.first();
560  if( w )
561  {
562  kdDebug( 702 ) << "create TabWidget" << endl;
563  d->tabwidget = new KTabWidget( d->frame,
564  "KPluginSelector TabWidget" );
565  w->reparent( d->tabwidget, TQPoint( 0, 0 ) );
566  d->tabwidget->addTab( w, w->catName() );
567  connect( d->tabwidget, TQT_SIGNAL( currentChanged( TQWidget * ) ), w,
568  TQT_SLOT( tabWidgetChanged( TQWidget * ) ) );
569  }
570  }
571 }
572 
573 static TQValueList<KPluginInfo*> tdepartsPluginInfos( const TQString& instanceName )
574 {
575  if( instanceName.isNull() )
576  return TQValueList<KPluginInfo*>(); //nothing
577 
578  const TQStringList desktopfilenames = TDEGlobal::dirs()->findAllResources( "data",
579  instanceName + "/kpartplugins/*.desktop", true, false );
580  return KPluginInfo::fromFiles( desktopfilenames );
581 }
582 
583 void KPluginSelector::addPlugins( const TQString & instanceName,
584  const TQString & catname, const TQString & category, TDEConfig * config )
585 {
586  const TQValueList<KPluginInfo*> plugininfos = tdepartsPluginInfos( instanceName );
587  if ( plugininfos.isEmpty() )
588  return;
589  checkNeedForTabWidget();
590  Q_ASSERT( config ); // please set config, or use addPlugins( instance, ... ) which takes care of it
591  if ( !config ) // KDE4: ensure that config is always set; make it second in the arg list?
592  config = new KSimpleConfig( instanceName ); // memleak!
593  TDEConfigGroup * cfgGroup = new TDEConfigGroup( config, "KParts Plugins" );
594  kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl;
595  addPluginsInternal( plugininfos, catname, category, cfgGroup );
596 }
597 
598 void KPluginSelector::addPluginsInternal( const TQValueList<KPluginInfo*> plugininfos,
599  const TQString & catname, const TQString & category,
600  TDEConfigGroup* cfgGroup )
601 {
602  KPluginSelectionWidget * w;
603  if( d->tabwidget )
604  {
605  w = new KPluginSelectionWidget( plugininfos, this,
606  d->tabwidget, catname, category, cfgGroup );
607  d->tabwidget->addTab( w, catname );
608  connect( d->tabwidget, TQT_SIGNAL( currentChanged( TQWidget * ) ), w,
609  TQT_SLOT( tabWidgetChanged( TQWidget * ) ) );
610  }
611  else
612  w = new KPluginSelectionWidget( plugininfos, this, d->frame,
613  catname, category, cfgGroup );
614  w->setMinimumSize( 200, 200 );
615  connect( w, TQT_SIGNAL( changed( bool ) ), this, TQT_SIGNAL( changed( bool ) ) );
616  connect( w, TQT_SIGNAL( configCommitted( const TQCString & ) ), this,
617  TQT_SIGNAL( configCommitted( const TQCString & ) ) );
618  d->pswidgets += w;
619 }
620 
621 void KPluginSelector::addPlugins( const TDEInstance * instance, const TQString &
622  catname, const TQString & category, TDEConfig * config )
623 {
624  if ( !config )
625  config = instance->config();
626  addPlugins( instance->instanceName(), catname, category, config );
627 }
628 
629 void KPluginSelector::addPlugins( const TQValueList<KPluginInfo*> & plugininfos,
630  const TQString & catname, const TQString & category, TDEConfig * config )
631 {
632  checkNeedForTabWidget();
633  // the TDEConfigGroup becomes owned by KPluginSelectionWidget
634  TDEConfigGroup * cfgGroup = new TDEConfigGroup( config ? config : TDEGlobal::config(), "Plugins" );
635  kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl;
636  addPluginsInternal( plugininfos, catname, category, cfgGroup );
637 }
638 
639 TQWidgetStack * KPluginSelector::widgetStack()
640 {
641  return d->widgetstack;
642 }
643 
644 inline void KPluginSelector::configPage( int id )
645 {
646  if( id == 1 )
647  {
648  // no config page
649  if( d->hideconfigpage )
650  {
651  d->widgetstack->hide();
652  return;
653  }
654  }
655  else
656  d->widgetstack->show();
657 
658  d->widgetstack->raiseWidget( id );
659 }
660 
661 void KPluginSelector::setShowEmptyConfigPage( bool show )
662 {
663  d->hideconfigpage = !show;
664  if( d->hideconfigpage )
665  if( d->widgetstack->id( d->widgetstack->visibleWidget() ) == 1 )
666  d->widgetstack->hide();
667 }
668 
669 void KPluginSelector::load()
670 {
671  for( TQValueList<KPluginSelectionWidget *>::Iterator it =
672  d->pswidgets.begin(); it != d->pswidgets.end(); ++it )
673  {
674  ( *it )->load();
675  }
676 }
677 
678 void KPluginSelector::save()
679 {
680  for( TQValueList<KPluginSelectionWidget *>::Iterator it =
681  d->pswidgets.begin(); it != d->pswidgets.end(); ++it )
682  {
683  ( *it )->save();
684  }
685 }
686 
687 void KPluginSelector::defaults()
688 {
689  kdDebug( 702 ) << k_funcinfo << endl;
690 
691  // what should defaults do? here's what I think:
692  // Pressing a button in the dialog should not change any widgets that are
693  // not visible for the user. Therefor we may only change the currently
694  // visible plugin's KCM. Restoring the default plugin selections is therefor
695  // not possible. (if the plugin has multiple KCMs they will be shown in a
696  // tabwidget - defaults() will be called for all of them)
697 
698  TQWidget * pluginconfig = d->widgetstack->visibleWidget();
699  TDECModuleProxy * kcm = ::tqqt_cast<TDECModuleProxy*>(pluginconfig);
700  if( kcm )
701  {
702  kdDebug( 702 ) << "call TDECModule::defaults() for the plugins KCM"
703  << endl;
704  kcm->defaults();
705  return;
706  }
707 
708  // if we get here the visible Widget must be a tabwidget holding more than
709  // one KCM
710  TQObjectList * kcms = pluginconfig->queryList( "TDECModuleProxy",
711  0, false, false );
712  TQObjectListIt it( *kcms );
713  TQObject * obj;
714  while( ( obj = it.current() ) != 0 )
715  {
716  ++it;
717  ( ( TDECModule* )obj )->defaults();
718  }
719  delete kcms;
720  // FIXME: update changed state
721 }
722 #include "kpluginselector.moc"
723 #include "kpluginselector_p.moc"
TDEConfig
KPluginInfo
Information about a plugin.
Definition: kplugininfo.h:42
TDECModuleInfo
A class that provides information about a TDECModule.
Definition: tdecmoduleinfo.h:49
KPluginInfo::pluginName
const TQString & pluginName() const
Definition: kplugininfo.cpp:245
TDECModuleProxy::defaults
void defaults()
Calling it will cause the contained module to load its default values.
Definition: tdecmoduleproxy.cpp:552
KPluginInfo::isPluginEnabled
virtual bool isPluginEnabled() const
Definition: kplugininfo.cpp:198
KPluginSelector::addPlugins
void addPlugins(const TQString &instanceName, const TQString &catname=TQString::null, const TQString &category=TQString::null, TDEConfig *config=0)
Add a list of KParts plugins.
Definition: kpluginselector.cpp:583
kdError
kdbgstream kdError(int area=0)
KPluginInfo::kcmServices
const TQValueList< KService::Ptr > & kcmServices() const
Definition: kplugininfo.cpp:275
KPluginSelector::load
void load()
Load the state of the plugins (selected or not) from the KPluginInfo objects.
Definition: kpluginselector.cpp:669
KPluginSelector::setShowEmptyConfigPage
void setShowEmptyConfigPage(bool)
Set whether the area for showing the KCMs of the plugins should be hidden if the plugin doesn't have ...
Definition: kpluginselector.cpp:661
kdDebug
kdbgstream kdDebug(int area=0)
TDECModuleProxy::realModule
TDECModule * realModule() const
Access to the actual module.
Definition: tdecmoduleproxy.cpp:140
KPluginInfo::save
virtual void save(TDEConfigGroup *config=0)
Save state of the plugin - enabled or not.
Definition: kplugininfo.cpp:319
KPluginSelector::save
void save()
Save the configuration.
Definition: kpluginselector.cpp:678
KPluginInfo::load
virtual void load(TDEConfigGroup *config=0)
Load the state of the plugin - enabled or not.
Definition: kplugininfo.cpp:336
KPluginSelector::changed
void changed(bool)
Tells you whether the configuration is changed or not.
TDEGlobal::dirs
static TDEStandardDirs * dirs()
TDEConfigGroup
tdelocale.h
TDEStandardDirs::findAllResources
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
KPluginInfo::fromFiles
static KPluginInfo::List fromFiles(const TQStringList &files, TDEConfig *config=0, const TQString &group=TQString::null)
Definition: kplugininfo.cpp:168
KPluginInfo::setPluginEnabled
virtual void setPluginEnabled(bool enabled)
Set whether the plugin is currently loaded.
Definition: kplugininfo.cpp:192
KPluginSelector::configCommitted
void configCommitted(const TQCString &instanceName)
Emitted after the config of an embedded KCM has been saved.
TDECModuleInfo::service
KService::Ptr service() const
Definition: tdecmoduleinfo.h:137
TDEListView
TDEIcon::Small
KPluginSelector::KPluginSelector
KPluginSelector(TQWidget *parent, const char *name=0)
Create a new KPluginSelector.
Definition: kpluginselector.cpp:519
TDECModuleInfo::moduleName
TQString moduleName() const
Definition: tdecmoduleinfo.h:131
KPluginSelector::defaults
void defaults()
Change to applications defaults.
Definition: kpluginselector.cpp:687
TDECModule
KPluginInfo::isHidden
bool isHidden() const
Definition: kplugininfo.cpp:187
TDEGlobal::config
static TDEConfig * config()
endl
kndbgstream & endl(kndbgstream &s)
KSimpleConfig
KPluginSelectionWidget
TDEStdAccel::name
TQString name(StdAccel id)
TDECModuleProxy
Encapsulates a TDECModule for embedding.
Definition: tdecmoduleproxy.h:68
TDEStdAccel::label
TQString label(StdAccel id)
TDEInstance
KPluginSelector
A widget to select what plugins to load and configure the plugins.
Definition: kpluginselector.h:60
KPluginInfo::dependencies
const TQStringList & dependencies() const
Definition: kplugininfo.cpp:265
KTabWidget

tdeutils

Skip menu "tdeutils"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.8.8
This website is maintained by Timothy Pearson.