summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-13 00:09:20 (UTC)
committer zautrix <zautrix>2004-10-13 00:09:20 (UTC)
commitd56ca1073ce493afdeb54e33425638f7147d4bca (patch) (unidiff)
tree03b21c9d7a875c7f7dd46d936d834570d211ae42
parent0dab27179ee6b1e0a052ab589a27e31ffb887912 (diff)
downloadkdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.zip
kdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.tar.gz
kdepimpi-d56ca1073ce493afdeb54e33425638f7147d4bca.tar.bz2
fix in save vcal as local time
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/vcalformat.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 309c699..a6ae1bc 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,548 +1,544 @@
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 <qptrlist.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 30
31#include <kdebug.h> 31#include <kdebug.h>
32#include <kglobal.h> 32#include <kglobal.h>
33#include <kmessagebox.h> 33#include <kmessagebox.h>
34#include <kiconloader.h> 34#include <kiconloader.h>
35#include <klocale.h> 35#include <klocale.h>
36 36
37#include "vcc.h" 37#include "vcc.h"
38#include "vobject.h" 38#include "vobject.h"
39 39
40#include "vcaldrag.h" 40#include "vcaldrag.h"
41#include "calendar.h" 41#include "calendar.h"
42 42
43#include "vcalformat.h" 43#include "vcalformat.h"
44 44
45using namespace KCal; 45using namespace KCal;
46 46
47VCalFormat::VCalFormat() 47VCalFormat::VCalFormat()
48{ 48{
49 mCalendar = 0; 49 mCalendar = 0;
50 useLocalTime = false; 50 useLocalTime = false;
51} 51}
52 52
53VCalFormat::~VCalFormat() 53VCalFormat::~VCalFormat()
54{ 54{
55} 55}
56 56
57void VCalFormat::setLocalTime ( bool b ) 57void VCalFormat::setLocalTime ( bool b )
58{ 58{
59 useLocalTime = b; 59 useLocalTime = b;
60} 60}
61bool VCalFormat::load(Calendar *calendar, const QString &fileName) 61bool VCalFormat::load(Calendar *calendar, const QString &fileName)
62{ 62{
63 mCalendar = calendar; 63 mCalendar = calendar;
64 clearException(); 64 clearException();
65 65 useLocalTime = mCalendar->isLocalTime();
66 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
67
68 VObject *vcal = 0; 66 VObject *vcal = 0;
69 67
70 // this is not necessarily only 1 vcal. Could be many vcals, or include 68 // this is not necessarily only 1 vcal. Could be many vcals, or include
71 // a vcard... 69 // a vcard...
72 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 70 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
73 71
74 if (!vcal) { 72 if (!vcal) {
75 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 73 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
76 return FALSE; 74 return FALSE;
77 } 75 }
78 76
79 // any other top-level calendar stuff should be added/initialized here 77 // any other top-level calendar stuff should be added/initialized here
80 78
81 // put all vobjects into their proper places 79 // put all vobjects into their proper places
82 populate(vcal); 80 populate(vcal);
83 81
84 // clean up from vcal API stuff 82 // clean up from vcal API stuff
85 cleanVObjects(vcal); 83 cleanVObjects(vcal);
86 cleanStrTbl(); 84 cleanStrTbl();
87 85
88 return true; 86 return true;
89} 87}
90 88
91 89
92bool VCalFormat::save(Calendar *calendar, const QString &fileName) 90bool VCalFormat::save(Calendar *calendar, const QString &fileName)
93{ 91{
94 mCalendar = calendar; 92 mCalendar = calendar;
93 useLocalTime = mCalendar->isLocalTime();
95 94
96 QString tmpStr; 95 QString tmpStr;
97 VObject *vcal, *vo; 96 VObject *vcal, *vo;
98 97
99 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
100 98
101 vcal = newVObject(VCCalProp); 99 vcal = newVObject(VCCalProp);
102 100
103 // addPropValue(vcal,VCLocationProp, "0.0"); 101 // addPropValue(vcal,VCLocationProp, "0.0");
104 addPropValue(vcal,VCProdIdProp, productId()); 102 addPropValue(vcal,VCProdIdProp, productId());
105 tmpStr = mCalendar->getTimeZoneStr(); 103 tmpStr = mCalendar->getTimeZoneStr();
106 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 104 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
107 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 105 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
108 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 106 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
109 107
110 // TODO STUFF 108 // TODO STUFF
111 QPtrList<Todo> todoList = mCalendar->rawTodos(); 109 QPtrList<Todo> todoList = mCalendar->rawTodos();
112 QPtrListIterator<Todo> qlt(todoList); 110 QPtrListIterator<Todo> qlt(todoList);
113 for (; qlt.current(); ++qlt) { 111 for (; qlt.current(); ++qlt) {
114 vo = eventToVTodo(qlt.current()); 112 vo = eventToVTodo(qlt.current());
115 addVObjectProp(vcal, vo); 113 addVObjectProp(vcal, vo);
116 } 114 }
117 115
118 // EVENT STUFF 116 // EVENT STUFF
119 QPtrList<Event> events = mCalendar->rawEvents(); 117 QPtrList<Event> events = mCalendar->rawEvents();
120 Event *ev; 118 Event *ev;
121 for(ev=events.first();ev;ev=events.next()) { 119 for(ev=events.first();ev;ev=events.next()) {
122 vo = eventToVEvent(ev); 120 vo = eventToVEvent(ev);
123 addVObjectProp(vcal, vo); 121 addVObjectProp(vcal, vo);
124 } 122 }
125 123
126 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 124 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
127 cleanVObjects(vcal); 125 cleanVObjects(vcal);
128 cleanStrTbl(); 126 cleanStrTbl();
129 127
130 if (QFile::exists(fileName)) { 128 if (QFile::exists(fileName)) {
131 kdDebug(5800) << "No error" << endl;
132 return true; 129 return true;
133 } else { 130 } else {
134 kdDebug(5800) << "Error" << endl;
135 return false; // error 131 return false; // error
136 } 132 }
137} 133}
138 134
139bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 135bool VCalFormat::fromString( Calendar *calendar, const QString &text )
140{ 136{
141 // TODO: Factor out VCalFormat::fromString() 137 // TODO: Factor out VCalFormat::fromString()
142 138
143 QCString data = text.utf8(); 139 QCString data = text.utf8();
144 140
145 if ( !data.size() ) return false; 141 if ( !data.size() ) return false;
146 142
147 VObject *vcal = Parse_MIME( data.data(), data.size()); 143 VObject *vcal = Parse_MIME( data.data(), data.size());
148 if ( !vcal ) return false; 144 if ( !vcal ) return false;
149 145
150 VObjectIterator i; 146 VObjectIterator i;
151 VObject *curvo; 147 VObject *curvo;
152 initPropIterator( &i, vcal ); 148 initPropIterator( &i, vcal );
153 149
154 // we only take the first object. TODO: parse all incidences. 150 // we only take the first object. TODO: parse all incidences.
155 do { 151 do {
156 curvo = nextVObject( &i ); 152 curvo = nextVObject( &i );
157 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 153 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
158 strcmp( vObjectName( curvo ), VCTodoProp ) ); 154 strcmp( vObjectName( curvo ), VCTodoProp ) );
159 155
160 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 156 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
161 Event *event = VEventToEvent( curvo ); 157 Event *event = VEventToEvent( curvo );
162 calendar->addEvent( event ); 158 calendar->addEvent( event );
163 } else { 159 } else {
164 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 160 qDebug("VCalFormat::fromString(): Unknown object type. ");
165 deleteVObject( vcal ); 161 deleteVObject( vcal );
166 return false; 162 return false;
167 } 163 }
168 164
169 deleteVObject( vcal ); 165 deleteVObject( vcal );
170 166
171 return true; 167 return true;
172} 168}
173 169
174QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal) 170QString VCalFormat::eventToString( Event * event, Calendar *calendar, bool useLocal)
175{ 171{
176 172
177 if ( !event ) return QString::null; 173 if ( !event ) return QString::null;
178 bool useL = useLocalTime; 174 bool useL = useLocalTime;
179 useLocalTime = useLocal; 175 useLocalTime = useLocal;
180 mCalendar = calendar; 176 mCalendar = calendar;
181 VObject *vevent = eventToVEvent( event ); 177 VObject *vevent = eventToVEvent( event );
182 char *buf = writeMemVObject( 0, 0, vevent ); 178 char *buf = writeMemVObject( 0, 0, vevent );
183 QString result( buf ); 179 QString result( buf );
184 cleanVObject( vevent ); 180 cleanVObject( vevent );
185 useLocalTime = useL; 181 useLocalTime = useL;
186 return result; 182 return result;
187} 183}
188QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal ) 184QString VCalFormat::todoToString( Todo * todo, Calendar *calendar, bool useLocal )
189{ 185{
190 186
191 if ( !todo ) return QString::null; 187 if ( !todo ) return QString::null;
192 bool useL = useLocalTime; 188 bool useL = useLocalTime;
193 useLocalTime = useLocal; 189 useLocalTime = useLocal;
194 mCalendar = calendar; 190 mCalendar = calendar;
195 VObject *vevent = eventToVTodo( todo ); 191 VObject *vevent = eventToVTodo( todo );
196 char *buf = writeMemVObject( 0, 0, vevent ); 192 char *buf = writeMemVObject( 0, 0, vevent );
197 QString result( buf ); 193 QString result( buf );
198 cleanVObject( vevent ); 194 cleanVObject( vevent );
199 useLocalTime = useL; 195 useLocalTime = useL;
200 return result; 196 return result;
201} 197}
202 198
203QString VCalFormat::toString( Calendar *calendar ) 199QString VCalFormat::toString( Calendar *calendar )
204{ 200{
205 // TODO: Factor out VCalFormat::asString() 201 // TODO: Factor out VCalFormat::asString()
206 202
207 VObject *vcal = newVObject(VCCalProp); 203 VObject *vcal = newVObject(VCCalProp);
208 204
209 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 205 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
210 QString tmpStr = mCalendar->getTimeZoneStr(); 206 QString tmpStr = mCalendar->getTimeZoneStr();
211 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 207 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
212 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 208 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
213 209
214 // TODO: Use all data. 210 // TODO: Use all data.
215 QPtrList<Event> events = calendar->events(); 211 QPtrList<Event> events = calendar->events();
216 Event *event = events.first(); 212 Event *event = events.first();
217 if ( !event ) return QString::null; 213 if ( !event ) return QString::null;
218 214
219 VObject *vevent = eventToVEvent( event ); 215 VObject *vevent = eventToVEvent( event );
220 216
221 addVObjectProp( vcal, vevent ); 217 addVObjectProp( vcal, vevent );
222 218
223 char *buf = writeMemVObject( 0, 0, vcal ); 219 char *buf = writeMemVObject( 0, 0, vcal );
224 220
225 QString result( buf ); 221 QString result( buf );
226 222
227 cleanVObject( vcal ); 223 cleanVObject( vcal );
228 224
229 return result; 225 return result;
230} 226}
231 227
232VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 228VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
233{ 229{
234 VObject *vtodo; 230 VObject *vtodo;
235 QString tmpStr; 231 QString tmpStr;
236 QStringList tmpStrList; 232 QStringList tmpStrList;
237 233
238 vtodo = newVObject(VCTodoProp); 234 vtodo = newVObject(VCTodoProp);
239 235
240 // due date 236 // due date
241 if (anEvent->hasDueDate()) { 237 if (anEvent->hasDueDate()) {
242 tmpStr = qDateTimeToISO(anEvent->dtDue(), 238 tmpStr = qDateTimeToISO(anEvent->dtDue(),
243 !anEvent->doesFloat()); 239 !anEvent->doesFloat());
244 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 240 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
245 } 241 }
246 242
247 // start date 243 // start date
248 if (anEvent->hasStartDate()) { 244 if (anEvent->hasStartDate()) {
249 tmpStr = qDateTimeToISO(anEvent->dtStart(), 245 tmpStr = qDateTimeToISO(anEvent->dtStart(),
250 !anEvent->doesFloat()); 246 !anEvent->doesFloat());
251 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 247 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
252 } 248 }
253 249
254 // creation date 250 // creation date
255 tmpStr = qDateTimeToISO(anEvent->created()); 251 tmpStr = qDateTimeToISO(anEvent->created());
256 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 252 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
257 253
258 // unique id 254 // unique id
259 addPropValue(vtodo, VCUniqueStringProp, 255 addPropValue(vtodo, VCUniqueStringProp,
260 anEvent->uid().local8Bit()); 256 anEvent->uid().local8Bit());
261 257
262 // revision 258 // revision
263 tmpStr.sprintf("%i", anEvent->revision()); 259 tmpStr.sprintf("%i", anEvent->revision());
264 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 260 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
265 261
266 // last modification date 262 // last modification date
267 tmpStr = qDateTimeToISO(anEvent->lastModified()); 263 tmpStr = qDateTimeToISO(anEvent->lastModified());
268 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 264 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
269 265
270 // organizer stuff 266 // organizer stuff
271 tmpStr = "MAILTO:" + anEvent->organizer(); 267 tmpStr = "MAILTO:" + anEvent->organizer();
272 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 268 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
273 269
274 // attendees 270 // attendees
275 if (anEvent->attendeeCount() != 0) { 271 if (anEvent->attendeeCount() != 0) {
276 QPtrList<Attendee> al = anEvent->attendees(); 272 QPtrList<Attendee> al = anEvent->attendees();
277 QPtrListIterator<Attendee> ai(al); 273 QPtrListIterator<Attendee> ai(al);
278 Attendee *curAttendee; 274 Attendee *curAttendee;
279 275
280 for (; ai.current(); ++ai) { 276 for (; ai.current(); ++ai) {
281 curAttendee = ai.current(); 277 curAttendee = ai.current();
282 if (!curAttendee->email().isEmpty() && 278 if (!curAttendee->email().isEmpty() &&
283 !curAttendee->name().isEmpty()) 279 !curAttendee->name().isEmpty())
284 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 280 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
285 curAttendee->email() + ">"; 281 curAttendee->email() + ">";
286 else if (curAttendee->name().isEmpty()) 282 else if (curAttendee->name().isEmpty())
287 tmpStr = "MAILTO: " + curAttendee->email(); 283 tmpStr = "MAILTO: " + curAttendee->email();
288 else if (curAttendee->email().isEmpty()) 284 else if (curAttendee->email().isEmpty())
289 tmpStr = "MAILTO: " + curAttendee->name(); 285 tmpStr = "MAILTO: " + curAttendee->name();
290 else if (curAttendee->name().isEmpty() && 286 else if (curAttendee->name().isEmpty() &&
291 curAttendee->email().isEmpty()) 287 curAttendee->email().isEmpty())
292 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 288 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
293 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 289 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
294 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 290 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
295 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 291 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
296 } 292 }
297 } 293 }
298 294
299 // description BL: 295 // description BL:
300 if (!anEvent->description().isEmpty()) { 296 if (!anEvent->description().isEmpty()) {
301 VObject *d = addPropValue(vtodo, VCDescriptionProp, 297 VObject *d = addPropValue(vtodo, VCDescriptionProp,
302 anEvent->description().local8Bit()); 298 anEvent->description().local8Bit());
303 if (anEvent->description().find('\n') != -1) 299 if (anEvent->description().find('\n') != -1)
304 addProp(d, VCQuotedPrintableProp); 300 addProp(d, VCQuotedPrintableProp);
305 } 301 }
306 302
307 // summary 303 // summary
308 if (!anEvent->summary().isEmpty()) 304 if (!anEvent->summary().isEmpty())
309 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 305 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
310 306
311 if (!anEvent->location().isEmpty()) 307 if (!anEvent->location().isEmpty())
312 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 308 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
313 309
314 // completed 310 // completed
315 // status 311 // status
316 // backward compatibility, KOrganizer used to interpret only these two values 312 // backward compatibility, KOrganizer used to interpret only these two values
317 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 313 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
318 "NEEDS_ACTION"); 314 "NEEDS_ACTION");
319 // completion date 315 // completion date
320 if (anEvent->hasCompletedDate()) { 316 if (anEvent->hasCompletedDate()) {
321 tmpStr = qDateTimeToISO(anEvent->completed()); 317 tmpStr = qDateTimeToISO(anEvent->completed());
322 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 318 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
323 } 319 }
324 320
325 // priority 321 // priority
326 tmpStr.sprintf("%i",anEvent->priority()); 322 tmpStr.sprintf("%i",anEvent->priority());
327 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 323 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
328 324
329 // related event 325 // related event
330 if (anEvent->relatedTo()) { 326 if (anEvent->relatedTo()) {
331 addPropValue(vtodo, VCRelatedToProp, 327 addPropValue(vtodo, VCRelatedToProp,
332 anEvent->relatedTo()->uid().local8Bit()); 328 anEvent->relatedTo()->uid().local8Bit());
333 } 329 }
334 330
335 // categories 331 // categories
336 tmpStrList = anEvent->categories(); 332 tmpStrList = anEvent->categories();
337 tmpStr = ""; 333 tmpStr = "";
338 QString catStr; 334 QString catStr;
339 for ( QStringList::Iterator it = tmpStrList.begin(); 335 for ( QStringList::Iterator it = tmpStrList.begin();
340 it != tmpStrList.end(); 336 it != tmpStrList.end();
341 ++it ) { 337 ++it ) {
342 catStr = *it; 338 catStr = *it;
343 if (catStr[0] == ' ') 339 if (catStr[0] == ' ')
344 tmpStr += catStr.mid(1); 340 tmpStr += catStr.mid(1);
345 else 341 else
346 tmpStr += catStr; 342 tmpStr += catStr;
347 // this must be a ';' character as the vCalendar specification requires! 343 // this must be a ';' character as the vCalendar specification requires!
348 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 344 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
349 // read in. 345 // read in.
350 tmpStr += ";"; 346 tmpStr += ";";
351 } 347 }
352 if (!tmpStr.isEmpty()) { 348 if (!tmpStr.isEmpty()) {
353 tmpStr.truncate(tmpStr.length()-1); 349 tmpStr.truncate(tmpStr.length()-1);
354 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 350 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
355 } 351 }
356 352
357 // alarm stuff 353 // alarm stuff
358 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 354 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
359 QPtrList<Alarm> alarms = anEvent->alarms(); 355 QPtrList<Alarm> alarms = anEvent->alarms();
360 Alarm* alarm; 356 Alarm* alarm;
361 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 357 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
362 if (alarm->enabled()) { 358 if (alarm->enabled()) {
363 VObject *a; 359 VObject *a;
364 tmpStr = qDateTimeToISO(alarm->time()); 360 tmpStr = qDateTimeToISO(alarm->time());
365 if (alarm->type() == Alarm::Audio) { 361 if (alarm->type() == Alarm::Audio) {
366 a = addProp(vtodo, VCAAlarmProp); 362 a = addProp(vtodo, VCAAlarmProp);
367 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 363 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
368 addPropValue(a, VCRepeatCountProp, "1"); 364 addPropValue(a, VCRepeatCountProp, "1");
369 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 365 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
370 } 366 }
371 else if (alarm->type() == Alarm::Procedure) { 367 else if (alarm->type() == Alarm::Procedure) {
372 a = addProp(vtodo, VCPAlarmProp); 368 a = addProp(vtodo, VCPAlarmProp);
373 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 369 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
374 addPropValue(a, VCRepeatCountProp, "1"); 370 addPropValue(a, VCRepeatCountProp, "1");
375 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 371 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
376 } else { 372 } else {
377 a = addProp(vtodo, VCDAlarmProp); 373 a = addProp(vtodo, VCDAlarmProp);
378 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 374 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
379 addPropValue(a, VCRepeatCountProp, "1"); 375 addPropValue(a, VCRepeatCountProp, "1");
380 addPropValue(a, VCDisplayStringProp, "beep!"); 376 addPropValue(a, VCDisplayStringProp, "beep!");
381 } 377 }
382 } 378 }
383 } 379 }
384 380
385 if (anEvent->pilotId()) { 381 if (anEvent->pilotId()) {
386 // pilot sync stuff 382 // pilot sync stuff
387 tmpStr.sprintf("%i",anEvent->pilotId()); 383 tmpStr.sprintf("%i",anEvent->pilotId());
388 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 384 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
389 tmpStr.sprintf("%i",anEvent->syncStatus()); 385 tmpStr.sprintf("%i",anEvent->syncStatus());
390 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 386 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
391 } 387 }
392 388
393 return vtodo; 389 return vtodo;
394} 390}
395 391
396VObject* VCalFormat::eventToVEvent(const Event *anEvent) 392VObject* VCalFormat::eventToVEvent(const Event *anEvent)
397{ 393{
398 VObject *vevent; 394 VObject *vevent;
399 QString tmpStr; 395 QString tmpStr;
400 QStringList tmpStrList; 396 QStringList tmpStrList;
401 397
402 vevent = newVObject(VCEventProp); 398 vevent = newVObject(VCEventProp);
403 399
404 // start and end time 400 // start and end time
405 tmpStr = qDateTimeToISO(anEvent->dtStart(), 401 tmpStr = qDateTimeToISO(anEvent->dtStart(),
406 !anEvent->doesFloat()); 402 !anEvent->doesFloat());
407 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 403 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
408 404
409 // events that have time associated but take up no time should 405 // events that have time associated but take up no time should
410 // not have both DTSTART and DTEND. 406 // not have both DTSTART and DTEND.
411 if (anEvent->dtStart() != anEvent->dtEnd()) { 407 if (anEvent->dtStart() != anEvent->dtEnd()) {
412 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 408 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
413 !anEvent->doesFloat()); 409 !anEvent->doesFloat());
414 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 410 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
415 } 411 }
416 412
417 // creation date 413 // creation date
418 tmpStr = qDateTimeToISO(anEvent->created()); 414 tmpStr = qDateTimeToISO(anEvent->created());
419 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 415 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
420 416
421 // unique id 417 // unique id
422 addPropValue(vevent, VCUniqueStringProp, 418 addPropValue(vevent, VCUniqueStringProp,
423 anEvent->uid().local8Bit()); 419 anEvent->uid().local8Bit());
424 420
425 // revision 421 // revision
426 tmpStr.sprintf("%i", anEvent->revision()); 422 tmpStr.sprintf("%i", anEvent->revision());
427 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 423 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
428 424
429 // last modification date 425 // last modification date
430 tmpStr = qDateTimeToISO(anEvent->lastModified()); 426 tmpStr = qDateTimeToISO(anEvent->lastModified());
431 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 427 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
432 428
433 // attendee and organizer stuff 429 // attendee and organizer stuff
434 tmpStr = "MAILTO:" + anEvent->organizer(); 430 tmpStr = "MAILTO:" + anEvent->organizer();
435 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 431 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
436 432
437 if (anEvent->attendeeCount() != 0) { 433 if (anEvent->attendeeCount() != 0) {
438 QPtrList<Attendee> al = anEvent->attendees(); 434 QPtrList<Attendee> al = anEvent->attendees();
439 QPtrListIterator<Attendee> ai(al); 435 QPtrListIterator<Attendee> ai(al);
440 Attendee *curAttendee; 436 Attendee *curAttendee;
441 437
442 // TODO: Put this functionality into Attendee class 438 // TODO: Put this functionality into Attendee class
443 for (; ai.current(); ++ai) { 439 for (; ai.current(); ++ai) {
444 curAttendee = ai.current(); 440 curAttendee = ai.current();
445 if (!curAttendee->email().isEmpty() && 441 if (!curAttendee->email().isEmpty() &&
446 !curAttendee->name().isEmpty()) 442 !curAttendee->name().isEmpty())
447 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 443 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
448 curAttendee->email() + ">"; 444 curAttendee->email() + ">";
449 else if (curAttendee->name().isEmpty()) 445 else if (curAttendee->name().isEmpty())
450 tmpStr = "MAILTO: " + curAttendee->email(); 446 tmpStr = "MAILTO: " + curAttendee->email();
451 else if (curAttendee->email().isEmpty()) 447 else if (curAttendee->email().isEmpty())
452 tmpStr = "MAILTO: " + curAttendee->name(); 448 tmpStr = "MAILTO: " + curAttendee->name();
453 else if (curAttendee->name().isEmpty() && 449 else if (curAttendee->name().isEmpty() &&
454 curAttendee->email().isEmpty()) 450 curAttendee->email().isEmpty())
455 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 451 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
456 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 452 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
457 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; 453 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
458 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 454 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
459 } 455 }
460 } 456 }
461 457
462 // recurrence rule stuff 458 // recurrence rule stuff
463 if (anEvent->recurrence()->doesRecur()) { 459 if (anEvent->recurrence()->doesRecur()) {
464 // some more variables 460 // some more variables
465 QPtrList<Recurrence::rMonthPos> tmpPositions; 461 QPtrList<Recurrence::rMonthPos> tmpPositions;
466 QPtrList<int> tmpDays; 462 QPtrList<int> tmpDays;
467 int *tmpDay; 463 int *tmpDay;
468 Recurrence::rMonthPos *tmpPos; 464 Recurrence::rMonthPos *tmpPos;
469 QString tmpStr2; 465 QString tmpStr2;
470 int i; 466 int i;
471 467
472 switch(anEvent->recurrence()->doesRecur()) { 468 switch(anEvent->recurrence()->doesRecur()) {
473 case Recurrence::rDaily: 469 case Recurrence::rDaily:
474 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 470 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
475// if (anEvent->rDuration > 0) 471// if (anEvent->rDuration > 0)
476 //tmpStr += "#"; 472 //tmpStr += "#";
477 break; 473 break;
478 case Recurrence::rWeekly: 474 case Recurrence::rWeekly:
479 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); 475 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency());
480 for (i = 0; i < 7; i++) { 476 for (i = 0; i < 7; i++) {
481 if (anEvent->recurrence()->days().testBit(i)) 477 if (anEvent->recurrence()->days().testBit(i))
482 tmpStr += dayFromNum(i); 478 tmpStr += dayFromNum(i);
483 } 479 }
484 break; 480 break;
485 case Recurrence::rMonthlyPos: 481 case Recurrence::rMonthlyPos:
486 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); 482 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency());
487 // write out all rMonthPos's 483 // write out all rMonthPos's
488 tmpPositions = anEvent->recurrence()->monthPositions(); 484 tmpPositions = anEvent->recurrence()->monthPositions();
489 for (tmpPos = tmpPositions.first(); 485 for (tmpPos = tmpPositions.first();
490 tmpPos; 486 tmpPos;
491 tmpPos = tmpPositions.next()) { 487 tmpPos = tmpPositions.next()) {
492 488
493 tmpStr2.sprintf("%i", tmpPos->rPos); 489 tmpStr2.sprintf("%i", tmpPos->rPos);
494 if (tmpPos->negative) 490 if (tmpPos->negative)
495 tmpStr2 += "- "; 491 tmpStr2 += "- ";
496 else 492 else
497 tmpStr2 += "+ "; 493 tmpStr2 += "+ ";
498 tmpStr += tmpStr2; 494 tmpStr += tmpStr2;
499 for (i = 0; i < 7; i++) { 495 for (i = 0; i < 7; i++) {
500 if (tmpPos->rDays.testBit(i)) 496 if (tmpPos->rDays.testBit(i))
501 tmpStr += dayFromNum(i); 497 tmpStr += dayFromNum(i);
502 } 498 }
503 } // loop for all rMonthPos's 499 } // loop for all rMonthPos's
504 break; 500 break;
505 case Recurrence::rMonthlyDay: 501 case Recurrence::rMonthlyDay:
506 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); 502 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency());
507 // write out all rMonthDays; 503 // write out all rMonthDays;
508 tmpDays = anEvent->recurrence()->monthDays(); 504 tmpDays = anEvent->recurrence()->monthDays();
509 for (tmpDay = tmpDays.first(); 505 for (tmpDay = tmpDays.first();
510 tmpDay; 506 tmpDay;
511 tmpDay = tmpDays.next()) { 507 tmpDay = tmpDays.next()) {
512 tmpStr2.sprintf("%i ", *tmpDay); 508 tmpStr2.sprintf("%i ", *tmpDay);
513 tmpStr += tmpStr2; 509 tmpStr += tmpStr2;
514 } 510 }
515 break; 511 break;
516 case Recurrence::rYearlyMonth: 512 case Recurrence::rYearlyMonth:
517 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); 513 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency());
518 // write out all the rYearNums; 514 // write out all the rYearNums;
519 tmpDays = anEvent->recurrence()->yearNums(); 515 tmpDays = anEvent->recurrence()->yearNums();
520 for (tmpDay = tmpDays.first(); 516 for (tmpDay = tmpDays.first();
521 tmpDay; 517 tmpDay;
522 tmpDay = tmpDays.next()) { 518 tmpDay = tmpDays.next()) {
523 tmpStr2.sprintf("%i ", *tmpDay); 519 tmpStr2.sprintf("%i ", *tmpDay);
524 tmpStr += tmpStr2; 520 tmpStr += tmpStr2;
525 } 521 }
526 break; 522 break;
527 case Recurrence::rYearlyDay: 523 case Recurrence::rYearlyDay:
528 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); 524 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency());
529 // write out all the rYearNums; 525 // write out all the rYearNums;
530 tmpDays = anEvent->recurrence()->yearNums(); 526 tmpDays = anEvent->recurrence()->yearNums();
531 for (tmpDay = tmpDays.first(); 527 for (tmpDay = tmpDays.first();
532 tmpDay; 528 tmpDay;
533 tmpDay = tmpDays.next()) { 529 tmpDay = tmpDays.next()) {
534 tmpStr2.sprintf("%i ", *tmpDay); 530 tmpStr2.sprintf("%i ", *tmpDay);
535 tmpStr += tmpStr2; 531 tmpStr += tmpStr2;
536 } 532 }
537 break; 533 break;
538 default: 534 default:
539 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; 535 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl;
540 break; 536 break;
541 } // switch 537 } // switch
542 538
543 if (anEvent->recurrence()->duration() > 0) { 539 if (anEvent->recurrence()->duration() > 0) {
544 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); 540 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration());
545 tmpStr += tmpStr2; 541 tmpStr += tmpStr2;
546 } else if (anEvent->recurrence()->duration() == -1) { 542 } else if (anEvent->recurrence()->duration() == -1) {
547 tmpStr += "#0"; // defined as repeat forever 543 tmpStr += "#0"; // defined as repeat forever
548 } else { 544 } else {