libshumate/auto/
location.rs1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "ShumateLocation")]
38 pub struct Location(Interface<ffi::ShumateLocation, ffi::ShumateLocationInterface>);
39
40 match fn {
41 type_ => || ffi::shumate_location_get_type(),
42 }
43}
44
45impl Location {
46 pub const NONE: Option<&'static Location> = None;
47}
48
49pub trait LocationExt: IsA<Location> + 'static {
55 #[cfg(feature = "v1_2")]
67 #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
68 #[doc(alias = "shumate_location_distance")]
69 fn distance(&self, other: &impl IsA<Location>) -> f64 {
70 unsafe {
71 ffi::shumate_location_distance(
72 self.as_ref().to_glib_none().0,
73 other.as_ref().to_glib_none().0,
74 )
75 }
76 }
77
78 #[doc(alias = "shumate_location_get_latitude")]
84 #[doc(alias = "get_latitude")]
85 fn latitude(&self) -> f64 {
86 unsafe { ffi::shumate_location_get_latitude(self.as_ref().to_glib_none().0) }
87 }
88
89 #[doc(alias = "shumate_location_get_longitude")]
95 #[doc(alias = "get_longitude")]
96 fn longitude(&self) -> f64 {
97 unsafe { ffi::shumate_location_get_longitude(self.as_ref().to_glib_none().0) }
98 }
99
100 #[doc(alias = "shumate_location_set_location")]
106 fn set_location(&self, latitude: f64, longitude: f64) {
107 unsafe {
108 ffi::shumate_location_set_location(self.as_ref().to_glib_none().0, latitude, longitude);
109 }
110 }
111
112 fn set_latitude(&self, latitude: f64) {
114 ObjectExt::set_property(self.as_ref(), "latitude", latitude)
115 }
116
117 fn set_longitude(&self, longitude: f64) {
119 ObjectExt::set_property(self.as_ref(), "longitude", longitude)
120 }
121
122 #[doc(alias = "latitude")]
123 fn connect_latitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
124 unsafe extern "C" fn notify_latitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
125 this: *mut ffi::ShumateLocation,
126 _param_spec: glib::ffi::gpointer,
127 f: glib::ffi::gpointer,
128 ) {
129 unsafe {
130 let f: &F = &*(f as *const F);
131 f(Location::from_glib_borrow(this).unsafe_cast_ref())
132 }
133 }
134 unsafe {
135 let f: Box_<F> = Box_::new(f);
136 connect_raw(
137 self.as_ptr() as *mut _,
138 c"notify::latitude".as_ptr(),
139 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
140 notify_latitude_trampoline::<Self, F> as *const (),
141 )),
142 Box_::into_raw(f),
143 )
144 }
145 }
146
147 #[doc(alias = "longitude")]
148 fn connect_longitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
149 unsafe extern "C" fn notify_longitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
150 this: *mut ffi::ShumateLocation,
151 _param_spec: glib::ffi::gpointer,
152 f: glib::ffi::gpointer,
153 ) {
154 unsafe {
155 let f: &F = &*(f as *const F);
156 f(Location::from_glib_borrow(this).unsafe_cast_ref())
157 }
158 }
159 unsafe {
160 let f: Box_<F> = Box_::new(f);
161 connect_raw(
162 self.as_ptr() as *mut _,
163 c"notify::longitude".as_ptr(),
164 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165 notify_longitude_trampoline::<Self, F> as *const (),
166 )),
167 Box_::into_raw(f),
168 )
169 }
170 }
171}
172
173impl<O: IsA<Location>> LocationExt for O {}