Skip to main content

gio/auto/
action_group.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::ffi;
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    ///  are actually implemented with
16    /// calls to `Gio::ActionGroup::query_action()`.
17    ///
18    /// ## Signals
19    ///
20    ///
21    /// #### `action-added`
22    ///  Signals that a new action was just added to the group.
23    ///
24    /// This signal is emitted after the action has been added
25    /// and is now visible.
26    ///
27    /// Detailed
28    ///
29    ///
30    /// #### `action-enabled-changed`
31    ///  Signals that the enabled status of the named action has changed.
32    ///
33    /// Detailed
34    ///
35    ///
36    /// #### `action-removed`
37    ///  Signals that an action is just about to be removed from the group.
38    ///
39    /// This signal is emitted before the action is removed, so the action
40    /// is still visible and can be queried from the signal handler.
41    ///
42    /// Detailed
43    ///
44    ///
45    /// #### `action-state-changed`
46    ///  Signals that the state of the named action has changed.
47    ///
48    /// Detailed
49    ///
50    /// # Implements
51    ///
52    /// [`ActionGroupExt`][trait@crate::prelude::ActionGroupExt]
53    #[doc(alias = "GActionGroup")]
54    pub struct ActionGroup(Interface<ffi::GActionGroup, ffi::GActionGroupInterface>);
55
56    match fn {
57        type_ => || ffi::g_action_group_get_type(),
58    }
59}
60
61impl ActionGroup {
62    pub const NONE: Option<&'static ActionGroup> = None;
63}
64
65/// Trait containing all [`struct@ActionGroup`] methods.
66///
67/// # Implementors
68///
69/// [`ActionGroup`][struct@crate::ActionGroup], [`Application`][struct@crate::Application], [`DBusActionGroup`][struct@crate::DBusActionGroup], [`RemoteActionGroup`][struct@crate::RemoteActionGroup], [`SimpleActionGroup`][struct@crate::SimpleActionGroup]
70pub trait ActionGroupExt: IsA<ActionGroup> + 'static {
71    /// Emits the [`action-added`][struct@crate::ActionGroup#action-added] signal on @self.
72    ///
73    /// This function should only be called by [type@Gio.ActionGroup] implementations.
74    /// ## `action_name`
75    /// the name of an action in the group
76    #[doc(alias = "g_action_group_action_added")]
77    fn action_added(&self, action_name: &str) {
78        unsafe {
79            ffi::g_action_group_action_added(
80                self.as_ref().to_glib_none().0,
81                action_name.to_glib_none().0,
82            );
83        }
84    }
85
86    /// Emits the [`action-enabled-changed`][struct@crate::ActionGroup#action-enabled-changed] signal on @self.
87    ///
88    /// This function should only be called by [type@Gio.ActionGroup] implementations.
89    /// ## `action_name`
90    /// the name of an action in the group
91    /// ## `enabled`
92    /// whether the action is now enabled
93    #[doc(alias = "g_action_group_action_enabled_changed")]
94    fn action_enabled_changed(&self, action_name: &str, enabled: bool) {
95        unsafe {
96            ffi::g_action_group_action_enabled_changed(
97                self.as_ref().to_glib_none().0,
98                action_name.to_glib_none().0,
99                enabled.into_glib(),
100            );
101        }
102    }
103
104    /// Emits the [`action-removed`][struct@crate::ActionGroup#action-removed] signal on @self.
105    ///
106    /// This function should only be called by [type@Gio.ActionGroup] implementations.
107    /// ## `action_name`
108    /// the name of an action in the group
109    #[doc(alias = "g_action_group_action_removed")]
110    fn action_removed(&self, action_name: &str) {
111        unsafe {
112            ffi::g_action_group_action_removed(
113                self.as_ref().to_glib_none().0,
114                action_name.to_glib_none().0,
115            );
116        }
117    }
118
119    /// Emits the [`action-state-changed`][struct@crate::ActionGroup#action-state-changed] signal on @self.
120    ///
121    /// This function should only be called by [type@Gio.ActionGroup] implementations.
122    /// ## `action_name`
123    /// the name of an action in the group
124    /// ## `state`
125    /// the new state of the named action
126    #[doc(alias = "g_action_group_action_state_changed")]
127    fn action_state_changed(&self, action_name: &str, state: &glib::Variant) {
128        unsafe {
129            ffi::g_action_group_action_state_changed(
130                self.as_ref().to_glib_none().0,
131                action_name.to_glib_none().0,
132                state.to_glib_none().0,
133            );
134        }
135    }
136
137    /// );
138    ///
139    /// g_debug ("Application has been terminated. Exiting.");
140    ///
141    /// exit (0);
142    /// ```text
143    ///
144    /// ## `action_name`
145    /// the name of the action to activate
146    /// ## `parameter`
147    /// parameters to the activation
148    #[doc(alias = "g_action_group_activate_action")]
149    fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>) {
150        unsafe {
151            ffi::g_action_group_activate_action(
152                self.as_ref().to_glib_none().0,
153                action_name.to_glib_none().0,
154                parameter.to_glib_none().0,
155            );
156        }
157    }
158
159    /// Request for the state of the named action within @self to be
160    /// changed to @value.
161    ///
162    /// The action must be stateful and @value must be of the correct type.
163    /// See [`action_state_type()`][Self::action_state_type()].
164    ///
165    /// This call merely requests a change.  The action may refuse to change
166    /// its state or may change its state to something other than @value.
167    /// See [`action_state_hint()`][Self::action_state_hint()].
168    ///
169    /// If the @value GVariant is floating, it is consumed.
170    /// ## `action_name`
171    /// the name of the action to request the change on
172    /// ## `value`
173    /// the new state
174    #[doc(alias = "g_action_group_change_action_state")]
175    fn change_action_state(&self, action_name: &str, value: &glib::Variant) {
176        unsafe {
177            ffi::g_action_group_change_action_state(
178                self.as_ref().to_glib_none().0,
179                action_name.to_glib_none().0,
180                value.to_glib_none().0,
181            );
182        }
183    }
184
185    /// Checks if the named action within @self is currently enabled.
186    ///
187    /// An action must be enabled in order to be activated or in order to
188    /// have its state changed from outside callers.
189    /// ## `action_name`
190    /// the name of the action to query
191    ///
192    /// # Returns
193    ///
194    /// whether the action is currently enabled
195    #[doc(alias = "g_action_group_get_action_enabled")]
196    #[doc(alias = "get_action_enabled")]
197    fn is_action_enabled(&self, action_name: &str) -> bool {
198        unsafe {
199            from_glib(ffi::g_action_group_get_action_enabled(
200                self.as_ref().to_glib_none().0,
201                action_name.to_glib_none().0,
202            ))
203        }
204    }
205
206    /// Queries the type of the parameter that must be given when activating
207    /// the named action within @self.
208    ///
209    /// When activating the action using [`activate_action()`][Self::activate_action()],
210    /// the [type@GLib.Variant] given to that function must be of the type returned
211    /// by this function.
212    ///
213    /// In the case that this function returns `NULL`, you must not give any
214    /// [type@GLib.Variant], but `NULL` instead.
215    ///
216    /// The parameter type of a particular action will never change but it is
217    /// possible for an action to be removed and for a new action to be added
218    /// with the same name but a different parameter type.
219    /// ## `action_name`
220    /// the name of the action to query
221    ///
222    /// # Returns
223    ///
224    /// the parameter type
225    #[doc(alias = "g_action_group_get_action_parameter_type")]
226    #[doc(alias = "get_action_parameter_type")]
227    fn action_parameter_type(&self, action_name: &str) -> Option<glib::VariantType> {
228        unsafe {
229            from_glib_none(ffi::g_action_group_get_action_parameter_type(
230                self.as_ref().to_glib_none().0,
231                action_name.to_glib_none().0,
232            ))
233        }
234    }
235
236    /// Queries the current state of the named action within @self.
237    ///
238    /// If the action is not stateful then `NULL` will be returned.  If the
239    /// action is stateful then the type of the return value is the type
240    /// given by [`action_state_type()`][Self::action_state_type()].
241    ///
242    /// The return value (if non-`NULL`) should be freed with
243    /// `GLib::Variant::unref()` when it is no longer required.
244    /// ## `action_name`
245    /// the name of the action to query
246    ///
247    /// # Returns
248    ///
249    /// the current state of the action
250    #[doc(alias = "g_action_group_get_action_state")]
251    #[doc(alias = "get_action_state")]
252    fn action_state(&self, action_name: &str) -> Option<glib::Variant> {
253        unsafe {
254            from_glib_full(ffi::g_action_group_get_action_state(
255                self.as_ref().to_glib_none().0,
256                action_name.to_glib_none().0,
257            ))
258        }
259    }
260
261    /// Requests a hint about the valid range of values for the state of the
262    /// named action within @self.
263    ///
264    /// If `NULL` is returned it either means that the action is not stateful
265    /// or that there is no hint about the valid range of values for the
266    /// state of the action.
267    ///
268    /// If a [type@GLib.Variant] array is returned then each item in the array is a
269    /// possible value for the state.  If a [type@GLib.Variant] pair (ie: two-tuple) is
270    /// returned then the tuple specifies the inclusive lower and upper bound
271    /// of valid values for the state.
272    ///
273    /// In any case, the information is merely a hint.  It may be possible to
274    /// have a state value outside of the hinted range and setting a value
275    /// within the range may fail.
276    ///
277    /// The return value (if non-`NULL`) should be freed with
278    /// `GLib::Variant::unref()` when it is no longer required.
279    /// ## `action_name`
280    /// the name of the action to query
281    ///
282    /// # Returns
283    ///
284    /// the state range hint
285    #[doc(alias = "g_action_group_get_action_state_hint")]
286    #[doc(alias = "get_action_state_hint")]
287    fn action_state_hint(&self, action_name: &str) -> Option<glib::Variant> {
288        unsafe {
289            from_glib_full(ffi::g_action_group_get_action_state_hint(
290                self.as_ref().to_glib_none().0,
291                action_name.to_glib_none().0,
292            ))
293        }
294    }
295
296    /// Queries the type of the state of the named action within
297    /// @self.
298    ///
299    /// If the action is stateful then this function returns the
300    /// [type@GLib.VariantType] of the state.  All calls to
301    /// [`change_action_state()`][Self::change_action_state()] must give a [type@GLib.Variant] of this
302    /// type and [`action_state()`][Self::action_state()] will return a [type@GLib.Variant]
303    /// of the same type.
304    ///
305    /// If the action is not stateful then this function will return `NULL`.
306    /// In that case, [`action_state()`][Self::action_state()] will return `NULL`
307    /// and you must not call [`change_action_state()`][Self::change_action_state()].
308    ///
309    /// The state type of a particular action will never change but it is
310    /// possible for an action to be removed and for a new action to be added
311    /// with the same name but a different state type.
312    /// ## `action_name`
313    /// the name of the action to query
314    ///
315    /// # Returns
316    ///
317    /// the state type, if the action is stateful
318    #[doc(alias = "g_action_group_get_action_state_type")]
319    #[doc(alias = "get_action_state_type")]
320    fn action_state_type(&self, action_name: &str) -> Option<glib::VariantType> {
321        unsafe {
322            from_glib_none(ffi::g_action_group_get_action_state_type(
323                self.as_ref().to_glib_none().0,
324                action_name.to_glib_none().0,
325            ))
326        }
327    }
328
329    /// Checks if the named action exists within @self.
330    /// ## `action_name`
331    /// the name of the action to check for
332    ///
333    /// # Returns
334    ///
335    /// whether the named action exists
336    #[doc(alias = "g_action_group_has_action")]
337    fn has_action(&self, action_name: &str) -> bool {
338        unsafe {
339            from_glib(ffi::g_action_group_has_action(
340                self.as_ref().to_glib_none().0,
341                action_name.to_glib_none().0,
342            ))
343        }
344    }
345
346    /// Lists the actions contained within @self.
347    ///
348    /// The caller is responsible for freeing the list with `strfreev()` when
349    /// it is no longer required.
350    ///
351    /// # Returns
352    ///
353    /// a `NULL`-terminated array
354    ///   of the names of the actions in the group
355    #[doc(alias = "g_action_group_list_actions")]
356    fn list_actions(&self) -> Vec<glib::GString> {
357        unsafe {
358            FromGlibPtrContainer::from_glib_full(ffi::g_action_group_list_actions(
359                self.as_ref().to_glib_none().0,
360            ))
361        }
362    }
363
364    /// Signals that a new action was just added to the group.
365    ///
366    /// This signal is emitted after the action has been added
367    /// and is now visible.
368    /// ## `action_name`
369    /// the name of the action in @action_group
370    #[doc(alias = "action-added")]
371    fn connect_action_added<F: Fn(&Self, &str) + 'static>(
372        &self,
373        detail: Option<&str>,
374        f: F,
375    ) -> SignalHandlerId {
376        unsafe extern "C" fn action_added_trampoline<
377            P: IsA<ActionGroup>,
378            F: Fn(&P, &str) + 'static,
379        >(
380            this: *mut ffi::GActionGroup,
381            action_name: *mut std::ffi::c_char,
382            f: glib::ffi::gpointer,
383        ) {
384            unsafe {
385                let f: &F = &*(f as *const F);
386                f(
387                    ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
388                    &glib::GString::from_glib_borrow(action_name),
389                )
390            }
391        }
392        unsafe {
393            let f: Box_<F> = Box_::new(f);
394            let detailed_signal_name = detail.map(|name| format!("action-added::{name}\0"));
395            let signal_name = detailed_signal_name.as_ref().map_or(c"action-added", |n| {
396                std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
397            });
398            connect_raw(
399                self.as_ptr() as *mut _,
400                signal_name.as_ptr(),
401                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402                    action_added_trampoline::<Self, F> as *const (),
403                )),
404                Box_::into_raw(f),
405            )
406        }
407    }
408
409    /// Signals that the enabled status of the named action has changed.
410    /// ## `action_name`
411    /// the name of the action in @action_group
412    /// ## `enabled`
413    /// whether the action is enabled
414    #[doc(alias = "action-enabled-changed")]
415    fn connect_action_enabled_changed<F: Fn(&Self, &str, bool) + 'static>(
416        &self,
417        detail: Option<&str>,
418        f: F,
419    ) -> SignalHandlerId {
420        unsafe extern "C" fn action_enabled_changed_trampoline<
421            P: IsA<ActionGroup>,
422            F: Fn(&P, &str, bool) + 'static,
423        >(
424            this: *mut ffi::GActionGroup,
425            action_name: *mut std::ffi::c_char,
426            enabled: glib::ffi::gboolean,
427            f: glib::ffi::gpointer,
428        ) {
429            unsafe {
430                let f: &F = &*(f as *const F);
431                f(
432                    ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
433                    &glib::GString::from_glib_borrow(action_name),
434                    from_glib(enabled),
435                )
436            }
437        }
438        unsafe {
439            let f: Box_<F> = Box_::new(f);
440            let detailed_signal_name =
441                detail.map(|name| format!("action-enabled-changed::{name}\0"));
442            let signal_name = detailed_signal_name
443                .as_ref()
444                .map_or(c"action-enabled-changed", |n| {
445                    std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
446                });
447            connect_raw(
448                self.as_ptr() as *mut _,
449                signal_name.as_ptr(),
450                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
451                    action_enabled_changed_trampoline::<Self, F> as *const (),
452                )),
453                Box_::into_raw(f),
454            )
455        }
456    }
457
458    /// Signals that an action is just about to be removed from the group.
459    ///
460    /// This signal is emitted before the action is removed, so the action
461    /// is still visible and can be queried from the signal handler.
462    /// ## `action_name`
463    /// the name of the action in @action_group
464    #[doc(alias = "action-removed")]
465    fn connect_action_removed<F: Fn(&Self, &str) + 'static>(
466        &self,
467        detail: Option<&str>,
468        f: F,
469    ) -> SignalHandlerId {
470        unsafe extern "C" fn action_removed_trampoline<
471            P: IsA<ActionGroup>,
472            F: Fn(&P, &str) + 'static,
473        >(
474            this: *mut ffi::GActionGroup,
475            action_name: *mut std::ffi::c_char,
476            f: glib::ffi::gpointer,
477        ) {
478            unsafe {
479                let f: &F = &*(f as *const F);
480                f(
481                    ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
482                    &glib::GString::from_glib_borrow(action_name),
483                )
484            }
485        }
486        unsafe {
487            let f: Box_<F> = Box_::new(f);
488            let detailed_signal_name = detail.map(|name| format!("action-removed::{name}\0"));
489            let signal_name = detailed_signal_name
490                .as_ref()
491                .map_or(c"action-removed", |n| {
492                    std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
493                });
494            connect_raw(
495                self.as_ptr() as *mut _,
496                signal_name.as_ptr(),
497                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
498                    action_removed_trampoline::<Self, F> as *const (),
499                )),
500                Box_::into_raw(f),
501            )
502        }
503    }
504
505    /// Signals that the state of the named action has changed.
506    /// ## `action_name`
507    /// the name of the action in @action_group
508    /// ## `value`
509    /// the new value of the state
510    #[doc(alias = "action-state-changed")]
511    fn connect_action_state_changed<F: Fn(&Self, &str, &glib::Variant) + 'static>(
512        &self,
513        detail: Option<&str>,
514        f: F,
515    ) -> SignalHandlerId {
516        unsafe extern "C" fn action_state_changed_trampoline<
517            P: IsA<ActionGroup>,
518            F: Fn(&P, &str, &glib::Variant) + 'static,
519        >(
520            this: *mut ffi::GActionGroup,
521            action_name: *mut std::ffi::c_char,
522            value: *mut glib::ffi::GVariant,
523            f: glib::ffi::gpointer,
524        ) {
525            unsafe {
526                let f: &F = &*(f as *const F);
527                f(
528                    ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
529                    &glib::GString::from_glib_borrow(action_name),
530                    &from_glib_borrow(value),
531                )
532            }
533        }
534        unsafe {
535            let f: Box_<F> = Box_::new(f);
536            let detailed_signal_name = detail.map(|name| format!("action-state-changed::{name}\0"));
537            let signal_name = detailed_signal_name
538                .as_ref()
539                .map_or(c"action-state-changed", |n| {
540                    std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
541                });
542            connect_raw(
543                self.as_ptr() as *mut _,
544                signal_name.as_ptr(),
545                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
546                    action_state_changed_trampoline::<Self, F> as *const (),
547                )),
548                Box_::into_raw(f),
549            )
550        }
551    }
552}
553
554impl<O: IsA<ActionGroup>> ActionGroupExt for O {}