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