From 091ee97b70b82a1a8cbe1a73ab7e4ba0a4f9b97c Mon Sep 17 00:00:00 2001 From: "Ospald, Julian" Date: Tue, 11 Jul 2017 15:35:10 +0200 Subject: [PATCH] Remove BoolError occurences Because currently depends on unpublished glib binding. --- src/functions.rs | 19 ++++++++++++------- src/notification.rs | 24 ++++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/functions.rs b/src/functions.rs index 4d48c144..b2312a98 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -1,6 +1,6 @@ use ffi; use glib::translate::*; -use glib; +use glib_ffi; use std::ptr; @@ -18,13 +18,18 @@ pub fn is_initted() -> bool { /// /// # Returns /// -/// `Ok(())` if successful, `Err(err)` on error. -pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> { +/// `Ok(())` if successful, `Err(str)` on error. +// TODO: switch back to BoolError when it hits stable glib +pub fn init(app_name: &str) -> Result<(), String> { unsafe { - glib::error::BoolError::from_glib( - ffi::notify_init(app_name.to_glib_none().0), - "Failed to initialize libnotify", - ) + let b = ffi::notify_init(app_name.to_glib_none().0); + + match b { + glib_ffi::GFALSE => Err( + String::from("Failed to initialize libnotify"), + ), + _ => Ok(()), + } } } diff --git a/src/notification.rs b/src/notification.rs index eeafbf88..172ab924 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -214,7 +214,8 @@ impl Notification { /// # Returns /// /// `true`, unless an invalid parameter was passed. - /// `Ok(())` on success, or `Err(err)` if an invalid parameter was passed + /// `Ok(())` on success, or `Err(str)` if an invalid parameter was passed + // TODO: switch back to BoolError when it hits stable glib pub fn update< 'a, 'b, @@ -225,21 +226,24 @@ impl Notification { summary: &str, body: P, icon: Q, - ) -> Result<(), glib::error::BoolError> { + ) -> Result<(), String> { let body = body.into(); let body = body.to_glib_none(); let icon = icon.into(); let icon = icon.to_glib_none(); unsafe { - glib::error::BoolError::from_glib( - ffi::notify_notification_update( - self.to_glib_none().0, - summary.to_glib_none().0, - body.0, - icon.0, + let b = ffi::notify_notification_update( + self.to_glib_none().0, + summary.to_glib_none().0, + body.0, + icon.0, + ); + match b { + glib_ffi::GFALSE => Err( + String::from("Invalid parameter passed"), ), - "Invalid parameter passed", - ) + _ => Ok(()), + } } } }