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