ui: add Notification kinds

embed
Manos Pitsidianakis 2019-09-15 23:35:30 +03:00
parent 5cf620f43c
commit c695d7a8e2
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
8 changed files with 37 additions and 15 deletions

View File

@ -554,6 +554,7 @@ impl Component for Composer {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some("Could not save draft.".into()), Some("Could not save draft.".into()),
e.into(), e.into(),
Some(NotificationType::ERROR),
)); ));
} }
context.replies.push_back(UIEvent::Action(Tab(Kill(*u)))); context.replies.push_back(UIEvent::Action(Tab(Kill(*u))));
@ -599,6 +600,7 @@ impl Component for Composer {
.to_string(), .to_string(),
), ),
e.to_string(), e.to_string(),
Some(NotificationType::ERROR),
)); ));
return true; return true;
} }
@ -627,6 +629,7 @@ impl Component for Composer {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some(format!("Failed to execute {}", editor)), Some(format!("Failed to execute {}", editor)),
e.to_string(), e.to_string(),
Some(NotificationType::ERROR),
)); ));
context.replies.push_back(UIEvent::Fork(ForkType::Finished)); context.replies.push_back(UIEvent::Fork(ForkType::Finished));
context.restore_input(); context.restore_input();
@ -651,6 +654,7 @@ impl Component for Composer {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some("could not add attachment".to_string()), Some("could not add attachment".to_string()),
e.to_string(), e.to_string(),
Some(NotificationType::ERROR),
)); ));
self.dirty = true; self.dirty = true;
return 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( context.replies.push_back(UIEvent::Notification(
Some("Could not save in 'Sent' folder.".into()), Some("Could not save in 'Sent' folder.".into()),
e.into(), e.into(),
Some(NotificationType::ERROR),
)); ));
} else { } else {
failure = false; failure = false;
@ -789,9 +794,11 @@ pub fn send_draft(context: &mut Context, account_cursor: usize, draft: Draft) ->
if !failure { if !failure {
let output = msmtp.wait().expect("Failed to wait on mailer"); let output = msmtp.wait().expect("Failed to wait on mailer");
if output.success() { if output.success() {
context context.replies.push_back(UIEvent::Notification(
.replies Some("Sent.".into()),
.push_back(UIEvent::Notification(Some("Sent.".into()), String::new())); String::new(),
None,
));
} else { } else {
if let Some(exit_code) = output.code() { if let Some(exit_code) = output.code() {
log( log(

View File

@ -145,6 +145,7 @@ impl MailView {
filter_invocation, filter_invocation,
)), )),
String::new(), String::new(),
Some(NotificationType::ERROR),
)); ));
return; return;
} }
@ -187,6 +188,7 @@ impl MailView {
.to_string(), .to_string(),
), ),
String::new(), String::new(),
Some(NotificationType::ERROR),
)); ));
return; return;
} }
@ -941,6 +943,7 @@ impl Component for MailView {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some("Sent unsubscribe email.".into()), Some("Sent unsubscribe email.".into()),
"Sent unsubscribe email".to_string(), "Sent unsubscribe email".to_string(),
None,
)); ));
return true; return true;
} }

View File

@ -112,6 +112,7 @@ impl EnvelopeView {
filter_invocation, filter_invocation,
)), )),
String::new(), String::new(),
Some(NotificationType::ERROR),
)); ));
return; return;
} }

View File

@ -48,9 +48,10 @@ impl HtmlView {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some(format!( Some(format!(
"Failed to start html filter process: {}", "Failed to start html filter process: {}",
filter_invocation filter_invocation,
)), )),
String::new(), String::new(),
Some(NotificationType::ERROR),
)); ));
String::from_utf8_lossy(&bytes).to_string() String::from_utf8_lossy(&bytes).to_string()
} else { } else {
@ -93,6 +94,7 @@ impl HtmlView {
context.replies.push_back(UIEvent::Notification( context.replies.push_back(UIEvent::Notification(
Some("Failed to find any application to use as html filter".to_string()), Some("Failed to find any application to use as html filter".to_string()),
String::new(), String::new(),
Some(NotificationType::ERROR),
)); ));
String::from_utf8_lossy(&bytes).to_string() String::from_utf8_lossy(&bytes).to_string()
}; };

