kcmkorgsummary.cpp
1 /*
2  This file is part of Kontact.
3  Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <tqbuttongroup.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqradiobutton.h>
28 #include <tqspinbox.h>
29 
30 #include <tdeaboutdata.h>
31 #include <tdeapplication.h>
32 #include <tdeaccelmanager.h>
33 #include <tdeconfig.h>
34 #include <kdebug.h>
35 #include <kdialogbase.h>
36 #include <tdelocale.h>
37 
38 #include "kcmkorgsummary.h"
39 
40 #include <tdemacros.h>
41 
42 extern "C"
43 {
44  TDE_EXPORT TDECModule *create_korgsummary( TQWidget *parent, const char * )
45  {
46  return new KCMKOrgSummary( parent, "kcmkorgsummary" );
47  }
48 }
49 
50 KCMKOrgSummary::KCMKOrgSummary( TQWidget *parent, const char *name )
51  : TDECModule( parent, name )
52 {
53  initGUI();
54 
55  customDaysChanged( 1 );
56 
57  connect( mCalendarGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( modified() ) );
58  connect( mCalendarGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( buttonClicked( int ) ) );
59  connect( mTodoGroup, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( modified() ) );
60  connect( mCustomDays, TQ_SIGNAL( valueChanged( int ) ), TQ_SLOT( modified() ) );
61  connect( mCustomDays, TQ_SIGNAL( valueChanged( int ) ), TQ_SLOT( customDaysChanged( int ) ) );
62 
63  TDEAcceleratorManager::manage( this );
64 
65  load();
66 
67  TDEAboutData *about = new TDEAboutData( I18N_NOOP( "kcmkorgsummary" ),
68  I18N_NOOP( "Schedule Configuration Dialog" ),
69  0, 0, TDEAboutData::License_GPL,
70  I18N_NOOP( "(c) 2003 - 2004 Tobias Koenig" ) );
71 
72  about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
73  setAboutData( about );
74 }
75 
76 void KCMKOrgSummary::modified()
77 {
78  emit changed( true );
79 }
80 
81 void KCMKOrgSummary::buttonClicked( int id )
82 {
83  mCustomDays->setEnabled( id == 4 );
84 }
85 
86 void KCMKOrgSummary::customDaysChanged( int value )
87 {
88  mCustomDays->setSuffix( i18n( " day", " days", value ) );
89 }
90 
91 void KCMKOrgSummary::initGUI()
92 {
93  TQVBoxLayout *layout = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
94 
95  mCalendarGroup = new TQButtonGroup( 0, TQt::Vertical, i18n( "Appointments" ), this );
96  TQVBoxLayout *boxLayout = new TQVBoxLayout( mCalendarGroup->layout(),
97  KDialog::spacingHint() );
98 
99  TQLabel *label = new TQLabel( i18n( "How many days should the calendar show at once?" ), mCalendarGroup );
100  boxLayout->addWidget( label );
101 
102  TQRadioButton *button = new TQRadioButton( i18n( "One day" ), mCalendarGroup );
103  boxLayout->addWidget( button );
104 
105  button = new TQRadioButton( i18n( "Five days" ), mCalendarGroup );
106  boxLayout->addWidget( button );
107 
108  button = new TQRadioButton( i18n( "One week" ), mCalendarGroup );
109  boxLayout->addWidget( button );
110 
111  button = new TQRadioButton( i18n( "One month" ), mCalendarGroup );
112  boxLayout->addWidget( button );
113 
114  TQHBoxLayout *hbox = new TQHBoxLayout( boxLayout, KDialog::spacingHint() );
115 
116  button = new TQRadioButton( "", mCalendarGroup );
117  hbox->addWidget( button );
118 
119  mCustomDays = new TQSpinBox( 1, 365, 1, mCalendarGroup );
120  mCustomDays->setEnabled( false );
121  hbox->addWidget( mCustomDays );
122 
123  hbox->addStretch( 1 );
124 
125  layout->addWidget( mCalendarGroup );
126 
127  mTodoGroup = new TQButtonGroup( 2, TQt::Horizontal, i18n( "To-dos" ), this );
128  new TQRadioButton( i18n( "Show all to-dos" ), mTodoGroup );
129  new TQRadioButton( i18n( "Show today's to-dos only" ), mTodoGroup );
130 
131  layout->addWidget( mTodoGroup );
132 
133  layout->addStretch();
134 }
135 
136 void KCMKOrgSummary::load()
137 {
138  TDEConfig config( "kcmkorgsummaryrc" );
139 
140  config.setGroup( "Calendar" );
141  int days = config.readNumEntry( "DaysToShow", 1 );
142  if ( days == 1 )
143  mCalendarGroup->setButton( 0 );
144  else if ( days == 5 )
145  mCalendarGroup->setButton( 1 );
146  else if ( days == 7 )
147  mCalendarGroup->setButton( 2 );
148  else if ( days == 31 )
149  mCalendarGroup->setButton( 3 );
150  else {
151  mCalendarGroup->setButton( 4 );
152  mCustomDays->setValue( days );
153  mCustomDays->setEnabled( true );
154  }
155 
156  config.setGroup( "Todo" );
157  bool allTodos = config.readBoolEntry( "ShowAllTodos", false );
158 
159  if ( allTodos )
160  mTodoGroup->setButton( 0 );
161  else
162  mTodoGroup->setButton( 1 );
163 
164  emit changed( false );
165 }
166 
167 void KCMKOrgSummary::save()
168 {
169  TDEConfig config( "kcmkorgsummaryrc" );
170 
171  config.setGroup( "Calendar" );
172 
173  int days;
174  switch ( mCalendarGroup->selectedId() ) {
175  case 0: days = 1; break;
176  case 1: days = 5; break;
177  case 2: days = 7; break;
178  case 3: days = 31; break;
179  case 4:
180  default: days = mCustomDays->value(); break;
181  }
182  config.writeEntry( "DaysToShow", days );
183 
184  config.setGroup( "Todo" );
185  config.writeEntry( "ShowAllTodos", mTodoGroup->selectedId() == 0 );
186 
187  config.sync();
188 
189  emit changed( false );
190 }
191 
192 void KCMKOrgSummary::defaults()
193 {
194  mCalendarGroup->setButton( 0 );
195  mTodoGroup->setButton( 1 );
196 
197  emit changed( true );
198 }
199 
200 #include "kcmkorgsummary.moc"