kutils Library API Documentation

kpluginselector.cpp

00001 /* This file is part of the KDE project 00002 Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00016 Boston, MA 02111-1307, USA. 00017 00018 */ 00019 00020 #include "kpluginselector.h" 00021 #include "kpluginselector_p.h" 00022 00023 #include <qtooltip.h> 00024 #include <qvbox.h> 00025 #include <qlabel.h> 00026 #include <qstrlist.h> 00027 #include <qfile.h> 00028 #include <qstring.h> 00029 #include <qlayout.h> 00030 #include <qptrlist.h> 00031 #include <qwidgetstack.h> 00032 #include <qcursor.h> 00033 #include <qapplication.h> 00034 #include <qobjectlist.h> 00035 #include <qcstring.h> 00036 00037 #include <kdebug.h> 00038 #include <klocale.h> 00039 #include <klistview.h> 00040 #include <ksimpleconfig.h> 00041 #include <kdialog.h> 00042 #include <kglobal.h> 00043 #include <kglobalsettings.h> 00044 #include <kstandarddirs.h> 00045 #include <ktabctl.h> 00046 #include <kcmoduleinfo.h> 00047 #include <qvaluelist.h> 00048 #include <kservice.h> 00049 #include <ktrader.h> 00050 #include <ktabwidget.h> 00051 #include <kiconloader.h> 00052 #include <kcmodule.h> 00053 #include "kcmoduleinfo.h" 00054 #include "kcmoduleloader.h" 00055 #include <qsplitter.h> 00056 #include <qframe.h> 00057 #include "kplugininfo.h" 00058 #include <kinstance.h> 00059 #include <qptrdict.h> 00060 #include <qstringlist.h> 00061 #include "kcmoduleproxy.h" 00062 00063 /* 00064 QCheckListViewItem that holds a pointer to the KPluginInfo object. 00065 Used in the tooltip code to access additional fields 00066 */ 00067 class KPluginInfoLVI : public QCheckListItem 00068 { 00069 public: 00070 KPluginInfoLVI( KPluginInfo *pluginInfo, KListView *parent ) 00071 : QCheckListItem( parent, pluginInfo->name(), QCheckListItem::CheckBox ), m_pluginInfo( pluginInfo ) 00072 { 00073 } 00074 00075 KPluginInfo * pluginInfo() { return m_pluginInfo; } 00076 00077 private: 00078 KPluginInfo *m_pluginInfo; 00079 }; 00080 00081 /* 00082 Custom QToolTip for the list view. 00083 The decision whether or not to show tooltips is taken in 00084 maybeTip(). See also the QListView sources from Qt itself. 00085 */ 00086 class KPluginListViewToolTip : public QToolTip 00087 { 00088 public: 00089 KPluginListViewToolTip( QWidget *parent, KListView *lv ); 00090 00091 void maybeTip( const QPoint &pos ); 00092 00093 private: 00094 KListView *m_listView; 00095 }; 00096 00097 KPluginListViewToolTip::KPluginListViewToolTip( QWidget *parent, KListView *lv ) 00098 : QToolTip( parent ), m_listView( lv ) 00099 { 00100 } 00101 00102 void KPluginListViewToolTip::maybeTip( const QPoint &pos ) 00103 { 00104 if ( !parentWidget() || !m_listView ) 00105 return; 00106 00107 KPluginInfoLVI *item = dynamic_cast<KPluginInfoLVI *>( m_listView->itemAt( pos ) ); 00108 if ( !item ) 00109 return; 00110 00111 QString toolTip = i18n( "<qt><table>" 00112 "<tr><td><b>Description:</b></td><td>%1</td></tr>" 00113 "<tr><td><b>Author:</b></td><td>%2</td></tr>" 00114 "<tr><td><b>Version:</b></td><td>%3</td></tr>" 00115 "<tr><td><b>License:</b></td><td>%4</td></tr></table></qt>" ).arg( item->pluginInfo()->comment(), 00116 item->pluginInfo()->author(), item->pluginInfo()->version(), item->pluginInfo()->license() ); 00117 00118 //kdDebug( 702 ) << k_funcinfo << "Adding tooltip: itemRect: " << itemRect << ", tooltip: " << toolTip << endl; 00119 tip( m_listView->itemRect( item ), toolTip ); 00120 } 00121 00122 struct KPluginSelectionWidget::KPluginSelectionWidgetPrivate 00123 { 00124 KPluginSelectionWidgetPrivate( const QString & _instanceName, 00125 KPluginSelector * _kps, const QString & _cat, 00126 KConfigGroup * _config ) 00127 : instanceName( _instanceName ) 00128 , widgetstack( 0 ) 00129 , kps( _kps ) 00130 , config( _config ) 00131 , tooltip( 0 ) 00132 , catname( _cat ) 00133 , currentplugininfo( 0 ) 00134 , visible( true ) 00135 , currentchecked( false ) 00136 , changed( 0 ) 00137 { 00138 moduleParentComponents.setAutoDelete( true ); 00139 } 00140 00141 ~KPluginSelectionWidgetPrivate() 00142 { 00143 delete config; 00144 } 00145 00146 QMap<QCheckListItem*, KPluginInfo*> pluginInfoMap; 00147 00148 QString instanceName; // isNull() for non-KParts plugins 00149 QWidgetStack * widgetstack; 00150 KPluginSelector * kps; 00151 KConfigGroup * config; 00152 KPluginListViewToolTip *tooltip; 00153 00154 QDict<KCModuleInfo> pluginconfigmodules; 00155 QMap<QString, int> widgetIDs; 00156 QMap<KPluginInfo*, bool> plugincheckedchanged; 00157 QString catname; 00158 QValueList<KCModuleProxy*> modulelist; 00159 QPtrDict<QStringList> moduleParentComponents; 00160 00161 KPluginInfo * currentplugininfo; 00162 bool visible; 00163 bool currentchecked; 00164 int changed; 00165 }; 00166 00167 KPluginSelectionWidget::KPluginSelectionWidget( const QString & instanceName, 00168 KPluginSelector * kps, QWidget * parent, const QString & catname, 00169 const QString & category, KConfigGroup * config, const char * name ) 00170 : QWidget( parent, name ) 00171 , d( new KPluginSelectionWidgetPrivate( instanceName, kps, catname, config ) ) 00172 { 00173 init( kpartsPluginInfos(), category ); 00174 } 00175 00176 KPluginSelectionWidget::KPluginSelectionWidget( 00177 const QValueList<KPluginInfo*> & plugininfos, KPluginSelector * kps, 00178 QWidget * parent, const QString & catname, const QString & category, 00179 KConfigGroup * config, const char * name ) 00180 : QWidget( parent, name ) 00181 , d( new KPluginSelectionWidgetPrivate( 0, kps, catname, config ) ) 00182 { 00183 init( plugininfos, category ); 00184 } 00185 00186 inline QString KPluginSelectionWidget::catName() const 00187 { 00188 return d->catname; 00189 } 00190 00191 QValueList<KPluginInfo*> KPluginSelectionWidget::kpartsPluginInfos() const 00192 { 00193 if( d->instanceName.isNull() ) 00194 { 00195 QValueList<KPluginInfo*> list; 00196 return list; //nothing 00197 } 00198 00199 QStringList desktopfilenames = KGlobal::dirs()->findAllResources( "data", 00200 d->instanceName + "/kpartplugins/*.desktop", true, false ); 00201 return KPluginInfo::fromFiles( desktopfilenames ); 00202 } 00203 00204 void KPluginSelectionWidget::init( const QValueList<KPluginInfo*> & plugininfos, 00205 const QString & category ) 00206 { 00207 // setup Widgets 00208 ( new QVBoxLayout( this, 0, KDialog::spacingHint() ) )->setAutoAdd( true ); 00209 KListView * listview = new KListView( this ); 00210 d->tooltip = new KPluginListViewToolTip( listview->viewport(), listview ); 00211 connect( listview, SIGNAL( pressed( QListViewItem * ) ), this, 00212 SLOT( executed( QListViewItem * ) ) ); 00213 connect( listview, SIGNAL( spacePressed( QListViewItem * ) ), this, 00214 SLOT( executed( QListViewItem * ) ) ); 00215 connect( listview, SIGNAL( returnPressed( QListViewItem * ) ), this, 00216 SLOT( executed( QListViewItem * ) ) ); 00217 connect( listview, SIGNAL( selectionChanged( QListViewItem * ) ), this, 00218 SLOT( executed( QListViewItem * ) ) ); 00219 listview->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ); 00220 listview->setAcceptDrops( false ); 00221 listview->setFullWidth( true ); 00222 listview->setSelectionModeExt( KListView::Single ); 00223 listview->setAllColumnsShowFocus( true ); 00224 listview->addColumn( i18n( "Name" ) ); 00225 for( QValueList<KPluginInfo*>::ConstIterator it = plugininfos.begin(); 00226 it != plugininfos.end(); ++it ) 00227 { 00228 d->plugincheckedchanged[ *it ] = false; 00229 if( !( *it )->isHidden() && 00230 ( category.isNull() || ( *it )->category() == category ) ) 00231 { 00232 QCheckListItem * item = new KPluginInfoLVI( *it, listview ); 00233 if( ! ( *it )->icon().isEmpty() ) 00234 item->setPixmap( 0, SmallIcon( ( *it )->icon(), IconSize( KIcon::Small ) ) ); 00235 item->setOn( ( *it )->isPluginEnabled() ); 00236 d->pluginInfoMap.insert( item, *it ); 00237 } 00238 } 00239 00240 // widgetstack 00241 d->widgetstack = d->kps->widgetStack(); 00242 load(); 00243 // select and highlight the first item in the plugin list 00244 if( listview->firstChild() ) 00245 listview->setSelected( listview->firstChild(), true ); 00246 } 00247 00248 KPluginSelectionWidget::~KPluginSelectionWidget() 00249 { 00250 delete d->tooltip; 00251 delete d; 00252 } 00253 00254 bool KPluginSelectionWidget::pluginIsLoaded( const QString & pluginName ) const 00255 { 00256 for( QMap<QCheckListItem*, KPluginInfo*>::ConstIterator it = 00257 d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it ) 00258 if( it.data()->pluginName() == pluginName ) 00259 return it.data()->isPluginEnabled(); 00260 return false; 00261 } 00262 00263 00264 QWidget * KPluginSelectionWidget::insertKCM( QWidget * parent, 00265 const KCModuleInfo & moduleinfo ) 00266 { 00267 KCModuleProxy * module = new KCModuleProxy( moduleinfo, false, 00268 parent ); 00269 if( !module->realModule() ) 00270 { 00271 //FIXME: not very verbose 00272 QLabel * label = new QLabel( i18n( "Error" ), parent ); 00273 label->setAlignment( Qt::AlignCenter ); 00274 00275 return label; 00276 } 00277 // add the KCM to the list so that we can call load/save/defaults on it 00278 d->modulelist.append( module ); 00279 QStringList * parentComponents = new QStringList( 00280 moduleinfo.service()->property( 00281 "X-KDE-ParentComponents" ).toStringList() ); 00282 d->moduleParentComponents.insert( module, parentComponents ); 00283 connect( module, SIGNAL( changed( bool ) ), SLOT( clientChanged( bool ) ) ); 00284 return module; 00285 } 00286 00287 void KPluginSelectionWidget::embeddPluginKCMs( KPluginInfo * plugininfo, bool checked ) 00288 { 00289 //if we have Services for the plugin we should be able to 00290 //create KCM(s) 00291 QApplication::setOverrideCursor( Qt::WaitCursor ); 00292 if( plugininfo->kcmServices().size() > 1 ) 00293 { 00294 // we need a tabwidget 00295 KTabWidget * tabwidget = new KTabWidget( d->widgetstack ); 00296 tabwidget->setEnabled( checked ); 00297 00298 int id = d->widgetstack->addWidget( tabwidget ); 00299 d->kps->configPage( id ); 00300 d->widgetIDs[ plugininfo->pluginName() ] = id; 00301 00302 for( QValueList<KService::Ptr>::ConstIterator it = 00303 plugininfo->kcmServices().begin(); 00304 it != plugininfo->kcmServices().end(); ++it ) 00305 { 00306 if( !( *it )->noDisplay() ) 00307 { 00308 KCModuleInfo moduleinfo( *it ); 00309 QWidget * module = insertKCM( tabwidget, moduleinfo ); 00310 tabwidget->addTab( module, moduleinfo.moduleName() ); 00311 } 00312 } 00313 } 00314 else 00315 { 00316 if( !plugininfo->kcmServices().front()->noDisplay() ) 00317 { 00318 KCModuleInfo moduleinfo( 00319 plugininfo->kcmServices().front() ); 00320 QWidget * module = insertKCM( d->widgetstack, moduleinfo ); 00321 module->setEnabled( checked ); 00322 00323 int id = d->widgetstack->addWidget( module ); 00324 d->kps->configPage( id ); 00325 d->widgetIDs[ plugininfo->pluginName() ] = id; 00326 } 00327 } 00328 QApplication::restoreOverrideCursor(); 00329 } 00330 00331 inline void KPluginSelectionWidget::updateConfigPage() 00332 { 00333 updateConfigPage( d->currentplugininfo, d->currentchecked ); 00334 } 00335 00336 void KPluginSelectionWidget::updateConfigPage( KPluginInfo * plugininfo, 00337 bool checked ) 00338 { 00339 kdDebug( 702 ) << k_funcinfo << endl; 00340 d->currentplugininfo = plugininfo; 00341 d->currentchecked = checked; 00342 00343 // if this widget is not currently visible (meaning that it's in a tabwidget 00344 // and another tab is currently opened) it's not allowed to change the 00345 // widgetstack 00346 if( ! d->visible ) 00347 return; 00348 00349 if( 0 == plugininfo ) 00350 { 00351 d->kps->configPage( 1 ); 00352 return; 00353 } 00354 00355 if( plugininfo->kcmServices().empty() ) 00356 d->kps->configPage( 1 ); 00357 else 00358 { 00359 if( !d->widgetIDs.contains( plugininfo->pluginName() ) ) 00360 // if no widget exists for the plugin create it 00361 embeddPluginKCMs( plugininfo, checked ); 00362 else 00363 { 00364 // the page already exists 00365 int id = d->widgetIDs[ plugininfo->pluginName() ]; 00366 d->kps->configPage( id ); 00367 d->widgetstack->widget( id )->setEnabled( checked ); 00368 } 00369 } 00370 } 00371 00372 void KPluginSelectionWidget::clientChanged( bool didchange ) 00373 { 00374 kdDebug( 702 ) << k_funcinfo << endl; 00375 d->changed += didchange ? 1 : -1; 00376 if( d->changed == 1 ) 00377 emit changed( true ); 00378 else if( d->changed == 0 ) 00379 emit changed( false ); 00380 else if( d->changed < 0 ) 00381 kdError( 702 ) << "negative changed value: " << d->changed << endl; 00382 } 00383 00384 void KPluginSelectionWidget::tabWidgetChanged( QWidget * widget ) 00385 { 00386 if( widget == this ) 00387 { 00388 d->visible = true; 00389 updateConfigPage(); 00390 } 00391 else 00392 d->visible = false; 00393 } 00394 00395 void KPluginSelectionWidget::executed( QListViewItem * item ) 00396 { 00397 kdDebug( 702 ) << k_funcinfo << endl; 00398 if( item == 0 ) 00399 return; 00400 00401 // Why not a dynamic_cast? - Martijn 00402 // because this is what the Qt API suggests; and since gcc 3.x I don't 00403 // trust dynamic_cast anymore - mkretz 00404 if( item->rtti() != 1 ) //check for a QCheckListItem 00405 return; 00406 00407 QCheckListItem * citem = static_cast<QCheckListItem *>( item ); 00408 bool checked = citem->isOn(); 00409 kdDebug( 702 ) << "it's a " << ( checked ? "checked" : "unchecked" ) 00410 << " QCheckListItem" << endl; 00411 00412 KPluginInfo * info = d->pluginInfoMap[ citem ]; 00413 if( info->isHidden() ) 00414 kdFatal( 702 ) << "bummer" << endl; 00415 00416 if ( info->isPluginEnabled() != checked ) 00417 { 00418 kdDebug( 702 ) << "Item changed state, emitting changed()" << endl; 00419 00420 if( ! d->plugincheckedchanged[ info ] ) 00421 { 00422 ++d->changed; 00423 if ( d->changed == 1 ) 00424 emit changed( true ); 00425 } 00426 d->plugincheckedchanged[ info ] = true; 00427 00428 checkDependencies( info ); 00429 } 00430 else 00431 { 00432 if( d->plugincheckedchanged[ info ] ) 00433 { 00434 --d->changed; 00435 if ( d->changed == 0 ) 00436 emit changed( false ); 00437 } 00438 d->plugincheckedchanged[ info ] = false; 00439 // FIXME: plugins that depend on this plugin need to be disabled, too 00440 } 00441 00442 updateConfigPage( info, checked ); 00443 } 00444 00445 void KPluginSelectionWidget::load() 00446 { 00447 kdDebug( 702 ) << k_funcinfo << endl; 00448 00449 for( QMap<QCheckListItem*, KPluginInfo*>::Iterator it = 00450 d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it ) 00451 { 00452 KPluginInfo * info = it.data(); 00453 info->load( d->config ); 00454 it.key()->setOn( info->isPluginEnabled() ); 00455 if( d->visible && info == d->currentplugininfo ) 00456 d->currentchecked = info->isPluginEnabled(); 00457 } 00458 00459 for( QValueList<KCModuleProxy*>::Iterator it = d->modulelist.begin(); 00460 it != d->modulelist.end(); ++it ) 00461 if( ( *it )->changed() ) 00462 ( *it )->load(); 00463 00464 updateConfigPage(); 00465 // TODO: update changed state 00466 } 00467 00468 void KPluginSelectionWidget::save() 00469 { 00470 kdDebug( 702 ) << k_funcinfo << endl; 00471 00472 for( QMap<QCheckListItem*, KPluginInfo*>::Iterator it = 00473 d->pluginInfoMap.begin(); it != d->pluginInfoMap.end(); ++it ) 00474 { 00475 KPluginInfo * info = it.data(); 00476 bool checked = it.key()->isOn(); 00477 info->setPluginEnabled( checked ); 00478 info->save( d->config ); 00479 d->plugincheckedchanged[ info ] = false; 00480 } 00481 QStringList updatedModules; 00482 for( QValueList<KCModuleProxy*>::Iterator it = d->modulelist.begin(); 00483 it != d->modulelist.end(); ++it ) 00484 if( ( *it )->changed() ) 00485 { 00486 ( *it )->save(); 00487 QStringList * names = d->moduleParentComponents[ *it ]; 00488 for( QStringList::ConstIterator nameit = names->begin(); 00489 nameit != names->end(); ++nameit ) 00490 if( updatedModules.find( *nameit ) == updatedModules.end() ) 00491 updatedModules.append( *nameit ); 00492 } 00493 for( QStringList::ConstIterator it = updatedModules.begin(); it != updatedModules.end(); ++it ) 00494 emit configCommitted( ( *it ).latin1() ); 00495 00496 updateConfigPage(); 00497 kdDebug( 702 ) << "syncing config file" << endl; 00498 d->config->sync(); 00499 d->changed = 0; 00500 emit changed( false ); 00501 } 00502 00503 void KPluginSelectionWidget::checkDependencies( const KPluginInfo * info ) 00504 { 00505 if( info->dependencies().isEmpty() ) 00506 return; 00507 00508 for( QStringList::ConstIterator it = info->dependencies().begin(); 00509 it != info->dependencies().end(); ++it ) 00510 for( QMap<QCheckListItem*, 00511 KPluginInfo*>::Iterator infoIt = d->pluginInfoMap.begin(); 00512 infoIt != d->pluginInfoMap.end(); ++infoIt ) 00513 if( infoIt.data()->pluginName() == *it ) 00514 { 00515 if( !infoIt.key()->isOn() ) 00516 { 00517 infoIt.key()->setOn( true ); 00518 checkDependencies( infoIt.data() ); 00519 } 00520 continue; 00521 } 00522 } 00523 00524 class KPluginSelector::KPluginSelectorPrivate 00525 { 00526 public: 00527 KPluginSelectorPrivate() 00528 : frame( 0 ) 00529 , tabwidget( 0 ) 00530 , widgetstack( 0 ) 00531 , hideconfigpage( false ) 00532 { 00533 } 00534 00535 QFrame * frame; 00536 KTabWidget * tabwidget; 00537 QWidgetStack * widgetstack; 00538 QValueList<KPluginSelectionWidget *> pswidgets; 00539 bool hideconfigpage; 00540 }; 00541 00542 KPluginSelector::KPluginSelector( QWidget * parent, const char * name ) 00543 : QWidget( parent, name ) 00544 , d( new KPluginSelectorPrivate ) 00545 { 00546 QBoxLayout * hbox = new QHBoxLayout( this, 0, KDialog::spacingHint() ); 00547 hbox->setAutoAdd( true ); 00548 d->frame = new QFrame( this, "KPluginSelector left frame" ); 00549 d->frame->setFrameStyle( QFrame::NoFrame ); 00550 ( new QVBoxLayout( d->frame, 0, KDialog::spacingHint() ) )->setAutoAdd( true ); 00551 00552 // widgetstack 00553 d->widgetstack = new QWidgetStack( this, "KPluginSelector Config Pages" ); 00554 d->widgetstack->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 00555 d->widgetstack->setMinimumSize( 200, 200 ); 00556 00557 QLabel * label = new QLabel( i18n( "(This plugin is not configurable)" ), 00558 d->widgetstack ); 00559 ( new QVBoxLayout( label, 0, KDialog::spacingHint() ) )->setAutoAdd( true ); 00560 label->setAlignment( Qt::AlignCenter ); 00561 label->setMinimumSize( 200, 200 ); 00562 00563 d->widgetstack->addWidget( label, 1 ); 00564 00565 configPage( 1 ); 00566 } 00567 00568 KPluginSelector::~KPluginSelector() 00569 { 00570 delete d; 00571 } 00572 00573 void KPluginSelector::checkNeedForTabWidget() 00574 { 00575 kdDebug( 702 ) << k_funcinfo << endl; 00576 if( ! d->tabwidget && d->pswidgets.size() == 1 ) 00577 { 00578 kdDebug( 702 ) << "no TabWidget and one KPluginSelectionWidget" << endl; 00579 // there's only one KPluginSelectionWidget yet, we need a TabWidget 00580 KPluginSelectionWidget * w = d->pswidgets.first(); 00581 if( w ) 00582 { 00583 kdDebug( 702 ) << "create TabWidget" << endl; 00584 d->tabwidget = new KTabWidget( d->frame, 00585 "KPluginSelector TabWidget" ); 00586 w->reparent( d->tabwidget, QPoint( 0, 0 ) ); 00587 d->tabwidget->addTab( w, w->catName() ); 00588 connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w, 00589 SLOT( tabWidgetChanged( QWidget * ) ) ); 00590 } 00591 } 00592 } 00593 00594 void KPluginSelector::addPlugins( const QString & instanceName, 00595 const QString & catname, const QString & category, KConfig * config ) 00596 { 00597 checkNeedForTabWidget(); 00598 // FIXME: mem leak: the KSimpleConfig object needs to be deleted 00599 KConfigGroup * cfgGroup = new KConfigGroup( config ? config : 00600 new KSimpleConfig( instanceName ), "KParts Plugins" ); 00601 kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl; 00602 KPluginSelectionWidget * w; 00603 if( d->tabwidget ) 00604 { 00605 w = new KPluginSelectionWidget( instanceName, this, 00606 d->tabwidget, catname, category, cfgGroup ); 00607 d->tabwidget->addTab( w, catname ); 00608 connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w, 00609 SLOT( tabWidgetChanged( QWidget * ) ) ); 00610 } 00611 else 00612 w = new KPluginSelectionWidget( instanceName, this, d->frame, 00613 catname, category, cfgGroup ); 00614 w->setMinimumSize( 200, 200 ); 00615 connect( w, SIGNAL( changed( bool ) ), this, SIGNAL( changed( bool ) ) ); 00616 connect( w, SIGNAL( configCommitted( const QCString & ) ), this, 00617 SIGNAL( configCommitted( const QCString & ) ) ); 00618 d->pswidgets += w; 00619 } 00620 00621 void KPluginSelector::addPlugins( const KInstance * instance, const QString & 00622 catname, const QString & category, KConfig * config ) 00623 { 00624 addPlugins( instance->instanceName(), catname, category, config ); 00625 } 00626 00627 void KPluginSelector::addPlugins( const QValueList<KPluginInfo*> & plugininfos, 00628 const QString & catname, const QString & category, KConfig * config ) 00629 { 00630 checkNeedForTabWidget(); 00631 KConfigGroup * cfgGroup = new KConfigGroup( config ? config : KGlobal::config(), "Plugins" ); 00632 kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl; 00633 KPluginSelectionWidget * w; 00634 if( d->tabwidget ) 00635 { 00636 w = new KPluginSelectionWidget( plugininfos, this, 00637 d->tabwidget, catname, category, cfgGroup ); 00638 d->tabwidget->addTab( w, catname ); 00639 connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w, 00640 SLOT( tabWidgetChanged( QWidget * ) ) ); 00641 } 00642 else 00643 w = new KPluginSelectionWidget( plugininfos, this, d->frame, 00644 catname, category, cfgGroup ); 00645 w->setMinimumSize( 200, 200 ); 00646 connect( w, SIGNAL( changed( bool ) ), this, SIGNAL( changed( bool ) ) ); 00647 connect( w, SIGNAL( configCommitted( const QCString & ) ), this, 00648 SIGNAL( configCommitted( const QCString & ) ) ); 00649 d->pswidgets += w; 00650 } 00651 00652 QWidgetStack * KPluginSelector::widgetStack() 00653 { 00654 return d->widgetstack; 00655 } 00656 00657 inline void KPluginSelector::configPage( int id ) 00658 { 00659 if( id == 1 ) 00660 { 00661 // no config page 00662 if( d->hideconfigpage ) 00663 { 00664 d->widgetstack->hide(); 00665 return; 00666 } 00667 } 00668 else 00669 d->widgetstack->show(); 00670 00671 d->widgetstack->raiseWidget( id ); 00672 } 00673 00674 void KPluginSelector::setShowEmptyConfigPage( bool show ) 00675 { 00676 d->hideconfigpage = !show; 00677 if( d->hideconfigpage ) 00678 if( d->widgetstack->id( d->widgetstack->visibleWidget() ) == 1 ) 00679 d->widgetstack->hide(); 00680 } 00681 00682 void KPluginSelector::load() 00683 { 00684 for( QValueList<KPluginSelectionWidget *>::Iterator it = 00685 d->pswidgets.begin(); it != d->pswidgets.end(); ++it ) 00686 { 00687 ( *it )->load(); 00688 } 00689 } 00690 00691 void KPluginSelector::save() 00692 { 00693 for( QValueList<KPluginSelectionWidget *>::Iterator it = 00694 d->pswidgets.begin(); it != d->pswidgets.end(); ++it ) 00695 { 00696 ( *it )->save(); 00697 } 00698 } 00699 00700 void KPluginSelector::defaults() 00701 { 00702 kdDebug( 702 ) << k_funcinfo << endl; 00703 00704 // what should defaults do? here's what I think: 00705 // Pressing a button in the dialog should not change any widgets that are 00706 // not visible for the user. Therefor we may only change the currently 00707 // visible plugin's KCM. Restoring the default plugin selections is therefor 00708 // not possible. (if the plugin has multiple KCMs they will be shown in a 00709 // tabwidget - defaults() will be called for all of them) 00710 00711 QWidget * pluginconfig = d->widgetstack->visibleWidget(); 00712 KCModuleProxy * kcm = ( KCModuleProxy* )pluginconfig->qt_cast( 00713 "KCModuleProxy" ); 00714 if( kcm ) 00715 { 00716 kdDebug( 702 ) << "call KCModule::defaults() for the plugins KCM" 00717 << endl; 00718 kcm->defaults(); 00719 return; 00720 } 00721 00722 // if we get here the visible Widget must be a tabwidget holding more than 00723 // one KCM 00724 QObjectList * kcms = pluginconfig->queryList( "KCModuleProxy", 00725 0, false, false ); 00726 QObjectListIt it( *kcms ); 00727 QObject * obj; 00728 while( ( obj = it.current() ) != 0 ) 00729 { 00730 ++it; 00731 ( ( KCModule* )obj )->defaults(); 00732 } 00733 delete kcms; 00734 // FIXME: update changed state 00735 } 00736 00737 // vim: sw=4 sts=4 et 00738 00739 #include "kpluginselector.moc" 00740 #include "kpluginselector_p.moc"
KDE Logo
This file is part of the documentation for kutils Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:22:59 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003