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

use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::Value;
use glib_sys;
use gobject_sys;
use nm_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use Setting;
use SettingIPConfig;

glib_wrapper! {
    pub struct SettingIP4Config(Object<nm_sys::NMSettingIP4Config, nm_sys::NMSettingIP4ConfigClass, SettingIP4ConfigClass>) @extends SettingIPConfig, Setting;

    match fn {
        get_type => || nm_sys::nm_setting_ip4_config_get_type(),
    }
}

impl SettingIP4Config {
    pub fn new() -> SettingIP4Config {
        unsafe { Setting::from_glib_full(nm_sys::nm_setting_ip4_config_new()).unsafe_cast() }
    }
}

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

pub const NONE_SETTING_IP4_CONFIG: Option<&SettingIP4Config> = None;

pub trait SettingIP4ConfigExt: 'static {
    fn get_dhcp_client_id(&self) -> Option<GString>;

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn get_dhcp_fqdn(&self) -> Option<GString>;

    fn set_property_dhcp_client_id(&self, dhcp_client_id: Option<&str>);

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn set_property_dhcp_fqdn(&self, dhcp_fqdn: Option<&str>);

    fn connect_property_dhcp_client_id_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId;

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn connect_property_dhcp_fqdn_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<SettingIP4Config>> SettingIP4ConfigExt for O {
    fn get_dhcp_client_id(&self) -> Option<GString> {
        unsafe {
            from_glib_none(nm_sys::nm_setting_ip4_config_get_dhcp_client_id(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn get_dhcp_fqdn(&self) -> Option<GString> {
        unsafe {
            from_glib_none(nm_sys::nm_setting_ip4_config_get_dhcp_fqdn(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_property_dhcp_client_id(&self, dhcp_client_id: Option<&str>) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"dhcp-client-id\0".as_ptr() as *const _,
                Value::from(dhcp_client_id).to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn set_property_dhcp_fqdn(&self, dhcp_fqdn: Option<&str>) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"dhcp-fqdn\0".as_ptr() as *const _,
                Value::from(dhcp_fqdn).to_glib_none().0,
            );
        }
    }

    fn connect_property_dhcp_client_id_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_dhcp_client_id_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut nm_sys::NMSettingIP4Config,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<SettingIP4Config>,
        {
            let f: &F = &*(f as *const F);
            f(&SettingIP4Config::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::dhcp-client-id\0".as_ptr() as *const _,
                Some(transmute(
                    notify_dhcp_client_id_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(any(feature = "v1_2", feature = "dox"))]
    fn connect_property_dhcp_fqdn_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_dhcp_fqdn_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut nm_sys::NMSettingIP4Config,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<SettingIP4Config>,
        {
            let f: &F = &*(f as *const F);
            f(&SettingIP4Config::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::dhcp-fqdn\0".as_ptr() as *const _,
                Some(transmute(notify_dhcp_fqdn_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for SettingIP4Config {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "SettingIP4Config")
    }
}
