mirror of https://git.meli.delivery/meli/meli
ui: add contacts and account panel
parent
07a51de0b6
commit
92bb3bf8d3
@ -0,0 +1,160 @@
|
||||
/*
|
||||
* meli - addressbook module
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
use chrono::{DateTime, Local};
|
||||
use uuid::Uuid;
|
||||
use fnv::FnvHashMap;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct AddressBook {
|
||||
display_name: String,
|
||||
created: DateTime<Local>,
|
||||
last_edited: DateTime<Local>,
|
||||
cards: FnvHashMap<Uuid, Card>
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct Card {
|
||||
uuid: Uuid,
|
||||
title: String,
|
||||
firstname: String,
|
||||
lastname: String,
|
||||
additionalname: String,
|
||||
name_prefix: String,
|
||||
name_suffix: String,
|
||||
//address
|
||||
|
||||
birthday: Option<DateTime<Local>>,
|
||||
email: String,
|
||||
url: String,
|
||||
key: String,
|
||||
|
||||
last_edited: DateTime<Local>,
|
||||
extra_properties: FnvHashMap<String, String>
|
||||
}
|
||||
|
||||
impl AddressBook {
|
||||
pub fn new(display_name: String) -> AddressBook {
|
||||
AddressBook {
|
||||
display_name,
|
||||
created: Local::now(),
|
||||
last_edited: Local::now(),
|
||||
cards: FnvHashMap::default(),
|
||||
}
|
||||
}
|
||||
pub fn add_card(&mut self, card: Card) {
|
||||
self.cards.insert(card.uuid, card);
|
||||
}
|
||||
pub fn remove_card(&mut self, card_uuid: Uuid) {
|
||||
self.cards.remove(&card_uuid);
|
||||
}
|
||||
pub fn card_exists(&self, card_uuid: Uuid) -> bool {
|
||||
self.cards.contains_key(&card_uuid)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Card {
|
||||
pub fn new() -> Card {
|
||||
Card {
|
||||
uuid: Uuid::new_v4(),
|
||||
title: String::new(),
|
||||
firstname: String::new(),
|
||||
lastname: String::new(),
|
||||
additionalname: String::new(),
|
||||
name_prefix: String::new(),
|
||||
name_suffix: String::new(),
|
||||
//address
|
||||
|
||||
birthday: None,
|
||||
email: String::new(),
|
||||
url: String::new(),
|
||||
key: String::new(),
|
||||
|
||||
last_edited: Local::now(),
|
||||
extra_properties: FnvHashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
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 additionalname(&self) -> &str {
|
||||
self.additionalname.as_str()
|
||||
}
|
||||
pub fn name_prefix(&self) -> &str {
|
||||
self.name_prefix.as_str()
|
||||
}
|
||||
pub fn name_suffix(&self) -> &str {
|
||||
self.name_suffix.as_str()
|
||||
}
|
||||
pub fn email(&self) -> &str {
|
||||
self.email.as_str()
|
||||
}
|
||||
pub fn url(&self) -> &str {
|
||||
self.url.as_str()
|
||||
}
|
||||
pub fn key(&self) -> &str {
|
||||
self.key.as_str()
|
||||
}
|
||||
|
||||
pub fn set_title(&mut self, new: &str) {
|
||||
self.title = new.to_string();()
|
||||
}
|
||||
pub fn set_firstname(&mut self, new: &str) {
|
||||
self.firstname = new.to_string();
|
||||
}
|
||||
pub fn set_lastname(&mut self, new: &str) {
|
||||
self.lastname = new.to_string();
|
||||
}
|
||||
pub fn set_additionalname(&mut self, new: &str) {
|
||||
self.additionalname = new.to_string();
|
||||
}
|
||||
pub fn set_name_prefix(&mut self, new: &str) {
|
||||
self.name_prefix = new.to_string();
|
||||
}
|
||||
pub fn set_name_suffix(&mut self, new: &str) {
|
||||
self.name_suffix = new.to_string();
|
||||
}
|
||||
pub fn set_email(&mut self, new: &str) {
|
||||
self.email = new.to_string();
|
||||
}
|
||||
pub fn set_url(&mut self, new: &str) {
|
||||
self.url = new.to_string();
|
||||
}
|
||||
pub fn set_key(&mut self, new: &str) {
|
||||
self.key = new.to_string();
|
||||
}
|
||||
|
||||
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(|v| v.as_str())
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* meli - contacts module
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
|
||||
use melib::{AddressBook, Card};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ContactManager {
|
||||
content: CellBuffer,
|
||||
dirty: bool,
|
||||
initialized: bool,
|
||||
}
|
||||
|
||||
impl Default for ContactManager {
|
||||
fn default() -> Self {
|
||||
ContactManager {
|
||||
content: CellBuffer::default(),
|
||||
dirty: true,
|
||||
initialized: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ContactManager {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "contacts")
|
||||
}
|
||||
}
|
||||
|
||||
impl ContactManager {
|
||||
}
|
||||
|
||||
impl Component for ContactManager {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
if !self.initialized {
|
||||
clear_area(grid, area);
|
||||
self.initialized = true;
|
||||
}
|
||||
context.dirty_areas.push_back(area);
|
||||
}
|
||||
|
||||
fn process_event(&mut self, event: &UIEvent, context: &mut Context) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
|
||||
fn set_dirty(&mut self) {
|
||||
self.dirty = true;
|
||||
self.initialized = false;
|
||||
}
|
||||
|
||||
fn kill(&mut self, uuid: Uuid) {
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* meli - ui crate.
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ContactsPanel {
|
||||
content: CellBuffer,
|
||||
dirty: bool,
|
||||
}
|
||||
|
||||
impl fmt::Display for ContactsPanel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "contacts")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Component for ContactsPanel {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
if self.dirty {
|
||||
self.dirty = false;
|
||||
}
|
||||
clear_area(grid, area);
|
||||
|
||||
let (width, height) = self.content.size();
|
||||
copy_area(grid, &self.content, area, ((0, 0), (width - 1, height - 1)));
|
||||
context.dirty_areas.push_back(area);
|
||||
}
|
||||
fn process_event(&mut self, event: &UIEvent, context: &mut Context) -> bool {
|
||||
false
|
||||
}
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
fn set_dirty(&mut self) {
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl ContactsPanel {
|
||||
pub fn new(context: &Context) -> ContactsPanel {
|
||||
let mut content = CellBuffer::new(120, 25 + context.accounts.len() * 20, Cell::default());
|
||||
write_string_to_grid(
|
||||
"Contacts",
|
||||
&mut content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((2, 3), (120 - 1, 3)),
|
||||
true,
|
||||
);
|
||||
|
||||
for (i, a) in context.accounts.iter().enumerate() {
|
||||
create_box(&mut content, ((2,5+i*10 ), (120-1, 15+i*10)));
|
||||
let (x, y) = write_string_to_grid(
|
||||
a.name(),
|
||||
&mut content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((3, 5 + i*10), (120 - 2, 5 + i*10)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
" ▒██▒ ",
|
||||
&mut content,
|
||||
Color::Byte(32),
|
||||
Color::Default,
|
||||
((x, y), (120 - 2, 5 + i*10)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
&a.runtime_settings.account().identity,
|
||||
&mut content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((4, y + 2), (120 - 2, y + 2)),
|
||||
true,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
ContactsPanel {
|
||||
content,
|
||||
dirty: true,
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
/*
|
||||
* meli - accounts module.
|
||||
*
|
||||
* Copyright 2019 Manos Pitsidianakis
|
||||
*
|
||||
* This file is part of meli.
|
||||
*
|
||||
* meli is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* meli 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with meli. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
mod contacts;
|
||||
|
||||
pub use contacts::*;
|
||||
|
||||
use super::*;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AccountsPanel {
|
||||
cursor: usize,
|
||||
content: CellBuffer,
|
||||
dirty: bool,
|
||||
}
|
||||
|
||||
impl fmt::Display for AccountsPanel {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "accounts")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Component for AccountsPanel {
|
||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||
if self.dirty {
|
||||
write_string_to_grid(
|
||||
"Accounts",
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((2, 3), (120 - 1, 3)),
|
||||
true,
|
||||
);
|
||||
|
||||
for (i, a) in context.accounts.iter().enumerate() {
|
||||
create_box(&mut self.content, ((2,5+i*10 ), (120-1, 15+i*10)));
|
||||
let (x, y) = write_string_to_grid(
|
||||
a.name(),
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((3, 5 + i*10), (120 - 2, 5 + i*10)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
" ▒██▒ ",
|
||||
&mut self.content,
|
||||
Color::Byte(32),
|
||||
Color::Default,
|
||||
((x, y), (120 - 2, 5 + i*10)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
&a.runtime_settings.account().identity,
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((4, y + 2), (120 - 2, y + 2)),
|
||||
true,
|
||||
);
|
||||
if i == self.cursor {
|
||||
for h in 1..8 {
|
||||
self.content[(2, h+y+1)].set_ch('*');
|
||||
}
|
||||
}
|
||||
write_string_to_grid(
|
||||
"- Settings",
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((5, y + 3), (120 - 2, y + 3)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
"- Contacts",
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((5, y + 4), (120 - 2, y + 4)),
|
||||
true,
|
||||
);
|
||||
write_string_to_grid(
|
||||
"- Mailing Lists",
|
||||
&mut self.content,
|
||||
Color::Default,
|
||||
Color::Default,
|
||||
((5, y + 5), (120 - 2, y + 5)),
|
||||
true,
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
self.dirty = false;
|
||||
}
|
||||
clear_area(grid, area);
|
||||
|
||||
let (width, height) = self.content.size();
|
||||
copy_area(grid, &self.content, area, ((0, 0), (width - 1, height - 1)));
|
||||
context.dirty_areas.push_back(area);
|
||||
}
|
||||
fn process_event(&mut self, event: &UIEvent, context: &mut Context) -> bool {
|
||||
match event.event_type {
|
||||
UIEventType::Input(Key::Up) => {
|
||||
self.cursor = self.cursor.saturating_sub(1);
|
||||
self.dirty = true;
|
||||
return true;
|
||||
},
|
||||
UIEventType::Input(Key::Down) => {
|
||||
if self.cursor + 1 < context.accounts.len() {
|
||||
self.cursor += 1;
|
||||
self.dirty = true;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
fn is_dirty(&self) -> bool {
|
||||
self.dirty
|
||||
}
|
||||
fn set_dirty(&mut self) {
|
||||
self.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl AccountsPanel {
|
||||
pub fn new(context: &Context) -> AccountsPanel {
|
||||
let mut content = CellBuffer::new(120, 25 + context.accounts.len() * 20, Cell::default());
|
||||
|
||||
AccountsPanel {
|
||||
cursor: 0,
|
||||
content,
|
||||
dirty: true,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue