kcmsdsummary.cpp
1/*
2 This file is part of Kontact.
3 Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4 Copyright (c) 2004 Allen Winter <winter@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqbuttongroup.h>
26#include <tqcheckbox.h>
27#include <tqlabel.h>
28#include <tqlayout.h>
29#include <tqradiobutton.h>
30#include <tqspinbox.h>
31
32#include <tdeaboutdata.h>
33#include <tdeapplication.h>
34#include <tdeaccelmanager.h>
35#include <tdeconfig.h>
36#include <kdebug.h>
37#include <kdialogbase.h>
38#include <tdelocale.h>
39
40#include "kcmsdsummary.h"
41
42#include <tdemacros.h>
43
44extern "C"
45{
46 TDE_EXPORT TDECModule *create_sdsummary( TQWidget *parent, const char * )
47 {
48 return new KCMSDSummary( parent, "kcmsdsummary" );
49 }
50}
51
52KCMSDSummary::KCMSDSummary( TQWidget *parent, const char *name )
53 : TDECModule( parent, name )
54{
55 initGUI();
56
57 customDaysChanged( 1 );
58
59 connect( mDaysGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( modified() ) );
60 connect( mDaysGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( buttonClicked( int ) ) );
61 connect( mCalendarGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( modified() ) );
62 connect( mContactGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( modified() ) );
63 connect( mCustomDays, TQ_SIGNAL( valueChanged( int ) ), TQ_SLOT( modified() ) );
64 connect( mCustomDays, TQ_SIGNAL( valueChanged( int ) ), TQ_SLOT( customDaysChanged( int ) ) );
65
66 TDEAcceleratorManager::manage( this );
67
68 load();
69}
70
71void KCMSDSummary::modified()
72{
73 emit changed( true );
74}
75
76void KCMSDSummary::buttonClicked( int id )
77{
78 mCustomDays->setEnabled( id == 4 );
79}
80
81void KCMSDSummary::customDaysChanged( int value )
82{
83 mCustomDays->setSuffix( i18n( " day", " days", value ) );
84}
85
86void KCMSDSummary::initGUI()
87{
88 TQGridLayout *layout = new TQGridLayout( this, 3, 2, KDialog::spacingHint() );
89
90 mDaysGroup = new TQButtonGroup( 0, TQt::Vertical, i18n( "Special Dates Summary" ), this );
91 TQVBoxLayout *boxLayout = new TQVBoxLayout( mDaysGroup->layout(),
92 KDialog::spacingHint() );
93
94 TQLabel *label = new TQLabel( i18n( "How many days should the special dates summary show at once?" ), mDaysGroup );
95 boxLayout->addWidget( label );
96
97 TQRadioButton *button = new TQRadioButton( i18n( "One day" ), mDaysGroup );
98 boxLayout->addWidget( button );
99
100 button = new TQRadioButton( i18n( "Five days" ), mDaysGroup );
101 boxLayout->addWidget( button );
102
103 button = new TQRadioButton( i18n( "One week" ), mDaysGroup );
104 boxLayout->addWidget( button );
105
106 button = new TQRadioButton( i18n( "One month" ), mDaysGroup );
107 boxLayout->addWidget( button );
108
109 TQHBoxLayout *hbox = new TQHBoxLayout( boxLayout, KDialog::spacingHint() );
110
111 button = new TQRadioButton( "", mDaysGroup );
112 hbox->addWidget( button );
113
114 mCustomDays = new TQSpinBox( 1, 365, 1, mDaysGroup );
115 mCustomDays->setEnabled( false );
116 hbox->addWidget( mCustomDays );
117
118 hbox->addStretch( 1 );
119
120 layout->addMultiCellWidget( mDaysGroup, 0, 0, 0, 1 );
121
122 mCalendarGroup = new TQButtonGroup( 1, TQt::Horizontal, i18n( "Special Dates From Calendar" ), this );
123
124 mShowBirthdaysFromCal = new TQCheckBox( i18n( "Show birthdays" ), mCalendarGroup );
125 mShowAnniversariesFromCal = new TQCheckBox( i18n( "Show anniversaries" ), mCalendarGroup );
126 mShowHolidays = new TQCheckBox( i18n( "Show holidays" ), mCalendarGroup );
127
128 mShowSpecialsFromCal = new TQCheckBox( i18n( "Show special occasions" ), mCalendarGroup );
129
130 mContactGroup = new TQButtonGroup( 1, TQt::Horizontal, i18n( "Special Dates From Contact List" ), this );
131
132 mShowBirthdaysFromKAB = new TQCheckBox( i18n( "Show birthdays" ), mContactGroup );
133 mShowAnniversariesFromKAB = new TQCheckBox( i18n( "Show anniversaries" ), mContactGroup );
134
135 layout->addWidget( mCalendarGroup, 1, 0 );
136 layout->addWidget( mContactGroup, 1, 1 );
137
138 layout->setRowStretch( 2, 1 );
139}
140
141void KCMSDSummary::load()
142{
143 TDEConfig config( "kcmsdsummaryrc" );
144
145 config.setGroup( "Days" );
146 int days = config.readNumEntry( "DaysToShow", 7 );
147 if ( days == 1 )
148 mDaysGroup->setButton( 0 );
149 else if ( days == 5 )
150 mDaysGroup->setButton( 1 );
151 else if ( days == 7 )
152 mDaysGroup->setButton( 2 );
153 else if ( days == 31 )
154 mDaysGroup->setButton( 3 );
155 else {
156 mDaysGroup->setButton( 4 );
157 mCustomDays->setValue( days );
158 mCustomDays->setEnabled( true );
159 }
160
161 config.setGroup( "EventTypes" );
162
163 mShowBirthdaysFromKAB->
164 setChecked( config.readBoolEntry( "ShowBirthdaysFromContacts", true ) );
165 mShowBirthdaysFromCal->
166 setChecked( config.readBoolEntry( "ShowBirthdaysFromCalendar", true ) );
167
168 mShowAnniversariesFromKAB->
169 setChecked( config.readBoolEntry( "ShowAnniversariesFromContacts", true ) );
170 mShowAnniversariesFromCal->
171 setChecked( config.readBoolEntry( "ShowAnniversariesFromCalendar", true ) );
172
173 mShowHolidays->
174 setChecked( config.readBoolEntry( "ShowHolidays", true ) );
175
176 mShowSpecialsFromCal->
177 setChecked( config.readBoolEntry( "ShowSpecialsFromCalendar", true ) );
178
179 emit changed( false );
180}
181
182void KCMSDSummary::save()
183{
184 TDEConfig config( "kcmsdsummaryrc" );
185
186 config.setGroup( "Days" );
187
188 int days;
189 switch ( mDaysGroup->selectedId() ) {
190 case 0: days = 1; break;
191 case 1: days = 5; break;
192 case 2: days = 7; break;
193 case 3: days = 31; break;
194 case 4:
195 default: days = mCustomDays->value(); break;
196 }
197 config.writeEntry( "DaysToShow", days );
198
199 config.setGroup( "EventTypes" );
200
201 config.writeEntry( "ShowBirthdaysFromContacts",
202 mShowBirthdaysFromKAB->isChecked() );
203 config.writeEntry( "ShowBirthdaysFromCalendar",
204 mShowBirthdaysFromCal->isChecked() );
205
206 config.writeEntry( "ShowAnniversariesFromContacts",
207 mShowAnniversariesFromKAB->isChecked() );
208 config.writeEntry( "ShowAnniversariesFromCalendar",
209 mShowAnniversariesFromCal->isChecked() );
210
211 config.writeEntry( "ShowHolidays",
212 mShowHolidays->isChecked() );
213
214 config.writeEntry( "ShowSpecialsFromCalendar",
215 mShowSpecialsFromCal->isChecked() );
216
217 config.sync();
218
219 emit changed( false );
220}
221
222void KCMSDSummary::defaults()
223{
224 mDaysGroup->setButton( 7 );
225 mShowBirthdaysFromKAB->setChecked( true );
226 mShowBirthdaysFromCal->setChecked( true );
227 mShowAnniversariesFromKAB->setChecked( true );
228 mShowAnniversariesFromCal->setChecked( true );
229 mShowHolidays->setChecked( true );
230 mShowSpecialsFromCal->setChecked( true );
231
232 emit changed( true );
233}
234
235const TDEAboutData* KCMSDSummary::aboutData() const
236{
237 TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kcmsdsummary" ),
238 I18N_NOOP( "Special Dates Configuration Dialog" ),
239 0, 0, TDEAboutData::License_GPL,
240 I18N_NOOP( "(c) 2004 Tobias Koenig" ) );
241
242 about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
243 about->addAuthor( "Allen Winter", 0, "winter@kde.org" );
244
245 return about;
246}
247
248#include "kcmsdsummary.moc"