// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::ffi;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "ShumateLocation")]
    pub struct Location(Interface<ffi::ShumateLocation, ffi::ShumateLocationInterface>);

    match fn {
        type_ => || ffi::shumate_location_get_type(),
    }
}

impl Location {
    pub const NONE: Option<&'static Location> = None;
}

pub trait LocationExt: IsA<Location> + 'static {
    #[cfg(feature = "v1_2")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
    #[doc(alias = "shumate_location_distance")]
    fn distance(&self, other: &impl IsA<Location>) -> f64 {
        unsafe {
            ffi::shumate_location_distance(
                self.as_ref().to_glib_none().0,
                other.as_ref().to_glib_none().0,
            )
        }
    }

    #[doc(alias = "shumate_location_get_latitude")]
    #[doc(alias = "get_latitude")]
    fn latitude(&self) -> f64 {
        unsafe { ffi::shumate_location_get_latitude(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "shumate_location_get_longitude")]
    #[doc(alias = "get_longitude")]
    fn longitude(&self) -> f64 {
        unsafe { ffi::shumate_location_get_longitude(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "shumate_location_set_location")]
    fn set_location(&self, latitude: f64, longitude: f64) {
        unsafe {
            ffi::shumate_location_set_location(self.as_ref().to_glib_none().0, latitude, longitude);
        }
    }

    fn set_latitude(&self, latitude: f64) {
        ObjectExt::set_property(self.as_ref(), "latitude", latitude)
    }

    fn set_longitude(&self, longitude: f64) {
        ObjectExt::set_property(self.as_ref(), "longitude", longitude)
    }

    #[doc(alias = "latitude")]
    fn connect_latitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_latitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
            this: *mut ffi::ShumateLocation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Location::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::latitude".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_latitude_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "longitude")]
    fn connect_longitude_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_longitude_trampoline<P: IsA<Location>, F: Fn(&P) + 'static>(
            this: *mut ffi::ShumateLocation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(Location::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::longitude".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_longitude_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Location>> LocationExt for O {}
