1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
|
/*
This file is part of kdepim.
Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <klocale.h>
#include <kmdcodec.h>
#include <libkdepim/kpimprefs.h>
#include <libkcal/event.h>
#include <libkcal/journal.h>
#include <libkcal/recurrence.h>
#include <libkcal/kcalversion.h>
#include <kabc/stdaddressbook.h>
#include <kabc/addressee.h>
#include <kdebug.h>
#include "incidenceconverter.h"
#define GW_MAX_RECURRENCES 50
IncidenceConverter::IncidenceConverter( struct soap* soap )
: GWConverter( soap )
{
mTimezone = KPimPrefs::timezone();
}
void IncidenceConverter::setFrom( const TQString &name,
const TQString &email, const TQString &uuid )
{
mFromName = name;
mFromEmail = email;
mFromUuid = uuid;
}
KCal::Event* IncidenceConverter::convertFromAppointment( ngwt__Appointment* appointment )
{
kdDebug() << "IncidenceConverter::convertFromAppointment()" << endl;
if ( !appointment )
return 0;
KCal::Event *event = new KCal::Event();
if ( !convertFromCalendarItem( appointment, event ) ) {
delete event;
return 0;
}
if ( appointment->allDayEvent && (*appointment->allDayEvent) )
{
event->setFloats( true );
if ( appointment->startDay != 0 )
event->setDtStart( stringToTQDate( appointment->startDay ).addDays( 1 ) );
if ( appointment->endDay != 0 )
event->setDtEnd( stringToTQDate( appointment->endDay) );
kdDebug() << " all day event." << endl;
}
else
{
event->setFloats( false );
if ( appointment->startDate != 0 ) {
event->setDtStart( charToTQDateTime( appointment->startDate, mTimezone ) );
}
if ( appointment->endDate != 0 )
event->setDtEnd( charToTQDateTime( appointment->endDate, mTimezone ) );
}
kdDebug() << "start date: " << event->dtStart() << endl;
kdDebug() << "end date: " << event->dtEnd() << endl;
if ( appointment->alarm ) {
KCal::Alarm *alarm = event->newAlarm();
alarm->setStartOffset( appointment->alarm->__item * -1 );
alarm->setEnabled( appointment->alarm->enabled );
}
if ( appointment->place )
event->setLocation( stringToTQString( appointment->place ) );
if ( appointment->acceptLevel ) {
if ( *appointment->acceptLevel == Tentative )
event->setTransparency( KCal::Event::Transparent );
else
event->setTransparency( KCal::Event::Opaque );
}
return event;
}
ngwt__Appointment* IncidenceConverter::convertToAppointment( KCal::Event* event )
{
kdDebug() << "IncidenceConverter::convertToAppointment()" << endl;
if ( !event )
return 0;
ngwt__Appointment* appointment = soap_new_ngwt__Appointment( soap(), -1 );
appointment->startDate = 0;
appointment->endDate = 0;
appointment->startDay = 0;
appointment->endDay = 0;
appointment->acceptLevel = 0;
appointment->alarm = 0;
appointment->allDayEvent = 0;
appointment->place = 0;
appointment->timezone = 0;
if ( !convertToCalendarItem( event, appointment ) ) {
soap_dealloc( soap(), appointment );
return 0;
}
if ( event->doesFloat() ) {
bool *allDayEvent = (bool*)soap_malloc( soap(), 1 );
(*allDayEvent ) = true;
appointment->allDayEvent = allDayEvent;
if ( event->dtStart().isValid() ) {
/* kdDebug() << " convertToAppointment() raw start date: " << event->dtStart().toString() << endl;*/
TQDateTime start = event->dtStart();
start.setTime( TQTime( 0, 0, 0 ) );
appointment->startDate = qDateTimeToChar( start, mTimezone );
//appointment->startDay = qDateToString( event->dtStart().date()/*.addDays( -1 )*/ );
/* kdDebug() << " converted start date: " << appointment->startDate << endl;*/
}
else
kdDebug() << " event start date not valid " << endl;
if ( event->hasEndDate() ) {
// kdDebug() << " convertToAppointment() raw end date: " << event->dtEnd().toString() << endl;
TQDateTime end = event->dtEnd();
end = end.addDays( 1 );
end.setTime( TQTime( 0, 0, 0 ) );
appointment->endDate = qDateTimeToChar( end, mTimezone );
//appointment->endDay = qDateToString( event->dtEnd().date() );
// kdDebug() << " converted end date:" << appointment->endDate << endl;
}
else
kdDebug() << " event end date not valid " << endl;
} else {
appointment->allDayEvent = 0;
if ( event->dtStart().isValid() )
appointment->startDate = qDateTimeToChar( event->dtStart(), mTimezone );
if ( event->hasEndDate() )
appointment->endDate = qDateTimeToChar( event->dtEnd(), mTimezone );
}
enum ngwt__AcceptLevel * al = (enum ngwt__AcceptLevel*)soap_malloc(soap(), sizeof(enum ngwt__AcceptLevel));
*al = Busy;
appointment->acceptLevel = al;
KCal::Alarm::List alarms = event->alarms();
if ( !alarms.isEmpty() ) {
ngwt__Alarm* alarm = soap_new_ngwt__Alarm( soap(), -1 );
alarm->__item = alarms.first()->startOffset().asSeconds() * -1;
bool * enabled = (bool *)soap_malloc(soap(), sizeof(bool));
*enabled = alarms.first()->enabled();
alarm->enabled = enabled;
appointment->alarm = alarm;
} else
appointment->alarm = 0;
if ( !event->location().isEmpty() ) {
std::string* location = qStringToString( event->location() );
appointment->place = location;
} else
appointment->place = 0;
appointment->timezone = 0;
return appointment;
}
KCal::Todo* IncidenceConverter::convertFromTask( ngwt__Task* task )
{
if ( !task )
return 0;
KCal::Todo *todo = new KCal::Todo();
if ( !convertFromCalendarItem( task, todo ) ) {
delete todo;
return 0;
}
if ( task->startDate ) {
todo->setHasStartDate( true );
todo->setDtStart( stringToTQDateTime( task->startDate ) );
}
if ( task->dueDate ) {
todo->setHasDueDate( true );
todo->setDtDue( stringToTQDateTime( task->dueDate ) );
}
if ( task->taskPriority ) {
TQString priority = stringToTQString( task->taskPriority );
// FIXME: Store priority string somewhere
int p = priority.toInt();
if ( p == 0 ) p = 3;
todo->setPriority( p );
}
if ( task->completed )
todo->setCompleted( *task->completed );
todo->setLocation( i18n( "Novell GroupWise does not support locations for to-dos." ) );
return todo;
}
ngwt__Task* IncidenceConverter::convertToTask( KCal::Todo* todo )
{
if ( !todo )
return 0;
ngwt__Task* task = soap_new_ngwt__Task( soap(), -1 );
task->startDate = 0;
task->dueDate = 0;
task->assignedDate = 0;
task->taskPriority = 0;
task->completed = 0;
if ( !convertToCalendarItem( todo, task ) ) {
soap_dealloc( soap(), task );
return 0;
}
if ( todo->dtStart().isValid() )
task->startDate = qDateTimeToString( todo->dtStart(), mTimezone );
if ( todo->hasDueDate() ) {
task->dueDate = qDateTimeToString( todo->dtDue() );
}
// FIXME: Restore custom priorities
TQString priority = TQString::number( todo->priority() );
task->taskPriority = qStringToString( priority );
task->completed = (bool*)soap_malloc( soap(), 1 );
if ( todo->isCompleted() )
(*task->completed) = true;
else
(*task->completed) = false;
return task;
}
KCal::Journal* IncidenceConverter::convertFromNote( ngwt__Note* note)
{
kdDebug() << "IncidenceConverter::convertFromNote()" << endl;
if ( !note )
return 0;
KCal::Journal *journal = new KCal::Journal();
if ( !convertFromCalendarItem( note, journal ) ) {
kdDebug() << "Couldn't convert Note to Journal!" << endl;
delete journal;
return 0;
}
if ( note->startDate ) {
kdDebug() << "Journal start date is: " << note->startDate->c_str() << endl;
journal->setDtStart( stringToTQDate( note->startDate ) );
}
return journal;
}
ngwt__Note* IncidenceConverter::convertToNote( KCal::Journal* journal )
{
if ( !journal )
return 0;
ngwt__Note* note = soap_new_ngwt__Note( soap(), -1 );
note->startDate = 0;
if ( !convertToCalendarItem( journal, note ) ) {
soap_dealloc( soap(), note );
return 0;
}
if ( journal->doesFloat() ) {
if ( journal->dtStart().isValid() )
note->startDate = qDateToString( journal->dtStart().date() );
} else {
if ( journal->dtStart().isValid() )
note->startDate = qDateTimeToString( journal->dtStart(), mTimezone );
}
if ( !note->subject )
note->subject = qStringToString( TQString("NO SUBJECT") );
return note;
}
bool IncidenceConverter::convertToCalendarItem( KCal::Incidence* incidence, ngwt__CalendarItem* item )
{
kdDebug() << k_funcinfo << endl;
//TODO: support the new iCal standard recurrence rule
// ngwt__CalendarItem
item->rdate = 0;
item->rrule = 0;
item->exdate = 0;
item->recurrenceKey = 0;
item->iCalId = 0;
// ngwt__Mail
item->subject = 0;
item->originalSubject = 0;
item->subjectPrefix = 0;
item->distribution = 0;
item->message = 0;
item->attachments = 0;
item->options = 0;
item->link = 0;
item->hasAttachment = false;
item->size = 0;
item->subType = 0;
item->nntpOrImap = 0;
item->smimeType = 0;
// ngwt__BoxEntry
item->status = 0;
item->thread = 0;
item->msgId = 0;
item->messageId = 0;
item->source = 0;
item->returnSentItemsId = 0;
item->delivered = 0;
item->class_ = 0;
item->security = 0;
item->comment = 0;
// ngwt__ContainerItem
item->categories = 0;
item->created = 0;
item->customs = 0;
// ngwt__Item
item->id = 0;
item->name = 0;
item->version = 0;
item->modified = 0;
item->changes = 0;
TQString id = incidence->customProperty( "GWRESOURCE", "UID" );
if ( !id.isEmpty() ) item->id = qStringToString( id );
// Container
if ( !incidence->customProperty( "GWRESOURCE", "CONTAINER" ).isEmpty() ) {
std::vector<ngwt__ContainerRef*>* container = soap_new_std__vectorTemplateOfPointerTongwt__ContainerRef( soap(), -1 );
ngwt__ContainerRef* containerRef = soap_new_ngwt__ContainerRef( soap(), -1 );
containerRef->deleted = 0;
containerRef->__item = incidence->customProperty( "GWRESOURCE", "CONTAINER" ).utf8().data();
container->push_back( containerRef );
item->container = *container;
}
// secrecy
item->class_ = (ngwt__ItemClass *)soap_malloc( soap(), sizeof( ngwt__ItemClass ) );
switch ( incidence->secrecy() )
{
case KCal::Event::SecrecyPublic:
*item->class_ = Public;
break;
case KCal::Event::SecrecyPrivate:
*item->class_ = Private;
break;
case KCal::Event::SecrecyConfidential:
*item->class_ = Private;
break;
}
// options
item->options = soap_new_ngwt__ItemOptions( soap(), -1 );
item->options->concealSubject = 0;
item->options->delayDeliveryUntil = 0;
item->options->expires = 0;
item->options->hidden = 0;
item->options->priority = Standard;
// summary
if ( !incidence->summary().isEmpty() )
item->subject = qStringToString( incidence->summary() );
// TODO: reinstate when we know that this isn't causing problems with recurrence
// if ( incidence->created().isValid() ) {
// item->created = qDateTimeToChar( incidence->created(), mTimezone );
// } else
// item->created = 0;
// if ( incidence->lastModified().isValid() )
// item->modified = qDateTimeToChar( incidence->lastModified(), mTimezone );
setItemDescription( incidence, item );
item->source = (ngwt__ItemSource *)soap_malloc( soap(), sizeof( ngwt__ItemSource ) );
#if 1
if ( incidence->attendeeCount() > 0 ) {
setAttendees( incidence, item );
*item->source = sent_;
}
else
*item->source = personal_;
#endif
setRecurrence( incidence, item );
return true;
}
void IncidenceConverter::setAttendees( KCal::Incidence *incidence,
ngwt__CalendarItem *item )
{
item->distribution = soap_new_ngwt__Distribution( soap(), -1 );
item->distribution->from = soap_new_ngwt__From( soap(), -1 );
// ngwt__From
item->distribution->from->replyTo = 0;
// ngwt__NameAndEmail
item->distribution->from->displayName = 0;
item->distribution->from->email = 0;
item->distribution->from->uuid = 0;
item->distribution->from->displayName = qStringToString( incidence->organizer().name() );
item->distribution->from->email = qStringToString( incidence->organizer().email() );
if ( !mFromName.isEmpty() ) item->distribution->from->displayName = qStringToString( mFromName );
if ( !mFromEmail.isEmpty() ) item->distribution->from->email = qStringToString( mFromEmail );
if ( !mFromUuid.isEmpty() ) item->distribution->from->uuid = qStringToString( mFromUuid );
TQString to; // To list consists of display names of organizer and attendees separated by "; "
to += incidence->organizer().name();
item->distribution->sendoptions = soap_new_ngwt__SendOptions( soap(), -1 );
item->distribution->sendoptions->requestReply = 0;
item->distribution->sendoptions->mimeEncoding = 0;
item->distribution->sendoptions->notification = 0;
item->distribution->sendoptions->statusTracking = soap_new_ngwt__StatusTracking( soap(),
-1 );
item->distribution->sendoptions->statusTracking->autoDelete = false;
item->distribution->sendoptions->statusTracking->__item = All_;
item->distribution->recipients = soap_new_ngwt__RecipientList( soap(), -1 );
item->distribution->recipients->recipient = *( soap_new_std__vectorTemplateOfPointerTongwt__Recipient( soap(), -1 ) );
KCal::Attendee::List attendees = incidence->attendees();
KCal::Attendee::List::ConstIterator it;
for( it = attendees.begin(); it != attendees.end(); ++it ) {
if ( !to.isEmpty() )
to += TQString::fromLatin1( "; %1" ).arg( (*it)->name() );
kdDebug() << "IncidenceConverter::setAttendees(), adding " << (*it)->fullName()
<< endl;
TQString uuid;
TQValueList<KABC::Addressee> addList = KABC::StdAddressBook::self()->findByEmail( (*it)->email() );
if ( !addList.first().isEmpty() )
uuid = addList.first().custom( "GWRESOURCE", "UUID" ); //uuid may be mandatory for the recipients list to be stored on the server...
item->distribution->recipients->recipient.push_back( createRecipient( (*it)->name(), (*it)->email(), uuid ) );
}
item->distribution->to = qStringToString( to );
item->distribution->cc = 0;
item->distribution->bc = 0;
}
ngwt__Recipient *IncidenceConverter::createRecipient( const TQString &name,
const TQString &email, const TQString &uuid )
{
ngwt__Recipient *recipient = soap_new_ngwt__Recipient( soap(), -1 );
recipient->recipienStatus = 0;
if ( !uuid.isEmpty() ) recipient->uuid = qStringToString( uuid );
else recipient->uuid = 0;
if ( !name.isEmpty() ) {
kdDebug() << "- recipient name: " << name << endl;
recipient->displayName = qStringToString( name );
} else {
recipient->displayName = 0;
}
if ( !email.isEmpty() ) {
kdDebug() << "- recipient email: " << email << endl;
recipient->email = qStringToString( email );
} else {
recipient->email = 0;
}
recipient->distType = TO;
recipient->recipType = User_;
recipient->acceptLevel = 0;
return recipient;
}
bool IncidenceConverter::convertFromCalendarItem( ngwt__CalendarItem* item,
KCal::Incidence* incidence )
{
incidence->setCustomProperty( "GWRESOURCE", "UID",
stringToTQString( item->id ) );
if ( item->subject && !item->subject->empty() )
incidence->setSummary( stringToTQString( item->subject ) );
kdDebug() << "SUMMARY: " << incidence->summary() << endl;
if ( item->created ) {
kdDebug() << "item created at " << item->created << endl;
incidence->setCreated( charToTQDateTime( item->created, mTimezone ) );
}
if ( item->modified != 0 ) {
kdDebug() << "item modified at " << item->created << endl;
incidence->setLastModified( charToTQDateTime( item->modified, mTimezone ) );
}
getItemDescription( item, incidence );
getAttendees( item, incidence );
if ( item->recurrenceKey )
incidence->setCustomProperty( "GWRESOURCE", "RECURRENCEKEY", TQString::number( *item->recurrenceKey ) );
/*
// This must just be a very early cut at recurrence
if ( item->rdate && item->rdate->date ) {
std::vector<xsd__date>* dateList = item->rdate->date;
std::vector<xsd__date>::const_iterator it;
for ( it = dateList->begin(); it != dateList->end(); ++it ) {
TQDate date = TQDate::fromString( s2q( *it ), Qt::ISODate );
if ( date.isValid() )
}
}
*/
/*
bool* isRecurring 0;
std::string* iCalId 0;
*/
return true;
}
void IncidenceConverter::getItemDescription( ngwt__CalendarItem *item, KCal::Incidence *incidence )
{
if ( item->message ) {
std::vector<ngwt__MessagePart*> parts = item->message->part;
std::vector<ngwt__MessagePart*>::const_iterator it = parts.begin();
for ( ; it != parts.end(); ++it ) {
xsd__base64Binary data = (*it)->__item;
// text/plain should be the description
if ( stringToTQString( (*it)->contentType ) == "text/plain" ) {
TQString description = TQString::fromUtf8( (char*)data.__ptr, data.__size );
incidence->setDescription( description );
kdDebug() << "Incidence description decodes to: " << description << endl;
return;
}
}
}
}
void IncidenceConverter::setItemDescription( KCal::Incidence *incidence,
ngwt__CalendarItem *item )
{
if ( !incidence->description().isEmpty() ) {
ngwt__MessageBody *message = soap_new_ngwt__MessageBody( soap(), -1 );
message->part =
*soap_new_std__vectorTemplateOfPointerTongwt__MessagePart( soap(), -1 );
ngwt__MessagePart *part = soap_new_ngwt__MessagePart( soap(), -1 );
xsd__base64Binary data;
data.__ptr =
(unsigned char*)qStringToChar( incidence->description().utf8() );
data.__size = incidence->description().utf8().length();
part->id = 0;
part->__item = data;
part->contentId = 0;
std::string *str = soap_new_std__string( soap(), -1 );
str->append( "text/plain" );
part->contentType = str;
part->length = 0; // this is optional and sending the actual length of the source string truncates the data.
part->offset = 0; // optional
message->part.push_back( part );
item->message = message;
} else
item->message = 0;
}
void IncidenceConverter::getAttendees( ngwt__CalendarItem *item, KCal::Incidence *incidence )
{
kdDebug() << "IncidenceConverter::getAttendees()" << ( item->subject ? item->subject->c_str() : "no subject" )
<< endl;
if ( item->distribution && item->distribution->from ) {
kdDebug() << "-- from" << endl;
KCal::Person organizer( stringToTQString( item->distribution->from->displayName ),
stringToTQString( item->distribution->from->email ) );
incidence->setOrganizer( organizer );
}
if ( item->distribution && item->distribution->recipients ) {
kdDebug() << "-- recipients" << endl;
std::vector<ngwt__Recipient*> recipients = item->distribution->recipients->recipient;
std::vector<ngwt__Recipient*>::const_iterator it;
for ( it = recipients.begin(); it != recipients.end(); ++it ) {
ngwt__Recipient *recipient = *it;
kdDebug() << "---- recipient " << recipient->email->c_str() << endl;
KCal::Attendee *attendee = new KCal::Attendee(
stringToTQString( recipient->displayName ),
stringToTQString( recipient->email ) );
// set our status
if ( emailsMatch( stringToTQString(recipient->email), mFromEmail ) )
if ( item->status->accepted )
attendee->setStatus( ( *item->status->accepted ) ? KCal::Attendee::Accepted : KCal::Attendee::NeedsAction );
else
kdDebug() << "---- found ourselves, but not accepted" << endl;
else
kdDebug() << "---- '" << "' != '" << (qStringToString( mFromEmail ))->c_str() << "'" << endl;
incidence->addAttendee( attendee );
}
}
}
void IncidenceConverter::setRecurrence( KCal::Incidence * incidence, ngwt__CalendarItem * item )
{
kdDebug() << k_funcinfo << endl;
ngwt__Frequency * freq = 0;
const KCal::Recurrence * recur = incidence->recurrence();
if ( incidence->doesRecur() )
{
item->rrule = soap_new_ngwt__RecurrenceRule( soap(), -1 );
item->rrule->frequency = 0; //
item->rrule->count = 0;
item->rrule->until = 0; //
item->rrule->interval = 0; //
item->rrule->byDay = 0;
item->rrule->byYearDay = 0;
item->rrule->byMonthDay = 0;
item->rrule->byMonth = 0;
freq = (ngwt__Frequency *)soap_malloc( soap(), sizeof( ngwt__Frequency ) );
// interval
if ( recur->frequency() > 1 ) {
item->rrule->interval = (unsigned long *)soap_malloc( soap(), sizeof( unsigned long * ) );
*item->rrule->interval = recur->frequency();
}
// end date
if ( recur->duration() > 0 ) // number of recurrences. If end date is set we don't use this.
{
item->rrule->count = (long unsigned int *)soap_malloc( soap(), sizeof( long unsigned int * ) );
*item->rrule->count = recur->duration();
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
else if ( recur->endDateTime().isValid() )
#else
else if ( recur->endDate().isValid() )
#endif
item->rrule->until = qDateToString( recur->endDate() );
else // GROUPWISE doesn't accept infinite recurrence so end after GW_MAX_RECURRENCES recurrences
{
item->rrule->count = (long unsigned int *)soap_malloc( soap(), sizeof( long unsigned int * ) );
*item->rrule->count = GW_MAX_RECURRENCES;
}
// recurrence date - try setting it using the recurrence start date - didn't help
/* std::string startDate;
startDate.append( recur->recurStart().date().toString( Qt::ISODate ).utf8() );
item->rdate = soap_new_ngwt__RecurrenceDateType( soap(), -1 );
item->rdate->date.push_back( startDate );*/
// exceptions list - try sending empty list even if no exceptions
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
KCal::DateList exceptions = recur->exDates();
#else
KCal::DateList exceptions = incidence->exDates();
#endif
if ( !exceptions.isEmpty() )
{
item->exdate = soap_new_ngwt__RecurrenceDateType( soap(), -1 );
for ( KCal::DateList::ConstIterator it = exceptions.begin(); it != exceptions.end(); ++it )
{
std::string startDate;
startDate.append( TQString((*it).toString( Qt::ISODate )).utf8() );
item->exdate->date.push_back( startDate );
}
}
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
if ( incidence->recurrenceType() == KCal::Recurrence::rDaily )
#else
if ( incidence->doesRecur() == KCal::Recurrence::rDaily )
#endif
{
kdDebug() << "incidence recurs daily" << endl;
*freq = Daily;
item->rrule->frequency = freq;
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
else if ( incidence->recurrenceType() == KCal::Recurrence::rWeekly )
#else
else if ( incidence->doesRecur() == KCal::Recurrence::rWeekly )
#endif
{
kdDebug() << "incidence recurs weekly" << endl;
#if 1 //trying out byDay recurrence
*freq = Weekly;
item->rrule->frequency = freq;
// now change the bitArray of the days of the week that it recurs on to a ngwt__DayOfWeekList *
TQBitArray ba = recur->days();
ngwt__DayOfYearWeekList * weeklyDays = soap_new_ngwt__DayOfYearWeekList( soap(), -1 );
for ( int i = 0; i < 7; ++i )
{
if ( ba[i] )
{
ngwt__DayOfYearWeek * day = soap_new_ngwt__DayOfYearWeek( soap(), -1 );
day->occurrence = 0;
switch( i )
{
case 0:
day->__item = Monday;
break;
case 1:
day->__item = Tuesday;
break;
case 2:
day->__item = Wednesday;
break;
case 3:
day->__item = Thursday;
break;
case 4:
day->__item = Friday;
break;
case 5:
day->__item = Saturday;
break;
case 6:
day->__item = Sunday;
break;
}
weeklyDays->day.push_back( day );
}
}
// add the list of days to the recurrence rule
item->rrule->byDay = weeklyDays;
#endif
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
else if ( incidence->recurrenceType() == KCal::Recurrence::rMonthlyDay )
#else
else if ( incidence->doesRecur() == KCal::Recurrence::rMonthlyDay )
#endif
{
kdDebug() << "incidence recurs monthly" << endl;
;
*freq = Monthly;
item->rrule->frequency = freq;
// TODO: translate '3rd wednesday of month' etc into rdates
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
else if ( incidence->recurrenceType() == KCal::Recurrence::rYearlyDay )
#else
else if ( incidence->doesRecur() == KCal::Recurrence::rYearlyDay )
#endif
{
kdDebug() << "incidence recurs yearly on day #" << endl;
*freq = Yearly;
item->rrule->frequency = freq;
// TODO: translate '1st sunday in may'
ngwt__DayOfYearList * daysOfYear = soap_new_ngwt__DayOfYearList( soap(), -1 );
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
TQValueList<int> rmd;
rmd = recur->yearMonths();
daysOfYear->day.push_back( rmd.first() );
#else
TQPtrList<int> rmd;
rmd = recur->yearNums();
daysOfYear->day.push_back( *rmd.first() );
#endif
item->rrule->byYearDay = daysOfYear;
// no need to do MonthList recurrence as these will appear as separate instances when fetched from GW
}
#if LIBKCAL_IS_VERSION( 1, 3, 0 )
else if ( incidence->recurrenceType() == KCal::Recurrence::rYearlyMonth )
#else
else if ( incidence->doesRecur() == KCal::Recurrence::rYearlyMonth )
#endif
{
kdDebug() << "incidence recurs yearly on monthday" << endl;
*freq = Yearly;
item->rrule->frequency = freq;
}
}
|