use crate::{Context, Stream, ffi};
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "MirageContextual")]
pub struct Contextual(Interface<ffi::MirageContextual, ffi::MirageContextualInterface>);
match fn {
type_ => || ffi::mirage_contextual_get_type(),
}
}
impl Contextual {
pub const NONE: Option<&'static Contextual> = None;
}
pub trait ContextualExt: IsA<Contextual> + 'static {
#[doc(alias = "mirage_contextual_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_contextual_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_contextual_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_contextual_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_contextual_debug_is_active")]
fn debug_is_active(&self, level: i32) -> bool {
unsafe {
from_glib(ffi::mirage_contextual_debug_is_active(
self.as_ref().to_glib_none().0,
level,
))
}
}
#[doc(alias = "mirage_contextual_debug_print_buffer")]
fn debug_print_buffer(&self, level: i32, prefix: Option<&str>, width: i32, buffer: &[u8]) {
let buffer_length = buffer.len() as _;
unsafe {
ffi::mirage_contextual_debug_print_buffer(
self.as_ref().to_glib_none().0,
level,
prefix.to_glib_none().0,
width,
buffer.to_glib_none().0,
buffer_length,
);
}
}
#[doc(alias = "mirage_contextual_get_context")]
#[doc(alias = "get_context")]
fn context(&self) -> Option<Context> {
unsafe {
from_glib_full(ffi::mirage_contextual_get_context(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "mirage_contextual_get_option")]
#[doc(alias = "get_option")]
fn option(&self, name: &str) -> Option<glib::Variant> {
unsafe {
from_glib_full(ffi::mirage_contextual_get_option(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
))
}
}
#[cfg(feature = "v3_3_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v3_3_2")))]
#[doc(alias = "mirage_contextual_inherit_context")]
fn inherit_context(&self, other: &impl IsA<Contextual>) {
unsafe {
ffi::mirage_contextual_inherit_context(
self.as_ref().to_glib_none().0,
other.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "mirage_contextual_obtain_password")]
fn obtain_password(&self) -> Result<glib::GString, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret =
ffi::mirage_contextual_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_contextual_set_context")]
fn set_context(&self, context: impl IsA<Context>) {
unsafe {
ffi::mirage_contextual_set_context(
self.as_ref().to_glib_none().0,
context.upcast().into_glib_ptr(),
);
}
}
}
impl<O: IsA<Contextual>> ContextualExt for O {}