• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KUtils

componentsdialog.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "componentsdialog_p.h"
00021 #include <klocale.h>
00022 #include <QtGui/QLayout>
00023 #include <QtGui/QLabel>
00024 #include <kplugininfo.h>
00025 #include <kiconloader.h>
00026 #include <kdebug.h>
00027 #include <kconfig.h>
00028 #include <kseparator.h>
00029 
00030 #include <QtCore/QList>
00031 #include <QtGui/QTreeWidget>
00032 
00033 namespace KSettings
00034 {
00035 
00036 class ComponentsDialog::ComponentsDialogPrivate
00037 {
00038     public:
00039         QTreeWidget * listview;
00040         QFrame * infowidget;
00041         QLabel * iconwidget;
00042         QLabel * commentwidget;
00043         QLabel * descriptionwidget;
00044         QMap<QTreeWidgetItem*, KPluginInfo*> plugininfomap;
00045         QList<KPluginInfo*> plugininfolist;
00046 };
00047 
00048 ComponentsDialog::ComponentsDialog( QWidget * parent, const char * name )
00049     : KDialog( parent ), d( new ComponentsDialogPrivate )
00050 {
00051     setObjectName( name );
00052     setModal( false );
00053     setCaption( i18n( "Select Components" ) );
00054 
00055     QWidget * page = new QWidget( this );
00056     setMainWidget( page );
00057     QHBoxLayout *hbox = new QHBoxLayout( page );
00058     hbox->setMargin( 0 );
00059     hbox->setSpacing( KDialog::spacingHint() );
00060 
00061     d->listview = new QTreeWidget( page );
00062     d->listview->setMinimumSize( 200, 200 );
00063     d->infowidget = new QFrame( page );
00064     d->infowidget->setMinimumSize( 200, 200 );
00065 
00066     QVBoxLayout *vbox = new QVBoxLayout( d->infowidget );
00067     vbox->setMargin( 0 );
00068     vbox->setSpacing( KDialog::spacingHint() );
00069 
00070     d->iconwidget = new QLabel( d->infowidget );
00071     vbox->addWidget( d->iconwidget );
00072     vbox->addWidget( new KSeparator( d->infowidget ) );
00073     d->commentwidget = new QLabel( d->infowidget );
00074     d->commentwidget->setWordWrap( true );
00075     vbox->addWidget( d->commentwidget );
00076     d->descriptionwidget = new QLabel( d->infowidget );
00077     d->descriptionwidget->setWordWrap( true );
00078     vbox->addWidget( d->descriptionwidget );
00079 
00080     d->listview->setAcceptDrops( false );
00081 
00082     connect( d->listview, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ), this,
00083             SLOT( executed( QTreeWidgetItem *, int ) ) );
00084     connect( d->listview, SIGNAL( itemActivated( QTreeWidgetItem *, int ) ), this,
00085             SLOT( executed( QTreeWidgetItem *, int ) ) );
00086     connect( d->listview, SIGNAL( itemSelectionChanged( QTreeWidgetItem *, int ) ), this,
00087             SLOT( executed( QTreeWidgetItem *, int ) ) );
00088 }
00089 
00090 ComponentsDialog::~ComponentsDialog()
00091 {
00092     delete d;
00093 }
00094 
00095 void ComponentsDialog::addPluginInfo( KPluginInfo * info )
00096 {
00097     d->plugininfolist.append( info );
00098 }
00099 
00100 void ComponentsDialog::setPluginInfos( const QMap<QString, KPluginInfo*> &
00101         plugininfos )
00102 {
00103     for( QMap<QString, KPluginInfo*>::ConstIterator it = plugininfos.begin();
00104             it != plugininfos.end(); ++it )
00105     {
00106         d->plugininfolist.append( it.value() );
00107     }
00108 }
00109 
00110 void ComponentsDialog::setPluginInfos( const QList<KPluginInfo *> &plugins )
00111 {
00112     d->plugininfolist = plugins;
00113 }
00114 
00115 void ComponentsDialog::show()
00116 {
00117     // clear the treelist
00118     d->listview->clear();
00119     d->plugininfomap.clear();
00120 
00121     // construct the treelist
00122     for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00123             it != d->plugininfolist.end(); ++it )
00124     {
00125         ( *it )->load();
00126         QTreeWidgetItem * item = new QTreeWidgetItem( d->listview, QStringList( ( *it )->name() ) );
00127         if( ! ( *it )->icon().isEmpty() )
00128             item->setIcon( 0, SmallIcon( ( *it )->icon(), IconSize( KIconLoader::Small ) ) );
00129         item->setCheckState( 0, ( *it )->isPluginEnabled() ? Qt::Checked : Qt::Unchecked );
00130         d->plugininfomap[ item ] = ( *it );
00131     }
00132     KDialog::show();
00133 }
00134 
00135 void ComponentsDialog::executed( QTreeWidgetItem * item, int )
00136 {
00137     kDebug( 704 ) ;
00138     if( item == 0 )
00139         return;
00140 
00141     bool checked = ( item->checkState(0) == Qt::Checked );
00142 
00143     kDebug( 704 ) << "it's a " << ( checked ? "checked" : "unchecked" )
00144         << " QCheckListItem" << endl;
00145 
00146     KPluginInfo * info = d->plugininfomap[ item ];
00147     info->setPluginEnabled( checked );
00148     //checkDependencies( info );
00149     // show info about the component on the right
00150     d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) );
00151     d->commentwidget->setText( info->comment() );
00152     //d->descriptionwidget->setText( info->description() );
00153 }
00154 
00155 void ComponentsDialog::savePluginInfos()
00156 {
00157     for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00158             it != d->plugininfolist.end(); ++it )
00159     {
00160         if ((*it)->config().isValid()) {
00161             ( *it )->save();
00162             (*it)->config().sync();
00163         }
00164     }
00165 }
00166 
00167 void ComponentsDialog::slotOk()
00168 {
00169     savePluginInfos();
00170     KDialog::slotButtonClicked( Ok );
00171 }
00172 
00173 void ComponentsDialog::slotApply()
00174 {
00175     savePluginInfos();
00176     KDialog::slotButtonClicked( Apply );
00177 }
00178 
00179 } //namespace
00180 
00181 #include "componentsdialog_p.moc"

KUtils

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal