use crate::{Contextual, Disc, Object, ParserInfo, Stream, ffi};
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "MirageParser")]
pub struct Parser(Object<ffi::MirageParser, ffi::MirageParserClass>) @extends Object, @implements Contextual;
match fn {
type_ => || ffi::mirage_parser_get_type(),
}
}
impl Parser {
pub const NONE: Option<&'static Parser> = None;
}
pub trait ParserExt: IsA<Parser> + 'static {
#[doc(alias = "mirage_parser_add_redbook_pregap")]
fn add_redbook_pregap(&self, disc: &impl IsA<Disc>) {
unsafe {
ffi::mirage_parser_add_redbook_pregap(
self.as_ref().to_glib_none().0,
disc.as_ref().to_glib_none().0,
);
}
}
#[doc(alias = "mirage_parser_create_text_stream")]
fn create_text_stream(
&self,
stream: impl IsA<Stream>,
) -> Result<gio::DataInputStream, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::mirage_parser_create_text_stream(
self.as_ref().to_glib_none().0,
stream.upcast().into_glib_ptr(),
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "mirage_parser_get_info")]
#[doc(alias = "get_info")]
fn info(&self) -> Option<ParserInfo> {
unsafe { from_glib_none(ffi::mirage_parser_get_info(self.as_ref().to_glib_none().0)) }
}
#[doc(alias = "mirage_parser_guess_medium_type")]
fn guess_medium_type(&self, disc: &impl IsA<Disc>) -> i32 {
unsafe {
ffi::mirage_parser_guess_medium_type(
self.as_ref().to_glib_none().0,
disc.as_ref().to_glib_none().0,
)
}
}
#[doc(alias = "mirage_parser_load_image")]
fn load_image(&self, streams: &[Stream]) -> Result<Disc, glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::mirage_parser_load_image(
self.as_ref().to_glib_none().0,
streams.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}
}
impl<O: IsA<Parser>> ParserExt for O {}