comparison src/prefs.c @ 5814:fb9209877f37

[gaim-migrate @ 6244] more useful errors when we try to use an unknown pref, or use a pref as a different type than it was defined committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 08 Jun 2003 15:35:28 +0000
parents 2adc29c88a45
children 6aa7651c7c15
comparison
equal deleted inserted replaced
5813:b116f3a73256 5814:fb9209877f37
384 } 384 }
385 385
386 void gaim_prefs_trigger_callback(const char *name) { 386 void gaim_prefs_trigger_callback(const char *name) {
387 struct gaim_pref *pref = find_pref(name); 387 struct gaim_pref *pref = find_pref(name);
388 388
389 g_return_if_fail(pref != NULL); 389 if(!pref) {
390 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
391 "gaim_prefs_trigger_callback: Unknown pref %s\n", name);
392 return;
393 }
394
390 do_callbacks(name, pref); 395 do_callbacks(name, pref);
391 } 396 }
392 397
393 void gaim_prefs_set_generic(const char *name, gpointer value) { 398 void gaim_prefs_set_generic(const char *name, gpointer value) {
394 struct gaim_pref *pref = find_pref(name); 399 struct gaim_pref *pref = find_pref(name);
395 400
396 g_return_if_fail(pref != NULL); 401 if(!pref) {
402 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
403 "gaim_prefs_set_generic: Unknown pref %s\n", name);
404 return;
405 }
397 406
398 pref->value.generic = value; 407 pref->value.generic = value;
399 do_callbacks(name, pref); 408 do_callbacks(name, pref);
400 } 409 }
401 410
402 void gaim_prefs_set_bool(const char *name, gboolean value) { 411 void gaim_prefs_set_bool(const char *name, gboolean value) {
403 struct gaim_pref *pref = find_pref(name); 412 struct gaim_pref *pref = find_pref(name);
404 413
405 if(pref) { 414 if(pref) {
406 g_return_if_fail(pref->type == GAIM_PREF_BOOLEAN); 415 if(pref->type != GAIM_PREF_BOOLEAN) {
416 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
417 "gaim_prefs_set_bool: %s not a boolean pref\n", name);
418 return;
419 }
407 420
408 if(pref->value.boolean != value) { 421 if(pref->value.boolean != value) {
409 pref->value.boolean = value; 422 pref->value.boolean = value;
410 do_callbacks(name, pref); 423 do_callbacks(name, pref);
411 } 424 }
416 429
417 void gaim_prefs_set_int(const char *name, int value) { 430 void gaim_prefs_set_int(const char *name, int value) {
418 struct gaim_pref *pref = find_pref(name); 431 struct gaim_pref *pref = find_pref(name);
419 432
420 if(pref) { 433 if(pref) {
421 g_return_if_fail(pref->type == GAIM_PREF_INT); 434 if(pref->type != GAIM_PREF_INT) {
435 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
436 "gaim_prefs_set_int: %s not an integer pref\n", name);
437 return;
438 }
422 439
423 if(pref->value.integer != value) { 440 if(pref->value.integer != value) {
424 pref->value.integer = value; 441 pref->value.integer = value;
425 do_callbacks(name, pref); 442 do_callbacks(name, pref);
426 } 443 }
431 448
432 void gaim_prefs_set_string(const char *name, const char *value) { 449 void gaim_prefs_set_string(const char *name, const char *value) {
433 struct gaim_pref *pref = find_pref(name); 450 struct gaim_pref *pref = find_pref(name);
434 451
435 if(pref) { 452 if(pref) {
436 g_return_if_fail(pref->type == GAIM_PREF_STRING); 453 if(pref->type != GAIM_PREF_STRING) {
454 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
455 "gaim_prefs_set_string: %s not a string pref\n", name);
456 return;
457 }
437 458
438 if(strcmp(pref->value.string, value)) { 459 if(strcmp(pref->value.string, value)) {
439 g_free(pref->value.string); 460 g_free(pref->value.string);
440 pref->value.string = g_strdup(value); 461 pref->value.string = g_strdup(value);
441 do_callbacks(name, pref); 462 do_callbacks(name, pref);
447 468
448 void gaim_prefs_set_string_list(const char *name, GList *value) { 469 void gaim_prefs_set_string_list(const char *name, GList *value) {
449 struct gaim_pref *pref = find_pref(name); 470 struct gaim_pref *pref = find_pref(name);
450 if(pref) { 471 if(pref) {
451 GList *tmp; 472 GList *tmp;
473
474 if(pref->type != GAIM_PREF_STRING_LIST) {
475 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
476 "gaim_prefs_set_string_list: %s not a string list pref\n",
477 name);
478 return;
479 }
480
452 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) 481 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
453 g_free(tmp->data); 482 g_free(tmp->data);
454 483
455 g_list_free(pref->value.stringlist); 484 g_list_free(pref->value.stringlist);
456 pref->value.stringlist = NULL; 485 pref->value.stringlist = NULL;
465 } 494 }
466 495
467 gpointer gaim_prefs_get_generic(const char *name) { 496 gpointer gaim_prefs_get_generic(const char *name) {
468 struct gaim_pref *pref = find_pref(name); 497 struct gaim_pref *pref = find_pref(name);
469 498
470 g_return_val_if_fail(pref != NULL, NULL); 499 if(!pref) {
500 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
501 "gaim_prefs_get_generic: Unknown pref %s\n", name);
502 return NULL;
503 }
471 504
472 return pref->value.generic; 505 return pref->value.generic;
473 } 506 }
474 507
475 gboolean gaim_prefs_get_bool(const char *name) { 508 gboolean gaim_prefs_get_bool(const char *name) {
476 struct gaim_pref *pref = find_pref(name); 509 struct gaim_pref *pref = find_pref(name);
477 510
478 g_return_val_if_fail(pref != NULL, FALSE); 511 if(!pref) {
479 g_return_val_if_fail(pref->type == GAIM_PREF_BOOLEAN, FALSE); 512 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
513 "gaim_prefs_get_bool: Unknown pref %s\n", name);
514 return FALSE;
515 } else if(pref->type != GAIM_PREF_BOOLEAN) {
516 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
517 "gaim_prefs_get_bool: %s not a boolean pref\n", name);
518 return FALSE;
519 }
480 520
481 return pref->value.boolean; 521 return pref->value.boolean;
482 } 522 }
483 523
484 int gaim_prefs_get_int(const char *name) { 524 int gaim_prefs_get_int(const char *name) {
485 struct gaim_pref *pref = find_pref(name); 525 struct gaim_pref *pref = find_pref(name);
486 526
487 g_return_val_if_fail(pref != NULL, 0); 527 if(!pref) {
488 g_return_val_if_fail(pref->type == GAIM_PREF_INT, 0); 528 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
529 "gaim_prefs_get_int: Unknown pref %s\n", name);
530 return 0;
531 } else if(pref->type != GAIM_PREF_INT) {
532 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
533 "gaim_prefs_get_int: %s not an integer pref\n", name);
534 return 0;
535 }
489 536
490 return pref->value.integer; 537 return pref->value.integer;
491 } 538 }
492 539
493 const char *gaim_prefs_get_string(const char *name) { 540 const char *gaim_prefs_get_string(const char *name) {
494 struct gaim_pref *pref = find_pref(name); 541 struct gaim_pref *pref = find_pref(name);
495 542
496 g_return_val_if_fail(pref != NULL, NULL); 543 if(!pref) {
497 g_return_val_if_fail(pref->type == GAIM_PREF_STRING, NULL); 544 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
545 "gaim_prefs_get_string: Unknown pref %s\n", name);
546 return NULL;
547 } else if(pref->type != GAIM_PREF_STRING) {
548 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
549 "gaim_prefs_get_string: %s not a string pref\n", name);
550 return NULL;
551 }
498 552
499 return pref->value.string; 553 return pref->value.string;
500 } 554 }
501 555
502 GList *gaim_prefs_get_string_list(const char *name) { 556 GList *gaim_prefs_get_string_list(const char *name) {
503 struct gaim_pref *pref = find_pref(name); 557 struct gaim_pref *pref = find_pref(name);
504 GList *ret = NULL, *tmp; 558 GList *ret = NULL, *tmp;
505 559
506 g_return_val_if_fail(pref != NULL, NULL); 560 if(!pref) {
507 g_return_val_if_fail(pref->type == GAIM_PREF_STRING_LIST, NULL); 561 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
562 "gaim_prefs_get_string_list: Unknown pref %s\n", name);
563 return NULL;
564 } else if(pref->type != GAIM_PREF_STRING_LIST) {
565 gaim_debug(GAIM_DEBUG_ERROR, "prefs",
566 "gaim_prefs_get_string_list: %s not a string list pref\n", name);
567 return NULL;
568 }
508 569
509 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) 570 for(tmp = pref->value.stringlist; tmp; tmp = tmp->next)
510 ret = g_list_append(ret, g_strdup(tmp->data)); 571 ret = g_list_append(ret, g_strdup(tmp->data));
511 572
512 return ret; 573 return ret;