Cargo fmt
This commit is contained in:
parent
557ebbc93f
commit
d939bee7ea
@ -27,7 +27,7 @@ impl ToGlib for Urgency {
|
|||||||
Urgency::Low => ffi::NOTIFY_URGENCY_LOW,
|
Urgency::Low => ffi::NOTIFY_URGENCY_LOW,
|
||||||
Urgency::Normal => ffi::NOTIFY_URGENCY_NORMAL,
|
Urgency::Normal => ffi::NOTIFY_URGENCY_NORMAL,
|
||||||
Urgency::Critical => ffi::NOTIFY_URGENCY_CRITICAL,
|
Urgency::Critical => ffi::NOTIFY_URGENCY_CRITICAL,
|
||||||
Urgency::__Unknown(value) => unsafe{std::mem::transmute(value)}
|
Urgency::__Unknown(value) => unsafe { std::mem::transmute(value) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,4 +43,3 @@ impl FromGlib<ffi::NotifyUrgency> for Urgency {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,7 @@ use std::ptr;
|
|||||||
///
|
///
|
||||||
/// `true` if libnotify is initialized, or `false` otherwise.
|
/// `true` if libnotify is initialized, or `false` otherwise.
|
||||||
pub fn is_initted() -> bool {
|
pub fn is_initted() -> bool {
|
||||||
unsafe {
|
unsafe { from_glib(ffi::notify_is_initted()) }
|
||||||
from_glib(ffi::notify_is_initted())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialized libnotify. This must be called before any other functions.
|
/// Initialized libnotify. This must be called before any other functions.
|
||||||
@ -23,7 +21,10 @@ pub fn is_initted() -> bool {
|
|||||||
/// `Ok(())` if successful, `Err(err)` on error.
|
/// `Ok(())` if successful, `Err(err)` on error.
|
||||||
pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> {
|
pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
glib::error::BoolError::from_glib(ffi::notify_init(app_name.to_glib_none().0), "Failed to initialize libnotify")
|
glib::error::BoolError::from_glib(
|
||||||
|
ffi::notify_init(app_name.to_glib_none().0),
|
||||||
|
"Failed to initialize libnotify",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +35,7 @@ pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> {
|
|||||||
/// The registered application name, passed to `init()`.
|
/// The registered application name, passed to `init()`.
|
||||||
pub fn get_app_name() -> Option<String> {
|
pub fn get_app_name() -> Option<String> {
|
||||||
assert_initialized_libnotify!();
|
assert_initialized_libnotify!();
|
||||||
unsafe {
|
unsafe { from_glib_none(ffi::notify_get_app_name()) }
|
||||||
from_glib_none(ffi::notify_get_app_name())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Synchronously queries the server for its capabilities and returns them as
|
/// Synchronously queries the server for its capabilities and returns them as
|
||||||
@ -67,8 +66,22 @@ pub fn get_server_info() -> Option<(String, String, String, String)> {
|
|||||||
let mut ret_vendor = ptr::null_mut();
|
let mut ret_vendor = ptr::null_mut();
|
||||||
let mut ret_version = ptr::null_mut();
|
let mut ret_version = ptr::null_mut();
|
||||||
let mut ret_spec_version = ptr::null_mut();
|
let mut ret_spec_version = ptr::null_mut();
|
||||||
let ret = from_glib(ffi::notify_get_server_info(&mut ret_name, &mut ret_vendor, &mut ret_version, &mut ret_spec_version));
|
let ret = from_glib(ffi::notify_get_server_info(
|
||||||
if ret { Some((from_glib_full(ret_name), from_glib_full(ret_vendor), from_glib_full(ret_version), from_glib_full(ret_spec_version))) } else { None }
|
&mut ret_name,
|
||||||
|
&mut ret_vendor,
|
||||||
|
&mut ret_version,
|
||||||
|
&mut ret_spec_version,
|
||||||
|
));
|
||||||
|
if ret {
|
||||||
|
Some((
|
||||||
|
from_glib_full(ret_name),
|
||||||
|
from_glib_full(ret_vendor),
|
||||||
|
from_glib_full(ret_version),
|
||||||
|
from_glib_full(ret_spec_version),
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,4 +105,3 @@ pub fn uninit() {
|
|||||||
ffi::notify_uninit();
|
ffi::notify_uninit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,14 +36,22 @@ impl Notification {
|
|||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// The new `Notification`.
|
/// The new `Notification`.
|
||||||
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(summary: &str, body: P, icon: Q) -> Notification {
|
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(
|
||||||
|
summary: &str,
|
||||||
|
body: P,
|
||||||
|
icon: Q,
|
||||||
|
) -> Notification {
|
||||||
assert_initialized_libnotify!();
|
assert_initialized_libnotify!();
|
||||||
let body = body.into();
|
let body = body.into();
|
||||||
let body = body.to_glib_none();
|
let body = body.to_glib_none();
|
||||||
let icon = icon.into();
|
let icon = icon.into();
|
||||||
let icon = icon.to_glib_none();
|
let icon = icon.to_glib_none();
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_full(ffi::notify_notification_new(summary.to_glib_none().0, body.0, icon.0))
|
from_glib_full(ffi::notify_notification_new(
|
||||||
|
summary.to_glib_none().0,
|
||||||
|
body.0,
|
||||||
|
icon.0,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,9 +101,7 @@ impl Notification {
|
|||||||
/// ## `key`
|
/// ## `key`
|
||||||
/// the hint key
|
/// the hint key
|
||||||
/// ## `value`
|
/// ## `value`
|
||||||
pub fn set_hint(&self,
|
pub fn set_hint(&self, key: &str, value: Option<glib::variant::Variant>) {
|
||||||
key: &str,
|
|
||||||
value: Option<glib::variant::Variant>) {
|
|
||||||
assert_initialized_libnotify!();
|
assert_initialized_libnotify!();
|
||||||
|
|
||||||
let gvalue: *mut glib_ffi::GVariant = {
|
let gvalue: *mut glib_ffi::GVariant = {
|
||||||
@ -106,9 +112,11 @@ impl Notification {
|
|||||||
};
|
};
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_hint(self.to_glib_none().0,
|
ffi::notify_notification_set_hint(
|
||||||
|
self.to_glib_none().0,
|
||||||
key.to_glib_none().0,
|
key.to_glib_none().0,
|
||||||
gvalue)
|
gvalue,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +127,10 @@ impl Notification {
|
|||||||
assert_initialized_libnotify!();
|
assert_initialized_libnotify!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_image_from_pixbuf(self.to_glib_none().0,
|
ffi::notify_notification_set_image_from_pixbuf(
|
||||||
pixbuf.to_glib_none().0);
|
self.to_glib_none().0,
|
||||||
|
pixbuf.to_glib_none().0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +151,10 @@ impl Notification {
|
|||||||
let app_name = app_name.into();
|
let app_name = app_name.into();
|
||||||
let app_name = app_name.to_glib_none();
|
let app_name = app_name.to_glib_none();
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_app_name(self.to_glib_none().0, app_name.0);
|
ffi::notify_notification_set_app_name(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
app_name.0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +164,10 @@ impl Notification {
|
|||||||
/// The category.
|
/// The category.
|
||||||
pub fn set_category(&self, category: &str) {
|
pub fn set_category(&self, category: &str) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_category(self.to_glib_none().0, category.to_glib_none().0);
|
ffi::notify_notification_set_category(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
category.to_glib_none().0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +180,10 @@ impl Notification {
|
|||||||
/// The timeout in milliseconds.
|
/// The timeout in milliseconds.
|
||||||
pub fn set_timeout(&self, timeout: i32) {
|
pub fn set_timeout(&self, timeout: i32) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_timeout(self.to_glib_none().0, timeout);
|
ffi::notify_notification_set_timeout(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
timeout,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +194,10 @@ impl Notification {
|
|||||||
/// The urgency level.
|
/// The urgency level.
|
||||||
pub fn set_urgency(&self, urgency: Urgency) {
|
pub fn set_urgency(&self, urgency: Urgency) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::notify_notification_set_urgency(self.to_glib_none().0, urgency.to_glib());
|
ffi::notify_notification_set_urgency(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
urgency.to_glib(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,13 +215,31 @@ impl Notification {
|
|||||||
///
|
///
|
||||||
/// `true`, unless an invalid parameter was passed.
|
/// `true`, unless an invalid parameter was passed.
|
||||||
/// `Ok(())` on success, or `Err(err)` if an invalid parameter was passed
|
/// `Ok(())` on success, or `Err(err)` if an invalid parameter was passed
|
||||||
pub fn update<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(&self, summary: &str, body: P, icon: Q) -> Result<(), glib::error::BoolError> {
|
pub fn update<
|
||||||
|
'a,
|
||||||
|
'b,
|
||||||
|
P: Into<Option<&'a str>>,
|
||||||
|
Q: Into<Option<&'b str>>,
|
||||||
|
>(
|
||||||
|
&self,
|
||||||
|
summary: &str,
|
||||||
|
body: P,
|
||||||
|
icon: Q,
|
||||||
|
) -> Result<(), glib::error::BoolError> {
|
||||||
let body = body.into();
|
let body = body.into();
|
||||||
let body = body.to_glib_none();
|
let body = body.to_glib_none();
|
||||||
let icon = icon.into();
|
let icon = icon.into();
|
||||||
let icon = icon.to_glib_none();
|
let icon = icon.to_glib_none();
|
||||||
unsafe {
|
unsafe {
|
||||||
glib::error::BoolError::from_glib(ffi::notify_notification_update(self.to_glib_none().0, summary.to_glib_none().0, body.0, icon.0), "Invalid parameter passed")
|
glib::error::BoolError::from_glib(
|
||||||
|
ffi::notify_notification_update(
|
||||||
|
self.to_glib_none().0,
|
||||||
|
summary.to_glib_none().0,
|
||||||
|
body.0,
|
||||||
|
icon.0,
|
||||||
|
),
|
||||||
|
"Invalid parameter passed",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user