summaryrefslogtreecommitdiff
path: root/src/libical/vcomponent_cxx.cpp
blob: ed34ecab01e51cb1cd544653489072d6caa5cd8e (plain)
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
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
/**
 * @file    vcomponent_cxx.cpp
 * @author  fnguyen (12/10/01)
 * @brief   Implementation of C++ Wrapper for icalcomponent.c
 *
 * (C) COPYRIGHT 2001, Critical Path

 This library is free software; you can redistribute it and/or modify
 it under the terms of either:

    The LGPL as published by the Free Software Foundation, version
    2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html

 Or:

    The Mozilla Public License Version 2.0. You may obtain a copy of
    the License at http://www.mozilla.org/MPL/
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "vcomponent_cxx.h"
#include "icalparameter_cxx.h"
#include "icalproperty_cxx.h"
#include "icalvalue_cxx.h"
using namespace LibICal;

extern "C" {
#include "icalmemory.h"
}

#include <cstdlib>

VComponent::VComponent() : imp(icalcomponent_new(ICAL_ANY_COMPONENT))
{
}

VComponent::VComponent(const VComponent &v) : imp(icalcomponent_new_clone(v.imp))
{
    if (imp == NULL) {
        throw icalerrno;
    }
}

VComponent &VComponent::operator=(const VComponent &v)
{
    if (this == &v) {
        return *this;
    }

    if (imp != NULL) {
        icalcomponent_free(imp);
        imp = icalcomponent_new_clone(v.imp);
        if (imp == NULL) {
            throw icalerrno;
        }
    }

    return *this;
}

void VComponent::detach()
{
    imp = NULL;
}

VComponent::~VComponent()
{
    if (imp != NULL) {
        icalcomponent_free(imp);
    }
}

VComponent::VComponent(icalcomponent *v) : imp(v)
{
}

/* char* returned is in the ring buffer. caller doesn't have to free it */
char *VComponent::quote_ical_string(char *str)
{
    const char *p;
    size_t  buf_sz;
    buf_sz = strlen(str) * 2; // assume worse case scenarios.
    // otherwise, we have to parse the string and count \ */
    char *out = static_cast<char *>(icalmemory_new_buffer(buf_sz)); /* memory from the ring buf */
    char *pout;

    if (out == 0) {
        return 0;
    }

    pout = out;

    for (p = str; *p != 0; p++) {

        if (*p == '\\') {
            *pout++ = '\\';
        }
        *pout++ = *p;
    }
    *pout++ = '\0';

    return out;
}

/**
 * @brief Constructor
 *
 * Create a new VComponent from a string.
 *
 * @exception ICAL_MALFORMEDDATA_ERROR
 *            Catch this error if you
 *
 */
VComponent::VComponent(const std::string &str)
    : imp(icalcomponent_new_from_string(str.c_str()))
{
    if (imp == NULL) {
        if (! icalerrno) {
            icalerrno = ICAL_BADARG_ERROR;
        }
        throw icalerrno;
    }
}

VComponent::VComponent(const icalcomponent_kind &kind) : imp(icalcomponent_new(kind))
{
    if (imp == NULL) {
        throw icalerrno;
    }
}

std::string VComponent::as_ical_string()
{
    char *str = icalcomponent_as_ical_string(imp);

    if (str == NULL) {
        throw icalerrno;
    }

    return (str);
}

bool VComponent::is_valid()
{
    if (imp == NULL) {
        return false;
    }
    return (icalcomponent_is_valid(imp) != 0);
}

icalcomponent_kind VComponent::isa()
{
    return icalcomponent_isa(imp);
}

int VComponent::isa_component(void *component)
{
    return icalcomponent_isa_component(component);
}

void VComponent::new_from_string(const std::string &str)
{
    if (imp != NULL) {
        icalcomponent_free(imp);
    }
    imp = icalcomponent_new_from_string(str.c_str());
}

