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 
5 use gio_sys;
6 use glib::object::Cast;
7 use glib::object::IsA;
8 use glib::signal::connect_raw;
9 use glib::signal::SignalHandlerId;
10 use glib::translate::*;
11 use glib::GString;
12 use glib::StaticType;
13 use glib::ToValue;
14 use glib::Value;
15 use glib_sys;
16 use gobject_sys;
17 use std::boxed::Box as Box_;
18 use std::fmt;
19 use std::mem::transmute;
20 use std::ptr;
21 use Converter;
22 use Error;
23 
24 glib_wrapper! {
25     pub struct CharsetConverter(Object<gio_sys::GCharsetConverter, gio_sys::GCharsetConverterClass, CharsetConverterClass>) @implements Converter;
26 
27     match fn {
28         get_type => || gio_sys::g_charset_converter_get_type(),
29     }
30 }
31 
32 impl CharsetConverter {
new(to_charset: &str, from_charset: &str) -> Result<CharsetConverter, Error>33     pub fn new(to_charset: &str, from_charset: &str) -> Result<CharsetConverter, Error> {
34         unsafe {
35             let mut error = ptr::null_mut();
36             let ret = gio_sys::g_charset_converter_new(
37                 to_charset.to_glib_none().0,
38                 from_charset.to_glib_none().0,
39                 &mut error,
40             );
41             if error.is_null() {
42                 Ok(from_glib_full(ret))
43             } else {
44                 Err(from_glib_full(error))
45             }
46         }
47     }
48 }
49 
50 pub struct CharsetConverterBuilder {
51     from_charset: Option<String>,
52     to_charset: Option<String>,
53     use_fallback: Option<bool>,
54 }
55 
56 impl CharsetConverterBuilder {
new() -> Self57     pub fn new() -> Self {
58         Self {
59             from_charset: None,
60             to_charset: None,
61             use_fallback: None,
62         }
63     }
64 
build(self) -> CharsetConverter65     pub fn build(self) -> CharsetConverter {
66         let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
67         if let Some(ref from_charset) = self.from_charset {
68             properties.push(("from-charset", from_charset));
69         }
70         if let Some(ref to_charset) = self.to_charset {
71             properties.push(("to-charset", to_charset));
72         }
73         if let Some(ref use_fallback) = self.use_fallback {
74             properties.push(("use-fallback", use_fallback));
75         }
76         glib::Object::new(CharsetConverter::static_type(), &properties)
77             .expect("object new")
78             .downcast()
79             .expect("downcast")
80     }
81 
from_charset(mut self, from_charset: &str) -> Self82     pub fn from_charset(mut self, from_charset: &str) -> Self {
83         self.from_charset = Some(from_charset.to_string());
84         self
85     }
86 
to_charset(mut self, to_charset: &str) -> Self87     pub fn to_charset(mut self, to_charset: &str) -> Self {
88         self.to_charset = Some(to_charset.to_string());
89         self
90     }
91 
use_fallback(mut self, use_fallback: bool) -> Self92     pub fn use_fallback(mut self, use_fallback: bool) -> Self {
93         self.use_fallback = Some(use_fallback);
94         self
95     }
96 }
97 
98 pub const NONE_CHARSET_CONVERTER: Option<&CharsetConverter> = None;
99 
100 pub trait CharsetConverterExt: 'static {
get_num_fallbacks(&self) -> u32101     fn get_num_fallbacks(&self) -> u32;
102 
get_use_fallback(&self) -> bool103     fn get_use_fallback(&self) -> bool;
104 
set_use_fallback(&self, use_fallback: bool)105     fn set_use_fallback(&self, use_fallback: bool);
106 
get_property_from_charset(&self) -> Option<GString>107     fn get_property_from_charset(&self) -> Option<GString>;
108 
get_property_to_charset(&self) -> Option<GString>109     fn get_property_to_charset(&self) -> Option<GString>;
110 
connect_property_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId111     fn connect_property_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F)
112         -> SignalHandlerId;
113 }
114 
115 impl<O: IsA<CharsetConverter>> CharsetConverterExt for O {
get_num_fallbacks(&self) -> u32116     fn get_num_fallbacks(&self) -> u32 {
117         unsafe { gio_sys::g_charset_converter_get_num_fallbacks(self.as_ref().to_glib_none().0) }
118     }
119 
get_use_fallback(&self) -> bool120     fn get_use_fallback(&self) -> bool {
121         unsafe {
122             from_glib(gio_sys::g_charset_converter_get_use_fallback(
123                 self.as_ref().to_glib_none().0,
124             ))
125         }
126     }
127 
set_use_fallback(&self, use_fallback: bool)128     fn set_use_fallback(&self, use_fallback: bool) {
129         unsafe {
130             gio_sys::g_charset_converter_set_use_fallback(
131                 self.as_ref().to_glib_none().0,
132                 use_fallback.to_glib(),
133             );
134         }
135     }
136 
get_property_from_charset(&self) -> Option<GString>137     fn get_property_from_charset(&self) -> Option<GString> {
138         unsafe {
139             let mut value = Value::from_type(<GString as StaticType>::static_type());
140             gobject_sys::g_object_get_property(
141                 self.to_glib_none().0 as *mut gobject_sys::GObject,
142                 b"from-charset\0".as_ptr() as *const _,
143                 value.to_glib_none_mut().0,
144             );
145             value.get()
146         }
147     }
148 
get_property_to_charset(&self) -> Option<GString>149     fn get_property_to_charset(&self) -> Option<GString> {
150         unsafe {
151             let mut value = Value::from_type(<GString as StaticType>::static_type());
152             gobject_sys::g_object_get_property(
153                 self.to_glib_none().0 as *mut gobject_sys::GObject,
154                 b"to-charset\0".as_ptr() as *const _,
155                 value.to_glib_none_mut().0,
156             );
157             value.get()
158         }
159     }
160 
connect_property_use_fallback_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId161     fn connect_property_use_fallback_notify<F: Fn(&Self) + 'static>(
162         &self,
163         f: F,
164     ) -> SignalHandlerId {
165         unsafe extern "C" fn notify_use_fallback_trampoline<P, F: Fn(&P) + 'static>(
166             this: *mut gio_sys::GCharsetConverter,
167             _param_spec: glib_sys::gpointer,
168             f: glib_sys::gpointer,
169         ) where
170             P: IsA<CharsetConverter>,
171         {
172             let f: &F = &*(f as *const F);
173             f(&CharsetConverter::from_glib_borrow(this).unsafe_cast())
174         }
175         unsafe {
176             let f: Box_<F> = Box_::new(f);
177             connect_raw(
178                 self.as_ptr() as *mut _,
179                 b"notify::use-fallback\0".as_ptr() as *const _,
180                 Some(transmute(
181                     notify_use_fallback_trampoline::<Self, F> as usize,
182                 )),
183                 Box_::into_raw(f),
184             )
185         }
186     }
187 }
188 
189 impl fmt::Display for CharsetConverter {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result190     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
191         write!(f, "CharsetConverter")
192     }
193 }
194