gio/auto/
zlib_decompressor.rs1use gio_sys;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::Value;
13use glib_sys;
14use gobject_sys;
15use std::boxed::Box as Box_;
16use std::fmt;
17use std::mem::transmute;
18use Converter;
19use FileInfo;
20use ZlibCompressorFormat;
21
22glib_wrapper! {
23 pub struct ZlibDecompressor(Object<gio_sys::GZlibDecompressor, gio_sys::GZlibDecompressorClass, ZlibDecompressorClass>) @implements Converter;
24
25 match fn {
26 get_type => || gio_sys::g_zlib_decompressor_get_type(),
27 }
28}
29
30impl ZlibDecompressor {
31 pub fn new(format: ZlibCompressorFormat) -> ZlibDecompressor {
32 unsafe { from_glib_full(gio_sys::g_zlib_decompressor_new(format.to_glib())) }
33 }
34}
35
36pub const NONE_ZLIB_DECOMPRESSOR: Option<&ZlibDecompressor> = None;
37
38pub trait ZlibDecompressorExt: 'static {
39 fn get_file_info(&self) -> Option<FileInfo>;
40
41 fn get_property_format(&self) -> ZlibCompressorFormat;
42
43 fn connect_property_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
44}
45
46impl<O: IsA<ZlibDecompressor>> ZlibDecompressorExt for O {
47 fn get_file_info(&self) -> Option<FileInfo> {
48 unsafe {
49 from_glib_none(gio_sys::g_zlib_decompressor_get_file_info(
50 self.as_ref().to_glib_none().0,
51 ))
52 }
53 }
54
55 fn get_property_format(&self) -> ZlibCompressorFormat {
56 unsafe {
57 let mut value = Value::from_type(<ZlibCompressorFormat as StaticType>::static_type());
58 gobject_sys::g_object_get_property(
59 self.to_glib_none().0 as *mut gobject_sys::GObject,
60 b"format\0".as_ptr() as *const _,
61 value.to_glib_none_mut().0,
62 );
63 value.get().unwrap()
64 }
65 }
66
67 fn connect_property_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
68 unsafe extern "C" fn notify_file_info_trampoline<P, F: Fn(&P) + 'static>(
69 this: *mut gio_sys::GZlibDecompressor,
70 _param_spec: glib_sys::gpointer,
71 f: glib_sys::gpointer,
72 ) where
73 P: IsA<ZlibDecompressor>,
74 {
75 let f: &F = &*(f as *const F);
76 f(&ZlibDecompressor::from_glib_borrow(this).unsafe_cast())
77 }
78 unsafe {
79 let f: Box_<F> = Box_::new(f);
80 connect_raw(
81 self.as_ptr() as *mut _,
82 b"notify::file-info\0".as_ptr() as *const _,
83 Some(transmute(notify_file_info_trampoline::<Self, F> as usize)),
84 Box_::into_raw(f),
85 )
86 }
87 }
88}
89
90impl fmt::Display for ZlibDecompressor {
91 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
92 write!(f, "ZlibDecompressor")
93 }
94}