summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-15 23:36:30 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-15 23:38:32 +0300
commitbd8424c1f894ae0d1b8bf8f2893c4bd8795446b9 (patch)
tree448398ff4b9cd78ece8fb02bd1465a57f61e31cb
parentc695d7a8e2be16ec19ac3ca8af39b64c55b88bac (diff)
ui: add notification `play_sound`, `sound_file` conf settings
-rw-r--r--ui/src/components/notifications.rs20
-rw-r--r--ui/src/conf.rs4
-rw-r--r--ui/src/conf/notifications.rs7
3 files changed, 30 insertions, 1 deletions
diff --git a/ui/src/components/notifications.rs b/ui/src/components/notifications.rs
index 2a3cdc8e..706275bd 100644
--- a/ui/src/components/notifications.rs
+++ b/ui/src/components/notifications.rs
@@ -40,8 +40,9 @@ 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 {
+ fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if let UIEvent::Notification(ref title, ref body, ref kind) = event {
+ let settings = &context.runtime_settings.notifications;
let mut notification = notify_rust::Notification::new();
notification
.appname("meli")
@@ -49,6 +50,23 @@ impl Component for XDGNotifications {
.summary(title.as_ref().map(String::as_str).unwrap_or("meli"))
.body(&escape_str(body))
.icon("dialog-information");
+ match kind {
+ Some(NotificationType::NewMail) => {
+ notification.hint(notify_rust::hints::NotificationHint::Category(
+ "email".to_owned(),
+ ));
+ }
+ _ => {}
+ }
+ if settings.play_sound.is_true() {
+ if let Some(ref sound_path) = settings.sound_file {
+ notification.hint(notify_rust::hints::NotificationHint::SoundFile(
+ sound_path.to_owned(),
+ ));
+ } else {
+ notification.sound_name("message-new-email");
+ }
+ }
notification.show().unwrap();
}
diff --git a/ui/src/conf.rs b/ui/src/conf.rs
index 09c8decf..218f1458 100644
--- a/ui/src/conf.rs
+++ b/ui/src/conf.rs
@@ -470,6 +470,10 @@ mod default_vals {
pub(in crate::conf) fn none<T>() -> Option<T> {
None
}
+
+ pub(in crate::conf) fn internal_value_false() -> super::ToggleFlag {
+ super::ToggleFlag::InternalVal(false)
+ }
}
impl<'de> Deserialize<'de> for IndexStyle {
diff --git a/ui/src/conf/notifications.rs b/ui/src/conf/notifications.rs
index 663ab7cf..c450e2b4 100644
--- a/ui/src/conf/notifications.rs
+++ b/ui/src/conf/notifications.rs
@@ -19,6 +19,9 @@
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
+use super::default_vals::internal_value_false;
+use super::toggleflag_de;
+
fn none() -> Option<String> {
None
}
@@ -30,4 +33,8 @@ pub struct NotificationsSettings {
/// Default: None
#[serde(default = "none")]
pub script: Option<String>,
+ #[serde(deserialize_with = "toggleflag_de", default = "internal_value_false")]
+ pub play_sound: super::ToggleFlag,
+ #[serde(default = "none")]
+ pub sound_file: Option<String>,
}