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
#[cfg(any(feature = "v2_38", feature = "dox"))]
use Error;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;
glib_wrapper! {
pub struct Action(Object<ffi::GAction, ffi::GActionInterface>);
match fn {
get_type => || ffi::g_action_get_type(),
}
}
impl Action {
#[cfg(any(feature = "v2_38", feature = "dox"))]
pub fn name_is_valid(action_name: &str) -> bool {
unsafe {
from_glib(ffi::g_action_name_is_valid(action_name.to_glib_none().0))
}
}
#[cfg(any(feature = "v2_38", feature = "dox"))]
pub fn parse_detailed_name(detailed_name: &str) -> Result<(String, glib::Variant), Error> {
unsafe {
let mut action_name = ptr::null_mut();
let mut target_value = ptr::null_mut();
let mut error = ptr::null_mut();
let _ = ffi::g_action_parse_detailed_name(detailed_name.to_glib_none().0, &mut action_name, &mut target_value, &mut error);
if error.is_null() { Ok((from_glib_full(action_name), from_glib_full(target_value))) } else { Err(from_glib_full(error)) }
}
}
#[cfg(any(feature = "v2_38", feature = "dox"))]
pub fn print_detailed_name<'a, P: Into<Option<&'a glib::Variant>>>(action_name: &str, target_value: P) -> Option<String> {
let target_value = target_value.into();
let target_value = target_value.to_glib_none();
unsafe {
from_glib_full(ffi::g_action_print_detailed_name(action_name.to_glib_none().0, target_value.0))
}
}
}
pub trait ActionExt {
fn activate<'a, P: Into<Option<&'a glib::Variant>>>(&self, parameter: P);
fn change_state(&self, value: &glib::Variant);
fn get_enabled(&self) -> bool;
fn get_name(&self) -> Option<String>;
fn get_parameter_type(&self) -> Option<glib::VariantType>;
fn get_state(&self) -> Option<glib::Variant>;
fn get_state_hint(&self) -> Option<glib::Variant>;
fn get_state_type(&self) -> Option<glib::VariantType>;
fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_parameter_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<Action> + IsA<glib::object::Object>> ActionExt for O {
fn activate<'a, P: Into<Option<&'a glib::Variant>>>(&self, parameter: P) {
let parameter = parameter.into();
let parameter = parameter.to_glib_none();
unsafe {
ffi::g_action_activate(self.to_glib_none().0, parameter.0);
}
}
fn change_state(&self, value: &glib::Variant) {
unsafe {
ffi::g_action_change_state(self.to_glib_none().0, value.to_glib_none().0);
}
}
fn get_enabled(&self) -> bool {
unsafe {
from_glib(ffi::g_action_get_enabled(self.to_glib_none().0))
}
}
fn get_name(&self) -> Option<String> {
unsafe {
from_glib_none(ffi::g_action_get_name(self.to_glib_none().0))
}
}
fn get_parameter_type(&self) -> Option<glib::VariantType> {
unsafe {
from_glib_none(ffi::g_action_get_parameter_type(self.to_glib_none().0))
}
}
fn get_state(&self) -> Option<glib::Variant> {
unsafe {
from_glib_full(ffi::g_action_get_state(self.to_glib_none().0))
}
}
fn get_state_hint(&self) -> Option<glib::Variant> {
unsafe {
from_glib_full(ffi::g_action_get_state_hint(self.to_glib_none().0))
}
}
fn get_state_type(&self) -> Option<glib::VariantType> {
unsafe {
from_glib_none(ffi::g_action_get_state_type(self.to_glib_none().0))
}
}
fn connect_property_enabled_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::enabled",
transmute(notify_enabled_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::name",
transmute(notify_name_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_property_parameter_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::parameter-type",
transmute(notify_parameter_type_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_property_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::state",
transmute(notify_state_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
fn connect_property_state_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&Self) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "notify::state-type",
transmute(notify_state_type_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn notify_enabled_trampoline<P>(this: *mut ffi::GAction, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Action> {
let f: &&(Fn(&P) + 'static) = transmute(f);
f(&Action::from_glib_borrow(this).downcast_unchecked())
}
unsafe extern "C" fn notify_name_trampoline<P>(this: *mut ffi::GAction, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Action> {
let f: &&(Fn(&P) + 'static) = transmute(f);
f(&Action::from_glib_borrow(this).downcast_unchecked())
}
unsafe extern "C" fn notify_parameter_type_trampoline<P>(this: *mut ffi::GAction, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Action> {
let f: &&(Fn(&P) + 'static) = transmute(f);
f(&Action::from_glib_borrow(this).downcast_unchecked())
}
unsafe extern "C" fn notify_state_trampoline<P>(this: *mut ffi::GAction, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Action> {
let f: &&(Fn(&P) + 'static) = transmute(f);
f(&Action::from_glib_borrow(this).downcast_unchecked())
}
unsafe extern "C" fn notify_state_type_trampoline<P>(this: *mut ffi::GAction, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Action> {
let f: &&(Fn(&P) + 'static) = transmute(f);
f(&Action::from_glib_borrow(this).downcast_unchecked())
}