Added color support for calendar creation
This commit is contained in:
parent
d28309b21d
commit
a8e5bfbc63
3 changed files with 22 additions and 17 deletions
|
@ -84,7 +84,7 @@ async fn add_items_and_sync_again(provider: &mut CalDavProvider)
|
||||||
let new_calendar_url: Url = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
|
let new_calendar_url: Url = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
|
||||||
let new_calendar_name = "A brave new calendar".to_string();
|
let new_calendar_name = "A brave new calendar".to_string();
|
||||||
if let Err(_err) = provider.local_mut()
|
if let Err(_err) = provider.local_mut()
|
||||||
.create_calendar(new_calendar_url.clone(), new_calendar_name.clone(), SupportedComponents::TODO, None)
|
.create_calendar(new_calendar_url.clone(), new_calendar_name.clone(), SupportedComponents::TODO, Some("#ff8000".parse().unwrap()))
|
||||||
.await {
|
.await {
|
||||||
println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
|
println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,12 +23,12 @@ bitflags! {
|
||||||
impl SupportedComponents {
|
impl SupportedComponents {
|
||||||
pub fn to_xml_string(&self) -> String {
|
pub fn to_xml_string(&self) -> String {
|
||||||
format!(r#"
|
format!(r#"
|
||||||
<C:supported-calendar-component-set>
|
<B:supported-calendar-component-set>
|
||||||
{} {}
|
{} {}
|
||||||
</C:supported-calendar-component-set>
|
</B:supported-calendar-component-set>
|
||||||
"#,
|
"#,
|
||||||
if self.contains(Self::EVENT) { "<C:comp name=\"VEVENT\"/>" } else { "" },
|
if self.contains(Self::EVENT) { "<B:comp name=\"VEVENT\"/>" } else { "" },
|
||||||
if self.contains(Self::TODO) { "<C:comp name=\"VTODO\"/>" } else { "" },
|
if self.contains(Self::TODO) { "<B:comp name=\"VTODO\"/>" } else { "" },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ impl CalDavSource<RemoteCalendar> for Client {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let creation_body = calendar_body(name, supported_components);
|
let creation_body = calendar_body(name, supported_components, color);
|
||||||
|
|
||||||
let response = reqwest::Client::new()
|
let response = reqwest::Client::new()
|
||||||
.request(Method::from_bytes(b"MKCALENDAR").unwrap(), url.clone())
|
.request(Method::from_bytes(b"MKCALENDAR").unwrap(), url.clone())
|
||||||
|
@ -282,21 +282,26 @@ impl CalDavSource<RemoteCalendar> for Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn calendar_body(name: String, supported_components: SupportedComponents) -> String {
|
fn calendar_body(name: String, supported_components: SupportedComponents, color: Option<Color>) -> String {
|
||||||
|
let color_property = match color {
|
||||||
|
None => "".to_string(),
|
||||||
|
Some(color) => format!("<D:calendar-color xmlns:D=\"http://apple.com/ns/ical/\">{}FF</D:calendar-color>", color.to_hex_string().to_ascii_uppercase()),
|
||||||
|
};
|
||||||
|
|
||||||
// This is taken from https://tools.ietf.org/html/rfc4791#page-24
|
// This is taken from https://tools.ietf.org/html/rfc4791#page-24
|
||||||
format!(r#"<?xml version="1.0" encoding="utf-8" ?>
|
format!(r#"<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<C:mkcalendar xmlns:D="DAV:"
|
<B:mkcalendar xmlns:B="urn:ietf:params:xml:ns:caldav">
|
||||||
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
<A:set xmlns:A="DAV:">
|
||||||
<D:set>
|
<A:prop>
|
||||||
<D:prop>
|
<A:displayname>{}</A:displayname>
|
||||||
<D:displayname>{}</D:displayname>
|
|
||||||
{}
|
{}
|
||||||
</D:prop>
|
{}
|
||||||
</D:set>
|
</A:prop>
|
||||||
</C:mkcalendar>
|
</A:set>
|
||||||
|
</B:mkcalendar>
|
||||||
"#,
|
"#,
|
||||||
name,
|
name,
|
||||||
|
color_property,
|
||||||
supported_components.to_xml_string(),
|
supported_components.to_xml_string(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue