1use crate::{Menuitem,Status,TextDirection};
7use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
8use std::{boxed::Box as Box_,fmt,mem::transmute};
9
10glib::wrapper! {
11 #[doc(alias = "DbusmenuServer")]
12 pub struct Server(Object<ffi::DbusmenuServer, ffi::DbusmenuServerClass>);
13
14 match fn {
15 type_ => || ffi::dbusmenu_server_get_type(),
16 }
17}
18
19impl Server {
20 pub const NONE: Option<&'static Server> = None;
21
22
23 #[doc(alias = "dbusmenu_server_new")]
32 pub fn new(object: &str) -> Server {
33 assert_initialized_main_thread!();
34 unsafe {
35 from_glib_full(ffi::dbusmenu_server_new(object.to_glib_none().0))
36 }
37 }
38}
39
40pub trait ServerExt: 'static {
46 #[doc(alias = "dbusmenu_server_get_icon_paths")]
54 #[doc(alias = "get_icon_paths")]
55 fn icon_paths(&self) -> Vec<glib::GString>;
56
57 #[doc(alias = "dbusmenu_server_get_status")]
62 #[doc(alias = "get_status")]
63 fn status(&self) -> Status;
64
65 #[doc(alias = "dbusmenu_server_get_text_direction")]
72 #[doc(alias = "get_text_direction")]
73 fn text_direction(&self) -> TextDirection;
74
75 #[doc(alias = "dbusmenu_server_set_icon_paths")]
78 fn set_icon_paths(&self, icon_paths: &[&str]);
79
80 #[doc(alias = "dbusmenu_server_set_root")]
86 fn set_root(&self, root: &impl IsA<Menuitem>);
87
88 #[doc(alias = "dbusmenu_server_set_status")]
92 fn set_status(&self, status: Status);
93
94 #[doc(alias = "dbusmenu_server_set_text_direction")]
101 fn set_text_direction(&self, dir: TextDirection);
102
103 #[doc(alias = "dbus-object")]
104 fn dbus_object(&self) -> Option<glib::GString>;
105
106 #[doc(alias = "root-node")]
107 fn root_node(&self) -> Option<Menuitem>;
108
109 #[doc(alias = "root-node")]
110 fn set_root_node<P: IsA<Menuitem>>(&self, root_node: Option<&P>);
111
112 fn version(&self) -> u32;
113
114 #[doc(alias = "item-activation-requested")]
121 fn connect_item_activation_requested<F: Fn(&Self, i32, u32) + 'static>(&self, f: F) -> SignalHandlerId;
122
123 #[doc(alias = "item-property-updated")]
124 fn connect_item_property_updated<F: Fn(&Self, i32, &str, &glib::Variant) + 'static>(&self, f: F) -> SignalHandlerId;
125
126 #[doc(alias = "item-updated")]
127 fn connect_item_updated<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId;
128
129 #[doc(alias = "layout-updated")]
137 fn connect_layout_updated<F: Fn(&Self, u32, i32) + 'static>(&self, f: F) -> SignalHandlerId;
138
139 #[doc(alias = "root-node")]
140 fn connect_root_node_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
141
142 #[doc(alias = "version")]
143 fn connect_version_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
144}
145
146impl<O: IsA<Server>> ServerExt for O {
147 fn icon_paths(&self) -> Vec<glib::GString> {
148 unsafe {
149 FromGlibPtrContainer::from_glib_none(ffi::dbusmenu_server_get_icon_paths(self.as_ref().to_glib_none().0))
150 }
151 }
152
153 fn status(&self) -> Status {
154 unsafe {
155 from_glib(ffi::dbusmenu_server_get_status(self.as_ref().to_glib_none().0))
156 }
157 }
158
159 fn text_direction(&self) -> TextDirection {
160 unsafe {
161 from_glib(ffi::dbusmenu_server_get_text_direction(self.as_ref().to_glib_none().0))
162 }
163 }
164
165 fn set_icon_paths(&self, icon_paths: &[&str]) {
166 unsafe {
167 ffi::dbusmenu_server_set_icon_paths(self.as_ref().to_glib_none().0, icon_paths.to_glib_none().0);
168 }
169 }
170
171 fn set_root(&self, root: &impl IsA<Menuitem>) {
172 unsafe {
173 ffi::dbusmenu_server_set_root(self.as_ref().to_glib_none().0, root.as_ref().to_glib_none().0);
174 }
175 }
176
177 fn set_status(&self, status: Status) {
178 unsafe {
179 ffi::dbusmenu_server_set_status(self.as_ref().to_glib_none().0, status.into_glib());
180 }
181 }
182
183 fn set_text_direction(&self, dir: TextDirection) {
184 unsafe {
185 ffi::dbusmenu_server_set_text_direction(self.as_ref().to_glib_none().0, dir.into_glib());
186 }
187 }
188
189 fn dbus_object(&self) -> Option<glib::GString> {
190 glib::ObjectExt::property(self.as_ref(), "dbus-object")
191 }
192
193 fn root_node(&self) -> Option<Menuitem> {
194 glib::ObjectExt::property(self.as_ref(), "root-node")
195 }
196
197 fn set_root_node<P: IsA<Menuitem>>(&self, root_node: Option<&P>) {
198 glib::ObjectExt::set_property(self.as_ref(),"root-node", root_node)
199 }
200
201 fn version(&self) -> u32 {
202 glib::ObjectExt::property(self.as_ref(), "version")
203 }
204
205 fn connect_item_activation_requested<F: Fn(&Self, i32, u32) + 'static>(&self, f: F) -> SignalHandlerId {
206 unsafe extern "C" fn item_activation_requested_trampoline<P: IsA<Server>, F: Fn(&P, i32, u32) + 'static>(this: *mut ffi::DbusmenuServer, arg1: libc::c_int, arg2: libc::c_uint, f: glib::ffi::gpointer) {
207 let f: &F = &*(f as *const F);
208 f(Server::from_glib_borrow(this).unsafe_cast_ref(), arg1, arg2)
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(self.as_ptr() as *mut _, b"item-activation-requested\0".as_ptr() as *const _,
213 Some(transmute::<_, unsafe extern "C" fn()>(item_activation_requested_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
214 }
215 }
216
217 fn connect_item_property_updated<F: Fn(&Self, i32, &str, &glib::Variant) + 'static>(&self, f: F) -> SignalHandlerId {
218 unsafe extern "C" fn item_property_updated_trampoline<P: IsA<Server>, F: Fn(&P, i32, &str, &glib::Variant) + 'static>(this: *mut ffi::DbusmenuServer, object: libc::c_int, p0: *mut libc::c_char, p1: *mut glib::ffi::GVariant, f: glib::ffi::gpointer) {
219 let f: &F = &*(f as *const F);
220 f(Server::from_glib_borrow(this).unsafe_cast_ref(), object, &glib::GString::from_glib_borrow(p0), &from_glib_borrow(p1))
221 }
222 unsafe {
223 let f: Box_<F> = Box_::new(f);
224 connect_raw(self.as_ptr() as *mut _, b"item-property-updated\0".as_ptr() as *const _,
225 Some(transmute::<_, unsafe extern "C" fn()>(item_property_updated_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
226 }
227 }
228
229 fn connect_item_updated<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
230 unsafe extern "C" fn item_updated_trampoline<P: IsA<Server>, F: Fn(&P, i32) + 'static>(this: *mut ffi::DbusmenuServer, object: libc::c_int, f: glib::ffi::gpointer) {
231 let f: &F = &*(f as *const F);
232 f(Server::from_glib_borrow(this).unsafe_cast_ref(), object)
233 }
234 unsafe {
235 let f: Box_<F> = Box_::new(f);
236 connect_raw(self.as_ptr() as *mut _, b"item-updated\0".as_ptr() as *const _,
237 Some(transmute::<_, unsafe extern "C" fn()>(item_updated_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
238 }
239 }
240
241 fn connect_layout_updated<F: Fn(&Self, u32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
242 unsafe extern "C" fn layout_updated_trampoline<P: IsA<Server>, F: Fn(&P, u32, i32) + 'static>(this: *mut ffi::DbusmenuServer, arg1: libc::c_uint, arg2: libc::c_int, f: glib::ffi::gpointer) {
243 let f: &F = &*(f as *const F);
244 f(Server::from_glib_borrow(this).unsafe_cast_ref(), arg1, arg2)
245 }
246 unsafe {
247 let f: Box_<F> = Box_::new(f);
248 connect_raw(self.as_ptr() as *mut _, b"layout-updated\0".as_ptr() as *const _,
249 Some(transmute::<_, unsafe extern "C" fn()>(layout_updated_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
250 }
251 }
252
253 fn connect_root_node_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
254 unsafe extern "C" fn notify_root_node_trampoline<P: IsA<Server>, F: Fn(&P) + 'static>(this: *mut ffi::DbusmenuServer, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
255 let f: &F = &*(f as *const F);
256 f(Server::from_glib_borrow(this).unsafe_cast_ref())
257 }
258 unsafe {
259 let f: Box_<F> = Box_::new(f);
260 connect_raw(self.as_ptr() as *mut _, b"notify::root-node\0".as_ptr() as *const _,
261 Some(transmute::<_, unsafe extern "C" fn()>(notify_root_node_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
262 }
263 }
264
265 fn connect_version_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266 unsafe extern "C" fn notify_version_trampoline<P: IsA<Server>, F: Fn(&P) + 'static>(this: *mut ffi::DbusmenuServer, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
267 let f: &F = &*(f as *const F);
268 f(Server::from_glib_borrow(this).unsafe_cast_ref())
269 }
270 unsafe {
271 let f: Box_<F> = Box_::new(f);
272 connect_raw(self.as_ptr() as *mut _, b"notify::version\0".as_ptr() as *const _,
273 Some(transmute::<_, unsafe extern "C" fn()>(notify_version_trampoline::<Self, F> as *const ())), Box_::into_raw(f))
274 }
275 }
276}
277
278impl fmt::Display for Server {
279 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
280 f.write_str("Server")
281 }
282}