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