libmirage 0.1.1

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

use crate::{Disc, Stream, ffi};
use glib::{prelude::*, translate::*};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "MirageContext")]
    pub struct Context(Object<ffi::MirageContext, ffi::MirageContextClass>);

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

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

pub trait ContextExt: IsA<Context> + 'static {
    #[doc(alias = "mirage_context_clear_options")]
    fn clear_options(&self) {
        unsafe {
            ffi::mirage_context_clear_options(self.as_ref().to_glib_none().0);
        }
    }

    #[doc(alias = "mirage_context_create_input_stream")]
    fn create_input_stream(&self, filename: &str) -> Result<Stream, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::mirage_context_create_input_stream(
                self.as_ref().to_glib_none().0,
                filename.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "mirage_context_create_output_stream")]
    fn create_output_stream(
        &self,
        filename: &str,
        filter_chain: &[&str],
    ) -> Result<Stream, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::mirage_context_create_output_stream(
                self.as_ref().to_glib_none().0,
                filename.to_glib_none().0,
                filter_chain.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "mirage_context_get_debug_domain")]
    #[doc(alias = "get_debug_domain")]
    fn debug_domain(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::mirage_context_get_debug_domain(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "mirage_context_get_debug_mask")]
    #[doc(alias = "get_debug_mask")]
    fn debug_mask(&self) -> i32 {
        unsafe { ffi::mirage_context_get_debug_mask(self.as_ref().to_glib_none().0) }
    }

    #[doc(alias = "mirage_context_get_debug_name")]
    #[doc(alias = "get_debug_name")]
    fn debug_name(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::mirage_context_get_debug_name(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "mirage_context_get_option")]
    #[doc(alias = "get_option")]
    fn option(&self, name: &str) -> Option<glib::Variant> {
        unsafe {
            from_glib_full(ffi::mirage_context_get_option(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "mirage_context_load_image")]
    fn load_image(&self, filenames: &[&str]) -> Result<Disc, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret = ffi::mirage_context_load_image(
                self.as_ref().to_glib_none().0,
                filenames.to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "mirage_context_obtain_password")]
    fn obtain_password(&self) -> Result<glib::GString, glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let ret =
                ffi::mirage_context_obtain_password(self.as_ref().to_glib_none().0, &mut error);
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "mirage_context_set_debug_domain")]
    fn set_debug_domain(&self, domain: &str) {
        unsafe {
            ffi::mirage_context_set_debug_domain(
                self.as_ref().to_glib_none().0,
                domain.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "mirage_context_set_debug_mask")]
    fn set_debug_mask(&self, debug_mask: i32) {
        unsafe {
            ffi::mirage_context_set_debug_mask(self.as_ref().to_glib_none().0, debug_mask);
        }
    }

    #[doc(alias = "mirage_context_set_debug_name")]
    fn set_debug_name(&self, name: &str) {
        unsafe {
            ffi::mirage_context_set_debug_name(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "mirage_context_set_option")]
    fn set_option(&self, name: &str, value: glib::Variant) {
        unsafe {
            ffi::mirage_context_set_option(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                value.into_glib_ptr(),
            );
        }
    }

    #[doc(alias = "mirage_context_set_password_function")]
    fn set_password_function(&self, func: Option<Box_<dyn Fn() -> String + 'static>>) {
        let func_data: Box_<Option<Box_<dyn Fn() -> String + 'static>>> = Box_::new(func);
        unsafe extern "C" fn func_func(user_data: glib::ffi::gpointer) -> *mut std::ffi::c_char {
            unsafe {
                let callback = &*(user_data as *mut Option<Box_<dyn Fn() -> String + 'static>>);
                if let Some(ref callback) = *callback {
                    callback()
                } else {
                    panic!("cannot get closure...")
                }
                .to_glib_full()
            }
        }
        let func = if func_data.is_some() {
            Some(func_func as _)
        } else {
            None
        };
        unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
            unsafe {
                let _callback =
                    Box_::from_raw(data as *mut Option<Box_<dyn Fn() -> String + 'static>>);
            }
        }
        let destroy_call3 = Some(destroy_func as _);
        let super_callback0: Box_<Option<Box_<dyn Fn() -> String + 'static>>> = func_data;
        unsafe {
            ffi::mirage_context_set_password_function(
                self.as_ref().to_glib_none().0,
                func,
                Box_::into_raw(super_callback0) as *mut _,
                destroy_call3,
            );
        }
    }
}

impl<O: IsA<Context>> ContextExt for O {}