gio/auto/
zlib_compressor.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Converter, FileInfo, ZlibCompressorFormat};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// `GZlibCompressor` is an implementation of [`Converter`][crate::Converter] that
15    /// compresses data using zlib.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `file-info`
21    ///  If set to a non-[`None`] #GFileInfo object, and #GZlibCompressor:format is
22    /// [`ZlibCompressorFormat::Gzip`][crate::ZlibCompressorFormat::Gzip], the compressor will write the file name
23    /// and modification time from the file info to the GZIP header.
24    ///
25    /// Readable | Writeable
26    ///
27    ///
28    /// #### `format`
29    ///  The format of the compressed data.
30    ///
31    /// Readable | Writeable | Construct Only
32    ///
33    ///
34    /// #### `level`
35    ///  The level of compression from `0` (no compression) to `9` (most
36    /// compression). `-1` for the default level.
37    ///
38    /// Readable | Writeable | Construct Only
39    ///
40    /// # Implements
41    ///
42    /// [`trait@glib::ObjectExt`], [`ConverterExt`][trait@crate::prelude::ConverterExt], [`ConverterExtManual`][trait@crate::prelude::ConverterExtManual]
43    #[doc(alias = "GZlibCompressor")]
44    pub struct ZlibCompressor(Object<ffi::GZlibCompressor, ffi::GZlibCompressorClass>) @implements Converter;
45
46    match fn {
47        type_ => || ffi::g_zlib_compressor_get_type(),
48    }
49}
50
51impl ZlibCompressor {
52    /// Creates a new #GZlibCompressor.
53    /// ## `format`
54    /// The format to use for the compressed data
55    /// ## `level`
56    /// compression level (0-9), -1 for default
57    ///
58    /// # Returns
59    ///
60    /// a new #GZlibCompressor
61    #[doc(alias = "g_zlib_compressor_new")]
62    pub fn new(format: ZlibCompressorFormat, level: i32) -> ZlibCompressor {
63        unsafe { from_glib_full(ffi::g_zlib_compressor_new(format.into_glib(), level)) }
64    }
65
66    /// Returns the #GZlibCompressor:file-info property.
67    ///
68    /// # Returns
69    ///
70    /// a #GFileInfo, or [`None`]
71    #[doc(alias = "g_zlib_compressor_get_file_info")]
72    #[doc(alias = "get_file_info")]
73    #[doc(alias = "file-info")]
74    pub fn file_info(&self) -> Option<FileInfo> {
75        unsafe { from_glib_none(ffi::g_zlib_compressor_get_file_info(self.to_glib_none().0)) }
76    }
77
78    /// Sets @file_info in @self. If non-[`None`], and @self's
79    /// #GZlibCompressor:format property is [`ZlibCompressorFormat::Gzip`][crate::ZlibCompressorFormat::Gzip],
80    /// it will be used to set the file name and modification time in
81    /// the GZIP header of the compressed data.
82    ///
83    /// Note: it is an error to call this function while a compression is in
84    /// progress; it may only be called immediately after creation of @self,
85    /// or after resetting it with g_converter_reset().
86    /// ## `file_info`
87    /// a #GFileInfo
88    #[doc(alias = "g_zlib_compressor_set_file_info")]
89    #[doc(alias = "file-info")]
90    pub fn set_file_info(&self, file_info: Option<&FileInfo>) {
91        unsafe {
92            ffi::g_zlib_compressor_set_file_info(self.to_glib_none().0, file_info.to_glib_none().0);
93        }
94    }
95
96    /// The format of the compressed data.
97    pub fn format(&self) -> ZlibCompressorFormat {
98        ObjectExt::property(self, "format")
99    }
100
101    /// The level of compression from `0` (no compression) to `9` (most
102    /// compression). `-1` for the default level.
103    pub fn level(&self) -> i32 {
104        ObjectExt::property(self, "level")
105    }
106
107    #[doc(alias = "file-info")]
108    pub fn connect_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
109        unsafe extern "C" fn notify_file_info_trampoline<F: Fn(&ZlibCompressor) + 'static>(
110            this: *mut ffi::GZlibCompressor,
111            _param_spec: glib::ffi::gpointer,
112            f: glib::ffi::gpointer,
113        ) {
114            let f: &F = &*(f as *const F);
115            f(&from_glib_borrow(this))
116        }
117        unsafe {
118            let f: Box_<F> = Box_::new(f);
119            connect_raw(
120                self.as_ptr() as *mut _,
121                b"notify::file-info\0".as_ptr() as *const _,
122                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
123                    notify_file_info_trampoline::<F> as *const (),
124                )),
125                Box_::into_raw(f),
126            )
127        }
128    }
129}