kcmsdsummary.cpp
00001 /* 00002 This file is part of Kontact. 00003 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org> 00004 Copyright (c) 2004 Allen Winter <winter@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include <tqbuttongroup.h> 00026 #include <tqcheckbox.h> 00027 #include <tqlabel.h> 00028 #include <tqlayout.h> 00029 #include <tqradiobutton.h> 00030 #include <tqspinbox.h> 00031 00032 #include <tdeaboutdata.h> 00033 #include <tdeapplication.h> 00034 #include <tdeaccelmanager.h> 00035 #include <tdeconfig.h> 00036 #include <kdebug.h> 00037 #include <kdialogbase.h> 00038 #include <tdelocale.h> 00039 00040 #include "kcmsdsummary.h" 00041 00042 #include <tdepimmacros.h> 00043 00044 extern "C" 00045 { 00046 KDE_EXPORT TDECModule *create_sdsummary( TQWidget *parent, const char * ) 00047 { 00048 return new KCMSDSummary( parent, "kcmsdsummary" ); 00049 } 00050 } 00051 00052 KCMSDSummary::KCMSDSummary( TQWidget *parent, const char *name ) 00053 : TDECModule( parent, name ) 00054 { 00055 initGUI(); 00056 00057 customDaysChanged( 1 ); 00058 00059 connect( mDaysGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( modified() ) ); 00060 connect( mDaysGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( buttonClicked( int ) ) ); 00061 connect( mCalendarGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( modified() ) ); 00062 connect( mContactGroup, TQT_SIGNAL( clicked( int ) ), TQT_SLOT( modified() ) ); 00063 connect( mCustomDays, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( modified() ) ); 00064 connect( mCustomDays, TQT_SIGNAL( valueChanged( int ) ), TQT_SLOT( customDaysChanged( int ) ) ); 00065 00066 TDEAcceleratorManager::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 TQGridLayout *layout = new TQGridLayout( this, 3, 2, KDialog::spacingHint() ); 00089 00090 mDaysGroup = new TQButtonGroup( 0, Qt::Vertical, i18n( "Special Dates Summary" ), this ); 00091 TQVBoxLayout *boxLayout = new TQVBoxLayout( mDaysGroup->layout(), 00092 KDialog::spacingHint() ); 00093 00094 TQLabel *label = new TQLabel( i18n( "How many days should the special dates summary show at once?" ), mDaysGroup ); 00095 boxLayout->addWidget( label ); 00096 00097 TQRadioButton *button = new TQRadioButton( i18n( "One day" ), mDaysGroup ); 00098 boxLayout->addWidget( button ); 00099 00100 button = new TQRadioButton( i18n( "Five days" ), mDaysGroup ); 00101 boxLayout->addWidget( button ); 00102 00103 button = new TQRadioButton( i18n( "One week" ), mDaysGroup ); 00104 boxLayout->addWidget( button ); 00105 00106 button = new TQRadioButton( i18n( "One month" ), mDaysGroup ); 00107 boxLayout->addWidget( button ); 00108 00109 TQHBoxLayout *hbox = new TQHBoxLayout( boxLayout, KDialog::spacingHint() ); 00110 00111 button = new TQRadioButton( "", mDaysGroup ); 00112 hbox->addWidget( button ); 00113 00114 mCustomDays = new TQSpinBox( 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 TQButtonGroup( 1, Qt::Horizontal, i18n( "Special Dates From Calendar" ), this ); 00123 00124 mShowBirthdaysFromCal = new TQCheckBox( i18n( "Show birthdays" ), mCalendarGroup ); 00125 mShowAnniversariesFromCal = new TQCheckBox( i18n( "Show anniversaries" ), mCalendarGroup ); 00126 mShowHolidays = new TQCheckBox( i18n( "Show holidays" ), mCalendarGroup ); 00127 00128 mShowSpecialsFromCal = new TQCheckBox( i18n( "Show special occasions" ), mCalendarGroup ); 00129 00130 mContactGroup = new TQButtonGroup( 1, Qt::Horizontal, i18n( "Special Dates From Contact List" ), this ); 00131 00132 mShowBirthdaysFromKAB = new TQCheckBox( i18n( "Show birthdays" ), mContactGroup ); 00133 mShowAnniversariesFromKAB = new TQCheckBox( 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 TDEConfig 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 TDEConfig 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 TDEAboutData* KCMSDSummary::aboutData() const 00236 { 00237 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kcmsdsummary" ), 00238 I18N_NOOP( "Special Dates Configuration Dialog" ), 00239 0, 0, TDEAboutData::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"