gio/auto/
action.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 gio_sys;
6use glib;
7use glib::object::Cast;
8use glib::object::IsA;
9use glib::signal::connect_raw;
10use glib::signal::SignalHandlerId;
11use glib::translate::*;
12use glib::GString;
13use glib_sys;
14use std::boxed::Box as Box_;
15use std::fmt;
16use std::mem::transmute;
17use std::ptr;
18use Error;
19
20glib_wrapper! {
21    pub struct Action(Interface<gio_sys::GAction>);
22
23    match fn {
24        get_type => || gio_sys::g_action_get_type(),
25    }
26}
27
28impl Action {
29    pub fn name_is_valid(action_name: &str) -> bool {
30        unsafe {
31            from_glib(gio_sys::g_action_name_is_valid(
32                action_name.to_glib_none().0,
33            ))
34        }
35    }
36
37    pub fn parse_detailed_name(detailed_name: &str) -> Result<(GString, glib::Variant), Error> {
38        unsafe {
39            let mut action_name = ptr::null_mut();
40            let mut target_value = ptr::null_mut();
41            let mut error = ptr::null_mut();
42            let _ = gio_sys::g_action_parse_detailed_name(
43                detailed_name.to_glib_none().0,
44                &mut action_name,
45                &mut target_value,
46                &mut error,
47            );
48            if error.is_null() {
49                Ok((from_glib_full(action_name), from_glib_full(target_value)))
50            } else {
51                Err(from_glib_full(error))
52            }
53        }
54    }
55
56    pub fn print_detailed_name(
57        action_name: &str,
58        target_value: Option<&glib::Variant>,
59    ) -> Option<GString> {
60        unsafe {
61            from_glib_full(gio_sys::g_action_print_detailed_name(
62                action_name.to_glib_none().0,
63                target_value.to_glib_none().0,
64            ))
65        }
66    }
67}
68
69pub const NONE_ACTION: Option<&Action> = None;
70
71pub trait ActionExt: 'static {
72    fn activate(&self, parameter: Option<&glib::Variant>);
73
74    fn change_state(&self, value: &glib::Variant);
75
76    fn get_enabled(&self) -> bool;
77
78    fn get_name(&self) -> Option<GString>;
79
80    fn get_parameter_type(&self) -> Option<glib::VariantType>;
81
82    fn get_state(&self) -> Option<glib::Variant>;
83
84    fn get_state_hint(&self) -> Option<glib::Variant>;
85
86    fn get_state_type(&self) -> Option<glib::VariantType>;
87
88    fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
89
90    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
91
92    fn connect_property_parameter_type_notify<F: Fn(&Self) + 'static>(
93        &self,
94        f: F,
95    ) -> SignalHandlerId;
96
97    fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
98
99    fn connect_property_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
100}
101
102impl<O: IsA<Action>> ActionExt for O {
103    fn activate(&self, parameter: Option<&glib::Variant>) {
104        unsafe {
105            gio_sys::g_action_activate(self.as_ref().to_glib_none().0, parameter.to_glib_none().0);
106        }
107    }
108
109    fn change_state(&self, value: &glib::Variant) {
110        unsafe {
111            gio_sys::g_action_change_state(self.as_ref().to_glib_none().0, value.to_glib_none().0);
112        }
113    }
114
115    fn get_enabled(&self) -> bool {
116        unsafe {
117            from_glib(gio_sys::g_action_get_enabled(
118                self.as_ref().to_glib_none().0,
119            ))
120        }
121    }
122
123    fn get_name(&self) -> Option<GString> {
124        unsafe { from_glib_none(gio_sys::g_action_get_name(self.as_ref().to_glib_none().0)) }
125    }
126
127    fn get_parameter_type(&self) -> Option<glib::VariantType> {
128        unsafe {
129            from_glib_none(gio_sys::g_action_get_parameter_type(
130                self.as_ref().to_glib_none().0,
131            ))
132        }
133    }
134
135    fn get_state(&self) -> Option<glib::Variant> {
136        unsafe { from_glib_full(gio_sys::g_action_get_state(self.as_ref().to_glib_none().0)) }
137    }
138
139    fn get_state_hint(&self) -> Option<glib::Variant> {
140        unsafe {
141            from_glib_full(gio_sys::g_action_get_state_hint(
142                self.as_ref().to_glib_none().0,
143            ))
144        }
145    }
146
147    fn get_state_type(&self) -> Option<glib::VariantType> {
148        unsafe {
149            from_glib_none(gio_sys::g_action_get_state_type(
150                self.as_ref().to_glib_none().0,
151            ))
152        }
153    }
154
155    fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
156        unsafe extern "C" fn notify_enabled_trampoline<P, F: Fn(&P) + 'static>(
157            this: *mut gio_sys::GAction,
158            _param_spec: glib_sys::gpointer,
159            f: glib_sys::gpointer,
160        ) where
161            P: IsA<Action>,
162        {
163            let f: &F = &*(f as *const F);
164            f(&Action::from_glib_borrow(this).unsafe_cast())
165        }
166        unsafe {
167            let f: Box_<F> = Box_::new(f);
168            connect_raw(
169                self.as_ptr() as *mut _,
170                b"notify::enabled\0".as_ptr() as *const _,
171                Some(transmute(notify_enabled_trampoline::<Self, F> as usize)),
172                Box_::into_raw(f),
173            )
174        }
175    }
176
177    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
178        unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
179            this: *mut gio_sys::GAction,
180            _param_spec: glib_sys::gpointer,
181            f: glib_sys::gpointer,
182        ) where
183            P: IsA<Action>,
184        {
185            let f: &F = &*(f as *const F);
186            f(&Action::from_glib_borrow(this).unsafe_cast())
187        }
188        unsafe {
189            let f: Box_<F> = Box_::new(f);
190            connect_raw(
191                self.as_ptr() as *mut _,
192                b"notify::name\0".as_ptr() as *const _,
193                Some(transmute(notify_name_trampoline::<Self, F> as usize)),
194                Box_::into_raw(f),
195            )
196        }
197    }
198
199    fn connect_property_parameter_type_notify<F: Fn(&Self) + 'static>(
200        &self,
201        f: F,
202    ) -> SignalHandlerId {
203        unsafe extern "C" fn notify_parameter_type_trampoline<P, F: Fn(&P) + 'static>(
204            this: *mut gio_sys::GAction,
205            _param_spec: glib_sys::gpointer,
206            f: glib_sys::gpointer,
207        ) where
208            P: IsA<Action>,
209        {
210            let f: &F = &*(f as *const F);
211            f(&Action::from_glib_borrow(this).unsafe_cast())
212        }
213        unsafe {
214            let f: Box_<F> = Box_::new(f);
215            connect_raw(
216                self.as_ptr() as *mut _,
217                b"notify::parameter-type\0".as_ptr() as *const _,
218                Some(transmute(
219                    notify_parameter_type_trampoline::<Self, F> as usize,
220                )),
221                Box_::into_raw(f),
222            )
223        }
224    }
225
226    fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
227        unsafe extern "C" fn notify_state_trampoline<P, F: Fn(&P) + 'static>(
228            this: *mut gio_sys::GAction,
229            _param_spec: glib_sys::gpointer,
230            f: glib_sys::gpointer,
231        ) where
232            P: IsA<Action>,
233        {
234            let f: &F = &*(f as *const F);
235            f(&Action::from_glib_borrow(this).unsafe_cast())
236        }
237        unsafe {
238            let f: Box_<F> = Box_::new(f);
239            connect_raw(
240                self.as_ptr() as *mut _,
241                b"notify::state\0".as_ptr() as *const _,
242                Some(transmute(notify_state_trampoline::<Self, F> as usize)),
243                Box_::into_raw(f),
244            )
245        }
246    }
247
248    fn connect_property_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
249        unsafe extern "C" fn notify_state_type_trampoline<P, F: Fn(&P) + 'static>(
250            this: *mut gio_sys::GAction,
251            _param_spec: glib_sys::gpointer,
252            f: glib_sys::gpointer,
253        ) where
254            P: IsA<Action>,
255        {
256            let f: &F = &*(f as *const F);
257            f(&Action::from_glib_borrow(this).unsafe_cast())
258        }
259        unsafe {
260            let f: Box_<F> = Box_::new(f);
261            connect_raw(
262                self.as_ptr() as *mut _,
263                b"notify::state-type\0".as_ptr() as *const _,
264                Some(transmute(notify_state_type_trampoline::<Self, F> as usize)),
265                Box_::into_raw(f),
266            )
267        }
268    }
269}
270
271impl fmt::Display for Action {
272    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
273        write!(f, "Action")
274    }
275}