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
pub mod cached_calendar;
pub mod remote_calendar;
use std::convert::TryFrom;
use std::error::Error;
use serde::{Deserialize, Serialize};
use bitflags::bitflags;
bitflags! {
#[derive(Serialize, Deserialize)]
pub struct SupportedComponents: u8 {
const EVENT = 1;
const TODO = 2;
}
}
impl SupportedComponents {
pub fn to_xml_string(&self) -> String {
format!(r#"
<B:supported-calendar-component-set>
{} {}
</B:supported-calendar-component-set>
"#,
if self.contains(Self::EVENT) { "<B:comp name=\"VEVENT\"/>" } else { "" },
if self.contains(Self::TODO) { "<B:comp name=\"VTODO\"/>" } else { "" },
)
}
}
impl TryFrom<minidom::Element> for SupportedComponents {
type Error = Box<dyn Error>;
fn try_from(element: minidom::Element) -> Result<Self, Self::Error> {
if element.name() != "supported-calendar-component-set" {
return Err("Element must be a <supported-calendar-component-set>".into());
}
let mut flags = Self::empty();
for child in element.children() {
match child.attr("name") {
None => continue,
Some("VEVENT") => flags.insert(Self::EVENT),
Some("VTODO") => flags.insert(Self::TODO),
Some(other) => {
log::warn!("Unimplemented supported component type: {:?}. Ignoring it", other);
continue
},
};
}
Ok(flags)
}
}
pub enum SearchFilter {
All,
Tasks,
}
impl Default for SearchFilter {
fn default() -> Self {
SearchFilter::All
}
}