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

use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem::transmute};

glib::wrapper! {
    #[doc(alias = "GnomeWallClock")]
    pub struct WallClock(Object<ffi::GnomeWallClock, ffi::GnomeWallClockClass>);

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

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

    #[doc(alias = "gnome_wall_clock_new")]
    pub fn new() -> WallClock {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gnome_wall_clock_new()) }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`WallClock`] objects.
    ///
    /// This method returns an instance of [`WallClockBuilder`](crate::builders::WallClockBuilder) which can be used to create [`WallClock`] objects.
    pub fn builder() -> WallClockBuilder {
        WallClockBuilder::new()
    }
}

impl Default for WallClock {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`WallClock`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct WallClockBuilder {
    builder: glib::object::ObjectBuilder<'static, WallClock>,
}

impl WallClockBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    pub fn force_seconds(self, force_seconds: bool) -> Self {
        Self {
            builder: self.builder.property("force-seconds", force_seconds),
        }
    }

    pub fn time_only(self, time_only: bool) -> Self {
        Self {
            builder: self.builder.property("time-only", time_only),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`WallClock`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> WallClock {
        self.builder.build()
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::WallClock>> Sealed for T {}
}

pub trait WallClockExt: IsA<WallClock> + sealed::Sealed + 'static {
    #[doc(alias = "gnome_wall_clock_get_clock")]
    #[doc(alias = "get_clock")]
    fn clock(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gnome_wall_clock_get_clock(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_wall_clock_get_timezone")]
    #[doc(alias = "get_timezone")]
    fn timezone(&self) -> Option<glib::TimeZone> {
        unsafe {
            from_glib_none(ffi::gnome_wall_clock_get_timezone(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gnome_wall_clock_string_for_datetime")]
    fn string_for_datetime(
        &self,
        now: &glib::DateTime,
        clock_format: gdesktop_enums::ClockFormat,
        show_weekday: bool,
        show_full_date: bool,
        show_seconds: bool,
    ) -> Option<glib::GString> {
        unsafe {
            from_glib_full(ffi::gnome_wall_clock_string_for_datetime(
                self.as_ref().to_glib_none().0,
                now.to_glib_none().0,
                clock_format.into_glib(),
                show_weekday.into_glib(),
                show_full_date.into_glib(),
                show_seconds.into_glib(),
            ))
        }
    }

    #[doc(alias = "force-seconds")]
    fn is_force_seconds(&self) -> bool {
        ObjectExt::property(self.as_ref(), "force-seconds")
    }

    #[doc(alias = "force-seconds")]
    fn set_force_seconds(&self, force_seconds: bool) {
        ObjectExt::set_property(self.as_ref(), "force-seconds", force_seconds)
    }

    #[doc(alias = "time-only")]
    fn is_time_only(&self) -> bool {
        ObjectExt::property(self.as_ref(), "time-only")
    }

    #[doc(alias = "time-only")]
    fn set_time_only(&self, time_only: bool) {
        ObjectExt::set_property(self.as_ref(), "time-only", time_only)
    }

    #[doc(alias = "clock")]
    fn connect_clock_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_clock_trampoline<P: IsA<WallClock>, F: Fn(&P) + 'static>(
            this: *mut ffi::GnomeWallClock,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WallClock::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::clock\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_clock_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "force-seconds")]
    fn connect_force_seconds_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_force_seconds_trampoline<
            P: IsA<WallClock>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GnomeWallClock,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WallClock::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::force-seconds\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_force_seconds_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "time-only")]
    fn connect_time_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_time_only_trampoline<P: IsA<WallClock>, F: Fn(&P) + 'static>(
            this: *mut ffi::GnomeWallClock,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WallClock::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::time-only\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_time_only_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "timezone")]
    fn connect_timezone_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_timezone_trampoline<P: IsA<WallClock>, F: Fn(&P) + 'static>(
            this: *mut ffi::GnomeWallClock,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(WallClock::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::timezone\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_timezone_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<WallClock>> WallClockExt for O {}

impl fmt::Display for WallClock {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("WallClock")
    }
}
