summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koeditorrecurrence.cpp12
-rw-r--r--korganizer/koeditorrecurrence.h3
-rw-r--r--libkcal/calendarlocal.cpp2
-rw-r--r--libkcal/icalformatimpl.cpp11
-rw-r--r--libkcal/journal.cpp2
5 files changed, 21 insertions, 9 deletions
diff --git a/korganizer/koeditorrecurrence.cpp b/korganizer/koeditorrecurrence.cpp
index 89504db..0e74a99 100644
--- a/korganizer/koeditorrecurrence.cpp
+++ b/korganizer/koeditorrecurrence.cpp
@@ -1,1126 +1,1130 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#include <qlayout.h> 26#include <qlayout.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qbuttongroup.h> 28#include <qbuttongroup.h>
29#include <qvgroupbox.h> 29#include <qvgroupbox.h>
30#include <qwidgetstack.h> 30#include <qwidgetstack.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qlistbox.h> 32#include <qlistbox.h>
33#include <qspinbox.h> 33#include <qspinbox.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qapplication.h> 35#include <qapplication.h>
36 36
37#include <kdialog.h> 37#include <kdialog.h>
38#include <kglobal.h> 38#include <kglobal.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kiconloader.h> 40#include <kiconloader.h>
41#include <kdebug.h> 41#include <kdebug.h>
42#include <knumvalidator.h> 42#include <knumvalidator.h>
43 43
44#include <libkcal/event.h> 44#include <libkcal/event.h>
45#include <libkcal/todo.h> 45#include <libkcal/todo.h>
46 46
47#include <libkdepim/kdateedit.h> 47#include <libkdepim/kdateedit.h>
48 48
49#include "koprefs.h" 49#include "koprefs.h"
50 50
51#include "koeditorrecurrence.h" 51#include "koeditorrecurrence.h"
52 52
53/////////////////////////// RecurBase /////////////////////////////// 53/////////////////////////// RecurBase ///////////////////////////////
54 54
55RecurBase::RecurBase( QWidget *parent, const char *name ) : 55RecurBase::RecurBase( QWidget *parent, const char *name ) :
56 QWidget( parent, name ) 56 QWidget( parent, name )
57{ 57{
58 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this ); 58 mFrequencyEdit = new QSpinBox( 1, 9999, 1, this );
59 mFrequencyEdit->setValue( 1 ); 59 mFrequencyEdit->setValue( 1 );
60} 60}
61 61
62QWidget *RecurBase::frequencyEdit() 62QWidget *RecurBase::frequencyEdit()
63{ 63{
64 return mFrequencyEdit; 64 return mFrequencyEdit;
65} 65}
66 66
67void RecurBase::setFrequency( int f ) 67void RecurBase::setFrequency( int f )
68{ 68{
69 if ( f < 1 ) f = 1; 69 if ( f < 1 ) f = 1;
70 70
71 mFrequencyEdit->setValue( f ); 71 mFrequencyEdit->setValue( f );
72} 72}
73 73
74int RecurBase::frequency() 74int RecurBase::frequency()
75{ 75{
76 return mFrequencyEdit->value(); 76 return mFrequencyEdit->value();
77} 77}
78 78
79/////////////////////////// RecurDaily /////////////////////////////// 79/////////////////////////// RecurDaily ///////////////////////////////
80 80
81RecurDaily::RecurDaily( QWidget *parent, const char *name ) : 81RecurDaily::RecurDaily( QWidget *parent, const char *name ) :
82 RecurBase( parent, name ) 82 RecurBase( parent, name )
83{ 83{
84 QBoxLayout *topLayout = new QHBoxLayout( this ); 84 QBoxLayout *topLayout = new QHBoxLayout( this );
85 topLayout->setSpacing( KDialog::spacingHint() ); 85 topLayout->setSpacing( KDialog::spacingHint() );
86 topLayout->setMargin( KDialog::marginHintSmall() ); 86 topLayout->setMargin( KDialog::marginHintSmall() );
87 87
88 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 88 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
89 topLayout->addWidget( preLabel ); 89 topLayout->addWidget( preLabel );
90 90
91 topLayout->addWidget( frequencyEdit() ); 91 topLayout->addWidget( frequencyEdit() );
92 92
93 QLabel *postLabel = new QLabel( i18n("day(s)"), this ); 93 QLabel *postLabel = new QLabel( i18n("day(s)"), this );
94 topLayout->addWidget( postLabel ); 94 topLayout->addWidget( postLabel );
95} 95}
96 96
97 97
98/////////////////////////// RecurWeekly /////////////////////////////// 98/////////////////////////// RecurWeekly ///////////////////////////////
99 99
100RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) : 100RecurWeekly::RecurWeekly( QWidget *parent, const char *name ) :
101 RecurBase( parent, name ) 101 RecurBase( parent, name )
102{ 102{
103 QBoxLayout *topLayout = new QVBoxLayout( this ); 103 QBoxLayout *topLayout = new QVBoxLayout( this );
104 topLayout->setSpacing( KDialog::spacingHint() ); 104 topLayout->setSpacing( KDialog::spacingHint() );
105 topLayout->setMargin( KDialog::marginHintSmall() ); 105 topLayout->setMargin( KDialog::marginHintSmall() );
106 106
107 //topLayout->addStretch( 1 ); 107 //topLayout->addStretch( 1 );
108 108
109 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout ); 109 QBoxLayout *weeksLayout = new QHBoxLayout( topLayout );
110 110
111 QLabel *preLabel = new QLabel( i18n("Recur every"), this ); 111 QLabel *preLabel = new QLabel( i18n("Recur every"), this );
112 weeksLayout->addWidget( preLabel ); 112 weeksLayout->addWidget( preLabel );
113 113
114 weeksLayout->addWidget( frequencyEdit() ); 114 weeksLayout->addWidget( frequencyEdit() );
115 115
116 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this ); 116 QLabel *postLabel = new QLabel( i18n("week(s) on:"), this );
117 weeksLayout->addWidget( postLabel ); 117 weeksLayout->addWidget( postLabel );
118 118
119 QHBox *dayBox = new QHBox( this ); 119 QHBox *dayBox = new QHBox( this );
120 topLayout->addWidget( dayBox, 1, AlignVCenter ); 120 topLayout->addWidget( dayBox, 1, AlignVCenter );
121 // TODO: Respect start of week setting 121 // TODO: Respect start of week setting
122 for ( int i = 0; i < 7; ++i ) { 122 for ( int i = 0; i < 7; ++i ) {
123 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true ); 123 QString weekDayName = KGlobal::locale()->weekDayName( i + 1, true );
124 int left = 1; 124 int left = 1;
125 if ( QApplication::desktop()->width() > 480 ) { 125 if ( QApplication::desktop()->width() > 480 ) {
126 ++left; 126 ++left;
127 if ( QApplication::desktop()->width() > 640 ) 127 if ( QApplication::desktop()->width() > 640 )
128 ++left; 128 ++left;
129 } 129 }
130 mDayBoxes[ i ] = new QCheckBox( weekDayName.left( left ), dayBox ); 130 mDayBoxes[ i ] = new QCheckBox( weekDayName.left( left ), dayBox );
131 } 131 }
132 132
133 topLayout->addStretch( ); 133 topLayout->addStretch( );
134} 134}
135 135
136void RecurWeekly::setDays( const QBitArray &days ) 136void RecurWeekly::setDays( const QBitArray &days )
137{ 137{
138 for ( int i = 0; i < 7; ++i ) { 138 for ( int i = 0; i < 7; ++i ) {
139 mDayBoxes[ i ]->setChecked( days.testBit( i ) ); 139 mDayBoxes[ i ]->setChecked( days.testBit( i ) );
140 } 140 }
141} 141}
142 142
143QBitArray RecurWeekly::days() 143QBitArray RecurWeekly::days()
144{ 144{
145 QBitArray days( 7 ); 145 QBitArray days( 7 );
146 146
147 for ( int i = 0; i < 7; ++i ) { 147 for ( int i = 0; i < 7; ++i ) {
148 days.setBit( i, mDayBoxes[ i ]->isChecked() ); 148 days.setBit( i, mDayBoxes[ i ]->isChecked() );
149 } 149 }
150 150
151 return days; 151 return days;
152} 152}
153 153
154/////////////////////////// RecurMonthly /////////////////////////////// 154/////////////////////////// RecurMonthly ///////////////////////////////
155 155
156RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) : 156RecurMonthly::RecurMonthly( QWidget *parent, const char *name ) :
157 RecurBase( parent, name ) 157 RecurBase( parent, name )
158{ 158{
159 QBoxLayout *topLayout = new QVBoxLayout( this ); 159 QBoxLayout *topLayout = new QVBoxLayout( this );
160 topLayout->setSpacing( KDialog::spacingHint() ); 160 topLayout->setSpacing( KDialog::spacingHint() );
161 topLayout->setMargin( KDialog::marginHintSmall() ); 161 topLayout->setMargin( KDialog::marginHintSmall() );
162 162
163 163
164 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 164 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
165 165
166 QLabel *preLabel = new QLabel( i18n("every"), this ); 166 QLabel *preLabel = new QLabel( i18n("every"), this );
167 freqLayout->addWidget( preLabel ); 167 freqLayout->addWidget( preLabel );
168 168
169 freqLayout->addWidget( frequencyEdit() ); 169 freqLayout->addWidget( frequencyEdit() );
170 170
171 QLabel *postLabel = new QLabel( i18n("month(s)"), this ); 171 QLabel *postLabel = new QLabel( i18n("month(s)"), this );
172 freqLayout->addWidget( postLabel ); 172 freqLayout->addWidget( postLabel );
173 173
174 174
175 QButtonGroup *buttonGroup = new QButtonGroup( this ); 175 QButtonGroup *buttonGroup = new QButtonGroup( this );
176 buttonGroup->setFrameStyle( QFrame::NoFrame ); 176 buttonGroup->setFrameStyle( QFrame::NoFrame );
177 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 177 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
178 178
179 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 ); 179 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 3, 2 );
180 buttonLayout->setSpacing( KDialog::spacingHint() ); 180 buttonLayout->setSpacing( KDialog::spacingHint() );
181 buttonLayout->setMargin( KDialog::marginHintSmall() ); 181 buttonLayout->setMargin( KDialog::marginHintSmall() );
182 182
183 183
184 QString recurOnText; 184 QString recurOnText;
185 if ( QApplication::desktop()->width() > 320 ) { 185 if ( QApplication::desktop()->width() > 320 ) {
186 recurOnText = i18n("Recur on the"); 186 recurOnText = i18n("Recur on the");
187 } 187 }
188 188
189 mByDayRadio = new QRadioButton( recurOnText, buttonGroup ); 189 mByDayRadio = new QRadioButton( recurOnText, buttonGroup );
190 buttonLayout->addWidget( mByDayRadio, 0, 0 ); 190 buttonLayout->addWidget( mByDayRadio, 0, 0 );
191 191
192 mByDayCombo = new QComboBox( buttonGroup ); 192 mByDayCombo = new QComboBox( buttonGroup );
193 mByDayCombo->setSizeLimit( 7 ); 193 mByDayCombo->setSizeLimit( 7 );
194 mByDayCombo->insertItem( i18n("1st") ); 194 mByDayCombo->insertItem( i18n("1st") );
195 mByDayCombo->insertItem( i18n("2nd") ); 195 mByDayCombo->insertItem( i18n("2nd") );
196 mByDayCombo->insertItem( i18n("3rd") ); 196 mByDayCombo->insertItem( i18n("3rd") );
197 mByDayCombo->insertItem( i18n("4th") ); 197 mByDayCombo->insertItem( i18n("4th") );
198 mByDayCombo->insertItem( i18n("5th") ); 198 mByDayCombo->insertItem( i18n("5th") );
199 mByDayCombo->insertItem( i18n("6th") ); 199 mByDayCombo->insertItem( i18n("6th") );
200 mByDayCombo->insertItem( i18n("7th") ); 200 mByDayCombo->insertItem( i18n("7th") );
201 mByDayCombo->insertItem( i18n("8th") ); 201 mByDayCombo->insertItem( i18n("8th") );
202 mByDayCombo->insertItem( i18n("9th") ); 202 mByDayCombo->insertItem( i18n("9th") );
203 mByDayCombo->insertItem( i18n("10th") ); 203 mByDayCombo->insertItem( i18n("10th") );
204 mByDayCombo->insertItem( i18n("11th") ); 204 mByDayCombo->insertItem( i18n("11th") );
205 mByDayCombo->insertItem( i18n("12th") ); 205 mByDayCombo->insertItem( i18n("12th") );
206 mByDayCombo->insertItem( i18n("13th") ); 206 mByDayCombo->insertItem( i18n("13th") );
207 mByDayCombo->insertItem( i18n("14th") ); 207 mByDayCombo->insertItem( i18n("14th") );
208 mByDayCombo->insertItem( i18n("15th") ); 208 mByDayCombo->insertItem( i18n("15th") );
209 mByDayCombo->insertItem( i18n("16th") ); 209 mByDayCombo->insertItem( i18n("16th") );
210 mByDayCombo->insertItem( i18n("17th") ); 210 mByDayCombo->insertItem( i18n("17th") );
211 mByDayCombo->insertItem( i18n("18th") ); 211 mByDayCombo->insertItem( i18n("18th") );
212 mByDayCombo->insertItem( i18n("19th") ); 212 mByDayCombo->insertItem( i18n("19th") );
213 mByDayCombo->insertItem( i18n("20th") ); 213 mByDayCombo->insertItem( i18n("20th") );
214 mByDayCombo->insertItem( i18n("21st") ); 214 mByDayCombo->insertItem( i18n("21st") );
215 mByDayCombo->insertItem( i18n("22nd") ); 215 mByDayCombo->insertItem( i18n("22nd") );
216 mByDayCombo->insertItem( i18n("23rd") ); 216 mByDayCombo->insertItem( i18n("23rd") );
217 mByDayCombo->insertItem( i18n("24th") ); 217 mByDayCombo->insertItem( i18n("24th") );
218 mByDayCombo->insertItem( i18n("25th") ); 218 mByDayCombo->insertItem( i18n("25th") );
219 mByDayCombo->insertItem( i18n("26th") ); 219 mByDayCombo->insertItem( i18n("26th") );
220 mByDayCombo->insertItem( i18n("27th") ); 220 mByDayCombo->insertItem( i18n("27th") );
221 mByDayCombo->insertItem( i18n("28th") ); 221 mByDayCombo->insertItem( i18n("28th") );
222 mByDayCombo->insertItem( i18n("29th") ); 222 mByDayCombo->insertItem( i18n("29th") );
223 mByDayCombo->insertItem( i18n("30th") ); 223 mByDayCombo->insertItem( i18n("30th") );
224 mByDayCombo->insertItem( i18n("31st") ); 224 mByDayCombo->insertItem( i18n("31st") );
225 buttonLayout->addWidget( mByDayCombo, 0, 1 ); 225 buttonLayout->addWidget( mByDayCombo, 0, 1 );
226 226
227 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup ); 227 QLabel *byDayLabel = new QLabel( i18n("day"), buttonGroup );
228 buttonLayout->addWidget( byDayLabel, 0, 2 ); 228 buttonLayout->addWidget( byDayLabel, 0, 2 );
229 229
230 230
231 mByPosRadio = new QRadioButton( recurOnText, buttonGroup); 231 mByPosRadio = new QRadioButton( recurOnText, buttonGroup);
232 buttonLayout->addWidget( mByPosRadio, 1, 0 ); 232 buttonLayout->addWidget( mByPosRadio, 1, 0 );
233 233
234 mByPosCountCombo = new QComboBox( buttonGroup ); 234 mByPosCountCombo = new QComboBox( buttonGroup );
235 mByPosCountCombo->insertItem( i18n("1st") ); 235 mByPosCountCombo->insertItem( i18n("1st") );
236 mByPosCountCombo->insertItem( i18n("2nd") ); 236 mByPosCountCombo->insertItem( i18n("2nd") );
237 mByPosCountCombo->insertItem( i18n("3rd") ); 237 mByPosCountCombo->insertItem( i18n("3rd") );
238 mByPosCountCombo->insertItem( i18n("4th") ); 238 mByPosCountCombo->insertItem( i18n("4th") );
239 mByPosCountCombo->insertItem( i18n("5th") ); 239 mByPosCountCombo->insertItem( i18n("5th") );
240 buttonLayout->addWidget( mByPosCountCombo, 1, 1 ); 240 buttonLayout->addWidget( mByPosCountCombo, 1, 1 );
241 241
242 mByPosWeekdayCombo = new QComboBox( buttonGroup ); 242 mByPosWeekdayCombo = new QComboBox( buttonGroup );
243 mByPosWeekdayCombo->insertItem( i18n("Monday") ); 243 mByPosWeekdayCombo->insertItem( i18n("Monday") );
244 mByPosWeekdayCombo->insertItem( i18n("Tuesday") ); 244 mByPosWeekdayCombo->insertItem( i18n("Tuesday") );
245 mByPosWeekdayCombo->insertItem( i18n("Wednesday") ); 245 mByPosWeekdayCombo->insertItem( i18n("Wednesday") );
246 mByPosWeekdayCombo->insertItem( i18n("Thursday") ); 246 mByPosWeekdayCombo->insertItem( i18n("Thursday") );
247 mByPosWeekdayCombo->insertItem( i18n("Friday") ); 247 mByPosWeekdayCombo->insertItem( i18n("Friday") );
248 mByPosWeekdayCombo->insertItem( i18n("Saturday") ); 248 mByPosWeekdayCombo->insertItem( i18n("Saturday") );
249 mByPosWeekdayCombo->insertItem( i18n("Sunday") ); 249 mByPosWeekdayCombo->insertItem( i18n("Sunday") );
250 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 ); 250 buttonLayout->addWidget( mByPosWeekdayCombo, 1, 2 );
251} 251}
252 252
253void RecurMonthly::setByDay( int day ) 253void RecurMonthly::setByDay( int day )
254{ 254{
255 mByDayRadio->setChecked( true ); 255 mByDayRadio->setChecked( true );
256 mByDayCombo->setCurrentItem( day ); 256 mByDayCombo->setCurrentItem( day );
257} 257}
258 258
259void RecurMonthly::setByPos( int count, int weekday ) 259void RecurMonthly::setByPos( int count, int weekday )
260{ 260{
261 mByPosRadio->setChecked( true ); 261 mByPosRadio->setChecked( true );
262 mByPosCountCombo->setCurrentItem( count ); 262 mByPosCountCombo->setCurrentItem( count );
263 mByPosWeekdayCombo->setCurrentItem( weekday ); 263 mByPosWeekdayCombo->setCurrentItem( weekday );
264} 264}
265 265
266bool RecurMonthly::byDay() 266bool RecurMonthly::byDay()
267{ 267{
268 return mByDayRadio->isChecked(); 268 return mByDayRadio->isChecked();
269} 269}
270 270
271bool RecurMonthly::byPos() 271bool RecurMonthly::byPos()
272{ 272{
273 return mByPosRadio->isChecked(); 273 return mByPosRadio->isChecked();
274} 274}
275 275
276int RecurMonthly::day() 276int RecurMonthly::day()
277{ 277{
278 return mByDayCombo->currentItem() + 1; 278 return mByDayCombo->currentItem() + 1;
279} 279}
280 280
281int RecurMonthly::count() 281int RecurMonthly::count()
282{ 282{
283 return mByPosCountCombo->currentItem() + 1; 283 return mByPosCountCombo->currentItem() + 1;
284} 284}
285 285
286int RecurMonthly::weekday() 286int RecurMonthly::weekday()
287{ 287{
288 return mByPosWeekdayCombo->currentItem(); 288 return mByPosWeekdayCombo->currentItem();
289} 289}
290 290
291/////////////////////////// RecurYearly /////////////////////////////// 291/////////////////////////// RecurYearly ///////////////////////////////
292 292
293RecurYearly::RecurYearly( QWidget *parent, const char *name ) : 293RecurYearly::RecurYearly( QWidget *parent, const char *name ) :
294 RecurBase( parent, name ) 294 RecurBase( parent, name )
295{ 295{
296 QBoxLayout *topLayout = new QVBoxLayout( this ); 296 QBoxLayout *topLayout = new QVBoxLayout( this );
297 topLayout->setSpacing( KDialog::spacingHint() ); 297 topLayout->setSpacing( KDialog::spacingHint() );
298 topLayout->setMargin( KDialog::marginHintSmall() ); 298 topLayout->setMargin( KDialog::marginHintSmall() );
299 299
300 300
301 QBoxLayout *freqLayout = new QHBoxLayout( topLayout ); 301 QBoxLayout *freqLayout = new QHBoxLayout( topLayout );
302 302
303 QLabel *preLabel = new QLabel( i18n("every"), this ); 303 QLabel *preLabel = new QLabel( i18n("every"), this );
304 freqLayout->addWidget( preLabel ); 304 freqLayout->addWidget( preLabel );
305 305
306 freqLayout->addWidget( frequencyEdit() ); 306 freqLayout->addWidget( frequencyEdit() );
307 307
308 QLabel *postLabel = new QLabel( i18n("year(s)"), this ); 308 QLabel *postLabel = new QLabel( i18n("year(s)"), this );
309 freqLayout->addWidget( postLabel ); 309 freqLayout->addWidget( postLabel );
310 310
311 311
312 QButtonGroup *buttonGroup = new QButtonGroup( this ); 312 QButtonGroup *buttonGroup = new QButtonGroup( this );
313 buttonGroup->setFrameStyle( QFrame::NoFrame ); 313 buttonGroup->setFrameStyle( QFrame::NoFrame );
314 topLayout->addWidget( buttonGroup, 1, AlignVCenter ); 314 topLayout->addWidget( buttonGroup, 1, AlignVCenter );
315 315
316 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 ); 316 QGridLayout *buttonLayout = new QGridLayout( buttonGroup, 2, 3 );
317 317
318 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup); 318 mByMonthRadio = new QRadioButton( i18n("On day "), buttonGroup);
319 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight); 319 buttonLayout->addWidget( mByMonthRadio, 0, 0 , Qt::AlignRight);
320 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup ); 320 mByDayLabel = new QLabel( i18n("%1 of ").arg(1), buttonGroup );
321 321
322 buttonLayout->addWidget( mByDayLabel, 0, 1 ); 322 buttonLayout->addWidget( mByDayLabel, 0, 1 );
323 mByMonthCombo = new QComboBox( buttonGroup ); 323 mByMonthCombo = new QComboBox( buttonGroup );
324 mByMonthCombo->insertItem( i18n("January") ); 324 mByMonthCombo->insertItem( i18n("January") );
325 mByMonthCombo->insertItem( i18n("February") ); 325 mByMonthCombo->insertItem( i18n("February") );
326 mByMonthCombo->insertItem( i18n("March") ); 326 mByMonthCombo->insertItem( i18n("March") );
327 mByMonthCombo->insertItem( i18n("April") ); 327 mByMonthCombo->insertItem( i18n("April") );
328 mByMonthCombo->insertItem( i18n("May") ); 328 mByMonthCombo->insertItem( i18n("May") );
329 mByMonthCombo->insertItem( i18n("June") ); 329 mByMonthCombo->insertItem( i18n("June") );
330 mByMonthCombo->insertItem( i18n("July") ); 330 mByMonthCombo->insertItem( i18n("July") );
331 mByMonthCombo->insertItem( i18n("August") ); 331 mByMonthCombo->insertItem( i18n("August") );
332 mByMonthCombo->insertItem( i18n("September") ); 332 mByMonthCombo->insertItem( i18n("September") );
333 mByMonthCombo->insertItem( i18n("October") ); 333 mByMonthCombo->insertItem( i18n("October") );
334 mByMonthCombo->insertItem( i18n("November") ); 334 mByMonthCombo->insertItem( i18n("November") );
335 mByMonthCombo->insertItem( i18n("December") ); 335 mByMonthCombo->insertItem( i18n("December") );
336 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft ); 336 buttonLayout->addWidget( mByMonthCombo, 0, 2,Qt::AlignLeft );
337 if ( QApplication::desktop()->width() <= 640 ) { 337 if ( QApplication::desktop()->width() <= 640 ) {
338 mByMonthCombo->setSizeLimit( 6 ); 338 mByMonthCombo->setSizeLimit( 6 );
339 } 339 }
340 340
341 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup); 341 mByDayRadio = new QRadioButton( i18n("On day "), buttonGroup);
342 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight); 342 buttonLayout->addWidget( mByDayRadio, 1, 0 , Qt::AlignRight);
343 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup ); 343 mDayOfLabel = new QLabel( i18n("%1 of the year").arg(1), buttonGroup );
344 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 ); 344 buttonLayout->addMultiCellWidget( mDayOfLabel, 1, 1, 1,3 );
345 345
346} 346}
347 347
348void RecurYearly::setByDay( int doy ) 348void RecurYearly::setByDay( int doy )
349{ 349{
350 mByDayRadio->setChecked( true ); 350 mByDayRadio->setChecked( true );
351 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) ); 351 mDayOfLabel->setText(i18n("%1 of the year").arg( doy ) );
352} 352}
353 353
354void RecurYearly::setByMonth( int month, int day ) 354void RecurYearly::setByMonth( int month, int day )
355{ 355{
356 mByMonthRadio->setChecked( true ); 356 mByMonthRadio->setChecked( true );
357 mByMonthCombo->setCurrentItem( month - 1 ); 357 mByMonthCombo->setCurrentItem( month - 1 );
358 mByDayLabel->setText(i18n("%1 of ").arg( day ) ); 358 mByDayLabel->setText(i18n("%1 of ").arg( day ) );
359 mDay = day; 359 mDay = day;
360} 360}
361 361
362bool RecurYearly::byMonth() 362bool RecurYearly::byMonth()
363{ 363{
364 return mByMonthRadio->isChecked(); 364 return mByMonthRadio->isChecked();
365} 365}
366 366
367bool RecurYearly::byDay() 367bool RecurYearly::byDay()
368{ 368{
369 return mByDayRadio->isChecked(); 369 return mByDayRadio->isChecked();
370} 370}
371 371
372int RecurYearly::month() 372int RecurYearly::month()
373{ 373{
374 return mByMonthCombo->currentItem() + 1; 374 return mByMonthCombo->currentItem() + 1;
375} 375}
376int RecurYearly::day() 376int RecurYearly::day()
377{ 377{
378 return mDay;//mByDayCombo->currentItem() + 1; 378 return mDay;//mByDayCombo->currentItem() + 1;
379} 379}
380 380
381//////////////////////////// ExceptionsWidget ////////////////////////// 381//////////////////////////// ExceptionsWidget //////////////////////////
382 382
383ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) : 383ExceptionsWidget::ExceptionsWidget( QWidget *parent, const char *name ) :
384 QWidget( parent, name ) 384 QWidget( parent, name )
385{ 385{
386 QBoxLayout *topLayout = new QVBoxLayout( this ); 386 QBoxLayout *topLayout = new QVBoxLayout( this );
387 387
388 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"), 388 QGroupBox *groupBox = new QGroupBox( 1, Horizontal, i18n("Exceptions"),
389 this ); 389 this );
390 topLayout->addWidget( groupBox ); 390 topLayout->addWidget( groupBox );
391 391
392 QWidget *box = new QWidget( groupBox ); 392 QWidget *box = new QWidget( groupBox );
393 393
394 QGridLayout *boxLayout = new QGridLayout( box ); 394 QGridLayout *boxLayout = new QGridLayout( box );
395 395
396 mExceptionDateEdit = new KDateEdit( box ); 396 mExceptionDateEdit = new KDateEdit( box );
397 boxLayout->addWidget( mExceptionDateEdit, 0, 0 ); 397 boxLayout->addWidget( mExceptionDateEdit, 0, 0 );
398 398
399 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box ); 399 QPushButton *addExceptionButton = new QPushButton( i18n("Add"), box );
400 boxLayout->addWidget( addExceptionButton, 1, 0 ); 400 boxLayout->addWidget( addExceptionButton, 1, 0 );
401 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box ); 401 QPushButton *changeExceptionButton = new QPushButton( i18n("Change"), box );
402 boxLayout->addWidget( changeExceptionButton, 2, 0 ); 402 boxLayout->addWidget( changeExceptionButton, 2, 0 );
403 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box ); 403 QPushButton *deleteExceptionButton = new QPushButton( i18n("Delete"), box );
404 boxLayout->addWidget( deleteExceptionButton, 3, 0 ); 404 boxLayout->addWidget( deleteExceptionButton, 3, 0 );
405 405
406 mExceptionList = new QListBox( box ); 406 mExceptionList = new QListBox( box );
407 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 ); 407 boxLayout->addMultiCellWidget( mExceptionList, 0, 3, 1, 1 );
408 408
409 boxLayout->setRowStretch( 4, 1 ); 409 boxLayout->setRowStretch( 4, 1 );
410 boxLayout->setColStretch( 1, 3 ); 410 boxLayout->setColStretch( 1, 3 );
411 411
412 connect( addExceptionButton, SIGNAL( clicked() ), 412 connect( addExceptionButton, SIGNAL( clicked() ),
413 SLOT( addException() ) ); 413 SLOT( addException() ) );
414 connect( changeExceptionButton, SIGNAL( clicked() ), 414 connect( changeExceptionButton, SIGNAL( clicked() ),
415 SLOT( changeException() ) ); 415 SLOT( changeException() ) );
416 connect( deleteExceptionButton, SIGNAL( clicked() ), 416 connect( deleteExceptionButton, SIGNAL( clicked() ),
417 SLOT( deleteException() ) ); 417 SLOT( deleteException() ) );
418 if ( QApplication::desktop()->width() < 480 ) { 418 if ( QApplication::desktop()->width() < 480 ) {
419 setMinimumWidth( 220 ); 419 setMinimumWidth( 220 );
420 } else { 420 } else {
421 setMinimumWidth( 440 ); 421 setMinimumWidth( 440 );
422 mExceptionDateEdit->setMinimumWidth( 200 ); 422 mExceptionDateEdit->setMinimumWidth( 200 );
423 } 423 }
424} 424}
425 425
426void ExceptionsWidget::setDefaults( const QDateTime &from ) 426void ExceptionsWidget::setDefaults( const QDateTime &from )
427{ 427{
428 mExceptionDateEdit->setDate( from.date() ); 428 mExceptionDateEdit->setDate( from.date() );
429} 429}
430 430
431void ExceptionsWidget::addException() 431void ExceptionsWidget::addException()
432{ 432{
433 QDate date = mExceptionDateEdit->date(); 433 QDate date = mExceptionDateEdit->date();
434 QString dateStr = KGlobal::locale()->formatDate( date ); 434 QString dateStr = KGlobal::locale()->formatDate( date );
435 if( !mExceptionList->findItem( dateStr ) ) { 435 if( !mExceptionList->findItem( dateStr ) ) {
436 mExceptionDates.append( date ); 436 mExceptionDates.append( date );
437 mExceptionList->insertItem( dateStr ); 437 mExceptionList->insertItem( dateStr );
438 } 438 }
439} 439}
440 440
441void ExceptionsWidget::changeException() 441void ExceptionsWidget::changeException()
442{ 442{
443 int pos = mExceptionList->currentItem(); 443 int pos = mExceptionList->currentItem();
444 if ( pos < 0 ) return; 444 if ( pos < 0 ) return;
445 445
446 QDate date = mExceptionDateEdit->date(); 446 QDate date = mExceptionDateEdit->date();
447 mExceptionDates[ pos ] = date; 447 mExceptionDates[ pos ] = date;
448 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos ); 448 mExceptionList->changeItem( KGlobal::locale()->formatDate( date ), pos );
449} 449}
450 450
451void ExceptionsWidget::deleteException() 451void ExceptionsWidget::deleteException()
452{ 452{
453 int pos = mExceptionList->currentItem(); 453 int pos = mExceptionList->currentItem();
454 if ( pos < 0 ) return; 454 if ( pos < 0 ) return;
455 455
456 mExceptionDates.remove( mExceptionDates.at( pos ) ); 456 mExceptionDates.remove( mExceptionDates.at( pos ) );
457 mExceptionList->removeItem( pos ); 457 mExceptionList->removeItem( pos );
458} 458}
459 459
460void ExceptionsWidget::setDates( const DateList &dates ) 460void ExceptionsWidget::setDates( const DateList &dates )
461{ 461{
462 mExceptionList->clear(); 462 mExceptionList->clear();
463 mExceptionDates.clear(); 463 mExceptionDates.clear();
464 DateList::ConstIterator dit; 464 DateList::ConstIterator dit;
465 for ( dit = dates.begin(); dit != dates.end(); ++dit ) { 465 for ( dit = dates.begin(); dit != dates.end(); ++dit ) {
466 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) ); 466 mExceptionList->insertItem( KGlobal::locale()->formatDate(* dit ) );
467 mExceptionDates.append( *dit ); 467 mExceptionDates.append( *dit );
468 } 468 }
469} 469}
470 470
471DateList ExceptionsWidget::dates() 471DateList ExceptionsWidget::dates()
472{ 472{
473 return mExceptionDates; 473 return mExceptionDates;
474} 474}
475 475
476///////////////////////// ExceptionsDialog /////////////////////////// 476///////////////////////// ExceptionsDialog ///////////////////////////
477 477
478ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) : 478ExceptionsDialog::ExceptionsDialog( QWidget *parent, const char *name ) :
479 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel ) 479 KDialogBase( parent, name, true, i18n("Edit exceptions"), Ok|Cancel )
480{ 480{
481 mExceptions = new ExceptionsWidget( this ); 481 mExceptions = new ExceptionsWidget( this );
482 setMainWidget( mExceptions ); 482 setMainWidget( mExceptions );
483 resize(220,10); 483 resize(220,10);
484} 484}
485 485
486void ExceptionsDialog::setDefaults( const QDateTime &from ) 486void ExceptionsDialog::setDefaults( const QDateTime &from )
487{ 487{
488 mExceptions->setDefaults( from ); 488 mExceptions->setDefaults( from );
489} 489}
490 490
491void ExceptionsDialog::setDates( const DateList &dates ) 491void ExceptionsDialog::setDates( const DateList &dates )
492{ 492{
493 mExceptions->setDates( dates ); 493 mExceptions->setDates( dates );
494} 494}
495 495
496DateList ExceptionsDialog::dates() 496DateList ExceptionsDialog::dates()
497{ 497{
498 return mExceptions->dates(); 498 return mExceptions->dates();
499} 499}
500 500
501///////////////////////// RecurrenceRangeWidget /////////////////////////// 501///////////////////////// RecurrenceRangeWidget ///////////////////////////
502 502
503RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent, 503RecurrenceRangeWidget::RecurrenceRangeWidget( QWidget *parent,
504 const char *name ) 504 const char *name )
505 : QWidget( parent, name ) 505 : QWidget( parent, name )
506{ 506{
507 QBoxLayout *topLayout = new QVBoxLayout( this ); 507 QBoxLayout *topLayout = new QVBoxLayout( this );
508 508
509 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"), 509 mRangeGroupBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Range"),
510 this ); 510 this );
511 topLayout->addWidget( mRangeGroupBox ); 511 topLayout->addWidget( mRangeGroupBox );
512 512
513 QWidget *rangeBox = new QWidget( mRangeGroupBox ); 513 QWidget *rangeBox = new QWidget( mRangeGroupBox );
514 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox ); 514 QVBoxLayout *rangeLayout = new QVBoxLayout( rangeBox );
515 rangeLayout->setSpacing( KDialog::spacingHint() ); 515 rangeLayout->setSpacing( KDialog::spacingHint() );
516 rangeLayout->setMargin( KDialog::marginHintSmall() ); 516 rangeLayout->setMargin( KDialog::marginHintSmall() );
517 517
518 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox ); 518 mStartDateLabel = new QLabel( i18n("Begin on:"), rangeBox );
519 rangeLayout->addWidget( mStartDateLabel ); 519 rangeLayout->addWidget( mStartDateLabel );
520 520
521 QButtonGroup *rangeButtonGroup = new QButtonGroup; 521 mRangeButtonGroup = new QButtonGroup;
522 522
523 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox ); 523 mNoEndDateButton = new QRadioButton( i18n("No ending date"), rangeBox );
524 rangeButtonGroup->insert( mNoEndDateButton ); 524 mRangeButtonGroup->insert( mNoEndDateButton );
525 rangeLayout->addWidget( mNoEndDateButton ); 525 rangeLayout->addWidget( mNoEndDateButton );
526 526
527 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout ); 527 QBoxLayout *durationLayout = new QHBoxLayout( rangeLayout );
528 durationLayout->setSpacing( KDialog::spacingHint() ); 528 durationLayout->setSpacing( KDialog::spacingHint() );
529 529
530 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox ); 530 mEndDurationButton = new QRadioButton( i18n("End after"), rangeBox );
531 rangeButtonGroup->insert( mEndDurationButton ); 531 mRangeButtonGroup->insert( mEndDurationButton );
532 durationLayout->addWidget( mEndDurationButton ); 532 durationLayout->addWidget( mEndDurationButton );
533 533
534 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox ); 534 mEndDurationEdit = new QSpinBox( 1, 9999, 1, rangeBox );
535 durationLayout->addWidget( mEndDurationEdit ); 535 durationLayout->addWidget( mEndDurationEdit );
536 536
537 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox ); 537 QLabel *endDurationLabel = new QLabel( i18n("occurrence(s)"), rangeBox );
538 durationLayout ->addWidget( endDurationLabel ); 538 durationLayout ->addWidget( endDurationLabel );
539 539
540 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout ); 540 QBoxLayout *endDateLayout = new QHBoxLayout( rangeLayout );
541 endDateLayout->setSpacing( KDialog::spacingHint() ); 541 endDateLayout->setSpacing( KDialog::spacingHint() );
542 542
543 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox ); 543 mEndDateButton = new QRadioButton( i18n("End by:"), rangeBox );
544 rangeButtonGroup->insert( mEndDateButton ); 544 mRangeButtonGroup->insert( mEndDateButton );
545 endDateLayout->addWidget( mEndDateButton ); 545 endDateLayout->addWidget( mEndDateButton );
546 546
547 mEndDateEdit = new KDateEdit( rangeBox ); 547 mEndDateEdit = new KDateEdit( rangeBox );
548 endDateLayout->addWidget( mEndDateEdit ); 548 endDateLayout->addWidget( mEndDateEdit );
549 549
550 //endDateLayout->addStretch( 1 ); 550 //endDateLayout->addStretch( 1 );
551 551
552 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ), 552 connect( mNoEndDateButton, SIGNAL( toggled( bool ) ),
553 SLOT( showCurrentRange() ) ); 553 SLOT( showCurrentRange() ) );
554 connect( mEndDurationButton, SIGNAL( toggled( bool ) ), 554 connect( mEndDurationButton, SIGNAL( toggled( bool ) ),
555 SLOT( showCurrentRange() ) ); 555 SLOT( showCurrentRange() ) );
556 connect( mEndDateButton, SIGNAL( toggled( bool ) ), 556 connect( mEndDateButton, SIGNAL( toggled( bool ) ),
557 SLOT( showCurrentRange() ) ); 557 SLOT( showCurrentRange() ) );
558} 558}
559 559
560RecurrenceRangeWidget::~RecurrenceRangeWidget()
561{
562 delete mRangeButtonGroup;
563}
560void RecurrenceRangeWidget::setDefaults( const QDateTime &from ) 564void RecurrenceRangeWidget::setDefaults( const QDateTime &from )
561{ 565{
562 mNoEndDateButton->setChecked( true ); 566 mNoEndDateButton->setChecked( true );
563 567
564 setDateTimes( from ); 568 setDateTimes( from );
565 mEndDateEdit->setDate( from.date() ); 569 mEndDateEdit->setDate( from.date() );
566} 570}
567 571
568void RecurrenceRangeWidget::setDuration( int duration ) 572void RecurrenceRangeWidget::setDuration( int duration )
569{ 573{
570 if ( duration == -1 ) { 574 if ( duration == -1 ) {
571 mNoEndDateButton->setChecked( true ); 575 mNoEndDateButton->setChecked( true );
572 } else if ( duration == 0 ) { 576 } else if ( duration == 0 ) {
573 mEndDateButton->setChecked( true ); 577 mEndDateButton->setChecked( true );
574 } else { 578 } else {
575 mEndDurationButton->setChecked( true ); 579 mEndDurationButton->setChecked( true );
576 mEndDurationEdit->setValue( duration ); 580 mEndDurationEdit->setValue( duration );
577 } 581 }
578} 582}
579 583
580int RecurrenceRangeWidget::duration() 584int RecurrenceRangeWidget::duration()
581{ 585{
582 if ( mNoEndDateButton->isChecked() ) { 586 if ( mNoEndDateButton->isChecked() ) {
583 return -1; 587 return -1;
584 } else if ( mEndDurationButton->isChecked() ) { 588 } else if ( mEndDurationButton->isChecked() ) {
585 return mEndDurationEdit->value(); 589 return mEndDurationEdit->value();
586 } else { 590 } else {
587 return 0; 591 return 0;
588 } 592 }
589} 593}
590 594
591void RecurrenceRangeWidget::setEndDate( const QDate &date ) 595void RecurrenceRangeWidget::setEndDate( const QDate &date )
592{ 596{
593 mEndDateEdit->setDate( date ); 597 mEndDateEdit->setDate( date );
594} 598}
595 599
596QDate RecurrenceRangeWidget::endDate() 600QDate RecurrenceRangeWidget::endDate()
597{ 601{
598 return mEndDateEdit->date(); 602 return mEndDateEdit->date();
599} 603}
600 604
601void RecurrenceRangeWidget::showCurrentRange() 605void RecurrenceRangeWidget::showCurrentRange()
602{ 606{
603 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() ); 607 mEndDurationEdit->setEnabled( mEndDurationButton->isChecked() );
604 mEndDateEdit->setEnabled( mEndDateButton->isChecked() ); 608 mEndDateEdit->setEnabled( mEndDateButton->isChecked() );
605} 609}
606 610
607void RecurrenceRangeWidget::setDateTimes( const QDateTime &start, 611void RecurrenceRangeWidget::setDateTimes( const QDateTime &start,
608 const QDateTime & ) 612 const QDateTime & )
609{ 613{
610 mStartDateLabel->setText( i18n("Start date: %1") 614 mStartDateLabel->setText( i18n("Start date: %1")
611 .arg( KGlobal::locale()->formatDate( start.date() ) ) ); 615 .arg( KGlobal::locale()->formatDate( start.date() ) ) );
612 616
613 if(!mEndDateButton->isChecked()) 617 if(!mEndDateButton->isChecked())
614 mEndDateEdit->setDate( start.date() ); 618 mEndDateEdit->setDate( start.date() );
615} 619}
616 620
617///////////////////////// RecurrenceRangeDialog /////////////////////////// 621///////////////////////// RecurrenceRangeDialog ///////////////////////////
618 622
619RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent, 623RecurrenceRangeDialog::RecurrenceRangeDialog( QWidget *parent,
620 const char *name ) : 624 const char *name ) :
621 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel ) 625 KDialogBase( parent, name, true, i18n("Edit Recurrence Range"), Ok|Cancel )
622{ 626{
623 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this ); 627 mRecurrenceRangeWidget = new RecurrenceRangeWidget( this );
624 setMainWidget( mRecurrenceRangeWidget ); 628 setMainWidget( mRecurrenceRangeWidget );
625} 629}
626 630
627void RecurrenceRangeDialog::setDefaults( const QDateTime &from ) 631void RecurrenceRangeDialog::setDefaults( const QDateTime &from )
628{ 632{
629 mRecurrenceRangeWidget->setDefaults( from ); 633 mRecurrenceRangeWidget->setDefaults( from );
630} 634}
631 635
632void RecurrenceRangeDialog::setDuration( int duration ) 636void RecurrenceRangeDialog::setDuration( int duration )
633{ 637{
634 mRecurrenceRangeWidget->setDuration( duration ); 638 mRecurrenceRangeWidget->setDuration( duration );
635} 639}
636 640
637int RecurrenceRangeDialog::duration() 641int RecurrenceRangeDialog::duration()
638{ 642{
639 return mRecurrenceRangeWidget->duration(); 643 return mRecurrenceRangeWidget->duration();
640} 644}
641 645
642void RecurrenceRangeDialog::setEndDate( const QDate &date ) 646void RecurrenceRangeDialog::setEndDate( const QDate &date )
643{ 647{
644 mRecurrenceRangeWidget->setEndDate( date ); 648 mRecurrenceRangeWidget->setEndDate( date );
645} 649}
646 650
647QDate RecurrenceRangeDialog::endDate() 651QDate RecurrenceRangeDialog::endDate()
648{ 652{
649 return mRecurrenceRangeWidget->endDate(); 653 return mRecurrenceRangeWidget->endDate();
650} 654}
651 655
652void RecurrenceRangeDialog::setDateTimes( const QDateTime &start, 656void RecurrenceRangeDialog::setDateTimes( const QDateTime &start,
653 const QDateTime &end ) 657 const QDateTime &end )
654{ 658{
655 mRecurrenceRangeWidget->setDateTimes( start, end ); 659 mRecurrenceRangeWidget->setDateTimes( start, end );
656} 660}
657 661
658//////////////////////////// RecurrenceChooser //////////////////////// 662//////////////////////////// RecurrenceChooser ////////////////////////
659 663
660RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) : 664RecurrenceChooser::RecurrenceChooser( QWidget *parent, const char *name ) :
661 QWidget( parent, name ) 665 QWidget( parent, name )
662{ 666{
663 QBoxLayout *topLayout = new QVBoxLayout( this ); 667 QBoxLayout *topLayout = new QVBoxLayout( this );
664 668
665 mTypeCombo = new QComboBox( this ); 669 mTypeCombo = new QComboBox( this );
666 mTypeCombo->insertItem( i18n("Daily") ); 670 mTypeCombo->insertItem( i18n("Daily") );
667 mTypeCombo->insertItem( i18n("Weekly") ); 671 mTypeCombo->insertItem( i18n("Weekly") );
668 mTypeCombo->insertItem( i18n("Monthly") ); 672 mTypeCombo->insertItem( i18n("Monthly") );
669 mTypeCombo->insertItem( i18n("Yearly") ); 673 mTypeCombo->insertItem( i18n("Yearly") );
670 674
671 topLayout->addWidget( mTypeCombo ); 675 topLayout->addWidget( mTypeCombo );
672 676
673 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) ); 677 connect( mTypeCombo, SIGNAL( activated( int ) ), SLOT( emitChoice() ) );
674 678
675} 679}
676 680
677int RecurrenceChooser::type() 681int RecurrenceChooser::type()
678{ 682{
679 if ( mTypeCombo ) { 683 if ( mTypeCombo ) {
680 return mTypeCombo->currentItem(); 684 return mTypeCombo->currentItem();
681 } else { 685 } else {
682 if ( mDailyButton->isChecked() ) return Daily; 686 if ( mDailyButton->isChecked() ) return Daily;
683 else if ( mWeeklyButton->isChecked() ) return Weekly; 687 else if ( mWeeklyButton->isChecked() ) return Weekly;
684 else if ( mMonthlyButton->isChecked() ) return Monthly; 688 else if ( mMonthlyButton->isChecked() ) return Monthly;
685 else return Yearly; 689 else return Yearly;
686 } 690 }
687} 691}
688 692
689void RecurrenceChooser::setType( int type ) 693void RecurrenceChooser::setType( int type )
690{ 694{
691 if ( mTypeCombo ) { 695 if ( mTypeCombo ) {
692 mTypeCombo->setCurrentItem( type ); 696 mTypeCombo->setCurrentItem( type );
693 } else { 697 } else {
694 switch ( type ) { 698 switch ( type ) {
695 case Daily: 699 case Daily:
696 mDailyButton->setChecked( true ); 700 mDailyButton->setChecked( true );
697 break; 701 break;
698 case Weekly: 702 case Weekly:
699 mWeeklyButton->setChecked( true ); 703 mWeeklyButton->setChecked( true );
700 break; 704 break;
701 case Monthly: 705 case Monthly:
702 mMonthlyButton->setChecked( true ); 706 mMonthlyButton->setChecked( true );
703 break; 707 break;
704 case Yearly: 708 case Yearly:
705 default: 709 default:
706 mYearlyButton->setChecked( true ); 710 mYearlyButton->setChecked( true );
707 break; 711 break;
708 } 712 }
709 } 713 }
710} 714}
711 715
712void RecurrenceChooser::emitChoice() 716void RecurrenceChooser::emitChoice()
713{ 717{
714 emit chosen ( type() ); 718 emit chosen ( type() );
715} 719}
716 720
717/////////////////////////////// Main Widget ///////////////////////////// 721/////////////////////////////// Main Widget /////////////////////////////
718 722
719KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) : 723KOEditorRecurrence::KOEditorRecurrence( QWidget* parent, const char *name ) :
720 QWidget( parent, name ) 724 QWidget( parent, name )
721{ 725{
722 QGridLayout *topLayout = new QGridLayout( this, 2,2 ); 726 QGridLayout *topLayout = new QGridLayout( this, 2,2 );
723 topLayout->setSpacing( KDialog::spacingHint() ); 727 topLayout->setSpacing( KDialog::spacingHint() );
724 topLayout->setMargin( KDialog::marginHintSmall() ); 728 topLayout->setMargin( KDialog::marginHintSmall() );
725 729
726 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this ); 730 mEnabledCheck = new QCheckBox( i18n("Enable Recurrence"), this );
727 connect( mEnabledCheck, SIGNAL( toggled( bool ) ), 731 connect( mEnabledCheck, SIGNAL( toggled( bool ) ),
728 SLOT( setEnabled( bool ) ) ); 732 SLOT( setEnabled( bool ) ) );
729 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 ); 733 topLayout->addMultiCellWidget( mEnabledCheck, 0, 0, 0, 1 );
730 734
731 735
732 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"), 736 mTimeGroupBox = new QGroupBox( 1, Horizontal, i18n("Time"),
733 this ); 737 this );
734 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 ); 738 topLayout->addMultiCellWidget( mTimeGroupBox, 1, 1 , 0 , 1 );
735 739
736 if ( QApplication::desktop()->width() <= 640 ) { 740 if ( QApplication::desktop()->width() <= 640 ) {
737 mTimeGroupBox->hide(); 741 mTimeGroupBox->hide();
738 } 742 }
739 743
740// QFrame *timeFrame = new QFrame( mTimeGroupBox ); 744// QFrame *timeFrame = new QFrame( mTimeGroupBox );
741// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame ); 745// QBoxLayout *layoutTimeFrame = new QHBoxLayout( timeFrame );
742// layoutTimeFrame->setSpacing( KDialog::spacingHint() ); 746// layoutTimeFrame->setSpacing( KDialog::spacingHint() );
743 747
744 mDateTimeLabel = new QLabel( mTimeGroupBox ); 748 mDateTimeLabel = new QLabel( mTimeGroupBox );
745// mDateTimeLabel = new QLabel( timeFrame ); 749// mDateTimeLabel = new QLabel( timeFrame );
746// layoutTimeFrame->addWidget( mDateTimeLabel ); 750// layoutTimeFrame->addWidget( mDateTimeLabel );
747 //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); 751 //mTimeGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
748 //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) ); 752 //mDateTimeLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum) );
749 mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this ); 753 mRuleBox = new QGroupBox( 1, Horizontal, i18n("Recurrence Rule"), this );
750 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 ); 754 topLayout->addMultiCellWidget( mRuleBox, 2, 2, 0, 1 );
751 mRecurrenceChooser = new RecurrenceChooser( mRuleBox ); 755 mRecurrenceChooser = new RecurrenceChooser( mRuleBox );
752 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ), 756 connect( mRecurrenceChooser, SIGNAL( chosen( int ) ),
753 SLOT( showCurrentRule( int ) ) ); 757 SLOT( showCurrentRule( int ) ) );
754 758
755 759
756 mRuleStack = new QWidgetStack( mRuleBox ); 760 mRuleStack = new QWidgetStack( mRuleBox );
757 761
758 mDaily = new RecurDaily( mRuleStack ); 762 mDaily = new RecurDaily( mRuleStack );
759 mRuleStack->addWidget( mDaily, 0 ); 763 mRuleStack->addWidget( mDaily, 0 );
760 764
761 mWeekly = new RecurWeekly( mRuleStack ); 765 mWeekly = new RecurWeekly( mRuleStack );
762 mRuleStack->addWidget( mWeekly, 0 ); 766 mRuleStack->addWidget( mWeekly, 0 );
763 767
764 mMonthly = new RecurMonthly( mRuleStack ); 768 mMonthly = new RecurMonthly( mRuleStack );
765 mRuleStack->addWidget( mMonthly, 0 ); 769 mRuleStack->addWidget( mMonthly, 0 );
766 770
767 mYearly = new RecurYearly( mRuleStack ); 771 mYearly = new RecurYearly( mRuleStack );
768 mRuleStack->addWidget( mYearly, 0 ); 772 mRuleStack->addWidget( mYearly, 0 );
769 773
770 showCurrentRule( mRecurrenceChooser->type() ); 774 showCurrentRule( mRecurrenceChooser->type() );
771 mRecurrenceRangeWidget = 0; 775 mRecurrenceRangeWidget = 0;
772 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this ); 776 mRecurrenceRangeDialog = new RecurrenceRangeDialog( this );
773 mRecurrenceRange = mRecurrenceRangeDialog; 777 mRecurrenceRange = mRecurrenceRangeDialog;
774 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."), 778 mRecurrenceRangeButton = new QPushButton( i18n("Recurrence Range..."),
775 this ); 779 this );
776 780
777 connect( mRecurrenceRangeButton, SIGNAL( clicked() ), 781 connect( mRecurrenceRangeButton, SIGNAL( clicked() ),
778 SLOT( showRecurrenceRangeDialog() ) ); 782 SLOT( showRecurrenceRangeDialog() ) );
779 783
780 mExceptionsWidget = 0; 784 mExceptionsWidget = 0;
781 mExceptionsDialog = new ExceptionsDialog( this ); 785 mExceptionsDialog = new ExceptionsDialog( this );
782 mExceptions = mExceptionsDialog; 786 mExceptions = mExceptionsDialog;
783 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this ); 787 mExceptionsButton = new QPushButton( i18n("Exceptions..."), this );
784 if ( QApplication::desktop()->width() < 320 ) { 788 if ( QApplication::desktop()->width() < 320 ) {
785 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 ); 789 topLayout->addMultiCellWidget( mRecurrenceRangeButton, 3, 3, 0, 1 );
786 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 ); 790 topLayout->addMultiCellWidget( mExceptionsButton, 4, 4, 0, 1 );
787 } else { 791 } else {
788 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 ); 792 topLayout->addWidget( mRecurrenceRangeButton, 3, 0 );
789 topLayout->addWidget( mExceptionsButton, 3, 1 ); 793 topLayout->addWidget( mExceptionsButton, 3, 1 );
790 } 794 }
791 connect( mExceptionsButton, SIGNAL( clicked() ), 795 connect( mExceptionsButton, SIGNAL( clicked() ),
792 SLOT( showExceptionsDialog() ) ); 796 SLOT( showExceptionsDialog() ) );
793} 797}
794 798
795KOEditorRecurrence::~KOEditorRecurrence() 799KOEditorRecurrence::~KOEditorRecurrence()
796{ 800{
797} 801}
798 802
799void KOEditorRecurrence::setEnabled( bool enabled ) 803void KOEditorRecurrence::setEnabled( bool enabled )
800{ 804{
801// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl; 805// kdDebug() << "KOEditorRecurrence::setEnabled(): " << (enabled ? "on" : "off") << endl;
802 806
803 mTimeGroupBox->setEnabled( enabled ); 807 mTimeGroupBox->setEnabled( enabled );
804 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled ); 808 if ( mRecurrenceRangeWidget ) mRecurrenceRangeWidget->setEnabled( enabled );
805 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled ); 809 if ( mRecurrenceRangeButton ) mRecurrenceRangeButton->setEnabled( enabled );
806 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled ); 810 if ( mExceptionsWidget ) mExceptionsWidget->setEnabled( enabled );
807 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled ); 811 if ( mExceptionsButton ) mExceptionsButton->setEnabled( enabled );
808 mRuleBox->setEnabled( enabled ); 812 mRuleBox->setEnabled( enabled );
809} 813}
810 814
811void KOEditorRecurrence::showCurrentRule( int current ) 815void KOEditorRecurrence::showCurrentRule( int current )
812{ 816{
813 switch ( current ) { 817 switch ( current ) {
814 case Daily: 818 case Daily:
815 mRuleStack->raiseWidget( mDaily ); 819 mRuleStack->raiseWidget( mDaily );
816 break; 820 break;
817 case Weekly: 821 case Weekly:
818 mRuleStack->raiseWidget( mWeekly ); 822 mRuleStack->raiseWidget( mWeekly );
819 break; 823 break;
820 case Monthly: 824 case Monthly:
821 mRuleStack->raiseWidget( mMonthly ); 825 mRuleStack->raiseWidget( mMonthly );
822 break; 826 break;
823 default: 827 default:
824 case Yearly: 828 case Yearly:
825 mRuleStack->raiseWidget( mYearly ); 829 mRuleStack->raiseWidget( mYearly );
826 break; 830 break;
827 } 831 }
828} 832}
829 833
830void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end ) 834void KOEditorRecurrence::setDateTimes( QDateTime start, QDateTime end )
831{ 835{
832// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl; 836// kdDebug() << "KOEditorRecurrence::setDateTimes" << endl;
833 837
834 mRecurrenceRange->setDateTimes( start, end ); 838 mRecurrenceRange->setDateTimes( start, end );
835 mExceptions->setDefaults( end ); 839 mExceptions->setDefaults( end );
836 840
837} 841}
838void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to ) 842void KOEditorRecurrence::setDefaultsDates( QDateTime from, QDateTime to )
839{ 843{
840 setDateTimes( from, to ); 844 setDateTimes( from, to );
841 QBitArray days( 7 ); 845 QBitArray days( 7 );
842 days.fill( 0 ); 846 days.fill( 0 );
843 days.setBit( from.date().dayOfWeek()- 1); 847 days.setBit( from.date().dayOfWeek()- 1);
844 mWeekly->setDays( days ); 848 mWeekly->setDays( days );
845 bool byPos = mMonthly->byPos(); 849 bool byPos = mMonthly->byPos();
846 if ( byPos ) 850 if ( byPos )
847 mMonthly->setByDay( from.date().day()-1 ); 851 mMonthly->setByDay( from.date().day()-1 );
848 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 ); 852 mMonthly->setByPos((from.date().day()/7), from.date().dayOfWeek()-1 );
849 if ( ! byPos) 853 if ( ! byPos)
850 mMonthly->setByDay( from.date().day()-1 ); 854 mMonthly->setByDay( from.date().day()-1 );
851 855
852 bool byDay = mYearly->byDay(); 856 bool byDay = mYearly->byDay();
853 if ( ! byDay ) 857 if ( ! byDay )
854 mYearly->setByDay( from.date().dayOfYear() ); 858 mYearly->setByDay( from.date().dayOfYear() );
855 mYearly->setByMonth( from.date().month(), from.date().day() ); 859 mYearly->setByMonth( from.date().month(), from.date().day() );
856 if ( byDay ) 860 if ( byDay )
857 mYearly->setByDay( from.date().dayOfYear() ); 861 mYearly->setByDay( from.date().dayOfYear() );
858} 862}
859void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to ) 863void KOEditorRecurrence::setDefaults( QDateTime from, QDateTime to )
860{ 864{
861 865
862 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() ); 866 // qDebug("KOEditorRecurrence::setDefaults %s %s ",from.toString().latin1(),to.toString().latin1() );
863 //setDateTimes( from, to ); 867 //setDateTimes( from, to );
864 868
865 bool enabled = false; 869 bool enabled = false;
866 mEnabledCheck->setChecked( enabled ); 870 mEnabledCheck->setChecked( enabled );
867 setEnabled( enabled ); 871 setEnabled( enabled );
868 872
869 mExceptions->setDefaults( to ); 873 mExceptions->setDefaults( to );
870 mRecurrenceRange->setDefaults( to ); 874 mRecurrenceRange->setDefaults( to );
871 875
872 mRecurrenceChooser->setType( RecurrenceChooser::Weekly ); 876 mRecurrenceChooser->setType( RecurrenceChooser::Weekly );
873 showCurrentRule( mRecurrenceChooser->type() ); 877 showCurrentRule( mRecurrenceChooser->type() );
874 878
875 mDaily->setFrequency( 1 ); 879 mDaily->setFrequency( 1 );
876 mWeekly->setFrequency( 1 ); 880 mWeekly->setFrequency( 1 );
877 mMonthly->setFrequency( 1 ); 881 mMonthly->setFrequency( 1 );
878 mYearly->setFrequency( 1 ); 882 mYearly->setFrequency( 1 );
879 setDefaultsDates( from, to ); 883 setDefaultsDates( from, to );
880} 884}
881 885
882void KOEditorRecurrence::readEvent(Incidence *event) 886void KOEditorRecurrence::readEvent(Incidence *event)
883{ 887{
884 888
885 QDateTime dtEnd; 889 QDateTime dtEnd;
886 if ( event->typeID() == eventID ) 890 if ( event->typeID() == eventID )
887 dtEnd = ((Event*)event)->dtEnd(); 891 dtEnd = ((Event*)event)->dtEnd();
888 else 892 else
889 dtEnd = ((Todo*)event)->dtDue(); 893 dtEnd = ((Todo*)event)->dtDue();
890 894
891 setDefaults( event->dtStart(), dtEnd ); 895 setDefaults( event->dtStart(), dtEnd );
892 QBitArray rDays( 7 ); 896 QBitArray rDays( 7 );
893 QPtrList<Recurrence::rMonthPos> rmp; 897 QPtrList<Recurrence::rMonthPos> rmp;
894 QPtrList<int> rmd; 898 QPtrList<int> rmd;
895 int day = 0; 899 int day = 0;
896 int count = 0; 900 int count = 0;
897 int month = 0; 901 int month = 0;
898 setDateTimes( event->dtStart(), dtEnd ); 902 setDateTimes( event->dtStart(), dtEnd );
899 903
900 904
901 905
902 int recurs = event->doesRecur(); 906 int recurs = event->doesRecur();
903 907
904 mEnabledCheck->setChecked( recurs ); 908 mEnabledCheck->setChecked( recurs );
905 setEnabled( recurs ); 909 setEnabled( recurs );
906 910
907 int recurrenceType = RecurrenceChooser::Weekly; 911 int recurrenceType = RecurrenceChooser::Weekly;
908 if ( recurs ) { 912 if ( recurs ) {
909 Recurrence *r = event->recurrence(); 913 Recurrence *r = event->recurrence();
910 int f = r->frequency(); 914 int f = r->frequency();
911 switch ( recurs ) { 915 switch ( recurs ) {
912 case Recurrence::rNone: 916 case Recurrence::rNone:
913 setDefaults( event->dtStart(), dtEnd ); 917 setDefaults( event->dtStart(), dtEnd );
914 break; 918 break;
915 case Recurrence::rDaily: 919 case Recurrence::rDaily:
916 recurrenceType = RecurrenceChooser::Daily; 920 recurrenceType = RecurrenceChooser::Daily;
917 mDaily->setFrequency( f ); 921 mDaily->setFrequency( f );
918 break; 922 break;
919 case Recurrence::rWeekly: 923 case Recurrence::rWeekly:
920 recurrenceType = RecurrenceChooser::Weekly; 924 recurrenceType = RecurrenceChooser::Weekly;
921 mWeekly->setFrequency( f ); 925 mWeekly->setFrequency( f );
922 mWeekly->setDays( r->days() ); 926 mWeekly->setDays( r->days() );
923 break; 927 break;
924 case Recurrence::rMonthlyPos: 928 case Recurrence::rMonthlyPos:
925 // we only handle one possibility in the list right now, 929 // we only handle one possibility in the list right now,
926 // so I have hardcoded calls with first(). If we make the GUI 930 // so I have hardcoded calls with first(). If we make the GUI
927 // more extended, this can be changed. 931 // more extended, this can be changed.
928 recurrenceType = RecurrenceChooser::Monthly; 932 recurrenceType = RecurrenceChooser::Monthly;
929 933
930 rmp = r->monthPositions(); 934 rmp = r->monthPositions();
931 if ( rmp.first()->negative ) 935 if ( rmp.first()->negative )
932 count = 5 - rmp.first()->rPos - 1; 936 count = 5 - rmp.first()->rPos - 1;
933 else 937 else
934 count = rmp.first()->rPos - 1; 938 count = rmp.first()->rPos - 1;
935 day = 0; 939 day = 0;
936 while ( !rmp.first()->rDays.testBit( day ) ) ++day; 940 while ( !rmp.first()->rDays.testBit( day ) ) ++day;
937 mMonthly->setByPos( count, day ); 941 mMonthly->setByPos( count, day );
938 942
939 mMonthly->setFrequency( f ); 943 mMonthly->setFrequency( f );
940 944
941 break; 945 break;
942 case Recurrence::rMonthlyDay: 946 case Recurrence::rMonthlyDay:
943 recurrenceType = RecurrenceChooser::Monthly; 947 recurrenceType = RecurrenceChooser::Monthly;
944 948
945 rmd = r->monthDays(); 949 rmd = r->monthDays();
946 day = *rmd.first() - 1; 950 day = *rmd.first() - 1;
947 mMonthly->setByDay( day ); 951 mMonthly->setByDay( day );
948 952
949 mMonthly->setFrequency( f ); 953 mMonthly->setFrequency( f );
950 954
951 break; 955 break;
952 case Recurrence::rYearlyMonth: 956 case Recurrence::rYearlyMonth:
953 { 957 {
954 recurrenceType = RecurrenceChooser::Yearly; 958 recurrenceType = RecurrenceChooser::Yearly;
955 //qDebug("Recurrence::rYearlyMonth: "); 959 //qDebug("Recurrence::rYearlyMonth: ");
956 day = event->dtStart().date().day(); 960 day = event->dtStart().date().day();
957 rmd = r->yearNums(); 961 rmd = r->yearNums();
958 if ( rmd.count() > 0 ) 962 if ( rmd.count() > 0 )
959 month = *rmd.first(); 963 month = *rmd.first();
960 else 964 else
961 month = event->dtStart().date().month() ; 965 month = event->dtStart().date().month() ;
962 mYearly->setByMonth( month, day ); 966 mYearly->setByMonth( month, day );
963#if 0 967#if 0
964 //qDebug("2day = %d ",day ); 968 //qDebug("2day = %d ",day );
965 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions(); 969 QPtrList<Recurrence::rMonthPos> monthlist = r->yearMonthPositions();
966 int month; 970 int month;
967 if ( !monthlist.isEmpty() ) { 971 if ( !monthlist.isEmpty() ) {
968 month = monthlist.first()->rPos ; 972 month = monthlist.first()->rPos ;
969 } else { 973 } else {
970 month = event->dtStart().date().month() ; 974 month = event->dtStart().date().month() ;
971 } 975 }
972 mYearly->setByMonth( day, month ); 976 mYearly->setByMonth( day, month );
973#endif 977#endif
974 mYearly->setFrequency( f ); 978 mYearly->setFrequency( f );
975 } 979 }
976 980
977 break; 981 break;
978 case Recurrence::rYearlyDay: 982 case Recurrence::rYearlyDay:
979 //qDebug("Recurrence::rYearlyDay: "); 983 //qDebug("Recurrence::rYearlyDay: ");
980 recurrenceType = RecurrenceChooser::Yearly; 984 recurrenceType = RecurrenceChooser::Yearly;
981 mYearly->setByDay( event->dtStart().date().dayOfYear() ); 985 mYearly->setByDay( event->dtStart().date().dayOfYear() );
982 mYearly->setFrequency( f ); 986 mYearly->setFrequency( f );
983 break; 987 break;
984 default: 988 default:
985 setDefaults( event->dtStart(), dtEnd ); 989 setDefaults( event->dtStart(), dtEnd );
986 break; 990 break;
987 } 991 }
988 } 992 }
989 mRecurrenceChooser->setType( recurrenceType ); 993 mRecurrenceChooser->setType( recurrenceType );
990 showCurrentRule( recurrenceType ); 994 showCurrentRule( recurrenceType );
991 995
992 mRecurrenceRange->setDateTimes( event->dtStart() ); 996 mRecurrenceRange->setDateTimes( event->dtStart() );
993 997
994 if ( event->doesRecur() ) { 998 if ( event->doesRecur() ) {
995 Recurrence *r = event->recurrence(); 999 Recurrence *r = event->recurrence();
996 mRecurrenceRange->setDuration( r->duration() ); 1000 mRecurrenceRange->setDuration( r->duration() );
997 if ( r->duration() == 0 ) 1001 if ( r->duration() == 0 )
998 { 1002 {
999 if ( r->endDate() < event->dtStart().date() ) 1003 if ( r->endDate() < event->dtStart().date() )
1000 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1004 mRecurrenceRange->setEndDate( event->dtStart().date() );
1001 else 1005 else
1002 mRecurrenceRange->setEndDate( r->endDate() ); 1006 mRecurrenceRange->setEndDate( r->endDate() );
1003 } else 1007 } else
1004 mRecurrenceRange->setEndDate( event->dtStart().date() ); 1008 mRecurrenceRange->setEndDate( event->dtStart().date() );
1005 } 1009 }
1006 1010
1007 mExceptions->setDates( event->exDates() ); 1011 mExceptions->setDates( event->exDates() );
1008} 1012}
1009 1013
1010void KOEditorRecurrence::writeEvent( Incidence *event ) 1014void KOEditorRecurrence::writeEvent( Incidence *event )
1011{ 1015{
1012 1016
1013 1017
1014 if ( !mEnabledCheck->isChecked() ) { 1018 if ( !mEnabledCheck->isChecked() ) {
1015 if ( event->doesRecur() ) 1019 if ( event->doesRecur() )
1016 event->recurrence()->unsetRecurs(); 1020 event->recurrence()->unsetRecurs();
1017 } else { 1021 } else {
1018 Recurrence *r = event->recurrence(); 1022 Recurrence *r = event->recurrence();
1019 1023
1020 // clear out any old settings; 1024 // clear out any old settings;
1021 r->unsetRecurs(); 1025 r->unsetRecurs();
1022 int duration = mRecurrenceRange->duration(); 1026 int duration = mRecurrenceRange->duration();
1023 QDate endDate; 1027 QDate endDate;
1024 if ( duration == 0 ) endDate = mRecurrenceRange->endDate(); 1028 if ( duration == 0 ) endDate = mRecurrenceRange->endDate();
1025 1029
1026 int recurrenceType = mRecurrenceChooser->type(); 1030 int recurrenceType = mRecurrenceChooser->type();
1027 1031
1028 if ( recurrenceType == RecurrenceChooser::Daily ) { 1032 if ( recurrenceType == RecurrenceChooser::Daily ) {
1029 int freq = mDaily->frequency(); 1033 int freq = mDaily->frequency();
1030 if ( duration != 0 ) r->setDaily( freq, duration ); 1034 if ( duration != 0 ) r->setDaily( freq, duration );
1031 else r->setDaily( freq, endDate ); 1035 else r->setDaily( freq, endDate );
1032 } else if ( recurrenceType == RecurrenceChooser::Weekly ) { 1036 } else if ( recurrenceType == RecurrenceChooser::Weekly ) {
1033 int freq = mWeekly->frequency(); 1037 int freq = mWeekly->frequency();
1034 QBitArray days = mWeekly->days(); 1038 QBitArray days = mWeekly->days();
1035 int j; 1039 int j;
1036 bool found = false; 1040 bool found = false;
1037 for (j = 0; j < 7 ; ++j ) { 1041 for (j = 0; j < 7 ; ++j ) {
1038 found |=days.at(j); 1042 found |=days.at(j);
1039 } 1043 }
1040 if ( !found ) { 1044 if ( !found ) {
1041 days.setBit( event->dtStart().date().dayOfWeek()-1); 1045 days.setBit( event->dtStart().date().dayOfWeek()-1);
1042 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1); 1046 //qDebug("bit set %d ", event->dtStart().date().dayOfWeek()-1);
1043 } 1047 }
1044 if ( duration != 0 ) r->setWeekly( freq, days, duration ); 1048 if ( duration != 0 ) r->setWeekly( freq, days, duration );
1045 else r->setWeekly( freq, days, endDate ); 1049 else r->setWeekly( freq, days, endDate );
1046 } else if ( recurrenceType == RecurrenceChooser::Monthly ) { 1050 } else if ( recurrenceType == RecurrenceChooser::Monthly ) {
1047 int freq = mMonthly->frequency(); 1051 int freq = mMonthly->frequency();
1048 if ( mMonthly->byPos() ) { 1052 if ( mMonthly->byPos() ) {
1049 int pos = mMonthly->count(); 1053 int pos = mMonthly->count();
1050 1054
1051 QBitArray days( 7 ); 1055 QBitArray days( 7 );
1052 days.fill( false ); 1056 days.fill( false );
1053 1057
1054 days.setBit( mMonthly->weekday() ); 1058 days.setBit( mMonthly->weekday() );
1055 if ( duration != 0 ) 1059 if ( duration != 0 )
1056 r->setMonthly( Recurrence::rMonthlyPos, freq, duration ); 1060 r->setMonthly( Recurrence::rMonthlyPos, freq, duration );
1057 else 1061 else
1058 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 1062 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
1059 r->addMonthlyPos( pos, days ); 1063 r->addMonthlyPos( pos, days );
1060 } else { 1064 } else {
1061 // it's by day 1065 // it's by day
1062 int day = mMonthly->day(); 1066 int day = mMonthly->day();
1063 1067
1064 if ( duration != 0 ) { 1068 if ( duration != 0 ) {
1065 r->setMonthly( Recurrence::rMonthlyDay, freq, duration ); 1069 r->setMonthly( Recurrence::rMonthlyDay, freq, duration );
1066 } else { 1070 } else {
1067 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 1071 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
1068 } 1072 }
1069 r->addMonthlyDay( day ); 1073 r->addMonthlyDay( day );
1070 } 1074 }
1071 } else if ( recurrenceType == RecurrenceChooser::Yearly ) { 1075 } else if ( recurrenceType == RecurrenceChooser::Yearly ) {
1072 //qDebug("RecurrenceChooser::Yearly "); 1076 //qDebug("RecurrenceChooser::Yearly ");
1073 int freq = mYearly->frequency(); 1077 int freq = mYearly->frequency();
1074 if ( mYearly->byDay() ) { 1078 if ( mYearly->byDay() ) {
1075 if ( duration != 0 ) { 1079 if ( duration != 0 ) {
1076 r->setYearly( Recurrence::rYearlyDay, freq, duration ); 1080 r->setYearly( Recurrence::rYearlyDay, freq, duration );
1077 } else { 1081 } else {
1078 r->setYearly( Recurrence::rYearlyDay, freq, endDate ); 1082 r->setYearly( Recurrence::rYearlyDay, freq, endDate );
1079 } 1083 }
1080 r->addYearlyNum( event->dtStart().date().dayOfYear() ); 1084 r->addYearlyNum( event->dtStart().date().dayOfYear() );
1081 } else { 1085 } else {
1082 if ( duration != 0 ) { 1086 if ( duration != 0 ) {
1083 r->setYearly( Recurrence::rYearlyMonth, freq, duration ); 1087 r->setYearly( Recurrence::rYearlyMonth, freq, duration );
1084 } else { 1088 } else {
1085 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 1089 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
1086 } 1090 }
1087 r->addYearlyNum( mYearly->month() ); 1091 r->addYearlyNum( mYearly->month() );
1088 } 1092 }
1089 1093
1090 } 1094 }
1091 1095
1092 event->setExDates( mExceptions->dates() ); 1096 event->setExDates( mExceptions->dates() );
1093 } 1097 }
1094} 1098}
1095 1099
1096void KOEditorRecurrence::setDateTimeStr( const QString &str ) 1100void KOEditorRecurrence::setDateTimeStr( const QString &str )
1097{ 1101{
1098 mDateTimeLabel->setText( str ); 1102 mDateTimeLabel->setText( str );
1099} 1103}
1100 1104
1101bool KOEditorRecurrence::validateInput() 1105bool KOEditorRecurrence::validateInput()
1102{ 1106{
1103 // Check input here 1107 // Check input here
1104 1108
1105 return true; 1109 return true;
1106} 1110}
1107 1111
1108void KOEditorRecurrence::showExceptionsDialog() 1112void KOEditorRecurrence::showExceptionsDialog()
1109{ 1113{
1110 DateList dates = mExceptions->dates(); 1114 DateList dates = mExceptions->dates();
1111 int result = mExceptionsDialog->exec(); 1115 int result = mExceptionsDialog->exec();
1112 if ( result == QDialog::Rejected ) mExceptions->setDates( dates ); 1116 if ( result == QDialog::Rejected ) mExceptions->setDates( dates );
1113} 1117}
1114 1118
1115void KOEditorRecurrence::showRecurrenceRangeDialog() 1119void KOEditorRecurrence::showRecurrenceRangeDialog()
1116{ 1120{
1117 int duration = mRecurrenceRange->duration(); 1121 int duration = mRecurrenceRange->duration();
1118 QDate endDate = mRecurrenceRange->endDate(); 1122 QDate endDate = mRecurrenceRange->endDate();
1119 1123
1120 int result = mRecurrenceRangeDialog->exec(); 1124 int result = mRecurrenceRangeDialog->exec();
1121 if ( result == QDialog::Rejected ) { 1125 if ( result == QDialog::Rejected ) {
1122 mRecurrenceRange->setDuration( duration ); 1126 mRecurrenceRange->setDuration( duration );
1123 mRecurrenceRange->setEndDate( endDate ); 1127 mRecurrenceRange->setEndDate( endDate );
1124 } 1128 }
1125 1129
1126} 1130}
diff --git a/korganizer/koeditorrecurrence.h b/korganizer/koeditorrecurrence.h
index f398f62..75e0c73 100644
--- a/korganizer/koeditorrecurrence.h
+++ b/korganizer/koeditorrecurrence.h
@@ -1,324 +1,327 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 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 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 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef _KOEDITORRECURRENCE_H 23#ifndef _KOEDITORRECURRENCE_H
24#define _KOEDITORRECURRENCE_H 24#define _KOEDITORRECURRENCE_H
25 25
26#include <qframe.h> 26#include <qframe.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30#include <qgroupbox.h> 30#include <qgroupbox.h>
31#include <qlineedit.h> 31#include <qlineedit.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qmultilineedit.h> 33#include <qmultilineedit.h>
34#include <qlistview.h> 34#include <qlistview.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36#include <qbuttongroup.h>
36 37
37#include <kdialogbase.h> 38#include <kdialogbase.h>
38 39
39#include <libkcal/event.h> 40#include <libkcal/event.h>
40 41
41#include "ktimeedit.h" 42#include "ktimeedit.h"
42 43
43class QWidgetStack; 44class QWidgetStack;
44class QSpinBox; 45class QSpinBox;
45 46
46class KDateEdit; 47class KDateEdit;
47 48
48using namespace KCal; 49using namespace KCal;
49 50
50class RecurBase : public QWidget 51class RecurBase : public QWidget
51{ 52{
52 public: 53 public:
53 RecurBase( QWidget *parent = 0, const char *name = 0 ); 54 RecurBase( QWidget *parent = 0, const char *name = 0 );
54 55
55 void setFrequency( int ); 56 void setFrequency( int );
56 int frequency(); 57 int frequency();
57 58
58 QWidget *frequencyEdit(); 59 QWidget *frequencyEdit();
59 60
60 private: 61 private:
61 QSpinBox *mFrequencyEdit; 62 QSpinBox *mFrequencyEdit;
62}; 63};
63 64
64class RecurDaily : public RecurBase 65class RecurDaily : public RecurBase
65{ 66{
66 public: 67 public:
67 RecurDaily( QWidget *parent = 0, const char *name = 0 ); 68 RecurDaily( QWidget *parent = 0, const char *name = 0 );
68}; 69};
69 70
70class RecurWeekly : public RecurBase 71class RecurWeekly : public RecurBase
71{ 72{
72 public: 73 public:
73 RecurWeekly( QWidget *parent = 0, const char *name = 0 ); 74 RecurWeekly( QWidget *parent = 0, const char *name = 0 );
74 75
75 void setDays( const QBitArray & ); 76 void setDays( const QBitArray & );
76 QBitArray days(); 77 QBitArray days();
77 78
78 private: 79 private:
79 QCheckBox *mDayBoxes[7]; 80 QCheckBox *mDayBoxes[7];
80}; 81};
81 82
82class RecurMonthly : public RecurBase 83class RecurMonthly : public RecurBase
83{ 84{
84 public: 85 public:
85 RecurMonthly( QWidget *parent = 0, const char *name = 0 ); 86 RecurMonthly( QWidget *parent = 0, const char *name = 0 );
86 87
87 void setByDay( int day ); 88 void setByDay( int day );
88 void setByPos( int count, int weekday ); 89 void setByPos( int count, int weekday );
89 90
90 bool byDay(); 91 bool byDay();
91 bool byPos(); 92 bool byPos();
92 93
93 int day(); 94 int day();
94 95
95 int count(); 96 int count();
96 int weekday(); 97 int weekday();
97 98
98 private: 99 private:
99 QRadioButton *mByDayRadio; 100 QRadioButton *mByDayRadio;
100 QComboBox *mByDayCombo; 101 QComboBox *mByDayCombo;
101 102
102 QRadioButton *mByPosRadio; 103 QRadioButton *mByPosRadio;
103 QComboBox *mByPosCountCombo; 104 QComboBox *mByPosCountCombo;
104 QComboBox *mByPosWeekdayCombo; 105 QComboBox *mByPosWeekdayCombo;
105}; 106};
106 107
107class RecurYearly : public RecurBase 108class RecurYearly : public RecurBase
108{ 109{
109 public: 110 public:
110 RecurYearly( QWidget *parent = 0, const char *name = 0 ); 111 RecurYearly( QWidget *parent = 0, const char *name = 0 );
111 112
112 void setByDay( int doy ); 113 void setByDay( int doy );
113 void setByMonth( int month, int day ); 114 void setByMonth( int month, int day );
114 115
115 bool byMonth(); 116 bool byMonth();
116 bool byDay(); 117 bool byDay();
117 118
118 int month(); 119 int month();
119 int day(); 120 int day();
120 121
121 private: 122 private:
122 int mDay; 123 int mDay;
123 QRadioButton *mByMonthRadio; 124 QRadioButton *mByMonthRadio;
124 QComboBox *mByMonthCombo; 125 QComboBox *mByMonthCombo;
125 QLabel* mByDayLabel; 126 QLabel* mByDayLabel;
126 QLabel* mDayOfLabel; 127 QLabel* mDayOfLabel;
127 QRadioButton *mByDayRadio; 128 QRadioButton *mByDayRadio;
128}; 129};
129 130
130class RecurrenceChooser : public QWidget 131class RecurrenceChooser : public QWidget
131{ 132{
132 Q_OBJECT 133 Q_OBJECT
133 public: 134 public:
134 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 ); 135 RecurrenceChooser( QWidget *parent = 0, const char *name = 0 );
135 136
136 enum { Daily, Weekly, Monthly, Yearly }; 137 enum { Daily, Weekly, Monthly, Yearly };
137 138
138 void setType( int ); 139 void setType( int );
139 int type(); 140 int type();
140 141
141 signals: 142 signals:
142 void chosen( int ); 143 void chosen( int );
143 144
144 protected slots: 145 protected slots:
145 void emitChoice(); 146 void emitChoice();
146 147
147 private: 148 private:
148 QComboBox *mTypeCombo; 149 QComboBox *mTypeCombo;
149 150
150 QRadioButton *mDailyButton; 151 QRadioButton *mDailyButton;
151 QRadioButton *mWeeklyButton; 152 QRadioButton *mWeeklyButton;
152 QRadioButton *mMonthlyButton; 153 QRadioButton *mMonthlyButton;
153 QRadioButton *mYearlyButton; 154 QRadioButton *mYearlyButton;
154}; 155};
155 156
156class ExceptionsBase 157class ExceptionsBase
157{ 158{
158 public: 159 public:
159 virtual void setDefaults( const QDateTime &from ) = 0; 160 virtual void setDefaults( const QDateTime &from ) = 0;
160 virtual void setDates( const DateList & ) = 0; 161 virtual void setDates( const DateList & ) = 0;
161 virtual DateList dates() = 0; 162 virtual DateList dates() = 0;
162}; 163};
163 164
164class ExceptionsWidget : public QWidget, public ExceptionsBase 165class ExceptionsWidget : public QWidget, public ExceptionsBase
165{ 166{
166 Q_OBJECT 167 Q_OBJECT
167 public: 168 public:
168 ExceptionsWidget( QWidget *parent = 0, const char *name = 0 ); 169 ExceptionsWidget( QWidget *parent = 0, const char *name = 0 );
169 170
170 void setDefaults( const QDateTime &from ); 171 void setDefaults( const QDateTime &from );
171 172
172 void setDates( const DateList & ); 173 void setDates( const DateList & );
173 DateList dates(); 174 DateList dates();
174 175
175 protected slots: 176 protected slots:
176 void addException(); 177 void addException();
177 void changeException(); 178 void changeException();
178 void deleteException(); 179 void deleteException();
179 180
180 private: 181 private:
181 KDateEdit *mExceptionDateEdit; 182 KDateEdit *mExceptionDateEdit;
182 QListBox *mExceptionList; 183 QListBox *mExceptionList;
183 DateList mExceptionDates; 184 DateList mExceptionDates;
184}; 185};
185 186
186class ExceptionsDialog : public KDialogBase, public ExceptionsBase 187class ExceptionsDialog : public KDialogBase, public ExceptionsBase
187{ 188{
188 public: 189 public:
189 ExceptionsDialog( QWidget *parent, const char *name = 0 ); 190 ExceptionsDialog( QWidget *parent, const char *name = 0 );
190 191
191 void setDefaults( const QDateTime &from ); 192 void setDefaults( const QDateTime &from );
192 193
193 void setDates( const DateList & ); 194 void setDates( const DateList & );
194 DateList dates(); 195 DateList dates();
195 196
196 private: 197 private:
197 ExceptionsWidget *mExceptions; 198 ExceptionsWidget *mExceptions;
198}; 199};
199 200
200class RecurrenceRangeBase 201class RecurrenceRangeBase
201{ 202{
202 public: 203 public:
203 virtual void setDefaults( const QDateTime &from ) = 0; 204 virtual void setDefaults( const QDateTime &from ) = 0;
204 205
205 virtual void setDuration( int ) = 0; 206 virtual void setDuration( int ) = 0;
206 virtual int duration() = 0; 207 virtual int duration() = 0;
207 208
208 virtual void setEndDate( const QDate & ) = 0; 209 virtual void setEndDate( const QDate & ) = 0;
209 virtual QDate endDate() = 0; 210 virtual QDate endDate() = 0;
210 211
211 virtual void setDateTimes( const QDateTime &start, 212 virtual void setDateTimes( const QDateTime &start,
212 const QDateTime &end = QDateTime() ) = 0; 213 const QDateTime &end = QDateTime() ) = 0;
213}; 214};
214 215
215class RecurrenceRangeWidget : public QWidget, public RecurrenceRangeBase 216class RecurrenceRangeWidget : public QWidget, public RecurrenceRangeBase
216{ 217{
217 Q_OBJECT 218 Q_OBJECT
218 public: 219 public:
219 RecurrenceRangeWidget( QWidget *parent = 0, const char *name = 0 ); 220 RecurrenceRangeWidget( QWidget *parent = 0, const char *name = 0 );
221 ~RecurrenceRangeWidget();
220 222
221 void setDefaults( const QDateTime &from ); 223 void setDefaults( const QDateTime &from );
222 224
223 void setDuration( int ); 225 void setDuration( int );
224 int duration(); 226 int duration();
225 227
226 void setEndDate( const QDate & ); 228 void setEndDate( const QDate & );
227 QDate endDate(); 229 QDate endDate();
228 230
229 void setDateTimes( const QDateTime &start, 231 void setDateTimes( const QDateTime &start,
230 const QDateTime &end = QDateTime() ); 232 const QDateTime &end = QDateTime() );
231 233
232 protected slots: 234 protected slots:
233 void showCurrentRange(); 235 void showCurrentRange();
234 236
235 private: 237 private:
238 QButtonGroup *mRangeButtonGroup;
236 QGroupBox *mRangeGroupBox; 239 QGroupBox *mRangeGroupBox;
237 QLabel *mStartDateLabel; 240 QLabel *mStartDateLabel;
238 QRadioButton *mNoEndDateButton; 241 QRadioButton *mNoEndDateButton;
239 QRadioButton *mEndDurationButton; 242 QRadioButton *mEndDurationButton;
240 QSpinBox *mEndDurationEdit; 243 QSpinBox *mEndDurationEdit;
241 QRadioButton *mEndDateButton; 244 QRadioButton *mEndDateButton;
242 KDateEdit *mEndDateEdit; 245 KDateEdit *mEndDateEdit;
243}; 246};
244 247
245class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase 248class RecurrenceRangeDialog : public KDialogBase, public RecurrenceRangeBase
246{ 249{
247 public: 250 public:
248 RecurrenceRangeDialog( QWidget *parent = 0, const char *name = 0 ); 251 RecurrenceRangeDialog( QWidget *parent = 0, const char *name = 0 );
249 252
250 void setDefaults( const QDateTime &from ); 253 void setDefaults( const QDateTime &from );
251 254
252 void setDuration( int ); 255 void setDuration( int );
253 int duration(); 256 int duration();
254 257
255 void setEndDate( const QDate & ); 258 void setEndDate( const QDate & );
256 QDate endDate(); 259 QDate endDate();
257 260
258 void setDateTimes( const QDateTime &start, 261 void setDateTimes( const QDateTime &start,
259 const QDateTime &end = QDateTime() ); 262 const QDateTime &end = QDateTime() );
260 263
261 private: 264 private:
262 RecurrenceRangeWidget *mRecurrenceRangeWidget; 265 RecurrenceRangeWidget *mRecurrenceRangeWidget;
263}; 266};
264 267
265class KOEditorRecurrence : public QWidget 268class KOEditorRecurrence : public QWidget
266{ 269{
267 Q_OBJECT 270 Q_OBJECT
268 public: 271 public:
269 KOEditorRecurrence ( QWidget *parent = 0, const char *name = 0 ); 272 KOEditorRecurrence ( QWidget *parent = 0, const char *name = 0 );
270 virtual ~KOEditorRecurrence(); 273 virtual ~KOEditorRecurrence();
271 274
272 enum { Daily, Weekly, Monthly, Yearly }; 275 enum { Daily, Weekly, Monthly, Yearly };
273 276
274 /** Read event object and setup widgets accordingly */ 277 /** Read event object and setup widgets accordingly */
275 void readEvent( Incidence * ); 278 void readEvent( Incidence * );
276 /** Write event settings to event object */ 279 /** Write event settings to event object */
277 void writeEvent( Incidence * ); 280 void writeEvent( Incidence * );
278 281
279 /** Check if the input is valid. */ 282 /** Check if the input is valid. */
280 bool validateInput(); 283 bool validateInput();
281 284
282 public slots: 285 public slots:
283 void setDefaultsDates( QDateTime from, QDateTime to ); 286 void setDefaultsDates( QDateTime from, QDateTime to );
284 void setDefaults( QDateTime from, QDateTime to ); 287 void setDefaults( QDateTime from, QDateTime to );
285 void setEnabled( bool ); 288 void setEnabled( bool );
286 void setDateTimes( QDateTime start, QDateTime end ); 289 void setDateTimes( QDateTime start, QDateTime end );
287 void setDateTimeStr( const QString & ); 290 void setDateTimeStr( const QString & );
288 291
289 signals: 292 signals:
290 void dateTimesChanged( QDateTime start, QDateTime end ); 293 void dateTimesChanged( QDateTime start, QDateTime end );
291 294
292 protected slots: 295 protected slots:
293 void showCurrentRule( int ); 296 void showCurrentRule( int );
294 void showExceptionsDialog(); 297 void showExceptionsDialog();
295 void showRecurrenceRangeDialog(); 298 void showRecurrenceRangeDialog();
296 299
297 private: 300 private:
298 QCheckBox *mEnabledCheck; 301 QCheckBox *mEnabledCheck;
299 302
300 QGroupBox *mTimeGroupBox; 303 QGroupBox *mTimeGroupBox;
301 QLabel *mDateTimeLabel; 304 QLabel *mDateTimeLabel;
302 305
303 QGroupBox *mRuleBox; 306 QGroupBox *mRuleBox;
304 QWidgetStack *mRuleStack; 307 QWidgetStack *mRuleStack;
305 RecurrenceChooser *mRecurrenceChooser; 308 RecurrenceChooser *mRecurrenceChooser;
306 309
307 RecurDaily *mDaily; 310 RecurDaily *mDaily;
308 RecurWeekly *mWeekly; 311 RecurWeekly *mWeekly;
309 RecurMonthly *mMonthly; 312 RecurMonthly *mMonthly;
310 RecurYearly *mYearly; 313 RecurYearly *mYearly;
311 314
312 RecurrenceRangeBase *mRecurrenceRange; 315 RecurrenceRangeBase *mRecurrenceRange;
313 RecurrenceRangeWidget *mRecurrenceRangeWidget; 316 RecurrenceRangeWidget *mRecurrenceRangeWidget;
314 RecurrenceRangeDialog *mRecurrenceRangeDialog; 317 RecurrenceRangeDialog *mRecurrenceRangeDialog;
315 QPushButton *mRecurrenceRangeButton; 318 QPushButton *mRecurrenceRangeButton;
316 319
317 ExceptionsBase *mExceptions; 320 ExceptionsBase *mExceptions;
318 ExceptionsDialog *mExceptionsDialog; 321 ExceptionsDialog *mExceptionsDialog;
319 ExceptionsWidget *mExceptionsWidget; 322 ExceptionsWidget *mExceptionsWidget;
320 QPushButton *mExceptionsButton; 323 QPushButton *mExceptionsButton;
321 324
322}; 325};
323 326
324#endif 327#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index eef8327..5baa7dc 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,1025 +1,1025 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 ); 68 registerObserver( 0 );
69 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
70 close(); 70 close();
71} 71}
72bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
73{ 73{
74 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
75 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
76 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
77 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
78 return true; 78 return true;
79 } 79 }
80 return false; 80 return false;
81} 81}
82 82
83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
84{ 84{
85 Todo *todo;; 85 Todo *todo;;
86 Incidence *retVal = 0; 86 Incidence *retVal = 0;
87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
88 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
89 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
90 if ( retVal ) { 90 if ( retVal ) {
91 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
92 retVal = todo; 92 retVal = todo;
93 } 93 }
94 } else { 94 } else {
95 retVal = todo; 95 retVal = todo;
96 } 96 }
97 } 97 }
98 } 98 }
99 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
100 Event *event; 100 Event *event;
101 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
102 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
103 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
104 if ( retVal ) { 104 if ( retVal ) {
105 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
106 retVal = event; 106 retVal = event;
107 } 107 }
108 } else { 108 } else {
109 retVal = event; 109 retVal = event;
110 } 110 }
111 } 111 }
112 } 112 }
113 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
115 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
116 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
117 if ( retVal ) { 117 if ( retVal ) {
118 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
119 retVal = it; 119 retVal = it;
120 } 120 }
121 } else { 121 } else {
122 retVal = it; 122 retVal = it;
123 } 123 }
124 } 124 }
125 return retVal; 125 return retVal;
126} 126}
127 127
128bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
129{ 129{
130 // 1 look for raw inc in local 130 // 1 look for raw inc in local
131 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
132 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
133 // if inc in local, replace it 133 // if inc in local, replace it
134 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
135 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
136 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
137 while ( inL ) { 137 while ( inL ) {
138 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
139 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
140 deleteIncidence( inL ); 140 deleteIncidence( inL );
141 inL = localInc.next(); 141 inL = localInc.next();
142 } 142 }
143 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
144 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
145 while ( inR ) { 145 while ( inR ) {
146 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
147 if ( inL ) { 147 if ( inL ) {
148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
149 int calID = inL->calID(); 149 int calID = inL->calID();
150 deleteIncidence( inL ); 150 deleteIncidence( inL );
151 inL = inR->clone(); 151 inL = inR->clone();
152 inL->setCalID( calID ); 152 inL->setCalID( calID );
153 addIncidence( inL ); 153 addIncidence( inL );
154 } 154 }
155 } else { 155 } else {
156 inL = inR->clone(); 156 inL = inR->clone();
157 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
158 addIncidence( inL ); 158 addIncidence( inL );
159 } 159 }
160 inR = er.next(); 160 inR = er.next();
161 } 161 }
162 return true; 162 return true;
163} 163}
164 164
165 165
166bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
167{ 167{
168 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
169 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
170 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
171 addCalendar( &calendar ); 171 addCalendar( &calendar );
172 return true; 172 return true;
173 } 173 }
174 return false; 174 return false;
175} 175}
176void CalendarLocal::setSyncEventsReadOnly() 176void CalendarLocal::setSyncEventsReadOnly()
177{ 177{
178 Event * ev; 178 Event * ev;
179 ev = mEventList.first(); 179 ev = mEventList.first();
180 while ( ev ) { 180 while ( ev ) {
181 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
182 ev->setReadOnly( true ); 182 ev->setReadOnly( true );
183 ev = mEventList.next(); 183 ev = mEventList.next();
184 } 184 }
185} 185}
186void CalendarLocal::addCalendar( Calendar* cal ) 186void CalendarLocal::addCalendar( Calendar* cal )
187{ 187{
188 cal->setDontDeleteIncidencesOnClose(); 188 cal->setDontDeleteIncidencesOnClose();
189 { 189 {
190 QPtrList<Event> EventList = cal->rawEvents(); 190 QPtrList<Event> EventList = cal->rawEvents();
191 Event * ev = EventList.first(); 191 Event * ev = EventList.first();
192 while ( ev ) { 192 while ( ev ) {
193 ev->unRegisterObserver( cal ); 193 ev->unRegisterObserver( cal );
194 ev->registerObserver( this ); 194 ev->registerObserver( this );
195 mEventList.append( ev ); 195 mEventList.append( ev );
196 ev = EventList.next(); 196 ev = EventList.next();
197 } 197 }
198 } 198 }
199 { 199 {
200 200
201 QPtrList<Todo> TodoList = cal->rawTodos(); 201 QPtrList<Todo> TodoList = cal->rawTodos();
202 Todo * ev = TodoList.first(); 202 Todo * ev = TodoList.first();
203 while ( ev ) { 203 while ( ev ) {
204 QString rel = ev->relatedToUid(); 204 QString rel = ev->relatedToUid();
205 if ( !rel.isEmpty() ){ 205 if ( !rel.isEmpty() ){
206 ev->setRelatedTo ( 0 ); 206 ev->setRelatedTo ( 0 );
207 ev->setRelatedToUid( rel ); 207 ev->setRelatedToUid( rel );
208 } 208 }
209 ev = TodoList.next(); 209 ev = TodoList.next();
210 } 210 }
211 //TodoList = cal->rawTodos(); 211 //TodoList = cal->rawTodos();
212 ev = TodoList.first(); 212 ev = TodoList.first();
213 while ( ev ) { 213 while ( ev ) {
214 ev->unRegisterObserver( cal ); 214 ev->unRegisterObserver( cal );
215 ev->registerObserver( this ); 215 ev->registerObserver( this );
216 mTodoList.append( ev ); 216 mTodoList.append( ev );
217 setupRelations( ev ); 217 setupRelations( ev );
218 ev = TodoList.next(); 218 ev = TodoList.next();
219 } 219 }
220 } 220 }
221 { 221 {
222 QPtrList<Journal> JournalList = cal->journals(); 222 QPtrList<Journal> JournalList = cal->journals();
223 Journal * ev = JournalList.first(); 223 Journal * ev = JournalList.first();
224 while ( ev ) { 224 while ( ev ) {
225 ev->unRegisterObserver( cal ); 225 ev->unRegisterObserver( cal );
226 ev->registerObserver( this ); 226 ev->registerObserver( this );
227 mJournalList.append( ev ); 227 mJournalList.append( ev );
228 ev = JournalList.next(); 228 ev = JournalList.next();
229 } 229 }
230 } 230 }
231 setModified( true ); 231 setModified( true );
232} 232}
233bool CalendarLocal::load( const QString &fileName ) 233bool CalendarLocal::load( const QString &fileName )
234{ 234{
235 FileStorage storage( this, fileName ); 235 FileStorage storage( this, fileName );
236 return storage.load(); 236 return storage.load();
237} 237}
238 238
239bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 239bool CalendarLocal::save( const QString &fileName, CalFormat *format )
240{ 240{
241 FileStorage storage( this, fileName, format ); 241 FileStorage storage( this, fileName, format );
242 return storage.save(); 242 return storage.save();
243} 243}
244 244
245void CalendarLocal::stopAllTodos() 245void CalendarLocal::stopAllTodos()
246{ 246{
247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
248 it->setRunning( false ); 248 it->setRunning( false );
249 249
250} 250}
251void CalendarLocal::close() 251void CalendarLocal::close()
252{ 252{
253 253
254 Todo * i; 254 Todo * i;
255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
256 256
257 mEventList.setAutoDelete( true ); 257 mEventList.setAutoDelete( true );
258 mTodoList.setAutoDelete( true ); 258 mTodoList.setAutoDelete( true );
259 mJournalList.setAutoDelete( false ); 259 mJournalList.setAutoDelete( true );
260 260
261 mEventList.clear(); 261 mEventList.clear();
262 mTodoList.clear(); 262 mTodoList.clear();
263 mJournalList.clear(); 263 mJournalList.clear();
264 264
265 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
266 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
267 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
268 268
269 setModified( false ); 269 setModified( false );
270} 270}
271 271
272bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
273{ 273{
274 QString cat; 274 QString cat;
275 bool isBirthday = true; 275 bool isBirthday = true;
276 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
277 isBirthday = false; 277 isBirthday = false;
278 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
280 isBirthday = true; 280 isBirthday = true;
281 cat = i18n( "Birthday" ); 281 cat = i18n( "Birthday" );
282 } else { 282 } else {
283 qDebug("addAnniversaryNoDup called without fitting category! "); 283 qDebug("addAnniversaryNoDup called without fitting category! ");
284 return false; 284 return false;
285 } 285 }
286 Event * eve; 286 Event * eve;
287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
288 if ( !(eve->categories().contains( cat ) )) 288 if ( !(eve->categories().contains( cat ) ))
289 continue; 289 continue;
290 // now we have an event with fitting category 290 // now we have an event with fitting category
291 if ( eve->dtStart().date() != event->dtStart().date() ) 291 if ( eve->dtStart().date() != event->dtStart().date() )
292 continue; 292 continue;
293 // now we have an event with fitting category+date 293 // now we have an event with fitting category+date
294 if ( eve->summary() != event->summary() ) 294 if ( eve->summary() != event->summary() )
295 continue; 295 continue;
296 // now we have an event with fitting category+date+summary 296 // now we have an event with fitting category+date+summary
297 return false; 297 return false;
298 } 298 }
299 return addEvent( event ); 299 return addEvent( event );
300 300
301} 301}
302bool CalendarLocal::addEventNoDup( Event *event ) 302bool CalendarLocal::addEventNoDup( Event *event )
303{ 303{
304 Event * eve; 304 Event * eve;
305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
306 if ( *eve == *event ) { 306 if ( *eve == *event ) {
307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
308 return false; 308 return false;
309 } 309 }
310 } 310 }
311 return addEvent( event ); 311 return addEvent( event );
312} 312}
313 313
314bool CalendarLocal::addEvent( Event *event ) 314bool CalendarLocal::addEvent( Event *event )
315{ 315{
316 insertEvent( event ); 316 insertEvent( event );
317 317
318 event->registerObserver( this ); 318 event->registerObserver( this );
319 319
320 setModified( true ); 320 setModified( true );
321 if ( event->calID() == 0 ) 321 if ( event->calID() == 0 )
322 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
323 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
324 324
325 return true; 325 return true;
326} 326}
327 327
328void CalendarLocal::deleteEvent( Event *event ) 328void CalendarLocal::deleteEvent( Event *event )
329{ 329{
330 if ( mUndoIncidence ) delete mUndoIncidence; 330 if ( mUndoIncidence ) delete mUndoIncidence;
331 mUndoIncidence = event->clone(); 331 mUndoIncidence = event->clone();
332 if ( mEventList.removeRef( event ) ) { 332 if ( mEventList.removeRef( event ) ) {
333 setModified( true ); 333 setModified( true );
334 } 334 }
335} 335}
336 336
337 337
338Event *CalendarLocal::event( const QString &uid ) 338Event *CalendarLocal::event( const QString &uid )
339{ 339{
340 Event *event; 340 Event *event;
341 Event *retVal = 0; 341 Event *retVal = 0;
342 for ( event = mEventList.first(); event; event = mEventList.next() ) { 342 for ( event = mEventList.first(); event; event = mEventList.next() ) {
343 if ( event->calEnabled() && event->uid() == uid ) { 343 if ( event->calEnabled() && event->uid() == uid ) {
344 if ( retVal ) { 344 if ( retVal ) {
345 if ( retVal->calID() > event->calID() ) { 345 if ( retVal->calID() > event->calID() ) {
346 retVal = event; 346 retVal = event;
347 } 347 }
348 } else { 348 } else {
349 retVal = event; 349 retVal = event;
350 } 350 }
351 } 351 }
352 } 352 }
353 return retVal; 353 return retVal;
354} 354}
355bool CalendarLocal::addTodoNoDup( Todo *todo ) 355bool CalendarLocal::addTodoNoDup( Todo *todo )
356{ 356{
357 Todo * eve; 357 Todo * eve;
358 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 358 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
359 if ( *eve == *todo ) { 359 if ( *eve == *todo ) {
360 //qDebug("duplicate todo found! not inserted! "); 360 //qDebug("duplicate todo found! not inserted! ");
361 return false; 361 return false;
362 } 362 }
363 } 363 }
364 return addTodo( todo ); 364 return addTodo( todo );
365} 365}
366bool CalendarLocal::addTodo( Todo *todo ) 366bool CalendarLocal::addTodo( Todo *todo )
367{ 367{
368 mTodoList.append( todo ); 368 mTodoList.append( todo );
369 369
370 todo->registerObserver( this ); 370 todo->registerObserver( this );
371 371
372 // Set up subtask relations 372 // Set up subtask relations
373 setupRelations( todo ); 373 setupRelations( todo );
374 374
375 setModified( true ); 375 setModified( true );
376 if ( todo->calID() == 0 ) 376 if ( todo->calID() == 0 )
377 todo->setCalID( mDefaultCalendar ); 377 todo->setCalID( mDefaultCalendar );
378 todo->setCalEnabled( true ); 378 todo->setCalEnabled( true );
379 return true; 379 return true;
380} 380}
381 381
382void CalendarLocal::deleteTodo( Todo *todo ) 382void CalendarLocal::deleteTodo( Todo *todo )
383{ 383{
384 // Handle orphaned children 384 // Handle orphaned children
385 if ( mUndoIncidence ) delete mUndoIncidence; 385 if ( mUndoIncidence ) delete mUndoIncidence;
386 removeRelations( todo ); 386 removeRelations( todo );
387 mUndoIncidence = todo->clone(); 387 mUndoIncidence = todo->clone();
388 388
389 if ( mTodoList.removeRef( todo ) ) { 389 if ( mTodoList.removeRef( todo ) ) {
390 setModified( true ); 390 setModified( true );
391 } 391 }
392} 392}
393 393
394QPtrList<Todo> CalendarLocal::rawTodos() 394QPtrList<Todo> CalendarLocal::rawTodos()
395{ 395{
396 QPtrList<Todo> el; 396 QPtrList<Todo> el;
397 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 397 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
398 if ( it->calEnabled() ) el.append( it ); 398 if ( it->calEnabled() ) el.append( it );
399 return el; 399 return el;
400} 400}
401Todo *CalendarLocal::todo( QString syncProf, QString id ) 401Todo *CalendarLocal::todo( QString syncProf, QString id )
402{ 402{
403 Todo *todo; 403 Todo *todo;
404 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 404 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
405 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 405 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
406 } 406 }
407 407
408 return 0; 408 return 0;
409} 409}
410void CalendarLocal::removeSyncInfo( QString syncProfile) 410void CalendarLocal::removeSyncInfo( QString syncProfile)
411{ 411{
412 QPtrList<Incidence> all = rawIncidences() ; 412 QPtrList<Incidence> all = rawIncidences() ;
413 Incidence *inc; 413 Incidence *inc;
414 for ( inc = all.first(); inc; inc = all.next() ) { 414 for ( inc = all.first(); inc; inc = all.next() ) {
415 inc->removeID( syncProfile ); 415 inc->removeID( syncProfile );
416 } 416 }
417 if ( syncProfile.isEmpty() ) { 417 if ( syncProfile.isEmpty() ) {
418 QPtrList<Event> el; 418 QPtrList<Event> el;
419 Event *todo; 419 Event *todo;
420 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 420 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
421 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 421 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
422 el.append( todo ); 422 el.append( todo );
423 } 423 }
424 for ( todo = el.first(); todo; todo = el.next() ) { 424 for ( todo = el.first(); todo; todo = el.next() ) {
425 deleteIncidence ( todo ); 425 deleteIncidence ( todo );
426 } 426 }
427 } else { 427 } else {
428 Event *lse = event( "last-syncEvent-"+ syncProfile); 428 Event *lse = event( "last-syncEvent-"+ syncProfile);
429 if ( lse ) 429 if ( lse )
430 deleteIncidence ( lse ); 430 deleteIncidence ( lse );
431 } 431 }
432} 432}
433QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 433QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
434{ 434{
435 QPtrList<Event> el; 435 QPtrList<Event> el;
436 Event *todo; 436 Event *todo;
437 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 437 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
438 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 438 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
439 if ( todo->summary().left(3) == "E: " ) 439 if ( todo->summary().left(3) == "E: " )
440 el.append( todo ); 440 el.append( todo );
441 } 441 }
442 442
443 return el; 443 return el;
444 444
445} 445}
446Event *CalendarLocal::event( QString syncProf, QString id ) 446Event *CalendarLocal::event( QString syncProf, QString id )
447{ 447{
448 Event *todo; 448 Event *todo;
449 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 449 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
450 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 450 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
451 } 451 }
452 452
453 return 0; 453 return 0;
454} 454}
455Todo *CalendarLocal::todo( const QString &uid ) 455Todo *CalendarLocal::todo( const QString &uid )
456{ 456{
457 Todo *todo;; 457 Todo *todo;;
458 Todo *retVal = 0; 458 Todo *retVal = 0;
459 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 459 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
460 if ( todo->calEnabled() && todo->uid() == uid ) { 460 if ( todo->calEnabled() && todo->uid() == uid ) {
461 if ( retVal ) { 461 if ( retVal ) {
462 if ( retVal->calID() > todo->calID() ) { 462 if ( retVal->calID() > todo->calID() ) {
463 retVal = todo; 463 retVal = todo;
464 } 464 }
465 } else { 465 } else {
466 retVal = todo; 466 retVal = todo;
467 } 467 }
468 } 468 }
469 } 469 }
470 return retVal; 470 return retVal;
471} 471}
472QString CalendarLocal::nextSummary() const 472QString CalendarLocal::nextSummary() const
473{ 473{
474 return mNextSummary; 474 return mNextSummary;
475} 475}
476QDateTime CalendarLocal::nextAlarmEventDateTime() const 476QDateTime CalendarLocal::nextAlarmEventDateTime() const
477{ 477{
478 return mNextAlarmEventDateTime; 478 return mNextAlarmEventDateTime;
479} 479}
480void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 480void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
481{ 481{
482 //mNextAlarmIncidence 482 //mNextAlarmIncidence
483 //mNextAlarmDateTime 483 //mNextAlarmDateTime
484 //return mNextSummary; 484 //return mNextSummary;
485 //return mNextAlarmEventDateTime; 485 //return mNextAlarmEventDateTime;
486 bool newNextAlarm = false; 486 bool newNextAlarm = false;
487 bool computeNextAlarm = false; 487 bool computeNextAlarm = false;
488 bool ok; 488 bool ok;
489 int offset; 489 int offset;
490 QDateTime nextA; 490 QDateTime nextA;
491 // QString nextSum; 491 // QString nextSum;
492 //QDateTime nextEvent; 492 //QDateTime nextEvent;
493 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 493 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
494 computeNextAlarm = true; 494 computeNextAlarm = true;
495 } else { 495 } else {
496 if ( ! deleted ) { 496 if ( ! deleted ) {
497 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 497 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
498 if ( ok ) { 498 if ( ok ) {
499 if ( nextA < mNextAlarmDateTime ) { 499 if ( nextA < mNextAlarmDateTime ) {
500 deRegisterAlarm(); 500 deRegisterAlarm();
501 mNextAlarmDateTime = nextA; 501 mNextAlarmDateTime = nextA;
502 mNextSummary = incidence->summary(); 502 mNextSummary = incidence->summary();
503 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 503 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
504 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 504 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
505 newNextAlarm = true; 505 newNextAlarm = true;
506 mNextAlarmIncidence = incidence; 506 mNextAlarmIncidence = incidence;
507 } else { 507 } else {
508 if ( incidence == mNextAlarmIncidence ) { 508 if ( incidence == mNextAlarmIncidence ) {
509 computeNextAlarm = true; 509 computeNextAlarm = true;
510 } 510 }
511 } 511 }
512 } else { 512 } else {
513 if ( mNextAlarmIncidence == incidence ) { 513 if ( mNextAlarmIncidence == incidence ) {
514 computeNextAlarm = true; 514 computeNextAlarm = true;
515 } 515 }
516 } 516 }
517 } else { // deleted 517 } else { // deleted
518 if ( incidence == mNextAlarmIncidence ) { 518 if ( incidence == mNextAlarmIncidence ) {
519 computeNextAlarm = true; 519 computeNextAlarm = true;
520 } 520 }
521 } 521 }
522 } 522 }
523 if ( computeNextAlarm ) { 523 if ( computeNextAlarm ) {
524 deRegisterAlarm(); 524 deRegisterAlarm();
525 nextA = nextAlarm( 1000 ); 525 nextA = nextAlarm( 1000 );
526 if (! mNextAlarmIncidence ) { 526 if (! mNextAlarmIncidence ) {
527 return; 527 return;
528 } 528 }
529 newNextAlarm = true; 529 newNextAlarm = true;
530 } 530 }
531 if ( newNextAlarm ) 531 if ( newNextAlarm )
532 registerAlarm(); 532 registerAlarm();
533} 533}
534QString CalendarLocal:: getAlarmNotification() 534QString CalendarLocal:: getAlarmNotification()
535{ 535{
536 QString ret; 536 QString ret;
537 // this should not happen 537 // this should not happen
538 if (! mNextAlarmIncidence ) 538 if (! mNextAlarmIncidence )
539 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 539 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
540 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 540 Alarm* alarm = mNextAlarmIncidence->alarms().first();
541 if ( alarm->type() == Alarm::Procedure ) { 541 if ( alarm->type() == Alarm::Procedure ) {
542 ret = "proc_alarm" + alarm->programFile()+"+++"; 542 ret = "proc_alarm" + alarm->programFile()+"+++";
543 } else { 543 } else {
544 ret = "audio_alarm" +alarm->audioFile() +"+++"; 544 ret = "audio_alarm" +alarm->audioFile() +"+++";
545 } 545 }
546 ret += "cal_alarm"+ mNextSummary.left( 25 ); 546 ret += "cal_alarm"+ mNextSummary.left( 25 );
547 if ( mNextSummary.length() > 25 ) 547 if ( mNextSummary.length() > 25 )
548 ret += "\n" + mNextSummary.mid(25, 25 ); 548 ret += "\n" + mNextSummary.mid(25, 25 );
549 ret+= "\n"+mNextAlarmEventDateTimeString; 549 ret+= "\n"+mNextAlarmEventDateTimeString;
550 return ret; 550 return ret;
551} 551}
552void CalendarLocal::registerAlarm() 552void CalendarLocal::registerAlarm()
553{ 553{
554 mLastAlarmNotificationString = getAlarmNotification(); 554 mLastAlarmNotificationString = getAlarmNotification();
555 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 555 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
556 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 556 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
557// #ifndef DESKTOP_VERSION 557// #ifndef DESKTOP_VERSION
558// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 558// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
559// #endif 559// #endif
560} 560}
561void CalendarLocal::deRegisterAlarm() 561void CalendarLocal::deRegisterAlarm()
562{ 562{
563 if ( mLastAlarmNotificationString.isNull() ) 563 if ( mLastAlarmNotificationString.isNull() )
564 return; 564 return;
565 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 565 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
566 566
567 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 567 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
568 mNextAlarmEventDateTime = QDateTime(); 568 mNextAlarmEventDateTime = QDateTime();
569// #ifndef DESKTOP_VERSION 569// #ifndef DESKTOP_VERSION
570// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 570// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
571// #endif 571// #endif
572} 572}
573 573
574QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 574QPtrList<Todo> CalendarLocal::todos( const QDate &date )
575{ 575{
576 QPtrList<Todo> todos; 576 QPtrList<Todo> todos;
577 577
578 Todo *todo; 578 Todo *todo;
579 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 579 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
580 if ( !todo->calEnabled() ) continue; 580 if ( !todo->calEnabled() ) continue;
581 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 581 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
582 todos.append( todo ); 582 todos.append( todo );
583 } 583 }
584 } 584 }
585 585
586 filter()->apply( &todos ); 586 filter()->apply( &todos );
587 return todos; 587 return todos;
588} 588}
589void CalendarLocal::reInitAlarmSettings() 589void CalendarLocal::reInitAlarmSettings()
590{ 590{
591 if ( !mNextAlarmIncidence ) { 591 if ( !mNextAlarmIncidence ) {
592 nextAlarm( 1000 ); 592 nextAlarm( 1000 );
593 } 593 }
594 deRegisterAlarm(); 594 deRegisterAlarm();
595 mNextAlarmIncidence = 0; 595 mNextAlarmIncidence = 0;
596 checkAlarmForIncidence( 0, false ); 596 checkAlarmForIncidence( 0, false );
597 597
598} 598}
599 599
600 600
601 601
602QDateTime CalendarLocal::nextAlarm( int daysTo ) 602QDateTime CalendarLocal::nextAlarm( int daysTo )
603{ 603{
604 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 604 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
605 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 605 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
606 QDateTime next; 606 QDateTime next;
607 Event *e; 607 Event *e;
608 bool ok; 608 bool ok;
609 bool found = false; 609 bool found = false;
610 int offset; 610 int offset;
611 mNextAlarmIncidence = 0; 611 mNextAlarmIncidence = 0;
612 for( e = mEventList.first(); e; e = mEventList.next() ) { 612 for( e = mEventList.first(); e; e = mEventList.next() ) {
613 if ( !e->calEnabled() ) continue; 613 if ( !e->calEnabled() ) continue;
614 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 614 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
615 if ( ok ) { 615 if ( ok ) {
616 if ( next < nextA ) { 616 if ( next < nextA ) {
617 nextA = next; 617 nextA = next;
618 found = true; 618 found = true;
619 mNextSummary = e->summary(); 619 mNextSummary = e->summary();
620 mNextAlarmEventDateTime = next.addSecs(offset ) ; 620 mNextAlarmEventDateTime = next.addSecs(offset ) ;
621 mNextAlarmIncidence = (Incidence *) e; 621 mNextAlarmIncidence = (Incidence *) e;
622 } 622 }
623 } 623 }
624 } 624 }
625 Todo *t; 625 Todo *t;
626 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 626 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
627 if ( !t->calEnabled() ) continue; 627 if ( !t->calEnabled() ) continue;
628 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 628 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
629 if ( ok ) { 629 if ( ok ) {
630 if ( next < nextA ) { 630 if ( next < nextA ) {
631 nextA = next; 631 nextA = next;
632 found = true; 632 found = true;
633 mNextSummary = t->summary(); 633 mNextSummary = t->summary();
634 mNextAlarmEventDateTime = next.addSecs(offset ); 634 mNextAlarmEventDateTime = next.addSecs(offset );
635 mNextAlarmIncidence = (Incidence *) t; 635 mNextAlarmIncidence = (Incidence *) t;
636 } 636 }
637 } 637 }
638 } 638 }
639 if ( mNextAlarmIncidence ) { 639 if ( mNextAlarmIncidence ) {
640 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 640 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
641 mNextAlarmDateTime = nextA; 641 mNextAlarmDateTime = nextA;
642 } 642 }
643 return nextA; 643 return nextA;
644} 644}
645Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 645Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
646{ 646{
647 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 647 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
648} 648}
649 649
650Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 650Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
651{ 651{
652 652
653 Alarm::List alarms; 653 Alarm::List alarms;
654 654
655 Event *e; 655 Event *e;
656 656
657 for( e = mEventList.first(); e; e = mEventList.next() ) { 657 for( e = mEventList.first(); e; e = mEventList.next() ) {
658 if ( !e->calEnabled() ) continue; 658 if ( !e->calEnabled() ) continue;
659 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 659 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
660 else appendAlarms( alarms, e, from, to ); 660 else appendAlarms( alarms, e, from, to );
661 } 661 }
662 662
663 Todo *t; 663 Todo *t;
664 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 664 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
665 if ( !t->calEnabled() ) continue; 665 if ( !t->calEnabled() ) continue;
666 appendAlarms( alarms, t, from, to ); 666 appendAlarms( alarms, t, from, to );
667 } 667 }
668 668
669 return alarms; 669 return alarms;
670} 670}
671 671
672void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 672void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
673 const QDateTime &from, const QDateTime &to ) 673 const QDateTime &from, const QDateTime &to )
674{ 674{
675 QPtrList<Alarm> alarmList = incidence->alarms(); 675 QPtrList<Alarm> alarmList = incidence->alarms();
676 Alarm *alarm; 676 Alarm *alarm;
677 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 677 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
678// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 678// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
679// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 679// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
680 if ( alarm->enabled() ) { 680 if ( alarm->enabled() ) {
681 if ( alarm->time() >= from && alarm->time() <= to ) { 681 if ( alarm->time() >= from && alarm->time() <= to ) {
682 alarms.append( alarm ); 682 alarms.append( alarm );
683 } 683 }
684 } 684 }
685 } 685 }
686} 686}
687 687
688void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 688void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
689 Incidence *incidence, 689 Incidence *incidence,
690 const QDateTime &from, 690 const QDateTime &from,
691 const QDateTime &to ) 691 const QDateTime &to )
692{ 692{
693 693
694 QPtrList<Alarm> alarmList = incidence->alarms(); 694 QPtrList<Alarm> alarmList = incidence->alarms();
695 Alarm *alarm; 695 Alarm *alarm;
696 QDateTime qdt; 696 QDateTime qdt;
697 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 697 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
698 if (incidence->recursOn(from.date())) { 698 if (incidence->recursOn(from.date())) {
699 qdt.setTime(alarm->time().time()); 699 qdt.setTime(alarm->time().time());
700 qdt.setDate(from.date()); 700 qdt.setDate(from.date());
701 } 701 }
702 else qdt = alarm->time(); 702 else qdt = alarm->time();
703 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 703 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
704 if ( alarm->enabled() ) { 704 if ( alarm->enabled() ) {
705 if ( qdt >= from && qdt <= to ) { 705 if ( qdt >= from && qdt <= to ) {
706 alarms.append( alarm ); 706 alarms.append( alarm );
707 } 707 }
708 } 708 }
709 } 709 }
710} 710}
711 711
712 712
713/****************************** PROTECTED METHODS ****************************/ 713/****************************** PROTECTED METHODS ****************************/
714 714
715// after changes are made to an event, this should be called. 715// after changes are made to an event, this should be called.
716void CalendarLocal::update( IncidenceBase *incidence ) 716void CalendarLocal::update( IncidenceBase *incidence )
717{ 717{
718 incidence->setSyncStatus( Event::SYNCMOD ); 718 incidence->setSyncStatus( Event::SYNCMOD );
719 incidence->setLastModified( QDateTime::currentDateTime() ); 719 incidence->setLastModified( QDateTime::currentDateTime() );
720 // we should probably update the revision number here, 720 // we should probably update the revision number here,
721 // or internally in the Event itself when certain things change. 721 // or internally in the Event itself when certain things change.
722 // need to verify with ical documentation. 722 // need to verify with ical documentation.
723 723
724 setModified( true ); 724 setModified( true );
725} 725}
726 726
727void CalendarLocal::insertEvent( Event *event ) 727void CalendarLocal::insertEvent( Event *event )
728{ 728{
729 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 729 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
730} 730}
731 731
732 732
733QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 733QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
734{ 734{
735 QPtrList<Event> eventList; 735 QPtrList<Event> eventList;
736 736
737 Event *event; 737 Event *event;
738 for( event = mEventList.first(); event; event = mEventList.next() ) { 738 for( event = mEventList.first(); event; event = mEventList.next() ) {
739 if ( !event->calEnabled() ) continue; 739 if ( !event->calEnabled() ) continue;
740 if ( event->doesRecur() ) { 740 if ( event->doesRecur() ) {
741 if ( event->isMultiDay() ) { 741 if ( event->isMultiDay() ) {
742 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 742 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
743 int i; 743 int i;
744 for ( i = 0; i <= extraDays; i++ ) { 744 for ( i = 0; i <= extraDays; i++ ) {
745 if ( event->recursOn( qd.addDays( -i ) ) ) { 745 if ( event->recursOn( qd.addDays( -i ) ) ) {
746 eventList.append( event ); 746 eventList.append( event );
747 break; 747 break;
748 } 748 }
749 } 749 }
750 } else { 750 } else {
751 if ( event->recursOn( qd ) ) 751 if ( event->recursOn( qd ) )
752 eventList.append( event ); 752 eventList.append( event );
753 } 753 }
754 } else { 754 } else {
755 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 755 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
756 eventList.append( event ); 756 eventList.append( event );
757 } 757 }
758 } 758 }
759 } 759 }
760 760
761 if ( !sorted ) { 761 if ( !sorted ) {
762 return eventList; 762 return eventList;
763 } 763 }
764 764
765 // kdDebug(5800) << "Sorting events for date\n" << endl; 765 // kdDebug(5800) << "Sorting events for date\n" << endl;
766 // now, we have to sort it based on dtStart.time() 766 // now, we have to sort it based on dtStart.time()
767 QPtrList<Event> eventListSorted; 767 QPtrList<Event> eventListSorted;
768 Event *sortEvent; 768 Event *sortEvent;
769 for ( event = eventList.first(); event; event = eventList.next() ) { 769 for ( event = eventList.first(); event; event = eventList.next() ) {
770 sortEvent = eventListSorted.first(); 770 sortEvent = eventListSorted.first();
771 int i = 0; 771 int i = 0;
772 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 772 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
773 { 773 {
774 i++; 774 i++;
775 sortEvent = eventListSorted.next(); 775 sortEvent = eventListSorted.next();
776 } 776 }
777 eventListSorted.insert( i, event ); 777 eventListSorted.insert( i, event );
778 } 778 }
779 return eventListSorted; 779 return eventListSorted;
780} 780}
781 781
782 782
783QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 783QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
784 bool inclusive ) 784 bool inclusive )
785{ 785{
786 Event *event = 0; 786 Event *event = 0;
787 787
788 QPtrList<Event> eventList; 788 QPtrList<Event> eventList;
789 789
790 // Get non-recurring events 790 // Get non-recurring events
791 for( event = mEventList.first(); event; event = mEventList.next() ) { 791 for( event = mEventList.first(); event; event = mEventList.next() ) {
792 if ( !event->calEnabled() ) continue; 792 if ( !event->calEnabled() ) continue;
793 if ( event->doesRecur() ) { 793 if ( event->doesRecur() ) {
794 QDate rStart = event->dtStart().date(); 794 QDate rStart = event->dtStart().date();
795 bool found = false; 795 bool found = false;
796 if ( inclusive ) { 796 if ( inclusive ) {
797 if ( rStart >= start && rStart <= end ) { 797 if ( rStart >= start && rStart <= end ) {
798 // Start date of event is in range. Now check for end date. 798 // Start date of event is in range. Now check for end date.
799 // if duration is negative, event recurs forever, so do not include it. 799 // if duration is negative, event recurs forever, so do not include it.
800 if ( event->recurrence()->duration() == 0 ) { // End date set 800 if ( event->recurrence()->duration() == 0 ) { // End date set
801 QDate rEnd = event->recurrence()->endDate(); 801 QDate rEnd = event->recurrence()->endDate();
802 if ( rEnd >= start && rEnd <= end ) { // End date within range 802 if ( rEnd >= start && rEnd <= end ) { // End date within range
803 found = true; 803 found = true;
804 } 804 }
805 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 805 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
806 // TODO: Calculate end date from duration. Should be done in Event 806 // TODO: Calculate end date from duration. Should be done in Event
807 // For now exclude all events with a duration. 807 // For now exclude all events with a duration.
808 } 808 }
809 } 809 }
810 } else { 810 } else {
811 bool founOne; 811 bool founOne;
812 QDate next = event->getNextOccurence( start, &founOne ).date(); 812 QDate next = event->getNextOccurence( start, &founOne ).date();
813 if ( founOne ) { 813 if ( founOne ) {
814 if ( next <= end ) { 814 if ( next <= end ) {
815 found = true; 815 found = true;
816 } 816 }
817 } 817 }
818 818
819 /* 819 /*
820 // crap !!! 820 // crap !!!
821 if ( rStart <= end ) { // Start date not after range 821 if ( rStart <= end ) { // Start date not after range
822 if ( rStart >= start ) { // Start date within range 822 if ( rStart >= start ) { // Start date within range
823 found = true; 823 found = true;
824 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 824 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
825 found = true; 825 found = true;
826 } else if ( event->recurrence()->duration() == 0 ) { // End date set 826 } else if ( event->recurrence()->duration() == 0 ) { // End date set
827 QDate rEnd = event->recurrence()->endDate(); 827 QDate rEnd = event->recurrence()->endDate();
828 if ( rEnd >= start && rEnd <= end ) { // End date within range 828 if ( rEnd >= start && rEnd <= end ) { // End date within range
829 found = true; 829 found = true;
830 } 830 }
831 } else { // Duration set 831 } else { // Duration set
832 // TODO: Calculate end date from duration. Should be done in Event 832 // TODO: Calculate end date from duration. Should be done in Event
833 // For now include all events with a duration. 833 // For now include all events with a duration.
834 found = true; 834 found = true;
835 } 835 }
836 } 836 }
837 */ 837 */
838 838
839 } 839 }
840 840
841 if ( found ) eventList.append( event ); 841 if ( found ) eventList.append( event );
842 } else { 842 } else {
843 QDate s = event->dtStart().date(); 843 QDate s = event->dtStart().date();
844 QDate e = event->dtEnd().date(); 844 QDate e = event->dtEnd().date();
845 845
846 if ( inclusive ) { 846 if ( inclusive ) {
847 if ( s >= start && e <= end ) { 847 if ( s >= start && e <= end ) {
848 eventList.append( event ); 848 eventList.append( event );
849 } 849 }
850 } else { 850 } else {
851 if ( ( e >= start && s <= end ) ) { 851 if ( ( e >= start && s <= end ) ) {
852 eventList.append( event ); 852 eventList.append( event );
853 } 853 }
854 } 854 }
855 } 855 }
856 } 856 }
857 857
858 return eventList; 858 return eventList;
859} 859}
860 860
861QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 861QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
862{ 862{
863 return rawEventsForDate( qdt.date() ); 863 return rawEventsForDate( qdt.date() );
864} 864}
865 865
866QPtrList<Event> CalendarLocal::rawEvents() 866QPtrList<Event> CalendarLocal::rawEvents()
867{ 867{
868 QPtrList<Event> el; 868 QPtrList<Event> el;
869 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 869 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
870 if ( it->calEnabled() ) el.append( it ); 870 if ( it->calEnabled() ) el.append( it );
871 return el; 871 return el;
872} 872}
873 873
874bool CalendarLocal::addJournal(Journal *journal) 874bool CalendarLocal::addJournal(Journal *journal)
875{ 875{
876 mJournalList.append(journal); 876 mJournalList.append(journal);
877 877
878 journal->registerObserver( this ); 878 journal->registerObserver( this );
879 879
880 setModified( true ); 880 setModified( true );
881 if ( journal->calID() == 0 ) 881 if ( journal->calID() == 0 )
882 journal->setCalID( mDefaultCalendar ); 882 journal->setCalID( mDefaultCalendar );
883 journal->setCalEnabled( true ); 883 journal->setCalEnabled( true );
884 return true; 884 return true;
885} 885}
886 886
887void CalendarLocal::deleteJournal( Journal *journal ) 887void CalendarLocal::deleteJournal( Journal *journal )
888{ 888{
889 if ( mUndoIncidence ) delete mUndoIncidence; 889 if ( mUndoIncidence ) delete mUndoIncidence;
890 mUndoIncidence = journal->clone(); 890 mUndoIncidence = journal->clone();
891 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 891 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
892 if ( mJournalList.removeRef(journal) ) { 892 if ( mJournalList.removeRef(journal) ) {
893 setModified( true ); 893 setModified( true );
894 } 894 }
895} 895}
896 896
897QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 897QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
898{ 898{
899 QPtrList<Journal> el; 899 QPtrList<Journal> el;
900 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 900 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
901 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 901 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
902 return el; 902 return el;
903} 903}
904Journal *CalendarLocal::journal( const QDate &date ) 904Journal *CalendarLocal::journal( const QDate &date )
905{ 905{
906// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 906// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
907 907
908 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 908 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
909 if ( it->calEnabled() && it->dtStart().date() == date ) 909 if ( it->calEnabled() && it->dtStart().date() == date )
910 return it; 910 return it;
911 911
912 return 0; 912 return 0;
913} 913}
914 914
915Journal *CalendarLocal::journal( const QString &uid ) 915Journal *CalendarLocal::journal( const QString &uid )
916{ 916{
917 Journal * retVal = 0; 917 Journal * retVal = 0;
918 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 918 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
919 if ( it->calEnabled() && it->uid() == uid ) { 919 if ( it->calEnabled() && it->uid() == uid ) {
920 if ( retVal ) { 920 if ( retVal ) {
921 if ( retVal->calID() > it->calID() ) { 921 if ( retVal->calID() > it->calID() ) {
922 retVal = it; 922 retVal = it;
923 } 923 }
924 } else { 924 } else {
925 retVal = it; 925 retVal = it;
926 } 926 }
927 } 927 }
928 return retVal; 928 return retVal;
929} 929}
930 930
931QPtrList<Journal> CalendarLocal::journals() 931QPtrList<Journal> CalendarLocal::journals()
932{ 932{
933 QPtrList<Journal> el; 933 QPtrList<Journal> el;
934 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 934 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
935 if ( it->calEnabled() ) el.append( it ); 935 if ( it->calEnabled() ) el.append( it );
936 return el; 936 return el;
937} 937}
938void CalendarLocal::setCalendarRemove( int id ) 938void CalendarLocal::setCalendarRemove( int id )
939{ 939{
940 940
941 { 941 {
942 QPtrList<Event> EventList = mEventList; 942 QPtrList<Event> EventList = mEventList;
943 Event * ev = EventList.first(); 943 Event * ev = EventList.first();
944 while ( ev ) { 944 while ( ev ) {
945 if ( ev->calID() == id ) 945 if ( ev->calID() == id )
946 deleteEvent( ev ); 946 deleteEvent( ev );
947 ev = EventList.next(); 947 ev = EventList.next();
948 } 948 }
949 } 949 }
950 { 950 {
951 951
952 QPtrList<Todo> TodoList = mTodoList; 952 QPtrList<Todo> TodoList = mTodoList;
953 Todo * ev = TodoList.first(); 953 Todo * ev = TodoList.first();
954 while ( ev ) { 954 while ( ev ) {
955 if ( ev->calID() == id ) 955 if ( ev->calID() == id )
956 deleteTodo( ev ); 956 deleteTodo( ev );
957 ev = TodoList.next(); 957 ev = TodoList.next();
958 } 958 }
959 } 959 }
960 { 960 {
961 QPtrList<Journal> JournalList = mJournalList; 961 QPtrList<Journal> JournalList = mJournalList;
962 Journal * ev = JournalList.first(); 962 Journal * ev = JournalList.first();
963 while ( ev ) { 963 while ( ev ) {
964 if ( ev->calID() == id ) 964 if ( ev->calID() == id )
965 deleteJournal( ev ); 965 deleteJournal( ev );
966 ev = JournalList.next(); 966 ev = JournalList.next();
967 } 967 }
968 } 968 }
969 969
970 if ( mUndoIncidence ) delete mUndoIncidence; 970 if ( mUndoIncidence ) delete mUndoIncidence;
971 mUndoIncidence = 0; 971 mUndoIncidence = 0;
972 972
973} 973}
974 974
975void CalendarLocal::setCalendarEnabled( int id, bool enable ) 975void CalendarLocal::setCalendarEnabled( int id, bool enable )
976{ 976{
977 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 977 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
978 if ( it->calID() == id ) it->setCalEnabled( enable ); 978 if ( it->calID() == id ) it->setCalEnabled( enable );
979 979
980 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 980 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
981 if ( it->calID() == id ) it->setCalEnabled( enable ); 981 if ( it->calID() == id ) it->setCalEnabled( enable );
982 982
983 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 983 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
984 if ( it->calID() == id ) it->setCalEnabled( enable ); 984 if ( it->calID() == id ) it->setCalEnabled( enable );
985 985
986} 986}
987 987
988void CalendarLocal::setReadOnly( int id, bool enable ) 988void CalendarLocal::setReadOnly( int id, bool enable )
989{ 989{
990 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 990 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
991 if ( it->calID() == id ) it->setReadOnly( enable ); 991 if ( it->calID() == id ) it->setReadOnly( enable );
992 992
993 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 993 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
994 if ( it->calID() == id ) it->setReadOnly( enable ); 994 if ( it->calID() == id ) it->setReadOnly( enable );
995 995
996 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 996 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
997 if ( it->calID() == id ) it->setReadOnly( enable ); 997 if ( it->calID() == id ) it->setReadOnly( enable );
998 998
999} 999}
1000 1000
1001void CalendarLocal::setAlarmEnabled( int id, bool enable ) 1001void CalendarLocal::setAlarmEnabled( int id, bool enable )
1002{ 1002{
1003 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1003 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1004 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1004 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1005 1005
1006 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1006 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1007 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1007 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1008 1008
1009 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1009 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1010 if ( it->calID() == id ) it->setAlarmEnabled( enable ); 1010 if ( it->calID() == id ) it->setAlarmEnabled( enable );
1011 reInitAlarmSettings(); 1011 reInitAlarmSettings();
1012 1012
1013} 1013}
1014void CalendarLocal::setDefaultCalendarEnabledOnly() 1014void CalendarLocal::setDefaultCalendarEnabledOnly()
1015{ 1015{
1016 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1016 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1017 it->setCalEnabled( it->calID() == mDefaultCalendar ); 1017 it->setCalEnabled( it->calID() == mDefaultCalendar );
1018 1018
1019 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 1019 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
1020 it->setCalEnabled( it->calID() == mDefaultCalendar); 1020 it->setCalEnabled( it->calID() == mDefaultCalendar);
1021 1021
1022 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 1022 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
1023 it->setCalEnabled( it->calID() == mDefaultCalendar); 1023 it->setCalEnabled( it->calID() == mDefaultCalendar);
1024 1024
1025} 1025}
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index f349681..53aa039 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1,2173 +1,2176 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <qdatetime.h> 21#include <qdatetime.h>
22#include <qstring.h> 22#include <qstring.h>
23#include <qptrlist.h> 23#include <qptrlist.h>
24#include <qfile.h> 24#include <qfile.h>
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28#include <kglobal.h> 28#include <kglobal.h>
29 29
30extern "C" { 30extern "C" {
31 #include <ical.h> 31 #include <ical.h>
32 #include <icalss.h> 32 #include <icalss.h>
33 #include <icalparser.h> 33 #include <icalparser.h>
34 #include <icalrestriction.h> 34 #include <icalrestriction.h>
35} 35}
36 36
37#include "calendar.h" 37#include "calendar.h"
38#include "journal.h" 38#include "journal.h"
39#include "icalformat.h" 39#include "icalformat.h"
40#include "icalformatimpl.h" 40#include "icalformatimpl.h"
41#include "compat.h" 41#include "compat.h"
42 42
43#define _ICAL_VERSION "2.0" 43#define _ICAL_VERSION "2.0"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47const int gSecondsPerMinute = 60; 47const int gSecondsPerMinute = 60;
48const int gSecondsPerHour = gSecondsPerMinute * 60; 48const int gSecondsPerHour = gSecondsPerMinute * 60;
49const int gSecondsPerDay = gSecondsPerHour * 24; 49const int gSecondsPerDay = gSecondsPerHour * 24;
50const int gSecondsPerWeek = gSecondsPerDay * 7; 50const int gSecondsPerWeek = gSecondsPerDay * 7;
51 51
52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) : 52ICalFormatImpl::ICalFormatImpl( ICalFormat *parent ) :
53 mParent( parent ), mCalendarVersion( 0 ) 53 mParent( parent ), mCalendarVersion( 0 )
54{ 54{
55 mCompat = new Compat; 55 mCompat = new Compat;
56} 56}
57 57
58ICalFormatImpl::~ICalFormatImpl() 58ICalFormatImpl::~ICalFormatImpl()
59{ 59{
60 delete mCompat; 60 delete mCompat;
61} 61}
62 62
63class ToStringVisitor : public Incidence::Visitor 63class ToStringVisitor : public Incidence::Visitor
64{ 64{
65 public: 65 public:
66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {} 66 ToStringVisitor( ICalFormatImpl *impl ) : mImpl( impl ), mComponent( 0 ) {}
67 67
68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; } 68 bool visit( Event *e ) { mComponent = mImpl->writeEvent( e ); return true; }
69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; } 69 bool visit( Todo *e ) { mComponent = mImpl->writeTodo( e ); return true; }
70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; } 70 bool visit( Journal *e ) { mComponent = mImpl->writeJournal( e ); return true; }
71 71
72 icalcomponent *component() { return mComponent; } 72 icalcomponent *component() { return mComponent; }
73 73
74 private: 74 private:
75 ICalFormatImpl *mImpl; 75 ICalFormatImpl *mImpl;
76 icalcomponent *mComponent; 76 icalcomponent *mComponent;
77}; 77};
78 78
79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence) 79icalcomponent *ICalFormatImpl::writeIncidence(Incidence *incidence)
80{ 80{
81 ToStringVisitor v( this ); 81 ToStringVisitor v( this );
82 incidence->accept(v); 82 incidence->accept(v);
83 return v.component(); 83 return v.component();
84} 84}
85 85
86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo) 86icalcomponent *ICalFormatImpl::writeTodo(Todo *todo)
87{ 87{
88 QString tmpStr; 88 QString tmpStr;
89 QStringList tmpStrList; 89 QStringList tmpStrList;
90 90
91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT); 91 icalcomponent *vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
92 92
93 writeIncidence(vtodo,todo); 93 writeIncidence(vtodo,todo);
94 94
95 // due date 95 // due date
96 if (todo->hasDueDate()) { 96 if (todo->hasDueDate()) {
97 icaltimetype due; 97 icaltimetype due;
98 if (todo->doesFloat()) { 98 if (todo->doesFloat()) {
99 due = writeICalDate(todo->dtDue().date()); 99 due = writeICalDate(todo->dtDue().date());
100 } else { 100 } else {
101 due = writeICalDateTime(todo->dtDue()); 101 due = writeICalDateTime(todo->dtDue());
102 } 102 }
103 icalcomponent_add_property(vtodo,icalproperty_new_due(due)); 103 icalcomponent_add_property(vtodo,icalproperty_new_due(due));
104 } 104 }
105 105
106 // start time 106 // start time
107 if (todo->hasStartDate()) { 107 if (todo->hasStartDate()) {
108 icaltimetype start; 108 icaltimetype start;
109 if (todo->doesFloat()) { 109 if (todo->doesFloat()) {
110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl; 110// kdDebug(5800) << "§§ Incidence " << todo->summary() << " floats." << endl;
111 start = writeICalDate(todo->dtStart().date()); 111 start = writeICalDate(todo->dtStart().date());
112 } else { 112 } else {
113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl; 113// kdDebug(5800) << "§§ incidence " << todo->summary() << " has time." << endl;
114 start = writeICalDateTime(todo->dtStart()); 114 start = writeICalDateTime(todo->dtStart());
115 } 115 }
116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start)); 116 icalcomponent_add_property(vtodo,icalproperty_new_dtstart(start));
117 } 117 }
118 118
119 // completion date 119 // completion date
120 if (todo->isCompleted()) { 120 if (todo->isCompleted()) {
121 if (!todo->hasCompletedDate()) { 121 if (!todo->hasCompletedDate()) {
122 // If todo was created by KOrganizer <2.2 it has no correct completion 122 // If todo was created by KOrganizer <2.2 it has no correct completion
123 // date. Set it to now. 123 // date. Set it to now.
124 todo->setCompleted(QDateTime::currentDateTime()); 124 todo->setCompleted(QDateTime::currentDateTime());
125 } 125 }
126 icaltimetype completed = writeICalDateTime(todo->completed()); 126 icaltimetype completed = writeICalDateTime(todo->completed());
127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed)); 127 icalcomponent_add_property(vtodo,icalproperty_new_completed(completed));
128 } 128 }
129 129
130 icalcomponent_add_property(vtodo, 130 icalcomponent_add_property(vtodo,
131 icalproperty_new_percentcomplete(todo->percentComplete())); 131 icalproperty_new_percentcomplete(todo->percentComplete()));
132 132
133 return vtodo; 133 return vtodo;
134} 134}
135 135
136icalcomponent *ICalFormatImpl::writeEvent(Event *event) 136icalcomponent *ICalFormatImpl::writeEvent(Event *event)
137{ 137{
138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid() 138 kdDebug(5800) << "Write Event '" << event->summary() << "' (" << event->uid()
139 << ")" << endl; 139 << ")" << endl;
140 140
141 QString tmpStr; 141 QString tmpStr;
142 QStringList tmpStrList; 142 QStringList tmpStrList;
143 143
144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT); 144 icalcomponent *vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
145 145
146 writeIncidence(vevent,event); 146 writeIncidence(vevent,event);
147 147
148 // start time 148 // start time
149 icaltimetype start; 149 icaltimetype start;
150 if (event->doesFloat()) { 150 if (event->doesFloat()) {
151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 151// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
152 start = writeICalDate(event->dtStart().date()); 152 start = writeICalDate(event->dtStart().date());
153 } else { 153 } else {
154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 154// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
155 start = writeICalDateTime(event->dtStart()); 155 start = writeICalDateTime(event->dtStart());
156 } 156 }
157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start)); 157 icalcomponent_add_property(vevent,icalproperty_new_dtstart(start));
158 158
159 if (event->hasEndDate()) { 159 if (event->hasEndDate()) {
160 // end time 160 // end time
161 icaltimetype end; 161 icaltimetype end;
162 if (event->doesFloat()) { 162 if (event->doesFloat()) {
163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl; 163// kdDebug(5800) << "§§ Event " << event->summary() << " floats." << endl;
164 // +1 day because end date is non-inclusive. 164 // +1 day because end date is non-inclusive.
165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) ); 165 end = writeICalDate( event->dtEnd().date().addDays( 1 ) );
166 } else { 166 } else {
167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl; 167// kdDebug(5800) << "§§ Event " << event->summary() << " has time." << endl;
168 end = writeICalDateTime(event->dtEnd()); 168 end = writeICalDateTime(event->dtEnd());
169 } 169 }
170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end)); 170 icalcomponent_add_property(vevent,icalproperty_new_dtend(end));
171 } 171 }
172 172
173// TODO: attachments, resources 173// TODO: attachments, resources
174#if 0 174#if 0
175 // attachments 175 // attachments
176 tmpStrList = anEvent->attachments(); 176 tmpStrList = anEvent->attachments();
177 for ( QStringList::Iterator it = tmpStrList.begin(); 177 for ( QStringList::Iterator it = tmpStrList.begin();
178 it != tmpStrList.end(); 178 it != tmpStrList.end();
179 ++it ) 179 ++it )
180 addPropValue(vevent, VCAttachProp, (*it).utf8()); 180 addPropValue(vevent, VCAttachProp, (*it).utf8());
181 181
182 // resources 182 // resources
183 tmpStrList = anEvent->resources(); 183 tmpStrList = anEvent->resources();
184 tmpStr = tmpStrList.join(";"); 184 tmpStr = tmpStrList.join(";");
185 if (!tmpStr.isEmpty()) 185 if (!tmpStr.isEmpty())
186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8()); 186 addPropValue(vevent, VCResourcesProp, tmpStr.utf8());
187 187
188#endif 188#endif
189 189
190 // Transparency 190 // Transparency
191 switch( event->transparency() ) { 191 switch( event->transparency() ) {
192 case Event::Transparent: 192 case Event::Transparent:
193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT)); 193 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_TRANSPARENT));
194 break; 194 break;
195 case Event::Opaque: 195 case Event::Opaque:
196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE)); 196 icalcomponent_add_property(vevent, icalproperty_new_transp(ICAL_TRANSP_OPAQUE));
197 break; 197 break;
198 } 198 }
199 199
200 return vevent; 200 return vevent;
201} 201}
202 202
203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy, 203icalcomponent *ICalFormatImpl::writeFreeBusy(FreeBusy *freebusy,
204 Scheduler::Method method) 204 Scheduler::Method method)
205{ 205{
206 206
207 207
208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 208 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
209 209
210 writeIncidenceBase(vfreebusy,freebusy); 210 writeIncidenceBase(vfreebusy,freebusy);
211 211
212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 212 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
213 writeICalDateTime(freebusy->dtStart()))); 213 writeICalDateTime(freebusy->dtStart())));
214 214
215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 215 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
216 writeICalDateTime(freebusy->dtEnd()))); 216 writeICalDateTime(freebusy->dtEnd())));
217 217
218 if (method == Scheduler::Request) { 218 if (method == Scheduler::Request) {
219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 219 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
220 freebusy->uid().utf8())); 220 freebusy->uid().utf8()));
221 } 221 }
222 222
223 //Loops through all the periods in the freebusy object 223 //Loops through all the periods in the freebusy object
224 QValueList<Period> list = freebusy->busyPeriods(); 224 QValueList<Period> list = freebusy->busyPeriods();
225 QValueList<Period>::Iterator it; 225 QValueList<Period>::Iterator it;
226 icalperiodtype period; 226 icalperiodtype period;
227 for (it = list.begin(); it!= list.end(); ++it) { 227 for (it = list.begin(); it!= list.end(); ++it) {
228 period.start = writeICalDateTime((*it).start()); 228 period.start = writeICalDateTime((*it).start());
229 period.end = writeICalDateTime((*it).end()); 229 period.end = writeICalDateTime((*it).end());
230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 230 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
231 } 231 }
232 232
233 return vfreebusy; 233 return vfreebusy;
234} 234}
235 235
236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 236icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
237{ 237{
238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 238 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
239 239
240 writeIncidence(vjournal,journal); 240 writeIncidence(vjournal,journal);
241 241
242 // start time 242 // start time
243 if (journal->dtStart().isValid()) { 243 if (journal->dtStart().isValid()) {
244 icaltimetype start; 244 icaltimetype start;
245 if (journal->doesFloat()) { 245 if (journal->doesFloat()) {
246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 246// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
247 start = writeICalDate(journal->dtStart().date()); 247 start = writeICalDate(journal->dtStart().date());
248 } else { 248 } else {
249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 249// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
250 start = writeICalDateTime(journal->dtStart()); 250 start = writeICalDateTime(journal->dtStart());
251 } 251 }
252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 252 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
253 } 253 }
254 254
255 return vjournal; 255 return vjournal;
256} 256}
257 257
258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 258void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
259{ 259{
260 // pilot sync stuff 260 // pilot sync stuff
261// TODO: move this application-specific code to kpilot 261// TODO: move this application-specific code to kpilot
262 if (incidence->pilotId()) { 262 if (incidence->pilotId()) {
263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 263 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 264 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
265 } 265 }
266 if ( !incidence->IDStr().isEmpty()) { 266 if ( !incidence->IDStr().isEmpty()) {
267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() ); 267 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
268 } 268 }
269 269
270 270
271 writeIncidenceBase(parent,incidence); 271 writeIncidenceBase(parent,incidence);
272 if (incidence->cancelled()) { 272 if (incidence->cancelled()) {
273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 273 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
274 } 274 }
275 275
276 // creation date 276 // creation date
277 icalcomponent_add_property(parent,icalproperty_new_created( 277 icalcomponent_add_property(parent,icalproperty_new_created(
278 writeICalDateTime(incidence->created()))); 278 writeICalDateTime(incidence->created())));
279 279
280 // unique id 280 // unique id
281 icalcomponent_add_property(parent,icalproperty_new_uid( 281 icalcomponent_add_property(parent,icalproperty_new_uid(
282 incidence->uid().utf8())); 282 incidence->uid().utf8()));
283 283
284 // revision 284 // revision
285 icalcomponent_add_property(parent,icalproperty_new_sequence( 285 icalcomponent_add_property(parent,icalproperty_new_sequence(
286 incidence->revision())); 286 incidence->revision()));
287 287
288 // last modification date 288 // last modification date
289 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 289 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
290 writeICalDateTime(incidence->lastModified()))); 290 writeICalDateTime(incidence->lastModified())));
291 291
292 // description 292 // description
293 if (!incidence->description().isEmpty()) { 293 if (!incidence->description().isEmpty()) {
294 icalcomponent_add_property(parent,icalproperty_new_description( 294 icalcomponent_add_property(parent,icalproperty_new_description(
295 incidence->description().utf8())); 295 incidence->description().utf8()));
296 } 296 }
297 297
298 // summary 298 // summary
299 if (!incidence->summary().isEmpty()) { 299 if (!incidence->summary().isEmpty()) {
300 icalcomponent_add_property(parent,icalproperty_new_summary( 300 icalcomponent_add_property(parent,icalproperty_new_summary(
301 incidence->summary().utf8())); 301 incidence->summary().utf8()));
302 } 302 }
303 303
304 // location 304 // location
305 if (!incidence->location().isEmpty()) { 305 if (!incidence->location().isEmpty()) {
306 icalcomponent_add_property(parent,icalproperty_new_location( 306 icalcomponent_add_property(parent,icalproperty_new_location(
307 incidence->location().utf8())); 307 incidence->location().utf8()));
308 } 308 }
309 309
310// TODO: 310// TODO:
311 // status 311 // status
312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 312// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
313 313
314 // secrecy 314 // secrecy
315 enum icalproperty_class classInt; 315 enum icalproperty_class classInt;
316 switch (incidence->secrecy()) { 316 switch (incidence->secrecy()) {
317 case Incidence::SecrecyPublic: 317 case Incidence::SecrecyPublic:
318 classInt = ICAL_CLASS_PUBLIC; 318 classInt = ICAL_CLASS_PUBLIC;
319 break; 319 break;
320 case Incidence::SecrecyConfidential: 320 case Incidence::SecrecyConfidential:
321 classInt = ICAL_CLASS_CONFIDENTIAL; 321 classInt = ICAL_CLASS_CONFIDENTIAL;
322 break; 322 break;
323 case Incidence::SecrecyPrivate: 323 case Incidence::SecrecyPrivate:
324 classInt =ICAL_CLASS_PRIVATE ; 324 classInt =ICAL_CLASS_PRIVATE ;
325 default: 325 default:
326 classInt =ICAL_CLASS_PRIVATE ; 326 classInt =ICAL_CLASS_PRIVATE ;
327 break; 327 break;
328 } 328 }
329 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 329 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
330 330
331 // priority 331 // priority
332 icalcomponent_add_property(parent,icalproperty_new_priority( 332 icalcomponent_add_property(parent,icalproperty_new_priority(
333 incidence->priority())); 333 incidence->priority()));
334 334
335 // categories 335 // categories
336 QStringList categories = incidence->categories(); 336 QStringList categories = incidence->categories();
337 QStringList::Iterator it; 337 QStringList::Iterator it;
338 for(it = categories.begin(); it != categories.end(); ++it ) { 338 for(it = categories.begin(); it != categories.end(); ++it ) {
339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 339 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
340 } 340 }
341// TODO: Ensure correct concatenation of categories properties. 341// TODO: Ensure correct concatenation of categories properties.
342 342
343/* 343/*
344 // categories 344 // categories
345 tmpStrList = incidence->getCategories(); 345 tmpStrList = incidence->getCategories();
346 tmpStr = ""; 346 tmpStr = "";
347 QString catStr; 347 QString catStr;
348 for ( QStringList::Iterator it = tmpStrList.begin(); 348 for ( QStringList::Iterator it = tmpStrList.begin();
349 it != tmpStrList.end(); 349 it != tmpStrList.end();
350 ++it ) { 350 ++it ) {
351 catStr = *it; 351 catStr = *it;
352 if (catStr[0] == ' ') 352 if (catStr[0] == ' ')
353 tmpStr += catStr.mid(1); 353 tmpStr += catStr.mid(1);
354 else 354 else
355 tmpStr += catStr; 355 tmpStr += catStr;
356 // this must be a ';' character as the vCalendar specification requires! 356 // this must be a ';' character as the vCalendar specification requires!
357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 357 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
358 // read in. 358 // read in.
359 tmpStr += ";"; 359 tmpStr += ";";
360 } 360 }
361 if (!tmpStr.isEmpty()) { 361 if (!tmpStr.isEmpty()) {
362 tmpStr.truncate(tmpStr.length()-1); 362 tmpStr.truncate(tmpStr.length()-1);
363 icalcomponent_add_property(parent,icalproperty_new_categories( 363 icalcomponent_add_property(parent,icalproperty_new_categories(
364 writeText(incidence->getCategories().join(";")))); 364 writeText(incidence->getCategories().join(";"))));
365 } 365 }
366*/ 366*/
367 367
368 // related event 368 // related event
369 if (!incidence->relatedToUid().isEmpty()) { 369 if (!incidence->relatedToUid().isEmpty()) {
370 icalcomponent_add_property(parent,icalproperty_new_relatedto( 370 icalcomponent_add_property(parent,icalproperty_new_relatedto(
371 incidence->relatedToUid().utf8())); 371 incidence->relatedToUid().utf8()));
372 } 372 }
373 373
374 // recurrence rule stuff 374 // recurrence rule stuff
375 if (incidence->doesRecur()) { 375 if (incidence->doesRecur()) {
376 icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence())); 376 icalcomponent_add_property(parent,writeRecurrenceRule(incidence->recurrence()));
377 // recurrence excpetion dates 377 // recurrence excpetion dates
378 DateList dateList = incidence->exDates(); 378 DateList dateList = incidence->exDates();
379 DateList::ConstIterator exIt; 379 DateList::ConstIterator exIt;
380 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 380 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
381 icalcomponent_add_property(parent,icalproperty_new_exdate( 381 icalcomponent_add_property(parent,icalproperty_new_exdate(
382 writeICalDate(*exIt))); 382 writeICalDate(*exIt)));
383 } 383 }
384 } 384 }
385 385
386 // attachments 386 // attachments
387 QPtrList<Attachment> attachments = incidence->attachments(); 387 QPtrList<Attachment> attachments = incidence->attachments();
388 for (Attachment *at = attachments.first(); at; at = attachments.next()) 388 for (Attachment *at = attachments.first(); at; at = attachments.next())
389 icalcomponent_add_property(parent,writeAttachment(at)); 389 icalcomponent_add_property(parent,writeAttachment(at));
390 390
391 // alarms 391 // alarms
392 QPtrList<Alarm> alarms = incidence->alarms(); 392 QPtrList<Alarm> alarms = incidence->alarms();
393 Alarm* alarm; 393 Alarm* alarm;
394 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 394 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
395 if (alarm->enabled()) { 395 if (alarm->enabled()) {
396 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 396 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
397 icalcomponent_add_component(parent,writeAlarm(alarm)); 397 icalcomponent_add_component(parent,writeAlarm(alarm));
398 } 398 }
399 } 399 }
400 if( incidence->hasRecurrenceID() ) { 400 if( incidence->hasRecurrenceID() ) {
401 icalcomponent_add_property(parent, 401 icalcomponent_add_property(parent,
402 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID()))); 402 icalproperty_new_recurrenceid( writeICalDateTime( incidence->recurrenceID())));
403 } 403 }
404 // duration 404 // duration
405 405
406// turned off as it always is set to PTS0 (and must not occur together with DTEND 406// turned off as it always is set to PTS0 (and must not occur together with DTEND
407 407
408 if (incidence->hasDuration()) { 408 if (incidence->hasDuration()) {
409 icaldurationtype duration; 409 icaldurationtype duration;
410 duration = writeICalDuration(incidence->duration()); 410 duration = writeICalDuration(incidence->duration());
411 icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 411 icalcomponent_add_property(parent,icalproperty_new_duration(duration));
412 } 412 }
413} 413}
414 414
415void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 415void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
416{ 416{
417 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 417 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
418 writeICalDateTime(QDateTime::currentDateTime()))); 418 writeICalDateTime(QDateTime::currentDateTime())));
419 419
420 // organizer stuff 420 // organizer stuff
421 icalcomponent_add_property(parent,icalproperty_new_organizer( 421 icalcomponent_add_property(parent,icalproperty_new_organizer(
422 ("MAILTO:" + incidenceBase->organizer()).utf8())); 422 ("MAILTO:" + incidenceBase->organizer()).utf8()));
423 423
424 // attendees 424 // attendees
425 if (incidenceBase->attendeeCount() != 0) { 425 if (incidenceBase->attendeeCount() != 0) {
426 QPtrList<Attendee> al = incidenceBase->attendees(); 426 QPtrList<Attendee> al = incidenceBase->attendees();
427 QPtrListIterator<Attendee> ai(al); 427 QPtrListIterator<Attendee> ai(al);
428 for (; ai.current(); ++ai) { 428 for (; ai.current(); ++ai) {
429 icalcomponent_add_property(parent,writeAttendee(ai.current())); 429 icalcomponent_add_property(parent,writeAttendee(ai.current()));
430 } 430 }
431 } 431 }
432 432
433 // custom properties 433 // custom properties
434 writeCustomProperties(parent, incidenceBase); 434 writeCustomProperties(parent, incidenceBase);
435} 435}
436 436
437void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 437void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
438{ 438{
439 QMap<QCString, QString> custom = properties->customProperties(); 439 QMap<QCString, QString> custom = properties->customProperties();
440 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 440 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
441 icalproperty *p = icalproperty_new_x(c.data().utf8()); 441 icalproperty *p = icalproperty_new_x(c.data().utf8());
442 icalproperty_set_x_name(p,c.key()); 442 icalproperty_set_x_name(p,c.key());
443 icalcomponent_add_property(parent,p); 443 icalcomponent_add_property(parent,p);
444 } 444 }
445} 445}
446 446
447icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 447icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
448{ 448{
449 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 449 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
450 450
451 if (!attendee->name().isEmpty()) { 451 if (!attendee->name().isEmpty()) {
452 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 452 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
453 } 453 }
454 454
455 455
456 icalproperty_add_parameter(p,icalparameter_new_rsvp( 456 icalproperty_add_parameter(p,icalparameter_new_rsvp(
457 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 457 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
458 458
459 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 459 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
460 switch (attendee->status()) { 460 switch (attendee->status()) {
461 default: 461 default:
462 case Attendee::NeedsAction: 462 case Attendee::NeedsAction:
463 status = ICAL_PARTSTAT_NEEDSACTION; 463 status = ICAL_PARTSTAT_NEEDSACTION;
464 break; 464 break;
465 case Attendee::Accepted: 465 case Attendee::Accepted:
466 status = ICAL_PARTSTAT_ACCEPTED; 466 status = ICAL_PARTSTAT_ACCEPTED;
467 break; 467 break;
468 case Attendee::Declined: 468 case Attendee::Declined:
469 status = ICAL_PARTSTAT_DECLINED; 469 status = ICAL_PARTSTAT_DECLINED;
470 break; 470 break;
471 case Attendee::Tentative: 471 case Attendee::Tentative:
472 status = ICAL_PARTSTAT_TENTATIVE; 472 status = ICAL_PARTSTAT_TENTATIVE;
473 break; 473 break;
474 case Attendee::Delegated: 474 case Attendee::Delegated:
475 status = ICAL_PARTSTAT_DELEGATED; 475 status = ICAL_PARTSTAT_DELEGATED;
476 break; 476 break;
477 case Attendee::Completed: 477 case Attendee::Completed:
478 status = ICAL_PARTSTAT_COMPLETED; 478 status = ICAL_PARTSTAT_COMPLETED;
479 break; 479 break;
480 case Attendee::InProcess: 480 case Attendee::InProcess:
481 status = ICAL_PARTSTAT_INPROCESS; 481 status = ICAL_PARTSTAT_INPROCESS;
482 break; 482 break;
483 } 483 }
484 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 484 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
485 485
486 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 486 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
487 switch (attendee->role()) { 487 switch (attendee->role()) {
488 case Attendee::Chair: 488 case Attendee::Chair:
489 role = ICAL_ROLE_CHAIR; 489 role = ICAL_ROLE_CHAIR;
490 break; 490 break;
491 default: 491 default:
492 case Attendee::ReqParticipant: 492 case Attendee::ReqParticipant:
493 role = ICAL_ROLE_REQPARTICIPANT; 493 role = ICAL_ROLE_REQPARTICIPANT;
494 break; 494 break;
495 case Attendee::OptParticipant: 495 case Attendee::OptParticipant:
496 role = ICAL_ROLE_OPTPARTICIPANT; 496 role = ICAL_ROLE_OPTPARTICIPANT;
497 break; 497 break;
498 case Attendee::NonParticipant: 498 case Attendee::NonParticipant:
499 role = ICAL_ROLE_NONPARTICIPANT; 499 role = ICAL_ROLE_NONPARTICIPANT;
500 break; 500 break;
501 } 501 }
502 icalproperty_add_parameter(p,icalparameter_new_role(role)); 502 icalproperty_add_parameter(p,icalparameter_new_role(role));
503 503
504 if (!attendee->uid().isEmpty()) { 504 if (!attendee->uid().isEmpty()) {
505 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 505 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
506 icalparameter_set_xname(icalparameter_uid,"X-UID"); 506 icalparameter_set_xname(icalparameter_uid,"X-UID");
507 icalproperty_add_parameter(p,icalparameter_uid); 507 icalproperty_add_parameter(p,icalparameter_uid);
508 } 508 }
509 509
510 return p; 510 return p;
511} 511}
512 512
513icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 513icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
514{ 514{
515#if 0 515#if 0
516 icalattachtype* attach = icalattachtype_new(); 516 icalattachtype* attach = icalattachtype_new();
517 if (att->isURI()) 517 if (att->isURI())
518 icalattachtype_set_url(attach, att->uri().utf8().data()); 518 icalattachtype_set_url(attach, att->uri().utf8().data());
519 else 519 else
520 icalattachtype_set_base64(attach, att->data(), 0); 520 icalattachtype_set_base64(attach, att->data(), 0);
521#endif 521#endif
522 icalattach *attach; 522 icalattach *attach;
523 if (att->isURI()) 523 if (att->isURI())
524 attach = icalattach_new_from_url( att->uri().utf8().data()); 524 attach = icalattach_new_from_url( att->uri().utf8().data());
525 else 525 else
526 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); 526 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
527 icalproperty *p = icalproperty_new_attach(attach); 527 icalproperty *p = icalproperty_new_attach(attach);
528 if (!att->mimeType().isEmpty()) 528 if (!att->mimeType().isEmpty())
529 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 529 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
530 530
531 if (att->isBinary()) { 531 if (att->isBinary()) {
532 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 532 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
533 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 533 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
534 } 534 }
535 return p; 535 return p;
536} 536}
537 537
538icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 538icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
539{ 539{
540// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 540// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
541 541
542 icalrecurrencetype r; 542 icalrecurrencetype r;
543 543
544 icalrecurrencetype_clear(&r); 544 icalrecurrencetype_clear(&r);
545 545
546 int index = 0; 546 int index = 0;
547 int index2 = 0; 547 int index2 = 0;
548 548
549 QPtrList<Recurrence::rMonthPos> tmpPositions; 549 QPtrList<Recurrence::rMonthPos> tmpPositions;
550 QPtrList<int> tmpDays; 550 QPtrList<int> tmpDays;
551 int *tmpDay; 551 int *tmpDay;
552 Recurrence::rMonthPos *tmpPos; 552 Recurrence::rMonthPos *tmpPos;
553 bool datetime = false; 553 bool datetime = false;
554 int day; 554 int day;
555 int i; 555 int i;
556 556
557 switch(recur->doesRecur()) { 557 switch(recur->doesRecur()) {
558 case Recurrence::rMinutely: 558 case Recurrence::rMinutely:
559 r.freq = ICAL_MINUTELY_RECURRENCE; 559 r.freq = ICAL_MINUTELY_RECURRENCE;
560 datetime = true; 560 datetime = true;
561 break; 561 break;
562 case Recurrence::rHourly: 562 case Recurrence::rHourly:
563 r.freq = ICAL_HOURLY_RECURRENCE; 563 r.freq = ICAL_HOURLY_RECURRENCE;
564 datetime = true; 564 datetime = true;
565 break; 565 break;
566 case Recurrence::rDaily: 566 case Recurrence::rDaily:
567 r.freq = ICAL_DAILY_RECURRENCE; 567 r.freq = ICAL_DAILY_RECURRENCE;
568 break; 568 break;
569 case Recurrence::rWeekly: 569 case Recurrence::rWeekly:
570 r.freq = ICAL_WEEKLY_RECURRENCE; 570 r.freq = ICAL_WEEKLY_RECURRENCE;
571 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 571 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
572 for (i = 0; i < 7; i++) { 572 for (i = 0; i < 7; i++) {
573 if (recur->days().testBit(i)) { 573 if (recur->days().testBit(i)) {
574 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 574 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
575 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 575 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
576 } 576 }
577 } 577 }
578// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 578// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
579 break; 579 break;
580 case Recurrence::rMonthlyPos: 580 case Recurrence::rMonthlyPos:
581 r.freq = ICAL_MONTHLY_RECURRENCE; 581 r.freq = ICAL_MONTHLY_RECURRENCE;
582 582
583 tmpPositions = recur->monthPositions(); 583 tmpPositions = recur->monthPositions();
584 for (tmpPos = tmpPositions.first(); 584 for (tmpPos = tmpPositions.first();
585 tmpPos; 585 tmpPos;
586 tmpPos = tmpPositions.next()) { 586 tmpPos = tmpPositions.next()) {
587 for (i = 0; i < 7; i++) { 587 for (i = 0; i < 7; i++) {
588 if (tmpPos->rDays.testBit(i)) { 588 if (tmpPos->rDays.testBit(i)) {
589 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 589 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
590 day += tmpPos->rPos*8; 590 day += tmpPos->rPos*8;
591 if (tmpPos->negative) day = -day; 591 if (tmpPos->negative) day = -day;
592 r.by_day[index++] = day; 592 r.by_day[index++] = day;
593 } 593 }
594 } 594 }
595 } 595 }
596// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 596// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
597 break; 597 break;
598 case Recurrence::rMonthlyDay: 598 case Recurrence::rMonthlyDay:
599 r.freq = ICAL_MONTHLY_RECURRENCE; 599 r.freq = ICAL_MONTHLY_RECURRENCE;
600 600
601 tmpDays = recur->monthDays(); 601 tmpDays = recur->monthDays();
602 for (tmpDay = tmpDays.first(); 602 for (tmpDay = tmpDays.first();
603 tmpDay; 603 tmpDay;
604 tmpDay = tmpDays.next()) { 604 tmpDay = tmpDays.next()) {
605 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); 605 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay);
606 } 606 }
607// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 607// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
608 break; 608 break;
609 case Recurrence::rYearlyMonth: 609 case Recurrence::rYearlyMonth:
610 case Recurrence::rYearlyPos: 610 case Recurrence::rYearlyPos:
611 r.freq = ICAL_YEARLY_RECURRENCE; 611 r.freq = ICAL_YEARLY_RECURRENCE;
612 612
613 tmpDays = recur->yearNums(); 613 tmpDays = recur->yearNums();
614 for (tmpDay = tmpDays.first(); 614 for (tmpDay = tmpDays.first();
615 tmpDay; 615 tmpDay;
616 tmpDay = tmpDays.next()) { 616 tmpDay = tmpDays.next()) {
617 r.by_month[index++] = *tmpDay; 617 r.by_month[index++] = *tmpDay;
618 } 618 }
619// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; 619// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX;
620 if (recur->doesRecur() == Recurrence::rYearlyPos) { 620 if (recur->doesRecur() == Recurrence::rYearlyPos) {
621 tmpPositions = recur->monthPositions(); 621 tmpPositions = recur->monthPositions();
622 for (tmpPos = tmpPositions.first(); 622 for (tmpPos = tmpPositions.first();
623 tmpPos; 623 tmpPos;
624 tmpPos = tmpPositions.next()) { 624 tmpPos = tmpPositions.next()) {
625 for (i = 0; i < 7; i++) { 625 for (i = 0; i < 7; i++) {
626 if (tmpPos->rDays.testBit(i)) { 626 if (tmpPos->rDays.testBit(i)) {
627 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 627 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
628 day += tmpPos->rPos*8; 628 day += tmpPos->rPos*8;
629 if (tmpPos->negative) day = -day; 629 if (tmpPos->negative) day = -day;
630 r.by_day[index2++] = day; 630 r.by_day[index2++] = day;
631 } 631 }
632 } 632 }
633 } 633 }
634// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; 634// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX;
635 } 635 }
636 break; 636 break;
637 case Recurrence::rYearlyDay: 637 case Recurrence::rYearlyDay:
638 r.freq = ICAL_YEARLY_RECURRENCE; 638 r.freq = ICAL_YEARLY_RECURRENCE;
639 639
640 tmpDays = recur->yearNums(); 640 tmpDays = recur->yearNums();
641 for (tmpDay = tmpDays.first(); 641 for (tmpDay = tmpDays.first();
642 tmpDay; 642 tmpDay;
643 tmpDay = tmpDays.next()) { 643 tmpDay = tmpDays.next()) {
644 r.by_year_day[index++] = *tmpDay; 644 r.by_year_day[index++] = *tmpDay;
645 } 645 }
646// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 646// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
647 break; 647 break;
648 default: 648 default:
649 r.freq = ICAL_NO_RECURRENCE; 649 r.freq = ICAL_NO_RECURRENCE;
650 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; 650 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
651 break; 651 break;
652 } 652 }
653 653
654 r.interval = recur->frequency(); 654 r.interval = recur->frequency();
655 655
656 if (recur->duration() > 0) { 656 if (recur->duration() > 0) {
657 r.count = recur->duration(); 657 r.count = recur->duration();
658 } else if (recur->duration() == -1) { 658 } else if (recur->duration() == -1) {
659 r.count = 0; 659 r.count = 0;
660 } else { 660 } else {
661 if (datetime) 661 if (datetime)
662 r.until = writeICalDateTime(recur->endDateTime()); 662 r.until = writeICalDateTime(recur->endDateTime());
663 else 663 else
664 r.until = writeICalDate(recur->endDate()); 664 r.until = writeICalDate(recur->endDate());
665 } 665 }
666 666
667// Debug output 667// Debug output
668#if 0 668#if 0
669 const char *str = icalrecurrencetype_as_string(&r); 669 const char *str = icalrecurrencetype_as_string(&r);
670 if (str) { 670 if (str) {
671 kdDebug(5800) << " String: " << str << endl; 671 kdDebug(5800) << " String: " << str << endl;
672 } else { 672 } else {
673 kdDebug(5800) << " No String" << endl; 673 kdDebug(5800) << " No String" << endl;
674 } 674 }
675#endif 675#endif
676 676
677 return icalproperty_new_rrule(r); 677 return icalproperty_new_rrule(r);
678} 678}
679 679
680icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) 680icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
681{ 681{
682 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); 682 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
683 683
684 icalproperty_action action; 684 icalproperty_action action;
685 icalattach *attach = 0; 685 icalattach *attach = 0;
686 686
687 switch (alarm->type()) { 687 switch (alarm->type()) {
688 case Alarm::Procedure: 688 case Alarm::Procedure:
689 action = ICAL_ACTION_PROCEDURE; 689 action = ICAL_ACTION_PROCEDURE;
690 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); 690 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() );
691 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 691 icalcomponent_add_property(a,icalproperty_new_attach(attach));
692 if (!alarm->programArguments().isEmpty()) { 692 if (!alarm->programArguments().isEmpty()) {
693 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 693 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
694 } 694 }
695 icalattach_unref( attach ); 695 icalattach_unref( attach );
696 break; 696 break;
697 case Alarm::Audio: 697 case Alarm::Audio:
698 action = ICAL_ACTION_AUDIO; 698 action = ICAL_ACTION_AUDIO;
699 if (!alarm->audioFile().isEmpty()) { 699 if (!alarm->audioFile().isEmpty()) {
700 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); 700 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
701 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 701 icalcomponent_add_property(a,icalproperty_new_attach(attach));
702 icalattach_unref( attach ); 702 icalattach_unref( attach );
703 } 703 }
704 break; 704 break;
705 case Alarm::Email: { 705 case Alarm::Email: {
706 action = ICAL_ACTION_EMAIL; 706 action = ICAL_ACTION_EMAIL;
707 QValueList<Person> addresses = alarm->mailAddresses(); 707 QValueList<Person> addresses = alarm->mailAddresses();
708 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 708 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
709 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 709 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
710 if (!(*ad).name().isEmpty()) { 710 if (!(*ad).name().isEmpty()) {
711 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 711 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
712 } 712 }
713 icalcomponent_add_property(a,p); 713 icalcomponent_add_property(a,p);
714 } 714 }
715 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 715 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
716 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 716 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
717 QStringList attachments = alarm->mailAttachments(); 717 QStringList attachments = alarm->mailAttachments();
718 if (attachments.count() > 0) { 718 if (attachments.count() > 0) {
719 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 719 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
720 attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); 720 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
721 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 721 icalcomponent_add_property(a,icalproperty_new_attach(attach));
722 icalattach_unref( attach ); 722 icalattach_unref( attach );
723 } 723 }
724 } 724 }
725 break; 725 break;
726 } 726 }
727 case Alarm::Display: 727 case Alarm::Display:
728 action = ICAL_ACTION_DISPLAY; 728 action = ICAL_ACTION_DISPLAY;
729 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 729 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
730 break; 730 break;
731 case Alarm::Invalid: 731 case Alarm::Invalid:
732 default: 732 default:
733 kdDebug(5800) << "Unknown type of alarm" << endl; 733 kdDebug(5800) << "Unknown type of alarm" << endl;
734 action = ICAL_ACTION_NONE; 734 action = ICAL_ACTION_NONE;
735 break; 735 break;
736 } 736 }
737 icalcomponent_add_property(a,icalproperty_new_action(action)); 737 icalcomponent_add_property(a,icalproperty_new_action(action));
738 738
739 // Trigger time 739 // Trigger time
740 icaltriggertype trigger; 740 icaltriggertype trigger;
741 if ( alarm->hasTime() ) { 741 if ( alarm->hasTime() ) {
742 trigger.time = writeICalDateTime(alarm->time()); 742 trigger.time = writeICalDateTime(alarm->time());
743 trigger.duration = icaldurationtype_null_duration(); 743 trigger.duration = icaldurationtype_null_duration();
744 } else { 744 } else {
745 trigger.time = icaltime_null_time(); 745 trigger.time = icaltime_null_time();
746 Duration offset; 746 Duration offset;
747 if ( alarm->hasStartOffset() ) 747 if ( alarm->hasStartOffset() )
748 offset = alarm->startOffset(); 748 offset = alarm->startOffset();
749 else 749 else
750 offset = alarm->endOffset(); 750 offset = alarm->endOffset();
751 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 751 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
752 } 752 }
753 icalproperty *p = icalproperty_new_trigger(trigger); 753 icalproperty *p = icalproperty_new_trigger(trigger);
754 if ( alarm->hasEndOffset() ) 754 if ( alarm->hasEndOffset() )
755 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 755 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
756 icalcomponent_add_property(a,p); 756 icalcomponent_add_property(a,p);
757 757
758 // Repeat count and duration 758 // Repeat count and duration
759 if (alarm->repeatCount()) { 759 if (alarm->repeatCount()) {
760 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 760 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
761 icalcomponent_add_property(a,icalproperty_new_duration( 761 icalcomponent_add_property(a,icalproperty_new_duration(
762 icaldurationtype_from_int(alarm->snoozeTime()*60))); 762 icaldurationtype_from_int(alarm->snoozeTime()*60)));
763 } 763 }
764 764
765 // Custom properties 765 // Custom properties
766 QMap<QCString, QString> custom = alarm->customProperties(); 766 QMap<QCString, QString> custom = alarm->customProperties();
767 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 767 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
768 icalproperty *p = icalproperty_new_x(c.data().utf8()); 768 icalproperty *p = icalproperty_new_x(c.data().utf8());
769 icalproperty_set_x_name(p,c.key()); 769 icalproperty_set_x_name(p,c.key());
770 icalcomponent_add_property(a,p); 770 icalcomponent_add_property(a,p);
771 } 771 }
772 772
773 return a; 773 return a;
774} 774}
775 775
776Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 776Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
777{ 777{
778 Todo *todo = new Todo; 778 Todo *todo = new Todo;
779 779
780 readIncidence(vtodo,todo); 780 readIncidence(vtodo,todo);
781 781
782 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 782 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
783 783
784// int intvalue; 784// int intvalue;
785 icaltimetype icaltime; 785 icaltimetype icaltime;
786 786
787 QStringList categories; 787 QStringList categories;
788 788
789 while (p) { 789 while (p) {
790 icalproperty_kind kind = icalproperty_isa(p); 790 icalproperty_kind kind = icalproperty_isa(p);
791 switch (kind) { 791 switch (kind) {
792 792
793 case ICAL_DUE_PROPERTY: // due date 793 case ICAL_DUE_PROPERTY: // due date
794 icaltime = icalproperty_get_due(p); 794 icaltime = icalproperty_get_due(p);
795 if (icaltime.is_date) { 795 if (icaltime.is_date) {
796 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 796 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
797 todo->setFloats(true); 797 todo->setFloats(true);
798 798
799 } else { 799 } else {
800 todo->setDtDue(readICalDateTime(icaltime)); 800 todo->setDtDue(readICalDateTime(icaltime));
801 todo->setFloats(false); 801 todo->setFloats(false);
802 } 802 }
803 todo->setHasDueDate(true); 803 todo->setHasDueDate(true);
804 break; 804 break;
805 805
806 case ICAL_COMPLETED_PROPERTY: // completion date 806 case ICAL_COMPLETED_PROPERTY: // completion date
807 icaltime = icalproperty_get_completed(p); 807 icaltime = icalproperty_get_completed(p);
808 todo->setCompleted(readICalDateTime(icaltime)); 808 todo->setCompleted(readICalDateTime(icaltime));
809 break; 809 break;
810 810
811 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed 811 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
812 todo->setPercentComplete(icalproperty_get_percentcomplete(p)); 812 todo->setPercentComplete(icalproperty_get_percentcomplete(p));
813 break; 813 break;
814 814
815 case ICAL_RELATEDTO_PROPERTY: // related todo (parent) 815 case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
816 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 816 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
817 mTodosRelate.append(todo); 817 mTodosRelate.append(todo);
818 break; 818 break;
819 819
820 case ICAL_DTSTART_PROPERTY: 820 case ICAL_DTSTART_PROPERTY:
821 // Flag that todo has start date. Value is read in by readIncidence(). 821 // Flag that todo has start date. Value is read in by readIncidence().
822 todo->setHasStartDate(true); 822 todo->setHasStartDate(true);
823 break; 823 break;
824 824
825 default: 825 default:
826// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind 826// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind
827// << endl; 827// << endl;
828 break; 828 break;
829 } 829 }
830 830
831 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); 831 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
832 } 832 }
833 833
834 return todo; 834 return todo;
835} 835}
836 836
837Event *ICalFormatImpl::readEvent(icalcomponent *vevent) 837Event *ICalFormatImpl::readEvent(icalcomponent *vevent)
838{ 838{
839 Event *event = new Event; 839 Event *event = new Event;
840 event->setFloats(false); 840 event->setFloats(false);
841 841
842 readIncidence(vevent,event); 842 readIncidence(vevent,event);
843 843
844 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); 844 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY);
845 845
846// int intvalue; 846// int intvalue;
847 icaltimetype icaltime; 847 icaltimetype icaltime;
848 848
849 QStringList categories; 849 QStringList categories;
850 QString transparency; 850 QString transparency;
851 851
852 while (p) { 852 while (p) {
853 icalproperty_kind kind = icalproperty_isa(p); 853 icalproperty_kind kind = icalproperty_isa(p);
854 switch (kind) { 854 switch (kind) {
855 855
856 case ICAL_DTEND_PROPERTY: // start date and time 856 case ICAL_DTEND_PROPERTY: // start date and time
857 icaltime = icalproperty_get_dtend(p); 857 icaltime = icalproperty_get_dtend(p);
858 if (icaltime.is_date) { 858 if (icaltime.is_date) {
859 event->setFloats( true ); 859 event->setFloats( true );
860 // End date is non-inclusive 860 // End date is non-inclusive
861 QDate endDate = readICalDate( icaltime ).addDays( -1 ); 861 QDate endDate = readICalDate( icaltime ).addDays( -1 );
862 mCompat->fixFloatingEnd( endDate ); 862 mCompat->fixFloatingEnd( endDate );
863 if ( endDate < event->dtStart().date() ) { 863 if ( endDate < event->dtStart().date() ) {
864 endDate = event->dtStart().date(); 864 endDate = event->dtStart().date();
865 } 865 }
866 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); 866 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) );
867 } else { 867 } else {
868 event->setDtEnd(readICalDateTime(icaltime)); 868 event->setDtEnd(readICalDateTime(icaltime));
869 } 869 }
870 break; 870 break;
871 871
872// TODO: 872// TODO:
873 // at this point, there should be at least a start or end time. 873 // at this point, there should be at least a start or end time.
874 // fix up for events that take up no time but have a time associated 874 // fix up for events that take up no time but have a time associated
875#if 0 875#if 0
876 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 876 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
877 anEvent->setDtStart(anEvent->dtEnd()); 877 anEvent->setDtStart(anEvent->dtEnd());
878 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 878 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
879 anEvent->setDtEnd(anEvent->dtStart()); 879 anEvent->setDtEnd(anEvent->dtStart());
880#endif 880#endif
881 881
882// TODO: exdates 882// TODO: exdates
883#if 0 883#if 0
884 // recurrence exceptions 884 // recurrence exceptions
885 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { 885 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
886 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); 886 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo)));
887 deleteStr(s); 887 deleteStr(s);
888 } 888 }
889#endif 889#endif
890 890
891#if 0 891#if 0
892 // secrecy 892 // secrecy
893 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 893 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
894 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); 894 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo)));
895 deleteStr(s); 895 deleteStr(s);
896 } 896 }
897 else 897 else
898 anEvent->setSecrecy("PUBLIC"); 898 anEvent->setSecrecy("PUBLIC");
899 899
900 // attachments 900 // attachments
901 tmpStrList.clear(); 901 tmpStrList.clear();
902 initPropIterator(&voi, vevent); 902 initPropIterator(&voi, vevent);
903 while (moreIteration(&voi)) { 903 while (moreIteration(&voi)) {
904 vo = nextVObject(&voi); 904 vo = nextVObject(&voi);
905 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 905 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
906 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); 906 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo)));
907 deleteStr(s); 907 deleteStr(s);
908 } 908 }
909 } 909 }
910 anEvent->setAttachments(tmpStrList); 910 anEvent->setAttachments(tmpStrList);
911 911
912 // resources 912 // resources
913 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 913 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
914 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 914 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
915 deleteStr(s); 915 deleteStr(s);
916 tmpStrList.clear(); 916 tmpStrList.clear();
917 index1 = 0; 917 index1 = 0;
918 index2 = 0; 918 index2 = 0;
919 QString resource; 919 QString resource;
920 while ((index2 = resources.find(';', index1)) != -1) { 920 while ((index2 = resources.find(';', index1)) != -1) {
921 resource = resources.mid(index1, (index2 - index1)); 921 resource = resources.mid(index1, (index2 - index1));
922 tmpStrList.append(resource); 922 tmpStrList.append(resource);
923 index1 = index2; 923 index1 = index2;
924 } 924 }
925 anEvent->setResources(tmpStrList); 925 anEvent->setResources(tmpStrList);
926 } 926 }
927#endif 927#endif
928 928
929 case ICAL_RELATEDTO_PROPERTY: // releated event (parent) 929 case ICAL_RELATEDTO_PROPERTY: // releated event (parent)
930 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 930 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
931 mEventsRelate.append(event); 931 mEventsRelate.append(event);
932 break; 932 break;
933 933
934 case ICAL_TRANSP_PROPERTY: // Transparency 934 case ICAL_TRANSP_PROPERTY: // Transparency
935 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) 935 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT )
936 event->setTransparency( Event::Transparent ); 936 event->setTransparency( Event::Transparent );
937 else 937 else
938 event->setTransparency( Event::Opaque ); 938 event->setTransparency( Event::Opaque );
939 break; 939 break;
940 940
941 default: 941 default:
942// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind 942// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind
943// << endl; 943// << endl;
944 break; 944 break;
945 } 945 }
946 946
947 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); 947 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY);
948 } 948 }
949 949
950 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); 950 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
951 if (!msade.isNull()) { 951 if (!msade.isNull()) {
952 bool floats = (msade == QString::fromLatin1("TRUE")); 952 bool floats = (msade == QString::fromLatin1("TRUE"));
953 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; 953 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl;
954 event->setFloats(floats); 954 event->setFloats(floats);
955 if (floats) { 955 if (floats) {
956 QDateTime endDate = event->dtEnd(); 956 QDateTime endDate = event->dtEnd();
957 event->setDtEnd(endDate.addDays(-1)); 957 event->setDtEnd(endDate.addDays(-1));
958 } 958 }
959 } 959 }
960 960
961 // some stupid vCal exporters ignore the standard and use Description 961 // some stupid vCal exporters ignore the standard and use Description
962 // instead of Summary for the default field. Correct for this. 962 // instead of Summary for the default field. Correct for this.
963 if (event->summary().isEmpty() && 963 if (event->summary().isEmpty() &&
964 !(event->description().isEmpty())) { 964 !(event->description().isEmpty())) {
965 QString tmpStr = event->description().simplifyWhiteSpace(); 965 QString tmpStr = event->description().simplifyWhiteSpace();
966 event->setDescription(""); 966 event->setDescription("");
967 event->setSummary(tmpStr); 967 event->setSummary(tmpStr);
968 } 968 }
969 969
970 return event; 970 return event;
971} 971}
972 972
973FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) 973FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
974{ 974{
975 FreeBusy *freebusy = new FreeBusy; 975 FreeBusy *freebusy = new FreeBusy;
976 976
977 readIncidenceBase(vfreebusy,freebusy); 977 readIncidenceBase(vfreebusy,freebusy);
978 978
979 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); 979 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
980 980
981 icaltimetype icaltime; 981 icaltimetype icaltime;
982 icalperiodtype icalperiod; 982 icalperiodtype icalperiod;
983 QDateTime period_start, period_end; 983 QDateTime period_start, period_end;
984 984
985 while (p) { 985 while (p) {
986 icalproperty_kind kind = icalproperty_isa(p); 986 icalproperty_kind kind = icalproperty_isa(p);
987 switch (kind) { 987 switch (kind) {
988 988
989 case ICAL_DTSTART_PROPERTY: // start date and time 989 case ICAL_DTSTART_PROPERTY: // start date and time
990 icaltime = icalproperty_get_dtstart(p); 990 icaltime = icalproperty_get_dtstart(p);
991 freebusy->setDtStart(readICalDateTime(icaltime)); 991 freebusy->setDtStart(readICalDateTime(icaltime));
992 break; 992 break;
993 993
994 case ICAL_DTEND_PROPERTY: // start End Date and Time 994 case ICAL_DTEND_PROPERTY: // start End Date and Time
995 icaltime = icalproperty_get_dtend(p); 995 icaltime = icalproperty_get_dtend(p);
996 freebusy->setDtEnd(readICalDateTime(icaltime)); 996 freebusy->setDtEnd(readICalDateTime(icaltime));
997 break; 997 break;
998 998
999 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times 999 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times
1000 icalperiod = icalproperty_get_freebusy(p); 1000 icalperiod = icalproperty_get_freebusy(p);
1001 period_start = readICalDateTime(icalperiod.start); 1001 period_start = readICalDateTime(icalperiod.start);
1002 period_end = readICalDateTime(icalperiod.end); 1002 period_end = readICalDateTime(icalperiod.end);
1003 freebusy->addPeriod(period_start, period_end); 1003 freebusy->addPeriod(period_start, period_end);
1004 break; 1004 break;
1005 1005
1006 default: 1006 default:
1007 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1007 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1008 << endl; 1008 << endl;
1009 break; 1009 break;
1010 } 1010 }
1011 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1011 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1012 } 1012 }
1013 1013
1014 return freebusy; 1014 return freebusy;
1015} 1015}
1016 1016
1017Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1017Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1018{ 1018{
1019 Journal *journal = new Journal; 1019 Journal *journal = new Journal;
1020 1020
1021 readIncidence(vjournal,journal); 1021 readIncidence(vjournal,journal);
1022 1022
1023 if ( !journal->dtStart().isValid() && journal->created().isValid() ) { 1023 if ( !journal->dtStart().isValid() && journal->created().isValid() ) {
1024 journal->setDtStart( journal->created() ); 1024 journal->setDtStart( journal->created() );
1025 } 1025 }
1026 return journal; 1026 return journal;
1027} 1027}
1028 1028
1029Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1029Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1030{ 1030{
1031 icalparameter *p = 0; 1031 icalparameter *p = 0;
1032 1032
1033 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1033 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1034 1034
1035 QString name; 1035 QString name;
1036 QString uid = QString::null; 1036 QString uid = QString::null;
1037 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1037 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1038 if (p) { 1038 if (p) {
1039 name = QString::fromUtf8(icalparameter_get_cn(p)); 1039 name = QString::fromUtf8(icalparameter_get_cn(p));
1040 } else { 1040 } else {
1041 } 1041 }
1042 1042
1043 bool rsvp=false; 1043 bool rsvp=false;
1044 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1044 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1045 if (p) { 1045 if (p) {
1046 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1046 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1047 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1047 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1048 } 1048 }
1049 1049
1050 Attendee::PartStat status = Attendee::NeedsAction; 1050 Attendee::PartStat status = Attendee::NeedsAction;
1051 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1051 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1052 if (p) { 1052 if (p) {
1053 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1053 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1054 switch(partStatParameter) { 1054 switch(partStatParameter) {
1055 default: 1055 default:
1056 case ICAL_PARTSTAT_NEEDSACTION: 1056 case ICAL_PARTSTAT_NEEDSACTION:
1057 status = Attendee::NeedsAction; 1057 status = Attendee::NeedsAction;
1058 break; 1058 break;
1059 case ICAL_PARTSTAT_ACCEPTED: 1059 case ICAL_PARTSTAT_ACCEPTED:
1060 status = Attendee::Accepted; 1060 status = Attendee::Accepted;
1061 break; 1061 break;
1062 case ICAL_PARTSTAT_DECLINED: 1062 case ICAL_PARTSTAT_DECLINED:
1063 status = Attendee::Declined; 1063 status = Attendee::Declined;
1064 break; 1064 break;
1065 case ICAL_PARTSTAT_TENTATIVE: 1065 case ICAL_PARTSTAT_TENTATIVE:
1066 status = Attendee::Tentative; 1066 status = Attendee::Tentative;
1067 break; 1067 break;
1068 case ICAL_PARTSTAT_DELEGATED: 1068 case ICAL_PARTSTAT_DELEGATED:
1069 status = Attendee::Delegated; 1069 status = Attendee::Delegated;
1070 break; 1070 break;
1071 case ICAL_PARTSTAT_COMPLETED: 1071 case ICAL_PARTSTAT_COMPLETED:
1072 status = Attendee::Completed; 1072 status = Attendee::Completed;
1073 break; 1073 break;
1074 case ICAL_PARTSTAT_INPROCESS: 1074 case ICAL_PARTSTAT_INPROCESS:
1075 status = Attendee::InProcess; 1075 status = Attendee::InProcess;
1076 break; 1076 break;
1077 } 1077 }
1078 } 1078 }
1079 1079
1080 Attendee::Role role = Attendee::ReqParticipant; 1080 Attendee::Role role = Attendee::ReqParticipant;
1081 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1081 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1082 if (p) { 1082 if (p) {
1083 icalparameter_role roleParameter = icalparameter_get_role(p); 1083 icalparameter_role roleParameter = icalparameter_get_role(p);
1084 switch(roleParameter) { 1084 switch(roleParameter) {
1085 case ICAL_ROLE_CHAIR: 1085 case ICAL_ROLE_CHAIR:
1086 role = Attendee::Chair; 1086 role = Attendee::Chair;
1087 break; 1087 break;
1088 default: 1088 default:
1089 case ICAL_ROLE_REQPARTICIPANT: 1089 case ICAL_ROLE_REQPARTICIPANT:
1090 role = Attendee::ReqParticipant; 1090 role = Attendee::ReqParticipant;
1091 break; 1091 break;
1092 case ICAL_ROLE_OPTPARTICIPANT: 1092 case ICAL_ROLE_OPTPARTICIPANT:
1093 role = Attendee::OptParticipant; 1093 role = Attendee::OptParticipant;
1094 break; 1094 break;
1095 case ICAL_ROLE_NONPARTICIPANT: 1095 case ICAL_ROLE_NONPARTICIPANT:
1096 role = Attendee::NonParticipant; 1096 role = Attendee::NonParticipant;
1097 break; 1097 break;
1098 } 1098 }
1099 } 1099 }
1100 1100
1101 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1101 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1102 uid = icalparameter_get_xvalue(p); 1102 uid = icalparameter_get_xvalue(p);
1103 // This should be added, but there seems to be a libical bug here. 1103 // This should be added, but there seems to be a libical bug here.
1104 /*while (p) { 1104 /*while (p) {
1105 // if (icalparameter_get_xname(p) == "X-UID") { 1105 // if (icalparameter_get_xname(p) == "X-UID") {
1106 uid = icalparameter_get_xvalue(p); 1106 uid = icalparameter_get_xvalue(p);
1107 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1107 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1108 } */ 1108 } */
1109 1109
1110 return new Attendee( name, email, rsvp, status, role, uid ); 1110 return new Attendee( name, email, rsvp, status, role, uid );
1111} 1111}
1112 1112
1113Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1113Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1114{ 1114{
1115 icalattach *a = icalproperty_get_attach(attach); 1115 icalattach *a = icalproperty_get_attach(attach);
1116 icalparameter_value v = ICAL_VALUE_NONE; 1116 icalparameter_value v = ICAL_VALUE_NONE;
1117 icalparameter_encoding e = ICAL_ENCODING_NONE; 1117 icalparameter_encoding e = ICAL_ENCODING_NONE;
1118 1118
1119 Attachment *attachment = 0; 1119 Attachment *attachment = 0;
1120 /* 1120 /*
1121 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1121 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1122 if (vp) 1122 if (vp)
1123 v = icalparameter_get_value(vp); 1123 v = icalparameter_get_value(vp);
1124 1124
1125 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1125 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1126 if (ep) 1126 if (ep)
1127 e = icalparameter_get_encoding(ep); 1127 e = icalparameter_get_encoding(ep);
1128 */ 1128 */
1129 int isurl = icalattach_get_is_url (a); 1129 int isurl = icalattach_get_is_url (a);
1130 if (isurl == 0) 1130 if (isurl == 0)
1131 attachment = new Attachment((const char*)icalattach_get_data(a)); 1131 attachment = new Attachment((const char*)icalattach_get_data(a));
1132 else { 1132 else {
1133 attachment = new Attachment(QString(icalattach_get_url(a))); 1133 attachment = new Attachment(QString(icalattach_get_url(a)));
1134 } 1134 }
1135 1135
1136 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1136 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1137 if (p) 1137 if (p)
1138 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1138 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1139 1139
1140 return attachment; 1140 return attachment;
1141} 1141}
1142#include <qtextcodec.h> 1142#include <qtextcodec.h>
1143void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1143void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1144{ 1144{
1145 readIncidenceBase(parent,incidence); 1145 readIncidenceBase(parent,incidence);
1146 1146
1147 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1147 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1148 bool readrec = false; 1148 bool readrec = false;
1149 const char *text; 1149 const char *text;
1150 int intvalue; 1150 int intvalue;
1151 icaltimetype icaltime; 1151 icaltimetype icaltime;
1152 icaldurationtype icalduration; 1152 icaldurationtype icalduration;
1153 struct icalrecurrencetype rectype; 1153 struct icalrecurrencetype rectype;
1154 QStringList categories; 1154 QStringList categories;
1155 1155
1156 while (p) { 1156 while (p) {
1157 icalproperty_kind kind = icalproperty_isa(p); 1157 icalproperty_kind kind = icalproperty_isa(p);
1158 switch (kind) { 1158 switch (kind) {
1159 1159
1160 case ICAL_CREATED_PROPERTY: 1160 case ICAL_CREATED_PROPERTY:
1161 icaltime = icalproperty_get_created(p); 1161 icaltime = icalproperty_get_created(p);
1162 incidence->setCreated(readICalDateTime(icaltime)); 1162 incidence->setCreated(readICalDateTime(icaltime));
1163 break; 1163 break;
1164 1164
1165 case ICAL_SEQUENCE_PROPERTY: // sequence 1165 case ICAL_SEQUENCE_PROPERTY: // sequence
1166 intvalue = icalproperty_get_sequence(p); 1166 intvalue = icalproperty_get_sequence(p);
1167 incidence->setRevision(intvalue); 1167 incidence->setRevision(intvalue);
1168 break; 1168 break;
1169 1169
1170 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1170 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1171 icaltime = icalproperty_get_lastmodified(p); 1171 icaltime = icalproperty_get_lastmodified(p);
1172 incidence->setLastModified(readICalDateTime(icaltime)); 1172 incidence->setLastModified(readICalDateTime(icaltime));
1173 break; 1173 break;
1174 1174
1175 case ICAL_DTSTART_PROPERTY: // start date and time 1175 case ICAL_DTSTART_PROPERTY: // start date and time
1176 icaltime = icalproperty_get_dtstart(p); 1176 icaltime = icalproperty_get_dtstart(p);
1177 if (icaltime.is_date) { 1177 if (icaltime.is_date) {
1178 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1178 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1179 incidence->setFloats(true); 1179 incidence->setFloats(true);
1180 } else { 1180 } else {
1181 incidence->setDtStart(readICalDateTime(icaltime)); 1181 incidence->setDtStart(readICalDateTime(icaltime));
1182 } 1182 }
1183 break; 1183 break;
1184 1184
1185 case ICAL_DURATION_PROPERTY: // start date and time 1185 case ICAL_DURATION_PROPERTY: // start date and time
1186 icalduration = icalproperty_get_duration(p); 1186 icalduration = icalproperty_get_duration(p);
1187 incidence->setDuration(readICalDuration(icalduration)); 1187 incidence->setDuration(readICalDuration(icalduration));
1188 break; 1188 break;
1189 1189
1190 case ICAL_DESCRIPTION_PROPERTY: // description 1190 case ICAL_DESCRIPTION_PROPERTY: // description
1191 text = icalproperty_get_description(p); 1191 text = icalproperty_get_description(p);
1192 incidence->setDescription(QString::fromUtf8(text)); 1192 incidence->setDescription(QString::fromUtf8(text));
1193 break; 1193 break;
1194 1194
1195 case ICAL_SUMMARY_PROPERTY: // summary 1195 case ICAL_SUMMARY_PROPERTY: // summary
1196 { 1196 {
1197 text = icalproperty_get_summary(p); 1197 text = icalproperty_get_summary(p);
1198 incidence->setSummary(QString::fromUtf8(text)); 1198 incidence->setSummary(QString::fromUtf8(text));
1199 } 1199 }
1200 break; 1200 break;
1201 case ICAL_STATUS_PROPERTY: // summary 1201 case ICAL_STATUS_PROPERTY: // summary
1202 { 1202 {
1203 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1203 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1204 incidence->setCancelled( true ); 1204 incidence->setCancelled( true );
1205 } 1205 }
1206 break; 1206 break;
1207 1207
1208 case ICAL_LOCATION_PROPERTY: // location 1208 case ICAL_LOCATION_PROPERTY: // location
1209 text = icalproperty_get_location(p); 1209 text = icalproperty_get_location(p);
1210 incidence->setLocation(QString::fromUtf8(text)); 1210 incidence->setLocation(QString::fromUtf8(text));
1211 break; 1211 break;
1212 1212
1213 case ICAL_RECURRENCEID_PROPERTY: 1213 case ICAL_RECURRENCEID_PROPERTY:
1214 icaltime = icalproperty_get_recurrenceid(p); 1214 icaltime = icalproperty_get_recurrenceid(p);
1215 incidence->setRecurrenceID( readICalDateTime(icaltime) ); 1215 incidence->setRecurrenceID( readICalDateTime(icaltime) );
1216 //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() ); 1216 //qDebug(" RecurrenceID %s",incidence->recurrenceID().toString().latin1() );
1217 break; 1217 break;
1218#if 0 1218#if 0
1219 // status 1219 // status
1220 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1220 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1221 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1221 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1222 deleteStr(s); 1222 deleteStr(s);
1223 } 1223 }
1224 else 1224 else
1225 incidence->setStatus("NEEDS ACTION"); 1225 incidence->setStatus("NEEDS ACTION");
1226#endif 1226#endif
1227 1227
1228 case ICAL_PRIORITY_PROPERTY: // priority 1228 case ICAL_PRIORITY_PROPERTY: // priority
1229 intvalue = icalproperty_get_priority(p); 1229 intvalue = icalproperty_get_priority(p);
1230 incidence->setPriority(intvalue); 1230 incidence->setPriority(intvalue);
1231 break; 1231 break;
1232 1232
1233 case ICAL_CATEGORIES_PROPERTY: // categories 1233 case ICAL_CATEGORIES_PROPERTY: // categories
1234 text = icalproperty_get_categories(p); 1234 text = icalproperty_get_categories(p);
1235 categories.append(QString::fromUtf8(text)); 1235 categories.append(QString::fromUtf8(text));
1236 break; 1236 break;
1237 //******************************************* 1237 //*******************************************
1238 case ICAL_RRULE_PROPERTY: 1238 case ICAL_RRULE_PROPERTY:
1239 // we do need (maybe )start datetime of incidence for recurrence 1239 // we do need (maybe )start datetime of incidence for recurrence
1240 // such that we can read recurrence only after we read incidence completely 1240 // such that we can read recurrence only after we read incidence completely
1241 readrec = true; 1241 readrec = true;
1242 rectype = icalproperty_get_rrule(p); 1242 rectype = icalproperty_get_rrule(p);
1243 break; 1243 break;
1244 1244
1245 case ICAL_EXDATE_PROPERTY: 1245 case ICAL_EXDATE_PROPERTY:
1246 icaltime = icalproperty_get_exdate(p); 1246 icaltime = icalproperty_get_exdate(p);
1247 incidence->addExDate(readICalDate(icaltime)); 1247 incidence->addExDate(readICalDate(icaltime));
1248 break; 1248 break;
1249 1249
1250 case ICAL_CLASS_PROPERTY: { 1250 case ICAL_CLASS_PROPERTY: {
1251 int inttext = icalproperty_get_class(p); 1251 int inttext = icalproperty_get_class(p);
1252 if (inttext == ICAL_CLASS_PUBLIC ) { 1252 if (inttext == ICAL_CLASS_PUBLIC ) {
1253 incidence->setSecrecy(Incidence::SecrecyPublic); 1253 incidence->setSecrecy(Incidence::SecrecyPublic);
1254 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1254 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1255 incidence->setSecrecy(Incidence::SecrecyConfidential); 1255 incidence->setSecrecy(Incidence::SecrecyConfidential);
1256 } else { 1256 } else {
1257 incidence->setSecrecy(Incidence::SecrecyPrivate); 1257 incidence->setSecrecy(Incidence::SecrecyPrivate);
1258 } 1258 }
1259 } 1259 }
1260 break; 1260 break;
1261 1261
1262 case ICAL_ATTACH_PROPERTY: // attachments 1262 case ICAL_ATTACH_PROPERTY: // attachments
1263 incidence->addAttachment(readAttachment(p)); 1263 incidence->addAttachment(readAttachment(p));
1264 break; 1264 break;
1265 1265
1266 default: 1266 default:
1267// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1267// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1268// << endl; 1268// << endl;
1269 break; 1269 break;
1270 } 1270 }
1271 1271
1272 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1272 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1273 } 1273 }
1274 if ( readrec ) { 1274 if ( readrec ) {
1275 readRecurrenceRule(rectype,incidence); 1275 readRecurrenceRule(rectype,incidence);
1276 } 1276 }
1277 // kpilot stuff 1277 // kpilot stuff
1278// TODO: move this application-specific code to kpilot 1278// TODO: move this application-specific code to kpilot
1279 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1279 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1280 if (!kp.isNull()) { 1280 if (!kp.isNull()) {
1281 incidence->setPilotId(kp.toInt()); 1281 incidence->setPilotId(kp.toInt());
1282 } 1282 }
1283 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1283 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1284 if (!kp.isNull()) { 1284 if (!kp.isNull()) {
1285 incidence->setSyncStatus(kp.toInt()); 1285 incidence->setSyncStatus(kp.toInt());
1286 } 1286 }
1287 1287
1288 1288
1289 kp = incidence->nonKDECustomProperty("X-KOPIEXTID"); 1289 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1290 if (!kp.isNull()) { 1290 if (!kp.isNull()) {
1291 incidence->setIDStr(kp); 1291 incidence->setIDStr(kp);
1292 } 1292 }
1293 1293
1294 // Cancel backwards compatibility mode for subsequent changes by the application 1294 // Cancel backwards compatibility mode for subsequent changes by the application
1295 if ( readrec ) 1295 if ( readrec )
1296 incidence->recurrence()->setCompatVersion(); 1296 incidence->recurrence()->setCompatVersion();
1297 1297
1298 // add categories 1298 // add categories
1299 incidence->setCategories(categories); 1299 incidence->setCategories(categories);
1300 1300
1301 // iterate through all alarms 1301 // iterate through all alarms
1302 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1302 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1303 alarm; 1303 alarm;
1304 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1304 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1305 readAlarm(alarm,incidence); 1305 readAlarm(alarm,incidence);
1306 } 1306 }
1307} 1307}
1308 1308
1309void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1309void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1310{ 1310{
1311 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1311 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1312 1312
1313 while (p) { 1313 while (p) {
1314 icalproperty_kind kind = icalproperty_isa(p); 1314 icalproperty_kind kind = icalproperty_isa(p);
1315 switch (kind) { 1315 switch (kind) {
1316 1316
1317 case ICAL_UID_PROPERTY: // unique id 1317 case ICAL_UID_PROPERTY: // unique id
1318 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1318 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1319 break; 1319 break;
1320 1320
1321 case ICAL_ORGANIZER_PROPERTY: // organizer 1321 case ICAL_ORGANIZER_PROPERTY: // organizer
1322 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1322 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1323 break; 1323 break;
1324 1324
1325 case ICAL_ATTENDEE_PROPERTY: // attendee 1325 case ICAL_ATTENDEE_PROPERTY: // attendee
1326 incidenceBase->addAttendee(readAttendee(p)); 1326 incidenceBase->addAttendee(readAttendee(p));
1327 break; 1327 break;
1328 1328
1329 default: 1329 default:
1330 break; 1330 break;
1331 } 1331 }
1332 1332
1333 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1333 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1334 } 1334 }
1335 1335
1336 // custom properties 1336 // custom properties
1337 readCustomProperties(parent, incidenceBase); 1337 readCustomProperties(parent, incidenceBase);
1338} 1338}
1339 1339
1340void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1340void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1341{ 1341{
1342 QMap<QCString, QString> customProperties; 1342 QMap<QCString, QString> customProperties;
1343 1343
1344 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1344 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1345 1345
1346 while (p) { 1346 while (p) {
1347 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1347 QString value = QString::fromUtf8(icalproperty_get_x(p));
1348 customProperties[icalproperty_get_x_name(p)] = value; 1348 customProperties[icalproperty_get_x_name(p)] = value;
1349 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1349 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1350 1350
1351 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1351 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1352 } 1352 }
1353 1353
1354 properties->setCustomProperties(customProperties); 1354 properties->setCustomProperties(customProperties);
1355} 1355}
1356 1356
1357void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1357void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1358{ 1358{
1359// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1359// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1360 1360
1361 Recurrence *recur = incidence->recurrence(); 1361 Recurrence *recur = incidence->recurrence();
1362 recur->setCompatVersion(mCalendarVersion); 1362 recur->setCompatVersion(mCalendarVersion);
1363 recur->unsetRecurs(); 1363 recur->unsetRecurs();
1364 1364
1365 struct icalrecurrencetype r = rrule; 1365 struct icalrecurrencetype r = rrule;
1366 1366
1367 dumpIcalRecurrence(r); 1367 dumpIcalRecurrence(r);
1368 readRecurrence( r, recur, incidence); 1368 readRecurrence( r, recur, incidence);
1369} 1369}
1370 1370
1371void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1371void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1372{ 1372{
1373 int wkst; 1373 int wkst;
1374 int index = 0; 1374 int index = 0;
1375 short day = 0; 1375 short day = 0;
1376 QBitArray qba(7); 1376 QBitArray qba(7);
1377 int frequ = r.freq; 1377 int frequ = r.freq;
1378 int interv = r.interval; 1378 int interv = r.interval;
1379 // preprocessing for odd recurrence definitions 1379 // preprocessing for odd recurrence definitions
1380 1380
1381 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1381 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1382 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1382 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1383 interv = 12; 1383 interv = 12;
1384 } 1384 }
1385 } 1385 }
1386 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1386 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1387 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1387 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1388 frequ = ICAL_MONTHLY_RECURRENCE; 1388 frequ = ICAL_MONTHLY_RECURRENCE;
1389 interv = 12* r.interval; 1389 interv = 12* r.interval;
1390 } 1390 }
1391 } 1391 }
1392 1392
1393 switch (frequ) { 1393 switch (frequ) {
1394 case ICAL_MINUTELY_RECURRENCE: 1394 case ICAL_MINUTELY_RECURRENCE:
1395 if (!icaltime_is_null_time(r.until)) { 1395 if (!icaltime_is_null_time(r.until)) {
1396 recur->setMinutely(interv,readICalDateTime(r.until)); 1396 recur->setMinutely(interv,readICalDateTime(r.until));
1397 } else { 1397 } else {
1398 if (r.count == 0) 1398 if (r.count == 0)
1399 recur->setMinutely(interv,-1); 1399 recur->setMinutely(interv,-1);
1400 else 1400 else
1401 recur->setMinutely(interv,r.count); 1401 recur->setMinutely(interv,r.count);
1402 } 1402 }
1403 break; 1403 break;
1404 case ICAL_HOURLY_RECURRENCE: 1404 case ICAL_HOURLY_RECURRENCE:
1405 if (!icaltime_is_null_time(r.until)) { 1405 if (!icaltime_is_null_time(r.until)) {
1406 recur->setHourly(interv,readICalDateTime(r.until)); 1406 recur->setHourly(interv,readICalDateTime(r.until));
1407 } else { 1407 } else {
1408 if (r.count == 0) 1408 if (r.count == 0)
1409 recur->setHourly(interv,-1); 1409 recur->setHourly(interv,-1);
1410 else 1410 else
1411 recur->setHourly(interv,r.count); 1411 recur->setHourly(interv,r.count);
1412 } 1412 }
1413 break; 1413 break;
1414 case ICAL_DAILY_RECURRENCE: 1414 case ICAL_DAILY_RECURRENCE:
1415 if (!icaltime_is_null_time(r.until)) { 1415 if (!icaltime_is_null_time(r.until)) {
1416 recur->setDaily(interv,readICalDate(r.until)); 1416 recur->setDaily(interv,readICalDate(r.until));
1417 } else { 1417 } else {
1418 if (r.count == 0) 1418 if (r.count == 0)
1419 recur->setDaily(interv,-1); 1419 recur->setDaily(interv,-1);
1420 else 1420 else
1421 recur->setDaily(interv,r.count); 1421 recur->setDaily(interv,r.count);
1422 } 1422 }
1423 break; 1423 break;
1424 case ICAL_WEEKLY_RECURRENCE: 1424 case ICAL_WEEKLY_RECURRENCE:
1425 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1425 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1426 wkst = (r.week_start + 5)%7 + 1; 1426 wkst = (r.week_start + 5)%7 + 1;
1427 if (!icaltime_is_null_time(r.until)) { 1427 if (!icaltime_is_null_time(r.until)) {
1428 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1428 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1429 } else { 1429 } else {
1430 if (r.count == 0) 1430 if (r.count == 0)
1431 recur->setWeekly(interv,qba,-1,wkst); 1431 recur->setWeekly(interv,qba,-1,wkst);
1432 else 1432 else
1433 recur->setWeekly(interv,qba,r.count,wkst); 1433 recur->setWeekly(interv,qba,r.count,wkst);
1434 } 1434 }
1435 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1435 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1436 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1436 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1437 //qDebug("weekly error found "); 1437 //qDebug("weekly error found ");
1438 qba.setBit(wday); 1438 qba.setBit(wday);
1439 } else { 1439 } else {
1440 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1440 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1441 // kdDebug(5800) << " " << day << endl; 1441 // kdDebug(5800) << " " << day << endl;
1442 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1442 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1443 } 1443 }
1444 } 1444 }
1445 break; 1445 break;
1446 case ICAL_MONTHLY_RECURRENCE: 1446 case ICAL_MONTHLY_RECURRENCE:
1447 1447
1448 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1448 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1449 if (!icaltime_is_null_time(r.until)) { 1449 if (!icaltime_is_null_time(r.until)) {
1450 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1450 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1451 readICalDate(r.until)); 1451 readICalDate(r.until));
1452 } else { 1452 } else {
1453 if (r.count == 0) 1453 if (r.count == 0)
1454 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1454 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1455 else 1455 else
1456 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1456 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1457 } 1457 }
1458 bool useSetPos = false; 1458 bool useSetPos = false;
1459 short pos = 0; 1459 short pos = 0;
1460 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1460 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1461 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1461 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1462 pos = icalrecurrencetype_day_position(day); 1462 pos = icalrecurrencetype_day_position(day);
1463 if (pos) { 1463 if (pos) {
1464 day = icalrecurrencetype_day_day_of_week(day); 1464 day = icalrecurrencetype_day_day_of_week(day);
1465 QBitArray ba(7); // don't wipe qba 1465 QBitArray ba(7); // don't wipe qba
1466 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1466 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1467 recur->addMonthlyPos(pos,ba); 1467 recur->addMonthlyPos(pos,ba);
1468 } else { 1468 } else {
1469 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1469 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1470 useSetPos = true; 1470 useSetPos = true;
1471 } 1471 }
1472 } 1472 }
1473 if (useSetPos) { 1473 if (useSetPos) {
1474 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1474 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1475 recur->addMonthlyPos(r.by_set_pos[0],qba); 1475 recur->addMonthlyPos(r.by_set_pos[0],qba);
1476 } 1476 }
1477 } 1477 }
1478 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1478 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1479 if (!icaltime_is_null_time(r.until)) { 1479 if (!icaltime_is_null_time(r.until)) {
1480 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1480 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1481 readICalDate(r.until)); 1481 readICalDate(r.until));
1482 } else { 1482 } else {
1483 if (r.count == 0) 1483 if (r.count == 0)
1484 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1484 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1485 else 1485 else
1486 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1486 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1487 } 1487 }
1488 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1488 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1489 // kdDebug(5800) << "----b " << day << endl; 1489 // kdDebug(5800) << "----b " << day << endl;
1490 recur->addMonthlyDay(day); 1490 recur->addMonthlyDay(day);
1491 } 1491 }
1492 } 1492 }
1493 break; 1493 break;
1494 case ICAL_YEARLY_RECURRENCE: 1494 case ICAL_YEARLY_RECURRENCE:
1495 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1495 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1496 //qDebug(" YEARLY DAY OF YEAR"); 1496 //qDebug(" YEARLY DAY OF YEAR");
1497 if (!icaltime_is_null_time(r.until)) { 1497 if (!icaltime_is_null_time(r.until)) {
1498 recur->setYearly(Recurrence::rYearlyDay,interv, 1498 recur->setYearly(Recurrence::rYearlyDay,interv,
1499 readICalDate(r.until)); 1499 readICalDate(r.until));
1500 } else { 1500 } else {
1501 if (r.count == 0) 1501 if (r.count == 0)
1502 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1502 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1503 else 1503 else
1504 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1504 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1505 } 1505 }
1506 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1506 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1507 recur->addYearlyNum(day); 1507 recur->addYearlyNum(day);
1508 } 1508 }
1509 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1509 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1510 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1510 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1511 qDebug("YEARLY POS NOT SUPPORTED BY GUI"); 1511 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1512 if (!icaltime_is_null_time(r.until)) { 1512 if (!icaltime_is_null_time(r.until)) {
1513 recur->setYearly(Recurrence::rYearlyPos,interv, 1513 recur->setYearly(Recurrence::rYearlyPos,interv,
1514 readICalDate(r.until)); 1514 readICalDate(r.until));
1515 } else { 1515 } else {
1516 if (r.count == 0) 1516 if (r.count == 0)
1517 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1517 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1518 else 1518 else
1519 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1519 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1520 } 1520 }
1521 bool useSetPos = false; 1521 bool useSetPos = false;
1522 short pos = 0; 1522 short pos = 0;
1523 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1523 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1524 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1524 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1525 pos = icalrecurrencetype_day_position(day); 1525 pos = icalrecurrencetype_day_position(day);
1526 if (pos) { 1526 if (pos) {
1527 day = icalrecurrencetype_day_day_of_week(day); 1527 day = icalrecurrencetype_day_day_of_week(day);
1528 QBitArray ba(7); // don't wipe qba 1528 QBitArray ba(7); // don't wipe qba
1529 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1529 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1530 recur->addYearlyMonthPos(pos,ba); 1530 recur->addYearlyMonthPos(pos,ba);
1531 } else { 1531 } else {
1532 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1532 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1533 useSetPos = true; 1533 useSetPos = true;
1534 } 1534 }
1535 } 1535 }
1536 if (useSetPos) { 1536 if (useSetPos) {
1537 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1537 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1538 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1538 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1539 } 1539 }
1540 } 1540 }
1541 } else { 1541 } else {
1542 //qDebug("YEARLY MONTH "); 1542 //qDebug("YEARLY MONTH ");
1543 if (!icaltime_is_null_time(r.until)) { 1543 if (!icaltime_is_null_time(r.until)) {
1544 recur->setYearly(Recurrence::rYearlyMonth,interv, 1544 recur->setYearly(Recurrence::rYearlyMonth,interv,
1545 readICalDate(r.until)); 1545 readICalDate(r.until));
1546 } else { 1546 } else {
1547 if (r.count == 0) 1547 if (r.count == 0)
1548 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1548 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1549 else 1549 else
1550 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1550 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1551 } 1551 }
1552 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1552 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1553 index = 0; 1553 index = 0;
1554 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1554 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1555 recur->addYearlyNum(day); 1555 recur->addYearlyNum(day);
1556 } 1556 }
1557 } else { 1557 } else {
1558 recur->addYearlyNum(incidence->dtStart().date().month()); 1558 recur->addYearlyNum(incidence->dtStart().date().month());
1559 } 1559 }
1560 } 1560 }
1561 1561
1562 } 1562 }
1563 break; 1563 break;
1564 default: 1564 default:
1565 ; 1565 ;
1566 break; 1566 break;
1567 } 1567 }
1568} 1568}
1569 1569
1570void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1570void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1571{ 1571{
1572 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1572 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1573 1573
1574 Alarm* ialarm = incidence->newAlarm(); 1574 Alarm* ialarm = incidence->newAlarm();
1575 ialarm->setRepeatCount(0); 1575 ialarm->setRepeatCount(0);
1576 ialarm->setEnabled(true); 1576 ialarm->setEnabled(true);
1577 1577
1578 // Determine the alarm's action type 1578 // Determine the alarm's action type
1579 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1579 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1580 if ( !p ) { 1580 if ( !p ) {
1581 return; 1581 return;
1582 } 1582 }
1583 1583
1584 icalproperty_action action = icalproperty_get_action(p); 1584 icalproperty_action action = icalproperty_get_action(p);
1585 Alarm::Type type = Alarm::Display; 1585 Alarm::Type type = Alarm::Display;
1586 switch ( action ) { 1586 switch ( action ) {
1587 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1587 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1588 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1588 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1589 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1589 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1590 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1590 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1591 default: 1591 default:
1592 ; 1592 ;
1593 return; 1593 return;
1594 } 1594 }
1595 ialarm->setType(type); 1595 ialarm->setType(type);
1596 1596
1597 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1597 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1598 while (p) { 1598 while (p) {
1599 icalproperty_kind kind = icalproperty_isa(p); 1599 icalproperty_kind kind = icalproperty_isa(p);
1600 1600
1601 switch (kind) { 1601 switch (kind) {
1602 case ICAL_TRIGGER_PROPERTY: { 1602 case ICAL_TRIGGER_PROPERTY: {
1603 icaltriggertype trigger = icalproperty_get_trigger(p); 1603 icaltriggertype trigger = icalproperty_get_trigger(p);
1604 if (icaltime_is_null_time(trigger.time)) { 1604 if (icaltime_is_null_time(trigger.time)) {
1605 if (icaldurationtype_is_null_duration(trigger.duration)) { 1605 if (icaldurationtype_is_null_duration(trigger.duration)) {
1606 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; 1606 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1607 } else { 1607 } else {
1608 Duration duration = icaldurationtype_as_int( trigger.duration ); 1608 Duration duration = icaldurationtype_as_int( trigger.duration );
1609 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1609 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1610 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1610 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1611 ialarm->setEndOffset(duration); 1611 ialarm->setEndOffset(duration);
1612 else 1612 else
1613 ialarm->setStartOffset(duration); 1613 ialarm->setStartOffset(duration);
1614 } 1614 }
1615 } else { 1615 } else {
1616 ialarm->setTime(readICalDateTime(trigger.time)); 1616 ialarm->setTime(readICalDateTime(trigger.time));
1617 } 1617 }
1618 break; 1618 break;
1619 } 1619 }
1620 case ICAL_DURATION_PROPERTY: { 1620 case ICAL_DURATION_PROPERTY: {
1621 icaldurationtype duration = icalproperty_get_duration(p); 1621 icaldurationtype duration = icalproperty_get_duration(p);
1622 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1622 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1623 break; 1623 break;
1624 } 1624 }
1625 case ICAL_REPEAT_PROPERTY: 1625 case ICAL_REPEAT_PROPERTY:
1626 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1626 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1627 break; 1627 break;
1628 1628
1629 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1629 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1630 case ICAL_DESCRIPTION_PROPERTY: { 1630 case ICAL_DESCRIPTION_PROPERTY: {
1631 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1631 QString description = QString::fromUtf8(icalproperty_get_description(p));
1632 switch ( action ) { 1632 switch ( action ) {
1633 case ICAL_ACTION_DISPLAY: 1633 case ICAL_ACTION_DISPLAY:
1634 ialarm->setText( description ); 1634 ialarm->setText( description );
1635 break; 1635 break;
1636 case ICAL_ACTION_PROCEDURE: 1636 case ICAL_ACTION_PROCEDURE:
1637 ialarm->setProgramArguments( description ); 1637 ialarm->setProgramArguments( description );
1638 break; 1638 break;
1639 case ICAL_ACTION_EMAIL: 1639 case ICAL_ACTION_EMAIL:
1640 ialarm->setMailText( description ); 1640 ialarm->setMailText( description );
1641 break; 1641 break;
1642 default: 1642 default:
1643 break; 1643 break;
1644 } 1644 }
1645 break; 1645 break;
1646 } 1646 }
1647 // Only in EMAIL alarm 1647 // Only in EMAIL alarm
1648 case ICAL_SUMMARY_PROPERTY: 1648 case ICAL_SUMMARY_PROPERTY:
1649 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1649 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1650 break; 1650 break;
1651 1651
1652 // Only in EMAIL alarm 1652 // Only in EMAIL alarm
1653 case ICAL_ATTENDEE_PROPERTY: { 1653 case ICAL_ATTENDEE_PROPERTY: {
1654 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1654 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1655 QString name; 1655 QString name;
1656 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1656 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1657 if (param) { 1657 if (param) {
1658 name = QString::fromUtf8(icalparameter_get_cn(param)); 1658 name = QString::fromUtf8(icalparameter_get_cn(param));
1659 } 1659 }
1660 ialarm->addMailAddress(Person(name, email)); 1660 ialarm->addMailAddress(Person(name, email));
1661 break; 1661 break;
1662 } 1662 }
1663 // Only in AUDIO and EMAIL and PROCEDURE alarms 1663 // Only in AUDIO and EMAIL and PROCEDURE alarms
1664 case ICAL_ATTACH_PROPERTY: { 1664 case ICAL_ATTACH_PROPERTY: {
1665 icalattach *attach = icalproperty_get_attach(p); 1665 icalattach *attach = icalproperty_get_attach(p);
1666 QString url = QFile::decodeName(icalattach_get_url(attach)); 1666 QString url = QFile::decodeName(icalattach_get_url(attach));
1667 switch ( action ) { 1667 switch ( action ) {
1668 case ICAL_ACTION_AUDIO: 1668 case ICAL_ACTION_AUDIO:
1669 ialarm->setAudioFile( url ); 1669 ialarm->setAudioFile( url );
1670 break; 1670 break;
1671 case ICAL_ACTION_PROCEDURE: 1671 case ICAL_ACTION_PROCEDURE:
1672 ialarm->setProgramFile( url ); 1672 ialarm->setProgramFile( url );
1673 break; 1673 break;
1674 case ICAL_ACTION_EMAIL: 1674 case ICAL_ACTION_EMAIL:
1675 ialarm->addMailAttachment( url ); 1675 ialarm->addMailAttachment( url );
1676 break; 1676 break;
1677 default: 1677 default:
1678 break; 1678 break;
1679 } 1679 }
1680 break; 1680 break;
1681 } 1681 }
1682 default: 1682 default:
1683 break; 1683 break;
1684 } 1684 }
1685 1685
1686 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1686 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1687 } 1687 }
1688 1688
1689 // custom properties 1689 // custom properties
1690 readCustomProperties(alarm, ialarm); 1690 readCustomProperties(alarm, ialarm);
1691 1691
1692 // TODO: check for consistency of alarm properties 1692 // TODO: check for consistency of alarm properties
1693} 1693}
1694 1694
1695icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1695icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1696{ 1696{
1697 icaltimetype t; 1697 icaltimetype t;
1698 1698
1699 t.year = date.year(); 1699 t.year = date.year();
1700 t.month = date.month(); 1700 t.month = date.month();
1701 t.day = date.day(); 1701 t.day = date.day();
1702 1702
1703 t.hour = 0; 1703 t.hour = 0;
1704 t.minute = 0; 1704 t.minute = 0;
1705 t.second = 0; 1705 t.second = 0;
1706 1706
1707 t.is_date = 1; 1707 t.is_date = 1;
1708 1708
1709 t.is_utc = 0; 1709 t.is_utc = 0;
1710 1710
1711 t.zone = 0; 1711 t.zone = 0;
1712 1712
1713 return t; 1713 return t;
1714} 1714}
1715 1715
1716icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1716icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1717{ 1717{
1718 icaltimetype t; 1718 icaltimetype t;
1719 t.is_date = 0; 1719 t.is_date = 0;
1720 t.zone = 0; 1720 t.zone = 0;
1721 QDateTime datetime; 1721 QDateTime datetime;
1722 if ( mParent->utc() ) { 1722 if ( mParent->utc() ) {
1723 int offset = KGlobal::locale()->localTimeOffset( dt ); 1723 int offset = KGlobal::locale()->localTimeOffset( dt );
1724 datetime = dt.addSecs ( -offset*60); 1724 datetime = dt.addSecs ( -offset*60);
1725 t.is_utc = 1; 1725 t.is_utc = 1;
1726 } 1726 }
1727 else { 1727 else {
1728 datetime = dt; 1728 datetime = dt;
1729 t.is_utc = 0; 1729 t.is_utc = 0;
1730 1730
1731 } 1731 }
1732 t.year = datetime.date().year(); 1732 t.year = datetime.date().year();
1733 t.month = datetime.date().month(); 1733 t.month = datetime.date().month();
1734 t.day = datetime.date().day(); 1734 t.day = datetime.date().day();
1735 1735
1736 t.hour = datetime.time().hour(); 1736 t.hour = datetime.time().hour();
1737 t.minute = datetime.time().minute(); 1737 t.minute = datetime.time().minute();
1738 t.second = datetime.time().second(); 1738 t.second = datetime.time().second();
1739 1739
1740 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1740 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1741 1741
1742// if ( mParent->utc() ) { 1742// if ( mParent->utc() ) {
1743// datetime = KGlobal::locale()->localTime( dt ); 1743// datetime = KGlobal::locale()->localTime( dt );
1744// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1744// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1745// if (mParent->timeZoneId().isEmpty()) 1745// if (mParent->timeZoneId().isEmpty())
1746// t = icaltime_as_utc(t, 0); 1746// t = icaltime_as_utc(t, 0);
1747// else 1747// else
1748// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1748// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1749// } 1749// }
1750 1750
1751 return t; 1751 return t;
1752} 1752}
1753 1753
1754QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1754QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1755{ 1755{
1756 QDateTime dt (QDate(t.year,t.month,t.day), 1756 QDateTime dt (QDate(t.year,t.month,t.day),
1757 QTime(t.hour,t.minute,t.second) ); 1757 QTime(t.hour,t.minute,t.second) );
1758 1758
1759 if (t.is_utc) { 1759 if (t.is_utc) {
1760 int offset = KGlobal::locale()->localTimeOffset( dt ); 1760 int offset = KGlobal::locale()->localTimeOffset( dt );
1761 dt = dt.addSecs ( offset*60); 1761 dt = dt.addSecs ( offset*60);
1762 } 1762 }
1763 1763
1764 return dt; 1764 return dt;
1765} 1765}
1766 1766
1767QDate ICalFormatImpl::readICalDate(icaltimetype t) 1767QDate ICalFormatImpl::readICalDate(icaltimetype t)
1768{ 1768{
1769 return QDate(t.year,t.month,t.day); 1769 return QDate(t.year,t.month,t.day);
1770} 1770}
1771 1771
1772icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1772icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1773{ 1773{
1774 icaldurationtype d; 1774 icaldurationtype d;
1775 1775
1776 d.is_neg = (seconds<0)?1:0; 1776 d.is_neg = (seconds<0)?1:0;
1777 if (seconds<0) seconds = -seconds; 1777 if (seconds<0) seconds = -seconds;
1778 1778
1779 d.weeks = seconds / gSecondsPerWeek; 1779 d.weeks = seconds / gSecondsPerWeek;
1780 seconds %= gSecondsPerWeek; 1780 seconds %= gSecondsPerWeek;
1781 d.days = seconds / gSecondsPerDay; 1781 d.days = seconds / gSecondsPerDay;
1782 seconds %= gSecondsPerDay; 1782 seconds %= gSecondsPerDay;
1783 d.hours = seconds / gSecondsPerHour; 1783 d.hours = seconds / gSecondsPerHour;
1784 seconds %= gSecondsPerHour; 1784 seconds %= gSecondsPerHour;
1785 d.minutes = seconds / gSecondsPerMinute; 1785 d.minutes = seconds / gSecondsPerMinute;
1786 seconds %= gSecondsPerMinute; 1786 seconds %= gSecondsPerMinute;
1787 d.seconds = seconds; 1787 d.seconds = seconds;
1788 return d; 1788 return d;
1789} 1789}
1790 1790
1791int ICalFormatImpl::readICalDuration(icaldurationtype d) 1791int ICalFormatImpl::readICalDuration(icaldurationtype d)
1792{ 1792{
1793 int result = 0; 1793 int result = 0;
1794 1794
1795 result += d.weeks * gSecondsPerWeek; 1795 result += d.weeks * gSecondsPerWeek;
1796 result += d.days * gSecondsPerDay; 1796 result += d.days * gSecondsPerDay;
1797 result += d.hours * gSecondsPerHour; 1797 result += d.hours * gSecondsPerHour;
1798 result += d.minutes * gSecondsPerMinute; 1798 result += d.minutes * gSecondsPerMinute;
1799 result += d.seconds; 1799 result += d.seconds;
1800 1800
1801 if (d.is_neg) result *= -1; 1801 if (d.is_neg) result *= -1;
1802 1802
1803 return result; 1803 return result;
1804} 1804}
1805 1805
1806icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1806icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1807{ 1807{
1808 icalcomponent *calendar; 1808 icalcomponent *calendar;
1809 1809
1810 // Root component 1810 // Root component
1811 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1811 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1812 1812
1813 icalproperty *p; 1813 icalproperty *p;
1814 1814
1815 // Product Identifier 1815 // Product Identifier
1816 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1816 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1817 icalcomponent_add_property(calendar,p); 1817 icalcomponent_add_property(calendar,p);
1818 1818
1819 // TODO: Add time zone 1819 // TODO: Add time zone
1820 1820
1821 // iCalendar version (2.0) 1821 // iCalendar version (2.0)
1822 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1822 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1823 icalcomponent_add_property(calendar,p); 1823 icalcomponent_add_property(calendar,p);
1824 1824
1825 // Custom properties 1825 // Custom properties
1826 if( cal != 0 ) 1826 if( cal != 0 )
1827 writeCustomProperties(calendar, cal); 1827 writeCustomProperties(calendar, cal);
1828 1828
1829 return calendar; 1829 return calendar;
1830} 1830}
1831 1831
1832 1832
1833 1833
1834// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1834// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1835// and break it down from its tree-like format into the dictionary format 1835// and break it down from its tree-like format into the dictionary format
1836// that is used internally in the ICalFormatImpl. 1836// that is used internally in the ICalFormatImpl.
1837bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1837bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1838{ 1838{
1839 // this function will populate the caldict dictionary and other event 1839 // this function will populate the caldict dictionary and other event
1840 // lists. It turns vevents into Events and then inserts them. 1840 // lists. It turns vevents into Events and then inserts them.
1841 1841
1842 if (!calendar) return false; 1842 if (!calendar) return false;
1843 1843
1844// TODO: check for METHOD 1844// TODO: check for METHOD
1845#if 0 1845#if 0
1846 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1846 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1847 char *methodType = 0; 1847 char *methodType = 0;
1848 methodType = fakeCString(vObjectUStringZValue(curVO)); 1848 methodType = fakeCString(vObjectUStringZValue(curVO));
1849 if (mEnableDialogs) 1849 if (mEnableDialogs)
1850 KMessageBox::information(mTopWidget, 1850 KMessageBox::information(mTopWidget,
1851 i18n("This calendar is an iTIP transaction of type \"%1\".") 1851 i18n("This calendar is an iTIP transaction of type \"%1\".")
1852 .arg(methodType), 1852 .arg(methodType),
1853 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1853 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1854 delete methodType; 1854 delete methodType;
1855 } 1855 }
1856#endif 1856#endif
1857 1857
1858 icalproperty *p; 1858 icalproperty *p;
1859 1859
1860 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1860 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1861 if (!p) { 1861 if (!p) {
1862// TODO: does no PRODID really matter? 1862// TODO: does no PRODID really matter?
1863// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1863// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1864// return false; 1864// return false;
1865 mLoadedProductId = ""; 1865 mLoadedProductId = "";
1866 mCalendarVersion = 0; 1866 mCalendarVersion = 0;
1867 } else { 1867 } else {
1868 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1868 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1869 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1869 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1870 1870
1871 delete mCompat; 1871 delete mCompat;
1872 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1872 mCompat = CompatFactory::createCompat( mLoadedProductId );
1873 } 1873 }
1874 1874
1875// TODO: check for unknown PRODID 1875// TODO: check for unknown PRODID
1876#if 0 1876#if 0
1877 if (!mCalendarVersion 1877 if (!mCalendarVersion
1878 && CalFormat::productId() != mLoadedProductId) { 1878 && CalFormat::productId() != mLoadedProductId) {
1879 // warn the user that we might have trouble reading non-known calendar. 1879 // warn the user that we might have trouble reading non-known calendar.
1880 if (mEnableDialogs) 1880 if (mEnableDialogs)
1881 KMessageBox::information(mTopWidget, 1881 KMessageBox::information(mTopWidget,
1882 i18n("This vCalendar file was not created by KOrganizer " 1882 i18n("This vCalendar file was not created by KOrganizer "
1883 "or any other product we support. Loading anyway..."), 1883 "or any other product we support. Loading anyway..."),
1884 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); 1884 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application()));
1885 } 1885 }
1886#endif 1886#endif
1887 1887
1888 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); 1888 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
1889 if (!p) { 1889 if (!p) {
1890 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1890 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1891 return false; 1891 return false;
1892 } else { 1892 } else {
1893 const char *version = icalproperty_get_version(p); 1893 const char *version = icalproperty_get_version(p);
1894 1894
1895 if (strcmp(version,"1.0") == 0) { 1895 if (strcmp(version,"1.0") == 0) {
1896 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, 1896 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1,
1897 i18n("Expected iCalendar format"))); 1897 i18n("Expected iCalendar format")));
1898 return false; 1898 return false;
1899 } else if (strcmp(version,"2.0") != 0) { 1899 } else if (strcmp(version,"2.0") != 0) {
1900 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1900 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1901 return false; 1901 return false;
1902 } 1902 }
1903 } 1903 }
1904 1904
1905 1905
1906// TODO: check for calendar format version 1906// TODO: check for calendar format version
1907#if 0 1907#if 0
1908 // warn the user we might have trouble reading this unknown version. 1908 // warn the user we might have trouble reading this unknown version.
1909 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1909 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1910 char *s = fakeCString(vObjectUStringZValue(curVO)); 1910 char *s = fakeCString(vObjectUStringZValue(curVO));
1911 if (strcmp(_VCAL_VERSION, s) != 0) 1911 if (strcmp(_VCAL_VERSION, s) != 0)
1912 if (mEnableDialogs) 1912 if (mEnableDialogs)
1913 KMessageBox::sorry(mTopWidget, 1913 KMessageBox::sorry(mTopWidget,
1914 i18n("This vCalendar file has version %1.\n" 1914 i18n("This vCalendar file has version %1.\n"
1915 "We only support %2.") 1915 "We only support %2.")
1916 .arg(s).arg(_VCAL_VERSION), 1916 .arg(s).arg(_VCAL_VERSION),
1917 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); 1917 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application()));
1918 deleteStr(s); 1918 deleteStr(s);
1919 } 1919 }
1920#endif 1920#endif
1921 1921
1922 // custom properties 1922 // custom properties
1923 readCustomProperties(calendar, cal); 1923 readCustomProperties(calendar, cal);
1924 1924
1925// TODO: set time zone 1925// TODO: set time zone
1926#if 0 1926#if 0
1927 // set the time zone 1927 // set the time zone
1928 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1928 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1929 char *s = fakeCString(vObjectUStringZValue(curVO)); 1929 char *s = fakeCString(vObjectUStringZValue(curVO));
1930 cal->setTimeZone(s); 1930 cal->setTimeZone(s);
1931 deleteStr(s); 1931 deleteStr(s);
1932 } 1932 }
1933#endif 1933#endif
1934 1934
1935 // Store all events with a relatedTo property in a list for post-processing 1935 // Store all events with a relatedTo property in a list for post-processing
1936 mEventsRelate.clear(); 1936 mEventsRelate.clear();
1937 mTodosRelate.clear(); 1937 mTodosRelate.clear();
1938 // TODO: make sure that only actually added ecvens go to this lists. 1938 // TODO: make sure that only actually added ecvens go to this lists.
1939 1939
1940 icalcomponent *c; 1940 icalcomponent *c;
1941 1941
1942 // Iterate through all todos 1942 // Iterate through all todos
1943 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); 1943 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
1944 while (c) { 1944 while (c) {
1945// kdDebug(5800) << "----Todo found" << endl; 1945// kdDebug(5800) << "----Todo found" << endl;
1946 Todo *todo = readTodo(c); 1946 Todo *todo = readTodo(c);
1947 if (!cal->todo(todo->uid())) cal->addTodo(todo); 1947 if (!cal->todo(todo->uid()))
1948 cal->addTodo(todo);
1948 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); 1949 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
1949 } 1950 }
1950 1951
1951 // Iterate through all events 1952 // Iterate through all events
1952 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); 1953 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
1953 while (c) { 1954 while (c) {
1954// kdDebug(5800) << "----Event found" << endl; 1955// kdDebug(5800) << "----Event found" << endl;
1955 Event *event = readEvent(c); 1956 Event *event = readEvent(c);
1956 if (!cal->event(event->uid())) cal->addEvent(event); 1957 if (!cal->event(event->uid()))
1958 cal->addEvent(event);
1957 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); 1959 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
1958 } 1960 }
1959 1961
1960 // Iterate through all journals 1962 // Iterate through all journals
1961 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); 1963 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
1962 while (c) { 1964 while (c) {
1963// kdDebug(5800) << "----Journal found" << endl; 1965// kdDebug(5800) << "----Journal found" << endl;
1964 Journal *journal = readJournal(c); 1966 Journal *journal = readJournal(c);
1965 if (!cal->journal(journal->uid())) cal->addJournal(journal); 1967 if (!cal->journal(journal->uid()))
1968 cal->addJournal(journal);
1966 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); 1969 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
1967 } 1970 }
1968 1971
1969#if 0 1972#if 0
1970 initPropIterator(&i, vcal); 1973 initPropIterator(&i, vcal);
1971 1974
1972 // go through all the vobjects in the vcal 1975 // go through all the vobjects in the vcal
1973 while (moreIteration(&i)) { 1976 while (moreIteration(&i)) {
1974 curVO = nextVObject(&i); 1977 curVO = nextVObject(&i);
1975 1978
1976 /************************************************************************/ 1979 /************************************************************************/
1977 1980
1978 // now, check to see that the object is an event or todo. 1981 // now, check to see that the object is an event or todo.
1979 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1982 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1980 1983
1981 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { 1984 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) {
1982 char *s; 1985 char *s;
1983 s = fakeCString(vObjectUStringZValue(curVOProp)); 1986 s = fakeCString(vObjectUStringZValue(curVOProp));
1984 // check to see if event was deleted by the kpilot conduit 1987 // check to see if event was deleted by the kpilot conduit
1985 if (atoi(s) == Event::SYNCDEL) { 1988 if (atoi(s) == Event::SYNCDEL) {
1986 deleteStr(s); 1989 deleteStr(s);
1987 goto SKIP; 1990 goto SKIP;
1988 } 1991 }
1989 deleteStr(s); 1992 deleteStr(s);
1990 } 1993 }
1991 1994
1992 // this code checks to see if we are trying to read in an event 1995 // this code checks to see if we are trying to read in an event
1993 // that we already find to be in the calendar. If we find this 1996 // that we already find to be in the calendar. If we find this
1994 // to be the case, we skip the event. 1997 // to be the case, we skip the event.
1995 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1998 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1996 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1999 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1997 QString tmpStr(s); 2000 QString tmpStr(s);
1998 deleteStr(s); 2001 deleteStr(s);
1999 2002
2000 if (cal->event(tmpStr)) { 2003 if (cal->event(tmpStr)) {
2001 goto SKIP; 2004 goto SKIP;
2002 } 2005 }
2003 if (cal->todo(tmpStr)) { 2006 if (cal->todo(tmpStr)) {
2004 goto SKIP; 2007 goto SKIP;
2005 } 2008 }
2006 } 2009 }
2007 2010
2008 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 2011 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
2009 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 2012 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
2010 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 2013 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
2011 goto SKIP; 2014 goto SKIP;
2012 } 2015 }
2013 2016
2014 anEvent = VEventToEvent(curVO); 2017 anEvent = VEventToEvent(curVO);
2015 // we now use addEvent instead of insertEvent so that the 2018 // we now use addEvent instead of insertEvent so that the
2016 // signal/slot get connected. 2019 // signal/slot get connected.
2017 if (anEvent) 2020 if (anEvent)
2018 cal->addEvent(anEvent); 2021 cal->addEvent(anEvent);
2019 else { 2022 else {
2020 // some sort of error must have occurred while in translation. 2023 // some sort of error must have occurred while in translation.
2021 goto SKIP; 2024 goto SKIP;
2022 } 2025 }
2023 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 2026 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
2024 anEvent = VTodoToEvent(curVO); 2027 anEvent = VTodoToEvent(curVO);
2025 cal->addTodo(anEvent); 2028 cal->addTodo(anEvent);
2026 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 2029 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
2027 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 2030 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
2028 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 2031 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
2029 // do nothing, we know these properties and we want to skip them. 2032 // do nothing, we know these properties and we want to skip them.
2030 // we have either already processed them or are ignoring them. 2033 // we have either already processed them or are ignoring them.
2031 ; 2034 ;
2032 } else { 2035 } else {
2033 ; 2036 ;
2034 } 2037 }
2035 SKIP: 2038 SKIP:
2036 ; 2039 ;
2037 } // while 2040 } // while
2038#endif 2041#endif
2039 2042
2040 // Post-Process list of events with relations, put Event objects in relation 2043 // Post-Process list of events with relations, put Event objects in relation
2041 Event *ev; 2044 Event *ev;
2042 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 2045 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
2043 Incidence * inc = cal->event(ev->relatedToUid()); 2046 Incidence * inc = cal->event(ev->relatedToUid());
2044 if ( inc ) 2047 if ( inc )
2045 ev->setRelatedTo( inc ); 2048 ev->setRelatedTo( inc );
2046 } 2049 }
2047 Todo *todo; 2050 Todo *todo;
2048 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 2051 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
2049 Incidence * inc = cal->todo(todo->relatedToUid()); 2052 Incidence * inc = cal->todo(todo->relatedToUid());
2050 if ( inc ) 2053 if ( inc )
2051 todo->setRelatedTo( inc ); 2054 todo->setRelatedTo( inc );
2052 } 2055 }
2053 2056
2054 return true; 2057 return true;
2055} 2058}
2056 2059
2057QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) 2060QString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2058{ 2061{
2059// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " 2062// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: "
2060// << icalcomponent_as_ical_string(c) << endl; 2063// << icalcomponent_as_ical_string(c) << endl;
2061 2064
2062 QString errorMessage; 2065 QString errorMessage;
2063 2066
2064 icalproperty *error; 2067 icalproperty *error;
2065 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); 2068 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
2066 while(error) { 2069 while(error) {
2067 errorMessage += icalproperty_get_xlicerror(error); 2070 errorMessage += icalproperty_get_xlicerror(error);
2068 errorMessage += "\n"; 2071 errorMessage += "\n";
2069 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); 2072 error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY);
2070 } 2073 }
2071 2074
2072// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; 2075// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl;
2073 2076
2074 return errorMessage; 2077 return errorMessage;
2075} 2078}
2076 2079
2077void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) 2080void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r)
2078{ 2081{
2079 int i; 2082 int i;
2080 2083
2081 2084
2082 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2085 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2083 int index = 0; 2086 int index = 0;
2084 QString out = " By Day: "; 2087 QString out = " By Day: ";
2085 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2088 while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2086 out.append(QString::number(i) + " "); 2089 out.append(QString::number(i) + " ");
2087 } 2090 }
2088 } 2091 }
2089 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2092 if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2090 int index = 0; 2093 int index = 0;
2091 QString out = " By Month Day: "; 2094 QString out = " By Month Day: ";
2092 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2095 while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2093 out.append(QString::number(i) + " "); 2096 out.append(QString::number(i) + " ");
2094 } 2097 }
2095 } 2098 }
2096 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2099 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2097 int index = 0; 2100 int index = 0;
2098 QString out = " By Year Day: "; 2101 QString out = " By Year Day: ";
2099 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2102 while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2100 out.append(QString::number(i) + " "); 2103 out.append(QString::number(i) + " ");
2101 } 2104 }
2102 } 2105 }
2103 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2106 if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2104 int index = 0; 2107 int index = 0;
2105 QString out = " By Month: "; 2108 QString out = " By Month: ";
2106 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2109 while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2107 out.append(QString::number(i) + " "); 2110 out.append(QString::number(i) + " ");
2108 } 2111 }
2109 } 2112 }
2110 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 2113 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
2111 int index = 0; 2114 int index = 0;
2112 QString out = " By Set Pos: "; 2115 QString out = " By Set Pos: ";
2113 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 2116 while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
2114 out.append(QString::number(i) + " "); 2117 out.append(QString::number(i) + " ");
2115 } 2118 }
2116 } 2119 }
2117} 2120}
2118 2121
2119icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, 2122icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence,
2120 Scheduler::Method method) 2123 Scheduler::Method method)
2121{ 2124{
2122 icalcomponent *message = createCalendarComponent(); 2125 icalcomponent *message = createCalendarComponent();
2123 2126
2124 icalproperty_method icalmethod = ICAL_METHOD_NONE; 2127 icalproperty_method icalmethod = ICAL_METHOD_NONE;
2125 2128
2126 switch (method) { 2129 switch (method) {
2127 case Scheduler::Publish: 2130 case Scheduler::Publish:
2128 icalmethod = ICAL_METHOD_PUBLISH; 2131 icalmethod = ICAL_METHOD_PUBLISH;
2129 break; 2132 break;
2130 case Scheduler::Request: 2133 case Scheduler::Request:
2131 icalmethod = ICAL_METHOD_REQUEST; 2134 icalmethod = ICAL_METHOD_REQUEST;
2132 break; 2135 break;
2133 case Scheduler::Refresh: 2136 case Scheduler::Refresh:
2134 icalmethod = ICAL_METHOD_REFRESH; 2137 icalmethod = ICAL_METHOD_REFRESH;
2135 break; 2138 break;
2136 case Scheduler::Cancel: 2139 case Scheduler::Cancel:
2137 icalmethod = ICAL_METHOD_CANCEL; 2140 icalmethod = ICAL_METHOD_CANCEL;
2138 break; 2141 break;
2139 case Scheduler::Add: 2142 case Scheduler::Add:
2140 icalmethod = ICAL_METHOD_ADD; 2143 icalmethod = ICAL_METHOD_ADD;
2141 break; 2144 break;
2142 case Scheduler::Reply: 2145 case Scheduler::Reply:
2143 icalmethod = ICAL_METHOD_REPLY; 2146 icalmethod = ICAL_METHOD_REPLY;
2144 break; 2147 break;
2145 case Scheduler::Counter: 2148 case Scheduler::Counter:
2146 icalmethod = ICAL_METHOD_COUNTER; 2149 icalmethod = ICAL_METHOD_COUNTER;
2147 break; 2150 break;
2148 case Scheduler::Declinecounter: 2151 case Scheduler::Declinecounter:
2149 icalmethod = ICAL_METHOD_DECLINECOUNTER; 2152 icalmethod = ICAL_METHOD_DECLINECOUNTER;
2150 break; 2153 break;
2151 default: 2154 default:
2152 2155
2153 return message; 2156 return message;
2154 } 2157 }
2155 2158
2156 icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); 2159 icalcomponent_add_property(message,icalproperty_new_method(icalmethod));
2157 2160
2158 // TODO: check, if dynamic cast is required 2161 // TODO: check, if dynamic cast is required
2159 if(incidence->typeID() == todoID ) { 2162 if(incidence->typeID() == todoID ) {
2160 Todo *todo = static_cast<Todo *>(incidence); 2163 Todo *todo = static_cast<Todo *>(incidence);
2161 icalcomponent_add_component(message,writeTodo(todo)); 2164 icalcomponent_add_component(message,writeTodo(todo));
2162 } 2165 }
2163 if(incidence->typeID() == eventID ) { 2166 if(incidence->typeID() == eventID ) {
2164 Event *event = static_cast<Event *>(incidence); 2167 Event *event = static_cast<Event *>(incidence);
2165 icalcomponent_add_component(message,writeEvent(event)); 2168 icalcomponent_add_component(message,writeEvent(event));
2166 } 2169 }
2167 if(incidence->typeID() == freebusyID) { 2170 if(incidence->typeID() == freebusyID) {
2168 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); 2171 FreeBusy *freebusy = static_cast<FreeBusy *>(incidence);
2169 icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); 2172 icalcomponent_add_component(message,writeFreeBusy(freebusy, method));
2170 } 2173 }
2171 2174
2172 return message; 2175 return message;
2173} 2176}
diff --git a/libkcal/journal.cpp b/libkcal/journal.cpp
index 859161f..c4e4474 100644
--- a/libkcal/journal.cpp
+++ b/libkcal/journal.cpp
@@ -1,49 +1,51 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include "journal.h" 21#include "journal.h"
22 22
23using namespace KCal; 23using namespace KCal;
24 24
25Journal::Journal() 25Journal::Journal()
26{ 26{
27 qDebug("New JJJ ");
27} 28}
28 29
29Journal::~Journal() 30Journal::~Journal()
30{ 31{
32 qDebug("delete JJJ ");
31} 33}
32 34
33Incidence *Journal::clone() 35Incidence *Journal::clone()
34{ 36{
35 return new Journal(*this); 37 return new Journal(*this);
36} 38}
37 39
38 40
39bool KCal::operator==( const Journal& j1, const Journal& j2 ) 41bool KCal::operator==( const Journal& j1, const Journal& j2 )
40{ 42{
41 return operator==( (const Incidence&)j1, (const Incidence&)j2 ); 43 return operator==( (const Incidence&)j1, (const Incidence&)j2 );
42} 44}
43 45
44 46
45QDateTime Journal::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 47QDateTime Journal::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
46{ 48{
47 *ok = false; 49 *ok = false;
48 return QDateTime (); 50 return QDateTime ();
49} 51}