Skip to main content

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    ///  panel.
10    ///
11    /// The `.desktop` file must be named as `org.gnome.TestApplication.desktop`,
12    /// where `org.gnome.TestApplication` is the ID passed to
13    /// [`Application::new()`][crate::Application::new()].
14    ///
15    /// User interaction with a notification (either the default action, or
16    /// buttons) must be associated with actions on the application (ie:
17    /// `app.` actions).  It is not possible to route user interaction
18    /// through the notification itself, because the object will not exist if
19    /// the application is autostarted as a result of a notification being
20    /// clicked.
21    ///
22    /// A notification can be sent with [`ApplicationExt::send_notification()`][crate::prelude::ApplicationExt::send_notification()].
23    ///
24    /// In Windows, notification actions are unsupported, when sending the notification
25    /// a warning will be printed if a default action or action buttons were added.
26    ///
27    /// # Implements
28    ///
29    /// [`trait@glib::ObjectExt`]
30    #[doc(alias = "GNotification")]
31    pub struct Notification(Object<ffi::GNotification>);
32
33    match fn {
34        type_ => || ffi::g_notification_get_type(),
35    }
36}
37
38impl Notification {
39    /// Creates a new #GNotification with @title as its title.
40    ///
41    /// After populating @notification with more details, it can be sent to
42    /// the desktop shell with g_application_send_notification(). Changing
43    /// any properties after this call will not have any effect until
44    /// resending @notification.
45    /// ## `title`
46    /// the title of the notification
47    ///
48    /// # Returns
49    ///
50    /// a new #GNotification instance
51    #[doc(alias = "g_notification_new")]
52    pub fn new(title: &str) -> Notification {
53        unsafe { from_glib_full(ffi::g_notification_new(title.to_glib_none().0)) }
54    }
55
56    /// Adds a button to @self that activates the action in
57    /// @detailed_action when clicked. That action must be an
58    /// application-wide action (starting with "app."). If @detailed_action
59    /// contains a target, the action will be activated with that target as
60    /// its parameter.
61    ///
62    /// See g_action_parse_detailed_name() for a description of the format
63    /// for @detailed_action.
64    /// ## `label`
65    /// label of the button
66    /// ## `detailed_action`
67    /// a detailed action name
68    #[doc(alias = "g_notification_add_button")]
69    pub fn add_button(&self, label: &str, detailed_action: &str) {
70        unsafe {
71            ffi::g_notification_add_button(
72                self.to_glib_none().0,
73                label.to_glib_none().0,
74                detailed_action.to_glib_none().0,
75            );
76        }
77    }
78
79    //#[doc(alias = "g_notification_add_button_with_target")]
80    //pub fn add_button_with_target(&self, label: &str, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
81    //    unsafe { TODO: call ffi:g_notification_add_button_with_target() }
82    //}
83
84    /// Adds a button to @self that activates @action when clicked.
85    /// @action must be an application-wide action (it must start with "app.").
86    ///
87    /// If @target is non-[`None`], @action will be activated with @target as
88    /// its parameter.
89    /// ## `label`
90    /// label of the button
91    /// ## `action`
92    /// an action name
93    /// ## `target`
94    /// a #GVariant to use as @action's parameter, or [`None`]
95    #[doc(alias = "g_notification_add_button_with_target_value")]
96    pub fn add_button_with_target_value(
97        &self,
98        label: &str,
99        action: &str,
100        target: Option<&glib::Variant>,
101    ) {
102        unsafe {
103            ffi::g_notification_add_button_with_target_value(
104                self.to_glib_none().0,
105                label.to_glib_none().0,
106                action.to_glib_none().0,
107                target.to_glib_none().0,
108            );
109        }
110    }
111
112    /// Sets the body of @self to @body.
113    /// ## `body`
114    /// the new body for @self, or [`None`]
115    #[doc(alias = "g_notification_set_body")]
116    pub fn set_body(&self, body: Option<&str>) {
117        unsafe {
118            ffi::g_notification_set_body(self.to_glib_none().0, body.to_glib_none().0);
119        }
120    }
121
122    /// Sets the type of @self to @category. Categories have a main
123    /// type like `email`, `im` or `device` and can have a detail separated
124    /// by a `.`, e.g. `im.received` or `email.arrived`. Setting the category
125    /// helps the notification server to select proper feedback to the user.
126    ///
127    /// Standard categories are [listed in the specification](https://specifications.freedesktop.org/notification-spec/latest/ar01s06.html).
128    /// ## `category`
129    /// the category for @self, or [`None`] for no category
130    #[cfg(feature = "v2_70")]
131    #[cfg_attr(docsrs, doc(cfg(feature = "v2_70")))]
132    #[doc(alias = "g_notification_set_category")]
133    pub fn set_category(&self, category: Option<&str>) {
134        unsafe {
135            ffi::g_notification_set_category(self.to_glib_none().0, category.to_glib_none().0);
136        }
137    }
138
139    /// Sets the default action of @self to @detailed_action. This
140    /// action is activated when the notification is clicked on.
141    ///
142    /// The action in @detailed_action must be an application-wide action (it
143    /// must start with "app."). If @detailed_action contains a target, the
144    /// given action will be activated with that target as its parameter.
145    /// See g_action_parse_detailed_name() for a description of the format
146    /// for @detailed_action.
147    ///
148    /// When no default action is set, the application that the notification
149    /// was sent on is activated.
150    /// ## `detailed_action`
151    /// a detailed action name
152    #[doc(alias = "g_notification_set_default_action")]
153    pub fn set_default_action(&self, detailed_action: &str) {
154        unsafe {
155            ffi::g_notification_set_default_action(
156                self.to_glib_none().0,
157                detailed_action.to_glib_none().0,
158            );
159        }
160    }
161
162    //#[doc(alias = "g_notification_set_default_action_and_target")]
163    //pub fn set_default_action_and_target(&self, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
164    //    unsafe { TODO: call ffi:g_notification_set_default_action_and_target() }
165    //}
166
167    /// Sets the default action of @self to @action. This action is
168    /// activated when the notification is clicked on. It must be an
169    /// application-wide action (start with "app.").
170    ///
171    /// If @target is non-[`None`], @action will be activated with @target as
172    /// its parameter. If @target is floating, it will be consumed.
173    ///
174    /// When no default action is set, the application that the notification
175    /// was sent on is activated.
176    /// ## `action`
177    /// an action name
178    /// ## `target`
179    /// a #GVariant to use as @action's parameter, or [`None`]
180    #[doc(alias = "g_notification_set_default_action_and_target_value")]
181    pub fn set_default_action_and_target_value(
182        &self,
183        action: &str,
184        target: Option<&glib::Variant>,
185    ) {
186        unsafe {
187            ffi::g_notification_set_default_action_and_target_value(
188                self.to_glib_none().0,
189                action.to_glib_none().0,
190                target.to_glib_none().0,
191            );
192        }
193    }
194
195    /// Sets the icon of @self to @icon.
196    /// ## `icon`
197    /// the icon to be shown in @self, as a #GIcon
198    #[doc(alias = "g_notification_set_icon")]
199    pub fn set_icon(&self, icon: &impl IsA<Icon>) {
200        unsafe {
201            ffi::g_notification_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
202        }
203    }
204
205    /// Sets the priority of @self to @priority. See
206    /// #GNotificationPriority for possible values.
207    /// ## `priority`
208    /// a #GNotificationPriority
209    #[doc(alias = "g_notification_set_priority")]
210    pub fn set_priority(&self, priority: NotificationPriority) {
211        unsafe {
212            ffi::g_notification_set_priority(self.to_glib_none().0, priority.into_glib());
213        }
214    }
215
216    /// Sets the title of @self to @title.
217    /// ## `title`
218    /// the new title for @self
219    #[doc(alias = "g_notification_set_title")]
220    pub fn set_title(&self, title: &str) {
221        unsafe {
222            ffi::g_notification_set_title(self.to_glib_none().0, title.to_glib_none().0);
223        }
224    }
225}