summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHendrik Sollich <hendrik@hoodie.de>2017-01-08 01:00:38 +0100
committerHendrik Sollich <hendrik@hoodie.de>2017-01-08 01:00:38 +0100
commitb60375cd0ad6cda92d7fe497ad5af64f9a171354 (patch)
tree4c3c0f704b69a498017b2f292a758590d7a58631 /src
parente28d012e5c5365874f9e6db90065dd8fb6c19cf1 (diff)
better support for VTODO tasks
Diffstat (limited to 'src')
-rw-r--r--src/calendar.rs1
-rw-r--r--src/components.rs58
-rw-r--r--src/lib.rs3
-rw-r--r--src/properties.rs66
4 files changed, 127 insertions, 1 deletions
diff --git a/src/calendar.rs b/src/calendar.rs
index 52c087e..930107a 100644
--- a/src/calendar.rs
+++ b/src/calendar.rs
@@ -91,6 +91,7 @@ impl Calendar {
}
impl ToString for Calendar {
+ /// # panics
fn to_string(&self) -> String {
let mut out_string = String::new();
self.fmt_write(&mut out_string).unwrap();
diff --git a/src/components.rs b/src/components.rs
index eddcaeb..6908c57 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -29,10 +29,19 @@ impl Event {
Event { properties: mem::replace(&mut self.properties, HashMap::new()) }
}
+ /// Defines the overall status or confirmation
+ pub fn status(&mut self, status: EventStatus) -> &mut Self {
+ self.append_property(status.into());
+ self
+ }
+
//pub fn repeats<R:Repeater+?Sized>(&mut self, repeat: R) -> &mut Self {
// unimplemented!()
//}
+
+
+
}
@@ -49,6 +58,38 @@ impl Todo {
Todo { properties: mem::replace(&mut self.properties, HashMap::new()) }
}
+ /// Set the PERCENT-COMPLETE `Property`
+ ///
+ /// Ranges between 0 - 100
+ pub fn percent_complete(&mut self, percent: u8) -> &mut Self {
+ self.add_property("PERCENT-COMPLETE", &percent.to_string());
+ self
+ }
+
+
+ /// Set the COMPLETED `Property`, date only
+ pub fn due<TZ:TimeZone>(&mut self, dt: DateTime<TZ>) -> &mut Self
+ where TZ::Offset: fmt::Display
+ {
+ self.add_property("DUE", dt.format("%Y%m%dT%H%M%S").to_string().as_ref());
+ self
+ }
+
+ /// Set the COMPLETED `Property`, date only
+ pub fn completed<TZ:TimeZone>(&mut self, dt: DateTime<TZ>) -> &mut Self
+ where TZ::Offset: fmt::Display
+ {
+ self.add_property("COMPLETED", dt.format("%Y%m%dT%H%M%S").to_string().as_ref());
+ self
+ }
+
+ /// Defines the overall status or confirmation
+ pub fn status(&mut self, status: TodoStatus) -> &mut Self {
+ self.append_property(status.into());
+ self
+ }
+
+
//pub fn repeats<R:Repeater+?Sized>(&mut self, repeat: R) -> &mut Self {
// unimplemented!()
//}
@@ -58,7 +99,6 @@ impl Todo {
/// Implemented by everything that goes into a `Calendar`
pub trait Component {
-
/// Returns kind of component.
///
///
@@ -154,6 +194,15 @@ pub trait Component {
self
}
+ /// Defindes the relative priority.
+ ///
+ /// Ranges from 0 to 10, larger values will be truncated
+ fn priority(&mut self, priority:u32) -> &mut Self {
+ let priority = ::std::cmp::min(priority, 10);
+ self.add_property("PRIORITY", &priority.to_string());
+ self
+ }
+
/// Prints to stdout
fn print(&self) -> Result<(), fmt::Error> {
let mut out = String::new();
@@ -172,6 +221,12 @@ pub trait Component {
self.add_property("DESCRIPTION", desc)
}
+ // TODO there can be multiple attendees, this requires to changed the underlying datastructure
+ ///// Set the description
+ //fn attendee(&mut self, desc: &str) -> &mut Self {
+ // self.add_multi_property("ATTENDEE", desc) // multiproperties should be a multimap
+ //}
+
/// Set the LOCATION
/// 3.8.1.7. Location
fn location(&mut self, location: &str) -> &mut Self {
@@ -185,6 +240,7 @@ pub trait Component {
}
}
+
macro_rules! component_impl {
($t:ty, $kind:expr) => {
impl Component for $t {
diff --git a/src/lib.rs b/src/lib.rs
index aeda709..ffcdb98 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -67,7 +67,10 @@ mod calendar;
//pub mod repeats;
pub use properties::{Property, Parameter, Class, ValueType};
+pub use properties::{TodoStatus, EventStatus};
//pub use components::{event, todo};
pub use components::{Event, Todo, Component};
pub use calendar::Calendar;
+// TODO Calendar TimeZone VTIMEZONE STANDARD DAYLIGHT (see thunderbird exports)
+
diff --git a/src/properties.rs b/src/properties.rs
index 5ae5332..c12ee89 100644
--- a/src/properties.rs
+++ b/src/properties.rs
@@ -163,3 +163,69 @@ impl Into<Parameter> for ValueType {
}
}
}
+
+
+#[derive(Copy,Clone,Debug)]
+/// Encodes the status of an `Event`
+pub enum EventStatus {
+ /// Indicates event is tentative.
+ Tentative,
+ /// Indicates event is definite.
+ Confirmed,
+ /// Indicates event was cancelled.
+ Cancelled,
+ //Custom(&str)
+}
+
+#[derive(Copy,Clone,Debug)]
+/// Encodes the status of a `Todo`
+pub enum TodoStatus {
+ /// Indicates to-do needs action.
+ NeedsAction,
+ /// Indicates to-do is completed.
+ Completed,
+ /// Indicates to-do is in process.
+ InProcess,
+ /// Indicates to-do was cancelled.
+ Cancelled,
+ //Custom(&str)
+}
+
+//pub enum JournalStatuw{
+// Draft,
+// Final,
+// Cancelled,
+// Custom(&str)
+//}
+
+
+impl Into<Property> for EventStatus {
+ fn into(self) -> Property {
+ Property {
+ key: String::from("STATUS"),
+ value: String::from(match self {
+ EventStatus::Tentative => "TENTATIVE",
+ EventStatus::Confirmed => "CONFIRMED",
+ EventStatus::Cancelled => "CANCELLED",
+ }),
+ parameters: HashMap::new()
+ }
+ }
+}
+
+impl Into<Property> for TodoStatus {
+ fn into(self) -> Property {
+ Property {
+ key: String::from("STATUS"),
+ value: String::from(match self {
+ TodoStatus::NeedsAction => "NEEDS-ACTION",
+ TodoStatus::Completed => "COMPLETED",
+ TodoStatus::InProcess => "IN-PROCESS",
+ TodoStatus::Cancelled => "CANCELLED",
+ //TodoStatus::Custom(s) => "CU",
+ }),
+ parameters: HashMap::new()
+ }
+ }
+}
+