Skip to main content

glib/auto/
key_file.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::{Bytes, Error, KeyFileFlags, ffi, translate::*};
6
7crate::wrapper! {
8    /// data), data_len);
9    /// ```text
10    ///
11    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12    pub struct KeyFile(Shared<ffi::GKeyFile>);
13
14    match fn {
15        ref => |ptr| ffi::g_key_file_ref(ptr),
16        unref => |ptr| ffi::g_key_file_unref(ptr),
17        type_ => || ffi::g_key_file_get_type(),
18    }
19}
20
21impl KeyFile {
22    /// Creates a new empty [`KeyFile`][crate::KeyFile] object.
23    ///
24    /// Use [`load_from_file()`][Self::load_from_file()],
25    /// [`load_from_data()`][Self::load_from_data()], [`load_from_dirs()`][Self::load_from_dirs()] or
26    /// [`load_from_data_dirs()`][Self::load_from_data_dirs()] to
27    /// read an existing key file.
28    ///
29    /// # Returns
30    ///
31    /// an empty [`KeyFile`][crate::KeyFile].
32    #[doc(alias = "g_key_file_new")]
33    pub fn new() -> KeyFile {
34        unsafe { from_glib_full(ffi::g_key_file_new()) }
35    }
36
37    /// Retrieves a comment above @key from @group_name.
38    ///
39    /// If @key is `NULL` then @comment will be read from above
40    /// @group_name. If both @key and @group_name are `NULL`, then
41    /// @comment will be read from above the first group in the file.
42    ///
43    /// Note that the returned string does not include the `#` comment markers,
44    /// but does include any whitespace after them (on each line). It includes
45    /// the line breaks between lines, but does not include the final line break.
46    /// ## `group_name`
47    /// a group name, or `NULL` to get a top-level comment
48    /// ## `key`
49    /// a key, or `NULL` to get a group comment
50    ///
51    /// # Returns
52    ///
53    /// a comment that should be freed with `free()`
54    #[doc(alias = "g_key_file_get_comment")]
55    #[doc(alias = "get_comment")]
56    pub fn comment(
57        &self,
58        group_name: Option<&str>,
59        key: Option<&str>,
60    ) -> Result<crate::GString, crate::Error> {
61        unsafe {
62            let mut error = std::ptr::null_mut();
63            let ret = ffi::g_key_file_get_comment(
64                self.to_glib_none().0,
65                group_name.to_glib_none().0,
66                key.to_glib_none().0,
67                &mut error,
68            );
69            if error.is_null() {
70                Ok(from_glib_full(ret))
71            } else {
72                Err(from_glib_full(error))
73            }
74        }
75    }
76
77    /// Returns the value associated with @key under @group_name as a double.
78    ///
79    /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
80    /// returned. Likewise, if the value associated with @key cannot be interpreted
81    /// as a double then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
82    /// ## `group_name`
83    /// a group name
84    /// ## `key`
85    /// a key
86    ///
87    /// # Returns
88    ///
89    /// the value associated with the key as a double, or
90    ///     `0.0` if the key was not found or could not be parsed.
91    #[doc(alias = "g_key_file_get_double")]
92    #[doc(alias = "get_double")]
93    pub fn double(&self, group_name: &str, key: &str) -> Result<f64, crate::Error> {
94        unsafe {
95            let mut error = std::ptr::null_mut();
96            let ret = ffi::g_key_file_get_double(
97                self.to_glib_none().0,
98                group_name.to_glib_none().0,
99                key.to_glib_none().0,
100                &mut error,
101            );
102            if error.is_null() {
103                Ok(ret)
104            } else {
105                Err(from_glib_full(error))
106            }
107        }
108    }
109
110    /// Returns the values associated with @key under @group_name as
111    /// doubles.
112    ///
113    /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
114    /// returned. Likewise, if the values associated with @key cannot be interpreted
115    /// as doubles then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
116    /// ## `group_name`
117    /// a group name
118    /// ## `key`
119    /// a key
120    ///
121    /// # Returns
122    ///
123    ///
124    ///     the values associated with the key as a list of doubles, or `NULL` if the
125    ///     key was not found or could not be parsed. The returned list of doubles
126    ///     should be freed with `free()` when no longer needed.
127    #[doc(alias = "g_key_file_get_double_list")]
128    #[doc(alias = "get_double_list")]
129    pub fn double_list(&self, group_name: &str, key: &str) -> Result<Vec<f64>, crate::Error> {
130        unsafe {
131            let mut length = std::mem::MaybeUninit::uninit();
132            let mut error = std::ptr::null_mut();
133            let ret = ffi::g_key_file_get_double_list(
134                self.to_glib_none().0,
135                group_name.to_glib_none().0,
136                key.to_glib_none().0,
137                length.as_mut_ptr(),
138                &mut error,
139            );
140            if error.is_null() {
141                Ok(FromGlibContainer::from_glib_container_num(
142                    ret,
143                    length.assume_init() as _,
144                ))
145            } else {
146                Err(from_glib_full(error))
147            }
148        }
149    }
150
151    /// Returns the value associated with @key under @group_name as a signed
152    /// 64-bit integer.
153    ///
154    /// This is similar to [`integer()`][Self::integer()] but can return
155    /// 64-bit results without truncation.
156    /// ## `group_name`
157    /// a group name
158    /// ## `key`
159    /// a key
160    ///
161    /// # Returns
162    ///
163    /// the value associated with the key as a signed 64-bit integer, or
164    ///    `0` if the key was not found or could not be parsed.
165    #[doc(alias = "g_key_file_get_int64")]
166    #[doc(alias = "get_int64")]
167    pub fn int64(&self, group_name: &str, key: &str) -> Result<i64, crate::Error> {
168        unsafe {
169            let mut error = std::ptr::null_mut();
170            let ret = ffi::g_key_file_get_int64(
171                self.to_glib_none().0,
172                group_name.to_glib_none().0,
173                key.to_glib_none().0,
174                &mut error,
175            );
176            if error.is_null() {
177                Ok(ret)
178            } else {
179                Err(from_glib_full(error))
180            }
181        }
182    }
183
184    /// Returns the value associated with @key under @group_name as an
185    /// integer.
186    ///
187    /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
188    /// returned. Likewise, if the value associated with @key cannot be interpreted
189    /// as an integer, or is out of range for a `gint`, then
190    /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
191    /// ## `group_name`
192    /// a group name
193    /// ## `key`
194    /// a key
195    ///
196    /// # Returns
197    ///
198    /// the value associated with the key as an integer, or
199    ///     `0` if the key was not found or could not be parsed.
200    #[doc(alias = "g_key_file_get_integer")]
201    #[doc(alias = "get_integer")]
202    pub fn integer(&self, group_name: &str, key: &str) -> Result<i32, crate::Error> {
203        unsafe {
204            let mut error = std::ptr::null_mut();
205            let ret = ffi::g_key_file_get_integer(
206                self.to_glib_none().0,
207                group_name.to_glib_none().0,
208                key.to_glib_none().0,
209                &mut error,
210            );
211            if error.is_null() {
212                Ok(ret)
213            } else {
214                Err(from_glib_full(error))
215            }
216        }
217    }
218
219    /// Returns the values associated with @key under @group_name as
220    /// integers.
221    ///
222    /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
223    /// returned. Likewise, if the values associated with @key cannot be interpreted
224    /// as integers, or are out of range for `gint`, then
225    /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
226    /// ## `group_name`
227    /// a group name
228    /// ## `key`
229    /// a key
230    ///
231    /// # Returns
232    ///
233    ///
234    ///     the values associated with the key as a list of integers, or `NULL` if
235    ///     the key was not found or could not be parsed. The returned list of
236    ///     integers should be freed with `free()` when no longer needed.
237    #[doc(alias = "g_key_file_get_integer_list")]
238    #[doc(alias = "get_integer_list")]
239    pub fn integer_list(&self, group_name: &str, key: &str) -> Result<Vec<i32>, crate::Error> {
240        unsafe {
241            let mut length = std::mem::MaybeUninit::uninit();
242            let mut error = std::ptr::null_mut();
243            let ret = ffi::g_key_file_get_integer_list(
244                self.to_glib_none().0,
245                group_name.to_glib_none().0,
246                key.to_glib_none().0,
247                length.as_mut_ptr(),
248                &mut error,
249            );
250            if error.is_null() {
251                Ok(FromGlibContainer::from_glib_container_num(
252                    ret,
253                    length.assume_init() as _,
254                ))
255            } else {
256                Err(from_glib_full(error))
257            }
258        }
259    }
260
261    /// Returns the actual locale which the result of
262    /// [`locale_string()`][Self::locale_string()] or
263    /// [`locale_string_list()`][Self::locale_string_list()] came from.
264    ///
265    /// If calling [`locale_string()`][Self::locale_string()] or
266    /// [`locale_string_list()`][Self::locale_string_list()] with exactly the same @self,
267    /// @group_name, @key and @locale, the result of those functions will
268    /// have originally been tagged with the locale that is the result of
269    /// this function.
270    /// ## `group_name`
271    /// a group name
272    /// ## `key`
273    /// a key
274    /// ## `locale`
275    /// a locale identifier or `NULL` to use the current locale
276    ///
277    /// # Returns
278    ///
279    /// the locale from the file, or `NULL` if the key was not
280    ///   found or the entry in the file was was untranslated
281    #[doc(alias = "g_key_file_get_locale_for_key")]
282    #[doc(alias = "get_locale_for_key")]
283    pub fn locale_for_key(
284        &self,
285        group_name: &str,
286        key: &str,
287        locale: Option<&str>,
288    ) -> Option<crate::GString> {
289        unsafe {
290            from_glib_full(ffi::g_key_file_get_locale_for_key(
291                self.to_glib_none().0,
292                group_name.to_glib_none().0,
293                key.to_glib_none().0,
294                locale.to_glib_none().0,
295            ))
296        }
297    }
298
299    /// Returns the name of the start group of the file.
300    ///
301    /// # Returns
302    ///
303    /// The start group of the key file.
304    #[doc(alias = "g_key_file_get_start_group")]
305    #[doc(alias = "get_start_group")]
306    pub fn start_group(&self) -> Option<crate::GString> {
307        unsafe { from_glib_full(ffi::g_key_file_get_start_group(self.to_glib_none().0)) }
308    }
309
310    /// Returns the value associated with @key under @group_name as an unsigned
311    /// 64-bit integer.
312    ///
313    /// This is similar to [`integer()`][Self::integer()] but can return
314    /// large positive results without truncation.
315    /// ## `group_name`
316    /// a group name
317    /// ## `key`
318    /// a key
319    ///
320    /// # Returns
321    ///
322    /// the value associated with the key as an unsigned 64-bit integer,
323    ///    or `0` if the key was not found or could not be parsed.
324    #[doc(alias = "g_key_file_get_uint64")]
325    #[doc(alias = "get_uint64")]
326    pub fn uint64(&self, group_name: &str, key: &str) -> Result<u64, crate::Error> {
327        unsafe {
328            let mut error = std::ptr::null_mut();
329            let ret = ffi::g_key_file_get_uint64(
330                self.to_glib_none().0,
331                group_name.to_glib_none().0,
332                key.to_glib_none().0,
333                &mut error,
334            );
335            if error.is_null() {
336                Ok(ret)
337            } else {
338                Err(from_glib_full(error))
339            }
340        }
341    }
342
343    /// Returns the raw value associated with @key under @group_name.
344    ///
345    /// Use [`string()`][Self::string()] to retrieve an unescaped UTF-8 string.
346    ///
347    /// If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND]
348    /// is returned.  If the @group_name cannot be found,
349    /// [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
350    /// ## `group_name`
351    /// a group name
352    /// ## `key`
353    /// a key
354    ///
355    /// # Returns
356    ///
357    /// a newly allocated string or `NULL` if the specified
358    ///  key cannot be found.
359    #[doc(alias = "g_key_file_get_value")]
360    #[doc(alias = "get_value")]
361    pub fn value(&self, group_name: &str, key: &str) -> Result<crate::GString, crate::Error> {
362        unsafe {
363            let mut error = std::ptr::null_mut();
364            let ret = ffi::g_key_file_get_value(
365                self.to_glib_none().0,
366                group_name.to_glib_none().0,
367                key.to_glib_none().0,
368                &mut error,
369            );
370            if error.is_null() {
371                Ok(from_glib_full(ret))
372            } else {
373                Err(from_glib_full(error))
374            }
375        }
376    }
377
378    /// Looks whether the key file has the group @group_name.
379    /// ## `group_name`
380    /// a group name
381    ///
382    /// # Returns
383    ///
384    /// true if @group_name is a part of @self, false otherwise.
385    #[doc(alias = "g_key_file_has_group")]
386    pub fn has_group(&self, group_name: &str) -> bool {
387        unsafe {
388            from_glib(ffi::g_key_file_has_group(
389                self.to_glib_none().0,
390                group_name.to_glib_none().0,
391            ))
392        }
393    }
394
395    /// Loads a key file from the data in @bytes into an empty [`KeyFile`][crate::KeyFile]
396    /// structure.
397    ///
398    /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
399    /// ## `bytes`
400    /// a [`Bytes`][crate::Bytes]
401    /// ## `flags`
402    /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
403    ///
404    /// # Returns
405    ///
406    /// true if a key file could be loaded, false otherwise
407    #[doc(alias = "g_key_file_load_from_bytes")]
408    pub fn load_from_bytes(&self, bytes: &Bytes, flags: KeyFileFlags) -> Result<(), crate::Error> {
409        unsafe {
410            let mut error = std::ptr::null_mut();
411            let is_ok = ffi::g_key_file_load_from_bytes(
412                self.to_glib_none().0,
413                bytes.to_glib_none().0,
414                flags.into_glib(),
415                &mut error,
416            );
417            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
418            if error.is_null() {
419                Ok(())
420            } else {
421                Err(from_glib_full(error))
422            }
423        }
424    }
425
426    /// Loads a key file from memory into an empty [`KeyFile`][crate::KeyFile] structure.
427    ///
428    /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
429    /// ## `data`
430    /// key file loaded in memory
431    /// ## `length`
432    /// the length of @data in bytes (or `(gsize)-1` if data is nul-terminated)
433    /// ## `flags`
434    /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
435    ///
436    /// # Returns
437    ///
438    /// true if a key file could be loaded, false otherwise
439    #[doc(alias = "g_key_file_load_from_data")]
440    pub fn load_from_data(&self, data: &str, flags: KeyFileFlags) -> Result<(), crate::Error> {
441        let length = data.len() as _;
442        unsafe {
443            let mut error = std::ptr::null_mut();
444            let is_ok = ffi::g_key_file_load_from_data(
445                self.to_glib_none().0,
446                data.to_glib_none().0,
447                length,
448                flags.into_glib(),
449                &mut error,
450            );
451            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
452            if error.is_null() {
453                Ok(())
454            } else {
455                Err(from_glib_full(error))
456            }
457        }
458    }
459
460    /// Loads a key file into an empty [`KeyFile`][crate::KeyFile] structure.
461    ///
462    /// If the OS returns an error when opening or reading the file, a
463    /// [`FileError`][crate::FileError] is returned. If there is a problem parsing the file,
464    /// a [`KeyFileError`][crate::KeyFileError] is returned.
465    ///
466    /// This function will never return a [error@GLib.KeyFileError.NOT_FOUND]
467    /// error. If the @file is not found, [error@GLib.FileError.NOENT] is returned.
468    /// ## `file`
469    /// the path of a filename to load, in the GLib filename encoding
470    /// ## `flags`
471    /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
472    ///
473    /// # Returns
474    ///
475    /// true if a key file could be loaded, false otherwise
476    #[doc(alias = "g_key_file_load_from_file")]
477    pub fn load_from_file(
478        &self,
479        file: impl AsRef<std::path::Path>,
480        flags: KeyFileFlags,
481    ) -> Result<(), crate::Error> {
482        unsafe {
483            let mut error = std::ptr::null_mut();
484            let is_ok = ffi::g_key_file_load_from_file(
485                self.to_glib_none().0,
486                file.as_ref().to_glib_none().0,
487                flags.into_glib(),
488                &mut error,
489            );
490            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
491            if error.is_null() {
492                Ok(())
493            } else {
494                Err(from_glib_full(error))
495            }
496        }
497    }
498
499    /// message);
500    ///     return;
501    ///   }
502    ///
503    /// g_autofree char *val = g_key_file_get_string (kf, "Management", "Setting", NULL);
504    /// ```text
505    ///
506    /// ## `project`
507    /// name of the project used as subdirectory
508    /// ## `etc_subdir`
509    /// directory path for administrative configuration files
510    /// ## `run_subdir`
511    /// directory path for ephemeral overrides
512    /// ## `usr_subdir`
513    /// directory path for vendor-defined settings
514    /// ## `config_name`
515    /// basename of the configuration file
516    /// ## `config_suffix`
517    /// suffix of the configuration file
518    /// ## `flags`
519    /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
520    ///
521    /// # Returns
522    ///
523    /// true on success, false otherwise
524    #[cfg(feature = "v2_90")]
525    #[cfg_attr(docsrs, doc(cfg(feature = "v2_90")))]
526    #[doc(alias = "g_key_file_load_unix_configurations")]
527    pub fn load_unix_configurations(
528        &self,
529        project: Option<&str>,
530        etc_subdir: Option<impl AsRef<std::path::Path>>,
531        run_subdir: Option<impl AsRef<std::path::Path>>,
532        usr_subdir: Option<impl AsRef<std::path::Path>>,
533        config_name: impl AsRef<std::path::Path>,
534        config_suffix: Option<impl AsRef<std::path::Path>>,
535        flags: KeyFileFlags,
536    ) -> Result<(), crate::Error> {
537        unsafe {
538            let mut error = std::ptr::null_mut();
539            let is_ok = ffi::g_key_file_load_unix_configurations(
540                self.to_glib_none().0,
541                project.to_glib_none().0,
542                etc_subdir.as_ref().map(|p| p.as_ref()).to_glib_none().0,
543                run_subdir.as_ref().map(|p| p.as_ref()).to_glib_none().0,
544                usr_subdir.as_ref().map(|p| p.as_ref()).to_glib_none().0,
545                config_name.as_ref().to_glib_none().0,
546                config_suffix.as_ref().map(|p| p.as_ref()).to_glib_none().0,
547                flags.into_glib(),
548                &mut error,
549            );
550            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
551            if error.is_null() {
552                Ok(())
553            } else {
554                Err(from_glib_full(error))
555            }
556        }
557    }
558
559    /// Removes a comment above @key from @group_name.
560    ///
561    /// If @key is `NULL` then @comment will be removed above @group_name.
562    /// If both @key and @group_name are `NULL`, then @comment will
563    /// be removed above the first group in the file.
564    /// ## `group_name`
565    /// a group name, or `NULL` to get a top-level comment
566    /// ## `key`
567    /// a key, or `NULL` to get a group comment
568    ///
569    /// # Returns
570    ///
571    /// true if the comment was removed, false otherwise
572    #[doc(alias = "g_key_file_remove_comment")]
573    pub fn remove_comment(
574        &self,
575        group_name: Option<&str>,
576        key: Option<&str>,
577    ) -> Result<(), crate::Error> {
578        unsafe {
579            let mut error = std::ptr::null_mut();
580            let is_ok = ffi::g_key_file_remove_comment(
581                self.to_glib_none().0,
582                group_name.to_glib_none().0,
583                key.to_glib_none().0,
584                &mut error,
585            );
586            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
587            if error.is_null() {
588                Ok(())
589            } else {
590                Err(from_glib_full(error))
591            }
592        }
593    }
594
595    /// Removes the specified group, @group_name,
596    /// from the key file.
597    /// ## `group_name`
598    /// a group name
599    ///
600    /// # Returns
601    ///
602    /// true if the group was removed, false otherwise
603    #[doc(alias = "g_key_file_remove_group")]
604    pub fn remove_group(&self, group_name: &str) -> Result<(), crate::Error> {
605        unsafe {
606            let mut error = std::ptr::null_mut();
607            let is_ok = ffi::g_key_file_remove_group(
608                self.to_glib_none().0,
609                group_name.to_glib_none().0,
610                &mut error,
611            );
612            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
613            if error.is_null() {
614                Ok(())
615            } else {
616                Err(from_glib_full(error))
617            }
618        }
619    }
620
621    /// Removes @key in @group_name from the key file.
622    /// ## `group_name`
623    /// a group name
624    /// ## `key`
625    /// a key name to remove
626    ///
627    /// # Returns
628    ///
629    /// true if the key was removed, false otherwise
630    #[doc(alias = "g_key_file_remove_key")]
631    pub fn remove_key(&self, group_name: &str, key: &str) -> Result<(), crate::Error> {
632        unsafe {
633            let mut error = std::ptr::null_mut();
634            let is_ok = ffi::g_key_file_remove_key(
635                self.to_glib_none().0,
636                group_name.to_glib_none().0,
637                key.to_glib_none().0,
638                &mut error,
639            );
640            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
641            if error.is_null() {
642                Ok(())
643            } else {
644                Err(from_glib_full(error))
645            }
646        }
647    }
648
649    /// Associates a new boolean value with @key under @group_name.
650    ///
651    /// If @key cannot be found then it is created.
652    /// ## `group_name`
653    /// a group name
654    /// ## `key`
655    /// a key
656    /// ## `value`
657    /// true or false
658    #[doc(alias = "g_key_file_set_boolean")]
659    pub fn set_boolean(&self, group_name: &str, key: &str, value: bool) {
660        unsafe {
661            ffi::g_key_file_set_boolean(
662                self.to_glib_none().0,
663                group_name.to_glib_none().0,
664                key.to_glib_none().0,
665                value.into_glib(),
666            );
667        }
668    }
669
670    //#[doc(alias = "g_key_file_set_boolean_list")]
671    //pub fn set_boolean_list(&self, group_name: &str, key: &str, list: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 1 }) {
672    //    unsafe { TODO: call ffi:g_key_file_set_boolean_list() }
673    //}
674
675    /// Places a comment above @key from @group_name.
676    ///
677    /// If @key is `NULL` then @comment will be written above @group_name.
678    /// If both @key and @group_name are `NULL`, then @comment will be
679    /// written above the first group in the file.
680    ///
681    /// Passing a non-existent @group_name or @key to this function returns
682    /// false and populates @error. (In contrast, passing a non-existent
683    /// `group_name` or `key` to [`set_string()`][Self::set_string()]
684    /// creates the associated group name and key.)
685    ///
686    /// Note that this function prepends a `#` comment marker to
687    /// each line of @comment.
688    /// ## `group_name`
689    /// a group name, or `NULL` to write a top-level comment
690    /// ## `key`
691    /// a key, or `NULL` to write a group comment
692    /// ## `comment`
693    /// a comment
694    ///
695    /// # Returns
696    ///
697    /// true if the comment was written, false otherwise
698    #[doc(alias = "g_key_file_set_comment")]
699    pub fn set_comment(
700        &self,
701        group_name: Option<&str>,
702        key: Option<&str>,
703        comment: &str,
704    ) -> Result<(), crate::Error> {
705        unsafe {
706            let mut error = std::ptr::null_mut();
707            let is_ok = ffi::g_key_file_set_comment(
708                self.to_glib_none().0,
709                group_name.to_glib_none().0,
710                key.to_glib_none().0,
711                comment.to_glib_none().0,
712                &mut error,
713            );
714            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
715            if error.is_null() {
716                Ok(())
717            } else {
718                Err(from_glib_full(error))
719            }
720        }
721    }
722
723    /// Associates a new double value with @key under @group_name.
724    ///
725    /// If @key cannot be found then it is created.
726    /// ## `group_name`
727    /// a group name
728    /// ## `key`
729    /// a key
730    /// ## `value`
731    /// a double value
732    #[doc(alias = "g_key_file_set_double")]
733    pub fn set_double(&self, group_name: &str, key: &str, value: f64) {
734        unsafe {
735            ffi::g_key_file_set_double(
736                self.to_glib_none().0,
737                group_name.to_glib_none().0,
738                key.to_glib_none().0,
739                value,
740            );
741        }
742    }
743
744    /// Associates a new integer value with @key under @group_name.
745    ///
746    /// If @key cannot be found then it is created.
747    /// ## `group_name`
748    /// a group name
749    /// ## `key`
750    /// a key
751    /// ## `value`
752    /// an integer value
753    #[doc(alias = "g_key_file_set_int64")]
754    pub fn set_int64(&self, group_name: &str, key: &str, value: i64) {
755        unsafe {
756            ffi::g_key_file_set_int64(
757                self.to_glib_none().0,
758                group_name.to_glib_none().0,
759                key.to_glib_none().0,
760                value,
761            );
762        }
763    }
764
765    /// Associates a new integer value with @key under @group_name.
766    ///
767    /// If @key cannot be found then it is created.
768    /// ## `group_name`
769    /// a group name
770    /// ## `key`
771    /// a key
772    /// ## `value`
773    /// an integer value
774    #[doc(alias = "g_key_file_set_integer")]
775    pub fn set_integer(&self, group_name: &str, key: &str, value: i32) {
776        unsafe {
777            ffi::g_key_file_set_integer(
778                self.to_glib_none().0,
779                group_name.to_glib_none().0,
780                key.to_glib_none().0,
781                value,
782            );
783        }
784    }
785
786    /// Sets the character which is used to separate values in lists.
787    ///
788    /// Typically `;` or `,` are used as separators. The default list separator
789    /// is `;`.
790    /// ## `separator`
791    /// the separator
792    #[doc(alias = "g_key_file_set_list_separator")]
793    pub fn set_list_separator(&self, separator: crate::Char) {
794        unsafe {
795            ffi::g_key_file_set_list_separator(self.to_glib_none().0, separator.into_glib());
796        }
797    }
798
799    /// Associates a string value for @key and @locale under @group_name.
800    ///
801    /// If the translation for @key cannot be found then it is created.
802    ///
803    /// If @locale is `C` then the untranslated value is set (since GLib 2.84).
804    /// ## `group_name`
805    /// a group name
806    /// ## `key`
807    /// a key
808    /// ## `locale`
809    /// a locale identifier
810    /// ## `string`
811    /// a string
812    #[doc(alias = "g_key_file_set_locale_string")]
813    pub fn set_locale_string(&self, group_name: &str, key: &str, locale: &str, string: &str) {
814        unsafe {
815            ffi::g_key_file_set_locale_string(
816                self.to_glib_none().0,
817                group_name.to_glib_none().0,
818                key.to_glib_none().0,
819                locale.to_glib_none().0,
820                string.to_glib_none().0,
821            );
822        }
823    }
824
825    /// Associates a new string value with @key under @group_name.
826    ///
827    /// If @key cannot be found then it is created.
828    /// If @group_name cannot be found then it is created.
829    /// Unlike [`set_value()`][Self::set_value()], this function handles characters
830    /// that need escaping, such as newlines.
831    /// ## `group_name`
832    /// a group name
833    /// ## `key`
834    /// a key
835    /// ## `string`
836    /// a string
837    #[doc(alias = "g_key_file_set_string")]
838    pub fn set_string(&self, group_name: &str, key: &str, string: &str) {
839        unsafe {
840            ffi::g_key_file_set_string(
841                self.to_glib_none().0,
842                group_name.to_glib_none().0,
843                key.to_glib_none().0,
844                string.to_glib_none().0,
845            );
846        }
847    }
848
849    /// Associates a new integer value with @key under @group_name.
850    ///
851    /// If @key cannot be found then it is created.
852    /// ## `group_name`
853    /// a group name
854    /// ## `key`
855    /// a key
856    /// ## `value`
857    /// an integer value
858    #[doc(alias = "g_key_file_set_uint64")]
859    pub fn set_uint64(&self, group_name: &str, key: &str, value: u64) {
860        unsafe {
861            ffi::g_key_file_set_uint64(
862                self.to_glib_none().0,
863                group_name.to_glib_none().0,
864                key.to_glib_none().0,
865                value,
866            );
867        }
868    }
869
870    /// Associates a new value with @key under @group_name.
871    ///
872    /// If @key cannot be found then it is created. If @group_name cannot
873    /// be found then it is created. To set an UTF-8 string which may contain
874    /// characters that need escaping (such as newlines or spaces), use
875    /// [`set_string()`][Self::set_string()].
876    /// ## `group_name`
877    /// a group name
878    /// ## `key`
879    /// a key
880    /// ## `value`
881    /// a string
882    #[doc(alias = "g_key_file_set_value")]
883    pub fn set_value(&self, group_name: &str, key: &str, value: &str) {
884        unsafe {
885            ffi::g_key_file_set_value(
886                self.to_glib_none().0,
887                group_name.to_glib_none().0,
888                key.to_glib_none().0,
889                value.to_glib_none().0,
890            );
891        }
892    }
893}
894
895impl Default for KeyFile {
896    fn default() -> Self {
897        Self::new()
898    }
899}