Compare commits

..

No commits in common. "master" and "gir" have entirely different histories.
master ... gir

14 changed files with 81 additions and 186 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
Cargo.lock Cargo.lock
target/ target/
.cargo/ .cargo/
docs.md

View File

@ -27,4 +27,4 @@ after_success:
env: env:
global: global:
- TRAVIS_CARGO_NIGHTLY_FEATURE="" - TRAVIS_CARGO_NIGHTLY_FEATURE=""
- secure: B9+n+ikrYqSxK1SYOHIvjtYi58IvdVC0HYJxyDiJnzIcEtos/aDiGbMZU1pIvC+qIAibdltIqzZ1afVC1msfsxeaov2e4VPKfTJV0gwLLq6tzuuaOeujtM9YUUWrdr8QQXk3LEPIl8HD5jm6VTLcl2TqPeiiyn96rk67nA5jeS8= - secure: B8QPcNgwOmbJ8dNJn/p/tE1cLeUOLTo/Oj7nOBkK1tatMgS6yfQFa5pyNEqeTyZAyNptssqSH1BpRC3RxTJ/b+kFzdy8Kq1nkJfp9R9zTY34w5gWukfmmTH4Qe2lyWY/DKL1lGVjb+8mroV9sPaS5Y4DqYHbeYtpWF8Gi27vIL4=

View File

@ -1,24 +1,19 @@
[package] [package]
authors = [
"Mika Attila <radiantstatue@gmail.com>",
"Julian Ospald <hasufell@posteo.de>",
]
description = "Rust bindings to libnotify"
documentation = "https://hasufell.github.io/rust-libnotify/libnotify/"
keywords = [
"libnotify",
"notification",
]
license = "MIT"
name = "libnotify" name = "libnotify"
version = "1.0.0"
authors = ["Mika Attila <radiantstatue@gmail.com>", "Julian Ospald <hasufell@posteo.de>"]
license = "MIT"
description = "Rust bindings to libnotify"
readme = "README.md" readme = "README.md"
repository = "https://github.com/hasufell/rust-libnotify" repository = "https://github.com/crumblingstatue/rust-libnotify"
version = "1.0.2" documentation = "http://crumblingstatue.github.io/doc/libnotify/libnotify/"
keywords = ["libnotify", "notification"]
[dependencies] [dependencies]
gdk-pixbuf = "^0.2.0" error-chain = ">=0.10.0"
gdk-pixbuf-sys = "^0.4.0" gdk-pixbuf = { git = "https://github.com/gtk-rs/gdk-pixbuf.git" }
glib = "^0.3.1" gdk-pixbuf-sys = { git = "https://github.com/gtk-rs/sys" }
glib-sys = "^0.4.0" glib = { git = "https://github.com/gtk-rs/glib.git" }
gobject-sys = "^0.4.0" glib-sys = { git = "https://github.com/gtk-rs/sys" }
libnotify-sys = "^1.0.1" gobject-sys = { git = "https://github.com/gtk-rs/sys" }
libnotify-sys = { path = "libnotify-sys" }

View File

