nm_rs/auto/
setting_user.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi,Setting};
7use glib::{prelude::*,signal::{connect_raw, SignalHandlerId},translate::*};
8use std::{boxed::Box as Box_};
9
10glib::wrapper! {
11    /// General User Profile Settings
12    ///
13    /// ## Properties
14    ///
15    ///
16    /// #### `data`
17    ///  A dictionary of key/value pairs with user data. This data is ignored by NetworkManager
18    /// and can be used at the users discretion. The keys only support a strict ascii format,
19    /// but the values can be arbitrary UTF8 strings up to a certain length.
20    ///
21    /// Readable | Writeable
22    /// <details><summary><h4>Setting</h4></summary>
23    ///
24    ///
25    /// #### `name`
26    ///  The setting's name, which uniquely identifies the setting within the
27    /// connection.  Each setting type has a name unique to that type, for
28    /// example "ppp" or "802-11-wireless" or "802-3-ethernet".
29    ///
30    /// Readable
31    /// </details>
32    ///
33    /// # Implements
34    ///
35    /// [`SettingExt`][trait@crate::prelude::SettingExt]
36    #[doc(alias = "NMSettingUser")]
37    pub struct SettingUser(Object<ffi::NMSettingUser, ffi::NMSettingUserClass>) @extends Setting;
38
39    match fn {
40        type_ => || ffi::nm_setting_user_get_type(),
41    }
42}
43
44impl SettingUser {
45    /// Creates a new #NMSettingUser object with default values.
46    ///
47    /// # Returns
48    ///
49    /// the new empty #NMSettingUser object
50    #[doc(alias = "nm_setting_user_new")]
51    pub fn new() -> SettingUser {
52        assert_initialized_main_thread!();
53        unsafe {
54            Setting::from_glib_full(ffi::nm_setting_user_new()).unsafe_cast()
55        }
56    }
57
58            // rustdoc-stripper-ignore-next
59            /// Creates a new builder-pattern struct instance to construct [`SettingUser`] objects.
60            ///
61            /// This method returns an instance of [`SettingUserBuilder`](crate::builders::SettingUserBuilder) which can be used to create [`SettingUser`] objects.
62            pub fn builder() -> SettingUserBuilder {
63                SettingUserBuilder::new()
64            }
65        
66
67    /// ## `key`
68    /// the key to lookup
69    ///
70    /// # Returns
71    ///
72    /// the value associated with @key or [`None`] if no such
73    ///   value exists.
74    #[doc(alias = "nm_setting_user_get_data")]
75    #[doc(alias = "get_data")]
76    pub fn data(&self, key: &str) -> glib::GString {
77        unsafe {
78            from_glib_none(ffi::nm_setting_user_get_data(self.to_glib_none().0, key.to_glib_none().0))
79        }
80    }
81
82    ///
83    /// # Returns
84    ///
85    /// a
86    ///   [`None`]-terminated array containing each key from the table.
87    #[doc(alias = "nm_setting_user_get_keys")]
88    #[doc(alias = "get_keys")]
89    pub fn keys(&self) -> Vec<glib::GString> {
90        unsafe {
91            let mut out_len = std::mem::MaybeUninit::uninit();
92            let ret = FromGlibContainer::from_glib_none_num(ffi::nm_setting_user_get_keys(self.to_glib_none().0, out_len.as_mut_ptr()), out_len.assume_init() as _);
93            ret
94        }
95    }
96
97    /// ## `key`
98    /// the key to set
99    /// ## `val`
100    /// the value to set or [`None`] to clear a key.
101    ///
102    /// # Returns
103    ///
104    /// [`true`] if the operation was successful. The operation
105    ///   can fail if @key or @val are not valid strings according
106    ///   to nm_setting_user_check_key() and nm_setting_user_check_val().
107    #[doc(alias = "nm_setting_user_set_data")]
108    #[doc(alias = "data")]
109    pub fn set_data(&self, key: &str, val: Option<&str>) -> Result<(), glib::Error> {
110        unsafe {
111            let mut error = std::ptr::null_mut();
112            let is_ok = ffi::nm_setting_user_set_data(self.to_glib_none().0, key.to_glib_none().0, val.to_glib_none().0, &mut error);
113            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
114            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
115        }
116    }
117
118    /// Checks whether @key is a valid user data key. This means,
119    /// key is not [`None`], not too large and valid ASCII. Also,
120    /// only digits and numbers are allowed with a few special
121    /// characters. The key must contain at least one '.' and
122    /// look like a fully qualified DNS name.
123    /// ## `key`
124    /// the key to check
125    ///
126    /// # Returns
127    ///
128    /// [`true`] if @key is a valid user data key.
129    #[doc(alias = "nm_setting_user_check_key")]
130    pub fn check_key(key: &str) -> Result<(), glib::Error> {
131        assert_initialized_main_thread!();
132        unsafe {
133            let mut error = std::ptr::null_mut();
134            let is_ok = ffi::nm_setting_user_check_key(key.to_glib_none().0, &mut error);
135            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
136            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
137        }
138    }
139
140    /// Checks whether @val is a valid user data value. This means,
141    /// value is not [`None`], not too large and valid UTF-8.
142    /// ## `val`
143    /// the value to check
144    ///
145    /// # Returns
146    ///
147    /// [`true`] if @val is a valid user data value.
148    #[doc(alias = "nm_setting_user_check_val")]
149    pub fn check_val(val: &str) -> Result<(), glib::Error> {
150        assert_initialized_main_thread!();
151        unsafe {
152            let mut error = std::ptr::null_mut();
153            let is_ok = ffi::nm_setting_user_check_val(val.to_glib_none().0, &mut error);
154            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
155            if error.is_null() { Ok(()) } else { Err(from_glib_full(error)) }
156        }
157    }
158
159    #[cfg(feature = "v1_8")]
160    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
161    #[doc(alias = "data")]
162    pub fn connect_data_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
163        unsafe extern "C" fn notify_data_trampoline<F: Fn(&SettingUser) + 'static>(this: *mut ffi::NMSettingUser, _param_spec: glib::ffi::gpointer, f: glib::ffi::gpointer) {
164            let f: &F = &*(f as *const F);
165            f(&from_glib_borrow(this))
166        }
167        unsafe {
168            let f: Box_<F> = Box_::new(f);
169            connect_raw(self.as_ptr() as *mut _, c"notify::data".as_ptr() as *const _,
170                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(notify_data_trampoline::<F> as *const ())), Box_::into_raw(f))
171        }
172    }
173}
174
175#[cfg(feature = "v1_8")]
176#[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
177impl Default for SettingUser {
178                     fn default() -> Self {
179                         Self::new()
180                     }
181                 }
182
183// rustdoc-stripper-ignore-next
184        /// A [builder-pattern] type to construct [`SettingUser`] objects.
185        ///
186        /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
187#[must_use = "The builder must be built to be used"]
188pub struct SettingUserBuilder {
189            builder: glib::object::ObjectBuilder<'static, SettingUser>,
190        }
191
192        impl SettingUserBuilder {
193        fn new() -> Self {
194            Self { builder: glib::object::Object::builder() }
195        }
196
197                        //    #[cfg(feature = "v1_8")]
198    #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
199    //pub fn data(self, data: /*Unimplemented*/HashTable TypeId { ns_id: 0, id: 28 }/TypeId { ns_id: 0, id: 28 }) -> Self {
200                        //    Self { builder: self.builder.property("data", data), }
201                        //}
202
203    // rustdoc-stripper-ignore-next
204    /// Build the [`SettingUser`].
205    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
206    pub fn build(self) -> SettingUser {
207assert_initialized_main_thread!();
208    self.builder.build() }
209}