/* Working with properties */
void VComponent::add_property(ICalProperty *property)
{
    icalcomponent_add_property(imp, *property);
}

void VComponent::remove_property(ICalProperty *property)
{
    icalcomponent_remove_property(imp, *property);
    icalproperty_free(*property);
    property->detach();     // set imp to null, it's free already.
}

int VComponent::count_properties(const icalproperty_kind &kind)
{
    return icalcomponent_count_properties(imp, kind);
}

/* Iterate through the properties */
ICalProperty *VComponent::get_current_property()
{
    icalproperty *t = icalcomponent_get_current_property(imp);
    return ((t != NULL) ? new ICalProperty(t) : NULL);
}

ICalProperty *VComponent::get_first_property(const icalproperty_kind &kind)
{
    icalproperty *t = icalcomponent_get_first_property(imp, kind);
    return ((t != NULL) ? new ICalProperty(t) : NULL);
}

ICalProperty *VComponent::get_next_property(const icalproperty_kind &kind)
{
    icalproperty *t = icalcomponent_get_next_property(imp, kind);
    return ((t != NULL) ? new ICalProperty(t) : NULL);
}

/* Working with components */
/* Return the first VEVENT, VTODO or VJOURNAL sub-component if it is one of those types */
VComponent *VComponent::get_inner()
{
    return new VComponent(icalcomponent_get_inner(imp));
}

void VComponent::add_component(VComponent *child)
{
    icalcomponent_add_component(imp, *child);
}

void VComponent::remove_component(VComponent *child)
{
    icalcomponent_remove_component(imp, *child);
}

int VComponent::count_components(const icalcomponent_kind &kind)
{
    return  icalcomponent_count_components(imp, kind);
}

/* Iteration Routines. There are two forms of iterators, internal and
   external. The internal ones came first, and are almost completely
   sufficient, but they fail badly when you want to construct a loop that
   removes components from the container.
*/

/* Iterate through components */
VComponent *VComponent::get_current_component()
{
    icalcomponent *t = icalcomponent_get_current_component(imp);
    return ((t != NULL) ? new VComponent(t) : NULL);
}

VComponent *VComponent::get_first_component(const icalcomponent_kind &kind)
{
    VComponent *result = NULL;
    icalcomponent *t = icalcomponent_get_first_component(imp, kind);
    if (t != NULL) {
        switch (kind) {
        case ICAL_VALARM_COMPONENT:
            result = new VAlarm(t);
            break;
        case ICAL_VCALENDAR_COMPONENT:
            result = new VCalendar(t);
            break;
        case ICAL_VEVENT_COMPONENT:
            result = new VEvent(t);
            break;
        case ICAL_VQUERY_COMPONENT:
            result = new VQuery(t);
            break;
        case ICAL_VTODO_COMPONENT:
            result = new VToDo(t);
            break;
        case ICAL_VAGENDA_COMPONENT:
            result = new VAgenda(t);
            break;
        default:
            result = new VComponent(t);
        }
    }

    return (result);
}

VComponent *VComponent::get_next_component(const icalcomponent_kind &kind)
{
    VComponent *result = NULL;
    icalcomponent *t = icalcomponent_get_next_component(imp, kind);
    if (t != NULL) {
        switch (kind) {
        case ICAL_VALARM_COMPONENT:
            result = new VAlarm(t);
            break;
        case ICAL_VCALENDAR_COMPONENT:
            result = new VCalendar(t);
            break;
        case ICAL_VEVENT_COMPONENT:
            result = new VEvent(t);
            break;
        case ICAL_VQUERY_COMPONENT:
            result = new VQuery(t);
            break;
        case ICAL_VTODO_COMPONENT:
            result = new VToDo(t);
            break;
        case ICAL_VAGENDA_COMPONENT:
            result = new VAgenda(t);
            break;
        default:
            result = new VComponent(t);
        }
    }

    return (result);
}

