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