Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
a951e61a6c | |||
d830a339e1 | |||
843fb0c731 | |||
afcf7a7581 | |||
831b761b02 | |||
8e955a6e08 | |||
a3d579d750 | |||
6536667a4d | |||
f954a77778 | |||
![]() |
fc8ca1af63 | ||
![]() |
f28b8bc052 | ||
![]() |
49f09df64a | ||
![]() |
a8b22fa6ef | ||
![]() |
5f551cf664 | ||
![]() |
08d77ee4ff | ||
![]() |
03059f79c6 | ||
![]() |
091ee97b70 | ||
![]() |
d939bee7ea | ||
![]() |
557ebbc93f | ||
![]() |
b50ff703ad | ||
![]() |
a75ae6a1fe | ||
![]() |
d2a17eba0b | ||
![]() |
e789326c83 | ||
![]() |
6a96044a68 | ||
![]() |
cee315cf36 | ||
![]() |
ac0502b16c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
Cargo.lock
|
||||
target/
|
||||
.cargo/
|
||||
docs.md
|
||||
|
@ -27,4 +27,4 @@ after_success:
|
||||
env:
|
||||
global:
|
||||
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
|
||||
- secure: B8QPcNgwOmbJ8dNJn/p/tE1cLeUOLTo/Oj7nOBkK1tatMgS6yfQFa5pyNEqeTyZAyNptssqSH1BpRC3RxTJ/b+kFzdy8Kq1nkJfp9R9zTY34w5gWukfmmTH4Qe2lyWY/DKL1lGVjb+8mroV9sPaS5Y4DqYHbeYtpWF8Gi27vIL4=
|
||||
- secure: B9+n+ikrYqSxK1SYOHIvjtYi58IvdVC0HYJxyDiJnzIcEtos/aDiGbMZU1pIvC+qIAibdltIqzZ1afVC1msfsxeaov2e4VPKfTJV0gwLLq6tzuuaOeujtM9YUUWrdr8QQXk3LEPIl8HD5jm6VTLcl2TqPeiiyn96rk67nA5jeS8=
|
||||
|
33
Cargo.toml
33
Cargo.toml
@ -1,19 +1,24 @@
|
||||
[package]
|
||||
name = "libnotify"
|
||||
version = "1.0.0"
|
||||
authors = ["Mika Attila <radiantstatue@gmail.com>", "Julian Ospald <hasufell@posteo.de>"]
|
||||
license = "MIT"
|
||||
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"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/crumblingstatue/rust-libnotify"
|
||||
documentation = "http://crumblingstatue.github.io/doc/libnotify/libnotify/"
|
||||
keywords = ["libnotify", "notification"]
|
||||
repository = "https://github.com/hasufell/rust-libnotify"
|
||||
version = "1.0.2"
|
||||
|
||||
[dependencies]
|
||||
error-chain = ">=0.10.0"
|
||||
gdk-pixbuf = { git = "https://github.com/gtk-rs/gdk-pixbuf.git" }
|
||||
gdk-pixbuf-sys = { git = "https://github.com/gtk-rs/sys" }
|
||||
glib = { git = "https://github.com/gtk-rs/glib.git" }
|
||||
glib-sys = { git = "https://github.com/gtk-rs/sys" }
|
||||
gobject-sys = { git = "https://github.com/gtk-rs/sys" }
|
||||
libnotify-sys = { path = "libnotify-sys" }
|
||||
gdk-pixbuf = "^0.2.0"
|
||||
gdk-pixbuf-sys = "^0.4.0"
|
||||
glib = "^0.3.1"
|
||||
glib-sys = "^0.4.0"
|
||||
gobject-sys = "^0.4.0"
|
||||
libnotify-sys = "^1.0.1"
|
||||
|
12
README.md
12
README.md
@ -1,8 +1,12 @@
|
||||
[](https://travis-ci.org/hasufell/rust-libnotify)
|
||||
[](https://crates.io/crates/libnotify)
|
||||
[](LICENSE)
|
||||
[](https://crates.io/crates/libnotify)
|
||||
|
||||
[](https://docs.rs/libnotify)
|
||||
[](https://hasufell.github.io/rust-libnotify/)
|
||||
|
||||
# libnotify-rs
|
||||
[](https://travis-ci.org/hasufell/rust-libnotify)
|
||||
[](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.
|
||||
|
||||
* [Online documentation](https://hasufell.github.io/rust-libnotify/)
|
||||
|
@ -3,14 +3,14 @@ extern crate libnotify;
|
||||
fn main() {
|
||||
// Init libnotify
|
||||
libnotify::init("myapp");
|
||||
// Create a new notification and show it
|
||||
// Create a new notification (doesn't show it yet)
|
||||
let n =
|
||||
libnotify::Notification::new("Summary", Some("Optional Body"), None);
|
||||
// Show the notification
|
||||
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();
|
||||
// Show the update notification
|
||||
// Show the updated notification
|
||||
n.show().unwrap();
|
||||
// We are done, deinit
|
||||
libnotify::uninit();
|
||||
|
2
gir
2
gir
@ -1 +1 @@
|
||||
Subproject commit 89daf8f60096fb80b7a1eff67feb0bf1bf165ec4
|
||||
Subproject commit ac9a8dadb62d003af9f0c6ed46e82ff0971125e5
|
@ -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]
|
||||
pkg-config = ">=0.3.7"
|
||||
pkg-config = ">=0.3.9"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "^0.9.0"
|
||||
libc = "^0.2.0"
|
||||
|
||||
[dependencies.gdk-pixbuf-sys]
|
||||
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"
|
||||
bitflags = "^0.9.1"
|
||||
gdk-pixbuf-sys = "^0.4.0"
|
||||
glib-sys = "^0.4.0"
|
||||
gobject-sys = "^0.4.0"
|
||||
libc = "^0.2.30"
|
||||
|
||||
[lib]
|
||||
name = "libnotify_sys"
|
||||
|
||||
[package]
|
||||
build = "build.rs"
|
||||
links = "libnotify"
|
||||
name = "libnotify-sys"
|
||||
version = "1.0.0"
|
||||
|
||||
|
21
libnotify-sys/LICENSE
Normal file
21
libnotify-sys/LICENSE
Normal 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
7
libnotify-sys/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
[](https://crates.io/crates/libnotify-sys)
|
||||
[](LICENSE)
|
||||
[](https://crates.io/crates/libnotify-sys)
|
||||
|
||||
# rust-libnotify-sys
|
||||
|
||||
Rust FFI declarations for libnotify
|
@ -4,7 +4,7 @@
|
||||
#![allow(non_camel_case_types, non_upper_case_globals)]
|
||||
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate bitflags;
|
||||
extern crate bitflags;
|
||||
extern crate glib_sys as glib;
|
||||
extern crate gobject_sys as gobject;
|
||||
extern crate gdk_pixbuf_sys as gdk_pixbuf;
|
||||
|
@ -27,7 +27,7 @@ impl ToGlib for Urgency {
|
||||
Urgency::Low => ffi::NOTIFY_URGENCY_LOW,
|
||||
Urgency::Normal => ffi::NOTIFY_URGENCY_NORMAL,
|
||||
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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
use glib;
|
||||
use glib_ffi;
|
||||
use std::ptr;
|
||||
|
||||
|
||||
@ -11,19 +11,25 @@ use std::ptr;
|
||||
///
|
||||
/// `true` if libnotify is initialized, or `false` otherwise.
|
||||
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.
|
||||
///
|
||||
/// # 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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,9 +40,7 @@ pub fn init(app_name: &str) -> Result<(), glib::error::BoolError> {
|
||||
/// The registered application name, passed to `init()`.
|
||||
pub fn get_app_name() -> Option<String> {
|
||||
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
|
||||
@ -67,8 +71,22 @@ pub fn get_server_info() -> Option<(String, String, String, String)> {
|
||||
let mut ret_vendor = ptr::null_mut();
|
||||
let mut ret_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));
|
||||
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 }
|
||||
let ret = from_glib(ffi::notify_get_server_info(
|
||||
&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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,15 @@
|
||||
//! fn main() {
|
||||
//! // Init libnotify
|
||||
//! 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",
|
||||
//! Some("Optional Body"),
|
||||
//! None);
|
||||
//! // Show the notification
|
||||
//! 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();
|
||||
//! // Show the update notification
|
||||
//! // Show the updated notification
|
||||
//! n.show().unwrap();
|
||||
//! // We are done, deinit
|
||||
//! libnotify::uninit();
|
||||
|
@ -4,6 +4,9 @@ use gdk_pixbuf;
|
||||
use glib::translate::*;
|
||||
use glib;
|
||||
use glib_ffi;
|
||||
use gobject_ffi;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std;
|
||||
|
||||
|
||||
@ -36,14 +39,22 @@ impl Notification {
|
||||
/// # Returns
|
||||
///
|
||||
/// 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!();
|
||||
let body = body.into();
|
||||
let body = body.to_glib_none();
|
||||
let icon = icon.into();
|
||||
let icon = icon.to_glib_none();
|
||||
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
|
||||
///
|
||||
/// `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> {
|
||||
assert_initialized_libnotify!();
|
||||
unsafe {
|
||||
@ -70,8 +81,7 @@ impl Notification {
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// `true` if successful. On error, this will return `false` and set
|
||||
/// `error`.
|
||||
/// `Ok(())` on success, or `Err(err)` on error
|
||||
// TODO: test if Error leaks memory
|
||||
pub fn show(&self) -> Result<(), glib::error::Error> {
|
||||
assert_initialized_libnotify!();
|
||||
@ -94,9 +104,7 @@ impl Notification {
|
||||
/// ## `key`
|
||||
/// the hint key
|
||||
/// ## `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!();
|
||||
|
||||
let gvalue: *mut glib_ffi::GVariant = {
|
||||
@ -107,9 +115,11 @@ impl Notification {
|
||||
};
|
||||
|
||||
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,
|
||||
gvalue)
|
||||
gvalue,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,8 +130,10 @@ impl Notification {
|
||||
assert_initialized_libnotify!();
|
||||
|
||||
unsafe {
|
||||
ffi::notify_notification_set_image_from_pixbuf(self.to_glib_none().0,
|
||||
pixbuf.to_glib_none().0);
|
||||
ffi::notify_notification_set_image_from_pixbuf(
|
||||
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.to_glib_none();
|
||||
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.
|
||||
pub fn set_category(&self, category: &str) {
|
||||
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.
|
||||
pub fn set_timeout(&self, timeout: i32) {
|
||||
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.
|
||||
pub fn set_urgency(&self, urgency: Urgency) {
|
||||
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
|
||||
///
|
||||
/// `true`, unless 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> {
|
||||
/// `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,
|
||||
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.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), "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(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user