2017-09-23 15:51:35 +00:00
|
|
|
//
|
|
|
|
// imag - the personal information management suite for the commandline
|
2018-02-07 01:48:53 +00:00
|
|
|
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
2017-09-23 15:51:35 +00:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; version
|
|
|
|
// 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
//
|
|
|
|
|
2018-02-13 23:12:23 +00:00
|
|
|
use std::path::Path;
|
2017-09-23 15:51:35 +00:00
|
|
|
use std::path::PathBuf;
|
2018-02-13 23:12:23 +00:00
|
|
|
use std::result::Result as RResult;
|
2017-09-23 15:51:35 +00:00
|
|
|
|
2017-09-23 18:18:20 +00:00
|
|
|
use vobject::parse_component;
|
|
|
|
|
2017-09-23 15:51:35 +00:00
|
|
|
use libimagstore::store::Store;
|
|
|
|
use libimagstore::store::FileLockEntry;
|
2017-10-02 18:44:08 +00:00
|
|
|
use libimagstore::storeid::StoreIdIterator;
|
2018-01-08 22:39:23 +00:00
|
|
|
use libimagentryutil::isa::Is;
|
2017-09-23 15:51:35 +00:00
|
|
|
|
2018-01-08 22:39:23 +00:00
|
|
|
use contact::IsContact;
|
2018-02-13 23:12:23 +00:00
|
|
|
use error::ContactError as CE;
|
2018-03-12 13:43:02 +00:00
|
|
|
use error::ContactErrorKind as CEK;
|
2017-09-23 15:51:35 +00:00
|
|
|
use error::Result;
|
2017-09-23 18:18:20 +00:00
|
|
|
use util;
|
2017-09-23 15:51:35 +00:00
|
|
|
|
2018-04-25 09:28:40 +00:00
|
|
|
pub trait ContactStore<'a> {
|
2017-09-23 15:51:35 +00:00
|
|
|
|
|
|
|
// creating
|
|
|
|
|
|
|
|
fn create_from_path(&'a self, p: &PathBuf) -> Result<FileLockEntry<'a>>;
|
|
|
|
|
2017-09-23 18:18:20 +00:00
|
|
|
/// Create contact ref from buffer
|
2018-04-25 09:28:40 +00:00
|
|
|
fn create_from_buf(&'a self, buf: &String) -> Result<FileLockEntry<'a>>;
|
2017-09-23 18:18:20 +00:00
|
|
|
|
2017-09-23 15:51:35 +00:00
|
|
|
// getting
|
|
|
|
|
2017-10-02 18:44:08 +00:00
|
|
|
fn all_contacts(&'a self) -> Result<StoreIdIterator>;
|
2017-09-23 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 18:44:08 +00:00
|
|
|
/// The extension for the Store to work with contacts
|
2017-09-23 15:51:35 +00:00
|
|
|
impl<'a> ContactStore<'a> for Store {
|
|
|
|
|
|
|
|
fn create_from_path(&'a self, p: &PathBuf) -> Result<FileLockEntry<'a>> {
|
2018-04-25 09:28:40 +00:00
|
|
|
util::read_to_string(p).and_then(|buf| self.create_from_buf(&buf))
|
2017-09-23 18:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Create contact ref from buffer
|
2018-04-25 09:28:40 +00:00
|
|
|
fn create_from_buf(&'a self, buf: &String) -> Result<FileLockEntry<'a>> {
|
2017-09-23 18:18:20 +00:00
|
|
|
let component = parse_component(&buf)?;
|
|
|
|
debug!("Parsed: {:?}", component);
|
|
|
|
|
2018-04-25 09:28:40 +00:00
|
|
|
unimplemented!()
|
2017-09-23 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 18:44:08 +00:00
|
|
|
fn all_contacts(&'a self) -> Result<StoreIdIterator> {
|
2018-03-12 11:52:24 +00:00
|
|
|
let iter = self
|
|
|
|
.entries()?
|
|
|
|
.without_store()
|
|
|
|
.filter(|id| id.is_in_collection(&["contact"]));
|
|
|
|
|
|
|
|
Ok(StoreIdIterator::new(Box::new(iter)))
|
2017-09-23 15:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-10-02 18:44:08 +00:00
|
|
|
|