libkdepim

kprefsdialog.cpp

00001 /*
00002     This file is part of libkdepim.
00003 
00004     Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006     Copyright (C) 2005 Allen Winter <winter@kde.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qbuttongroup.h>
00027 #include <qlineedit.h>
00028 #include <qfont.h>
00029 #include <qspinbox.h>
00030 #include <qframe.h>
00031 #include <qcombobox.h>
00032 #include <qcheckbox.h>
00033 #include <qradiobutton.h>
00034 #include <qpushbutton.h>
00035 #include <qdatetimeedit.h>
00036 #include <qwhatsthis.h>
00037 
00038 #include <kcolorbutton.h>
00039 #include <kdebug.h>
00040 #include <klocale.h>
00041 #include <kfontdialog.h>
00042 #include <kmessagebox.h>
00043 #include <kconfigskeleton.h>
00044 #include <kurlrequester.h>
00045 #include "ktimeedit.h"
00046 #include "kdateedit.h"
00047 
00048 #include "kprefsdialog.h"
00049 #include "kprefsdialog.moc"
00050 
00051 namespace KPrefsWidFactory {
00052 
00053 KPrefsWid *create( KConfigSkeletonItem *item, QWidget *parent )
00054 {
00055   KConfigSkeleton::ItemBool *boolItem =
00056       dynamic_cast<KConfigSkeleton::ItemBool *>( item );
00057   if ( boolItem ) {
00058     return new KPrefsWidBool( boolItem, parent );
00059   }
00060 
00061   KConfigSkeleton::ItemString *stringItem =
00062       dynamic_cast<KConfigSkeleton::ItemString *>( item );
00063   if ( stringItem ) {
00064     return new KPrefsWidString( stringItem, parent );
00065   }
00066 
00067   KConfigSkeleton::ItemEnum *enumItem =
00068       dynamic_cast<KConfigSkeleton::ItemEnum *>( item );
00069   if ( enumItem ) {
00070     QValueList<KConfigSkeleton::ItemEnum::Choice> choices = enumItem->choices();
00071     if ( choices.isEmpty() ) {
00072       kdError() << "KPrefsWidFactory::create(): Enum has no choices." << endl;
00073       return 0;
00074     } else {
00075       KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent );
00076       QValueList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
00077       for( it = choices.begin(); it != choices.end(); ++it ) {
00078         radios->addRadio( (*it).label );
00079       }
00080       return radios;
00081     }
00082   }
00083 
00084   KConfigSkeleton::ItemInt *intItem =
00085       dynamic_cast<KConfigSkeleton::ItemInt *>( item );
00086   if ( intItem ) {
00087     return new KPrefsWidInt( intItem, parent );
00088   }
00089 
00090   return 0;
00091 }
00092 
00093 }
00094 
00095 
00096 QValueList<QWidget *> KPrefsWid::widgets() const
00097 {
00098   return QValueList<QWidget *>();
00099 }
00100 
00101 
00102 KPrefsWidBool::KPrefsWidBool( KConfigSkeleton::ItemBool *item, QWidget *parent )
00103   : mItem( item )
00104 {
00105   mCheck = new QCheckBox( item->label(), parent);
00106   connect( mCheck, SIGNAL( clicked() ), SIGNAL( changed() ) );
00107   if ( !item->whatsThis().isNull() ) {
00108     QWhatsThis::add( mCheck, item->whatsThis() );
00109   }
00110 }
00111 
00112 void KPrefsWidBool::readConfig()
00113 {
00114   mCheck->setChecked( mItem->value() );
00115 }
00116 
00117 void KPrefsWidBool::writeConfig()
00118 {
00119   mItem->setValue( mCheck->isChecked() );
00120 }
00121 
00122 QCheckBox *KPrefsWidBool::checkBox()
00123 {
00124   return mCheck;
00125 }
00126 
00127 QValueList<QWidget *> KPrefsWidBool::widgets() const
00128 {
00129   QValueList<QWidget *> widgets;
00130   widgets.append( mCheck );
00131   return widgets;
00132 }
00133 
00134 
00135 KPrefsWidInt::KPrefsWidInt( KConfigSkeleton::ItemInt *item,
00136                             QWidget *parent )
00137   : mItem( item )
00138 {
00139   mLabel = new QLabel( mItem->label()+':', parent );
00140   mSpin = new QSpinBox( parent );
00141   if ( !item->minValue().isNull() ) {
00142     mSpin->setMinValue( item->minValue().toInt() );
00143   }
00144   if ( !item->maxValue().isNull() ) {
00145     mSpin->setMaxValue( item->maxValue().toInt() );
00146   }
00147   connect( mSpin, SIGNAL( valueChanged( int ) ), SIGNAL( changed() ) );
00148   mLabel->setBuddy( mSpin );
00149   QString whatsThis = mItem->whatsThis();
00150   if ( !whatsThis.isEmpty() ) {
00151     QWhatsThis::add( mLabel, whatsThis );
00152     QWhatsThis::add( mSpin, whatsThis );
00153   }
00154 }
00155 
00156 void KPrefsWidInt::readConfig()
00157 {
00158   mSpin->setValue( mItem->value() );
00159 }
00160 
00161 void KPrefsWidInt::writeConfig()
00162 {
00163   mItem->setValue( mSpin->value() );
00164 }
00165 
00166 QLabel *KPrefsWidInt::label()
00167 {
00168   return mLabel;
00169 }
00170 
00171 QSpinBox *KPrefsWidInt::spinBox()
00172 {
00173   return mSpin;
00174 }
00175 
00176 QValueList<QWidget *> KPrefsWidInt::widgets() const
00177 {
00178   QValueList<QWidget *> widgets;
00179   widgets.append( mLabel );
00180   widgets.append( mSpin );
00181   return widgets;
00182 }
00183 
00184 
00185 KPrefsWidColor::KPrefsWidColor( KConfigSkeleton::ItemColor *item,
00186                                 QWidget *parent )
00187   : mItem( item )
00188 {
00189   mButton = new KColorButton( parent );
00190   connect( mButton, SIGNAL( changed( const QColor & ) ), SIGNAL( changed() ) );
00191   mLabel = new QLabel( mButton, mItem->label()+':', parent );
00192   mLabel->setBuddy( mButton );
00193   QString whatsThis = mItem->whatsThis();
00194   if (!whatsThis.isNull()) {
00195     QWhatsThis::add(mButton, whatsThis);
00196   }
00197 }
00198 
00199 KPrefsWidColor::~KPrefsWidColor()
00200 {
00201 //  kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
00202 }
00203 
00204 void KPrefsWidColor::readConfig()
00205 {
00206   mButton->setColor( mItem->value() );
00207 }
00208 
00209 void KPrefsWidColor::writeConfig()
00210 {
00211   mItem->setValue( mButton->color() );
00212 }
00213 
00214 QLabel *KPrefsWidColor::label()
00215 {
00216   return mLabel;
00217 }
00218 
00219 KColorButton *KPrefsWidColor::button()
00220 {
00221   return mButton;
00222 }
00223 
00224 
00225 KPrefsWidFont::KPrefsWidFont( KConfigSkeleton::ItemFont *item,
00226                               QWidget *parent, const QString &sampleText )
00227   : mItem( item )
00228 {
00229   mLabel = new QLabel( mItem->label()+':', parent );
00230 
00231   mPreview = new QLabel( sampleText, parent );
00232   mPreview->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00233 
00234   mButton = new QPushButton( i18n("Choose..."), parent );
00235   connect( mButton, SIGNAL( clicked() ), SLOT( selectFont() ) );
00236   QString whatsThis = mItem->whatsThis();
00237   if (!whatsThis.isNull()) {
00238     QWhatsThis::add(mPreview, whatsThis);
00239     QWhatsThis::add(mButton, whatsThis);
00240   }
00241 }
00242 
00243 KPrefsWidFont::~KPrefsWidFont()
00244 {
00245 }
00246 
00247 void KPrefsWidFont::readConfig()
00248 {
00249   mPreview->setFont( mItem->value() );
00250 }
00251 
00252 void KPrefsWidFont::writeConfig()
00253 {
00254   mItem->setValue( mPreview->font() );
00255 }
00256 
00257 QLabel *KPrefsWidFont::label()
00258 {
00259   return mLabel;
00260 }
00261 
00262 QFrame *KPrefsWidFont::preview()
00263 {
00264   return mPreview;
00265 }
00266 
00267 QPushButton *KPrefsWidFont::button()
00268 {
00269   return mButton;
00270 }
00271 
00272 void KPrefsWidFont::selectFont()
00273 {
00274   QFont myFont(mPreview->font());
00275   int result = KFontDialog::getFont(myFont);
00276   if (result == KFontDialog::Accepted) {
00277     mPreview->setFont(myFont);
00278     emit changed();
00279   }
00280 }
00281 
00282 
00283 KPrefsWidTime::KPrefsWidTime( KConfigSkeleton::ItemDateTime *item,
00284                               QWidget *parent )
00285   : mItem( item )
00286 {
00287   mLabel = new QLabel( mItem->label()+':', parent );
00288   mTimeEdit = new KTimeEdit( parent );
00289   mLabel->setBuddy( mTimeEdit );
00290   connect( mTimeEdit, SIGNAL( timeChanged( QTime ) ), SIGNAL( changed() ) );
00291   QString whatsThis = mItem->whatsThis();
00292   if ( !whatsThis.isNull() ) {
00293     QWhatsThis::add( mTimeEdit, whatsThis );
00294   }
00295 }
00296 
00297 void KPrefsWidTime::readConfig()
00298 {
00299   mTimeEdit->setTime( mItem->value().time() );
00300 }
00301 
00302 void KPrefsWidTime::writeConfig()
00303 {
00304   // Don't overwrite the date value of the QDateTime, so we can use a
00305   // KPrefsWidTime and a KPrefsWidDate on the same config entry!
00306   QDateTime dt( mItem->value() );
00307   dt.setTime( mTimeEdit->getTime() );
00308   mItem->setValue( dt );
00309 }
00310 
00311 QLabel *KPrefsWidTime::label()
00312 {
00313   return mLabel;
00314 }
00315 
00316 KTimeEdit *KPrefsWidTime::timeEdit()
00317 {
00318   return mTimeEdit;
00319 }
00320 
00321 
00322 KPrefsWidDuration::KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item,
00323                                       QWidget *parent )
00324   : mItem( item )
00325 {
00326   mLabel = new QLabel( mItem->label()+':', parent );
00327   mTimeEdit = new QTimeEdit( parent );
00328   mLabel->setBuddy( mTimeEdit );
00329   mTimeEdit->setAutoAdvance( true );
00330   mTimeEdit->setDisplay( QTimeEdit::Hours | QTimeEdit::Minutes );
00331   mTimeEdit->setRange( QTime( 0, 1 ), QTime( 24, 0 ) ); // [1min, 24hr]
00332   connect( mTimeEdit,
00333            SIGNAL( valueChanged( const QTime & ) ), SIGNAL( changed() ) );
00334   QString whatsThis = mItem->whatsThis();
00335   if ( !whatsThis.isNull() ) {
00336     QWhatsThis::add( mTimeEdit, whatsThis );
00337   }
00338 }
00339 
00340 void KPrefsWidDuration::readConfig()
00341 {
00342   mTimeEdit->setTime( mItem->value().time() );
00343 }
00344 
00345 void KPrefsWidDuration::writeConfig()
00346 {
00347   QDateTime dt( mItem->value() );
00348   dt.setTime( mTimeEdit->time() );
00349   mItem->setValue( dt );
00350 }
00351 
00352 QLabel *KPrefsWidDuration::label()
00353 {
00354   return mLabel;
00355 }
00356 
00357 QTimeEdit *KPrefsWidDuration::timeEdit()
00358 {
00359   return mTimeEdit;
00360 }
00361 
00362 
00363 KPrefsWidDate::KPrefsWidDate( KConfigSkeleton::ItemDateTime *item,
00364                               QWidget *parent )
00365   : mItem( item )
00366 {
00367   mLabel = new QLabel( mItem->label()+':', parent );
00368   mDateEdit = new KDateEdit( parent );
00369   mLabel->setBuddy( mDateEdit );
00370   connect( mDateEdit, SIGNAL( dateChanged( const QDate& ) ), SIGNAL( changed() ) );
00371   QString whatsThis = mItem->whatsThis();
00372   if ( !whatsThis.isNull() ) {
00373     QWhatsThis::add( mDateEdit, whatsThis );
00374   }
00375 }
00376 
00377 void KPrefsWidDate::readConfig()
00378 {
00379   mDateEdit->setDate( mItem->value().date() );
00380 }
00381 
00382 void KPrefsWidDate::writeConfig()
00383 {
00384   QDateTime dt( mItem->value() );
00385   dt.setDate( mDateEdit->date() );
00386   mItem->setValue( dt );
00387 }
00388 
00389 QLabel *KPrefsWidDate::label()
00390 {
00391   return mLabel;
00392 }
00393 
00394 KDateEdit *KPrefsWidDate::dateEdit()
00395 {
00396   return mDateEdit;
00397 }
00398 
00399 
00400 KPrefsWidRadios::KPrefsWidRadios( KConfigSkeleton::ItemEnum *item,
00401                                   QWidget *parent )
00402   : mItem( item )
00403 {
00404   mBox = new QButtonGroup( 1, Qt::Horizontal, mItem->label(), parent );
00405   connect( mBox, SIGNAL( clicked( int ) ), SIGNAL( changed() ) );
00406 }
00407 
00408 KPrefsWidRadios::~KPrefsWidRadios()
00409 {
00410 }
00411 
00412 void KPrefsWidRadios::addRadio(const QString &text, const QString &whatsThis)
00413 {
00414   QRadioButton *r = new QRadioButton(text,mBox);
00415   if (!whatsThis.isNull()) {
00416     QWhatsThis::add(r, whatsThis);
00417   }
00418 }
00419 
00420 QButtonGroup *KPrefsWidRadios::groupBox()
00421 {
00422   return mBox;
00423 }
00424 
00425 void KPrefsWidRadios::readConfig()
00426 {
00427   mBox->setButton( mItem->value() );
00428 }
00429 
00430 void KPrefsWidRadios::writeConfig()
00431 {
00432   mItem->setValue( mBox->id( mBox->selected() ) );
00433 }
00434 
00435 QValueList<QWidget *> KPrefsWidRadios::widgets() const
00436 {
00437   QValueList<QWidget *> w;
00438   w.append( mBox );
00439   return w;
00440 }
00441 
00442 
00443 KPrefsWidString::KPrefsWidString( KConfigSkeleton::ItemString *item,
00444                                   QWidget *parent,
00445                                   QLineEdit::EchoMode echomode )
00446   : mItem( item )
00447 {
00448   mLabel = new QLabel( mItem->label()+':', parent );
00449   mEdit = new QLineEdit( parent );
00450   mLabel->setBuddy( mEdit );
00451   connect( mEdit, SIGNAL( textChanged( const QString & ) ),
00452            SIGNAL( changed() ) );
00453   mEdit->setEchoMode( echomode );
00454   QString whatsThis = mItem->whatsThis();
00455   if ( !whatsThis.isNull() ) {
00456     QWhatsThis::add( mEdit, whatsThis );
00457   }
00458 }
00459 
00460 KPrefsWidString::~KPrefsWidString()
00461 {
00462 }
00463 
00464 void KPrefsWidString::readConfig()
00465 {
00466   mEdit->setText( mItem->value() );
00467 }
00468 
00469 void KPrefsWidString::writeConfig()
00470 {
00471   mItem->setValue( mEdit->text() );
00472 }
00473 
00474 QLabel *KPrefsWidString::label()
00475 {
00476   return mLabel;
00477 }
00478 
00479 QLineEdit *KPrefsWidString::lineEdit()
00480 {
00481   return mEdit;
00482 }
00483 
00484 QValueList<QWidget *> KPrefsWidString::widgets() const
00485 {
00486   QValueList<QWidget *> widgets;
00487   widgets.append( mLabel );
00488   widgets.append( mEdit );
00489   return widgets;
00490 }
00491 
00492 
00493 KPrefsWidPath::KPrefsWidPath( KConfigSkeleton::ItemPath *item, QWidget *parent,
00494                               const QString &filter, uint mode )
00495   : mItem( item )
00496 {
00497   mLabel = new QLabel( mItem->label()+':', parent );
00498   mURLRequester = new KURLRequester( parent );
00499   mLabel->setBuddy( mURLRequester );
00500   mURLRequester->setMode( mode );
00501   mURLRequester->setFilter( filter );
00502   connect( mURLRequester, SIGNAL( textChanged( const QString & ) ),
00503            SIGNAL( changed() ) );
00504   QString whatsThis = mItem->whatsThis();
00505   if ( !whatsThis.isNull() ) {
00506     QWhatsThis::add( mURLRequester, whatsThis );
00507   }
00508 }
00509 
00510 KPrefsWidPath::~KPrefsWidPath()
00511 {
00512 }
00513 
00514 void KPrefsWidPath::readConfig()
00515 {
00516   mURLRequester->setURL( mItem->value() );
00517 }
00518 
00519 void KPrefsWidPath::writeConfig()
00520 {
00521   mItem->setValue( mURLRequester->url() );
00522 }
00523 
00524 QLabel *KPrefsWidPath::label()
00525 {
00526   return mLabel;
00527 }
00528 
00529 KURLRequester *KPrefsWidPath::urlRequester()
00530 {
00531   return mURLRequester;
00532 }
00533 
00534 QValueList<QWidget *> KPrefsWidPath::widgets() const
00535 {
00536   QValueList<QWidget *> widgets;
00537   widgets.append( mLabel );
00538   widgets.append( mURLRequester );
00539   return widgets;
00540 }
00541 
00542 
00543 KPrefsWidManager::KPrefsWidManager( KConfigSkeleton *prefs )
00544   : mPrefs( prefs )
00545 {
00546 }
00547 
00548 KPrefsWidManager::~KPrefsWidManager()
00549 {
00550 }
00551 
00552 void KPrefsWidManager::addWid( KPrefsWid *wid )
00553 {
00554   mPrefsWids.append( wid );
00555 }
00556 
00557 KPrefsWidBool *KPrefsWidManager::addWidBool( KConfigSkeleton::ItemBool *item,
00558                                              QWidget *parent )
00559 {
00560   KPrefsWidBool *w = new KPrefsWidBool( item, parent );
00561   addWid( w );
00562   return w;
00563 }
00564 
00565 KPrefsWidTime *KPrefsWidManager::addWidTime( KConfigSkeleton::ItemDateTime *item,
00566                                              QWidget *parent )
00567 {
00568   KPrefsWidTime *w = new KPrefsWidTime( item, parent );
00569   addWid( w );
00570   return w;
00571 }
00572 
00573 KPrefsWidDuration *KPrefsWidManager::addWidDuration( KConfigSkeleton::ItemDateTime *item,
00574                                                      QWidget *parent )
00575 {
00576   KPrefsWidDuration *w = new KPrefsWidDuration( item, parent );
00577   addWid( w );
00578   return w;
00579 }
00580 
00581 KPrefsWidDate *KPrefsWidManager::addWidDate( KConfigSkeleton::ItemDateTime *item,
00582                                              QWidget *parent )
00583 {
00584   KPrefsWidDate *w = new KPrefsWidDate( item, parent );
00585   addWid( w );
00586   return w;
00587 }
00588 
00589 KPrefsWidColor *KPrefsWidManager::addWidColor( KConfigSkeleton::ItemColor *item,
00590                                                QWidget *parent )
00591 {
00592   KPrefsWidColor *w = new KPrefsWidColor( item, parent );
00593   addWid( w );
00594   return w;
00595 }
00596 
00597 KPrefsWidRadios *KPrefsWidManager::addWidRadios( KConfigSkeleton::ItemEnum *item,
00598                                                  QWidget *parent )
00599 {
00600   KPrefsWidRadios *w = new KPrefsWidRadios( item, parent );
00601   QValueList<KConfigSkeleton::ItemEnum::Choice> choices;
00602   choices = item->choices();
00603   QValueList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
00604   for( it = choices.begin(); it != choices.end(); ++it ) {
00605     w->addRadio( (*it).label, (*it).whatsThis );
00606   }
00607   addWid( w );
00608   return w;
00609 }
00610 
00611 KPrefsWidString *KPrefsWidManager::addWidString( KConfigSkeleton::ItemString *item,
00612                                                  QWidget *parent )
00613 {
00614   KPrefsWidString *w = new KPrefsWidString( item, parent,
00615                                             QLineEdit::Normal );
00616   addWid( w );
00617   return w;
00618 }
00619 
00620 KPrefsWidPath *KPrefsWidManager::addWidPath( KConfigSkeleton::ItemPath *item,
00621                                              QWidget *parent, const QString &filter, uint mode )
00622 {
00623   KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode );
00624   addWid( w );
00625   return w;
00626 }
00627 
00628 KPrefsWidString *KPrefsWidManager::addWidPassword( KConfigSkeleton::ItemString *item,
00629                                                    QWidget *parent )
00630 {
00631   KPrefsWidString *w = new KPrefsWidString( item, parent, QLineEdit::Password );
00632   addWid( w );
00633   return w;
00634 }
00635 
00636 KPrefsWidFont *KPrefsWidManager::addWidFont( KConfigSkeleton::ItemFont *item,
00637                                              QWidget *parent,
00638                                              const QString &sampleText )
00639 {
00640   KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText );
00641   addWid( w );
00642   return w;
00643 }
00644 
00645 KPrefsWidInt *KPrefsWidManager::addWidInt( KConfigSkeleton::ItemInt *item,
00646                                            QWidget *parent )
00647 {
00648   KPrefsWidInt *w = new KPrefsWidInt( item, parent );
00649   addWid( w );
00650   return w;
00651 }
00652 
00653 void KPrefsWidManager::setWidDefaults()
00654 {
00655   kdDebug() << "KPrefsWidManager::setWidDefaults()" << endl;
00656 
00657   bool tmp = mPrefs->useDefaults( true );
00658 
00659   readWidConfig();
00660 
00661   mPrefs->useDefaults( tmp );
00662 }
00663 
00664 void KPrefsWidManager::readWidConfig()
00665 {
00666   kdDebug(5310) << "KPrefsWidManager::readWidConfig()" << endl;
00667 
00668   KPrefsWid *wid;
00669   for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
00670     wid->readConfig();
00671   }
00672 }
00673 
00674 void KPrefsWidManager::writeWidConfig()
00675 {
00676   kdDebug(5310) << "KPrefsWidManager::writeWidConfig()" << endl;
00677 
00678   KPrefsWid *wid;
00679   for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
00680     wid->writeConfig();
00681   }
00682 
00683   mPrefs->writeConfig();
00684 }
00685 
00686 
00687 KPrefsDialog::KPrefsDialog( KConfigSkeleton *prefs, QWidget *parent, char *name,
00688                             bool modal )
00689   : KDialogBase(IconList,i18n("Preferences"),Ok|Apply|Cancel|Default,Ok,parent,
00690                 name,modal,true),
00691     KPrefsWidManager( prefs )
00692 {
00693 // TODO: This seems to cause a crash on exit. Investigate later.
00694 //  mPrefsWids.setAutoDelete(true);
00695 
00696 //  connect(this,SIGNAL(defaultClicked()),SLOT(setDefaults()));
00697   connect(this,SIGNAL(cancelClicked()),SLOT(reject()));
00698 }
00699 
00700 KPrefsDialog::~KPrefsDialog()
00701 {
00702 }
00703 
00704 void KPrefsDialog::autoCreate()
00705 {
00706   KConfigSkeletonItem::List items = prefs()->items();
00707 
00708   QMap<QString,QWidget *> mGroupPages;
00709   QMap<QString,QGridLayout *> mGroupLayouts;
00710   QMap<QString,int> mCurrentRows;
00711 
00712   KConfigSkeletonItem::List::ConstIterator it;
00713   for( it = items.begin(); it != items.end(); ++it ) {
00714     QString group = (*it)->group();
00715     QString name = (*it)->name();
00716 
00717     kdDebug() << "ITEMS: " << (*it)->name() << endl;
00718 
00719     QWidget *page;
00720     QGridLayout *layout;
00721     int currentRow;
00722     if ( !mGroupPages.contains( group ) ) {
00723       page = addPage( group );
00724       layout = new QGridLayout( page );
00725       mGroupPages.insert( group, page );
00726       mGroupLayouts.insert( group, layout );
00727       currentRow = 0;
00728       mCurrentRows.insert( group, currentRow );
00729     } else {
00730       page = mGroupPages[ group ];
00731       layout = mGroupLayouts[ group ];
00732       currentRow = mCurrentRows[ group ];
00733     }
00734 
00735     KPrefsWid *wid = KPrefsWidFactory::create( *it, page );
00736 
00737     if ( wid ) {
00738       QValueList<QWidget *> widgets = wid->widgets();
00739       if ( widgets.count() == 1 ) {
00740         layout->addMultiCellWidget( widgets[ 0 ],
00741                                     currentRow, currentRow, 0, 1 );
00742       } else if ( widgets.count() == 2 ) {
00743         layout->addWidget( widgets[ 0 ], currentRow, 0 );
00744         layout->addWidget( widgets[ 1 ], currentRow, 1 );
00745       } else {
00746         kdError() << "More widgets than expected: " << widgets.count() << endl;
00747       }
00748 
00749       if ( (*it)->isImmutable() ) {
00750         QValueList<QWidget *>::Iterator it2;
00751         for( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) {
00752           (*it2)->setEnabled( false );
00753         }
00754       }
00755 
00756       addWid( wid );
00757 
00758       mCurrentRows.replace( group, ++currentRow );
00759     }
00760   }
00761 
00762   readConfig();
00763 }
00764 
00765 void KPrefsDialog::setDefaults()
00766 {
00767   setWidDefaults();
00768 }
00769 
00770 void KPrefsDialog::readConfig()
00771 {
00772   readWidConfig();
00773 
00774   usrReadConfig();
00775 }
00776 
00777 void KPrefsDialog::writeConfig()
00778 {
00779   writeWidConfig();
00780 
00781   usrWriteConfig();
00782 
00783   readConfig();
00784 }
00785 
00786 
00787 void KPrefsDialog::slotApply()
00788 {
00789   writeConfig();
00790   emit configChanged();
00791 }
00792 
00793 void KPrefsDialog::slotOk()
00794 {
00795   slotApply();
00796   accept();
00797 }
00798 
00799 void KPrefsDialog::slotDefault()
00800 {
00801   kdDebug() << "KPrefsDialog::slotDefault()" << endl;
00802 
00803   if (KMessageBox::warningContinueCancel(this,
00804       i18n("You are about to set all preferences to default values. All "
00805       "custom modifications will be lost."),i18n("Setting Default Preferences"),
00806       i18n("Reset to Defaults"))
00807     == KMessageBox::Continue) setDefaults();
00808 }
00809 
00810 
00811 KPrefsModule::KPrefsModule( KConfigSkeleton *prefs, QWidget *parent,
00812                             const char *name )
00813   : KCModule( parent, name ),
00814     KPrefsWidManager( prefs )
00815 {
00816   emit changed( false );
00817 }
00818 
00819 void KPrefsModule::addWid( KPrefsWid *wid )
00820 {
00821   KPrefsWidManager::addWid( wid );
00822 
00823   connect( wid, SIGNAL( changed() ), SLOT( slotWidChanged() ) );
00824 }
00825 
00826 void KPrefsModule::slotWidChanged()
00827 {
00828   kdDebug(5310) << "KPrefsModule::slotWidChanged()" << endl;
00829 
00830   emit changed( true );
00831 }
00832 
00833 void KPrefsModule::load()
00834 {
00835   kdDebug(5310) << "KPrefsModule::load()" << endl;
00836 
00837   readWidConfig();
00838 
00839   usrReadConfig();
00840 
00841   emit changed( false );
00842 }
00843 
00844 void KPrefsModule::save()
00845 {
00846   kdDebug(5310) << "KPrefsModule::save()" << endl;
00847 
00848   writeWidConfig();
00849 
00850   usrWriteConfig();
00851 }
00852 
00853 void KPrefsModule::defaults()
00854 {
00855   setWidDefaults();
00856 
00857   emit changed( true );
00858 }
KDE Home | KDE Accessibility Home | Description of Access Keys