Add Notification::set_hint()

This commit is contained in:
Julian Ospald 2017-07-09 14:23:37 +02:00
parent cdc4af3be1
commit 95263c33f8
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
2 changed files with 24 additions and 0 deletions

View File

@ -14,3 +14,4 @@ keywords = ["libnotify", "notification"]
libnotify-sys = "^0.5.0"
glib-sys = "^0.3.4"
gtypes = "^0.2.0"
glib = "^0.1.3"

View File

@ -21,6 +21,7 @@
extern crate libnotify_sys as sys;
extern crate glib_sys;
extern crate glib;
extern crate gtypes;
use std::ffi::{self, CStr, CString};
@ -28,6 +29,7 @@ use std::os::raw::c_int;
use std::marker::PhantomData;
use std::fmt;
use std::error::Error;
use glib::translate::*;
use gtypes::{TRUE, FALSE};
@ -254,6 +256,27 @@ impl<'a> Notification<'a> {
return Ok(());
}
/// Sets a hint for `key` with value `value`. If value is `None`,
/// then key is unset.
pub fn set_hint(&self, key: &str, value: Option<glib::variant::Variant>) -> Result<(), NotificationCreationError> {
let key = try!(CString::new(key));
let gvalue: *mut glib_sys::GVariant = {
match value {
Some(ref value) => value.to_glib_none().0,
None => std::ptr::null_mut(),
}
};
unsafe {
sys::notify_notification_set_hint(self.handle,
key.as_ptr(),
gvalue)
}
return Ok(());
}
}
/// An error that can happen when attempting to show a notification.