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
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
00116 d->listview->clear();
00117 d->plugininfomap.clear();
00118
00119
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
00147
00148 d->iconwidget->setPixmap( SmallIcon( info->icon(), KIconLoader::SizeLarge ) );
00149 d->commentwidget->setText( info->comment() );
00150
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 }
00178
00179 #include "componentsdialog_p.moc"