00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kprefsdialog.h"
00026 #include "ktimeedit.h"
00027 #include "kdateedit.h"
00028
00029 #include <kdeversion.h>
00030 #include <KColorButton>
00031 #include <KComboBox>
00032 #include <KConfigSkeleton>
00033 #include <KDebug>
00034 #include <KFontDialog>
00035 #include <KLineEdit>
00036 #include <KLocale>
00037 #include <KMessageBox>
00038 #include <KPageWidget>
00039 #include <KUrlRequester>
00040
00041 #include <QFont>
00042 #include <QFrame>
00043 #include <QCheckBox>
00044 #include <QGridLayout>
00045 #include <QLabel>
00046 #include <QLayout>
00047 #include <QPushButton>
00048 #include <QRadioButton>
00049 #include <QSpinBox>
00050 #include <QTimeEdit>
00051 #include <Q3ButtonGroup>
00052 #include <Q3HBox>
00053
00054 #include "kprefsdialog.moc"
00055
00056 using namespace KPIM;
00057
00058 namespace KPrefsWidFactory {
00059 KPrefsWid *create( KConfigSkeletonItem *item, QWidget *parent )
00060 {
00061 KConfigSkeleton::ItemBool *boolItem =
00062 dynamic_cast<KConfigSkeleton::ItemBool *>( item );
00063 if ( boolItem ) {
00064 return new KPrefsWidBool( boolItem, parent );
00065 }
00066
00067 KConfigSkeleton::ItemString *stringItem =
00068 dynamic_cast<KConfigSkeleton::ItemString *>( item );
00069 if ( stringItem ) {
00070 return new KPrefsWidString( stringItem, parent );
00071 }
00072
00073 KConfigSkeleton::ItemEnum *enumItem =
00074 dynamic_cast<KConfigSkeleton::ItemEnum *>( item );
00075 if ( enumItem ) {
00076 QList<KConfigSkeleton::ItemEnum::Choice> choices = enumItem->choices();
00077 if ( choices.isEmpty() ) {
00078 kError() << "Enum has no choices.";
00079 return 0;
00080 } else {
00081 KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent );
00082 QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
00083 for ( it = choices.begin(); it != choices.end(); ++it ) {
00084 radios->addRadio( (*it).label );
00085 }
00086 return radios;
00087 }
00088 }
00089
00090 KConfigSkeleton::ItemInt *intItem = dynamic_cast<KConfigSkeleton::ItemInt *>( item );
00091 if ( intItem ) {
00092 return new KPrefsWidInt( intItem, parent );
00093 }
00094
00095 return 0;
00096 }
00097
00098 }
00099
00100 QList<QWidget *> KPrefsWid::widgets() const
00101 {
00102 return QList<QWidget *>();
00103 }
00104
00105 KPrefsWidBool::KPrefsWidBool( KConfigSkeleton::ItemBool *item, QWidget *parent )
00106 : mItem( item )
00107 {
00108 mCheck = new QCheckBox( mItem->label(), parent );
00109 connect( mCheck, SIGNAL(clicked()), SIGNAL(changed()) );
00110 #if KDE_IS_VERSION( 4, 1, 63 )
00111 QString toolTip = mItem->toolTip();
00112 if ( !toolTip.isEmpty() ) {
00113 mCheck->setToolTip( toolTip );
00114 }
00115 #endif
00116 QString whatsThis = mItem->whatsThis();
00117 if ( !whatsThis.isEmpty() ) {
00118 mCheck->setWhatsThis( whatsThis );
00119 }
00120 }
00121
00122 void KPrefsWidBool::readConfig()
00123 {
00124 mCheck->setChecked( mItem->value() );
00125 }
00126
00127 void KPrefsWidBool::writeConfig()
00128 {
00129 mItem->setValue( mCheck->isChecked() );
00130 }
00131
00132 QCheckBox *KPrefsWidBool::checkBox()
00133 {
00134 return mCheck;
00135 }
00136
00137 QList<QWidget *> KPrefsWidBool::widgets() const
00138 {
00139 QList<QWidget *> widgets;
00140 widgets.append( mCheck );
00141 return widgets;
00142 }
00143
00144 KPrefsWidInt::KPrefsWidInt( KConfigSkeleton::ItemInt *item, QWidget *parent )
00145 : mItem( item )
00146 {
00147 mLabel = new QLabel( mItem->label() + ':', parent );
00148 mSpin = new QSpinBox( parent );
00149 if ( !mItem->minValue().isNull() ) {
00150 mSpin->setMinimum( mItem->minValue().toInt() );
00151 }
00152 if ( !mItem->maxValue().isNull() ) {
00153 mSpin->setMaximum( mItem->maxValue().toInt() );
00154 }
00155 connect( mSpin, SIGNAL(valueChanged(int)), SIGNAL(changed()) );
00156 mLabel->setBuddy( mSpin );
00157 #if KDE_IS_VERSION( 4, 1, 63 )
00158 QString toolTip = mItem->toolTip();
00159 if ( !toolTip.isEmpty() ) {
00160 mLabel->setToolTip( toolTip );
00161 mSpin->setToolTip( toolTip );
00162 }
00163 #endif
00164 QString whatsThis = mItem->whatsThis();
00165 if ( !whatsThis.isEmpty() ) {
00166 mLabel->setWhatsThis( whatsThis );
00167 mSpin->setWhatsThis( whatsThis );
00168 }
00169 }
00170
00171 void KPrefsWidInt::readConfig()
00172 {
00173 mSpin->setValue( mItem->value() );
00174 }
00175
00176 void KPrefsWidInt::writeConfig()
00177 {
00178 mItem->setValue( mSpin->value() );
00179 }
00180
00181 QLabel *KPrefsWidInt::label()
00182 {
00183 return mLabel;
00184 }
00185
00186 QSpinBox *KPrefsWidInt::spinBox()
00187 {
00188 return mSpin;
00189 }
00190
00191 QList<QWidget *> KPrefsWidInt::widgets() const
00192 {
00193 QList<QWidget *> widgets;
00194 widgets.append( mLabel );
00195 widgets.append( mSpin );
00196 return widgets;
00197 }
00198
00199 KPrefsWidColor::KPrefsWidColor( KConfigSkeleton::ItemColor *item, QWidget *parent )
00200 : mItem( item )
00201 {
00202 mButton = new KColorButton( parent );
00203 connect( mButton, SIGNAL(changed(const QColor&)), SIGNAL(changed()) );
00204 mLabel = new QLabel( mItem->label() + ':', parent );
00205 mLabel->setBuddy( mButton );
00206 #if KDE_IS_VERSION( 4, 1, 63 )
00207 QString toolTip = mItem->toolTip();
00208 if ( !toolTip.isEmpty() ) {
00209 mButton->setToolTip( toolTip );
00210 }
00211 #endif
00212 QString whatsThis = mItem->whatsThis();
00213 if ( !whatsThis.isEmpty() ) {
00214 mButton->setWhatsThis( whatsThis );
00215 }
00216 }
00217
00218 KPrefsWidColor::~KPrefsWidColor()
00219 {
00220 }
00221
00222 void KPrefsWidColor::readConfig()
00223 {
00224 mButton->setColor( mItem->value() );
00225 }
00226
00227 void KPrefsWidColor::writeConfig()
00228 {
00229 mItem->setValue( mButton->color() );
00230 }
00231
00232 QLabel *KPrefsWidColor::label()
00233 {
00234 return mLabel;
00235 }
00236
00237 KColorButton *KPrefsWidColor::button()
00238 {
00239 return mButton;
00240 }
00241
00242 KPrefsWidFont::KPrefsWidFont( KConfigSkeleton::ItemFont *item,
00243 QWidget *parent, const QString &sampleText )
00244 : mItem( item )
00245 {
00246 mLabel = new QLabel( mItem->label() + ':', parent );
00247
00248 mPreview = new QLabel( sampleText, parent );
00249 mPreview->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00250
00251 mButton = new QPushButton( i18n( "Choose..." ), parent );
00252 connect( mButton, SIGNAL(clicked()), SLOT(selectFont()) );
00253 #if KDE_IS_VERSION( 4, 1, 63 )
00254 QString toolTip = mItem->toolTip();
00255 if ( !toolTip.isEmpty() ) {
00256 mPreview->setToolTip( toolTip );
00257 mButton->setToolTip( toolTip );
00258 }
00259 #endif
00260 QString whatsThis = mItem->whatsThis();
00261 if ( !whatsThis.isEmpty() ) {
00262 mPreview->setWhatsThis( whatsThis );
00263 mButton->setWhatsThis( whatsThis );
00264 }
00265 }
00266
00267 KPrefsWidFont::~KPrefsWidFont()
00268 {
00269 }
00270
00271 void KPrefsWidFont::readConfig()
00272 {
00273 mPreview->setFont( mItem->value() );
00274 }
00275
00276 void KPrefsWidFont::writeConfig()
00277 {
00278 mItem->setValue( mPreview->font() );
00279 }
00280
00281 QLabel *KPrefsWidFont::label()
00282 {
00283 return mLabel;
00284 }
00285
00286 QFrame *KPrefsWidFont::preview()
00287 {
00288 return mPreview;
00289 }
00290
00291 QPushButton *KPrefsWidFont::button()
00292 {
00293 return mButton;
00294 }
00295
00296 void KPrefsWidFont::selectFont()
00297 {
00298 QFont myFont( mPreview->font() );
00299 int result = KFontDialog::getFont( myFont );
00300 if ( result == KFontDialog::Accepted ) {
00301 mPreview->setFont( myFont );
00302 emit changed();
00303 }
00304 }
00305
00306 KPrefsWidTime::KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, QWidget *parent )
00307 : mItem( item )
00308 {
00309 mLabel = new QLabel( mItem->label() + ':', parent );
00310 mTimeEdit = new KTimeEdit( parent );
00311 mLabel->setBuddy( mTimeEdit );
00312 connect( mTimeEdit, SIGNAL(timeChanged(QTime)), SIGNAL(changed()) );
00313 #if KDE_IS_VERSION( 4, 1, 63 )
00314 QString toolTip = mItem->toolTip();
00315 if ( !toolTip.isEmpty() ) {
00316 mTimeEdit->setToolTip( toolTip );
00317 }
00318 #endif
00319 QString whatsThis = mItem->whatsThis();
00320 if ( !whatsThis.isEmpty() ) {
00321 mTimeEdit->setWhatsThis( whatsThis );
00322 }
00323 }
00324
00325 void KPrefsWidTime::readConfig()
00326 {
00327 mTimeEdit->setTime( mItem->value().time() );
00328 }
00329
00330 void KPrefsWidTime::writeConfig()
00331 {
00332
00333
00334 QDateTime dt( mItem->value() );
00335 dt.setTime( mTimeEdit->getTime() );
00336 mItem->setValue( dt );
00337 }
00338
00339 QLabel *KPrefsWidTime::label()
00340 {
00341 return mLabel;
00342 }
00343
00344 KTimeEdit *KPrefsWidTime::timeEdit()
00345 {
00346 return mTimeEdit;
00347 }
00348
00349 KPrefsWidDuration::KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item, QWidget *parent )
00350 : mItem( item )
00351 {
00352 mLabel = new QLabel( mItem->label() + ':', parent );
00353 mTimeEdit = new QTimeEdit( parent );
00354 mLabel->setBuddy( mTimeEdit );
00355 mTimeEdit->setDisplayFormat( "hh:mm:ss" );
00356 mTimeEdit->setMinimumTime( QTime( 0, 1 ) );
00357 mTimeEdit->setMaximumTime( QTime( 24, 0 ) );
00358 connect( mTimeEdit, SIGNAL(timeChanged(const QTime&)), SIGNAL(changed()) );
00359 #if KDE_IS_VERSION( 4, 1, 63 )
00360 QString toolTip = mItem->toolTip();
00361 if ( !toolTip.isEmpty() ) {
00362 mTimeEdit->setToolTip( toolTip );
00363 }
00364 #endif
00365 QString whatsThis = mItem->whatsThis();
00366 if ( !whatsThis.isEmpty() ) {
00367 mTimeEdit->setWhatsThis( whatsThis );
00368 }
00369 }
00370
00371 void KPrefsWidDuration::readConfig()
00372 {
00373 mTimeEdit->setTime( mItem->value().time() );
00374 }
00375
00376 void KPrefsWidDuration::writeConfig()
00377 {
00378 QDateTime dt( mItem->value() );
00379 dt.setTime( mTimeEdit->time() );
00380 mItem->setValue( dt );
00381 }
00382
00383 QLabel *KPrefsWidDuration::label()
00384 {
00385 return mLabel;
00386 }
00387
00388 QTimeEdit *KPrefsWidDuration::timeEdit()
00389 {
00390 return mTimeEdit;
00391 }
00392
00393 KPrefsWidDate::KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, QWidget *parent )
00394 : mItem( item )
00395 {
00396 mLabel = new QLabel( mItem->label() + ':', parent );
00397 mDateEdit = new KDateEdit( parent );
00398 mLabel->setBuddy( mDateEdit );
00399 connect( mDateEdit, SIGNAL(dateChanged(const QDate&)), SIGNAL(changed()) );
00400 #if KDE_IS_VERSION( 4, 1, 63 )
00401 QString toolTip = mItem->toolTip();
00402 if ( !toolTip.isEmpty() ) {
00403 mDateEdit->setToolTip( toolTip );
00404 }
00405 #endif
00406 QString whatsThis = mItem->whatsThis();
00407 if ( !whatsThis.isEmpty() ) {
00408 mDateEdit->setWhatsThis( whatsThis );
00409 }
00410 }
00411
00412 void KPrefsWidDate::readConfig()
00413 {
00414 if ( !mItem->value().date().isValid() ) {
00415 mItem->setValue( QDateTime::currentDateTime() );
00416 }
00417 mDateEdit->setDate( mItem->value().date() );
00418 }
00419
00420 void KPrefsWidDate::writeConfig()
00421 {
00422 QDateTime dt( mItem->value() );
00423 dt.setDate( mDateEdit->date() );
00424 mItem->setValue( dt );
00425 if ( !mItem->value().date().isValid() ) {
00426 mItem->setValue( QDateTime::currentDateTime() );
00427 }
00428 }
00429
00430 QLabel *KPrefsWidDate::label()
00431 {
00432 return mLabel;
00433 }
00434
00435 KDateEdit *KPrefsWidDate::dateEdit()
00436 {
00437 return mDateEdit;
00438 }
00439
00440 KPrefsWidRadios::KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, QWidget *parent )
00441 : mItem( item )
00442 {
00443 mBox = new Q3ButtonGroup( 1, Qt::Horizontal, mItem->label(), parent );
00444 connect( mBox, SIGNAL(clicked(int)), SIGNAL(changed()) );
00445 }
00446
00447 KPrefsWidRadios::~KPrefsWidRadios()
00448 {
00449 }
00450
00451 void KPrefsWidRadios::addRadio( const QString &text, const QString &toolTip,
00452 const QString &whatsThis )
00453 {
00454 QRadioButton *r = new QRadioButton( text, mBox );
00455 if ( !toolTip.isEmpty() ) {
00456 r->setToolTip( toolTip );
00457 }
00458 if ( !whatsThis.isEmpty() ) {
00459 r->setWhatsThis( whatsThis );
00460 }
00461 }
00462
00463 Q3ButtonGroup *KPrefsWidRadios::groupBox()
00464 {
00465 return mBox;
00466 }
00467
00468 void KPrefsWidRadios::readConfig()
00469 {
00470 mBox->setButton( mItem->value() );
00471 }
00472
00473 void KPrefsWidRadios::writeConfig()
00474 {
00475 mItem->setValue( mBox->id( mBox->selected() ) );
00476 }
00477
00478 QList<QWidget *> KPrefsWidRadios::widgets() const
00479 {
00480 QList<QWidget *> w;
00481 w.append( mBox );
00482 return w;
00483 }
00484
00485 KPrefsWidCombo::KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, QWidget *parent )
00486 : mItem( item )
00487 {
00488 Q3HBox *hbox = new Q3HBox( parent );
00489 new QLabel( mItem->label(), hbox );
00490 mCombo = new KComboBox( hbox );
00491 connect( mCombo, SIGNAL(activated(int)), SIGNAL(changed()) );
00492 }
00493
00494 KPrefsWidCombo::~KPrefsWidCombo()
00495 {
00496 }
00497
00498 void KPrefsWidCombo::readConfig()
00499 {
00500 mCombo->setCurrentIndex( mItem->value() );
00501 }
00502
00503 void KPrefsWidCombo::writeConfig()
00504 {
00505 mItem->setValue( mCombo->currentIndex() );
00506 }
00507
00508 QList<QWidget *> KPrefsWidCombo::widgets() const
00509 {
00510 QList<QWidget *> w;
00511 w.append( mCombo );
00512 return w;
00513 }
00514
00515 KComboBox *KPrefsWidCombo::comboBox()
00516 {
00517 return mCombo;
00518 }
00519
00520 KPrefsWidString::KPrefsWidString( KConfigSkeleton::ItemString *item, QWidget *parent,
00521 KLineEdit::EchoMode echomode )
00522 : mItem( item )
00523 {
00524 mLabel = new QLabel( mItem->label() + ':', parent );
00525 mEdit = new KLineEdit( parent );
00526 mLabel->setBuddy( mEdit );
00527 connect( mEdit, SIGNAL(textChanged(const QString&)), SIGNAL(changed()) );
00528 mEdit->setEchoMode( echomode );
00529 #if KDE_IS_VERSION( 4, 1, 63 )
00530 QString toolTip = mItem->toolTip();
00531 if ( !toolTip.isEmpty() ) {
00532 mEdit->setToolTip( toolTip );
00533 }
00534 #endif
00535 QString whatsThis = mItem->whatsThis();
00536 if ( !whatsThis.isEmpty() ) {
00537 mEdit->setWhatsThis( whatsThis );
00538 }
00539 }
00540
00541 KPrefsWidString::~KPrefsWidString()
00542 {
00543 }
00544
00545 void KPrefsWidString::readConfig()
00546 {
00547 mEdit->setText( mItem->value() );
00548 }
00549
00550 void KPrefsWidString::writeConfig()
00551 {
00552 mItem->setValue( mEdit->text() );
00553 }
00554
00555 QLabel *KPrefsWidString::label()
00556 {
00557 return mLabel;
00558 }
00559
00560 KLineEdit *KPrefsWidString::lineEdit()
00561 {
00562 return mEdit;
00563 }
00564
00565 QList<QWidget *> KPrefsWidString::widgets() const
00566 {
00567 QList<QWidget *> widgets;
00568 widgets.append( mLabel );
00569 widgets.append( mEdit );
00570 return widgets;
00571 }
00572
00573 KPrefsWidPath::KPrefsWidPath( KConfigSkeleton::ItemPath *item, QWidget *parent,
00574 const QString &filter, KFile::Modes mode )
00575 : mItem( item )
00576 {
00577 mLabel = new QLabel( mItem->label() + ':', parent );
00578 mURLRequester = new KUrlRequester( parent );
00579 mLabel->setBuddy( mURLRequester );
00580 mURLRequester->setMode( mode );
00581 mURLRequester->setFilter( filter );
00582 connect( mURLRequester, SIGNAL(textChanged(const QString&)), SIGNAL(changed()) );
00583 #if KDE_IS_VERSION( 4, 1, 63 )
00584 QString toolTip = mItem->toolTip();
00585 if ( !toolTip.isEmpty() ) {
00586 mURLRequester->setToolTip( toolTip );
00587 }
00588 #endif
00589 QString whatsThis = mItem->whatsThis();
00590 if ( !whatsThis.isEmpty() ) {
00591 mURLRequester->setWhatsThis( whatsThis );
00592 }
00593 }
00594
00595 KPrefsWidPath::~KPrefsWidPath()
00596 {
00597 }
00598
00599 void KPrefsWidPath::readConfig()
00600 {
00601 mURLRequester->setPath( mItem->value() );
00602 }
00603
00604 void KPrefsWidPath::writeConfig()
00605 {
00606 mItem->setValue( mURLRequester->url().path() );
00607 }
00608
00609 QLabel *KPrefsWidPath::label()
00610 {
00611 return mLabel;
00612 }
00613
00614 KUrlRequester *KPrefsWidPath::urlRequester()
00615 {
00616 return mURLRequester;
00617 }
00618
00619 QList<QWidget *> KPrefsWidPath::widgets() const
00620 {
00621 QList<QWidget *> widgets;
00622 widgets.append( mLabel );
00623 widgets.append( mURLRequester );
00624 return widgets;
00625 }
00626
00627 KPrefsWidManager::KPrefsWidManager( KConfigSkeleton *prefs )
00628 : mPrefs( prefs )
00629 {
00630 }
00631
00632 KPrefsWidManager::~KPrefsWidManager()
00633 {
00634 qDeleteAll( mPrefsWids );
00635 mPrefsWids.clear();
00636 }
00637
00638 void KPrefsWidManager::addWid( KPrefsWid *wid )
00639 {
00640 mPrefsWids.append( wid );
00641 }
00642
00643 KPrefsWidBool *KPrefsWidManager::addWidBool( KConfigSkeleton::ItemBool *item,
00644 QWidget *parent )
00645 {
00646 KPrefsWidBool *w = new KPrefsWidBool( item, parent );
00647 addWid( w );
00648 return w;
00649 }
00650
00651 KPrefsWidTime *KPrefsWidManager::addWidTime( KConfigSkeleton::ItemDateTime *item,
00652 QWidget *parent )
00653 {
00654 KPrefsWidTime *w = new KPrefsWidTime( item, parent );
00655 addWid( w );
00656 return w;
00657 }
00658
00659 KPrefsWidDuration *KPrefsWidManager::addWidDuration( KConfigSkeleton::ItemDateTime *item,
00660 QWidget *parent )
00661 {
00662 KPrefsWidDuration *w = new KPrefsWidDuration( item, parent );
00663 addWid( w );
00664 return w;
00665 }
00666
00667 KPrefsWidDate *KPrefsWidManager::addWidDate( KConfigSkeleton::ItemDateTime *item,
00668 QWidget *parent )
00669 {
00670 KPrefsWidDate *w = new KPrefsWidDate( item, parent );
00671 addWid( w );
00672 return w;
00673 }
00674
00675 KPrefsWidColor *KPrefsWidManager::addWidColor( KConfigSkeleton::ItemColor *item,
00676 QWidget *parent )
00677 {
00678 KPrefsWidColor *w = new KPrefsWidColor( item, parent );
00679 addWid( w );
00680 return w;
00681 }
00682
00683 KPrefsWidRadios *KPrefsWidManager::addWidRadios( KConfigSkeleton::ItemEnum *item,
00684 QWidget *parent )
00685 {
00686 KPrefsWidRadios *w = new KPrefsWidRadios( item, parent );
00687 #if KDE_IS_VERSION( 4, 1, 63 )
00688 QList<KConfigSkeleton::ItemEnum::Choice2> choices;
00689 choices = item->choices2();
00690 QList<KConfigSkeleton::ItemEnum::Choice2>::ConstIterator it;
00691 for ( it = choices.begin(); it != choices.end(); ++it ) {
00692 w->addRadio( (*it).label, (*it).toolTip, (*it).whatsThis );
00693 }
00694 #else
00695 QList<KConfigSkeleton::ItemEnum::Choice> choices;
00696 choices = item->choices();
00697 QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
00698 for ( it = choices.begin(); it != choices.end(); ++it ) {
00699 w->addRadio( (*it).label, QString(), (*it).whatsThis );
00700 }
00701 #endif
00702 addWid( w );
00703 return w;
00704 }
00705
00706 KPrefsWidCombo *KPrefsWidManager::addWidCombo( KConfigSkeleton::ItemEnum *item,
00707 QWidget *parent )
00708 {
00709 KPrefsWidCombo *w = new KPrefsWidCombo( item, parent );
00710 QList<KConfigSkeleton::ItemEnum::Choice> choices;
00711 choices = item->choices();
00712 QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
00713 for ( it = choices.begin(); it != choices.end(); ++it ) {
00714 w->comboBox()->addItem( (*it).label );
00715 }
00716 addWid( w );
00717 return w;
00718 }
00719
00720 KPrefsWidString *KPrefsWidManager::addWidString( KConfigSkeleton::ItemString *item,
00721 QWidget *parent )
00722 {
00723 KPrefsWidString *w = new KPrefsWidString( item, parent, KLineEdit::Normal );
00724 addWid( w );
00725 return w;
00726 }
00727
00728 KPrefsWidPath *KPrefsWidManager::addWidPath( KConfigSkeleton::ItemPath *item,
00729 QWidget *parent,
00730 const QString &filter,
00731 KFile::Modes mode )
00732 {
00733 KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode );
00734 addWid( w );
00735 return w;
00736 }
00737
00738 KPrefsWidString *KPrefsWidManager::addWidPassword( KConfigSkeleton::ItemString *item,
00739 QWidget *parent )
00740 {
00741 KPrefsWidString *w = new KPrefsWidString( item, parent, KLineEdit::Password );
00742 addWid( w );
00743 return w;
00744 }
00745
00746 KPrefsWidFont *KPrefsWidManager::addWidFont( KConfigSkeleton::ItemFont *item,
00747 QWidget *parent,
00748 const QString &sampleText )
00749 {
00750 KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText );
00751 addWid( w );
00752 return w;
00753 }
00754
00755 KPrefsWidInt *KPrefsWidManager::addWidInt( KConfigSkeleton::ItemInt *item,
00756 QWidget *parent )
00757 {
00758 KPrefsWidInt *w = new KPrefsWidInt( item, parent );
00759 addWid( w );
00760 return w;
00761 }
00762
00763 void KPrefsWidManager::setWidDefaults()
00764 {
00765 bool tmp = mPrefs->useDefaults( true );
00766 readWidConfig();
00767 mPrefs->useDefaults( tmp );
00768 }
00769
00770 void KPrefsWidManager::readWidConfig()
00771 {
00772 QList<KPrefsWid*>::Iterator it;
00773 for ( it = mPrefsWids.begin(); it != mPrefsWids.end(); ++it ) {
00774 (*it)->readConfig();
00775 }
00776 }
00777
00778 void KPrefsWidManager::writeWidConfig()
00779 {
00780 QList<KPrefsWid*>::Iterator it;
00781 for ( it = mPrefsWids.begin(); it != mPrefsWids.end(); ++it ) {
00782 (*it)->writeConfig();
00783 }
00784
00785 mPrefs->writeConfig();
00786 }
00787
00788 KPrefsDialog::KPrefsDialog( KConfigSkeleton *prefs, QWidget *parent, bool modal )
00789 : KPageDialog( parent ),
00790 KPrefsWidManager( prefs )
00791 {
00792 setFaceType( List );
00793 setCaption( i18n( "Preferences" ) );
00794 setButtons( Ok|Apply|Cancel|Default );
00795 setDefaultButton( Ok );
00796 setModal( modal );
00797 showButtonSeparator( true );
00798 connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
00799 connect( this, SIGNAL(applyClicked()), SLOT(slotApply()) );
00800 connect( this, SIGNAL(defaultClicked()), SLOT(slotDefault()) );
00801 connect( this, SIGNAL(cancelClicked()), SLOT(reject()) );
00802 }
00803
00804 KPrefsDialog::~KPrefsDialog()
00805 {
00806
00807 }
00808
00809 void KPrefsDialog::autoCreate()
00810 {
00811 KConfigSkeletonItem::List items = prefs()->items();
00812
00813 QMap<QString,QWidget *> mGroupPages;
00814 QMap<QString,QGridLayout *> mGroupLayouts;
00815 QMap<QString,int> mCurrentRows;
00816
00817 KConfigSkeletonItem::List::ConstIterator it;
00818 for ( it = items.begin(); it != items.end(); ++it ) {
00819 QString group = (*it)->group();
00820 QString name = (*it)->name();
00821
00822 QWidget *page;
00823 QGridLayout *layout;
00824 int currentRow;
00825 if ( !mGroupPages.contains( group ) ) {
00826 page = new QWidget( this );
00827 addPage( page, group );
00828 layout = new QGridLayout( page );
00829 mGroupPages.insert( group, page );
00830 mGroupLayouts.insert( group, layout );
00831 currentRow = 0;
00832 mCurrentRows.insert( group, currentRow );
00833 } else {
00834 page = mGroupPages[ group ];
00835 layout = mGroupLayouts[ group ];
00836 currentRow = mCurrentRows[ group ];
00837 }
00838
00839 KPrefsWid *wid = KPrefsWidFactory::create( *it, page );
00840
00841 if ( wid ) {
00842 QList<QWidget *> widgets = wid->widgets();
00843 if ( widgets.count() == 1 ) {
00844 layout->addWidget( widgets[ 0 ], currentRow, currentRow, 0, 1 );
00845 } else if ( widgets.count() == 2 ) {
00846 layout->addWidget( widgets[ 0 ], currentRow, 0 );
00847 layout->addWidget( widgets[ 1 ], currentRow, 1 );
00848 } else {
00849 kError() <<"More widgets than expected:" << widgets.count();
00850 }
00851
00852 if ( (*it)->isImmutable() ) {
00853 QList<QWidget *>::Iterator it2;
00854 for ( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) {
00855 (*it2)->setEnabled( false );
00856 }
00857 }
00858 addWid( wid );
00859 mCurrentRows.insert( group, ++currentRow );
00860 }
00861 }
00862
00863 readConfig();
00864 }
00865
00866 void KPrefsDialog::setDefaults()
00867 {
00868 setWidDefaults();
00869 }
00870
00871 void KPrefsDialog::readConfig()
00872 {
00873 readWidConfig();
00874 usrReadConfig();
00875 }
00876
00877 void KPrefsDialog::writeConfig()
00878 {
00879 writeWidConfig();
00880 usrWriteConfig();
00881 readConfig();
00882 }
00883
00884 void KPrefsDialog::slotApply()
00885 {
00886 writeConfig();
00887
00888 emit configChanged();
00889 }
00890
00891 void KPrefsDialog::slotOk()
00892 {
00893 slotApply();
00894 accept();
00895 }
00896
00897 void KPrefsDialog::slotDefault()
00898 {
00899 if ( KMessageBox::warningContinueCancel(
00900 this,
00901 i18n( "You are about to set all preferences to default values. "
00902 "All custom modifications will be lost." ),
00903 i18n( "Setting Default Preferences" ),
00904 KGuiItem( i18n( "Reset to Defaults" ) ) ) == KMessageBox::Continue ) {
00905 setDefaults();
00906 }
00907 }
00908
00909 KPrefsModule::KPrefsModule( KConfigSkeleton *prefs, const KComponentData &instance,
00910 QWidget *parent, const QVariantList &args )
00911 : KCModule( instance, parent, args ),
00912 KPrefsWidManager( prefs )
00913 {
00914 emit changed( false );
00915 }
00916
00917 void KPrefsModule::addWid( KPrefsWid *wid )
00918 {
00919 KPrefsWidManager::addWid( wid );
00920 connect( wid, SIGNAL(changed()), SLOT(slotWidChanged()) );
00921 }
00922
00923 void KPrefsModule::slotWidChanged()
00924 {
00925 emit changed( true );
00926 }
00927
00928 void KPrefsModule::load()
00929 {
00930 readWidConfig();
00931 usrReadConfig();
00932
00933 emit changed( false );
00934 }
00935
00936 void KPrefsModule::save()
00937 {
00938 writeWidConfig();
00939 usrWriteConfig();
00940 }
00941
00942 void KPrefsModule::defaults()
00943 {
00944 setWidDefaults();
00945
00946 emit changed( true );
00947 }