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