/* Using external iterators */
icalcompiter VComponent::begin_component(const icalcomponent_kind &kind)
{
    return icalcomponent_begin_component(imp, kind);
}

icalcompiter VComponent::end_component(const icalcomponent_kind &kind)
{
    return icalcomponent_end_component(imp, kind);
}

VComponent *VComponent::next(icalcompiter *i)
{
    return reinterpret_cast<VComponent *>(icalcompiter_next(i));
}

VComponent *VComponent::prev(icalcompiter *i)
{
    return reinterpret_cast<VComponent *>(icalcompiter_prior(i));
}

VComponent *VComponent::current(icalcompiter *i)
{
    return reinterpret_cast<VComponent *>(icalcompiter_deref(i));
}

/* Working with embedded error properties */
int VComponent::count_errors()
{
    return icalcomponent_count_errors(imp);
}

/* Remove all X-LIC-ERROR properties*/
void VComponent::strip_errors()
{
    icalcomponent_strip_errors(imp);
}

/* Convert some X-LIC-ERROR properties into RETURN-STATUS properties*/
void VComponent::convert_errors()
{
    icalcomponent_convert_errors(imp);
}

/* Kind conversion routines */
icalcomponent_kind VComponent::string_to_kind(const std::string &str)
{
    return icalcomponent_string_to_kind(str.c_str());
}

std::string VComponent::kind_to_string(const icalcomponent_kind &kind)
{
    return static_cast<std::string>(icalcomponent_kind_to_string(kind));
}

struct icaltimetype VComponent::get_dtstart() const {
    return icalcomponent_get_dtstart(imp);
}

void VComponent::set_dtstart(const struct icaltimetype &v)
{
    icalcomponent_set_dtstart(imp, v);
}

/* For the icalcomponent routines only, dtend and duration are tied
   together. If you call the set routine for one and the other exists,
   the routine will calculate the change to the other. That is, if
   there is a DTEND and you call set_duration, the routine will modify
   DTEND to be the sum of DTSTART and the duration. If you call a get
   routine for one and the other exists, the routine will calculate
   the return value. If you call a set routine and neither exists, the
   routine will create the apcompriate comperty.
*/

struct icaltimetype VComponent::get_dtend() const {
    return icalcomponent_get_dtend(imp);
}

void VComponent::set_dtend(const struct icaltimetype &v)
{
    icalcomponent_set_dtend(imp, v);
}

struct icaltimetype VComponent::get_due() const {
    return icalcomponent_get_due(imp);
}

void VComponent::set_due(const struct icaltimetype &v)
{
    icalcomponent_set_due(imp, v);
}

struct icaldurationtype VComponent::get_duration() const {
    return icalcomponent_get_duration(imp);
}

void VComponent::set_duration(const struct icaldurationtype &v)
{
    icalcomponent_set_duration(imp, v);
}

icalproperty_method VComponent::get_method() const
{
    return icalcomponent_get_method(imp);
}

void VComponent::set_method(const icalproperty_method &method)
{
    icalcomponent_set_method(imp, method);
}

struct icaltimetype VComponent::get_dtstamp() const {
    return icalcomponent_get_dtstamp(imp);
}

void VComponent::set_dtstamp(const struct icaltimetype &v)
{
    icalcomponent_set_dtstamp(imp, v);
}

std::string VComponent::get_summary() const
{
    return static_cast<std::string>(icalcomponent_get_summary(imp));
}

void VComponent::set_summary(const std::string &v)
{
    icalcomponent_set_summary(imp, v.c_str());
}

std::string VComponent::get_location() const
{
    return static_cast<std::string>(icalcomponent_get_location(imp));
}

void VComponent::set_location(const std::string &v)
{
    icalcomponent_set_location(imp, v.c_str());
}

std::string VComponent::get_description() const
{
    return static_cast<std::string>(icalcomponent_get_description(imp));
}

