diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-15 23:35:30 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-15 23:38:32 +0300 |
commit | c695d7a8e2be16ec19ac3ca8af39b64c55b88bac (patch) | |
tree | f3d53e46745a4f588d26fea886349e1ff1c8b092 | |
parent | 5cf620f43c09ccc2278aedf1908f20fa3926870c (diff) |
ui: add Notification kinds
-rw-r--r-- | ui/src/components/mail/compose.rs | 13 | ||||
-rw-r--r-- | ui/src/components/mail/view.rs | 3 | ||||
-rw-r--r-- | ui/src/components/mail/view/envelope.rs | 1 | ||||
-rw-r--r-- | ui/src/components/mail/view/html.rs | 4 | ||||
-rw-r--r-- | ui/src/components/notifications.rs | 17 | ||||
-rw-r--r-- | ui/src/conf/accounts.rs | 3 | ||||
-rw-r--r-- | ui/src/state.rs | 2 | ||||
-rw-r--r-- | ui/src/types.rs | 9 |
8 files changed, 37 insertions, 15 deletions
diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs index f62decfc..2a369751 100644 --- a/ui/src/components/mail/compose.rs +++ b/ui/src/components/mail/compose.rs @@ -554,6 +554,7 @@ impl Component for Composer { context.replies.push_back(UIEvent::Notification( Some("Could not save draft.".into()), e.into(), + Some(NotificationType::ERROR), )); } context.replies.push_back(UIEvent::Action(Tab(Kill(*u)))); @@ -599,6 +600,7 @@ impl Component for Composer { .to_string(), ), e.to_string(), + Some(NotificationType::ERROR), )); return true; } @@ -627,6 +629,7 @@ impl Component for Composer { context.replies.push_back(UIEvent::Notification( Some(format!("Failed to execute {}", editor)), e.to_string(), + Some(NotificationType::ERROR), )); context.replies.push_back(UIEvent::Fork(ForkType::Finished)); context.restore_input(); @@ -651,6 +654,7 @@ impl Component for Composer { context.replies.push_back(UIEvent::Notification( Some("could not add attachment".to_string()), e.to_string(), + Some(NotificationType::ERROR), )); self.dirty = true; return true; @@ -781,6 +785,7 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) -> context.replies.push_back(UIEvent::Notification( Some("Could not save in 'Sent' folder.".into()), e.into(), + Some(NotificationType::ERROR), )); } else { failure = false; @@ -789,9 +794,11 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) -> if !failure { let output = msmtp.wait().expect("Failed to wait on mailer"); if output.success() { - context - .replies - .push_back(UIEvent::Notification(Some("Sent.".into()), String::new())); + context.replies.push_back(UIEvent::Notification( + Some("Sent.".into()), + String::new(), + None, + )); } else { if let Some(exit_code) = output.code() { log( diff --git a/ui/src/components/mail/view.rs b/ui/src/components/mail/view.rs index 43bcbf70..2767acd6 100644 --- a/ui/src/components/mail/view.rs +++ b/ui/src/components/mail/view.rs @@ -145,6 +145,7 @@ impl MailView { filter_invocation, )), String::new(), + Some(NotificationType::ERROR), )); return; } @@ -187,6 +188,7 @@ impl MailView { .to_string(), ), String::new(), + Some(NotificationType::ERROR), )); return; } @@ -941,6 +943,7 @@ impl Component for MailView { context.replies.push_back(UIEvent::Notification( Some("Sent unsubscribe email.".into()), "Sent unsubscribe email".to_string(), + None, )); return true; } diff --git a/ui/src/components/mail/view/envelope.rs b/ui/src/components/mail/view/envelope.rs index 58e49a6d..a614a21c 100644 --- a/ui/src/components/mail/view/envelope.rs +++ b/ui/src/components/mail/view/envelope.rs @@ -112,6 +112,7 @@ impl EnvelopeView { filter_invocation, )), String::new(), + Some(NotificationType::ERROR), )); return; } diff --git a/ui/src/components/mail/view/html.rs b/ui/src/components/mail/view/html.rs index 076db1ed..97ee5aba 100644 --- a/ui/src/components/mail/view/html.rs +++ b/ui/src/components/mail/view/html.rs @@ -48,9 +48,10 @@ impl HtmlView { context.replies.push_back(UIEvent::Notification( Some(format!( "Failed to start html filter process: {}", - filter_invocation + filter_invocation, )), String::new(), + Some(NotificationType::ERROR), )); String::from_utf8_lossy(&bytes).to_string() } else { @@ -93,6 +94,7 @@ impl HtmlView { context.replies.push_back(UIEvent::Notification( Some("Failed to find any application to use as html filter".to_string()), String::new(), + Some(NotificationType::ERROR), )); String::from_utf8_lossy(&bytes).to_string() }; diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs index 1ac986a0..2a3cdc8e 100644 --- a/ui/src/components/notifications.rs +++ b/ui/src/components/notifications.rs @@ -22,7 +22,7 @@ /*! Notification handling components. */ -use notify_rust::Notification as notify_Notification; +use notify_rust; use std::process::{Command, Stdio}; use super::*; @@ -41,15 +41,16 @@ impl fmt::Display for XDGNotifications { impl Component for XDGNotifications { fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool { - if let UIEvent::Notification(ref title, ref body) = event { - notify_Notification::new() + if let UIEvent::Notification(ref title, ref body, ref kind) = event { + let mut notification = notify_rust::Notification::new(); + notification .appname("meli") .icon("mail-message-new") - .summary(title.as_ref().map(String::as_str).unwrap_or("Event")) + .summary(title.as_ref().map(String::as_str).unwrap_or("meli")) .body(&escape_str(body)) - .icon("dialog-information") - .show() - .unwrap(); + .icon("dialog-information"); + + notification.show().unwrap(); } false } @@ -121,7 +122,7 @@ impl fmt::Display for NotificationFilter { impl Component for NotificationFilter { fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { - if let UIEvent::Notification(ref title, ref body) = event { + if let UIEvent::Notification(ref title, ref body, ref kind) = event { if let Some(ref bin) = context.runtime_settings.notifications.script { if let Err(v) = Command::new(bin) .arg(title.as_ref().map(String::as_str).unwrap_or("Event")) diff --git a/ui/src/conf/accounts.rs b/ui/src/conf/accounts.rs index afd9ad3c..dd4c5a3f 100644 --- a/ui/src/conf/accounts.rs +++ b/ui/src/conf/accounts.rs @@ -452,7 +452,7 @@ impl Account { } let env = self.get_env(&env_hash); return Some(Notification( - Some("new mail".into()), + Some("new e-mail".into()), format!( "{} {:.15}:\n\nFrom: {:.15}\nSubject: {:.15}", self.name, @@ -460,6 +460,7 @@ impl Account { env.subject(), env.field_from_to_string(), ), + Some(crate::types::NotificationType::NewMail), )); } RefreshEventKind::Remove(envelope_hash) => { diff --git a/ui/src/state.rs b/ui/src/state.rs index 2bf2edc8..a1007259 100644 --- a/ui/src/state.rs +++ b/ui/src/state.rs @@ -307,7 +307,7 @@ impl State { if let Some(notification) = accounts[idxa].reload(event, hash, (work_controller, sender, replies)) { - if let UIEvent::Notification(_, _) = notification { + if let UIEvent::Notification(_, _, _) = notification { self.context .replies .push_back(UIEvent::MailboxUpdate((idxa, hash))); diff --git a/ui/src/types.rs b/ui/src/types.rs index 24e5ba25..1ad54160 100644 --- a/ui/src/types.rs +++ b/ui/src/types.rs @@ -70,6 +70,13 @@ pub enum ForkType { } #[derive(Debug)] +pub enum NotificationType { + INFO, + ERROR, + NewMail, +} + +#[derive(Debug)] pub enum UIEvent { Input(Key), ExInput(Key), @@ -82,7 +89,7 @@ pub enum UIEvent { ChangeMailbox(usize), ChangeMode(UIMode), Command(String), - Notification(Option<String>, String), + Notification(Option<String>, String, Option<NotificationType>), Action(Action), StatusEvent(StatusEvent), MailboxUpdate((usize, FolderHash)), // (account_idx, mailbox_idx) |