Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d19aadb4d2 | ||
|
|
7556615e78 | ||
|
|
1636812abc | ||
|
|
d979d8a2d1 | ||
|
|
d23eabffea | ||
|
|
ffd99b67e2 | ||
|
|
72df2c0adb | ||
|
|
dac1075025 | ||
|
|
d3ad5323fb | ||
|
|
445f0b6d13 | ||
|
|
a0955acabd |
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "libnotify"
|
name = "libnotify"
|
||||||
version = "0.0.2"
|
version = "0.1.0"
|
||||||
authors = ["Mika Attila <radiantstatue@gmail.com>"]
|
authors = ["Mika Attila <radiantstatue@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Rust bindings to libnotify"
|
description = "Rust bindings to libnotify"
|
||||||
@@ -11,5 +11,6 @@ documentation = "http://crumblingstatue.github.io/doc/libnotify/libnotify/"
|
|||||||
keywords = ["libnotify", "notification"]
|
keywords = ["libnotify", "notification"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libnotify-sys = "*"
|
libnotify-sys = "0.2.0"
|
||||||
glib-2_0-sys = "*"
|
glib-2-0-sys = "0.46.0"
|
||||||
|
gtypes = "0.1.2"
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
extern crate libnotify;
|
extern crate libnotify;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let notify = libnotify::Context::new("hello").unwrap();
|
let notify = libnotify::Context::new("hello").unwrap_or_else(|e| {
|
||||||
|
panic!("{}", e);
|
||||||
|
});
|
||||||
|
let body_text = Some("This is the optional body text.");
|
||||||
let n = notify.new_notification("This is the summary.",
|
let n = notify.new_notification("This is the summary.",
|
||||||
Some("This is the optional body text."),
|
body_text,
|
||||||
None).unwrap();
|
None).unwrap_or_else(|e| panic!("{}", e));
|
||||||
n.show().unwrap();
|
n.show().ok().expect("Failed to show notification");
|
||||||
}
|
}
|
||||||
|
|||||||
48
src/lib.rs
48
src/lib.rs
@@ -1,10 +1,31 @@
|
|||||||
extern crate "libnotify-sys" as sys;
|
//! Rustic bindings to [libnotify](https://developer.gnome.org/libnotify/)
|
||||||
extern crate "glib-2_0-sys" as glib;
|
//!
|
||||||
|
//! ```rust
|
||||||
|
//! extern crate libnotify;
|
||||||
|
//!
|
||||||
|
//! fn main() {
|
||||||
|
//! let notify = libnotify::Context::new("hello").unwrap_or_else(|e| {
|
||||||
|
//! panic!("{}", e);
|
||||||
|
//! });
|
||||||
|
//! let body_text = Some("This is the optional body text.");
|
||||||
|
//! let n = notify.new_notification("This is the summary.",
|
||||||
|
//! body_text,
|
||||||
|
//! None).unwrap_or_else(|e| {
|
||||||
|
//! panic!("{}", e);
|
||||||
|
//! });
|
||||||
|
//! n.show().ok().expect("Failed to show notification");
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
extern crate libnotify_sys as sys;
|
||||||
|
extern crate glib_2_0_sys as glib;
|
||||||
|
extern crate gtypes;
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use glib::types::{
|
use gtypes::{
|
||||||
TRUE,
|
TRUE,
|
||||||
FALSE
|
FALSE
|
||||||
};
|
};
|
||||||
@@ -18,12 +39,33 @@ pub enum ContextCreationError {
|
|||||||
NulError
|
NulError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ContextCreationError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
use ContextCreationError::*;
|
||||||
|
match *self {
|
||||||
|
AlreadyExists => write!(f, "A Libnotify context already exists."),
|
||||||
|
InitFailure => write!(f, "Failed to initialize libnotify."),
|
||||||
|
NulError => write!(f, "Argument contains a nul character.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum NotificationCreationError {
|
pub enum NotificationCreationError {
|
||||||
NulError,
|
NulError,
|
||||||
Unknown
|
Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for NotificationCreationError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
use NotificationCreationError::*;
|
||||||
|
match *self {
|
||||||
|
NulError => write!(f, "Argument contains a nul character."),
|
||||||
|
Unknown => write!(f, "Unknown error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The context which within libnotify operates.
|
/// The context which within libnotify operates.
|
||||||
///
|
///
|
||||||
/// Only one context can exist at a time.
|
/// Only one context can exist at a time.
|
||||||
|
|||||||
Reference in New Issue
Block a user