one entry for korganizer in khelpcenters navigation tree is enough
[kdepim.git] / libkdepim / kprefsdialog.cpp
blobb3b64a12cee84a96a1779e499c8d9791863566fe
1 /*
2 This file is part of libkdepim.
4 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 Copyright (C) 2005,2008 Allen Winter <winter@kde.org>
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
23 //krazy:excludeall=tipsandthis
25 #include "kprefsdialog.h"
26 #include "ktimeedit.h"
27 #include "kdateedit.h"
29 #include <KColorButton>
30 #include <KComboBox>
31 #include <KConfigSkeleton>
32 #include <KDebug>
33 #include <KFontDialog>
34 #include <KLineEdit>
35 #include <KLocale>
36 #include <KMessageBox>
37 #include <KPageWidget>
38 #include <KUrlRequester>
40 #include <QFont>
41 #include <QFrame>
42 #include <QCheckBox>
43 #include <QGridLayout>
44 #include <QLabel>
45 #include <QLayout>
46 #include <QPushButton>
47 #include <QRadioButton>
48 #include <QSpinBox>
49 #include <QTimeEdit>
50 #include <QButtonGroup>
51 #include <QGroupBox>
52 #include <KHBox>
54 #include "kprefsdialog.moc"
56 using namespace KPIM;
58 namespace KPrefsWidFactory {
59 KPrefsWid *create( KConfigSkeletonItem *item, QWidget *parent )
61 KConfigSkeleton::ItemBool *boolItem =
62 dynamic_cast<KConfigSkeleton::ItemBool *>( item );
63 if ( boolItem ) {
64 return new KPrefsWidBool( boolItem, parent );
67 KConfigSkeleton::ItemString *stringItem =
68 dynamic_cast<KConfigSkeleton::ItemString *>( item );
69 if ( stringItem ) {
70 return new KPrefsWidString( stringItem, parent );
73 KConfigSkeleton::ItemEnum *enumItem =
74 dynamic_cast<KConfigSkeleton::ItemEnum *>( item );
75 if ( enumItem ) {
76 QList<KConfigSkeleton::ItemEnum::Choice> choices = enumItem->choices();
77 if ( choices.isEmpty() ) {
78 kError() << "Enum has no choices.";
79 return 0;
80 } else {
81 KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent );
82 QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
83 int value = 0;
84 for ( it = choices.constBegin(); it != choices.constEnd(); ++it ) {
85 radios->addRadio( value++, (*it).label );
87 return radios;
91 KConfigSkeleton::ItemInt *intItem = dynamic_cast<KConfigSkeleton::ItemInt *>( item );
92 if ( intItem ) {
93 return new KPrefsWidInt( intItem, parent );
96 return 0;
99 } // namespace KPrefsWidFactory
101 QList<QWidget *> KPrefsWid::widgets() const
103 return QList<QWidget *>();
106 KPrefsWidBool::KPrefsWidBool( KConfigSkeleton::ItemBool *item, QWidget *parent )
107 : mItem( item )
109 mCheck = new QCheckBox( mItem->label(), parent );
110 connect( mCheck, SIGNAL(clicked()), SIGNAL(changed()) );
111 QString toolTip = mItem->toolTip();
112 if ( !toolTip.isEmpty() ) {
113 mCheck->setToolTip( toolTip );
115 QString whatsThis = mItem->whatsThis();
116 if ( !whatsThis.isEmpty() ) {
117 mCheck->setWhatsThis( whatsThis );
121 void KPrefsWidBool::readConfig()
123 mCheck->setChecked( mItem->value() );
126 void KPrefsWidBool::writeConfig()
128 mItem->setValue( mCheck->isChecked() );
131 QCheckBox *KPrefsWidBool::checkBox()
133 return mCheck;
136 QList<QWidget *> KPrefsWidBool::widgets() const
138 QList<QWidget *> widgets;
139 widgets.append( mCheck );
140 return widgets;
143 KPrefsWidInt::KPrefsWidInt( KConfigSkeleton::ItemInt *item, QWidget *parent )
144 : mItem( item )
146 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
147 mSpin = new QSpinBox( parent );
148 if ( !mItem->minValue().isNull() ) {
149 mSpin->setMinimum( mItem->minValue().toInt() );
151 if ( !mItem->maxValue().isNull() ) {
152 mSpin->setMaximum( mItem->maxValue().toInt() );
154 connect( mSpin, SIGNAL(valueChanged(int)), SIGNAL(changed()) );
155 mLabel->setBuddy( mSpin );
156 QString toolTip = mItem->toolTip();
157 if ( !toolTip.isEmpty() ) {
158 mLabel->setToolTip( toolTip );
159 mSpin->setToolTip( toolTip );
161 QString whatsThis = mItem->whatsThis();
162 if ( !whatsThis.isEmpty() ) {
163 mLabel->setWhatsThis( whatsThis );
164 mSpin->setWhatsThis( whatsThis );
168 void KPrefsWidInt::readConfig()
170 mSpin->setValue( mItem->value() );
173 void KPrefsWidInt::writeConfig()
175 mItem->setValue( mSpin->value() );
178 QLabel *KPrefsWidInt::label()
180 return mLabel;
183 QSpinBox *KPrefsWidInt::spinBox()
185 return mSpin;
188 QList<QWidget *> KPrefsWidInt::widgets() const
190 QList<QWidget *> widgets;
191 widgets.append( mLabel );
192 widgets.append( mSpin );
193 return widgets;
196 KPrefsWidColor::KPrefsWidColor( KConfigSkeleton::ItemColor *item, QWidget *parent )
197 : mItem( item )
199 mButton = new KColorButton( parent );
200 connect( mButton, SIGNAL(changed(const QColor&)), SIGNAL(changed()) );
201 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
202 mLabel->setBuddy( mButton );
203 QString toolTip = mItem->toolTip();
204 if ( !toolTip.isEmpty() ) {
205 mButton->setToolTip( toolTip );
207 QString whatsThis = mItem->whatsThis();
208 if ( !whatsThis.isEmpty() ) {
209 mButton->setWhatsThis( whatsThis );
213 KPrefsWidColor::~KPrefsWidColor()
217 void KPrefsWidColor::readConfig()
219 mButton->setColor( mItem->value() );
222 void KPrefsWidColor::writeConfig()
224 mItem->setValue( mButton->color() );
227 QLabel *KPrefsWidColor::label()
229 return mLabel;
232 KColorButton *KPrefsWidColor::button()
234 return mButton;
237 KPrefsWidFont::KPrefsWidFont( KConfigSkeleton::ItemFont *item,
238 QWidget *parent, const QString &sampleText )
239 : mItem( item )
241 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
243 mPreview = new QLabel( sampleText, parent );
244 mPreview->setFrameStyle( QFrame::Panel | QFrame::Sunken );
246 mButton = new QPushButton( i18n( "Choose..." ), parent );
247 connect( mButton, SIGNAL(clicked()), SLOT(selectFont()) );
248 QString toolTip = mItem->toolTip();
249 if ( !toolTip.isEmpty() ) {
250 mPreview->setToolTip( toolTip );
251 mButton->setToolTip( toolTip );
253 QString whatsThis = mItem->whatsThis();
254 if ( !whatsThis.isEmpty() ) {
255 mPreview->setWhatsThis( whatsThis );
256 mButton->setWhatsThis( whatsThis );
260 KPrefsWidFont::~KPrefsWidFont()
264 void KPrefsWidFont::readConfig()
266 mPreview->setFont( mItem->value() );
269 void KPrefsWidFont::writeConfig()
271 mItem->setValue( mPreview->font() );
274 QLabel *KPrefsWidFont::label()
276 return mLabel;
279 QFrame *KPrefsWidFont::preview()
281 return mPreview;
284 QPushButton *KPrefsWidFont::button()
286 return mButton;
289 void KPrefsWidFont::selectFont()
291 #ifndef QT_NO_FONTDIALOG
292 QFont myFont( mPreview->font() );
293 int result = KFontDialog::getFont( myFont );
294 if ( result == KFontDialog::Accepted ) {
295 mPreview->setFont( myFont );
296 emit changed();
298 #endif
301 KPrefsWidTime::KPrefsWidTime( KConfigSkeleton::ItemDateTime *item, QWidget *parent )
302 : mItem( item )
304 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
305 mTimeEdit = new KTimeEdit( parent );
306 mLabel->setBuddy( mTimeEdit );
307 connect( mTimeEdit, SIGNAL(timeEdited(const QTime&)), SIGNAL(changed()) );
308 QString toolTip = mItem->toolTip();
309 if ( !toolTip.isEmpty() ) {
310 mTimeEdit->setToolTip( toolTip );
312 QString whatsThis = mItem->whatsThis();
313 if ( !whatsThis.isEmpty() ) {
314 mTimeEdit->setWhatsThis( whatsThis );
318 void KPrefsWidTime::readConfig()
320 mTimeEdit->setTime( mItem->value().time() );
323 void KPrefsWidTime::writeConfig()
325 // Don't overwrite the date value of the QDateTime, so we can use a
326 // KPrefsWidTime and a KPrefsWidDate on the same config entry!
327 QDateTime dt( mItem->value() );
328 dt.setTime( mTimeEdit->time() );
329 mItem->setValue( dt );
332 QLabel *KPrefsWidTime::label()
334 return mLabel;
337 KTimeEdit *KPrefsWidTime::timeEdit()
339 return mTimeEdit;
342 KPrefsWidDuration::KPrefsWidDuration( KConfigSkeleton::ItemDateTime *item,
343 const QString &format, QWidget *parent )
344 : mItem( item )
346 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
347 mTimeEdit = new QTimeEdit( parent );
348 mLabel->setBuddy( mTimeEdit );
349 if ( format.isEmpty() ) {
350 mTimeEdit->setDisplayFormat( QLatin1String( "hh:mm:ss" ) );
351 } else {
352 mTimeEdit->setDisplayFormat( format );
354 mTimeEdit->setMinimumTime( QTime( 0, 1 ) ); // [1 min]
355 mTimeEdit->setMaximumTime( QTime( 24, 0 ) ); // [24 hr]
356 connect( mTimeEdit, SIGNAL(timeEdited(const QTime&)), SIGNAL(changed()) );
357 QString toolTip = mItem->toolTip();
358 if ( !toolTip.isEmpty() ) {
359 mTimeEdit->setToolTip( toolTip );
361 QString whatsThis = mItem->whatsThis();
362 if ( !whatsThis.isEmpty() ) {
363 mTimeEdit->setWhatsThis( whatsThis );
367 void KPrefsWidDuration::readConfig()
369 mTimeEdit->setTime( mItem->value().time() );
372 void KPrefsWidDuration::writeConfig()
374 QDateTime dt( mItem->value() );
375 dt.setTime( mTimeEdit->time() );
376 mItem->setValue( dt );
379 QLabel *KPrefsWidDuration::label()
381 return mLabel;
384 QTimeEdit *KPrefsWidDuration::timeEdit()
386 return mTimeEdit;
389 KPrefsWidDate::KPrefsWidDate( KConfigSkeleton::ItemDateTime *item, QWidget *parent )
390 : mItem( item )
392 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
393 mDateEdit = new KDateEdit( parent );
394 mLabel->setBuddy( mDateEdit );
395 connect( mDateEdit, SIGNAL(dateEdited(const QDate&)), SIGNAL(changed()) );
396 QString toolTip = mItem->toolTip();
397 if ( !toolTip.isEmpty() ) {
398 mDateEdit->setToolTip( toolTip );
400 QString whatsThis = mItem->whatsThis();
401 if ( !whatsThis.isEmpty() ) {
402 mDateEdit->setWhatsThis( whatsThis );
406 void KPrefsWidDate::readConfig()
408 if ( !mItem->value().date().isValid() ) {
409 mItem->setValue( QDateTime::currentDateTime() );
411 mDateEdit->setDate( mItem->value().date().isValid() ?
412 mItem->value().date() : QDate::currentDate() );
415 void KPrefsWidDate::writeConfig()
417 QDateTime dt( mItem->value() );
418 dt.setDate( mDateEdit->date() );
419 mItem->setValue( dt );
420 if ( !mItem->value().date().isValid() ) {
421 mItem->setValue( QDateTime::currentDateTime() );
425 QLabel *KPrefsWidDate::label()
427 return mLabel;
430 KDateEdit *KPrefsWidDate::dateEdit()
432 return mDateEdit;
435 KPrefsWidRadios::KPrefsWidRadios( KConfigSkeleton::ItemEnum *item, QWidget *parent )
436 : mItem( item )
438 mBox = new QGroupBox( mItem->label(), parent );
439 new QVBoxLayout( mBox );
440 mGroup = new QButtonGroup( parent );
441 connect( mGroup, SIGNAL(buttonClicked(int)), SIGNAL(changed()) );
444 KPrefsWidRadios::~KPrefsWidRadios()
448 void KPrefsWidRadios::addRadio( int value, const QString &text, const QString &toolTip,
449 const QString &whatsThis )
451 QRadioButton *r = new QRadioButton( text, mBox );
452 mBox->layout()->addWidget( r );
453 mGroup->addButton( r, value );
454 if ( !toolTip.isEmpty() ) {
455 r->setToolTip( toolTip );
457 if ( !whatsThis.isEmpty() ) {
458 r->setWhatsThis( whatsThis );
462 QGroupBox *KPrefsWidRadios::groupBox() const
464 return mBox;
467 void KPrefsWidRadios::readConfig()
469 if ( !mGroup->button( mItem->value() ) )
470 return;
471 mGroup->button( mItem->value() )->setChecked( true );
474 void KPrefsWidRadios::writeConfig()
476 mItem->setValue( mGroup->checkedId() );
479 QList<QWidget *> KPrefsWidRadios::widgets() const
481 QList<QWidget *> w;
482 w.append( mBox );
483 return w;
486 KPrefsWidCombo::KPrefsWidCombo( KConfigSkeleton::ItemEnum *item, QWidget *parent )
487 : mItem( item )
489 KHBox *hbox = new KHBox( parent );
490 new QLabel( mItem->label(), hbox );
491 mCombo = new KComboBox( hbox );
492 connect( mCombo, SIGNAL(activated(int)), SIGNAL(changed()) );
495 KPrefsWidCombo::~KPrefsWidCombo()
499 void KPrefsWidCombo::readConfig()
501 mCombo->setCurrentIndex( mItem->value() );
504 void KPrefsWidCombo::writeConfig()
506 mItem->setValue( mCombo->currentIndex() );
509 QList<QWidget *> KPrefsWidCombo::widgets() const
511 QList<QWidget *> w;
512 w.append( mCombo );
513 return w;
516 KComboBox *KPrefsWidCombo::comboBox()
518 return mCombo;
521 KPrefsWidString::KPrefsWidString( KConfigSkeleton::ItemString *item, QWidget *parent,
522 KLineEdit::EchoMode echomode )
523 : mItem( item )
525 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
526 mEdit = new KLineEdit( parent );
527 mLabel->setBuddy( mEdit );
528 connect( mEdit, SIGNAL(textChanged(const QString&)), SIGNAL(changed()) );
529 mEdit->setEchoMode( echomode );
530 QString toolTip = mItem->toolTip();
531 if ( !toolTip.isEmpty() ) {
532 mEdit->setToolTip( toolTip );
534 QString whatsThis = mItem->whatsThis();
535 if ( !whatsThis.isEmpty() ) {
536 mEdit->setWhatsThis( whatsThis );
540 KPrefsWidString::~KPrefsWidString()
544 void KPrefsWidString::readConfig()
546 mEdit->setText( mItem->value() );
549 void KPrefsWidString::writeConfig()
551 mItem->setValue( mEdit->text() );
554 QLabel *KPrefsWidString::label()
556 return mLabel;
559 KLineEdit *KPrefsWidString::lineEdit()
561 return mEdit;
564 QList<QWidget *> KPrefsWidString::widgets() const
566 QList<QWidget *> widgets;
567 widgets.append( mLabel );
568 widgets.append( mEdit );
569 return widgets;
572 KPrefsWidPath::KPrefsWidPath( KConfigSkeleton::ItemPath *item, QWidget *parent,
573 const QString &filter, KFile::Modes mode )
574 : mItem( item )
576 mLabel = new QLabel( mItem->label() + QLatin1Char( ':' ), parent );
577 mURLRequester = new KUrlRequester( parent );
578 mLabel->setBuddy( mURLRequester );
579 mURLRequester->setMode( mode );
580 mURLRequester->setFilter( filter );
581 connect( mURLRequester, SIGNAL(textChanged(const QString&)), SIGNAL(changed()) );
582 QString toolTip = mItem->toolTip();
583 if ( !toolTip.isEmpty() ) {
584 mURLRequester->setToolTip( toolTip );
586 QString whatsThis = mItem->whatsThis();
587 if ( !whatsThis.isEmpty() ) {
588 mURLRequester->setWhatsThis( whatsThis );
592 KPrefsWidPath::~KPrefsWidPath()
596 void KPrefsWidPath::readConfig()
598 mURLRequester->setUrl( KUrl( mItem->value() ) );
601 void KPrefsWidPath::writeConfig()
603 mItem->setValue( mURLRequester->url().path() );
606 QLabel *KPrefsWidPath::label()
608 return mLabel;
611 KUrlRequester *KPrefsWidPath::urlRequester()
613 return mURLRequester;
616 QList<QWidget *> KPrefsWidPath::widgets() const
618 QList<QWidget *> widgets;
619 widgets.append( mLabel );
620 widgets.append( mURLRequester );
621 return widgets;
624 KPrefsWidManager::KPrefsWidManager( KConfigSkeleton *prefs )
625 : mPrefs( prefs )
629 KPrefsWidManager::~KPrefsWidManager()
631 qDeleteAll( mPrefsWids );
632 mPrefsWids.clear();
635 void KPrefsWidManager::addWid( KPrefsWid *wid )
637 mPrefsWids.append( wid );
640 KPrefsWidBool *KPrefsWidManager::addWidBool( KConfigSkeleton::ItemBool *item,
641 QWidget *parent )
643 KPrefsWidBool *w = new KPrefsWidBool( item, parent );
644 addWid( w );
645 return w;
648 KPrefsWidTime *KPrefsWidManager::addWidTime( KConfigSkeleton::ItemDateTime *item,
649 QWidget *parent )
651 KPrefsWidTime *w = new KPrefsWidTime( item, parent );
652 addWid( w );
653 return w;
656 KPrefsWidDuration *KPrefsWidManager::addWidDuration( KConfigSkeleton::ItemDateTime *item,
657 const QString &format,
658 QWidget *parent )
660 KPrefsWidDuration *w = new KPrefsWidDuration( item, format, parent );
661 addWid( w );
662 return w;
665 KPrefsWidDate *KPrefsWidManager::addWidDate( KConfigSkeleton::ItemDateTime *item,
666 QWidget *parent )
668 KPrefsWidDate *w = new KPrefsWidDate( item, parent );
669 addWid( w );
670 return w;
673 KPrefsWidColor *KPrefsWidManager::addWidColor( KConfigSkeleton::ItemColor *item,
674 QWidget *parent )
676 KPrefsWidColor *w = new KPrefsWidColor( item, parent );
677 addWid( w );
678 return w;
681 KPrefsWidRadios *KPrefsWidManager::addWidRadios( KConfigSkeleton::ItemEnum *item,
682 QWidget *parent )
684 KPrefsWidRadios *w = new KPrefsWidRadios( item, parent );
685 QList<KConfigSkeleton::ItemEnum::Choice2> choices;
686 choices = item->choices2();
687 QList<KConfigSkeleton::ItemEnum::Choice2>::ConstIterator it;
688 int value = 0;
689 for ( it = choices.constBegin(); it != choices.constEnd(); ++it ) {
690 w->addRadio( value++, (*it).label, (*it).toolTip, (*it).whatsThis );
692 addWid( w );
693 return w;
696 KPrefsWidCombo *KPrefsWidManager::addWidCombo( KConfigSkeleton::ItemEnum *item,
697 QWidget *parent )
699 KPrefsWidCombo *w = new KPrefsWidCombo( item, parent );
700 QList<KConfigSkeleton::ItemEnum::Choice> choices;
701 choices = item->choices();
702 QList<KConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
703 for ( it = choices.constBegin(); it != choices.constEnd(); ++it ) {
704 w->comboBox()->addItem( (*it).label );
706 addWid( w );
707 return w;
710 KPrefsWidString *KPrefsWidManager::addWidString( KConfigSkeleton::ItemString *item,
711 QWidget *parent )
713 KPrefsWidString *w = new KPrefsWidString( item, parent, KLineEdit::Normal );
714 addWid( w );
715 return w;
718 KPrefsWidPath *KPrefsWidManager::addWidPath( KConfigSkeleton::ItemPath *item,
719 QWidget *parent,
720 const QString &filter,
721 KFile::Modes mode )
723 KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode );
724 addWid( w );
725 return w;
728 KPrefsWidString *KPrefsWidManager::addWidPassword( KConfigSkeleton::ItemString *item,
729 QWidget *parent )
731 KPrefsWidString *w = new KPrefsWidString( item, parent, KLineEdit::Password );
732 addWid( w );
733 return w;
736 KPrefsWidFont *KPrefsWidManager::addWidFont( KConfigSkeleton::ItemFont *item,
737 QWidget *parent,
738 const QString &sampleText )
740 KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText );
741 addWid( w );
742 return w;
745 KPrefsWidInt *KPrefsWidManager::addWidInt( KConfigSkeleton::ItemInt *item,
746 QWidget *parent )
748 KPrefsWidInt *w = new KPrefsWidInt( item, parent );
749 addWid( w );
750 return w;
753 void KPrefsWidManager::setWidDefaults()
755 bool tmp = mPrefs->useDefaults( true );
756 readWidConfig();
757 mPrefs->useDefaults( tmp );
760 void KPrefsWidManager::readWidConfig()
762 QList<KPrefsWid*>::Iterator it;
763 for ( it = mPrefsWids.begin(); it != mPrefsWids.end(); ++it ) {
764 (*it)->readConfig();
768 void KPrefsWidManager::writeWidConfig()
770 QList<KPrefsWid*>::Iterator it;
771 for ( it = mPrefsWids.begin(); it != mPrefsWids.end(); ++it ) {
772 (*it)->writeConfig();
775 mPrefs->writeConfig();
778 KPrefsDialog::KPrefsDialog( KConfigSkeleton *prefs, QWidget *parent, bool modal )
779 : KPageDialog( parent ),
780 KPrefsWidManager( prefs )
782 setFaceType( List );
783 setCaption( i18n( "Preferences" ) );
784 setButtons( Ok|Apply|Cancel|Default );
785 setDefaultButton( Ok );
786 setModal( modal );
787 showButtonSeparator( true );
788 connect( this, SIGNAL(okClicked()), SLOT(slotOk()) );
789 connect( this, SIGNAL(applyClicked()), SLOT(slotApply()) );
790 connect( this, SIGNAL(defaultClicked()), SLOT(slotDefault()) );
791 connect( this, SIGNAL(cancelClicked()), SLOT(reject()) );
794 KPrefsDialog::~KPrefsDialog()
799 void KPrefsDialog::autoCreate()
801 KConfigSkeletonItem::List items = prefs()->items();
803 QMap<QString,QWidget *> mGroupPages;
804 QMap<QString,QGridLayout *> mGroupLayouts;
805 QMap<QString,int> mCurrentRows;
807 KConfigSkeletonItem::List::ConstIterator it;
808 for ( it = items.constBegin(); it != items.constEnd(); ++it ) {
809 QString group = (*it)->group();
810 QString name = (*it)->name();
812 QWidget *page;
813 QGridLayout *layout;
814 int currentRow;
815 if ( !mGroupPages.contains( group ) ) {
816 page = new QWidget( this );
817 addPage( page, group );
818 layout = new QGridLayout( page );
819 mGroupPages.insert( group, page );
820 mGroupLayouts.insert( group, layout );
821 currentRow = 0;
822 mCurrentRows.insert( group, currentRow );
823 } else {
824 page = mGroupPages[ group ];
825 layout = mGroupLayouts[ group ];
826 currentRow = mCurrentRows[ group ];
829 KPrefsWid *wid = KPrefsWidFactory::create( *it, page );
831 if ( wid ) {
832 QList<QWidget *> widgets = wid->widgets();
833 if ( widgets.count() == 1 ) {
834 layout->addWidget( widgets[ 0 ], currentRow, currentRow, 0, 1 );
835 } else if ( widgets.count() == 2 ) {
836 layout->addWidget( widgets[ 0 ], currentRow, 0 );
837 layout->addWidget( widgets[ 1 ], currentRow, 1 );
838 } else {
839 kError() <<"More widgets than expected:" << widgets.count();
842 if ( (*it)->isImmutable() ) {
843 QList<QWidget *>::Iterator it2;
844 for ( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) {
845 (*it2)->setEnabled( false );
848 addWid( wid );
849 mCurrentRows.insert( group, ++currentRow );
853 readConfig();
856 void KPrefsDialog::setDefaults()
858 setWidDefaults();
861 void KPrefsDialog::readConfig()
863 readWidConfig();
864 usrReadConfig();
867 void KPrefsDialog::writeConfig()
869 writeWidConfig();
870 usrWriteConfig();
871 readConfig();
874 void KPrefsDialog::slotApply()
876 writeConfig();
878 emit configChanged();
881 void KPrefsDialog::slotOk()
883 slotApply();
884 accept();
887 void KPrefsDialog::slotDefault()
889 if ( KMessageBox::warningContinueCancel(
890 this,
891 i18n( "You are about to set all preferences to default values. "
892 "All custom modifications will be lost." ),
893 i18n( "Setting Default Preferences" ),
894 KGuiItem( i18n( "Reset to Defaults" ) ) ) == KMessageBox::Continue ) {
895 setDefaults();
899 KPrefsModule::KPrefsModule( KConfigSkeleton *prefs, const KComponentData &instance,
900 QWidget *parent, const QVariantList &args )
901 : KCModule( instance, parent, args ),
902 KPrefsWidManager( prefs )
904 emit changed( false );
907 void KPrefsModule::addWid( KPrefsWid *wid )
909 KPrefsWidManager::addWid( wid );
910 connect( wid, SIGNAL(changed()), SLOT(slotWidChanged()) );
913 void KPrefsModule::slotWidChanged()
915 emit changed( true );
918 void KPrefsModule::load()
920 readWidConfig();
921 usrReadConfig();
923 emit changed( false );
926 void KPrefsModule::save()
928 writeWidConfig();
929 usrWriteConfig();
932 void KPrefsModule::defaults()
934 setWidDefaults();
936 emit changed( true );