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