// 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_sys;
use light_dm_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib_wrapper! {
    pub struct Session(Object<light_dm_sys::LightDMSession, light_dm_sys::LightDMSessionClass, SessionClass>);

    match fn {
        get_type => || light_dm_sys::lightdm_session_get_type(),
    }
}

pub const NONE_SESSION: Option<&Session> = None;

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

    fn get_key(&self) -> Option<GString>;

    fn get_name(&self) -> Option<GString>;

    fn get_session_type(&self) -> Option<GString>;

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

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

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

impl<O: IsA<Session>> SessionExt for O {
    fn get_comment(&self) -> Option<GString> {
        unsafe {
            from_glib_none(light_dm_sys::lightdm_session_get_comment(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_key(&self) -> Option<GString> {
        unsafe {
            from_glib_none(light_dm_sys::lightdm_session_get_key(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_name(&self) -> Option<GString> {
        unsafe {
            from_glib_none(light_dm_sys::lightdm_session_get_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_session_type(&self) -> Option<GString> {
        unsafe {
            from_glib_none(light_dm_sys::lightdm_session_get_session_type(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn connect_property_comment_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_comment_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut light_dm_sys::LightDMSession,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Session>,
        {
            let f: &F = &*(f as *const F);
            f(&Session::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::comment\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_comment_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_key_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_key_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut light_dm_sys::LightDMSession,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Session>,
        {
            let f: &F = &*(f as *const F);
            f(&Session::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::key\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_key_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_property_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_name_trampoline<P, F: Fn(&P) + 'static>(
            this: *mut light_dm_sys::LightDMSession,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Session>,
        {
            let f: &F = &*(f as *const F);
            f(&Session::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::name\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_name_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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