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             if( names->size() == 0 )
00489                 names->append( QString::null );
00490             for( QStringList::ConstIterator nameit = names->begin();
00491                     nameit != names->end(); ++nameit )
00492                 if( updatedModules.find( *nameit ) == updatedModules.end() )
00493                     updatedModules.append( *nameit );
00494         }
00495     for( QStringList::ConstIterator it = updatedModules.begin(); it != updatedModules.end(); ++it )
00496         emit configCommitted( ( *it ).latin1() );
00497 
00498     updateConfigPage();
00499     kdDebug( 702 ) << "syncing config file" << endl;
00500     d->config->sync();
00501     d->changed = 0;
00502     emit changed( false );
00503 }
00504 
00505 void KPluginSelectionWidget::checkDependencies( const KPluginInfo * info )
00506 {
00507     if( info->dependencies().isEmpty() )
00508         return;
00509 
00510     for( QStringList::ConstIterator it = info->dependencies().begin();
00511             it != info->dependencies().end(); ++it )
00512         for( QMap<QCheckListItem*,
00513                 KPluginInfo*>::Iterator infoIt = d->pluginInfoMap.begin();
00514                 infoIt != d->pluginInfoMap.end(); ++infoIt )
00515             if( infoIt.data()->pluginName() == *it )
00516             {
00517                 if( !infoIt.key()->isOn() )
00518                 {
00519                     infoIt.key()->setOn( true );
00520                     checkDependencies( infoIt.data() );
00521                 }
00522                 continue;
00523             }
00524 }
00525 
00526 class KPluginSelector::KPluginSelectorPrivate
00527 {
00528     public:
00529         KPluginSelectorPrivate()
00530             : frame( 0 )
00531             , tabwidget( 0 )
00532             , widgetstack( 0 )
00533             , hideconfigpage( false )
00534             {
00535             }
00536 
00537         QFrame * frame;
00538         KTabWidget * tabwidget;
00539         QWidgetStack * widgetstack;
00540         QValueList<KPluginSelectionWidget *> pswidgets;
00541         bool hideconfigpage;
00542 };
00543 
00544 KPluginSelector::KPluginSelector( QWidget * parent, const char * name )
00545 : QWidget( parent, name )
00546 , d( new KPluginSelectorPrivate )
00547 {
00548     QBoxLayout * hbox = new QHBoxLayout( this, 0, KDialog::spacingHint() );
00549     hbox->setAutoAdd( true );
00550     
00551     QSplitter* splitter = new QSplitter( QSplitter::Horizontal, this );
00552     d->frame = new QFrame( splitter, "KPluginSelector left frame" );
00553     d->frame->setFrameStyle( QFrame::NoFrame );
00554     ( new QVBoxLayout( d->frame, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
00555 
00556     // widgetstack
00557     d->widgetstack = new QWidgetStack( splitter, "KPluginSelector Config Pages" );
00558     d->widgetstack->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00559     d->widgetstack->setMinimumSize( 200, 200 );
00560 
00561     QLabel * label = new QLabel( i18n( "(This plugin is not configurable)" ),
00562             d->widgetstack );
00563     ( new QVBoxLayout( label, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
00564     label->setAlignment( Qt::AlignCenter );
00565     label->setMinimumSize( 200, 200 );
00566 
00567     d->widgetstack->addWidget( label, 1 );
00568 
00569     configPage( 1 );
00570 }
00571 
00572 KPluginSelector::~KPluginSelector()
00573 {
00574     delete d;
00575 }
00576 
00577 void KPluginSelector::checkNeedForTabWidget()
00578 {
00579     kdDebug( 702 ) << k_funcinfo << endl;
00580     if( ! d->tabwidget && d->pswidgets.size() == 1 )
00581     {
00582         kdDebug( 702 ) << "no TabWidget and one KPluginSelectionWidget" << endl;
00583         // there's only one KPluginSelectionWidget yet, we need a TabWidget
00584         KPluginSelectionWidget * w = d->pswidgets.first();
00585         if( w )
00586         {
00587             kdDebug( 702 ) << "create TabWidget" << endl;
00588             d->tabwidget = new KTabWidget( d->frame,
00589                     "KPluginSelector TabWidget" );
00590             w->reparent( d->tabwidget, QPoint( 0, 0 ) );
00591             d->tabwidget->addTab( w, w->catName() );
00592             connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w,
00593                     SLOT( tabWidgetChanged( QWidget * ) ) );
00594         }
00595     }
00596 }
00597 
00598 void KPluginSelector::addPlugins( const QString & instanceName,
00599         const QString & catname, const QString & category, KConfig * config )
00600 {
00601     checkNeedForTabWidget();
00602     // FIXME: mem leak: the KSimpleConfig object needs to be deleted
00603     KConfigGroup * cfgGroup = new KConfigGroup( config ? config :
00604             new KSimpleConfig( instanceName ), "KParts Plugins" );
00605     kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl;
00606     KPluginSelectionWidget * w;
00607     if( d->tabwidget )
00608     {
00609         w = new KPluginSelectionWidget( instanceName, this,
00610                 d->tabwidget, catname, category, cfgGroup );
00611         d->tabwidget->addTab( w, catname );
00612         connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w,
00613                 SLOT( tabWidgetChanged( QWidget * ) ) );
00614     }
00615     else
00616         w = new KPluginSelectionWidget( instanceName, this, d->frame,
00617                 catname, category, cfgGroup );
00618     w->setMinimumSize( 200, 200 );
00619     connect( w, SIGNAL( changed( bool ) ), this, SIGNAL( changed( bool ) ) );
00620     connect( w, SIGNAL( configCommitted( const QCString & ) ), this,
00621             SIGNAL( configCommitted( const QCString & ) ) );
00622     d->pswidgets += w;
00623 }
00624 
00625 void KPluginSelector::addPlugins( const KInstance * instance, const QString &
00626         catname, const QString & category, KConfig * config )
00627 {
00628     addPlugins( instance->instanceName(), catname, category, config );
00629 }
00630 
00631 void KPluginSelector::addPlugins( const QValueList<KPluginInfo*> & plugininfos,
00632         const QString & catname, const QString & category, KConfig * config )
00633 {
00634     checkNeedForTabWidget();
00635     KConfigGroup * cfgGroup = new KConfigGroup( config ? config : KGlobal::config(), "Plugins" );
00636     kdDebug( 702 ) << k_funcinfo << "cfgGroup = " << cfgGroup << endl;
00637     KPluginSelectionWidget * w;
00638     if( d->tabwidget )
00639     {
00640         w = new KPluginSelectionWidget( plugininfos, this,
00641                 d->tabwidget, catname, category, cfgGroup );
00642         d->tabwidget->addTab( w, catname );
00643         connect( d->tabwidget, SIGNAL( currentChanged( QWidget * ) ), w,
00644                 SLOT( tabWidgetChanged( QWidget * ) ) );
00645     }
00646     else
00647         w = new KPluginSelectionWidget( plugininfos, this, d->frame,
00648                 catname, category, cfgGroup );
00649     w->setMinimumSize( 200, 200 );
00650     connect( w, SIGNAL( changed( bool ) ), this, SIGNAL( changed( bool ) ) );
00651     connect( w, SIGNAL( configCommitted( const QCString & ) ), this,
00652             SIGNAL( configCommitted( const QCString & ) ) );
00653     d->pswidgets += w;
00654 }
00655 
00656 QWidgetStack * KPluginSelector::widgetStack()
00657 {
00658     return d->widgetstack;
00659 }
00660 
00661 inline void KPluginSelector::configPage( int id )
00662 {
00663     if( id == 1 )
00664     {
00665         // no config page
00666         if( d->hideconfigpage )
00667         {
00668             d->widgetstack->hide();
00669             return;
00670         }
00671     }
00672     else
00673         d->widgetstack->show();
00674 
00675     d->widgetstack->raiseWidget( id );
00676 }
00677 
00678 void KPluginSelector::setShowEmptyConfigPage( bool show )
00679 {
00680     d->hideconfigpage = !show;
00681     if( d->hideconfigpage )
00682         if( d->widgetstack->id( d->widgetstack->visibleWidget() ) == 1 )
00683             d->widgetstack->hide();
00684 }
00685 
00686 void KPluginSelector::load()
00687 {
00688     for( QValueList<KPluginSelectionWidget *>::Iterator it =
00689             d->pswidgets.begin(); it != d->pswidgets.end(); ++it )
00690     {
00691         ( *it )->load();
00692     }
00693 }
00694 
00695 void KPluginSelector::save()
00696 {
00697     for( QValueList<KPluginSelectionWidget *>::Iterator it =
00698             d->pswidgets.begin(); it != d->pswidgets.end(); ++it )
00699     {
00700         ( *it )->save();
00701     }
00702 }
00703 
00704 void KPluginSelector::defaults()
00705 {
00706     kdDebug( 702 ) << k_funcinfo << endl;
00707 
00708     // what should defaults do? here's what I think:
00709     // Pressing a button in the dialog should not change any widgets that are
00710     // not visible for the user. Therefor we may only change the currently
00711     // visible plugin's KCM. Restoring the default plugin selections is therefor
00712     // not possible. (if the plugin has multiple KCMs they will be shown in a
00713     // tabwidget - defaults() will be called for all of them)
00714 
00715     QWidget * pluginconfig = d->widgetstack->visibleWidget();
00716     KCModuleProxy * kcm = ( KCModuleProxy* )pluginconfig->qt_cast(
00717             "KCModuleProxy" );
00718     if( kcm )
00719     {
00720         kdDebug( 702 ) << "call KCModule::defaults() for the plugins KCM"
00721             << endl;
00722         kcm->defaults();
00723         return;
00724     }
00725 
00726     // if we get here the visible Widget must be a tabwidget holding more than
00727     // one KCM
00728     QObjectList * kcms = pluginconfig->queryList( "KCModuleProxy",
00729             0, false, false );
00730     QObjectListIt it( *kcms );
00731     QObject * obj;
00732     while( ( obj = it.current() ) != 0 )
00733     {
00734         ++it;
00735         ( ( KCModule* )obj )->defaults();
00736     }
00737     delete kcms;
00738     // FIXME: update changed state
00739 }
00740 
00741 // vim: sw=4 sts=4 et
00742 
00743 #include "kpluginselector.moc"
00744 #include "kpluginselector_p.moc"
KDE Logo
This file is part of the documentation for kutils Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jul 2 13:08:27 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003