KUtils
componentsdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00118 d->listview->clear();
00119 d->plugininfomap.clear();
00120
00121
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
00149
00150 d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) );
00151 d->commentwidget->setText( info->comment() );
00152
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 }
00180
00181 #include "componentsdialog_p.moc"