@ -1,12 +1,8 @@
[![Latest Version](https://img.shields.io/crates/v/libnotify.svg)](https://crates.io/crates/libnotify)
[![License](https://img.shields.io/github/license/hasufell/rust-libnotify.svg)](LICENSE)
[![Crate download count](https://img.shields.io/crates/d/libnotify.svg)](https://crates.io/crates/libnotify)
[![Documentation (crates.io)](https://img.shields.io/badge/documentation-docs.rs-df3600.svg)](https://docs.rs/libnotify)
[![Documentation (master)](https://img.shields.io/badge/documentation-master-yellow.svg)](https://hasufell.github.io/rust-libnotify/)
[![Build Status](https://travis-ci.org/hasufell/rust-libnotify.svg)](https://travis-ci.org/hasufell/rust-libnotify) [![Build Status](https://travis-ci.org/hasufell/rust-libnotify.svg)](https://travis-ci.org/hasufell/rust-libnotify)
[![Join the chat at https://gitter.im/hasufell/rust-libnotify](https://badges.gitter.im/hasufell/rust-libnotify.svg)](https://gitter.im/hasufell/rust-libnotify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Latest Version](https://img.shields.io/crates/v/libnotify.svg)](https://crates.io/crates/libnotify)
# rust-libnotify
# libnotify-rs
Rust binding to libnotify. Rust binding to libnotify.
* [Online documentation](https://hasufell.github.io/rust-libnotify/)

View File

@ -3,14 +3,14 @@ extern crate libnotify;
fn main() { fn main() {
// Init libnotify // Init libnotify
libnotify::init("myapp"); libnotify::init("myapp");
// Create a new notification (doesn't show it yet) // Create a new notification and show it
let n = let n =
libnotify::Notification::new("Summary", Some("Optional Body"), None); libnotify::Notification::new("Summary", Some("Optional Body"), None);
// Show the notification // Show the notification
n.show().unwrap(); n.show().unwrap();
// Update the existent notification // You can also use the .show() convenience method on the context
n.update("I am another notification", None, None).unwrap(); n.update("I am another notification", None, None).unwrap();
// Show the updated notification // Show the update notification
n.show().unwrap(); n.show().unwrap();
// We are done, deinit // We are done, deinit
libnotify::uninit(); libnotify::uninit();

2
gir

@ -1 +1 @@
Subproject commit ac9a8dadb62d003af9f0c6ed46e82ff0971125e5 Subproject commit 89daf8f60096fb80b7a1eff67feb0bf1bf165ec4

View File

@ -1,30 +1,25 @@
[package]
authors = [
"Mika Attila <radiantstatue@gmail.com>",
"Julian Ospald <hasufell@posteo.de>",
]
build = "build.rs"
description = "FFI bindings to libnotify"
keywords = [
"libnotify",
"notification",
]
license = "MIT"
links = "libnotify"
name = "libnotify-sys"
readme = "README.md"
repository = "https://github.com/hasufell/rust-libnotify"
version = "1.0.1"
[build-dependencies] [build-dependencies]
pkg-config = ">=0.3.9" pkg-config = ">=0.3.7"
[dependencies] [dependencies]
bitflags = "^0.9.1" bitflags = "^0.9.0"
gdk-pixbuf-sys = "^0.4.0" libc = "^0.2.0"
glib-sys = "^0.4.0"
gobject-sys = "^0.4.0" [dependencies.gdk-pixbuf-sys]
libc = "^0.2.30" git = "https://github.com/gtk-rs/sys"
[dependencies.glib-sys]
git = "https://github.com/gtk-rs/sys"
[dependencies.gobject-sys]
git = "https://github.com/gtk-rs/sys"
[lib] [lib]
name = "libnotify_sys" name = "libnotify_sys"
[package]
build = "build.rs"
links = "libnotify"
name = "libnotify-sys"
version = "1.0.0"

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Mika Attila
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,7 +0,0 @@
[![Latest Version](https://img.shields.io/crates/v/libnotify-sys.svg)](https://crates.io/crates/libnotify-sys)
[![License](https://img.shields.io/github/license/hasufell/rust-libnotify.svg)](LICENSE)
[![Crate download count](https://img.shields.io/crates/d/libnotify-sys.svg)](https://crates.io/crates/libnotify-sys)
# rust-libnotify-sys
Rust FFI declarations for libnotify

View File

@ -4,7 +4,7 @@
#![allow(non_camel_case_types, non_upper_case_globals)] #![allow(non_camel_case_types, non_upper_case_globals)]
extern crate libc; extern crate libc;
extern crate bitflags; #[macro_use] extern crate bitflags;
extern crate glib_sys as glib; extern crate glib_sys as glib;
extern crate gobject_sys as gobject; extern crate gobject_sys as gobject;
extern crate gdk_pixbuf_sys as gdk_pixbuf; extern crate gdk_pixbuf_sys as gdk_pixbuf;

View File

@ -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,3 +43,4 @@ impl FromGlib<ffi::NotifyUrgency> for Urgency {
} }
} }
} }

View File

@ -1,6 +1,6 @@
use ffi; use ffi;
use glib::translate::*; use glib::translate::*;
use glib_ffi; use glib;
use std::ptr; use std::ptr;
@ -11,25 +11,19 @@ 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 { from_glib(ffi::notify_is_initted()) } unsafe {
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.
/// ///
/// # Returns /// # Returns
/// ///
/// `Ok(())` if successful, `Err(str)` on error. /// `Ok(())` if successful, `Err(err)` on error.
// TODO: switch back to BoolError when it hits stable glib pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> {
pub fn init(app_name: &str) -> Result<(), String> {
unsafe { unsafe {
let b = ffi::notify_init(app_name.to_glib_none().0); glib::error::BoolError::from_glib(ffi::notify_init(app_name.to_glib_none().0), "Failed to initialize libnotify")
match b {
glib_ffi::GFALSE => Err(
String::from("Failed to initialize libnotify"),
),
_ => Ok(()),
}
} }
} }
@ -40,7 +34,9 @@ pub fn init(app_name: &str) -> Result<(), String> {
/// 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 { from_glib_none(ffi::notify_get_app_name()) } unsafe {
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
@ -71,22 +67,8 @@ 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( let ret = from_glib(ffi::notify_get_server_info(&mut ret_name, &mut ret_vendor, &mut ret_version, &mut ret_spec_version));
&mut ret_name, 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_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
}
} }
} }
@ -110,3 +92,4 @@ pub fn uninit() {
ffi::notify_uninit(); ffi::notify_uninit();
} }
} }

View File

@ -6,15 +6,15 @@
//! fn main() { //! fn main() {
//! // Init libnotify //! // Init libnotify
//! libnotify::init("myapp").unwrap(); //! libnotify::init("myapp").unwrap();
//! // Create a new notification (doesn't show it yet) //! // Create a new notification and show it
//! let n = libnotify::Notification::new("Summary", //! let n = libnotify::Notification::new("Summary",
//! Some("Optional Body"), //! Some("Optional Body"),
//! None); //! None);
//! // Show the notification //! // Show the notification
//! n.show().unwrap(); //! n.show().unwrap();
//! // Update the existent notification //! // You can also use the .show() convenience method on the context
//! n.update("I am another notification", None, None).unwrap(); //! n.update("I am another notification", None, None).unwrap();
//! // Show the updated notification //! // Show the update notification
//! n.show().unwrap(); //! n.show().unwrap();
//! // We are done, deinit //! // We are done, deinit
//! libnotify::uninit(); //! libnotify::uninit();

View File

@ -4,9 +4,6 @@ use gdk_pixbuf;
use glib::translate::*; use glib::translate::*;
use glib; use glib;
use glib_ffi; use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;
use std; use std;
@ -39,22 +36,14 @@ 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>>>( pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b str>>>(summary: &str, body: P, icon: Q) -> Notification {
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( from_glib_full(ffi::notify_notification_new(summary.to_glib_none().0, body.0, icon.0))
summary.to_glib_none().0,
body.0,
icon.0,
))
} }
} }
@ -62,7 +51,7 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `Ok(())` on success, or `Err(err)` on error /// `true` on success, or `false` on error with `error` filled in
pub fn close(&self) -> Result<(), glib::error::Error> { pub fn close(&self) -> Result<(), glib::error::Error> {
assert_initialized_libnotify!(); assert_initialized_libnotify!();
unsafe { unsafe {
@ -81,7 +70,8 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `Ok(())` on success, or `Err(err)` on error /// `true` if successful. On error, this will return `false` and set
/// `error`.
// TODO: test if Error leaks memory // TODO: test if Error leaks memory
pub fn show(&self) -> Result<(), glib::error::Error> { pub fn show(&self) -> Result<(), glib::error::Error> {
assert_initialized_libnotify!(); assert_initialized_libnotify!();
@ -104,7 +94,9 @@ impl Notification {
/// ## `key` /// ## `key`
/// the hint key /// the hint key
/// ## `value` /// ## `value`
pub fn set_hint(&self, key: &str, value: Option<glib::variant::Variant>) { pub fn set_hint(&self,
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 = {
@ -115,11 +107,9 @@ impl Notification {
}; };
unsafe { unsafe {
ffi::notify_notification_set_hint( ffi::notify_notification_set_hint(self.to_glib_none().0,
self.to_glib_none().0,
key.to_glib_none().0, key.to_glib_none().0,
gvalue, gvalue)
)
} }
} }
@ -130,10 +120,8 @@ impl Notification {
assert_initialized_libnotify!(); assert_initialized_libnotify!();
unsafe { unsafe {
ffi::notify_notification_set_image_from_pixbuf( ffi::notify_notification_set_image_from_pixbuf(self.to_glib_none().0,
self.to_glib_none().0, pixbuf.to_glib_none().0);
pixbuf.to_glib_none().0,
);
} }
} }
@ -154,10 +142,7 @@ 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( ffi::notify_notification_set_app_name(self.to_glib_none().0, app_name.0);
self.to_glib_none().0,
app_name.0,
);
} }
} }
@ -167,10 +152,7 @@ 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( ffi::notify_notification_set_category(self.to_glib_none().0, category.to_glib_none().0);
self.to_glib_none().0,
category.to_glib_none().0,
);
} }
} }
@ -183,10 +165,7 @@ 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( ffi::notify_notification_set_timeout(self.to_glib_none().0, timeout);
self.to_glib_none().0,
timeout,
);
} }
} }
@ -197,10 +176,7 @@ 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( ffi::notify_notification_set_urgency(self.to_glib_none().0, urgency.to_glib());
self.to_glib_none().0,
urgency.to_glib(),
);
} }
} }
@ -216,36 +192,14 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `Ok(())` on success, or `Err(str)` if an invalid parameter was passed /// `true`, unless an invalid parameter was passed.
// TODO: switch back to BoolError when it hits stable glib 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<(), String> {
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 {
let b = ffi::notify_notification_update( 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")
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"),
),
_ => Ok(()),
}
} }
} }
} }