diff --git a/Cargo.toml b/Cargo.toml index 75b6dafc..d8b45e87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 47ee6ddb..909b66c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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) -> 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.