1
mod alarm;
2
mod daylight;
3
mod event;
4
mod free_busy;
5
mod iana_component;
6
mod journal;
7
mod standard;
8
mod time_zone;
9
mod todo;
10
mod x_component;
11

            
12
pub use crate::model::component::daylight::DaylightComponent;
13
pub use crate::model::component::standard::StandardComponent;
14
pub use alarm::{
15
    AddAlarmComponent, AlarmComponent, AudioAlarmComponentBuilder, DisplayAlarmComponentBuilder,
16
    EmailAlarmComponentBuilder,
17
};
18
pub use event::{EventComponent, EventComponentBuilder};
19
pub use free_busy::{FreeBusyComponent, FreeBusyComponentBuilder};
20
pub use iana_component::{IanaComponent, IanaComponentBuilder};
21
pub use journal::{JournalComponent, JournalComponentBuilder};
22
pub use time_zone::{TimeZoneComponent, TimeZoneComponentBuilder};
23
pub use todo::{ToDoComponent, ToDoComponentBuilder};
24
pub use x_component::{XComponent, XComponentBuilder};
25

            
26
#[derive(Debug, PartialEq)]
27
pub enum CalendarComponent {
28
    Event(EventComponent),
29
    ToDo(ToDoComponent),
30
    Journal(JournalComponent),
31
    FreeBusy(FreeBusyComponent),
32
    TimeZone(TimeZoneComponent),
33
    Standard(StandardComponent),
34
    Daylight(DaylightComponent),
35
    Alarm(AlarmComponent),
36
    IanaComponent(IanaComponent),
37
    XComponent(XComponent),
38
}
39

            
40
impl ComponentAccess for CalendarComponent {
41
68
    fn properties(&self) -> &[ComponentProperty] {
42
68
        match self {
43
            CalendarComponent::Event(e) => &e.properties,
44
            CalendarComponent::ToDo(t) => &t.properties,
45
            CalendarComponent::Journal(j) => &j.properties,
46
            CalendarComponent::FreeBusy(f) => &f.properties,
47
            CalendarComponent::TimeZone(tz) => &tz.properties,
48
6
            CalendarComponent::Standard(s) => &s.properties,
49
            CalendarComponent::Daylight(d) => &d.properties,
50
62
            CalendarComponent::Alarm(a) => &a.properties,
51
            CalendarComponent::IanaComponent(i) => &i.properties,
52
            CalendarComponent::XComponent(x) => &x.properties,
53
        }
54
68
    }
55
}
56

            
57
macro_rules! impl_finish_component_build {
58
    ($ev:expr) => {
59
92
        pub fn finish_component(mut self) -> $crate::model::object::ICalObjectBuilder {
60
92
            self.owner.inner.components.push($ev(self.inner));
61
92
            self.owner
62
92
        }
63
    };
64
}
65

            
66
pub(crate) use impl_finish_component_build;
67

            
68
macro_rules! impl_other_component_properties {
69
    ($x_builder:ident, $iana_builder:ident, $inner:ty) => {
70
56
        pub fn add_x_property<N: ToString, V: ToString>(
71
56
            self,
72
56
            name: N,
73
56
            value: V,
74
56
        ) -> $x_builder<$inner> {
75
56
            $x_builder::new(self, name.to_string(), value.to_string())
76
56
        }
77

            
78
56
        pub fn add_iana_property<N: ToString, V: ToString>(
79
56
            self,
80
56
            name: N,
81
56
            value: V,
82
56
        ) -> $iana_builder<$inner> {
83
56
            $iana_builder::new(self, name.to_string(), value.to_string())
84
56
        }
85
    };
86
}
87

            
88
pub(crate) use impl_other_component_properties;
89

            
90
macro_rules! add_date_time_stamp {
91
    () => {
92
50
        pub fn add_date_time_stamp(
93
50
            self,
94
50
            date: time::Date,
95
50
            time: time::Time,
96
50
        ) -> $crate::model::property::DateTimeStampPropertyBuilder<Self> {
97
50
            $crate::model::property::DateTimeStampPropertyBuilder::new(self, date, time)
98
50
        }
99
    };
100
}
101

            
102
pub(crate) use add_date_time_stamp;
103

            
104
macro_rules! add_unique_identifier {
105
    () => {
106
18
        pub fn add_unique_identifier<V: ToString>(
107
18
            self,
108
18
            value: V,
109
18
        ) -> $crate::model::property::UniqueIdentifierPropertyBuilder<Self> {
110
18
            $crate::model::property::UniqueIdentifierPropertyBuilder::new(self, value.to_string())
111
18
        }
112
    };
113
}
114

            
115
pub(crate) use add_unique_identifier;
116

            
117
macro_rules! add_class {
118
    () => {
119
38
        pub fn add_classification(
120
38
            self,
121
38
            value: $crate::model::property::Classification,
122
38
        ) -> $crate::model::property::ClassificationPropertyBuilder<Self> {
123
38
            $crate::model::property::ClassificationPropertyBuilder::new(self, value)
124
38
        }
125
    };
126
}
127

            
128
pub(crate) use add_class;
129

            
130
macro_rules! add_created {
131
    () => {
132
38
        pub fn add_date_time_created(
133
38
            self,
134
38
            date: time::Date,
135
38
            time: time::Time,
136
38
        ) -> $crate::model::property::CreatedPropertyBuilder<Self> {
137
38
            $crate::model::property::CreatedPropertyBuilder::new(self, date, time)
138
38
        }
139
    };
140
}
141

            
142
pub(crate) use add_created;
143

            
144
macro_rules! add_description {
145
    () => {
146
26
        pub fn add_description<V: ToString>(
147
26
            self,
148
26
            value: V,
149
26
        ) -> $crate::model::property::DescriptionPropertyBuilder<Self> {
150
26
            $crate::model::property::DescriptionPropertyBuilder::new(self, value.to_string())
151
26
        }
152
    };
153
}
154

            
155
pub(crate) use add_description;
156

            
157
macro_rules! add_date_time_start {
158
    () => {
159
74
        pub fn add_date_time_start(
160
74
            self,
161
74
            date: time::Date,
162
74
            time: Option<time::Time>,
163
74
        ) -> $crate::model::property::DateTimeStartPropertyBuilder<Self> {
164
74
            $crate::model::property::DateTimeStartPropertyBuilder::new(self, date, time)
165
74
        }
166
    };
167
}
168

            
169
pub(crate) use add_date_time_start;
170

            
171
macro_rules! add_geographic_position {
172
    () => {
173
26
        pub fn add_geographic_position(
174
26
            self,
175
26
            latitude: f64,
176
26
            longitude: f64,
177
26
        ) -> $crate::model::property::GeographicPositionPropertyBuilder<Self> {
178
26
            $crate::model::property::GeographicPositionPropertyBuilder::new(
179
26
                self, latitude, longitude,
180
26
            )
181
26
        }
182
    };
183
}
184

            
185
pub(crate) use add_geographic_position;
186

            
187
macro_rules! add_last_modified {
188
    () => {
189
50
        pub fn add_last_modified(
190
50
            self,
191
50
            date: time::Date,
192
50
            time: time::Time,
193
50
        ) -> $crate::model::property::LastModifiedPropertyBuilder<Self> {
194
50
            $crate::model::property::LastModifiedPropertyBuilder::new(self, date, time)
195
50
        }
196
    };
197
}
198

            
199
pub(crate) use add_last_modified;
200

            
201
macro_rules! add_location {
202
    () => {
203
24
        pub fn add_location(
204
24
            self,
205
24
            value: &str,
206
24
        ) -> $crate::model::property::LocationPropertyBuilder<Self> {
207
24
            $crate::model::property::LocationPropertyBuilder::new(self, value.to_string())
208
24
        }
209
    };
210
}
211

            
212
pub(crate) use add_location;
213

            
214
macro_rules! add_organizer {
215
    () => {
216
50
        pub fn add_organizer(
217
50
            self,
218
50
            value: &str,
219
50
        ) -> $crate::model::property::OrganizerPropertyBuilder<Self> {
220
50
            $crate::model::property::OrganizerPropertyBuilder::new(self, value.to_string())
221
50
        }
222
    };
223
}
224

            
225
pub(crate) use add_organizer;
226

            
227
macro_rules! add_priority {
228
    () => {
229
26
        pub fn add_priority(
230
26
            self,
231
26
            value: u8,
232
26
        ) -> $crate::model::property::PriorityPropertyBuilder<Self> {
233
26
            $crate::model::property::PriorityPropertyBuilder::new(self, value)
234
26
        }
235
    };
236
}
237

            
238
pub(crate) use add_priority;
239

            
240
macro_rules! add_recurrence_id {
241
    () => {
242
38
        pub fn add_recurrence_id(
243
38
            self,
244
38
            date: time::Date,
245
38
            time: Option<time::Time>,
246
38
        ) -> $crate::model::property::RecurrenceIdPropertyBuilder<Self> {
247
38
            $crate::model::property::RecurrenceIdPropertyBuilder::new(self, date, time)
248
38
        }
249
    };
250
}
251

            
252
pub(crate) use add_recurrence_id;
253

            
254
macro_rules! add_sequence {
255
    () => {
256
38
        pub fn add_sequence(
257
38
            self,
258
38
            value: u32,
259
38
        ) -> $crate::model::property::SequencePropertyBuilder<Self> {
260
38
            $crate::model::property::SequencePropertyBuilder::new(self, value)
261
38
        }
262
    };
263
}
264

            
265
pub(crate) use add_sequence;
266

            
267
macro_rules! add_summary {
268
    () => {
269
18
        pub fn add_summary<V: ToString>(
270
18
            self,
271
18
            value: V,
272
18
        ) -> $crate::model::property::SummaryPropertyBuilder<Self> {
273
18
            $crate::model::property::SummaryPropertyBuilder::new(self, value.to_string())
274
18
        }
275
    };
276
}
277

            
278
pub(crate) use add_summary;
279

            
280
macro_rules! add_url {
281
    () => {
282
50
        pub fn add_url(self, value: &str) -> $crate::model::property::UrlPropertyBuilder<Self> {
283
50
            $crate::model::property::UrlPropertyBuilder::new(self, value.to_string())
284
50
        }
285
    };
286
}
287

            
288
pub(crate) use add_url;
289

            
290
macro_rules! add_recurrence_rule {
291
    () => {
292
62
        pub fn add_recurrence_rule(
293
62
            self,
294
62
            frequency: $crate::common::RecurFreq,
295
62
            builder: fn(
296
62
                $crate::model::property::RecurrenceRule,
297
62
            ) -> $crate::model::property::RecurrenceRule,
298
62
        ) -> $crate::model::property::RecurrenceRulePropertyBuilder<Self> {
299
62
            $crate::model::property::RecurrenceRulePropertyBuilder::new(
300
62
                self,
301
62
                builder($crate::model::property::RecurrenceRule::new(frequency)),
302
62
            )
303
62
        }
304
    };
305
}
306

            
307
pub(crate) use add_recurrence_rule;
308

            
309
macro_rules! add_duration {
310
    () => {
311
30
        pub fn add_duration(
312
30
            self,
313
30
            builder: fn() -> $crate::model::property::Duration,
314
30
        ) -> $crate::model::property::DurationPropertyBuilder<Self> {
315
30
            $crate::model::property::DurationPropertyBuilder::new(self, builder())
316
30
        }
317
    };
318
}
319

            
320
pub(crate) use add_duration;
321

            
322
macro_rules! add_attach {
323
    () => {
324
42
        pub fn add_attach_uri(
325
42
            self,
326
42
            value: &str,
327
42
        ) -> $crate::model::property::AttachPropertyBuilder<Self> {
328
42
            $crate::model::property::AttachPropertyBuilder::new_with_uri(self, value.to_string())
329
42
        }
330

            
331
4
        pub fn add_attach_binary(
332
4
            self,
333
4
            value: &str,
334
4
        ) -> $crate::model::property::AttachPropertyBuilder<Self> {
335
4
            $crate::model::property::AttachPropertyBuilder::new_with_binary(self, value.to_string())
336
4
        }
337
    };
338
}
339

            
340
pub(crate) use add_attach;
341

            
342
macro_rules! add_categories {
343
    () => {
344
38
        pub fn add_categories(
345
38
            self,
346
38
            value: Vec<&str>,
347
38
        ) -> $crate::model::property::CategoriesPropertyBuilder<Self> {
348
38
            $crate::model::property::CategoriesPropertyBuilder::new(
349
38
                self,
350
119
                value.into_iter().map(|s| s.to_string()).collect(),
351
38
            )
352
38
        }
353
    };
354
}
355

            
356
pub(crate) use add_categories;
357

            
358
macro_rules! add_comment {
359
    () => {
360
26
        pub fn add_comment<V: ToString>(
361
26
            self,
362
26
            value: V,
363
26
        ) -> $crate::model::property::CommentPropertyBuilder<Self> {
364
26
            $crate::model::property::CommentPropertyBuilder::new(self, value.to_string())
365
26
        }
366
    };
367
}
368

            
369
pub(crate) use add_comment;
370

            
371
macro_rules! add_contact {
372
    () => {
373
18
        pub fn add_contact<V: ToString>(
374
18
            self,
375
18
            value: V,
376
18
        ) -> $crate::model::property::ContactPropertyBuilder<Self> {
377
18
            $crate::model::property::ContactPropertyBuilder::new(self, value.to_string())
378
18
        }
379
    };
380
}
381

            
382
pub(crate) use add_contact;
383

            
384
macro_rules! add_exception_date_times {
385
    () => {
386
38
        pub fn add_exception_date_times(
387
38
            self,
388
38
            date_times: std::vec::Vec<$crate::common::CalendarDateTime>,
389
38
        ) -> $crate::model::property::ExceptionDateTimesPropertyBuilder<Self> {
390
38
            $crate::model::property::ExceptionDateTimesPropertyBuilder::new(self, date_times)
391
38
        }
392
    };
393
}
394

            
395
pub(crate) use add_exception_date_times;
396

            
397
macro_rules! add_request_status {
398
    () => {
399
50
        pub fn add_request_status(
400
50
            self,
401
50
            status_code: &[u32],
402
50
            description: &str,
403
50
            exception_data: std::option::Option<&str>,
404
50
        ) -> $crate::model::property::RequestStatusPropertyBuilder<Self> {
405
50
            $crate::model::property::RequestStatusPropertyBuilder::new(
406
50
                self,
407
50
                status_code.to_vec(),
408
50
                description.to_string(),
409
58
                exception_data.map(|s| s.to_string()),
410
50
            )
411
50
        }
412
    };
413
}
414

            
415
pub(crate) use add_request_status;
416

            
417
macro_rules! add_related {
418
    () => {
419
38
        pub fn add_related_to(
420
38
            self,
421
38
            value: &str,
422
38
        ) -> $crate::model::property::RelatedToPropertyBuilder<Self> {
423
38
            $crate::model::property::RelatedToPropertyBuilder::new(self, value.to_string())
424
38
        }
425
    };
426
}
427

            
428
pub(crate) use add_related;
429

            
430
macro_rules! add_resources {
431
    () => {
432
26
        pub fn add_resources(
433
26
            self,
434
26
            value: std::vec::Vec<&str>,
435
26
        ) -> $crate::model::property::ResourcesPropertyBuilder<Self> {
436
26
            $crate::model::property::ResourcesPropertyBuilder::new(
437
26
                self,
438
81
                value.into_iter().map(|s| s.to_string()).collect(),
439
26
            )
440
26
        }
441
    };
442
}
443

            
444
pub(crate) use add_resources;
445

            
446
macro_rules! add_recurrence_date {
447
    () => {
448
60
        pub fn add_recurrence_date_date_times(
449
60
            self,
450
60
            date_times: std::vec::Vec<$crate::common::CalendarDateTime>,
451
60
        ) -> $crate::model::property::RecurrenceDateTimesPropertyBuilder<Self> {
452
60
            $crate::model::property::RecurrenceDateTimesPropertyBuilder::new_date_times(
453
60
                self, date_times,
454
60
            )
455
60
        }
456

            
457
2
        pub fn add_recurrence_date_periods(
458
2
            self,
459
2
            periods: std::vec::Vec<$crate::model::property::Period>,
460
2
        ) -> $crate::model::property::RecurrenceDateTimesPropertyBuilder<Self> {
461
2
            $crate::model::property::RecurrenceDateTimesPropertyBuilder::new_periods(self, periods)
462
2
        }
463
    };
464
}
465

            
466
pub(crate) use add_recurrence_date;
467

            
468
macro_rules! add_date_time_end {
469
    () => {
470
26
        pub fn add_date_time_end(
471
26
            self,
472
26
            date: time::Date,
473
26
            time: std::option::Option<time::Time>,
474
26
        ) -> $crate::model::property::DateTimeEndPropertyBuilder<Self> {
475
26
            $crate::model::property::DateTimeEndPropertyBuilder::new(self, date, time)
476
26
        }
477
    };
478
}
479

            
480
pub(crate) use add_date_time_end;
481

            
482
macro_rules! add_action {
483
    ($typ:expr) => {
484
16
        pub fn add_action(self) -> $crate::model::property::ActionPropertyBuilder<Self> {
485
16
            $crate::model::property::ActionPropertyBuilder::new(self, $typ)
486
16
        }
487
    };
488
}
489

            
490
pub(crate) use add_action;
491

            
492
macro_rules! add_trigger {
493
    () => {
494
8
        pub fn add_relative_trigger(
495
8
            self,
496
8
            value: $crate::model::property::Duration,
497
8
        ) -> $crate::model::property::RelativeTriggerPropertyBuilder<Self> {
498
8
            $crate::model::property::RelativeTriggerPropertyBuilder::new(self, value)
499
8
        }
500

            
501
8
        pub fn add_absolute_trigger(
502
8
            self,
503
8
            date: time::Date,
504
8
            time: time::Time,
505
8
        ) -> $crate::model::property::AbsoluteTriggerPropertyBuilder<Self> {
506
8
            $crate::model::property::AbsoluteTriggerPropertyBuilder::new(self, date, time)
507
8
        }
508
    };
509
}
510

            
511
pub(crate) use add_trigger;
512

            
513
macro_rules! add_repeat {
514
    () => {
515
16
        pub fn add_repeat(
516
16
            self,
517
16
            value: u32,
518
16
        ) -> $crate::model::property::RepeatPropertyBuilder<Self> {
519
16
            $crate::model::property::RepeatPropertyBuilder::new(self, value)
520
16
        }
521
    };
522
}
523

            
524
pub(crate) use add_repeat;
525

            
526
macro_rules! add_alarms {
527
    () => {
528
12
        pub fn add_audio_alarm(
529
12
            self,
530
12
        ) -> $crate::model::component::alarm::AudioAlarmComponentBuilder<Self> {
531
12
            $crate::model::component::alarm::AudioAlarmComponentBuilder::new(self)
532
12
        }
533

            
534
24
        pub fn add_display_alarm(
535
24
            self,
536
24
        ) -> $crate::model::component::alarm::DisplayAlarmComponentBuilder<Self> {
537
24
            $crate::model::component::alarm::DisplayAlarmComponentBuilder::new(self)
538
24
        }
539

            
540
12
        pub fn add_email_alarm(
541
12
            self,
542
12
        ) -> $crate::model::component::alarm::EmailAlarmComponentBuilder<Self> {
543
12
            $crate::model::component::alarm::EmailAlarmComponentBuilder::new(self)
544
12
        }
545
    };
546
}
547

            
548
use crate::model::property::ComponentProperty;
549
use crate::model::ComponentAccess;
550
pub(crate) use add_alarms;