00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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::addPluginInfo(
KPluginInfo * info )
00089 {
00090 d->plugininfolist.append( info );
00091 }
00092
00093 void ComponentsDialog::setPluginInfos(
const QMap<QString, KPluginInfo*> &
00094 plugininfos )
00095 {
00096
for(
QMap<QString, KPluginInfo*>::ConstIterator it = plugininfos.begin();
00097 it != plugininfos.end(); ++it )
00098 {
00099 d->plugininfolist.append( it.data() );
00100 }
00101 }
00102
00103 void ComponentsDialog::setPluginInfos(
const QValueList<KPluginInfo *> &plugins )
00104 {
00105 d->plugininfolist = plugins;
00106 }
00107
00108 void ComponentsDialog::show()
00109 {
00110
00111 d->listview->clear();
00112 d->plugininfomap.clear();
00113
00114
00115
for(
QValueList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00116 it != d->plugininfolist.end(); ++it )
00117 {
00118 ( *it )->load();
00119
QCheckListItem * item =
new QCheckListItem( d->listview, ( *it )->name(),
00120 QCheckListItem::CheckBox );
00121
if( ! ( *it )->icon().isEmpty() )
00122 item->setPixmap( 0, SmallIcon( ( *it )->icon(), IconSize( KIcon::Small ) ) );
00123 item->setOn( ( *it )->isPluginEnabled() );
00124 d->plugininfomap[ item ] = ( *it );
00125 }
00126 KDialogBase::show();
00127 }
00128
00129
void ComponentsDialog::executed(
QListViewItem * item )
00130 {
00131
kdDebug( 704 ) <<
k_funcinfo <<
endl;
00132
if( item == 0 )
00133
return;
00134
if( item->rtti() != 1 )
00135
return;
00136
00137
QCheckListItem * citem = static_cast<QCheckListItem *>( item );
00138
bool checked = citem->isOn();
00139
00140
kdDebug( 704 ) <<
"it's a " << ( checked ?
"checked" :
"unchecked" )
00141 <<
" QCheckListItem" <<
endl;
00142
00143
KPluginInfo * info = d->plugininfomap[ citem ];
00144 info->
setPluginEnabled( checked );
00145
00146
00147 d->iconwidget->setPixmap( SmallIcon( info->
icon(), KIcon::SizeLarge ) );
00148 d->commentwidget->setText( info->
comment() );
00149
00150 }
00151
00152
void ComponentsDialog::savePluginInfos()
00153 {
00154
for(
QValueList<KPluginInfo*>::ConstIterator it = d->plugininfolist.begin();
00155 it != d->plugininfolist.end(); ++it )
00156 {
00157
if( ( *it )->config() )
00158 {
00159 ( *it )->save();
00160 ( *it )->config()->sync();
00161 }
00162 }
00163 }
00164
00165
void ComponentsDialog::slotOk()
00166 {
00167 savePluginInfos();
00168
KDialogBase::slotOk();
00169 }
00170
00171
void ComponentsDialog::slotApply()
00172 {
00173 savePluginInfos();
00174
KDialogBase::slotApply();
00175 }
00176
00177 }
00178
00179
#include "componentsdialog.moc"
00180