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    /// Removes a comment above @key from @group_name.
500    ///
501    /// If @key is `NULL` then @comment will be removed above @group_name.
502    /// If both @key and @group_name are `NULL`, then @comment will
503    /// be removed above the first group in the file.
504    /// ## `group_name`
505    /// a group name, or `NULL` to get a top-level comment
506    /// ## `key`
507    /// a key, or `NULL` to get a group comment
508    ///
509    /// # Returns
510    ///
511    /// true if the comment was removed, false otherwise
512    #[doc(alias = "g_key_file_remove_comment")]
513    pub fn remove_comment(
514        &self,
515        group_name: Option<&str>,
516        key: Option<&str>,
517    ) -> Result<(), crate::Error> {
518        unsafe {
519            let mut error = std::ptr::null_mut();
520            let is_ok = ffi::g_key_file_remove_comment(
521                self.to_glib_none().0,
522                group_name.to_glib_none().0,
523                key.to_glib_none().0,
524                &mut error,
525            );
526            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
527            if error.is_null() {
528                Ok(())
529            } else {
530                Err(from_glib_full(error))
531            }
532        }
533    }
534
535    /// Removes the specified group, @group_name,
536    /// from the key file.
537    /// ## `group_name`
538    /// a group name
539    ///
540    /// # Returns
541    ///
542    /// true if the group was removed, false otherwise
543    #[doc(alias = "g_key_file_remove_group")]
544    pub fn remove_group(&self, group_name: &str) -> Result<(), crate::Error> {
545        unsafe {
546            let mut error = std::ptr::null_mut();
547            let is_ok = ffi::g_key_file_remove_group(
548                self.to_glib_none().0,
549                group_name.to_glib_none().0,
550                &mut error,
551            );
552            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
553            if error.is_null() {
554                Ok(())
555            } else {
556                Err(from_glib_full(error))
557            }
558        }
559    }
560
561    /// Removes @key in @group_name from the key file.
562    /// ## `group_name`
563    /// a group name
564    /// ## `key`
565    /// a key name to remove
566    ///
567    /// # Returns
568    ///
569    /// true if the key was removed, false otherwise
570    #[doc(alias = "g_key_file_remove_key")]
571    pub fn remove_key(&self, group_name: &str, key: &str) -> Result<(), crate::Error> {
572        unsafe {
573            let mut error = std::ptr::null_mut();
574            let is_ok = ffi::g_key_file_remove_key(
575                self.to_glib_none().0,
576                group_name.to_glib_none().0,
577                key.to_glib_none().0,
578                &mut error,
579            );
580            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
581            if error.is_null() {
582                Ok(())
583            } else {
584                Err(from_glib_full(error))
585            }
586        }
587    }
588
589    /// Associates a new boolean value with @key under @group_name.
590    ///
591    /// If @key cannot be found then it is created.
592    /// ## `group_name`
593    /// a group name
594    /// ## `key`
595    /// a key
596    /// ## `value`
597    /// true or false
598    #[doc(alias = "g_key_file_set_boolean")]
599    pub fn set_boolean(&self, group_name: &str, key: &str, value: bool) {
600        unsafe {
601            ffi::g_key_file_set_boolean(
602                self.to_glib_none().0,
603                group_name.to_glib_none().0,
604                key.to_glib_none().0,
605                value.into_glib(),
606            );
607        }
608    }
609
610    //#[doc(alias = "g_key_file_set_boolean_list")]
611    //pub fn set_boolean_list(&self, group_name: &str, key: &str, list: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 1 }) {
612    //    unsafe { TODO: call ffi:g_key_file_set_boolean_list() }
613    //}
614
615    /// Places a comment above @key from @group_name.
616    ///
617    /// If @key is `NULL` then @comment will be written above @group_name.
618    /// If both @key and @group_name are `NULL`, then @comment will be
619    /// written above the first group in the file.
620    ///
621    /// Passing a non-existent @group_name or @key to this function returns
622    /// false and populates @error. (In contrast, passing a non-existent
623    /// `group_name` or `key` to [`set_string()`][Self::set_string()]
624    /// creates the associated group name and key.)
625    ///
626    /// Note that this function prepends a `#` comment marker to
627    /// each line of @comment.
628    /// ## `group_name`
629    /// a group name, or `NULL` to write a top-level comment
630    /// ## `key`
631    /// a key, or `NULL` to write a group comment
632    /// ## `comment`
633    /// a comment
634    ///
635    /// # Returns
636    ///
637    /// true if the comment was written, false otherwise
638    #[doc(alias = "g_key_file_set_comment")]
639    pub fn set_comment(
640        &self,
641        group_name: Option<&str>,
642        key: Option<&str>,
643        comment: &str,
644    ) -> Result<(), crate::Error> {
645        unsafe {
646            let mut error = std::ptr::null_mut();
647            let is_ok = ffi::g_key_file_set_comment(
648                self.to_glib_none().0,
649                group_name.to_glib_none().0,
650                key.to_glib_none().0,
651                comment.to_glib_none().0,
652                &mut error,
653            );
654            debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
655            if error.is_null() {
656                Ok(())
657            } else {
658                Err(from_glib_full(error))
659            }
660        }
661    }
662
663    /// Associates a new double value with @key under @group_name.
664    ///
665    /// If @key cannot be found then it is created.
666    /// ## `group_name`
667    /// a group name
668    /// ## `key`
669    /// a key
670    /// ## `value`
671    /// a double value
672    #[doc(alias = "g_key_file_set_double")]
673    pub fn set_double(&self, group_name: &str, key: &str, value: f64) {
674        unsafe {
675            ffi::g_key_file_set_double(
676                self.to_glib_none().0,
677                group_name.to_glib_none().0,
678                key.to_glib_none().0,
679                value,
680            );
681        }
682    }
683
684    /// Associates a new integer value with @key under @group_name.
685    ///
686    /// If @key cannot be found then it is created.
687    /// ## `group_name`
688    /// a group name
689    /// ## `key`
690    /// a key
691    /// ## `value`
692    /// an integer value
693    #[doc(alias = "g_key_file_set_int64")]
694    pub fn set_int64(&self, group_name: &str, key: &str, value: i64) {
695        unsafe {
696            ffi::g_key_file_set_int64(
697                self.to_glib_none().0,
698                group_name.to_glib_none().0,
699                key.to_glib_none().0,
700                value,
701            );
702        }
703    }
704
705    /// Associates a new integer value with @key under @group_name.
706    ///
707    /// If @key cannot be found then it is created.
708    /// ## `group_name`
709    /// a group name
710    /// ## `key`
711    /// a key
712    /// ## `value`
713    /// an integer value
714    #[doc(alias = "g_key_file_set_integer")]
715    pub fn set_integer(&self, group_name: &str, key: &str, value: i32) {
716        unsafe {
717            ffi::g_key_file_set_integer(
718                self.to_glib_none().0,
719                group_name.to_glib_none().0,
720                key.to_glib_none().0,
721                value,
722            );
723        }
724    }
725
726    /// Sets the character which is used to separate values in lists.
727    ///
728    /// Typically `;` or `,` are used as separators. The default list separator
729    /// is `;`.
730    /// ## `separator`
731    /// the separator
732    #[doc(alias = "g_key_file_set_list_separator")]
733    pub fn set_list_separator(&self, separator: crate::Char) {
734        unsafe {
735            ffi::g_key_file_set_list_separator(self.to_glib_none().0, separator.into_glib());
736        }
737    }
738
739    /// Associates a string value for @key and @locale under @group_name.
740    ///
741    /// If the translation for @key cannot be found then it is created.
742    ///
743    /// If @locale is `C` then the untranslated value is set (since GLib 2.84).
744    /// ## `group_name`
745    /// a group name
746    /// ## `key`
747    /// a key
748    /// ## `locale`
749    /// a locale identifier
750    /// ## `string`
751    /// a string
752    #[doc(alias = "g_key_file_set_locale_string")]
753    pub fn set_locale_string(&self, group_name: &str, key: &str, locale: &str, string: &str) {
754        unsafe {
755            ffi::g_key_file_set_locale_string(
756                self.to_glib_none().0,
757                group_name.to_glib_none().0,
758                key.to_glib_none().0,
759                locale.to_glib_none().0,
760                string.to_glib_none().0,
761            );
762        }
763    }
764
765    /// Associates a new string value with @key under @group_name.
766    ///
767    /// If @key cannot be found then it is created.
768    /// If @group_name cannot be found then it is created.
769    /// Unlike [`set_value()`][Self::set_value()], this function handles characters
770    /// that need escaping, such as newlines.
771    /// ## `group_name`
772    /// a group name
773    /// ## `key`
774    /// a key
775    /// ## `string`
776    /// a string
777    #[doc(alias = "g_key_file_set_string")]
778    pub fn set_string(&self, group_name: &str, key: &str, string: &str) {
779        unsafe {
780            ffi::g_key_file_set_string(
781                self.to_glib_none().0,
782                group_name.to_glib_none().0,
783                key.to_glib_none().0,
784                string.to_glib_none().0,
785            );
786        }
787    }
788
789    /// Associates a new integer value with @key under @group_name.
790    ///
791    /// If @key cannot be found then it is created.
792    /// ## `group_name`
793    /// a group name
794    /// ## `key`
795    /// a key
796    /// ## `value`
797    /// an integer value
798    #[doc(alias = "g_key_file_set_uint64")]
799    pub fn set_uint64(&self, group_name: &str, key: &str, value: u64) {
800        unsafe {
801            ffi::g_key_file_set_uint64(
802                self.to_glib_none().0,
803                group_name.to_glib_none().0,
804                key.to_glib_none().0,
805                value,
806            );
807        }
808    }
809
810    /// Associates a new value with @key under @group_name.
811    ///
812    /// If @key cannot be found then it is created. If @group_name cannot
813    /// be found then it is created. To set an UTF-8 string which may contain
814    /// characters that need escaping (such as newlines or spaces), use
815    /// [`set_string()`][Self::set_string()].
816    /// ## `group_name`
817    /// a group name
818    /// ## `key`
819    /// a key
820    /// ## `value`
821    /// a string
822    #[doc(alias = "g_key_file_set_value")]
823    pub fn set_value(&self, group_name: &str, key: &str, value: &str) {
824        unsafe {
825            ffi::g_key_file_set_value(
826                self.to_glib_none().0,
827                group_name.to_glib_none().0,
828                key.to_glib_none().0,
829                value.to_glib_none().0,
830            );
831        }
832    }
833}
834
835impl Default for KeyFile {
836    fn default() -> Self {
837        Self::new()
838    }
839}