kitchen_fridge/calendar/
mod.rs1pub mod cached_calendar;
4pub mod remote_calendar;
5
6use std::convert::TryFrom;
7use std::error::Error;
8
9use serde::{Deserialize, Serialize};
10
11use bitflags::bitflags;
12
13bitflags! {
14 #[derive(Serialize, Deserialize)]
15 pub struct SupportedComponents: u8 {
16 const EVENT = 1;
18 const TODO = 2;
20 }
21}
22
23impl SupportedComponents {
24 pub fn to_xml_string(&self) -> String {
25 format!(r#"
26 <B:supported-calendar-component-set>
27 {} {}
28 </B:supported-calendar-component-set>
29 "#,
30 if self.contains(Self::EVENT) { "<B:comp name=\"VEVENT\"/>" } else { "" },
31 if self.contains(Self::TODO) { "<B:comp name=\"VTODO\"/>" } else { "" },
32 )
33 }
34}
35
36impl TryFrom<minidom::Element> for SupportedComponents {
37 type Error = Box<dyn Error>;
38
39 fn try_from(element: minidom::Element) -> Result<Self, Self::Error> {
41 if element.name() != "supported-calendar-component-set" {
42 return Err("Element must be a <supported-calendar-component-set>".into());
43 }
44
45 let mut flags = Self::empty();
46 for child in element.children() {
47 match child.attr("name") {
48 None => continue,
49 Some("VEVENT") => flags.insert(Self::EVENT),
50 Some("VTODO") => flags.insert(Self::TODO),
51 Some(other) => {
52 log::warn!("Unimplemented supported component type: {:?}. Ignoring it", other);
53 continue
54 },
55 };
56 }
57
58 Ok(flags)
59 }
60}
61
62
63pub enum SearchFilter {
65 All,
67 Tasks,
69 }
74
75impl Default for SearchFilter {
76 fn default() -> Self {
77 SearchFilter::All
78 }
79}