gio/auto/
zlib_compressor.rs1use crate::{Converter, FileInfo, ZlibCompressorFormat, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GZlibCompressor")]
15 pub struct ZlibCompressor(Object<ffi::GZlibCompressor, ffi::GZlibCompressorClass>) @implements Converter;
16
17 match fn {
18 type_ => || ffi::g_zlib_compressor_get_type(),
19 }
20}
21
22impl ZlibCompressor {
23 #[doc(alias = "g_zlib_compressor_new")]
24 pub fn new(format: ZlibCompressorFormat, level: i32) -> ZlibCompressor {
25 unsafe { from_glib_full(ffi::g_zlib_compressor_new(format.into_glib(), level)) }
26 }
27
28 #[doc(alias = "g_zlib_compressor_get_file_info")]
29 #[doc(alias = "get_file_info")]
30 #[doc(alias = "file-info")]
31 pub fn file_info(&self) -> Option<FileInfo> {
32 unsafe { from_glib_none(ffi::g_zlib_compressor_get_file_info(self.to_glib_none().0)) }
33 }
34
35 #[cfg(feature = "v2_86")]
36 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
37 #[doc(alias = "g_zlib_compressor_get_os")]
38 #[doc(alias = "get_os")]
39 pub fn os(&self) -> i32 {
40 unsafe { ffi::g_zlib_compressor_get_os(self.to_glib_none().0) }
41 }
42
43 #[doc(alias = "g_zlib_compressor_set_file_info")]
44 #[doc(alias = "file-info")]
45 pub fn set_file_info(&self, file_info: Option<&FileInfo>) {
46 unsafe {
47 ffi::g_zlib_compressor_set_file_info(self.to_glib_none().0, file_info.to_glib_none().0);
48 }
49 }
50
51 #[cfg(feature = "v2_86")]
52 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
53 #[doc(alias = "g_zlib_compressor_set_os")]
54 #[doc(alias = "os")]
55 pub fn set_os(&self, os: i32) {
56 unsafe {
57 ffi::g_zlib_compressor_set_os(self.to_glib_none().0, os);
58 }
59 }
60
61 pub fn format(&self) -> ZlibCompressorFormat {
62 ObjectExt::property(self, "format")
63 }
64
65 pub fn level(&self) -> i32 {
66 ObjectExt::property(self, "level")
67 }
68
69 #[doc(alias = "file-info")]
70 pub fn connect_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
71 unsafe extern "C" fn notify_file_info_trampoline<F: Fn(&ZlibCompressor) + 'static>(
72 this: *mut ffi::GZlibCompressor,
73 _param_spec: glib::ffi::gpointer,
74 f: glib::ffi::gpointer,
75 ) {
76 unsafe {
77 let f: &F = &*(f as *const F);
78 f(&from_glib_borrow(this))
79 }
80 }
81 unsafe {
82 let f: Box_<F> = Box_::new(f);
83 connect_raw(
84 self.as_ptr() as *mut _,
85 c"notify::file-info".as_ptr(),
86 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
87 notify_file_info_trampoline::<F> as *const (),
88 )),
89 Box_::into_raw(f),
90 )
91 }
92 }
93
94 #[cfg(feature = "v2_86")]
95 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
96 #[doc(alias = "os")]
97 pub fn connect_os_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
98 unsafe extern "C" fn notify_os_trampoline<F: Fn(&ZlibCompressor) + 'static>(
99 this: *mut ffi::GZlibCompressor,
100 _param_spec: glib::ffi::gpointer,
101 f: glib::ffi::gpointer,
102 ) {
103 unsafe {
104 let f: &F = &*(f as *const F);
105 f(&from_glib_borrow(this))
106 }
107 }
108 unsafe {
109 let f: Box_<F> = Box_::new(f);
110 connect_raw(
111 self.as_ptr() as *mut _,
112 c"notify::os".as_ptr(),
113 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
114 notify_os_trampoline::<F> as *const (),
115 )),
116 Box_::into_raw(f),
117 )
118 }
119 }
120}