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