2020-02-08 23:42:31 +02:00
|
|
|
/*
|
|
|
|
* meli
|
|
|
|
*
|
|
|
|
* Copyright 2020 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::*;
|
2020-10-21 13:13:46 +03:00
|
|
|
use crate::components::PageMovement;
|
2020-02-08 23:42:31 +02:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct OfflineListing {
|
2020-08-17 15:31:30 +03:00
|
|
|
cursor_pos: (AccountHash, MailboxHash),
|
2020-02-08 23:42:31 +02:00
|
|
|
_row_updates: SmallVec<[ThreadHash; 8]>,
|
2020-07-25 20:41:26 +03:00
|
|
|
_selection: HashMap<ThreadHash, bool>,
|
2020-07-08 00:26:40 +03:00
|
|
|
dirty: bool,
|
2020-02-08 23:42:31 +02:00
|
|
|
id: ComponentId,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MailListingTrait for OfflineListing {
|
|
|
|
fn row_updates(&mut self) -> &mut SmallVec<[ThreadHash; 8]> {
|
|
|
|
&mut self._row_updates
|
|
|
|
}
|
|
|
|
|
2020-07-25 20:41:26 +03:00
|
|
|
fn selection(&mut self) -> &mut HashMap<ThreadHash, bool> {
|
|
|
|
&mut self._selection
|
|
|
|
}
|
|
|
|
|
2020-02-08 23:42:31 +02:00
|
|
|
fn get_focused_items(&self, _context: &Context) -> SmallVec<[ThreadHash; 8]> {
|
|
|
|
return SmallVec::new();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn refresh_mailbox(&mut self, _context: &mut Context, _force: bool) {}
|
2020-06-07 14:25:33 +03:00
|
|
|
fn redraw_threads_list(
|
|
|
|
&mut self,
|
|
|
|
_context: &Context,
|
|
|
|
_items: Box<dyn Iterator<Item = ThreadHash>>,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
fn redraw_envelope_list(
|
|
|
|
&mut self,
|
|
|
|
_context: &Context,
|
|
|
|
_items: Box<dyn Iterator<Item = EnvelopeHash>>,
|
|
|
|
) {
|
|
|
|
}
|
2020-02-08 23:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ListingTrait for OfflineListing {
|
2020-08-17 15:31:30 +03:00
|
|
|
fn coordinates(&self) -> (AccountHash, MailboxHash) {
|
2020-02-08 23:42:31 +02:00
|
|
|
self.cursor_pos
|
|
|
|
}
|
|
|
|
|
2020-08-17 15:31:30 +03:00
|
|
|
fn set_coordinates(&mut self, coordinates: (AccountHash, MailboxHash)) {
|
2020-02-08 23:42:31 +02:00
|
|
|
self.cursor_pos = coordinates;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn highlight_line(
|
|
|
|
&mut self,
|
|
|
|
_grid: &mut CellBuffer,
|
|
|
|
_area: Area,
|
|
|
|
_idx: usize,
|
|
|
|
_context: &Context,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw_list(&mut self, _: &mut CellBuffer, _: Area, _: &mut Context) {}
|
|
|
|
|
|
|
|
fn set_movement(&mut self, _: PageMovement) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for OfflineListing {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "mail")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OfflineListing {
|
2020-08-17 15:31:30 +03:00
|
|
|
pub fn new(cursor_pos: (AccountHash, MailboxHash)) -> Self {
|
2020-02-08 23:42:31 +02:00
|
|
|
OfflineListing {
|
|
|
|
cursor_pos,
|
|
|
|
_row_updates: SmallVec::new(),
|
2020-07-25 20:41:26 +03:00
|
|
|
_selection: HashMap::default(),
|
2020-07-08 00:26:40 +03:00
|
|
|
dirty: true,
|
2020-02-08 23:42:31 +02:00
|
|
|
id: ComponentId::new_v4(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Component for OfflineListing {
|
2020-05-08 11:00:45 +03:00
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
2020-07-08 00:26:40 +03:00
|
|
|
if !self.dirty {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.dirty = false;
|
2020-05-08 11:00:45 +03:00
|
|
|
let theme_default = conf::value(context, "theme_default");
|
|
|
|
clear_area(grid, area, theme_default);
|
|
|
|
if let Err(err) = context.is_online(self.cursor_pos.0) {
|
|
|
|
let (x, _) = write_string_to_grid(
|
|
|
|
"offline: ",
|
|
|
|
grid,
|
|
|
|
Color::Byte(243),
|
|
|
|
theme_default.bg,
|
|
|
|
theme_default.attrs,
|
|
|
|
area,
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
write_string_to_grid(
|
|
|
|
&err.to_string(),
|
|
|
|
grid,
|
|
|
|
Color::Red,
|
|
|
|
theme_default.bg,
|
|
|
|
theme_default.attrs,
|
|
|
|
(set_x(upper_left!(area), x + 1), bottom_right!(area)),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
} else {
|
2020-07-08 00:26:40 +03:00
|
|
|
let (_, mut y) = write_string_to_grid(
|
|
|
|
"loading...",
|
|
|
|
grid,
|
|
|
|
Color::Byte(243),
|
|
|
|
theme_default.bg,
|
|
|
|
theme_default.attrs,
|
|
|
|
area,
|
|
|
|
None,
|
|
|
|
);
|
2020-08-17 15:31:30 +03:00
|
|
|
let mut jobs: SmallVec<[_; 64]> = context.accounts[&self.cursor_pos.0]
|
2020-07-08 00:26:40 +03:00
|
|
|
.active_jobs
|
|
|
|
.iter()
|
|
|
|
.collect();
|
|
|
|
jobs.sort_by_key(|(j, _)| *j);
|
|
|
|
for (job_id, j) in jobs {
|
|
|
|
write_string_to_grid(
|
|
|
|
&format!("{}: {:?}", job_id, j),
|
|
|
|
grid,
|
|
|
|
theme_default.fg,
|
|
|
|
theme_default.bg,
|
|
|
|
theme_default.attrs,
|
|
|
|
(set_y(upper_left!(area), y + 1), bottom_right!(area)),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
y += 1;
|
|
|
|
}
|
|
|
|
|
2020-05-08 11:00:45 +03:00
|
|
|
context
|
|
|
|
.replies
|
|
|
|
.push_back(UIEvent::AccountStatusChange(self.cursor_pos.0));
|
|
|
|
}
|
|
|
|
context.dirty_areas.push_back(area);
|
|
|
|
}
|
2020-07-08 00:26:40 +03:00
|
|
|
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool {
|
|
|
|
match event {
|
2020-08-17 15:31:30 +03:00
|
|
|
UIEvent::AccountStatusChange(account_hash) if *account_hash == self.cursor_pos.0 => {
|
|
|
|
self.dirty = true
|
|
|
|
}
|
2020-07-08 00:26:40 +03:00
|
|
|
_ => {}
|
|
|
|
}
|
2020-02-08 23:42:31 +02:00
|
|
|
false
|
|
|
|
}
|
|
|
|
fn is_dirty(&self) -> bool {
|
2020-07-08 00:26:40 +03:00
|
|
|
self.dirty
|
|
|
|
}
|
|
|
|
|
2020-07-13 18:49:27 +03:00
|
|
|
fn set_dirty(&mut self, _value: bool) {
|
2020-07-08 00:26:40 +03:00
|
|
|
self.dirty = true;
|
2020-02-08 23:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn id(&self) -> ComponentId {
|
|
|
|
self.id
|
|
|
|
}
|
|
|
|
fn set_id(&mut self, id: ComponentId) {
|
|
|
|
self.id = id;
|
|
|
|
}
|
|
|
|
}
|