1 | // This file was generated by gir (https://github.com/gtk-rs/gir) |
2 | // from gir-files (https://github.com/gtk-rs/gir-files) |
3 | // DO NOT EDIT |
4 | |
5 | use crate::{translate::*, Bytes, Error, KeyFileFlags}; |
6 | use std::{mem, ptr}; |
7 | |
8 | crate::wrapper! { |
9 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
10 | pub struct KeyFile(Shared<ffi::GKeyFile>); |
11 | |
12 | match fn { |
13 | ref => |ptr| ffi::g_key_file_ref(ptr), |
14 | unref => |ptr| ffi::g_key_file_unref(ptr), |
15 | type_ => || ffi::g_key_file_get_type(), |
16 | } |
17 | } |
18 | |
19 | impl KeyFile { |
20 | #[doc (alias = "g_key_file_new" )] |
21 | pub fn new() -> KeyFile { |
22 | unsafe { from_glib_full(ffi::g_key_file_new()) } |
23 | } |
24 | |
25 | #[doc (alias = "g_key_file_get_comment" )] |
26 | #[doc (alias = "get_comment" )] |
27 | pub fn comment( |
28 | &self, |
29 | group_name: Option<&str>, |
30 | key: Option<&str>, |
31 | ) -> Result<crate::GString, crate::Error> { |
32 | unsafe { |
33 | let mut error = ptr::null_mut(); |
34 | let ret = ffi::g_key_file_get_comment( |
35 | self.to_glib_none().0, |
36 | group_name.to_glib_none().0, |
37 | key.to_glib_none().0, |
38 | &mut error, |
39 | ); |
40 | if error.is_null() { |
41 | Ok(from_glib_full(ret)) |
42 | } else { |
43 | Err(from_glib_full(error)) |
44 | } |
45 | } |
46 | } |
47 | |
48 | #[doc (alias = "g_key_file_get_double" )] |
49 | #[doc (alias = "get_double" )] |
50 | pub fn double(&self, group_name: &str, key: &str) -> Result<f64, crate::Error> { |
51 | unsafe { |
52 | let mut error = ptr::null_mut(); |
53 | let ret = ffi::g_key_file_get_double( |
54 | self.to_glib_none().0, |
55 | group_name.to_glib_none().0, |
56 | key.to_glib_none().0, |
57 | &mut error, |
58 | ); |
59 | if error.is_null() { |
60 | Ok(ret) |
61 | } else { |
62 | Err(from_glib_full(error)) |
63 | } |
64 | } |
65 | } |
66 | |
67 | #[doc (alias = "g_key_file_get_double_list" )] |
68 | #[doc (alias = "get_double_list" )] |
69 | pub fn double_list(&self, group_name: &str, key: &str) -> Result<Vec<f64>, crate::Error> { |
70 | unsafe { |
71 | let mut length = mem::MaybeUninit::uninit(); |
72 | let mut error = ptr::null_mut(); |
73 | let ret = ffi::g_key_file_get_double_list( |
74 | self.to_glib_none().0, |
75 | group_name.to_glib_none().0, |
76 | key.to_glib_none().0, |
77 | length.as_mut_ptr(), |
78 | &mut error, |
79 | ); |
80 | if error.is_null() { |
81 | Ok(FromGlibContainer::from_glib_container_num( |
82 | ret, |
83 | length.assume_init() as _, |
84 | )) |
85 | } else { |
86 | Err(from_glib_full(error)) |
87 | } |
88 | } |
89 | } |
90 | |
91 | #[doc (alias = "g_key_file_get_int64" )] |
92 | #[doc (alias = "get_int64" )] |
93 | pub fn int64(&self, group_name: &str, key: &str) -> Result<i64, crate::Error> { |
94 | unsafe { |
95 | let mut error = ptr::null_mut(); |
96 | let ret = ffi::g_key_file_get_int64( |
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 | #[doc (alias = "g_key_file_get_integer" )] |
111 | #[doc (alias = "get_integer" )] |
112 | pub fn integer(&self, group_name: &str, key: &str) -> Result<i32, crate::Error> { |
113 | unsafe { |
114 | let mut error = ptr::null_mut(); |
115 | let ret = ffi::g_key_file_get_integer( |
116 | self.to_glib_none().0, |
117 | group_name.to_glib_none().0, |
118 | key.to_glib_none().0, |
119 | &mut error, |
120 | ); |
121 | if error.is_null() { |
122 | Ok(ret) |
123 | } else { |
124 | Err(from_glib_full(error)) |
125 | } |
126 | } |
127 | } |
128 | |
129 | #[doc (alias = "g_key_file_get_integer_list" )] |
130 | #[doc (alias = "get_integer_list" )] |
131 | pub fn integer_list(&self, group_name: &str, key: &str) -> Result<Vec<i32>, crate::Error> { |
132 | unsafe { |
133 | let mut length = mem::MaybeUninit::uninit(); |
134 | let mut error = ptr::null_mut(); |
135 | let ret = ffi::g_key_file_get_integer_list( |
136 | self.to_glib_none().0, |
137 | group_name.to_glib_none().0, |
138 | key.to_glib_none().0, |
139 | length.as_mut_ptr(), |
140 | &mut error, |
141 | ); |
142 | if error.is_null() { |
143 | Ok(FromGlibContainer::from_glib_container_num( |
144 | ret, |
145 | length.assume_init() as _, |
146 | )) |
147 | } else { |
148 | Err(from_glib_full(error)) |
149 | } |
150 | } |
151 | } |
152 | |
153 | #[doc (alias = "g_key_file_get_locale_for_key" )] |
154 | #[doc (alias = "get_locale_for_key" )] |
155 | pub fn locale_for_key( |
156 | &self, |
157 | group_name: &str, |
158 | key: &str, |
159 | locale: Option<&str>, |
160 | ) -> Option<crate::GString> { |
161 | unsafe { |
162 | from_glib_full(ffi::g_key_file_get_locale_for_key( |
163 | self.to_glib_none().0, |
164 | group_name.to_glib_none().0, |
165 | key.to_glib_none().0, |
166 | locale.to_glib_none().0, |
167 | )) |
168 | } |
169 | } |
170 | |
171 | #[doc (alias = "g_key_file_get_start_group" )] |
172 | #[doc (alias = "get_start_group" )] |
173 | pub fn start_group(&self) -> Option<crate::GString> { |
174 | unsafe { from_glib_full(ffi::g_key_file_get_start_group(self.to_glib_none().0)) } |
175 | } |
176 | |
177 | #[doc (alias = "g_key_file_get_uint64" )] |
178 | #[doc (alias = "get_uint64" )] |
179 | pub fn uint64(&self, group_name: &str, key: &str) -> Result<u64, crate::Error> { |
180 | unsafe { |
181 | let mut error = ptr::null_mut(); |
182 | let ret = ffi::g_key_file_get_uint64( |
183 | self.to_glib_none().0, |
184 | group_name.to_glib_none().0, |
185 | key.to_glib_none().0, |
186 | &mut error, |
187 | ); |
188 | if error.is_null() { |
189 | Ok(ret) |
190 | } else { |
191 | Err(from_glib_full(error)) |
192 | } |
193 | } |
194 | } |
195 | |
196 | #[doc (alias = "g_key_file_get_value" )] |
197 | #[doc (alias = "get_value" )] |
198 | pub fn value(&self, group_name: &str, key: &str) -> Result<crate::GString, crate::Error> { |
199 | unsafe { |
200 | let mut error = ptr::null_mut(); |
201 | let ret = ffi::g_key_file_get_value( |
202 | self.to_glib_none().0, |
203 | group_name.to_glib_none().0, |
204 | key.to_glib_none().0, |
205 | &mut error, |
206 | ); |
207 | if error.is_null() { |
208 | Ok(from_glib_full(ret)) |
209 | } else { |
210 | Err(from_glib_full(error)) |
211 | } |
212 | } |
213 | } |
214 | |
215 | #[doc (alias = "g_key_file_has_group" )] |
216 | pub fn has_group(&self, group_name: &str) -> bool { |
217 | unsafe { |
218 | from_glib(ffi::g_key_file_has_group( |
219 | self.to_glib_none().0, |
220 | group_name.to_glib_none().0, |
221 | )) |
222 | } |
223 | } |
224 | |
225 | #[doc (alias = "g_key_file_load_from_bytes" )] |
226 | pub fn load_from_bytes(&self, bytes: &Bytes, flags: KeyFileFlags) -> Result<(), crate::Error> { |
227 | unsafe { |
228 | let mut error = ptr::null_mut(); |
229 | let is_ok = ffi::g_key_file_load_from_bytes( |
230 | self.to_glib_none().0, |
231 | bytes.to_glib_none().0, |
232 | flags.into_glib(), |
233 | &mut error, |
234 | ); |
235 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
236 | if error.is_null() { |
237 | Ok(()) |
238 | } else { |
239 | Err(from_glib_full(error)) |
240 | } |
241 | } |
242 | } |
243 | |
244 | #[doc (alias = "g_key_file_load_from_data" )] |
245 | pub fn load_from_data(&self, data: &str, flags: KeyFileFlags) -> Result<(), crate::Error> { |
246 | let length = data.len() as _; |
247 | unsafe { |
248 | let mut error = ptr::null_mut(); |
249 | let is_ok = ffi::g_key_file_load_from_data( |
250 | self.to_glib_none().0, |
251 | data.to_glib_none().0, |
252 | length, |
253 | flags.into_glib(), |
254 | &mut error, |
255 | ); |
256 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
257 | if error.is_null() { |
258 | Ok(()) |
259 | } else { |
260 | Err(from_glib_full(error)) |
261 | } |
262 | } |
263 | } |
264 | |
265 | #[doc (alias = "g_key_file_load_from_file" )] |
266 | pub fn load_from_file( |
267 | &self, |
268 | file: impl AsRef<std::path::Path>, |
269 | flags: KeyFileFlags, |
270 | ) -> Result<(), crate::Error> { |
271 | unsafe { |
272 | let mut error = ptr::null_mut(); |
273 | let is_ok = ffi::g_key_file_load_from_file( |
274 | self.to_glib_none().0, |
275 | file.as_ref().to_glib_none().0, |
276 | flags.into_glib(), |
277 | &mut error, |
278 | ); |
279 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
280 | if error.is_null() { |
281 | Ok(()) |
282 | } else { |
283 | Err(from_glib_full(error)) |
284 | } |
285 | } |
286 | } |
287 | |
288 | #[doc (alias = "g_key_file_remove_comment" )] |
289 | pub fn remove_comment( |
290 | &self, |
291 | group_name: Option<&str>, |
292 | key: Option<&str>, |
293 | ) -> Result<(), crate::Error> { |
294 | unsafe { |
295 | let mut error = ptr::null_mut(); |
296 | let is_ok = ffi::g_key_file_remove_comment( |
297 | self.to_glib_none().0, |
298 | group_name.to_glib_none().0, |
299 | key.to_glib_none().0, |
300 | &mut error, |
301 | ); |
302 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
303 | if error.is_null() { |
304 | Ok(()) |
305 | } else { |
306 | Err(from_glib_full(error)) |
307 | } |
308 | } |
309 | } |
310 | |
311 | #[doc (alias = "g_key_file_remove_group" )] |
312 | pub fn remove_group(&self, group_name: &str) -> Result<(), crate::Error> { |
313 | unsafe { |
314 | let mut error = ptr::null_mut(); |
315 | let is_ok = ffi::g_key_file_remove_group( |
316 | self.to_glib_none().0, |
317 | group_name.to_glib_none().0, |
318 | &mut error, |
319 | ); |
320 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
321 | if error.is_null() { |
322 | Ok(()) |
323 | } else { |
324 | Err(from_glib_full(error)) |
325 | } |
326 | } |
327 | } |
328 | |
329 | #[doc (alias = "g_key_file_remove_key" )] |
330 | pub fn remove_key(&self, group_name: &str, key: &str) -> Result<(), crate::Error> { |
331 | unsafe { |
332 | let mut error = ptr::null_mut(); |
333 | let is_ok = ffi::g_key_file_remove_key( |
334 | self.to_glib_none().0, |
335 | group_name.to_glib_none().0, |
336 | key.to_glib_none().0, |
337 | &mut error, |
338 | ); |
339 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
340 | if error.is_null() { |
341 | Ok(()) |
342 | } else { |
343 | Err(from_glib_full(error)) |
344 | } |
345 | } |
346 | } |
347 | |
348 | #[doc (alias = "g_key_file_set_boolean" )] |
349 | pub fn set_boolean(&self, group_name: &str, key: &str, value: bool) { |
350 | unsafe { |
351 | ffi::g_key_file_set_boolean( |
352 | self.to_glib_none().0, |
353 | group_name.to_glib_none().0, |
354 | key.to_glib_none().0, |
355 | value.into_glib(), |
356 | ); |
357 | } |
358 | } |
359 | |
360 | //#[doc(alias = "g_key_file_set_boolean_list")] |
361 | //pub fn set_boolean_list(&self, group_name: &str, key: &str, list: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 1 }) { |
362 | // unsafe { TODO: call ffi:g_key_file_set_boolean_list() } |
363 | //} |
364 | |
365 | #[doc (alias = "g_key_file_set_comment" )] |
366 | pub fn set_comment( |
367 | &self, |
368 | group_name: Option<&str>, |
369 | key: Option<&str>, |
370 | comment: &str, |
371 | ) -> Result<(), crate::Error> { |
372 | unsafe { |
373 | let mut error = ptr::null_mut(); |
374 | let is_ok = ffi::g_key_file_set_comment( |
375 | self.to_glib_none().0, |
376 | group_name.to_glib_none().0, |
377 | key.to_glib_none().0, |
378 | comment.to_glib_none().0, |
379 | &mut error, |
380 | ); |
381 | debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null()); |
382 | if error.is_null() { |
383 | Ok(()) |
384 | } else { |
385 | Err(from_glib_full(error)) |
386 | } |
387 | } |
388 | } |
389 | |
390 | #[doc (alias = "g_key_file_set_double" )] |
391 | pub fn set_double(&self, group_name: &str, key: &str, value: f64) { |
392 | unsafe { |
393 | ffi::g_key_file_set_double( |
394 | self.to_glib_none().0, |
395 | group_name.to_glib_none().0, |
396 | key.to_glib_none().0, |
397 | value, |
398 | ); |
399 | } |
400 | } |
401 | |
402 | #[doc (alias = "g_key_file_set_int64" )] |
403 | pub fn set_int64(&self, group_name: &str, key: &str, value: i64) { |
404 | unsafe { |
405 | ffi::g_key_file_set_int64( |
406 | self.to_glib_none().0, |
407 | group_name.to_glib_none().0, |
408 | key.to_glib_none().0, |
409 | value, |
410 | ); |
411 | } |
412 | } |
413 | |
414 | #[doc (alias = "g_key_file_set_integer" )] |
415 | pub fn set_integer(&self, group_name: &str, key: &str, value: i32) { |
416 | unsafe { |
417 | ffi::g_key_file_set_integer( |
418 | self.to_glib_none().0, |
419 | group_name.to_glib_none().0, |
420 | key.to_glib_none().0, |
421 | value, |
422 | ); |
423 | } |
424 | } |
425 | |
426 | #[doc (alias = "g_key_file_set_list_separator" )] |
427 | pub fn set_list_separator(&self, separator: crate::Char) { |
428 | unsafe { |
429 | ffi::g_key_file_set_list_separator(self.to_glib_none().0, separator.into_glib()); |
430 | } |
431 | } |
432 | |
433 | #[doc (alias = "g_key_file_set_locale_string" )] |
434 | pub fn set_locale_string(&self, group_name: &str, key: &str, locale: &str, string: &str) { |
435 | unsafe { |
436 | ffi::g_key_file_set_locale_string( |
437 | self.to_glib_none().0, |
438 | group_name.to_glib_none().0, |
439 | key.to_glib_none().0, |
440 | locale.to_glib_none().0, |
441 | string.to_glib_none().0, |
442 | ); |
443 | } |
444 | } |
445 | |
446 | #[doc (alias = "g_key_file_set_string" )] |
447 | pub fn set_string(&self, group_name: &str, key: &str, string: &str) { |
448 | unsafe { |
449 | ffi::g_key_file_set_string( |
450 | self.to_glib_none().0, |
451 | group_name.to_glib_none().0, |
452 | key.to_glib_none().0, |
453 | string.to_glib_none().0, |
454 | ); |
455 | } |
456 | } |
457 | |
458 | #[doc (alias = "g_key_file_set_uint64" )] |
459 | pub fn set_uint64(&self, group_name: &str, key: &str, value: u64) { |
460 | unsafe { |
461 | ffi::g_key_file_set_uint64( |
462 | self.to_glib_none().0, |
463 | group_name.to_glib_none().0, |
464 | key.to_glib_none().0, |
465 | value, |
466 | ); |
467 | } |
468 | } |
469 | |
470 | #[doc (alias = "g_key_file_set_value" )] |
471 | pub fn set_value(&self, group_name: &str, key: &str, value: &str) { |
472 | unsafe { |
473 | ffi::g_key_file_set_value( |
474 | self.to_glib_none().0, |
475 | group_name.to_glib_none().0, |
476 | key.to_glib_none().0, |
477 | value.to_glib_none().0, |
478 | ); |
479 | } |
480 | } |
481 | } |
482 | |
483 | impl Default for KeyFile { |
484 | fn default() -> Self { |
485 | Self::new() |
486 | } |
487 | } |
488 | |