void VComponent::set_description(const std::string &v)
{
    icalcomponent_set_description(imp, v.c_str());
}

std::string VComponent::get_comment() const
{
    return static_cast<std::string>(icalcomponent_get_comment(imp));
}

void VComponent::set_comment(const std::string &v)
{
    icalcomponent_set_comment(imp, v.c_str());
}

std::string VComponent::get_uid() const
{
    return static_cast<std::string>(icalcomponent_get_uid(imp));
}

void VComponent::set_uid(const std::string &v)
{
    icalcomponent_set_uid(imp, v.c_str());
}

std::string VComponent::get_relcalid() const
{
    return static_cast<std::string>(icalcomponent_get_relcalid(imp));
}

void VComponent::set_relcalid(const std::string &v)
{
    icalcomponent_set_relcalid(imp, v.c_str());
}

struct icaltimetype VComponent::get_recurrenceid() const {
    return icalcomponent_get_recurrenceid(imp);
}

void VComponent::set_recurrenceid(const struct icaltimetype &v)
{
    icalcomponent_set_recurrenceid(imp, v);
}

int VComponent::get_sequence() const
{
    return icalcomponent_get_sequence(imp);
}

void VComponent::set_sequence(const int &v)
{
    icalcomponent_set_sequence(imp, v);
}

int VComponent::get_status() const
{
    return icalcomponent_get_status(imp);
}

void VComponent::set_status(const enum icalproperty_status &v)
{
    icalcomponent_set_status(imp, v);
}

/* For VCOMPONENT: Return a reference to the first VEVENT, VTODO, or VJOURNAL */
VComponent *VComponent::get_first_real_component()
{
    return reinterpret_cast<VComponent *>(icalcomponent_get_first_real_component(imp));
}

/* For VEVENT, VTODO, VJOURNAL and VTIMEZONE: report the start and end
   times of an event in UTC */
struct icaltime_span VComponent::get_span()
{
    return icalcomponent_get_span(imp);
}

int VComponent::recurrence_is_excluded(struct icaltimetype *dtstart,
                                       struct icaltimetype *recurtime)
{
    return  icalproperty_recurrence_is_excluded(imp, dtstart, recurtime);
}

/* Internal operations. They are private, and you should not be using them. */
VComponent *VComponent::get_parent()
{
    return new VComponent(icalcomponent_get_parent(imp));
}

void VComponent::set_parent(VComponent *parent)
{
    icalcomponent_set_parent(imp, *parent);
}

/* ignoreValue means remove properties even if the data doesn't match */
bool VComponent::remove(VComponent &fromVC, bool ignoreValue)
{
    /* the two components must be the same kind */
    if (this->isa() != fromVC.isa()) {
        return false;
    }

    /* properties first */
    ICalPropertyTmpPtr propToBeRemoved;
    for (propToBeRemoved = fromVC.get_first_property(ICAL_ANY_PROPERTY);
         propToBeRemoved != NULL;
         propToBeRemoved = fromVC.get_next_property(ICAL_ANY_PROPERTY)) {

        /* loop through properties from this component */
        ICalPropertyTmpPtr next;
        ICalPropertyTmpPtr p;
        for (p = this->get_first_property(propToBeRemoved->isa()); p != NULL; p = next) {
            next = this->get_next_property(propToBeRemoved->isa());
            if (ignoreValue) {
                this->remove_property(p);
            } else {
                if (p == propToBeRemoved) {
                    this->remove_property(p);
                    break;
                }
            }
        }
    }

    /* components next - should remove by UID */
    VComponentTmpPtr comp;
    for (comp = fromVC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL;
         comp = fromVC.get_next_component(ICAL_ANY_COMPONENT)) {
        const std::string fromCompUid = comp->get_uid();
        VComponentTmpPtr c;
        for (c = this->get_first_component(comp->isa()); c != NULL;
             c = this->get_next_component(comp->isa())) {
            if (strcmp(fromCompUid.c_str(), c->get_uid().c_str()) == 0) {
                // recursively go down the components
                c->remove(*comp, ignoreValue);
                // if all properties are removed and there is no sub-components, then
                // remove this compoent
                if ((c->count_properties(ICAL_ANY_PROPERTY) == 0) &&
                    (c->count_components(ICAL_ANY_COMPONENT) == 0)) {
                    this->remove_component(c);
                }
                break;
            }
        }
    }

    return true;
}

