summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-04-10 16:48:25 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:44 +0300
commit0e2e8b09f6403a80967487eff8dc04d9ab3c008a (patch)
treef72a364b53b3664dc419477de992408b5e51d64d
parentadb3123c574bcd0ef264f6ccd1807aa6206cdaed (diff)
ui: update accounts tab on mailboxupdate
-rw-r--r--ui/src/components/mail/accounts.rs159
-rw-r--r--ui/src/conf/accounts.rs44
2 files changed, 138 insertions, 65 deletions
diff --git a/ui/src/components/mail/accounts.rs b/ui/src/components/mail/accounts.rs
index c3684a4b..42ee3f8d 100644
--- a/ui/src/components/mail/accounts.rs
+++ b/ui/src/components/mail/accounts.rs
@@ -38,71 +38,7 @@ impl fmt::Display for AccountsPanel {
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.initialize(context);
self.dirty = false;
}
clear_area(grid, area);
@@ -134,6 +70,9 @@ impl Component for AccountsPanel {
});
return true;
}
+ UIEventType::MailboxUpdate(_) => {
+ self.dirty = true;
+ }
_ => {}
}
@@ -157,4 +96,94 @@ impl AccountsPanel {
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,
+ );
+ }
+ }
}
diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs
index 56209299..05bf8997 100644
--- a/ui/src/conf/accounts.rs
+++ b/ui/src/conf/accounts.rs
@@ -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 {
pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self {
let mut backend = map.get(settings.account().format())(settings.account());
@@ -313,6 +351,12 @@ impl Account {
self.backend
.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 {