Struct notify_rust::Notification [] [src]

pub struct Notification {
    pub appname: String,
    pub summary: String,
    pub body: String,
    pub icon: String,
    pub hints: HashSet<NotificationHint>,
    pub actions: Vec<String>,
    pub timeout: i32,
}

Desktop Notification.

A desktop notification is configured via builder pattern, before it is launched with show().

Fields

Filled by default with executable name.

Single line to summarize the content.

Multiple lines possible, may support simple markup, checkout get_capabilities() -> body-markup and body-hyperlinks.

Use a file:// URI or a name in an icon theme, must be compliant freedesktop.org.

Checkout NotificationHint

See Notification::actions() and Notification::action()

Lifetime of the Notification in ms. Often not respected by server, sorry.

Methods

impl Notification
[src]

Constructs a new Notification.

Most fields are empty by default, only appname is prefilled with the name of the current executable. The appname is used by some desktop environments to group notifications.

Overwrite the appname field used for Notification.

Set the summary.

Often acts as title of the notification. For more elaborate content use the body field.

Set the content of the body field.

Multiline textual content of the notification. Each line should be treated as a paragraph. Simple html markup should be supported, depending on the server implementation.

Set the icon field.

You can use commom icon names here, usually those in /usr/share/icons can all be used. You can also use an absolute path to file.

Adds a hint.

This method will add a hint to the internal hint hashset. Hints must be of type NotificationHint.

use notify_rust::Notification;
use notify_rust::NotificationHint;
Notification::new()
    .summary("Category:email")
    .body("This should not go away until you acknoledge it.")
    .icon("thunderbird")
    .appname("thunderbird")
    .hint(NotificationHint::Category("email".to_string()))
    .hint(NotificationHint::Resident(true))
    .show();

Set the timeout.

This sets the time (in miliseconds) from the time the notification is displayed until it is closed again by the Notification Server. According to specification -1 will leave the timeout to be set by the server and 0 will cause the notification never to expire.

Set actions.

To quote http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify

Actions are sent over as a list of pairs. Each even element in the list (starting at index 0) represents the identifier for the action. Each odd element in the list is the localized string that will be displayed to the user.

There is nothing fancy going on here yet. Carefull! This replaces the internal list of actions!

Add an action.

This adds a single action to the internal list of actions.

Finalizes a Notification.

Part of the builder pattern, returns a complete copy of the built notification.

Sends Notification to D-Bus.

Returns id from D-Bus.

Wraps show() but prints notification to stdout.

Wraps show() and blocks.

This method takes a closure that takes an action name.

Example

use notify_rust::Notification;
use notify_rust::NotificationHint as Hint;
Notification::new()
    .summary("click me")
    .action("default", "default")
    .action("clicked", "click here")
    .hint(Hint::Resident(true))
    .show_and_wait_for_action({|action|
        match action {
            "default" => {println!("so boring")},
            "clicked" => {println!("that was correct")},
            _ => ()
        }
    });