ui: update accounts tab on mailboxupdate
parent
adb3123c57
commit
0e2e8b09f6
|
@ -38,71 +38,7 @@ impl fmt::Display for AccountsPanel {
|
||||||
impl Component for AccountsPanel {
|
impl Component for AccountsPanel {
|
||||||
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
||||||
if self.dirty {
|
if self.dirty {
|
||||||
write_string_to_grid(
|
self.initialize(context);
|
||||||
"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;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
clear_area(grid, area);
|
clear_area(grid, area);
|
||||||
|
@ -134,6 +70,9 @@ impl Component for AccountsPanel {
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
UIEventType::MailboxUpdate(_) => {
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,4 +96,94 @@ impl AccountsPanel {
|
||||||
dirty: true,
|
dirty: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn initialize(&mut self, context: &Context) {
|
||||||
|
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() {
|
||||||
|
for x in 2..(120 - 1) {
|
||||||
|
set_and_join_box(&mut self.content, (x, 5 + i * 10), HORZ_BOUNDARY);
|
||||||
|
}
|
||||||
|
//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('*');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for h in 1..8 {
|
||||||
|
self.content[(2, h + y + 1)].set_ch(' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let (x, _) = write_string_to_grid(
|
||||||
|
"- Settings",
|
||||||
|
&mut self.content,
|
||||||
|
Color::Default,
|
||||||
|
Color::Default,
|
||||||
|
((5, y + 3), (120 - 2, y + 3)),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
write_string_to_grid(
|
||||||
|
&format!(
|
||||||
|
"total {}",
|
||||||
|
a.iter_mailboxes().fold(0, |mut acc, m| {
|
||||||
|
acc += m
|
||||||
|
.map(|m| m.collection.values().filter(|e| !e.is_seen()).count())
|
||||||
|
.unwrap_or(0);
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
),
|
||||||
|
&mut self.content,
|
||||||
|
Color::Default,
|
||||||
|
Color::Default,
|
||||||
|
((10 + x, 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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,44 @@ impl Drop for Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct MailboxIterator<'a> {
|
||||||
|
folders: &'a [Option<Result<Mailbox>>],
|
||||||
|
pos: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for MailboxIterator<'a> {
|
||||||
|
type Item = Option<&'a Mailbox>;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Option<&'a Mailbox>> {
|
||||||
|
eprintln!(
|
||||||
|
"self.pos = {}, iter.len {}",
|
||||||
|
self.pos,
|
||||||
|
self.folders[self.pos..]
|
||||||
|
.iter()
|
||||||
|
.collect::<Vec<&Option<Result<Mailbox>>>>()
|
||||||
|
.len()
|
||||||
|
);
|
||||||
|
if self.pos == self.folders.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
for f in self.folders[self.pos..].iter() {
|
||||||
|
if self.pos == self.folders.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.pos += 1;
|
||||||
|
if let Some(Err(_)) = f {
|
||||||
|
return Some(None);
|
||||||
|
}
|
||||||
|
if let None = f {
|
||||||
|
return Some(None);
|
||||||
|
}
|
||||||
|
return Some(Some(f.as_ref().unwrap().as_ref().unwrap()));
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self {
|
pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self {
|
||||||
let mut backend = map.get(settings.account().format())(settings.account());
|
let mut backend = map.get(settings.account().format())(settings.account());
|
||||||
|
@ -313,6 +351,12 @@ impl Account {
|
||||||
self.backend
|
self.backend
|
||||||
.save(&finalize.as_bytes(), &self.settings.conf.draft_folder)
|
.save(&finalize.as_bytes(), &self.settings.conf.draft_folder)
|
||||||
}
|
}
|
||||||
|
pub fn iter_mailboxes<'a>(&'a self) -> MailboxIterator<'a> {
|
||||||
|
MailboxIterator {
|
||||||
|
folders: &self.folders,
|
||||||
|
pos: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<usize> for Account {
|
impl Index<usize> for Account {
|
||||||
|
|
Loading…
Reference in New Issue