00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <qbuttongroup.h>
00025 #include <qcheckbox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qradiobutton.h>
00029 #include <qspinbox.h>
00030
00031 #include <kaboutdata.h>
00032 #include <kapplication.h>
00033 #include <kaccelmanager.h>
00034 #include <kconfig.h>
00035 #include <kdebug.h>
00036 #include <kdialogbase.h>
00037 #include <klocale.h>
00038
00039 #include "kcmkabsummary.h"
00040
00041 extern "C"
00042 {
00043 KCModule *create_kabsummary( QWidget *parent, const char * )
00044 {
00045 return new KCMKABSummary( parent, "kcmkabsummary" );
00046 }
00047 }
00048
00049 KCMKABSummary::KCMKABSummary( QWidget *parent, const char *name )
00050 : KCModule( parent, name )
00051 {
00052 initGUI();
00053
00054 customDaysChanged( 1 );
00055
00056 connect( mDaysGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00057 connect( mDaysGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
00058 connect( mShowGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00059 connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( modified() ) );
00060 connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( customDaysChanged( int ) ) );
00061
00062 KAcceleratorManager::manage( this );
00063
00064 load();
00065 }
00066
00067 void KCMKABSummary::modified()
00068 {
00069 emit changed( true );
00070 }
00071
00072 void KCMKABSummary::buttonClicked( int id )
00073 {
00074 mCustomDays->setEnabled( id == 4 );
00075 }
00076
00077 void KCMKABSummary::customDaysChanged( int value )
00078 {
00079 mCustomDays->setSuffix( i18n( " day", " days", value ) );
00080 }
00081
00082 void KCMKABSummary::initGUI()
00083 {
00084 QVBoxLayout *layout = new QVBoxLayout( this, KDialog::marginHint(),
00085 KDialog::spacingHint() );
00086
00087 mDaysGroup = new QButtonGroup( 0, Vertical, i18n( "Address Book Summary" ), this );
00088 QVBoxLayout *boxLayout = new QVBoxLayout( mDaysGroup->layout(),
00089 KDialog::spacingHint() );
00090
00091 QLabel *label = new QLabel( i18n( "How many days should the address book summary display at once?" ), mDaysGroup );
00092 boxLayout->addWidget( label );
00093
00094 QRadioButton *button = new QRadioButton( i18n( "One day" ), mDaysGroup );
00095 boxLayout->addWidget( button );
00096
00097 button = new QRadioButton( i18n( "Five days" ), mDaysGroup );
00098 boxLayout->addWidget( button );
00099
00100 button = new QRadioButton( i18n( "One week" ), mDaysGroup );
00101 boxLayout->addWidget( button );
00102
00103 button = new QRadioButton( i18n( "One month" ), mDaysGroup );
00104 boxLayout->addWidget( button );
00105
00106 QHBoxLayout *hbox = new QHBoxLayout( boxLayout, KDialog::spacingHint() );
00107
00108 button = new QRadioButton( "", mDaysGroup );
00109 hbox->addWidget( button );
00110
00111 mCustomDays = new QSpinBox( 1, 365, 1, mDaysGroup );
00112 mCustomDays->setEnabled( false );
00113 hbox->addWidget( mCustomDays );
00114
00115 hbox->addStretch( 1 );
00116
00117 layout->addWidget( mDaysGroup );
00118
00119 mShowGroup = new QButtonGroup( 2, Horizontal, i18n( "Event Types" ), this );
00120 mShowBirthdays = new QCheckBox( i18n( "Show all birthdays" ), mShowGroup );
00121 mShowAnniversaries = new QCheckBox( i18n( "Show all anniversaries" ), mShowGroup );
00122
00123 layout->addWidget( mShowGroup );
00124 }
00125
00126 void KCMKABSummary::load()
00127 {
00128 KConfig config( "kcmkabsummaryrc" );
00129
00130 config.setGroup( "Days" );
00131 int days = config.readNumEntry( "DaysToShow", 7 );
00132 if ( days == 1 )
00133 mDaysGroup->setButton( 0 );
00134 else if ( days == 5 )
00135 mDaysGroup->setButton( 1 );
00136 else if ( days == 7 )
00137 mDaysGroup->setButton( 2 );
00138 else if ( days == 31 )
00139 mDaysGroup->setButton( 3 );
00140 else {
00141 mDaysGroup->setButton( 4 );
00142 mCustomDays->setValue( days );
00143 mCustomDays->setEnabled( true );
00144 }
00145
00146 config.setGroup( "EventTypes" );
00147 mShowBirthdays->setChecked( config.readBoolEntry( "ShowBirthdays", true ) );
00148 mShowAnniversaries->setChecked( config.readBoolEntry( "ShowAnniversaries", true ) );
00149
00150 emit changed( false );
00151 }
00152
00153 void KCMKABSummary::save()
00154 {
00155 KConfig config( "kcmkabsummaryrc" );
00156
00157 config.setGroup( "Days" );
00158
00159 int days;
00160 switch ( mDaysGroup->selectedId() ) {
00161 case 0: days = 1; break;
00162 case 1: days = 5; break;
00163 case 2: days = 7; break;
00164 case 3: days = 31; break;
00165 case 4:
00166 default: days = mCustomDays->value(); break;
00167 }
00168 config.writeEntry( "DaysToShow", days );
00169
00170 config.setGroup( "EventTypes" );
00171 config.writeEntry( "ShowBirthdays", mShowBirthdays->isChecked() );
00172 config.writeEntry( "ShowAnniversaries", mShowAnniversaries->isChecked() );
00173
00174 config.sync();
00175
00176 emit changed( false );
00177 }
00178
00179 void KCMKABSummary::defaults()
00180 {
00181 mDaysGroup->setButton( 7 );
00182 mShowBirthdays->setChecked( true );
00183 mShowAnniversaries->setChecked( true );
00184
00185 emit changed( true );
00186 }
00187
00188 const KAboutData* KCMKABSummary::aboutData() const
00189 {
00190 KAboutData *about = new KAboutData( I18N_NOOP( "kcmkabsummary" ),
00191 I18N_NOOP( "Address Book Configuration Dialog" ),
00192 0, 0, KAboutData::License_GPL,
00193 I18N_NOOP( "(c) 2004 Tobias Koenig" ) );
00194
00195 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00196
00197 return about;
00198 }
00199
00200 #include "kcmkabsummary.moc"