Display number of mails

pull/4/head
Benedikt Terhechte 3 years ago
parent 663366743b
commit 71f599d58e

@ -18,13 +18,14 @@ Update: It currently parses 632115 emails in ~56 seconds, so roughly `11.000` em
- [x] try re-opening a database... - [x] try re-opening a database...
- [x] save config into sqlite - [x] save config into sqlite
- [x] store last opened sqlite file - [x] store last opened sqlite file
- [ ] check if we get any values for the to_sender to_domain fields etc - [x] check if we get any values for the to_sender to_domain fields etc (only to_group seemingly has no data for my mails)
- [x] update to egui 15 - [x] update to egui 15
- [ ] add more tests - [x] add more tests
- [ ] build static linux binary via docker - [ ] build static linux binary via docker
- [ ] try to build a static windows binary - [ ] try to build a static windows binary
- [ ] update metadata in Cargo.toml - [ ] update metadata in Cargo.toml
- [ ] add app platform icons - [ ] add app platform icons
- [ ] for many mails, the segmentations don't work correctly due to async issues
## Linux Issues ## Linux Issues

@ -40,6 +40,8 @@ pub struct ImporterUI {
progress_divisions: usize, progress_divisions: usize,
/// we're done importing /// we're done importing
pub done_importing: bool, pub done_importing: bool,
/// Total amount of mails we imported
pub total_mails: usize,
/// Any errors during importing /// Any errors during importing
pub importer_error: Option<eyre::Report>, pub importer_error: Option<eyre::Report>,
/// On macOS, we lack the permission to the mail folder. This can be /// On macOS, we lack the permission to the mail folder. This can be
@ -95,6 +97,7 @@ impl ImporterUI {
progress_blocks, progress_blocks,
progress_divisions, progress_divisions,
done_importing: false, done_importing: false,
total_mails: 0,
importer_error: None, importer_error: None,
missing_permissions: false, missing_permissions: false,
}) })
@ -115,6 +118,7 @@ impl StateUIVariant for ImporterUI {
}, },
(_, true) => StateUIAction::ImportDone { (_, true) => StateUIAction::ImportDone {
config: self.config.clone(), config: self.config.clone(),
total: 0,
}, },
(_, false) => StateUIAction::Nothing, (_, false) => StateUIAction::Nothing,
} }
@ -129,7 +133,7 @@ impl ImporterUI {
let available = ui.available_size(); let available = ui.available_size();
let (label, progress, writing, done) = match self.handle_adapter() { let (label, progress, writing, done, written) = match self.handle_adapter() {
Ok(state) => { Ok(state) => {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
if state.missing_permissions { if state.missing_permissions {
@ -140,14 +144,15 @@ impl ImporterUI {
label, label,
progress, progress,
writing, writing,
written,
done, done,
.. ..
} = state; } = state;
(label, progress, writing, done) (label, progress, writing, done, written)
} }
Err(e) => { Err(e) => {
// Generate a response signifying we're done - as there was an error // Generate a response signifying we're done - as there was an error
let response = (format!("Error {}", &e), 1.0, false, true); let response = (format!("Error {}", &e), 1.0, false, true, 0);
self.importer_error = Some(e); self.importer_error = Some(e);
response response
} }
@ -163,6 +168,7 @@ impl ImporterUI {
self.importer_error = handle.join().ok().map(|e| e.err()).flatten(); self.importer_error = handle.join().ok().map(|e| e.err()).flatten();
} }
self.done_importing = true; self.done_importing = true;
self.total_mails = written;
} }
let n = (self.progress_blocks.len() as f32 * progress) as usize; let n = (self.progress_blocks.len() as f32 * progress) as usize;
@ -280,6 +286,7 @@ struct InternalAdapterState {
label: String, label: String,
progress: f32, progress: f32,
writing: bool, writing: bool,
written: usize,
done: bool, done: bool,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
missing_permissions: bool, missing_permissions: bool,
@ -309,6 +316,7 @@ impl ImporterUI {
let State { let State {
done, done,
finishing, finishing,
written,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
missing_permissions, missing_permissions,
} = self.adapter.finished()?; } = self.adapter.finished()?;
@ -320,6 +328,7 @@ impl ImporterUI {
label, label,
progress, progress,
writing, writing,
written,
done, done,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
missing_permissions, missing_permissions,

@ -22,10 +22,11 @@ pub struct MainUI {
error: Option<Report>, error: Option<Report>,
state: UIState, state: UIState,
filter_state: FilterState, filter_state: FilterState,
total: usize,
} }
impl MainUI { impl MainUI {
pub fn new(config: Config) -> Result<Self> { pub fn new(config: Config, total: usize) -> Result<Self> {
let mut engine = Engine::new(&config)?; let mut engine = Engine::new(&config)?;
engine.start()?; engine.start()?;
Ok(Self { Ok(Self {
@ -34,6 +35,7 @@ impl MainUI {
error: None, error: None,
state: UIState::default(), state: UIState::default(),
filter_state: FilterState::new(), filter_state: FilterState::new(),
total,
}) })
} }
} }
@ -55,7 +57,7 @@ impl StateUIVariant for MainUI {
.fill(platform_colors.window_background) .fill(platform_colors.window_background)
.stroke(Stroke::none()); .stroke(Stroke::none());
egui::TopBottomPanel::top("my_panel") egui::TopBottomPanel::top("panel")
.frame(frame) .frame(frame)
.show(ctx, |ui| { .show(ctx, |ui| {
ui.add(super::super::navigation_bar::NavigationBar::new( ui.add(super::super::navigation_bar::NavigationBar::new(
@ -63,11 +65,12 @@ impl StateUIVariant for MainUI {
&mut self.error, &mut self.error,
&mut self.state, &mut self.state,
&mut self.filter_state, &mut self.filter_state,
self.total,
)); ));
}); });
if self.state.show_emails { if self.state.show_emails {
egui::SidePanel::right("my_left_panel") egui::SidePanel::right("left_panel")
.default_width(500.0) .default_width(500.0)
.show(ctx, |ui| { .show(ctx, |ui| {
ui.add(super::super::mail_panel::MailPanel::new( ui.add(super::super::mail_panel::MailPanel::new(

@ -27,6 +27,7 @@ pub enum StateUIAction {
}, },
ImportDone { ImportDone {
config: Config, config: Config,
total: usize,
}, },
Close { Close {
config: Config, config: Config,
@ -77,8 +78,8 @@ impl StateUI {
StateUIAction::OpenDatabase { database_path } => { StateUIAction::OpenDatabase { database_path } => {
*self = self.open_database(database_path) *self = self.open_database(database_path)
} }
StateUIAction::ImportDone { config } => { StateUIAction::ImportDone { config, total } => {
*self = match main::MainUI::new(config.clone()) { *self = match main::MainUI::new(config.clone(), total) {
Ok(n) => StateUI::Main(n), Ok(n) => StateUI::Main(n),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))), Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))),
}; };
@ -122,7 +123,13 @@ impl StateUI {
Err(report) => return StateUI::Error(error::ErrorUI::new(report, None)), Err(report) => return StateUI::Error(error::ErrorUI::new(report, None)),
}; };
match main::MainUI::new(config.clone()) { let total =
match crate::database::Database::new(&database_path).and_then(|db| db.total_mails()) {
Ok(config) => config,
Err(report) => return StateUI::Error(error::ErrorUI::new(report, None)),
};
match main::MainUI::new(config.clone(), total) {
Ok(n) => StateUI::Main(n), Ok(n) => StateUI::Main(n),
Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))), Err(e) => StateUI::Error(ErrorUI::new(e, Some(config.clone()))),
} }

@ -1,6 +1,7 @@
use crate::model::Engine; use crate::model::Engine;
use eframe::egui::{self, Color32, Widget}; use eframe::egui::{self, Color32, Label, Widget};
use eyre::Report; use eyre::Report;
use num_format::{Locale, ToFormattedString};
use super::app_state::UIState; use super::app_state::UIState;
use super::platform::navigation_button; use super::platform::navigation_button;
@ -12,6 +13,7 @@ pub struct NavigationBar<'a> {
error: &'a mut Option<Report>, error: &'a mut Option<Report>,
state: &'a mut UIState, state: &'a mut UIState,
filter_state: &'a mut FilterState, filter_state: &'a mut FilterState,
total_mails: usize,
} }
impl<'a> NavigationBar<'a> { impl<'a> NavigationBar<'a> {
@ -20,12 +22,14 @@ impl<'a> NavigationBar<'a> {
error: &'a mut Option<Report>, error: &'a mut Option<Report>,
state: &'a mut UIState, state: &'a mut UIState,
filter_state: &'a mut FilterState, filter_state: &'a mut FilterState,
total_mails: usize,
) -> Self { ) -> Self {
NavigationBar { NavigationBar {
engine, engine,
error, error,
state, state,
filter_state, filter_state,
total_mails,
} }
} }
} }
@ -58,6 +62,11 @@ impl<'a> Widget for NavigationBar<'a> {
ui.add(FilterPanel::new(self.engine, self.filter_state, self.error)); ui.add(FilterPanel::new(self.engine, self.filter_state, self.error));
}); });
ui.add(Label::new(format!(
"{} Mails",
self.total_mails.to_formatted_string(&Locale::en)
)));
// This is a hack to get right-alignment. // This is a hack to get right-alignment.
// we can't size the button, we can only size text. We will size text // we can't size the button, we can only size text. We will size text
// and then use ~that for these buttons // and then use ~that for these buttons

@ -30,6 +30,7 @@ pub struct Progress {
pub struct State { pub struct State {
pub finishing: bool, pub finishing: bool,
pub done: bool, pub done: bool,
pub written: usize,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub missing_permissions: bool, pub missing_permissions: bool,
} }
@ -129,6 +130,7 @@ impl Adapter {
Ok(State { Ok(State {
finishing: item.finishing, finishing: item.finishing,
done: item.done, done: item.done,
written: item.total_write,
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
missing_permissions: item.missing_permissions, missing_permissions: item.missing_permissions,
}) })

Loading…
Cancel
Save