merge FirstName/LastName fields in Contacts

First names and Last names are an anglocentric concept and do not apply
cleanly to the rest of the world's cultures.
embed
Manos Pitsidianakis 2019-06-06 12:21:47 +03:00
parent b6c0236d24
commit d772d10d66
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
4 changed files with 19 additions and 56 deletions

View File

@ -38,8 +38,7 @@ pub struct AddressBook {
pub struct Card {
id: CardId,
title: String,
firstname: String,
lastname: String,
name: String,
additionalname: String,
name_prefix: String,
name_suffix: String,
@ -94,8 +93,7 @@ impl Card {
Card {
id: Uuid::new_v4(),
title: String::new(),
firstname: String::new(),
lastname: String::new(),
name: String::new(),
additionalname: String::new(),
name_prefix: String::new(),
name_suffix: String::new(),
@ -118,11 +116,8 @@ impl Card {
pub fn title(&self) -> &str {
self.title.as_str()
}
pub fn firstname(&self) -> &str {
self.firstname.as_str()
}
pub fn lastname(&self) -> &str {
self.lastname.as_str()
pub fn name(&self) -> &str {
self.name.as_str()
}
pub fn additionalname(&self) -> &str {
self.additionalname.as_str()
@ -152,11 +147,8 @@ impl Card {
pub fn set_title(&mut self, new: String) {
self.title = new;
}
pub fn set_firstname(&mut self, new: String) {
self.firstname = new;
}
pub fn set_lastname(&mut self, new: String) {
self.lastname = new;
pub fn set_name(&mut self, new: String) {
self.name = new;
}
pub fn set_additionalname(&mut self, new: String) {
self.additionalname = new;
@ -191,11 +183,8 @@ impl From<FnvHashMap<String, String>> for Card {
if let Some(val) = map.remove("Title") {
card.title = val;
}
if let Some(val) = map.remove("First Name") {
card.firstname = val;
}
if let Some(val) = map.remove("Last Name") {
card.lastname = val;
if let Some(val) = map.remove("Name") {
card.name = val;
}
if let Some(val) = map.remove("Additional Name") {
card.additionalname = val;

View File

@ -98,9 +98,7 @@ impl ContactManager {
self.form = FormWidget::new("Save".into());
self.form.add_button(("Cancel".into(), false));
self.form
.push(("First Name".into(), self.card.firstname().to_string()));
self.form
.push(("Last Name".into(), self.card.lastname().to_string()));
.push(("Name".into(), self.card.name().to_string()));
self.form.push((
"Additional Name".into(),
self.card.additionalname().to_string(),

View File

@ -77,25 +77,17 @@ impl ContactList {
if self.id_positions.capacity() < book.len() {
self.id_positions.reserve(book.len());
}
let mut maxima = (
"First Name".len(),
"Last Name".len(),
"E-mail".len(),
"URL".len(),
);
let mut maxima = ("Name".len(), "E-mail".len());
for c in book.values() {
self.id_positions.push(*c.id());
maxima.0 = std::cmp::max(maxima.0, c.firstname().split_graphemes().len());
maxima.1 = std::cmp::max(maxima.1, c.lastname().split_graphemes().len());
maxima.2 = std::cmp::max(maxima.2, c.email().split_graphemes().len());
maxima.3 = std::cmp::max(maxima.3, c.url().split_graphemes().len());
maxima.0 = std::cmp::max(maxima.0, c.name().split_graphemes().len());
maxima.1 = std::cmp::max(maxima.1, c.email().split_graphemes().len());
}
maxima.0 += 5;
maxima.1 += maxima.0 + 5;
maxima.2 += maxima.1 + 5;
write_string_to_grid(
"First Name",
"Name",
&mut self.content,
Color::Default,
Color::Default,
@ -103,7 +95,7 @@ impl ContactList {
false,
);
write_string_to_grid(
"Last Name",
"E-mail",
&mut self.content,
Color::Default,
Color::Default,
@ -111,26 +103,18 @@ impl ContactList {
false,
);
write_string_to_grid(
"E-mail",
"URL",
&mut self.content,
Color::Default,
Color::Default,
((maxima.1, 0), (MAX_COLS - 1, self.length)),
false,
);
write_string_to_grid(
"URL",
&mut self.content,
Color::Default,
Color::Default,
((maxima.2, 0), (MAX_COLS - 1, self.length)),
false,
);
for (i, c) in book.values().enumerate() {
self.id_positions.push(*c.id());
write_string_to_grid(
c.firstname(),
c.name(),
&mut self.content,
Color::Default,
Color::Default,
@ -138,27 +122,19 @@ impl ContactList {
false,
);
write_string_to_grid(
c.lastname(),
c.email(),
&mut self.content,
Color::Default,
Color::Default,
((maxima.0, i + 1), (MAX_COLS - 1, self.length)),
false,
);
write_string_to_grid(
c.email(),
&mut self.content,
Color::Default,
Color::Default,
((maxima.1, i + 1), (MAX_COLS - 1, self.length)),
false,
);
write_string_to_grid(
c.url(),
&mut self.content,
Color::Default,
Color::Default,
((maxima.2, i + 1), (MAX_COLS - 1, self.length)),
((maxima.1, i + 1), (MAX_COLS - 1, self.length)),
false,
);
}

View File

@ -550,7 +550,7 @@ impl Component for MailView {
let mut new_card: Card = Card::new();
new_card.set_email(env.get_email());
new_card.set_lastname(env.get_display_name());
new_card.set_name(env.get_display_name());
results.push(new_card);
}
}