Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d19aadb4d2 | ||
|
|
7556615e78 | ||
|
|
1636812abc | ||
|
|
d979d8a2d1 | ||
|
|
d23eabffea | ||
|
|
ffd99b67e2 | ||
|
|
72df2c0adb | ||
|
|
dac1075025 | ||
|
|
d3ad5323fb | ||
|
|
445f0b6d13 | ||
|
|
a0955acabd |
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "libnotify"
|
||||
version = "0.0.2"
|
||||
version = "0.1.0"
|
||||
authors = ["Mika Attila <radiantstatue@gmail.com>"]
|
||||
license = "MIT"
|
||||
description = "Rust bindings to libnotify"
|
||||
@@ -11,5 +11,6 @@ documentation = "http://crumblingstatue.github.io/doc/libnotify/libnotify/"
|
||||
keywords = ["libnotify", "notification"]
|
||||
|
||||
[dependencies]
|
||||
libnotify-sys = "*"
|
||||
glib-2_0-sys = "*"
|
||||
libnotify-sys = "0.2.0"
|
||||
glib-2-0-sys = "0.46.0"
|
||||
gtypes = "0.1.2"
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
extern crate libnotify;
|
||||
|
||||
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.",
|
||||
Some("This is the optional body text."),
|
||||
None).unwrap();
|
||||
n.show().unwrap();
|
||||
body_text,
|
||||
None).unwrap_or_else(|e| panic!("{}", e));
|
||||
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;
|
||||
extern crate "glib-2_0-sys" as glib;
|
||||
//! Rustic bindings to [libnotify](https://developer.gnome.org/libnotify/)
|
||||
//!
|
||||
//! ```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::marker::PhantomData;
|
||||
use std::fmt;
|
||||
|
||||
use glib::types::{
|
||||
use gtypes::{
|
||||
TRUE,
|
||||
FALSE
|
||||
};
|
||||
@@ -18,12 +39,33 @@ pub enum ContextCreationError {
|
||||
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)]
|
||||
pub enum NotificationCreationError {
|
||||
NulError,
|
||||
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.
|
||||
///
|
||||
/// Only one context can exist at a time.
|
||||
|
||||
Reference in New Issue
Block a user