1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Icon;
use crate::NotificationPriority;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`Notification`][crate::Notification] is a mechanism for creating a notification to be shown
    /// to the user -- typically as a pop-up notification presented by the
    /// desktop environment shell.
    ///
    /// The key difference between [`Notification`][crate::Notification] and other similar APIs is
    /// that, if supported by the desktop environment, notifications sent
    /// with [`Notification`][crate::Notification] will persist after the application has exited,
    /// and even across system reboots.
    ///
    /// Since the user may click on a notification while the application is
    /// not running, applications using [`Notification`][crate::Notification] should be able to be
    /// started as a D-Bus service, using [`Application`][crate::Application].
    ///
    /// In order for [`Notification`][crate::Notification] to work, the application must have installed
    /// a `.desktop` file. For example:
    ///
    /// ```text
    ///  [Desktop Entry]
    ///   Name=Test Application
    ///   Comment=Description of what Test Application does
    ///   Exec=gnome-test-application
    ///   Icon=org.gnome.TestApplication
    ///   Terminal=false
    ///   Type=Application
    ///   Categories=GNOME;GTK;TestApplication Category;
    ///   StartupNotify=true
    ///   DBusActivatable=true
    ///   X-GNOME-UsesNotifications=true
    /// ```
    ///
    /// The `X-GNOME-UsesNotifications` key indicates to GNOME Control Center
    /// that this application uses notifications, so it can be listed in the
    /// Control Center’s ‘Notifications’ panel.
    ///
    /// The `.desktop` file must be named as `org.gnome.TestApplication.desktop`,
    /// where `org.gnome.TestApplication` is the ID passed to [`Application::new()`][crate::Application::new()].
    ///
    /// User interaction with a notification (either the default action, or
    /// buttons) must be associated with actions on the application (ie:
    /// "app." actions). It is not possible to route user interaction
    /// through the notification itself, because the object will not exist if
    /// the application is autostarted as a result of a notification being
    /// clicked.
    ///
    /// A notification can be sent with [`ApplicationExt::send_notification()`][crate::prelude::ApplicationExt::send_notification()].
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`]
    #[doc(alias = "GNotification")]
    pub struct Notification(Object<ffi::GNotification>);

    match fn {
        type_ => || ffi::g_notification_get_type(),
    }
}

impl Notification {
    /// Creates a new [`Notification`][crate::Notification] with `title` as its title.
    ///
    /// After populating `notification` with more details, it can be sent to
    /// the desktop shell with [`ApplicationExt::send_notification()`][crate::prelude::ApplicationExt::send_notification()]. Changing
    /// any properties after this call will not have any effect until
    /// resending `notification`.
    /// ## `title`
    /// the title of the notification
    ///
    /// # Returns
    ///
    /// a new [`Notification`][crate::Notification] instance
    #[doc(alias = "g_notification_new")]
    pub fn new(title: &str) -> Notification {
        unsafe { from_glib_full(ffi::g_notification_new(title.to_glib_none().0)) }
    }

    /// Adds a button to `self` that activates the action in
    /// `detailed_action` when clicked. That action must be an
    /// application-wide action (starting with "app."). If `detailed_action`
    /// contains a target, the action will be activated with that target as
    /// its parameter.
    ///
    /// See [`Action::parse_detailed_name()`][crate::Action::parse_detailed_name()] for a description of the format
    /// for `detailed_action`.
    /// ## `label`
    /// label of the button
    /// ## `detailed_action`
    /// a detailed action name
    #[doc(alias = "g_notification_add_button")]
    pub fn add_button(&self, label: &str, detailed_action: &str) {
        unsafe {
            ffi::g_notification_add_button(
                self.to_glib_none().0,
                label.to_glib_none().0,
                detailed_action.to_glib_none().0,
            );
        }
    }

    //#[doc(alias = "g_notification_add_button_with_target")]
    //pub fn add_button_with_target(&self, label: &str, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
    //    unsafe { TODO: call ffi:g_notification_add_button_with_target() }
    //}

    /// Adds a button to `self` that activates `action` when clicked.
    /// `action` must be an application-wide action (it must start with "app.").
    ///
    /// If `target` is non-[`None`], `action` will be activated with `target` as
    /// its parameter.
    /// ## `label`
    /// label of the button
    /// ## `action`
    /// an action name
    /// ## `target`
    /// a [`glib::Variant`][struct@crate::glib::Variant] to use as `action`'s parameter, or [`None`]
    #[doc(alias = "g_notification_add_button_with_target_value")]
    pub fn add_button_with_target_value(
        &self,
        label: &str,
        action: &str,
        target: Option<&glib::Variant>,
    ) {
        unsafe {
            ffi::g_notification_add_button_with_target_value(
                self.to_glib_none().0,
                label.to_glib_none().0,
                action.to_glib_none().0,
                target.to_glib_none().0,
            );
        }
    }

    /// Sets the body of `self` to `body`.
    /// ## `body`
    /// the new body for `self`, or [`None`]
    #[doc(alias = "g_notification_set_body")]
    pub fn set_body(&self, body: Option<&str>) {
        unsafe {
            ffi::g_notification_set_body(self.to_glib_none().0, body.to_glib_none().0);
        }
    }

    /// Sets the type of `self` to `category`. Categories have a main
    /// type like `email`, `im` or `device` and can have a detail separated
    /// by a `.`, e.g. `im.received` or `email.arrived`. Setting the category
    /// helps the notification server to select proper feedback to the user.
    ///
    /// Standard categories are [listed in the specification](https://specifications.freedesktop.org/notification-spec/latest/ar01s06.html).
    /// ## `category`
    /// the category for `self`, or [`None`] for no category
    #[cfg(any(feature = "v2_70", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_70")))]
    #[doc(alias = "g_notification_set_category")]
    pub fn set_category(&self, category: Option<&str>) {
        unsafe {
            ffi::g_notification_set_category(self.to_glib_none().0, category.to_glib_none().0);
        }
    }

    /// Sets the default action of `self` to `detailed_action`. This
    /// action is activated when the notification is clicked on.
    ///
    /// The action in `detailed_action` must be an application-wide action (it
    /// must start with "app."). If `detailed_action` contains a target, the
    /// given action will be activated with that target as its parameter.
    /// See [`Action::parse_detailed_name()`][crate::Action::parse_detailed_name()] for a description of the format
    /// for `detailed_action`.
    ///
    /// When no default action is set, the application that the notification
    /// was sent on is activated.
    /// ## `detailed_action`
    /// a detailed action name
    #[doc(alias = "g_notification_set_default_action")]
    pub fn set_default_action(&self, detailed_action: &str) {
        unsafe {
            ffi::g_notification_set_default_action(
                self.to_glib_none().0,
                detailed_action.to_glib_none().0,
            );
        }
    }

    //#[doc(alias = "g_notification_set_default_action_and_target")]
    //pub fn set_default_action_and_target(&self, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
    //    unsafe { TODO: call ffi:g_notification_set_default_action_and_target() }
    //}

    /// Sets the default action of `self` to `action`. This action is
    /// activated when the notification is clicked on. It must be an
    /// application-wide action (start with "app.").
    ///
    /// If `target` is non-[`None`], `action` will be activated with `target` as
    /// its parameter.
    ///
    /// When no default action is set, the application that the notification
    /// was sent on is activated.
    /// ## `action`
    /// an action name
    /// ## `target`
    /// a [`glib::Variant`][struct@crate::glib::Variant] to use as `action`'s parameter, or [`None`]
    #[doc(alias = "g_notification_set_default_action_and_target_value")]
    pub fn set_default_action_and_target_value(
        &self,
        action: &str,
        target: Option<&glib::Variant>,
    ) {
        unsafe {
            ffi::g_notification_set_default_action_and_target_value(
                self.to_glib_none().0,
                action.to_glib_none().0,
                target.to_glib_none().0,
            );
        }
    }

    /// Sets the icon of `self` to `icon`.
    /// ## `icon`
    /// the icon to be shown in `self`, as a [`Icon`][crate::Icon]
    #[doc(alias = "g_notification_set_icon")]
    pub fn set_icon(&self, icon: &impl IsA<Icon>) {
        unsafe {
            ffi::g_notification_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
        }
    }

    /// Sets the priority of `self` to `priority`. See
    /// [`NotificationPriority`][crate::NotificationPriority] for possible values.
    /// ## `priority`
    /// a [`NotificationPriority`][crate::NotificationPriority]
    #[doc(alias = "g_notification_set_priority")]
    pub fn set_priority(&self, priority: NotificationPriority) {
        unsafe {
            ffi::g_notification_set_priority(self.to_glib_none().0, priority.into_glib());
        }
    }

    /// Sets the title of `self` to `title`.
    /// ## `title`
    /// the new title for `self`
    #[doc(alias = "g_notification_set_title")]
    pub fn set_title(&self, title: &str) {
        unsafe {
            ffi::g_notification_set_title(self.to_glib_none().0, title.to_glib_none().0);
        }
    }
}

impl fmt::Display for Notification {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Notification")
    }
}