/*
* meli - ui crate.
*
* Copyright 2017-2018 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 .
*/
/*! Entities that handle Mail specific functions.
*/
use super::*;
use melib::backends::Folder;
pub mod listing;
pub use listing::*;
pub mod view;
pub use view::*;
mod compose;
pub use self::compose::*;
mod accounts;
pub use self::accounts::*;
#[derive(Debug)]
struct AccountMenuEntry {
name: String,
// Index in the config account vector.
index: usize,
// Each entry and its index in the account
entries: Vec<(usize, Folder)>,
}
/// The account sidebar.
#[derive(Debug)]
pub struct AccountMenu {
accounts: Vec,
dirty: bool,
cursor: Option<(usize, usize)>,
}
impl fmt::Display for AccountMenu {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO display subject/info
write!(f, "menu")
}
}
impl AccountMenu {
pub fn new(accounts: &[Account]) -> Self {
let accounts = accounts
.iter()
.enumerate()
.map(|(i, a)| AccountMenuEntry {
name: a.name().to_string(),
index: i,
entries: {
let mut entries = Vec::with_capacity(a.len());
for (idx, acc) in a.list_folders().into_iter().enumerate() {
entries.push((idx, acc));
}
entries
},
})
.collect();
AccountMenu {
accounts,
dirty: true,
cursor: None,
}
}
/*
* Print a single account in the menu area.
*/
fn print_account(
&self,
grid: &mut CellBuffer,
area: Area,
a: &AccountMenuEntry,
context: &mut Context,
) -> usize {
if !is_valid_area!(area) {
eprintln!("BUG: invalid area in print_account");
}
let upper_left = upper_left!(area);
let bottom_right = bottom_right!(area);
let highlight = self.cursor.map(|(x, _)| x == a.index).unwrap_or(false);
let mut parents: Vec