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