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 <qbuttongroup.h>
00026 #include <qcheckbox.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qradiobutton.h>
00030 #include <qspinbox.h>
00031
00032 #include <kaboutdata.h>
00033 #include <kapplication.h>
00034 #include <kaccelmanager.h>
00035 #include <kconfig.h>
00036 #include <kdebug.h>
00037 #include <kdialogbase.h>
00038 #include <klocale.h>
00039
00040 #include "kcmsdsummary.h"
00041
00042 #include <kdepimmacros.h>
00043
00044 extern "C"
00045 {
00046 KDE_EXPORT KCModule *create_sdsummary( QWidget *parent, const char * )
00047 {
00048 return new KCMSDSummary( parent, "kcmsdsummary" );
00049 }
00050 }
00051
00052 KCMSDSummary::KCMSDSummary( QWidget *parent, const char *name )
00053 : KCModule( parent, name )
00054 {
00055 initGUI();
00056
00057 customDaysChanged( 1 );
00058
00059 connect( mDaysGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00060 connect( mDaysGroup, SIGNAL( clicked( int ) ), SLOT( buttonClicked( int ) ) );
00061 connect( mCalendarGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00062 connect( mContactGroup, SIGNAL( clicked( int ) ), SLOT( modified() ) );
00063 connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( modified() ) );
00064 connect( mCustomDays, SIGNAL( valueChanged( int ) ), SLOT( customDaysChanged( int ) ) );
00065
00066 KAcceleratorManager::manage( this );
00067
00068 load();
00069 }
00070
00071 void KCMSDSummary::modified()
00072 {
00073 emit changed( true );
00074 }
00075
00076 void KCMSDSummary::buttonClicked( int id )
00077 {
00078 mCustomDays->setEnabled( id == 4 );
00079 }
00080
00081 void KCMSDSummary::customDaysChanged( int value )
00082 {
00083 mCustomDays->setSuffix( i18n( " day", " days", value ) );
00084 }
00085
00086 void KCMSDSummary::initGUI()
00087 {
00088 QGridLayout *layout = new QGridLayout( this, 3, 2, KDialog::spacingHint() );
00089
00090 mDaysGroup = new QButtonGroup( 0, Vertical, i18n( "Special Dates Summary" ), this );
00091 QVBoxLayout *boxLayout = new QVBoxLayout( mDaysGroup->layout(),
00092 KDialog::spacingHint() );
00093
00094 QLabel *label = new QLabel( i18n( "How many days should the special dates summary show at once?" ), mDaysGroup );
00095 boxLayout->addWidget( label );
00096
00097 QRadioButton *button = new QRadioButton( i18n( "One day" ), mDaysGroup );
00098 boxLayout->addWidget( button );
00099
00100 button = new QRadioButton( i18n( "Five days" ), mDaysGroup );
00101 boxLayout->addWidget( button );
00102
00103 button = new QRadioButton( i18n( "One week" ), mDaysGroup );
00104 boxLayout->addWidget( button );
00105
00106 button = new QRadioButton( i18n( "One month" ), mDaysGroup );
00107 boxLayout->addWidget( button );
00108
00109 QHBoxLayout *hbox = new QHBoxLayout( boxLayout, KDialog::spacingHint() );
00110
00111 button = new QRadioButton( "", mDaysGroup );
00112 hbox->addWidget( button );
00113
00114 mCustomDays = new QSpinBox( 1, 365, 1, mDaysGroup );
00115 mCustomDays->setEnabled( false );
00116 hbox->addWidget( mCustomDays );
00117
00118 hbox->addStretch( 1 );
00119
00120 layout->addMultiCellWidget( mDaysGroup, 0, 0, 0, 1 );
00121
00122 mCalendarGroup = new QButtonGroup( 1, Horizontal, i18n( "Special Dates From Calendar" ), this );
00123
00124 mShowBirthdaysFromCal = new QCheckBox( i18n( "Show birthdays" ), mCalendarGroup );
00125 mShowAnniversariesFromCal = new QCheckBox( i18n( "Show anniversaries" ), mCalendarGroup );
00126 mShowHolidays = new QCheckBox( i18n( "Show holidays" ), mCalendarGroup );
00127
00128 mShowSpecialsFromCal = new QCheckBox( i18n( "Show special occasions" ), mCalendarGroup );
00129
00130 mContactGroup = new QButtonGroup( 1, Horizontal, i18n( "Special Dates From Contact List" ), this );
00131
00132 mShowBirthdaysFromKAB = new QCheckBox( i18n( "Show birthdays" ), mContactGroup );
00133 mShowAnniversariesFromKAB = new QCheckBox( i18n( "Show anniversaries" ), mContactGroup );
00134
00135 layout->addWidget( mCalendarGroup, 1, 0 );
00136 layout->addWidget( mContactGroup, 1, 1 );
00137
00138 layout->setRowStretch( 2, 1 );
00139 }
00140
00141 void KCMSDSummary::load()
00142 {
00143 KConfig config( "kcmsdsummaryrc" );
00144
00145 config.setGroup( "Days" );
00146 int days = config.readNumEntry( "DaysToShow", 7 );
00147 if ( days == 1 )
00148 mDaysGroup->setButton( 0 );
00149 else if ( days == 5 )
00150 mDaysGroup->setButton( 1 );
00151 else if ( days == 7 )
00152 mDaysGroup->setButton( 2 );
00153 else if ( days == 31 )
00154 mDaysGroup->setButton( 3 );
00155 else {
00156 mDaysGroup->setButton( 4 );
00157 mCustomDays->setValue( days );
00158 mCustomDays->setEnabled( true );
00159 }
00160
00161 config.setGroup( "EventTypes" );
00162
00163 mShowBirthdaysFromKAB->
00164 setChecked( config.readBoolEntry( "ShowBirthdaysFromContacts", true ) );
00165 mShowBirthdaysFromCal->
00166 setChecked( config.readBoolEntry( "ShowBirthdaysFromCalendar", true ) );
00167
00168 mShowAnniversariesFromKAB->
00169 setChecked( config.readBoolEntry( "ShowAnniversariesFromContacts", true ) );
00170 mShowAnniversariesFromCal->
00171 setChecked( config.readBoolEntry( "ShowAnniversariesFromCalendar", true ) );
00172
00173 mShowHolidays->
00174 setChecked( config.readBoolEntry( "ShowHolidays", true ) );
00175
00176 mShowSpecialsFromCal->
00177 setChecked( config.readBoolEntry( "ShowSpecialsFromCalendar", true ) );
00178
00179 emit changed( false );
00180 }
00181
00182 void KCMSDSummary::save()
00183 {
00184 KConfig config( "kcmsdsummaryrc" );
00185
00186 config.setGroup( "Days" );
00187
00188 int days;
00189 switch ( mDaysGroup->selectedId() ) {
00190 case 0: days = 1; break;
00191 case 1: days = 5; break;
00192 case 2: days = 7; break;
00193 case 3: days = 31; break;
00194 case 4:
00195 default: days = mCustomDays->value(); break;
00196 }
00197 config.writeEntry( "DaysToShow", days );
00198
00199 config.setGroup( "EventTypes" );
00200
00201 config.writeEntry( "ShowBirthdaysFromContacts",
00202 mShowBirthdaysFromKAB->isChecked() );
00203 config.writeEntry( "ShowBirthdaysFromCalendar",
00204 mShowBirthdaysFromCal->isChecked() );
00205
00206 config.writeEntry( "ShowAnniversariesFromContacts",
00207 mShowAnniversariesFromKAB->isChecked() );
00208 config.writeEntry( "ShowAnniversariesFromCalendar",
00209 mShowAnniversariesFromCal->isChecked() );
00210
00211 config.writeEntry( "ShowHolidays",
00212 mShowHolidays->isChecked() );
00213
00214 config.writeEntry( "ShowSpecialsFromCalendar",
00215 mShowSpecialsFromCal->isChecked() );
00216
00217 config.sync();
00218
00219 emit changed( false );
00220 }
00221
00222 void KCMSDSummary::defaults()
00223 {
00224 mDaysGroup->setButton( 7 );
00225 mShowBirthdaysFromKAB->setChecked( true );
00226 mShowBirthdaysFromCal->setChecked( true );
00227 mShowAnniversariesFromKAB->setChecked( true );
00228 mShowAnniversariesFromCal->setChecked( true );
00229 mShowHolidays->setChecked( true );
00230 mShowSpecialsFromCal->setChecked( true );
00231
00232 emit changed( true );
00233 }
00234
00235 const KAboutData* KCMSDSummary::aboutData() const
00236 {
00237 KAboutData *about = new KAboutData( I18N_NOOP( "kcmsdsummary" ),
00238 I18N_NOOP( "Special Dates Configuration Dialog" ),
00239 0, 0, KAboutData::License_GPL,
00240 I18N_NOOP( "(c) 2004 Tobias Koenig" ) );
00241
00242 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
00243 about->addAuthor( "Allen Winter", 0, "winter@kde.org" );
00244
00245 return about;
00246 }
00247
00248 #include "kcmsdsummary.moc"