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