gio/auto/notification.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Icon, NotificationPriority, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// `GNotification` is a mechanism for creating a notification to be shown
10 /// to the user — typically as a pop-up notification presented by the
11 /// desktop environment shell.
12 ///
13 /// The key difference between `GNotification` and other similar APIs is
14 /// that, if supported by the desktop environment, notifications sent
15 /// with `GNotification` will persist after the application has exited,
16 /// and even across system reboots.
17 ///
18 /// Since the user may click on a notification while the application is
19 /// not running, applications using `GNotification` should be able to be
20 /// started as a D-Bus service, using [`Application`][crate::Application].
21 ///
22 /// In order for `GNotification` to work, the application must have installed
23 /// a `.desktop` file. For example:
24 /// ```text
25 /// [Desktop Entry]
26 /// Name=Test Application
27 /// Comment=Description of what Test Application does
28 /// Exec=gnome-test-application
29 /// Icon=org.gnome.TestApplication
30 /// Terminal=false
31 /// Type=Application
32 /// Categories=GNOME;GTK;TestApplication Category;
33 /// StartupNotify=true
34 /// DBusActivatable=true
35 /// X-GNOME-UsesNotifications=true
36 /// ```
37 ///
38 /// The `X-GNOME-UsesNotifications` key indicates to GNOME Control Center
39 /// that this application uses notifications, so it can be listed in the
40 /// Control Center’s ‘Notifications’ panel.
41 ///
42 /// The `.desktop` file must be named as `org.gnome.TestApplication.desktop`,
43 /// where `org.gnome.TestApplication` is the ID passed to
44 /// [`Application::new()`][crate::Application::new()].
45 ///
46 /// User interaction with a notification (either the default action, or
47 /// buttons) must be associated with actions on the application (ie:
48 /// `app.` actions). It is not possible to route user interaction
49 /// through the notification itself, because the object will not exist if
50 /// the application is autostarted as a result of a notification being
51 /// clicked.
52 ///
53 /// A notification can be sent with [`ApplicationExt::send_notification()`][crate::prelude::ApplicationExt::send_notification()].
54 ///
55 /// In Windows, notification actions are unsupported, when sending the notification
56 /// a warning will be printed if a default action or action buttons were added.
57 ///
58 /// # Implements
59 ///
60 /// [`trait@glib::ObjectExt`]
61 #[doc(alias = "GNotification")]
62 pub struct Notification(Object<ffi::GNotification>);
63
64 match fn {
65 type_ => || ffi::g_notification_get_type(),
66 }
67}
68
69impl Notification {
70 /// Creates a new #GNotification with @title as its title.
71 ///
72 /// After populating @notification with more details, it can be sent to
73 /// the desktop shell with g_application_send_notification(). Changing
74 /// any properties after this call will not have any effect until
75 /// resending @notification.
76 /// ## `title`
77 /// the title of the notification
78 ///
79 /// # Returns
80 ///
81 /// a new #GNotification instance
82 #[doc(alias = "g_notification_new")]
83 pub fn new(title: &str) -> Notification {
84 unsafe { from_glib_full(ffi::g_notification_new(title.to_glib_none().0)) }
85 }
86
87 /// Adds a button to @self that activates the action in
88 /// @detailed_action when clicked. That action must be an
89 /// application-wide action (starting with "app."). If @detailed_action
90 /// contains a target, the action will be activated with that target as
91 /// its parameter.
92 ///
93 /// See g_action_parse_detailed_name() for a description of the format
94 /// for @detailed_action.
95 /// ## `label`
96 /// label of the button
97 /// ## `detailed_action`
98 /// a detailed action name
99 #[doc(alias = "g_notification_add_button")]
100 pub fn add_button(&self, label: &str, detailed_action: &str) {
101 unsafe {
102 ffi::g_notification_add_button(
103 self.to_glib_none().0,
104 label.to_glib_none().0,
105 detailed_action.to_glib_none().0,
106 );
107 }
108 }
109
110 //#[doc(alias = "g_notification_add_button_with_target")]
111 //pub fn add_button_with_target(&self, label: &str, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
112 // unsafe { TODO: call ffi:g_notification_add_button_with_target() }
113 //}
114
115 /// Adds a button to @self that activates @action when clicked.
116 /// @action must be an application-wide action (it must start with "app.").
117 ///
118 /// If @target is non-[`None`], @action will be activated with @target as
119 /// its parameter.
120 /// ## `label`
121 /// label of the button
122 /// ## `action`
123 /// an action name
124 /// ## `target`
125 /// a #GVariant to use as @action's parameter, or [`None`]
126 #[doc(alias = "g_notification_add_button_with_target_value")]
127 pub fn add_button_with_target_value(
128 &self,
129 label: &str,
130 action: &str,
131 target: Option<&glib::Variant>,
132 ) {
133 unsafe {
134 ffi::g_notification_add_button_with_target_value(
135 self.to_glib_none().0,
136 label.to_glib_none().0,
137 action.to_glib_none().0,
138 target.to_glib_none().0,
139 );
140 }
141 }
142
143 /// Sets the body of @self to @body.
144 /// ## `body`
145 /// the new body for @self, or [`None`]
146 #[doc(alias = "g_notification_set_body")]
147 pub fn set_body(&self, body: Option<&str>) {
148 unsafe {
149 ffi::g_notification_set_body(self.to_glib_none().0, body.to_glib_none().0);
150 }
151 }
152
153 /// Sets the type of @self to @category. Categories have a main
154 /// type like `email`, `im` or `device` and can have a detail separated
155 /// by a `.`, e.g. `im.received` or `email.arrived`. Setting the category
156 /// helps the notification server to select proper feedback to the user.
157 ///
158 /// Standard categories are [listed in the specification](https://specifications.freedesktop.org/notification-spec/latest/ar01s06.html).
159 /// ## `category`
160 /// the category for @self, or [`None`] for no category
161 #[cfg(feature = "v2_70")]
162 #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
163 #[doc(alias = "g_notification_set_category")]
164 pub fn set_category(&self, category: Option<&str>) {
165 unsafe {
166 ffi::g_notification_set_category(self.to_glib_none().0, category.to_glib_none().0);
167 }
168 }
169
170 /// Sets the default action of @self to @detailed_action. This
171 /// action is activated when the notification is clicked on.
172 ///
173 /// The action in @detailed_action must be an application-wide action (it
174 /// must start with "app."). If @detailed_action contains a target, the
175 /// given action will be activated with that target as its parameter.
176 /// See g_action_parse_detailed_name() for a description of the format
177 /// for @detailed_action.
178 ///
179 /// When no default action is set, the application that the notification
180 /// was sent on is activated.
181 /// ## `detailed_action`
182 /// a detailed action name
183 #[doc(alias = "g_notification_set_default_action")]
184 pub fn set_default_action(&self, detailed_action: &str) {
185 unsafe {
186 ffi::g_notification_set_default_action(
187 self.to_glib_none().0,
188 detailed_action.to_glib_none().0,
189 );
190 }
191 }
192
193 //#[doc(alias = "g_notification_set_default_action_and_target")]
194 //pub fn set_default_action_and_target(&self, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
195 // unsafe { TODO: call ffi:g_notification_set_default_action_and_target() }
196 //}
197
198 /// Sets the default action of @self to @action. This action is
199 /// activated when the notification is clicked on. It must be an
200 /// application-wide action (start with "app.").
201 ///
202 /// If @target is non-[`None`], @action will be activated with @target as
203 /// its parameter. If @target is floating, it will be consumed.
204 ///
205 /// When no default action is set, the application that the notification
206 /// was sent on is activated.
207 /// ## `action`
208 /// an action name
209 /// ## `target`
210 /// a #GVariant to use as @action's parameter, or [`None`]
211 #[doc(alias = "g_notification_set_default_action_and_target_value")]
212 pub fn set_default_action_and_target_value(
213 &self,
214 action: &str,
215 target: Option<&glib::Variant>,
216 ) {
217 unsafe {
218 ffi::g_notification_set_default_action_and_target_value(
219 self.to_glib_none().0,
220 action.to_glib_none().0,
221 target.to_glib_none().0,
222 );
223 }
224 }
225
226 /// Sets the icon of @self to @icon.
227 /// ## `icon`
228 /// the icon to be shown in @self, as a #GIcon
229 #[doc(alias = "g_notification_set_icon")]
230 pub fn set_icon(&self, icon: &impl IsA<Icon>) {
231 unsafe {
232 ffi::g_notification_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
233 }
234 }
235
236 /// Sets the priority of @self to @priority. See
237 /// #GNotificationPriority for possible values.
238 /// ## `priority`
239 /// a #GNotificationPriority
240 #[doc(alias = "g_notification_set_priority")]
241 pub fn set_priority(&self, priority: NotificationPriority) {
242 unsafe {
243 ffi::g_notification_set_priority(self.to_glib_none().0, priority.into_glib());
244 }
245 }
246
247 /// Sets the title of @self to @title.
248 /// ## `title`
249 /// the new title for @self
250 #[doc(alias = "g_notification_set_title")]
251 pub fn set_title(&self, title: &str) {
252 unsafe {
253 ffi::g_notification_set_title(self.to_glib_none().0, title.to_glib_none().0);
254 }
255 }
256}