Add Notification::set_urgency()

This commit is contained in:
Julian Ospald 2017-07-09 19:31:25 +02:00
parent c2efdd0842
commit 6166c861e4
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 40 additions and 0 deletions

View File

@ -33,6 +33,36 @@ use std::marker::PhantomData;
use std::os::raw::c_int;
/// The urgency level of the notification.
pub enum Urgency {
/// Low urgency. Used for unimportant notifications.
Low,
/// Normal urgency. Used for most standard notifications.
Normal,
/// Critical urgency. Used for very important notifications.
Critical,
}
impl From<sys::NotifyUrgency> for Urgency {
fn from(urgency: sys::NotifyUrgency) -> Urgency {
match urgency {
sys::NotifyUrgency::NotifyUrgencyLow => Urgency::Low,
sys::NotifyUrgency::NotifyUrgencyNormal => Urgency::Normal,
sys::NotifyUrgency::NotifyUrgencyCritical => Urgency::Critical,
}
}
}
impl From<Urgency> for sys::NotifyUrgency {
fn from(urgency: Urgency) -> sys::NotifyUrgency {
match urgency {
Urgency::Low => sys::NotifyUrgency::NotifyUrgencyLow,
Urgency::Normal => sys::NotifyUrgency::NotifyUrgencyNormal,
Urgency::Critical => sys::NotifyUrgency::NotifyUrgencyCritical,
}
}
}
/// Error that can happen on context creation
#[derive(Debug)]
@ -298,6 +328,16 @@ impl<'a> Notification<'a> {
return Ok(());
}
/// Sets the urgency level of this notification.
pub fn set_urgency(&self, urgency: Urgency) {
let urgency: sys::NotifyUrgency = From::from(urgency);
unsafe {
sys::notify_notification_set_urgency(self.handle,
urgency);
}
}
}