summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-10 19:41:31 (UTC)
committer zautrix <zautrix>2004-08-10 19:41:31 (UTC)
commit2f1b58e344b882578977dd3786f7a94495096d22 (patch) (unidiff)
tree6658bef546b6feac1688aa465ca94344e15704d7 /libkcal
parent467e50111dfd6d66aca205501b6bf369b7f0a166 (diff)
downloadkdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.zip
kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.gz
kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.bz2
More syncing stuff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp15
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/incidencebase.cpp3
-rw-r--r--libkcal/phoneformat.cpp227
-rw-r--r--libkcal/phoneformat.h4
-rw-r--r--libkcal/vcalformat.cpp7
-rw-r--r--libkcal/vcalformat.h4
7 files changed, 221 insertions, 40 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 32aac7a..a3977d7 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,426 +1,441 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,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 <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h"
33 34
34using namespace KCal; 35using namespace KCal;
35 36
36Calendar::Calendar() 37Calendar::Calendar()
37{ 38{
38 39
39 init(); 40 init();
40 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); 41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") );
41} 42}
42 43
43Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
44{ 45{
45 46
46 init(); 47 init();
47 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
48} 49}
49 50
50void Calendar::init() 51void Calendar::init()
51{ 52{
52 mObserver = 0; 53 mObserver = 0;
53 mNewObserver = false; 54 mNewObserver = false;
54 55
55 mModified = false; 56 mModified = false;
56 57
57 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
58 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
59 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
60 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
61 62
62 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
63 // even that good of one at that. 64 // even that good of one at that.
64// srandom(time(0)); 65// srandom(time(0));
65 66
66 // user information... 67 // user information...
67 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
68 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
69 70
70#if 0 71#if 0
71 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
72// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
73 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
74 extern long int timezone; 75 extern long int timezone;
75 struct tm *now; 76 struct tm *now;
76 time_t curtime; 77 time_t curtime;
77 curtime = time(0); 78 curtime = time(0);
78 now = localtime(&curtime); 79 now = localtime(&curtime);
79 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
80 if (now->tm_isdst) 81 if (now->tm_isdst)
81 hourOff += 1; 82 hourOff += 1;
82 QString tzStr; 83 QString tzStr;
83 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
84 hourOff, 85 hourOff,
85 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
86 87
87 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
88 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
89// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
90 } else { 91 } else {
91 tzStr = tmpStr; 92 tzStr = tmpStr;
92 } 93 }
93 94
94 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
95 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
96 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
97 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
98 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
99 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
100 } 101 }
101 102
102 setTimeZone(tzStr); 103 setTimeZone(tzStr);
103#endif 104#endif
104 105
105// KOPrefs::instance()->writeConfig(); 106// KOPrefs::instance()->writeConfig();
106} 107}
107 108
108Calendar::~Calendar() 109Calendar::~Calendar()
109{ 110{
110 delete mDefaultFilter; 111 delete mDefaultFilter;
111} 112}
112 113
113const QString &Calendar::getOwner() const 114const QString &Calendar::getOwner() const
114{ 115{
115 return mOwner; 116 return mOwner;
116} 117}
117 118
118void Calendar::setOwner(const QString &os) 119void Calendar::setOwner(const QString &os)
119{ 120{
120 int i; 121 int i;
121 mOwner = os; 122 mOwner = os;
122 i = mOwner.find(','); 123 i = mOwner.find(',');
123 if (i != -1) 124 if (i != -1)
124 mOwner = mOwner.left(i); 125 mOwner = mOwner.left(i);
125 126
126 setModified( true ); 127 setModified( true );
127} 128}
128 129
129void Calendar::setTimeZone(const QString & tz) 130void Calendar::setTimeZone(const QString & tz)
130{ 131{
131 bool neg = FALSE; 132 bool neg = FALSE;
132 int hours, minutes; 133 int hours, minutes;
133 QString tmpStr(tz); 134 QString tmpStr(tz);
134 135
135 if (tmpStr.left(1) == "-") 136 if (tmpStr.left(1) == "-")
136 neg = TRUE; 137 neg = TRUE;
137 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
138 tmpStr.remove(0, 1); 139 tmpStr.remove(0, 1);
139 hours = tmpStr.left(2).toInt(); 140 hours = tmpStr.left(2).toInt();
140 if (tmpStr.length() > 2) 141 if (tmpStr.length() > 2)
141 minutes = tmpStr.right(2).toInt(); 142 minutes = tmpStr.right(2).toInt();
142 else 143 else
143 minutes = 0; 144 minutes = 0;
144 mTimeZone = (60*hours+minutes); 145 mTimeZone = (60*hours+minutes);
145 if (neg) 146 if (neg)
146 mTimeZone = -mTimeZone; 147 mTimeZone = -mTimeZone;
147 mLocalTime = false; 148 mLocalTime = false;
148 149
149 setModified( true ); 150 setModified( true );
150} 151}
151 152
152QString Calendar::getTimeZoneStr() const 153QString Calendar::getTimeZoneStr() const
153{ 154{
154 if (mLocalTime) 155 if (mLocalTime)
155 return ""; 156 return "";
156 QString tmpStr; 157 QString tmpStr;
157 int hours = abs(mTimeZone / 60); 158 int hours = abs(mTimeZone / 60);
158 int minutes = abs(mTimeZone % 60); 159 int minutes = abs(mTimeZone % 60);
159 bool neg = mTimeZone < 0; 160 bool neg = mTimeZone < 0;
160 161
161 tmpStr.sprintf("%c%.2d%.2d", 162 tmpStr.sprintf("%c%.2d%.2d",
162 (neg ? '-' : '+'), 163 (neg ? '-' : '+'),
163 hours, minutes); 164 hours, minutes);
164 return tmpStr; 165 return tmpStr;
165} 166}
166 167
167void Calendar::setTimeZone(int tz) 168void Calendar::setTimeZone(int tz)
168{ 169{
169 mTimeZone = tz; 170 mTimeZone = tz;
170 mLocalTime = false; 171 mLocalTime = false;
171 172
172 setModified( true ); 173 setModified( true );
173} 174}
174 175
175int Calendar::getTimeZone() const 176int Calendar::getTimeZone() const
176{ 177{
177 return mTimeZone; 178 return mTimeZone;
178} 179}
179 180
180void Calendar::setTimeZoneId(const QString &id) 181void Calendar::setTimeZoneId(const QString &id)
181{ 182{
182 mTimeZoneId = id; 183 mTimeZoneId = id;
183 mLocalTime = false; 184 mLocalTime = false;
184 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
185 if ( mTimeZone > 1000) 186 if ( mTimeZone > 1000)
186 setLocalTime(); 187 setLocalTime();
187 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
188 setModified( true ); 189 setModified( true );
189} 190}
190 191
191QString Calendar::timeZoneId() const 192QString Calendar::timeZoneId() const
192{ 193{
193 return mTimeZoneId; 194 return mTimeZoneId;
194} 195}
195 196
196void Calendar::setLocalTime() 197void Calendar::setLocalTime()
197{ 198{
198 //qDebug("Calendar::setLocalTime() "); 199 //qDebug("Calendar::setLocalTime() ");
199 mLocalTime = true; 200 mLocalTime = true;
200 mTimeZone = 0; 201 mTimeZone = 0;
201 mTimeZoneId = ""; 202 mTimeZoneId = "";
202 203
203 setModified( true ); 204 setModified( true );
204} 205}
205 206
206bool Calendar::isLocalTime() const 207bool Calendar::isLocalTime() const
207{ 208{
208 return mLocalTime; 209 return mLocalTime;
209} 210}
210 211
211const QString &Calendar::getEmail() 212const QString &Calendar::getEmail()
212{ 213{
213 return mOwnerEmail; 214 return mOwnerEmail;
214} 215}
215 216
216void Calendar::setEmail(const QString &e) 217void Calendar::setEmail(const QString &e)
217{ 218{
218 mOwnerEmail = e; 219 mOwnerEmail = e;
219 220
220 setModified( true ); 221 setModified( true );
221} 222}
222 223
223void Calendar::setFilter(CalFilter *filter) 224void Calendar::setFilter(CalFilter *filter)
224{ 225{
225 mFilter = filter; 226 mFilter = filter;
226} 227}
227 228
228CalFilter *Calendar::filter() 229CalFilter *Calendar::filter()
229{ 230{
230 return mFilter; 231 return mFilter;
231} 232}
232 233
233QPtrList<Incidence> Calendar::incidences() 234QPtrList<Incidence> Calendar::incidences()
234{ 235{
235 QPtrList<Incidence> incidences; 236 QPtrList<Incidence> incidences;
236 237
237 Incidence *i; 238 Incidence *i;
238 239
239 QPtrList<Event> e = events(); 240 QPtrList<Event> e = events();
240 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 241 for( i = e.first(); i; i = e.next() ) incidences.append( i );
241 242
242 QPtrList<Todo> t = todos(); 243 QPtrList<Todo> t = todos();
243 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 244 for( i = t.first(); i; i = t.next() ) incidences.append( i );
244 245
245 QPtrList<Journal> j = journals(); 246 QPtrList<Journal> j = journals();
246 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 247 for( i = j.first(); i; i = j.next() ) incidences.append( i );
247 248
248 return incidences; 249 return incidences;
249} 250}
251void Calendar::resetTempSyncStat()
252{
253 QPtrList<Incidence> incidences;
254
255 Incidence *i;
256
257 QPtrList<Event> e = rawEvents();
258 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
250 259
260 QPtrList<Todo> t = rawTodos();
261 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
262
263 QPtrList<Journal> j = journals();
264 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
265}
251QPtrList<Incidence> Calendar::rawIncidences() 266QPtrList<Incidence> Calendar::rawIncidences()
252{ 267{
253 QPtrList<Incidence> incidences; 268 QPtrList<Incidence> incidences;
254 269
255 Incidence *i; 270 Incidence *i;
256 271
257 QPtrList<Event> e = rawEvents(); 272 QPtrList<Event> e = rawEvents();
258 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 273 for( i = e.first(); i; i = e.next() ) incidences.append( i );
259 274
260 QPtrList<Todo> t = rawTodos(); 275 QPtrList<Todo> t = rawTodos();
261 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 276 for( i = t.first(); i; i = t.next() ) incidences.append( i );
262 277
263 QPtrList<Journal> j = journals(); 278 QPtrList<Journal> j = journals();
264 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 279 for( i = j.first(); i; i = j.next() ) incidences.append( i );
265 280
266 return incidences; 281 return incidences;
267} 282}
268 283
269QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 284QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
270{ 285{
271 QPtrList<Event> el = rawEventsForDate(date,sorted); 286 QPtrList<Event> el = rawEventsForDate(date,sorted);
272 mFilter->apply(&el); 287 mFilter->apply(&el);
273 return el; 288 return el;
274} 289}
275 290
276QPtrList<Event> Calendar::events( const QDateTime &qdt ) 291QPtrList<Event> Calendar::events( const QDateTime &qdt )
277{ 292{
278 QPtrList<Event> el = rawEventsForDate(qdt); 293 QPtrList<Event> el = rawEventsForDate(qdt);
279 mFilter->apply(&el); 294 mFilter->apply(&el);
280 return el; 295 return el;
281} 296}
282 297
283QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 298QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
284 bool inclusive) 299 bool inclusive)
285{ 300{
286 QPtrList<Event> el = rawEvents(start,end,inclusive); 301 QPtrList<Event> el = rawEvents(start,end,inclusive);
287 mFilter->apply(&el); 302 mFilter->apply(&el);
288 return el; 303 return el;
289} 304}
290 305
291QPtrList<Event> Calendar::events() 306QPtrList<Event> Calendar::events()
292{ 307{
293 QPtrList<Event> el = rawEvents(); 308 QPtrList<Event> el = rawEvents();
294 mFilter->apply(&el); 309 mFilter->apply(&el);
295 return el; 310 return el;
296} 311}
297 312
298 313
299bool Calendar::addIncidence(Incidence *i) 314bool Calendar::addIncidence(Incidence *i)
300{ 315{
301 Incidence::AddVisitor<Calendar> v(this); 316 Incidence::AddVisitor<Calendar> v(this);
302 317
303 return i->accept(v); 318 return i->accept(v);
304} 319}
305void Calendar::deleteIncidence(Incidence *in) 320void Calendar::deleteIncidence(Incidence *in)
306{ 321{
307 if ( in->type() == "Event" ) 322 if ( in->type() == "Event" )
308 deleteEvent( (Event*) in ); 323 deleteEvent( (Event*) in );
309 else if ( in->type() =="Todo" ) 324 else if ( in->type() =="Todo" )
310 deleteTodo( (Todo*) in); 325 deleteTodo( (Todo*) in);
311 else if ( in->type() =="Journal" ) 326 else if ( in->type() =="Journal" )
312 deleteJournal( (Journal*) in ); 327 deleteJournal( (Journal*) in );
313} 328}
314 329
315Incidence* Calendar::incidence( const QString& uid ) 330Incidence* Calendar::incidence( const QString& uid )
316{ 331{
317 Incidence* i; 332 Incidence* i;
318 333
319 if( (i = todo( uid )) != 0 ) 334 if( (i = todo( uid )) != 0 )
320 return i; 335 return i;
321 if( (i = event( uid )) != 0 ) 336 if( (i = event( uid )) != 0 )
322 return i; 337 return i;
323 if( (i = journal( uid )) != 0 ) 338 if( (i = journal( uid )) != 0 )
324 return i; 339 return i;
325 340
326 return 0; 341 return 0;
327} 342}
328 343
329QPtrList<Todo> Calendar::todos() 344QPtrList<Todo> Calendar::todos()
330{ 345{
331 QPtrList<Todo> tl = rawTodos(); 346 QPtrList<Todo> tl = rawTodos();
332 mFilter->apply( &tl ); 347 mFilter->apply( &tl );
333 return tl; 348 return tl;
334} 349}
335 350
336// When this is called, the todo have already been added to the calendar. 351// When this is called, the todo have already been added to the calendar.
337// This method is only about linking related todos 352// This method is only about linking related todos
338void Calendar::setupRelations( Incidence *incidence ) 353void Calendar::setupRelations( Incidence *incidence )
339{ 354{
340 QString uid = incidence->uid(); 355 QString uid = incidence->uid();
341 //qDebug("Calendar::setupRelations "); 356 //qDebug("Calendar::setupRelations ");
342 // First, go over the list of orphans and see if this is their parent 357 // First, go over the list of orphans and see if this is their parent
343 while( Incidence* i = mOrphans[ uid ] ) { 358 while( Incidence* i = mOrphans[ uid ] ) {
344 mOrphans.remove( uid ); 359 mOrphans.remove( uid );
345 i->setRelatedTo( incidence ); 360 i->setRelatedTo( incidence );
346 incidence->addRelation( i ); 361 incidence->addRelation( i );
347 mOrphanUids.remove( i->uid() ); 362 mOrphanUids.remove( i->uid() );
348 } 363 }
349 364
350 // Now see about this incidences parent 365 // Now see about this incidences parent
351 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 366 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
352 // This incidence has a uid it is related to, but is not registered to it yet 367 // This incidence has a uid it is related to, but is not registered to it yet
353 // Try to find it 368 // Try to find it
354 Incidence* parent = this->incidence( incidence->relatedToUid() ); 369 Incidence* parent = this->incidence( incidence->relatedToUid() );
355 if( parent ) { 370 if( parent ) {
356 // Found it 371 // Found it
357 incidence->setRelatedTo( parent ); 372 incidence->setRelatedTo( parent );
358 parent->addRelation( incidence ); 373 parent->addRelation( incidence );
359 } else { 374 } else {
360 // Not found, put this in the mOrphans list 375 // Not found, put this in the mOrphans list
361 mOrphans.insert( incidence->relatedToUid(), incidence ); 376 mOrphans.insert( incidence->relatedToUid(), incidence );
362 mOrphanUids.insert( incidence->uid(), incidence ); 377 mOrphanUids.insert( incidence->uid(), incidence );
363 } 378 }
364 } 379 }
365} 380}
366 381
367// If a task with subtasks is deleted, move it's subtasks to the orphans list 382// If a task with subtasks is deleted, move it's subtasks to the orphans list
368void Calendar::removeRelations( Incidence *incidence ) 383void Calendar::removeRelations( Incidence *incidence )
369{ 384{
370 // qDebug("Calendar::removeRelations "); 385 // qDebug("Calendar::removeRelations ");
371 QString uid = incidence->uid(); 386 QString uid = incidence->uid();
372 387
373 QPtrList<Incidence> relations = incidence->relations(); 388 QPtrList<Incidence> relations = incidence->relations();
374 for( Incidence* i = relations.first(); i; i = relations.next() ) 389 for( Incidence* i = relations.first(); i; i = relations.next() )
375 if( !mOrphanUids.find( i->uid() ) ) { 390 if( !mOrphanUids.find( i->uid() ) ) {
376 mOrphans.insert( uid, i ); 391 mOrphans.insert( uid, i );
377 mOrphanUids.insert( i->uid(), i ); 392 mOrphanUids.insert( i->uid(), i );
378 i->setRelatedTo( 0 ); 393 i->setRelatedTo( 0 );
379 i->setRelatedToUid( uid ); 394 i->setRelatedToUid( uid );
380 } 395 }
381 396
382 // If this incidence is related to something else, tell that about it 397 // If this incidence is related to something else, tell that about it
383 if( incidence->relatedTo() ) 398 if( incidence->relatedTo() )
384 incidence->relatedTo()->removeRelation( incidence ); 399 incidence->relatedTo()->removeRelation( incidence );
385 400
386 // Remove this one from the orphans list 401 // Remove this one from the orphans list
387 if( mOrphanUids.remove( uid ) ) 402 if( mOrphanUids.remove( uid ) )
388 // This incidence is located in the orphans list - it should be removed 403 // This incidence is located in the orphans list - it should be removed
389 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 404 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
390 // Removing wasn't that easy 405 // Removing wasn't that easy
391 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 406 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
392 if( it.current()->uid() == uid ) { 407 if( it.current()->uid() == uid ) {
393 mOrphans.remove( it.currentKey() ); 408 mOrphans.remove( it.currentKey() );
394 break; 409 break;
395 } 410 }
396 } 411 }
397 } 412 }
398} 413}
399 414
400void Calendar::registerObserver( Observer *observer ) 415void Calendar::registerObserver( Observer *observer )
401{ 416{
402 mObserver = observer; 417 mObserver = observer;
403 mNewObserver = true; 418 mNewObserver = true;
404} 419}
405 420
406void Calendar::setModified( bool modified ) 421void Calendar::setModified( bool modified )
407{ 422{
408 if ( mObserver ) mObserver->calendarModified( modified, this ); 423 if ( mObserver ) mObserver->calendarModified( modified, this );
409 if ( modified != mModified || mNewObserver ) { 424 if ( modified != mModified || mNewObserver ) {
410 mNewObserver = false; 425 mNewObserver = false;
411 // if ( mObserver ) mObserver->calendarModified( modified, this ); 426 // if ( mObserver ) mObserver->calendarModified( modified, this );
412 mModified = modified; 427 mModified = modified;
413 } 428 }
414} 429}
415 430
416void Calendar::setLoadedProductId( const QString &id ) 431void Calendar::setLoadedProductId( const QString &id )
417{ 432{
418 mLoadedProductId = id; 433 mLoadedProductId = id;
419} 434}
420 435
421QString Calendar::loadedProductId() 436QString Calendar::loadedProductId()
422{ 437{
423 return mLoadedProductId; 438 return mLoadedProductId;
424} 439}
425 440
426//#include "calendar.moc" 441//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4a3223c..06a911c 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,350 +1,351 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
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#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35 35
36#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 36#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
37 37
38class KConfig; 38class KConfig;
39 39
40namespace KCal { 40namespace KCal {
41 41
42class CalFilter; 42class CalFilter;
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 void deleteIncidence(Incidence *in); 68 void deleteIncidence(Incidence *in);
69 void resetTempSyncStat();
69 /** 70 /**
70 Clears out the current calendar, freeing all used memory etc. 71 Clears out the current calendar, freeing all used memory etc.
71 */ 72 */
72 virtual void close() = 0; 73 virtual void close() = 0;
73 74
74 /** 75 /**
75 Sync changes in memory to persistant storage. 76 Sync changes in memory to persistant storage.
76 */ 77 */
77 virtual void save() = 0; 78 virtual void save() = 0;
78 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 79 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
79 virtual bool isSaving() { return false; } 80 virtual bool isSaving() { return false; }
80 81
81 /** 82 /**
82 Return the owner of the calendar's full name. 83 Return the owner of the calendar's full name.
83 */ 84 */
84 const QString &getOwner() const; 85 const QString &getOwner() const;
85 /** 86 /**
86 Set the owner of the calendar. Should be owner's full name. 87 Set the owner of the calendar. Should be owner's full name.
87 */ 88 */
88 void setOwner( const QString &os ); 89 void setOwner( const QString &os );
89 /** 90 /**
90 Return the email address of the calendar owner. 91 Return the email address of the calendar owner.
91 */ 92 */
92 const QString &getEmail(); 93 const QString &getEmail();
93 /** 94 /**
94 Set the email address of the calendar owner. 95 Set the email address of the calendar owner.
95 */ 96 */
96 void setEmail( const QString & ); 97 void setEmail( const QString & );
97 98
98 /** 99 /**
99 Set time zone from a timezone string (e.g. -2:00) 100 Set time zone from a timezone string (e.g. -2:00)
100 */ 101 */
101 void setTimeZone( const QString &tz ); 102 void setTimeZone( const QString &tz );
102 /** 103 /**
103 Set time zone from a minutes value (e.g. -60) 104 Set time zone from a minutes value (e.g. -60)
104 */ 105 */
105 void setTimeZone( int tz ); 106 void setTimeZone( int tz );
106 /** 107 /**
107 Return time zone as offest in minutes. 108 Return time zone as offest in minutes.
108 */ 109 */
109 int getTimeZone() const; 110 int getTimeZone() const;
110 /** 111 /**
111 Compute an ISO 8601 format string from the time zone. 112 Compute an ISO 8601 format string from the time zone.
112 */ 113 */
113 QString getTimeZoneStr() const; 114 QString getTimeZoneStr() const;
114 /** 115 /**
115 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 116 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
116 values). 117 values).
117 */ 118 */
118 void setTimeZoneId( const QString & ); 119 void setTimeZoneId( const QString & );
119 /** 120 /**
120 Return time zone id. 121 Return time zone id.
121 */ 122 */
122 QString timeZoneId() const; 123 QString timeZoneId() const;
123 /** 124 /**
124 Use local time, not UTC or a time zone. 125 Use local time, not UTC or a time zone.
125 */ 126 */
126 void setLocalTime(); 127 void setLocalTime();
127 /** 128 /**
128 Return whether local time is being used. 129 Return whether local time is being used.
129 */ 130 */
130 bool isLocalTime() const; 131 bool isLocalTime() const;
131 132
132 /** 133 /**
133 Add an incidence to calendar. 134 Add an incidence to calendar.
134 135
135 @return true on success, false on error. 136 @return true on success, false on error.
136 */ 137 */
137 virtual bool addIncidence( Incidence * ); 138 virtual bool addIncidence( Incidence * );
138 /** 139 /**
139 Return filtered list of all incidences of this calendar. 140 Return filtered list of all incidences of this calendar.
140 */ 141 */
141 virtual QPtrList<Incidence> incidences(); 142 virtual QPtrList<Incidence> incidences();
142 143
143 /** 144 /**
144 Return unfiltered list of all incidences of this calendar. 145 Return unfiltered list of all incidences of this calendar.
145 */ 146 */
146 virtual QPtrList<Incidence> rawIncidences(); 147 virtual QPtrList<Incidence> rawIncidences();
147 148
148 /** 149 /**
149 Adds a Event to this calendar object. 150 Adds a Event to this calendar object.
150 @param anEvent a pointer to the event to add 151 @param anEvent a pointer to the event to add
151 152
152 @return true on success, false on error. 153 @return true on success, false on error.
153 */ 154 */
154 virtual bool addEventNoDup( Event *event ) = 0; 155 virtual bool addEventNoDup( Event *event ) = 0;
155 virtual bool addAnniversaryNoDup( Event *event ) = 0; 156 virtual bool addAnniversaryNoDup( Event *event ) = 0;
156 virtual bool addEvent( Event *anEvent ) = 0; 157 virtual bool addEvent( Event *anEvent ) = 0;
157 /** 158 /**
158 Delete event from calendar. 159 Delete event from calendar.
159 */ 160 */
160 virtual void deleteEvent( Event * ) = 0; 161 virtual void deleteEvent( Event * ) = 0;
161 /** 162 /**
162 Retrieves an event on the basis of the unique string ID. 163 Retrieves an event on the basis of the unique string ID.
163 */ 164 */
164 virtual Event *event( const QString &UniqueStr ) = 0; 165 virtual Event *event( const QString &UniqueStr ) = 0;
165 virtual Event *event( QString, QString ) = 0; 166 virtual Event *event( QString, QString ) = 0;
166 /** 167 /**
167 Builds and then returns a list of all events that match for the 168 Builds and then returns a list of all events that match for the
168 date specified. useful for dayView, etc. etc. 169 date specified. useful for dayView, etc. etc.
169 The calendar filter is applied. 170 The calendar filter is applied.
170 */ 171 */
171 QPtrList<Event> events( const QDate &date, bool sorted = false); 172 QPtrList<Event> events( const QDate &date, bool sorted = false);
172 /** 173 /**
173 Get events, which occur on the given date. 174 Get events, which occur on the given date.
174 The calendar filter is applied. 175 The calendar filter is applied.
175 */ 176 */
176 QPtrList<Event> events( const QDateTime &qdt ); 177 QPtrList<Event> events( const QDateTime &qdt );
177 /** 178 /**
178 Get events in a range of dates. If inclusive is set to true, only events 179 Get events in a range of dates. If inclusive is set to true, only events
179 are returned, which are completely included in the range. 180 are returned, which are completely included in the range.
180 The calendar filter is applied. 181 The calendar filter is applied.
181 */ 182 */
182 QPtrList<Event> events( const QDate &start, const QDate &end, 183 QPtrList<Event> events( const QDate &start, const QDate &end,
183 bool inclusive = false); 184 bool inclusive = false);
184 /** 185 /**
185 Return filtered list of all events in calendar. 186 Return filtered list of all events in calendar.
186 */ 187 */
187 virtual QPtrList<Event> events(); 188 virtual QPtrList<Event> events();
188 /** 189 /**
189 Return unfiltered list of all events in calendar. 190 Return unfiltered list of all events in calendar.
190 */ 191 */
191 virtual QPtrList<Event> rawEvents() = 0; 192 virtual QPtrList<Event> rawEvents() = 0;
192 193
193 /** 194 /**
194 Add a todo to the todolist. 195 Add a todo to the todolist.
195 196
196 @return true on success, false on error. 197 @return true on success, false on error.
197 */ 198 */
198 virtual bool addTodo( Todo *todo ) = 0; 199 virtual bool addTodo( Todo *todo ) = 0;
199 virtual bool addTodoNoDup( Todo *todo ) = 0; 200 virtual bool addTodoNoDup( Todo *todo ) = 0;
200 /** 201 /**
201 Remove a todo from the todolist. 202 Remove a todo from the todolist.
202 */ 203 */
203 virtual void deleteTodo( Todo * ) = 0; 204 virtual void deleteTodo( Todo * ) = 0;
204 virtual void deleteJournal( Journal * ) = 0; 205 virtual void deleteJournal( Journal * ) = 0;
205 /** 206 /**
206 Return filterd list of todos. 207 Return filterd list of todos.
207 */ 208 */
208 virtual QPtrList<Todo> todos(); 209 virtual QPtrList<Todo> todos();
209 /** 210 /**
210 Searches todolist for an event with this unique string identifier, 211 Searches todolist for an event with this unique string identifier,
211 returns a pointer or null. 212 returns a pointer or null.
212 */ 213 */
213 virtual Todo *todo( const QString &uid ) = 0; 214 virtual Todo *todo( const QString &uid ) = 0;
214 virtual Todo *todo( QString, QString ) = 0; 215 virtual Todo *todo( QString, QString ) = 0;
215 /** 216 /**
216 Returns list of todos due on the specified date. 217 Returns list of todos due on the specified date.
217 */ 218 */
218 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 219 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
219 /** 220 /**
220 Return unfiltered list of todos. 221 Return unfiltered list of todos.
221 */ 222 */
222 virtual QPtrList<Todo> rawTodos() = 0; 223 virtual QPtrList<Todo> rawTodos() = 0;
223 224
224 /** 225 /**
225 Add a Journal entry to calendar. 226 Add a Journal entry to calendar.
226 227
227 @return true on success, false on error. 228 @return true on success, false on error.
228 */ 229 */
229 virtual bool addJournal( Journal * ) = 0; 230 virtual bool addJournal( Journal * ) = 0;
230 /** 231 /**
231 Return Journal for given date. 232 Return Journal for given date.
232 */ 233 */
233 virtual Journal *journal( const QDate & ) = 0; 234 virtual Journal *journal( const QDate & ) = 0;
234 /** 235 /**
235 Return Journal with given UID. 236 Return Journal with given UID.
236 */ 237 */
237 virtual Journal *journal( const QString &UID ) = 0; 238 virtual Journal *journal( const QString &UID ) = 0;
238 /** 239 /**
239 Return list of all Journal entries. 240 Return list of all Journal entries.
240 */ 241 */
241 virtual QPtrList<Journal> journals() = 0; 242 virtual QPtrList<Journal> journals() = 0;
242 243
243 /** 244 /**
244 Searches all incidence types for an incidence with this unique 245 Searches all incidence types for an incidence with this unique
245 string identifier, returns a pointer or null. 246 string identifier, returns a pointer or null.
246 */ 247 */
247 Incidence* incidence( const QString&UID ); 248 Incidence* incidence( const QString&UID );
248 249
249 /** 250 /**
250 Setup relations for an incidence. 251 Setup relations for an incidence.
251 */ 252 */
252 virtual void setupRelations( Incidence * ); 253 virtual void setupRelations( Incidence * );
253 /** 254 /**
254 Remove all relations to an incidence 255 Remove all relations to an incidence
255 */ 256 */
256 virtual void removeRelations( Incidence * ); 257 virtual void removeRelations( Incidence * );
257 258
258 /** 259 /**
259 Set calendar filter, which filters events for the events() functions. 260 Set calendar filter, which filters events for the events() functions.
260 The Filter object is owned by the caller. 261 The Filter object is owned by the caller.
261 */ 262 */
262 void setFilter( CalFilter * ); 263 void setFilter( CalFilter * );
263 /** 264 /**
264 Return calendar filter. 265 Return calendar filter.
265 */ 266 */
266 CalFilter *filter(); 267 CalFilter *filter();
267 virtual QDateTime nextAlarm( int daysTo ) = 0; 268 virtual QDateTime nextAlarm( int daysTo ) = 0;
268 virtual QString nextSummary( ) const = 0; 269 virtual QString nextSummary( ) const = 0;
269 virtual void reInitAlarmSettings() = 0; 270 virtual void reInitAlarmSettings() = 0;
270 virtual QDateTime nextAlarmEventDateTime() const = 0; 271 virtual QDateTime nextAlarmEventDateTime() const = 0;
271 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 272 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
272 /** 273 /**
273 Return all alarms, which ocur in the given time interval. 274 Return all alarms, which ocur in the given time interval.
274 */ 275 */
275 virtual Alarm::List alarms( const QDateTime &from, 276 virtual Alarm::List alarms( const QDateTime &from,
276 const QDateTime &to ) = 0; 277 const QDateTime &to ) = 0;
277 278
278 class Observer { 279 class Observer {
279 public: 280 public:
280 virtual void calendarModified( bool, Calendar * ) = 0; 281 virtual void calendarModified( bool, Calendar * ) = 0;
281 }; 282 };
282 283
283 void registerObserver( Observer * ); 284 void registerObserver( Observer * );
284 285
285 void setModified( bool ); 286 void setModified( bool );
286 287
287 /** 288 /**
288 Set product id returned by loadedProductId(). This function is only 289 Set product id returned by loadedProductId(). This function is only
289 useful for the calendar loading code. 290 useful for the calendar loading code.
290 */ 291 */
291 void setLoadedProductId( const QString & ); 292 void setLoadedProductId( const QString & );
292 /** 293 /**
293 Return product id taken from file that has been loaded. Returns 294 Return product id taken from file that has been loaded. Returns
294 QString::null, if no calendar has been loaded. 295 QString::null, if no calendar has been loaded.
295 */ 296 */
296 QString loadedProductId(); 297 QString loadedProductId();
297 298
298 signals: 299 signals:
299 void calendarChanged(); 300 void calendarChanged();
300 void calendarSaved(); 301 void calendarSaved();
301 void calendarLoaded(); 302 void calendarLoaded();
302 void addAlarm(const QDateTime &qdt, const QString &noti ); 303 void addAlarm(const QDateTime &qdt, const QString &noti );
303 void removeAlarm(const QDateTime &qdt, const QString &noti ); 304 void removeAlarm(const QDateTime &qdt, const QString &noti );
304 305
305 protected: 306 protected:
306 /** 307 /**
307 Get unfiltered events, which occur on the given date. 308 Get unfiltered events, which occur on the given date.
308 */ 309 */
309 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 310 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
310 /** 311 /**
311 Get unfiltered events, which occur on the given date. 312 Get unfiltered events, which occur on the given date.
312 */ 313 */
313 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 314 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
314 bool sorted = false ) = 0; 315 bool sorted = false ) = 0;
315 /** 316 /**
316 Get events in a range of dates. If inclusive is set to true, only events 317 Get events in a range of dates. If inclusive is set to true, only events
317 are returned, which are completely included in the range. 318 are returned, which are completely included in the range.
318 */ 319 */
319 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 320 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
320 bool inclusive = false ) = 0; 321 bool inclusive = false ) = 0;
321 Incidence *mNextAlarmIncidence; 322 Incidence *mNextAlarmIncidence;
322 323
323private: 324private:
324 void init(); 325 void init();
325 326
326 QString mOwner; // who the calendar belongs to 327 QString mOwner; // who the calendar belongs to
327 QString mOwnerEmail; // email address of the owner 328 QString mOwnerEmail; // email address of the owner
328 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 329 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
329 bool mLocalTime; // use local time, not UTC or a time zone 330 bool mLocalTime; // use local time, not UTC or a time zone
330 331
331 CalFilter *mFilter; 332 CalFilter *mFilter;
332 CalFilter *mDefaultFilter; 333 CalFilter *mDefaultFilter;
333 334
334 QString mTimeZoneId; 335 QString mTimeZoneId;
335 336
336 Observer *mObserver; 337 Observer *mObserver;
337 bool mNewObserver; 338 bool mNewObserver;
338 339
339 bool mModified; 340 bool mModified;
340 341
341 QString mLoadedProductId; 342 QString mLoadedProductId;
342 343
343 // This list is used to put together related todos 344 // This list is used to put together related todos
344 QDict<Incidence> mOrphans; 345 QDict<Incidence> mOrphans;
345 QDict<Incidence> mOrphanUids; 346 QDict<Incidence> mOrphanUids;
346}; 347};
347 348
348} 349}
349 350
350#endif 351#endif
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 15c4fa8..64a343c 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,406 +1,407 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h"
27 28
28#include "incidencebase.h" 29#include "incidencebase.h"
29 30
30using namespace KCal; 31using namespace KCal;
31 32
32IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
33 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
34 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
35{ 36{
36 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
37 mOrganizer = ""; 38 mOrganizer = "";
38 mFloats = false; 39 mFloats = false;
39 mDuration = 0; 40 mDuration = 0;
40 mHasDuration = false; 41 mHasDuration = false;
41 mPilotId = 0; 42 mPilotId = 0;
42 mExternalId = ":"; 43 mExternalId = ":";
43 mTempSyncStat = 0; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
44 mSyncStatus = 0; 45 mSyncStatus = 0;
45 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
46} 47}
47 48
48IncidenceBase::IncidenceBase(const IncidenceBase &i) : 49IncidenceBase::IncidenceBase(const IncidenceBase &i) :
49 CustomProperties( i ) 50 CustomProperties( i )
50{ 51{
51 mReadOnly = i.mReadOnly; 52 mReadOnly = i.mReadOnly;
52 mDtStart = i.mDtStart; 53 mDtStart = i.mDtStart;
53 mDuration = i.mDuration; 54 mDuration = i.mDuration;
54 mHasDuration = i.mHasDuration; 55 mHasDuration = i.mHasDuration;
55 mOrganizer = i.mOrganizer; 56 mOrganizer = i.mOrganizer;
56 mUid = i.mUid; 57 mUid = i.mUid;
57 QPtrList<Attendee> attendees = i.attendees(); 58 QPtrList<Attendee> attendees = i.attendees();
58 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
59 mAttendees.append( new Attendee( *a ) ); 60 mAttendees.append( new Attendee( *a ) );
60 } 61 }
61 mFloats = i.mFloats; 62 mFloats = i.mFloats;
62 mLastModified = i.mLastModified; 63 mLastModified = i.mLastModified;
63 mPilotId = i.mPilotId; 64 mPilotId = i.mPilotId;
64 mTempSyncStat = i.mTempSyncStat; 65 mTempSyncStat = i.mTempSyncStat;
65 mSyncStatus = i.mSyncStatus; 66 mSyncStatus = i.mSyncStatus;
66 mExternalId = i.mExternalId; 67 mExternalId = i.mExternalId;
67 // The copied object is a new one, so it isn't observed by the observer 68 // The copied object is a new one, so it isn't observed by the observer
68 // of the original object. 69 // of the original object.
69 mObservers.clear(); 70 mObservers.clear();
70 71
71 mAttendees.setAutoDelete( true ); 72 mAttendees.setAutoDelete( true );
72} 73}
73 74
74IncidenceBase::~IncidenceBase() 75IncidenceBase::~IncidenceBase()
75{ 76{
76} 77}
77 78
78 79
79bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
80{ 81{
81 // do not compare mSyncStatus and mExternalId 82 // do not compare mSyncStatus and mExternalId
82 if( i1.attendees().count() != i2.attendees().count() ) { 83 if( i1.attendees().count() != i2.attendees().count() ) {
83 return false; // no need to check further 84 return false; // no need to check further
84 } 85 }
85 if ( i1.attendees().count() > 0 ) { 86 if ( i1.attendees().count() > 0 ) {
86 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
87 while ( a1 ) { 88 while ( a1 ) {
88 if ( !( (*a1) == (*a2)) ) 89 if ( !( (*a1) == (*a2)) )
89 { 90 {
90 //qDebug("Attendee not equal "); 91 //qDebug("Attendee not equal ");
91 return false; 92 return false;
92 } 93 }
93 a1 = i1.attendees().next(); 94 a1 = i1.attendees().next();
94 a2 = i2.attendees().next(); 95 a2 = i2.attendees().next();
95 } 96 }
96 } 97 }
97 //if ( i1.dtStart() != i2.dtStart() ) 98 //if ( i1.dtStart() != i2.dtStart() )
98 // return false; 99 // return false;
99#if 0 100#if 0
100 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
101 qDebug("1 %d ",i1.duration() == i2.duration() ); 102 qDebug("1 %d ",i1.duration() == i2.duration() );
102 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
103 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
104 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
105 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 106 qDebug("6 %d ",i1.organizer() == i2.organizer() );
106 107
107#endif 108#endif
108 return ( i1.organizer() == i2.organizer() && 109 return ( i1.organizer() == i2.organizer() &&
109 // i1.uid() == i2.uid() && 110 // i1.uid() == i2.uid() &&
110 // Don't compare lastModified, otherwise the operator is not 111 // Don't compare lastModified, otherwise the operator is not
111 // of much use. We are not comparing for identity, after all. 112 // of much use. We are not comparing for identity, after all.
112 i1.doesFloat() == i2.doesFloat() && 113 i1.doesFloat() == i2.doesFloat() &&
113 i1.duration() == i2.duration() && 114 i1.duration() == i2.duration() &&
114 i1.hasDuration() == i2.hasDuration() && 115 i1.hasDuration() == i2.hasDuration() &&
115 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
116 // no need to compare mObserver 117 // no need to compare mObserver
117} 118}
118 119
119 120
120QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 121QDateTime IncidenceBase::getEvenTime( QDateTime dt )
121{ 122{
122 QTime t = dt.time(); 123 QTime t = dt.time();
123 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
124 return dt; 125 return dt;
125} 126}
126 127
127 128
128void IncidenceBase::setUid(const QString &uid) 129void IncidenceBase::setUid(const QString &uid)
129{ 130{
130 mUid = uid; 131 mUid = uid;
131 updated(); 132 updated();
132} 133}
133 134
134QString IncidenceBase::uid() const 135QString IncidenceBase::uid() const
135{ 136{
136 return mUid; 137 return mUid;
137} 138}
138 139
139void IncidenceBase::setLastModified(const QDateTime &lm) 140void IncidenceBase::setLastModified(const QDateTime &lm)
140{ 141{
141 // DON'T! updated() because we call this from 142 // DON'T! updated() because we call this from
142 // Calendar::updateEvent(). 143 // Calendar::updateEvent().
143 mLastModified = getEvenTime(lm); 144 mLastModified = getEvenTime(lm);
144 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
145} 146}
146 147
147QDateTime IncidenceBase::lastModified() const 148QDateTime IncidenceBase::lastModified() const
148{ 149{
149 return mLastModified; 150 return mLastModified;
150} 151}
151 152
152void IncidenceBase::setOrganizer(const QString &o) 153void IncidenceBase::setOrganizer(const QString &o)
153{ 154{
154 // we don't check for readonly here, because it is 155 // we don't check for readonly here, because it is
155 // possible that by setting the organizer we are changing 156 // possible that by setting the organizer we are changing
156 // the event's readonly status... 157 // the event's readonly status...
157 mOrganizer = o; 158 mOrganizer = o;
158 if (mOrganizer.left(7).upper() == "MAILTO:") 159 if (mOrganizer.left(7).upper() == "MAILTO:")
159 mOrganizer = mOrganizer.remove(0,7); 160 mOrganizer = mOrganizer.remove(0,7);
160 161
161 updated(); 162 updated();
162} 163}
163 164
164QString IncidenceBase::organizer() const 165QString IncidenceBase::organizer() const
165{ 166{
166 return mOrganizer; 167 return mOrganizer;
167} 168}
168 169
169void IncidenceBase::setReadOnly( bool readOnly ) 170void IncidenceBase::setReadOnly( bool readOnly )
170{ 171{
171 mReadOnly = readOnly; 172 mReadOnly = readOnly;
172} 173}
173 174
174void IncidenceBase::setDtStart(const QDateTime &dtStart) 175void IncidenceBase::setDtStart(const QDateTime &dtStart)
175{ 176{
176// if (mReadOnly) return; 177// if (mReadOnly) return;
177 mDtStart = getEvenTime(dtStart); 178 mDtStart = getEvenTime(dtStart);
178 updated(); 179 updated();
179} 180}
180 181
181QDateTime IncidenceBase::dtStart() const 182QDateTime IncidenceBase::dtStart() const
182{ 183{
183 return mDtStart; 184 return mDtStart;
184} 185}
185 186
186QString IncidenceBase::dtStartTimeStr() const 187QString IncidenceBase::dtStartTimeStr() const
187{ 188{
188 return KGlobal::locale()->formatTime(dtStart().time()); 189 return KGlobal::locale()->formatTime(dtStart().time());
189} 190}
190 191
191QString IncidenceBase::dtStartDateStr(bool shortfmt) const 192QString IncidenceBase::dtStartDateStr(bool shortfmt) const
192{ 193{
193 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 194 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
194} 195}
195 196
196QString IncidenceBase::dtStartStr(bool shortfmt) const 197QString IncidenceBase::dtStartStr(bool shortfmt) const
197{ 198{
198 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 199 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
199} 200}
200 201
201 202
202bool IncidenceBase::doesFloat() const 203bool IncidenceBase::doesFloat() const
203{ 204{
204 return mFloats; 205 return mFloats;
205} 206}
206 207
207void IncidenceBase::setFloats(bool f) 208void IncidenceBase::setFloats(bool f)
208{ 209{
209 if (mReadOnly) return; 210 if (mReadOnly) return;
210 mFloats = f; 211 mFloats = f;
211 updated(); 212 updated();
212} 213}
213 214
214 215
215void IncidenceBase::addAttendee(Attendee *a, bool doupdate) 216void IncidenceBase::addAttendee(Attendee *a, bool doupdate)
216{ 217{
217 if (mReadOnly) return; 218 if (mReadOnly) return;
218 if (a->name().left(7).upper() == "MAILTO:") 219 if (a->name().left(7).upper() == "MAILTO:")
219 a->setName(a->name().remove(0,7)); 220 a->setName(a->name().remove(0,7));
220 221
221 mAttendees.append(a); 222 mAttendees.append(a);
222 if (doupdate) updated(); 223 if (doupdate) updated();
223} 224}
224 225
225#if 0 226#if 0
226void IncidenceBase::removeAttendee(Attendee *a) 227void IncidenceBase::removeAttendee(Attendee *a)
227{ 228{
228 if (mReadOnly) return; 229 if (mReadOnly) return;
229 mAttendees.removeRef(a); 230 mAttendees.removeRef(a);
230 updated(); 231 updated();
231} 232}
232 233
233void IncidenceBase::removeAttendee(const char *n) 234void IncidenceBase::removeAttendee(const char *n)
234{ 235{
235 Attendee *a; 236 Attendee *a;
236 237
237 if (mReadOnly) return; 238 if (mReadOnly) return;
238 for (a = mAttendees.first(); a; a = mAttendees.next()) 239 for (a = mAttendees.first(); a; a = mAttendees.next())
239 if (a->getName() == n) { 240 if (a->getName() == n) {
240 mAttendees.remove(); 241 mAttendees.remove();
241 break; 242 break;
242 } 243 }
243} 244}
244#endif 245#endif
245 246
246void IncidenceBase::clearAttendees() 247void IncidenceBase::clearAttendees()
247{ 248{
248 if (mReadOnly) return; 249 if (mReadOnly) return;
249 mAttendees.clear(); 250 mAttendees.clear();
250} 251}
251 252
252#if 0 253#if 0
253Attendee *IncidenceBase::getAttendee(const char *n) const 254Attendee *IncidenceBase::getAttendee(const char *n) const
254{ 255{
255 QPtrListIterator<Attendee> qli(mAttendees); 256 QPtrListIterator<Attendee> qli(mAttendees);
256 257
257 qli.toFirst(); 258 qli.toFirst();
258 while (qli) { 259 while (qli) {
259 if (qli.current()->getName() == n) 260 if (qli.current()->getName() == n)
260 return qli.current(); 261 return qli.current();
261 ++qli; 262 ++qli;
262 } 263 }
263 return 0L; 264 return 0L;
264} 265}
265#endif 266#endif
266 267
267Attendee *IncidenceBase::attendeeByMail(const QString &email) 268Attendee *IncidenceBase::attendeeByMail(const QString &email)
268{ 269{
269 QPtrListIterator<Attendee> qli(mAttendees); 270 QPtrListIterator<Attendee> qli(mAttendees);
270 271
271 qli.toFirst(); 272 qli.toFirst();
272 while (qli) { 273 while (qli) {
273 if (qli.current()->email() == email) 274 if (qli.current()->email() == email)
274 return qli.current(); 275 return qli.current();
275 ++qli; 276 ++qli;
276 } 277 }
277 return 0L; 278 return 0L;
278} 279}
279 280
280Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 281Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
281{ 282{
282 QPtrListIterator<Attendee> qli(mAttendees); 283 QPtrListIterator<Attendee> qli(mAttendees);
283 284
284 QStringList mails = emails; 285 QStringList mails = emails;
285 if (!email.isEmpty()) { 286 if (!email.isEmpty()) {
286 mails.append(email); 287 mails.append(email);
287 } 288 }
288 qli.toFirst(); 289 qli.toFirst();
289 while (qli) { 290 while (qli) {
290 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 291 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
291 if (qli.current()->email() == *it) 292 if (qli.current()->email() == *it)
292 return qli.current(); 293 return qli.current();
293 } 294 }
294 295
295 ++qli; 296 ++qli;
296 } 297 }
297 return 0L; 298 return 0L;
298} 299}
299 300
300void IncidenceBase::setDuration(int seconds) 301void IncidenceBase::setDuration(int seconds)
301{ 302{
302 mDuration = seconds; 303 mDuration = seconds;
303 setHasDuration(true); 304 setHasDuration(true);
304} 305}
305 306
306int IncidenceBase::duration() const 307int IncidenceBase::duration() const
307{ 308{
308 return mDuration; 309 return mDuration;
309} 310}
310 311
311void IncidenceBase::setHasDuration(bool b) 312void IncidenceBase::setHasDuration(bool b)
312{ 313{
313 mHasDuration = b; 314 mHasDuration = b;
314} 315}
315 316
316bool IncidenceBase::hasDuration() const 317bool IncidenceBase::hasDuration() const
317{ 318{
318 return mHasDuration; 319 return mHasDuration;
319} 320}
320 321
321void IncidenceBase::setSyncStatus(int stat) 322void IncidenceBase::setSyncStatus(int stat)
322{ 323{
323 if (mReadOnly) return; 324 if (mReadOnly) return;
324 mSyncStatus = stat; 325 mSyncStatus = stat;
325} 326}
326 327
327int IncidenceBase::syncStatus() const 328int IncidenceBase::syncStatus() const
328{ 329{
329 return mSyncStatus; 330 return mSyncStatus;
330} 331}
331 332
332void IncidenceBase::setPilotId( int id ) 333void IncidenceBase::setPilotId( int id )
333{ 334{
334 if (mReadOnly) return; 335 if (mReadOnly) return;
335 mPilotId = id; 336 mPilotId = id;
336} 337}
337 338
338int IncidenceBase::pilotId() const 339int IncidenceBase::pilotId() const
339{ 340{
340 return mPilotId; 341 return mPilotId;
341} 342}
342 343
343int IncidenceBase::tempSyncStat() const 344int IncidenceBase::tempSyncStat() const
344{ 345{
345 return mTempSyncStat; 346 return mTempSyncStat;
346} 347}
347void IncidenceBase::setTempSyncStat( int id ) 348void IncidenceBase::setTempSyncStat( int id )
348{ 349{
349 if (mReadOnly) return; 350 if (mReadOnly) return;
350 mTempSyncStat = id; 351 mTempSyncStat = id;
351} 352}
352 353
353void IncidenceBase::removeID(const QString &prof) 354void IncidenceBase::removeID(const QString &prof)
354{ 355{
355 mExternalId = KIdManager::removeId ( mExternalId, prof); 356 mExternalId = KIdManager::removeId ( mExternalId, prof);
356 357
357} 358}
358void IncidenceBase::setID( const QString & prof , const QString & id ) 359void IncidenceBase::setID( const QString & prof , const QString & id )
359{ 360{
360 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 361 mExternalId = KIdManager::setId ( mExternalId, prof, id );
361} 362}
362QString IncidenceBase::getID( const QString & prof) 363QString IncidenceBase::getID( const QString & prof)
363{ 364{
364 return KIdManager::getId ( mExternalId, prof ); 365 return KIdManager::getId ( mExternalId, prof );
365} 366}
366 367
367// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 368// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0:
368// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0 369// format name;III;JJJ: III >= 0, may be -1. JJJ always >= 0
369void IncidenceBase::setCsum( const QString & prof , const QString & id ) 370void IncidenceBase::setCsum( const QString & prof , const QString & id )
370{ 371{
371 mExternalId = KIdManager::setCsum ( mExternalId, prof, id ); 372 mExternalId = KIdManager::setCsum ( mExternalId, prof, id );
372} 373}
373QString IncidenceBase::getCsum( const QString & prof) 374QString IncidenceBase::getCsum( const QString & prof)
374{ 375{
375 return KIdManager::getCsum ( mExternalId, prof ); 376 return KIdManager::getCsum ( mExternalId, prof );
376} 377}
377 378
378void IncidenceBase::setIDStr( const QString & s ) 379void IncidenceBase::setIDStr( const QString & s )
379{ 380{
380 if (mReadOnly) return; 381 if (mReadOnly) return;
381 mExternalId = s; 382 mExternalId = s;
382} 383}
383 384
384QString IncidenceBase::IDStr() const 385QString IncidenceBase::IDStr() const
385{ 386{
386 return mExternalId ; 387 return mExternalId ;
387} 388}
388void IncidenceBase::registerObserver( IncidenceBase::Observer *observer ) 389void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
389{ 390{
390 if( !mObservers.contains(observer) ) mObservers.append( observer ); 391 if( !mObservers.contains(observer) ) mObservers.append( observer );
391} 392}
392 393
393void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer ) 394void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
394{ 395{
395 mObservers.remove( observer ); 396 mObservers.remove( observer );
396} 397}
397 398
398void IncidenceBase::updated() 399void IncidenceBase::updated()
399{ 400{
400 QPtrListIterator<Observer> it(mObservers); 401 QPtrListIterator<Observer> it(mObservers);
401 while( it.current() ) { 402 while( it.current() ) {
402 Observer *o = it.current(); 403 Observer *o = it.current();
403 ++it; 404 ++it;
404 o->incidenceUpdated( this ); 405 o->incidenceUpdated( this );
405 } 406 }
406} 407}
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index e6d4879..6bbc0a3 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -1,1266 +1,1427 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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 <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49class PhoneParser : public QObject 49class PhoneParser : public QObject
50{ 50{
51public: 51public:
52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { 52 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
53 ; 53 ;
54 } 54 }
55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) 55 bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s)
56 { 56 {
57 57
58 int id = ToDo->Location; 58 int id = ToDo->Location;
59 Todo *todo; 59 Todo *todo;
60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); 60 todo = existingCalendar->todo( mProfileName ,QString::number( id ) );
61 if (todo ) 61 if (todo )
62 todo = (Todo *)todo->clone(); 62 todo = (Todo *)todo->clone();
63 else 63 else
64 todo = new Todo; 64 todo = new Todo;
65 todo->setID( mProfileName,QString::number( id ) ); 65 todo->setID( mProfileName,QString::number( id ) );
66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 66 todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
67 int priority; 67 int priority;
68 switch (ToDo->Priority) { 68 switch (ToDo->Priority) {
69 case GSM_Priority_Low : priority = 1; break; 69 case GSM_Priority_Low : priority = 5; break;
70 case GSM_Priority_Medium : priority = 3; break; 70 case GSM_Priority_Medium : priority = 3; break;
71 case GSM_Priority_High : priority = 5; break; 71 case GSM_Priority_High : priority = 1; break;
72 default :priority = 3 ;break; 72 default :priority = 3 ;break;
73 } 73 }
74 todo->setPriority( priority ); 74 todo->setPriority( priority );
75 GSM_Phone_Functions*Phone; 75 GSM_Phone_Functions*Phone;
76 Phone=s->Phone.Functions; 76 Phone=s->Phone.Functions;
77 int j; 77 int j;
78 GSM_DateTime* dtp; 78 GSM_DateTime* dtp;
79 bool alarm = false; 79 bool alarm = false;
80 QDateTime alarmDt; 80 QDateTime alarmDt;
81 GSM_Category Category; 81 GSM_Category Category;
82 int error; 82 int error;
83 for (j=0;j<ToDo->EntriesNum;j++) { 83 for (j=0;j<ToDo->EntriesNum;j++) {
84 84
85 //qDebug(" for todo %d",ToDo->Location ); 85 //qDebug(" for todo %d",ToDo->Location );
86 switch (ToDo->Entries[j].EntryType) { 86 switch (ToDo->Entries[j].EntryType) {
87 case TODO_END_DATETIME: 87 case TODO_END_DATETIME:
88 dtp = &ToDo->Entries[j].Date ; 88 dtp = &ToDo->Entries[j].Date ;
89 todo->setDtDue (fromGSM ( dtp )); 89 todo->setDtDue (fromGSM ( dtp ));
90 break; 90 break;
91 case TODO_COMPLETED: 91 case TODO_COMPLETED:
92 if ( ToDo->Entries[j].Number == 1 ) { 92 if ( ToDo->Entries[j].Number == 1 ) {
93 todo->setCompleted( true ); 93 todo->setCompleted( true );
94 } 94 }
95 else { 95 else {
96 todo->setCompleted( false ); 96 todo->setCompleted( false );
97 } 97 }
98 break; 98 break;
99 case TODO_ALARM_DATETIME: 99 case TODO_ALARM_DATETIME:
100 dtp = &ToDo->Entries[j].Date ; 100 dtp = &ToDo->Entries[j].Date ;
101 alarm = true; 101 alarm = true;
102 alarmDt = fromGSM ( dtp ); 102 alarmDt = fromGSM ( dtp );
103 break; 103 break;
104 case TODO_SILENT_ALARM_DATETIME: 104 case TODO_SILENT_ALARM_DATETIME:
105 dtp = &ToDo->Entries[j].Date ; 105 dtp = &ToDo->Entries[j].Date ;
106 alarm = true; 106 alarm = true;
107 alarmDt = fromGSM ( dtp ); 107 alarmDt = fromGSM ( dtp );
108 break; 108 break;
109 case TODO_TEXT: 109 case TODO_TEXT:
110 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); 110 //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text ));
111 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); 111 todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text )));
112 break; 112 break;
113 case TODO_PRIVATE: 113 case TODO_PRIVATE:
114 if ( ToDo->Entries[j].Number == 1 ) 114 if ( ToDo->Entries[j].Number == 1 )
115 todo->setSecrecy( Incidence::SecrecyPrivate ); 115 todo->setSecrecy( Incidence::SecrecyPrivate );
116 else 116 else
117 todo->setSecrecy( Incidence::SecrecyPublic ); 117 todo->setSecrecy( Incidence::SecrecyPublic );
118 break; 118 break;
119 case TODO_CATEGORY: 119 case TODO_CATEGORY:
120 Category.Location = ToDo->Entries[j].Number; 120 Category.Location = ToDo->Entries[j].Number;
121 Category.Type = Category_ToDo; 121 Category.Type = Category_ToDo;
122 error=Phone->GetCategory(s, &Category); 122 error=Phone->GetCategory(s, &Category);
123 if (error == ERR_NONE) { 123 if (error == ERR_NONE) {
124 QStringList cat = todo->categories(); 124 QStringList cat = todo->categories();
125 QString nCat = QString ( (const char*)Category.Name ); 125 QString nCat = QString ( (const char*)Category.Name );
126 if ( !nCat.isEmpty() ) 126 if ( !nCat.isEmpty() )
127 if ( !cat.contains( nCat )) { 127 if ( !cat.contains( nCat )) {
128 cat << nCat; 128 cat << nCat;
129 todo->setCategories( cat ); 129 todo->setCategories( cat );
130 } 130 }
131 } 131 }
132 break; 132 break;
133 case TODO_CONTACTID: 133 case TODO_CONTACTID:
134#if 0 134#if 0
135 // not supported 135 // not supported
136 entry.Location = ToDo->Entries[j].Number; 136 entry.Location = ToDo->Entries[j].Number;
137 entry.MemoryType = MEM_ME; 137 entry.MemoryType = MEM_ME;
138 error=Phone->GetMemory(s, &entry); 138 error=Phone->GetMemory(s, &entry);
139 if (error == ERR_NONE) { 139 if (error == ERR_NONE) {
140 name = GSM_PhonebookGetEntryName(&entry); 140 name = GSM_PhonebookGetEntryName(&entry);
141 if (name != NULL) { 141 if (name != NULL) {
142 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); 142 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
143 } else { 143 } else {
144 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 144 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
145 } 145 }
146 } else { 146 } else {
147 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 147 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
148 } 148 }
149#endif 149#endif
150 break; 150 break;
151 case TODO_PHONE: 151 case TODO_PHONE:
152#if 0 152#if 0
153 // not supported 153 // not supported
154 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 154 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
155#endif 155#endif
156 break; 156 break;
157 } 157 }
158 } 158 }
159 QString alarmString = "na"; 159 QString alarmString = "na";
160 if ( alarm ) { 160 if ( alarm ) {
161 Alarm *alarm; 161 Alarm *alarm;
162 if ( todo->alarms().count() > 0 ) 162 if ( todo->alarms().count() > 0 )
163 alarm = todo->alarms().first(); 163 alarm = todo->alarms().first();
164 else { 164 else {
165 alarm = new Alarm( todo ); 165 alarm = new Alarm( todo );
166 todo->addAlarm( alarm ); 166 todo->addAlarm( alarm );
167 } 167 }
168 alarm->setType( Alarm::Audio ); 168 alarm->setType( Alarm::Audio );
169 alarm->setEnabled( true ); 169 alarm->setEnabled( true );
170 int alarmOffset = alarmDt.secsTo( todo->dtStart() ); 170 int alarmOffset = alarmDt.secsTo( todo->dtStart() );
171 alarm->setStartOffset( -alarmOffset ); 171 alarm->setStartOffset( -alarmOffset );
172 alarmString = QString::number( alarmOffset ); 172 alarmString = QString::number( alarmOffset );
173 } else { 173 } else {
174 Alarm *alarm; 174 Alarm *alarm;
175 if ( todo->alarms().count() > 0 ) { 175 if ( todo->alarms().count() > 0 ) {
176 alarm = todo->alarms().first(); 176 alarm = todo->alarms().first();
177 alarm->setType( Alarm::Audio ); 177 alarm->setType( Alarm::Audio );
178 alarm->setStartOffset( -60*15 ); 178 alarm->setStartOffset( -60*15 );
179 alarm->setEnabled( false ); 179 alarm->setEnabled( false );
180 } 180 }
181 } 181 }
182 // csum ***************************************** 182 // csum *****************************************
183 uint cSum; 183 uint cSum;
184 cSum = PhoneFormat::getCsumTodo( todo ); 184 cSum = PhoneFormat::getCsumTodo( todo );
185 todo->setCsum( mProfileName, QString::number( cSum )); 185 todo->setCsum( mProfileName, QString::number( cSum ));
186 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 186 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
187 mCalendar->addTodo( todo); 187 mCalendar->addTodo( todo);
188 188
189 return true; 189 return true;
190 } 190 }
191 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) 191 bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note)
192 { 192 {
193 193
194 int id = Note->Location; 194 int id = Note->Location;
195 Event *event; 195 Event *event;
196 event = existingCalendar->event( mProfileName ,QString::number( id ) ); 196 event = existingCalendar->event( mProfileName ,QString::number( id ) );
197 if ( event ) 197 if ( event )
198 event = (Event*)event->clone(); 198 event = (Event*)event->clone();
199 else 199 else
200 event = new Event; 200 event = new Event;
201 event->setID( mProfileName,QString::number( id ) ); 201 event->setID( mProfileName,QString::number( id ) );
202 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 202 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
203 203
204 204
205 int i = 0; 205 int i = 0;
206 bool repeating = false; 206 bool repeating = false;
207 int repeat_dayofweek = -1; 207 int repeat_dayofweek = -1;
208 int repeat_day = -1; 208 int repeat_day = -1;
209 int repeat_weekofmonth = -1; 209 int repeat_weekofmonth = -1;
210 int repeat_month = -1; 210 int repeat_month = -1;
211 int repeat_frequency = -1; 211 int repeat_frequency = -1;
212 int rec_type = -1; 212 int rec_type = -1;
213 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 213 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
214 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 214 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
215 GSM_DateTime* dtp; 215 GSM_DateTime* dtp;
216 bool alarm = false; 216 bool alarm = false;
217 QDateTime alarmDt; 217 QDateTime alarmDt;
218 repeat_startdate.Day= 0; 218 repeat_startdate.Day= 0;
219 repeat_stopdate.Day = 0; 219 repeat_stopdate.Day = 0;
220 for (i=0;i<Note->EntriesNum;i++) { 220 for (i=0;i<Note->EntriesNum;i++) {
221 221
222 //qDebug(" for ev"); 222 //qDebug(" for ev");
223 switch (Note->Entries[i].EntryType) { 223 switch (Note->Entries[i].EntryType) {
224 case CAL_START_DATETIME: 224 case CAL_START_DATETIME:
225 dtp = &Note->Entries[i].Date ; 225 dtp = &Note->Entries[i].Date ;
226 if ( dtp->Hour > 24 ) { 226 if ( dtp->Hour > 24 ) {
227 event->setFloats( true ); 227 event->setFloats( true );
228 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 228 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
229 } else { 229 } else {
230 event->setDtStart (fromGSM ( dtp )); 230 event->setDtStart (fromGSM ( dtp ));
231 231
232 } 232 }
233 //Note->Entries[i].Date.Hour = 5;
233 break; 234 break;
234 case CAL_END_DATETIME: 235 case CAL_END_DATETIME:
235 dtp = &Note->Entries[i].Date ; 236 dtp = &Note->Entries[i].Date ;
236 if ( dtp->Hour > 24 ) { 237 if ( dtp->Hour > 24 ) {
237 event->setFloats( true ); 238 event->setFloats( true );
238 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); 239 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
239 } else { 240 } else {
240 event->setDtEnd (fromGSM ( dtp )); 241 event->setDtEnd (fromGSM ( dtp ));
241 } 242 }
242 break; 243 break;
243 case CAL_ALARM_DATETIME: 244 case CAL_ALARM_DATETIME:
244 dtp = &Note->Entries[i].Date ; 245 dtp = &Note->Entries[i].Date ;
245 alarm = true; 246 alarm = true;
246 alarmDt = fromGSM ( dtp ); 247 alarmDt = fromGSM ( dtp );
247 break; 248 break;
248 case CAL_SILENT_ALARM_DATETIME: 249 case CAL_SILENT_ALARM_DATETIME:
249 dtp = &Note->Entries[i].Date ; 250 dtp = &Note->Entries[i].Date ;
250 alarm = true; 251 alarm = true;
251 alarmDt = fromGSM ( dtp ); 252 alarmDt = fromGSM ( dtp );
252 break; 253 break;
253 case CAL_RECURRANCE: 254 case CAL_RECURRANCE:
254 rec_type = Note->Entries[i].Number; 255 rec_type = Note->Entries[i].Number;
255 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); 256 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
256 break; 257 break;
257 case CAL_TEXT: 258 case CAL_TEXT:
258 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); 259 //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) );
259 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); 260 event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text )));
260 break; 261 break;
261 case CAL_LOCATION: 262 case CAL_LOCATION:
262 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); 263 event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) ));
263 break; 264 break;
264 case CAL_PHONE: 265 case CAL_PHONE:
265 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); 266 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
266 break; 267 break;
267 case CAL_PRIVATE: 268 case CAL_PRIVATE:
268 if ( Note->Entries[i].Number == 1 ) 269 if ( Note->Entries[i].Number == 1 )
269 event->setSecrecy( Incidence::SecrecyPrivate ); 270 event->setSecrecy( Incidence::SecrecyPrivate );
270 else 271 else
271 event->setSecrecy( Incidence::SecrecyPublic ); 272 event->setSecrecy( Incidence::SecrecyPublic );
272 273
273 break; 274 break;
274 case CAL_CONTACTID: 275 case CAL_CONTACTID:
275#if 0 276#if 0
276 entry.Location = Note->Entries[i].Number; 277 entry.Location = Note->Entries[i].Number;
277 entry.MemoryType = MEM_ME; 278 entry.MemoryType = MEM_ME;
278 error=Phone->GetMemory(&s, &entry); 279 error=Phone->GetMemory(&s, &entry);
279 if (error == ERR_NONE) { 280 if (error == ERR_NONE) {
280 name = GSM_PhonebookGetEntryName(&entry); 281 name = GSM_PhonebookGetEntryName(&entry);
281 if (name != NULL) { 282 if (name != NULL) {
282 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 283 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
283 } else { 284 } else {
284 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 285 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
285 } 286 }
286 } else { 287 } else {
287 //printmsg("Contact ID : %d\n",Note->Entries[i].Number); 288 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
288 } 289 }
289#endif 290#endif
290 break; 291 break;
291 case CAL_REPEAT_DAYOFWEEK: 292 case CAL_REPEAT_DAYOFWEEK:
292 repeat_dayofweek = Note->Entries[i].Number; 293 repeat_dayofweek = Note->Entries[i].Number;
293 repeating = true; 294 repeating = true;
294 break; 295 break;
295 case CAL_REPEAT_DAY: 296 case CAL_REPEAT_DAY:
296 repeat_day = Note->Entries[i].Number; 297 repeat_day = Note->Entries[i].Number;
297 repeating = true; 298 repeating = true;
298 break; 299 break;
299 case CAL_REPEAT_WEEKOFMONTH: 300 case CAL_REPEAT_WEEKOFMONTH:
300 repeat_weekofmonth = Note->Entries[i].Number; 301 repeat_weekofmonth = Note->Entries[i].Number;
301 repeating = true; 302 repeating = true;
302 break; 303 break;
303 case CAL_REPEAT_MONTH: 304 case CAL_REPEAT_MONTH:
304 repeat_month = Note->Entries[i].Number; 305 repeat_month = Note->Entries[i].Number;
305 repeating = true; 306 repeating = true;
306 break; 307 break;
307 case CAL_REPEAT_FREQUENCY: 308 case CAL_REPEAT_FREQUENCY:
308 repeat_frequency = Note->Entries[i].Number; 309 repeat_frequency = Note->Entries[i].Number;
309 repeating = true; 310 repeating = true;
310 break; 311 break;
311 case CAL_REPEAT_STARTDATE: 312 case CAL_REPEAT_STARTDATE:
312 repeat_startdate = Note->Entries[i].Date; 313 repeat_startdate = Note->Entries[i].Date;
313 repeating = true; 314 repeating = true;
314 break; 315 break;
315 case CAL_REPEAT_STOPDATE: 316 case CAL_REPEAT_STOPDATE:
316 repeat_stopdate = Note->Entries[i].Date; 317 repeat_stopdate = Note->Entries[i].Date;
317 repeating = true; 318 repeating = true;
318 break; 319 break;
319 } 320 }
320 } 321 }
321#if 0 322#if 0
322 event->setDescription( attList[4] ); 323 event->setDescription( attList[4] );
323 bool repeating = false; 324 bool repeating = false;
324 int repeat_dayofweek = -1; 325 int repeat_dayofweek = -1;
325 int repeat_day = -1; 326 int repeat_day = -1;
326 int repeat_weekofmonth = -1; 327 int repeat_weekofmonth = -1;
327 int repeat_month = -1; 328 int repeat_month = -1;
328 int repeat_frequency = -1; 329 int repeat_frequency = -1;
329 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 330 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
330 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 331 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
331 332
332#endif 333#endif
333 334
334 QString recurString = "no"; 335 QString recurString = "no";
335 if ( repeating && repeat_frequency != -1) { 336 if ( repeating && repeat_frequency != -1) {
336 recurString = "y"; 337 recurString = "y";
337 if ( repeat_dayofweek >= 0 ) 338 if ( repeat_dayofweek >= 0 )
338 recurString += "dow" + QString::number (repeat_dayofweek); 339 recurString += "dow" + QString::number (repeat_dayofweek);
339 if ( repeat_day >= 0 ) 340 if ( repeat_day >= 0 )
340 recurString += "d" + QString::number (repeat_day); 341 recurString += "d" + QString::number (repeat_day);
341 if ( repeat_weekofmonth >= 0 ) 342 if ( repeat_weekofmonth >= 0 )
342 recurString += "w" + QString::number (repeat_weekofmonth); 343 recurString += "w" + QString::number (repeat_weekofmonth);
343 if ( repeat_month >= 0 ) 344 if ( repeat_month >= 0 )
344 recurString += "m" + QString::number ( repeat_month ); 345 recurString += "m" + QString::number ( repeat_month );
345 if ( repeat_frequency >= 0 ) 346 if ( repeat_frequency >= 0 )
346 recurString += "f" + QString::number (repeat_frequency ); 347 recurString += "f" + QString::number (repeat_frequency );
347 348
348 int rtype = 0; 349 int rtype = 0;
349 // qDebug("recurs "); 350 // qDebug("recurs ");
350 QDate startDate, endDate; 351 QDate startDate, endDate;
351 if ( repeat_startdate.Day > 0 ) { 352 if ( repeat_startdate.Day > 0 ) {
352 startDate = datefromGSM ( &repeat_startdate ); 353 startDate = datefromGSM ( &repeat_startdate );
353 event->setDtStart(QDateTime ( startDate, event->dtStart().time())); 354 event->setDtStart(QDateTime ( startDate, event->dtStart().time()));
354 } else { 355 } else {
355 startDate = event->dtStart().date(); 356 startDate = event->dtStart().date();
356 } 357 }
357 int freq = repeat_frequency; 358 int freq = repeat_frequency;
358 bool hasEndDate = false; 359 bool hasEndDate = false;
359 if ( repeat_stopdate.Day > 0 ) { 360 if ( repeat_stopdate.Day > 0 ) {
360 endDate = datefromGSM ( &repeat_stopdate ); 361 endDate = datefromGSM ( &repeat_stopdate );
361 hasEndDate = true; 362 hasEndDate = true;
362 } 363 }
363 364
364 uint weekDaysNum = repeat_dayofweek ; 365 uint weekDaysNum = repeat_dayofweek ;
365 // 1 == monday, 7 == sunday 366 // 1 == monday, 7 == sunday
366 QBitArray weekDays( 7 ); 367 QBitArray weekDays( 7 );
367 int i; 368 int i;
368 int bb = 1; 369 int bb = 1;
369 for( i = 1; i <= 7; ++i ) { 370 for( i = 1; i <= 7; ++i ) {
370 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 371 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
371 bb = 2 << (i-1); 372 bb = 2 << (i-1);
372 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 373 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
373 } 374 }
374 // qDebug("next "); 375 // qDebug("next ");
375 int pos = 0; 376 int pos = 0;
376 Recurrence *r = event->recurrence(); 377 Recurrence *r = event->recurrence();
377 /* 378 /*
378 0 daily; 379 0 daily;
379 1 weekly;x 380 1 weekly;x
380 2 monthpos;x 381 2 monthpos;x
381 3 monthlyday; 382 3 monthlyday;
382 4 rYearlyMont 383 4 rYearlyMont
383 bool repeating = false; 384 bool repeating = false;
384 int repeat_dayofweek = -1; 385 int repeat_dayofweek = -1;
385 int repeat_day = -1; 386 int repeat_day = -1;
386 int repeat_weekofmonth = -1; 387 int repeat_weekofmonth = -1;
387 int repeat_month = -1; 388 int repeat_month = -1;
388 int repeat_frequency = -1; 389 int repeat_frequency = -1;
389 */ 390 */
390 int dayOfWeek = startDate.dayOfWeek(); 391 int dayOfWeek = startDate.dayOfWeek();
391 if ( repeat_weekofmonth >= 0 ) { 392 if ( repeat_weekofmonth >= 0 ) {
392 rtype = 2; // ************************ 2 MonthlyPos 393 rtype = 2; // ************************ 2 MonthlyPos
393 pos = repeat_weekofmonth; 394 pos = repeat_weekofmonth;
394 if ( repeat_dayofweek >= 0 ) 395 if ( repeat_dayofweek >= 0 )
395 dayOfWeek = repeat_dayofweek; 396 dayOfWeek = repeat_dayofweek;
396 if (repeat_month > 0) { 397 if (repeat_month > 0) {
397 if ( repeat_month != event->dtStart().date().month() ) { 398 if ( repeat_month != event->dtStart().date().month() ) {
398 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); 399 QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() );
399 event->setDtStart(QDateTime ( date , event->dtStart().time()) ); 400 event->setDtStart(QDateTime ( date , event->dtStart().time()) );
400 } 401 }
401 if ( freq == 1 ) 402 if ( freq == 1 )
402 freq = 12; 403 freq = 12;
403 } 404 }
404 } else if ( repeat_dayofweek >= 0 ) { 405 } else if ( repeat_dayofweek >= 0 ) {
405 rtype = 1;// ************************ 1 Weekly 406 rtype = 1;// ************************ 1 Weekly
406 } else if ( repeat_day >= 0 ) { 407 } else if ( repeat_day >= 0 ) {
407 if ( repeat_month > 0) { 408 if ( repeat_month > 0) {
408 rtype = 4; 409 rtype = 4;
409 } else { 410 } else {
410 rtype = 3; 411 rtype = 3;
411 } 412 }
412 } else { 413 } else {
413 rtype = 0 ; 414 rtype = 0 ;
414 } 415 }
415 416
416 if ( rtype == 0 ) { 417 if ( rtype == 0 ) {
417 if ( hasEndDate ) r->setDaily( freq, endDate ); 418 if ( hasEndDate ) r->setDaily( freq, endDate );
418 else r->setDaily( freq, -1 ); 419 else r->setDaily( freq, -1 );
419 } else if ( rtype == 1 ) { 420 } else if ( rtype == 1 ) {
420 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 421 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
421 else r->setWeekly( freq, weekDays, -1 ); 422 else r->setWeekly( freq, weekDays, -1 );
422 } else if ( rtype == 3 ) { 423 } else if ( rtype == 3 ) {
423 if ( hasEndDate ) 424 if ( hasEndDate )
424 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 425 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
425 else 426 else
426 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 427 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
427 r->addMonthlyDay( startDate.day() ); 428 r->addMonthlyDay( startDate.day() );
428 } else if ( rtype == 2 ) { 429 } else if ( rtype == 2 ) {
429 if ( hasEndDate ) 430 if ( hasEndDate )
430 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 431 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
431 else 432 else
432 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 433 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
433 QBitArray days( 7 ); 434 QBitArray days( 7 );
434 days.fill( false ); 435 days.fill( false );
435 days.setBit( dayOfWeek - 1 ); 436 days.setBit( dayOfWeek - 1 );
436 r->addMonthlyPos( pos, days ); 437 r->addMonthlyPos( pos, days );
437 } else if ( rtype == 4 ) { 438 } else if ( rtype == 4 ) {
438 if ( hasEndDate ) 439 if ( hasEndDate )
439 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 440 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
440 else 441 else
441 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 442 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
442 r->addYearlyNum( startDate.month() ); 443 r->addYearlyNum( startDate.month() );
443 } 444 }
444 } else { 445 } else {
445 event->recurrence()->unsetRecurs(); 446 event->recurrence()->unsetRecurs();
446 } 447 }
447 448
448 QStringList categoryList; 449 QStringList categoryList;
449 categoryList << getCategory( Note ); 450 categoryList << getCategory( Note );
450 event->setCategories( categoryList ); 451 event->setCategories( categoryList );
451 // strange 0 semms to mean: alarm enabled 452 // strange 0 semms to mean: alarm enabled
452 if ( alarm ) { 453 if ( alarm ) {
453 Alarm *alarm; 454 Alarm *alarm;
454 if ( event->alarms().count() > 0 ) 455 if ( event->alarms().count() > 0 )
455 alarm = event->alarms().first(); 456 alarm = event->alarms().first();
456 else { 457 else {
457 alarm = new Alarm( event ); 458 alarm = new Alarm( event );
458 event->addAlarm( alarm ); 459 event->addAlarm( alarm );
459 } 460 }
460 alarm->setType( Alarm::Audio ); 461 alarm->setType( Alarm::Audio );
461 alarm->setEnabled( true ); 462 alarm->setEnabled( true );
462 int alarmOffset = alarmDt.secsTo( event->dtStart() ); 463 int alarmOffset = alarmDt.secsTo( event->dtStart() );
463 alarm->setStartOffset( -alarmOffset ); 464 alarm->setStartOffset( -alarmOffset );
464 } else { 465 } else {
465 Alarm *alarm; 466 Alarm *alarm;
466 if ( event->alarms().count() > 0 ) { 467 if ( event->alarms().count() > 0 ) {
467 alarm = event->alarms().first(); 468 alarm = event->alarms().first();
468 alarm->setType( Alarm::Audio ); 469 alarm->setType( Alarm::Audio );
469 alarm->setStartOffset( -60*15 ); 470 alarm->setStartOffset( -60*15 );
470 alarm->setEnabled( false ); 471 alarm->setEnabled( false );
471 } 472 }
472 } 473 }
473 // csum ***************************************** 474 // csum *****************************************
474 475
475 uint cSum; 476 uint cSum;
476 cSum = PhoneFormat::getCsumEvent( event ); 477 cSum = PhoneFormat::getCsumEvent( event );
477 event->setCsum( mProfileName, QString::number( cSum )); 478 event->setCsum( mProfileName, QString::number( cSum ));
478 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 479 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
479 mCalendar->addEvent( event); 480 mCalendar->addEvent( event);
480 481
481 return true; 482 return true;
482 } 483 }
483 484
484 485
485 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { 486 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) {
486 QDateTime dt; 487 QDateTime dt;
487 int y,m,t,h,min,sec; 488 int y,m,t,h,min,sec;
488 y = dtp->Year; 489 y = dtp->Year;
489 m = dtp->Month; 490 m = dtp->Month;
490 t = dtp->Day; 491 t = dtp->Day;
491 h = dtp->Hour; 492 h = dtp->Hour;
492 min = dtp->Minute; 493 min = dtp->Minute;
493 sec = dtp->Second; 494 sec = dtp->Second;
494 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 495 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
495 // dtp->Timezone: offset in hours 496 // dtp->Timezone: offset in hours
496 int offset = KGlobal::locale()->localTimeOffset( dt ); 497 int offset = KGlobal::locale()->localTimeOffset( dt );
497 if ( useTz ) 498 if ( useTz )
498 dt = dt.addSecs ( offset*60); 499 dt = dt.addSecs ( offset*60);
499 return dt; 500 return dt;
500 501
501 } 502 }
502 503
503 static QString dtToString( const QDateTime& dti, bool useTZ = false ) 504 static QString dtToString( const QDateTime& dti, bool useTZ = false )
504 { 505 {
505 QString datestr; 506 QString datestr;
506 QString timestr; 507 QString timestr;
507 int offset = KGlobal::locale()->localTimeOffset( dti ); 508 int offset = KGlobal::locale()->localTimeOffset( dti );
508 QDateTime dt; 509 QDateTime dt;
509 if (useTZ) 510 if (useTZ)
510 dt = dti.addSecs ( -(offset*60)); 511 dt = dti.addSecs ( -(offset*60));
511 else 512 else
512 dt = dti; 513 dt = dti;
513 if(dt.date().isValid()){ 514 if(dt.date().isValid()){
514 const QDate& date = dt.date(); 515 const QDate& date = dt.date();
515 datestr.sprintf("%04d%02d%02d", 516 datestr.sprintf("%04d%02d%02d",
516 date.year(), date.month(), date.day()); 517 date.year(), date.month(), date.day());
517 } 518 }
518 if(dt.time().isValid()){ 519 if(dt.time().isValid()){
519 const QTime& time = dt.time(); 520 const QTime& time = dt.time();
520 timestr.sprintf("T%02d%02d%02d", 521 timestr.sprintf("T%02d%02d%02d",
521 time.hour(), time.minute(), time.second()); 522 time.hour(), time.minute(), time.second());
522 } 523 }
523 return datestr + timestr; 524 return datestr + timestr;
524 } 525 }
525 QDate datefromGSM ( GSM_DateTime*dtp ) { 526 QDate datefromGSM ( GSM_DateTime*dtp ) {
526 return QDate ( dtp->Year, dtp->Month, dtp->Day ); 527 return QDate ( dtp->Year, dtp->Month, dtp->Day );
527 } 528 }
528 QString getCategory( GSM_CalendarEntry*Note) 529 QString getCategory( GSM_CalendarEntry*Note)
529 { 530 {
530 QString CATEGORY; 531 QString CATEGORY;
531 switch (Note->Type) { 532 switch (Note->Type) {
532 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; 533 case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break;
533 case GSM_CAL_CALL : CATEGORY = QString("Call"); break; 534 case GSM_CAL_CALL : CATEGORY = QString("Call"); break;
534 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; 535 case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break;
535 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; 536 case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break;
536 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; 537 case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break;
537 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; 538 case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break;
538 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; 539 case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break;
539 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; 540 case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break;
540 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; 541 case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break;
541 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; 542 case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break;
542 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; 543 case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break;
543 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; 544 case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break;
544 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; 545 case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break;
545 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; 546 case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break;
546 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; 547 case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break;
547 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; 548 case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break;
548 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; 549 case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break;
549 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; 550 case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break;
550 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; 551 case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break;
551 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; 552 case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break;
552 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; 553 case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break;
553 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; 554 case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break;
554 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; 555 case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break;
555 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; 556 case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break;
556 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; 557 case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break;
557 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; 558 case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break;
558 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; 559 case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break;
559 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; 560 case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break;
560 default : CATEGORY = QString(""); 561 default : CATEGORY = QString("");
561 } 562 }
562 563
563 return CATEGORY; 564 return CATEGORY;
564 } 565 }
565 566
566protected: 567protected:
567private: 568private:
568 Calendar *mCalendar; 569 Calendar *mCalendar;
569 QString mProfileName ; 570 QString mProfileName ;
570}; 571};
571 572
572 573
573PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) 574PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model )
574{ 575{
575 mProfileName = profileName; 576 mProfileName = profileName;
576 mDevice = device; 577 mDevice = device;
577 mConnection = connection; 578 mConnection = connection;
578 mModel = model; 579 mModel = model;
579} 580}
580 581
581PhoneFormat::~PhoneFormat() 582PhoneFormat::~PhoneFormat()
582{ 583{
583} 584}
584int PhoneFormat::initDevice(GSM_StateMachine *s) 585int PhoneFormat::initDevice(GSM_StateMachine *s)
585{ 586{
586 GSM_ReadConfig(NULL, &s->Config[0], 0); 587 GSM_ReadConfig(NULL, &s->Config[0], 0);
587 s->ConfigNum = 1; 588 s->ConfigNum = 1;
588 GSM_Config *cfg = &s->Config[0]; 589 GSM_Config *cfg = &s->Config[0];
589 if ( ! mConnection.isEmpty() ) { 590 if ( ! mConnection.isEmpty() ) {
590 cfg->Connection = strdup(mConnection.latin1()); 591 cfg->Connection = strdup(mConnection.latin1());
591 cfg->DefaultConnection = false; 592 cfg->DefaultConnection = false;
592 qDebug("Connection set %s ", cfg->Connection ); 593 qDebug("Connection set %s ", cfg->Connection );
593 594
594 } 595 }
595 if ( ! mDevice.isEmpty() ) { 596 if ( ! mDevice.isEmpty() ) {
596 cfg->Device = strdup(mDevice.latin1()); 597 cfg->Device = strdup(mDevice.latin1());
597 cfg->DefaultDevice = false; 598 cfg->DefaultDevice = false;
598 qDebug("Device set %s ", cfg->Device); 599 qDebug("Device set %s ", cfg->Device);
599 600
600 } 601 }
601 if ( ! mModel.isEmpty() ) { 602 if ( ! mModel.isEmpty() ) {
602 strcpy(cfg->Model,mModel.latin1() ); 603 strcpy(cfg->Model,mModel.latin1() );
603 cfg->DefaultModel = false; 604 cfg->DefaultModel = false;
604 qDebug("Model set %s ",cfg->Model ); 605 qDebug("Model set %s ",cfg->Model );
605 } 606 }
606 int error=GSM_InitConnection(s,3); 607 int error=GSM_InitConnection(s,3);
607 return error; 608 return error;
608} 609}
609ulong PhoneFormat::getCsumTodo( Todo* todo ) 610ulong PhoneFormat::getCsumTodo( Todo* todo )
610{ 611{
611 QStringList attList; 612 QStringList attList;
612 if ( todo->hasDueDate() ) 613 if ( todo->hasDueDate() )
613 attList << PhoneParser::dtToString ( todo->dtDue() ); 614 attList << PhoneParser::dtToString ( todo->dtDue() );
614 attList << todo->summary(); 615 attList << todo->summary();
615 QString completedString = "no"; 616 QString completedString = "no";
616 if ( todo->isCompleted() ) 617 if ( todo->isCompleted() )
617 completedString = "yes"; 618 completedString = "yes";
618 attList << completedString; 619 attList << completedString;
619 attList << QString::number( todo->priority() ); 620 attList << QString::number( todo->priority() );
620 QString alarmString = "na"; 621 QString alarmString = "na";
621 Alarm *alarm; 622 Alarm *alarm;
622 if ( todo->alarms().count() > 0 ) { 623 if ( todo->alarms().count() > 0 ) {
623 alarm = todo->alarms().first(); 624 alarm = todo->alarms().first();
624 if ( alarm->enabled() ) { 625 if ( alarm->enabled() ) {
625 alarmString = QString::number(alarm->startOffset().asSeconds() ); 626 alarmString = QString::number(alarm->startOffset().asSeconds() );
626 } 627 }
627 } 628 }
628 attList << alarmString; 629 attList << alarmString;
629 attList << todo->categoriesStr(); 630 attList << todo->categoriesStr();
630 attList << todo->secrecyStr(); 631 attList << todo->secrecyStr();
631 return PhoneFormat::getCsum(attList ); 632 return PhoneFormat::getCsum(attList );
632 633
633} 634}
634ulong PhoneFormat::getCsumEvent( Event* event ) 635ulong PhoneFormat::getCsumEvent( Event* event )
635{ 636{
636 QStringList attList; 637 QStringList attList;
637 attList << PhoneParser::dtToString ( event->dtStart() ); 638 attList << PhoneParser::dtToString ( event->dtStart() );
638 attList << PhoneParser::dtToString ( event->dtEnd() ); 639 attList << PhoneParser::dtToString ( event->dtEnd() );
639 attList << event->summary(); 640 attList << event->summary();
640 attList << event->location(); 641 attList << event->location();
641 QString alarmString = "na"; 642 QString alarmString = "na";
642 Alarm *alarm; 643 Alarm *alarm;
643 if ( event->alarms().count() > 0 ) { 644 if ( event->alarms().count() > 0 ) {
644 alarm = event->alarms().first(); 645 alarm = event->alarms().first();
645 if ( alarm->enabled() ) { 646 if ( alarm->enabled() ) {
646 alarmString = QString::number( alarm->startOffset().asSeconds() ); 647 alarmString = QString::number( alarm->startOffset().asSeconds() );
647 } 648 }
648 } 649 }
649 attList << alarmString; 650 attList << alarmString;
650 Recurrence* rec = event->recurrence(); 651 Recurrence* rec = event->recurrence();
651 QStringList list; 652 QStringList list;
652 bool writeEndDate = false; 653 bool writeEndDate = false;
653 switch ( rec->doesRecur() ) 654 switch ( rec->doesRecur() )
654 { 655 {
655 case Recurrence::rDaily: // 0 656 case Recurrence::rDaily: // 0
656 list.append( "0" ); 657 list.append( "0" );
657 list.append( QString::number( rec->frequency() ));//12 658 list.append( QString::number( rec->frequency() ));//12
658 list.append( "0" ); 659 list.append( "0" );
659 list.append( "0" ); 660 list.append( "0" );
660 writeEndDate = true; 661 writeEndDate = true;
661 break; 662 break;
662 case Recurrence::rWeekly:// 1 663 case Recurrence::rWeekly:// 1
663 list.append( "1" ); 664 list.append( "1" );
664 list.append( QString::number( rec->frequency()) );//12 665 list.append( QString::number( rec->frequency()) );//12
665 list.append( "0" ); 666 list.append( "0" );
666 { 667 {
667 int days = 0; 668 int days = 0;
668 QBitArray weekDays = rec->days(); 669 QBitArray weekDays = rec->days();
669 int i; 670 int i;
670 for( i = 1; i <= 7; ++i ) { 671 for( i = 1; i <= 7; ++i ) {
671 if ( weekDays[i-1] ) { 672 if ( weekDays[i-1] ) {
672 days += 1 << (i-1); 673 days += 1 << (i-1);
673 } 674 }
674 } 675 }
675 list.append( QString::number( days ) ); 676 list.append( QString::number( days ) );
676 } 677 }
677 //pending weekdays 678 //pending weekdays
678 writeEndDate = true; 679 writeEndDate = true;
679 680
680 break; 681 break;
681 case Recurrence::rMonthlyPos:// 2 682 case Recurrence::rMonthlyPos:// 2
682 list.append( "2" ); 683 list.append( "2" );
683 list.append( QString::number( rec->frequency()) );//12 684 list.append( QString::number( rec->frequency()) );//12
684 685
685 writeEndDate = true; 686 writeEndDate = true;
686 { 687 {
687 int count = 1; 688 int count = 1;
688 QPtrList<Recurrence::rMonthPos> rmp; 689 QPtrList<Recurrence::rMonthPos> rmp;
689 rmp = rec->monthPositions(); 690 rmp = rec->monthPositions();
690 if ( rmp.first()->negative ) 691 if ( rmp.first()->negative )
691 count = 5 - rmp.first()->rPos - 1; 692 count = 5 - rmp.first()->rPos - 1;
692 else 693 else
693 count = rmp.first()->rPos - 1; 694 count = rmp.first()->rPos - 1;
694 list.append( QString::number( count ) ); 695 list.append( QString::number( count ) );
695 696
696 } 697 }
697 698
698 list.append( "0" ); 699 list.append( "0" );
699 break; 700 break;
700 case Recurrence::rMonthlyDay:// 3 701 case Recurrence::rMonthlyDay:// 3
701 list.append( "3" ); 702 list.append( "3" );
702 list.append( QString::number( rec->frequency()) );//12 703 list.append( QString::number( rec->frequency()) );//12
703 list.append( "0" ); 704 list.append( "0" );
704 list.append( "0" ); 705 list.append( "0" );
705 writeEndDate = true; 706 writeEndDate = true;
706 break; 707 break;
707 case Recurrence::rYearlyMonth://4 708 case Recurrence::rYearlyMonth://4
708 list.append( "4" ); 709 list.append( "4" );
709 list.append( QString::number( rec->frequency()) );//12 710 list.append( QString::number( rec->frequency()) );//12
710 list.append( "0" ); 711 list.append( "0" );
711 list.append( "0" ); 712 list.append( "0" );
712 writeEndDate = true; 713 writeEndDate = true;
713 break; 714 break;
714 715
715 default: 716 default:
716 list.append( "255" ); 717 list.append( "255" );
717 list.append( QString() ); 718 list.append( QString() );
718 list.append( "0" ); 719 list.append( "0" );
719 list.append( QString() ); 720 list.append( QString() );
720 list.append( "0" ); 721 list.append( "0" );
721 list.append( "20991231T000000" ); 722 list.append( "20991231T000000" );
722 break; 723 break;
723 } 724 }
724 if ( writeEndDate ) { 725 if ( writeEndDate ) {
725 726
726 if ( rec->endDate().isValid() ) { // 15 + 16 727 if ( rec->endDate().isValid() ) { // 15 + 16
727 list.append( "1" ); 728 list.append( "1" );
728 list.append( PhoneParser::dtToString( rec->endDate()) ); 729 list.append( PhoneParser::dtToString( rec->endDate()) );
729 } else { 730 } else {
730 list.append( "0" ); 731 list.append( "0" );
731 list.append( "20991231T000000" ); 732 list.append( "20991231T000000" );
732 } 733 }
733 734
734 } 735 }
735 attList << list.join(""); 736 attList << list.join("");
736 attList << event->categoriesStr(); 737 attList << event->categoriesStr();
737 attList << event->secrecyStr(); 738 attList << event->secrecyStr();
738 return PhoneFormat::getCsum(attList ); 739 return PhoneFormat::getCsum(attList );
739} 740}
740ulong PhoneFormat::getCsum( const QStringList & attList) 741ulong PhoneFormat::getCsum( const QStringList & attList)
741{ 742{
742 int max = attList.count() -1; 743 int max = attList.count() -1;
743 ulong cSum = 0; 744 ulong cSum = 0;
744 int j,k,i; 745 int j,k,i;
745 int add; 746 int add;
746 for ( i = 1; i < max ; ++i ) { 747 for ( i = 1; i < max ; ++i ) {
747 QString s = attList[i]; 748 QString s = attList[i];
748 if ( ! s.isEmpty() ){ 749 if ( ! s.isEmpty() ){
749 j = s.length(); 750 j = s.length();
750 for ( k = 0; k < j; ++k ) { 751 for ( k = 0; k < j; ++k ) {
751 int mul = k +1; 752 int mul = k +1;
752 add = s[k].unicode (); 753 add = s[k].unicode ();
753 if ( k < 16 ) 754 if ( k < 16 )
754 mul = mul * mul; 755 mul = mul * mul;
755 add = add * mul *i*i*i; 756 add = add * mul *i*i*i;
756 cSum += add; 757 cSum += add;
757 } 758 }
758 } 759 }
759 } 760 }
760 return cSum; 761 return cSum;
761 762
762} 763}
763//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 764//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
764#include <stdlib.h> 765#include <stdlib.h>
765#define DEBUGMODE false 766#define DEBUGMODE false
766bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 767bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
767{ 768{
768 GSM_StateMachines; 769 GSM_StateMachines;
769 qDebug(" load "); 770 qDebug(" load ");
770 s.opened = false; 771 s.opened = false;
771 s.msg = NULL; 772 s.msg = NULL;
772 s.ConfigNum = 0; 773 s.ConfigNum = 0;
773 QLabel status ( i18n("Reading data. Opening device ..."), 0 ); 774 QLabel status ( i18n("Opening device ..."), 0 );
774 int w = status.sizeHint().width()+20 ; 775 int w = status.sizeHint().width()+20 ;
775 if ( w < 200 ) w = 200; 776 if ( w < 200 ) w = 230;
776 int h = status.sizeHint().height()+20 ; 777 int h = status.sizeHint().height()+20 ;
777 int dw = QApplication::desktop()->width(); 778 int dw = QApplication::desktop()->width();
778 int dh = QApplication::desktop()->height(); 779 int dh = QApplication::desktop()->height();
779 status.setCaption(i18n("Reading Phone Data") ); 780 status.setCaption(i18n("Reading phone...") );
780 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 781 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
781 status.show(); 782 status.show();
782 status.raise(); 783 status.raise();
783 qApp->processEvents(); 784 qApp->processEvents();
784#if 0 785#if 0
785 static char*cp; 786 static char*cp;
786 static INI_Section *cfg = NULL; 787 static INI_Section *cfg = NULL;
787 cfg=GSM_FindGammuRC(); 788 cfg=GSM_FindGammuRC();
788 int i; 789 int i;
789 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 790 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
790 if (cfg!=NULL) { 791 if (cfg!=NULL) {
791 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); 792 cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false);
792 if (cp) di.coding = cp; 793 if (cp) di.coding = cp;
793 794
794 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); 795 s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false);
795 if (s.Config[i].Localize) { 796 if (s.Config[i].Localize) {
796 s.msg=INI_ReadFile(s.Config[i].Localize, true); 797 s.msg=INI_ReadFile(s.Config[i].Localize, true);
797 } else { 798 } else {
798#if !defined(WIN32) && defined(LOCALE_PATH) 799#if !defined(WIN32) && defined(LOCALE_PATH)
799 locale = setlocale(LC_MESSAGES, NULL); 800 locale = setlocale(LC_MESSAGES, NULL);
800 if (locale != NULL) { 801 if (locale != NULL) {
801 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 802 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
802 LOCALE_PATH, 803 LOCALE_PATH,
803 tolower(locale[0]), 804 tolower(locale[0]),
804 tolower(locale[1])); 805 tolower(locale[1]));
805 s.msg = INI_ReadFile(locale_file, true); 806 s.msg = INI_ReadFile(locale_file, true);
806 } 807 }
807#endif 808#endif
808 } 809 }
809 } 810 }
810 811
811 /* Wanted user specific configuration? */ 812 /* Wanted user specific configuration? */
812 813
813 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 814 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
814 815
815 s.ConfigNum++; 816 s.ConfigNum++;
816 817
817 /* We want to use only one file descriptor for global and state machine debug output */ 818 /* We want to use only one file descriptor for global and state machine debug output */
818 s.Config[i].UseGlobalDebugFile = true; 819 s.Config[i].UseGlobalDebugFile = true;
819 820
820 821
821 822
822 /* We wanted to read just user specified configuration. */ 823 /* We wanted to read just user specified configuration. */
823 {break;} 824 {break;}
824 } 825 }
825 826
826#endif 827#endif
827 int error=initDevice(&s); 828 int error=initDevice(&s);
828 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 829 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
829 if ( error != ERR_NONE ) 830 if ( error != ERR_NONE )
830 return false; 831 return false;
831 GSM_Phone_Functions*Phone; 832 GSM_Phone_Functions*Phone;
832 GSM_CalendarEntrynote; 833 GSM_CalendarEntrynote;
833 bool start = true; 834 bool start = true;
834 Phone=s.Phone.Functions; 835 Phone=s.Phone.Functions;
835 bool gshutdown = false; 836 bool gshutdown = false;
836 PhoneParser handler( calendar, mProfileName ); 837 PhoneParser handler( calendar, mProfileName );
837 int ccc = 0; 838 int ccc = 0;
838 QString message = i18n("Processing event # "); 839 QString message = i18n(" Reading event # ");
839 int procCount = 0; 840 int procCount = 0;
840 qDebug("Debug: only 10 calender items are downloaded "); 841 qDebug("Debug: only 10 calender items are downloaded ");
841 while (!gshutdown && ccc++ < 10) { 842 while (!gshutdown && ccc++ < 10) {
842 status.setText ( message + QString::number ( ++procCount ) ); 843 status.setText ( message + QString::number ( ++procCount ) );
843 qApp->processEvents(); 844 qApp->processEvents();
844 qDebug("readEvent %d ", ccc); 845 qDebug("readEvent %d ", ccc);
845 error=Phone->GetNextCalendar(&s,&note,start); 846 error=Phone->GetNextCalendar(&s,&note,start);
846 if (error == ERR_EMPTY) break; 847 if (error == ERR_EMPTY) break;
847 start = false; 848 start = false;
848 handler.readEvent( existingCal, &note ); 849 handler.readEvent( existingCal, &note );
850 qDebug("Org loc %d ",note.Location);
851 //note.Location = 0;
852 error=Phone->SetCalendar(&s,&note);
853 qDebug("new loc %d ",note.Location);
849 } 854 }
850 855
851 start = true; 856 start = true;
852 GSM_ToDoEntry ToDo; 857 GSM_ToDoEntry ToDo;
853 ccc = 0; 858 ccc = 0;
854 message = i18n("Processing todo # "); 859 message = i18n(" Reading todo # ");
855 procCount = 0; 860 procCount = 0;
856 while (!gshutdown) { 861 while (!gshutdown && ccc++ < 10) {
857 status.setText ( message + QString::number ( ++procCount ) ); 862 status.setText ( message + QString::number ( ++procCount ) );
858 qApp->processEvents(); 863 qApp->processEvents();
859 error = Phone->GetNextToDo(&s, &ToDo, start); 864 error = Phone->GetNextToDo(&s, &ToDo, start);
860 if (error == ERR_EMPTY) break; 865 if (error == ERR_EMPTY) break;
861 start = false; 866 start = false;
862 qDebug("ReadTodo %d ", ++ccc); 867 qDebug("ReadTodo %d ", ccc);
863 handler.readTodo( existingCal, &ToDo, &s); 868 handler.readTodo( existingCal, &ToDo, &s);
864 869
865 } 870 }
866 871
867 error=GSM_TerminateConnection(&s); 872 error=GSM_TerminateConnection(&s);
868 873
869 return true; 874 return true;
870} 875}
871void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note ) 876#include <qcstring.h>
877void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note )
872{ 878{
873 QString eText = vfconverter.eventToString( ev ); 879 QString eText = vfconverter.eventToString( ev, cal );
874 int pos = 0; 880 int pos = 0;
875 GSM_ToDoEntry dummy; 881 GSM_ToDoEntry dummy;
876 GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); 882 qDebug( "Convert event");
883 QByteArray ba;
884 QDataStream s ( ba, IO_WriteOnly );
885 s << eText.utf8();
886 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
887 qDebug( "Convert event done");
888 Note->Location = 0;
889 QString loc = ev->getID(mProfileName);
890 if ( !loc.isEmpty() ){
891 Note->Location = loc.toInt();
892 }
893
877} 894}
878void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo ) 895void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo )
879{ 896{
880 QString tText = vfconverter.todoToString( todo ); 897 qDebug( "Convert todo1");
898 QString tText = vfconverter.todoToString( todo, cal );
881 int pos = 0; 899 int pos = 0;
882 GSM_CalendarEntry dummy; 900 GSM_CalendarEntry dummy;
883 GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); 901 QByteArray ba;
902 QDataStream s ( ba, IO_WriteOnly );
903 s << tText.utf8();
904 GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
905 qDebug( "Convert todo done ");
906 gsmTodo->Location = 0;
907 QString loc = todo->getID(mProfileName);
908 if ( !loc.isEmpty() ){
909 gsmTodo->Location = loc.toInt();
910 }
911
884} 912}
885void PhoneFormat::afterSave( Incidence* inc) 913void PhoneFormat::afterSave( Incidence* inc)
886{ 914{
887 uint csum; 915 uint csum;
888 if ( inc->type() == "Event") 916 if ( inc->type() == "Event")
889 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 917 csum = PhoneFormat::getCsumEvent( (Event*) inc );
890 else 918 else
891 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 919 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
892 inc->setCsum( mProfileName, QString::number( csum )); 920 inc->setCsum( mProfileName, QString::number( csum ));
893 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 921 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
894 922
895} 923}
896bool PhoneFormat::save( Calendar *calendar) 924bool PhoneFormat::save( Calendar *calendar)
897{ 925{
926 return true;
898 GSM_StateMachines; 927 GSM_StateMachines;
899 qDebug(" save "); 928 qDebug(" save ");
900 s.opened = false; 929 s.opened = false;
901 s.msg = NULL; 930 s.msg = NULL;
902 s.ConfigNum = 0; 931 s.ConfigNum = 0;
903 QLabel status ( i18n("Writing data. Opening device ..."), 0 ); 932 QLabel status ( i18n(" Opening device ..."), 0 );
904 int w = status.sizeHint().width()+20 ; 933 int w = status.sizeHint().width()+20 ;
905 if ( w < 200 ) w = 200; 934 if ( w < 200 ) w = 230;
906 int h = status.sizeHint().height()+20 ; 935 int h = status.sizeHint().height()+20 ;
907 int dw = QApplication::desktop()->width(); 936 int dw = QApplication::desktop()->width();
908 int dh = QApplication::desktop()->height(); 937 int dh = QApplication::desktop()->height();
909 status.setCaption(i18n("Writing Phone Data") ); 938 status.setCaption(i18n("Writing to phone...") );
910 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 939 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
911 status.show(); 940 status.show();
912 status.raise(); 941 status.raise();
913 qApp->processEvents(); 942 qApp->processEvents();
914 943
915 int error=initDevice(&s); 944 int error=initDevice(&s);
916 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); 945 qDebug("GSM Init %d (no error is %d)", error, ERR_NONE);
917 if ( error != ERR_NONE ) 946 if ( error != ERR_NONE )
918 return false; 947 return false;
919 GSM_Phone_Functions*Phone; 948 GSM_Phone_Functions*Phone;
920 GSM_CalendarEntryNote; 949 GSM_CalendarEntryNote;
921 bool start = true; 950 bool start = true;
922 Phone=s.Phone.Functions; 951 Phone=s.Phone.Functions;
923 bool gshutdown = false; 952 bool gshutdown = false;
924 QPtrList<Event> er = calendar->rawEvents(); 953 QPtrList<Event> er = calendar->rawEvents();
925 Event* ev = er.first(); 954 Event* ev = er.first();
926 QString message = i18n("Processing event # "); 955 QString message = i18n(" Processing event # ");
927 int procCount = 0; 956 int procCount = 0;
928 while ( ev ) { 957 bool planB = true;// false;
929 //qDebug("i %d ", ++i); 958 while ( ev && ! planB) {
930 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one 959 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
931 960
932 status.setText ( message + QString::number ( ++procCount ) ); 961 status.setText ( message + QString::number ( ++procCount ) );
933 qApp->processEvents(); 962 qApp->processEvents();
934 event2GSM( ev, &Note ); 963 qDebug("event1 %d ", procCount);
964 event2GSM( calendar, ev, &Note );
935 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 965 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
936 error = Phone->DeleteCalendar(&s, &Note); 966 error = Phone->DeleteCalendar(&s, &Note);
967 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
968 planB = true;
969 qDebug(" e delete planB %d ", error);
970 break;
971 }
937 } 972 }
938 else if ( ev->getID(mProfileName).isEmpty() ) { // add new 973 else if ( ev->getID(mProfileName).isEmpty() ) { // add new
939 // we have to do this later after deleting 974 // we have to do this later after deleting
940 975
941 } 976 }
942 else { // change existing 977 else { // change existing
943 error = Phone->SetCalendar(&s, &Note); 978 error = Phone->SetCalendar(&s, &Note);
979 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
980 planB = true;
981 qDebug(" e change planB %d ", error);
982 break;
983 }
984 qDebug("Change Calendar. Location %d status: %d",Note.Location, error );
944 } 985 }
945 } 986 }
946 ev = er.next(); 987 ev = er.next();
947 } 988 }
948 ev = er.first(); 989 ev = er.first();
949 // pending get empty slots 990 // pending get empty slots
950 while ( ev ) { 991 int loc = 0;
992 while ( ev && ! planB) {
951 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 993 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
994 qDebug("event2 %d ", procCount);
952 if ( ev->getID(mProfileName).isEmpty() ) { 995 if ( ev->getID(mProfileName).isEmpty() ) {
953 status.setText ( message + QString::number ( ++procCount ) ); 996 status.setText ( message + QString::number ( ++procCount ) );
954 qApp->processEvents(); 997 qApp->processEvents();
955 //int newID ;//= pending 998 //int newID ;//= pending
956 //ev->setID(mProfileName, QString::number( newID )); 999 //ev->setID(mProfileName, QString::number( newID ));
957 event2GSM( ev, &Note ); 1000 event2GSM( calendar, ev, &Note );
958 Note.Location = 0; 1001 ++loc;
1002 Note.Location = loc;
959 error = Phone->AddCalendar(&s, &Note); 1003 error = Phone->AddCalendar(&s, &Note);
1004 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1005 planB = true;
1006 qDebug(" e add planB %d ", error);
1007 break;
1008 }
960 ev->setID( mProfileName, QString::number( Note.Location ) ); 1009 ev->setID( mProfileName, QString::number( Note.Location ) );
961 qDebug("New Calendar. Location %d ",Note.Location ); 1010 qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN);
962 afterSave( ev ); 1011 afterSave( ev );
963 } else { 1012 } else {
964 afterSave( ev ); // setting temp sync stat for changed items 1013 afterSave( ev ); // setting temp sync stat for changed items
965 } 1014 }
966 } 1015 }
967 ev = er.next(); 1016 ev = er.next();
968 } 1017 }
1018
1019
1020 if ( planB ) {
1021 qDebug("delete all calendar...");
1022 status.setText ( i18n("Deleting all calendar..."));
1023 qApp->processEvents();
1024 error=Phone->DeleteAllCalendar(&s);
1025 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1026 message = i18n(" Deleting event # ");
1027 procCount = 0;
1028 while (1) {
1029 status.setText ( message + QString::number ( ++procCount ) );
1030 qApp->processEvents();
1031 qDebug("deleting event ... %d", procCount);
1032 error = Phone->GetNextCalendar(&s,&Note,true);
1033 if (error != ERR_NONE) break;
1034 error = Phone->DeleteCalendar(&s,&Note);
1035 }
1036 qDebug("deleting calendar ... finished");
1037 } else {
1038 status.setText ( i18n("All calendar deleted!"));
1039 qDebug("all cal deleted");
1040 }
1041 bool planC = false;
1042 ev = er.first();
1043 procCount = 0;
1044 message = i18n(" Writing event # ");
1045 while ( ev && ! planC) {
1046 status.setText ( message + QString::number ( ++procCount ) );
1047 qApp->processEvents();
1048 event2GSM( calendar, ev, &Note );
1049 Note.Location = procCount;
1050 error=Phone->AddCalendar(&s,&Note);
1051 if (error != ERR_NONE ) {
1052 // we have currently no planC :-(
1053 // planC = true;
1054 //qDebug("add planC %d ", error);
1055 //break;
1056 // we remove the ID such that this todo is not deleted after next sync
1057 ev->removeID(mProfileName);
1058 ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1059 qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error);
1060 } else {
1061 qDebug("cal adding loc %d planB stat %d ", Note.Location ,error);
1062 ev->setID(mProfileName, QString::number( Note.Location ));
1063 afterSave( ev );
1064 }
1065 ev = er.next();
1066 }
1067 if ( planC ) {
1068 qDebug("writing cal went wrong...");
1069
1070 // we have currently no planC :-(
1071 }
1072 }
969 GSM_ToDoEntry ToDoEntry; 1073 GSM_ToDoEntry ToDoEntry;
970 QPtrList<Todo> tl = calendar->rawTodos(); 1074 QPtrList<Todo> tl = calendar->rawTodos();
971 Todo* to = tl.first(); 1075 Todo* to = tl.first();
972 1076
973 message = i18n("Processing todo # "); 1077 message = i18n(" Processing todo # ");
974 procCount = 0; 1078 procCount = 0;
975 while ( to ) { 1079 planB = false;
1080 while ( to && ! planB ) {
976 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 1081 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
1082 qDebug("todo3 %d ", procCount);
977 status.setText ( message + QString::number ( ++procCount ) ); 1083 status.setText ( message + QString::number ( ++procCount ) );
978 qApp->processEvents(); 1084 qApp->processEvents();
979 todo2GSM( to, &ToDoEntry ); 1085 qDebug("todo5 %d ", procCount);
1086 todo2GSM( calendar, to, &ToDoEntry );
980 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 1087 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
981 error=Phone->DeleteToDo(&s,&ToDoEntry); 1088 error=Phone->DeleteToDo(&s,&ToDoEntry);
1089 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1090 planB = true;
1091 qDebug("delete planB %d ", error);
1092 }
982 } 1093 }
983 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 1094 else if ( to->getID(mProfileName).isEmpty() ) { // add new
984 ; 1095 ;
985 } 1096 }
986 else { // change existing 1097 else { // change existing
987 error=Phone->SetToDo(&s,&ToDoEntry); 1098 error=Phone->SetToDo(&s,&ToDoEntry);
1099 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1100 planB = true;
1101 qDebug("set planB %d ", error);
1102 }
1103 qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error );
988 } 1104 }
989 } 1105 }
990 to = tl.next(); 1106 to = tl.next();
991 } 1107 }
992 1108
993 // pending get empty slots 1109 // pending get empty slots
994 to = tl.first(); 1110 to = tl.first();
995 while ( to ) { 1111 while ( to && ! planB ) {
1112 qDebug("todo2 %d ", procCount);
996 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { 1113 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
1114 qDebug("todo4 %d ", procCount);
997 if ( to->getID(mProfileName).isEmpty() ) { 1115 if ( to->getID(mProfileName).isEmpty() ) {
998 status.setText ( message + QString::number ( ++procCount ) ); 1116 status.setText ( message + QString::number ( ++procCount ) );
999 qApp->processEvents(); 1117 qApp->processEvents();
1000 //int newID ;//= pending 1118 //int newID ;//= pending
1001 //to->setID(mProfileName, QString::number( newID )); 1119 //to->setID(mProfileName, QString::number( newID ));
1002 todo2GSM( to, &ToDoEntry ); 1120 todo2GSM( calendar,to, &ToDoEntry );
1003 ToDoEntry.Location = 0; 1121 ToDoEntry.Location = 0;
1004 error=Phone->AddToDo(&s,&ToDoEntry); 1122 error=Phone->AddToDo(&s,&ToDoEntry);
1123 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1124 planB = true;
1125 qDebug("new planB %d ", error);
1126 }
1005 to->setID(mProfileName, QString::number( ToDoEntry.Location )); 1127 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1006 afterSave( to ); 1128 afterSave( to );
1007 qDebug("New Todo. Location %d ",ToDoEntry.Location ); 1129 qDebug("New Todo. Location %d %d",ToDoEntry.Location, error );
1008 } else { 1130 } else {
1009 afterSave( to ); 1131 afterSave( to );
1010 } 1132 }
1011 } 1133 }
1012 to = tl.next(); 1134 to = tl.next();
1013 } 1135 }
1136 if ( planB ) {
1137 qDebug("delete all ...");
1138 error=Phone->DeleteAllToDo(&s);
1139 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1140 while (1) {
1141 qDebug("deleting todo ...");
1142 error = Phone->GetNextToDo(&s,&ToDoEntry,true);
1143 if (error != ERR_NONE) break;
1144 error = Phone->DeleteToDo(&s,&ToDoEntry);
1145 }
1146 qDebug("deleting todo ... finished");
1147 } else {
1148 qDebug("all todo deleted");
1149 }
1150 bool planC = false;
1151 to = tl.first();
1152 while ( to && ! planC ) {
1153 todo2GSM( calendar,to, &ToDoEntry );
1154 ToDoEntry.Location = 0;
1155 error=Phone->AddToDo(&s,&ToDoEntry);
1156 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
1157 // we have currently no planC :-(
1158 // planC = true;
1159 //qDebug("add planC %d ", error);
1160 //break;
1161 // we remove the ID such that this todo is not deleted after next sync
1162 to->removeID(mProfileName);
1163 to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
1164 } else {
1165 qDebug("adding %d planB %d ", ToDoEntry.Location ,error);
1166 to->setID(mProfileName, QString::number( ToDoEntry.Location ));
1167 afterSave( to );
1168 }
1169 to = tl.next();
1170 }
1171 if ( planC ) {
1172 // we have currently no planC :-(
1173 }
1174 }
1014 return true; 1175 return true;
1015} 1176}
1016QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) 1177QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
1017{ 1178{
1018 QString datestr; 1179 QString datestr;
1019 QString timestr; 1180 QString timestr;
1020 int offset = KGlobal::locale()->localTimeOffset( dti ); 1181 int offset = KGlobal::locale()->localTimeOffset( dti );
1021 QDateTime dt; 1182 QDateTime dt;
1022 if (useTZ) 1183 if (useTZ)
1023 dt = dti.addSecs ( -(offset*60)); 1184 dt = dti.addSecs ( -(offset*60));
1024 else 1185 else
1025 dt = dti; 1186 dt = dti;
1026 if(dt.date().isValid()){ 1187 if(dt.date().isValid()){
1027 const QDate& date = dt.date(); 1188 const QDate& date = dt.date();
1028 datestr.sprintf("%04d%02d%02d", 1189 datestr.sprintf("%04d%02d%02d",
1029 date.year(), date.month(), date.day()); 1190 date.year(), date.month(), date.day());
1030 } 1191 }
1031 if(dt.time().isValid()){ 1192 if(dt.time().isValid()){
1032 const QTime& time = dt.time(); 1193 const QTime& time = dt.time();
1033 timestr.sprintf("T%02d%02d%02d", 1194 timestr.sprintf("T%02d%02d%02d",
1034 time.hour(), time.minute(), time.second()); 1195 time.hour(), time.minute(), time.second());
1035 } 1196 }
1036 return datestr + timestr; 1197 return datestr + timestr;
1037} 1198}
1038QString PhoneFormat::getEventString( Event* event ) 1199QString PhoneFormat::getEventString( Event* event )
1039{ 1200{
1040#if 0 1201#if 0
1041 QStringList list; 1202 QStringList list;
1042 list.append( QString::number(event->zaurusId() ) ); 1203 list.append( QString::number(event->zaurusId() ) );
1043 list.append( event->categories().join(",") ); 1204 list.append( event->categories().join(",") );
1044 if ( !event->summary().isEmpty() ) 1205 if ( !event->summary().isEmpty() )
1045 list.append( event->summary() ); 1206 list.append( event->summary() );
1046 else 1207 else
1047 list.append("" ); 1208 list.append("" );
1048 if ( !event->location().isEmpty() ) 1209 if ( !event->location().isEmpty() )
1049 list.append( event->location() ); 1210 list.append( event->location() );
1050 else 1211 else
1051 list.append("" ); 1212 list.append("" );
1052 if ( !event->description().isEmpty() ) 1213 if ( !event->description().isEmpty() )
1053 list.append( event->description() ); 1214 list.append( event->description() );
1054 else 1215 else
1055 list.append( "" ); 1216 list.append( "" );
1056 if ( event->doesFloat () ) { 1217 if ( event->doesFloat () ) {
1057 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 1218 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
1058 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 1219 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
1059 list.append( "1" ); 1220 list.append( "1" );
1060 1221
1061 } 1222 }
1062 else { 1223 else {
1063 list.append( dtToString( event->dtStart()) ); 1224 list.append( dtToString( event->dtStart()) );
1064 list.append( dtToString( event->dtEnd()) ); //6 1225 list.append( dtToString( event->dtEnd()) ); //6
1065 list.append( "0" ); 1226 list.append( "0" );
1066 } 1227 }
1067 bool noAlarm = true; 1228 bool noAlarm = true;
1068 if ( event->alarms().count() > 0 ) { 1229 if ( event->alarms().count() > 0 ) {
1069 Alarm * al = event->alarms().first(); 1230 Alarm * al = event->alarms().first();
1070 if ( al->enabled() ) { 1231 if ( al->enabled() ) {
1071 noAlarm = false; 1232 noAlarm = false;
1072 list.append( "0" ); // yes, 0 == alarm 1233 list.append( "0" ); // yes, 0 == alarm
1073 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 1234 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
1074 if ( al->type() == Alarm::Audio ) 1235 if ( al->type() == Alarm::Audio )
1075 list.append( "1" ); // type audio 1236 list.append( "1" ); // type audio
1076 else 1237 else
1077 list.append( "0" ); // type silent 1238 list.append( "0" ); // type silent
1078 } 1239 }
1079 } 1240 }
1080 if ( noAlarm ) { 1241 if ( noAlarm ) {
1081 list.append( "1" ); // yes, 1 == no alarm 1242 list.append( "1" ); // yes, 1 == no alarm
1082 list.append( "0" ); // no alarm offset 1243 list.append( "0" ); // no alarm offset
1083 list.append( "1" ); // type 1244 list.append( "1" ); // type
1084 } 1245 }
1085 // next is: 11 1246 // next is: 11
1086 // next is: 11-16 are recurrence 1247 // next is: 11-16 are recurrence
1087 Recurrence* rec = event->recurrence(); 1248 Recurrence* rec = event->recurrence();
1088 1249
1089 bool writeEndDate = false; 1250 bool writeEndDate = false;
1090 switch ( rec->doesRecur() ) 1251 switch ( rec->doesRecur() )
1091 { 1252 {
1092 case Recurrence::rDaily: // 0 1253 case Recurrence::rDaily: // 0
1093 list.append( "0" ); 1254 list.append( "0" );
1094 list.append( QString::number( rec->frequency() ));//12 1255 list.append( QString::number( rec->frequency() ));//12
1095 list.append( "0" ); 1256 list.append( "0" );
1096 list.append( "0" ); 1257 list.append( "0" );
1097 writeEndDate = true; 1258 writeEndDate = true;
1098 break; 1259 break;
1099 case Recurrence::rWeekly:// 1 1260 case Recurrence::rWeekly:// 1
1100 list.append( "1" ); 1261 list.append( "1" );
1101 list.append( QString::number( rec->frequency()) );//12 1262 list.append( QString::number( rec->frequency()) );//12
1102 list.append( "0" ); 1263 list.append( "0" );
1103 { 1264 {
1104 int days = 0; 1265 int days = 0;
1105 QBitArray weekDays = rec->days(); 1266 QBitArray weekDays = rec->days();
1106 int i; 1267 int i;
1107 for( i = 1; i <= 7; ++i ) { 1268 for( i = 1; i <= 7; ++i ) {
1108 if ( weekDays[i-1] ) { 1269 if ( weekDays[i-1] ) {
1109 days += 1 << (i-1); 1270 days += 1 << (i-1);
1110 } 1271 }
1111 } 1272 }
1112 list.append( QString::number( days ) ); 1273 list.append( QString::number( days ) );
1113 } 1274 }
1114 //pending weekdays 1275 //pending weekdays
1115 writeEndDate = true; 1276 writeEndDate = true;
1116 1277
1117 break; 1278 break;
1118 case Recurrence::rMonthlyPos:// 2 1279 case Recurrence::rMonthlyPos:// 2
1119 list.append( "2" ); 1280 list.append( "2" );
1120 list.append( QString::number( rec->frequency()) );//12 1281 list.append( QString::number( rec->frequency()) );//12
1121 1282
1122 writeEndDate = true; 1283 writeEndDate = true;
1123 { 1284 {
1124 int count = 1; 1285 int count = 1;
1125 QPtrList<Recurrence::rMonthPos> rmp; 1286 QPtrList<Recurrence::rMonthPos> rmp;
1126 rmp = rec->monthPositions(); 1287 rmp = rec->monthPositions();
1127 if ( rmp.first()->negative ) 1288 if ( rmp.first()->negative )
1128 count = 5 - rmp.first()->rPos - 1; 1289 count = 5 - rmp.first()->rPos - 1;
1129 else 1290 else
1130 count = rmp.first()->rPos - 1; 1291 count = rmp.first()->rPos - 1;
1131 list.append( QString::number( count ) ); 1292 list.append( QString::number( count ) );
1132 1293
1133 } 1294 }
1134 1295
1135 list.append( "0" ); 1296 list.append( "0" );
1136 break; 1297 break;
1137 case Recurrence::rMonthlyDay:// 3 1298 case Recurrence::rMonthlyDay:// 3
1138 list.append( "3" ); 1299 list.append( "3" );
1139 list.append( QString::number( rec->frequency()) );//12 1300 list.append( QString::number( rec->frequency()) );//12
1140 list.append( "0" ); 1301 list.append( "0" );
1141 list.append( "0" ); 1302 list.append( "0" );
1142 writeEndDate = true; 1303 writeEndDate = true;
1143 break; 1304 break;
1144 case Recurrence::rYearlyMonth://4 1305 case Recurrence::rYearlyMonth://4
1145 list.append( "4" ); 1306 list.append( "4" );
1146 list.append( QString::number( rec->frequency()) );//12 1307 list.append( QString::number( rec->frequency()) );//12
1147 list.append( "0" ); 1308 list.append( "0" );
1148 list.append( "0" ); 1309 list.append( "0" );
1149 writeEndDate = true; 1310 writeEndDate = true;
1150 break; 1311 break;
1151 1312
1152 default: 1313 default:
1153 list.append( "255" ); 1314 list.append( "255" );
1154 list.append( QString() ); 1315 list.append( QString() );
1155 list.append( "0" ); 1316 list.append( "0" );
1156 list.append( QString() ); 1317 list.append( QString() );
1157 list.append( "0" ); 1318 list.append( "0" );
1158 list.append( "20991231T000000" ); 1319 list.append( "20991231T000000" );
1159 break; 1320 break;
1160 } 1321 }
1161 if ( writeEndDate ) { 1322 if ( writeEndDate ) {
1162 1323
1163 if ( rec->endDate().isValid() ) { // 15 + 16 1324 if ( rec->endDate().isValid() ) { // 15 + 16
1164 list.append( "1" ); 1325 list.append( "1" );
1165 list.append( dtToString( rec->endDate()) ); 1326 list.append( dtToString( rec->endDate()) );
1166 } else { 1327 } else {
1167 list.append( "0" ); 1328 list.append( "0" );
1168 list.append( "20991231T000000" ); 1329 list.append( "20991231T000000" );
1169 } 1330 }
1170 1331
1171 } 1332 }
1172 if ( event->doesFloat () ) { 1333 if ( event->doesFloat () ) {
1173 list.append( dtToString( event->dtStart(), false ).left( 8 )); 1334 list.append( dtToString( event->dtStart(), false ).left( 8 ));
1174 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 1335 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
1175 1336
1176 } 1337 }
1177 else { 1338 else {
1178 list.append( QString() ); 1339 list.append( QString() );
1179 list.append( QString() ); 1340 list.append( QString() );
1180 1341
1181 } 1342 }
1182 if (event->dtStart().date() == event->dtEnd().date() ) 1343 if (event->dtStart().date() == event->dtEnd().date() )
1183 list.append( "0" ); 1344 list.append( "0" );
1184 else 1345 else
1185 list.append( "1" ); 1346 list.append( "1" );
1186 1347
1187 1348
1188 for(QStringList::Iterator it=list.begin(); 1349 for(QStringList::Iterator it=list.begin();
1189 it!=list.end(); ++it){ 1350 it!=list.end(); ++it){
1190 QString& s = (*it); 1351 QString& s = (*it);
1191 s.replace(QRegExp("\""), "\"\""); 1352 s.replace(QRegExp("\""), "\"\"");
1192 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1353 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1193 s.prepend('\"'); 1354 s.prepend('\"');
1194 s.append('\"'); 1355 s.append('\"');
1195 } else if(s.isEmpty() && !s.isNull()){ 1356 } else if(s.isEmpty() && !s.isNull()){
1196 s = "\"\""; 1357 s = "\"\"";
1197 } 1358 }
1198 } 1359 }
1199 return list.join(","); 1360 return list.join(",");
1200#endif 1361#endif
1201 return QString(); 1362 return QString();
1202 1363
1203} 1364}
1204QString PhoneFormat::getTodoString( Todo* todo ) 1365QString PhoneFormat::getTodoString( Todo* todo )
1205{ 1366{
1206#if 0 1367#if 0
1207 QStringList list; 1368 QStringList list;
1208 list.append( QString::number( todo->zaurusId() ) ); 1369 list.append( QString::number( todo->zaurusId() ) );
1209 list.append( todo->categories().join(",") ); 1370 list.append( todo->categories().join(",") );
1210 1371
1211 if ( todo->hasStartDate() ) { 1372 if ( todo->hasStartDate() ) {
1212 list.append( dtToString( todo->dtStart()) ); 1373 list.append( dtToString( todo->dtStart()) );
1213 } else 1374 } else
1214 list.append( QString() ); 1375 list.append( QString() );
1215 1376
1216 if ( todo->hasDueDate() ) { 1377 if ( todo->hasDueDate() ) {
1217 QTime tim; 1378 QTime tim;
1218 if ( todo->doesFloat()) { 1379 if ( todo->doesFloat()) {
1219 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 1380 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
1220 } else { 1381 } else {
1221 list.append( dtToString(todo->dtDue() ) ); 1382 list.append( dtToString(todo->dtDue() ) );
1222 } 1383 }
1223 } else 1384 } else
1224 list.append( QString() ); 1385 list.append( QString() );
1225 1386
1226 if ( todo->isCompleted() ) { 1387 if ( todo->isCompleted() ) {
1227 list.append( dtToString( todo->completed()) ); 1388 list.append( dtToString( todo->completed()) );
1228 list.append( "0" ); // yes 0 == completed 1389 list.append( "0" ); // yes 0 == completed
1229 } else { 1390 } else {
1230 list.append( dtToString( todo->completed()) ); 1391 list.append( dtToString( todo->completed()) );
1231 list.append( "1" ); 1392 list.append( "1" );
1232 } 1393 }
1233 list.append( QString::number( todo->priority() )); 1394 list.append( QString::number( todo->priority() ));
1234 if( ! todo->summary().isEmpty() ) 1395 if( ! todo->summary().isEmpty() )
1235 list.append( todo->summary() ); 1396 list.append( todo->summary() );
1236 else 1397 else
1237 list.append( "" ); 1398 list.append( "" );
1238 if (! todo->description().isEmpty() ) 1399 if (! todo->description().isEmpty() )
1239 list.append( todo->description() ); 1400 list.append( todo->description() );
1240 else 1401 else
1241 list.append( "" ); 1402 list.append( "" );
1242 for(QStringList::Iterator it=list.begin(); 1403 for(QStringList::Iterator it=list.begin();
1243 it!=list.end(); ++it){ 1404 it!=list.end(); ++it){
1244 QString& s = (*it); 1405 QString& s = (*it);
1245 s.replace(QRegExp("\""), "\"\""); 1406 s.replace(QRegExp("\""), "\"\"");
1246 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 1407 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
1247 s.prepend('\"'); 1408 s.prepend('\"');
1248 s.append('\"'); 1409 s.append('\"');
1249 } else if(s.isEmpty() && !s.isNull()){ 1410 } else if(s.isEmpty() && !s.isNull()){
1250 s = "\"\""; 1411 s = "\"\"";
1251 } 1412 }
1252 } 1413 }
1253 return list.join(","); 1414 return list.join(",");
1254#endif 1415#endif
1255 return QString(); 1416 return QString();
1256} 1417}
1257 1418
1258 1419
1259QString PhoneFormat::toString( Calendar * ) 1420QString PhoneFormat::toString( Calendar * )
1260{ 1421{
1261 return QString::null; 1422 return QString::null;
1262} 1423}
1263bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 1424bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
1264{ 1425{
1265 return false; 1426 return false;
1266} 1427}
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 33b2091..2c2e51c 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -1,67 +1,67 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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#ifndef PHONEFORMAT_H 21#ifndef PHONEFORMAT_H
22#define PHONEFORMAT_H 22#define PHONEFORMAT_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25 25
26#include "scheduler.h" 26#include "scheduler.h"
27 27
28#include "vcalformat.h" 28#include "vcalformat.h"
29#include "calformat.h" 29#include "calformat.h"
30extern "C" { 30extern "C" {
31#include "../gammu/emb/common/gammu.h" 31#include "../gammu/emb/common/gammu.h"
32} 32}
33namespace KCal { 33namespace KCal {
34 34
35/** 35/**
36 This class implements the calendar format used by Phone. 36 This class implements the calendar format used by Phone.
37*/ 37*/
38 class Event; 38 class Event;
39 class Todo; 39 class Todo;
40class PhoneFormat : public QObject { 40class PhoneFormat : public QObject {
41 public: 41 public:
42 /** Create new iCalendar format. */ 42 /** Create new iCalendar format. */
43 PhoneFormat(QString profileName, QString device,QString connection, QString model); 43 PhoneFormat(QString profileName, QString device,QString connection, QString model);
44 virtual ~PhoneFormat(); 44 virtual ~PhoneFormat();
45 45
46 bool load( Calendar * ,Calendar * ); 46 bool load( Calendar * ,Calendar * );
47 bool save( Calendar * ); 47 bool save( Calendar * );
48 bool fromString( Calendar *, const QString & ); 48 bool fromString( Calendar *, const QString & );
49 QString toString( Calendar * ); 49 QString toString( Calendar * );
50 static ulong getCsum( const QStringList & ); 50 static ulong getCsum( const QStringList & );
51 static ulong getCsumTodo( Todo* to ); 51 static ulong getCsumTodo( Todo* to );
52 static ulong getCsumEvent( Event* ev ); 52 static ulong getCsumEvent( Event* ev );
53 private: 53 private:
54 VCalFormat vfconverter; 54 VCalFormat vfconverter;
55 void event2GSM( Event* ev, GSM_CalendarEntry*Note ); 55 void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note );
56 void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo ); 56 void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo );
57 int initDevice(GSM_StateMachine *s); 57 int initDevice(GSM_StateMachine *s);
58 QString getEventString( Event* ); 58 QString getEventString( Event* );
59 QString getTodoString( Todo* ); 59 QString getTodoString( Todo* );
60 QString dtToGSM( const QDateTime& dt, bool useTZ = true ); 60 QString dtToGSM( const QDateTime& dt, bool useTZ = true );
61 QString mProfileName, mDevice, mConnection, mModel; 61 QString mProfileName, mDevice, mConnection, mModel;
62 void afterSave( Incidence* ); 62 void afterSave( Incidence* );
63}; 63};
64 64
65} 65}
66 66
67#endif 67#endif
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 1167e58..076cd3f 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1,1697 +1,1700 @@
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 <kmessagebox.h> 32#include <kmessagebox.h>
33#include <kiconloader.h> 33#include <kiconloader.h>
34#include <klocale.h> 34#include <klocale.h>
35 35
36#include "vcc.h" 36#include "vcc.h"
37#include "vobject.h" 37#include "vobject.h"
38 38
39#include "vcaldrag.h" 39#include "vcaldrag.h"
40#include "calendar.h" 40#include "calendar.h"
41 41
42#include "vcalformat.h" 42#include "vcalformat.h"
43 43
44using namespace KCal; 44using namespace KCal;
45 45
46VCalFormat::VCalFormat() 46VCalFormat::VCalFormat()
47{ 47{
48 mCalendar = 0;
48} 49}
49 50
50VCalFormat::~VCalFormat() 51VCalFormat::~VCalFormat()
51{ 52{
52} 53}
53 54
54bool VCalFormat::load(Calendar *calendar, const QString &fileName) 55bool VCalFormat::load(Calendar *calendar, const QString &fileName)
55{ 56{
56 mCalendar = calendar; 57 mCalendar = calendar;
57 58
58 clearException(); 59 clearException();
59 60
60 kdDebug(5800) << "VCalFormat::load() " << fileName << endl; 61 kdDebug(5800) << "VCalFormat::load() " << fileName << endl;
61 62
62 VObject *vcal = 0; 63 VObject *vcal = 0;
63 64
64 // this is not necessarily only 1 vcal. Could be many vcals, or include 65 // this is not necessarily only 1 vcal. Could be many vcals, or include
65 // a vcard... 66 // a vcard...
66 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); 67 vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
67 68
68 if (!vcal) { 69 if (!vcal) {
69 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 70 setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
70 return FALSE; 71 return FALSE;
71 } 72 }
72 73
73 // any other top-level calendar stuff should be added/initialized here 74 // any other top-level calendar stuff should be added/initialized here
74 75
75 // put all vobjects into their proper places 76 // put all vobjects into their proper places
76 populate(vcal); 77 populate(vcal);
77 78
78 // clean up from vcal API stuff 79 // clean up from vcal API stuff
79 cleanVObjects(vcal); 80 cleanVObjects(vcal);
80 cleanStrTbl(); 81 cleanStrTbl();
81 82
82 return true; 83 return true;
83} 84}
84 85
85 86
86bool VCalFormat::save(Calendar *calendar, const QString &fileName) 87bool VCalFormat::save(Calendar *calendar, const QString &fileName)
87{ 88{
88 mCalendar = calendar; 89 mCalendar = calendar;
89 90
90 QString tmpStr; 91 QString tmpStr;
91 VObject *vcal, *vo; 92 VObject *vcal, *vo;
92 93
93 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; 94 kdDebug(5800) << "VCalFormat::save(): " << fileName << endl;
94 95
95 vcal = newVObject(VCCalProp); 96 vcal = newVObject(VCCalProp);
96 97
97 // addPropValue(vcal,VCLocationProp, "0.0"); 98 // addPropValue(vcal,VCLocationProp, "0.0");
98 addPropValue(vcal,VCProdIdProp, productId()); 99 addPropValue(vcal,VCProdIdProp, productId());
99 tmpStr = mCalendar->getTimeZoneStr(); 100 tmpStr = mCalendar->getTimeZoneStr();
100 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); 101 //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
101 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); 102 addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit());
102 addPropValue(vcal,VCVersionProp, _VCAL_VERSION); 103 addPropValue(vcal,VCVersionProp, _VCAL_VERSION);
103 104
104 // TODO STUFF 105 // TODO STUFF
105 QPtrList<Todo> todoList = mCalendar->rawTodos(); 106 QPtrList<Todo> todoList = mCalendar->rawTodos();
106 QPtrListIterator<Todo> qlt(todoList); 107 QPtrListIterator<Todo> qlt(todoList);
107 for (; qlt.current(); ++qlt) { 108 for (; qlt.current(); ++qlt) {
108 vo = eventToVTodo(qlt.current()); 109 vo = eventToVTodo(qlt.current());
109 addVObjectProp(vcal, vo); 110 addVObjectProp(vcal, vo);
110 } 111 }
111 112
112 // EVENT STUFF 113 // EVENT STUFF
113 QPtrList<Event> events = mCalendar->rawEvents(); 114 QPtrList<Event> events = mCalendar->rawEvents();
114 Event *ev; 115 Event *ev;
115 for(ev=events.first();ev;ev=events.next()) { 116 for(ev=events.first();ev;ev=events.next()) {
116 vo = eventToVEvent(ev); 117 vo = eventToVEvent(ev);
117 addVObjectProp(vcal, vo); 118 addVObjectProp(vcal, vo);
118 } 119 }
119 120
120 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal); 121 writeVObjectToFile(QFile::encodeName(fileName).data() ,vcal);
121 cleanVObjects(vcal); 122 cleanVObjects(vcal);
122 cleanStrTbl(); 123 cleanStrTbl();
123 124
124 if (QFile::exists(fileName)) { 125 if (QFile::exists(fileName)) {
125 kdDebug(5800) << "No error" << endl; 126 kdDebug(5800) << "No error" << endl;
126 return true; 127 return true;
127 } else { 128 } else {
128 kdDebug(5800) << "Error" << endl; 129 kdDebug(5800) << "Error" << endl;
129 return false; // error 130 return false; // error
130 } 131 }
131} 132}
132 133
133bool VCalFormat::fromString( Calendar *calendar, const QString &text ) 134bool VCalFormat::fromString( Calendar *calendar, const QString &text )
134{ 135{
135 // TODO: Factor out VCalFormat::fromString() 136 // TODO: Factor out VCalFormat::fromString()
136 137
137 QCString data = text.utf8(); 138 QCString data = text.utf8();
138 139
139 if ( !data.size() ) return false; 140 if ( !data.size() ) return false;
140 141
141 VObject *vcal = Parse_MIME( data.data(), data.size()); 142 VObject *vcal = Parse_MIME( data.data(), data.size());
142 if ( !vcal ) return false; 143 if ( !vcal ) return false;
143 144
144 VObjectIterator i; 145 VObjectIterator i;
145 VObject *curvo; 146 VObject *curvo;
146 initPropIterator( &i, vcal ); 147 initPropIterator( &i, vcal );
147 148
148 // we only take the first object. TODO: parse all incidences. 149 // we only take the first object. TODO: parse all incidences.
149 do { 150 do {
150 curvo = nextVObject( &i ); 151 curvo = nextVObject( &i );
151 } while ( strcmp( vObjectName( curvo ), VCEventProp ) && 152 } while ( strcmp( vObjectName( curvo ), VCEventProp ) &&
152 strcmp( vObjectName( curvo ), VCTodoProp ) ); 153 strcmp( vObjectName( curvo ), VCTodoProp ) );
153 154
154 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) { 155 if ( strcmp( vObjectName( curvo ), VCEventProp ) == 0 ) {
155 Event *event = VEventToEvent( curvo ); 156 Event *event = VEventToEvent( curvo );
156 calendar->addEvent( event ); 157 calendar->addEvent( event );
157 } else { 158 } else {
158 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl; 159 kdDebug(5800) << "VCalFormat::fromString(): Unknown object type." << endl;
159 deleteVObject( vcal ); 160 deleteVObject( vcal );
160 return false; 161 return false;
161 } 162 }
162 163
163 deleteVObject( vcal ); 164 deleteVObject( vcal );
164 165
165 return true; 166 return true;
166} 167}
167 168
168QString VCalFormat::eventToString( Event * event) 169QString VCalFormat::eventToString( Event * event, Calendar *calendar)
169{ 170{
170 if ( !event ) return QString::null; 171 if ( !event ) return QString::null;
172 mCalendar = calendar;
171 VObject *vevent = eventToVEvent( event ); 173 VObject *vevent = eventToVEvent( event );
172 char *buf = writeMemVObject( 0, 0, vevent ); 174 char *buf = writeMemVObject( 0, 0, vevent );
173 QString result( buf ); 175 QString result( buf );
174 cleanVObject( vevent ); 176 cleanVObject( vevent );
175 return result; 177 return result;
176} 178}
177QString VCalFormat::todoToString( Todo * todo ) 179QString VCalFormat::todoToString( Todo * todo, Calendar *calendar )
178{ 180{
179 if ( !todo ) return QString::null; 181 if ( !todo ) return QString::null;
182 mCalendar = calendar;
180 VObject *vevent = eventToVTodo( todo ); 183 VObject *vevent = eventToVTodo( todo );
181 char *buf = writeMemVObject( 0, 0, vevent ); 184 char *buf = writeMemVObject( 0, 0, vevent );
182 QString result( buf ); 185 QString result( buf );
183 cleanVObject( vevent ); 186 cleanVObject( vevent );
184 return result; 187 return result;
185} 188}
186 189
187QString VCalFormat::toString( Calendar *calendar ) 190QString VCalFormat::toString( Calendar *calendar )
188{ 191{
189 // TODO: Factor out VCalFormat::asString() 192 // TODO: Factor out VCalFormat::asString()
190 193
191 VObject *vcal = newVObject(VCCalProp); 194 VObject *vcal = newVObject(VCCalProp);
192 195
193 addPropValue( vcal, VCProdIdProp, CalFormat::productId() ); 196 addPropValue( vcal, VCProdIdProp, CalFormat::productId() );
194 QString tmpStr = mCalendar->getTimeZoneStr(); 197 QString tmpStr = mCalendar->getTimeZoneStr();
195 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() ); 198 addPropValue( vcal, VCTimeZoneProp, tmpStr.local8Bit() );
196 addPropValue( vcal, VCVersionProp, _VCAL_VERSION ); 199 addPropValue( vcal, VCVersionProp, _VCAL_VERSION );
197 200
198 // TODO: Use all data. 201 // TODO: Use all data.
199 QPtrList<Event> events = calendar->events(); 202 QPtrList<Event> events = calendar->events();
200 Event *event = events.first(); 203 Event *event = events.first();
201 if ( !event ) return QString::null; 204 if ( !event ) return QString::null;
202 205
203 VObject *vevent = eventToVEvent( event ); 206 VObject *vevent = eventToVEvent( event );
204 207
205 addVObjectProp( vcal, vevent ); 208 addVObjectProp( vcal, vevent );
206 209
207 char *buf = writeMemVObject( 0, 0, vcal ); 210 char *buf = writeMemVObject( 0, 0, vcal );
208 211
209 QString result( buf ); 212 QString result( buf );
210 213
211 cleanVObject( vcal ); 214 cleanVObject( vcal );
212 215
213 return result; 216 return result;
214} 217}
215 218
216VObject *VCalFormat::eventToVTodo(const Todo *anEvent) 219VObject *VCalFormat::eventToVTodo(const Todo *anEvent)
217{ 220{
218 VObject *vtodo; 221 VObject *vtodo;
219 QString tmpStr; 222 QString tmpStr;
220 QStringList tmpStrList; 223 QStringList tmpStrList;
221 224
222 vtodo = newVObject(VCTodoProp); 225 vtodo = newVObject(VCTodoProp);
223 226
224 // due date 227 // due date
225 if (anEvent->hasDueDate()) { 228 if (anEvent->hasDueDate()) {
226 tmpStr = qDateTimeToISO(anEvent->dtDue(), 229 tmpStr = qDateTimeToISO(anEvent->dtDue(),
227 !anEvent->doesFloat()); 230 !anEvent->doesFloat());
228 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit()); 231 addPropValue(vtodo, VCDueProp, tmpStr.local8Bit());
229 } 232 }
230 233
231 // start date 234 // start date
232 if (anEvent->hasStartDate()) { 235 if (anEvent->hasStartDate()) {
233 tmpStr = qDateTimeToISO(anEvent->dtStart(), 236 tmpStr = qDateTimeToISO(anEvent->dtStart(),
234 !anEvent->doesFloat()); 237 !anEvent->doesFloat());
235 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit()); 238 addPropValue(vtodo, VCDTstartProp, tmpStr.local8Bit());
236 } 239 }
237 240
238 // creation date 241 // creation date
239 tmpStr = qDateTimeToISO(anEvent->created()); 242 tmpStr = qDateTimeToISO(anEvent->created());
240 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit()); 243 addPropValue(vtodo, VCDCreatedProp, tmpStr.local8Bit());
241 244
242 // unique id 245 // unique id
243 addPropValue(vtodo, VCUniqueStringProp, 246 addPropValue(vtodo, VCUniqueStringProp,
244 anEvent->uid().local8Bit()); 247 anEvent->uid().local8Bit());
245 248
246 // revision 249 // revision
247 tmpStr.sprintf("%i", anEvent->revision()); 250 tmpStr.sprintf("%i", anEvent->revision());
248 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit()); 251 addPropValue(vtodo, VCSequenceProp, tmpStr.local8Bit());
249 252
250 // last modification date 253 // last modification date
251 tmpStr = qDateTimeToISO(anEvent->lastModified()); 254 tmpStr = qDateTimeToISO(anEvent->lastModified());
252 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit()); 255 addPropValue(vtodo, VCLastModifiedProp, tmpStr.local8Bit());
253 256
254 // organizer stuff 257 // organizer stuff
255 tmpStr = "MAILTO:" + anEvent->organizer(); 258 tmpStr = "MAILTO:" + anEvent->organizer();
256 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit()); 259 addPropValue(vtodo, ICOrganizerProp, tmpStr.local8Bit());
257 260
258 // attendees 261 // attendees
259 if (anEvent->attendeeCount() != 0) { 262 if (anEvent->attendeeCount() != 0) {
260 QPtrList<Attendee> al = anEvent->attendees(); 263 QPtrList<Attendee> al = anEvent->attendees();
261 QPtrListIterator<Attendee> ai(al); 264 QPtrListIterator<Attendee> ai(al);
262 Attendee *curAttendee; 265 Attendee *curAttendee;
263 266
264 for (; ai.current(); ++ai) { 267 for (; ai.current(); ++ai) {
265 curAttendee = ai.current(); 268 curAttendee = ai.current();
266 if (!curAttendee->email().isEmpty() && 269 if (!curAttendee->email().isEmpty() &&
267 !curAttendee->name().isEmpty()) 270 !curAttendee->name().isEmpty())
268 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 271 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
269 curAttendee->email() + ">"; 272 curAttendee->email() + ">";
270 else if (curAttendee->name().isEmpty()) 273 else if (curAttendee->name().isEmpty())
271 tmpStr = "MAILTO: " + curAttendee->email(); 274 tmpStr = "MAILTO: " + curAttendee->email();
272 else if (curAttendee->email().isEmpty()) 275 else if (curAttendee->email().isEmpty())
273 tmpStr = "MAILTO: " + curAttendee->name(); 276 tmpStr = "MAILTO: " + curAttendee->name();
274 else if (curAttendee->name().isEmpty() && 277 else if (curAttendee->name().isEmpty() &&
275 curAttendee->email().isEmpty()) 278 curAttendee->email().isEmpty())
276 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 279 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
277 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit()); 280 VObject *aProp = addPropValue(vtodo, VCAttendeeProp, tmpStr.local8Bit());
278 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE"); 281 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");
279 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 282 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
280 } 283 }
281 } 284 }
282 285
283 // description BL: 286 // description BL:
284 if (!anEvent->description().isEmpty()) { 287 if (!anEvent->description().isEmpty()) {
285 VObject *d = addPropValue(vtodo, VCDescriptionProp, 288 VObject *d = addPropValue(vtodo, VCDescriptionProp,
286 anEvent->description().local8Bit()); 289 anEvent->description().local8Bit());
287 if (anEvent->description().find('\n') != -1) 290 if (anEvent->description().find('\n') != -1)
288 addProp(d, VCQuotedPrintableProp); 291 addProp(d, VCQuotedPrintableProp);
289 } 292 }
290 293
291 // summary 294 // summary
292 if (!anEvent->summary().isEmpty()) 295 if (!anEvent->summary().isEmpty())
293 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit()); 296 addPropValue(vtodo, VCSummaryProp, anEvent->summary().local8Bit());
294 297
295 if (!anEvent->location().isEmpty()) 298 if (!anEvent->location().isEmpty())
296 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit()); 299 addPropValue(vtodo, VCLocationProp, anEvent->location().local8Bit());
297 300
298 // completed 301 // completed
299 // status 302 // status
300 // backward compatibility, KOrganizer used to interpret only these two values 303 // backward compatibility, KOrganizer used to interpret only these two values
301 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" : 304 addPropValue(vtodo, VCStatusProp, anEvent->isCompleted() ? "COMPLETED" :
302 "NEEDS_ACTION"); 305 "NEEDS_ACTION");
303 // completion date 306 // completion date
304 if (anEvent->hasCompletedDate()) { 307 if (anEvent->hasCompletedDate()) {
305 tmpStr = qDateTimeToISO(anEvent->completed()); 308 tmpStr = qDateTimeToISO(anEvent->completed());
306 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit()); 309 addPropValue(vtodo, VCCompletedProp, tmpStr.local8Bit());
307 } 310 }
308 311
309 // priority 312 // priority
310 tmpStr.sprintf("%i",anEvent->priority()); 313 tmpStr.sprintf("%i",anEvent->priority());
311 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit()); 314 addPropValue(vtodo, VCPriorityProp, tmpStr.local8Bit());
312 315
313 // related event 316 // related event
314 if (anEvent->relatedTo()) { 317 if (anEvent->relatedTo()) {
315 addPropValue(vtodo, VCRelatedToProp, 318 addPropValue(vtodo, VCRelatedToProp,
316 anEvent->relatedTo()->uid().local8Bit()); 319 anEvent->relatedTo()->uid().local8Bit());
317 } 320 }
318 321
319 // categories 322 // categories
320 tmpStrList = anEvent->categories(); 323 tmpStrList = anEvent->categories();
321 tmpStr = ""; 324 tmpStr = "";
322 QString catStr; 325 QString catStr;
323 for ( QStringList::Iterator it = tmpStrList.begin(); 326 for ( QStringList::Iterator it = tmpStrList.begin();
324 it != tmpStrList.end(); 327 it != tmpStrList.end();
325 ++it ) { 328 ++it ) {
326 catStr = *it; 329 catStr = *it;
327 if (catStr[0] == ' ') 330 if (catStr[0] == ' ')
328 tmpStr += catStr.mid(1); 331 tmpStr += catStr.mid(1);
329 else 332 else
330 tmpStr += catStr; 333 tmpStr += catStr;
331 // this must be a ';' character as the vCalendar specification requires! 334 // this must be a ';' character as the vCalendar specification requires!
332 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 335 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
333 // read in. 336 // read in.
334 tmpStr += ";"; 337 tmpStr += ";";
335 } 338 }
336 if (!tmpStr.isEmpty()) { 339 if (!tmpStr.isEmpty()) {
337 tmpStr.truncate(tmpStr.length()-1); 340 tmpStr.truncate(tmpStr.length()-1);
338 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit()); 341 addPropValue(vtodo, VCCategoriesProp, tmpStr.local8Bit());
339 } 342 }
340 343
341 // alarm stuff 344 // alarm stuff
342 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl; 345 kdDebug(5800) << "vcalformat::eventToVTodo was called" << endl;
343 QPtrList<Alarm> alarms = anEvent->alarms(); 346 QPtrList<Alarm> alarms = anEvent->alarms();
344 Alarm* alarm; 347 Alarm* alarm;
345 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 348 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
346 if (alarm->enabled()) { 349 if (alarm->enabled()) {
347 VObject *a = addProp(vtodo, VCDAlarmProp); 350 VObject *a = addProp(vtodo, VCDAlarmProp);
348 tmpStr = qDateTimeToISO(alarm->time()); 351 tmpStr = qDateTimeToISO(alarm->time());
349 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 352 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
350 addPropValue(a, VCRepeatCountProp, "1"); 353 addPropValue(a, VCRepeatCountProp, "1");
351 addPropValue(a, VCDisplayStringProp, "beep!"); 354 addPropValue(a, VCDisplayStringProp, "beep!");
352 if (alarm->type() == Alarm::Audio) { 355 if (alarm->type() == Alarm::Audio) {
353 a = addProp(vtodo, VCAAlarmProp); 356 a = addProp(vtodo, VCAAlarmProp);
354 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 357 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
355 addPropValue(a, VCRepeatCountProp, "1"); 358 addPropValue(a, VCRepeatCountProp, "1");
356 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 359 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
357 } 360 }
358 else if (alarm->type() == Alarm::Procedure) { 361 else if (alarm->type() == Alarm::Procedure) {
359 a = addProp(vtodo, VCPAlarmProp); 362 a = addProp(vtodo, VCPAlarmProp);
360 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 363 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
361 addPropValue(a, VCRepeatCountProp, "1"); 364 addPropValue(a, VCRepeatCountProp, "1");
362 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 365 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
363 } 366 }
364 } 367 }
365 } 368 }
366 369
367 if (anEvent->pilotId()) { 370 if (anEvent->pilotId()) {
368 // pilot sync stuff 371 // pilot sync stuff
369 tmpStr.sprintf("%i",anEvent->pilotId()); 372 tmpStr.sprintf("%i",anEvent->pilotId());
370 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit()); 373 addPropValue(vtodo, XPilotIdProp, tmpStr.local8Bit());
371 tmpStr.sprintf("%i",anEvent->syncStatus()); 374 tmpStr.sprintf("%i",anEvent->syncStatus());
372 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit()); 375 addPropValue(vtodo, XPilotStatusProp, tmpStr.local8Bit());
373 } 376 }
374 377
375 return vtodo; 378 return vtodo;
376} 379}
377 380
378VObject* VCalFormat::eventToVEvent(const Event *anEvent) 381VObject* VCalFormat::eventToVEvent(const Event *anEvent)
379{ 382{
380 VObject *vevent; 383 VObject *vevent;
381 QString tmpStr; 384 QString tmpStr;
382 QStringList tmpStrList; 385 QStringList tmpStrList;
383 386
384 vevent = newVObject(VCEventProp); 387 vevent = newVObject(VCEventProp);
385 388
386 // start and end time 389 // start and end time
387 tmpStr = qDateTimeToISO(anEvent->dtStart(), 390 tmpStr = qDateTimeToISO(anEvent->dtStart(),
388 !anEvent->doesFloat()); 391 !anEvent->doesFloat());
389 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit()); 392 addPropValue(vevent, VCDTstartProp, tmpStr.local8Bit());
390 393
391 // events that have time associated but take up no time should 394 // events that have time associated but take up no time should
392 // not have both DTSTART and DTEND. 395 // not have both DTSTART and DTEND.
393 if (anEvent->dtStart() != anEvent->dtEnd()) { 396 if (anEvent->dtStart() != anEvent->dtEnd()) {
394 tmpStr = qDateTimeToISO(anEvent->dtEnd(), 397 tmpStr = qDateTimeToISO(anEvent->dtEnd(),
395 !anEvent->doesFloat()); 398 !anEvent->doesFloat());
396 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit()); 399 addPropValue(vevent, VCDTendProp, tmpStr.local8Bit());
397 } 400 }
398 401
399 // creation date 402 // creation date
400 tmpStr = qDateTimeToISO(anEvent->created()); 403 tmpStr = qDateTimeToISO(anEvent->created());
401 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit()); 404 addPropValue(vevent, VCDCreatedProp, tmpStr.local8Bit());
402 405
403 // unique id 406 // unique id
404 addPropValue(vevent, VCUniqueStringProp, 407 addPropValue(vevent, VCUniqueStringProp,
405 anEvent->uid().local8Bit()); 408 anEvent->uid().local8Bit());
406 409
407 // revision 410 // revision
408 tmpStr.sprintf("%i", anEvent->revision()); 411 tmpStr.sprintf("%i", anEvent->revision());
409 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit()); 412 addPropValue(vevent, VCSequenceProp, tmpStr.local8Bit());
410 413
411 // last modification date 414 // last modification date
412 tmpStr = qDateTimeToISO(anEvent->lastModified()); 415 tmpStr = qDateTimeToISO(anEvent->lastModified());
413 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit()); 416 addPropValue(vevent, VCLastModifiedProp, tmpStr.local8Bit());
414 417
415 // attendee and organizer stuff 418 // attendee and organizer stuff
416 tmpStr = "MAILTO:" + anEvent->organizer(); 419 tmpStr = "MAILTO:" + anEvent->organizer();
417 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit()); 420 addPropValue(vevent, ICOrganizerProp, tmpStr.local8Bit());
418 421
419 if (anEvent->attendeeCount() != 0) { 422 if (anEvent->attendeeCount() != 0) {
420 QPtrList<Attendee> al = anEvent->attendees(); 423 QPtrList<Attendee> al = anEvent->attendees();
421 QPtrListIterator<Attendee> ai(al); 424 QPtrListIterator<Attendee> ai(al);
422 Attendee *curAttendee; 425 Attendee *curAttendee;
423 426
424 // TODO: Put this functionality into Attendee class 427 // TODO: Put this functionality into Attendee class
425 for (; ai.current(); ++ai) { 428 for (; ai.current(); ++ai) {
426 curAttendee = ai.current(); 429 curAttendee = ai.current();
427 if (!curAttendee->email().isEmpty() && 430 if (!curAttendee->email().isEmpty() &&
428 !curAttendee->name().isEmpty()) 431 !curAttendee->name().isEmpty())
429 tmpStr = "MAILTO:" + curAttendee->name() + " <" + 432 tmpStr = "MAILTO:" + curAttendee->name() + " <" +
430 curAttendee->email() + ">"; 433 curAttendee->email() + ">";
431 else if (curAttendee->name().isEmpty()) 434 else if (curAttendee->name().isEmpty())
432 tmpStr = "MAILTO: " + curAttendee->email(); 435 tmpStr = "MAILTO: " + curAttendee->email();
433 else if (curAttendee->email().isEmpty()) 436 else if (curAttendee->email().isEmpty())
434 tmpStr = "MAILTO: " + curAttendee->name(); 437 tmpStr = "MAILTO: " + curAttendee->name();
435 else if (curAttendee->name().isEmpty() && 438 else if (curAttendee->name().isEmpty() &&
436 curAttendee->email().isEmpty()) 439 curAttendee->email().isEmpty())
437 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl; 440 kdDebug(5800) << "warning! this Event has an attendee w/o name or email!" << endl;
438 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit()); 441 VObject *aProp = addPropValue(vevent, VCAttendeeProp, tmpStr.local8Bit());
439 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");; 442 addPropValue(aProp, VCRSVPProp, curAttendee->RSVP() ? "TRUE" : "FALSE");;
440 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status())); 443 addPropValue(aProp, VCStatusProp, writeStatus(curAttendee->status()));
441 } 444 }
442 } 445 }
443 446
444 // recurrence rule stuff 447 // recurrence rule stuff
445 if (anEvent->recurrence()->doesRecur()) { 448 if (anEvent->recurrence()->doesRecur()) {
446 // some more variables 449 // some more variables
447 QPtrList<Recurrence::rMonthPos> tmpPositions; 450 QPtrList<Recurrence::rMonthPos> tmpPositions;
448 QPtrList<int> tmpDays; 451 QPtrList<int> tmpDays;
449 int *tmpDay; 452 int *tmpDay;
450 Recurrence::rMonthPos *tmpPos; 453 Recurrence::rMonthPos *tmpPos;
451 QString tmpStr2; 454 QString tmpStr2;
452 int i; 455 int i;
453 456
454 switch(anEvent->recurrence()->doesRecur()) { 457 switch(anEvent->recurrence()->doesRecur()) {
455 case Recurrence::rDaily: 458 case Recurrence::rDaily:
456 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency()); 459 tmpStr.sprintf("D%i ",anEvent->recurrence()->frequency());
457// if (anEvent->rDuration > 0) 460// if (anEvent->rDuration > 0)
458 //tmpStr += "#"; 461 //tmpStr += "#";
459 break; 462 break;
460 case Recurrence::rWeekly: 463 case Recurrence::rWeekly:
461 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency()); 464 tmpStr.sprintf("W%i ",anEvent->recurrence()->frequency());
462 for (i = 0; i < 7; i++) { 465 for (i = 0; i < 7; i++) {
463 if (anEvent->recurrence()->days().testBit(i)) 466 if (anEvent->recurrence()->days().testBit(i))
464 tmpStr += dayFromNum(i); 467 tmpStr += dayFromNum(i);
465 } 468 }
466 break; 469 break;
467 case Recurrence::rMonthlyPos: 470 case Recurrence::rMonthlyPos:
468 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency()); 471 tmpStr.sprintf("MP%i ", anEvent->recurrence()->frequency());
469 // write out all rMonthPos's 472 // write out all rMonthPos's
470 tmpPositions = anEvent->recurrence()->monthPositions(); 473 tmpPositions = anEvent->recurrence()->monthPositions();
471 for (tmpPos = tmpPositions.first(); 474 for (tmpPos = tmpPositions.first();
472 tmpPos; 475 tmpPos;
473 tmpPos = tmpPositions.next()) { 476 tmpPos = tmpPositions.next()) {
474 477
475 tmpStr2.sprintf("%i", tmpPos->rPos); 478 tmpStr2.sprintf("%i", tmpPos->rPos);
476 if (tmpPos->negative) 479 if (tmpPos->negative)
477 tmpStr2 += "- "; 480 tmpStr2 += "- ";
478 else 481 else
479 tmpStr2 += "+ "; 482 tmpStr2 += "+ ";
480 tmpStr += tmpStr2; 483 tmpStr += tmpStr2;
481 for (i = 0; i < 7; i++) { 484 for (i = 0; i < 7; i++) {
482 if (tmpPos->rDays.testBit(i)) 485 if (tmpPos->rDays.testBit(i))
483 tmpStr += dayFromNum(i); 486 tmpStr += dayFromNum(i);
484 } 487 }
485 } // loop for all rMonthPos's 488 } // loop for all rMonthPos's
486 break; 489 break;
487 case Recurrence::rMonthlyDay: 490 case Recurrence::rMonthlyDay:
488 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency()); 491 tmpStr.sprintf("MD%i ", anEvent->recurrence()->frequency());
489 // write out all rMonthDays; 492 // write out all rMonthDays;
490 tmpDays = anEvent->recurrence()->monthDays(); 493 tmpDays = anEvent->recurrence()->monthDays();
491 for (tmpDay = tmpDays.first(); 494 for (tmpDay = tmpDays.first();
492 tmpDay; 495 tmpDay;
493 tmpDay = tmpDays.next()) { 496 tmpDay = tmpDays.next()) {
494 tmpStr2.sprintf("%i ", *tmpDay); 497 tmpStr2.sprintf("%i ", *tmpDay);
495 tmpStr += tmpStr2; 498 tmpStr += tmpStr2;
496 } 499 }
497 break; 500 break;
498 case Recurrence::rYearlyMonth: 501 case Recurrence::rYearlyMonth:
499 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency()); 502 tmpStr.sprintf("YM%i ", anEvent->recurrence()->frequency());
500 // write out all the rYearNums; 503 // write out all the rYearNums;
501 tmpDays = anEvent->recurrence()->yearNums(); 504 tmpDays = anEvent->recurrence()->yearNums();
502 for (tmpDay = tmpDays.first(); 505 for (tmpDay = tmpDays.first();
503 tmpDay; 506 tmpDay;
504 tmpDay = tmpDays.next()) { 507 tmpDay = tmpDays.next()) {
505 tmpStr2.sprintf("%i ", *tmpDay); 508 tmpStr2.sprintf("%i ", *tmpDay);
506 tmpStr += tmpStr2; 509 tmpStr += tmpStr2;
507 } 510 }
508 break; 511 break;
509 case Recurrence::rYearlyDay: 512 case Recurrence::rYearlyDay:
510 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency()); 513 tmpStr.sprintf("YD%i ", anEvent->recurrence()->frequency());
511 // write out all the rYearNums; 514 // write out all the rYearNums;
512 tmpDays = anEvent->recurrence()->yearNums(); 515 tmpDays = anEvent->recurrence()->yearNums();
513 for (tmpDay = tmpDays.first(); 516 for (tmpDay = tmpDays.first();
514 tmpDay; 517 tmpDay;
515 tmpDay = tmpDays.next()) { 518 tmpDay = tmpDays.next()) {
516 tmpStr2.sprintf("%i ", *tmpDay); 519 tmpStr2.sprintf("%i ", *tmpDay);
517 tmpStr += tmpStr2; 520 tmpStr += tmpStr2;
518 } 521 }
519 break; 522 break;
520 default: 523 default:
521 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl; 524 kdDebug(5800) << "ERROR, it should never get here in eventToVEvent!" << endl;
522 break; 525 break;
523 } // switch 526 } // switch
524 527
525 if (anEvent->recurrence()->duration() > 0) { 528 if (anEvent->recurrence()->duration() > 0) {
526 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration()); 529 tmpStr2.sprintf("#%i",anEvent->recurrence()->duration());
527 tmpStr += tmpStr2; 530 tmpStr += tmpStr2;
528 } else if (anEvent->recurrence()->duration() == -1) { 531 } else if (anEvent->recurrence()->duration() == -1) {
529 tmpStr += "#0"; // defined as repeat forever 532 tmpStr += "#0"; // defined as repeat forever
530 } else { 533 } else {
531 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE); 534 tmpStr += qDateTimeToISO(anEvent->recurrence()->endDate(), FALSE);
532 } 535 }
533 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit()); 536 addPropValue(vevent,VCRRuleProp, tmpStr.local8Bit());
534 537
535 } // event repeats 538 } // event repeats
536 539
537 // exceptions to recurrence 540 // exceptions to recurrence
538 DateList dateList = anEvent->exDates(); 541 DateList dateList = anEvent->exDates();
539 DateList::ConstIterator it; 542 DateList::ConstIterator it;
540 QString tmpStr2; 543 QString tmpStr2;
541 544
542 for (it = dateList.begin(); it != dateList.end(); ++it) { 545 for (it = dateList.begin(); it != dateList.end(); ++it) {
543 tmpStr = qDateToISO(*it) + ";"; 546 tmpStr = qDateToISO(*it) + ";";
544 tmpStr2 += tmpStr; 547 tmpStr2 += tmpStr;
545 } 548 }
546 if (!tmpStr2.isEmpty()) { 549 if (!tmpStr2.isEmpty()) {
547 tmpStr2.truncate(tmpStr2.length()-1); 550 tmpStr2.truncate(tmpStr2.length()-1);
548 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit()); 551 addPropValue(vevent, VCExpDateProp, tmpStr2.local8Bit());
549 } 552 }
550 553
551 // description 554 // description
552 if (!anEvent->description().isEmpty()) { 555 if (!anEvent->description().isEmpty()) {
553 VObject *d = addPropValue(vevent, VCDescriptionProp, 556 VObject *d = addPropValue(vevent, VCDescriptionProp,
554 anEvent->description().local8Bit()); 557 anEvent->description().local8Bit());
555 if (anEvent->description().find('\n') != -1) 558 if (anEvent->description().find('\n') != -1)
556 addProp(d, VCQuotedPrintableProp); 559 addProp(d, VCQuotedPrintableProp);
557 } 560 }
558 561
559 // summary 562 // summary
560 if (!anEvent->summary().isEmpty()) 563 if (!anEvent->summary().isEmpty())
561 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit()); 564 addPropValue(vevent, VCSummaryProp, anEvent->summary().local8Bit());
562 565
563 if (!anEvent->location().isEmpty()) 566 if (!anEvent->location().isEmpty())
564 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit()); 567 addPropValue(vevent, VCLocationProp, anEvent->location().local8Bit());
565 568
566 // status 569 // status
567// TODO: define Event status 570// TODO: define Event status
568// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit()); 571// addPropValue(vevent, VCStatusProp, anEvent->statusStr().local8Bit());
569 572
570 // secrecy 573 // secrecy
571 const char *text = 0; 574 const char *text = 0;
572 switch (anEvent->secrecy()) { 575 switch (anEvent->secrecy()) {
573 case Incidence::SecrecyPublic: 576 case Incidence::SecrecyPublic:
574 text = "PUBLIC"; 577 text = "PUBLIC";
575 break; 578 break;
576 case Incidence::SecrecyPrivate: 579 case Incidence::SecrecyPrivate:
577 text = "PRIVATE"; 580 text = "PRIVATE";
578 break; 581 break;
579 case Incidence::SecrecyConfidential: 582 case Incidence::SecrecyConfidential:
580 text = "CONFIDENTIAL"; 583 text = "CONFIDENTIAL";
581 break; 584 break;
582 } 585 }
583 if (text) { 586 if (text) {
584 addPropValue(vevent, VCClassProp, text); 587 addPropValue(vevent, VCClassProp, text);
585 } 588 }
586 589
587 // categories 590 // categories
588 tmpStrList = anEvent->categories(); 591 tmpStrList = anEvent->categories();
589 tmpStr = ""; 592 tmpStr = "";
590 QString catStr; 593 QString catStr;
591 for ( QStringList::Iterator it = tmpStrList.begin(); 594 for ( QStringList::Iterator it = tmpStrList.begin();
592 it != tmpStrList.end(); 595 it != tmpStrList.end();
593 ++it ) { 596 ++it ) {
594 catStr = *it; 597 catStr = *it;
595 if (catStr[0] == ' ') 598 if (catStr[0] == ' ')
596 tmpStr += catStr.mid(1); 599 tmpStr += catStr.mid(1);
597 else 600 else
598 tmpStr += catStr; 601 tmpStr += catStr;
599 // this must be a ';' character as the vCalendar specification requires! 602 // this must be a ';' character as the vCalendar specification requires!
600 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is 603 // vcc.y has been hacked to translate the ';' to a ',' when the vcal is
601 // read in. 604 // read in.
602 tmpStr += ";"; 605 tmpStr += ";";
603 } 606 }
604 if (!tmpStr.isEmpty()) { 607 if (!tmpStr.isEmpty()) {
605 tmpStr.truncate(tmpStr.length()-1); 608 tmpStr.truncate(tmpStr.length()-1);
606 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit()); 609 addPropValue(vevent, VCCategoriesProp, tmpStr.local8Bit());
607 } 610 }
608 611
609 // attachments 612 // attachments
610 // TODO: handle binary attachments! 613 // TODO: handle binary attachments!
611 QPtrList<Attachment> attachments = anEvent->attachments(); 614 QPtrList<Attachment> attachments = anEvent->attachments();
612 for ( Attachment *at = attachments.first(); at; at = attachments.next() ) 615 for ( Attachment *at = attachments.first(); at; at = attachments.next() )
613 addPropValue(vevent, VCAttachProp, at->uri().local8Bit()); 616 addPropValue(vevent, VCAttachProp, at->uri().local8Bit());
614 617
615 // resources 618 // resources
616 tmpStrList = anEvent->resources(); 619 tmpStrList = anEvent->resources();
617 tmpStr = tmpStrList.join(";"); 620 tmpStr = tmpStrList.join(";");
618 if (!tmpStr.isEmpty()) 621 if (!tmpStr.isEmpty())
619 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit()); 622 addPropValue(vevent, VCResourcesProp, tmpStr.local8Bit());
620 623
621 // alarm stuff 624 // alarm stuff
622 QPtrList<Alarm> alarms = anEvent->alarms(); 625 QPtrList<Alarm> alarms = anEvent->alarms();
623 Alarm* alarm; 626 Alarm* alarm;
624 for (alarm = alarms.first(); alarm; alarm = alarms.next()) { 627 for (alarm = alarms.first(); alarm; alarm = alarms.next()) {
625 if (alarm->enabled()) { 628 if (alarm->enabled()) {
626 VObject *a = addProp(vevent, VCDAlarmProp); 629 VObject *a = addProp(vevent, VCDAlarmProp);
627 tmpStr = qDateTimeToISO(alarm->time()); 630 tmpStr = qDateTimeToISO(alarm->time());
628 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 631 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
629 addPropValue(a, VCRepeatCountProp, "1"); 632 addPropValue(a, VCRepeatCountProp, "1");
630 addPropValue(a, VCDisplayStringProp, "beep!"); 633 addPropValue(a, VCDisplayStringProp, "beep!");
631 if (alarm->type() == Alarm::Audio) { 634 if (alarm->type() == Alarm::Audio) {
632 a = addProp(vevent, VCAAlarmProp); 635 a = addProp(vevent, VCAAlarmProp);
633 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 636 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
634 addPropValue(a, VCRepeatCountProp, "1"); 637 addPropValue(a, VCRepeatCountProp, "1");
635 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile())); 638 addPropValue(a, VCAudioContentProp, QFile::encodeName(alarm->audioFile()));
636 } 639 }
637 if (alarm->type() == Alarm::Procedure) { 640 if (alarm->type() == Alarm::Procedure) {
638 a = addProp(vevent, VCPAlarmProp); 641 a = addProp(vevent, VCPAlarmProp);
639 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit()); 642 addPropValue(a, VCRunTimeProp, tmpStr.local8Bit());
640 addPropValue(a, VCRepeatCountProp, "1"); 643 addPropValue(a, VCRepeatCountProp, "1");
641 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile())); 644 addPropValue(a, VCProcedureNameProp, QFile::encodeName(alarm->programFile()));
642 } 645 }
643 } 646 }
644 } 647 }
645 648
646 // priority 649 // priority
647 tmpStr.sprintf("%i",anEvent->priority()); 650 tmpStr.sprintf("%i",anEvent->priority());
648 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit()); 651 addPropValue(vevent, VCPriorityProp, tmpStr.local8Bit());
649 652
650 // transparency 653 // transparency
651 tmpStr.sprintf("%i",anEvent->transparency()); 654 tmpStr.sprintf("%i",anEvent->transparency());
652 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit()); 655 addPropValue(vevent, VCTranspProp, tmpStr.local8Bit());
653 656
654 // related event 657 // related event
655 if (anEvent->relatedTo()) { 658 if (anEvent->relatedTo()) {
656 addPropValue(vevent, VCRelatedToProp, 659 addPropValue(vevent, VCRelatedToProp,
657 anEvent->relatedTo()->uid().local8Bit()); 660 anEvent->relatedTo()->uid().local8Bit());
658 } 661 }
659 662
660 if (anEvent->pilotId()) { 663 if (anEvent->pilotId()) {
661 // pilot sync stuff 664 // pilot sync stuff
662 tmpStr.sprintf("%i",anEvent->pilotId()); 665 tmpStr.sprintf("%i",anEvent->pilotId());
663 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit()); 666 addPropValue(vevent, XPilotIdProp, tmpStr.local8Bit());
664 tmpStr.sprintf("%i",anEvent->syncStatus()); 667 tmpStr.sprintf("%i",anEvent->syncStatus());
665 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit()); 668 addPropValue(vevent, XPilotStatusProp, tmpStr.local8Bit());
666 } 669 }
667 670
668 return vevent; 671 return vevent;
669} 672}
670 673
671Todo *VCalFormat::VTodoToEvent(VObject *vtodo) 674Todo *VCalFormat::VTodoToEvent(VObject *vtodo)
672{ 675{
673 VObject *vo; 676 VObject *vo;
674 VObjectIterator voi; 677 VObjectIterator voi;
675 char *s; 678 char *s;
676 679
677 Todo *anEvent = new Todo; 680 Todo *anEvent = new Todo;
678 681
679 // creation date 682 // creation date
680 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) { 683 if ((vo = isAPropertyOf(vtodo, VCDCreatedProp)) != 0) {
681 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 684 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
682 deleteStr(s); 685 deleteStr(s);
683 } 686 }
684 687
685 // unique id 688 // unique id
686 vo = isAPropertyOf(vtodo, VCUniqueStringProp); 689 vo = isAPropertyOf(vtodo, VCUniqueStringProp);
687 // while the UID property is preferred, it is not required. We'll use the 690 // while the UID property is preferred, it is not required. We'll use the
688 // default Event UID if none is given. 691 // default Event UID if none is given.
689 if (vo) { 692 if (vo) {
690 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 693 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
691 deleteStr(s); 694 deleteStr(s);
692 } 695 }
693 696
694 // last modification date 697 // last modification date
695 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) { 698 if ((vo = isAPropertyOf(vtodo, VCLastModifiedProp)) != 0) {
696 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 699 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
697 deleteStr(s); 700 deleteStr(s);
698 } 701 }
699 else 702 else
700 anEvent->setLastModified(QDateTime(QDate::currentDate(), 703 anEvent->setLastModified(QDateTime(QDate::currentDate(),
701 QTime::currentTime())); 704 QTime::currentTime()));
702 705
703 // organizer 706 // organizer
704 // if our extension property for the event's ORGANIZER exists, add it. 707 // if our extension property for the event's ORGANIZER exists, add it.
705 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) { 708 if ((vo = isAPropertyOf(vtodo, ICOrganizerProp)) != 0) {
706 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 709 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
707 deleteStr(s); 710 deleteStr(s);
708 } else { 711 } else {
709 anEvent->setOrganizer(mCalendar->getEmail()); 712 anEvent->setOrganizer(mCalendar->getEmail());
710 } 713 }
711 714
712 // attendees. 715 // attendees.
713 initPropIterator(&voi, vtodo); 716 initPropIterator(&voi, vtodo);
714 while (moreIteration(&voi)) { 717 while (moreIteration(&voi)) {
715 vo = nextVObject(&voi); 718 vo = nextVObject(&voi);
716 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 719 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
717 Attendee *a; 720 Attendee *a;
718 VObject *vp; 721 VObject *vp;
719 s = fakeCString(vObjectUStringZValue(vo)); 722 s = fakeCString(vObjectUStringZValue(vo));
720 QString tmpStr = QString::fromLocal8Bit(s); 723 QString tmpStr = QString::fromLocal8Bit(s);
721 deleteStr(s); 724 deleteStr(s);
722 tmpStr = tmpStr.simplifyWhiteSpace(); 725 tmpStr = tmpStr.simplifyWhiteSpace();
723 int emailPos1, emailPos2; 726 int emailPos1, emailPos2;
724 if ((emailPos1 = tmpStr.find('<')) > 0) { 727 if ((emailPos1 = tmpStr.find('<')) > 0) {
725 // both email address and name 728 // both email address and name
726 emailPos2 = tmpStr.findRev('>'); 729 emailPos2 = tmpStr.findRev('>');
727 a = new Attendee(tmpStr.left(emailPos1 - 1), 730 a = new Attendee(tmpStr.left(emailPos1 - 1),
728 tmpStr.mid(emailPos1 + 1, 731 tmpStr.mid(emailPos1 + 1,
729 emailPos2 - (emailPos1 + 1))); 732 emailPos2 - (emailPos1 + 1)));
730 } else if (tmpStr.find('@') > 0) { 733 } else if (tmpStr.find('@') > 0) {
731 // just an email address 734 // just an email address
732 a = new Attendee(0, tmpStr); 735 a = new Attendee(0, tmpStr);
733 } else { 736 } else {
734 // just a name 737 // just a name
735 QString email = tmpStr.replace( QRegExp(" "), "." ); 738 QString email = tmpStr.replace( QRegExp(" "), "." );
736 a = new Attendee(tmpStr,email); 739 a = new Attendee(tmpStr,email);
737 } 740 }
738 741
739 // is there an RSVP property? 742 // is there an RSVP property?
740 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 743 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
741 a->setRSVP(vObjectStringZValue(vp)); 744 a->setRSVP(vObjectStringZValue(vp));
742 // is there a status property? 745 // is there a status property?
743 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 746 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
744 a->setStatus(readStatus(vObjectStringZValue(vp))); 747 a->setStatus(readStatus(vObjectStringZValue(vp)));
745 // add the attendee 748 // add the attendee
746 anEvent->addAttendee(a); 749 anEvent->addAttendee(a);
747 } 750 }
748 } 751 }
749 752
750 // description for todo 753 // description for todo
751 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) { 754 if ((vo = isAPropertyOf(vtodo, VCDescriptionProp)) != 0) {
752 s = fakeCString(vObjectUStringZValue(vo)); 755 s = fakeCString(vObjectUStringZValue(vo));
753 anEvent->setDescription(QString::fromLocal8Bit(s)); 756 anEvent->setDescription(QString::fromLocal8Bit(s));
754 deleteStr(s); 757 deleteStr(s);
755 } 758 }
756 759
757 // summary 760 // summary
758 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) { 761 if ((vo = isAPropertyOf(vtodo, VCSummaryProp))) {
759 s = fakeCString(vObjectUStringZValue(vo)); 762 s = fakeCString(vObjectUStringZValue(vo));
760 anEvent->setSummary(QString::fromLocal8Bit(s)); 763 anEvent->setSummary(QString::fromLocal8Bit(s));
761 deleteStr(s); 764 deleteStr(s);
762 } 765 }
763 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) { 766 if ((vo = isAPropertyOf(vtodo, VCLocationProp))) {
764 s = fakeCString(vObjectUStringZValue(vo)); 767 s = fakeCString(vObjectUStringZValue(vo));
765 anEvent->setLocation(QString::fromLocal8Bit(s)); 768 anEvent->setLocation(QString::fromLocal8Bit(s));
766 deleteStr(s); 769 deleteStr(s);
767 } 770 }
768 771
769 772
770 // completed 773 // completed
771 // was: status 774 // was: status
772 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) { 775 if ((vo = isAPropertyOf(vtodo, VCStatusProp)) != 0) {
773 s = fakeCString(vObjectUStringZValue(vo)); 776 s = fakeCString(vObjectUStringZValue(vo));
774 if (strcmp(s,"COMPLETED") == 0) { 777 if (strcmp(s,"COMPLETED") == 0) {
775 anEvent->setCompleted(true); 778 anEvent->setCompleted(true);
776 } else { 779 } else {
777 anEvent->setCompleted(false); 780 anEvent->setCompleted(false);
778 } 781 }
779 deleteStr(s); 782 deleteStr(s);
780 } 783 }
781 else 784 else
782 anEvent->setCompleted(false); 785 anEvent->setCompleted(false);
783 786
784 // completion date 787 // completion date
785 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) { 788 if ((vo = isAPropertyOf(vtodo, VCCompletedProp)) != 0) {
786 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 789 anEvent->setCompleted(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
787 deleteStr(s); 790 deleteStr(s);
788 } 791 }
789 792
790 // priority 793 // priority
791 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) { 794 if ((vo = isAPropertyOf(vtodo, VCPriorityProp))) {
792 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 795 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
793 deleteStr(s); 796 deleteStr(s);
794 } 797 }
795 798
796 // due date 799 // due date
797 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) { 800 if ((vo = isAPropertyOf(vtodo, VCDueProp)) != 0) {
798 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 801 anEvent->setDtDue(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
799 deleteStr(s); 802 deleteStr(s);
800 anEvent->setHasDueDate(true); 803 anEvent->setHasDueDate(true);
801 } else { 804 } else {
802 anEvent->setHasDueDate(false); 805 anEvent->setHasDueDate(false);
803 } 806 }
804 807
805 // start time 808 // start time
806 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) { 809 if ((vo = isAPropertyOf(vtodo, VCDTstartProp)) != 0) {
807 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 810 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
808 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 811 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
809 deleteStr(s); 812 deleteStr(s);
810 anEvent->setHasStartDate(true); 813 anEvent->setHasStartDate(true);
811 } else { 814 } else {
812 anEvent->setHasStartDate(false); 815 anEvent->setHasStartDate(false);
813 } 816 }
814 817
815 /* alarm stuff */ 818 /* alarm stuff */
816 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl; 819 //kdDebug(5800) << "vcalformat::VTodoToEvent called" << endl;
817 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) { 820 if ((vo = isAPropertyOf(vtodo, VCDAlarmProp))) {
818 Alarm* alarm = anEvent->newAlarm(); 821 Alarm* alarm = anEvent->newAlarm();
819 VObject *a; 822 VObject *a;
820 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 823 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
821 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 824 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
822 deleteStr(s); 825 deleteStr(s);
823 } 826 }
824 alarm->setEnabled(true); 827 alarm->setEnabled(true);
825 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) { 828 if ((vo = isAPropertyOf(vtodo, VCPAlarmProp))) {
826 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 829 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
827 s = fakeCString(vObjectUStringZValue(a)); 830 s = fakeCString(vObjectUStringZValue(a));
828 alarm->setProcedureAlarm(QFile::decodeName(s)); 831 alarm->setProcedureAlarm(QFile::decodeName(s));
829 deleteStr(s); 832 deleteStr(s);
830 } 833 }
831 } 834 }
832 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) { 835 if ((vo = isAPropertyOf(vtodo, VCAAlarmProp))) {
833 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 836 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
834 s = fakeCString(vObjectUStringZValue(a)); 837 s = fakeCString(vObjectUStringZValue(a));
835 alarm->setAudioAlarm(QFile::decodeName(s)); 838 alarm->setAudioAlarm(QFile::decodeName(s));
836 deleteStr(s); 839 deleteStr(s);
837 } 840 }
838 } 841 }
839 } 842 }
840 843
841 // related todo 844 // related todo
842 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) { 845 if ((vo = isAPropertyOf(vtodo, VCRelatedToProp)) != 0) {
843 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 846 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
844 deleteStr(s); 847 deleteStr(s);
845 mTodosRelate.append(anEvent); 848 mTodosRelate.append(anEvent);
846 } 849 }
847 850
848 // categories 851 // categories
849 QStringList tmpStrList; 852 QStringList tmpStrList;
850 int index1 = 0; 853 int index1 = 0;
851 int index2 = 0; 854 int index2 = 0;
852 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) { 855 if ((vo = isAPropertyOf(vtodo, VCCategoriesProp)) != 0) {
853 s = fakeCString(vObjectUStringZValue(vo)); 856 s = fakeCString(vObjectUStringZValue(vo));
854 QString categories = QString::fromLocal8Bit(s); 857 QString categories = QString::fromLocal8Bit(s);
855 deleteStr(s); 858 deleteStr(s);
856 //const char* category; 859 //const char* category;
857 QString category; 860 QString category;
858 while ((index2 = categories.find(',', index1)) != -1) { 861 while ((index2 = categories.find(',', index1)) != -1) {
859 //category = (const char *) categories.mid(index1, (index2 - index1)); 862 //category = (const char *) categories.mid(index1, (index2 - index1));
860 category = categories.mid(index1, (index2 - index1)); 863 category = categories.mid(index1, (index2 - index1));
861 tmpStrList.append(category); 864 tmpStrList.append(category);
862 index1 = index2+1; 865 index1 = index2+1;
863 } 866 }
864 // get last category 867 // get last category
865 category = categories.mid(index1, (categories.length()-index1)); 868 category = categories.mid(index1, (categories.length()-index1));
866 tmpStrList.append(category); 869 tmpStrList.append(category);
867 anEvent->setCategories(tmpStrList); 870 anEvent->setCategories(tmpStrList);
868 } 871 }
869 872
870 /* PILOT SYNC STUFF */ 873 /* PILOT SYNC STUFF */
871 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) { 874 if ((vo = isAPropertyOf(vtodo, XPilotIdProp))) {
872 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 875 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
873 deleteStr(s); 876 deleteStr(s);
874 } 877 }
875 else 878 else
876 anEvent->setPilotId(0); 879 anEvent->setPilotId(0);
877 880
878 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) { 881 if ((vo = isAPropertyOf(vtodo, XPilotStatusProp))) {
879 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 882 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
880 deleteStr(s); 883 deleteStr(s);
881 } 884 }
882 else 885 else
883 anEvent->setSyncStatus(Event::SYNCMOD); 886 anEvent->setSyncStatus(Event::SYNCMOD);
884 887
885 return anEvent; 888 return anEvent;
886} 889}
887 890
888Event* VCalFormat::VEventToEvent(VObject *vevent) 891Event* VCalFormat::VEventToEvent(VObject *vevent)
889{ 892{
890 VObject *vo; 893 VObject *vo;
891 VObjectIterator voi; 894 VObjectIterator voi;
892 char *s; 895 char *s;
893 896
894 Event *anEvent = new Event; 897 Event *anEvent = new Event;
895 898
896 // creation date 899 // creation date
897 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) { 900 if ((vo = isAPropertyOf(vevent, VCDCreatedProp)) != 0) {
898 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 901 anEvent->setCreated(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
899 deleteStr(s); 902 deleteStr(s);
900 } 903 }
901 904
902 // unique id 905 // unique id
903 vo = isAPropertyOf(vevent, VCUniqueStringProp); 906 vo = isAPropertyOf(vevent, VCUniqueStringProp);
904 // while the UID property is preferred, it is not required. We'll use the 907 // while the UID property is preferred, it is not required. We'll use the
905 // default Event UID if none is given. 908 // default Event UID if none is given.
906 if (vo) { 909 if (vo) {
907 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo))); 910 anEvent->setUid(s = fakeCString(vObjectUStringZValue(vo)));
908 deleteStr(s); 911 deleteStr(s);
909 } 912 }
910 913
911 // revision 914 // revision
912 // again NSCAL doesn't give us much to work with, so we improvise... 915 // again NSCAL doesn't give us much to work with, so we improvise...
913 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) { 916 if ((vo = isAPropertyOf(vevent, VCSequenceProp)) != 0) {
914 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 917 anEvent->setRevision(atoi(s = fakeCString(vObjectUStringZValue(vo))));
915 deleteStr(s); 918 deleteStr(s);
916 } 919 }
917 else 920 else
918 anEvent->setRevision(0); 921 anEvent->setRevision(0);
919 922
920 // last modification date 923 // last modification date
921 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) { 924 if ((vo = isAPropertyOf(vevent, VCLastModifiedProp)) != 0) {
922 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 925 anEvent->setLastModified(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
923 deleteStr(s); 926 deleteStr(s);
924 } 927 }
925 else 928 else
926 anEvent->setLastModified(QDateTime(QDate::currentDate(), 929 anEvent->setLastModified(QDateTime(QDate::currentDate(),
927 QTime::currentTime())); 930 QTime::currentTime()));
928 931
929 // organizer 932 // organizer
930 // if our extension property for the event's ORGANIZER exists, add it. 933 // if our extension property for the event's ORGANIZER exists, add it.
931 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) { 934 if ((vo = isAPropertyOf(vevent, ICOrganizerProp)) != 0) {
932 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo))); 935 anEvent->setOrganizer(s = fakeCString(vObjectUStringZValue(vo)));
933 deleteStr(s); 936 deleteStr(s);
934 } else { 937 } else {
935 anEvent->setOrganizer(mCalendar->getEmail()); 938 anEvent->setOrganizer(mCalendar->getEmail());
936 } 939 }
937 940
938 // deal with attendees. 941 // deal with attendees.
939 initPropIterator(&voi, vevent); 942 initPropIterator(&voi, vevent);
940 while (moreIteration(&voi)) { 943 while (moreIteration(&voi)) {
941 vo = nextVObject(&voi); 944 vo = nextVObject(&voi);
942 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) { 945 if (strcmp(vObjectName(vo), VCAttendeeProp) == 0) {
943 Attendee *a; 946 Attendee *a;
944 VObject *vp; 947 VObject *vp;
945 s = fakeCString(vObjectUStringZValue(vo)); 948 s = fakeCString(vObjectUStringZValue(vo));
946 QString tmpStr = QString::fromLocal8Bit(s); 949 QString tmpStr = QString::fromLocal8Bit(s);
947 deleteStr(s); 950 deleteStr(s);
948 tmpStr = tmpStr.simplifyWhiteSpace(); 951 tmpStr = tmpStr.simplifyWhiteSpace();
949 int emailPos1, emailPos2; 952 int emailPos1, emailPos2;
950 if ((emailPos1 = tmpStr.find('<')) > 0) { 953 if ((emailPos1 = tmpStr.find('<')) > 0) {
951 // both email address and name 954 // both email address and name
952 emailPos2 = tmpStr.findRev('>'); 955 emailPos2 = tmpStr.findRev('>');
953 a = new Attendee(tmpStr.left(emailPos1 - 1), 956 a = new Attendee(tmpStr.left(emailPos1 - 1),
954 tmpStr.mid(emailPos1 + 1, 957 tmpStr.mid(emailPos1 + 1,
955 emailPos2 - (emailPos1 + 1))); 958 emailPos2 - (emailPos1 + 1)));
956 } else if (tmpStr.find('@') > 0) { 959 } else if (tmpStr.find('@') > 0) {
957 // just an email address 960 // just an email address
958 a = new Attendee(0, tmpStr); 961 a = new Attendee(0, tmpStr);
959 } else { 962 } else {
960 // just a name 963 // just a name
961 QString email = tmpStr.replace( QRegExp(" "), "." ); 964 QString email = tmpStr.replace( QRegExp(" "), "." );
962 a = new Attendee(tmpStr,email); 965 a = new Attendee(tmpStr,email);
963 } 966 }
964 967
965 // is there an RSVP property? 968 // is there an RSVP property?
966 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0) 969 if ((vp = isAPropertyOf(vo, VCRSVPProp)) != 0)
967 a->setRSVP(vObjectStringZValue(vp)); 970 a->setRSVP(vObjectStringZValue(vp));
968 // is there a status property? 971 // is there a status property?
969 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0) 972 if ((vp = isAPropertyOf(vo, VCStatusProp)) != 0)
970 a->setStatus(readStatus(vObjectStringZValue(vp))); 973 a->setStatus(readStatus(vObjectStringZValue(vp)));
971 // add the attendee 974 // add the attendee
972 anEvent->addAttendee(a); 975 anEvent->addAttendee(a);
973 } 976 }
974 } 977 }
975 978
976 // This isn't strictly true. An event that doesn't have a start time 979 // This isn't strictly true. An event that doesn't have a start time
977 // or an end time doesn't "float", it has an anchor in time but it doesn't 980 // or an end time doesn't "float", it has an anchor in time but it doesn't
978 // "take up" any time. 981 // "take up" any time.
979 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) || 982 /*if ((isAPropertyOf(vevent, VCDTstartProp) == 0) ||
980 (isAPropertyOf(vevent, VCDTendProp) == 0)) { 983 (isAPropertyOf(vevent, VCDTendProp) == 0)) {
981 anEvent->setFloats(TRUE); 984 anEvent->setFloats(TRUE);
982 } else { 985 } else {
983 }*/ 986 }*/
984 987
985 anEvent->setFloats(FALSE); 988 anEvent->setFloats(FALSE);
986 989
987 // start time 990 // start time
988 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) { 991 if ((vo = isAPropertyOf(vevent, VCDTstartProp)) != 0) {
989 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 992 anEvent->setDtStart(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
990 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl; 993 // kdDebug(5800) << "s is " << // s << ", ISO is " << ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))).toString() << endl;
991 deleteStr(s); 994 deleteStr(s);
992 if (anEvent->dtStart().time().isNull()) 995 if (anEvent->dtStart().time().isNull())
993 anEvent->setFloats(TRUE); 996 anEvent->setFloats(TRUE);
994 } 997 }
995 998
996 // stop time 999 // stop time
997 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) { 1000 if ((vo = isAPropertyOf(vevent, VCDTendProp)) != 0) {
998 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo)))); 1001 anEvent->setDtEnd(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(vo))));
999 deleteStr(s); 1002 deleteStr(s);
1000 if (anEvent->dtEnd().time().isNull()) 1003 if (anEvent->dtEnd().time().isNull())
1001 anEvent->setFloats(TRUE); 1004 anEvent->setFloats(TRUE);
1002 } 1005 }
1003 1006
1004 // at this point, there should be at least a start or end time. 1007 // at this point, there should be at least a start or end time.
1005 // fix up for events that take up no time but have a time associated 1008 // fix up for events that take up no time but have a time associated
1006 if (!(vo = isAPropertyOf(vevent, VCDTstartProp))) 1009 if (!(vo = isAPropertyOf(vevent, VCDTstartProp)))
1007 anEvent->setDtStart(anEvent->dtEnd()); 1010 anEvent->setDtStart(anEvent->dtEnd());
1008 if (!(vo = isAPropertyOf(vevent, VCDTendProp))) 1011 if (!(vo = isAPropertyOf(vevent, VCDTendProp)))
1009 anEvent->setDtEnd(anEvent->dtStart()); 1012 anEvent->setDtEnd(anEvent->dtStart());
1010 1013
1011 /////////////////////////////////////////////////////////////////////////// 1014 ///////////////////////////////////////////////////////////////////////////
1012 1015
1013 // repeat stuff 1016 // repeat stuff
1014 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) { 1017 if ((vo = isAPropertyOf(vevent, VCRRuleProp)) != 0) {
1015 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo))); 1018 QString tmpStr = (s = fakeCString(vObjectUStringZValue(vo)));
1016 deleteStr(s); 1019 deleteStr(s);
1017 tmpStr.simplifyWhiteSpace(); 1020 tmpStr.simplifyWhiteSpace();
1018 tmpStr = tmpStr.upper(); 1021 tmpStr = tmpStr.upper();
1019 1022
1020 /********************************* DAILY ******************************/ 1023 /********************************* DAILY ******************************/
1021 if (tmpStr.left(1) == "D") { 1024 if (tmpStr.left(1) == "D") {
1022 int index = tmpStr.find(' '); 1025 int index = tmpStr.find(' ');
1023 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1026 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1024 index = tmpStr.findRev(' ') + 1; // advance to last field 1027 index = tmpStr.findRev(' ') + 1; // advance to last field
1025 if (tmpStr.mid(index,1) == "#") index++; 1028 if (tmpStr.mid(index,1) == "#") index++;
1026 if (tmpStr.find('T', index) != -1) { 1029 if (tmpStr.find('T', index) != -1) {
1027 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1030 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1028 anEvent->recurrence()->setDaily(rFreq, rEndDate); 1031 anEvent->recurrence()->setDaily(rFreq, rEndDate);
1029 } else { 1032 } else {
1030 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1033 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1031 if (rDuration == 0) // VEvents set this to 0 forever, we use -1 1034 if (rDuration == 0) // VEvents set this to 0 forever, we use -1
1032 anEvent->recurrence()->setDaily(rFreq, -1); 1035 anEvent->recurrence()->setDaily(rFreq, -1);
1033 else 1036 else
1034 anEvent->recurrence()->setDaily(rFreq, rDuration); 1037 anEvent->recurrence()->setDaily(rFreq, rDuration);
1035 } 1038 }
1036 } 1039 }
1037 /********************************* WEEKLY ******************************/ 1040 /********************************* WEEKLY ******************************/
1038 else if (tmpStr.left(1) == "W") { 1041 else if (tmpStr.left(1) == "W") {
1039 int index = tmpStr.find(' '); 1042 int index = tmpStr.find(' ');
1040 int last = tmpStr.findRev(' ') + 1; 1043 int last = tmpStr.findRev(' ') + 1;
1041 int rFreq = tmpStr.mid(1, (index-1)).toInt(); 1044 int rFreq = tmpStr.mid(1, (index-1)).toInt();
1042 index += 1; // advance to beginning of stuff after freq 1045 index += 1; // advance to beginning of stuff after freq
1043 QBitArray qba(7); 1046 QBitArray qba(7);
1044 QString dayStr; 1047 QString dayStr;
1045 if( index == last ) { 1048 if( index == last ) {
1046 // e.g. W1 #0 1049 // e.g. W1 #0
1047 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1050 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1048 } 1051 }
1049 else { 1052 else {
1050 // e.g. W1 SU #0 1053 // e.g. W1 SU #0
1051 while (index < last) { 1054 while (index < last) {
1052 dayStr = tmpStr.mid(index, 3); 1055 dayStr = tmpStr.mid(index, 3);
1053 int dayNum = numFromDay(dayStr); 1056 int dayNum = numFromDay(dayStr);
1054 qba.setBit(dayNum); 1057 qba.setBit(dayNum);
1055 index += 3; // advance to next day, or possibly "#" 1058 index += 3; // advance to next day, or possibly "#"
1056 } 1059 }
1057 } 1060 }
1058 index = last; if (tmpStr.mid(index,1) == "#") index++; 1061 index = last; if (tmpStr.mid(index,1) == "#") index++;
1059 if (tmpStr.find('T', index) != -1) { 1062 if (tmpStr.find('T', index) != -1) {
1060 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1063 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1061 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate); 1064 anEvent->recurrence()->setWeekly(rFreq, qba, rEndDate);
1062 } else { 1065 } else {
1063 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1066 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1064 if (rDuration == 0) 1067 if (rDuration == 0)
1065 anEvent->recurrence()->setWeekly(rFreq, qba, -1); 1068 anEvent->recurrence()->setWeekly(rFreq, qba, -1);
1066 else 1069 else
1067 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration); 1070 anEvent->recurrence()->setWeekly(rFreq, qba, rDuration);
1068 } 1071 }
1069 } 1072 }
1070 /**************************** MONTHLY-BY-POS ***************************/ 1073 /**************************** MONTHLY-BY-POS ***************************/
1071 else if (tmpStr.left(2) == "MP") { 1074 else if (tmpStr.left(2) == "MP") {
1072 int index = tmpStr.find(' '); 1075 int index = tmpStr.find(' ');
1073 int last = tmpStr.findRev(' ') + 1; 1076 int last = tmpStr.findRev(' ') + 1;
1074 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1077 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1075 index += 1; // advance to beginning of stuff after freq 1078 index += 1; // advance to beginning of stuff after freq
1076 QBitArray qba(7); 1079 QBitArray qba(7);
1077 short tmpPos; 1080 short tmpPos;
1078 if( index == last ) { 1081 if( index == last ) {
1079 // e.g. MP1 #0 1082 // e.g. MP1 #0
1080 tmpPos = anEvent->dtStart().date().day()/7 + 1; 1083 tmpPos = anEvent->dtStart().date().day()/7 + 1;
1081 if( tmpPos == 5 ) 1084 if( tmpPos == 5 )
1082 tmpPos = -1; 1085 tmpPos = -1;
1083 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1086 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1084 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1087 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1085 } 1088 }
1086 else { 1089 else {
1087 // e.g. MP1 1+ SU #0 1090 // e.g. MP1 1+ SU #0
1088 while (index < last) { 1091 while (index < last) {
1089 tmpPos = tmpStr.mid(index,1).toShort(); 1092 tmpPos = tmpStr.mid(index,1).toShort();
1090 index += 1; 1093 index += 1;
1091 if (tmpStr.mid(index,1) == "-") 1094 if (tmpStr.mid(index,1) == "-")
1092 // convert tmpPos to negative 1095 // convert tmpPos to negative
1093 tmpPos = 0 - tmpPos; 1096 tmpPos = 0 - tmpPos;
1094 index += 2; // advance to day(s) 1097 index += 2; // advance to day(s)
1095 while (numFromDay(tmpStr.mid(index,3)) >= 0) { 1098 while (numFromDay(tmpStr.mid(index,3)) >= 0) {
1096 int dayNum = numFromDay(tmpStr.mid(index,3)); 1099 int dayNum = numFromDay(tmpStr.mid(index,3));
1097 qba.setBit(dayNum); 1100 qba.setBit(dayNum);
1098 index += 3; // advance to next day, or possibly pos or "#" 1101 index += 3; // advance to next day, or possibly pos or "#"
1099 } 1102 }
1100 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1103 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1101 qba.detach(); 1104 qba.detach();
1102 qba.fill(FALSE); // clear out 1105 qba.fill(FALSE); // clear out
1103 } // while != "#" 1106 } // while != "#"
1104 } 1107 }
1105 index = last; if (tmpStr.mid(index,1) == "#") index++; 1108 index = last; if (tmpStr.mid(index,1) == "#") index++;
1106 if (tmpStr.find('T', index) != -1) { 1109 if (tmpStr.find('T', index) != -1) {
1107 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - 1110 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() -
1108 index))).date(); 1111 index))).date();
1109 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); 1112 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate);
1110 } else { 1113 } else {
1111 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1114 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1112 if (rDuration == 0) 1115 if (rDuration == 0)
1113 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); 1116 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1);
1114 else 1117 else
1115 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); 1118 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration);
1116 } 1119 }
1117 } 1120 }
1118 1121
1119 /**************************** MONTHLY-BY-DAY ***************************/ 1122 /**************************** MONTHLY-BY-DAY ***************************/
1120 else if (tmpStr.left(2) == "MD") { 1123 else if (tmpStr.left(2) == "MD") {
1121 int index = tmpStr.find(' '); 1124 int index = tmpStr.find(' ');
1122 int last = tmpStr.findRev(' ') + 1; 1125 int last = tmpStr.findRev(' ') + 1;
1123 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1126 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1124 index += 1; 1127 index += 1;
1125 short tmpDay; 1128 short tmpDay;
1126 if( index == last ) { 1129 if( index == last ) {
1127 // e.g. MD1 #0 1130 // e.g. MD1 #0
1128 tmpDay = anEvent->dtStart().date().day(); 1131 tmpDay = anEvent->dtStart().date().day();
1129 anEvent->recurrence()->addMonthlyDay(tmpDay); 1132 anEvent->recurrence()->addMonthlyDay(tmpDay);
1130 } 1133 }
1131 else { 1134 else {
1132 // e.g. MD1 3 #0 1135 // e.g. MD1 3 #0
1133 while (index < last) { 1136 while (index < last) {
1134 int index2 = tmpStr.find(' ', index); 1137 int index2 = tmpStr.find(' ', index);
1135 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1138 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1136 index = index2-1; 1139 index = index2-1;
1137 if (tmpStr.mid(index, 1) == "-") 1140 if (tmpStr.mid(index, 1) == "-")
1138 tmpDay = 0 - tmpDay; 1141 tmpDay = 0 - tmpDay;
1139 index += 2; // advance the index; 1142 index += 2; // advance the index;
1140 anEvent->recurrence()->addMonthlyDay(tmpDay); 1143 anEvent->recurrence()->addMonthlyDay(tmpDay);
1141 } // while != # 1144 } // while != #
1142 } 1145 }
1143 index = last; if (tmpStr.mid(index,1) == "#") index++; 1146 index = last; if (tmpStr.mid(index,1) == "#") index++;
1144 if (tmpStr.find('T', index) != -1) { 1147 if (tmpStr.find('T', index) != -1) {
1145 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1148 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1146 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); 1149 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate);
1147 } else { 1150 } else {
1148 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1151 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1149 if (rDuration == 0) 1152 if (rDuration == 0)
1150 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); 1153 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1);
1151 else 1154 else
1152 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); 1155 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration);
1153 } 1156 }
1154 } 1157 }
1155 1158
1156 /*********************** YEARLY-BY-MONTH *******************************/ 1159 /*********************** YEARLY-BY-MONTH *******************************/
1157 else if (tmpStr.left(2) == "YM") { 1160 else if (tmpStr.left(2) == "YM") {
1158 int index = tmpStr.find(' '); 1161 int index = tmpStr.find(' ');
1159 int last = tmpStr.findRev(' ') + 1; 1162 int last = tmpStr.findRev(' ') + 1;
1160 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1163 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1161 index += 1; 1164 index += 1;
1162 short tmpMonth; 1165 short tmpMonth;
1163 if( index == last ) { 1166 if( index == last ) {
1164 // e.g. YM1 #0 1167 // e.g. YM1 #0
1165 tmpMonth = anEvent->dtStart().date().month(); 1168 tmpMonth = anEvent->dtStart().date().month();
1166 anEvent->recurrence()->addYearlyNum(tmpMonth); 1169 anEvent->recurrence()->addYearlyNum(tmpMonth);
1167 } 1170 }
1168 else { 1171 else {
1169 // e.g. YM1 3 #0 1172 // e.g. YM1 3 #0
1170 while (index < last) { 1173 while (index < last) {
1171 int index2 = tmpStr.find(' ', index); 1174 int index2 = tmpStr.find(' ', index);
1172 tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); 1175 tmpMonth = tmpStr.mid(index, (index2-index)).toShort();
1173 index = index2+1; 1176 index = index2+1;
1174 anEvent->recurrence()->addYearlyNum(tmpMonth); 1177 anEvent->recurrence()->addYearlyNum(tmpMonth);
1175 } // while != # 1178 } // while != #
1176 } 1179 }
1177 index = last; if (tmpStr.mid(index,1) == "#") index++; 1180 index = last; if (tmpStr.mid(index,1) == "#") index++;
1178 if (tmpStr.find('T', index) != -1) { 1181 if (tmpStr.find('T', index) != -1) {
1179 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1182 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1180 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); 1183 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate);
1181 } else { 1184 } else {
1182 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1185 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1183 if (rDuration == 0) 1186 if (rDuration == 0)
1184 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); 1187 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1);
1185 else 1188 else
1186 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); 1189 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration);
1187 } 1190 }
1188 } 1191 }
1189 1192
1190 /*********************** YEARLY-BY-DAY *********************************/ 1193 /*********************** YEARLY-BY-DAY *********************************/
1191 else if (tmpStr.left(2) == "YD") { 1194 else if (tmpStr.left(2) == "YD") {
1192 int index = tmpStr.find(' '); 1195 int index = tmpStr.find(' ');
1193 int last = tmpStr.findRev(' ') + 1; 1196 int last = tmpStr.findRev(' ') + 1;
1194 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1197 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1195 index += 1; 1198 index += 1;
1196 short tmpDay; 1199 short tmpDay;
1197 if( index == last ) { 1200 if( index == last ) {
1198 // e.g. YD1 #0 1201 // e.g. YD1 #0
1199 tmpDay = anEvent->dtStart().date().dayOfYear(); 1202 tmpDay = anEvent->dtStart().date().dayOfYear();
1200 anEvent->recurrence()->addYearlyNum(tmpDay); 1203 anEvent->recurrence()->addYearlyNum(tmpDay);
1201 } 1204 }
1202 else { 1205 else {
1203 // e.g. YD1 123 #0 1206 // e.g. YD1 123 #0
1204 while (index < last) { 1207 while (index < last) {
1205 int index2 = tmpStr.find(' ', index); 1208 int index2 = tmpStr.find(' ', index);
1206 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1209 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1207 index = index2+1; 1210 index = index2+1;
1208 anEvent->recurrence()->addYearlyNum(tmpDay); 1211 anEvent->recurrence()->addYearlyNum(tmpDay);
1209 } // while != # 1212 } // while != #
1210 } 1213 }
1211 index = last; if (tmpStr.mid(index,1) == "#") index++; 1214 index = last; if (tmpStr.mid(index,1) == "#") index++;
1212 if (tmpStr.find('T', index) != -1) { 1215 if (tmpStr.find('T', index) != -1) {
1213 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1216 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1214 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); 1217 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate);
1215 } else { 1218 } else {
1216 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1219 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1217 if (rDuration == 0) 1220 if (rDuration == 0)
1218 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); 1221 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1);
1219 else 1222 else
1220 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); 1223 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration);
1221 } 1224 }
1222 } else { 1225 } else {
1223 kdDebug(5800) << "we don't understand this type of recurrence!" << endl; 1226 kdDebug(5800) << "we don't understand this type of recurrence!" << endl;
1224 } // if 1227 } // if
1225 } // repeats 1228 } // repeats
1226 1229
1227 1230
1228 // recurrence exceptions 1231 // recurrence exceptions
1229 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { 1232 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) {
1230 s = fakeCString(vObjectUStringZValue(vo)); 1233 s = fakeCString(vObjectUStringZValue(vo));
1231 QStringList exDates = QStringList::split(",",s); 1234 QStringList exDates = QStringList::split(",",s);
1232 QStringList::ConstIterator it; 1235 QStringList::ConstIterator it;
1233 for(it = exDates.begin(); it != exDates.end(); ++it ) { 1236 for(it = exDates.begin(); it != exDates.end(); ++it ) {
1234 anEvent->addExDate(ISOToQDate(*it)); 1237 anEvent->addExDate(ISOToQDate(*it));
1235 } 1238 }
1236 deleteStr(s); 1239 deleteStr(s);
1237 } 1240 }
1238 1241
1239 // summary 1242 // summary
1240 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { 1243 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) {
1241 s = fakeCString(vObjectUStringZValue(vo)); 1244 s = fakeCString(vObjectUStringZValue(vo));
1242 anEvent->setSummary(QString::fromLocal8Bit(s)); 1245 anEvent->setSummary(QString::fromLocal8Bit(s));
1243 deleteStr(s); 1246 deleteStr(s);
1244 } 1247 }
1245 if ((vo = isAPropertyOf(vevent, VCLocationProp))) { 1248 if ((vo = isAPropertyOf(vevent, VCLocationProp))) {
1246 s = fakeCString(vObjectUStringZValue(vo)); 1249 s = fakeCString(vObjectUStringZValue(vo));
1247 anEvent->setLocation(QString::fromLocal8Bit(s)); 1250 anEvent->setLocation(QString::fromLocal8Bit(s));
1248 deleteStr(s); 1251 deleteStr(s);
1249 } 1252 }
1250 1253
1251 // description 1254 // description
1252 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { 1255 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) {
1253 s = fakeCString(vObjectUStringZValue(vo)); 1256 s = fakeCString(vObjectUStringZValue(vo));
1254 if (!anEvent->description().isEmpty()) { 1257 if (!anEvent->description().isEmpty()) {
1255 anEvent->setDescription(anEvent->description() + "\n" + 1258 anEvent->setDescription(anEvent->description() + "\n" +
1256 QString::fromLocal8Bit(s)); 1259 QString::fromLocal8Bit(s));
1257 } else { 1260 } else {
1258 anEvent->setDescription(QString::fromLocal8Bit(s)); 1261 anEvent->setDescription(QString::fromLocal8Bit(s));
1259 } 1262 }
1260 deleteStr(s); 1263 deleteStr(s);
1261 } 1264 }
1262 1265
1263 // some stupid vCal exporters ignore the standard and use Description 1266 // some stupid vCal exporters ignore the standard and use Description
1264 // instead of Summary for the default field. Correct for this. 1267 // instead of Summary for the default field. Correct for this.
1265 if (anEvent->summary().isEmpty() && 1268 if (anEvent->summary().isEmpty() &&
1266 !(anEvent->description().isEmpty())) { 1269 !(anEvent->description().isEmpty())) {
1267 QString tmpStr = anEvent->description().simplifyWhiteSpace(); 1270 QString tmpStr = anEvent->description().simplifyWhiteSpace();
1268 anEvent->setDescription(""); 1271 anEvent->setDescription("");
1269 anEvent->setSummary(tmpStr); 1272 anEvent->setSummary(tmpStr);
1270 } 1273 }
1271 1274
1272#if 0 1275#if 0
1273 // status 1276 // status
1274 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { 1277 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) {
1275 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); 1278 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo)));
1276 deleteStr(s); 1279 deleteStr(s);
1277// TODO: Define Event status 1280// TODO: Define Event status
1278// anEvent->setStatus(tmpStr); 1281// anEvent->setStatus(tmpStr);
1279 } 1282 }
1280 else 1283 else
1281// anEvent->setStatus("NEEDS ACTION"); 1284// anEvent->setStatus("NEEDS ACTION");
1282#endif 1285#endif
1283 1286
1284 // secrecy 1287 // secrecy
1285 int secrecy = Incidence::SecrecyPublic; 1288 int secrecy = Incidence::SecrecyPublic;
1286 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 1289 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
1287 s = fakeCString(vObjectUStringZValue(vo)); 1290 s = fakeCString(vObjectUStringZValue(vo));
1288 if (strcmp(s,"PRIVATE") == 0) { 1291 if (strcmp(s,"PRIVATE") == 0) {
1289 secrecy = Incidence::SecrecyPrivate; 1292 secrecy = Incidence::SecrecyPrivate;
1290 } else if (strcmp(s,"CONFIDENTIAL") == 0) { 1293 } else if (strcmp(s,"CONFIDENTIAL") == 0) {
1291 secrecy = Incidence::SecrecyConfidential; 1294 secrecy = Incidence::SecrecyConfidential;
1292 } 1295 }
1293 deleteStr(s); 1296 deleteStr(s);
1294 } 1297 }
1295 anEvent->setSecrecy(secrecy); 1298 anEvent->setSecrecy(secrecy);
1296 1299
1297 // categories 1300 // categories
1298 QStringList tmpStrList; 1301 QStringList tmpStrList;
1299 int index1 = 0; 1302 int index1 = 0;
1300 int index2 = 0; 1303 int index2 = 0;
1301 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { 1304 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1302 s = fakeCString(vObjectUStringZValue(vo)); 1305 s = fakeCString(vObjectUStringZValue(vo));
1303 QString categories = QString::fromLocal8Bit(s); 1306 QString categories = QString::fromLocal8Bit(s);
1304 deleteStr(s); 1307 deleteStr(s);
1305 //const char* category; 1308 //const char* category;
1306 QString category; 1309 QString category;
1307 while ((index2 = categories.find(',', index1)) != -1) { 1310 while ((index2 = categories.find(',', index1)) != -1) {
1308 //category = (const char *) categories.mid(index1, (index2 - index1)); 1311 //category = (const char *) categories.mid(index1, (index2 - index1));
1309 category = categories.mid(index1, (index2 - index1)); 1312 category = categories.mid(index1, (index2 - index1));
1310 tmpStrList.append(category); 1313 tmpStrList.append(category);
1311 index1 = index2+1; 1314 index1 = index2+1;
1312 } 1315 }
1313 // get last category 1316 // get last category
1314 category = categories.mid(index1, (categories.length()-index1)); 1317 category = categories.mid(index1, (categories.length()-index1));
1315 tmpStrList.append(category); 1318 tmpStrList.append(category);
1316 anEvent->setCategories(tmpStrList); 1319 anEvent->setCategories(tmpStrList);
1317 } 1320 }
1318 1321
1319 // attachments 1322 // attachments
1320 tmpStrList.clear(); 1323 tmpStrList.clear();
1321 initPropIterator(&voi, vevent); 1324 initPropIterator(&voi, vevent);
1322 while (moreIteration(&voi)) { 1325 while (moreIteration(&voi)) {
1323 vo = nextVObject(&voi); 1326 vo = nextVObject(&voi);
1324 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 1327 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1325 s = fakeCString(vObjectUStringZValue(vo)); 1328 s = fakeCString(vObjectUStringZValue(vo));
1326 anEvent->addAttachment(new Attachment(QString(s))); 1329 anEvent->addAttachment(new Attachment(QString(s)));
1327 deleteStr(s); 1330 deleteStr(s);
1328 } 1331 }
1329 } 1332 }
1330 1333
1331 // resources 1334 // resources
1332 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 1335 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1333 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1336 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1334 deleteStr(s); 1337 deleteStr(s);
1335 tmpStrList.clear(); 1338 tmpStrList.clear();
1336 index1 = 0; 1339 index1 = 0;
1337 index2 = 0; 1340 index2 = 0;
1338 QString resource; 1341 QString resource;
1339 while ((index2 = resources.find(';', index1)) != -1) { 1342 while ((index2 = resources.find(';', index1)) != -1) {
1340 resource = resources.mid(index1, (index2 - index1)); 1343 resource = resources.mid(index1, (index2 - index1));
1341 tmpStrList.append(resource); 1344 tmpStrList.append(resource);
1342 index1 = index2; 1345 index1 = index2;
1343 } 1346 }
1344 anEvent->setResources(tmpStrList); 1347 anEvent->setResources(tmpStrList);
1345 } 1348 }
1346 1349
1347 /* alarm stuff */ 1350 /* alarm stuff */
1348 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1351 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1349 Alarm* alarm = anEvent->newAlarm(); 1352 Alarm* alarm = anEvent->newAlarm();
1350 VObject *a; 1353 VObject *a;
1351 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1354 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1352 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1355 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1353 deleteStr(s); 1356 deleteStr(s);
1354 } 1357 }
1355 alarm->setEnabled(true); 1358 alarm->setEnabled(true);
1356 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1359 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1357 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1360 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1358 s = fakeCString(vObjectUStringZValue(a)); 1361 s = fakeCString(vObjectUStringZValue(a));
1359 alarm->setProcedureAlarm(QFile::decodeName(s)); 1362 alarm->setProcedureAlarm(QFile::decodeName(s));
1360 deleteStr(s); 1363 deleteStr(s);
1361 } 1364 }
1362 } 1365 }
1363 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1366 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1364 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1367 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1365 s = fakeCString(vObjectUStringZValue(a)); 1368 s = fakeCString(vObjectUStringZValue(a));
1366 alarm->setAudioAlarm(QFile::decodeName(s)); 1369 alarm->setAudioAlarm(QFile::decodeName(s));
1367 deleteStr(s); 1370 deleteStr(s);
1368 } 1371 }
1369 } 1372 }
1370 } 1373 }
1371 1374
1372 // priority 1375 // priority
1373 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1376 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1374 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1377 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1375 deleteStr(s); 1378 deleteStr(s);
1376 } 1379 }
1377 1380
1378 // transparency 1381 // transparency
1379 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1382 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1380 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1383 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1381 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1384 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1382 deleteStr(s); 1385 deleteStr(s);
1383 } 1386 }
1384 1387
1385 // related event 1388 // related event
1386 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1389 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1387 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1390 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1388 deleteStr(s); 1391 deleteStr(s);
1389 mEventsRelate.append(anEvent); 1392 mEventsRelate.append(anEvent);
1390 } 1393 }
1391 1394
1392 /* PILOT SYNC STUFF */ 1395 /* PILOT SYNC STUFF */
1393 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1396 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1394 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1397 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1395 deleteStr(s); 1398 deleteStr(s);
1396 } 1399 }
1397 else 1400 else
1398 anEvent->setPilotId(0); 1401 anEvent->setPilotId(0);
1399 1402
1400 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1403 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1401 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1404 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1402 deleteStr(s); 1405 deleteStr(s);
1403 } 1406 }
1404 else 1407 else
1405 anEvent->setSyncStatus(Event::SYNCMOD); 1408 anEvent->setSyncStatus(Event::SYNCMOD);
1406 1409
1407 return anEvent; 1410 return anEvent;
1408} 1411}
1409 1412
1410 1413
1411QString VCalFormat::qDateToISO(const QDate &qd) 1414QString VCalFormat::qDateToISO(const QDate &qd)
1412{ 1415{
1413 QString tmpStr; 1416 QString tmpStr;
1414 1417
1415 ASSERT(qd.isValid()); 1418 ASSERT(qd.isValid());
1416 1419
1417 tmpStr.sprintf("%.2d%.2d%.2d", 1420 tmpStr.sprintf("%.2d%.2d%.2d",
1418 qd.year(), qd.month(), qd.day()); 1421 qd.year(), qd.month(), qd.day());
1419 return tmpStr; 1422 return tmpStr;
1420 1423
1421} 1424}
1422 1425
1423QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1426QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1424{ 1427{
1425 QString tmpStr; 1428 QString tmpStr;
1426 1429
1427 ASSERT(qdt.date().isValid()); 1430 ASSERT(qdt.date().isValid());
1428 ASSERT(qdt.time().isValid()); 1431 ASSERT(qdt.time().isValid());
1429 if (zulu) { 1432 if (zulu) {
1430 QDateTime tmpDT(qdt); 1433 QDateTime tmpDT(qdt);
1431 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT. 1434 tmpDT = tmpDT.addSecs(60*(-mCalendar->getTimeZone())); // correct to GMT.
1432 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1435 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1433 tmpDT.date().year(), tmpDT.date().month(), 1436 tmpDT.date().year(), tmpDT.date().month(),
1434 tmpDT.date().day(), tmpDT.time().hour(), 1437 tmpDT.date().day(), tmpDT.time().hour(),
1435 tmpDT.time().minute(), tmpDT.time().second()); 1438 tmpDT.time().minute(), tmpDT.time().second());
1436 } else { 1439 } else {
1437 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1440 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1438 qdt.date().year(), qdt.date().month(), 1441 qdt.date().year(), qdt.date().month(),
1439 qdt.date().day(), qdt.time().hour(), 1442 qdt.date().day(), qdt.time().hour(),
1440 qdt.time().minute(), qdt.time().second()); 1443 qdt.time().minute(), qdt.time().second());
1441 } 1444 }
1442 return tmpStr; 1445 return tmpStr;
1443} 1446}
1444 1447
1445QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1448QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1446{ 1449{
1447 QDate tmpDate; 1450 QDate tmpDate;
1448 QTime tmpTime; 1451 QTime tmpTime;
1449 QString tmpStr; 1452 QString tmpStr;
1450 int year, month, day, hour, minute, second; 1453 int year, month, day, hour, minute, second;
1451 1454
1452 tmpStr = dtStr; 1455 tmpStr = dtStr;
1453 year = tmpStr.left(4).toInt(); 1456 year = tmpStr.left(4).toInt();
1454 month = tmpStr.mid(4,2).toInt(); 1457 month = tmpStr.mid(4,2).toInt();
1455 day = tmpStr.mid(6,2).toInt(); 1458 day = tmpStr.mid(6,2).toInt();
1456 hour = tmpStr.mid(9,2).toInt(); 1459 hour = tmpStr.mid(9,2).toInt();
1457 minute = tmpStr.mid(11,2).toInt(); 1460 minute = tmpStr.mid(11,2).toInt();
1458 second = tmpStr.mid(13,2).toInt(); 1461 second = tmpStr.mid(13,2).toInt();
1459 tmpDate.setYMD(year, month, day); 1462 tmpDate.setYMD(year, month, day);
1460 tmpTime.setHMS(hour, minute, second); 1463 tmpTime.setHMS(hour, minute, second);
1461 1464
1462 ASSERT(tmpDate.isValid()); 1465 ASSERT(tmpDate.isValid());
1463 ASSERT(tmpTime.isValid()); 1466 ASSERT(tmpTime.isValid());
1464 QDateTime tmpDT(tmpDate, tmpTime); 1467 QDateTime tmpDT(tmpDate, tmpTime);
1465 // correct for GMT if string is in Zulu format 1468 // correct for GMT if string is in Zulu format
1466 if (dtStr.at(dtStr.length()-1) == 'Z') 1469 if (dtStr.at(dtStr.length()-1) == 'Z')
1467 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); 1470 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone());
1468 return tmpDT; 1471 return tmpDT;
1469} 1472}
1470 1473
1471QDate VCalFormat::ISOToQDate(const QString &dateStr) 1474QDate VCalFormat::ISOToQDate(const QString &dateStr)
1472{ 1475{
1473 int year, month, day; 1476 int year, month, day;
1474 1477
1475 year = dateStr.left(4).toInt(); 1478 year = dateStr.left(4).toInt();
1476 month = dateStr.mid(4,2).toInt(); 1479 month = dateStr.mid(4,2).toInt();
1477 day = dateStr.mid(6,2).toInt(); 1480 day = dateStr.mid(6,2).toInt();
1478 1481
1479 return(QDate(year, month, day)); 1482 return(QDate(year, month, day));
1480} 1483}
1481 1484
1482// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1485// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1483// and break it down from it's tree-like format into the dictionary format 1486// and break it down from it's tree-like format into the dictionary format
1484// that is used internally in the VCalFormat. 1487// that is used internally in the VCalFormat.
1485void VCalFormat::populate(VObject *vcal) 1488void VCalFormat::populate(VObject *vcal)
1486{ 1489{
1487 // this function will populate the caldict dictionary and other event 1490 // this function will populate the caldict dictionary and other event
1488 // lists. It turns vevents into Events and then inserts them. 1491 // lists. It turns vevents into Events and then inserts them.
1489 1492
1490 VObjectIterator i; 1493 VObjectIterator i;
1491 VObject *curVO, *curVOProp; 1494 VObject *curVO, *curVOProp;
1492 Event *anEvent; 1495 Event *anEvent;
1493 1496
1494 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1497 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1495 char *methodType = 0; 1498 char *methodType = 0;
1496 methodType = fakeCString(vObjectUStringZValue(curVO)); 1499 methodType = fakeCString(vObjectUStringZValue(curVO));
1497 kdDebug() << "This calendar is an iTIP transaction of type '" 1500 kdDebug() << "This calendar is an iTIP transaction of type '"
1498 << methodType << "'" << endl; 1501 << methodType << "'" << endl;
1499 delete methodType; 1502 delete methodType;
1500 } 1503 }
1501 1504
1502 // warn the user that we might have trouble reading non-known calendar. 1505 // warn the user that we might have trouble reading non-known calendar.
1503 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1506 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1504 char *s = fakeCString(vObjectUStringZValue(curVO)); 1507 char *s = fakeCString(vObjectUStringZValue(curVO));
1505 if (strcmp(productId().local8Bit(), s) != 0) 1508 if (strcmp(productId().local8Bit(), s) != 0)
1506 kdDebug() << "This vCalendar file was not created by KOrganizer " 1509 kdDebug() << "This vCalendar file was not created by KOrganizer "
1507 "or any other product we support. Loading anyway..." << endl; 1510 "or any other product we support. Loading anyway..." << endl;
1508 mLoadedProductId = s; 1511 mLoadedProductId = s;
1509 deleteStr(s); 1512 deleteStr(s);
1510 } 1513 }
1511 1514
1512 // warn the user we might have trouble reading this unknown version. 1515 // warn the user we might have trouble reading this unknown version.
1513 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1516 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1514 char *s = fakeCString(vObjectUStringZValue(curVO)); 1517 char *s = fakeCString(vObjectUStringZValue(curVO));
1515 if (strcmp(_VCAL_VERSION, s) != 0) 1518 if (strcmp(_VCAL_VERSION, s) != 0)
1516 kdDebug() << "This vCalendar file has version " << s 1519 kdDebug() << "This vCalendar file has version " << s
1517 << "We only support " << _VCAL_VERSION << endl; 1520 << "We only support " << _VCAL_VERSION << endl;
1518 deleteStr(s); 1521 deleteStr(s);
1519 } 1522 }
1520 1523
1521 // set the time zone 1524 // set the time zone
1522 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1525 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1523 char *s = fakeCString(vObjectUStringZValue(curVO)); 1526 char *s = fakeCString(vObjectUStringZValue(curVO));
1524 mCalendar->setTimeZone(s); 1527 mCalendar->setTimeZone(s);
1525 deleteStr(s); 1528 deleteStr(s);
1526 } 1529 }
1527 1530
1528 1531
1529 // Store all events with a relatedTo property in a list for post-processing 1532 // Store all events with a relatedTo property in a list for post-processing
1530 mEventsRelate.clear(); 1533 mEventsRelate.clear();
1531 mTodosRelate.clear(); 1534 mTodosRelate.clear();
1532 1535
1533 initPropIterator(&i, vcal); 1536 initPropIterator(&i, vcal);
1534 1537
1535 // go through all the vobjects in the vcal 1538 // go through all the vobjects in the vcal
1536 while (moreIteration(&i)) { 1539 while (moreIteration(&i)) {
1537 curVO = nextVObject(&i); 1540 curVO = nextVObject(&i);
1538 1541
1539 /************************************************************************/ 1542 /************************************************************************/
1540 1543
1541 // now, check to see that the object is an event or todo. 1544 // now, check to see that the object is an event or todo.
1542 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1545 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1543 1546
1544 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { 1547 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) {
1545 char *s; 1548 char *s;
1546 s = fakeCString(vObjectUStringZValue(curVOProp)); 1549 s = fakeCString(vObjectUStringZValue(curVOProp));
1547 // check to see if event was deleted by the kpilot conduit 1550 // check to see if event was deleted by the kpilot conduit
1548 if (atoi(s) == Event::SYNCDEL) { 1551 if (atoi(s) == Event::SYNCDEL) {
1549 deleteStr(s); 1552 deleteStr(s);
1550 kdDebug(5800) << "skipping pilot-deleted event" << endl; 1553 kdDebug(5800) << "skipping pilot-deleted event" << endl;
1551 goto SKIP; 1554 goto SKIP;
1552 } 1555 }
1553 deleteStr(s); 1556 deleteStr(s);
1554 } 1557 }
1555 1558
1556 // this code checks to see if we are trying to read in an event 1559 // this code checks to see if we are trying to read in an event
1557 // that we already find to be in the calendar. If we find this 1560 // that we already find to be in the calendar. If we find this
1558 // to be the case, we skip the event. 1561 // to be the case, we skip the event.
1559 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1562 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1560 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1563 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1561 QString tmpStr(s); 1564 QString tmpStr(s);
1562 deleteStr(s); 1565 deleteStr(s);
1563 1566
1564 if (mCalendar->event(tmpStr)) { 1567 if (mCalendar->event(tmpStr)) {
1565 goto SKIP; 1568 goto SKIP;
1566 } 1569 }
1567 if (mCalendar->todo(tmpStr)) { 1570 if (mCalendar->todo(tmpStr)) {
1568 goto SKIP; 1571 goto SKIP;
1569 } 1572 }
1570 } 1573 }
1571 1574
1572 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1575 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1573 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 1576 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1574 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 1577 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1575 goto SKIP; 1578 goto SKIP;
1576 } 1579 }
1577 1580
1578 anEvent = VEventToEvent(curVO); 1581 anEvent = VEventToEvent(curVO);
1579 // we now use addEvent instead of insertEvent so that the 1582 // we now use addEvent instead of insertEvent so that the
1580 // signal/slot get connected. 1583 // signal/slot get connected.
1581 if (anEvent) { 1584 if (anEvent) {
1582 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { 1585 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) {
1583 kdDebug() << "VCalFormat::populate(): Event has invalid dates." 1586 kdDebug() << "VCalFormat::populate(): Event has invalid dates."
1584 << endl; 1587 << endl;
1585 } else { 1588 } else {
1586 mCalendar->addEvent(anEvent); 1589 mCalendar->addEvent(anEvent);
1587 } 1590 }
1588 } else { 1591 } else {
1589 // some sort of error must have occurred while in translation. 1592 // some sort of error must have occurred while in translation.
1590 goto SKIP; 1593 goto SKIP;
1591 } 1594 }
1592 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 1595 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1593 Todo *aTodo = VTodoToEvent(curVO); 1596 Todo *aTodo = VTodoToEvent(curVO);
1594 mCalendar->addTodo(aTodo); 1597 mCalendar->addTodo(aTodo);
1595 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 1598 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1596 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 1599 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1597 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 1600 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1598 // do nothing, we know these properties and we want to skip them. 1601 // do nothing, we know these properties and we want to skip them.
1599 // we have either already processed them or are ignoring them. 1602 // we have either already processed them or are ignoring them.
1600 ; 1603 ;
1601 } else { 1604 } else {
1602 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; 1605 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl;
1603 } 1606 }
1604 SKIP: 1607 SKIP:
1605 ; 1608 ;
1606 } // while 1609 } // while
1607 1610
1608 // Post-Process list of events with relations, put Event objects in relation 1611 // Post-Process list of events with relations, put Event objects in relation
1609 Event *ev; 1612 Event *ev;
1610 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 1613 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
1611 ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); 1614 ev->setRelatedTo(mCalendar->event(ev->relatedToUid()));
1612 } 1615 }
1613 Todo *todo; 1616 Todo *todo;
1614 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 1617 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
1615 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); 1618 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid()));
1616 } 1619 }
1617} 1620}
1618 1621
1619const char *VCalFormat::dayFromNum(int day) 1622const char *VCalFormat::dayFromNum(int day)
1620{ 1623{
1621 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; 1624 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " };
1622 1625
1623 return days[day]; 1626 return days[day];
1624} 1627}
1625 1628
1626int VCalFormat::numFromDay(const QString &day) 1629int VCalFormat::numFromDay(const QString &day)
1627{ 1630{
1628 if (day == "MO ") return 0; 1631 if (day == "MO ") return 0;
1629 if (day == "TU ") return 1; 1632 if (day == "TU ") return 1;
1630 if (day == "WE ") return 2; 1633 if (day == "WE ") return 2;
1631 if (day == "TH ") return 3; 1634 if (day == "TH ") return 3;
1632 if (day == "FR ") return 4; 1635 if (day == "FR ") return 4;
1633 if (day == "SA ") return 5; 1636 if (day == "SA ") return 5;
1634 if (day == "SU ") return 6; 1637 if (day == "SU ") return 6;
1635 1638
1636 return -1; // something bad happened. :) 1639 return -1; // something bad happened. :)
1637} 1640}
1638 1641
1639Attendee::PartStat VCalFormat::readStatus(const char *s) const 1642Attendee::PartStat VCalFormat::readStatus(const char *s) const
1640{ 1643{
1641 QString statStr = s; 1644 QString statStr = s;
1642 statStr = statStr.upper(); 1645 statStr = statStr.upper();
1643 Attendee::PartStat status; 1646 Attendee::PartStat status;
1644 1647
1645 if (statStr == "X-ACTION") 1648 if (statStr == "X-ACTION")
1646 status = Attendee::NeedsAction; 1649 status = Attendee::NeedsAction;
1647 else if (statStr == "NEEDS ACTION") 1650 else if (statStr == "NEEDS ACTION")
1648 status = Attendee::NeedsAction; 1651 status = Attendee::NeedsAction;
1649 else if (statStr== "ACCEPTED") 1652 else if (statStr== "ACCEPTED")
1650 status = Attendee::Accepted; 1653 status = Attendee::Accepted;
1651 else if (statStr== "SENT") 1654 else if (statStr== "SENT")
1652 status = Attendee::NeedsAction; 1655 status = Attendee::NeedsAction;
1653 else if (statStr== "TENTATIVE") 1656 else if (statStr== "TENTATIVE")
1654 status = Attendee::Tentative; 1657 status = Attendee::Tentative;
1655 else if (statStr== "CONFIRMED") 1658 else if (statStr== "CONFIRMED")
1656 status = Attendee::Accepted; 1659 status = Attendee::Accepted;
1657 else if (statStr== "DECLINED") 1660 else if (statStr== "DECLINED")
1658 status = Attendee::Declined; 1661 status = Attendee::Declined;
1659 else if (statStr== "COMPLETED") 1662 else if (statStr== "COMPLETED")
1660 status = Attendee::Completed; 1663 status = Attendee::Completed;
1661 else if (statStr== "DELEGATED") 1664 else if (statStr== "DELEGATED")
1662 status = Attendee::Delegated; 1665 status = Attendee::Delegated;
1663 else { 1666 else {
1664 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; 1667 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl;
1665 status = Attendee::NeedsAction; 1668 status = Attendee::NeedsAction;
1666 } 1669 }
1667 1670
1668 return status; 1671 return status;
1669} 1672}
1670 1673
1671QCString VCalFormat::writeStatus(Attendee::PartStat status) const 1674QCString VCalFormat::writeStatus(Attendee::PartStat status) const
1672{ 1675{
1673 switch(status) { 1676 switch(status) {
1674 default: 1677 default:
1675 case Attendee::NeedsAction: 1678 case Attendee::NeedsAction:
1676 return "NEEDS ACTION"; 1679 return "NEEDS ACTION";
1677 break; 1680 break;
1678 case Attendee::Accepted: 1681 case Attendee::Accepted:
1679 return "ACCEPTED"; 1682 return "ACCEPTED";
1680 break; 1683 break;
1681 case Attendee::Declined: 1684 case Attendee::Declined:
1682 return "DECLINED"; 1685 return "DECLINED";
1683 break; 1686 break;
1684 case Attendee::Tentative: 1687 case Attendee::Tentative:
1685 return "TENTATIVE"; 1688 return "TENTATIVE";
1686 break; 1689 break;
1687 case Attendee::Delegated: 1690 case Attendee::Delegated:
1688 return "DELEGATED"; 1691 return "DELEGATED";
1689 break; 1692 break;
1690 case Attendee::Completed: 1693 case Attendee::Completed:
1691 return "COMPLETED"; 1694 return "COMPLETED";
1692 break; 1695 break;
1693 case Attendee::InProcess: 1696 case Attendee::InProcess:
1694 return "NEEDS ACTION"; 1697 return "NEEDS ACTION";
1695 break; 1698 break;
1696 } 1699 }
1697} 1700}
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h
index 8490125..7b9ca26 100644
--- a/libkcal/vcalformat.h
+++ b/libkcal/vcalformat.h
@@ -1,110 +1,110 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
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#ifndef _VCALFORMAT_H 22#ifndef _VCALFORMAT_H
23#define _VCALFORMAT_H 23#define _VCALFORMAT_H
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#define _VCAL_VERSION "1.0" 27#define _VCAL_VERSION "1.0"
28 28
29class VObject; 29class VObject;
30 30
31namespace KCal { 31namespace KCal {
32 32
33/** 33/**
34 This class implements the vCalendar format. It provides methods for 34 This class implements the vCalendar format. It provides methods for
35 loading/saving/converting vCalendar format data into the internal KOrganizer 35 loading/saving/converting vCalendar format data into the internal KOrganizer
36 representation as Calendar and Events. 36 representation as Calendar and Events.
37 37
38 @short vCalendar format implementation 38 @short vCalendar format implementation
39*/ 39*/
40class VCalFormat : public CalFormat { 40class VCalFormat : public CalFormat {
41 public: 41 public:
42 VCalFormat(); 42 VCalFormat();
43 virtual ~VCalFormat(); 43 virtual ~VCalFormat();
44 44
45 /** loads a calendar on disk in vCalendar format into the current calendar. 45 /** loads a calendar on disk in vCalendar format into the current calendar.
46 * any information already present is lost. Returns TRUE if successful, 46 * any information already present is lost. Returns TRUE if successful,
47 * else returns FALSE. 47 * else returns FALSE.
48 * @param fileName the name of the calendar on disk. 48 * @param fileName the name of the calendar on disk.
49 */ 49 */
50 bool load(Calendar *,const QString &fileName); 50 bool load(Calendar *,const QString &fileName);
51 /** writes out the calendar to disk in vCalendar format. Returns true if 51 /** writes out the calendar to disk in vCalendar format. Returns true if
52 * successful and false on error. 52 * successful and false on error.
53 * @param fileName the name of the file 53 * @param fileName the name of the file
54 */ 54 */
55 bool save(Calendar *,const QString &fileName); 55 bool save(Calendar *,const QString &fileName);
56 56
57 /** 57 /**
58 Parse string and populate calendar with that information. 58 Parse string and populate calendar with that information.
59 */ 59 */
60 bool fromString( Calendar *, const QString & ); 60 bool fromString( Calendar *, const QString & );
61 /** 61 /**
62 Return calendar information as string. 62 Return calendar information as string.
63 */ 63 */
64 QString toString( Calendar * ); 64 QString toString( Calendar * );
65 QString eventToString( Event * ); 65 QString eventToString( Event *, Calendar *calendar );
66 QString todoToString( Todo * ); 66 QString todoToString( Todo * ,Calendar *calendar );
67 67
68 protected: 68 protected:
69 /** translates a VObject of the TODO type into a Event */ 69 /** translates a VObject of the TODO type into a Event */
70 Todo *VTodoToEvent(VObject *vtodo); 70 Todo *VTodoToEvent(VObject *vtodo);
71 /** translates a VObject into a Event and returns a pointer to it. */ 71 /** translates a VObject into a Event and returns a pointer to it. */
72 Event *VEventToEvent(VObject *vevent); 72 Event *VEventToEvent(VObject *vevent);
73 /** translate a Event into a VTodo-type VObject and return pointer */ 73 /** translate a Event into a VTodo-type VObject and return pointer */
74 VObject *eventToVTodo(const Todo *anEvent); 74 VObject *eventToVTodo(const Todo *anEvent);
75 /** translate a Event into a VObject and returns a pointer to it. */ 75 /** translate a Event into a VObject and returns a pointer to it. */
76 VObject* eventToVEvent(const Event *anEvent); 76 VObject* eventToVEvent(const Event *anEvent);
77 77
78 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ 78 /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */
79 QString qDateToISO(const QDate &); 79 QString qDateToISO(const QDate &);
80 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ 80 /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */
81 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); 81 QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE);
82 /** takes a string in the format YYYYMMDDTHHMMSS and returns a 82 /** takes a string in the format YYYYMMDDTHHMMSS and returns a
83 * valid QDateTime. */ 83 * valid QDateTime. */
84 QDateTime ISOToQDateTime(const QString & dtStr); 84 QDateTime ISOToQDateTime(const QString & dtStr);
85 /** takes a string in the format YYYYMMDD and returns a 85 /** takes a string in the format YYYYMMDD and returns a
86 * valid QDate. */ 86 * valid QDate. */
87 QDate ISOToQDate(const QString & dtStr); 87 QDate ISOToQDate(const QString & dtStr);
88 /** takes a vCalendar tree of VObjects, and puts all of them that have 88 /** takes a vCalendar tree of VObjects, and puts all of them that have
89 * the "event" property into the dictionary, todos in the todo-list, etc. */ 89 * the "event" property into the dictionary, todos in the todo-list, etc. */
90 void populate(VObject *vcal); 90 void populate(VObject *vcal);
91 91
92 /** takes a number 0 - 6 and returns the two letter string of that day, 92 /** takes a number 0 - 6 and returns the two letter string of that day,
93 * i.e. MO, TU, WE, etc. */ 93 * i.e. MO, TU, WE, etc. */
94 const char *dayFromNum(int day); 94 const char *dayFromNum(int day);
95 /** the reverse of the above function. */ 95 /** the reverse of the above function. */
96 int numFromDay(const QString &day); 96 int numFromDay(const QString &day);
97 97
98 Attendee::PartStat readStatus(const char *s) const; 98 Attendee::PartStat readStatus(const char *s) const;
99 QCString writeStatus(Attendee::PartStat status) const; 99 QCString writeStatus(Attendee::PartStat status) const;
100 100
101 private: 101 private:
102 Calendar *mCalendar; 102 Calendar *mCalendar;
103 103
104 QPtrList<Event> mEventsRelate; // events with relations 104 QPtrList<Event> mEventsRelate; // events with relations
105 QPtrList<Todo> mTodosRelate; // todos with relations 105 QPtrList<Todo> mTodosRelate; // todos with relations
106}; 106};
107 107
108} 108}
109 109
110#endif 110#endif