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