// 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::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use light_dm_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;
use User;

glib_wrapper! {
    pub struct UserList(Object<light_dm_sys::LightDMUserList, light_dm_sys::LightDMUserListClass, UserListClass>);

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

impl UserList {
    pub fn get_instance() -> Option<UserList> {
        unsafe { from_glib_none(light_dm_sys::lightdm_user_list_get_instance()) }
    }
}

pub const NONE_USER_LIST: Option<&UserList> = None;

pub trait UserListExt: 'static {
    fn get_length(&self) -> i32;

    fn get_user_by_name(&self, username: &str) -> Option<User>;

    fn get_users(&self) -> Vec<User>;

    fn get_property_num_users(&self) -> i32;

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

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

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

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

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

impl<O: IsA<UserList>> UserListExt for O {
    fn get_length(&self) -> i32 {
        unsafe { light_dm_sys::lightdm_user_list_get_length(self.as_ref().to_glib_none().0) }
    }

    fn get_user_by_name(&self, username: &str) -> Option<User> {
        unsafe {
            from_glib_none(light_dm_sys::lightdm_user_list_get_user_by_name(
                self.as_ref().to_glib_none().0,
                username.to_glib_none().0,
            ))
        }
    }

    fn get_users(&self) -> Vec<User> {
        unsafe {
            FromGlibPtrContainer::from_glib_none(light_dm_sys::lightdm_user_list_get_users(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn get_property_num_users(&self) -> i32 {
        unsafe {
            let mut value = Value::from_type(<i32 as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.to_glib_none().0 as *mut gobject_sys::GObject,
                b"num-users\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `num-users` getter")
                .unwrap()
        }
    }

    fn connect_user_added<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn user_added_trampoline<P, F: Fn(&P, &User) + 'static>(
            this: *mut light_dm_sys::LightDMUserList,
            user: *mut light_dm_sys::LightDMUser,
            f: glib_sys::gpointer,
        ) where
            P: IsA<UserList>,
        {
            let f: &F = &*(f as *const F);
            f(
                &UserList::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(user),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"user-added\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    user_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_user_changed<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn user_changed_trampoline<P, F: Fn(&P, &User) + 'static>(
            this: *mut light_dm_sys::LightDMUserList,
            user: *mut light_dm_sys::LightDMUser,
            f: glib_sys::gpointer,
        ) where
            P: IsA<UserList>,
        {
            let f: &F = &*(f as *const F);
            f(
                &UserList::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(user),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"user-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    user_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_user_removed<F: Fn(&Self, &User) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn user_removed_trampoline<P, F: Fn(&P, &User) + 'static>(
            this: *mut light_dm_sys::LightDMUserList,
            user: *mut light_dm_sys::LightDMUser,
            f: glib_sys::gpointer,
        ) where
            P: IsA<UserList>,
        {
            let f: &F = &*(f as *const F);
            f(
                &UserList::from_glib_borrow(this).unsafe_cast_ref(),
                &from_glib_borrow(user),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"user-removed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    user_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

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

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

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