1use gio_sys;
6use glib;
7use glib::object::IsA;
8use glib::translate::*;
9use std::fmt;
10use Icon;
11use NotificationPriority;
12
13glib_wrapper! {
14 pub struct Notification(Object<gio_sys::GNotification, NotificationClass>);
15
16 match fn {
17 get_type => || gio_sys::g_notification_get_type(),
18 }
19}
20
21impl Notification {
22 pub fn new(title: &str) -> Notification {
23 unsafe { from_glib_full(gio_sys::g_notification_new(title.to_glib_none().0)) }
24 }
25
26 pub fn add_button(&self, label: &str, detailed_action: &str) {
27 unsafe {
28 gio_sys::g_notification_add_button(
29 self.to_glib_none().0,
30 label.to_glib_none().0,
31 detailed_action.to_glib_none().0,
32 );
33 }
34 }
35
36 pub fn add_button_with_target_value(
41 &self,
42 label: &str,
43 action: &str,
44 target: Option<&glib::Variant>,
45 ) {
46 unsafe {
47 gio_sys::g_notification_add_button_with_target_value(
48 self.to_glib_none().0,
49 label.to_glib_none().0,
50 action.to_glib_none().0,
51 target.to_glib_none().0,
52 );
53 }
54 }
55
56 pub fn set_body(&self, body: Option<&str>) {
57 unsafe {
58 gio_sys::g_notification_set_body(self.to_glib_none().0, body.to_glib_none().0);
59 }
60 }
61
62 pub fn set_default_action(&self, detailed_action: &str) {
63 unsafe {
64 gio_sys::g_notification_set_default_action(
65 self.to_glib_none().0,
66 detailed_action.to_glib_none().0,
67 );
68 }
69 }
70
71 pub fn set_default_action_and_target_value(
76 &self,
77 action: &str,
78 target: Option<&glib::Variant>,
79 ) {
80 unsafe {
81 gio_sys::g_notification_set_default_action_and_target_value(
82 self.to_glib_none().0,
83 action.to_glib_none().0,
84 target.to_glib_none().0,
85 );
86 }
87 }
88
89 pub fn set_icon<P: IsA<Icon>>(&self, icon: &P) {
90 unsafe {
91 gio_sys::g_notification_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
92 }
93 }
94
95 pub fn set_priority(&self, priority: NotificationPriority) {
96 unsafe {
97 gio_sys::g_notification_set_priority(self.to_glib_none().0, priority.to_glib());
98 }
99 }
100
101 pub fn set_title(&self, title: &str) {
102 unsafe {
103 gio_sys::g_notification_set_title(self.to_glib_none().0, title.to_glib_none().0);
104 }
105 }
106}
107
108impl fmt::Display for Notification {
109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110 write!(f, "Notification")
111 }
112}