spice-client-glib 0.1.0

Rust bindings for the Spice client library
// 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::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    #[doc(alias = "SpiceURI")]
    pub struct URI(Object<ffi::SpiceURI, ffi::SpiceURIClass>);

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

impl URI {
    #[doc(alias = "spice_uri_get_hostname")]
    #[doc(alias = "get_hostname")]
    pub fn hostname(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::spice_uri_get_hostname(self.to_glib_none().0)) }
    }

    #[doc(alias = "spice_uri_get_password")]
    #[doc(alias = "get_password")]
    pub fn password(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::spice_uri_get_password(self.to_glib_none().0)) }
    }

    #[doc(alias = "spice_uri_get_port")]
    #[doc(alias = "get_port")]
    pub fn port(&self) -> u32 {
        unsafe { ffi::spice_uri_get_port(self.to_glib_none().0) }
    }

    #[doc(alias = "spice_uri_get_scheme")]
    #[doc(alias = "get_scheme")]
    pub fn scheme(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::spice_uri_get_scheme(self.to_glib_none().0)) }
    }

    #[doc(alias = "spice_uri_get_user")]
    #[doc(alias = "get_user")]
    pub fn user(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::spice_uri_get_user(self.to_glib_none().0)) }
    }

    #[doc(alias = "spice_uri_set_hostname")]
    pub fn set_hostname(&self, hostname: &str) {
        unsafe {
            ffi::spice_uri_set_hostname(self.to_glib_none().0, hostname.to_glib_none().0);
        }
    }

    #[doc(alias = "spice_uri_set_password")]
    pub fn set_password(&self, password: &str) {
        unsafe {
            ffi::spice_uri_set_password(self.to_glib_none().0, password.to_glib_none().0);
        }
    }

    #[doc(alias = "spice_uri_set_port")]
    pub fn set_port(&self, port: u32) {
        unsafe {
            ffi::spice_uri_set_port(self.to_glib_none().0, port);
        }
    }

    #[doc(alias = "spice_uri_set_scheme")]
    pub fn set_scheme(&self, scheme: &str) {
        unsafe {
            ffi::spice_uri_set_scheme(self.to_glib_none().0, scheme.to_glib_none().0);
        }
    }

    #[doc(alias = "spice_uri_set_user")]
    pub fn set_user(&self, user: &str) {
        unsafe {
            ffi::spice_uri_set_user(self.to_glib_none().0, user.to_glib_none().0);
        }
    }

    #[doc(alias = "spice_uri_to_string")]
    #[doc(alias = "to_string")]
    pub fn to_str(&self) -> glib::GString {
        unsafe { from_glib_full(ffi::spice_uri_to_string(self.to_glib_none().0)) }
    }

    #[doc(alias = "hostname")]
    pub fn connect_hostname_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_hostname_trampoline<F: Fn(&URI) + 'static>(
            this: *mut ffi::SpiceURI,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::hostname\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_hostname_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "password")]
    pub fn connect_password_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_password_trampoline<F: Fn(&URI) + 'static>(
            this: *mut ffi::SpiceURI,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::password\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_password_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "port")]
    pub fn connect_port_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_port_trampoline<F: Fn(&URI) + 'static>(
            this: *mut ffi::SpiceURI,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::port\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_port_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "scheme")]
    pub fn connect_scheme_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_scheme_trampoline<F: Fn(&URI) + 'static>(
            this: *mut ffi::SpiceURI,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::scheme\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_scheme_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "user")]
    pub fn connect_user_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_user_trampoline<F: Fn(&URI) + 'static>(
            this: *mut ffi::SpiceURI,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::user\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_user_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for URI {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(&self.to_str())
    }
}