libtdepim

kprefsdialog.cpp
1 /*
2  This file is part of libtdepim.
3 
4  Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6  Copyright (C) 2005 Allen Winter <winter@kde.org>
7 
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.
12 
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.
17 
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.
22 */
23 
24 #include <tqlayout.h>
25 #include <tqlabel.h>
26 #include <tqbuttongroup.h>
27 #include <tqlineedit.h>
28 #include <tqfont.h>
29 #include <tqspinbox.h>
30 #include <tqframe.h>
31 #include <tqcombobox.h>
32 #include <tqcheckbox.h>
33 #include <tqradiobutton.h>
34 #include <tqpushbutton.h>
35 #include <tqdatetimeedit.h>
36 #include <tqwhatsthis.h>
37 
38 #include <kcolorbutton.h>
39 #include <kdebug.h>
40 #include <tdelocale.h>
41 #include <tdefontdialog.h>
42 #include <tdemessagebox.h>
43 #include <tdeconfigskeleton.h>
44 #include <kurlrequester.h>
45 #include "ktimeedit.h"
46 #include "kdateedit.h"
47 
48 #include "kprefsdialog.h"
49 #include "kprefsdialog.moc"
50 
51 namespace KPrefsWidFactory {
52 
53 KPrefsWid *create( TDEConfigSkeletonItem *item, TQWidget *parent )
54 {
55  TDEConfigSkeleton::ItemBool *boolItem =
56  dynamic_cast<TDEConfigSkeleton::ItemBool *>( item );
57  if ( boolItem ) {
58  return new KPrefsWidBool( boolItem, parent );
59  }
60 
61  TDEConfigSkeleton::ItemString *stringItem =
62  dynamic_cast<TDEConfigSkeleton::ItemString *>( item );
63  if ( stringItem ) {
64  return new KPrefsWidString( stringItem, parent );
65  }
66 
67  TDEConfigSkeleton::ItemEnum *enumItem =
68  dynamic_cast<TDEConfigSkeleton::ItemEnum *>( item );
69  if ( enumItem ) {
70  TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices = enumItem->choices();
71  if ( choices.isEmpty() ) {
72  kdError() << "KPrefsWidFactory::create(): Enum has no choices." << endl;
73  return 0;
74  } else {
75  KPrefsWidRadios *radios = new KPrefsWidRadios( enumItem, parent );
76  TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
77  for( it = choices.begin(); it != choices.end(); ++it ) {
78  radios->addRadio( (*it).label );
79  }
80  return radios;
81  }
82  }
83 
84  TDEConfigSkeleton::ItemInt *intItem =
85  dynamic_cast<TDEConfigSkeleton::ItemInt *>( item );
86  if ( intItem ) {
87  return new KPrefsWidInt( intItem, parent );
88  }
89 
90  return 0;
91 }
92 
93 }
94 
95 
96 TQValueList<TQWidget *> KPrefsWid::widgets() const
97 {
98  return TQValueList<TQWidget *>();
99 }
100 
101 
102 KPrefsWidBool::KPrefsWidBool( TDEConfigSkeleton::ItemBool *item, TQWidget *parent )
103  : mItem( item )
104 {
105  mCheck = new TQCheckBox( item->label(), parent);
106  connect( mCheck, TQ_SIGNAL( clicked() ), TQ_SIGNAL( changed() ) );
107  if ( !item->whatsThis().isNull() ) {
108  TQWhatsThis::add( mCheck, item->whatsThis() );
109  }
110 }
111 
113 {
114  mCheck->setChecked( mItem->value() );
115 }
116 
118 {
119  mItem->setValue( mCheck->isChecked() );
120 }
121 
123 {
124  return mCheck;
125 }
126 
127 TQValueList<TQWidget *> KPrefsWidBool::widgets() const
128 {
129  TQValueList<TQWidget *> widgets;
130  widgets.append( mCheck );
131  return widgets;
132 }
133 
134 
135 KPrefsWidInt::KPrefsWidInt( TDEConfigSkeleton::ItemInt *item,
136  TQWidget *parent )
137  : mItem( item )
138 {
139  mLabel = new TQLabel( mItem->label()+':', parent );
140  mSpin = new TQSpinBox( parent );
141  if ( !item->minValue().isNull() ) {
142  mSpin->setMinValue( item->minValue().toInt() );
143  }
144  if ( !item->maxValue().isNull() ) {
145  mSpin->setMaxValue( item->maxValue().toInt() );
146  }
147  connect( mSpin, TQ_SIGNAL( valueChanged( int ) ), TQ_SIGNAL( changed() ) );
148  mLabel->setBuddy( mSpin );
149  TQString whatsThis = mItem->whatsThis();
150  if ( !whatsThis.isEmpty() ) {
151  TQWhatsThis::add( mLabel, whatsThis );
152  TQWhatsThis::add( mSpin, whatsThis );
153  }
154 }
155 
157 {
158  mSpin->setValue( mItem->value() );
159 }
160 
162 {
163  mItem->setValue( mSpin->value() );
164 }
165 
167 {
168  return mLabel;
169 }
170 
172 {
173  return mSpin;
174 }
175 
176 TQValueList<TQWidget *> KPrefsWidInt::widgets() const
177 {
178  TQValueList<TQWidget *> widgets;
179  widgets.append( mLabel );
180  widgets.append( mSpin );
181  return widgets;
182 }
183 
184 
185 KPrefsWidColor::KPrefsWidColor( TDEConfigSkeleton::ItemColor *item,
186  TQWidget *parent )
187  : mItem( item )
188 {
189  mButton = new KColorButton( parent );
190  connect( mButton, TQ_SIGNAL( changed( const TQColor & ) ), TQ_SIGNAL( changed() ) );
191  mLabel = new TQLabel( mButton, mItem->label()+':', parent );
192  mLabel->setBuddy( mButton );
193  TQString whatsThis = mItem->whatsThis();
194  if (!whatsThis.isNull()) {
195  TQWhatsThis::add(mButton, whatsThis);
196  }
197 }
198 
200 {
201 // kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
202 }
203 
205 {
206  mButton->setColor( mItem->value() );
207 }
208 
210 {
211  mItem->setValue( mButton->color() );
212 }
213 
215 {
216  return mLabel;
217 }
218 
219 KColorButton *KPrefsWidColor::button()
220 {
221  return mButton;
222 }
223 
224 
225 KPrefsWidFont::KPrefsWidFont( TDEConfigSkeleton::ItemFont *item,
226  TQWidget *parent, const TQString &sampleText )
227  : mItem( item )
228 {
229  mLabel = new TQLabel( mItem->label()+':', parent );
230 
231  mPreview = new TQLabel( sampleText, parent );
232  mPreview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
233 
234  mButton = new TQPushButton( i18n("Choose..."), parent );
235  connect( mButton, TQ_SIGNAL( clicked() ), TQ_SLOT( selectFont() ) );
236  TQString whatsThis = mItem->whatsThis();
237  if (!whatsThis.isNull()) {
238  TQWhatsThis::add(mPreview, whatsThis);
239  TQWhatsThis::add(mButton, whatsThis);
240  }
241 }
242 
244 {
245 }
246 
248 {
249  mPreview->setFont( mItem->value() );
250 }
251 
253 {
254  mItem->setValue( mPreview->font() );
255 }
256 
258 {
259  return mLabel;
260 }
261 
263 {
264  return mPreview;
265 }
266 
267 TQPushButton *KPrefsWidFont::button()
268 {
269  return mButton;
270 }
271 
272 void KPrefsWidFont::selectFont()
273 {
274  TQFont myFont(mPreview->font());
275  int result = TDEFontDialog::getFont(myFont);
276  if (result == TDEFontDialog::Accepted) {
277  mPreview->setFont(myFont);
278  emit changed();
279  }
280 }
281 
282 
283 KPrefsWidTime::KPrefsWidTime( TDEConfigSkeleton::ItemDateTime *item,
284  TQWidget *parent )
285  : mItem( item )
286 {
287  mLabel = new TQLabel( mItem->label()+':', parent );
288  mTimeEdit = new KTimeEdit( parent );
289  mLabel->setBuddy( mTimeEdit );
290  connect( mTimeEdit, TQ_SIGNAL( timeChanged( TQTime ) ), TQ_SIGNAL( changed() ) );
291  TQString whatsThis = mItem->whatsThis();
292  if ( !whatsThis.isNull() ) {
293  TQWhatsThis::add( mTimeEdit, whatsThis );
294  }
295 }
296 
298 {
299  mTimeEdit->setTime( mItem->value().time() );
300 }
301 
303 {
304  // Don't overwrite the date value of the TQDateTime, so we can use a
305  // KPrefsWidTime and a KPrefsWidDate on the same config entry!
306  TQDateTime dt( mItem->value() );
307  dt.setTime( mTimeEdit->getTime() );
308  mItem->setValue( dt );
309 }
310 
312 {
313  return mLabel;
314 }
315 
317 {
318  return mTimeEdit;
319 }
320 
321 
322 KPrefsWidDuration::KPrefsWidDuration( TDEConfigSkeleton::ItemDateTime *item,
323  TQWidget *parent )
324  : mItem( item )
325 {
326  mLabel = new TQLabel( mItem->label()+':', parent );
327  mTimeEdit = new TQTimeEdit( parent );
328  mLabel->setBuddy( mTimeEdit );
329  mTimeEdit->setAutoAdvance( true );
330  mTimeEdit->setDisplay( TQTimeEdit::Hours | TQTimeEdit::Minutes );
331  mTimeEdit->setRange( TQTime( 0, 1 ), TQTime( 24, 0 ) ); // [1min, 24hr]
332  connect( mTimeEdit,
333  TQ_SIGNAL( valueChanged( const TQTime & ) ), TQ_SIGNAL( changed() ) );
334  TQString whatsThis = mItem->whatsThis();
335  if ( !whatsThis.isNull() ) {
336  TQWhatsThis::add( mTimeEdit, whatsThis );
337  }
338 }
339 
341 {
342  mTimeEdit->setTime( mItem->value().time() );
343 }
344 
346 {
347  TQDateTime dt( mItem->value() );
348  dt.setTime( mTimeEdit->time() );
349  mItem->setValue( dt );
350 }
351 
353 {
354  return mLabel;
355 }
356 
358 {
359  return mTimeEdit;
360 }
361 
362 
363 KPrefsWidDate::KPrefsWidDate( TDEConfigSkeleton::ItemDateTime *item,
364  TQWidget *parent )
365  : mItem( item )
366 {
367  mLabel = new TQLabel( mItem->label()+':', parent );
368  mDateEdit = new KDateEdit( parent );
369  mLabel->setBuddy( mDateEdit );
370  connect( mDateEdit, TQ_SIGNAL( dateChanged( const TQDate& ) ), TQ_SIGNAL( changed() ) );
371  TQString whatsThis = mItem->whatsThis();
372  if ( !whatsThis.isNull() ) {
373  TQWhatsThis::add( mDateEdit, whatsThis );
374  }
375 }
376 
378 {
379  mDateEdit->setDate( mItem->value().date().isValid() ? mItem->value().date() : TQDate::currentDate() );
380 }
381 
383 {
384  TQDateTime dt( mItem->value() );
385  dt.setDate( mDateEdit->date() );
386  mItem->setValue( dt );
387 }
388 
390 {
391  return mLabel;
392 }
393 
395 {
396  return mDateEdit;
397 }
398 
399 
400 KPrefsWidRadios::KPrefsWidRadios( TDEConfigSkeleton::ItemEnum *item,
401  TQWidget *parent )
402  : mItem( item )
403 {
404  mBox = new TQButtonGroup( 1, TQt::Horizontal, mItem->label(), parent );
405  connect( mBox, TQ_SIGNAL( clicked( int ) ), TQ_SIGNAL( changed() ) );
406 }
407 
408 KPrefsWidRadios::~KPrefsWidRadios()
409 {
410 }
411 
412 void KPrefsWidRadios::addRadio(const TQString &text, const TQString &whatsThis)
413 {
414  TQRadioButton *r = new TQRadioButton(text,mBox);
415  if (!whatsThis.isNull()) {
416  TQWhatsThis::add(r, whatsThis);
417  }
418 }
419 
421 {
422  return mBox;
423 }
424 
426 {
427  mBox->setButton( mItem->value() );
428 }
429 
431 {
432  mItem->setValue( mBox->id( mBox->selected() ) );
433 }
434 
435 TQValueList<TQWidget *> KPrefsWidRadios::widgets() const
436 {
437  TQValueList<TQWidget *> w;
438  w.append( mBox );
439  return w;
440 }
441 
442 KPrefsWidCombo::KPrefsWidCombo( TDEConfigSkeleton::ItemEnum *item,
443  TQWidget *parent )
444  : mItem( item )
445 {
446  TQHBox *hbox = new TQHBox(parent);
447  new TQLabel( mItem->label(), hbox );
448  mCombo = new TQComboBox( hbox );
449  connect( mCombo, TQ_SIGNAL( activated( int ) ), TQ_SIGNAL( changed() ) );
450 }
451 
452 KPrefsWidCombo::~KPrefsWidCombo()
453 {
454 }
455 
457 {
458  mCombo->setCurrentItem( mItem->value() );
459 }
460 
462 {
463  mItem->setValue( mCombo->currentItem() );
464 }
465 
466 TQValueList<TQWidget *> KPrefsWidCombo::widgets() const
467 {
468  TQValueList<TQWidget *> w;
469  w.append( mCombo );
470  return w;
471 }
472 
473 TQComboBox* KPrefsWidCombo::comboBox()
474 {
475  return mCombo;
476 }
477 
478 KPrefsWidString::KPrefsWidString( TDEConfigSkeleton::ItemString *item,
479  TQWidget *parent,
480  TQLineEdit::EchoMode echomode )
481  : mItem( item )
482 {
483  mLabel = new TQLabel( mItem->label()+':', parent );
484  mEdit = new TQLineEdit( parent );
485  mLabel->setBuddy( mEdit );
486  connect( mEdit, TQ_SIGNAL( textChanged( const TQString & ) ),
487  TQ_SIGNAL( changed() ) );
488  mEdit->setEchoMode( echomode );
489  TQString whatsThis = mItem->whatsThis();
490  if ( !whatsThis.isNull() ) {
491  TQWhatsThis::add( mEdit, whatsThis );
492  }
493 }
494 
496 {
497 }
498 
500 {
501  mEdit->setText( mItem->value() );
502 }
503 
505 {
506  mItem->setValue( mEdit->text() );
507 }
508 
510 {
511  return mLabel;
512 }
513 
515 {
516  return mEdit;
517 }
518 
519 TQValueList<TQWidget *> KPrefsWidString::widgets() const
520 {
521  TQValueList<TQWidget *> widgets;
522  widgets.append( mLabel );
523  widgets.append( mEdit );
524  return widgets;
525 }
526 
527 
528 KPrefsWidPath::KPrefsWidPath( TDEConfigSkeleton::ItemPath *item, TQWidget *parent,
529  const TQString &filter, uint mode )
530  : mItem( item )
531 {
532  mLabel = new TQLabel( mItem->label()+':', parent );
533  mURLRequester = new KURLRequester( parent );
534  mLabel->setBuddy( mURLRequester );
535  mURLRequester->setMode( mode );
536  mURLRequester->setFilter( filter );
537  connect( mURLRequester, TQ_SIGNAL( textChanged( const TQString & ) ),
538  TQ_SIGNAL( changed() ) );
539  TQString whatsThis = mItem->whatsThis();
540  if ( !whatsThis.isNull() ) {
541  TQWhatsThis::add( mURLRequester, whatsThis );
542  }
543 }
544 
546 {
547 }
548 
550 {
551  mURLRequester->setURL( mItem->value() );
552 }
553 
555 {
556  mItem->setValue( mURLRequester->url() );
557 }
558 
560 {
561  return mLabel;
562 }
563 
565 {
566  return mURLRequester;
567 }
568 
569 TQValueList<TQWidget *> KPrefsWidPath::widgets() const
570 {
571  TQValueList<TQWidget *> widgets;
572  widgets.append( mLabel );
573  widgets.append( mURLRequester );
574  return widgets;
575 }
576 
577 
578 KPrefsWidManager::KPrefsWidManager( TDEConfigSkeleton *prefs )
579  : mPrefs( prefs )
580 {
581 }
582 
584 {
585 }
586 
588 {
589  mPrefsWids.append( wid );
590 }
591 
592 KPrefsWidBool *KPrefsWidManager::addWidBool( TDEConfigSkeleton::ItemBool *item,
593  TQWidget *parent )
594 {
595  KPrefsWidBool *w = new KPrefsWidBool( item, parent );
596  addWid( w );
597  return w;
598 }
599 
600 KPrefsWidTime *KPrefsWidManager::addWidTime( TDEConfigSkeleton::ItemDateTime *item,
601  TQWidget *parent )
602 {
603  KPrefsWidTime *w = new KPrefsWidTime( item, parent );
604  addWid( w );
605  return w;
606 }
607 
608 KPrefsWidDuration *KPrefsWidManager::addWidDuration( TDEConfigSkeleton::ItemDateTime *item,
609  TQWidget *parent )
610 {
611  KPrefsWidDuration *w = new KPrefsWidDuration( item, parent );
612  addWid( w );
613  return w;
614 }
615 
616 KPrefsWidDate *KPrefsWidManager::addWidDate( TDEConfigSkeleton::ItemDateTime *item,
617  TQWidget *parent )
618 {
619  KPrefsWidDate *w = new KPrefsWidDate( item, parent );
620  addWid( w );
621  return w;
622 }
623 
624 KPrefsWidColor *KPrefsWidManager::addWidColor( TDEConfigSkeleton::ItemColor *item,
625  TQWidget *parent )
626 {
627  KPrefsWidColor *w = new KPrefsWidColor( item, parent );
628  addWid( w );
629  return w;
630 }
631 
632 KPrefsWidRadios *KPrefsWidManager::addWidRadios( TDEConfigSkeleton::ItemEnum *item,
633  TQWidget *parent )
634 {
635  KPrefsWidRadios *w = new KPrefsWidRadios( item, parent );
636  TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices;
637  choices = item->choices();
638  TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
639  for( it = choices.begin(); it != choices.end(); ++it ) {
640  w->addRadio( (*it).label, (*it).whatsThis );
641  }
642  addWid( w );
643  return w;
644 }
645 
646 KPrefsWidCombo *KPrefsWidManager::addWidCombo( TDEConfigSkeleton::ItemEnum *item,
647  TQWidget* parent )
648 {
649  KPrefsWidCombo *w = new KPrefsWidCombo( item, parent );
650  TQValueList<TDEConfigSkeleton::ItemEnum::Choice> choices;
651  choices = item->choices();
652  TQValueList<TDEConfigSkeleton::ItemEnum::Choice>::ConstIterator it;
653  for( it = choices.begin(); it != choices.end(); ++it ) {
654  w->comboBox()->insertItem( (*it).label, -1 );
655  }
656  addWid( w );
657  return w;
658 }
659 
660 KPrefsWidString *KPrefsWidManager::addWidString( TDEConfigSkeleton::ItemString *item,
661  TQWidget *parent )
662 {
663  KPrefsWidString *w = new KPrefsWidString( item, parent,
664  TQLineEdit::Normal );
665  addWid( w );
666  return w;
667 }
668 
669 KPrefsWidPath *KPrefsWidManager::addWidPath( TDEConfigSkeleton::ItemPath *item,
670  TQWidget *parent, const TQString &filter, uint mode )
671 {
672  KPrefsWidPath *w = new KPrefsWidPath( item, parent, filter, mode );
673  addWid( w );
674  return w;
675 }
676 
677 KPrefsWidString *KPrefsWidManager::addWidPassword( TDEConfigSkeleton::ItemString *item,
678  TQWidget *parent )
679 {
680  KPrefsWidString *w = new KPrefsWidString( item, parent, TQLineEdit::Password );
681  addWid( w );
682  return w;
683 }
684 
685 KPrefsWidFont *KPrefsWidManager::addWidFont( TDEConfigSkeleton::ItemFont *item,
686  TQWidget *parent,
687  const TQString &sampleText )
688 {
689  KPrefsWidFont *w = new KPrefsWidFont( item, parent, sampleText );
690  addWid( w );
691  return w;
692 }
693 
694 KPrefsWidInt *KPrefsWidManager::addWidInt( TDEConfigSkeleton::ItemInt *item,
695  TQWidget *parent )
696 {
697  KPrefsWidInt *w = new KPrefsWidInt( item, parent );
698  addWid( w );
699  return w;
700 }
701 
703 {
704  kdDebug() << "KPrefsWidManager::setWidDefaults()" << endl;
705 
706  bool tmp = mPrefs->useDefaults( true );
707 
708  readWidConfig();
709 
710  mPrefs->useDefaults( tmp );
711 }
712 
714 {
715  kdDebug(5310) << "KPrefsWidManager::readWidConfig()" << endl;
716 
717  KPrefsWid *wid;
718  for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
719  wid->readConfig();
720  }
721 }
722 
724 {
725  kdDebug(5310) << "KPrefsWidManager::writeWidConfig()" << endl;
726 
727  KPrefsWid *wid;
728  for( wid = mPrefsWids.first(); wid; wid = mPrefsWids.next() ) {
729  wid->writeConfig();
730  }
731 
732  mPrefs->writeConfig();
733 }
734 
735 
736 KPrefsDialog::KPrefsDialog( TDEConfigSkeleton *prefs, TQWidget *parent, char *name,
737  bool modal )
738  : KDialogBase(IconList,i18n("Preferences"),Ok|Apply|Cancel|Default,Ok,parent,
739  name,modal,true),
740  KPrefsWidManager( prefs )
741 {
742 // TODO: This seems to cause a crash on exit. Investigate later.
743 // mPrefsWids.setAutoDelete(true);
744 
745 // connect(this,TQ_SIGNAL(defaultClicked()),TQ_SLOT(setDefaults()));
746  connect(this,TQ_SIGNAL(cancelClicked()),TQ_SLOT(reject()));
747 }
748 
750 {
751 }
752 
753 void KPrefsDialog::autoCreate()
754 {
755  TDEConfigSkeletonItem::List items = prefs()->items();
756 
757  TQMap<TQString,TQWidget *> mGroupPages;
758  TQMap<TQString,TQGridLayout *> mGroupLayouts;
759  TQMap<TQString,int> mCurrentRows;
760 
761  TDEConfigSkeletonItem::List::ConstIterator it;
762  for( it = items.begin(); it != items.end(); ++it ) {
763  TQString group = (*it)->group();
764  TQString name = (*it)->name();
765 
766  kdDebug() << "ITEMS: " << (*it)->name() << endl;
767 
768  TQWidget *page;
769  TQGridLayout *layout;
770  int currentRow;
771  if ( !mGroupPages.contains( group ) ) {
772  page = addPage( group );
773  layout = new TQGridLayout( page );
774  mGroupPages.insert( group, page );
775  mGroupLayouts.insert( group, layout );
776  currentRow = 0;
777  mCurrentRows.insert( group, currentRow );
778  } else {
779  page = mGroupPages[ group ];
780  layout = mGroupLayouts[ group ];
781  currentRow = mCurrentRows[ group ];
782  }
783 
784  KPrefsWid *wid = KPrefsWidFactory::create( *it, page );
785 
786  if ( wid ) {
787  TQValueList<TQWidget *> widgets = wid->widgets();
788  if ( widgets.count() == 1 ) {
789  layout->addMultiCellWidget( widgets[ 0 ],
790  currentRow, currentRow, 0, 1 );
791  } else if ( widgets.count() == 2 ) {
792  layout->addWidget( widgets[ 0 ], currentRow, 0 );
793  layout->addWidget( widgets[ 1 ], currentRow, 1 );
794  } else {
795  kdError() << "More widgets than expected: " << widgets.count() << endl;
796  }
797 
798  if ( (*it)->isImmutable() ) {
799  TQValueList<TQWidget *>::Iterator it2;
800  for( it2 = widgets.begin(); it2 != widgets.end(); ++it2 ) {
801  (*it2)->setEnabled( false );
802  }
803  }
804 
805  addWid( wid );
806 
807  mCurrentRows.replace( group, ++currentRow );
808  }
809  }
810 
811  readConfig();
812 }
813 
815 {
816  setWidDefaults();
817 }
818 
820 {
821  readWidConfig();
822 
823  usrReadConfig();
824 }
825 
827 {
828  writeWidConfig();
829 
830  usrWriteConfig();
831 
832  readConfig();
833 }
834 
835 
837 {
838  writeConfig();
839  emit configChanged();
840 }
841 
843 {
844  slotApply();
845  accept();
846 }
847 
849 {
850  kdDebug() << "KPrefsDialog::slotDefault()" << endl;
851 
852  if (KMessageBox::warningContinueCancel(this,
853  i18n("You are about to set all preferences to default values. All "
854  "custom modifications will be lost."),i18n("Setting Default Preferences"),
855  i18n("Reset to Defaults"))
856  == KMessageBox::Continue) setDefaults();
857 }
858 
859 
860 KPrefsModule::KPrefsModule( TDEConfigSkeleton *prefs, TQWidget *parent,
861  const char *name )
862  : TDECModule( parent, name ),
863  KPrefsWidManager( prefs )
864 {
865  emit changed( false );
866 }
867 
868 void KPrefsModule::addWid( KPrefsWid *wid )
869 {
871 
872  connect( wid, TQ_SIGNAL( changed() ), TQ_SLOT( slotWidChanged() ) );
873 }
874 
875 void KPrefsModule::slotWidChanged()
876 {
877  kdDebug(5310) << "KPrefsModule::slotWidChanged()" << endl;
878 
879  emit changed( true );
880 }
881 
882 void KPrefsModule::load()
883 {
884  kdDebug(5310) << "KPrefsModule::load()" << endl;
885 
886  readWidConfig();
887 
888  usrReadConfig();
889 
890  emit changed( false );
891 }
892 
893 void KPrefsModule::save()
894 {
895  kdDebug(5310) << "KPrefsModule::save()" << endl;
896 
897  writeWidConfig();
898 
899  usrWriteConfig();
900 }
901 
902 void KPrefsModule::defaults()
903 {
904  setWidDefaults();
905 
906  emit changed( true );
907 }
A date editing widget that consists of an editable combo box.
Definition: kdateedit.h:55
void setDate(const TQDate &date)
Sets the date.
Definition: kdateedit.cpp:110
TQDate date() const
Definition: kdateedit.cpp:116
void slotApply()
Apply changes to preferences.
void readConfig()
Read preferences from config file.
void writeConfig()
Write preferences to config file.
virtual void usrReadConfig()
Implement this to read custom configuration widgets.
Definition: kprefsdialog.h:769
KPrefsDialog(TDEConfigSkeleton *prefs, TQWidget *parent=0, char *name=0, bool modal=false)
Create a KPrefsDialog for a KPrefs object.
void setDefaults()
Set all widgets to default values.
void slotOk()
Accept changes to preferences and close dialog.
virtual ~KPrefsDialog()
Destructor.
void slotDefault()
Set preferences to default values.
void configChanged()
Emitted when the a changed configuration has been stored.
virtual void usrWriteConfig()
Implement this to write custom configuration widgets.
Definition: kprefsdialog.h:771
Widgets for bool settings in KPrefsDialog.
Definition: kprefsdialog.h:93
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidBool(TDEConfigSkeleton::ItemBool *item, TQWidget *parent)
Create a bool value control element consisting of a TQCheckbox.
TQCheckBox * checkBox()
Return the TQCheckbox used by this control element.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
Widgets for color settings in KPrefsDialog.
Definition: kprefsdialog.h:280
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KColorButton * button()
Return button opening the color dialog.
KPrefsWidColor(TDEConfigSkeleton::ItemColor *item, TQWidget *parent)
Create a color value control element consisting of a test field and a button for opening a color dial...
~KPrefsWidColor()
Destruct color setting widget.
TQLabel * label()
Return TQLabel for the button.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
Widgets for settings represented by a combo box in KPrefsDialog.
Definition: kprefsdialog.h:429
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
KPrefsWidCombo(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Create a control element for selection of an option.
Widgets for time settings in KPrefsDialog.
Definition: kprefsdialog.h:243
KPrefsWidDate(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a time value control element consisting of a label and a date box.
TQLabel * label()
Return TQLabel used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KDateEdit * dateEdit()
Return TQSpinBox used by this widget.
Widgets for duration settings in KPrefsDialog.
Definition: kprefsdialog.h:205
TQLabel * label()
Return TQLabel used by this widget.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KPrefsWidDuration(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a duration value control element consisting of a label and a spinbox.
TQTimeEdit * timeEdit()
Return TQSpinBox used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
Widgets for font settings in KPrefsDialog.
Definition: kprefsdialog.h:323
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
~KPrefsWidFont()
Destruct font setting widget.
TQFrame * preview()
Return TQFrame used as preview field.
TQLabel * label()
Return TQLabel.
TQPushButton * button()
Return button opening the font dialog.
KPrefsWidFont(TDEConfigSkeleton::ItemFont *item, TQWidget *parent, const TQString &sampleText)
Create a font value control element consisting of a test field and a button for opening a font dialog...
Widgets for int settings in KPrefsDialog.
Definition: kprefsdialog.h:127
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
TQLabel * label()
Return TQLabel used by this control element.
TQSpinBox * spinBox()
Return the TQSpinBox used by this control element.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidInt(TDEConfigSkeleton::ItemInt *item, TQWidget *parent)
Create a integer value control element consisting of a label and a spinbox.
Class for managing KPrefsWid objects.
Definition: kprefsdialog.h:558
KPrefsWidDuration * addWidDuration(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidDuration object.
KPrefsWidColor * addWidColor(TDEConfigSkeleton::ItemColor *item, TQWidget *parent)
Register a KPrefsWidColor object.
KPrefsWidString * addWidString(TDEConfigSkeleton::ItemString *item, TQWidget *parent)
Register a KPrefsWidString object.
KPrefsWidRadios * addWidRadios(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Register a KPrefsWidRadios object.
KPrefsWidTime * addWidTime(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidTime object.
KPrefsWidFont * addWidFont(TDEConfigSkeleton::ItemFont *item, TQWidget *parent, const TQString &sampleText)
Register a KPrefsWidFont object.
KPrefsWidPath * addWidPath(TDEConfigSkeleton::ItemPath *item, TQWidget *parent, const TQString &filter=TQString(), uint mode=KFile::File)
Register a path KPrefsWidPath object.
KPrefsWidBool * addWidBool(TDEConfigSkeleton::ItemBool *item, TQWidget *parent)
Register a KPrefsWidBool object.
void setWidDefaults()
Set all widgets to default values.
KPrefsWidCombo * addWidCombo(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Register a KPrefsWidCombo object.
KPrefsWidManager(TDEConfigSkeleton *prefs)
Create a KPrefsWidManager object for a KPrefs object.
virtual void addWid(KPrefsWid *)
Register a custom KPrefsWid object.
KPrefsWidDate * addWidDate(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Register a KPrefsWidDate object.
void writeWidConfig()
Write preferences to config file.
KPrefsWidString * addWidPassword(TDEConfigSkeleton::ItemString *item, TQWidget *parent)
Register a password KPrefsWidString object, with echomode set to TQLineEdit::Password.
KPrefsWidInt * addWidInt(TDEConfigSkeleton::ItemInt *item, TQWidget *parent)
Register a KPrefsWidInt object.
void readWidConfig()
Read preferences from config file.
virtual ~KPrefsWidManager()
Destructor.
Widgets for string settings in KPrefsDialog.
Definition: kprefsdialog.h:509
KURLRequester * urlRequester()
Return TQLineEdit used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KPrefsWidPath(TDEConfigSkeleton::ItemPath *item, TQWidget *parent, const TQString &filter=TQString(), uint mode=KFile::File)
Create a string value control element consisting of a test label and a line edit.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
virtual ~KPrefsWidPath()
Destructor.
TQLabel * label()
Return TQLabel used by this widget.
Widgets for settings represented by a group of radio buttons in KPrefsDialog.
Definition: kprefsdialog.h:381
void addRadio(const TQString &text, const TQString &whatsThis=TQString())
Add a radio button.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
KPrefsWidRadios(TDEConfigSkeleton::ItemEnum *item, TQWidget *parent)
Create a control element for selection of an option.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
TQButtonGroup * groupBox()
Return the box widget used by this widget.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
Widgets for string settings in KPrefsDialog.
Definition: kprefsdialog.h:462
virtual ~KPrefsWidString()
Destructor.
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
TQLineEdit * lineEdit()
Return TQLineEdit used by this widget.
TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
KPrefsWidString(TDEConfigSkeleton::ItemString *item, TQWidget *parent, TQLineEdit::EchoMode echomode=TQLineEdit::Normal)
Create a string value control element consisting of a test label and a line edit.
TQLabel * label()
Return TQLabel used by this widget.
Widgets for time settings in KPrefsDialog.
Definition: kprefsdialog.h:168
KPrefsWidTime(TDEConfigSkeleton::ItemDateTime *item, TQWidget *parent)
Create a time value control element consisting of a label and a spinbox.
TQLabel * label()
Return TQLabel used by this widget.
void readConfig()
This function is called to read value of the setting from the stored configuration and display it in ...
void writeConfig()
This function is called to write the current setting of the widget to the stored configuration.
KTimeEdit * timeEdit()
Return TQSpinBox used by this widget.
Base class for GUI control elements used by KPrefsDialog.
Definition: kprefsdialog.h:59
virtual TQValueList< TQWidget * > widgets() const
Return a list of widgets used by this control element.
void changed()
Emitted when widget value has changed.
virtual void writeConfig()=0
This function is called to write the current setting of the widget to the stored configuration.
virtual void readConfig()=0
This function is called to read value of the setting from the stored configuration and display it in ...
This is a class that provides an easy, user friendly way to edit times.
Definition: ktimeedit.h:45
TQTime getTime() const
returns the time that is currently set in the timeLineEdit.
Definition: ktimeedit.cpp:149
void setTime(TQTime qt)
used to set the time which is displayed to a specific value.
Definition: ktimeedit.cpp:177