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(
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(

View File

@ -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;
}

View File

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

View File

@ -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()
};

View File

@ -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"))

View File

@ -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) => {

View File

@ -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)));

View File

@ -69,6 +69,13 @@ pub enum ForkType {
NewDraft(File, std::process::Child),
}
#[derive(Debug)]
pub enum NotificationType {
INFO,
ERROR,
NewMail,
}
#[derive(Debug)]
pub enum UIEvent {
Input(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)