/* removeMissing == true: remove properties that are missing from fromC */
/* todo: only change the first occurrence of the property */
/* todo: removeMissing is not implemented */
bool VComponent::update(VComponent &fromC, bool removeMissing)
{
    /* make sure they are the same kind */
    if (this->isa() != fromC.isa()) {
        return false;
    }

    /* property first */
    ICalPropertyTmpPtr prop;
    for (prop = fromC.get_first_property(ICAL_ANY_PROPERTY); prop != NULL;
         prop = fromC.get_next_property(ICAL_ANY_PROPERTY)) {
        ICalPropertyTmpPtr thisProp;
        thisProp = this->get_first_property(prop->isa());
        if (thisProp == NULL) {
            thisProp = new ICalProperty(prop->isa());
            this->add_property(thisProp);
        }
        ICalValue *tempValue = prop->get_value();
        ICalValue *value = new ICalValue(*tempValue); // clone the value
        thisProp->set_value(*value);
        delete tempValue;
        delete value;
    }

    /* recursively updating sub-components */
    VComponentTmpPtr comp;
    for (comp = fromC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL;
         comp = fromC.get_next_component(ICAL_ANY_COMPONENT)) {
        VComponentTmpPtr thisComp;
        thisComp = this->get_first_component(comp->isa());
        if (thisComp == NULL) {
            thisComp = new VComponent(comp->isa());
            this->add_component(thisComp);
        }
        bool err = thisComp->update(*comp, removeMissing);
        if (!err) {
            return false;
        }
    }
    return true;
}

/* add components and property. recursively goes down child components */
bool VComponent::add(VComponent &fromC)
{
    /* make sure the kind are the same */
    if (this->isa() != fromC.isa()) {
        return false;
    }

    /* properties first */
    ICalPropertyTmpPtr prop;
    for (prop = fromC.get_first_property(ICAL_ANY_PROPERTY); prop != NULL;
         prop = fromC.get_next_property(ICAL_ANY_PROPERTY)) {
        /* clone another property */
        ICalProperty *p = new ICalProperty(*prop);
        add_property(p);
        delete p;
    }

    /* sub-components next */
    bool err = false;
    VComponentTmpPtr comp;
    for (comp = fromC.get_first_component(ICAL_ANY_COMPONENT); comp != NULL;
         comp = fromC.get_next_component(ICAL_ANY_COMPONENT)) {
        VComponent *c = new VComponent(comp->isa());
        err = c->add(*comp);
        _unused(err);
        add_component(c);
        delete c;
    }

    return true;
}

VCalendar::VCalendar() : VComponent(icalcomponent_new_vcalendar())
{
}

VCalendar::VCalendar(const VCalendar &v) : VComponent(v)
{
}

