kutils Library API Documentation

componentsdialog.cpp

00001 /*  This file is part of the KDE project
00002     Copyright (C) 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 "ksettings/componentsdialog.h"
00021 #include <klocale.h>
00022 #include <qlayout.h>
00023 #include <klistview.h>
00024 #include <qlabel.h>
00025 #include <qheader.h>
00026 #include <kplugininfo.h>
00027 #include <kiconloader.h>
00028 #include <kdebug.h>
00029 #include <kconfig.h>
00030 #include <kseparator.h>
00031 
00032 namespace KSettings
00033 {
00034 
00035 class ComponentsDialog::ComponentsDialogPrivate
00036 {
00037     public:
00038         KListView * listview;
00039         QFrame * infowidget;
00040         QLabel * iconwidget;
00041         QLabel * commentwidget;
00042         QLabel * descriptionwidget;
00043         QMap<QCheckListItem*, KPluginInfo*> plugininfomap;
00044         QValueList<KPluginInfo*> plugininfolist;
00045 };
00046 
00047 ComponentsDialog::ComponentsDialog( QWidget * parent, const char * name )
00048     : KDialogBase( parent, name, false, i18n( "Select Components" ) )
00049 , d( new ComponentsDialogPrivate )
00050 {
00051     QWidget * page = new QWidget( this );
00052     setMainWidget( page );
00053     ( new QHBoxLayout( page, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
00054     d->listview = new KListView( page );
00055     d->listview->setMinimumSize( 200, 200 );
00056     d->infowidget = new QFrame( page );
00057     d->infowidget->setMinimumSize( 200, 200 );
00058     ( new QVBoxLayout( d->infowidget, 0, KDialog::spacingHint() ) )->setAutoAdd( true );
00059     d->iconwidget = new QLabel( d->infowidget );
00060     ( void )new KSeparator( d->infowidget );
00061     d->commentwidget = new QLabel( d->infowidget );
00062     d->commentwidget->setAlignment( Qt::WordBreak );
00063     d->descriptionwidget = new QLabel( d->infowidget );
00064     d->descriptionwidget->setAlignment( Qt::WordBreak );
00065 
00066     d->listview->addColumn( QString::null );
00067     d->listview->header()->hide();
00068     d->listview->setRootIsDecorated( true );
00069     d->listview->setSorting( -1 );
00070     d->listview->setAcceptDrops( false );
00071     d->listview->setSelectionModeExt( KListView::Single );
00072     d->listview->setAllColumnsShowFocus( true );
00073 
00074     connect( d->listview, SIGNAL( pressed( QListViewItem * ) ), this,
00075             SLOT( executed( QListViewItem * ) ) );
00076     connect( d->listview, SIGNAL( spacePressed( QListViewItem * ) ), this,
00077             SLOT( executed( QListViewItem * ) ) );
00078     connect( d->listview, SIGNAL( returnPressed( QListViewItem * ) ), this,
00079             SLOT( executed( QListViewItem * ) ) );
00080     connect( d->listview, SIGNAL( selectionChanged( QListViewItem * ) ), this,
00081             SLOT( executed( QListViewItem * ) ) );
00082 }
00083 
00084 ComponentsDialog::~ComponentsDialog()
00085 {
00086 }
00087 
00088 void ComponentsDialog::setPluginInfos( const QMap<QString, KPluginInfo*> &
00089         plugininfos )
00090 {
00091     for( QMap<QString, KPluginInfo*>::ConstIterator it = plugininfos.begin();
00092             it != plugininfos.end(); ++it )
00093     {
00094         d->plugininfolist.append( it.data() );
00095     }
00096 }
00097 
00098 void ComponentsDialog::setPluginInfos( const QValueList<KPluginInfo *> &plugins )
00099 {
00100     d->plugininfolist = plugins;
00101 }
00102 
00103 void ComponentsDialog::show()
00104 {
00105     // construct the treelist
00106     d->listview->clear();
00107     for( QValueList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00108             it != d->plugininfolist.end(); ++it )
00109     {
00110         ( *it )->load();
00111         QCheckListItem * item = new QCheckListItem( d->listview, ( *it )->name(),
00112                 QCheckListItem::CheckBox );
00113         if( ! ( *it )->icon().isEmpty() )
00114             item->setPixmap( 0, SmallIcon( ( *it )->icon(), IconSize( KIcon::Small ) ) );
00115         item->setOn( ( *it )->isPluginEnabled() );
00116         d->plugininfomap[ item ] = ( *it );
00117     }
00118     KDialogBase::show();
00119 }
00120 
00121 void ComponentsDialog::executed( QListViewItem * item )
00122 {
00123     kdDebug( 704 ) << k_funcinfo << endl;
00124     if( item == 0 )
00125         return;
00126     if( item->rtti() != 1 ) // check for QCheckListItem
00127         return;
00128 
00129     QCheckListItem * citem = static_cast<QCheckListItem *>( item );
00130     bool checked = citem->isOn();
00131 
00132     kdDebug( 704 ) << "it's a " << ( checked ? "checked" : "unchecked" )
00133         << " QCheckListItem" << endl;
00134 
00135     KPluginInfo * info = d->plugininfomap[ citem ];
00136     info->setPluginEnabled( checked );
00137     //checkDependencies( info );
00138     // show info about the component on the right
00139     d->iconwidget->setPixmap( SmallIcon( info->icon(), KIcon::SizeLarge ) );
00140     d->commentwidget->setText( info->comment() );
00141     //d->descriptionwidget->setText( info->description() );
00142 }
00143 
00144 void ComponentsDialog::savePluginInfos()
00145 {
00146     for( QValueList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00147             it != d->plugininfolist.end(); ++it )
00148     {
00149         if( ( *it )->config() )
00150         {
00151             ( *it )->save();
00152             ( *it )->config()->sync();
00153         }
00154     }
00155 }
00156 
00157 void ComponentsDialog::slotOk()
00158 {
00159     savePluginInfos();
00160     KDialogBase::slotOk();
00161 }
00162 
00163 void ComponentsDialog::slotApply()
00164 {
00165     savePluginInfos();
00166     KDialogBase::slotApply();
00167 }
00168 
00169 } //namespace
00170 
00171 #include "componentsdialog.moc"
00172 // vim: sw=4 sts=4 et
KDE Logo
This file is part of the documentation for kutils Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 4 22:44:55 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003