Add Notification::update()
This commit is contained in:
parent
8c66220a4e
commit
cdc4af3be1
41
src/lib.rs
41
src/lib.rs
@ -66,6 +66,8 @@ pub enum NotificationCreationError {
|
|||||||
NulError(ffi::NulError),
|
NulError(ffi::NulError),
|
||||||
/// An unknown error happened.
|
/// An unknown error happened.
|
||||||
Unknown,
|
Unknown,
|
||||||
|
/// Invalid parameter passed to a glib function
|
||||||
|
InvalidParameter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for NotificationCreationError {
|
impl fmt::Display for NotificationCreationError {
|
||||||
@ -74,6 +76,7 @@ impl fmt::Display for NotificationCreationError {
|
|||||||
match *self {
|
match *self {
|
||||||
NulError(ref e) => write!(f, "{}", e),
|
NulError(ref e) => write!(f, "{}", e),
|
||||||
Unknown => write!(f, "Unknown error"),
|
Unknown => write!(f, "Unknown error"),
|
||||||
|
InvalidParameter => write!(f, "An invalid parameter was passed"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,6 +216,44 @@ impl<'a> Notification<'a> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the notification text and icon. This won't send the update
|
||||||
|
/// out and display it on the screen. For that, you will need to
|
||||||
|
/// call `.show()`.
|
||||||
|
pub fn update(&self,
|
||||||
|
summary: &str,
|
||||||
|
body: Option<&str>,
|
||||||
|
icon: Option<&str>) -> Result<(), NotificationCreationError> {
|
||||||
|
let summary = try!(CString::new(summary));
|
||||||
|
let body = match body {
|
||||||
|
Some(body) => Some(try!(CString::new(body))),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
let body_ptr = match body {
|
||||||
|
Some(ref body) => body.as_ptr(),
|
||||||
|
None => std::ptr::null(),
|
||||||
|
};
|
||||||
|
let icon = match icon {
|
||||||
|
Some(icon) => Some(try!(CString::new(icon))),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
let icon_ptr = match icon {
|
||||||
|
Some(ref icon) => icon.as_ptr(),
|
||||||
|
None => std::ptr::null(),
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let b = sys::notify_notification_update(self.handle,
|
||||||
|
summary.as_ptr(),
|
||||||
|
body_ptr,
|
||||||
|
icon_ptr);
|
||||||
|
if b == FALSE {
|
||||||
|
return Err(NotificationCreationError::InvalidParameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error that can happen when attempting to show a notification.
|
/// An error that can happen when attempting to show a notification.
|
||||||
|
Loading…
Reference in New Issue
Block a user