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; 7 use glib::object::Cast; 8 use glib::object::IsA; 9 use glib::signal::connect_raw; 10 use glib::signal::SignalHandlerId; 11 use glib::translate::*; 12 use glib::GString; 13 use glib::StaticType; 14 use glib::ToValue; 15 use glib::Value; 16 use glib_sys; 17 use gobject_sys; 18 use std::boxed::Box as Box_; 19 use std::fmt; 20 use std::mem::transmute; 21 use std::ptr; 22 use Converter; 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, glib::Error>33 pub fn new(to_charset: &str, from_charset: &str) -> Result<CharsetConverter, glib::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 #[derive(Clone, Default)] 51 pub struct CharsetConverterBuilder { 52 from_charset: Option<String>, 53 to_charset: Option<String>, 54 use_fallback: Option<bool>, 55 } 56 57 impl CharsetConverterBuilder { new() -> Self58 pub fn new() -> Self { 59 Self::default() 60 } 61 build(self) -> CharsetConverter62 pub fn build(self) -> CharsetConverter { 63 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 64 if let Some(ref from_charset) = self.from_charset { 65 properties.push(("from-charset", from_charset)); 66 } 67 if let Some(ref to_charset) = self.to_charset { 68 properties.push(("to-charset", to_charset)); 69 } 70 if let Some(ref use_fallback) = self.use_fallback { 71 properties.push(("use-fallback", use_fallback)); 72 } 73 glib::Object::new(CharsetConverter::static_type(), &properties) 74 .expect("object new") 75 .downcast() 76 .expect("downcast") 77 } 78 from_charset(mut self, from_charset: &str) -> Self79 pub fn from_charset(mut self, from_charset: &str) -> Self { 80 self.from_charset = Some(from_charset.to_string()); 81 self 82 } 83 to_charset(mut self, to_charset: &str) -> Self84 pub fn to_charset(mut self, to_charset: &str) -> Self { 85 self.to_charset = Some(to_charset.to_string()); 86 self 87 } 88 use_fallback(mut self, use_fallback: bool) -> Self89 pub fn use_fallback(mut self, use_fallback: bool) -> Self { 90 self.use_fallback = Some(use_fallback); 91 self 92 } 93 } 94 95 pub const NONE_CHARSET_CONVERTER: Option<&CharsetConverter> = None; 96 97 pub trait CharsetConverterExt: 'static { get_num_fallbacks(&self) -> u3298 fn get_num_fallbacks(&self) -> u32; 99 get_use_fallback(&self) -> bool100 fn get_use_fallback(&self) -> bool; 101 set_use_fallback(&self, use_fallback: bool)102 fn set_use_fallback(&self, use_fallback: bool); 103 get_property_from_charset(&self) -> Option<GString>104 fn get_property_from_charset(&self) -> Option<GString>; 105 get_property_to_charset(&self) -> Option<GString>106 fn get_property_to_charset(&self) -> Option<GString>; 107 connect_property_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId108 fn connect_property_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) 109 -> SignalHandlerId; 110 } 111 112 impl<O: IsA<CharsetConverter>> CharsetConverterExt for O { get_num_fallbacks(&self) -> u32113 fn get_num_fallbacks(&self) -> u32 { 114 unsafe { gio_sys::g_charset_converter_get_num_fallbacks(self.as_ref().to_glib_none().0) } 115 } 116 get_use_fallback(&self) -> bool117 fn get_use_fallback(&self) -> bool { 118 unsafe { 119 from_glib(gio_sys::g_charset_converter_get_use_fallback( 120 self.as_ref().to_glib_none().0, 121 )) 122 } 123 } 124 set_use_fallback(&self, use_fallback: bool)125 fn set_use_fallback(&self, use_fallback: bool) { 126 unsafe { 127 gio_sys::g_charset_converter_set_use_fallback( 128 self.as_ref().to_glib_none().0, 129 use_fallback.to_glib(), 130 ); 131 } 132 } 133 get_property_from_charset(&self) -> Option<GString>134 fn get_property_from_charset(&self) -> Option<GString> { 135 unsafe { 136 let mut value = Value::from_type(<GString as StaticType>::static_type()); 137 gobject_sys::g_object_get_property( 138 self.to_glib_none().0 as *mut gobject_sys::GObject, 139 b"from-charset\0".as_ptr() as *const _, 140 value.to_glib_none_mut().0, 141 ); 142 value 143 .get() 144 .expect("Return Value for property `from-charset` getter") 145 } 146 } 147 get_property_to_charset(&self) -> Option<GString>148 fn get_property_to_charset(&self) -> Option<GString> { 149 unsafe { 150 let mut value = Value::from_type(<GString as StaticType>::static_type()); 151 gobject_sys::g_object_get_property( 152 self.to_glib_none().0 as *mut gobject_sys::GObject, 153 b"to-charset\0".as_ptr() as *const _, 154 value.to_glib_none_mut().0, 155 ); 156 value 157 .get() 158 .expect("Return Value for property `to-charset` getter") 159 } 160 } 161 connect_property_use_fallback_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId162 fn connect_property_use_fallback_notify<F: Fn(&Self) + 'static>( 163 &self, 164 f: F, 165 ) -> SignalHandlerId { 166 unsafe extern "C" fn notify_use_fallback_trampoline<P, F: Fn(&P) + 'static>( 167 this: *mut gio_sys::GCharsetConverter, 168 _param_spec: glib_sys::gpointer, 169 f: glib_sys::gpointer, 170 ) where 171 P: IsA<CharsetConverter>, 172 { 173 let f: &F = &*(f as *const F); 174 f(&CharsetConverter::from_glib_borrow(this).unsafe_cast()) 175 } 176 unsafe { 177 let f: Box_<F> = Box_::new(f); 178 connect_raw( 179 self.as_ptr() as *mut _, 180 b"notify::use-fallback\0".as_ptr() as *const _, 181 Some(transmute( 182 notify_use_fallback_trampoline::<Self, F> as usize, 183 )), 184 Box_::into_raw(f), 185 ) 186 } 187 } 188 } 189 190 impl fmt::Display for CharsetConverter { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result191 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 192 write!(f, "CharsetConverter") 193 } 194 } 195