summaryrefslogtreecommitdiffabout
path: root/libkcal/vcalformat.cpp
Unidiff
Diffstat (limited to 'libkcal/vcalformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 2e19740..9cbaf16 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,771 +1,773 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brwon 3 Copyright (c) 1998 Preston Brwon
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <q3ptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qclipboard.h> 27#include <qclipboard.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qfile.h> 29#include <qfile.h>
30//Added by qt3to4:
31#include <Q3CString>
30 32
31#include <kdebug.h> 33#include <kdebug.h>
32#include <kglobal.h> 34#include <kglobal.h>
33#include <kmessagebox.h> 35#include <kmessagebox.h>
34#include <kiconloader.h> 36#include <kiconloader.h>
35#include <klocale.h> 37#include <klocale.h>
36 38
37#include "vcc.h" 39#include "vcc.h"
38#include "vobject.h" 40#include "vobject.h"
39 41
40#include "vcaldrag.h" 42#include "vcaldrag.h"
41#include "calendar.h" 43#include "calendar.h"
42 44
43#include "vcalformat.h" 45#include "vcalformat.h"
44 46
45using namespace KCal; 47using namespace KCal;
46 48
47VCalFormat::VCalFormat() 49VCalFormat::VCalFormat()
48{ 50{
49 mCalendar = 0; 51 mCalendar = 0;
50 useLocalTime = false; 52 useLocalTime = false;
51} 53}
52 54
53VCalFormat::~VCalFormat() 55VCalFormat::~VCalFormat()
54{ 56{
55} 57}
56 58
57void VCalFormat::setLocalTime ( bool b ) 59void VCalFormat::setLocalTime ( bool b )
58{ 60{
59 useLocalTime = b; 61 useLocalTime = b;
60} 62}
61bool VCalFormat::load(Calendar *calendar, const QString &fileName) 63bool VCalFormat::load(Calendar *calendar, const QString &fileName)
62{ 64{
63 mCalendar = calendar; 65 mCalendar = calendar;
64 clearException(); 66 clearException();
65 if ( ! useLocalTime ) 67 if ( ! useLocalTime )
66 useLocalTime = mCalendar->isLocalTime(); 68 useLocalTime = mCalendar->isLocalTime();
67 VObject *vcal = 0; 69 VObject *vcal = 0;
68 70
69 // this is not necessarily only 1 vcal. Could be many vcals, or include 71 // this is not necessarily only 1 vcal. Could be many vcals, or include
70 // a vcard... 72 // a vcard...
71 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 73 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
72 74
73 if (!vcal) { 75 if (!vcal) {
74 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 76 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
75 return FALSE; 77 return FALSE;
76 } 78 }
77 79
78 // any other top-level calendar stuff should be added/initialized here 80 // any other top-level calendar stuff should be added/initialized here
79 81
80 // put all vobjects into their proper places 82 // put all vobjects into their proper places
81 populate(vcal); 83 populate(vcal);
82 84
83 // clean up from vcal API stuff 85 // clean up from vcal API stuff
84 cleanVObjects(vcal); 86 cleanVObjects(vcal);
85 cleanStrTbl(); 87 cleanStrTbl();
86 88
87 return true; 89 return true;
88} 90}
89 91
90 92
91bool VCalFormat::save(Calendar *calendar, const QString &fileName) 93bool VCalFormat::save(Calendar *calendar, const QString &fileName)
92{ 94{
93 mCalendar = calendar; 95 mCalendar = calendar;
94 if ( ! useLocalTime ) 96 if ( ! useLocalTime )
95 useLocalTime = mCalendar->isLocalTime(); 97 useLocalTime = mCalendar->isLocalTime();
96 98
97 QString tmpStr; 99 QString tmpStr;
98 VObject *vcal, *vo; 100 VObject *vcal, *vo;
99 101
100 102
101 vcal = newVObject(VCCalProp); 103 vcal = newVObject(VCCalProp);
102 104
103 // addPropValue(vcal,VCLocationProp, "0.0"); 105 // addPropValue(vcal,VCLocationProp, "0.0");
104 addPropValue(vcal,VCProdIdProp, productId()); 106 addPropValue(vcal,VCProdIdProp, productId());
105 tmpStr = mCalendar->getTimeZoneStr(); 107 tmpStr = mCalendar->getTimeZoneStr();
106 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 108 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
107 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 109 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
108 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 110 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
109 111
110 // TODO STUFF 112 // TODO STUFF
111 QPtrList<Todo> todoList = mCalendar->rawTodos(); 113 Q3PtrList<Todo> todoList = mCalendar->rawTodos();
112 QPtrListIterator<Todo> qlt(todoList); 114 Q3PtrListIterator<Todo> qlt(todoList);
113 for (; qlt.current(); ++qlt) { 115 for (; qlt.current(); ++qlt) {
114 vo = eventToVTodo(qlt.current()); 116 vo = eventToVTodo(qlt.current());
115 addVObjectProp(vcal, vo); 117 addVObjectProp(vcal, vo);
116 } 118 }
117 119
118 // EVENT STUFF 120 // EVENT STUFF
119 QPtrList<Event> events = mCalendar->rawEvents(); 121 Q3PtrList<Event> events = mCalendar->rawEvents();
120 Event *ev; 122 Event *ev;
121 for(ev=events.first();ev;ev=events.next()) { 123 for(ev=events.first();ev;ev=events.next()) {
122 vo = eventToVEvent(ev); 124 vo = eventToVEvent(ev);
123 addVObjectProp(vcal, vo); 125 addVObjectProp(vcal, vo);
124 } 126 }
125 127
126 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 128 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
127 cleanVObjects(vcal); 129 cleanVObjects(vcal);
128 cleanStrTbl(); 130 cleanStrTbl();
129 131
130 if (QFile::exists(fileName)) { 132 if (QFile::exists(fileName)) {
131 return true; 133 return true;
132 } else { 134 } else {
133 return false; // error 135 return false; // error
134 } 136 }
135} 137}
136 138
137bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 139bool VCalFormat::fromString( Calendar *calendar, const QString &text )
138{ 140{
139 // TODO: Factor out VCalFormat::fromString() 141 // TODO: Factor out VCalFormat::fromString()
140 142
141 QCString data = text.utf8(); 143 Q3CString data = text.utf8();
142 144
143 if ( !data.size() ) return false; 145 if ( !data.size() ) return false;
144 146
145 VObject *vcal = Parse_MIME( data.data(), data.size()); 147 VObject *vcal = Parse_MIME( data.data(), data.size());
146 if ( !vcal ) return false; 148 if ( !vcal ) return false;
147 149
148 VObjectIterator i; 150 VObjectIterator i;
149 VObject *curvo; 151 VObject *curvo;
150 initPropIterator( &i, vcal ); 152 initPropIterator( &i, vcal );
151 153
152 // we only take the first object. TODO: parse all incidences. 154 // we only take the first object. TODO: parse all incidences.
153 do { 155 do {
154 curvo = nextVObject( &i ); 156 curvo = nextVObject( &i );
155 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 157 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
156 strcmp( vObjectName( curvo ), VCTodoProp ) ); 158 strcmp( vObjectName( curvo ), VCTodoProp ) );
157 159
158 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 160 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
159 Event *event = VEventToEvent( curvo ); 161 Event *event = VEventToEvent( curvo );
160 calendar->addEvent( event ); 162 calendar->addEvent( event );
161 } else { 163 } else {
162 qDebug("VCalFormat::fromString(): Unknown object type. "); 164 qDebug("VCalFormat::fromString(): Unknown object type. ");
163 deleteVObject( vcal ); 165 deleteVObject( vcal );
164 return false; 166 return false;
165 } 167 }
166 168
167 deleteVObject( vcal ); 169 deleteVObject( vcal );
168 170
169 return true; 171 return true;
170} 172}
171 173
172QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) 174QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
173{ 175{
174 176
175 if ( !event ) return QString::null; 177 if ( !event ) return QString::null;
176 bool useL = useLocalTime; 178 bool useL = useLocalTime;
177 useLocalTime = useLocal; 179 useLocalTime = useLocal;
178 mCalendar = calendar; 180 mCalendar = calendar;
179 VObject *vevent = eventToVEvent( event ); 181 VObject *vevent = eventToVEvent( event );
180 char *buf = writeMemVObject( 0, 0, vevent ); 182 char *buf = writeMemVObject( 0, 0, vevent );
181 QString result( buf ); 183 QString result( buf );
182 cleanVObject( vevent ); 184 cleanVObject( vevent );
183 useLocalTime = useL; 185 useLocalTime = useL;
184 return result; 186 return result;
185} 187}
186QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) 188QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
187{ 189{
188 190
189 if ( !todo ) return QString::null; 191 if ( !todo ) return QString::null;
190 bool useL = useLocalTime; 192 bool useL = useLocalTime;
191 useLocalTime = useLocal; 193 useLocalTime = useLocal;
192 mCalendar = calendar; 194 mCalendar = calendar;
193 VObject *vevent = eventToVTodo( todo ); 195 VObject *vevent = eventToVTodo( todo );
194 char *buf = writeMemVObject( 0, 0, vevent ); 196 char *buf = writeMemVObject( 0, 0, vevent );
195 QString result( buf ); 197 QString result( buf );
196 cleanVObject( vevent ); 198 cleanVObject( vevent );
197 useLocalTime = useL; 199 useLocalTime = useL;
198 return result; 200 return result;
199} 201}
200 202
201QString VCalFormat::toString( Calendar *calendar ) 203QString VCalFormat::toString( Calendar *calendar )
202{ 204{
203 // TODO: Factor out VCalFormat::asString() 205 // TODO: Factor out VCalFormat::asString()
204 206
205 VObject *vcal = newVObject(VCCalProp); 207 VObject *vcal = newVObject(VCCalProp);
206 208
207 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 209 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
208 QString tmpStr = mCalendar->getTimeZoneStr(); 210 QString tmpStr = mCalendar->getTimeZoneStr();
209 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 211 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
210 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 212 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
211 213
212 // TODO: Use all data. 214 // TODO: Use all data.
213 QPtrList<Event> events = calendar->events(); 215 Q3PtrList<Event> events = calendar->events();
214 Event *event = events.first(); 216 Event *event = events.first();
215 if ( !event ) return QString::null; 217 if ( !event ) return QString::null;
216 218
217 VObject *vevent = eventToVEvent( event ); 219 VObject *vevent = eventToVEvent( event );
218 220
219 addVObjectProp( vcal, vevent ); 221 addVObjectProp( vcal, vevent );
220 222
221 char *buf = writeMemVObject( 0, 0, vcal ); 223 char *buf = writeMemVObject( 0, 0, vcal );
222 224
223 QString result( buf ); 225 QString result( buf );
224 226
225 cleanVObject( vcal ); 227 cleanVObject( vcal );
226 228
227 return result; 229 return result;
228} 230}
229 231
230VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 232VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
231{ 233{
232 VObject *vtodo; 234 VObject *vtodo;
233 QString tmpStr; 235 QString tmpStr;
234 236
235 237
236 vtodo = newVObject(VCTodoProp); 238 vtodo = newVObject(VCTodoProp);
237 239
238 // due date 240 // due date
239 if (anEvent->hasDueDate()) { 241 if (anEvent->hasDueDate()) {
240 tmpStr = qDateTimeToISO(anEvent->dtDue(), 242 tmpStr = qDateTimeToISO(anEvent->dtDue(),
241 !anEvent->doesFloat()); 243 !anEvent->doesFloat());
242 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 244 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
243 } 245 }
244 246
245 // start date 247 // start date
246 if (anEvent->hasStartDate()) { 248 if (anEvent->hasStartDate()) {
247 tmpStr = qDateTimeToISO(anEvent->dtStart(), 249 tmpStr = qDateTimeToISO(anEvent->dtStart(),
248 !anEvent->doesFloat()); 250 !anEvent->doesFloat());
249 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 251 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
250 } 252 }
251 253
252 // creation date 254 // creation date
253 tmpStr = qDateTimeToISO(anEvent->created()); 255 tmpStr = qDateTimeToISO(anEvent->created());
254 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 256 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
255 257
256 // unique id 258 // unique id
257 addPropValue(vtodo, VCUniqueStringProp, 259 addPropValue(vtodo, VCUniqueStringProp,
258 anEvent->uid().local8Bit()); 260 anEvent->uid().local8Bit());
259 261
260 // revision 262 // revision
261 tmpStr.sprintf("%i", anEvent->revision()); 263 tmpStr.sprintf("%i", anEvent->revision());
262 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 264 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
263 265
264 // last modification date 266 // last modification date
265 tmpStr = qDateTimeToISO(anEvent->lastModified()); 267 tmpStr = qDateTimeToISO(anEvent->lastModified());
266 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 268 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
267 269
268 // organizer stuff 270 // organizer stuff
269 tmpStr = "MAILTO:" + anEvent->organizer(); 271 tmpStr = "MAILTO:" + anEvent->organizer();
270 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 272 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
271 273
272 // attendees 274 // attendees
273 if (anEvent->attendeeCount() != 0) { 275 if (anEvent->attendeeCount() != 0) {
274 QPtrList<Attendee> al = anEvent->attendees(); 276 Q3PtrList<Attendee> al = anEvent->attendees();
275 QPtrListIterator<Attendee> ai(al); 277 Q3PtrListIterator<Attendee> ai(al);
276 Attendee *curAttendee; 278 Attendee *curAttendee;
277 279
278 for (; ai.current(); ++ai) { 280 for (; ai.current(); ++ai) {
279 curAttendee = ai.current(); 281 curAttendee = ai.current();
280 if (!curAttendee->email().isEmpty() && 282 if (!curAttendee->email().isEmpty() &&
281 !curAttendee->name().isEmpty()) 283 !curAttendee->name().isEmpty())
282 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 284 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
283 curAttendee->email() + ">"; 285 curAttendee->email() + ">";
284 else if (curAttendee->name().isEmpty()) 286 else if (curAttendee->name().isEmpty())
285 tmpStr = "MAILTO: " + curAttendee->email(); 287 tmpStr = "MAILTO: " + curAttendee->email();
286 else if (curAttendee->email().isEmpty()) 288 else if (curAttendee->email().isEmpty())
287 tmpStr = "MAILTO: " + curAttendee->name(); 289 tmpStr = "MAILTO: " + curAttendee->name();
288 else if (curAttendee->name().isEmpty() && 290 else if (curAttendee->name().isEmpty() &&
289 curAttendee->email().isEmpty()) 291 curAttendee->email().isEmpty())
290 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 292 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
291 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 293 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
292 addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); 294 addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role()));
293 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 295 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
294 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 296 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
295 } 297 }
296 } 298 }
297 299
298 // description BL: 300 // description BL:
299 if (!anEvent->description().isEmpty()) { 301 if (!anEvent->description().isEmpty()) {
300 VObject *d = addPropValue(vtodo, VCDescriptionProp, 302 VObject *d = addPropValue(vtodo, VCDescriptionProp,
301 anEvent->description().local8Bit()); 303 anEvent->description().local8Bit());
302 if (anEvent->description().find('\n') != -1) 304 if (anEvent->description().find('\n') != -1)
303 addProp(d, VCQuotedPrintableProp); 305 addProp(d, VCQuotedPrintableProp);
304 } 306 }
305 307
306 // summary 308 // summary
307 if (!anEvent->summary().isEmpty()) 309 if (!anEvent->summary().isEmpty())
308 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 310 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
309 311
310 if (!anEvent->location().isEmpty()) 312 if (!anEvent->location().isEmpty())
311 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 313 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
312 314
313 // completed 315 // completed
314 // status 316 // status
315 // backward compatibility, KOrganizer used to interpret only these two values 317 // backward compatibility, KOrganizer used to interpret only these two values
316 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 318 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
317 "NEEDS_ACTION"); 319 "NEEDS_ACTION");
318 // completion date 320 // completion date
319 if (anEvent->hasCompletedDate()) { 321 if (anEvent->hasCompletedDate()) {
320 tmpStr = qDateTimeToISO(anEvent->completed()); 322 tmpStr = qDateTimeToISO(anEvent->completed());
321 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 323 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
322 } 324 }
323 325
324 // priority 326 // priority
325 tmpStr.sprintf("%i",anEvent->priority()); 327 tmpStr.sprintf("%i",anEvent->priority());
326 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 328 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
327 329
328 // related event 330 // related event
329 if (anEvent->relatedToUid()) { 331 if (!anEvent->relatedToUid().isEmpty()) {
330 addPropValue(vtodo, VCRelatedToProp, 332 addPropValue(vtodo, VCRelatedToProp,
331 anEvent->relatedToUid().local8Bit()); 333 anEvent->relatedToUid().local8Bit());
332 } 334 }
333 335
334 // categories 336 // categories
335 QStringList tmpStrList = anEvent->categories(); 337 QStringList tmpStrList = anEvent->categories();
336 tmpStr = ""; 338 tmpStr = "";
337 QString catStr; 339 QString catStr;
338 for ( QStringList::Iterator it = tmpStrList.begin(); 340 for ( QStringList::Iterator it = tmpStrList.begin();
339 it != tmpStrList.end(); 341 it != tmpStrList.end();
340 ++it ) { 342 ++it ) {
341 catStr = *it; 343 catStr = *it;
342 if (catStr[0] == ' ') 344 if (catStr[0] == ' ')
343 tmpStr += catStr.mid(1); 345 tmpStr += catStr.mid(1);
344 else 346 else
345 tmpStr += catStr; 347 tmpStr += catStr;
346 // this must be a ';' character as the vCalendar specification requires! 348 // this must be a ';' character as the vCalendar specification requires!
347 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 349 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
348 // read in. 350 // read in.
349 tmpStr += ";"; 351 tmpStr += ";";
350 } 352 }
351 if (!tmpStr.isEmpty()) { 353 if (!tmpStr.isEmpty()) {
352 tmpStr.truncate(tmpStr.length()-1); 354 tmpStr.truncate(tmpStr.length()-1);
353 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 355 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
354 } 356 }
355 357
356 // alarm stuff 358 // alarm stuff
357 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 359 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
358 QPtrList<Alarm> alarms = anEvent->alarms(); 360 Q3PtrList<Alarm> alarms = anEvent->alarms();
359 Alarm* alarm; 361 Alarm* alarm;
360 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 362 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
361 if (alarm->enabled()) { 363 if (alarm->enabled()) {
362 VObject *a; 364 VObject *a;
363 tmpStr = qDateTimeToISO(alarm->time()); 365 tmpStr = qDateTimeToISO(alarm->time());
364 if (alarm->type() == Alarm::Audio) { 366 if (alarm->type() == Alarm::Audio) {
365 a = addProp(vtodo, VCAAlarmProp); 367 a = addProp(vtodo, VCAAlarmProp);
366 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 368 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
367 addPropValue(a, VCRepeatCountProp, "1"); 369 addPropValue(a, VCRepeatCountProp, "1");
368 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 370 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
369 } 371 }
370 else if (alarm->type() == Alarm::Procedure) { 372 else if (alarm->type() == Alarm::Procedure) {
371 a = addProp(vtodo, VCPAlarmProp); 373 a = addProp(vtodo, VCPAlarmProp);
372 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 374 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
373 addPropValue(a, VCRepeatCountProp, "1"); 375 addPropValue(a, VCRepeatCountProp, "1");
374 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 376 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
375 } else { 377 } else {
376 a = addProp(vtodo, VCDAlarmProp); 378 a = addProp(vtodo, VCDAlarmProp);
377 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 379 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
378 addPropValue(a, VCRepeatCountProp, "1"); 380 addPropValue(a, VCRepeatCountProp, "1");
379 addPropValue(a, VCDisplayStringProp, "beep!"); 381 addPropValue(a, VCDisplayStringProp, "beep!");
380 } 382 }
381 } 383 }
382 } 384 }
383 385
384 if (anEvent->pilotId()) { 386 if (anEvent->pilotId()) {
385 // pilot sync stuff 387 // pilot sync stuff
386 tmpStr.sprintf("%i",anEvent->pilotId()); 388 tmpStr.sprintf("%i",anEvent->pilotId());
387 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 389 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
388 tmpStr.sprintf("%i",anEvent->syncStatus()); 390 tmpStr.sprintf("%i",anEvent->syncStatus());
389 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 391 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
390 } 392 }
391 393
392 return vtodo; 394 return vtodo;
393} 395}
394 396
395VObject* VCalFormat::eventToVEvent(Event *anEvent) 397VObject* VCalFormat::eventToVEvent(Event *anEvent)
396{ 398{
397 VObject *vevent; 399 VObject *vevent;
398 QString tmpStr; 400 QString tmpStr;
399 401
400 vevent = newVObject(VCEventProp); 402 vevent = newVObject(VCEventProp);
401 403
402 // start and end time 404 // start and end time
403 tmpStr = qDateTimeToISO(anEvent->dtStart(), 405 tmpStr = qDateTimeToISO(anEvent->dtStart(),
404 !anEvent->doesFloat()); 406 !anEvent->doesFloat());
405 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 407 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
406 408
407 // events that have time associated but take up no time should 409 // events that have time associated but take up no time should
408 // not have both DTSTART and DTEND. 410 // not have both DTSTART and DTEND.
409 if (anEvent->dtStart() != anEvent->dtEnd()) { 411 if (anEvent->dtStart() != anEvent->dtEnd()) {
410 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 412 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
411 !anEvent->doesFloat()); 413 !anEvent->doesFloat());
412 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 414 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
413 } 415 }
414 416
415 // creation date 417 // creation date
416 tmpStr = qDateTimeToISO(anEvent->created()); 418 tmpStr = qDateTimeToISO(anEvent->created());
417 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 419 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
418 420
419 // unique id 421 // unique id
420 addPropValue(vevent, VCUniqueStringProp, 422 addPropValue(vevent, VCUniqueStringProp,
421 anEvent->uid().local8Bit()); 423 anEvent->uid().local8Bit());
422 424
423 // revision 425 // revision
424 tmpStr.sprintf("%i", anEvent->revision()); 426 tmpStr.sprintf("%i", anEvent->revision());
425 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 427 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
426 428
427 // last modification date 429 // last modification date
428 tmpStr = qDateTimeToISO(anEvent->lastModified()); 430 tmpStr = qDateTimeToISO(anEvent->lastModified());
429 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 431 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
430 432
431 // attendee and organizer stuff 433 // attendee and organizer stuff
432 tmpStr = "MAILTO:" + anEvent->organizer(); 434 tmpStr = "MAILTO:" + anEvent->organizer();
433 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 435 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
434 436
435 if (anEvent->attendeeCount() != 0) { 437 if (anEvent->attendeeCount() != 0) {
436 QPtrList<Attendee> al = anEvent->attendees(); 438 Q3PtrList<Attendee> al = anEvent->attendees();
437 QPtrListIterator<Attendee> ai(al); 439 Q3PtrListIterator<Attendee> ai(al);
438 Attendee *curAttendee; 440 Attendee *curAttendee;
439 441
440 // TODO: Put this functionality into Attendee class 442 // TODO: Put this functionality into Attendee class
441 for (; ai.current(); ++ai) { 443 for (; ai.current(); ++ai) {
442 curAttendee = ai.current(); 444 curAttendee = ai.current();
443 if (!curAttendee->email().isEmpty() && 445 if (!curAttendee->email().isEmpty() &&
444 !curAttendee->name().isEmpty()) 446 !curAttendee->name().isEmpty())
445 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 447 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
446 curAttendee->email() + ">"; 448 curAttendee->email() + ">";
447 else if (curAttendee->name().isEmpty()) 449 else if (curAttendee->name().isEmpty())
448 tmpStr = "MAILTO: " + curAttendee->email(); 450 tmpStr = "MAILTO: " + curAttendee->email();
449 else if (curAttendee->email().isEmpty()) 451 else if (curAttendee->email().isEmpty())
450 tmpStr = "MAILTO: " + curAttendee->name(); 452 tmpStr = "MAILTO: " + curAttendee->name();
451 else if (curAttendee->name().isEmpty() && 453 else if (curAttendee->name().isEmpty() &&
452 curAttendee->email().isEmpty()) 454 curAttendee->email().isEmpty())
453 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 455 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
454 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 456 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
455 addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role())); 457 addPropValue(aProp, VCRoleProp, writeRole(curAttendee->role()));
456 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 458 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
457 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 459 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
458 } 460 }
459 } 461 }
460 462
461 // recurrence rule stuff 463 // recurrence rule stuff
462 if (anEvent->doesRecur()) { 464 if (anEvent->doesRecur()) {
463 // some more variables 465 // some more variables
464 QPtrList<Recurrence::rMonthPos> tmpPositions; 466 Q3PtrList<Recurrence::rMonthPos> tmpPositions;
465 QPtrList<int> tmpDays; 467 Q3PtrList<int> tmpDays;
466 int *tmpDay; 468 int *tmpDay;
467 Recurrence::rMonthPos *tmpPos; 469 Recurrence::rMonthPos *tmpPos;
468 QString tmpStr2; 470 QString tmpStr2;
469 int i; 471 int i;
470 472
471 switch(anEvent->recurrence()->doesRecur()) { 473 switch(anEvent->recurrence()->doesRecur()) {
472 case Recurrence::rDaily: 474 case Recurrence::rDaily:
473 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 475 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
474// if (anEvent->rDuration > 0) 476// if (anEvent->rDuration > 0)
475 //tmpStr += "#"; 477 //tmpStr += "#";
476 break; 478 break;
477 case Recurrence::rWeekly: 479 case Recurrence::rWeekly:
478 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); 480 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency());
479 for (i = 0; i < 7; i++) { 481 for (i = 0; i < 7; i++) {
480 if (anEvent->recurrence()->days().testBit(i)) 482 if (anEvent->recurrence()->days().testBit(i))
481 tmpStr += dayFromNum(i); 483 tmpStr += dayFromNum(i);
482 } 484 }
483 break; 485 break;
484 case Recurrence::rMonthlyPos: 486 case Recurrence::rMonthlyPos:
485 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); 487 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency());
486 // write out all rMonthPos's 488 // write out all rMonthPos's
487 tmpPositions = anEvent->recurrence()->monthPositions(); 489 tmpPositions = anEvent->recurrence()->monthPositions();
488 for (tmpPos = tmpPositions.first(); 490 for (tmpPos = tmpPositions.first();
489 tmpPos; 491 tmpPos;
490 tmpPos = tmpPositions.next()) { 492 tmpPos = tmpPositions.next()) {
491 493
492 tmpStr2.sprintf("%i", tmpPos->rPos); 494 tmpStr2.sprintf("%i", tmpPos->rPos);
493 if (tmpPos->negative) 495 if (tmpPos->negative)
494 tmpStr2 += "- "; 496 tmpStr2 += "- ";
495 else 497 else
496 tmpStr2 += "+ "; 498 tmpStr2 += "+ ";
497 tmpStr += tmpStr2; 499 tmpStr += tmpStr2;
498 for (i = 0; i < 7; i++) { 500 for (i = 0; i < 7; i++) {
499 if (tmpPos->rDays.testBit(i)) 501 if (tmpPos->rDays.testBit(i))
500 tmpStr += dayFromNum(i); 502 tmpStr += dayFromNum(i);
501 } 503 }
502 } // loop for all rMonthPos's 504 } // loop for all rMonthPos's
503 break; 505 break;
504 case Recurrence::rMonthlyDay: 506 case Recurrence::rMonthlyDay:
505 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); 507 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency());
506 // write out all rMonthDays; 508 // write out all rMonthDays;
507 tmpDays = anEvent->recurrence()->monthDays(); 509 tmpDays = anEvent->recurrence()->monthDays();
508 for (tmpDay = tmpDays.first(); 510 for (tmpDay = tmpDays.first();
509 tmpDay; 511 tmpDay;
510 tmpDay = tmpDays.next()) { 512 tmpDay = tmpDays.next()) {
511 tmpStr2.sprintf("%i ", *tmpDay); 513 tmpStr2.sprintf("%i ", *tmpDay);
512 tmpStr += tmpStr2; 514 tmpStr += tmpStr2;
513 } 515 }
514 break; 516 break;
515 case Recurrence::rYearlyMonth: 517 case Recurrence::rYearlyMonth:
516 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); 518 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency());
517 // write out all the rYearNums; 519 // write out all the rYearNums;
518 tmpDays = anEvent->recurrence()->yearNums(); 520 tmpDays = anEvent->recurrence()->yearNums();
519 for (tmpDay = tmpDays.first(); 521 for (tmpDay = tmpDays.first();
520 tmpDay; 522 tmpDay;
521 tmpDay = tmpDays.next()) { 523 tmpDay = tmpDays.next()) {
522 tmpStr2.sprintf("%i ", *tmpDay); 524 tmpStr2.sprintf("%i ", *tmpDay);
523 tmpStr += tmpStr2; 525 tmpStr += tmpStr2;
524 } 526 }
525 break; 527 break;
526 case Recurrence::rYearlyDay: 528 case Recurrence::rYearlyDay:
527 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); 529 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency());
528 // write out all the rYearNums; 530 // write out all the rYearNums;
529 tmpDays = anEvent->recurrence()->yearNums(); 531 tmpDays = anEvent->recurrence()->yearNums();
530 for (tmpDay = tmpDays.first(); 532 for (tmpDay = tmpDays.first();
531 tmpDay; 533 tmpDay;
532 tmpDay = tmpDays.next()) { 534 tmpDay = tmpDays.next()) {
533 tmpStr2.sprintf("%i ", *tmpDay); 535 tmpStr2.sprintf("%i ", *tmpDay);
534 tmpStr += tmpStr2; 536 tmpStr += tmpStr2;
535 } 537 }
536 break; 538 break;
537 default: 539 default:
538 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; 540 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl;
539 break; 541 break;
540 } // switch 542 } // switch
541 543
542 if (anEvent->recurrence()->duration() > 0) { 544 if (anEvent->recurrence()->duration() > 0) {
543 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); 545 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration());
544 tmpStr += tmpStr2; 546 tmpStr += tmpStr2;
545 } else if (anEvent->recurrence()->duration() == -1) { 547 } else if (anEvent->recurrence()->duration() == -1) {
546 tmpStr += "#0"; // defined as repeat forever 548 tmpStr += "#0"; // defined as repeat forever
547 } else { 549 } else {
548 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); 550 tmpStr += qDateTimeToISO((QDateTime)anEvent->recurrence()->endDate(), FALSE);
549 } 551 }
550 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); 552 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
551 553
552 } // event repeats 554 } // event repeats
553 555
554 // exceptions to recurrence 556 // exceptions to recurrence
555 DateList dateList = anEvent->exDates(); 557 DateList dateList = anEvent->exDates();
556 DateList::ConstIterator it; 558 DateList::ConstIterator it;
557 QString tmpStr2; 559 QString tmpStr2;
558 560
559 for (it = dateList.begin(); it != dateList.end(); ++it) { 561 for (it = dateList.begin(); it != dateList.end(); ++it) {
560 tmpStr = qDateToISO(*it) + ";"; 562 tmpStr = qDateToISO(*it) + ";";
561 tmpStr2 += tmpStr; 563 tmpStr2 += tmpStr;
562 } 564 }
563 if (!tmpStr2.isEmpty()) { 565 if (!tmpStr2.isEmpty()) {
564 tmpStr2.truncate(tmpStr2.length()-1); 566 tmpStr2.truncate(tmpStr2.length()-1);
565 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); 567 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
566 } 568 }
567 569
568 // description 570 // description
569 if (!anEvent->description().isEmpty()) { 571 if (!anEvent->description().isEmpty()) {
570 VObject *d = addPropValue(vevent, VCDescriptionProp, 572 VObject *d = addPropValue(vevent, VCDescriptionProp,
571 anEvent->description().local8Bit()); 573 anEvent->description().local8Bit());
572 if (anEvent->description().find('\n') != -1) 574 if (anEvent->description().find('\n') != -1)
573 addProp(d, VCQuotedPrintableProp); 575 addProp(d, VCQuotedPrintableProp);
574 } 576 }
575 577
576 // summary 578 // summary
577 if (!anEvent->summary().isEmpty()) 579 if (!anEvent->summary().isEmpty())
578 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); 580 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
579 581
580 if (!anEvent->location().isEmpty()) 582 if (!anEvent->location().isEmpty())
581 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); 583 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
582 584
583 // status 585 // status
584// TODO: define Event status 586// TODO: define Event status
585// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); 587// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
586 588
587 // secrecy 589 // secrecy
588 const char *text = 0; 590 const char *text = 0;
589 switch (anEvent->secrecy()) { 591 switch (anEvent->secrecy()) {
590 case Incidence::SecrecyPublic: 592 case Incidence::SecrecyPublic:
591 text = "PUBLIC"; 593 text = "PUBLIC";
592 break; 594 break;
593 case Incidence::SecrecyPrivate: 595 case Incidence::SecrecyPrivate:
594 text = "PRIVATE"; 596 text = "PRIVATE";
595 break; 597 break;
596 case Incidence::SecrecyConfidential: 598 case Incidence::SecrecyConfidential:
597 text = "CONFIDENTIAL"; 599 text = "CONFIDENTIAL";
598 break; 600 break;
599 } 601 }
600 if (text) { 602 if (text) {
601 addPropValue(vevent, VCClassProp, text); 603 addPropValue(vevent, VCClassProp, text);
602 } 604 }
603 605
604 // categories 606 // categories
605 QStringList tmpStrList = anEvent->categories(); 607 QStringList tmpStrList = anEvent->categories();
606 tmpStr = ""; 608 tmpStr = "";
607 QString catStr; 609 QString catStr;
608 for ( QStringList::Iterator it = tmpStrList.begin(); 610 for ( QStringList::Iterator it = tmpStrList.begin();
609 it != tmpStrList.end(); 611 it != tmpStrList.end();
610 ++it ) { 612 ++it ) {
611 catStr = *it; 613 catStr = *it;
612 if (catStr[0] == ' ') 614 if (catStr[0] == ' ')
613 tmpStr += catStr.mid(1); 615 tmpStr += catStr.mid(1);
614 else 616 else
615 tmpStr += catStr; 617 tmpStr += catStr;
616 // this must be a ';' character as the vCalendar specification requires! 618 // this must be a ';' character as the vCalendar specification requires!
617 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 619 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
618 // read in. 620 // read in.
619 tmpStr += ";"; 621 tmpStr += ";";
620 } 622 }
621 if (!tmpStr.isEmpty()) { 623 if (!tmpStr.isEmpty()) {
622 tmpStr.truncate(tmpStr.length()-1); 624 tmpStr.truncate(tmpStr.length()-1);
623 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); 625 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
624 } 626 }
625 627
626 // attachments 628 // attachments
627 // TODO: handle binary attachments! 629 // TODO: handle binary attachments!
628 QPtrList<Attachment> attachments = anEvent->attachments(); 630 Q3PtrList<Attachment> attachments = anEvent->attachments();
629 for ( Attachment *at = attachments.first(); at; at = attachments.next() ) 631 for ( Attachment *at = attachments.first(); at; at = attachments.next() )
630 addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); 632 addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
631 633
632 // resources 634 // resources
633 tmpStrList = anEvent->resources(); 635 tmpStrList = anEvent->resources();
634 tmpStr = tmpStrList.join(";"); 636 tmpStr = tmpStrList.join(";");
635 if (!tmpStr.isEmpty()) 637 if (!tmpStr.isEmpty())
636 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); 638 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
637 639
638 // alarm stuff 640 // alarm stuff
639 QPtrList<Alarm> alarms = anEvent->alarms(); 641 Q3PtrList<Alarm> alarms = anEvent->alarms();
640 Alarm* alarm; 642 Alarm* alarm;
641 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 643 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
642 if (alarm->enabled()) { 644 if (alarm->enabled()) {
643 VObject *a ; 645 VObject *a ;
644 tmpStr = qDateTimeToISO(alarm->time()); 646 tmpStr = qDateTimeToISO(alarm->time());
645 if (alarm->type() == Alarm::Audio) { 647 if (alarm->type() == Alarm::Audio) {
646 a = addProp(vevent, VCAAlarmProp); 648 a = addProp(vevent, VCAAlarmProp);
647 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 649 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
648 addPropValue(a, VCRepeatCountProp, "1"); 650 addPropValue(a, VCRepeatCountProp, "1");
649 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 651 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
650 } 652 }
651 if (alarm->type() == Alarm::Procedure) { 653 if (alarm->type() == Alarm::Procedure) {
652 a = addProp(vevent, VCPAlarmProp); 654 a = addProp(vevent, VCPAlarmProp);
653 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 655 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
654 addPropValue(a, VCRepeatCountProp, "1"); 656 addPropValue(a, VCRepeatCountProp, "1");
655 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 657 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
656 } else { 658 } else {
657 a = addProp(vevent, VCDAlarmProp); 659 a = addProp(vevent, VCDAlarmProp);
658 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 660 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
659 addPropValue(a, VCRepeatCountProp, "1"); 661 addPropValue(a, VCRepeatCountProp, "1");
660 addPropValue(a, VCDisplayStringProp, "beep!"); 662 addPropValue(a, VCDisplayStringProp, "beep!");
661 663
662 } 664 }
663 } 665 }
664 } 666 }
665 667
666 // priority 668 // priority
667 tmpStr.sprintf("%i",anEvent->priority()); 669 tmpStr.sprintf("%i",anEvent->priority());
668 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); 670 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
669 671
670 // transparency 672 // transparency
671 tmpStr.sprintf("%i",anEvent->transparency()); 673 tmpStr.sprintf("%i",anEvent->transparency());
672 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); 674 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
673 675
674 // related event 676 // related event
675 if (anEvent->relatedToUid()) { 677 if (!anEvent->relatedToUid().isEmpty()) {
676 addPropValue(vevent, VCRelatedToProp, 678 addPropValue(vevent, VCRelatedToProp,
677 anEvent->relatedToUid().local8Bit()); 679 anEvent->relatedToUid().local8Bit());
678 } 680 }
679 681
680 if (anEvent->pilotId()) { 682 if (anEvent->pilotId()) {
681 // pilot sync stuff 683 // pilot sync stuff
682 tmpStr.sprintf("%i",anEvent->pilotId()); 684 tmpStr.sprintf("%i",anEvent->pilotId());
683 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); 685 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
684 tmpStr.sprintf("%i",anEvent->syncStatus()); 686 tmpStr.sprintf("%i",anEvent->syncStatus());
685 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); 687 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
686 } 688 }
687 689
688 return vevent; 690 return vevent;
689} 691}
690 692
691Todo *VCalFormat::VTodoToEvent(VObject *vtodo) 693Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
692{ 694{
693 VObject *vo; 695 VObject *vo;
694 VObjectIterator voi; 696 VObjectIterator voi;
695 char *s; 697 char *s;
696 698
697 Todo *anEvent = new Todo; 699 Todo *anEvent = new Todo;
698 700
699 // creation date 701 // creation date
700 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { 702 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
701 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 703 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
702 deleteStr(s); 704 deleteStr(s);
703 } 705 }
704 706
705 // unique id 707 // unique id
706 vo = isAPropertyOf(vtodo, VCUniqueStringProp); 708 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
707 // while the UID property is preferred, it is not required. We'll use the 709 // while the UID property is preferred, it is not required. We'll use the
708 // default Event UID if none is given. 710 // default Event UID if none is given.
709 if (vo) { 711 if (vo) {
710 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 712 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
711 deleteStr(s); 713 deleteStr(s);
712 } 714 }
713 715
714 // last modification date 716 // last modification date
715 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { 717 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
716 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 718 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
717 deleteStr(s); 719 deleteStr(s);
718 } 720 }
719 else 721 else
720 anEvent->setLastModified(QDateTime(QDate::currentDate(), 722 anEvent->setLastModified(QDateTime(QDate::currentDate(),
721 QTime::currentTime())); 723 QTime::currentTime()));
722 724
723 // organizer 725 // organizer
724 // if our extension property for the event's ORGANIZER exists, add it. 726 // if our extension property for the event's ORGANIZER exists, add it.
725 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { 727 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
726 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 728 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
727 deleteStr(s); 729 deleteStr(s);
728 } else { 730 } else {
729 anEvent->setOrganizer(mCalendar->getEmail()); 731 anEvent->setOrganizer(mCalendar->getEmail());
730 } 732 }
731 733
732 // attendees. 734 // attendees.
733 initPropIterator(&voi, vtodo); 735 initPropIterator(&voi, vtodo);
734 while (moreIteration(&voi)) { 736 while (moreIteration(&voi)) {
735 vo = nextVObject(&voi); 737 vo = nextVObject(&voi);
736 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 738 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
737 Attendee *a; 739 Attendee *a;
738 VObject *vp; 740 VObject *vp;
739 s = fakeCString(vObjectUStringZValue(vo)); 741 s = fakeCString(vObjectUStringZValue(vo));
740 QString tmpStr = QString::fromLocal8Bit(s); 742 QString tmpStr = QString::fromLocal8Bit(s);
741 deleteStr(s); 743 deleteStr(s);
742 tmpStr = tmpStr.simplifyWhiteSpace(); 744 tmpStr = tmpStr.simplifyWhiteSpace();
743 int emailPos1, emailPos2; 745 int emailPos1, emailPos2;
744 if ((emailPos1 = tmpStr.find('<')) > 0) { 746 if ((emailPos1 = tmpStr.find('<')) > 0) {
745 // both email address and name 747 // both email address and name
746 emailPos2 = tmpStr.findRev('>'); 748 emailPos2 = tmpStr.findRev('>');
747 a = new Attendee(tmpStr.left(emailPos1 - 1), 749 a = new Attendee(tmpStr.left(emailPos1 - 1),
748 tmpStr.mid(emailPos1 + 1, 750 tmpStr.mid(emailPos1 + 1,
749 emailPos2 - (emailPos1 + 1))); 751 emailPos2 - (emailPos1 + 1)));
750 } else if (tmpStr.find('@') > 0) { 752 } else if (tmpStr.find('@') > 0) {
751 // just an email address 753 // just an email address
752 a = new Attendee(0, tmpStr); 754 a = new Attendee(0, tmpStr);
753 } else { 755 } else {
754 // just a name 756 // just a name
755 // QString email = tmpStr.replace( QRegExp(" "), "." ); 757 // QString email = tmpStr.replace( QRegExp(" "), "." );
756 a = new Attendee(tmpStr,0); 758 a = new Attendee(tmpStr,0);
757 } 759 }
758 // is there a Role property? 760 // is there a Role property?
759 if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0) 761 if ((vp = isAPropertyOf(vo, VCRoleProp)) != 0)
760 a->setRole(readRole(vObjectStringZValue(vp))); 762 a->setRole(readRole(vObjectStringZValue(vp)));
761 // is there an RSVP property? 763 // is there an RSVP property?
762 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 764 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
763 a->setRSVP(vObjectStringZValue(vp)); 765 a->setRSVP(vObjectStringZValue(vp));
764 // is there a status property? 766 // is there a status property?
765 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 767 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
766 a->setStatus(readStatus(vObjectStringZValue(vp))); 768 a->setStatus(readStatus(vObjectStringZValue(vp)));
767 // add the attendee 769 // add the attendee
768 anEvent->addAttendee(a); 770 anEvent->addAttendee(a);
769 } 771 }
770 } 772 }
771 773
@@ -1315,401 +1317,401 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
1315 // categories 1317 // categories
1316 QStringList tmpStrList; 1318 QStringList tmpStrList;
1317 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { 1319 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1318 s = fakeCString(vObjectUStringZValue(vo)); 1320 s = fakeCString(vObjectUStringZValue(vo));
1319 QString categories = QString::fromLocal8Bit(s); 1321 QString categories = QString::fromLocal8Bit(s);
1320 deleteStr(s); 1322 deleteStr(s);
1321 tmpStrList = QStringList::split( ';', categories ); 1323 tmpStrList = QStringList::split( ';', categories );
1322 anEvent->setCategories(tmpStrList); 1324 anEvent->setCategories(tmpStrList);
1323 } 1325 }
1324 1326
1325 // attachments 1327 // attachments
1326 initPropIterator(&voi, vevent); 1328 initPropIterator(&voi, vevent);
1327 while (moreIteration(&voi)) { 1329 while (moreIteration(&voi)) {
1328 vo = nextVObject(&voi); 1330 vo = nextVObject(&voi);
1329 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 1331 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1330 s = fakeCString(vObjectUStringZValue(vo)); 1332 s = fakeCString(vObjectUStringZValue(vo));
1331 anEvent->addAttachment(new Attachment(QString(s))); 1333 anEvent->addAttachment(new Attachment(QString(s)));
1332 deleteStr(s); 1334 deleteStr(s);
1333 } 1335 }
1334 } 1336 }
1335 1337
1336 // resources 1338 // resources
1337 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 1339 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1338 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1340 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1339 deleteStr(s); 1341 deleteStr(s);
1340 tmpStrList = QStringList::split( ';', resources ); 1342 tmpStrList = QStringList::split( ';', resources );
1341 anEvent->setResources(tmpStrList); 1343 anEvent->setResources(tmpStrList);
1342 } 1344 }
1343 /* alarm stuff */ 1345 /* alarm stuff */
1344 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1346 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1345 Alarm* alarm = anEvent->newAlarm(); 1347 Alarm* alarm = anEvent->newAlarm();
1346 VObject *a; 1348 VObject *a;
1347 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1349 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1348 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1350 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1349 deleteStr(s); 1351 deleteStr(s);
1350 } 1352 }
1351 alarm->setEnabled(true); 1353 alarm->setEnabled(true);
1352 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1354 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1353 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1355 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1354 s = fakeCString(vObjectUStringZValue(a)); 1356 s = fakeCString(vObjectUStringZValue(a));
1355 alarm->setProcedureAlarm(QFile::decodeName(s)); 1357 alarm->setProcedureAlarm(QFile::decodeName(s));
1356 deleteStr(s); 1358 deleteStr(s);
1357 } 1359 }
1358 } 1360 }
1359 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1361 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1360 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1362 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1361 s = fakeCString(vObjectUStringZValue(a)); 1363 s = fakeCString(vObjectUStringZValue(a));
1362 alarm->setAudioAlarm(QFile::decodeName(s)); 1364 alarm->setAudioAlarm(QFile::decodeName(s));
1363 deleteStr(s); 1365 deleteStr(s);
1364 } 1366 }
1365 } 1367 }
1366 } 1368 }
1367 1369
1368 // priority 1370 // priority
1369 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1371 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1370 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1372 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1371 deleteStr(s); 1373 deleteStr(s);
1372 } 1374 }
1373 1375
1374 // transparency 1376 // transparency
1375 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1377 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1376 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1378 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1377 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1379 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1378 deleteStr(s); 1380 deleteStr(s);
1379 } 1381 }
1380 1382
1381 // related event 1383 // related event
1382 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1384 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1383 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1385 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1384 deleteStr(s); 1386 deleteStr(s);
1385 mEventsRelate.append(anEvent); 1387 mEventsRelate.append(anEvent);
1386 } 1388 }
1387 1389
1388 /* PILOT SYNC STUFF */ 1390 /* PILOT SYNC STUFF */
1389 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1391 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1390 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1392 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1391 deleteStr(s); 1393 deleteStr(s);
1392 } 1394 }
1393 else 1395 else
1394 anEvent->setPilotId(0); 1396 anEvent->setPilotId(0);
1395 1397
1396 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1398 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1397 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1399 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1398 deleteStr(s); 1400 deleteStr(s);
1399 } 1401 }
1400 else 1402 else
1401 anEvent->setSyncStatus(Event::SYNCMOD); 1403 anEvent->setSyncStatus(Event::SYNCMOD);
1402 1404
1403 return anEvent; 1405 return anEvent;
1404} 1406}
1405 1407
1406 1408
1407QString VCalFormat::qDateToISO(const QDate &qd) 1409QString VCalFormat::qDateToISO(const QDate &qd)
1408{ 1410{
1409 QString tmpStr; 1411 QString tmpStr;
1410 1412
1411 ASSERT(qd.isValid()); 1413 Q_ASSERT(qd.isValid());
1412 1414
1413 tmpStr.sprintf("%.2d%.2d%.2d", 1415 tmpStr.sprintf("%.2d%.2d%.2d",
1414 qd.year(), qd.month(), qd.day()); 1416 qd.year(), qd.month(), qd.day());
1415 return tmpStr; 1417 return tmpStr;
1416 1418
1417} 1419}
1418 1420
1419QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1421QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1420{ 1422{
1421 QString tmpStr; 1423 QString tmpStr;
1422 1424
1423 ASSERT(qdt.date().isValid()); 1425 Q_ASSERT(qdt.date().isValid());
1424 ASSERT(qdt.time().isValid()); 1426 Q_ASSERT(qdt.time().isValid());
1425 if (zulu && !useLocalTime ) { 1427 if (zulu && !useLocalTime ) {
1426 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); 1428 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60);
1427 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1429 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1428 tmpDT.date().year(), tmpDT.date().month(), 1430 tmpDT.date().year(), tmpDT.date().month(),
1429 tmpDT.date().day(), tmpDT.time().hour(), 1431 tmpDT.date().day(), tmpDT.time().hour(),
1430 tmpDT.time().minute(), tmpDT.time().second()); 1432 tmpDT.time().minute(), tmpDT.time().second());
1431 } else { 1433 } else {
1432 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1434 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1433 qdt.date().year(), qdt.date().month(), 1435 qdt.date().year(), qdt.date().month(),
1434 qdt.date().day(), qdt.time().hour(), 1436 qdt.date().day(), qdt.time().hour(),
1435 qdt.time().minute(), qdt.time().second()); 1437 qdt.time().minute(), qdt.time().second());
1436 } 1438 }
1437 return tmpStr; 1439 return tmpStr;
1438} 1440}
1439 1441
1440QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1442QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1441{ 1443{
1442 QDate tmpDate; 1444 QDate tmpDate;
1443 QTime tmpTime; 1445 QTime tmpTime;
1444 QString tmpStr; 1446 QString tmpStr;
1445 int year, month, day, hour, minute, second; 1447 int year, month, day, hour, minute, second;
1446 1448
1447 tmpStr = dtStr; 1449 tmpStr = dtStr;
1448 year = tmpStr.left(4).toInt(); 1450 year = tmpStr.left(4).toInt();
1449 month = tmpStr.mid(4,2).toInt(); 1451 month = tmpStr.mid(4,2).toInt();
1450 day = tmpStr.mid(6,2).toInt(); 1452 day = tmpStr.mid(6,2).toInt();
1451 hour = tmpStr.mid(9,2).toInt(); 1453 hour = tmpStr.mid(9,2).toInt();
1452 minute = tmpStr.mid(11,2).toInt(); 1454 minute = tmpStr.mid(11,2).toInt();
1453 second = tmpStr.mid(13,2).toInt(); 1455 second = tmpStr.mid(13,2).toInt();
1454 tmpDate.setYMD(year, month, day); 1456 tmpDate.setYMD(year, month, day);
1455 tmpTime.setHMS(hour, minute, second); 1457 tmpTime.setHMS(hour, minute, second);
1456 1458
1457 ASSERT(tmpDate.isValid()); 1459 Q_ASSERT(tmpDate.isValid());
1458 ASSERT(tmpTime.isValid()); 1460 Q_ASSERT(tmpTime.isValid());
1459 QDateTime tmpDT(tmpDate, tmpTime); 1461 QDateTime tmpDT(tmpDate, tmpTime);
1460 // correct for GMT if string is in Zulu format 1462 // correct for GMT if string is in Zulu format
1461 if (dtStr.at(dtStr.length()-1) == 'Z') 1463 if (dtStr.at(dtStr.length()-1) == 'Z')
1462 tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60); 1464 tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60);
1463 return tmpDT; 1465 return tmpDT;
1464} 1466}
1465 1467
1466QDate VCalFormat::ISOToQDate(const QString &dateStr) 1468QDate VCalFormat::ISOToQDate(const QString &dateStr)
1467{ 1469{
1468 int year, month, day; 1470 int year, month, day;
1469 1471
1470 year = dateStr.left(4).toInt(); 1472 year = dateStr.left(4).toInt();
1471 month = dateStr.mid(4,2).toInt(); 1473 month = dateStr.mid(4,2).toInt();
1472 day = dateStr.mid(6,2).toInt(); 1474 day = dateStr.mid(6,2).toInt();
1473 1475
1474 return(QDate(year, month, day)); 1476 return(QDate(year, month, day));
1475} 1477}
1476 1478
1477// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1479// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1478// and break it down from it's tree-like format into the dictionary format 1480// and break it down from it's tree-like format into the dictionary format
1479// that is used internally in the VCalFormat. 1481// that is used internally in the VCalFormat.
1480void VCalFormat::populate(VObject *vcal) 1482void VCalFormat::populate(VObject *vcal)
1481{ 1483{
1482 // this function will populate the caldict dictionary and other event 1484 // this function will populate the caldict dictionary and other event
1483 // lists. It turns vevents into Events and then inserts them. 1485 // lists. It turns vevents into Events and then inserts them.
1484 1486
1485 VObjectIterator i; 1487 VObjectIterator i;
1486 VObject *curVO, *curVOProp; 1488 VObject *curVO, *curVOProp;
1487 Event *anEvent; 1489 Event *anEvent;
1488 1490
1489 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1491 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1490 char *methodType = 0; 1492 char *methodType = 0;
1491 methodType = fakeCString(vObjectUStringZValue(curVO)); 1493 methodType = fakeCString(vObjectUStringZValue(curVO));
1492 kdDebug() << "This calendar is an iTIP transaction of type '" 1494 kdDebug() << "This calendar is an iTIP transaction of type '"
1493 << methodType << "'" << endl; 1495 << methodType << "'" << endl;
1494 delete methodType; 1496 delete methodType;
1495 } 1497 }
1496 1498
1497 // warn the user that we might have trouble reading non-known calendar. 1499 // warn the user that we might have trouble reading non-known calendar.
1498 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1500 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1499 char *s = fakeCString(vObjectUStringZValue(curVO)); 1501 char *s = fakeCString(vObjectUStringZValue(curVO));
1500 if (strcmp(productId().local8Bit(), s) != 0) 1502 if (strcmp(productId().local8Bit(), s) != 0)
1501 kdDebug() << "This vCalendar file was not created by KOrganizer " 1503 kdDebug() << "This vCalendar file was not created by KOrganizer "
1502 "or any other product we support. Loading anyway..." << endl; 1504 "or any other product we support. Loading anyway..." << endl;
1503 mLoadedProductId = s; 1505 mLoadedProductId = s;
1504 deleteStr(s); 1506 deleteStr(s);
1505 } 1507 }
1506 1508
1507 // warn the user we might have trouble reading this unknown version. 1509 // warn the user we might have trouble reading this unknown version.
1508 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1510 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1509 char *s = fakeCString(vObjectUStringZValue(curVO)); 1511 char *s = fakeCString(vObjectUStringZValue(curVO));
1510 if (strcmp(_VCAL_VERSION, s) != 0) 1512 if (strcmp(_VCAL_VERSION, s) != 0)
1511 kdDebug() << "This vCalendar file has version " << s 1513 kdDebug() << "This vCalendar file has version " << s
1512 << "We only support " << _VCAL_VERSION << endl; 1514 << "We only support " << _VCAL_VERSION << endl;
1513 deleteStr(s); 1515 deleteStr(s);
1514 } 1516 }
1515 1517
1516 // set the time zone 1518 // set the time zone
1517 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1519 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1518 if ( vObjectUStringZValue(curVO) != 0 ) { 1520 if ( vObjectUStringZValue(curVO) != 0 ) {
1519 char *s = fakeCString(vObjectUStringZValue(curVO)); 1521 char *s = fakeCString(vObjectUStringZValue(curVO));
1520 mCalendar->setTimeZone(s); 1522 mCalendar->setTimeZone(s);
1521 deleteStr(s); 1523 deleteStr(s);
1522 } 1524 }
1523 } 1525 }
1524 1526
1525 // Store all events with a relatedTo property in a list for post-processing 1527 // Store all events with a relatedTo property in a list for post-processing
1526 mEventsRelate.clear(); 1528 mEventsRelate.clear();
1527 mTodosRelate.clear(); 1529 mTodosRelate.clear();
1528 1530
1529 initPropIterator(&i, vcal); 1531 initPropIterator(&i, vcal);
1530 1532
1531 // go through all the vobjects in the vcal 1533 // go through all the vobjects in the vcal
1532 while (moreIteration(&i)) { 1534 while (moreIteration(&i)) {
1533 curVO = nextVObject(&i); 1535 curVO = nextVObject(&i);
1534 1536
1535 /************************************************************************/ 1537 /************************************************************************/
1536 1538
1537 // now, check to see that the object is an event or todo. 1539 // now, check to see that the object is an event or todo.
1538 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1540 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1539 1541
1540 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { 1542 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) {
1541 char *s; 1543 char *s;
1542 s = fakeCString(vObjectUStringZValue(curVOProp)); 1544 s = fakeCString(vObjectUStringZValue(curVOProp));
1543 // check to see if event was deleted by the kpilot conduit 1545 // check to see if event was deleted by the kpilot conduit
1544 if (atoi(s) == Event::SYNCDEL) { 1546 if (atoi(s) == Event::SYNCDEL) {
1545 deleteStr(s); 1547 deleteStr(s);
1546 kdDebug(5800) << "skipping pilot-deleted event" << endl; 1548 kdDebug(5800) << "skipping pilot-deleted event" << endl;
1547 goto SKIP; 1549 goto SKIP;
1548 } 1550 }
1549 deleteStr(s); 1551 deleteStr(s);
1550 } 1552 }
1551 1553
1552 // this code checks to see if we are trying to read in an event 1554 // this code checks to see if we are trying to read in an event
1553 // that we already find to be in the calendar. If we find this 1555 // that we already find to be in the calendar. If we find this
1554 // to be the case, we skip the event. 1556 // to be the case, we skip the event.
1555 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1557 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1556 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1558 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1557 QString tmpStr(s); 1559 QString tmpStr(s);
1558 deleteStr(s); 1560 deleteStr(s);
1559 1561
1560 if (mCalendar->event(tmpStr)) { 1562 if (mCalendar->event(tmpStr)) {
1561 goto SKIP; 1563 goto SKIP;
1562 } 1564 }
1563 if (mCalendar->todo(tmpStr)) { 1565 if (mCalendar->todo(tmpStr)) {
1564 goto SKIP; 1566 goto SKIP;
1565 } 1567 }
1566 } 1568 }
1567 1569
1568 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1570 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1569 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 1571 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1570 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 1572 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1571 goto SKIP; 1573 goto SKIP;
1572 } 1574 }
1573 1575
1574 anEvent = VEventToEvent(curVO); 1576 anEvent = VEventToEvent(curVO);
1575 // we now use addEvent instead of insertEvent so that the 1577 // we now use addEvent instead of insertEvent so that the
1576 // signal/slot get connected. 1578 // signal/slot get connected.
1577 if (anEvent) { 1579 if (anEvent) {
1578 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { 1580 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) {
1579 kdDebug() << "VCalFormat::populate(): Event has invalid dates." 1581 kdDebug() << "VCalFormat::populate(): Event has invalid dates."
1580 << endl; 1582 << endl;
1581 } else { 1583 } else {
1582 mCalendar->addEvent(anEvent); 1584 mCalendar->addEvent(anEvent);
1583 } 1585 }
1584 } else { 1586 } else {
1585 // some sort of error must have occurred while in translation. 1587 // some sort of error must have occurred while in translation.
1586 goto SKIP; 1588 goto SKIP;
1587 } 1589 }
1588 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 1590 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1589 Todo *aTodo = VTodoToEvent(curVO); 1591 Todo *aTodo = VTodoToEvent(curVO);
1590 mCalendar->addTodo(aTodo); 1592 mCalendar->addTodo(aTodo);
1591 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 1593 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1592 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 1594 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1593 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 1595 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1594 // do nothing, we know these properties and we want to skip them. 1596 // do nothing, we know these properties and we want to skip them.
1595 // we have either already processed them or are ignoring them. 1597 // we have either already processed them or are ignoring them.
1596 ; 1598 ;
1597 } else { 1599 } else {
1598 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; 1600 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl;
1599 } 1601 }
1600 SKIP: 1602 SKIP:
1601 ; 1603 ;
1602 } // while 1604 } // while
1603 1605
1604 // Post-Process list of events with relations, put Event objects in relation 1606 // Post-Process list of events with relations, put Event objects in relation
1605 Event *ev; 1607 Event *ev;
1606 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 1608 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
1607 Incidence * inc = mCalendar->event(ev->relatedToUid()); 1609 Incidence * inc = mCalendar->event(ev->relatedToUid());
1608 if ( inc ) 1610 if ( inc )
1609 ev->setRelatedTo( inc ); 1611 ev->setRelatedTo( inc );
1610 } 1612 }
1611 Todo *todo; 1613 Todo *todo;
1612 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 1614 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
1613 Incidence * inc = mCalendar->todo(todo->relatedToUid()); 1615 Incidence * inc = mCalendar->todo(todo->relatedToUid());
1614 if ( inc ) 1616 if ( inc )
1615 todo->setRelatedTo( inc ); 1617 todo->setRelatedTo( inc );
1616 } 1618 }
1617} 1619}
1618 1620
1619const char *VCalFormat::dayFromNum(int day) 1621const char *VCalFormat::dayFromNum(int day)
1620{ 1622{
1621 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; 1623 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " };
1622 1624
1623 return days[day]; 1625 return days[day];
1624} 1626}
1625 1627
1626int VCalFormat::numFromDay(const QString &day) 1628int VCalFormat::numFromDay(const QString &day)
1627{ 1629{
1628 if (day == "MO ") return 0; 1630 if (day == "MO ") return 0;
1629 if (day == "TU ") return 1; 1631 if (day == "TU ") return 1;
1630 if (day == "WE ") return 2; 1632 if (day == "WE ") return 2;
1631 if (day == "TH ") return 3; 1633 if (day == "TH ") return 3;
1632 if (day == "FR ") return 4; 1634 if (day == "FR ") return 4;
1633 if (day == "SA ") return 5; 1635 if (day == "SA ") return 5;
1634 if (day == "SU ") return 6; 1636 if (day == "SU ") return 6;
1635 1637
1636 return -1; // something bad happened. :) 1638 return -1; // something bad happened. :)
1637} 1639}
1638Attendee::Role VCalFormat::readRole(const char *s) const 1640Attendee::Role VCalFormat::readRole(const char *s) const
1639{ 1641{
1640 QString statStr = s; 1642 QString statStr = s;
1641 statStr = statStr.upper(); 1643 statStr = statStr.upper();
1642 Attendee::Role role = Attendee::ReqParticipant; 1644 Attendee::Role role = Attendee::ReqParticipant;
1643 1645
1644 if ( statStr == "OWNER") 1646 if ( statStr == "OWNER")
1645 role = Attendee::Chair; 1647 role = Attendee::Chair;
1646 // enum Role { ReqParticipant, OptParticipant, NonParticipant, Chair }; 1648 // enum Role { ReqParticipant, OptParticipant, NonParticipant, Chair };
1647 1649
1648 return role; 1650 return role;
1649} 1651}
1650 1652
1651QCString VCalFormat::writeRole(Attendee::Role role) const 1653Q3CString VCalFormat::writeRole(Attendee::Role role) const
1652{ 1654{
1653 if ( role == Attendee::Chair ) 1655 if ( role == Attendee::Chair )
1654 return "OWNER"; 1656 return "OWNER";
1655 return "ATTENDEE"; 1657 return "ATTENDEE";
1656} 1658}
1657Attendee::PartStat VCalFormat::readStatus(const char *s) const 1659Attendee::PartStat VCalFormat::readStatus(const char *s) const
1658{ 1660{
1659 QString statStr = s; 1661 QString statStr = s;
1660 statStr = statStr.upper(); 1662 statStr = statStr.upper();
1661 Attendee::PartStat status; 1663 Attendee::PartStat status;
1662 1664
1663 if (statStr == "X-ACTION") 1665 if (statStr == "X-ACTION")
1664 status = Attendee::NeedsAction; 1666 status = Attendee::NeedsAction;
1665 else if (statStr == "NEEDS ACTION") 1667 else if (statStr == "NEEDS ACTION")
1666 status = Attendee::NeedsAction; 1668 status = Attendee::NeedsAction;
1667 else if (statStr== "ACCEPTED") 1669 else if (statStr== "ACCEPTED")
1668 status = Attendee::Accepted; 1670 status = Attendee::Accepted;
1669 else if (statStr== "SENT") 1671 else if (statStr== "SENT")
1670 status = Attendee::NeedsAction; 1672 status = Attendee::NeedsAction;
1671 else if (statStr== "TENTATIVE") 1673 else if (statStr== "TENTATIVE")
1672 status = Attendee::Tentative; 1674 status = Attendee::Tentative;
1673 else if (statStr== "CONFIRMED") 1675 else if (statStr== "CONFIRMED")
1674 status = Attendee::Accepted; 1676 status = Attendee::Accepted;
1675 else if (statStr== "DECLINED") 1677 else if (statStr== "DECLINED")
1676 status = Attendee::Declined; 1678 status = Attendee::Declined;
1677 else if (statStr== "COMPLETED") 1679 else if (statStr== "COMPLETED")
1678 status = Attendee::Completed; 1680 status = Attendee::Completed;
1679 else if (statStr== "DELEGATED") 1681 else if (statStr== "DELEGATED")
1680 status = Attendee::Delegated; 1682 status = Attendee::Delegated;
1681 else { 1683 else {
1682 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; 1684 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl;
1683 status = Attendee::NeedsAction; 1685 status = Attendee::NeedsAction;
1684 } 1686 }
1685 1687
1686 return status; 1688 return status;
1687} 1689}
1688 1690
1689QCString VCalFormat::writeStatus(Attendee::PartStat status) const 1691Q3CString VCalFormat::writeStatus(Attendee::PartStat status) const
1690{ 1692{
1691 switch(status) { 1693 switch(status) {
1692 default: 1694 default:
1693 case Attendee::NeedsAction: 1695 case Attendee::NeedsAction:
1694 return "NEEDS ACTION"; 1696 return "NEEDS ACTION";
1695 break; 1697 break;
1696 case Attendee::Accepted: 1698 case Attendee::Accepted:
1697 return "ACCEPTED"; 1699 return "ACCEPTED";
1698 break; 1700 break;
1699 case Attendee::Declined: 1701 case Attendee::Declined:
1700 return "DECLINED"; 1702 return "DECLINED";
1701 break; 1703 break;
1702 case Attendee::Tentative: 1704 case Attendee::Tentative:
1703 return "TENTATIVE"; 1705 return "TENTATIVE";
1704 break; 1706 break;
1705 case Attendee::Delegated: 1707 case Attendee::Delegated:
1706 return "DELEGATED"; 1708 return "DELEGATED";
1707 break; 1709 break;
1708 case Attendee::Completed: 1710 case Attendee::Completed:
1709 return "COMPLETED"; 1711 return "COMPLETED";
1710 break; 1712 break;
1711 case Attendee::InProcess: 1713 case Attendee::InProcess:
1712 return "NEEDS ACTION"; 1714 return "NEEDS ACTION";
1713 break; 1715 break;
1714 } 1716 }
1715} 1717}