VCalendar &VCalendar::operator=(const VCalendar &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VCalendar::~VCalendar()
{
}

VCalendar::VCalendar(icalcomponent *v) : VComponent(v)
{
}

VCalendar::VCalendar(const std::string &str) : VComponent(str)
{
}

/* VEvent */

VEvent::VEvent() : VComponent(icalcomponent_new_vevent())
{
}

VEvent::VEvent(const VEvent &v) : VComponent(v)
{
}

VEvent &VEvent::operator=(const VEvent &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VEvent::~VEvent()
{
}

VEvent::VEvent(icalcomponent *v) : VComponent(v)
{
}

VEvent::VEvent(const std::string &str) : VComponent(str)
{
}

/* VTodo */

VToDo::VToDo() : VComponent(icalcomponent_new_vtodo())
{
}

VToDo::VToDo(const VToDo &v) : VComponent(v)
{
}

VToDo &VToDo::operator=(const VToDo &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VToDo::~VToDo()
{
}

VToDo::VToDo(icalcomponent *v) : VComponent(v)
{
}

VToDo::VToDo(const std::string &str) : VComponent(str)
{
}

/* VAgenda */

VAgenda::VAgenda() : VComponent(icalcomponent_new_vagenda())
{
}

VAgenda::VAgenda(const VAgenda &v) : VComponent(v)
{
}

VAgenda &VAgenda::operator=(const VAgenda &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VAgenda::~VAgenda()
{
}

VAgenda::VAgenda(icalcomponent *v) : VComponent(v)
{
}

VAgenda::VAgenda(const std::string &str) : VComponent(str)
{
}

/* VQuery */

VQuery::VQuery() : VComponent(icalcomponent_new_vquery())
{
}

VQuery::VQuery(const VQuery &v) : VComponent(v)
{
}

VQuery &VQuery::operator=(const VQuery &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VQuery::~VQuery()
{
}

VQuery::VQuery(icalcomponent *v) : VComponent(v)
{
}

VQuery::VQuery(const std::string &str) : VComponent(str)
{
}

/* VJournal */

VJournal::VJournal() : VComponent(icalcomponent_new_vjournal())
{
}

VJournal::VJournal(const VJournal &v) : VComponent(v)
{
}

VJournal &VJournal::operator=(const VJournal &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VJournal::~VJournal()
{
}

VJournal::VJournal(icalcomponent *v) : VComponent(v)
{
}

VJournal::VJournal(const std::string &str) : VComponent(str)
{
}

/* VAlarm */

VAlarm::VAlarm() : VComponent(icalcomponent_new_valarm())
{
}

VAlarm::VAlarm(const VAlarm &v) : VComponent(v)
{
}

VAlarm &VAlarm::operator=(const VAlarm &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VAlarm::~VAlarm()
{
}

VAlarm::VAlarm(icalcomponent *v) : VComponent(v)
{
}

VAlarm::VAlarm(const std::string &str) : VComponent(str)
{
}

icalrequeststatus VAlarm::getTriggerTime(VComponent &c, struct icaltriggertype *tr)
{
    ICalPropertyTmpPtr trigger_prop = this->get_first_property(ICAL_TRIGGER_PROPERTY);

    // all VALARMs must have a TRIGGER
    if (trigger_prop == NULL) {
        return ICAL_3_1_INVPROPVAL_STATUS;
    }

    *tr = trigger_prop->get_trigger();

    if (icaltime_is_null_time(tr->time) == 1) {
        struct icaltimetype tt = icaltime_null_time();

        // relative time trigger

        // TRIGGER;RELATED=END:P5M 5 minutes after END
        // TRIGGER;RELATED=START:-P15M 15 minutes before START
        // get RELATED parameter

        ICalParameter *related_param = trigger_prop->get_first_parameter(ICAL_RELATED_PARAMETER);

        if ((related_param != NULL) && related_param->is_valid()) {

            // get RELATED parameter value
            icalparameter_related related = related_param->get_related();

            if (related != 0) {
                switch (related) {
                case ICAL_RELATED_END:
                    if (c.isa() == ICAL_VEVENT_COMPONENT) {
                        tt = c.get_dtend();

                        // If a recurrenceid exists, use that to calculate the
                        // dtend from the dtstart.
                        struct icaltimetype recur_time = c.get_recurrenceid();
                        if (icaltime_is_null_time(recur_time) != 1) {
                            struct icaldurationtype dur = icaltime_subtract(c.get_dtstart(), tt);
                            tt = icaltime_add(recur_time, dur);
                        }
                    } else if (c.isa() == ICAL_VTODO_COMPONENT) {
                        tt = c.get_due();
                        struct icaltimetype recur_time = c.get_recurrenceid();
                        if (icaltime_is_null_time(recur_time) != 1) {
                            tt = recur_time;
                        }
                    }
                    // @@@ TODO: if not DTEND or DUE, then DTSTART and DURATION must be present
                    break;
                case ICAL_RELATED_START:
                case ICAL_RELATED_X:
                case ICAL_RELATED_NONE:
                default:
                    tt = c.get_dtstart();
                    struct icaltimetype recur_time = c.get_recurrenceid();
                    if (icaltime_is_null_time(recur_time) != 1) {
                        tt = recur_time;
                    }
                    break;
                }
            }
        } else { // no RELATED explicitly specified, the default is
            // relative to the start of an event or to-do, rfc2445
            // if no RELATED, we are forced to use dtstart for VEVENT,
            // due for VTODO to calculate trigger time.
            // If a recur time exists, use that. Recur time trumps dtstart or due.
            struct icaltimetype recur_time = c.get_recurrenceid();
            if (icaltime_is_null_time(recur_time) != 1) {
                tt = recur_time;
            } else if (c.isa() == ICAL_VEVENT_COMPONENT) {
                tt = c.get_dtstart();
            } else if (c.isa() == ICAL_VTODO_COMPONENT) {
                tt = c.get_due();
            }
        }

        if (related_param != NULL) {
            free(related_param);
        }

        // malformed? encapsulating VEVENT or VTODO MUST have DTSTART/DTEND
        if (icaltime_is_null_time(tt) == 1) {
            return ICAL_3_1_INVPROPVAL_STATUS;
        };

        // now offset using tr.duration
        tr->time = icaltime_add(tt, tr->duration);
    }
    // else absolute time trigger

    return ICAL_2_0_SUCCESS_STATUS;
}

/* VFreeBusy */

VFreeBusy::VFreeBusy() : VComponent(icalcomponent_new_vfreebusy())
{
}

VFreeBusy::VFreeBusy(const VFreeBusy &v) : VComponent(v)
{
}

VFreeBusy &VFreeBusy::operator=(const VFreeBusy &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VFreeBusy::~VFreeBusy()
{
}

VFreeBusy::VFreeBusy(icalcomponent *v) : VComponent(v)
{
}

VFreeBusy::VFreeBusy(const std::string &str) : VComponent(str)
{
}

/* VTimezone */

VTimezone::VTimezone() : VComponent(icalcomponent_new_vtimezone())
{
}

VTimezone::VTimezone(const VTimezone &v) : VComponent(v)
{
}

VTimezone &VTimezone::operator=(const VTimezone &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

VTimezone::~VTimezone()
{
}

VTimezone::VTimezone(icalcomponent *v) : VComponent(v)
{
}

VTimezone::VTimezone(const std::string &str) : VComponent(str)
{
}

/* XStandard */

XStandard::XStandard() : VComponent(icalcomponent_new_xstandard())
{
}

XStandard::XStandard(const XStandard &v) : VComponent(v)
{
}

XStandard &XStandard::operator=(const XStandard &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

XStandard::~XStandard()
{
}

XStandard::XStandard(icalcomponent *v) : VComponent(v)
{
}

XStandard::XStandard(const std::string &str) : VComponent(str)
{
}

/* XDaylight */

XDaylight::XDaylight() : VComponent(icalcomponent_new_xdaylight())
{
}

XDaylight::XDaylight(const XDaylight &v) : VComponent(v)
{
}

XDaylight &XDaylight::operator=(const XDaylight &v)
{
    if (this == &v) {
        return *this;
    }
    VComponent::operator=(v);

    return *this;
}

XDaylight::~XDaylight()
{
}

XDaylight::XDaylight(icalcomponent *v) : VComponent(v)
{
}

XDaylight::XDaylight(const std::string &str) : VComponent(str)
{
}