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_name = "A brave new calendar".to_string();
|
||||
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 {
|
||||
println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ bitflags! {
|
|||
impl SupportedComponents {
|
||||
pub fn to_xml_string(&self) -> String {
|
||||
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::TODO) { "<C:comp name=\"VTODO\"/>" } else { "" },
|
||||
if self.contains(Self::EVENT) { "<B:comp name=\"VEVENT\"/>" } 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()
|
||||
.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
|
||||
format!(r#"<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:mkcalendar xmlns:D="DAV:"
|
||||
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:set>
|
||||
<D:prop>
|
||||
<D:displayname>{}</D:displayname>
|
||||
{}
|
||||
</D:prop>
|
||||
</D:set>
|
||||
</C:mkcalendar>
|
||||
<B:mkcalendar xmlns:B="urn:ietf:params:xml:ns:caldav">
|
||||
<A:set xmlns:A="DAV:">
|
||||
<A:prop>
|
||||
<A:displayname>{}</A:displayname>
|
||||
{}
|
||||
{}
|
||||
</A:prop>
|
||||
</A:set>
|
||||
</B:mkcalendar>
|
||||
"#,
|
||||
name,
|
||||
color_property,
|
||||
supported_components.to_xml_string(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue