Compare commits

...

26 Commits
gir ... master

Author SHA1 Message Date
a951e61a6c
Update libnotify deps 2017-09-02 01:00:43 +02:00
d830a339e1
Update libnotify-sys deps 2017-09-02 00:59:43 +02:00
843fb0c731
Fix build against latest glib 2017-07-19 19:47:08 +02:00
afcf7a7581
Fix build against latest gtk-rs 2017-07-14 00:47:21 +02:00
831b761b02 Explicitly add LICENSE to libnotify-sys subdir
So we also make sure it ends up in the cargo crate.
2017-07-13 11:41:45 +02:00
8e955a6e08 Add badges to libnotify-sys 2017-07-13 11:35:04 +02:00
a3d579d750 Fix LICENSE link 2017-07-13 11:24:15 +02:00
6536667a4d Reorder bagdes, add download count badge 2017-07-13 11:20:23 +02:00
f954a77778 Add documentation badges 2017-07-13 11:12:44 +02:00
Ospald, Julian
fc8ca1af63 Fix documentation 2017-07-11 16:33:31 +02:00
Ospald, Julian
f28b8bc052 Bump to 1.0.1 2017-07-11 15:59:55 +02:00
Ospald, Julian
49f09df64a Remove obsolete dependency 2017-07-11 15:59:24 +02:00
Ospald, Julian
a8b22fa6ef Cosmetic README fix 2017-07-11 15:53:01 +02:00
Ospald, Julian
5f551cf664 Add README.md to libnotify-sys 2017-07-11 15:53:01 +02:00
Ospald, Julian
08d77ee4ff Update metadata 2017-07-11 15:53:01 +02:00
Ospald, Julian
03059f79c6 Remove git dependencies 2017-07-11 15:53:01 +02:00
Ospald, Julian
091ee97b70 Remove BoolError occurences
Because currently depends on unpublished glib binding.
2017-07-11 15:53:01 +02:00
Ospald, Julian
d939bee7ea Cargo fmt 2017-07-11 15:24:10 +02:00
Ospald, Julian
557ebbc93f Fix examples 2017-07-11 15:18:40 +02:00
Ospald, Julian
b50ff703ad Update README 2017-07-11 15:06:27 +02:00
Ospald, Julian
a75ae6a1fe Fix documentation 2017-07-11 14:48:23 +02:00
Ospald, Julian
d2a17eba0b Fix compiler warnings 2017-07-11 14:48:17 +02:00
Ospald, Julian
e789326c83 Update .gitignore 2017-07-11 14:36:45 +02:00
Ospald, Julian
6a96044a68 Fix examples 2017-07-11 14:36:21 +02:00
Ospald, Julian
cee315cf36 Fix travis secret 2017-07-11 14:11:04 +02:00
Ospald, Julian
ac0502b16c Merge branch 'gir' 2017-07-11 13:58:52 +02:00
14 changed files with 185 additions and 80 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
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: B8QPcNgwOmbJ8dNJn/p/tE1cLeUOLTo/Oj7nOBkK1tatMgS6yfQFa5pyNEqeTyZAyNptssqSH1BpRC3RxTJ/b+kFzdy8Kq1nkJfp9R9zTY34w5gWukfmmTH4Qe2lyWY/DKL1lGVjb+8mroV9sPaS5Y4DqYHbeYtpWF8Gi27vIL4= - secure: B9+n+ikrYqSxK1SYOHIvjtYi58IvdVC0HYJxyDiJnzIcEtos/aDiGbMZU1pIvC+qIAibdltIqzZ1afVC1msfsxeaov2e4VPKfTJV0gwLLq6tzuuaOeujtM9YUUWrdr8QQXk3LEPIl8HD5jm6VTLcl2TqPeiiyn96rk67nA5jeS8=

View File

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

View File

