2021-02-18 12:02:04 +01:00
|
|
|
//! This module is the data source of the Caldav items
|
|
|
|
//!
|
|
|
|
//! This gives access to data from both the server and a local database for quick retrieval when the app starts
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
2021-02-20 00:10:05 +01:00
|
|
|
use std::error::Error;
|
2021-02-18 12:02:04 +01:00
|
|
|
|
2021-02-21 00:16:40 +01:00
|
|
|
pub mod calendar;
|
2021-02-19 07:58:53 +01:00
|
|
|
mod task;
|
2021-02-18 12:02:04 +01:00
|
|
|
mod client;
|
|
|
|
|
|
|
|
pub use calendar::Calendar;
|
2021-02-19 07:58:53 +01:00
|
|
|
pub use task::Task;
|
2021-02-18 12:02:04 +01:00
|
|
|
use client::Client;
|
|
|
|
|
|
|
|
/// A Caldav data source
|
|
|
|
pub struct DataSource {
|
|
|
|
client: Option<Client>,
|
|
|
|
|
2021-02-18 12:07:38 +01:00
|
|
|
calendars: Vec<Calendar>
|
2021-02-18 12:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DataSource {
|
|
|
|
/// Create a new data source
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self{
|
|
|
|
client: None,
|
|
|
|
calendars: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Tell this data source what the source server is
|
2021-02-20 00:10:05 +01:00
|
|
|
pub fn set_server(&mut self, url: String, username: String, password: String) -> Result<(), Box<dyn Error>> {
|
|
|
|
self.client = Some(Client::new(url, username, password)?);
|
|
|
|
Ok(())
|
2021-02-18 12:02:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Update the local database with info from the Client
|
2021-02-20 00:10:05 +01:00
|
|
|
pub fn fetch_from_server(&mut self) {
|
|
|
|
|
2021-02-18 12:02:04 +01:00
|
|
|
}
|
|
|
|
|
2021-02-19 07:58:53 +01:00
|
|
|
pub fn update_changes_to_server(&self) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-18 12:07:38 +01:00
|
|
|
pub fn calendars(&self) -> Vec<&Calendar> {
|
2021-02-18 12:02:04 +01:00
|
|
|
self.calendars
|
2021-02-18 12:07:38 +01:00
|
|
|
.iter()
|
|
|
|
.collect()
|
2021-02-18 12:02:04 +01:00
|
|
|
}
|
|
|
|
}
|