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::{ffi, translate::*, Bytes, Error, KeyFileFlags};
6
7crate::wrapper! {
8 /// `GKeyFile` parses .ini-like config files.
9 ///
10 /// `GKeyFile` lets you parse, edit or create files containing groups of
11 /// key-value pairs, which we call ‘key files’ for lack of a better name.
12 /// Several freedesktop.org specifications use key files. For example, the
13 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/)
14 /// and the [Icon Theme Specification](https://specifications.freedesktop.org/icon-theme-spec/latest/).
15 ///
16 /// The syntax of key files is described in detail in the
17 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
18 /// here is a quick summary: Key files consists of groups of key-value pairs, interspersed
19 /// with comments.
20 ///
21 /// **⚠️ The following code is in txt ⚠️**
22 ///
23 /// ```txt
24 /// # this is just an example
25 /// # there can be comments before the first group
26 ///
27 /// [First Group]
28 ///
29 /// Name=Key File Example\tthis value shows\nescaping
30 ///
31 /// # localized strings are stored in multiple key-value pairs
32 /// Welcome=Hello
33 /// Welcome[de]=Hallo
34 /// Welcome[fr_FR]=Bonjour
35 /// Welcome[it]=Ciao
36 ///
37 /// [Another Group]
38 ///
39 /// Numbers=2;20;-200;0
40 ///
41 /// Booleans=true;false;true;true
42 /// ```
43 ///
44 /// Lines beginning with a `#` and blank lines are considered comments.
45 ///
46 /// Groups are started by a header line containing the group name enclosed
47 /// in `[` and `]`, and ended implicitly by the start of the next group or
48 /// the end of the file. Each key-value pair must be contained in a group.
49 ///
50 /// Key-value pairs generally have the form `key=value`, with the exception
51 /// of localized strings, which have the form `key[locale]=value`, with a
52 /// locale identifier of the form `lang_COUNTRY@MODIFIER` where `COUNTRY`
53 /// and `MODIFIER` are optional. As a special case, the locale `C` is associated
54 /// with the untranslated pair `key=value` (since GLib 2.84). Space before and
55 /// after the `=` character is ignored. Newline, tab, carriage return and
56 /// backslash characters in value are escaped as `\n`, `\t`, `\r`, and `\\\\`,
57 /// respectively. To preserve leading spaces in values, these can also be escaped
58 /// as `\s`.
59 ///
60 /// Key files can store strings (possibly with localized variants), integers,
61 /// booleans and lists of these. Lists are separated by a separator character,
62 /// typically `;` or `,`. To use the list separator character in a value in
63 /// a list, it has to be escaped by prefixing it with a backslash.
64 ///
65 /// This syntax is obviously inspired by the .ini files commonly met
66 /// on Windows, but there are some important differences:
67 ///
68 /// - .ini files use the `;` character to begin comments,
69 /// key files use the `#` character.
70 ///
71 /// - Key files do not allow for ungrouped keys meaning only
72 /// comments can precede the first group.
73 ///
74 /// - Key files are always encoded in UTF-8.
75 ///
76 /// - Key and Group names are case-sensitive. For example, a group called
77 /// `[GROUP]` is a different from `[group]`.
78 ///
79 /// - .ini files don’t have a strongly typed boolean entry type,
80 /// they only have `GetProfileInt()`. In key files, only
81 /// `true` and `false` (in lower case) are allowed.
82 ///
83 /// Note that in contrast to the
84 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
85 /// groups in key files may contain the same key multiple times; the last entry wins.
86 /// Key files may also contain multiple groups with the same name; they are merged
87 /// together. Another difference is that keys and group names in key files are not
88 /// restricted to ASCII characters.
89 ///
90 /// Here is an example of loading a key file and reading a value:
91 ///
92 /// **⚠️ The following code is in c ⚠️**
93 ///
94 /// ```c
95 /// g_autoptr(GError) error = NULL;
96 /// g_autoptr(GKeyFile) key_file = g_key_file_new ();
97 ///
98 /// if (!g_key_file_load_from_file (key_file, "key-file.ini", flags, &error))
99 /// {
100 /// if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
101 /// g_warning ("Error loading key file: %s", error->message);
102 /// return;
103 /// }
104 ///
105 /// g_autofree gchar *val = g_key_file_get_string (key_file, "Group Name", "SomeKey", &error);
106 /// if (val == NULL &&
107 /// !g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
108 /// {
109 /// g_warning ("Error finding key in key file: %s", error->message);
110 /// return;
111 /// }
112 /// else if (val == NULL)
113 /// {
114 /// // Fall back to a default value.
115 /// val = g_strdup ("default-value");
116 /// }
117 /// ```
118 ///
119 /// Here is an example of creating and saving a key file:
120 ///
121 /// **⚠️ The following code is in c ⚠️**
122 ///
123 /// ```c
124 /// g_autoptr(GKeyFile) key_file = g_key_file_new ();
125 /// const gchar *val = …;
126 /// g_autoptr(GError) error = NULL;
127 ///
128 /// g_key_file_set_string (key_file, "Group Name", "SomeKey", val);
129 ///
130 /// // Save as a file.
131 /// if (!g_key_file_save_to_file (key_file, "key-file.ini", &error))
132 /// {
133 /// g_warning ("Error saving key file: %s", error->message);
134 /// return;
135 /// }
136 ///
137 /// // Or store to a GBytes for use elsewhere.
138 /// gsize data_len;
139 /// g_autofree guint8 *data = (guint8 *) g_key_file_to_data (key_file, &data_len, &error);
140 /// if (data == NULL)
141 /// {
142 /// g_warning ("Error saving key file: %s", error->message);
143 /// return;
144 /// }
145 /// g_autoptr(GBytes) bytes = g_bytes_new_take (g_steal_pointer (&data), data_len);
146 /// ```
147 // rustdoc-stripper-ignore-next-stop
148 /// `GKeyFile` parses .ini-like config files.
149 ///
150 /// `GKeyFile` lets you parse, edit or create files containing groups of
151 /// key-value pairs, which we call ‘key files’ for lack of a better name.
152 /// Several freedesktop.org specifications use key files. For example, the
153 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/)
154 /// and the [Icon Theme Specification](https://specifications.freedesktop.org/icon-theme-spec/latest/).
155 ///
156 /// The syntax of key files is described in detail in the
157 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
158 /// here is a quick summary: Key files consists of groups of key-value pairs, interspersed
159 /// with comments.
160 ///
161 /// **⚠️ The following code is in txt ⚠️**
162 ///
163 /// ```txt
164 /// # this is just an example
165 /// # there can be comments before the first group
166 ///
167 /// [First Group]
168 ///
169 /// Name=Key File Example\tthis value shows\nescaping
170 ///
171 /// # localized strings are stored in multiple key-value pairs
172 /// Welcome=Hello
173 /// Welcome[de]=Hallo
174 /// Welcome[fr_FR]=Bonjour
175 /// Welcome[it]=Ciao
176 ///
177 /// [Another Group]
178 ///
179 /// Numbers=2;20;-200;0
180 ///
181 /// Booleans=true;false;true;true
182 /// ```
183 ///
184 /// Lines beginning with a `#` and blank lines are considered comments.
185 ///
186 /// Groups are started by a header line containing the group name enclosed
187 /// in `[` and `]`, and ended implicitly by the start of the next group or
188 /// the end of the file. Each key-value pair must be contained in a group.
189 ///
190 /// Key-value pairs generally have the form `key=value`, with the exception
191 /// of localized strings, which have the form `key[locale]=value`, with a
192 /// locale identifier of the form `lang_COUNTRY@MODIFIER` where `COUNTRY`
193 /// and `MODIFIER` are optional. As a special case, the locale `C` is associated
194 /// with the untranslated pair `key=value` (since GLib 2.84). Space before and
195 /// after the `=` character is ignored. Newline, tab, carriage return and
196 /// backslash characters in value are escaped as `\n`, `\t`, `\r`, and `\\\\`,
197 /// respectively. To preserve leading spaces in values, these can also be escaped
198 /// as `\s`.
199 ///
200 /// Key files can store strings (possibly with localized variants), integers,
201 /// booleans and lists of these. Lists are separated by a separator character,
202 /// typically `;` or `,`. To use the list separator character in a value in
203 /// a list, it has to be escaped by prefixing it with a backslash.
204 ///
205 /// This syntax is obviously inspired by the .ini files commonly met
206 /// on Windows, but there are some important differences:
207 ///
208 /// - .ini files use the `;` character to begin comments,
209 /// key files use the `#` character.
210 ///
211 /// - Key files do not allow for ungrouped keys meaning only
212 /// comments can precede the first group.
213 ///
214 /// - Key files are always encoded in UTF-8.
215 ///
216 /// - Key and Group names are case-sensitive. For example, a group called
217 /// `[GROUP]` is a different from `[group]`.
218 ///
219 /// - .ini files don’t have a strongly typed boolean entry type,
220 /// they only have `GetProfileInt()`. In key files, only
221 /// `true` and `false` (in lower case) are allowed.
222 ///
223 /// Note that in contrast to the
224 /// [Desktop Entry Specification](https://specifications.freedesktop.org/desktop-entry-spec/latest/),
225 /// groups in key files may contain the same key multiple times; the last entry wins.
226 /// Key files may also contain multiple groups with the same name; they are merged
227 /// together. Another difference is that keys and group names in key files are not
228 /// restricted to ASCII characters.
229 ///
230 /// Here is an example of loading a key file and reading a value:
231 ///
232 /// **⚠️ The following code is in c ⚠️**
233 ///
234 /// ```c
235 /// g_autoptr(GError) error = NULL;
236 /// g_autoptr(GKeyFile) key_file = g_key_file_new ();
237 ///
238 /// if (!g_key_file_load_from_file (key_file, "key-file.ini", flags, &error))
239 /// {
240 /// if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
241 /// g_warning ("Error loading key file: %s", error->message);
242 /// return;
243 /// }
244 ///
245 /// g_autofree gchar *val = g_key_file_get_string (key_file, "Group Name", "SomeKey", &error);
246 /// if (val == NULL &&
247 /// !g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
248 /// {
249 /// g_warning ("Error finding key in key file: %s", error->message);
250 /// return;
251 /// }
252 /// else if (val == NULL)
253 /// {
254 /// // Fall back to a default value.
255 /// val = g_strdup ("default-value");
256 /// }
257 /// ```
258 ///
259 /// Here is an example of creating and saving a key file:
260 ///
261 /// **⚠️ The following code is in c ⚠️**
262 ///
263 /// ```c
264 /// g_autoptr(GKeyFile) key_file = g_key_file_new ();
265 /// const gchar *val = …;
266 /// g_autoptr(GError) error = NULL;
267 ///
268 /// g_key_file_set_string (key_file, "Group Name", "SomeKey", val);
269 ///
270 /// // Save as a file.
271 /// if (!g_key_file_save_to_file (key_file, "key-file.ini", &error))
272 /// {
273 /// g_warning ("Error saving key file: %s", error->message);
274 /// return;
275 /// }
276 ///
277 /// // Or store to a GBytes for use elsewhere.
278 /// gsize data_len;
279 /// g_autofree guint8 *data = (guint8 *) g_key_file_to_data (key_file, &data_len, &error);
280 /// if (data == NULL)
281 /// {
282 /// g_warning ("Error saving key file: %s", error->message);
283 /// return;
284 /// }
285 /// g_autoptr(GBytes) bytes = g_bytes_new_take (g_steal_pointer (&data), data_len);
286 /// ```
287 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
288 pub struct KeyFile(Shared<ffi::GKeyFile>);
289
290 match fn {
291 ref => |ptr| ffi::g_key_file_ref(ptr),
292 unref => |ptr| ffi::g_key_file_unref(ptr),
293 type_ => || ffi::g_key_file_get_type(),
294 }
295}
296
297impl KeyFile {
298 /// Creates a new empty [`KeyFile`][crate::KeyFile] object.
299 ///
300 /// Use [`load_from_file()`][Self::load_from_file()],
301 /// [`load_from_data()`][Self::load_from_data()], [`load_from_dirs()`][Self::load_from_dirs()] or
302 /// [`load_from_data_dirs()`][Self::load_from_data_dirs()] to
303 /// read an existing key file.
304 ///
305 /// # Returns
306 ///
307 /// an empty [`KeyFile`][crate::KeyFile].
308 // rustdoc-stripper-ignore-next-stop
309 /// Creates a new empty [`KeyFile`][crate::KeyFile] object.
310 ///
311 /// Use [`load_from_file()`][Self::load_from_file()],
312 /// [`load_from_data()`][Self::load_from_data()], [`load_from_dirs()`][Self::load_from_dirs()] or
313 /// [`load_from_data_dirs()`][Self::load_from_data_dirs()] to
314 /// read an existing key file.
315 ///
316 /// # Returns
317 ///
318 /// an empty [`KeyFile`][crate::KeyFile].
319 #[doc(alias = "g_key_file_new")]
320 pub fn new() -> KeyFile {
321 unsafe { from_glib_full(ffi::g_key_file_new()) }
322 }
323
324 /// Retrieves a comment above @key from @group_name.
325 ///
326 /// If @key is `NULL` then @comment will be read from above
327 /// @group_name. If both @key and @group_name are `NULL`, then
328 /// @comment will be read from above the first group in the file.
329 ///
330 /// Note that the returned string does not include the `#` comment markers,
331 /// but does include any whitespace after them (on each line). It includes
332 /// the line breaks between lines, but does not include the final line break.
333 /// ## `group_name`
334 /// a group name, or `NULL` to get a top-level comment
335 /// ## `key`
336 /// a key, or `NULL` to get a group comment
337 ///
338 /// # Returns
339 ///
340 /// a comment that should be freed with `free()`
341 // rustdoc-stripper-ignore-next-stop
342 /// Retrieves a comment above @key from @group_name.
343 ///
344 /// If @key is `NULL` then @comment will be read from above
345 /// @group_name. If both @key and @group_name are `NULL`, then
346 /// @comment will be read from above the first group in the file.
347 ///
348 /// Note that the returned string does not include the `#` comment markers,
349 /// but does include any whitespace after them (on each line). It includes
350 /// the line breaks between lines, but does not include the final line break.
351 /// ## `group_name`
352 /// a group name, or `NULL` to get a top-level comment
353 /// ## `key`
354 /// a key, or `NULL` to get a group comment
355 ///
356 /// # Returns
357 ///
358 /// a comment that should be freed with `free()`
359 #[doc(alias = "g_key_file_get_comment")]
360 #[doc(alias = "get_comment")]
361 pub fn comment(
362 &self,
363 group_name: Option<&str>,
364 key: Option<&str>,
365 ) -> Result<crate::GString, crate::Error> {
366 unsafe {
367 let mut error = std::ptr::null_mut();
368 let ret = ffi::g_key_file_get_comment(
369 self.to_glib_none().0,
370 group_name.to_glib_none().0,
371 key.to_glib_none().0,
372 &mut error,
373 );
374 if error.is_null() {
375 Ok(from_glib_full(ret))
376 } else {
377 Err(from_glib_full(error))
378 }
379 }
380 }
381
382 /// Returns the value associated with @key under @group_name as a double.
383 ///
384 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
385 /// returned. Likewise, if the value associated with @key cannot be interpreted
386 /// as a double then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
387 /// ## `group_name`
388 /// a group name
389 /// ## `key`
390 /// a key
391 ///
392 /// # Returns
393 ///
394 /// the value associated with the key as a double, or
395 /// `0.0` if the key was not found or could not be parsed.
396 // rustdoc-stripper-ignore-next-stop
397 /// Returns the value associated with @key under @group_name as a double.
398 ///
399 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
400 /// returned. Likewise, if the value associated with @key cannot be interpreted
401 /// as a double then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
402 /// ## `group_name`
403 /// a group name
404 /// ## `key`
405 /// a key
406 ///
407 /// # Returns
408 ///
409 /// the value associated with the key as a double, or
410 /// `0.0` if the key was not found or could not be parsed.
411 #[doc(alias = "g_key_file_get_double")]
412 #[doc(alias = "get_double")]
413 pub fn double(&self, group_name: &str, key: &str) -> Result<f64, crate::Error> {
414 unsafe {
415 let mut error = std::ptr::null_mut();
416 let ret = ffi::g_key_file_get_double(
417 self.to_glib_none().0,
418 group_name.to_glib_none().0,
419 key.to_glib_none().0,
420 &mut error,
421 );
422 if error.is_null() {
423 Ok(ret)
424 } else {
425 Err(from_glib_full(error))
426 }
427 }
428 }
429
430 /// Returns the values associated with @key under @group_name as
431 /// doubles.
432 ///
433 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
434 /// returned. Likewise, if the values associated with @key cannot be interpreted
435 /// as doubles then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
436 /// ## `group_name`
437 /// a group name
438 /// ## `key`
439 /// a key
440 ///
441 /// # Returns
442 ///
443 ///
444 /// the values associated with the key as a list of doubles, or `NULL` if the
445 /// key was not found or could not be parsed. The returned list of doubles
446 /// should be freed with `free()` when no longer needed.
447 // rustdoc-stripper-ignore-next-stop
448 /// Returns the values associated with @key under @group_name as
449 /// doubles.
450 ///
451 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
452 /// returned. Likewise, if the values associated with @key cannot be interpreted
453 /// as doubles then [error@GLib.KeyFileError.INVALID_VALUE] is returned.
454 /// ## `group_name`
455 /// a group name
456 /// ## `key`
457 /// a key
458 ///
459 /// # Returns
460 ///
461 ///
462 /// the values associated with the key as a list of doubles, or `NULL` if the
463 /// key was not found or could not be parsed. The returned list of doubles
464 /// should be freed with `free()` when no longer needed.
465 #[doc(alias = "g_key_file_get_double_list")]
466 #[doc(alias = "get_double_list")]
467 pub fn double_list(&self, group_name: &str, key: &str) -> Result<Vec<f64>, crate::Error> {
468 unsafe {
469 let mut length = std::mem::MaybeUninit::uninit();
470 let mut error = std::ptr::null_mut();
471 let ret = ffi::g_key_file_get_double_list(
472 self.to_glib_none().0,
473 group_name.to_glib_none().0,
474 key.to_glib_none().0,
475 length.as_mut_ptr(),
476 &mut error,
477 );
478 if error.is_null() {
479 Ok(FromGlibContainer::from_glib_container_num(
480 ret,
481 length.assume_init() as _,
482 ))
483 } else {
484 Err(from_glib_full(error))
485 }
486 }
487 }
488
489 /// Returns the value associated with @key under @group_name as a signed
490 /// 64-bit integer.
491 ///
492 /// This is similar to [`integer()`][Self::integer()] but can return
493 /// 64-bit results without truncation.
494 /// ## `group_name`
495 /// a group name
496 /// ## `key`
497 /// a key
498 ///
499 /// # Returns
500 ///
501 /// the value associated with the key as a signed 64-bit integer, or
502 /// `0` if the key was not found or could not be parsed.
503 // rustdoc-stripper-ignore-next-stop
504 /// Returns the value associated with @key under @group_name as a signed
505 /// 64-bit integer.
506 ///
507 /// This is similar to [`integer()`][Self::integer()] but can return
508 /// 64-bit results without truncation.
509 /// ## `group_name`
510 /// a group name
511 /// ## `key`
512 /// a key
513 ///
514 /// # Returns
515 ///
516 /// the value associated with the key as a signed 64-bit integer, or
517 /// `0` if the key was not found or could not be parsed.
518 #[doc(alias = "g_key_file_get_int64")]
519 #[doc(alias = "get_int64")]
520 pub fn int64(&self, group_name: &str, key: &str) -> Result<i64, crate::Error> {
521 unsafe {
522 let mut error = std::ptr::null_mut();
523 let ret = ffi::g_key_file_get_int64(
524 self.to_glib_none().0,
525 group_name.to_glib_none().0,
526 key.to_glib_none().0,
527 &mut error,
528 );
529 if error.is_null() {
530 Ok(ret)
531 } else {
532 Err(from_glib_full(error))
533 }
534 }
535 }
536
537 /// Returns the value associated with @key under @group_name as an
538 /// integer.
539 ///
540 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
541 /// returned. Likewise, if the value associated with @key cannot be interpreted
542 /// as an integer, or is out of range for a `gint`, then
543 /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
544 /// ## `group_name`
545 /// a group name
546 /// ## `key`
547 /// a key
548 ///
549 /// # Returns
550 ///
551 /// the value associated with the key as an integer, or
552 /// `0` if the key was not found or could not be parsed.
553 // rustdoc-stripper-ignore-next-stop
554 /// Returns the value associated with @key under @group_name as an
555 /// integer.
556 ///
557 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
558 /// returned. Likewise, if the value associated with @key cannot be interpreted
559 /// as an integer, or is out of range for a `gint`, then
560 /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
561 /// ## `group_name`
562 /// a group name
563 /// ## `key`
564 /// a key
565 ///
566 /// # Returns
567 ///
568 /// the value associated with the key as an integer, or
569 /// `0` if the key was not found or could not be parsed.
570 #[doc(alias = "g_key_file_get_integer")]
571 #[doc(alias = "get_integer")]
572 pub fn integer(&self, group_name: &str, key: &str) -> Result<i32, crate::Error> {
573 unsafe {
574 let mut error = std::ptr::null_mut();
575 let ret = ffi::g_key_file_get_integer(
576 self.to_glib_none().0,
577 group_name.to_glib_none().0,
578 key.to_glib_none().0,
579 &mut error,
580 );
581 if error.is_null() {
582 Ok(ret)
583 } else {
584 Err(from_glib_full(error))
585 }
586 }
587 }
588
589 /// Returns the values associated with @key under @group_name as
590 /// integers.
591 ///
592 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
593 /// returned. Likewise, if the values associated with @key cannot be interpreted
594 /// as integers, or are out of range for `gint`, then
595 /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
596 /// ## `group_name`
597 /// a group name
598 /// ## `key`
599 /// a key
600 ///
601 /// # Returns
602 ///
603 ///
604 /// the values associated with the key as a list of integers, or `NULL` if
605 /// the key was not found or could not be parsed. The returned list of
606 /// integers should be freed with `free()` when no longer needed.
607 // rustdoc-stripper-ignore-next-stop
608 /// Returns the values associated with @key under @group_name as
609 /// integers.
610 ///
611 /// If @key cannot be found then [error@GLib.KeyFileError.KEY_NOT_FOUND] is
612 /// returned. Likewise, if the values associated with @key cannot be interpreted
613 /// as integers, or are out of range for `gint`, then
614 /// [error@GLib.KeyFileError.INVALID_VALUE] is returned.
615 /// ## `group_name`
616 /// a group name
617 /// ## `key`
618 /// a key
619 ///
620 /// # Returns
621 ///
622 ///
623 /// the values associated with the key as a list of integers, or `NULL` if
624 /// the key was not found or could not be parsed. The returned list of
625 /// integers should be freed with `free()` when no longer needed.
626 #[doc(alias = "g_key_file_get_integer_list")]
627 #[doc(alias = "get_integer_list")]
628 pub fn integer_list(&self, group_name: &str, key: &str) -> Result<Vec<i32>, crate::Error> {
629 unsafe {
630 let mut length = std::mem::MaybeUninit::uninit();
631 let mut error = std::ptr::null_mut();
632 let ret = ffi::g_key_file_get_integer_list(
633 self.to_glib_none().0,
634 group_name.to_glib_none().0,
635 key.to_glib_none().0,
636 length.as_mut_ptr(),
637 &mut error,
638 );
639 if error.is_null() {
640 Ok(FromGlibContainer::from_glib_container_num(
641 ret,
642 length.assume_init() as _,
643 ))
644 } else {
645 Err(from_glib_full(error))
646 }
647 }
648 }
649
650 /// Returns the actual locale which the result of
651 /// [`locale_string()`][Self::locale_string()] or
652 /// [`locale_string_list()`][Self::locale_string_list()] came from.
653 ///
654 /// If calling [`locale_string()`][Self::locale_string()] or
655 /// [`locale_string_list()`][Self::locale_string_list()] with exactly the same @self,
656 /// @group_name, @key and @locale, the result of those functions will
657 /// have originally been tagged with the locale that is the result of
658 /// this function.
659 /// ## `group_name`
660 /// a group name
661 /// ## `key`
662 /// a key
663 /// ## `locale`
664 /// a locale identifier or `NULL` to use the current locale
665 ///
666 /// # Returns
667 ///
668 /// the locale from the file, or `NULL` if the key was not
669 /// found or the entry in the file was was untranslated
670 // rustdoc-stripper-ignore-next-stop
671 /// Returns the actual locale which the result of
672 /// [`locale_string()`][Self::locale_string()] or
673 /// [`locale_string_list()`][Self::locale_string_list()] came from.
674 ///
675 /// If calling [`locale_string()`][Self::locale_string()] or
676 /// [`locale_string_list()`][Self::locale_string_list()] with exactly the same @self,
677 /// @group_name, @key and @locale, the result of those functions will
678 /// have originally been tagged with the locale that is the result of
679 /// this function.
680 /// ## `group_name`
681 /// a group name
682 /// ## `key`
683 /// a key
684 /// ## `locale`
685 /// a locale identifier or `NULL` to use the current locale
686 ///
687 /// # Returns
688 ///
689 /// the locale from the file, or `NULL` if the key was not
690 /// found or the entry in the file was was untranslated
691 #[doc(alias = "g_key_file_get_locale_for_key")]
692 #[doc(alias = "get_locale_for_key")]
693 pub fn locale_for_key(
694 &self,
695 group_name: &str,
696 key: &str,
697 locale: Option<&str>,
698 ) -> Option<crate::GString> {
699 unsafe {
700 from_glib_full(ffi::g_key_file_get_locale_for_key(
701 self.to_glib_none().0,
702 group_name.to_glib_none().0,
703 key.to_glib_none().0,
704 locale.to_glib_none().0,
705 ))
706 }
707 }
708
709 /// Returns the name of the start group of the file.
710 ///
711 /// # Returns
712 ///
713 /// The start group of the key file.
714 // rustdoc-stripper-ignore-next-stop
715 /// Returns the name of the start group of the file.
716 ///
717 /// # Returns
718 ///
719 /// The start group of the key file.
720 #[doc(alias = "g_key_file_get_start_group")]
721 #[doc(alias = "get_start_group")]
722 pub fn start_group(&self) -> Option<crate::GString> {
723 unsafe { from_glib_full(ffi::g_key_file_get_start_group(self.to_glib_none().0)) }
724 }
725
726 /// Returns the value associated with @key under @group_name as an unsigned
727 /// 64-bit integer.
728 ///
729 /// This is similar to [`integer()`][Self::integer()] but can return
730 /// large positive results without truncation.
731 /// ## `group_name`
732 /// a group name
733 /// ## `key`
734 /// a key
735 ///
736 /// # Returns
737 ///
738 /// the value associated with the key as an unsigned 64-bit integer,
739 /// or `0` if the key was not found or could not be parsed.
740 // rustdoc-stripper-ignore-next-stop
741 /// Returns the value associated with @key under @group_name as an unsigned
742 /// 64-bit integer.
743 ///
744 /// This is similar to [`integer()`][Self::integer()] but can return
745 /// large positive results without truncation.
746 /// ## `group_name`
747 /// a group name
748 /// ## `key`
749 /// a key
750 ///
751 /// # Returns
752 ///
753 /// the value associated with the key as an unsigned 64-bit integer,
754 /// or `0` if the key was not found or could not be parsed.
755 #[doc(alias = "g_key_file_get_uint64")]
756 #[doc(alias = "get_uint64")]
757 pub fn uint64(&self, group_name: &str, key: &str) -> Result<u64, crate::Error> {
758 unsafe {
759 let mut error = std::ptr::null_mut();
760 let ret = ffi::g_key_file_get_uint64(
761 self.to_glib_none().0,
762 group_name.to_glib_none().0,
763 key.to_glib_none().0,
764 &mut error,
765 );
766 if error.is_null() {
767 Ok(ret)
768 } else {
769 Err(from_glib_full(error))
770 }
771 }
772 }
773
774 /// Returns the raw value associated with @key under @group_name.
775 ///
776 /// Use [`string()`][Self::string()] to retrieve an unescaped UTF-8 string.
777 ///
778 /// If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND]
779 /// is returned. If the @group_name cannot be found,
780 /// [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
781 /// ## `group_name`
782 /// a group name
783 /// ## `key`
784 /// a key
785 ///
786 /// # Returns
787 ///
788 /// a newly allocated string or `NULL` if the specified
789 /// key cannot be found.
790 // rustdoc-stripper-ignore-next-stop
791 /// Returns the raw value associated with @key under @group_name.
792 ///
793 /// Use [`string()`][Self::string()] to retrieve an unescaped UTF-8 string.
794 ///
795 /// If the key cannot be found, [error@GLib.KeyFileError.KEY_NOT_FOUND]
796 /// is returned. If the @group_name cannot be found,
797 /// [error@GLib.KeyFileError.GROUP_NOT_FOUND] is returned.
798 /// ## `group_name`
799 /// a group name
800 /// ## `key`
801 /// a key
802 ///
803 /// # Returns
804 ///
805 /// a newly allocated string or `NULL` if the specified
806 /// key cannot be found.
807 #[doc(alias = "g_key_file_get_value")]
808 #[doc(alias = "get_value")]
809 pub fn value(&self, group_name: &str, key: &str) -> Result<crate::GString, crate::Error> {
810 unsafe {
811 let mut error = std::ptr::null_mut();
812 let ret = ffi::g_key_file_get_value(
813 self.to_glib_none().0,
814 group_name.to_glib_none().0,
815 key.to_glib_none().0,
816 &mut error,
817 );
818 if error.is_null() {
819 Ok(from_glib_full(ret))
820 } else {
821 Err(from_glib_full(error))
822 }
823 }
824 }
825
826 /// Looks whether the key file has the group @group_name.
827 /// ## `group_name`
828 /// a group name
829 ///
830 /// # Returns
831 ///
832 /// true if @group_name is a part of @self, false otherwise.
833 // rustdoc-stripper-ignore-next-stop
834 /// Looks whether the key file has the group @group_name.
835 /// ## `group_name`
836 /// a group name
837 ///
838 /// # Returns
839 ///
840 /// true if @group_name is a part of @self, false otherwise.
841 #[doc(alias = "g_key_file_has_group")]
842 pub fn has_group(&self, group_name: &str) -> bool {
843 unsafe {
844 from_glib(ffi::g_key_file_has_group(
845 self.to_glib_none().0,
846 group_name.to_glib_none().0,
847 ))
848 }
849 }
850
851 /// Loads a key file from the data in @bytes into an empty [`KeyFile`][crate::KeyFile]
852 /// structure.
853 ///
854 /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
855 /// ## `bytes`
856 /// a [`Bytes`][crate::Bytes]
857 /// ## `flags`
858 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
859 ///
860 /// # Returns
861 ///
862 /// true if a key file could be loaded, false otherwise
863 // rustdoc-stripper-ignore-next-stop
864 /// Loads a key file from the data in @bytes into an empty [`KeyFile`][crate::KeyFile]
865 /// structure.
866 ///
867 /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
868 /// ## `bytes`
869 /// a [`Bytes`][crate::Bytes]
870 /// ## `flags`
871 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
872 ///
873 /// # Returns
874 ///
875 /// true if a key file could be loaded, false otherwise
876 #[doc(alias = "g_key_file_load_from_bytes")]
877 pub fn load_from_bytes(&self, bytes: &Bytes, flags: KeyFileFlags) -> Result<(), crate::Error> {
878 unsafe {
879 let mut error = std::ptr::null_mut();
880 let is_ok = ffi::g_key_file_load_from_bytes(
881 self.to_glib_none().0,
882 bytes.to_glib_none().0,
883 flags.into_glib(),
884 &mut error,
885 );
886 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
887 if error.is_null() {
888 Ok(())
889 } else {
890 Err(from_glib_full(error))
891 }
892 }
893 }
894
895 /// Loads a key file from memory into an empty [`KeyFile`][crate::KeyFile] structure.
896 ///
897 /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
898 /// ## `data`
899 /// key file loaded in memory
900 /// ## `length`
901 /// the length of @data in bytes (or `(gsize)-1` if data is nul-terminated)
902 /// ## `flags`
903 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
904 ///
905 /// # Returns
906 ///
907 /// true if a key file could be loaded, false otherwise
908 // rustdoc-stripper-ignore-next-stop
909 /// Loads a key file from memory into an empty [`KeyFile`][crate::KeyFile] structure.
910 ///
911 /// If the object cannot be created then a [`KeyFileError`][crate::KeyFileError] is returned.
912 /// ## `data`
913 /// key file loaded in memory
914 /// ## `length`
915 /// the length of @data in bytes (or `(gsize)-1` if data is nul-terminated)
916 /// ## `flags`
917 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
918 ///
919 /// # Returns
920 ///
921 /// true if a key file could be loaded, false otherwise
922 #[doc(alias = "g_key_file_load_from_data")]
923 pub fn load_from_data(&self, data: &str, flags: KeyFileFlags) -> Result<(), crate::Error> {
924 let length = data.len() as _;
925 unsafe {
926 let mut error = std::ptr::null_mut();
927 let is_ok = ffi::g_key_file_load_from_data(
928 self.to_glib_none().0,
929 data.to_glib_none().0,
930 length,
931 flags.into_glib(),
932 &mut error,
933 );
934 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
935 if error.is_null() {
936 Ok(())
937 } else {
938 Err(from_glib_full(error))
939 }
940 }
941 }
942
943 /// Loads a key file into an empty [`KeyFile`][crate::KeyFile] structure.
944 ///
945 /// If the OS returns an error when opening or reading the file, a
946 /// [`FileError`][crate::FileError] is returned. If there is a problem parsing the file,
947 /// a [`KeyFileError`][crate::KeyFileError] is returned.
948 ///
949 /// This function will never return a [error@GLib.KeyFileError.NOT_FOUND]
950 /// error. If the @file is not found, [error@GLib.FileError.NOENT] is returned.
951 /// ## `file`
952 /// the path of a filename to load, in the GLib filename encoding
953 /// ## `flags`
954 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
955 ///
956 /// # Returns
957 ///
958 /// true if a key file could be loaded, false otherwise
959 // rustdoc-stripper-ignore-next-stop
960 /// Loads a key file into an empty [`KeyFile`][crate::KeyFile] structure.
961 ///
962 /// If the OS returns an error when opening or reading the file, a
963 /// [`FileError`][crate::FileError] is returned. If there is a problem parsing the file,
964 /// a [`KeyFileError`][crate::KeyFileError] is returned.
965 ///
966 /// This function will never return a [error@GLib.KeyFileError.NOT_FOUND]
967 /// error. If the @file is not found, [error@GLib.FileError.NOENT] is returned.
968 /// ## `file`
969 /// the path of a filename to load, in the GLib filename encoding
970 /// ## `flags`
971 /// flags from [`KeyFileFlags`][crate::KeyFileFlags]
972 ///
973 /// # Returns
974 ///
975 /// true if a key file could be loaded, false otherwise
976 #[doc(alias = "g_key_file_load_from_file")]
977 pub fn load_from_file(
978 &self,
979 file: impl AsRef<std::path::Path>,
980 flags: KeyFileFlags,
981 ) -> Result<(), crate::Error> {
982 unsafe {
983 let mut error = std::ptr::null_mut();
984 let is_ok = ffi::g_key_file_load_from_file(
985 self.to_glib_none().0,
986 file.as_ref().to_glib_none().0,
987 flags.into_glib(),
988 &mut error,
989 );
990 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
991 if error.is_null() {
992 Ok(())
993 } else {
994 Err(from_glib_full(error))
995 }
996 }
997 }
998
999 /// Removes a comment above @key from @group_name.
1000 ///
1001 /// If @key is `NULL` then @comment will be removed above @group_name.
1002 /// If both @key and @group_name are `NULL`, then @comment will
1003 /// be removed above the first group in the file.
1004 /// ## `group_name`
1005 /// a group name, or `NULL` to get a top-level comment
1006 /// ## `key`
1007 /// a key, or `NULL` to get a group comment
1008 ///
1009 /// # Returns
1010 ///
1011 /// true if the comment was removed, false otherwise
1012 // rustdoc-stripper-ignore-next-stop
1013 /// Removes a comment above @key from @group_name.
1014 ///
1015 /// If @key is `NULL` then @comment will be removed above @group_name.
1016 /// If both @key and @group_name are `NULL`, then @comment will
1017 /// be removed above the first group in the file.
1018 /// ## `group_name`
1019 /// a group name, or `NULL` to get a top-level comment
1020 /// ## `key`
1021 /// a key, or `NULL` to get a group comment
1022 ///
1023 /// # Returns
1024 ///
1025 /// true if the comment was removed, false otherwise
1026 #[doc(alias = "g_key_file_remove_comment")]
1027 pub fn remove_comment(
1028 &self,
1029 group_name: Option<&str>,
1030 key: Option<&str>,
1031 ) -> Result<(), crate::Error> {
1032 unsafe {
1033 let mut error = std::ptr::null_mut();
1034 let is_ok = ffi::g_key_file_remove_comment(
1035 self.to_glib_none().0,
1036 group_name.to_glib_none().0,
1037 key.to_glib_none().0,
1038 &mut error,
1039 );
1040 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1041 if error.is_null() {
1042 Ok(())
1043 } else {
1044 Err(from_glib_full(error))
1045 }
1046 }
1047 }
1048
1049 /// Removes the specified group, @group_name,
1050 /// from the key file.
1051 /// ## `group_name`
1052 /// a group name
1053 ///
1054 /// # Returns
1055 ///
1056 /// true if the group was removed, false otherwise
1057 // rustdoc-stripper-ignore-next-stop
1058 /// Removes the specified group, @group_name,
1059 /// from the key file.
1060 /// ## `group_name`
1061 /// a group name
1062 ///
1063 /// # Returns
1064 ///
1065 /// true if the group was removed, false otherwise
1066 #[doc(alias = "g_key_file_remove_group")]
1067 pub fn remove_group(&self, group_name: &str) -> Result<(), crate::Error> {
1068 unsafe {
1069 let mut error = std::ptr::null_mut();
1070 let is_ok = ffi::g_key_file_remove_group(
1071 self.to_glib_none().0,
1072 group_name.to_glib_none().0,
1073 &mut error,
1074 );
1075 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1076 if error.is_null() {
1077 Ok(())
1078 } else {
1079 Err(from_glib_full(error))
1080 }
1081 }
1082 }
1083
1084 /// Removes @key in @group_name from the key file.
1085 /// ## `group_name`
1086 /// a group name
1087 /// ## `key`
1088 /// a key name to remove
1089 ///
1090 /// # Returns
1091 ///
1092 /// true if the key was removed, false otherwise
1093 // rustdoc-stripper-ignore-next-stop
1094 /// Removes @key in @group_name from the key file.
1095 /// ## `group_name`
1096 /// a group name
1097 /// ## `key`
1098 /// a key name to remove
1099 ///
1100 /// # Returns
1101 ///
1102 /// true if the key was removed, false otherwise
1103 #[doc(alias = "g_key_file_remove_key")]
1104 pub fn remove_key(&self, group_name: &str, key: &str) -> Result<(), crate::Error> {
1105 unsafe {
1106 let mut error = std::ptr::null_mut();
1107 let is_ok = ffi::g_key_file_remove_key(
1108 self.to_glib_none().0,
1109 group_name.to_glib_none().0,
1110 key.to_glib_none().0,
1111 &mut error,
1112 );
1113 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1114 if error.is_null() {
1115 Ok(())
1116 } else {
1117 Err(from_glib_full(error))
1118 }
1119 }
1120 }
1121
1122 /// Associates a new boolean value with @key under @group_name.
1123 ///
1124 /// If @key cannot be found then it is created.
1125 /// ## `group_name`
1126 /// a group name
1127 /// ## `key`
1128 /// a key
1129 /// ## `value`
1130 /// true or false
1131 // rustdoc-stripper-ignore-next-stop
1132 /// Associates a new boolean value with @key under @group_name.
1133 ///
1134 /// If @key cannot be found then it is created.
1135 /// ## `group_name`
1136 /// a group name
1137 /// ## `key`
1138 /// a key
1139 /// ## `value`
1140 /// true or false
1141 #[doc(alias = "g_key_file_set_boolean")]
1142 pub fn set_boolean(&self, group_name: &str, key: &str, value: bool) {
1143 unsafe {
1144 ffi::g_key_file_set_boolean(
1145 self.to_glib_none().0,
1146 group_name.to_glib_none().0,
1147 key.to_glib_none().0,
1148 value.into_glib(),
1149 );
1150 }
1151 }
1152
1153 //#[doc(alias = "g_key_file_set_boolean_list")]
1154 //pub fn set_boolean_list(&self, group_name: &str, key: &str, list: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 1 }) {
1155 // unsafe { TODO: call ffi:g_key_file_set_boolean_list() }
1156 //}
1157
1158 /// Places a comment above @key from @group_name.
1159 ///
1160 /// If @key is `NULL` then @comment will be written above @group_name.
1161 /// If both @key and @group_name are `NULL`, then @comment will be
1162 /// written above the first group in the file.
1163 ///
1164 /// Note that this function prepends a `#` comment marker to
1165 /// each line of @comment.
1166 /// ## `group_name`
1167 /// a group name, or `NULL` to write a top-level comment
1168 /// ## `key`
1169 /// a key, or `NULL` to write a group comment
1170 /// ## `comment`
1171 /// a comment
1172 ///
1173 /// # Returns
1174 ///
1175 /// true if the comment was written, false otherwise
1176 // rustdoc-stripper-ignore-next-stop
1177 /// Places a comment above @key from @group_name.
1178 ///
1179 /// If @key is `NULL` then @comment will be written above @group_name.
1180 /// If both @key and @group_name are `NULL`, then @comment will be
1181 /// written above the first group in the file.
1182 ///
1183 /// Note that this function prepends a `#` comment marker to
1184 /// each line of @comment.
1185 /// ## `group_name`
1186 /// a group name, or `NULL` to write a top-level comment
1187 /// ## `key`
1188 /// a key, or `NULL` to write a group comment
1189 /// ## `comment`
1190 /// a comment
1191 ///
1192 /// # Returns
1193 ///
1194 /// true if the comment was written, false otherwise
1195 #[doc(alias = "g_key_file_set_comment")]
1196 pub fn set_comment(
1197 &self,
1198 group_name: Option<&str>,
1199 key: Option<&str>,
1200 comment: &str,
1201 ) -> Result<(), crate::Error> {
1202 unsafe {
1203 let mut error = std::ptr::null_mut();
1204 let is_ok = ffi::g_key_file_set_comment(
1205 self.to_glib_none().0,
1206 group_name.to_glib_none().0,
1207 key.to_glib_none().0,
1208 comment.to_glib_none().0,
1209 &mut error,
1210 );
1211 debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
1212 if error.is_null() {
1213 Ok(())
1214 } else {
1215 Err(from_glib_full(error))
1216 }
1217 }
1218 }
1219
1220 /// Associates a new double value with @key under @group_name.
1221 ///
1222 /// If @key cannot be found then it is created.
1223 /// ## `group_name`
1224 /// a group name
1225 /// ## `key`
1226 /// a key
1227 /// ## `value`
1228 /// a double value
1229 // rustdoc-stripper-ignore-next-stop
1230 /// Associates a new double value with @key under @group_name.
1231 ///
1232 /// If @key cannot be found then it is created.
1233 /// ## `group_name`
1234 /// a group name
1235 /// ## `key`
1236 /// a key
1237 /// ## `value`
1238 /// a double value
1239 #[doc(alias = "g_key_file_set_double")]
1240 pub fn set_double(&self, group_name: &str, key: &str, value: f64) {
1241 unsafe {
1242 ffi::g_key_file_set_double(
1243 self.to_glib_none().0,
1244 group_name.to_glib_none().0,
1245 key.to_glib_none().0,
1246 value,
1247 );
1248 }
1249 }
1250
1251 /// Associates a new integer value with @key under @group_name.
1252 ///
1253 /// If @key cannot be found then it is created.
1254 /// ## `group_name`
1255 /// a group name
1256 /// ## `key`
1257 /// a key
1258 /// ## `value`
1259 /// an integer value
1260 // rustdoc-stripper-ignore-next-stop
1261 /// Associates a new integer value with @key under @group_name.
1262 ///
1263 /// If @key cannot be found then it is created.
1264 /// ## `group_name`
1265 /// a group name
1266 /// ## `key`
1267 /// a key
1268 /// ## `value`
1269 /// an integer value
1270 #[doc(alias = "g_key_file_set_int64")]
1271 pub fn set_int64(&self, group_name: &str, key: &str, value: i64) {
1272 unsafe {
1273 ffi::g_key_file_set_int64(
1274 self.to_glib_none().0,
1275 group_name.to_glib_none().0,
1276 key.to_glib_none().0,
1277 value,
1278 );
1279 }
1280 }
1281
1282 /// Associates a new integer value with @key under @group_name.
1283 ///
1284 /// If @key cannot be found then it is created.
1285 /// ## `group_name`
1286 /// a group name
1287 /// ## `key`
1288 /// a key
1289 /// ## `value`
1290 /// an integer value
1291 // rustdoc-stripper-ignore-next-stop
1292 /// Associates a new integer value with @key under @group_name.
1293 ///
1294 /// If @key cannot be found then it is created.
1295 /// ## `group_name`
1296 /// a group name
1297 /// ## `key`
1298 /// a key
1299 /// ## `value`
1300 /// an integer value
1301 #[doc(alias = "g_key_file_set_integer")]
1302 pub fn set_integer(&self, group_name: &str, key: &str, value: i32) {
1303 unsafe {
1304 ffi::g_key_file_set_integer(
1305 self.to_glib_none().0,
1306 group_name.to_glib_none().0,
1307 key.to_glib_none().0,
1308 value,
1309 );
1310 }
1311 }
1312
1313 /// Sets the character which is used to separate values in lists.
1314 ///
1315 /// Typically `;` or `,` are used as separators. The default list separator
1316 /// is `;`.
1317 /// ## `separator`
1318 /// the separator
1319 // rustdoc-stripper-ignore-next-stop
1320 /// Sets the character which is used to separate values in lists.
1321 ///
1322 /// Typically `;` or `,` are used as separators. The default list separator
1323 /// is `;`.
1324 /// ## `separator`
1325 /// the separator
1326 #[doc(alias = "g_key_file_set_list_separator")]
1327 pub fn set_list_separator(&self, separator: crate::Char) {
1328 unsafe {
1329 ffi::g_key_file_set_list_separator(self.to_glib_none().0, separator.into_glib());
1330 }
1331 }
1332
1333 /// Associates a string value for @key and @locale under @group_name.
1334 ///
1335 /// If the translation for @key cannot be found then it is created.
1336 ///
1337 /// If @locale is `C` then the untranslated value is set (since GLib 2.84).
1338 /// ## `group_name`
1339 /// a group name
1340 /// ## `key`
1341 /// a key
1342 /// ## `locale`
1343 /// a locale identifier
1344 /// ## `string`
1345 /// a string
1346 // rustdoc-stripper-ignore-next-stop
1347 /// Associates a string value for @key and @locale under @group_name.
1348 ///
1349 /// If the translation for @key cannot be found then it is created.
1350 ///
1351 /// If @locale is `C` then the untranslated value is set (since GLib 2.84).
1352 /// ## `group_name`
1353 /// a group name
1354 /// ## `key`
1355 /// a key
1356 /// ## `locale`
1357 /// a locale identifier
1358 /// ## `string`
1359 /// a string
1360 #[doc(alias = "g_key_file_set_locale_string")]
1361 pub fn set_locale_string(&self, group_name: &str, key: &str, locale: &str, string: &str) {
1362 unsafe {
1363 ffi::g_key_file_set_locale_string(
1364 self.to_glib_none().0,
1365 group_name.to_glib_none().0,
1366 key.to_glib_none().0,
1367 locale.to_glib_none().0,
1368 string.to_glib_none().0,
1369 );
1370 }
1371 }
1372
1373 /// Associates a new string value with @key under @group_name.
1374 ///
1375 /// If @key cannot be found then it is created.
1376 /// If @group_name cannot be found then it is created.
1377 /// Unlike [`set_value()`][Self::set_value()], this function handles characters
1378 /// that need escaping, such as newlines.
1379 /// ## `group_name`
1380 /// a group name
1381 /// ## `key`
1382 /// a key
1383 /// ## `string`
1384 /// a string
1385 // rustdoc-stripper-ignore-next-stop
1386 /// Associates a new string value with @key under @group_name.
1387 ///
1388 /// If @key cannot be found then it is created.
1389 /// If @group_name cannot be found then it is created.
1390 /// Unlike [`set_value()`][Self::set_value()], this function handles characters
1391 /// that need escaping, such as newlines.
1392 /// ## `group_name`
1393 /// a group name
1394 /// ## `key`
1395 /// a key
1396 /// ## `string`
1397 /// a string
1398 #[doc(alias = "g_key_file_set_string")]
1399 pub fn set_string(&self, group_name: &str, key: &str, string: &str) {
1400 unsafe {
1401 ffi::g_key_file_set_string(
1402 self.to_glib_none().0,
1403 group_name.to_glib_none().0,
1404 key.to_glib_none().0,
1405 string.to_glib_none().0,
1406 );
1407 }
1408 }
1409
1410 /// Associates a new integer value with @key under @group_name.
1411 ///
1412 /// If @key cannot be found then it is created.
1413 /// ## `group_name`
1414 /// a group name
1415 /// ## `key`
1416 /// a key
1417 /// ## `value`
1418 /// an integer value
1419 // rustdoc-stripper-ignore-next-stop
1420 /// Associates a new integer value with @key under @group_name.
1421 ///
1422 /// If @key cannot be found then it is created.
1423 /// ## `group_name`
1424 /// a group name
1425 /// ## `key`
1426 /// a key
1427 /// ## `value`
1428 /// an integer value
1429 #[doc(alias = "g_key_file_set_uint64")]
1430 pub fn set_uint64(&self, group_name: &str, key: &str, value: u64) {
1431 unsafe {
1432 ffi::g_key_file_set_uint64(
1433 self.to_glib_none().0,
1434 group_name.to_glib_none().0,
1435 key.to_glib_none().0,
1436 value,
1437 );
1438 }
1439 }
1440
1441 /// Associates a new value with @key under @group_name.
1442 ///
1443 /// If @key cannot be found then it is created. If @group_name cannot
1444 /// be found then it is created. To set an UTF-8 string which may contain
1445 /// characters that need escaping (such as newlines or spaces), use
1446 /// [`set_string()`][Self::set_string()].
1447 /// ## `group_name`
1448 /// a group name
1449 /// ## `key`
1450 /// a key
1451 /// ## `value`
1452 /// a string
1453 // rustdoc-stripper-ignore-next-stop
1454 /// Associates a new value with @key under @group_name.
1455 ///
1456 /// If @key cannot be found then it is created. If @group_name cannot
1457 /// be found then it is created. To set an UTF-8 string which may contain
1458 /// characters that need escaping (such as newlines or spaces), use
1459 /// [`set_string()`][Self::set_string()].
1460 /// ## `group_name`
1461 /// a group name
1462 /// ## `key`
1463 /// a key
1464 /// ## `value`
1465 /// a string
1466 #[doc(alias = "g_key_file_set_value")]
1467 pub fn set_value(&self, group_name: &str, key: &str, value: &str) {
1468 unsafe {
1469 ffi::g_key_file_set_value(
1470 self.to_glib_none().0,
1471 group_name.to_glib_none().0,
1472 key.to_glib_none().0,
1473 value.to_glib_none().0,
1474 );
1475 }
1476 }
1477}
1478
1479impl Default for KeyFile {
1480 fn default() -> Self {
1481 Self::new()
1482 }
1483}