@ -1,8 +1,12 @@
[![Build Status](https://travis-ci.org/hasufell/rust-libnotify.svg)](https://travis-ci.org/hasufell/rust-libnotify)
[![Latest Version](https://img.shields.io/crates/v/libnotify.svg)](https://crates.io/crates/libnotify) [![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/)
# libnotify-rs [![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)
# rust-libnotify
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 and show it // Create a new notification (doesn't show it yet)
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();
// You can also use the .show() convenience method on the context // Update the existent notification
n.update("I am another notification", None, None).unwrap(); n.update("I am another notification", None, None).unwrap();
// Show the update notification // Show the updated 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 89daf8f60096fb80b7a1eff67feb0bf1bf165ec4 Subproject commit ac9a8dadb62d003af9f0c6ed46e82ff0971125e5

View File

@ -1,25 +1,30 @@
[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.7" pkg-config = ">=0.3.9"
[dependencies] [dependencies]
bitflags = "^0.9.0" bitflags = "^0.9.1"
libc = "^0.2.0" gdk-pixbuf-sys = "^0.4.0"
glib-sys = "^0.4.0"
[dependencies.gdk-pixbuf-sys] gobject-sys = "^0.4.0"
git = "https://github.com/gtk-rs/sys" libc = "^0.2.30"
[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"

21
libnotify-sys/LICENSE Normal file
View File

@ -0,0 +1,21 @@
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.

7
libnotify-sys/README.md Normal file
View File

@ -0,0 +1,7 @@
[![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;
#[macro_use] extern crate bitflags; 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,4 +43,3 @@ impl FromGlib<ffi::NotifyUrgency> for Urgency {
} }
} }
} }

View File

@ -1,6 +1,6 @@
use ffi; use ffi;
use glib::translate::*; use glib::translate::*;
use glib; use glib_ffi;
use std::ptr; use std::ptr;
@ -11,19 +11,25 @@ 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.
/// ///
/// # Returns /// # Returns
/// ///
/// `Ok(())` if successful, `Err(err)` on error. /// `Ok(())` if successful, `Err(str)` on error.
pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> { // TODO: switch back to BoolError when it hits stable glib
pub fn init(app_name: &str) -> Result<(), String> {
unsafe { 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(()),
}
} }
} }
@ -34,9 +40,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 +71,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 +110,3 @@ 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 and show it //! // Create a new notification (doesn't show it yet)
//! 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();
//! // You can also use the .show() convenience method on the context //! // Update the existent notification
//! n.update("I am another notification", None, None).unwrap(); //! n.update("I am another notification", None, None).unwrap();
//! // Show the update notification //! // Show the updated notification
//! n.show().unwrap(); //! n.show().unwrap();
//! // We are done, deinit //! // We are done, deinit
//! libnotify::uninit(); //! libnotify::uninit();

View File

@ -4,6 +4,9 @@ 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;
@ -36,14 +39,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,
))
} }
} }
@ -51,7 +62,7 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `true` on success, or `false` on error with `error` filled in /// `Ok(())` on success, or `Err(err)` on error
pub fn close(&self) -> Result<(), glib::error::Error> { pub fn close(&self) -> Result<(), glib::error::Error> {
assert_initialized_libnotify!(); assert_initialized_libnotify!();
unsafe { unsafe {
@ -70,8 +81,7 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `true` if successful. On error, this will return `false` and set /// `Ok(())` on success, or `Err(err)` on error
/// `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!();
@ -94,9 +104,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 = {
@ -107,9 +115,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,
)
} }
} }
@ -120,8 +130,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,
);
} }
} }
@ -142,7 +154,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,
);
} }
} }
@ -152,7 +167,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,
);
} }
} }
@ -165,7 +183,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,
);
} }
} }
@ -176,7 +197,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(),
);
} }
} }
@ -192,14 +216,36 @@ impl Notification {
/// ///
/// # Returns /// # Returns
/// ///
/// `true`, unless an invalid parameter was passed. /// `Ok(())` on success, or `Err(str)` 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> { // 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<(), 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 {
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") 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"),
),
_ => Ok(()),
}
} }
} }
} }