summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-01 21:34:31 (UTC)
committer zautrix <zautrix>2004-08-01 21:34:31 (UTC)
commited3af1a632f953179ef3cad76ab5d99809f47d60 (patch) (unidiff)
treebe4fdfcf808d6876b4bee0698ddc17c8d20313d4
parent062113379f93ed645d2f246183c89eb8b6814834 (diff)
downloadkdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.zip
kdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.tar.gz
kdepimpi-ed3af1a632f953179ef3cad76ab5d99809f47d60.tar.bz2
More sync work
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp16
-rw-r--r--libkcal/incidencebase.cpp81
-rw-r--r--libkcal/incidencebase.h8
3 files changed, 92 insertions, 13 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index df05ab3..c23978d 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1,2058 +1,2052 @@
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#if QT_VERSION >= 300 206#if QT_VERSION >= 300
207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: " 207 kdDebug(5800) << "icalformatimpl: writeFreeBusy: startDate: "
208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: " 208 << freebusy->dtStart().toString("ddd MMMM d yyyy: h:m:s ap") << " End Date: "
209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl; 209 << freebusy->dtEnd().toString("ddd MMMM d yyyy: h:m:s ap") << endl;
210#endif 210#endif
211 211
212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT); 212 icalcomponent *vfreebusy = icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
213 213
214 writeIncidenceBase(vfreebusy,freebusy); 214 writeIncidenceBase(vfreebusy,freebusy);
215 215
216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart( 216 icalcomponent_add_property(vfreebusy, icalproperty_new_dtstart(
217 writeICalDateTime(freebusy->dtStart()))); 217 writeICalDateTime(freebusy->dtStart())));
218 218
219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend( 219 icalcomponent_add_property(vfreebusy, icalproperty_new_dtend(
220 writeICalDateTime(freebusy->dtEnd()))); 220 writeICalDateTime(freebusy->dtEnd())));
221 221
222 if (method == Scheduler::Request) { 222 if (method == Scheduler::Request) {
223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid( 223 icalcomponent_add_property(vfreebusy,icalproperty_new_uid(
224 freebusy->uid().utf8())); 224 freebusy->uid().utf8()));
225 } 225 }
226 226
227 //Loops through all the periods in the freebusy object 227 //Loops through all the periods in the freebusy object
228 QValueList<Period> list = freebusy->busyPeriods(); 228 QValueList<Period> list = freebusy->busyPeriods();
229 QValueList<Period>::Iterator it; 229 QValueList<Period>::Iterator it;
230 icalperiodtype period; 230 icalperiodtype period;
231 for (it = list.begin(); it!= list.end(); ++it) { 231 for (it = list.begin(); it!= list.end(); ++it) {
232 period.start = writeICalDateTime((*it).start()); 232 period.start = writeICalDateTime((*it).start());
233 period.end = writeICalDateTime((*it).end()); 233 period.end = writeICalDateTime((*it).end());
234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) ); 234 icalcomponent_add_property(vfreebusy, icalproperty_new_freebusy(period) );
235 } 235 }
236 236
237 return vfreebusy; 237 return vfreebusy;
238} 238}
239 239
240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal) 240icalcomponent *ICalFormatImpl::writeJournal(Journal *journal)
241{ 241{
242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT); 242 icalcomponent *vjournal = icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
243 243
244 writeIncidence(vjournal,journal); 244 writeIncidence(vjournal,journal);
245 245
246 // start time 246 // start time
247 if (journal->dtStart().isValid()) { 247 if (journal->dtStart().isValid()) {
248 icaltimetype start; 248 icaltimetype start;
249 if (journal->doesFloat()) { 249 if (journal->doesFloat()) {
250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl; 250// kdDebug(5800) << "§§ Incidence " << event->summary() << " floats." << endl;
251 start = writeICalDate(journal->dtStart().date()); 251 start = writeICalDate(journal->dtStart().date());
252 } else { 252 } else {
253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl; 253// kdDebug(5800) << "§§ incidence " << event->summary() << " has time." << endl;
254 start = writeICalDateTime(journal->dtStart()); 254 start = writeICalDateTime(journal->dtStart());
255 } 255 }
256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start)); 256 icalcomponent_add_property(vjournal,icalproperty_new_dtstart(start));
257 } 257 }
258 258
259 return vjournal; 259 return vjournal;
260} 260}
261 261
262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence) 262void ICalFormatImpl::writeIncidence(icalcomponent *parent,Incidence *incidence)
263{ 263{
264 // pilot sync stuff 264 // pilot sync stuff
265// TODO: move this application-specific code to kpilot 265// TODO: move this application-specific code to kpilot
266 if (incidence->pilotId()) { 266 if (incidence->pilotId()) {
267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId())); 267 incidence->setNonKDECustomProperty("X-PILOTID", QString::number(incidence->pilotId()));
268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus())); 268 incidence->setNonKDECustomProperty("X-PILOTSTAT", QString::number(incidence->syncStatus()));
269 } 269 }
270 if (incidence->zaurusId() >= 0) { 270 if ( !incidence->IDStr().isEmpty()) {
271 incidence->setNonKDECustomProperty("X-ZAURUSID", QString::number(incidence->zaurusId())); 271 incidence->setNonKDECustomProperty("X-KOPIEXTID",incidence->IDStr() );
272 } 272 }
273 273
274 if (incidence->zaurusUid() > 0) {
275 incidence->setNonKDECustomProperty("X-ZAURUSUID", QString::number(incidence->zaurusUid()));
276 }
277 274
278 writeIncidenceBase(parent,incidence); 275 writeIncidenceBase(parent,incidence);
279 if (incidence->cancelled()) { 276 if (incidence->cancelled()) {
280 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED)); 277 icalcomponent_add_property(parent,icalproperty_new_status(ICAL_STATUS_CANCELLED));
281 } 278 }
282 279
283 // creation date 280 // creation date
284 icalcomponent_add_property(parent,icalproperty_new_created( 281 icalcomponent_add_property(parent,icalproperty_new_created(
285 writeICalDateTime(incidence->created()))); 282 writeICalDateTime(incidence->created())));
286 283
287 // unique id 284 // unique id
288 icalcomponent_add_property(parent,icalproperty_new_uid( 285 icalcomponent_add_property(parent,icalproperty_new_uid(
289 incidence->uid().utf8())); 286 incidence->uid().utf8()));
290 287
291 // revision 288 // revision
292 icalcomponent_add_property(parent,icalproperty_new_sequence( 289 icalcomponent_add_property(parent,icalproperty_new_sequence(
293 incidence->revision())); 290 incidence->revision()));
294 291
295 // last modification date 292 // last modification date
296 icalcomponent_add_property(parent,icalproperty_new_lastmodified( 293 icalcomponent_add_property(parent,icalproperty_new_lastmodified(
297 writeICalDateTime(incidence->lastModified()))); 294 writeICalDateTime(incidence->lastModified())));
298 295
299 // description 296 // description
300 if (!incidence->description().isEmpty()) { 297 if (!incidence->description().isEmpty()) {
301 icalcomponent_add_property(parent,icalproperty_new_description( 298 icalcomponent_add_property(parent,icalproperty_new_description(
302 incidence->description().utf8())); 299 incidence->description().utf8()));
303 } 300 }
304 301
305 // summary 302 // summary
306 if (!incidence->summary().isEmpty()) { 303 if (!incidence->summary().isEmpty()) {
307 icalcomponent_add_property(parent,icalproperty_new_summary( 304 icalcomponent_add_property(parent,icalproperty_new_summary(
308 incidence->summary().utf8())); 305 incidence->summary().utf8()));
309 } 306 }
310 307
311 // location 308 // location
312 if (!incidence->location().isEmpty()) { 309 if (!incidence->location().isEmpty()) {
313 icalcomponent_add_property(parent,icalproperty_new_location( 310 icalcomponent_add_property(parent,icalproperty_new_location(
314 incidence->location().utf8())); 311 incidence->location().utf8()));
315 } 312 }
316 313
317// TODO: 314// TODO:
318 // status 315 // status
319// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8()); 316// addPropValue(parent, VCStatusProp, incidence->getStatusStr().utf8());
320 317
321 // secrecy 318 // secrecy
322 enum icalproperty_class classInt; 319 enum icalproperty_class classInt;
323 switch (incidence->secrecy()) { 320 switch (incidence->secrecy()) {
324 case Incidence::SecrecyPublic: 321 case Incidence::SecrecyPublic:
325 classInt = ICAL_CLASS_PUBLIC; 322 classInt = ICAL_CLASS_PUBLIC;
326 break; 323 break;
327 case Incidence::SecrecyConfidential: 324 case Incidence::SecrecyConfidential:
328 classInt = ICAL_CLASS_CONFIDENTIAL; 325 classInt = ICAL_CLASS_CONFIDENTIAL;
329 break; 326 break;
330 case Incidence::SecrecyPrivate: 327 case Incidence::SecrecyPrivate:
331 classInt =ICAL_CLASS_PRIVATE ; 328 classInt =ICAL_CLASS_PRIVATE ;
332 default: 329 default:
333 classInt =ICAL_CLASS_PRIVATE ; 330 classInt =ICAL_CLASS_PRIVATE ;
334 break; 331 break;
335 } 332 }
336 icalcomponent_add_property(parent,icalproperty_new_class(classInt)); 333 icalcomponent_add_property(parent,icalproperty_new_class(classInt));
337 334
338 // priority 335 // priority
339 icalcomponent_add_property(parent,icalproperty_new_priority( 336 icalcomponent_add_property(parent,icalproperty_new_priority(
340 incidence->priority())); 337 incidence->priority()));
341 338
342 // categories 339 // categories
343 QStringList categories = incidence->categories(); 340 QStringList categories = incidence->categories();
344 QStringList::Iterator it; 341 QStringList::Iterator it;
345 for(it = categories.begin(); it != categories.end(); ++it ) { 342 for(it = categories.begin(); it != categories.end(); ++it ) {
346 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8())); 343 icalcomponent_add_property(parent,icalproperty_new_categories((*it).utf8()));
347 } 344 }
348// TODO: Ensure correct concatenation of categories properties. 345// TODO: Ensure correct concatenation of categories properties.
349 346
350/* 347/*
351 // categories 348 // categories
352 tmpStrList = incidence->getCategories(); 349 tmpStrList = incidence->getCategories();
353 tmpStr = ""; 350 tmpStr = "";
354 QString catStr; 351 QString catStr;
355 for ( QStringList::Iterator it = tmpStrList.begin(); 352 for ( QStringList::Iterator it = tmpStrList.begin();
356 it != tmpStrList.end(); 353 it != tmpStrList.end();
357 ++it ) { 354 ++it ) {
358 catStr = *it; 355 catStr = *it;
359 if (catStr[0] == ' ') 356 if (catStr[0] == ' ')
360 tmpStr += catStr.mid(1); 357 tmpStr += catStr.mid(1);
361 else 358 else
362 tmpStr += catStr; 359 tmpStr += catStr;
363 // this must be a ';' character as the vCalendar specification requires! 360 // this must be a ';' character as the vCalendar specification requires!
364 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 361 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
365 // read in. 362 // read in.
366 tmpStr += ";"; 363 tmpStr += ";";
367 } 364 }
368 if (!tmpStr.isEmpty()) { 365 if (!tmpStr.isEmpty()) {
369 tmpStr.truncate(tmpStr.length()-1); 366 tmpStr.truncate(tmpStr.length()-1);
370 icalcomponent_add_property(parent,icalproperty_new_categories( 367 icalcomponent_add_property(parent,icalproperty_new_categories(
371 writeText(incidence->getCategories().join(";")))); 368 writeText(incidence->getCategories().join(";"))));
372 } 369 }
373*/ 370*/
374 371
375 // related event 372 // related event
376 if (incidence->relatedTo()) { 373 if (incidence->relatedTo()) {
377 icalcomponent_add_property(parent,icalproperty_new_relatedto( 374 icalcomponent_add_property(parent,icalproperty_new_relatedto(
378 incidence->relatedTo()->uid().utf8())); 375 incidence->relatedTo()->uid().utf8()));
379 } 376 }
380 377
381 // recurrence rule stuff 378 // recurrence rule stuff
382 Recurrence *recur = incidence->recurrence(); 379 Recurrence *recur = incidence->recurrence();
383 if (recur->doesRecur()) { 380 if (recur->doesRecur()) {
384 381
385 icalcomponent_add_property(parent,writeRecurrenceRule(recur)); 382 icalcomponent_add_property(parent,writeRecurrenceRule(recur));
386 } 383 }
387 384
388 // recurrence excpetion dates 385 // recurrence excpetion dates
389 DateList dateList = incidence->exDates(); 386 DateList dateList = incidence->exDates();
390 DateList::ConstIterator exIt; 387 DateList::ConstIterator exIt;
391 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) { 388 for(exIt = dateList.begin(); exIt != dateList.end(); ++exIt) {
392 icalcomponent_add_property(parent,icalproperty_new_exdate( 389 icalcomponent_add_property(parent,icalproperty_new_exdate(
393 writeICalDate(*exIt))); 390 writeICalDate(*exIt)));
394 } 391 }
395 392
396 // attachments 393 // attachments
397 QPtrList<Attachment> attachments = incidence->attachments(); 394 QPtrList<Attachment> attachments = incidence->attachments();
398 for (Attachment *at = attachments.first(); at; at = attachments.next()) 395 for (Attachment *at = attachments.first(); at; at = attachments.next())
399 icalcomponent_add_property(parent,writeAttachment(at)); 396 icalcomponent_add_property(parent,writeAttachment(at));
400 397
401 // alarms 398 // alarms
402 QPtrList<Alarm> alarms = incidence->alarms(); 399 QPtrList<Alarm> alarms = incidence->alarms();
403 Alarm* alarm; 400 Alarm* alarm;
404 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 401 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
405 if (alarm->enabled()) { 402 if (alarm->enabled()) {
406 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl; 403 kdDebug(5800) << "Write alarm for " << incidence->summary() << endl;
407 icalcomponent_add_component(parent,writeAlarm(alarm)); 404 icalcomponent_add_component(parent,writeAlarm(alarm));
408 } 405 }
409 } 406 }
410 407
411 // duration 408 // duration
412 409
413// turned off as it always is set to PTS0 (and must not occur together with DTEND 410// turned off as it always is set to PTS0 (and must not occur together with DTEND
414 411
415// if (incidence->hasDuration()) { 412// if (incidence->hasDuration()) {
416// icaldurationtype duration; 413// icaldurationtype duration;
417// duration = writeICalDuration(incidence->duration()); 414// duration = writeICalDuration(incidence->duration());
418// icalcomponent_add_property(parent,icalproperty_new_duration(duration)); 415// icalcomponent_add_property(parent,icalproperty_new_duration(duration));
419// } 416// }
420} 417}
421 418
422void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 419void ICalFormatImpl::writeIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
423{ 420{
424 icalcomponent_add_property(parent,icalproperty_new_dtstamp( 421 icalcomponent_add_property(parent,icalproperty_new_dtstamp(
425 writeICalDateTime(QDateTime::currentDateTime()))); 422 writeICalDateTime(QDateTime::currentDateTime())));
426 423
427 // organizer stuff 424 // organizer stuff
428 icalcomponent_add_property(parent,icalproperty_new_organizer( 425 icalcomponent_add_property(parent,icalproperty_new_organizer(
429 ("MAILTO:" + incidenceBase->organizer()).utf8())); 426 ("MAILTO:" + incidenceBase->organizer()).utf8()));
430 427
431 // attendees 428 // attendees
432 if (incidenceBase->attendeeCount() != 0) { 429 if (incidenceBase->attendeeCount() != 0) {
433 QPtrList<Attendee> al = incidenceBase->attendees(); 430 QPtrList<Attendee> al = incidenceBase->attendees();
434 QPtrListIterator<Attendee> ai(al); 431 QPtrListIterator<Attendee> ai(al);
435 for (; ai.current(); ++ai) { 432 for (; ai.current(); ++ai) {
436 icalcomponent_add_property(parent,writeAttendee(ai.current())); 433 icalcomponent_add_property(parent,writeAttendee(ai.current()));
437 } 434 }
438 } 435 }
439 436
440 // custom properties 437 // custom properties
441 writeCustomProperties(parent, incidenceBase); 438 writeCustomProperties(parent, incidenceBase);
442} 439}
443 440
444void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties) 441void ICalFormatImpl::writeCustomProperties(icalcomponent *parent,CustomProperties *properties)
445{ 442{
446 QMap<QCString, QString> custom = properties->customProperties(); 443 QMap<QCString, QString> custom = properties->customProperties();
447 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 444 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
448 icalproperty *p = icalproperty_new_x(c.data().utf8()); 445 icalproperty *p = icalproperty_new_x(c.data().utf8());
449 icalproperty_set_x_name(p,c.key()); 446 icalproperty_set_x_name(p,c.key());
450 icalcomponent_add_property(parent,p); 447 icalcomponent_add_property(parent,p);
451 } 448 }
452} 449}
453 450
454icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee) 451icalproperty *ICalFormatImpl::writeAttendee(Attendee *attendee)
455{ 452{
456 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8()); 453 icalproperty *p = icalproperty_new_attendee("mailto:" + attendee->email().utf8());
457 454
458 if (!attendee->name().isEmpty()) { 455 if (!attendee->name().isEmpty()) {
459 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8())); 456 icalproperty_add_parameter(p,icalparameter_new_cn(attendee->name().utf8()));
460 } 457 }
461 458
462 459
463 icalproperty_add_parameter(p,icalparameter_new_rsvp( 460 icalproperty_add_parameter(p,icalparameter_new_rsvp(
464 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE )); 461 attendee->RSVP() ? ICAL_RSVP_TRUE : ICAL_RSVP_FALSE ));
465 462
466 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION; 463 icalparameter_partstat status = ICAL_PARTSTAT_NEEDSACTION;
467 switch (attendee->status()) { 464 switch (attendee->status()) {
468 default: 465 default:
469 case Attendee::NeedsAction: 466 case Attendee::NeedsAction:
470 status = ICAL_PARTSTAT_NEEDSACTION; 467 status = ICAL_PARTSTAT_NEEDSACTION;
471 break; 468 break;
472 case Attendee::Accepted: 469 case Attendee::Accepted:
473 status = ICAL_PARTSTAT_ACCEPTED; 470 status = ICAL_PARTSTAT_ACCEPTED;
474 break; 471 break;
475 case Attendee::Declined: 472 case Attendee::Declined:
476 status = ICAL_PARTSTAT_DECLINED; 473 status = ICAL_PARTSTAT_DECLINED;
477 break; 474 break;
478 case Attendee::Tentative: 475 case Attendee::Tentative:
479 status = ICAL_PARTSTAT_TENTATIVE; 476 status = ICAL_PARTSTAT_TENTATIVE;
480 break; 477 break;
481 case Attendee::Delegated: 478 case Attendee::Delegated:
482 status = ICAL_PARTSTAT_DELEGATED; 479 status = ICAL_PARTSTAT_DELEGATED;
483 break; 480 break;
484 case Attendee::Completed: 481 case Attendee::Completed:
485 status = ICAL_PARTSTAT_COMPLETED; 482 status = ICAL_PARTSTAT_COMPLETED;
486 break; 483 break;
487 case Attendee::InProcess: 484 case Attendee::InProcess:
488 status = ICAL_PARTSTAT_INPROCESS; 485 status = ICAL_PARTSTAT_INPROCESS;
489 break; 486 break;
490 } 487 }
491 icalproperty_add_parameter(p,icalparameter_new_partstat(status)); 488 icalproperty_add_parameter(p,icalparameter_new_partstat(status));
492 489
493 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT; 490 icalparameter_role role = ICAL_ROLE_REQPARTICIPANT;
494 switch (attendee->role()) { 491 switch (attendee->role()) {
495 case Attendee::Chair: 492 case Attendee::Chair:
496 role = ICAL_ROLE_CHAIR; 493 role = ICAL_ROLE_CHAIR;
497 break; 494 break;
498 default: 495 default:
499 case Attendee::ReqParticipant: 496 case Attendee::ReqParticipant:
500 role = ICAL_ROLE_REQPARTICIPANT; 497 role = ICAL_ROLE_REQPARTICIPANT;
501 break; 498 break;
502 case Attendee::OptParticipant: 499 case Attendee::OptParticipant:
503 role = ICAL_ROLE_OPTPARTICIPANT; 500 role = ICAL_ROLE_OPTPARTICIPANT;
504 break; 501 break;
505 case Attendee::NonParticipant: 502 case Attendee::NonParticipant:
506 role = ICAL_ROLE_NONPARTICIPANT; 503 role = ICAL_ROLE_NONPARTICIPANT;
507 break; 504 break;
508 } 505 }
509 icalproperty_add_parameter(p,icalparameter_new_role(role)); 506 icalproperty_add_parameter(p,icalparameter_new_role(role));
510 507
511 if (!attendee->uid().isEmpty()) { 508 if (!attendee->uid().isEmpty()) {
512 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8()); 509 icalparameter* icalparameter_uid = icalparameter_new_x(attendee->uid().utf8());
513 icalparameter_set_xname(icalparameter_uid,"X-UID"); 510 icalparameter_set_xname(icalparameter_uid,"X-UID");
514 icalproperty_add_parameter(p,icalparameter_uid); 511 icalproperty_add_parameter(p,icalparameter_uid);
515 } 512 }
516 513
517 return p; 514 return p;
518} 515}
519 516
520icalproperty *ICalFormatImpl::writeAttachment(Attachment *att) 517icalproperty *ICalFormatImpl::writeAttachment(Attachment *att)
521{ 518{
522#if 0 519#if 0
523 icalattachtype* attach = icalattachtype_new(); 520 icalattachtype* attach = icalattachtype_new();
524 if (att->isURI()) 521 if (att->isURI())
525 icalattachtype_set_url(attach, att->uri().utf8().data()); 522 icalattachtype_set_url(attach, att->uri().utf8().data());
526 else 523 else
527 icalattachtype_set_base64(attach, att->data(), 0); 524 icalattachtype_set_base64(attach, att->data(), 0);
528#endif 525#endif
529 icalattach *attach; 526 icalattach *attach;
530 if (att->isURI()) 527 if (att->isURI())
531 attach = icalattach_new_from_url( att->uri().utf8().data()); 528 attach = icalattach_new_from_url( att->uri().utf8().data());
532 else 529 else
533 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0); 530 attach = icalattach_new_from_data ( (unsigned char *)att->data(), 0, 0);
534 icalproperty *p = icalproperty_new_attach(attach); 531 icalproperty *p = icalproperty_new_attach(attach);
535 if (!att->mimeType().isEmpty()) 532 if (!att->mimeType().isEmpty())
536 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data())); 533 icalproperty_add_parameter(p,icalparameter_new_fmttype(att->mimeType().utf8().data()));
537 534
538 if (att->isBinary()) { 535 if (att->isBinary()) {
539 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY)); 536 icalproperty_add_parameter(p,icalparameter_new_value(ICAL_VALUE_BINARY));
540 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64)); 537 icalproperty_add_parameter(p,icalparameter_new_encoding(ICAL_ENCODING_BASE64));
541 } 538 }
542 return p; 539 return p;
543} 540}
544 541
545icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur) 542icalproperty *ICalFormatImpl::writeRecurrenceRule(Recurrence *recur)
546{ 543{
547// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl; 544// kdDebug(5800) << "ICalFormatImpl::writeRecurrenceRule()" << endl;
548 545
549 icalrecurrencetype r; 546 icalrecurrencetype r;
550 547
551 icalrecurrencetype_clear(&r); 548 icalrecurrencetype_clear(&r);
552 549
553 int index = 0; 550 int index = 0;
554 int index2 = 0; 551 int index2 = 0;
555 552
556 QPtrList<Recurrence::rMonthPos> tmpPositions; 553 QPtrList<Recurrence::rMonthPos> tmpPositions;
557 QPtrList<int> tmpDays; 554 QPtrList<int> tmpDays;
558 int *tmpDay; 555 int *tmpDay;
559 Recurrence::rMonthPos *tmpPos; 556 Recurrence::rMonthPos *tmpPos;
560 bool datetime = false; 557 bool datetime = false;
561 int day; 558 int day;
562 int i; 559 int i;
563 560
564 switch(recur->doesRecur()) { 561 switch(recur->doesRecur()) {
565 case Recurrence::rMinutely: 562 case Recurrence::rMinutely:
566 r.freq = ICAL_MINUTELY_RECURRENCE; 563 r.freq = ICAL_MINUTELY_RECURRENCE;
567 datetime = true; 564 datetime = true;
568 break; 565 break;
569 case Recurrence::rHourly: 566 case Recurrence::rHourly:
570 r.freq = ICAL_HOURLY_RECURRENCE; 567 r.freq = ICAL_HOURLY_RECURRENCE;
571 datetime = true; 568 datetime = true;
572 break; 569 break;
573 case Recurrence::rDaily: 570 case Recurrence::rDaily:
574 r.freq = ICAL_DAILY_RECURRENCE; 571 r.freq = ICAL_DAILY_RECURRENCE;
575 break; 572 break;
576 case Recurrence::rWeekly: 573 case Recurrence::rWeekly:
577 r.freq = ICAL_WEEKLY_RECURRENCE; 574 r.freq = ICAL_WEEKLY_RECURRENCE;
578 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1); 575 r.week_start = static_cast<icalrecurrencetype_weekday>(recur->weekStart()%7 + 1);
579 for (i = 0; i < 7; i++) { 576 for (i = 0; i < 7; i++) {
580 if (recur->days().testBit(i)) { 577 if (recur->days().testBit(i)) {
581 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 578 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
582 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day); 579 r.by_day[index++] = icalrecurrencetype_day_day_of_week(day);
583 } 580 }
584 } 581 }
585// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 582// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
586 break; 583 break;
587 case Recurrence::rMonthlyPos: 584 case Recurrence::rMonthlyPos:
588 r.freq = ICAL_MONTHLY_RECURRENCE; 585 r.freq = ICAL_MONTHLY_RECURRENCE;
589 586
590 tmpPositions = recur->monthPositions(); 587 tmpPositions = recur->monthPositions();
591 for (tmpPos = tmpPositions.first(); 588 for (tmpPos = tmpPositions.first();
592 tmpPos; 589 tmpPos;
593 tmpPos = tmpPositions.next()) { 590 tmpPos = tmpPositions.next()) {
594 for (i = 0; i < 7; i++) { 591 for (i = 0; i < 7; i++) {
595 if (tmpPos->rDays.testBit(i)) { 592 if (tmpPos->rDays.testBit(i)) {
596 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 593 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
597 day += tmpPos->rPos*8; 594 day += tmpPos->rPos*8;
598 if (tmpPos->negative) day = -day; 595 if (tmpPos->negative) day = -day;
599 r.by_day[index++] = day; 596 r.by_day[index++] = day;
600 } 597 }
601 } 598 }
602 } 599 }
603// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 600// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
604 break; 601 break;
605 case Recurrence::rMonthlyDay: 602 case Recurrence::rMonthlyDay:
606 r.freq = ICAL_MONTHLY_RECURRENCE; 603 r.freq = ICAL_MONTHLY_RECURRENCE;
607 604
608 tmpDays = recur->monthDays(); 605 tmpDays = recur->monthDays();
609 for (tmpDay = tmpDays.first(); 606 for (tmpDay = tmpDays.first();
610 tmpDay; 607 tmpDay;
611 tmpDay = tmpDays.next()) { 608 tmpDay = tmpDays.next()) {
612 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay); 609 r.by_month_day[index++] = icalrecurrencetype_day_position(*tmpDay*8);//*tmpDay);
613 } 610 }
614// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 611// r.by_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
615 break; 612 break;
616 case Recurrence::rYearlyMonth: 613 case Recurrence::rYearlyMonth:
617 case Recurrence::rYearlyPos: 614 case Recurrence::rYearlyPos:
618 r.freq = ICAL_YEARLY_RECURRENCE; 615 r.freq = ICAL_YEARLY_RECURRENCE;
619 616
620 tmpDays = recur->yearNums(); 617 tmpDays = recur->yearNums();
621 for (tmpDay = tmpDays.first(); 618 for (tmpDay = tmpDays.first();
622 tmpDay; 619 tmpDay;
623 tmpDay = tmpDays.next()) { 620 tmpDay = tmpDays.next()) {
624 r.by_month[index++] = *tmpDay; 621 r.by_month[index++] = *tmpDay;
625 } 622 }
626// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX; 623// r.by_set_pos[index] = ICAL_RECURRENCE_ARRAY_MAX;
627 if (recur->doesRecur() == Recurrence::rYearlyPos) { 624 if (recur->doesRecur() == Recurrence::rYearlyPos) {
628 tmpPositions = recur->monthPositions(); 625 tmpPositions = recur->monthPositions();
629 for (tmpPos = tmpPositions.first(); 626 for (tmpPos = tmpPositions.first();
630 tmpPos; 627 tmpPos;
631 tmpPos = tmpPositions.next()) { 628 tmpPos = tmpPositions.next()) {
632 for (i = 0; i < 7; i++) { 629 for (i = 0; i < 7; i++) {
633 if (tmpPos->rDays.testBit(i)) { 630 if (tmpPos->rDays.testBit(i)) {
634 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1 631 day = (i + 1)%7 + 1; // convert from Monday=0 to Sunday=1
635 day += tmpPos->rPos*8; 632 day += tmpPos->rPos*8;
636 if (tmpPos->negative) day = -day; 633 if (tmpPos->negative) day = -day;
637 r.by_day[index2++] = day; 634 r.by_day[index2++] = day;
638 } 635 }
639 } 636 }
640 } 637 }
641// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX; 638// r.by_day[index2] = ICAL_RECURRENCE_ARRAY_MAX;
642 } 639 }
643 break; 640 break;
644 case Recurrence::rYearlyDay: 641 case Recurrence::rYearlyDay:
645 r.freq = ICAL_YEARLY_RECURRENCE; 642 r.freq = ICAL_YEARLY_RECURRENCE;
646 643
647 tmpDays = recur->yearNums(); 644 tmpDays = recur->yearNums();
648 for (tmpDay = tmpDays.first(); 645 for (tmpDay = tmpDays.first();
649 tmpDay; 646 tmpDay;
650 tmpDay = tmpDays.next()) { 647 tmpDay = tmpDays.next()) {
651 r.by_year_day[index++] = *tmpDay; 648 r.by_year_day[index++] = *tmpDay;
652 } 649 }
653// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX; 650// r.by_year_day[index] = ICAL_RECURRENCE_ARRAY_MAX;
654 break; 651 break;
655 default: 652 default:
656 r.freq = ICAL_NO_RECURRENCE; 653 r.freq = ICAL_NO_RECURRENCE;
657 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl; 654 kdDebug(5800) << "ICalFormatImpl::writeRecurrence(): no recurrence" << endl;
658 break; 655 break;
659 } 656 }
660 657
661 r.interval = recur->frequency(); 658 r.interval = recur->frequency();
662 659
663 if (recur->duration() > 0) { 660 if (recur->duration() > 0) {
664 r.count = recur->duration(); 661 r.count = recur->duration();
665 } else if (recur->duration() == -1) { 662 } else if (recur->duration() == -1) {
666 r.count = 0; 663 r.count = 0;
667 } else { 664 } else {
668 if (datetime) 665 if (datetime)
669 r.until = writeICalDateTime(recur->endDateTime()); 666 r.until = writeICalDateTime(recur->endDateTime());
670 else 667 else
671 r.until = writeICalDate(recur->endDate()); 668 r.until = writeICalDate(recur->endDate());
672 } 669 }
673 670
674// Debug output 671// Debug output
675#if 0 672#if 0
676 const char *str = icalrecurrencetype_as_string(&r); 673 const char *str = icalrecurrencetype_as_string(&r);
677 if (str) { 674 if (str) {
678 kdDebug(5800) << " String: " << str << endl; 675 kdDebug(5800) << " String: " << str << endl;
679 } else { 676 } else {
680 kdDebug(5800) << " No String" << endl; 677 kdDebug(5800) << " No String" << endl;
681 } 678 }
682#endif 679#endif
683 680
684 return icalproperty_new_rrule(r); 681 return icalproperty_new_rrule(r);
685} 682}
686 683
687icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm) 684icalcomponent *ICalFormatImpl::writeAlarm(Alarm *alarm)
688{ 685{
689 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT); 686 icalcomponent *a = icalcomponent_new(ICAL_VALARM_COMPONENT);
690 687
691 icalproperty_action action; 688 icalproperty_action action;
692 icalattach *attach = 0; 689 icalattach *attach = 0;
693 690
694 switch (alarm->type()) { 691 switch (alarm->type()) {
695 case Alarm::Procedure: 692 case Alarm::Procedure:
696 action = ICAL_ACTION_PROCEDURE; 693 action = ICAL_ACTION_PROCEDURE;
697 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() ); 694 attach = icalattach_new_from_url( QFile::encodeName(alarm->programFile()).data() );
698 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 695 icalcomponent_add_property(a,icalproperty_new_attach(attach));
699 if (!alarm->programArguments().isEmpty()) { 696 if (!alarm->programArguments().isEmpty()) {
700 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8())); 697 icalcomponent_add_property(a,icalproperty_new_description(alarm->programArguments().utf8()));
701 } 698 }
702 break; 699 break;
703 case Alarm::Audio: 700 case Alarm::Audio:
704 action = ICAL_ACTION_AUDIO; 701 action = ICAL_ACTION_AUDIO;
705 if (!alarm->audioFile().isEmpty()) { 702 if (!alarm->audioFile().isEmpty()) {
706 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data()); 703 attach = icalattach_new_from_url(QFile::encodeName( alarm->audioFile() ).data());
707 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 704 icalcomponent_add_property(a,icalproperty_new_attach(attach));
708 } 705 }
709 break; 706 break;
710 case Alarm::Email: { 707 case Alarm::Email: {
711 action = ICAL_ACTION_EMAIL; 708 action = ICAL_ACTION_EMAIL;
712 QValueList<Person> addresses = alarm->mailAddresses(); 709 QValueList<Person> addresses = alarm->mailAddresses();
713 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) { 710 for (QValueList<Person>::Iterator ad = addresses.begin(); ad != addresses.end(); ++ad) {
714 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8()); 711 icalproperty *p = icalproperty_new_attendee("MAILTO:" + (*ad).email().utf8());
715 if (!(*ad).name().isEmpty()) { 712 if (!(*ad).name().isEmpty()) {
716 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8())); 713 icalproperty_add_parameter(p,icalparameter_new_cn((*ad).name().utf8()));
717 } 714 }
718 icalcomponent_add_property(a,p); 715 icalcomponent_add_property(a,p);
719 } 716 }
720 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8())); 717 icalcomponent_add_property(a,icalproperty_new_summary(alarm->mailSubject().utf8()));
721 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 718 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
722 QStringList attachments = alarm->mailAttachments(); 719 QStringList attachments = alarm->mailAttachments();
723 if (attachments.count() > 0) { 720 if (attachments.count() > 0) {
724 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) { 721 for (QStringList::Iterator at = attachments.begin(); at != attachments.end(); ++at) {
725 attach = icalattach_new_from_url(QFile::encodeName( *at ).data()); 722 attach = icalattach_new_from_url(QFile::encodeName( *at ).data());
726 icalcomponent_add_property(a,icalproperty_new_attach(attach)); 723 icalcomponent_add_property(a,icalproperty_new_attach(attach));
727 } 724 }
728 } 725 }
729 break; 726 break;
730 } 727 }
731 case Alarm::Display: 728 case Alarm::Display:
732 action = ICAL_ACTION_DISPLAY; 729 action = ICAL_ACTION_DISPLAY;
733 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8())); 730 icalcomponent_add_property(a,icalproperty_new_description(alarm->text().utf8()));
734 break; 731 break;
735 case Alarm::Invalid: 732 case Alarm::Invalid:
736 default: 733 default:
737 kdDebug(5800) << "Unknown type of alarm" << endl; 734 kdDebug(5800) << "Unknown type of alarm" << endl;
738 action = ICAL_ACTION_NONE; 735 action = ICAL_ACTION_NONE;
739 break; 736 break;
740 } 737 }
741 icalcomponent_add_property(a,icalproperty_new_action(action)); 738 icalcomponent_add_property(a,icalproperty_new_action(action));
742 739
743 // Trigger time 740 // Trigger time
744 icaltriggertype trigger; 741 icaltriggertype trigger;
745 if ( alarm->hasTime() ) { 742 if ( alarm->hasTime() ) {
746 trigger.time = writeICalDateTime(alarm->time()); 743 trigger.time = writeICalDateTime(alarm->time());
747 trigger.duration = icaldurationtype_null_duration(); 744 trigger.duration = icaldurationtype_null_duration();
748 } else { 745 } else {
749 trigger.time = icaltime_null_time(); 746 trigger.time = icaltime_null_time();
750 Duration offset; 747 Duration offset;
751 if ( alarm->hasStartOffset() ) 748 if ( alarm->hasStartOffset() )
752 offset = alarm->startOffset(); 749 offset = alarm->startOffset();
753 else 750 else
754 offset = alarm->endOffset(); 751 offset = alarm->endOffset();
755 trigger.duration = icaldurationtype_from_int( offset.asSeconds() ); 752 trigger.duration = icaldurationtype_from_int( offset.asSeconds() );
756 } 753 }
757 icalproperty *p = icalproperty_new_trigger(trigger); 754 icalproperty *p = icalproperty_new_trigger(trigger);
758 if ( alarm->hasEndOffset() ) 755 if ( alarm->hasEndOffset() )
759 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END)); 756 icalproperty_add_parameter(p,icalparameter_new_related(ICAL_RELATED_END));
760 icalcomponent_add_property(a,p); 757 icalcomponent_add_property(a,p);
761 758
762 // Repeat count and duration 759 // Repeat count and duration
763 if (alarm->repeatCount()) { 760 if (alarm->repeatCount()) {
764 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount())); 761 icalcomponent_add_property(a,icalproperty_new_repeat(alarm->repeatCount()));
765 icalcomponent_add_property(a,icalproperty_new_duration( 762 icalcomponent_add_property(a,icalproperty_new_duration(
766 icaldurationtype_from_int(alarm->snoozeTime()*60))); 763 icaldurationtype_from_int(alarm->snoozeTime()*60)));
767 } 764 }
768 765
769 // Custom properties 766 // Custom properties
770 QMap<QCString, QString> custom = alarm->customProperties(); 767 QMap<QCString, QString> custom = alarm->customProperties();
771 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) { 768 for (QMap<QCString, QString>::Iterator c = custom.begin(); c != custom.end(); ++c) {
772 icalproperty *p = icalproperty_new_x(c.data().utf8()); 769 icalproperty *p = icalproperty_new_x(c.data().utf8());
773 icalproperty_set_x_name(p,c.key()); 770 icalproperty_set_x_name(p,c.key());
774 icalcomponent_add_property(a,p); 771 icalcomponent_add_property(a,p);
775 } 772 }
776 773
777 return a; 774 return a;
778} 775}
779 776
780Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo) 777Todo *ICalFormatImpl::readTodo(icalcomponent *vtodo)
781{ 778{
782 Todo *todo = new Todo; 779 Todo *todo = new Todo;
783 780
784 readIncidence(vtodo,todo); 781 readIncidence(vtodo,todo);
785 782
786 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY); 783 icalproperty *p = icalcomponent_get_first_property(vtodo,ICAL_ANY_PROPERTY);
787 784
788// int intvalue; 785// int intvalue;
789 icaltimetype icaltime; 786 icaltimetype icaltime;
790 787
791 QStringList categories; 788 QStringList categories;
792 789
793 while (p) { 790 while (p) {
794 icalproperty_kind kind = icalproperty_isa(p); 791 icalproperty_kind kind = icalproperty_isa(p);
795 switch (kind) { 792 switch (kind) {
796 793
797 case ICAL_DUE_PROPERTY: // due date 794 case ICAL_DUE_PROPERTY: // due date
798 icaltime = icalproperty_get_due(p); 795 icaltime = icalproperty_get_due(p);
799 if (icaltime.is_date) { 796 if (icaltime.is_date) {
800 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 797 todo->setDtDue(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
801 todo->setFloats(true); 798 todo->setFloats(true);
802 799
803 } else { 800 } else {
804 todo->setDtDue(readICalDateTime(icaltime)); 801 todo->setDtDue(readICalDateTime(icaltime));
805 todo->setFloats(false); 802 todo->setFloats(false);
806 } 803 }
807 todo->setHasDueDate(true); 804 todo->setHasDueDate(true);
808 break; 805 break;
809 806
810 case ICAL_COMPLETED_PROPERTY: // completion date 807 case ICAL_COMPLETED_PROPERTY: // completion date
811 icaltime = icalproperty_get_completed(p); 808 icaltime = icalproperty_get_completed(p);
812 todo->setCompleted(readICalDateTime(icaltime)); 809 todo->setCompleted(readICalDateTime(icaltime));
813 break; 810 break;
814 811
815 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed 812 case ICAL_PERCENTCOMPLETE_PROPERTY: // Percent completed
816 todo->setPercentComplete(icalproperty_get_percentcomplete(p)); 813 todo->setPercentComplete(icalproperty_get_percentcomplete(p));
817 break; 814 break;
818 815
819 case ICAL_RELATEDTO_PROPERTY: // related todo (parent) 816 case ICAL_RELATEDTO_PROPERTY: // related todo (parent)
820 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 817 todo->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
821 mTodosRelate.append(todo); 818 mTodosRelate.append(todo);
822 break; 819 break;
823 820
824 case ICAL_DTSTART_PROPERTY: 821 case ICAL_DTSTART_PROPERTY:
825 // Flag that todo has start date. Value is read in by readIncidence(). 822 // Flag that todo has start date. Value is read in by readIncidence().
826 todo->setHasStartDate(true); 823 todo->setHasStartDate(true);
827 break; 824 break;
828 825
829 default: 826 default:
830// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind 827// kdDebug(5800) << "ICALFormat::readTodo(): Unknown property: " << kind
831// << endl; 828// << endl;
832 break; 829 break;
833 } 830 }
834 831
835 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY); 832 p = icalcomponent_get_next_property(vtodo,ICAL_ANY_PROPERTY);
836 } 833 }
837 834
838 return todo; 835 return todo;
839} 836}
840 837
841Event *ICalFormatImpl::readEvent(icalcomponent *vevent) 838Event *ICalFormatImpl::readEvent(icalcomponent *vevent)
842{ 839{
843 Event *event = new Event; 840 Event *event = new Event;
844 event->setFloats(false); 841 event->setFloats(false);
845 842
846 readIncidence(vevent,event); 843 readIncidence(vevent,event);
847 844
848 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY); 845 icalproperty *p = icalcomponent_get_first_property(vevent,ICAL_ANY_PROPERTY);
849 846
850// int intvalue; 847// int intvalue;
851 icaltimetype icaltime; 848 icaltimetype icaltime;
852 849
853 QStringList categories; 850 QStringList categories;
854 QString transparency; 851 QString transparency;
855 852
856 while (p) { 853 while (p) {
857 icalproperty_kind kind = icalproperty_isa(p); 854 icalproperty_kind kind = icalproperty_isa(p);
858 switch (kind) { 855 switch (kind) {
859 856
860 case ICAL_DTEND_PROPERTY: // start date and time 857 case ICAL_DTEND_PROPERTY: // start date and time
861 icaltime = icalproperty_get_dtend(p); 858 icaltime = icalproperty_get_dtend(p);
862 if (icaltime.is_date) { 859 if (icaltime.is_date) {
863 event->setFloats( true ); 860 event->setFloats( true );
864 // End date is non-inclusive 861 // End date is non-inclusive
865 QDate endDate = readICalDate( icaltime ).addDays( -1 ); 862 QDate endDate = readICalDate( icaltime ).addDays( -1 );
866 mCompat->fixFloatingEnd( endDate ); 863 mCompat->fixFloatingEnd( endDate );
867 if ( endDate < event->dtStart().date() ) { 864 if ( endDate < event->dtStart().date() ) {
868 endDate = event->dtStart().date(); 865 endDate = event->dtStart().date();
869 } 866 }
870 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) ); 867 event->setDtEnd( QDateTime( endDate, QTime( 0, 0, 0 ) ) );
871 } else { 868 } else {
872 event->setDtEnd(readICalDateTime(icaltime)); 869 event->setDtEnd(readICalDateTime(icaltime));
873 } 870 }
874 break; 871 break;
875 872
876// TODO: 873// TODO:
877 // at this point, there should be at least a start or end time. 874 // at this point, there should be at least a start or end time.
878 // fix up for events that take up no time but have a time associated 875 // fix up for events that take up no time but have a time associated
879#if 0 876#if 0
880 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 877 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
881 anEvent->setDtStart(anEvent->dtEnd()); 878 anEvent->setDtStart(anEvent->dtEnd());
882 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 879 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
883 anEvent->setDtEnd(anEvent->dtStart()); 880 anEvent->setDtEnd(anEvent->dtStart());
884#endif 881#endif
885 882
886// TODO: exdates 883// TODO: exdates
887#if 0 884#if 0
888 // recurrence exceptions 885 // recurrence exceptions
889 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) { 886 if ((vo = isAPropertyOf(vevent, VCExDateProp)) != 0) {
890 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo))); 887 anEvent->setExDates(s = fakeCString(vObjectUStringZValue(vo)));
891 deleteStr(s); 888 deleteStr(s);
892 } 889 }
893#endif 890#endif
894 891
895#if 0 892#if 0
896 // secrecy 893 // secrecy
897 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 894 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
898 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo))); 895 anEvent->setSecrecy(s = fakeCString(vObjectUStringZValue(vo)));
899 deleteStr(s); 896 deleteStr(s);
900 } 897 }
901 else 898 else
902 anEvent->setSecrecy("PUBLIC"); 899 anEvent->setSecrecy("PUBLIC");
903 900
904 // attachments 901 // attachments
905 tmpStrList.clear(); 902 tmpStrList.clear();
906 initPropIterator(&voi, vevent); 903 initPropIterator(&voi, vevent);
907 while (moreIteration(&voi)) { 904 while (moreIteration(&voi)) {
908 vo = nextVObject(&voi); 905 vo = nextVObject(&voi);
909 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 906 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
910 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo))); 907 tmpStrList.append(s = fakeCString(vObjectUStringZValue(vo)));
911 deleteStr(s); 908 deleteStr(s);
912 } 909 }
913 } 910 }
914 anEvent->setAttachments(tmpStrList); 911 anEvent->setAttachments(tmpStrList);
915 912
916 // resources 913 // resources
917 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 914 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
918 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 915 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
919 deleteStr(s); 916 deleteStr(s);
920 tmpStrList.clear(); 917 tmpStrList.clear();
921 index1 = 0; 918 index1 = 0;
922 index2 = 0; 919 index2 = 0;
923 QString resource; 920 QString resource;
924 while ((index2 = resources.find(';', index1)) != -1) { 921 while ((index2 = resources.find(';', index1)) != -1) {
925 resource = resources.mid(index1, (index2 - index1)); 922 resource = resources.mid(index1, (index2 - index1));
926 tmpStrList.append(resource); 923 tmpStrList.append(resource);
927 index1 = index2; 924 index1 = index2;
928 } 925 }
929 anEvent->setResources(tmpStrList); 926 anEvent->setResources(tmpStrList);
930 } 927 }
931#endif 928#endif
932 929
933 case ICAL_RELATEDTO_PROPERTY: // releated event (parent) 930 case ICAL_RELATEDTO_PROPERTY: // releated event (parent)
934 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p))); 931 event->setRelatedToUid(QString::fromUtf8(icalproperty_get_relatedto(p)));
935 mEventsRelate.append(event); 932 mEventsRelate.append(event);
936 break; 933 break;
937 934
938 case ICAL_TRANSP_PROPERTY: // Transparency 935 case ICAL_TRANSP_PROPERTY: // Transparency
939 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT ) 936 if(icalproperty_get_transp(p) == ICAL_TRANSP_TRANSPARENT )
940 event->setTransparency( Event::Transparent ); 937 event->setTransparency( Event::Transparent );
941 else 938 else
942 event->setTransparency( Event::Opaque ); 939 event->setTransparency( Event::Opaque );
943 break; 940 break;
944 941
945 default: 942 default:
946// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind 943// kdDebug(5800) << "ICALFormat::readEvent(): Unknown property: " << kind
947// << endl; 944// << endl;
948 break; 945 break;
949 } 946 }
950 947
951 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY); 948 p = icalcomponent_get_next_property(vevent,ICAL_ANY_PROPERTY);
952 } 949 }
953 950
954 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT"); 951 QString msade = event->nonKDECustomProperty("X-MICROSOFT-CDO-ALLDAYEVENT");
955 if (!msade.isNull()) { 952 if (!msade.isNull()) {
956 bool floats = (msade == QString::fromLatin1("TRUE")); 953 bool floats = (msade == QString::fromLatin1("TRUE"));
957 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl; 954 kdDebug(5800) << "ICALFormat::readEvent(): all day event: " << floats << endl;
958 event->setFloats(floats); 955 event->setFloats(floats);
959 if (floats) { 956 if (floats) {
960 QDateTime endDate = event->dtEnd(); 957 QDateTime endDate = event->dtEnd();
961 event->setDtEnd(endDate.addDays(-1)); 958 event->setDtEnd(endDate.addDays(-1));
962 } 959 }
963 } 960 }
964 961
965 // some stupid vCal exporters ignore the standard and use Description 962 // some stupid vCal exporters ignore the standard and use Description
966 // instead of Summary for the default field. Correct for this. 963 // instead of Summary for the default field. Correct for this.
967 if (event->summary().isEmpty() && 964 if (event->summary().isEmpty() &&
968 !(event->description().isEmpty())) { 965 !(event->description().isEmpty())) {
969 QString tmpStr = event->description().simplifyWhiteSpace(); 966 QString tmpStr = event->description().simplifyWhiteSpace();
970 event->setDescription(""); 967 event->setDescription("");
971 event->setSummary(tmpStr); 968 event->setSummary(tmpStr);
972 } 969 }
973 970
974 return event; 971 return event;
975} 972}
976 973
977FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy) 974FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
978{ 975{
979 FreeBusy *freebusy = new FreeBusy; 976 FreeBusy *freebusy = new FreeBusy;
980 977
981 readIncidenceBase(vfreebusy,freebusy); 978 readIncidenceBase(vfreebusy,freebusy);
982 979
983 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY); 980 icalproperty *p = icalcomponent_get_first_property(vfreebusy,ICAL_ANY_PROPERTY);
984 981
985 icaltimetype icaltime; 982 icaltimetype icaltime;
986 icalperiodtype icalperiod; 983 icalperiodtype icalperiod;
987 QDateTime period_start, period_end; 984 QDateTime period_start, period_end;
988 985
989 while (p) { 986 while (p) {
990 icalproperty_kind kind = icalproperty_isa(p); 987 icalproperty_kind kind = icalproperty_isa(p);
991 switch (kind) { 988 switch (kind) {
992 989
993 case ICAL_DTSTART_PROPERTY: // start date and time 990 case ICAL_DTSTART_PROPERTY: // start date and time
994 icaltime = icalproperty_get_dtstart(p); 991 icaltime = icalproperty_get_dtstart(p);
995 freebusy->setDtStart(readICalDateTime(icaltime)); 992 freebusy->setDtStart(readICalDateTime(icaltime));
996 break; 993 break;
997 994
998 case ICAL_DTEND_PROPERTY: // start End Date and Time 995 case ICAL_DTEND_PROPERTY: // start End Date and Time
999 icaltime = icalproperty_get_dtend(p); 996 icaltime = icalproperty_get_dtend(p);
1000 freebusy->setDtEnd(readICalDateTime(icaltime)); 997 freebusy->setDtEnd(readICalDateTime(icaltime));
1001 break; 998 break;
1002 999
1003 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times 1000 case ICAL_FREEBUSY_PROPERTY: //Any FreeBusy Times
1004 icalperiod = icalproperty_get_freebusy(p); 1001 icalperiod = icalproperty_get_freebusy(p);
1005 period_start = readICalDateTime(icalperiod.start); 1002 period_start = readICalDateTime(icalperiod.start);
1006 period_end = readICalDateTime(icalperiod.end); 1003 period_end = readICalDateTime(icalperiod.end);
1007 freebusy->addPeriod(period_start, period_end); 1004 freebusy->addPeriod(period_start, period_end);
1008 break; 1005 break;
1009 1006
1010 default: 1007 default:
1011 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1008 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1012 << endl; 1009 << endl;
1013 break; 1010 break;
1014 } 1011 }
1015 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1012 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1016 } 1013 }
1017 1014
1018 return freebusy; 1015 return freebusy;
1019} 1016}
1020 1017
1021Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1018Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1022{ 1019{
1023 Journal *journal = new Journal; 1020 Journal *journal = new Journal;
1024 1021
1025 readIncidence(vjournal,journal); 1022 readIncidence(vjournal,journal);
1026 1023
1027 return journal; 1024 return journal;
1028} 1025}
1029 1026
1030Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1027Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1031{ 1028{
1032 icalparameter *p = 0; 1029 icalparameter *p = 0;
1033 1030
1034 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1031 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1035 1032
1036 QString name; 1033 QString name;
1037 QString uid = QString::null; 1034 QString uid = QString::null;
1038 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1035 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1039 if (p) { 1036 if (p) {
1040 name = QString::fromUtf8(icalparameter_get_cn(p)); 1037 name = QString::fromUtf8(icalparameter_get_cn(p));
1041 } else { 1038 } else {
1042 } 1039 }
1043 1040
1044 bool rsvp=false; 1041 bool rsvp=false;
1045 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1042 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1046 if (p) { 1043 if (p) {
1047 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1044 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1048 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1045 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1049 } 1046 }
1050 1047
1051 Attendee::PartStat status = Attendee::NeedsAction; 1048 Attendee::PartStat status = Attendee::NeedsAction;
1052 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1049 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1053 if (p) { 1050 if (p) {
1054 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1051 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1055 switch(partStatParameter) { 1052 switch(partStatParameter) {
1056 default: 1053 default:
1057 case ICAL_PARTSTAT_NEEDSACTION: 1054 case ICAL_PARTSTAT_NEEDSACTION:
1058 status = Attendee::NeedsAction; 1055 status = Attendee::NeedsAction;
1059 break; 1056 break;
1060 case ICAL_PARTSTAT_ACCEPTED: 1057 case ICAL_PARTSTAT_ACCEPTED:
1061 status = Attendee::Accepted; 1058 status = Attendee::Accepted;
1062 break; 1059 break;
1063 case ICAL_PARTSTAT_DECLINED: 1060 case ICAL_PARTSTAT_DECLINED:
1064 status = Attendee::Declined; 1061 status = Attendee::Declined;
1065 break; 1062 break;
1066 case ICAL_PARTSTAT_TENTATIVE: 1063 case ICAL_PARTSTAT_TENTATIVE:
1067 status = Attendee::Tentative; 1064 status = Attendee::Tentative;
1068 break; 1065 break;
1069 case ICAL_PARTSTAT_DELEGATED: 1066 case ICAL_PARTSTAT_DELEGATED:
1070 status = Attendee::Delegated; 1067 status = Attendee::Delegated;
1071 break; 1068 break;
1072 case ICAL_PARTSTAT_COMPLETED: 1069 case ICAL_PARTSTAT_COMPLETED:
1073 status = Attendee::Completed; 1070 status = Attendee::Completed;
1074 break; 1071 break;
1075 case ICAL_PARTSTAT_INPROCESS: 1072 case ICAL_PARTSTAT_INPROCESS:
1076 status = Attendee::InProcess; 1073 status = Attendee::InProcess;
1077 break; 1074 break;
1078 } 1075 }
1079 } 1076 }
1080 1077
1081 Attendee::Role role = Attendee::ReqParticipant; 1078 Attendee::Role role = Attendee::ReqParticipant;
1082 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1079 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1083 if (p) { 1080 if (p) {
1084 icalparameter_role roleParameter = icalparameter_get_role(p); 1081 icalparameter_role roleParameter = icalparameter_get_role(p);
1085 switch(roleParameter) { 1082 switch(roleParameter) {
1086 case ICAL_ROLE_CHAIR: 1083 case ICAL_ROLE_CHAIR:
1087 role = Attendee::Chair; 1084 role = Attendee::Chair;
1088 break; 1085 break;
1089 default: 1086 default:
1090 case ICAL_ROLE_REQPARTICIPANT: 1087 case ICAL_ROLE_REQPARTICIPANT:
1091 role = Attendee::ReqParticipant; 1088 role = Attendee::ReqParticipant;
1092 break; 1089 break;
1093 case ICAL_ROLE_OPTPARTICIPANT: 1090 case ICAL_ROLE_OPTPARTICIPANT:
1094 role = Attendee::OptParticipant; 1091 role = Attendee::OptParticipant;
1095 break; 1092 break;
1096 case ICAL_ROLE_NONPARTICIPANT: 1093 case ICAL_ROLE_NONPARTICIPANT:
1097 role = Attendee::NonParticipant; 1094 role = Attendee::NonParticipant;
1098 break; 1095 break;
1099 } 1096 }
1100 } 1097 }
1101 1098
1102 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1099 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1103 uid = icalparameter_get_xvalue(p); 1100 uid = icalparameter_get_xvalue(p);
1104 // This should be added, but there seems to be a libical bug here. 1101 // This should be added, but there seems to be a libical bug here.
1105 /*while (p) { 1102 /*while (p) {
1106 // if (icalparameter_get_xname(p) == "X-UID") { 1103 // if (icalparameter_get_xname(p) == "X-UID") {
1107 uid = icalparameter_get_xvalue(p); 1104 uid = icalparameter_get_xvalue(p);
1108 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1105 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1109 } */ 1106 } */
1110 1107
1111 return new Attendee( name, email, rsvp, status, role, uid ); 1108 return new Attendee( name, email, rsvp, status, role, uid );
1112} 1109}
1113 1110
1114Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1111Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1115{ 1112{
1116 icalattach *a = icalproperty_get_attach(attach); 1113 icalattach *a = icalproperty_get_attach(attach);
1117 icalparameter_value v = ICAL_VALUE_NONE; 1114 icalparameter_value v = ICAL_VALUE_NONE;
1118 icalparameter_encoding e = ICAL_ENCODING_NONE; 1115 icalparameter_encoding e = ICAL_ENCODING_NONE;
1119 1116
1120 Attachment *attachment = 0; 1117 Attachment *attachment = 0;
1121 /* 1118 /*
1122 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1119 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1123 if (vp) 1120 if (vp)
1124 v = icalparameter_get_value(vp); 1121 v = icalparameter_get_value(vp);
1125 1122
1126 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1123 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1127 if (ep) 1124 if (ep)
1128 e = icalparameter_get_encoding(ep); 1125 e = icalparameter_get_encoding(ep);
1129 */ 1126 */
1130 int isurl = icalattach_get_is_url (a); 1127 int isurl = icalattach_get_is_url (a);
1131 if (isurl == 0) 1128 if (isurl == 0)
1132 attachment = new Attachment((const char*)icalattach_get_data(a)); 1129 attachment = new Attachment((const char*)icalattach_get_data(a));
1133 else { 1130 else {
1134 attachment = new Attachment(QString(icalattach_get_url(a))); 1131 attachment = new Attachment(QString(icalattach_get_url(a)));
1135 } 1132 }
1136 1133
1137 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1134 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1138 if (p) 1135 if (p)
1139 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1136 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1140 1137
1141 return attachment; 1138 return attachment;
1142} 1139}
1143#include <qtextcodec.h> 1140#include <qtextcodec.h>
1144void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1141void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1145{ 1142{
1146 readIncidenceBase(parent,incidence); 1143 readIncidenceBase(parent,incidence);
1147 1144
1148 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1145 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1149 bool readrec = false; 1146 bool readrec = false;
1150 const char *text; 1147 const char *text;
1151 int intvalue; 1148 int intvalue;
1152 icaltimetype icaltime; 1149 icaltimetype icaltime;
1153 icaldurationtype icalduration; 1150 icaldurationtype icalduration;
1154 struct icalrecurrencetype rectype; 1151 struct icalrecurrencetype rectype;
1155 QStringList categories; 1152 QStringList categories;
1156 1153
1157 while (p) { 1154 while (p) {
1158 icalproperty_kind kind = icalproperty_isa(p); 1155 icalproperty_kind kind = icalproperty_isa(p);
1159 switch (kind) { 1156 switch (kind) {
1160 1157
1161 case ICAL_CREATED_PROPERTY: 1158 case ICAL_CREATED_PROPERTY:
1162 icaltime = icalproperty_get_created(p); 1159 icaltime = icalproperty_get_created(p);
1163 incidence->setCreated(readICalDateTime(icaltime)); 1160 incidence->setCreated(readICalDateTime(icaltime));
1164 break; 1161 break;
1165 1162
1166 case ICAL_SEQUENCE_PROPERTY: // sequence 1163 case ICAL_SEQUENCE_PROPERTY: // sequence
1167 intvalue = icalproperty_get_sequence(p); 1164 intvalue = icalproperty_get_sequence(p);
1168 incidence->setRevision(intvalue); 1165 incidence->setRevision(intvalue);
1169 break; 1166 break;
1170 1167
1171 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1168 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1172 icaltime = icalproperty_get_lastmodified(p); 1169 icaltime = icalproperty_get_lastmodified(p);
1173 incidence->setLastModified(readICalDateTime(icaltime)); 1170 incidence->setLastModified(readICalDateTime(icaltime));
1174 break; 1171 break;
1175 1172
1176 case ICAL_DTSTART_PROPERTY: // start date and time 1173 case ICAL_DTSTART_PROPERTY: // start date and time
1177 icaltime = icalproperty_get_dtstart(p); 1174 icaltime = icalproperty_get_dtstart(p);
1178 if (icaltime.is_date) { 1175 if (icaltime.is_date) {
1179 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1176 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1180 incidence->setFloats(true); 1177 incidence->setFloats(true);
1181 } else { 1178 } else {
1182 incidence->setDtStart(readICalDateTime(icaltime)); 1179 incidence->setDtStart(readICalDateTime(icaltime));
1183 } 1180 }
1184 break; 1181 break;
1185 1182
1186 case ICAL_DURATION_PROPERTY: // start date and time 1183 case ICAL_DURATION_PROPERTY: // start date and time
1187 icalduration = icalproperty_get_duration(p); 1184 icalduration = icalproperty_get_duration(p);
1188 incidence->setDuration(readICalDuration(icalduration)); 1185 incidence->setDuration(readICalDuration(icalduration));
1189 break; 1186 break;
1190 1187
1191 case ICAL_DESCRIPTION_PROPERTY: // description 1188 case ICAL_DESCRIPTION_PROPERTY: // description
1192 text = icalproperty_get_description(p); 1189 text = icalproperty_get_description(p);
1193 incidence->setDescription(QString::fromUtf8(text)); 1190 incidence->setDescription(QString::fromUtf8(text));
1194 break; 1191 break;
1195 1192
1196 case ICAL_SUMMARY_PROPERTY: // summary 1193 case ICAL_SUMMARY_PROPERTY: // summary
1197 { 1194 {
1198 text = icalproperty_get_summary(p); 1195 text = icalproperty_get_summary(p);
1199 incidence->setSummary(QString::fromUtf8(text)); 1196 incidence->setSummary(QString::fromUtf8(text));
1200 } 1197 }
1201 break; 1198 break;
1202 case ICAL_STATUS_PROPERTY: // summary 1199 case ICAL_STATUS_PROPERTY: // summary
1203 { 1200 {
1204 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1201 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1205 incidence->setCancelled( true ); 1202 incidence->setCancelled( true );
1206 } 1203 }
1207 break; 1204 break;
1208 1205
1209 case ICAL_LOCATION_PROPERTY: // location 1206 case ICAL_LOCATION_PROPERTY: // location
1210 text = icalproperty_get_location(p); 1207 text = icalproperty_get_location(p);
1211 incidence->setLocation(QString::fromUtf8(text)); 1208 incidence->setLocation(QString::fromUtf8(text));
1212 break; 1209 break;
1213 1210
1214#if 0 1211#if 0
1215 // status 1212 // status
1216 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1213 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1217 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1214 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1218 deleteStr(s); 1215 deleteStr(s);
1219 } 1216 }
1220 else 1217 else
1221 incidence->setStatus("NEEDS ACTION"); 1218 incidence->setStatus("NEEDS ACTION");
1222#endif 1219#endif
1223 1220
1224 case ICAL_PRIORITY_PROPERTY: // priority 1221 case ICAL_PRIORITY_PROPERTY: // priority
1225 intvalue = icalproperty_get_priority(p); 1222 intvalue = icalproperty_get_priority(p);
1226 incidence->setPriority(intvalue); 1223 incidence->setPriority(intvalue);
1227 break; 1224 break;
1228 1225
1229 case ICAL_CATEGORIES_PROPERTY: // categories 1226 case ICAL_CATEGORIES_PROPERTY: // categories
1230 text = icalproperty_get_categories(p); 1227 text = icalproperty_get_categories(p);
1231 categories.append(QString::fromUtf8(text)); 1228 categories.append(QString::fromUtf8(text));
1232 break; 1229 break;
1233 //******************************************* 1230 //*******************************************
1234 case ICAL_RRULE_PROPERTY: 1231 case ICAL_RRULE_PROPERTY:
1235 // we do need (maybe )start datetime of incidence for recurrence 1232 // we do need (maybe )start datetime of incidence for recurrence
1236 // such that we can read recurrence only after we read incidence completely 1233 // such that we can read recurrence only after we read incidence completely
1237 readrec = true; 1234 readrec = true;
1238 rectype = icalproperty_get_rrule(p); 1235 rectype = icalproperty_get_rrule(p);
1239 break; 1236 break;
1240 1237
1241 case ICAL_EXDATE_PROPERTY: 1238 case ICAL_EXDATE_PROPERTY:
1242 icaltime = icalproperty_get_exdate(p); 1239 icaltime = icalproperty_get_exdate(p);
1243 incidence->addExDate(readICalDate(icaltime)); 1240 incidence->addExDate(readICalDate(icaltime));
1244 break; 1241 break;
1245 1242
1246 case ICAL_CLASS_PROPERTY: { 1243 case ICAL_CLASS_PROPERTY: {
1247 int inttext = icalproperty_get_class(p); 1244 int inttext = icalproperty_get_class(p);
1248 if (inttext == ICAL_CLASS_PUBLIC ) { 1245 if (inttext == ICAL_CLASS_PUBLIC ) {
1249 incidence->setSecrecy(Incidence::SecrecyPublic); 1246 incidence->setSecrecy(Incidence::SecrecyPublic);
1250 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1247 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1251 incidence->setSecrecy(Incidence::SecrecyConfidential); 1248 incidence->setSecrecy(Incidence::SecrecyConfidential);
1252 } else { 1249 } else {
1253 incidence->setSecrecy(Incidence::SecrecyPrivate); 1250 incidence->setSecrecy(Incidence::SecrecyPrivate);
1254 } 1251 }
1255 } 1252 }
1256 break; 1253 break;
1257 1254
1258 case ICAL_ATTACH_PROPERTY: // attachments 1255 case ICAL_ATTACH_PROPERTY: // attachments
1259 incidence->addAttachment(readAttachment(p)); 1256 incidence->addAttachment(readAttachment(p));
1260 break; 1257 break;
1261 1258
1262 default: 1259 default:
1263// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1260// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1264// << endl; 1261// << endl;
1265 break; 1262 break;
1266 } 1263 }
1267 1264
1268 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1265 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1269 } 1266 }
1270 if ( readrec ) { 1267 if ( readrec ) {
1271 readRecurrenceRule(rectype,incidence); 1268 readRecurrenceRule(rectype,incidence);
1272 } 1269 }
1273 // kpilot stuff 1270 // kpilot stuff
1274// TODO: move this application-specific code to kpilot 1271// TODO: move this application-specific code to kpilot
1275 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1272 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1276 if (!kp.isNull()) { 1273 if (!kp.isNull()) {
1277 incidence->setPilotId(kp.toInt()); 1274 incidence->setPilotId(kp.toInt());
1278 } 1275 }
1279 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1276 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1280 if (!kp.isNull()) { 1277 if (!kp.isNull()) {
1281 incidence->setSyncStatus(kp.toInt()); 1278 incidence->setSyncStatus(kp.toInt());
1282 } 1279 }
1283 kp = incidence->nonKDECustomProperty("X-ZAURUSID");
1284 if (!kp.isNull()) {
1285 incidence->setZaurusId(kp.toInt());
1286 }
1287 1280
1288 kp = incidence->nonKDECustomProperty("X-ZAURUSUID"); 1281
1282 kp = incidence->nonKDECustomProperty("X-KOPIEXTID");
1289 if (!kp.isNull()) { 1283 if (!kp.isNull()) {
1290 incidence->setZaurusUid(kp.toInt()); 1284 incidence->setIDStr(kp);
1291 } 1285 }
1292 1286
1293 // Cancel backwards compatibility mode for subsequent changes by the application 1287 // Cancel backwards compatibility mode for subsequent changes by the application
1294 incidence->recurrence()->setCompatVersion(); 1288 incidence->recurrence()->setCompatVersion();
1295 1289
1296 // add categories 1290 // add categories
1297 incidence->setCategories(categories); 1291 incidence->setCategories(categories);
1298 1292
1299 // iterate through all alarms 1293 // iterate through all alarms
1300 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1294 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1301 alarm; 1295 alarm;
1302 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1296 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1303 readAlarm(alarm,incidence); 1297 readAlarm(alarm,incidence);
1304 } 1298 }
1305} 1299}
1306 1300
1307void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1301void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1308{ 1302{
1309 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1303 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1310 1304
1311 while (p) { 1305 while (p) {
1312 icalproperty_kind kind = icalproperty_isa(p); 1306 icalproperty_kind kind = icalproperty_isa(p);
1313 switch (kind) { 1307 switch (kind) {
1314 1308
1315 case ICAL_UID_PROPERTY: // unique id 1309 case ICAL_UID_PROPERTY: // unique id
1316 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1310 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1317 break; 1311 break;
1318 1312
1319 case ICAL_ORGANIZER_PROPERTY: // organizer 1313 case ICAL_ORGANIZER_PROPERTY: // organizer
1320 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1314 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1321 break; 1315 break;
1322 1316
1323 case ICAL_ATTENDEE_PROPERTY: // attendee 1317 case ICAL_ATTENDEE_PROPERTY: // attendee
1324 incidenceBase->addAttendee(readAttendee(p)); 1318 incidenceBase->addAttendee(readAttendee(p));
1325 break; 1319 break;
1326 1320
1327 default: 1321 default:
1328 break; 1322 break;
1329 } 1323 }
1330 1324
1331 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1325 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1332 } 1326 }
1333 1327
1334 // custom properties 1328 // custom properties
1335 readCustomProperties(parent, incidenceBase); 1329 readCustomProperties(parent, incidenceBase);
1336} 1330}
1337 1331
1338void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1332void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1339{ 1333{
1340 QMap<QCString, QString> customProperties; 1334 QMap<QCString, QString> customProperties;
1341 1335
1342 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1336 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1343 1337
1344 while (p) { 1338 while (p) {
1345 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1339 QString value = QString::fromUtf8(icalproperty_get_x(p));
1346 customProperties[icalproperty_get_x_name(p)] = value; 1340 customProperties[icalproperty_get_x_name(p)] = value;
1347 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1341 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1348 1342
1349 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1343 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1350 } 1344 }
1351 1345
1352 properties->setCustomProperties(customProperties); 1346 properties->setCustomProperties(customProperties);
1353} 1347}
1354 1348
1355void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1349void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1356{ 1350{
1357// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1351// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1358 1352
1359 Recurrence *recur = incidence->recurrence(); 1353 Recurrence *recur = incidence->recurrence();
1360 recur->setCompatVersion(mCalendarVersion); 1354 recur->setCompatVersion(mCalendarVersion);
1361 recur->unsetRecurs(); 1355 recur->unsetRecurs();
1362 1356
1363 struct icalrecurrencetype r = rrule; 1357 struct icalrecurrencetype r = rrule;
1364 1358
1365 dumpIcalRecurrence(r); 1359 dumpIcalRecurrence(r);
1366 readRecurrence( r, recur, incidence); 1360 readRecurrence( r, recur, incidence);
1367} 1361}
1368 1362
1369void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1363void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1370{ 1364{
1371 int wkst; 1365 int wkst;
1372 int index = 0; 1366 int index = 0;
1373 short day = 0; 1367 short day = 0;
1374 QBitArray qba(7); 1368 QBitArray qba(7);
1375 int frequ = r.freq; 1369 int frequ = r.freq;
1376 int interv = r.interval; 1370 int interv = r.interval;
1377 // preprocessing for odd recurrence definitions 1371 // preprocessing for odd recurrence definitions
1378 1372
1379 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1373 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1380 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1374 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1381 interv = 12; 1375 interv = 12;
1382 } 1376 }
1383 } 1377 }
1384 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1378 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1385 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1379 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1386 frequ = ICAL_MONTHLY_RECURRENCE; 1380 frequ = ICAL_MONTHLY_RECURRENCE;
1387 interv = 12* r.interval; 1381 interv = 12* r.interval;
1388 } 1382 }
1389 } 1383 }
1390 1384
1391 switch (frequ) { 1385 switch (frequ) {
1392 case ICAL_MINUTELY_RECURRENCE: 1386 case ICAL_MINUTELY_RECURRENCE:
1393 if (!icaltime_is_null_time(r.until)) { 1387 if (!icaltime_is_null_time(r.until)) {
1394 recur->setMinutely(interv,readICalDateTime(r.until)); 1388 recur->setMinutely(interv,readICalDateTime(r.until));
1395 } else { 1389 } else {
1396 if (r.count == 0) 1390 if (r.count == 0)
1397 recur->setMinutely(interv,-1); 1391 recur->setMinutely(interv,-1);
1398 else 1392 else
1399 recur->setMinutely(interv,r.count); 1393 recur->setMinutely(interv,r.count);
1400 } 1394 }
1401 break; 1395 break;
1402 case ICAL_HOURLY_RECURRENCE: 1396 case ICAL_HOURLY_RECURRENCE:
1403 if (!icaltime_is_null_time(r.until)) { 1397 if (!icaltime_is_null_time(r.until)) {
1404 recur->setHourly(interv,readICalDateTime(r.until)); 1398 recur->setHourly(interv,readICalDateTime(r.until));
1405 } else { 1399 } else {
1406 if (r.count == 0) 1400 if (r.count == 0)
1407 recur->setHourly(interv,-1); 1401 recur->setHourly(interv,-1);
1408 else 1402 else
1409 recur->setHourly(interv,r.count); 1403 recur->setHourly(interv,r.count);
1410 } 1404 }
1411 break; 1405 break;
1412 case ICAL_DAILY_RECURRENCE: 1406 case ICAL_DAILY_RECURRENCE:
1413 if (!icaltime_is_null_time(r.until)) { 1407 if (!icaltime_is_null_time(r.until)) {
1414 recur->setDaily(interv,readICalDate(r.until)); 1408 recur->setDaily(interv,readICalDate(r.until));
1415 } else { 1409 } else {
1416 if (r.count == 0) 1410 if (r.count == 0)
1417 recur->setDaily(interv,-1); 1411 recur->setDaily(interv,-1);
1418 else 1412 else
1419 recur->setDaily(interv,r.count); 1413 recur->setDaily(interv,r.count);
1420 } 1414 }
1421 break; 1415 break;
1422 case ICAL_WEEKLY_RECURRENCE: 1416 case ICAL_WEEKLY_RECURRENCE:
1423 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1417 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1424 wkst = (r.week_start + 5)%7 + 1; 1418 wkst = (r.week_start + 5)%7 + 1;
1425 if (!icaltime_is_null_time(r.until)) { 1419 if (!icaltime_is_null_time(r.until)) {
1426 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1420 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1427 } else { 1421 } else {
1428 if (r.count == 0) 1422 if (r.count == 0)
1429 recur->setWeekly(interv,qba,-1,wkst); 1423 recur->setWeekly(interv,qba,-1,wkst);
1430 else 1424 else
1431 recur->setWeekly(interv,qba,r.count,wkst); 1425 recur->setWeekly(interv,qba,r.count,wkst);
1432 } 1426 }
1433 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1427 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1434 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1428 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1435 //qDebug("weekly error found "); 1429 //qDebug("weekly error found ");
1436 qba.setBit(wday); 1430 qba.setBit(wday);
1437 } else { 1431 } else {
1438 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1432 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1439 // kdDebug(5800) << " " << day << endl; 1433 // kdDebug(5800) << " " << day << endl;
1440 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1434 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1441 } 1435 }
1442 } 1436 }
1443 break; 1437 break;
1444 case ICAL_MONTHLY_RECURRENCE: 1438 case ICAL_MONTHLY_RECURRENCE:
1445 1439
1446 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1440 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1447 if (!icaltime_is_null_time(r.until)) { 1441 if (!icaltime_is_null_time(r.until)) {
1448 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1442 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1449 readICalDate(r.until)); 1443 readICalDate(r.until));
1450 } else { 1444 } else {
1451 if (r.count == 0) 1445 if (r.count == 0)
1452 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1446 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1453 else 1447 else
1454 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1448 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1455 } 1449 }
1456 bool useSetPos = false; 1450 bool useSetPos = false;
1457 short pos = 0; 1451 short pos = 0;
1458 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1452 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1459 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1453 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1460 pos = icalrecurrencetype_day_position(day); 1454 pos = icalrecurrencetype_day_position(day);
1461 if (pos) { 1455 if (pos) {
1462 day = icalrecurrencetype_day_day_of_week(day); 1456 day = icalrecurrencetype_day_day_of_week(day);
1463 QBitArray ba(7); // don't wipe qba 1457 QBitArray ba(7); // don't wipe qba
1464 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1458 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1465 recur->addMonthlyPos(pos,ba); 1459 recur->addMonthlyPos(pos,ba);
1466 } else { 1460 } else {
1467 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1461 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1468 useSetPos = true; 1462 useSetPos = true;
1469 } 1463 }
1470 } 1464 }
1471 if (useSetPos) { 1465 if (useSetPos) {
1472 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1466 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1473 recur->addMonthlyPos(r.by_set_pos[0],qba); 1467 recur->addMonthlyPos(r.by_set_pos[0],qba);
1474 } 1468 }
1475 } 1469 }
1476 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1470 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1477 if (!icaltime_is_null_time(r.until)) { 1471 if (!icaltime_is_null_time(r.until)) {
1478 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1472 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1479 readICalDate(r.until)); 1473 readICalDate(r.until));
1480 } else { 1474 } else {
1481 if (r.count == 0) 1475 if (r.count == 0)
1482 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1476 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1483 else 1477 else
1484 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1478 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1485 } 1479 }
1486 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1480 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1487 // kdDebug(5800) << "----b " << day << endl; 1481 // kdDebug(5800) << "----b " << day << endl;
1488 recur->addMonthlyDay(day); 1482 recur->addMonthlyDay(day);
1489 } 1483 }
1490 } 1484 }
1491 break; 1485 break;
1492 case ICAL_YEARLY_RECURRENCE: 1486 case ICAL_YEARLY_RECURRENCE:
1493 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1487 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1494 //qDebug(" YEARLY DAY OF YEAR"); 1488 //qDebug(" YEARLY DAY OF YEAR");
1495 if (!icaltime_is_null_time(r.until)) { 1489 if (!icaltime_is_null_time(r.until)) {
1496 recur->setYearly(Recurrence::rYearlyDay,interv, 1490 recur->setYearly(Recurrence::rYearlyDay,interv,
1497 readICalDate(r.until)); 1491 readICalDate(r.until));
1498 } else { 1492 } else {
1499 if (r.count == 0) 1493 if (r.count == 0)
1500 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1494 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1501 else 1495 else
1502 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1496 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1503 } 1497 }
1504 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1498 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1505 recur->addYearlyNum(day); 1499 recur->addYearlyNum(day);
1506 } 1500 }
1507 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1501 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1508 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1502 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1509 qDebug("YEARLY POS NOT SUPPORTED BY GUI"); 1503 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1510 if (!icaltime_is_null_time(r.until)) { 1504 if (!icaltime_is_null_time(r.until)) {
1511 recur->setYearly(Recurrence::rYearlyPos,interv, 1505 recur->setYearly(Recurrence::rYearlyPos,interv,
1512 readICalDate(r.until)); 1506 readICalDate(r.until));
1513 } else { 1507 } else {
1514 if (r.count == 0) 1508 if (r.count == 0)
1515 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1509 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1516 else 1510 else
1517 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1511 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1518 } 1512 }
1519 bool useSetPos = false; 1513 bool useSetPos = false;
1520 short pos = 0; 1514 short pos = 0;
1521 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1515 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1522 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1516 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1523 pos = icalrecurrencetype_day_position(day); 1517 pos = icalrecurrencetype_day_position(day);
1524 if (pos) { 1518 if (pos) {
1525 day = icalrecurrencetype_day_day_of_week(day); 1519 day = icalrecurrencetype_day_day_of_week(day);
1526 QBitArray ba(7); // don't wipe qba 1520 QBitArray ba(7); // don't wipe qba
1527 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1521 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1528 recur->addYearlyMonthPos(pos,ba); 1522 recur->addYearlyMonthPos(pos,ba);
1529 } else { 1523 } else {
1530 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1524 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1531 useSetPos = true; 1525 useSetPos = true;
1532 } 1526 }
1533 } 1527 }
1534 if (useSetPos) { 1528 if (useSetPos) {
1535 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1529 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1536 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1530 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1537 } 1531 }
1538 } 1532 }
1539 } else { 1533 } else {
1540 //qDebug("YEARLY MONTH "); 1534 //qDebug("YEARLY MONTH ");
1541 if (!icaltime_is_null_time(r.until)) { 1535 if (!icaltime_is_null_time(r.until)) {
1542 recur->setYearly(Recurrence::rYearlyMonth,interv, 1536 recur->setYearly(Recurrence::rYearlyMonth,interv,
1543 readICalDate(r.until)); 1537 readICalDate(r.until));
1544 } else { 1538 } else {
1545 if (r.count == 0) 1539 if (r.count == 0)
1546 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1540 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1547 else 1541 else
1548 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1542 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1549 } 1543 }
1550 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1544 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1551 index = 0; 1545 index = 0;
1552 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1546 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1553 recur->addYearlyNum(day); 1547 recur->addYearlyNum(day);
1554 } 1548 }
1555 } else { 1549 } else {
1556 recur->addYearlyNum(incidence->dtStart().date().month()); 1550 recur->addYearlyNum(incidence->dtStart().date().month());
1557 } 1551 }
1558 } 1552 }
1559 1553
1560 } 1554 }
1561 break; 1555 break;
1562 default: 1556 default:
1563 ; 1557 ;
1564 break; 1558 break;
1565 } 1559 }
1566} 1560}
1567 1561
1568void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1562void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1569{ 1563{
1570 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1564 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1571 1565
1572 Alarm* ialarm = incidence->newAlarm(); 1566 Alarm* ialarm = incidence->newAlarm();
1573 ialarm->setRepeatCount(0); 1567 ialarm->setRepeatCount(0);
1574 ialarm->setEnabled(true); 1568 ialarm->setEnabled(true);
1575 1569
1576 // Determine the alarm's action type 1570 // Determine the alarm's action type
1577 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1571 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1578 if ( !p ) { 1572 if ( !p ) {
1579 return; 1573 return;
1580 } 1574 }
1581 1575
1582 icalproperty_action action = icalproperty_get_action(p); 1576 icalproperty_action action = icalproperty_get_action(p);
1583 Alarm::Type type = Alarm::Display; 1577 Alarm::Type type = Alarm::Display;
1584 switch ( action ) { 1578 switch ( action ) {
1585 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1579 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1586 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1580 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1587 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1581 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1588 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1582 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1589 default: 1583 default:
1590 ; 1584 ;
1591 return; 1585 return;
1592 } 1586 }
1593 ialarm->setType(type); 1587 ialarm->setType(type);
1594 1588
1595 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1589 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1596 while (p) { 1590 while (p) {
1597 icalproperty_kind kind = icalproperty_isa(p); 1591 icalproperty_kind kind = icalproperty_isa(p);
1598 1592
1599 switch (kind) { 1593 switch (kind) {
1600 case ICAL_TRIGGER_PROPERTY: { 1594 case ICAL_TRIGGER_PROPERTY: {
1601 icaltriggertype trigger = icalproperty_get_trigger(p); 1595 icaltriggertype trigger = icalproperty_get_trigger(p);
1602 if (icaltime_is_null_time(trigger.time)) { 1596 if (icaltime_is_null_time(trigger.time)) {
1603 if (icaldurationtype_is_null_duration(trigger.duration)) { 1597 if (icaldurationtype_is_null_duration(trigger.duration)) {
1604 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; 1598 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1605 } else { 1599 } else {
1606 Duration duration = icaldurationtype_as_int( trigger.duration ); 1600 Duration duration = icaldurationtype_as_int( trigger.duration );
1607 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1601 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1608 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1602 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1609 ialarm->setEndOffset(duration); 1603 ialarm->setEndOffset(duration);
1610 else 1604 else
1611 ialarm->setStartOffset(duration); 1605 ialarm->setStartOffset(duration);
1612 } 1606 }
1613 } else { 1607 } else {
1614 ialarm->setTime(readICalDateTime(trigger.time)); 1608 ialarm->setTime(readICalDateTime(trigger.time));
1615 } 1609 }
1616 break; 1610 break;
1617 } 1611 }
1618 case ICAL_DURATION_PROPERTY: { 1612 case ICAL_DURATION_PROPERTY: {
1619 icaldurationtype duration = icalproperty_get_duration(p); 1613 icaldurationtype duration = icalproperty_get_duration(p);
1620 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1614 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1621 break; 1615 break;
1622 } 1616 }
1623 case ICAL_REPEAT_PROPERTY: 1617 case ICAL_REPEAT_PROPERTY:
1624 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1618 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1625 break; 1619 break;
1626 1620
1627 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1621 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1628 case ICAL_DESCRIPTION_PROPERTY: { 1622 case ICAL_DESCRIPTION_PROPERTY: {
1629 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1623 QString description = QString::fromUtf8(icalproperty_get_description(p));
1630 switch ( action ) { 1624 switch ( action ) {
1631 case ICAL_ACTION_DISPLAY: 1625 case ICAL_ACTION_DISPLAY:
1632 ialarm->setText( description ); 1626 ialarm->setText( description );
1633 break; 1627 break;
1634 case ICAL_ACTION_PROCEDURE: 1628 case ICAL_ACTION_PROCEDURE:
1635 ialarm->setProgramArguments( description ); 1629 ialarm->setProgramArguments( description );
1636 break; 1630 break;
1637 case ICAL_ACTION_EMAIL: 1631 case ICAL_ACTION_EMAIL:
1638 ialarm->setMailText( description ); 1632 ialarm->setMailText( description );
1639 break; 1633 break;
1640 default: 1634 default:
1641 break; 1635 break;
1642 } 1636 }
1643 break; 1637 break;
1644 } 1638 }
1645 // Only in EMAIL alarm 1639 // Only in EMAIL alarm
1646 case ICAL_SUMMARY_PROPERTY: 1640 case ICAL_SUMMARY_PROPERTY:
1647 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1641 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1648 break; 1642 break;
1649 1643
1650 // Only in EMAIL alarm 1644 // Only in EMAIL alarm
1651 case ICAL_ATTENDEE_PROPERTY: { 1645 case ICAL_ATTENDEE_PROPERTY: {
1652 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1646 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1653 QString name; 1647 QString name;
1654 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1648 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1655 if (param) { 1649 if (param) {
1656 name = QString::fromUtf8(icalparameter_get_cn(param)); 1650 name = QString::fromUtf8(icalparameter_get_cn(param));
1657 } 1651 }
1658 ialarm->addMailAddress(Person(name, email)); 1652 ialarm->addMailAddress(Person(name, email));
1659 break; 1653 break;
1660 } 1654 }
1661 // Only in AUDIO and EMAIL and PROCEDURE alarms 1655 // Only in AUDIO and EMAIL and PROCEDURE alarms
1662 case ICAL_ATTACH_PROPERTY: { 1656 case ICAL_ATTACH_PROPERTY: {
1663 icalattach *attach = icalproperty_get_attach(p); 1657 icalattach *attach = icalproperty_get_attach(p);
1664 QString url = QFile::decodeName(icalattach_get_url(attach)); 1658 QString url = QFile::decodeName(icalattach_get_url(attach));
1665 switch ( action ) { 1659 switch ( action ) {
1666 case ICAL_ACTION_AUDIO: 1660 case ICAL_ACTION_AUDIO:
1667 ialarm->setAudioFile( url ); 1661 ialarm->setAudioFile( url );
1668 break; 1662 break;
1669 case ICAL_ACTION_PROCEDURE: 1663 case ICAL_ACTION_PROCEDURE:
1670 ialarm->setProgramFile( url ); 1664 ialarm->setProgramFile( url );
1671 break; 1665 break;
1672 case ICAL_ACTION_EMAIL: 1666 case ICAL_ACTION_EMAIL:
1673 ialarm->addMailAttachment( url ); 1667 ialarm->addMailAttachment( url );
1674 break; 1668 break;
1675 default: 1669 default:
1676 break; 1670 break;
1677 } 1671 }
1678 break; 1672 break;
1679 } 1673 }
1680 default: 1674 default:
1681 break; 1675 break;
1682 } 1676 }
1683 1677
1684 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1678 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1685 } 1679 }
1686 1680
1687 // custom properties 1681 // custom properties
1688 readCustomProperties(alarm, ialarm); 1682 readCustomProperties(alarm, ialarm);
1689 1683
1690 // TODO: check for consistency of alarm properties 1684 // TODO: check for consistency of alarm properties
1691} 1685}
1692 1686
1693icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1687icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1694{ 1688{
1695 icaltimetype t; 1689 icaltimetype t;
1696 1690
1697 t.year = date.year(); 1691 t.year = date.year();
1698 t.month = date.month(); 1692 t.month = date.month();
1699 t.day = date.day(); 1693 t.day = date.day();
1700 1694
1701 t.hour = 0; 1695 t.hour = 0;
1702 t.minute = 0; 1696 t.minute = 0;
1703 t.second = 0; 1697 t.second = 0;
1704 1698
1705 t.is_date = 1; 1699 t.is_date = 1;
1706 1700
1707 t.is_utc = 0; 1701 t.is_utc = 0;
1708 1702
1709 t.zone = 0; 1703 t.zone = 0;
1710 1704
1711 return t; 1705 return t;
1712} 1706}
1713 1707
1714icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1708icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1715{ 1709{
1716 icaltimetype t; 1710 icaltimetype t;
1717 t.is_date = 0; 1711 t.is_date = 0;
1718 t.zone = 0; 1712 t.zone = 0;
1719 QDateTime datetime; 1713 QDateTime datetime;
1720 if ( mParent->utc() ) { 1714 if ( mParent->utc() ) {
1721 int offset = KGlobal::locale()->localTimeOffset( dt ); 1715 int offset = KGlobal::locale()->localTimeOffset( dt );
1722 datetime = dt.addSecs ( -offset*60); 1716 datetime = dt.addSecs ( -offset*60);
1723 t.is_utc = 1; 1717 t.is_utc = 1;
1724 } 1718 }
1725 else { 1719 else {
1726 datetime = dt; 1720 datetime = dt;
1727 t.is_utc = 0; 1721 t.is_utc = 0;
1728 1722
1729 } 1723 }
1730 t.year = datetime.date().year(); 1724 t.year = datetime.date().year();
1731 t.month = datetime.date().month(); 1725 t.month = datetime.date().month();
1732 t.day = datetime.date().day(); 1726 t.day = datetime.date().day();
1733 1727
1734 t.hour = datetime.time().hour(); 1728 t.hour = datetime.time().hour();
1735 t.minute = datetime.time().minute(); 1729 t.minute = datetime.time().minute();
1736 t.second = datetime.time().second(); 1730 t.second = datetime.time().second();
1737 1731
1738 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1732 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1739 1733
1740// if ( mParent->utc() ) { 1734// if ( mParent->utc() ) {
1741// datetime = KGlobal::locale()->localTime( dt ); 1735// datetime = KGlobal::locale()->localTime( dt );
1742// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1736// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1743// if (mParent->timeZoneId().isEmpty()) 1737// if (mParent->timeZoneId().isEmpty())
1744// t = icaltime_as_utc(t, 0); 1738// t = icaltime_as_utc(t, 0);
1745// else 1739// else
1746// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1740// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1747// } 1741// }
1748 1742
1749 return t; 1743 return t;
1750} 1744}
1751 1745
1752QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1746QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1753{ 1747{
1754 QDateTime dt (QDate(t.year,t.month,t.day), 1748 QDateTime dt (QDate(t.year,t.month,t.day),
1755 QTime(t.hour,t.minute,t.second) ); 1749 QTime(t.hour,t.minute,t.second) );
1756 1750
1757 if (t.is_utc) { 1751 if (t.is_utc) {
1758 int offset = KGlobal::locale()->localTimeOffset( dt ); 1752 int offset = KGlobal::locale()->localTimeOffset( dt );
1759 dt = dt.addSecs ( offset*60); 1753 dt = dt.addSecs ( offset*60);
1760 } 1754 }
1761 1755
1762 return dt; 1756 return dt;
1763} 1757}
1764 1758
1765QDate ICalFormatImpl::readICalDate(icaltimetype t) 1759QDate ICalFormatImpl::readICalDate(icaltimetype t)
1766{ 1760{
1767 return QDate(t.year,t.month,t.day); 1761 return QDate(t.year,t.month,t.day);
1768} 1762}
1769 1763
1770icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1764icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1771{ 1765{
1772 icaldurationtype d; 1766 icaldurationtype d;
1773 1767
1774 d.weeks = seconds % gSecondsPerWeek; 1768 d.weeks = seconds % gSecondsPerWeek;
1775 seconds -= d.weeks * gSecondsPerWeek; 1769 seconds -= d.weeks * gSecondsPerWeek;
1776 d.days = seconds % gSecondsPerDay; 1770 d.days = seconds % gSecondsPerDay;
1777 seconds -= d.days * gSecondsPerDay; 1771 seconds -= d.days * gSecondsPerDay;
1778 d.hours = seconds % gSecondsPerHour; 1772 d.hours = seconds % gSecondsPerHour;
1779 seconds -= d.hours * gSecondsPerHour; 1773 seconds -= d.hours * gSecondsPerHour;
1780 d.minutes = seconds % gSecondsPerMinute; 1774 d.minutes = seconds % gSecondsPerMinute;
1781 seconds -= d.minutes * gSecondsPerMinute; 1775 seconds -= d.minutes * gSecondsPerMinute;
1782 d.seconds = seconds; 1776 d.seconds = seconds;
1783 d.is_neg = 0; 1777 d.is_neg = 0;
1784 1778
1785 return d; 1779 return d;
1786} 1780}
1787 1781
1788int ICalFormatImpl::readICalDuration(icaldurationtype d) 1782int ICalFormatImpl::readICalDuration(icaldurationtype d)
1789{ 1783{
1790 int result = 0; 1784 int result = 0;
1791 1785
1792 result += d.weeks * gSecondsPerWeek; 1786 result += d.weeks * gSecondsPerWeek;
1793 result += d.days * gSecondsPerDay; 1787 result += d.days * gSecondsPerDay;
1794 result += d.hours * gSecondsPerHour; 1788 result += d.hours * gSecondsPerHour;
1795 result += d.minutes * gSecondsPerMinute; 1789 result += d.minutes * gSecondsPerMinute;
1796 result += d.seconds; 1790 result += d.seconds;
1797 1791
1798 if (d.is_neg) result *= -1; 1792 if (d.is_neg) result *= -1;
1799 1793
1800 return result; 1794 return result;
1801} 1795}
1802 1796
1803icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1797icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1804{ 1798{
1805 icalcomponent *calendar; 1799 icalcomponent *calendar;
1806 1800
1807 // Root component 1801 // Root component
1808 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1802 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1809 1803
1810 icalproperty *p; 1804 icalproperty *p;
1811 1805
1812 // Product Identifier 1806 // Product Identifier
1813 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1807 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1814 icalcomponent_add_property(calendar,p); 1808 icalcomponent_add_property(calendar,p);
1815 1809
1816 // TODO: Add time zone 1810 // TODO: Add time zone
1817 1811
1818 // iCalendar version (2.0) 1812 // iCalendar version (2.0)
1819 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1813 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1820 icalcomponent_add_property(calendar,p); 1814 icalcomponent_add_property(calendar,p);
1821 1815
1822 // Custom properties 1816 // Custom properties
1823 if( cal != 0 ) 1817 if( cal != 0 )
1824 writeCustomProperties(calendar, cal); 1818 writeCustomProperties(calendar, cal);
1825 1819
1826 return calendar; 1820 return calendar;
1827} 1821}
1828 1822
1829 1823
1830 1824
1831// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1825// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1832// and break it down from its tree-like format into the dictionary format 1826// and break it down from its tree-like format into the dictionary format
1833// that is used internally in the ICalFormatImpl. 1827// that is used internally in the ICalFormatImpl.
1834bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1828bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1835{ 1829{
1836 // this function will populate the caldict dictionary and other event 1830 // this function will populate the caldict dictionary and other event
1837 // lists. It turns vevents into Events and then inserts them. 1831 // lists. It turns vevents into Events and then inserts them.
1838 1832
1839 if (!calendar) return false; 1833 if (!calendar) return false;
1840 1834
1841// TODO: check for METHOD 1835// TODO: check for METHOD
1842#if 0 1836#if 0
1843 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1837 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1844 char *methodType = 0; 1838 char *methodType = 0;
1845 methodType = fakeCString(vObjectUStringZValue(curVO)); 1839 methodType = fakeCString(vObjectUStringZValue(curVO));
1846 if (mEnableDialogs) 1840 if (mEnableDialogs)
1847 KMessageBox::information(mTopWidget, 1841 KMessageBox::information(mTopWidget,
1848 i18n("This calendar is an iTIP transaction of type \"%1\".") 1842 i18n("This calendar is an iTIP transaction of type \"%1\".")
1849 .arg(methodType), 1843 .arg(methodType),
1850 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1844 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1851 delete methodType; 1845 delete methodType;
1852 } 1846 }
1853#endif 1847#endif
1854 1848
1855 icalproperty *p; 1849 icalproperty *p;
1856 1850
1857 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1851 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1858 if (!p) { 1852 if (!p) {
1859// TODO: does no PRODID really matter? 1853// TODO: does no PRODID really matter?
1860// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1854// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1861// return false; 1855// return false;
1862 mLoadedProductId = ""; 1856 mLoadedProductId = "";
1863 mCalendarVersion = 0; 1857 mCalendarVersion = 0;
1864 } else { 1858 } else {
1865 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1859 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1866 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1860 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1867 1861
1868 delete mCompat; 1862 delete mCompat;
1869 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1863 mCompat = CompatFactory::createCompat( mLoadedProductId );
1870 } 1864 }
1871 1865
1872// TODO: check for unknown PRODID 1866// TODO: check for unknown PRODID
1873#if 0 1867#if 0
1874 if (!mCalendarVersion 1868 if (!mCalendarVersion
1875 && CalFormat::productId() != mLoadedProductId) { 1869 && CalFormat::productId() != mLoadedProductId) {
1876 // warn the user that we might have trouble reading non-known calendar. 1870 // warn the user that we might have trouble reading non-known calendar.
1877 if (mEnableDialogs) 1871 if (mEnableDialogs)
1878 KMessageBox::information(mTopWidget, 1872 KMessageBox::information(mTopWidget,
1879 i18n("This vCalendar file was not created by KOrganizer " 1873 i18n("This vCalendar file was not created by KOrganizer "
1880 "or any other product we support. Loading anyway..."), 1874 "or any other product we support. Loading anyway..."),
1881 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); 1875 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application()));
1882 } 1876 }
1883#endif 1877#endif
1884 1878
1885 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); 1879 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
1886 if (!p) { 1880 if (!p) {
1887 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1881 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1888 return false; 1882 return false;
1889 } else { 1883 } else {
1890 const char *version = icalproperty_get_version(p); 1884 const char *version = icalproperty_get_version(p);
1891 1885
1892 if (strcmp(version,"1.0") == 0) { 1886 if (strcmp(version,"1.0") == 0) {
1893 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, 1887 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1,
1894 i18n("Expected iCalendar format"))); 1888 i18n("Expected iCalendar format")));
1895 return false; 1889 return false;
1896 } else if (strcmp(version,"2.0") != 0) { 1890 } else if (strcmp(version,"2.0") != 0) {
1897 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1891 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1898 return false; 1892 return false;
1899 } 1893 }
1900 } 1894 }
1901 1895
1902 1896
1903// TODO: check for calendar format version 1897// TODO: check for calendar format version
1904#if 0 1898#if 0
1905 // warn the user we might have trouble reading this unknown version. 1899 // warn the user we might have trouble reading this unknown version.
1906 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1900 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1907 char *s = fakeCString(vObjectUStringZValue(curVO)); 1901 char *s = fakeCString(vObjectUStringZValue(curVO));
1908 if (strcmp(_VCAL_VERSION, s) != 0) 1902 if (strcmp(_VCAL_VERSION, s) != 0)
1909 if (mEnableDialogs) 1903 if (mEnableDialogs)
1910 KMessageBox::sorry(mTopWidget, 1904 KMessageBox::sorry(mTopWidget,
1911 i18n("This vCalendar file has version %1.\n" 1905 i18n("This vCalendar file has version %1.\n"
1912 "We only support %2.") 1906 "We only support %2.")
1913 .arg(s).arg(_VCAL_VERSION), 1907 .arg(s).arg(_VCAL_VERSION),
1914 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); 1908 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application()));
1915 deleteStr(s); 1909 deleteStr(s);
1916 } 1910 }
1917#endif 1911#endif
1918 1912
1919 // custom properties 1913 // custom properties
1920 readCustomProperties(calendar, cal); 1914 readCustomProperties(calendar, cal);
1921 1915
1922// TODO: set time zone 1916// TODO: set time zone
1923#if 0 1917#if 0
1924 // set the time zone 1918 // set the time zone
1925 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1919 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1926 char *s = fakeCString(vObjectUStringZValue(curVO)); 1920 char *s = fakeCString(vObjectUStringZValue(curVO));
1927 cal->setTimeZone(s); 1921 cal->setTimeZone(s);
1928 deleteStr(s); 1922 deleteStr(s);
1929 } 1923 }
1930#endif 1924#endif
1931 1925
1932 // Store all events with a relatedTo property in a list for post-processing 1926 // Store all events with a relatedTo property in a list for post-processing
1933 mEventsRelate.clear(); 1927 mEventsRelate.clear();
1934 mTodosRelate.clear(); 1928 mTodosRelate.clear();
1935 // TODO: make sure that only actually added ecvens go to this lists. 1929 // TODO: make sure that only actually added ecvens go to this lists.
1936 1930
1937 icalcomponent *c; 1931 icalcomponent *c;
1938 1932
1939 // Iterate through all todos 1933 // Iterate through all todos
1940 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); 1934 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
1941 while (c) { 1935 while (c) {
1942// kdDebug(5800) << "----Todo found" << endl; 1936// kdDebug(5800) << "----Todo found" << endl;
1943 Todo *todo = readTodo(c); 1937 Todo *todo = readTodo(c);
1944 if (!cal->todo(todo->uid())) cal->addTodo(todo); 1938 if (!cal->todo(todo->uid())) cal->addTodo(todo);
1945 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); 1939 c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT);
1946 } 1940 }
1947 1941
1948 // Iterate through all events 1942 // Iterate through all events
1949 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); 1943 c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
1950 while (c) { 1944 while (c) {
1951// kdDebug(5800) << "----Event found" << endl; 1945// kdDebug(5800) << "----Event found" << endl;
1952 Event *event = readEvent(c); 1946 Event *event = readEvent(c);
1953 if (!cal->event(event->uid())) cal->addEvent(event); 1947 if (!cal->event(event->uid())) cal->addEvent(event);
1954 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); 1948 c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT);
1955 } 1949 }
1956 1950
1957 // Iterate through all journals 1951 // Iterate through all journals
1958 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); 1952 c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
1959 while (c) { 1953 while (c) {
1960// kdDebug(5800) << "----Journal found" << endl; 1954// kdDebug(5800) << "----Journal found" << endl;
1961 Journal *journal = readJournal(c); 1955 Journal *journal = readJournal(c);
1962 if (!cal->journal(journal->uid())) cal->addJournal(journal); 1956 if (!cal->journal(journal->uid())) cal->addJournal(journal);
1963 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); 1957 c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT);
1964 } 1958 }
1965 1959
1966#if 0 1960#if 0
1967 initPropIterator(&i, vcal); 1961 initPropIterator(&i, vcal);
1968 1962
1969 // go through all the vobjects in the vcal 1963 // go through all the vobjects in the vcal
1970 while (moreIteration(&i)) { 1964 while (moreIteration(&i)) {
1971 curVO = nextVObject(&i); 1965 curVO = nextVObject(&i);
1972 1966
1973 /************************************************************************/ 1967 /************************************************************************/
1974 1968
1975 // now, check to see that the object is an event or todo. 1969 // now, check to see that the object is an event or todo.
1976 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1970 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1977 1971
1978 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { 1972 if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) {
1979 char *s; 1973 char *s;
1980 s = fakeCString(vObjectUStringZValue(curVOProp)); 1974 s = fakeCString(vObjectUStringZValue(curVOProp));
1981 // check to see if event was deleted by the kpilot conduit 1975 // check to see if event was deleted by the kpilot conduit
1982 if (atoi(s) == Event::SYNCDEL) { 1976 if (atoi(s) == Event::SYNCDEL) {
1983 deleteStr(s); 1977 deleteStr(s);
1984 goto SKIP; 1978 goto SKIP;
1985 } 1979 }
1986 deleteStr(s); 1980 deleteStr(s);
1987 } 1981 }
1988 1982
1989 // this code checks to see if we are trying to read in an event 1983 // this code checks to see if we are trying to read in an event
1990 // that we already find to be in the calendar. If we find this 1984 // that we already find to be in the calendar. If we find this
1991 // to be the case, we skip the event. 1985 // to be the case, we skip the event.
1992 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1986 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1993 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1987 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1994 QString tmpStr(s); 1988 QString tmpStr(s);
1995 deleteStr(s); 1989 deleteStr(s);
1996 1990
1997 if (cal->event(tmpStr)) { 1991 if (cal->event(tmpStr)) {
1998 goto SKIP; 1992 goto SKIP;
1999 } 1993 }
2000 if (cal->todo(tmpStr)) { 1994 if (cal->todo(tmpStr)) {
2001 goto SKIP; 1995 goto SKIP;
2002 } 1996 }
2003 } 1997 }
2004 1998
2005 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1999 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
2006 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 2000 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
2007 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 2001 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
2008 goto SKIP; 2002 goto SKIP;
2009 } 2003 }
2010 2004
2011 anEvent = VEventToEvent(curVO); 2005 anEvent = VEventToEvent(curVO);
2012 // we now use addEvent instead of insertEvent so that the 2006 // we now use addEvent instead of insertEvent so that the
2013 // signal/slot get connected. 2007 // signal/slot get connected.
2014 if (anEvent) 2008 if (anEvent)
2015 cal->addEvent(anEvent); 2009 cal->addEvent(anEvent);
2016 else { 2010 else {
2017 // some sort of error must have occurred while in translation. 2011 // some sort of error must have occurred while in translation.
2018 goto SKIP; 2012 goto SKIP;
2019 } 2013 }
2020 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 2014 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
2021 anEvent = VTodoToEvent(curVO); 2015 anEvent = VTodoToEvent(curVO);
2022 cal->addTodo(anEvent); 2016 cal->addTodo(anEvent);
2023 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 2017 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
2024 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 2018 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
2025 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 2019 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
2026 // do nothing, we know these properties and we want to skip them. 2020 // do nothing, we know these properties and we want to skip them.
2027 // we have either already processed them or are ignoring them. 2021 // we have either already processed them or are ignoring them.
2028 ; 2022 ;
2029 } else { 2023 } else {
2030 ; 2024 ;
2031 } 2025 }
2032 SKIP: 2026 SKIP:
2033 ; 2027 ;
2034 } // while 2028 } // while
2035#endif 2029#endif
2036 2030
2037 // Post-Process list of events with relations, put Event objects in relation 2031 // Post-Process list of events with relations, put Event objects in relation
2038 Event *ev; 2032 Event *ev;
2039 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 2033 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
2040 ev->setRelatedTo(cal->event(ev->relatedToUid())); 2034 ev->setRelatedTo(cal->event(ev->relatedToUid()));
2041 } 2035 }
2042 Todo *todo; 2036 Todo *todo;
2043 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 2037 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
2044 todo->setRelatedTo(cal->todo(todo->relatedToUid())); 2038 todo->setRelatedTo(cal->todo(todo->relatedToUid()));
2045 } 2039 }
2046 2040
2047 return true; 2041 return true;
2048} 2042}
2049 2043
2050QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) 2044QString ICalFormatImpl::extractErrorProperty(icalcomponent *c)
2051{ 2045{
2052// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " 2046// kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: "
2053// << icalcomponent_as_ical_string(c) << endl; 2047// << icalcomponent_as_ical_string(c) << endl;
2054 2048
2055 QString errorMessage; 2049 QString errorMessage;
2056 2050
2057 icalproperty *error; 2051 icalproperty *error;
2058 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); 2052 error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY);
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 707d666..d7c4595 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,393 +1,470 @@
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 <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidencebase.h" 27#include "incidencebase.h"
28 28
29using namespace KCal; 29using namespace KCal;
30 30
31IncidenceBase::IncidenceBase() : 31IncidenceBase::IncidenceBase() :
32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 32 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
33 mPilotId(0), mSyncStatus(SYNCMOD) 33 mPilotId(0), mSyncStatus(SYNCMOD)
34{ 34{
35 setUid(CalFormat::createUniqueId()); 35 setUid(CalFormat::createUniqueId());
36 mOrganizer = ""; 36 mOrganizer = "";
37 mFloats = false; 37 mFloats = false;
38 mDuration = 0; 38 mDuration = 0;
39 mHasDuration = false; 39 mHasDuration = false;
40 mPilotId = 0; 40 mPilotId = 0;
41 mZaurusId = -1; 41 mZaurusId = -1;
42 mZaurusUid = 0; 42 mZaurusUid = 0;
43 mExternalId = ":";
43 mTempSyncStat = 0; 44 mTempSyncStat = 0;
44 mSyncStatus = 0; 45 mSyncStatus = 0;
45 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
46} 47}
47 48
48IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
49 CustomProperties( i ) 50 CustomProperties( i )
50{ 51{
51 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
52 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
53 mDuration = i.mDuration; 54 mDuration = i.mDuration;
54 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
55 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
56 mUid = i.mUid; 57 mUid = i.mUid;
57 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
59 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
60 } 61 }
61 mFloats = i.mFloats; 62 mFloats = i.mFloats;
62 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
63 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
64 mZaurusId = i.mZaurusId; 65 mZaurusId = i.mZaurusId;
65 mZaurusUid = i.mZaurusUid; 66 mZaurusUid = i.mZaurusUid;
66 mTempSyncStat = i.mTempSyncStat; 67 mTempSyncStat = i.mTempSyncStat;
67 mSyncStatus = i.mSyncStatus; 68 mSyncStatus = i.mSyncStatus;
68 69 mExternalId = i.mExternalId;
69 // The copied object is a new one, so it isn't observed by the observer 70 // The copied object is a new one, so it isn't observed by the observer
70 // of the original object. 71 // of the original object.
71 mObservers.clear(); 72 mObservers.clear();
72 73
73 mAttendees.setAutoDelete( true ); 74 mAttendees.setAutoDelete( true );
74} 75}
75 76
76IncidenceBase::~IncidenceBase() 77IncidenceBase::~IncidenceBase()
77{ 78{
78} 79}
79 80
80 81
81bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 82bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
82{ 83{
83 84 // do not compare mSyncStatus and mExternalId
84 if( i1.attendees().count() != i2.attendees().count() ) { 85 if( i1.attendees().count() != i2.attendees().count() ) {
85 return false; // no need to check further 86 return false; // no need to check further
86 } 87 }
87 if ( i1.attendees().count() > 0 ) { 88 if ( i1.attendees().count() > 0 ) {
88 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 89 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
89 while ( a1 ) { 90 while ( a1 ) {
90 if ( !( (*a1) == (*a2)) ) 91 if ( !( (*a1) == (*a2)) )
91 { 92 {
92 //qDebug("Attendee not equal "); 93 //qDebug("Attendee not equal ");
93 return false; 94 return false;
94 } 95 }
95 a1 = i1.attendees().next(); 96 a1 = i1.attendees().next();
96 a2 = i2.attendees().next(); 97 a2 = i2.attendees().next();
97 } 98 }
98 } 99 }
99 //if ( i1.dtStart() != i2.dtStart() ) 100 //if ( i1.dtStart() != i2.dtStart() )
100 // return false; 101 // return false;
101#if 0 102#if 0
102 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 103 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
103 qDebug("1 %d ",i1.duration() == i2.duration() ); 104 qDebug("1 %d ",i1.duration() == i2.duration() );
104 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 105 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
105 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 106 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
106 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 107 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
107 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 108 qDebug("6 %d ",i1.organizer() == i2.organizer() );
108 109
109#endif 110#endif
110 return ( i1.organizer() == i2.organizer() && 111 return ( i1.organizer() == i2.organizer() &&
111 // i1.uid() == i2.uid() && 112 // i1.uid() == i2.uid() &&
112 // Don't compare lastModified, otherwise the operator is not 113 // Don't compare lastModified, otherwise the operator is not
113 // of much use. We are not comparing for identity, after all. 114 // of much use. We are not comparing for identity, after all.
114 i1.doesFloat() == i2.doesFloat() && 115 i1.doesFloat() == i2.doesFloat() &&
115 i1.duration() == i2.duration() && 116 i1.duration() == i2.duration() &&
116 i1.hasDuration() == i2.hasDuration() && 117 i1.hasDuration() == i2.hasDuration() &&
117 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 118 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
118 // no need to compare mObserver 119 // no need to compare mObserver
119} 120}
120 121
121 122
122QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 123QDateTime IncidenceBase::getEvenTime( QDateTime dt )
123{ 124{
124 QTime t = dt.time(); 125 QTime t = dt.time();
125 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 126 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
126 return dt; 127 return dt;
127} 128}
128 129
129 130
130void IncidenceBase::setUid(const QString &uid) 131void IncidenceBase::setUid(const QString &uid)
131{ 132{
132 mUid = uid; 133 mUid = uid;
133 updated(); 134 updated();
134} 135}
135 136
136QString IncidenceBase::uid() const 137QString IncidenceBase::uid() const
137{ 138{
138 return mUid; 139 return mUid;
139} 140}
140 141
141void IncidenceBase::setLastModified(const QDateTime &lm) 142void IncidenceBase::setLastModified(const QDateTime &lm)
142{ 143{
143 // DON'T! updated() because we call this from 144 // DON'T! updated() because we call this from
144 // Calendar::updateEvent(). 145 // Calendar::updateEvent().
145 mLastModified = getEvenTime(lm); 146 mLastModified = getEvenTime(lm);
146 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 147 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
147} 148}
148 149
149QDateTime IncidenceBase::lastModified() const 150QDateTime IncidenceBase::lastModified() const
150{ 151{
151 return mLastModified; 152 return mLastModified;
152} 153}
153 154
154void IncidenceBase::setOrganizer(const QString &o) 155void IncidenceBase::setOrganizer(const QString &o)
155{ 156{
156 // we don't check for readonly here, because it is 157 // we don't check for readonly here, because it is
157 // possible that by setting the organizer we are changing 158 // possible that by setting the organizer we are changing
158 // the event's readonly status... 159 // the event's readonly status...
159 mOrganizer = o; 160 mOrganizer = o;
160 if (mOrganizer.left(7).upper() == "MAILTO:") 161 if (mOrganizer.left(7).upper() == "MAILTO:")
161 mOrganizer = mOrganizer.remove(0,7); 162 mOrganizer = mOrganizer.remove(0,7);
162 163
163 updated(); 164 updated();
164} 165}
165 166
166QString IncidenceBase::organizer() const 167QString IncidenceBase::organizer() const
167{ 168{
168 return mOrganizer; 169 return mOrganizer;
169} 170}
170 171
171void IncidenceBase::setReadOnly( bool readOnly ) 172void IncidenceBase::setReadOnly( bool readOnly )
172{ 173{
173 mReadOnly = readOnly; 174 mReadOnly = readOnly;
174} 175}
175 176
176void IncidenceBase::setDtStart(const QDateTime &dtStart) 177void IncidenceBase::setDtStart(const QDateTime &dtStart)
177{ 178{
178// if (mReadOnly) return; 179// if (mReadOnly) return;
179 mDtStart = getEvenTime(dtStart); 180 mDtStart = getEvenTime(dtStart);
180 updated(); 181 updated();
181} 182}
182 183
183QDateTime IncidenceBase::dtStart() const 184QDateTime IncidenceBase::dtStart() const
184{ 185{
185 return mDtStart; 186 return mDtStart;
186} 187}
187 188
188QString IncidenceBase::dtStartTimeStr() const 189QString IncidenceBase::dtStartTimeStr() const
189{ 190{
190 return KGlobal::locale()->formatTime(dtStart().time()); 191 return KGlobal::locale()->formatTime(dtStart().time());
191} 192}
192 193
193QString IncidenceBase::dtStartDateStr(bool shortfmt) const 194QString IncidenceBase::dtStartDateStr(bool shortfmt) const
194{ 195{
195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 196 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
196} 197}
197 198
198QString IncidenceBase::dtStartStr(bool shortfmt) const 199QString IncidenceBase::dtStartStr(bool shortfmt) const
199{ 200{
200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 201 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
201} 202}
202 203
203 204
204bool IncidenceBase::doesFloat() const 205bool IncidenceBase::doesFloat() const
205{ 206{
206 return mFloats; 207 return mFloats;
207} 208}
208 209
209void IncidenceBase::setFloats(bool f) 210void IncidenceBase::setFloats(bool f)
210{ 211{
211 if (mReadOnly) return; 212 if (mReadOnly) return;
212 mFloats = f; 213 mFloats = f;
213 updated(); 214 updated();
214} 215}
215 216
216 217
217void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 218void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
218{ 219{
219 if (mReadOnly) return; 220 if (mReadOnly) return;
220 if (a->name().left(7).upper() == "MAILTO:") 221 if (a->name().left(7).upper() == "MAILTO:")
221 a->setName(a->name().remove(0,7)); 222 a->setName(a->name().remove(0,7));
222 223
223 mAttendees.append(a); 224 mAttendees.append(a);
224 if (doupdate) updated(); 225 if (doupdate) updated();
225} 226}
226 227
227#if 0 228#if 0
228void IncidenceBase::removeAttendee(Attendee *a) 229void IncidenceBase::removeAttendee(Attendee *a)
229{ 230{
230 if (mReadOnly) return; 231 if (mReadOnly) return;
231 mAttendees.removeRef(a); 232 mAttendees.removeRef(a);
232 updated(); 233 updated();
233} 234}
234 235
235void IncidenceBase::removeAttendee(const char *n) 236void IncidenceBase::removeAttendee(const char *n)
236{ 237{
237 Attendee *a; 238 Attendee *a;
238 239
239 if (mReadOnly) return; 240 if (mReadOnly) return;
240 for (a = mAttendees.first(); a; a = mAttendees.next()) 241 for (a = mAttendees.first(); a; a = mAttendees.next())
241 if (a->getName() == n) { 242 if (a->getName() == n) {
242 mAttendees.remove(); 243 mAttendees.remove();
243 break; 244 break;
244 } 245 }
245} 246}
246#endif 247#endif
247 248
248void IncidenceBase::clearAttendees() 249void IncidenceBase::clearAttendees()
249{ 250{
250 if (mReadOnly) return; 251 if (mReadOnly) return;
251 mAttendees.clear(); 252 mAttendees.clear();
252} 253}
253 254
254#if 0 255#if 0
255Attendee *IncidenceBase::getAttendee(const char *n) const 256Attendee *IncidenceBase::getAttendee(const char *n) const
256{ 257{
257 QPtrListIterator<Attendee> qli(mAttendees); 258 QPtrListIterator<Attendee> qli(mAttendees);
258 259
259 qli.toFirst(); 260 qli.toFirst();
260 while (qli) { 261 while (qli) {
261 if (qli.current()->getName() == n) 262 if (qli.current()->getName() == n)
262 return qli.current(); 263 return qli.current();
263 ++qli; 264 ++qli;
264 } 265 }
265 return 0L; 266 return 0L;
266} 267}
267#endif 268#endif
268 269
269Attendee *IncidenceBase::attendeeByMail(const QString &email) 270Attendee *IncidenceBase::attendeeByMail(const QString &email)
270{ 271{
271 QPtrListIterator<Attendee> qli(mAttendees); 272 QPtrListIterator<Attendee> qli(mAttendees);
272 273
273 qli.toFirst(); 274 qli.toFirst();
274 while (qli) { 275 while (qli) {
275 if (qli.current()->email() == email) 276 if (qli.current()->email() == email)
276 return qli.current(); 277 return qli.current();
277 ++qli; 278 ++qli;
278 } 279 }
279 return 0L; 280 return 0L;
280} 281}
281 282
282Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 283Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
283{ 284{
284 QPtrListIterator<Attendee> qli(mAttendees); 285 QPtrListIterator<Attendee> qli(mAttendees);
285 286
286 QStringList mails = emails; 287 QStringList mails = emails;
287 if (!email.isEmpty()) { 288 if (!email.isEmpty()) {
288 mails.append(email); 289 mails.append(email);
289 } 290 }
290 qli.toFirst(); 291 qli.toFirst();
291 while (qli) { 292 while (qli) {
292 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 293 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
293 if (qli.current()->email() == *it) 294 if (qli.current()->email() == *it)
294 return qli.current(); 295 return qli.current();
295 } 296 }
296 297
297 ++qli; 298 ++qli;
298 } 299 }
299 return 0L; 300 return 0L;
300} 301}
301 302
302void IncidenceBase::setDuration(int seconds) 303void IncidenceBase::setDuration(int seconds)
303{ 304{
304 mDuration = seconds; 305 mDuration = seconds;
305 setHasDuration(true); 306 setHasDuration(true);
306} 307}
307 308
308int IncidenceBase::duration() const 309int IncidenceBase::duration() const
309{ 310{
310 return mDuration; 311 return mDuration;
311} 312}
312 313
313void IncidenceBase::setHasDuration(bool b) 314void IncidenceBase::setHasDuration(bool b)
314{ 315{
315 mHasDuration = b; 316 mHasDuration = b;
316} 317}
317 318
318bool IncidenceBase::hasDuration() const 319bool IncidenceBase::hasDuration() const
319{ 320{
320 return mHasDuration; 321 return mHasDuration;
321} 322}
322 323
323void IncidenceBase::setSyncStatus(int stat) 324void IncidenceBase::setSyncStatus(int stat)
324{ 325{
325 if (mReadOnly) return; 326 if (mReadOnly) return;
326 mSyncStatus = stat; 327 mSyncStatus = stat;
327} 328}
328 329
329int IncidenceBase::syncStatus() const 330int IncidenceBase::syncStatus() const
330{ 331{
331 return mSyncStatus; 332 return mSyncStatus;
332} 333}
333 334
334void IncidenceBase::setPilotId( int id ) 335void IncidenceBase::setPilotId( int id )
335{ 336{
336 if (mReadOnly) return; 337 if (mReadOnly) return;
337 mPilotId = id; 338 mPilotId = id;
338} 339}
339 340
340int IncidenceBase::pilotId() const 341int IncidenceBase::pilotId() const
341{ 342{
342 return mPilotId; 343 return mPilotId;
343} 344}
344void IncidenceBase::setZaurusId( int id ) 345void IncidenceBase::setZaurusId( int id )
345{ 346{
346 if (mReadOnly) return; 347 if (mReadOnly) return;
347 mZaurusId = id; 348 mZaurusId = id;
348} 349}
349 350
350int IncidenceBase::zaurusId() const 351int IncidenceBase::zaurusId() const
351{ 352{
352 return mZaurusId; 353 return mZaurusId;
353} 354}
354 355
355int IncidenceBase::zaurusUid() const 356int IncidenceBase::zaurusUid() const
356{ 357{
357 return mZaurusUid; 358 return mZaurusUid;
358} 359}
359void IncidenceBase::setZaurusUid( int id ) 360void IncidenceBase::setZaurusUid( int id )
360{ 361{
361 if (mReadOnly) return; 362 if (mReadOnly) return;
362 mZaurusUid = id; 363 mZaurusUid = id;
363} 364}
364 365
365int IncidenceBase::tempSyncStat() const 366int IncidenceBase::tempSyncStat() const
366{ 367{
367 return mTempSyncStat; 368 return mTempSyncStat;
368} 369}
369void IncidenceBase::setTempSyncStat( int id ) 370void IncidenceBase::setTempSyncStat( int id )
370{ 371{
371 if (mReadOnly) return; 372 if (mReadOnly) return;
372 mTempSyncStat = id; 373 mTempSyncStat = id;
373} 374}
374 375
376void IncidenceBase::setID( const QString & prof , int id )
377{
378 int num = mExternalId.find( ":"+prof+";" );
379 if ( num >= 0 ) {
380 int len = prof.length()+2;
381 int end = mExternalId.find( ";", num+len );
382 if ( end > 0 ) {
383 mExternalId = mExternalId.left( num+len ) +QString::number( id)+mExternalId.mid( end );
384 } else
385 qDebug("Error in IncidenceBase::setID ");
386 } else {
387 mExternalId += prof+";"+QString::number( id) +";0:";
388 }
389}
390int IncidenceBase::getID( const QString & prof)
391{
392 int ret = -1;
393 int num = mExternalId.find(":"+ prof+";" );
394 if ( num >= 0 ) {
395 int len = prof.length()+2;
396 int end = mExternalId.find( ";", num+len );
397 if ( end > 0 ) {
398 bool ok;
399 ret = mExternalId.mid ( num + len,end-len-num).toInt( &ok );
400 if (!ok)
401 return -1;
402 }
403 }
404 return ret;
405}
406
407// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
408// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
409void IncidenceBase::setCsum( const QString & prof , int id )
410{
411 int num = mExternalId.find( ":"+prof+";");
412 if ( num >= 0 ) {
413 int len = prof.length()+2;
414 num = mExternalId.find( ";", num+len );
415 int end = mExternalId.find( ":", num+1 );
416 if ( end > 0 ) {
417 mExternalId = mExternalId.left( num ) +QString::number(id)+mExternalId.mid( end );
418 } else
419 qDebug("Error in IncidenceBase::setCsum ");
420 } else {
421 mExternalId += prof+";-1;"+QString::number( id) +":";
422 }
423}
424int IncidenceBase::getCsum( const QString & prof)
425{
426 int ret = -1;
427 int num = mExternalId.find( ":"+prof+";" );
428 if ( num >= 0 ) {
429 int len = prof.length()+2;
430 num = mExternalId.find( ";", num+len );
431 int end = mExternalId.find( ":", num+1 );
432 if ( end > 0 ) {
433 bool ok;
434 ret = mExternalId.mid ( num ,end-num).toInt( &ok );
435 if (!ok)
436 return -1;
437 }
438 }
439 return ret;
440}
441
442void IncidenceBase::setIDStr( const QString & s )
443{
444 if (mReadOnly) return;
445 mExternalId = s;
446}
447
448QString IncidenceBase::IDStr() const
449{
450 return mExternalId ;
451}
375void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 452void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
376{ 453{
377 if( !mObservers.contains(observer) ) mObservers.append( observer ); 454 if( !mObservers.contains(observer) ) mObservers.append( observer );
378} 455}
379 456
380void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 457void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
381{ 458{
382 mObservers.remove( observer ); 459 mObservers.remove( observer );
383} 460}
384 461
385void IncidenceBase::updated() 462void IncidenceBase::updated()
386{ 463{
387 QPtrListIterator<Observer> it(mObservers); 464 QPtrListIterator<Observer> it(mObservers);
388 while( it.current() ) { 465 while( it.current() ) {
389 Observer *o = it.current(); 466 Observer *o = it.current();
390 ++it; 467 ++it;
391 o->incidenceUpdated( this ); 468 o->incidenceUpdated( this );
392 } 469 }
393} 470}
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index ce6e254..2f85df6 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -1,170 +1,178 @@
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#ifndef KCAL_INCIDENCEBASE_H 20#ifndef KCAL_INCIDENCEBASE_H
21#define KCAL_INCIDENCEBASE_H 21#define KCAL_INCIDENCEBASE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29#include <qptrlist.h> 29#include <qptrlist.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "attendee.h" 32#include "attendee.h"
33 33
34namespace KCal { 34namespace KCal {
35 35
36typedef QValueList<QDate> DateList; 36typedef QValueList<QDate> DateList;
37 37
38/** 38/**
39 This class provides the base class common to all calendar components. 39 This class provides the base class common to all calendar components.
40*/ 40*/
41class IncidenceBase : public CustomProperties 41class IncidenceBase : public CustomProperties
42{ 42{
43 public: 43 public:
44 class Observer { 44 class Observer {
45 public: 45 public:
46 virtual void incidenceUpdated( IncidenceBase * ) = 0; 46 virtual void incidenceUpdated( IncidenceBase * ) = 0;
47 }; 47 };
48 48
49 IncidenceBase(); 49 IncidenceBase();
50 IncidenceBase(const IncidenceBase &); 50 IncidenceBase(const IncidenceBase &);
51 virtual ~IncidenceBase(); 51 virtual ~IncidenceBase();
52 52
53 virtual QCString type() const = 0; 53 virtual QCString type() const = 0;
54 54
55 /** Set the unique id for the event */ 55 /** Set the unique id for the event */
56 void setUid(const QString &); 56 void setUid(const QString &);
57 /** Return the unique id for the event */ 57 /** Return the unique id for the event */
58 QString uid() const; 58 QString uid() const;
59 59
60 /** Sets the time the incidence was last modified. */ 60 /** Sets the time the incidence was last modified. */
61 void setLastModified(const QDateTime &lm); 61 void setLastModified(const QDateTime &lm);
62 /** Return the time the incidence was last modified. */ 62 /** Return the time the incidence was last modified. */
63 QDateTime lastModified() const; 63 QDateTime lastModified() const;
64 64
65 /** sets the organizer for the event */ 65 /** sets the organizer for the event */
66 void setOrganizer(const QString &o); 66 void setOrganizer(const QString &o);
67 QString organizer() const; 67 QString organizer() const;
68 68
69 /** Set readonly status. */ 69 /** Set readonly status. */
70 virtual void setReadOnly( bool ); 70 virtual void setReadOnly( bool );
71 /** Return if the object is read-only. */ 71 /** Return if the object is read-only. */
72 bool isReadOnly() const { return mReadOnly; } 72 bool isReadOnly() const { return mReadOnly; }
73 73
74 /** for setting the event's starting date/time with a QDateTime. */ 74 /** for setting the event's starting date/time with a QDateTime. */
75 virtual void setDtStart(const QDateTime &dtStart); 75 virtual void setDtStart(const QDateTime &dtStart);
76 /** returns an event's starting date/time as a QDateTime. */ 76 /** returns an event's starting date/time as a QDateTime. */
77 QDateTime dtStart() const; 77 QDateTime dtStart() const;
78 /** returns an event's starting time as a string formatted according to the 78 /** returns an event's starting time as a string formatted according to the
79 users locale settings */ 79 users locale settings */
80 QString dtStartTimeStr() const; 80 QString dtStartTimeStr() const;
81 /** returns an event's starting date as a string formatted according to the 81 /** returns an event's starting date as a string formatted according to the
82 users locale settings */ 82 users locale settings */
83 QString dtStartDateStr(bool shortfmt=true) const; 83 QString dtStartDateStr(bool shortfmt=true) const;
84 /** returns an event's starting date and time as a string formatted according 84 /** returns an event's starting date and time as a string formatted according
85 to the users locale settings */ 85 to the users locale settings */
86 QString dtStartStr(bool shortfmt=true) const; 86 QString dtStartStr(bool shortfmt=true) const;
87 87
88 virtual void setDuration(int seconds); 88 virtual void setDuration(int seconds);
89 int duration() const; 89 int duration() const;
90 void setHasDuration(bool); 90 void setHasDuration(bool);
91 bool hasDuration() const; 91 bool hasDuration() const;
92 92
93 /** Return true or false depending on whether the incidence "floats," 93 /** Return true or false depending on whether the incidence "floats,"
94 * i.e. has a date but no time attached to it. */ 94 * i.e. has a date but no time attached to it. */
95 bool doesFloat() const; 95 bool doesFloat() const;
96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ 96 /** Set whether the incidence floats, i.e. has a date but no time attached to it. */
97 void setFloats(bool f); 97 void setFloats(bool f);
98 98
99 /** 99 /**
100 Add Attendee to this incidence. IncidenceBase takes ownership of the 100 Add Attendee to this incidence. IncidenceBase takes ownership of the
101 Attendee object. 101 Attendee object.
102 */ 102 */
103 void addAttendee(Attendee *a, bool doupdate=true ); 103 void addAttendee(Attendee *a, bool doupdate=true );
104// void removeAttendee(Attendee *a); 104// void removeAttendee(Attendee *a);
105// void removeAttendee(const char *n); 105// void removeAttendee(const char *n);
106 /** Remove all Attendees. */ 106 /** Remove all Attendees. */
107 void clearAttendees(); 107 void clearAttendees();
108 /** Return list of attendees. */ 108 /** Return list of attendees. */
109 QPtrList<Attendee> attendees() const { return mAttendees; }; 109 QPtrList<Attendee> attendees() const { return mAttendees; };
110 /** Return number of attendees. */ 110 /** Return number of attendees. */
111 int attendeeCount() const { return mAttendees.count(); }; 111 int attendeeCount() const { return mAttendees.count(); };
112 /** Return the Attendee with this email */ 112 /** Return the Attendee with this email */
113 Attendee* attendeeByMail(const QString &); 113 Attendee* attendeeByMail(const QString &);
114 /** Return first Attendee with one of this emails */ 114 /** Return first Attendee with one of this emails */
115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); 115 Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null);
116 116
117 /** pilot syncronization states */ 117 /** pilot syncronization states */
118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; 118 enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 };
119 /** Set synchronisation satus. */ 119 /** Set synchronisation satus. */
120 void setSyncStatus(int stat); 120 void setSyncStatus(int stat);
121 /** Return synchronisation status. */ 121 /** Return synchronisation status. */
122 int syncStatus() const; 122 int syncStatus() const;
123 123
124 /** Set Pilot Id. */ 124 /** Set Pilot Id. */
125 void setPilotId(int id); 125 void setPilotId(int id);
126 /** Return Pilot Id. */ 126 /** Return Pilot Id. */
127 int pilotId() const; 127 int pilotId() const;
128 128
129 void setZaurusId(int id); 129 void setZaurusId(int id);
130 int zaurusId() const; 130 int zaurusId() const;
131 void setZaurusUid(int id); 131 void setZaurusUid(int id);
132 int zaurusUid() const; 132 int zaurusUid() const;
133 void setTempSyncStat(int id); 133 void setTempSyncStat(int id);
134 int tempSyncStat() const; 134 int tempSyncStat() const;
135 void setIDStr( const QString & );
136 QString IDStr() const;
137 void setID( const QString &, int );
138 int getID( const QString & );
139 void setCsum( const QString &, int );
140 int getCsum( const QString & );
141
135 142
136 void registerObserver( Observer * ); 143 void registerObserver( Observer * );
137 void unRegisterObserver( Observer * ); 144 void unRegisterObserver( Observer * );
138 void updated(); 145 void updated();
139 146
140 protected: 147 protected:
141 bool mReadOnly; 148 bool mReadOnly;
142 QDateTime getEvenTime( QDateTime ); 149 QDateTime getEvenTime( QDateTime );
143 150
144 private: 151 private:
145 // base components 152 // base components
146 QDateTime mDtStart; 153 QDateTime mDtStart;
147 QString mOrganizer; 154 QString mOrganizer;
148 QString mUid; 155 QString mUid;
149 QDateTime mLastModified; 156 QDateTime mLastModified;
150 QPtrList<Attendee> mAttendees; 157 QPtrList<Attendee> mAttendees;
151 158
152 bool mFloats; 159 bool mFloats;
153 160
154 int mDuration; 161 int mDuration;
155 bool mHasDuration; 162 bool mHasDuration;
163 QString mExternalId;
156 int mZaurusId; 164 int mZaurusId;
157 int mZaurusUid; 165 int mZaurusUid;
158 int mTempSyncStat; 166 int mTempSyncStat;
159 167
160 // PILOT SYNCHRONIZATION STUFF 168 // PILOT SYNCHRONIZATION STUFF
161 int mPilotId; // unique id for pilot sync 169 int mPilotId; // unique id for pilot sync
162 int mSyncStatus; // status (for sync) 170 int mSyncStatus; // status (for sync)
163 171
164 QPtrList<Observer> mObservers; 172 QPtrList<Observer> mObservers;
165}; 173};
166 174
167bool operator==( const IncidenceBase&, const IncidenceBase& ); 175bool operator==( const IncidenceBase&, const IncidenceBase& );
168} 176}
169 177
170#endif 178#endif