View File

@ -22,7 +22,7 @@
/*! /*!
Notification handling components. Notification handling components.
*/ */
use notify_rust::Notification as notify_Notification; use notify_rust;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use super::*; use super::*;
@ -41,15 +41,16 @@ impl fmt::Display for XDGNotifications {
impl Component for XDGNotifications { impl Component for XDGNotifications {
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool { 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 {
notify_Notification::new() let mut notification = notify_rust::Notification::new();
notification
.appname("meli") .appname("meli")
.icon("mail-message-new") .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)) .body(&escape_str(body))
.icon("dialog-information") .icon("dialog-information");
.show()
.unwrap(); notification.show().unwrap();
} }
false false
} }
@ -121,7 +122,7 @@ impl fmt::Display for NotificationFilter {
impl Component for NotificationFilter { impl Component for NotificationFilter {
fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {} fn draw(&mut self, _grid: &mut CellBuffer, _area: Area, _context: &mut Context) {}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool { 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 Some(ref bin) = context.runtime_settings.notifications.script {
if let Err(v) = Command::new(bin) if let Err(v) = Command::new(bin)
.arg(title.as_ref().map(String::as_str).unwrap_or("Event")) .arg(title.as_ref().map(String::as_str).unwrap_or("Event"))

View File

@ -452,7 +452,7 @@ impl Account {
} }
let env = self.get_env(&env_hash); let env = self.get_env(&env_hash);
return Some(Notification( return Some(Notification(
Some("new mail".into()), Some("new e-mail".into()),
format!( format!(
"{} {:.15}:\n\nFrom: {:.15}\nSubject: {:.15}", "{} {:.15}:\n\nFrom: {:.15}\nSubject: {:.15}",
self.name, self.name,
@ -460,6 +460,7 @@ impl Account {
env.subject(), env.subject(),
env.field_from_to_string(), env.field_from_to_string(),
), ),
Some(crate::types::NotificationType::NewMail),
)); ));
} }
RefreshEventKind::Remove(envelope_hash) => { RefreshEventKind::Remove(envelope_hash) => {

View File

@ -307,7 +307,7 @@ impl State {
if let Some(notification) = if let Some(notification) =
accounts[idxa].reload(event, hash, (work_controller, sender, replies)) accounts[idxa].reload(event, hash, (work_controller, sender, replies))
{ {
if let UIEvent::Notification(_, _) = notification { if let UIEvent::Notification(_, _, _) = notification {
self.context self.context
.replies .replies
.push_back(UIEvent::MailboxUpdate((idxa, hash))); .push_back(UIEvent::MailboxUpdate((idxa, hash)));

View File

@ -69,6 +69,13 @@ pub enum ForkType {
NewDraft(File, std::process::Child), NewDraft(File, std::process::Child),
} }
#[derive(Debug)]
pub enum NotificationType {
INFO,
ERROR,
NewMail,
}
#[derive(Debug)] #[derive(Debug)]
pub enum UIEvent { pub enum UIEvent {
Input(Key), Input(Key),
@ -82,7 +89,7 @@ pub enum UIEvent {
ChangeMailbox(usize), ChangeMailbox(usize),
ChangeMode(UIMode), ChangeMode(UIMode),
Command(String), Command(String),
Notification(Option<String>, String), Notification(Option<String>, String, Option<NotificationType>),
Action(Action), Action(Action),
StatusEvent(StatusEvent), StatusEvent(StatusEvent),
MailboxUpdate((usize, FolderHash)), // (account_idx, mailbox_idx) MailboxUpdate((usize, FolderHash)), // (account_idx, mailbox_idx)