From d5d90f7ecd37efdd9ba31d8772e7c7c7b9108cd3 Mon Sep 17 00:00:00 2001 From: Nora Date: Tue, 12 Mar 2019 19:31:09 +0100 Subject: remove instance timestamp from icalvevent --- src/icalwrap/icalvcalendar.rs | 5 +++-- src/icalwrap/icalvevent.rs | 7 ++----- src/khevent.rs | 14 +++++++++----- src/khline.rs | 7 ++++--- 4 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/icalwrap/icalvcalendar.rs b/src/icalwrap/icalvcalendar.rs index adbe513..73290a6 100644 --- a/src/icalwrap/icalvcalendar.rs +++ b/src/icalwrap/icalvcalendar.rs @@ -1,5 +1,5 @@ use std::ffi::{CStr, CString}; -use std::path::{PathBuf,Path}; +use std::path::{PathBuf, Path}; use std::rc::Rc; use std::io; @@ -69,6 +69,7 @@ impl IcalVCalendar { self } + //TODO should probably be private pub fn from_str(str: &str, path: Option<&Path>) -> io::Result { unsafe { let c_str = CString::new(str).unwrap(); @@ -254,7 +255,7 @@ impl IcalVCalendar { IcalVEvent::from_ptr_with_parent(event, self) } - pub fn get_principal_event(&self) -> IcalVEvent { + pub(in crate::icalwrap) fn get_principal_event(&self) -> IcalVEvent { let mut event = self.get_first_event(); if let Some(ref timestamp) = self.instance_timestamp { event = event.with_internal_timestamp(timestamp) diff --git a/src/icalwrap/icalvevent.rs b/src/icalwrap/icalvevent.rs index 17aa263..75324c8 100644 --- a/src/icalwrap/icalvevent.rs +++ b/src/icalwrap/icalvevent.rs @@ -10,7 +10,6 @@ use crate::ical; pub struct IcalVEvent { ptr: *mut ical::icalcomponent, parent: Option, - instance_timestamp: Option, } impl Drop for IcalVEvent { @@ -39,7 +38,7 @@ impl IcalVEvent { IcalVEvent { ptr, parent: Some(parent.shallow_copy()), - instance_timestamp: None, + //instance_timestamp: None, } } @@ -106,15 +105,13 @@ impl IcalVEvent { IcalVEvent { ptr: self.ptr, parent: self.parent.as_ref().map(|parent| parent.shallow_copy()), - instance_timestamp: self.instance_timestamp.clone(), } } - pub fn with_internal_timestamp(&self, datetime: &IcalTime) -> IcalVEvent { + pub(in crate::icalwrap) fn with_internal_timestamp(&self, datetime: &IcalTime) -> IcalVEvent { IcalVEvent { ptr: self.ptr, parent: self.parent.as_ref().map(|parent| parent.shallow_copy()), - instance_timestamp: Some(datetime.clone()), } } diff --git a/src/khevent.rs b/src/khevent.rs index 26669b8..1ec9aae 100644 --- a/src/khevent.rs +++ b/src/khevent.rs @@ -1,14 +1,15 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use crate::icalwrap::IcalComponent; use crate::icalwrap::IcalDuration; use crate::icalwrap::IcalProperty; use crate::icalwrap::IcalTime; use crate::icalwrap::IcalTimeZone; +use crate::icalwrap::IcalVCalendar; use crate::icalwrap::IcalVEvent; +use crate::KhResult; pub struct KhEvent { - //TODO event should be private event: IcalVEvent, instance_timestamp: Option, } @@ -149,19 +150,22 @@ impl KhEvent { instance_timestamp, } } + + pub fn from_str(input: &str, path: Option<&Path>) -> KhResult { + let cal = IcalVCalendar::from_str(input, path)?; + Ok(cal.get_principal_khevent()) + } } #[cfg(test)] mod tests { use super::*; use crate::icalwrap::IcalTimeZone; - use crate::icalwrap::IcalVCalendar; use crate::testdata; #[test] fn test_is_recur_valid_master() { - let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); - let event = cal.get_principal_khevent(); + let event = KhEvent::from_str(testdata::TEST_EVENT_RECUR, None).unwrap(); assert!(event.is_recur_valid()); } diff --git a/src/khline.rs b/src/khline.rs index 8cf324f..d52c825 100644 --- a/src/khline.rs +++ b/src/khline.rs @@ -45,7 +45,8 @@ impl KhLine { self == &KhLine::from(event) } - pub fn matches(&self, event: &IcalVEvent) -> bool { + //TODO deprecated + fn matches(&self, event: &IcalVEvent) -> bool { self == &KhLine::from(event) } @@ -84,7 +85,7 @@ impl From<&KhEvent> for KhLine { impl From<&IcalVCalendar> for KhLine { fn from(cal: &IcalVCalendar) -> Self { - (&cal.get_principal_event()).into() + (&cal.get_principal_khevent()).into() } } @@ -247,7 +248,7 @@ mod tests { let khline = KhLine::from(&cal); - assert!(khline.matches(&cal.get_principal_event())); + assert!(khline.matches_khevent(&cal.get_principal_khevent())); } #[test] -- cgit v1.2.3