1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.KeyFile;
26 
27 private import glib.Bytes;
28 private import glib.ConstructionException;
29 private import glib.ErrorG;
30 private import glib.GException;
31 private import glib.Str;
32 private import glib.c.functions;
33 public  import glib.c.types;
34 public  import gtkc.glibtypes;
35 private import gtkd.Loader;
36 
37 
38 /**
39  * The GKeyFile struct contains only private data
40  * and should not be accessed directly.
41  */
42 public class KeyFile
43 {
44 	/** the main Gtk struct */
45 	protected GKeyFile* gKeyFile;
46 	protected bool ownedRef;
47 
48 	/** Get the main Gtk struct */
49 	public GKeyFile* getKeyFileStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return gKeyFile;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected void* getStruct()
58 	{
59 		return cast(void*)gKeyFile;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GKeyFile* gKeyFile, bool ownedRef = false)
66 	{
67 		this.gKeyFile = gKeyFile;
68 		this.ownedRef = ownedRef;
69 	}
70 
71 	~this ()
72 	{
73 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
74 			g_key_file_unref(gKeyFile);
75 	}
76 
77 
78 	/**
79 	 * Creates a new empty #GKeyFile object. Use
80 	 * g_key_file_load_from_file(), g_key_file_load_from_data(),
81 	 * g_key_file_load_from_dirs() or g_key_file_load_from_data_dirs() to
82 	 * read an existing key file.
83 	 *
84 	 * Returns: an empty #GKeyFile.
85 	 *
86 	 * Since: 2.6
87 	 *
88 	 * Throws: ConstructionException GTK+ fails to create the object.
89 	 */
90 	public this()
91 	{
92 		auto p = g_key_file_new();
93 
94 		if(p is null)
95 		{
96 			throw new ConstructionException("null returned by new");
97 		}
98 
99 		this(cast(GKeyFile*) p);
100 	}
101 
102 	/**
103 	 * Clears all keys and groups from @key_file, and decreases the
104 	 * reference count by 1. If the reference count reaches zero,
105 	 * frees the key file and all its allocated memory.
106 	 *
107 	 * Since: 2.6
108 	 */
109 	public void free()
110 	{
111 		g_key_file_free(gKeyFile);
112 		ownedRef = false;
113 	}
114 
115 	/**
116 	 * Returns the value associated with @key under @group_name as a
117 	 * boolean.
118 	 *
119 	 * If @key cannot be found then %FALSE is returned and @error is set
120 	 * to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value
121 	 * associated with @key cannot be interpreted as a boolean then %FALSE
122 	 * is returned and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
123 	 *
124 	 * Params:
125 	 *     groupName = a group name
126 	 *     key = a key
127 	 *
128 	 * Returns: the value associated with the key as a boolean,
129 	 *     or %FALSE if the key was not found or could not be parsed.
130 	 *
131 	 * Since: 2.6
132 	 *
133 	 * Throws: GException on failure.
134 	 */
135 	public bool getBoolean(string groupName, string key)
136 	{
137 		GError* err = null;
138 
139 		auto p = g_key_file_get_boolean(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err) != 0;
140 
141 		if (err !is null)
142 		{
143 			throw new GException( new ErrorG(err) );
144 		}
145 
146 		return p;
147 	}
148 
149 	/**
150 	 * Returns the values associated with @key under @group_name as
151 	 * booleans.
152 	 *
153 	 * If @key cannot be found then %NULL is returned and @error is set to
154 	 * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated
155 	 * with @key cannot be interpreted as booleans then %NULL is returned
156 	 * and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
157 	 *
158 	 * Params:
159 	 *     groupName = a group name
160 	 *     key = a key
161 	 *
162 	 * Returns: the values associated with the key as a list of booleans, or %NULL if the
163 	 *     key was not found or could not be parsed. The returned list of booleans
164 	 *     should be freed with g_free() when no longer needed.
165 	 *
166 	 * Since: 2.6
167 	 *
168 	 * Throws: GException on failure.
169 	 */
170 	public bool[] getBooleanList(string groupName, string key)
171 	{
172 		size_t length;
173 		GError* err = null;
174 
175 		auto p = g_key_file_get_boolean_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &length, &err);
176 
177 		if (err !is null)
178 		{
179 			throw new GException( new ErrorG(err) );
180 		}
181 
182 		bool[] r = new bool[length];
183 		for(size_t i = 0; i < length; i++)
184 		{
185 			r[i] = p[i] != 0;
186 		}
187 		return r;
188 	}
189 
190 	/**
191 	 * Retrieves a comment above @key from @group_name.
192 	 * If @key is %NULL then @comment will be read from above
193 	 * @group_name. If both @key and @group_name are %NULL, then
194 	 * @comment will be read from above the first group in the file.
195 	 *
196 	 * Note that the returned string does not include the '#' comment markers,
197 	 * but does include any whitespace after them (on each line). It includes
198 	 * the line breaks between lines, but does not include the final line break.
199 	 *
200 	 * Params:
201 	 *     groupName = a group name, or %NULL
202 	 *     key = a key
203 	 *
204 	 * Returns: a comment that should be freed with g_free()
205 	 *
206 	 * Since: 2.6
207 	 *
208 	 * Throws: GException on failure.
209 	 */
210 	public string getComment(string groupName, string key)
211 	{
212 		GError* err = null;
213 
214 		auto retStr = g_key_file_get_comment(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
215 
216 		if (err !is null)
217 		{
218 			throw new GException( new ErrorG(err) );
219 		}
220 
221 		scope(exit) Str.freeString(retStr);
222 		return Str.toString(retStr);
223 	}
224 
225 	/**
226 	 * Returns the value associated with @key under @group_name as a
227 	 * double. If @group_name is %NULL, the start_group is used.
228 	 *
229 	 * If @key cannot be found then 0.0 is returned and @error is set to
230 	 * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associated
231 	 * with @key cannot be interpreted as a double then 0.0 is returned
232 	 * and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
233 	 *
234 	 * Params:
235 	 *     groupName = a group name
236 	 *     key = a key
237 	 *
238 	 * Returns: the value associated with the key as a double, or
239 	 *     0.0 if the key was not found or could not be parsed.
240 	 *
241 	 * Since: 2.12
242 	 *
243 	 * Throws: GException on failure.
244 	 */
245 	public double getDouble(string groupName, string key)
246 	{
247 		GError* err = null;
248 
249 		auto p = g_key_file_get_double(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
250 
251 		if (err !is null)
252 		{
253 			throw new GException( new ErrorG(err) );
254 		}
255 
256 		return p;
257 	}
258 
259 	/**
260 	 * Returns the values associated with @key under @group_name as
261 	 * doubles.
262 	 *
263 	 * If @key cannot be found then %NULL is returned and @error is set to
264 	 * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated
265 	 * with @key cannot be interpreted as doubles then %NULL is returned
266 	 * and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
267 	 *
268 	 * Params:
269 	 *     groupName = a group name
270 	 *     key = a key
271 	 *
272 	 * Returns: the values associated with the key as a list of doubles, or %NULL if the
273 	 *     key was not found or could not be parsed. The returned list of doubles
274 	 *     should be freed with g_free() when no longer needed.
275 	 *
276 	 * Since: 2.12
277 	 *
278 	 * Throws: GException on failure.
279 	 */
280 	public double[] getDoubleList(string groupName, string key)
281 	{
282 		size_t length;
283 		GError* err = null;
284 
285 		auto p = g_key_file_get_double_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &length, &err);
286 
287 		if (err !is null)
288 		{
289 			throw new GException( new ErrorG(err) );
290 		}
291 
292 		return p[0 .. length];
293 	}
294 
295 	/**
296 	 * Returns all groups in the key file loaded with @key_file.
297 	 * The array of returned groups will be %NULL-terminated, so
298 	 * @length may optionally be %NULL.
299 	 *
300 	 * Params:
301 	 *     length = return location for the number of returned groups, or %NULL
302 	 *
303 	 * Returns: a newly-allocated %NULL-terminated array of strings.
304 	 *     Use g_strfreev() to free it.
305 	 *
306 	 * Since: 2.6
307 	 */
308 	public string[] getGroups(out size_t length)
309 	{
310 		auto retStr = g_key_file_get_groups(gKeyFile, &length);
311 
312 		scope(exit) Str.freeStringArray(retStr);
313 		return Str.toStringArray(retStr);
314 	}
315 
316 	/**
317 	 * Returns the value associated with @key under @group_name as a signed
318 	 * 64-bit integer. This is similar to g_key_file_get_integer() but can return
319 	 * 64-bit results without truncation.
320 	 *
321 	 * Params:
322 	 *     groupName = a non-%NULL group name
323 	 *     key = a non-%NULL key
324 	 *
325 	 * Returns: the value associated with the key as a signed 64-bit integer, or
326 	 *     0 if the key was not found or could not be parsed.
327 	 *
328 	 * Since: 2.26
329 	 *
330 	 * Throws: GException on failure.
331 	 */
332 	public long getInt64(string groupName, string key)
333 	{
334 		GError* err = null;
335 
336 		auto p = g_key_file_get_int64(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
337 
338 		if (err !is null)
339 		{
340 			throw new GException( new ErrorG(err) );
341 		}
342 
343 		return p;
344 	}
345 
346 	/**
347 	 * Returns the value associated with @key under @group_name as an
348 	 * integer.
349 	 *
350 	 * If @key cannot be found then 0 is returned and @error is set to
351 	 * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the value associated
352 	 * with @key cannot be interpreted as an integer, or is out of range
353 	 * for a #gint, then 0 is returned
354 	 * and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
355 	 *
356 	 * Params:
357 	 *     groupName = a group name
358 	 *     key = a key
359 	 *
360 	 * Returns: the value associated with the key as an integer, or
361 	 *     0 if the key was not found or could not be parsed.
362 	 *
363 	 * Since: 2.6
364 	 *
365 	 * Throws: GException on failure.
366 	 */
367 	public int getInteger(string groupName, string key)
368 	{
369 		GError* err = null;
370 
371 		auto p = g_key_file_get_integer(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
372 
373 		if (err !is null)
374 		{
375 			throw new GException( new ErrorG(err) );
376 		}
377 
378 		return p;
379 	}
380 
381 	/**
382 	 * Returns the values associated with @key under @group_name as
383 	 * integers.
384 	 *
385 	 * If @key cannot be found then %NULL is returned and @error is set to
386 	 * #G_KEY_FILE_ERROR_KEY_NOT_FOUND. Likewise, if the values associated
387 	 * with @key cannot be interpreted as integers, or are out of range for
388 	 * #gint, then %NULL is returned
389 	 * and @error is set to #G_KEY_FILE_ERROR_INVALID_VALUE.
390 	 *
391 	 * Params:
392 	 *     groupName = a group name
393 	 *     key = a key
394 	 *
395 	 * Returns: the values associated with the key as a list of integers, or %NULL if
396 	 *     the key was not found or could not be parsed. The returned list of
397 	 *     integers should be freed with g_free() when no longer needed.
398 	 *
399 	 * Since: 2.6
400 	 *
401 	 * Throws: GException on failure.
402 	 */
403 	public int[] getIntegerList(string groupName, string key)
404 	{
405 		size_t length;
406 		GError* err = null;
407 
408 		auto p = g_key_file_get_integer_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &length, &err);
409 
410 		if (err !is null)
411 		{
412 			throw new GException( new ErrorG(err) );
413 		}
414 
415 		return p[0 .. length];
416 	}
417 
418 	/**
419 	 * Returns all keys for the group name @group_name.  The array of
420 	 * returned keys will be %NULL-terminated, so @length may
421 	 * optionally be %NULL. In the event that the @group_name cannot
422 	 * be found, %NULL is returned and @error is set to
423 	 * #G_KEY_FILE_ERROR_GROUP_NOT_FOUND.
424 	 *
425 	 * Params:
426 	 *     groupName = a group name
427 	 *     length = return location for the number of keys returned, or %NULL
428 	 *
429 	 * Returns: a newly-allocated %NULL-terminated array of strings.
430 	 *     Use g_strfreev() to free it.
431 	 *
432 	 * Since: 2.6
433 	 *
434 	 * Throws: GException on failure.
435 	 */
436 	public string[] getKeys(string groupName, out size_t length)
437 	{
438 		GError* err = null;
439 
440 		auto retStr = g_key_file_get_keys(gKeyFile, Str.toStringz(groupName), &length, &err);
441 
442 		if (err !is null)
443 		{
444 			throw new GException( new ErrorG(err) );
445 		}
446 
447 		scope(exit) Str.freeStringArray(retStr);
448 		return Str.toStringArray(retStr);
449 	}
450 
451 	/**
452 	 * Returns the actual locale which the result of
453 	 * g_key_file_get_locale_string() or g_key_file_get_locale_string_list()
454 	 * came from.
455 	 *
456 	 * If calling g_key_file_get_locale_string() or
457 	 * g_key_file_get_locale_string_list() with exactly the same @key_file,
458 	 * @group_name, @key and @locale, the result of those functions will
459 	 * have originally been tagged with the locale that is the result of
460 	 * this function.
461 	 *
462 	 * Params:
463 	 *     groupName = a group name
464 	 *     key = a key
465 	 *     locale = a locale identifier or %NULL
466 	 *
467 	 * Returns: the locale from the file, or %NULL if the key was not
468 	 *     found or the entry in the file was was untranslated
469 	 *
470 	 * Since: 2.56
471 	 */
472 	public string getLocaleForKey(string groupName, string key, string locale)
473 	{
474 		auto retStr = g_key_file_get_locale_for_key(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(locale));
475 
476 		scope(exit) Str.freeString(retStr);
477 		return Str.toString(retStr);
478 	}
479 
480 	/**
481 	 * Returns the value associated with @key under @group_name
482 	 * translated in the given @locale if available.  If @locale is
483 	 * %NULL then the current locale is assumed.
484 	 *
485 	 * If @locale is to be non-%NULL, or if the current locale will change over
486 	 * the lifetime of the #GKeyFile, it must be loaded with
487 	 * %G_KEY_FILE_KEEP_TRANSLATIONS in order to load strings for all locales.
488 	 *
489 	 * If @key cannot be found then %NULL is returned and @error is set
490 	 * to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the value associated
491 	 * with @key cannot be interpreted or no suitable translation can
492 	 * be found then the untranslated value is returned.
493 	 *
494 	 * Params:
495 	 *     groupName = a group name
496 	 *     key = a key
497 	 *     locale = a locale identifier or %NULL
498 	 *
499 	 * Returns: a newly allocated string or %NULL if the specified
500 	 *     key cannot be found.
501 	 *
502 	 * Since: 2.6
503 	 *
504 	 * Throws: GException on failure.
505 	 */
506 	public string getLocaleString(string groupName, string key, string locale)
507 	{
508 		GError* err = null;
509 
510 		auto retStr = g_key_file_get_locale_string(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(locale), &err);
511 
512 		if (err !is null)
513 		{
514 			throw new GException( new ErrorG(err) );
515 		}
516 
517 		scope(exit) Str.freeString(retStr);
518 		return Str.toString(retStr);
519 	}
520 
521 	/**
522 	 * Returns the values associated with @key under @group_name
523 	 * translated in the given @locale if available.  If @locale is
524 	 * %NULL then the current locale is assumed.
525 	 *
526 	 * If @locale is to be non-%NULL, or if the current locale will change over
527 	 * the lifetime of the #GKeyFile, it must be loaded with
528 	 * %G_KEY_FILE_KEEP_TRANSLATIONS in order to load strings for all locales.
529 	 *
530 	 * If @key cannot be found then %NULL is returned and @error is set
531 	 * to #G_KEY_FILE_ERROR_KEY_NOT_FOUND. If the values associated
532 	 * with @key cannot be interpreted or no suitable translations
533 	 * can be found then the untranslated values are returned. The
534 	 * returned array is %NULL-terminated, so @length may optionally
535 	 * be %NULL.
536 	 *
537 	 * Params:
538 	 *     groupName = a group name
539 	 *     key = a key
540 	 *     locale = a locale identifier or %NULL
541 	 *
542 	 * Returns: a newly allocated %NULL-terminated string array
543 	 *     or %NULL if the key isn't found. The string array should be freed
544 	 *     with g_strfreev().
545 	 *
546 	 * Since: 2.6
547 	 *
548 	 * Throws: GException on failure.
549 	 */
550 	public string[] getLocaleStringList(string groupName, string key, string locale)
551 	{
552 		size_t length;
553 		GError* err = null;
554 
555 		auto retStr = g_key_file_get_locale_string_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(locale), &length, &err);
556 
557 		if (err !is null)
558 		{
559 			throw new GException( new ErrorG(err) );
560 		}
561 
562 		scope(exit) Str.freeStringArray(retStr);
563 		return Str.toStringArray(retStr, length);
564 	}
565 
566 	/**
567 	 * Returns the name of the start group of the file.
568 	 *
569 	 * Returns: The start group of the key file.
570 	 *
571 	 * Since: 2.6
572 	 */
573 	public string getStartGroup()
574 	{
575 		auto retStr = g_key_file_get_start_group(gKeyFile);
576 
577 		scope(exit) Str.freeString(retStr);
578 		return Str.toString(retStr);
579 	}
580 
581 	/**
582 	 * Returns the string value associated with @key under @group_name.
583 	 * Unlike g_key_file_get_value(), this function handles escape sequences
584 	 * like \s.
585 	 *
586 	 * In the event the key cannot be found, %NULL is returned and
587 	 * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND.  In the
588 	 * event that the @group_name cannot be found, %NULL is returned
589 	 * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND.
590 	 *
591 	 * Params:
592 	 *     groupName = a group name
593 	 *     key = a key
594 	 *
595 	 * Returns: a newly allocated string or %NULL if the specified
596 	 *     key cannot be found.
597 	 *
598 	 * Since: 2.6
599 	 *
600 	 * Throws: GException on failure.
601 	 */
602 	public string getString(string groupName, string key)
603 	{
604 		GError* err = null;
605 
606 		auto retStr = g_key_file_get_string(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
607 
608 		if (err !is null)
609 		{
610 			throw new GException( new ErrorG(err) );
611 		}
612 
613 		scope(exit) Str.freeString(retStr);
614 		return Str.toString(retStr);
615 	}
616 
617 	/**
618 	 * Returns the values associated with @key under @group_name.
619 	 *
620 	 * In the event the key cannot be found, %NULL is returned and
621 	 * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND.  In the
622 	 * event that the @group_name cannot be found, %NULL is returned
623 	 * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND.
624 	 *
625 	 * Params:
626 	 *     groupName = a group name
627 	 *     key = a key
628 	 *
629 	 * Returns: a %NULL-terminated string array or %NULL if the specified
630 	 *     key cannot be found. The array should be freed with g_strfreev().
631 	 *
632 	 * Since: 2.6
633 	 *
634 	 * Throws: GException on failure.
635 	 */
636 	public string[] getStringList(string groupName, string key)
637 	{
638 		size_t length;
639 		GError* err = null;
640 
641 		auto retStr = g_key_file_get_string_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &length, &err);
642 
643 		if (err !is null)
644 		{
645 			throw new GException( new ErrorG(err) );
646 		}
647 
648 		scope(exit) Str.freeStringArray(retStr);
649 		return Str.toStringArray(retStr, length);
650 	}
651 
652 	/**
653 	 * Returns the value associated with @key under @group_name as an unsigned
654 	 * 64-bit integer. This is similar to g_key_file_get_integer() but can return
655 	 * large positive results without truncation.
656 	 *
657 	 * Params:
658 	 *     groupName = a non-%NULL group name
659 	 *     key = a non-%NULL key
660 	 *
661 	 * Returns: the value associated with the key as an unsigned 64-bit integer,
662 	 *     or 0 if the key was not found or could not be parsed.
663 	 *
664 	 * Since: 2.26
665 	 *
666 	 * Throws: GException on failure.
667 	 */
668 	public ulong getUint64(string groupName, string key)
669 	{
670 		GError* err = null;
671 
672 		auto p = g_key_file_get_uint64(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
673 
674 		if (err !is null)
675 		{
676 			throw new GException( new ErrorG(err) );
677 		}
678 
679 		return p;
680 	}
681 
682 	/**
683 	 * Returns the raw value associated with @key under @group_name.
684 	 * Use g_key_file_get_string() to retrieve an unescaped UTF-8 string.
685 	 *
686 	 * In the event the key cannot be found, %NULL is returned and
687 	 * @error is set to #G_KEY_FILE_ERROR_KEY_NOT_FOUND.  In the
688 	 * event that the @group_name cannot be found, %NULL is returned
689 	 * and @error is set to #G_KEY_FILE_ERROR_GROUP_NOT_FOUND.
690 	 *
691 	 * Params:
692 	 *     groupName = a group name
693 	 *     key = a key
694 	 *
695 	 * Returns: a newly allocated string or %NULL if the specified
696 	 *     key cannot be found.
697 	 *
698 	 * Since: 2.6
699 	 *
700 	 * Throws: GException on failure.
701 	 */
702 	public string getValue(string groupName, string key)
703 	{
704 		GError* err = null;
705 
706 		auto retStr = g_key_file_get_value(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err);
707 
708 		if (err !is null)
709 		{
710 			throw new GException( new ErrorG(err) );
711 		}
712 
713 		scope(exit) Str.freeString(retStr);
714 		return Str.toString(retStr);
715 	}
716 
717 	/**
718 	 * Looks whether the key file has the group @group_name.
719 	 *
720 	 * Params:
721 	 *     groupName = a group name
722 	 *
723 	 * Returns: %TRUE if @group_name is a part of @key_file, %FALSE
724 	 *     otherwise.
725 	 *
726 	 * Since: 2.6
727 	 */
728 	public bool hasGroup(string groupName)
729 	{
730 		return g_key_file_has_group(gKeyFile, Str.toStringz(groupName)) != 0;
731 	}
732 
733 	/**
734 	 * Looks whether the key file has the key @key in the group
735 	 * @group_name.
736 	 *
737 	 * Note that this function does not follow the rules for #GError strictly;
738 	 * the return value both carries meaning and signals an error.  To use
739 	 * this function, you must pass a #GError pointer in @error, and check
740 	 * whether it is not %NULL to see if an error occurred.
741 	 *
742 	 * Language bindings should use g_key_file_get_value() to test whether
743 	 * or not a key exists.
744 	 *
745 	 * Params:
746 	 *     groupName = a group name
747 	 *     key = a key name
748 	 *
749 	 * Returns: %TRUE if @key is a part of @group_name, %FALSE otherwise
750 	 *
751 	 * Since: 2.6
752 	 *
753 	 * Throws: GException on failure.
754 	 */
755 	public bool hasKey(string groupName, string key)
756 	{
757 		GError* err = null;
758 
759 		auto p = g_key_file_has_key(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err) != 0;
760 
761 		if (err !is null)
762 		{
763 			throw new GException( new ErrorG(err) );
764 		}
765 
766 		return p;
767 	}
768 
769 	/**
770 	 * Loads a key file from the data in @bytes into an empty #GKeyFile structure.
771 	 * If the object cannot be created then %error is set to a #GKeyFileError.
772 	 *
773 	 * Params:
774 	 *     bytes = a #GBytes
775 	 *     flags = flags from #GKeyFileFlags
776 	 *
777 	 * Returns: %TRUE if a key file could be loaded, %FALSE otherwise
778 	 *
779 	 * Since: 2.50
780 	 *
781 	 * Throws: GException on failure.
782 	 */
783 	public bool loadFromBytes(Bytes bytes, GKeyFileFlags flags)
784 	{
785 		GError* err = null;
786 
787 		auto p = g_key_file_load_from_bytes(gKeyFile, (bytes is null) ? null : bytes.getBytesStruct(), flags, &err) != 0;
788 
789 		if (err !is null)
790 		{
791 			throw new GException( new ErrorG(err) );
792 		}
793 
794 		return p;
795 	}
796 
797 	/**
798 	 * Loads a key file from memory into an empty #GKeyFile structure.
799 	 * If the object cannot be created then %error is set to a #GKeyFileError.
800 	 *
801 	 * Params:
802 	 *     data = key file loaded in memory
803 	 *     length = the length of @data in bytes (or (gsize)-1 if data is nul-terminated)
804 	 *     flags = flags from #GKeyFileFlags
805 	 *
806 	 * Returns: %TRUE if a key file could be loaded, %FALSE otherwise
807 	 *
808 	 * Since: 2.6
809 	 *
810 	 * Throws: GException on failure.
811 	 */
812 	public bool loadFromData(string data, size_t length, GKeyFileFlags flags)
813 	{
814 		GError* err = null;
815 
816 		auto p = g_key_file_load_from_data(gKeyFile, Str.toStringz(data), length, flags, &err) != 0;
817 
818 		if (err !is null)
819 		{
820 			throw new GException( new ErrorG(err) );
821 		}
822 
823 		return p;
824 	}
825 
826 	/**
827 	 * This function looks for a key file named @file in the paths
828 	 * returned from g_get_user_data_dir() and g_get_system_data_dirs(),
829 	 * loads the file into @key_file and returns the file's full path in
830 	 * @full_path.  If the file could not be loaded then an %error is
831 	 * set to either a #GFileError or #GKeyFileError.
832 	 *
833 	 * Params:
834 	 *     file = a relative path to a filename to open and parse
835 	 *     fullPath = return location for a string containing the full path
836 	 *         of the file, or %NULL
837 	 *     flags = flags from #GKeyFileFlags
838 	 *
839 	 * Returns: %TRUE if a key file could be loaded, %FALSE othewise
840 	 *
841 	 * Since: 2.6
842 	 *
843 	 * Throws: GException on failure.
844 	 */
845 	public bool loadFromDataDirs(string file, out string fullPath, GKeyFileFlags flags)
846 	{
847 		char* outfullPath = null;
848 		GError* err = null;
849 
850 		auto p = g_key_file_load_from_data_dirs(gKeyFile, Str.toStringz(file), &outfullPath, flags, &err) != 0;
851 
852 		if (err !is null)
853 		{
854 			throw new GException( new ErrorG(err) );
855 		}
856 
857 		fullPath = Str.toString(outfullPath);
858 
859 		return p;
860 	}
861 
862 	/**
863 	 * This function looks for a key file named @file in the paths
864 	 * specified in @search_dirs, loads the file into @key_file and
865 	 * returns the file's full path in @full_path.
866 	 *
867 	 * If the file could not be found in any of the @search_dirs,
868 	 * %G_KEY_FILE_ERROR_NOT_FOUND is returned. If
869 	 * the file is found but the OS returns an error when opening or reading the
870 	 * file, a %G_FILE_ERROR is returned. If there is a problem parsing the file, a
871 	 * %G_KEY_FILE_ERROR is returned.
872 	 *
873 	 * Params:
874 	 *     file = a relative path to a filename to open and parse
875 	 *     searchDirs = %NULL-terminated array of directories to search
876 	 *     fullPath = return location for a string containing the full path
877 	 *         of the file, or %NULL
878 	 *     flags = flags from #GKeyFileFlags
879 	 *
880 	 * Returns: %TRUE if a key file could be loaded, %FALSE otherwise
881 	 *
882 	 * Since: 2.14
883 	 *
884 	 * Throws: GException on failure.
885 	 */
886 	public bool loadFromDirs(string file, string[] searchDirs, out string fullPath, GKeyFileFlags flags)
887 	{
888 		char* outfullPath = null;
889 		GError* err = null;
890 
891 		auto p = g_key_file_load_from_dirs(gKeyFile, Str.toStringz(file), Str.toStringzArray(searchDirs), &outfullPath, flags, &err) != 0;
892 
893 		if (err !is null)
894 		{
895 			throw new GException( new ErrorG(err) );
896 		}
897 
898 		fullPath = Str.toString(outfullPath);
899 
900 		return p;
901 	}
902 
903 	/**
904 	 * Loads a key file into an empty #GKeyFile structure.
905 	 *
906 	 * If the OS returns an error when opening or reading the file, a
907 	 * %G_FILE_ERROR is returned. If there is a problem parsing the file, a
908 	 * %G_KEY_FILE_ERROR is returned.
909 	 *
910 	 * This function will never return a %G_KEY_FILE_ERROR_NOT_FOUND error. If the
911 	 * @file is not found, %G_FILE_ERROR_NOENT is returned.
912 	 *
913 	 * Params:
914 	 *     file = the path of a filename to load, in the GLib filename encoding
915 	 *     flags = flags from #GKeyFileFlags
916 	 *
917 	 * Returns: %TRUE if a key file could be loaded, %FALSE otherwise
918 	 *
919 	 * Since: 2.6
920 	 *
921 	 * Throws: GException on failure.
922 	 */
923 	public bool loadFromFile(string file, GKeyFileFlags flags)
924 	{
925 		GError* err = null;
926 
927 		auto p = g_key_file_load_from_file(gKeyFile, Str.toStringz(file), flags, &err) != 0;
928 
929 		if (err !is null)
930 		{
931 			throw new GException( new ErrorG(err) );
932 		}
933 
934 		return p;
935 	}
936 
937 	alias doref = ref_;
938 	/**
939 	 * Increases the reference count of @key_file.
940 	 *
941 	 * Returns: the same @key_file.
942 	 *
943 	 * Since: 2.32
944 	 */
945 	public KeyFile ref_()
946 	{
947 		auto p = g_key_file_ref(gKeyFile);
948 
949 		if(p is null)
950 		{
951 			return null;
952 		}
953 
954 		return new KeyFile(cast(GKeyFile*) p, true);
955 	}
956 
957 	/**
958 	 * Removes a comment above @key from @group_name.
959 	 * If @key is %NULL then @comment will be removed above @group_name.
960 	 * If both @key and @group_name are %NULL, then @comment will
961 	 * be removed above the first group in the file.
962 	 *
963 	 * Params:
964 	 *     groupName = a group name, or %NULL
965 	 *     key = a key
966 	 *
967 	 * Returns: %TRUE if the comment was removed, %FALSE otherwise
968 	 *
969 	 * Since: 2.6
970 	 *
971 	 * Throws: GException on failure.
972 	 */
973 	public bool removeComment(string groupName, string key)
974 	{
975 		GError* err = null;
976 
977 		auto p = g_key_file_remove_comment(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err) != 0;
978 
979 		if (err !is null)
980 		{
981 			throw new GException( new ErrorG(err) );
982 		}
983 
984 		return p;
985 	}
986 
987 	/**
988 	 * Removes the specified group, @group_name,
989 	 * from the key file.
990 	 *
991 	 * Params:
992 	 *     groupName = a group name
993 	 *
994 	 * Returns: %TRUE if the group was removed, %FALSE otherwise
995 	 *
996 	 * Since: 2.6
997 	 *
998 	 * Throws: GException on failure.
999 	 */
1000 	public bool removeGroup(string groupName)
1001 	{
1002 		GError* err = null;
1003 
1004 		auto p = g_key_file_remove_group(gKeyFile, Str.toStringz(groupName), &err) != 0;
1005 
1006 		if (err !is null)
1007 		{
1008 			throw new GException( new ErrorG(err) );
1009 		}
1010 
1011 		return p;
1012 	}
1013 
1014 	/**
1015 	 * Removes @key in @group_name from the key file.
1016 	 *
1017 	 * Params:
1018 	 *     groupName = a group name
1019 	 *     key = a key name to remove
1020 	 *
1021 	 * Returns: %TRUE if the key was removed, %FALSE otherwise
1022 	 *
1023 	 * Since: 2.6
1024 	 *
1025 	 * Throws: GException on failure.
1026 	 */
1027 	public bool removeKey(string groupName, string key)
1028 	{
1029 		GError* err = null;
1030 
1031 		auto p = g_key_file_remove_key(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), &err) != 0;
1032 
1033 		if (err !is null)
1034 		{
1035 			throw new GException( new ErrorG(err) );
1036 		}
1037 
1038 		return p;
1039 	}
1040 
1041 	/**
1042 	 * Writes the contents of @key_file to @filename using
1043 	 * g_file_set_contents().
1044 	 *
1045 	 * This function can fail for any of the reasons that
1046 	 * g_file_set_contents() may fail.
1047 	 *
1048 	 * Params:
1049 	 *     filename = the name of the file to write to
1050 	 *
1051 	 * Returns: %TRUE if successful, else %FALSE with @error set
1052 	 *
1053 	 * Since: 2.40
1054 	 *
1055 	 * Throws: GException on failure.
1056 	 */
1057 	public bool saveToFile(string filename)
1058 	{
1059 		GError* err = null;
1060 
1061 		auto p = g_key_file_save_to_file(gKeyFile, Str.toStringz(filename), &err) != 0;
1062 
1063 		if (err !is null)
1064 		{
1065 			throw new GException( new ErrorG(err) );
1066 		}
1067 
1068 		return p;
1069 	}
1070 
1071 	/**
1072 	 * Associates a new boolean value with @key under @group_name.
1073 	 * If @key cannot be found then it is created.
1074 	 *
1075 	 * Params:
1076 	 *     groupName = a group name
1077 	 *     key = a key
1078 	 *     value = %TRUE or %FALSE
1079 	 *
1080 	 * Since: 2.6
1081 	 */
1082 	public void setBoolean(string groupName, string key, bool value)
1083 	{
1084 		g_key_file_set_boolean(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), value);
1085 	}
1086 
1087 	/**
1088 	 * Associates a list of boolean values with @key under @group_name.
1089 	 * If @key cannot be found then it is created.
1090 	 * If @group_name is %NULL, the start_group is used.
1091 	 *
1092 	 * Params:
1093 	 *     groupName = a group name
1094 	 *     key = a key
1095 	 *     list = an array of boolean values
1096 	 *
1097 	 * Since: 2.6
1098 	 */
1099 	public void setBooleanList(string groupName, string key, bool[] list)
1100 	{
1101 		int[] listArray = new int[list.length];
1102 		for ( int i = 0; i < list.length; i++ )
1103 		{
1104 			listArray[i] = list[i] ? 1 : 0;
1105 		}
1106 
1107 		g_key_file_set_boolean_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), listArray.ptr, cast(size_t)list.length);
1108 	}
1109 
1110 	/**
1111 	 * Places a comment above @key from @group_name.
1112 	 *
1113 	 * If @key is %NULL then @comment will be written above @group_name.
1114 	 * If both @key and @group_name  are %NULL, then @comment will be
1115 	 * written above the first group in the file.
1116 	 *
1117 	 * Note that this function prepends a '#' comment marker to
1118 	 * each line of @comment.
1119 	 *
1120 	 * Params:
1121 	 *     groupName = a group name, or %NULL
1122 	 *     key = a key
1123 	 *     comment = a comment
1124 	 *
1125 	 * Returns: %TRUE if the comment was written, %FALSE otherwise
1126 	 *
1127 	 * Since: 2.6
1128 	 *
1129 	 * Throws: GException on failure.
1130 	 */
1131 	public bool setComment(string groupName, string key, string comment)
1132 	{
1133 		GError* err = null;
1134 
1135 		auto p = g_key_file_set_comment(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(comment), &err) != 0;
1136 
1137 		if (err !is null)
1138 		{
1139 			throw new GException( new ErrorG(err) );
1140 		}
1141 
1142 		return p;
1143 	}
1144 
1145 	/**
1146 	 * Associates a new double value with @key under @group_name.
1147 	 * If @key cannot be found then it is created.
1148 	 *
1149 	 * Params:
1150 	 *     groupName = a group name
1151 	 *     key = a key
1152 	 *     value = an double value
1153 	 *
1154 	 * Since: 2.12
1155 	 */
1156 	public void setDouble(string groupName, string key, double value)
1157 	{
1158 		g_key_file_set_double(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), value);
1159 	}
1160 
1161 	/**
1162 	 * Associates a list of double values with @key under
1163 	 * @group_name.  If @key cannot be found then it is created.
1164 	 *
1165 	 * Params:
1166 	 *     groupName = a group name
1167 	 *     key = a key
1168 	 *     list = an array of double values
1169 	 *
1170 	 * Since: 2.12
1171 	 */
1172 	public void setDoubleList(string groupName, string key, double[] list)
1173 	{
1174 		g_key_file_set_double_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), list.ptr, cast(size_t)list.length);
1175 	}
1176 
1177 	/**
1178 	 * Associates a new integer value with @key under @group_name.
1179 	 * If @key cannot be found then it is created.
1180 	 *
1181 	 * Params:
1182 	 *     groupName = a group name
1183 	 *     key = a key
1184 	 *     value = an integer value
1185 	 *
1186 	 * Since: 2.26
1187 	 */
1188 	public void setInt64(string groupName, string key, long value)
1189 	{
1190 		g_key_file_set_int64(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), value);
1191 	}
1192 
1193 	/**
1194 	 * Associates a new integer value with @key under @group_name.
1195 	 * If @key cannot be found then it is created.
1196 	 *
1197 	 * Params:
1198 	 *     groupName = a group name
1199 	 *     key = a key
1200 	 *     value = an integer value
1201 	 *
1202 	 * Since: 2.6
1203 	 */
1204 	public void setInteger(string groupName, string key, int value)
1205 	{
1206 		g_key_file_set_integer(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), value);
1207 	}
1208 
1209 	/**
1210 	 * Associates a list of integer values with @key under @group_name.
1211 	 * If @key cannot be found then it is created.
1212 	 *
1213 	 * Params:
1214 	 *     groupName = a group name
1215 	 *     key = a key
1216 	 *     list = an array of integer values
1217 	 *
1218 	 * Since: 2.6
1219 	 */
1220 	public void setIntegerList(string groupName, string key, int[] list)
1221 	{
1222 		g_key_file_set_integer_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), list.ptr, cast(size_t)list.length);
1223 	}
1224 
1225 	/**
1226 	 * Sets the character which is used to separate
1227 	 * values in lists. Typically ';' or ',' are used
1228 	 * as separators. The default list separator is ';'.
1229 	 *
1230 	 * Params:
1231 	 *     separator = the separator
1232 	 *
1233 	 * Since: 2.6
1234 	 */
1235 	public void setListSeparator(char separator)
1236 	{
1237 		g_key_file_set_list_separator(gKeyFile, separator);
1238 	}
1239 
1240 	/**
1241 	 * Associates a string value for @key and @locale under @group_name.
1242 	 * If the translation for @key cannot be found then it is created.
1243 	 *
1244 	 * Params:
1245 	 *     groupName = a group name
1246 	 *     key = a key
1247 	 *     locale = a locale identifier
1248 	 *     string_ = a string
1249 	 *
1250 	 * Since: 2.6
1251 	 */
1252 	public void setLocaleString(string groupName, string key, string locale, string string_)
1253 	{
1254 		g_key_file_set_locale_string(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(locale), Str.toStringz(string_));
1255 	}
1256 
1257 	/**
1258 	 * Associates a list of string values for @key and @locale under
1259 	 * @group_name.  If the translation for @key cannot be found then
1260 	 * it is created.
1261 	 *
1262 	 * Params:
1263 	 *     groupName = a group name
1264 	 *     key = a key
1265 	 *     locale = a locale identifier
1266 	 *     list = a %NULL-terminated array of locale string values
1267 	 *
1268 	 * Since: 2.6
1269 	 */
1270 	public void setLocaleStringList(string groupName, string key, string locale, string[] list)
1271 	{
1272 		g_key_file_set_locale_string_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(locale), Str.toStringzArray(list), cast(size_t)list.length);
1273 	}
1274 
1275 	/**
1276 	 * Associates a new string value with @key under @group_name.
1277 	 * If @key cannot be found then it is created.
1278 	 * If @group_name cannot be found then it is created.
1279 	 * Unlike g_key_file_set_value(), this function handles characters
1280 	 * that need escaping, such as newlines.
1281 	 *
1282 	 * Params:
1283 	 *     groupName = a group name
1284 	 *     key = a key
1285 	 *     string_ = a string
1286 	 *
1287 	 * Since: 2.6
1288 	 */
1289 	public void setString(string groupName, string key, string string_)
1290 	{
1291 		g_key_file_set_string(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(string_));
1292 	}
1293 
1294 	/**
1295 	 * Associates a list of string values for @key under @group_name.
1296 	 * If @key cannot be found then it is created.
1297 	 * If @group_name cannot be found then it is created.
1298 	 *
1299 	 * Params:
1300 	 *     groupName = a group name
1301 	 *     key = a key
1302 	 *     list = an array of string values
1303 	 *
1304 	 * Since: 2.6
1305 	 */
1306 	public void setStringList(string groupName, string key, string[] list)
1307 	{
1308 		g_key_file_set_string_list(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringzArray(list), cast(size_t)list.length);
1309 	}
1310 
1311 	/**
1312 	 * Associates a new integer value with @key under @group_name.
1313 	 * If @key cannot be found then it is created.
1314 	 *
1315 	 * Params:
1316 	 *     groupName = a group name
1317 	 *     key = a key
1318 	 *     value = an integer value
1319 	 *
1320 	 * Since: 2.26
1321 	 */
1322 	public void setUint64(string groupName, string key, ulong value)
1323 	{
1324 		g_key_file_set_uint64(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), value);
1325 	}
1326 
1327 	/**
1328 	 * Associates a new value with @key under @group_name.
1329 	 *
1330 	 * If @key cannot be found then it is created. If @group_name cannot
1331 	 * be found then it is created. To set an UTF-8 string which may contain
1332 	 * characters that need escaping (such as newlines or spaces), use
1333 	 * g_key_file_set_string().
1334 	 *
1335 	 * Params:
1336 	 *     groupName = a group name
1337 	 *     key = a key
1338 	 *     value = a string
1339 	 *
1340 	 * Since: 2.6
1341 	 */
1342 	public void setValue(string groupName, string key, string value)
1343 	{
1344 		g_key_file_set_value(gKeyFile, Str.toStringz(groupName), Str.toStringz(key), Str.toStringz(value));
1345 	}
1346 
1347 	/**
1348 	 * This function outputs @key_file as a string.
1349 	 *
1350 	 * Note that this function never reports an error,
1351 	 * so it is safe to pass %NULL as @error.
1352 	 *
1353 	 * Params:
1354 	 *     length = return location for the length of the
1355 	 *         returned string, or %NULL
1356 	 *
1357 	 * Returns: a newly allocated string holding
1358 	 *     the contents of the #GKeyFile
1359 	 *
1360 	 * Since: 2.6
1361 	 *
1362 	 * Throws: GException on failure.
1363 	 */
1364 	public string toData(out size_t length)
1365 	{
1366 		GError* err = null;
1367 
1368 		auto retStr = g_key_file_to_data(gKeyFile, &length, &err);
1369 
1370 		if (err !is null)
1371 		{
1372 			throw new GException( new ErrorG(err) );
1373 		}
1374 
1375 		scope(exit) Str.freeString(retStr);
1376 		return Str.toString(retStr);
1377 	}
1378 
1379 	/**
1380 	 * Decreases the reference count of @key_file by 1. If the reference count
1381 	 * reaches zero, frees the key file and all its allocated memory.
1382 	 *
1383 	 * Since: 2.32
1384 	 */
1385 	public void unref()
1386 	{
1387 		g_key_file_unref(gKeyFile);
1388 	}
1389 
1390 	/** */
1391 	public static GQuark errorQuark()
1392 	{
1393 		return g_key_file_error_quark();
1394 	}
1395 }