gio/auto/
zlib_compressor.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 ZlibCompressor(Object<gio_sys::GZlibCompressor, gio_sys::GZlibCompressorClass, ZlibCompressorClass>) @implements Converter;
24
25 match fn {
26 get_type => || gio_sys::g_zlib_compressor_get_type(),
27 }
28}
29
30impl ZlibCompressor {
31 pub fn new(format: ZlibCompressorFormat, level: i32) -> ZlibCompressor {
32 unsafe { from_glib_full(gio_sys::g_zlib_compressor_new(format.to_glib(), level)) }
33 }
34}
35
36pub const NONE_ZLIB_COMPRESSOR: Option<&ZlibCompressor> = None;
37
38pub trait ZlibCompressorExt: 'static {
39 fn get_file_info(&self) -> Option<FileInfo>;
40
41 fn set_file_info(&self, file_info: Option<&FileInfo>);
42
43 fn get_property_format(&self) -> ZlibCompressorFormat;
44
45 fn get_property_level(&self) -> i32;
46
47 fn connect_property_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
48}
49
50impl<O: IsA<ZlibCompressor>> ZlibCompressorExt for O {
51 fn get_file_info(&self) -> Option<FileInfo> {
52 unsafe {
53 from_glib_none(gio_sys::g_zlib_compressor_get_file_info(
54 self.as_ref().to_glib_none().0,
55 ))
56 }
57 }
58
59 fn set_file_info(&self, file_info: Option<&FileInfo>) {
60 unsafe {
61 gio_sys::g_zlib_compressor_set_file_info(
62 self.as_ref().to_glib_none().0,
63 file_info.to_glib_none().0,
64 );
65 }
66 }
67
68 fn get_property_format(&self) -> ZlibCompressorFormat {
69 unsafe {
70 let mut value = Value::from_type(<ZlibCompressorFormat as StaticType>::static_type());
71 gobject_sys::g_object_get_property(
72 self.to_glib_none().0 as *mut gobject_sys::GObject,
73 b"format\0".as_ptr() as *const _,
74 value.to_glib_none_mut().0,
75 );
76 value.get().unwrap()
77 }
78 }
79
80 fn get_property_level(&self) -> i32 {
81 unsafe {
82 let mut value = Value::from_type(<i32 as StaticType>::static_type());
83 gobject_sys::g_object_get_property(
84 self.to_glib_none().0 as *mut gobject_sys::GObject,
85 b"level\0".as_ptr() as *const _,
86 value.to_glib_none_mut().0,
87 );
88 value.get().unwrap()
89 }
90 }
91
92 fn connect_property_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
93 unsafe extern "C" fn notify_file_info_trampoline<P, F: Fn(&P) + 'static>(
94 this: *mut gio_sys::GZlibCompressor,
95 _param_spec: glib_sys::gpointer,
96 f: glib_sys::gpointer,
97 ) where
98 P: IsA<ZlibCompressor>,
99 {
100 let f: &F = &*(f as *const F);
101 f(&ZlibCompressor::from_glib_borrow(this).unsafe_cast())
102 }
103 unsafe {
104 let f: Box_<F> = Box_::new(f);
105 connect_raw(
106 self.as_ptr() as *mut _,
107 b"notify::file-info\0".as_ptr() as *const _,
108 Some(transmute(notify_file_info_trampoline::<Self, F> as usize)),
109 Box_::into_raw(f),
110 )
111 }
112 }
113}
114
115impl fmt::Display for ZlibCompressor {
116 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
117 write!(f, "ZlibCompressor")
118 }
119}