1 /*
2 * Copyright (C) 2011 Christian Mollekopf <mollekopf@kolabsys.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "kolabcontainers.h"
19 #include "incidence_p.h"
20
21 namespace Kolab {
22
23 struct cDateTime::Private {
PrivateKolab::cDateTime::Private24 Private()
25 : year(-1),
26 month(-1),
27 day(-1),
28 hour(-1),
29 minute(-1),
30 second(-1),
31 isUtc(false){}
32
33 int year;
34 int month;
35 int day;
36 int hour;
37 int minute;
38 int second;
39 bool isUtc;
40 std::string timezone;
41 };
42
cDateTime()43 cDateTime::cDateTime()
44 : d(new cDateTime::Private())
45 {
46
47 }
48
cDateTime(int year,int month,int day,int hour,int minute,int second,bool isUtc)49 cDateTime::cDateTime(int year, int month, int day, int hour, int minute, int second, bool isUtc)
50 : d(new cDateTime::Private())
51 {
52 d->year = year;
53 d->month = month;
54 d->day = day;
55 d->hour = hour;
56 d->minute = minute;
57 d->second = second;
58 d->isUtc = isUtc;
59 }
60
cDateTime(const std::string & timezone,int year,int month,int day,int hour,int minute,int second)61 cDateTime::cDateTime(const std::string& timezone, int year, int month, int day, int hour, int minute, int second)
62 : d(new cDateTime::Private())
63 {
64 d->year = year;
65 d->month = month;
66 d->day = day;
67 d->hour = hour;
68 d->minute = minute;
69 d->second = second;
70 d->timezone = timezone;
71 }
72
cDateTime(int year,int month,int day)73 cDateTime::cDateTime(int year, int month, int day)
74 : d(new cDateTime::Private())
75 {
76 d->year = year;
77 d->month = month;
78 d->day = day;
79 }
80
cDateTime(const Kolab::cDateTime & other)81 cDateTime::cDateTime(const Kolab::cDateTime &other)
82 : d(new cDateTime::Private())
83 {
84 *d = *other.d;
85 }
86
~cDateTime()87 cDateTime::~cDateTime()
88 {
89
90 }
91
92
operator =(const Kolab::cDateTime & other)93 void cDateTime::operator=(const Kolab::cDateTime &other)
94 {
95 *d = *other.d;
96 }
97
operator ==(const Kolab::cDateTime & other) const98 bool cDateTime::operator==(const Kolab::cDateTime &other) const
99 {
100 if ( d->year == other.year() &&
101 d->month == other.month() &&
102 d->day == other.day() &&
103 d->hour == other.hour() &&
104 d->minute == other.minute() &&
105 d->second== other.second() &&
106 d->isUtc== other.isUTC() &&
107 d->timezone== other.timezone()) {
108 return true;
109 }
110 return false;
111 }
112
113
114
year() const115 int cDateTime::year() const
116 {
117 return d->year;
118 }
119
month() const120 int cDateTime::month() const
121 {
122 return d->month;
123 }
124
day() const125 int cDateTime::day() const
126 {
127 return d->day;
128 }
129
hour() const130 int cDateTime::hour() const
131 {
132 return d->hour;
133 }
134
minute() const135 int cDateTime::minute() const
136 {
137 return d->minute;
138 }
139
second() const140 int cDateTime::second() const
141 {
142 return d->second;
143 }
144
isDateOnly() const145 bool cDateTime::isDateOnly() const
146 {
147 if ((d->hour < 0) && (d->minute < 0) && (d->second < 0)) {
148 return true;
149 }
150 return false;
151 }
152
setDate(int year,int month,int day)153 void cDateTime::setDate(int year, int month, int day)
154 {
155 d->year = year;
156 d->month = month;
157 d->day = day;
158 }
setTime(int hour,int minute,int second)159 void cDateTime::setTime(int hour, int minute, int second)
160 {
161 d->hour = hour;
162 d->minute = minute;
163 d->second = second;
164 }
setTimezone(const std::string & tz)165 void cDateTime::setTimezone(const std::string &tz)
166 {
167 d->timezone = tz;
168 }
setUTC(bool utc)169 void cDateTime::setUTC(bool utc)
170 {
171 d->isUtc = utc;
172 }
173
isUTC() const174 bool cDateTime::isUTC() const
175 {
176 return d->isUtc;
177 }
178
timezone() const179 std::string cDateTime::timezone() const
180 {
181 return d->timezone;
182 }
183
isValid() const184 bool cDateTime::isValid() const
185 {
186 return (d->year >= 0 && d->month >= 0 && d->day >= 0);
187 }
188
189 struct RecurrenceRule::Private
190 {
PrivateKolab::RecurrenceRule::Private191 Private()
192 : freq(FreqNone),
193 weekstart(Monday),
194 count(-1),
195 interval(1){};
196
197 Frequency freq;
198 Weekday weekstart;
199 cDateTime end;
200 int count;
201 int interval;
202 std::vector<int> bysecond;
203 std::vector<int> byminute;
204 std::vector<int> byhour;
205 std::vector<DayPos> byday;
206 std::vector<int> bymonthday;
207 std::vector<int> byyearday;
208 std::vector<int> byweekno;
209 std::vector<int> bymonth;
210 };
211
RecurrenceRule()212 RecurrenceRule::RecurrenceRule()
213 : d(new RecurrenceRule::Private)
214 {
215
216 }
217
RecurrenceRule(const Kolab::RecurrenceRule & other)218 RecurrenceRule::RecurrenceRule(const Kolab::RecurrenceRule &other)
219 : d(new RecurrenceRule::Private)
220 {
221 *d = *other.d;
222 }
223
operator =(const Kolab::RecurrenceRule & other)224 void RecurrenceRule::operator=(const Kolab::RecurrenceRule &other)
225 {
226 *d = *other.d;
227 }
228
operator ==(const Kolab::RecurrenceRule & other) const229 bool RecurrenceRule::operator==(const Kolab::RecurrenceRule &other) const
230 {
231 if ( d->freq == other.frequency() &&
232 d->weekstart == other.weekStart() &&
233 d->end == other.end() &&
234 d->count == other.count() &&
235 d->interval == other.interval() &&
236 d->bysecond == other.bysecond() &&
237 d->byminute == other.byminute() &&
238 d->byhour == other.byhour() &&
239 d->byday == other.byday() &&
240 d->bymonthday == other.bymonthday() &&
241 d->byyearday == other.byyearday() &&
242 d->byweekno == other.byweekno() &&
243 d->bymonth == other.bymonth()) {
244 return true;
245 }
246 return false;
247 }
248
~RecurrenceRule()249 RecurrenceRule::~RecurrenceRule()
250 {
251
252 }
253
setFrequency(RecurrenceRule::Frequency freq)254 void RecurrenceRule::setFrequency(RecurrenceRule::Frequency freq)
255 {
256 d->freq = freq;
257 }
258
frequency() const259 RecurrenceRule::Frequency RecurrenceRule::frequency() const
260 {
261 return d->freq;
262 }
263
setWeekStart(Kolab::Weekday weekstart)264 void RecurrenceRule::setWeekStart(Kolab::Weekday weekstart)
265 {
266 d->weekstart = weekstart;
267 }
268
weekStart() const269 Kolab::Weekday RecurrenceRule::weekStart() const
270 {
271 return d->weekstart;
272 }
273
setEnd(const Kolab::cDateTime & end)274 void RecurrenceRule::setEnd(const Kolab::cDateTime &end)
275 {
276 d->end = end;
277 }
278
end() const279 cDateTime RecurrenceRule::end() const
280 {
281 return d->end;
282 }
283
setCount(int count)284 void RecurrenceRule::setCount(int count)
285 {
286 d->count = count;
287 }
288
count() const289 int RecurrenceRule::count() const
290 {
291 return d->count;
292 }
293
setInterval(int interval)294 void RecurrenceRule::setInterval(int interval)
295 {
296 d->interval = interval;
297 }
298
interval() const299 int RecurrenceRule::interval() const
300 {
301 return d->interval;
302 }
303
setBysecond(const std::vector<int> & by)304 void RecurrenceRule::setBysecond(const std::vector< int >&by)
305 {
306 d->bysecond = by;
307 }
308
309
bysecond() const310 std::vector< int > RecurrenceRule::bysecond() const
311 {
312 return d->bysecond;
313 }
314
setByminute(const std::vector<int> & by)315 void RecurrenceRule::setByminute(const std::vector< int > &by)
316 {
317 d->byminute = by;
318 }
319
byminute() const320 std::vector< int > RecurrenceRule::byminute() const
321 {
322 return d->byminute;
323 }
324
setByhour(const std::vector<int> & by)325 void RecurrenceRule::setByhour(const std::vector< int > &by)
326 {
327 d->byhour = by;
328 }
329
byhour() const330 std::vector< int > RecurrenceRule::byhour() const
331 {
332 return d->byhour;
333 }
334
setByday(const std::vector<DayPos> & by)335 void RecurrenceRule::setByday(const std::vector< DayPos > &by)
336 {
337 d->byday = by;
338 }
339
byday() const340 std::vector< DayPos > RecurrenceRule::byday() const
341 {
342 return d->byday;
343 }
344
setBymonthday(const std::vector<int> & by)345 void RecurrenceRule::setBymonthday(const std::vector< int > &by)
346 {
347 d->bymonthday = by;
348 }
349
bymonthday() const350 std::vector< int > RecurrenceRule::bymonthday() const
351 {
352 return d->bymonthday;
353 }
354
setByyearday(const std::vector<int> & by)355 void RecurrenceRule::setByyearday(const std::vector< int > &by)
356 {
357 d->byyearday = by;
358 }
359
byyearday() const360 std::vector< int > RecurrenceRule::byyearday() const
361 {
362 return d->byyearday;
363 }
364
setByweekno(const std::vector<int> & by)365 void RecurrenceRule::setByweekno(const std::vector< int > &by)
366 {
367 d->byweekno = by;
368 }
369
byweekno() const370 std::vector< int > RecurrenceRule::byweekno() const
371 {
372 return d->byweekno;
373 }
374
setBymonth(const std::vector<int> & by)375 void RecurrenceRule::setBymonth(const std::vector< int > &by)
376 {
377 d->bymonth = by;
378 }
379
bymonth() const380 std::vector< int > RecurrenceRule::bymonth() const
381 {
382 return d->bymonth;
383 }
384
isValid() const385 bool RecurrenceRule::isValid() const
386 {
387 if (d->freq == FreqNone) {
388 return false;
389 }
390 return true;
391 }
392
393
394
395 struct Attendee::Private
396 {
PrivateKolab::Attendee::Private397 Private()
398 : partStat(PartNeedsAction),
399 role(Required),
400 rsvp(false),
401 cutype(CutypeIndividual)
402 {};
403
404 ContactReference contact;
405 PartStatus partStat;
406 Role role;
407 bool rsvp;
408 std::vector<ContactReference> delegatedTo;
409 std::vector<ContactReference> delegatedFrom;
410 Cutype cutype;
411 };
412
Attendee()413 Attendee::Attendee()
414 : d(new Attendee::Private)
415 {
416
417 }
418
Attendee(const ContactReference & contact)419 Attendee::Attendee(const ContactReference& contact)
420 : d(new Attendee::Private)
421 {
422 d->contact = contact;
423 }
424
Attendee(const Kolab::Attendee & other)425 Attendee::Attendee(const Kolab::Attendee &other)
426 : d(new Attendee::Private)
427 {
428 *d = *other.d;
429 }
430
operator =(const Kolab::Attendee & other)431 void Attendee::operator=(const Kolab::Attendee &other)
432 {
433 *d = *other.d;
434 }
435
~Attendee()436 Attendee::~Attendee()
437 {
438
439 }
440
operator ==(const Kolab::Attendee & other) const441 bool Attendee::operator==(const Kolab::Attendee &other) const
442 {
443 if ( d->contact == other.contact() &&
444 d->partStat == other.partStat() &&
445 d->role == other.role() &&
446 d->rsvp == other.rsvp() &&
447 d->delegatedTo == other.delegatedTo() &&
448 d->delegatedFrom == other.delegatedFrom() &&
449 d->cutype == other.cutype()
450 ) {
451 return true;
452 }
453 return false;
454 }
455
isValid() const456 bool Attendee::isValid() const
457 {
458 return d->contact.isValid();
459 };
460
setContact(const ContactReference & c)461 void Attendee::setContact(const ContactReference &c)
462 {
463 d->contact = c;
464 }
465
contact() const466 ContactReference Attendee::contact() const
467 {
468 return d->contact;
469 }
470
471
setPartStat(PartStatus partStat)472 void Attendee::setPartStat(PartStatus partStat)
473 {
474 d->partStat = partStat;
475 }
476
partStat() const477 PartStatus Attendee::partStat() const
478 {
479 return d->partStat;
480 }
481
setRole(Role role)482 void Attendee::setRole(Role role)
483 {
484 d->role = role;
485 }
486
role() const487 Role Attendee::role() const
488 {
489 return d->role;
490 }
491
setRSVP(bool rsvp)492 void Attendee::setRSVP(bool rsvp)
493 {
494 d->rsvp = rsvp;
495 }
496
rsvp() const497 bool Attendee::rsvp() const
498 {
499 return d->rsvp;
500 }
501
setDelegatedTo(const std::vector<ContactReference> & del)502 void Attendee::setDelegatedTo(const std::vector< ContactReference > &del)
503 {
504 d->delegatedTo = del;
505 }
506
delegatedTo() const507 std::vector< ContactReference > Attendee::delegatedTo() const
508 {
509 return d->delegatedTo;
510 }
511
setDelegatedFrom(const std::vector<ContactReference> & del)512 void Attendee::setDelegatedFrom(const std::vector< ContactReference > &del)
513 {
514 d->delegatedFrom = del;
515 }
516
delegatedFrom() const517 std::vector< ContactReference > Attendee::delegatedFrom() const
518 {
519 return d->delegatedFrom;
520 }
521
setCutype(Cutype type)522 void Attendee::setCutype(Cutype type)
523 {
524 d->cutype = type;
525 }
526
cutype() const527 Cutype Attendee::cutype() const
528 {
529 return d->cutype;
530 }
531
532
533 struct Attachment::Private
534 {
535 std::string uri;
536 std::string data;
537 std::string mimetype;
538 std::string label;
539 bool isValid;
540 };
541
Attachment()542 Attachment::Attachment()
543 : d(new Attachment::Private)
544 {
545 d->isValid = false;
546 }
547
Attachment(const Kolab::Attachment & other)548 Attachment::Attachment(const Kolab::Attachment &other)
549 : d(new Attachment::Private)
550 {
551 *d = *other.d;
552 }
553
operator =(const Kolab::Attachment & other)554 void Attachment::operator=(const Kolab::Attachment &other)
555 {
556 *d = *other.d;
557 }
558
~Attachment()559 Attachment::~Attachment()
560 {
561 }
562
operator ==(const Kolab::Attachment & other) const563 bool Attachment::operator==(const Kolab::Attachment &other) const
564 {
565 return ( d->uri == other.uri() &&
566 d->data == other.data() &&
567 d->label == other.label() &&
568 d->mimetype == other.mimetype() );
569 }
570
setUri(const std::string & uri,const std::string & mimetype)571 void Attachment::setUri(const std::string &uri, const std::string& mimetype)
572 {
573 d->isValid = true;
574 d->uri = uri;
575 d->mimetype = mimetype;
576 }
577
uri() const578 std::string Attachment::uri() const
579 {
580 return d->uri;
581 }
582
mimetype() const583 std::string Attachment::mimetype() const
584 {
585 return d->mimetype;
586 }
587
setLabel(const std::string & label)588 void Attachment::setLabel(const std::string &label)
589 {
590 d->label = label;
591 }
592
label() const593 std::string Attachment::label() const
594 {
595 return d->label;
596 }
597
setData(const std::string & data,const std::string & mimetype)598 void Attachment::setData(const std::string &data, const std::string& mimetype)
599 {
600 d->isValid = true;
601 d->data = data;
602 d->mimetype = mimetype;
603 }
604
data() const605 std::string Attachment::data() const
606 {
607 return d->data;
608 }
609
isValid() const610 bool Attachment::isValid() const
611 {
612 return d->isValid;
613 }
614
615
616
617 struct Alarm::Private
618 {
PrivateKolab::Alarm::Private619 Private(): relativeTo(Start),
620 numrepeat(0),
621 type(Alarm::InvalidAlarm) {};
622 std::string text;
623 Attachment audioFile;
624 std::string summary;
625 std::vector<ContactReference> attendees;
626 cDateTime start;
627 Duration relativeDuration;
628 Relative relativeTo;
629 Duration duration;
630 int numrepeat;
631 Type type;
632
633 };
634
Alarm()635 Alarm::Alarm()
636 : d(new Alarm::Private)
637 {
638 }
639
Alarm(Alarm::Type type)640 Alarm::Alarm(Alarm::Type type)
641 : d(new Alarm::Private)
642 {
643 d->type = AudioAlarm;
644 }
645
Alarm(const std::string & text)646 Alarm::Alarm(const std::string &text)
647 : d(new Alarm::Private)
648 {
649 d->text = text;
650 d->type = DisplayAlarm;
651 }
652
653
Alarm(const Kolab::Attachment & audio)654 Alarm::Alarm(const Kolab::Attachment& audio)
655 : d(new Alarm::Private)
656 {
657 d->audioFile = audio;
658 d->type = AudioAlarm;
659 }
660
Alarm(const std::string & summary,const std::string & description,const std::vector<ContactReference> attendees)661 Alarm::Alarm(const std::string& summary, const std::string& description, const std::vector<ContactReference> attendees)
662 : d(new Alarm::Private)
663 {
664 d->summary = summary;
665 d->text = description;
666 d->attendees = attendees;
667 d->type = EMailAlarm;
668
669 }
670
Alarm(const Kolab::Alarm & other)671 Alarm::Alarm(const Kolab::Alarm &other)
672 : d(new Alarm::Private)
673 {
674 *d = *other.d;
675 }
676
operator =(const Kolab::Alarm & other)677 void Alarm::operator=(const Kolab::Alarm &other)
678 {
679 *d = *other.d;
680 }
681
~Alarm()682 Alarm::~Alarm()
683 {
684 }
685
operator ==(const Kolab::Alarm & other) const686 bool Alarm::operator==(const Kolab::Alarm &other) const
687 {
688 return ( d->text == other.description() &&
689 d->text == other.description() &&
690 d->audioFile == other.audioFile() &&
691 d->summary == other.summary() &&
692 d->attendees == other.attendees() &&
693 d->start == other.start() &&
694 d->relativeDuration == other.relativeStart() &&
695 d->relativeTo == other.relativeTo() &&
696 d->duration == other.duration() &&
697 d->numrepeat == other.numrepeat() );
698 }
699
text() const700 std::string Alarm::text() const
701 {
702 return d->text;
703 }
704
audioFile() const705 Attachment Alarm::audioFile() const
706 {
707 return d->audioFile;
708 }
709
summary() const710 std::string Alarm::summary() const
711 {
712 return d->summary;
713 }
714
description() const715 std::string Alarm::description() const
716 {
717 return d->text;
718 }
719
attendees() const720 std::vector<ContactReference> Alarm::attendees() const
721 {
722 return d->attendees;
723 }
724
setStart(const Kolab::cDateTime & start)725 void Alarm::setStart(const Kolab::cDateTime &start)
726 {
727 d->start = start;
728 }
729
start() const730 cDateTime Alarm::start() const
731 {
732 return d->start;
733 }
734
setRelativeStart(const Kolab::Duration & duration,Relative relativeTo)735 void Alarm::setRelativeStart(const Kolab::Duration &duration, Relative relativeTo)
736 {
737 d->relativeDuration = duration;
738 d->relativeTo = relativeTo;
739 }
740
relativeStart() const741 Duration Alarm::relativeStart() const
742 {
743 return d->relativeDuration;
744 }
745
relativeTo() const746 Relative Alarm::relativeTo() const
747 {
748 return d->relativeTo;
749 }
750
setDuration(const Kolab::Duration & duration,int numrepeat)751 void Alarm::setDuration(const Kolab::Duration &duration, int numrepeat)
752 {
753 d->numrepeat = numrepeat;
754 d->duration = duration;
755 }
756
duration() const757 Duration Alarm::duration() const
758 {
759 return d->duration;
760 }
761
numrepeat() const762 int Alarm::numrepeat() const
763 {
764 return d->numrepeat;
765 }
766
type() const767 Alarm::Type Alarm::type() const
768 {
769 return d->type;
770 }
771
772
773
774
775
776
777 }//Namespace
778