use crate::{Buffer, CompressionType, Encoding, File, NewlineType, ffi};
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
use glib::signal::{SignalHandlerId, connect_raw};
use glib::{prelude::*, translate::*};
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
use std::boxed::Box as Box_;
glib::wrapper! {
#[doc(alias = "GtkSourceFileLoader")]
pub struct FileLoader(Object<ffi::GtkSourceFileLoader, ffi::GtkSourceFileLoaderClass>);
match fn {
type_ => || ffi::gtk_source_file_loader_get_type(),
}
}
impl FileLoader {
#[doc(alias = "gtk_source_file_loader_new")]
pub fn new(buffer: &impl IsA<Buffer>, file: &impl IsA<File>) -> FileLoader {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::gtk_source_file_loader_new(
buffer.as_ref().to_glib_none().0,
file.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_file_loader_new_from_stream")]
#[doc(alias = "new_from_stream")]
pub fn from_stream(
buffer: &impl IsA<Buffer>,
file: &impl IsA<File>,
stream: &impl IsA<gio::InputStream>,
) -> FileLoader {
skip_assert_initialized!();
unsafe {
from_glib_full(ffi::gtk_source_file_loader_new_from_stream(
buffer.as_ref().to_glib_none().0,
file.as_ref().to_glib_none().0,
stream.as_ref().to_glib_none().0,
))
}
}
pub fn builder() -> FileLoaderBuilder {
FileLoaderBuilder::new()
}
#[doc(alias = "gtk_source_file_loader_get_buffer")]
#[doc(alias = "get_buffer")]
pub fn buffer(&self) -> Buffer {
unsafe {
from_glib_none(ffi::gtk_source_file_loader_get_buffer(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_file_loader_get_compression_type")]
#[doc(alias = "get_compression_type")]
pub fn compression_type(&self) -> CompressionType {
unsafe {
from_glib(ffi::gtk_source_file_loader_get_compression_type(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_file_loader_get_encoding")]
#[doc(alias = "get_encoding")]
pub fn encoding(&self) -> Encoding {
unsafe {
from_glib_none(ffi::gtk_source_file_loader_get_encoding(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_file_loader_get_file")]
#[doc(alias = "get_file")]
pub fn file(&self) -> File {
unsafe { from_glib_none(ffi::gtk_source_file_loader_get_file(self.to_glib_none().0)) }
}
#[doc(alias = "gtk_source_file_loader_get_input_stream")]
#[doc(alias = "get_input_stream")]
#[doc(alias = "input-stream")]
pub fn input_stream(&self) -> Option<gio::InputStream> {
unsafe {
from_glib_none(ffi::gtk_source_file_loader_get_input_stream(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gtk_source_file_loader_get_location")]
#[doc(alias = "get_location")]
pub fn location(&self) -> Option<gio::File> {
unsafe {
from_glib_none(ffi::gtk_source_file_loader_get_location(
self.to_glib_none().0,
))
}
}
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
#[doc(alias = "gtk_source_file_loader_get_max_size")]
#[doc(alias = "get_max_size")]
#[doc(alias = "max-size")]
pub fn max_size(&self) -> u64 {
unsafe { ffi::gtk_source_file_loader_get_max_size(self.to_glib_none().0) }
}
#[doc(alias = "gtk_source_file_loader_get_newline_type")]
#[doc(alias = "get_newline_type")]
pub fn newline_type(&self) -> NewlineType {
unsafe {
from_glib(ffi::gtk_source_file_loader_get_newline_type(
self.to_glib_none().0,
))
}
}
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
#[doc(alias = "gtk_source_file_loader_set_max_size")]
#[doc(alias = "max-size")]
pub fn set_max_size(&self, max_size: u64) {
unsafe {
ffi::gtk_source_file_loader_set_max_size(self.to_glib_none().0, max_size);
}
}
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
#[doc(alias = "max-size")]
pub fn connect_max_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_max_size_trampoline<F: Fn(&FileLoader) + 'static>(
this: *mut ffi::GtkSourceFileLoader,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
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 _,
c"notify::max-size".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_max_size_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for FileLoader {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
#[must_use = "The builder must be built to be used"]
pub struct FileLoaderBuilder {
builder: glib::object::ObjectBuilder<'static, FileLoader>,
}
impl FileLoaderBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn buffer(self, buffer: &impl IsA<Buffer>) -> Self {
Self {
builder: self.builder.property("buffer", buffer.clone().upcast()),
}
}
pub fn file(self, file: &impl IsA<File>) -> Self {
Self {
builder: self.builder.property("file", file.clone().upcast()),
}
}
pub fn input_stream(self, input_stream: &impl IsA<gio::InputStream>) -> Self {
Self {
builder: self
.builder
.property("input-stream", input_stream.clone().upcast()),
}
}
pub fn location(self, location: &impl IsA<gio::File>) -> Self {
Self {
builder: self.builder.property("location", location.clone().upcast()),
}
}
#[cfg(feature = "v5_22")]
#[cfg_attr(docsrs, doc(cfg(feature = "v5_22")))]
pub fn max_size(self, max_size: u64) -> Self {
Self {
builder: self.builder.property("max-size", max_size),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> FileLoader {
assert_initialized_main_thread!();
self.builder.build()
}
}