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 00060 d->listview = new QTreeWidget( page ); 00061 d->listview->setMinimumSize( 200, 200 ); 00062 d->infowidget = new QFrame( page ); 00063 d->infowidget->setMinimumSize( 200, 200 ); 00064 00065 QVBoxLayout *vbox = new QVBoxLayout( d->infowidget ); 00066 vbox->setMargin( 0 ); 00067 00068 d->iconwidget = new QLabel( d->infowidget ); 00069 vbox->addWidget( d->iconwidget ); 00070 vbox->addWidget( new KSeparator( d->infowidget ) ); 00071 d->commentwidget = new QLabel( d->infowidget ); 00072 d->commentwidget->setWordWrap( true ); 00073 vbox->addWidget( d->commentwidget ); 00074 d->descriptionwidget = new QLabel( d->infowidget ); 00075 d->descriptionwidget->setWordWrap( true ); 00076 vbox->addWidget( d->descriptionwidget ); 00077 00078 d->listview->setAcceptDrops( false ); 00079 00080 connect( d->listview, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ), this, 00081 SLOT( executed( QTreeWidgetItem *, int ) ) ); 00082 connect( d->listview, SIGNAL( itemActivated( QTreeWidgetItem *, int ) ), this, 00083 SLOT( executed( QTreeWidgetItem *, int ) ) ); 00084 connect( d->listview, SIGNAL( itemSelectionChanged( QTreeWidgetItem *, int ) ), this, 00085 SLOT( executed( QTreeWidgetItem *, int ) ) ); 00086 } 00087 00088 ComponentsDialog::~ComponentsDialog() 00089 { 00090 delete d; 00091 } 00092 00093 void ComponentsDialog::addPluginInfo( KPluginInfo * info ) 00094 { 00095 d->plugininfolist.append( info ); 00096 } 00097 00098 void ComponentsDialog::setPluginInfos( const QMap<QString, KPluginInfo*> & 00099 plugininfos ) 00100 { 00101 for( QMap<QString, KPluginInfo*>::ConstIterator it = plugininfos.begin(); 00102 it != plugininfos.end(); ++it ) 00103 { 00104 d->plugininfolist.append( it.value() ); 00105 } 00106 } 00107 00108 void ComponentsDialog::setPluginInfos( const QList<KPluginInfo *> &plugins ) 00109 { 00110 d->plugininfolist = plugins; 00111 } 00112 00113 void ComponentsDialog::show() 00114 { 00115 // clear the treelist 00116 d->listview->clear(); 00117 d->plugininfomap.clear(); 00118 00119 // construct the treelist 00120 for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.constBegin(); 00121 it != d->plugininfolist.constEnd(); ++it ) 00122 { 00123 ( *it )->load(); 00124 QTreeWidgetItem * item = new QTreeWidgetItem( d->listview, QStringList( ( *it )->name() ) ); 00125 if( ! ( *it )->icon().isEmpty() ) 00126 item->setIcon( 0, SmallIcon( ( *it )->icon(), IconSize( KIconLoader::Small ) ) ); 00127 item->setCheckState( 0, ( *it )->isPluginEnabled() ? Qt::Checked : Qt::Unchecked ); 00128 d->plugininfomap[ item ] = ( *it ); 00129 } 00130 KDialog::show(); 00131 } 00132 00133 void ComponentsDialog::executed( QTreeWidgetItem * item, int ) 00134 { 00135 kDebug( 704 ) ; 00136 if( item == 0 ) 00137 return; 00138 00139 bool checked = ( item->checkState(0) == Qt::Checked ); 00140 00141 kDebug( 704 ) << "it's a " << ( checked ? "checked" : "unchecked" ) 00142 << " QCheckListItem" << endl; 00143 00144 KPluginInfo * info = d->plugininfomap[ item ]; 00145 info->setPluginEnabled( checked ); 00146 //checkDependencies( info ); 00147 // show info about the component on the right 00148 d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) ); 00149 d->commentwidget->setText( info->comment() ); 00150 //d->descriptionwidget->setText( info->description() ); 00151 } 00152 00153 void ComponentsDialog::savePluginInfos() 00154 { 00155 for( QList<KPluginInfo*>::ConstIterator it = d->plugininfolist.constBegin(); 00156 it != d->plugininfolist.constEnd(); ++it ) 00157 { 00158 if ((*it)->config().isValid()) { 00159 ( *it )->save(); 00160 (*it)->config().sync(); 00161 } 00162 } 00163 } 00164 00165 void ComponentsDialog::slotOk() 00166 { 00167 savePluginInfos(); 00168 KDialog::slotButtonClicked( Ok ); 00169 } 00170 00171 void ComponentsDialog::slotApply() 00172 { 00173 savePluginInfos(); 00174 KDialog::slotButtonClicked( Apply ); 00175 } 00176 00177 } //namespace 00178 00179 #include "componentsdialog_p.moc"
KDE 4.6 API Reference