ui: improve contact additions from mail view

embed
Manos Pitsidianakis 2019-03-31 20:08:37 +03:00
parent 37716c85df
commit 5d9af8e32b
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 52 additions and 51 deletions

View File

@ -149,32 +149,32 @@ impl Card {
pub fn set_id(&mut self, new: Uuid) {
self.id = new;
}
pub fn set_title(&mut self, new: &str) {
self.title = new.to_string();
pub fn set_title(&mut self, new: String) {
self.title = new;
}
pub fn set_firstname(&mut self, new: &str) {
self.firstname = new.to_string();
pub fn set_firstname(&mut self, new: String) {
self.firstname = new;
}
pub fn set_lastname(&mut self, new: &str) {
self.lastname = new.to_string();
pub fn set_lastname(&mut self, new: String) {
self.lastname = new;
}
pub fn set_additionalname(&mut self, new: &str) {
self.additionalname = new.to_string();
pub fn set_additionalname(&mut self, new: String) {
self.additionalname = new;
}
pub fn set_name_prefix(&mut self, new: &str) {
self.name_prefix = new.to_string();
pub fn set_name_prefix(&mut self, new: String) {
self.name_prefix = new;
}
pub fn set_name_suffix(&mut self, new: &str) {
self.name_suffix = new.to_string();
pub fn set_name_suffix(&mut self, new: String) {
self.name_suffix = new;
}
pub fn set_email(&mut self, new: &str) {
self.email = new.to_string();
pub fn set_email(&mut self, new: String) {
self.email = new;
}
pub fn set_url(&mut self, new: &str) {
self.url = new.to_string();
pub fn set_url(&mut self, new: String) {
self.url = new;
}
pub fn set_key(&mut self, new: &str) {
self.key = new.to_string();
pub fn set_key(&mut self, new: String) {
self.key = new;
}
pub fn set_extra_property(&mut self, key: &str, value: String) {

View File

@ -394,53 +394,54 @@ impl Component for MailView {
match event.event_type {
UIEventType::Input(Key::Char('c')) => {
/*
let mut new_card: Card = Card::new();
new_card.set_email(&envelope.from()[0].get_email());
new_card.set_firstname(&envelope.from()[0].get_display_name());
if cfg!(feature = "debug_log") {
eprintln!("{:?}", new_card);
}
*/
if let ViewMode::ContactSelector(_) = self.mode {
if let ViewMode::ContactSelector(s) =
std::mem::replace(&mut self.mode, ViewMode::Normal)
{
for c in s.collect() {
let mut new_card: Card = Card::new();
let email = String::from_utf8(c).unwrap();
new_card.set_email(&email);
new_card.set_firstname("");
context.accounts[self.coordinates.0]
.address_book
.add_card(new_card);
{
let account = &mut context.accounts[self.coordinates.0];
let mut results = Vec::new();
{
let mailbox = &account[self.coordinates.1]
.as_ref()
.unwrap();
let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
for c in s.collect() {
let c = usize::from_ne_bytes({
[c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]]
});
for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() {
if idx != c {
continue;
}
let mut new_card: Card = Card::new();
new_card.set_email(env.get_email());
new_card.set_lastname(env.get_display_name());
results.push(new_card);
}
}
}
for c in results {
account.address_book.add_card(c);
}
}
//if cfg!(feature = "debug_log") {
//eprintln!("{:?}", s.collect());
//}
}
return true;
}
let accounts = &context.accounts;
let mailbox = &accounts[self.coordinates.0][self.coordinates.1]
.as_ref()
.unwrap();
let envelope: &Envelope = &mailbox.collection[&self.coordinates.2];
let mut entries = Vec::new();
entries.push((
envelope.from()[0].get_email().into_bytes(),
format!("{}", envelope.from()[0]),
));
entries.push((
envelope.to()[0].get_email().into_bytes(),
format!("{}", envelope.to()[0]),
));
for (idx, env) in envelope.from().iter().chain(envelope.to().iter()).enumerate() {
entries.push((
idx.to_ne_bytes().to_vec(),
format!("{}", env),
));
}
self.mode = ViewMode::ContactSelector(Selector::new(entries, true));
self.dirty = true;
//context.accounts.context(self.coordinates.0).address_book.add_card(new_card);
}
UIEventType::Input(Key::Esc) | UIEventType::Input(Key::Alt('')) => {
self.cmd_buf.clear();