1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
|
/* amide_gconf.c
*
* Part of amide - Amide's a Medical Image Dataset Examiner
*
* Copyright (C) 2007-2014 Andy Loening except as follows
* win32 registery code is derived directly from gnumeric
*
* Author: Andy Loening <loening@alum.mit.edu>
*/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "amide_gconf.h"
#if defined (G_PLATFORM_WIN32)
/* --------------------------- win32 version --------------------------- */
/* Note, this stuff has been adapted from gnumeric,
specifically the file gnm-conf-win32.c
*/
#include <windows.h>
#include <errno.h>
#ifndef ERANGE
/* mingw has not defined ERANGE (yet), MSVC has it though */
# define ERANGE 34
#endif
typedef struct _GOConfNode GOConfNode;
struct _GOConfNode {
HKEY hKey;
gchar *path;
};
static GOConfNode *root = NULL;
static void go_conf_win32_clone (HKEY hSrcKey, gchar *key, HKEY hDstKey, gchar *buf1, gchar *buf2, gchar *buf3) {
#define WIN32_MAX_REG_KEYNAME_LEN 256
#define WIN32_MAX_REG_VALUENAME_LEN 32767
#define WIN32_INIT_VALUE_DATA_LEN 2048
gint i;
gchar *subkey, *value_name, *data;
DWORD name_size, type, data_size;
HKEY hSrcSK, hDstSK;
FILETIME ft;
LONG ret;
if (RegOpenKeyEx (hSrcKey, key, 0, KEY_READ, &hSrcSK) != ERROR_SUCCESS)
return;
if (!buf1) {
subkey = g_malloc (WIN32_MAX_REG_KEYNAME_LEN);
value_name = g_malloc (WIN32_MAX_REG_VALUENAME_LEN);
data = g_malloc (WIN32_INIT_VALUE_DATA_LEN);
}
else {
subkey = buf1;
value_name = buf2;
data = buf3;
}
ret = ERROR_SUCCESS;
for (i = 0; ret == ERROR_SUCCESS; ++i) {
name_size = WIN32_MAX_REG_KEYNAME_LEN;
ret = RegEnumKeyEx (hSrcSK, i, subkey, &name_size, NULL, NULL, NULL, &ft);
if (ret != ERROR_SUCCESS)
continue;
if (RegCreateKeyEx (hDstKey, subkey, 0, NULL, 0, KEY_WRITE,
NULL, &hDstSK, NULL) == ERROR_SUCCESS) {
go_conf_win32_clone (hSrcSK, subkey, hDstSK, subkey, value_name, data);
RegCloseKey (hDstSK);
}
}
ret = ERROR_SUCCESS;
for (i = 0; ret == ERROR_SUCCESS; ++i) {
name_size = WIN32_MAX_REG_KEYNAME_LEN;
data_size = WIN32_MAX_REG_VALUENAME_LEN;
while ((ret = RegEnumValue (hSrcSK, i, value_name, &name_size,
NULL, &type, data, &data_size)) ==
ERROR_MORE_DATA)
data = g_realloc (data, data_size);
if (ret != ERROR_SUCCESS)
continue;
RegSetValueEx (hDstKey, value_name, 0, type, data, data_size);
}
RegCloseKey (hSrcSK);
if (!buf1) {
g_free (subkey);
g_free (value_name);
g_free (data);
}
}
static gboolean go_conf_win32_get_node (GOConfNode *node, HKEY *phKey, const gchar *key, gboolean *is_new) {
gchar *path, *c;
LONG ret;
DWORD disposition;
path = g_strconcat (node ? "" : "Software\\", key, NULL);
for (c = path; *c; ++c) {
if (*c == '/')
*c = '\\';
}
ret = RegCreateKeyEx (node ? node->hKey : HKEY_CURRENT_USER, path,
0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
NULL, phKey, &disposition);
g_free (path);
if (is_new)
*is_new = disposition == REG_CREATED_NEW_KEY;
#ifdef AMIDE_DEBUG
if (ret != ERROR_SUCCESS) {
LPTSTR msg_buf;
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ret,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msg_buf,
0,
NULL);
g_warning("Unable to save key '%s' : because %s", key, msg_buf);
}
#endif
return ret == ERROR_SUCCESS;
}
GOConfNode * go_conf_get_node (GOConfNode *parent, const gchar *key) {
HKEY hKey;
GOConfNode *node = NULL;
gboolean is_new;
if (go_conf_win32_get_node (parent, &hKey, key, &is_new)) {
if (!parent && is_new) {
gchar *path;
path = g_strconcat (".DEFAULT\\Software\\", key, NULL);
go_conf_win32_clone (HKEY_USERS, path, hKey, NULL, NULL, NULL);
g_free (path);
}
node = g_malloc (sizeof (GOConfNode));
node->hKey = hKey;
node->path = g_strdup (key);
}
return node;
}
static gboolean go_conf_win32_set (GOConfNode *node, const gchar *key, gint type, guchar *data, gint size) {
gchar *last_sep, *path = NULL;
HKEY hKey;
gboolean ok;
gboolean newpath=FALSE;
if ((last_sep = strrchr (key, '/')) != NULL) {
path = g_strndup (key, last_sep - key);
ok = go_conf_win32_get_node (node, &hKey, path, NULL);
g_free (path);
newpath=TRUE;
if (!ok) {
return FALSE;
}
key = last_sep + 1;
} else
hKey = node->hKey;
ok = RegSetValueEx (hKey, key, 0, type, data, size);
if (ok != ERROR_SUCCESS) {
#ifdef AMIDE_DEBUG
LPTSTR msg_buf;
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ok,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msg_buf,
0,
NULL);
g_warning("Unable to save key '%s' : because %s", key, msg_buf);
#endif
return FALSE;
}
if (newpath)
RegCloseKey (hKey);
return TRUE;
}
static gboolean go_conf_win32_get (GOConfNode *node, const gchar *key,
gulong *type, guchar **data, gulong *size,
gboolean realloc, gint *ret_code) {
gchar *last_sep, *path = NULL;
HKEY hKey;
LONG ret;
gboolean ok;
if ((last_sep = strrchr (key, '/')) != NULL) {
path = g_strndup (key, last_sep - key);
ok = go_conf_win32_get_node (node, &hKey, path, NULL);
g_free (path);
if (!ok) {
return FALSE;
}
key = last_sep + 1;
}
else
hKey = node->hKey;
if (!*data && realloc) {
RegQueryValueEx (hKey, key, NULL, type, NULL, size);
*data = g_new (guchar, *size);
}
while ((ret = RegQueryValueEx (hKey, key, NULL,
type, *data, size)) == ERROR_MORE_DATA &&
realloc)
*data = g_realloc (*data, *size);
if (path)
RegCloseKey (hKey);
if (ret_code)
*ret_code = ret;
return ret == ERROR_SUCCESS;
}
static guchar * go_conf_get (GOConfNode *node, const gchar *key, gulong expected) {
gulong type, size = 0;
guchar *ptr = NULL;
gint ret_code;
if (!go_conf_win32_get (node, key, &type, &ptr, &size, TRUE, &ret_code)) {
#ifdef AMIDE_DEBUG
LPTSTR msg_buf;
FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ret_code,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &msg_buf,
0,
NULL);
g_warning("Unable to load key '%s' : because %s", key, msg_buf);
LocalFree (msg_buf);
#endif
g_free (ptr);
return NULL;
}
if (type != expected) {
#ifdef AMIDE_DEBUG
g_warning("Expected `%lu' got `%lu' for key %s of node %s", expected, type, key, node->path);
#endif
g_free (ptr);
return NULL;
}
return ptr;
}
void amide_gconf_init(void) {
root = go_conf_get_node (NULL, PACKAGE);
return;
}
void amide_gconf_shutdown(void) {
if (root) {
RegCloseKey (root->hKey);
g_free (root->path);
g_free (root);
}
return;
}
gboolean amide_gconf_get_bool_with_default(const gchar * group, const gchar *key, gboolean default_val) {
guchar * val;
gboolean res;
gchar * real_key;
real_key = g_strdup_printf("%s/%s",group,key);
val = go_conf_get (root, real_key, REG_BINARY);
g_free(real_key);
if (val) {
res = (gboolean) *val;
g_free (val);
return res;
} else {
return default_val;
}
}
gboolean amide_gconf_get_bool(const gchar * group, const gchar * key) {
return amide_gconf_get_bool_with_default(group, key,FALSE);
}
gint amide_gconf_get_int_with_default(const gchar * group, const gchar *key, gint default_val) {
guchar * val;
gint res;
gchar * real_key;
real_key = g_strdup_printf("%s/%s",group,key);
val = go_conf_get (root, real_key, REG_DWORD);
g_free(real_key);
if (val) {
res = *(gint *) val;
g_free (val);
return res;
} else {
return default_val;
}
}
gint amide_gconf_get_int(const gchar * group, const gchar * key) {
return amide_gconf_get_int_with_default(group, key,0);
}
gdouble amide_gconf_get_float_with_default(const gchar * group, const gchar *key, gdouble default_val) {
gdouble res = -1;
gchar *val;
gboolean valid=FALSE;
gchar * real_key;
real_key = g_strdup_printf("%s/%s",group,key);
val = (gchar *) go_conf_get (root, real_key, REG_SZ);
g_free(real_key);
if (val) {
res = g_ascii_strtod (val, NULL);
if (errno != ERANGE) valid = TRUE;
g_free(val);
}
if (!valid)
return default_val;
else
return res;
}
gdouble amide_gconf_get_float(const gchar * group, const gchar * key) {
return amide_gconf_get_float_with_default(group, key, 0.0);
}
/* returns an allocated string that'll need to be free'd */
gchar * amide_gconf_get_string_with_default(const gchar * group, const gchar * key, const gchar * default_str) {
gchar * val;
gchar * real_key;
real_key = g_strdup_printf("%s/%s",group,key);
val = (gchar *) go_conf_get(root, real_key, REG_SZ);
g_free(real_key);
if (val)
return val;
else
return g_strdup(default_str);
}
/* returns an allocated string that'll need to be free'd */
gchar * amide_gconf_get_string (const gchar * group, const gchar *key) {
return amide_gconf_get_string_with_default(group, key,NULL);
}
gboolean amide_gconf_set_int(const gchar * group, const gchar *key, gint val) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("%s/%s",group,key);
return_val = go_conf_win32_set (root, real_key, REG_DWORD, (guchar *) &val, sizeof (DWORD));
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_float(const gchar * group, const char *key, gdouble val) {
gchar * real_key;
gboolean return_val;
gchar str[G_ASCII_DTOSTR_BUF_SIZE];
g_ascii_dtostr (str, sizeof (str), val);
real_key = g_strdup_printf("%s/%s",group,key);
return_val = go_conf_win32_set(root, real_key, REG_SZ, (guchar *) str, strlen (str) + 1);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_bool(const gchar * group, const gchar *key, gboolean val) {
gchar * real_key;
gboolean return_val;
guchar bool = val ? 1 : 0;
real_key = g_strdup_printf("%s/%s",group,key);
return_val = go_conf_win32_set (root, real_key, REG_BINARY, (guchar *) &bool, sizeof (bool));
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_string (const gchar * group, const char *key, const gchar *str) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("%s/%s",group,key);
return_val = go_conf_win32_set(root, real_key, REG_SZ, (guchar *) str, strlen (str) + 1);
g_free(real_key);
return return_val;
}
#elif defined(AMIDE_NATIVE_GTK_OSX) || !defined(AMIDE_USE_GCONF)
/* --------------------- flatfile version ----------------- */
#include <glib/gstdio.h>
#include <errno.h>
static GKeyFile *key_file = NULL;
static gchar * rcfilename = NULL;
void amide_gconf_init(void) {
const gchar *home;
home = g_get_home_dir();
g_return_if_fail(home != NULL);
rcfilename = g_build_filename (home, ".amiderc", NULL);
g_return_if_fail(rcfilename != NULL);
/* generate the key file, and load it in if a prior .ammiderc file exists */
key_file = g_key_file_new();
g_key_file_load_from_file(key_file, rcfilename, G_KEY_FILE_NONE, NULL);
return;
}
void amide_gconf_shutdown(void) {
FILE *fp = NULL;
gchar *key_data;
g_return_if_fail(rcfilename != NULL);
g_return_if_fail(key_file != NULL);
fp = g_fopen (rcfilename, "w");
if (fp == NULL) {
g_warning ("Couldn't write configuration info to %s", rcfilename);
return;
}
key_data = g_key_file_to_data (key_file, NULL, NULL);
if (key_data != NULL) {
fputs (key_data, fp);
g_free (key_data);
}
fclose (fp);
return;
}
gboolean amide_gconf_get_bool_with_default(const gchar * group, const gchar *key, gboolean default_val) {
gboolean val;
GError *error=NULL;
g_return_val_if_fail(key_file != NULL, default_val);
val = g_key_file_get_boolean (key_file, group, key, &error);
if (error != NULL) {
g_error_free(error);
return default_val;
} else
return val;
}
gboolean amide_gconf_get_bool(const gchar * group, const gchar * key) {
return amide_gconf_get_bool_with_default(group,key,FALSE);
}
gint amide_gconf_get_int_with_default(const gchar * group, const gchar *key, gint default_val) {
gint val;
GError *error=NULL;
g_return_val_if_fail(key_file != NULL, default_val);
val = g_key_file_get_integer(key_file, group, key, &error);
if (error != NULL) {
g_error_free(error);
return default_val;
} else
return val;
}
gint amide_gconf_get_int(const gchar * group, const gchar * key) {
return amide_gconf_get_int_with_default(group, key,0);
}
gdouble amide_gconf_get_float_with_default(const gchar * group, const gchar *key,gdouble default_val) {
gchar *ptr;
gdouble val;
GError *error=NULL;
gboolean valid = FALSE;
g_return_val_if_fail(key_file != NULL, default_val);
ptr = g_key_file_get_value (key_file, group, key, &error);
if ((ptr != NULL) && (error == NULL)) {
val = g_ascii_strtod (ptr, NULL);
if (errno != ERANGE) valid = TRUE;
}
if (ptr != NULL)
g_free (ptr);
if (!valid)
val = default_val;
return val;
}
gdouble amide_gconf_get_float(const gchar * group, const gchar * key) {
return amide_gconf_get_float_with_default(group, key, 0.0);
}
/* returns an allocated string that'll need to be free'd */
gchar * amide_gconf_get_string_with_default(const gchar * group, const gchar * key, const gchar * default_val) {
gchar *val;
GError *error=NULL;
g_return_val_if_fail(key_file != NULL, NULL);
val = g_key_file_get_string(key_file, group, key, &error);
if(error == NULL)
return val;
else
return g_strdup(default_val);
}
/* returns an allocated string that'll need to be free'd */
gchar * amide_gconf_get_string (const gchar * group, const gchar *key) {
return amide_gconf_get_string_with_default(group, key,NULL);
}
gboolean amide_gconf_set_bool(const gchar * group, const gchar *key, gboolean val) {
g_return_val_if_fail(key_file != NULL, FALSE);
g_key_file_set_boolean(key_file, group, key, val);
return TRUE;
}
gboolean amide_gconf_set_int(const gchar * group, const gchar *key, gint val) {
g_return_val_if_fail(key_file != NULL, FALSE);
g_key_file_set_integer(key_file, group, key, val);
return TRUE;
}
gboolean amide_gconf_set_float(const gchar * group, const char *key, gdouble val) {
g_return_val_if_fail(key_file != NULL, FALSE);
g_key_file_set_double(key_file, group, key, val);
return TRUE;
}
gboolean amide_gconf_set_string (const gchar * group, const char *key, const gchar *val) {
g_return_val_if_fail(key_file != NULL, FALSE);
g_key_file_set_string (key_file, group, key, val);
return TRUE;
}
#else
/* ------------------- gconf version ---------------------- */
#include <gconf/gconf-client.h>
#include <errno.h>
/* internal variables */
static GConfClient * client=NULL;
void amide_gconf_init(void) {
client = gconf_client_get_default();
return;
}
void amide_gconf_shutdown(void) {
g_object_unref(client);
return;
}
gint amide_gconf_get_int(const gchar * group, const gchar * key) {
gchar * real_key;
gint return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_get_int(client,real_key,NULL);
g_free(real_key);
return return_val;
}
gdouble amide_gconf_get_float(const gchar * group, const gchar * key) {
gchar * real_key;
gdouble return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_get_float(client,real_key,NULL);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_get_bool(const gchar * group, const gchar * key) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_get_bool(client,real_key,NULL);
g_free(real_key);
return return_val;
}
gchar * amide_gconf_get_string(const gchar * group, const gchar * key) {
gchar * real_key;
gchar * return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_get_string(client,real_key,NULL);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_int(const gchar * group, const gchar * key, gint val) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_set_int(client,real_key,val,NULL);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_float(const gchar * group, const gchar * key, gdouble val) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_set_float(client,real_key,val,NULL);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_bool(const gchar * group, const gchar * key, gboolean val) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
return_val = gconf_client_set_bool(client,real_key,val,NULL);
g_free(real_key);
return return_val;
}
gboolean amide_gconf_set_string(const gchar * group, const gchar * key, const gchar * val) {
gchar * real_key;
gboolean return_val;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group, key);
return_val = gconf_client_set_string(client,real_key,val,NULL);
g_free(real_key);
return return_val;
}
/* it's pretty retarded that gconf doesn't have a function that can do this more easily */
static gboolean amide_gconf_has_value(const gchar * group, const gchar *key) {
GConfValue * temp_val;
gchar * real_key;
real_key = g_strdup_printf("/apps/%s/%s/%s",PACKAGE,group,key);
temp_val = gconf_client_get(client, real_key, NULL);
g_free(real_key);
if (temp_val == NULL) return FALSE;
gconf_value_free(temp_val);
return TRUE;
}
/* some helper functions */
gint amide_gconf_get_int_with_default(const gchar * group, const gchar * key, const gint default_int) {
if (amide_gconf_has_value(group, key))
return amide_gconf_get_int(group, key);
else
return default_int;
}
gdouble amide_gconf_get_float_with_default(const gchar * group, const gchar * key, const gdouble default_float) {
if (amide_gconf_has_value(group, key))
return amide_gconf_get_float(group, key);
else
return default_float;
}
gboolean amide_gconf_get_bool_with_default(const gchar * group, const gchar * key, const gboolean default_bool) {
if (amide_gconf_has_value(group, key))
return amide_gconf_get_bool(group, key);
else
return default_bool;
}
/* returns an allocated string that'll need to be free'd */
gchar * amide_gconf_get_string_with_default(const gchar * group, const gchar * key, const gchar * default_str) {
if (amide_gconf_has_value(group, key))
return amide_gconf_get_string(group, key);
else
return g_strdup(default_str);
}
#endif
|