diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-10-20 11:14:29 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-10-20 11:32:31 +0300 |
commit | 5beed91df2b45fc506fd24494e7e766bf536e4fc (patch) | |
tree | 49c0187513887efdf1cbb8527b28c51191615e85 /melib/src/addressbook.rs | |
parent | dc525b9dddbefbc2cfe1da3276d01407893b3366 (diff) |
contacts: add support for externally managed contacts
Adds support for contacts (Cards) marked as `external_resource` which
prevents modifications from happening. No way to import external
contacts is added yet.
Diffstat (limited to 'melib/src/addressbook.rs')
-rw-r--r-- | melib/src/addressbook.rs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/melib/src/addressbook.rs b/melib/src/addressbook.rs index 79ed117d..481114a9 100644 --- a/melib/src/addressbook.rs +++ b/melib/src/addressbook.rs @@ -81,6 +81,9 @@ pub struct Card { color: u8, last_edited: DateTime<Local>, extra_properties: FnvHashMap<String, String>, + + /// If true, we can't make any changes because we do not manage this resource. + external_resource: bool, } impl AddressBook { @@ -134,6 +137,7 @@ impl Card { key: String::new(), last_edited: Local::now(), + external_resource: false, extra_properties: FnvHashMap::default(), color: 0, } @@ -202,37 +206,50 @@ impl Card { pub fn set_extra_property(&mut self, key: &str, value: String) { self.extra_properties.insert(key.to_string(), value); } + pub fn extra_property(&self, key: &str) -> Option<&str> { self.extra_properties.get(key).map(String::as_str) } + + pub fn extra_properties(&self) -> &FnvHashMap<String, String> { + &self.extra_properties + } + + pub fn set_external_resource(&mut self, new_val: bool) { + self.external_resource = new_val; + } + + pub fn external_resource(&self) -> bool { + self.external_resource + } } impl From<FnvHashMap<String, String>> for Card { fn from(mut map: FnvHashMap<String, String>) -> Card { let mut card = Card::new(); - if let Some(val) = map.remove("Title") { + if let Some(val) = map.remove("TITLE") { card.title = val; } - if let Some(val) = map.remove("Name") { + if let Some(val) = map.remove("NAME") { card.name = val; } - if let Some(val) = map.remove("Additional Name") { + if let Some(val) = map.remove("ADDITIONAL NAME") { card.additionalname = val; } - if let Some(val) = map.remove("Name Prefix") { + if let Some(val) = map.remove("NAME PREFIX") { card.name_prefix = val; } - if let Some(val) = map.remove("Name Suffix") { + if let Some(val) = map.remove("NAME SUFFIX") { card.name_suffix = val; } - if let Some(val) = map.remove("E-mail") { + if let Some(val) = map.remove("E-MAIL") { card.email = val; } - if let Some(val) = map.remove("url") { + if let Some(val) = map.remove("URL") { card.url = val; } - if let Some(val) = map.remove("key") { + if let Some(val) = map.remove("KEY") { card.key = val; } card.extra_properties = map; |