28 #include <glib/gi18n.h>
33 #include "option-util.h"
34 #include "engine-helpers-guile.h"
35 #include "glib-helpers.h"
36 #include "gnc-guile-utils.h"
38 #include "guile-mappings.h"
40 #include "swig-runtime.h"
77 GSList *option_sections;
79 gboolean options_dirty;
81 GNCOptionDBHandle handle;
83 GNCOptionGetUIValue get_ui_value;
84 GNCOptionSetUIValue set_ui_value;
85 GNCOptionSetSelectable set_selectable;
102 SCM index_to_description;
105 SCM number_of_indices;
106 SCM option_widget_changed_cb;
107 SCM date_option_subtype;
108 SCM date_option_show_time;
109 SCM date_option_value_type;
110 SCM date_option_value_absolute;
111 SCM date_option_value_relative;
117 static Getters getters = {0, 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0, 0
124 static GHashTable *option_dbs = NULL;
125 static int last_db_handle = 0;
130 gnc_option_set_changed (
GNCOption *option, gboolean changed)
132 g_return_if_fail (option != NULL);
133 option->changed = changed;
137 gnc_option_get_widget (
GNCOption *option)
139 if (!option)
return NULL;
140 return option->widget;
144 gnc_option_set_widget (
GNCOption *option, gpointer widget)
146 g_return_if_fail (option != NULL);
147 option->widget = widget;
151 gnc_option_get_ui_value (
GNCOption *option)
153 g_return_val_if_fail (option != NULL, SCM_UNDEFINED);
154 g_return_val_if_fail (option->odb != NULL, SCM_UNDEFINED);
155 g_return_val_if_fail (option->odb->get_ui_value != NULL, SCM_UNDEFINED);
157 return option->odb->get_ui_value (option);
161 gnc_option_set_ui_value (
GNCOption *option, gboolean use_default)
163 g_return_if_fail (option != NULL);
164 g_return_if_fail (option->odb != NULL);
166 if (!option->odb->set_ui_value)
169 option->odb->set_ui_value (option, use_default);
173 gnc_option_set_selectable (
GNCOption *option, gboolean selectable)
175 g_return_if_fail (option != NULL);
176 g_return_if_fail (option->odb != NULL);
177 g_return_if_fail (option->odb->set_selectable != NULL);
179 option->odb->set_selectable (option, selectable);
192 SCM func = scm_c_eval_string(
"gnc:send-options");
194 scm_call_2(func, scm_from_int (odb->handle), odb->guile_options);
206 gnc_option_db_new(SCM guile_options)
213 odb->guile_options = guile_options;
214 scm_gc_protect_object(guile_options);
216 odb->option_sections = NULL;
217 odb->options_dirty = FALSE;
219 if (option_dbs == NULL)
220 option_dbs = g_hash_table_new(g_int_hash, g_int_equal);
224 odb->handle = last_db_handle++;
225 lookup = g_hash_table_lookup(option_dbs, &odb->handle);
227 while (lookup != NULL);
229 g_hash_table_insert(option_dbs, &odb->handle, odb);
231 gnc_option_db_init(odb);
243 option_db_finder (gpointer key, gpointer value, gpointer data)
248 if (odb && (odb->guile_options == find_info->guile_options))
249 find_info->odb = odb;
253 gnc_option_db_find (SCM guile_options)
257 find_info.odb = NULL;
258 find_info.guile_options = guile_options;
260 g_hash_table_foreach (option_dbs, option_db_finder, &find_info);
262 return find_info.odb;
267 gnc_option_db_new_for_type(
QofIdType id_type)
271 if (!id_type)
return NULL;
272 options = gnc_make_kvp_options(id_type);
273 return gnc_option_db_new (options);
279 static SCM kvp_to_scm = SCM_UNDEFINED;
280 static SCM kvp_option_path = SCM_UNDEFINED;
283 if (!odb || !slots)
return;
285 if (kvp_to_scm == SCM_UNDEFINED)
287 kvp_to_scm = scm_c_eval_string(
"gnc:options-kvp->scm");
288 if (!scm_is_procedure (kvp_to_scm))
290 PERR (
"not a procedure\n");
291 kvp_to_scm = SCM_UNDEFINED;
296 if (kvp_option_path == SCM_UNDEFINED)
298 kvp_option_path = scm_c_eval_string(
"gnc:*kvp-option-path*");
299 if (kvp_option_path == SCM_UNDEFINED)
301 PERR (
"can't find the option path");
305 scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery(
"_p_KvpFrame"), 0);
307 scm_call_3 (kvp_to_scm, odb->guile_options, scm_slots, kvp_option_path);
313 static SCM scm_to_kvp = SCM_UNDEFINED;
314 static SCM kvp_option_path = SCM_UNDEFINED;
318 if (!odb || !slots)
return;
320 if (scm_to_kvp == SCM_UNDEFINED)
322 scm_to_kvp = scm_c_eval_string(
"gnc:options-scm->kvp");
323 if (!scm_is_procedure (scm_to_kvp))
325 PERR (
"not a procedure\n");
326 scm_to_kvp = SCM_UNDEFINED;
331 if (kvp_option_path == SCM_UNDEFINED)
333 kvp_option_path = scm_c_eval_string(
"gnc:*kvp-option-path*");
334 if (kvp_option_path == SCM_UNDEFINED)
336 PERR (
"can't find the option path");
340 scm_slots = SWIG_NewPointerObj(slots, SWIG_TypeQuery(
"_p_KvpFrame"), 0);
341 scm_clear_kvp = scm_from_bool (clear_kvp);
343 scm_call_4 (scm_to_kvp, odb->guile_options, scm_slots, kvp_option_path, scm_clear_kvp);
362 for (snode = odb->option_sections; snode; snode = snode->next)
367 for (onode = section->options; onode; onode = onode->next)
371 scm_gc_unprotect_object(option->guile_option);
376 g_slist_free(section->options);
377 section->options = NULL;
379 if (section->section_name != NULL)
380 free(section->section_name);
381 section->section_name = NULL;
386 g_slist_free(odb->option_sections);
388 odb->option_sections = NULL;
389 odb->options_dirty = FALSE;
391 g_hash_table_remove(option_dbs, &odb->handle);
393 if (g_hash_table_size(option_dbs) == 0)
395 g_hash_table_destroy(option_dbs);
399 scm_gc_unprotect_object(odb->guile_options);
400 odb->guile_options = SCM_UNDEFINED;
407 GNCOptionGetUIValue get_ui_value,
408 GNCOptionSetUIValue set_ui_value,
409 GNCOptionSetSelectable set_selectable)
411 g_return_if_fail (odb != NULL);
413 odb->get_ui_value = get_ui_value;
414 odb->set_ui_value = set_ui_value;
415 odb->set_selectable = set_selectable;
433 gnc_option_db_register_change_callback(
GNCOptionDB *odb,
434 GNCOptionChangeCallback callback,
443 if (!odb || !callback)
444 return SCM_UNDEFINED;
447 register_proc = scm_c_eval_string(
"gnc:options-register-c-callback");
448 if (!scm_is_procedure(register_proc))
450 PERR(
"not a procedure\n");
451 return SCM_UNDEFINED;
458 args = scm_cons(odb->guile_options, args);
461 arg = SWIG_NewPointerObj(data, SWIG_TypeQuery(
"_p_void"), 0);
462 args = scm_cons(arg, args);
465 arg = SWIG_NewPointerObj(
466 callback, SWIG_TypeQuery(
"GNCOptionChangeCallback"), 0);
467 args = scm_cons(arg, args);
476 arg = scm_from_utf8_string(name);
478 args = scm_cons(arg, args);
487 arg = scm_from_utf8_string(section);
489 args = scm_cons(arg, args);
492 return scm_apply(register_proc, args, SCM_EOL);
505 gnc_option_db_unregister_change_callback_id(
GNCOptionDB *odb, SCM callback_id)
509 if (callback_id == SCM_UNDEFINED)
512 proc = scm_c_eval_string(
"gnc:options-unregister-callback-id");
513 if (!scm_is_procedure(proc))
515 PERR(
"not a procedure\n");
519 scm_call_2(proc, callback_id, odb->guile_options);
523 gncp_option_invoke_callback (GNCOptionChangeCallback callback,
void *data)
533 proc = scm_c_eval_string(
"gnc:options-run-callbacks");
534 if (!scm_is_procedure(proc))
536 PERR(
"not a procedure\n");
540 scm_call_1(proc, odb->guile_options);
545 initialize_getters(
void)
547 static gboolean getters_initialized = FALSE;
549 if (getters_initialized)
552 getters.section = scm_c_eval_string(
"gnc:option-section");
553 getters.name = scm_c_eval_string(
"gnc:option-name");
554 getters.type = scm_c_eval_string(
"gnc:option-type");
555 getters.sort_tag = scm_c_eval_string(
"gnc:option-sort-tag");
556 getters.documentation =
557 scm_c_eval_string(
"gnc:option-documentation");
558 getters.getter = scm_c_eval_string(
"gnc:option-getter");
559 getters.setter = scm_c_eval_string(
"gnc:option-setter");
560 getters.default_getter =
561 scm_c_eval_string(
"gnc:option-default-getter");
562 getters.value_validator =
563 scm_c_eval_string(
"gnc:option-value-validator");
564 getters.option_data = scm_c_eval_string(
"gnc:option-data");
565 getters.index_to_name = scm_c_eval_string(
"gnc:option-index-get-name");
566 getters.index_to_description =
567 scm_c_eval_string(
"gnc:option-index-get-description");
568 getters.number_of_indices = scm_c_eval_string(
"gnc:option-number-of-indices");
569 getters.index_to_value = scm_c_eval_string(
"gnc:option-index-get-value");
570 getters.value_to_index = scm_c_eval_string(
"gnc:option-value-get-index");
571 getters.option_widget_changed_cb =
572 scm_c_eval_string(
"gnc:option-widget-changed-proc");
573 getters.date_option_subtype = scm_c_eval_string(
"gnc:date-option-get-subtype");
574 getters.date_option_show_time = scm_c_eval_string(
"gnc:date-option-show-time?");
575 getters.date_option_value_type = scm_c_eval_string (
"gnc:date-option-value-type");
576 getters.date_option_value_absolute =
577 scm_c_eval_string(
"gnc:date-option-absolute-time");
578 getters.date_option_value_relative =
579 scm_c_eval_string(
"gnc:date-option-relative-time");
581 getters_initialized = TRUE;
596 initialize_getters();
598 return gnc_scm_call_1_to_string(getters.section, option->guile_option);
613 initialize_getters();
615 return gnc_scm_call_1_to_string(getters.name, option->guile_option);
630 initialize_getters();
632 return gnc_scm_call_1_symbol_to_string(getters.type,
633 option->guile_option);
648 initialize_getters();
650 return gnc_scm_call_1_to_string(getters.sort_tag, option->guile_option);
663 gnc_option_documentation(
GNCOption *option)
665 initialize_getters();
667 return gnc_scm_call_1_to_string(getters.documentation,
668 option->guile_option);
683 initialize_getters();
685 return gnc_scm_call_1_to_procedure(getters.getter,
686 option->guile_option);
701 initialize_getters();
703 return gnc_scm_call_1_to_procedure(getters.setter,
704 option->guile_option);
717 gnc_option_default_getter(
GNCOption *option)
719 initialize_getters();
721 return gnc_scm_call_1_to_procedure(getters.default_getter,
722 option->guile_option);
735 gnc_option_value_validator(
GNCOption *option)
737 initialize_getters();
739 return gnc_scm_call_1_to_procedure(getters.value_validator,
740 option->guile_option);
756 gnc_option_widget_changed_proc_getter(
GNCOption *option)
760 initialize_getters();
762 if ( scm_is_procedure( getters.option_widget_changed_cb ) )
765 cb = scm_call_1(getters.option_widget_changed_cb, option->guile_option);
767 if ( scm_is_procedure( cb ) )
775 PERR(
"getters.option_widget_changed_cb is not a valid procedure\n");
778 return( SCM_UNDEFINED );
792 gnc_option_call_option_widget_changed_proc(
GNCOption *option)
796 cb = gnc_option_widget_changed_proc_getter(option);
798 if ( cb != SCM_UNDEFINED )
800 value = gnc_option_get_ui_value(option);
802 if ( value != SCM_UNDEFINED )
804 scm_call_1(cb, value);
819 gnc_option_num_permissible_values(
GNCOption *option)
823 initialize_getters();
825 value = scm_call_1(getters.number_of_indices, option->guile_option);
827 if (scm_is_exact(value))
829 return scm_to_int(value);
848 gnc_option_permissible_value_index(
GNCOption *option, SCM search_value)
851 value = scm_call_2(getters.value_to_index, option->guile_option, search_value);
852 if (value == SCM_BOOL_F)
858 return scm_to_int(value);
874 gnc_option_permissible_value(
GNCOption *option,
int index)
879 return SCM_UNDEFINED;
881 initialize_getters();
883 value = scm_call_2(getters.index_to_value, option->guile_option,
884 scm_from_int (index));
901 gnc_option_permissible_value_name(
GNCOption *option,
int index)
908 initialize_getters();
910 name = scm_call_2(getters.index_to_name, option->guile_option,
911 scm_from_int (index));
912 if (name == SCM_UNDEFINED)
914 if (!scm_is_string(name))
917 return gnc_scm_to_utf8_string (name);
932 gnc_option_permissible_value_description(
GNCOption *option,
int index)
939 initialize_getters();
941 help = scm_call_2(getters.index_to_description, option->guile_option,
942 scm_from_int (index));
943 if (help == SCM_UNDEFINED)
945 if (!scm_is_string(help))
948 return gnc_scm_to_utf8_string (help);
965 initialize_getters();
967 value = scm_call_1(getters.date_option_show_time, option->guile_option);
969 return scm_is_true(value);
980 gnc_option_get_option_data(
GNCOption *option)
982 initialize_getters();
984 return scm_call_1(getters.option_data, option->guile_option);
997 gnc_option_multiple_selection(
GNCOption *option)
1001 initialize_getters();
1003 pair = scm_call_1(getters.option_data, option->guile_option);
1005 return !scm_is_true(scm_not(SCM_CAR(pair)));
1018 gnc_option_get_account_type_list(
GNCOption *option)
1022 GList *type_list = NULL;
1024 initialize_getters();
1026 pair = scm_call_1(getters.option_data, option->guile_option);
1027 lst = SCM_CDR(pair);
1029 while (!scm_is_null (lst))
1035 item = SCM_CAR (lst);
1036 lst = SCM_CDR (lst);
1038 if (scm_is_false (scm_integer_p (item)))
1040 PERR (
"Invalid type");
1044 type = scm_to_long (item);
1045 type_list = g_list_prepend (type_list, GINT_TO_POINTER (type));
1049 return g_list_reverse (type_list);
1062 gboolean gnc_option_get_range_info(
GNCOption *option,
1063 double *lower_bound,
1064 double *upper_bound,
1071 initialize_getters();
1073 list = scm_call_1(getters.option_data, option->guile_option);
1075 if (!scm_is_list(list) || scm_is_null(list))
1079 value = SCM_CAR(list);
1080 list = SCM_CDR(list);
1082 if (!scm_is_number(value))
1085 if (lower_bound != NULL)
1086 *lower_bound = scm_to_double(value);
1088 if (!scm_is_list(list) || scm_is_null(list))
1092 value = SCM_CAR(list);
1093 list = SCM_CDR(list);
1095 if (!scm_is_number(value))
1098 if (upper_bound != NULL)
1099 *upper_bound = scm_to_double(value);
1101 if (!scm_is_list(list) || scm_is_null(list))
1105 value = SCM_CAR(list);
1106 list = SCM_CDR(list);
1108 if (!scm_is_number(value))
1114 if (num_decimals != NULL)
1116 double decimals = scm_to_double(value);
1117 *num_decimals = (int)decimals;
1120 if (!scm_is_list(list) || scm_is_null(list))
1124 value = SCM_CAR(list);
1125 list = SCM_CDR(list);
1127 if (!scm_is_number(value))
1130 if (step_size != NULL)
1131 *step_size = scm_to_double(value);
1146 gnc_option_color_range(
GNCOption *option)
1151 initialize_getters();
1153 list = scm_call_1(getters.option_data, option->guile_option);
1154 if (!scm_is_list(list) || scm_is_null(list))
1157 value = SCM_CAR(list);
1158 if (!scm_is_number(value))
1161 return scm_to_double(value);
1179 initialize_getters();
1181 list = scm_call_1(getters.option_data, option->guile_option);
1182 if (!scm_is_list(list) || scm_is_null(list))
1185 list = SCM_CDR(list);
1186 if (!scm_is_list(list) || scm_is_null(list))
1189 value = SCM_CAR(list);
1190 if (!scm_is_bool(value))
1193 return scm_is_true(value);
1205 gnc_option_get_color_argb(
GNCOption *option)
1207 gdouble red, green, blue, alpha;
1210 if (!gnc_option_get_color_info(option, FALSE, &red, &green, &blue, &alpha))
1213 color |= (guint32) (alpha * 255.0);
1216 color |= (guint32) (red * 255.0);
1219 color |= (guint32) (green * 255.0);
1222 color |= (guint32) (blue * 255.0);
1242 gnc_option_get_color_info(
GNCOption *option,
1243 gboolean use_default,
1258 getter = gnc_option_default_getter(option);
1260 getter = gnc_option_getter(option);
1261 if (getter == SCM_UNDEFINED)
1264 value = scm_call_0(getter);
1265 if (!scm_is_list(value) || scm_is_null(value) || !scm_is_number(SCM_CAR(value)))
1268 scale = gnc_option_color_range(option);
1272 scale = 1.0 / scale;
1274 rgba = scm_to_double(SCM_CAR(value));
1276 *red = MIN(1.0, rgba * scale);
1278 value = SCM_CDR(value);
1279 if (!scm_is_list(value) || scm_is_null(value) || !scm_is_number(SCM_CAR(value)))
1282 rgba = scm_to_double(SCM_CAR(value));
1284 *green = MIN(1.0, rgba * scale);
1286 value = SCM_CDR(value);
1287 if (!scm_is_list(value) || scm_is_null(value) || !scm_is_number(SCM_CAR(value)))
1290 rgba = scm_to_double(SCM_CAR(value));
1292 *blue = MIN(1.0, rgba * scale);
1294 value = SCM_CDR(value);
1295 if (!scm_is_list(value) || scm_is_null(value) || !scm_is_number(SCM_CAR(value)))
1298 rgba = scm_to_double(SCM_CAR(value));
1300 *alpha = MIN(1.0, rgba * scale);
1314 gnc_option_set_default(
GNCOption *option)
1323 default_getter = gnc_option_default_getter(option);
1324 if (default_getter == SCM_UNDEFINED)
1327 value = scm_call_0(default_getter);
1329 setter = gnc_option_setter(option);
1330 if (setter == SCM_UNDEFINED)
1333 scm_call_1(setter, value);
1338 compare_sections(gconstpointer a, gconstpointer b)
1343 return g_strcmp0(sa->section_name, sb->section_name);
1347 compare_option_tags(gconstpointer a, gconstpointer b)
1351 char *tag_a = gnc_option_sort_tag(oa);
1352 char *tag_b = gnc_option_sort_tag(ob);
1355 result = g_strcmp0(tag_a, tag_b);
1376 g_return_val_if_fail (odb, FALSE);
1378 return odb->options_dirty;
1390 g_return_if_fail (odb);
1392 odb->options_dirty = FALSE;
1406 gnc_option_db_register_option(GNCOptionDBHandle handle, SCM guile_option)
1412 odb = g_hash_table_lookup(option_dbs, &handle);
1414 g_return_if_fail (odb != NULL);
1416 odb->options_dirty = TRUE;
1420 option->guile_option = guile_option;
1421 option->changed = FALSE;
1422 option->widget = NULL;
1426 scm_gc_protect_object(guile_option);
1431 section->options = NULL;
1437 old = g_slist_find_custom(odb->option_sections, section, compare_sections);
1441 if (section->section_name != NULL)
1442 free(section->section_name);
1444 section = old->data;
1447 odb->option_sections = g_slist_insert_sorted(odb->option_sections,
1448 section, compare_sections);
1451 section->options = g_slist_insert_sorted(section->options, option,
1452 compare_option_tags);
1467 return g_slist_length(odb->option_sections);
1480 gnc_option_db_get_section(
GNCOptionDB *odb, gint i)
1482 return g_slist_nth_data(odb->option_sections, i);
1496 return section->section_name;
1510 return g_slist_length(section->options);
1525 return g_slist_nth_data(section->options, i);
1539 gnc_option_db_get_option_by_name(
GNCOptionDB *odb,
const char *section_name,
1542 GSList *section_node;
1543 GSList *option_node;
1553 section_key.section_name = (
char *) section_name;
1555 section_node = g_slist_find_custom(odb->option_sections, §ion_key,
1558 if (section_node == NULL)
1561 section = section_node->data;
1562 option_node = section->options;
1564 while (option_node != NULL)
1566 option = option_node->data;
1568 node_name = gnc_option_name(option);
1569 result = g_strcmp0(name, node_name);
1575 option_node = option_node->next;
1591 gnc_option_db_get_option_by_SCM(
GNCOptionDB *odb, SCM guile_option)
1598 option_key.guile_option = guile_option;
1601 name = gnc_option_name(&option_key);
1603 option = gnc_option_db_get_option_by_name(odb, section_name, name);
1605 if (section_name != NULL)
1616 gnc_option_valid_value(
GNCOption *option, SCM value)
1621 validator = gnc_option_value_validator(option);
1623 result = scm_call_1(validator, value);
1624 if (!scm_is_list(result) || scm_is_null(result))
1625 return SCM_UNDEFINED;
1627 ok = SCM_CAR(result);
1628 if (!scm_is_bool(ok))
1629 return SCM_UNDEFINED;
1631 if (!scm_is_true(ok))
1632 return SCM_UNDEFINED;
1634 result = SCM_CDR(result);
1635 if (!scm_is_list(result) || scm_is_null(result))
1636 return SCM_UNDEFINED;
1638 return SCM_CAR(result);
1645 SCM validator, setter, value;
1649 value = gnc_option_get_ui_value(option);
1650 if (value == SCM_UNDEFINED)
1653 validator = gnc_option_value_validator(option);
1655 result = scm_call_1(validator, value);
1656 if (!scm_is_list(result) || scm_is_null(result))
1658 PERR(
"bad validation result\n");
1663 ok = SCM_CAR(result);
1664 if (!scm_is_bool(ok))
1666 PERR(
"bad validation result\n");
1670 if (scm_is_true(ok))
1673 value = SCM_CADR(result);
1674 setter = gnc_option_setter(option);
1676 scm_call_1(setter, value);
1678 gnc_option_set_ui_value (option, FALSE);
1683 char *section, *name;
1684 const gchar *message;
1685 const gchar *format = _(
"There is a problem with option %s:%s.\n%s");
1689 oops = SCM_CADR(result);
1690 if (!scm_is_string(oops))
1692 PERR(
"bad validation result\n");
1696 message = gnc_scm_to_utf8_string (oops);
1697 name = gnc_option_name(option);
1702 GtkWidget *dialog = gtk_message_dialog_new(NULL,
1707 section ? section :
"(null)",
1708 name ? name :
"(null)",
1709 message ? message :
"(null)");
1710 gtk_dialog_run(GTK_DIALOG(dialog));
1711 gtk_widget_destroy(dialog);
1715 section ? section :
"(null)",
1716 name ? name :
"(null)",
1717 message ? message :
"(null)");
1722 if (section != NULL)
1724 g_free ((gpointer *) message);
1740 GSList *section_node;
1741 GSList *option_node;
1745 g_return_val_if_fail (odb, FALSE);
1747 for (section_node = odb->option_sections; section_node;
1748 section_node = section_node->next)
1751 section = section_node->data;
1753 for (option_node = section->options; option_node;
1754 option_node = option_node->next)
1757 option = option_node->data;
1759 if (option->changed)
1778 GSList *section_node;
1779 GSList *option_node;
1782 gboolean changed_something = FALSE;
1784 g_return_if_fail (odb);
1786 section_node = odb->option_sections;
1787 while (section_node != NULL)
1789 section = section_node->data;
1791 option_node = section->options;
1792 while (option_node != NULL)
1794 option = option_node->data;
1796 if (option->changed)
1798 gnc_commit_option(option_node->data);
1799 changed_something = TRUE;
1800 option->changed = FALSE;
1803 option_node = option_node->next;
1806 section_node = section_node->next;
1809 if (changed_something)
1810 gnc_call_option_change_callbacks(odb);
1825 GSList *option_node;
1828 g_return_if_fail (section);
1833 if (section->section_name == NULL ||
1834 strncmp (section->section_name,
"__", 2) == 0)
1837 for (option_node = section->options;
1838 option_node != NULL;
1839 option_node = option_node->next)
1841 option = option_node->data;
1843 gnc_option_set_ui_value (option, TRUE);
1844 gnc_option_set_changed (option, TRUE);
1859 GSList *section_node;
1862 g_return_if_fail (odb);
1864 for (section_node = odb->option_sections;
1865 section_node != NULL;
1866 section_node = section_node->next)
1868 section = section_node->data;
1869 gnc_option_db_section_reset_widgets (section);
1883 gnc_option_db_get_default_section(
GNCOptionDB *odb)
1891 getter = scm_c_eval_string(
"gnc:options-get-default-section");
1892 if (!scm_is_procedure(getter))
1895 value = scm_call_1(getter, odb->guile_options);
1896 if (!scm_is_string(value))
1899 return gnc_scm_to_utf8_string (value);
1916 const char *section,
1923 option = gnc_option_db_get_option_by_name(odb, section, name);
1926 return default_value;
1928 getter = gnc_option_getter(option);
1929 if (getter == SCM_UNDEFINED)
1930 return default_value;
1932 return scm_call_0(getter);
1947 gnc_option_db_lookup_boolean_option(
GNCOptionDB *odb,
1948 const char *section,
1950 gboolean default_value)
1956 option = gnc_option_db_get_option_by_name(odb, section, name);
1959 return default_value;
1961 getter = gnc_option_getter(option);
1962 if (getter == SCM_UNDEFINED)
1963 return default_value;
1965 value = scm_call_0(getter);
1967 if (scm_is_bool(value))
1968 return scm_is_true(value);
1970 return default_value;
1987 gnc_option_db_lookup_string_option(
GNCOptionDB *odb,
1988 const char *section,
1990 const char *default_value)
1996 option = gnc_option_db_get_option_by_name(odb, section, name);
2000 getter = gnc_option_getter(option);
2001 if (getter != SCM_UNDEFINED)
2003 value = scm_call_0(getter);
2004 if (scm_is_string(value))
2005 return gnc_scm_to_utf8_string (value);
2009 if (default_value == NULL)
2012 return strdup(default_value);
2029 gnc_option_db_lookup_font_option(
GNCOptionDB *odb,
2030 const char *section,
2032 const char *default_value)
2034 return gnc_option_db_lookup_string_option(odb, section, name, default_value);
2052 gnc_option_db_lookup_multichoice_option(
GNCOptionDB *odb,
2053 const char *section,
2055 const char *default_value)
2061 option = gnc_option_db_get_option_by_name(odb, section, name);
2065 getter = gnc_option_getter(option);
2066 if (getter != SCM_UNDEFINED)
2068 value = scm_call_0(getter);
2069 if (scm_is_symbol(value))
2070 return gnc_scm_symbol_to_locale_string (value);
2074 if (default_value == NULL)
2077 return strdup(default_value);
2106 gnc_option_db_lookup_date_option(
GNCOptionDB *odb,
2107 const char *section,
2109 gboolean *is_relative,
2111 char **set_rel_value,
2120 initialize_getters();
2122 if (set_ab_value == NULL)
2124 set_ab_value = &temp;
2127 if (set_rel_value != NULL)
2129 *set_rel_value = NULL;
2132 if (is_relative != NULL)
2134 *is_relative = FALSE;
2137 option = gnc_option_db_get_option_by_name(odb, section, name);
2141 getter = gnc_option_getter(option);
2142 if (getter != SCM_UNDEFINED)
2144 value = scm_call_0(getter);
2146 if (scm_is_pair(value))
2150 absolute = gnc_date_option_value_get_absolute (value);
2152 *set_ab_value = absolute;
2154 symbol = gnc_date_option_value_get_type (value);
2156 if (g_strcmp0(symbol,
"relative") == 0)
2158 SCM relative = gnc_date_option_value_get_relative (value);
2160 if (is_relative != NULL)
2161 *is_relative = TRUE;
2163 if (set_rel_value != NULL)
2164 *set_rel_value = gnc_scm_symbol_to_locale_string (relative);
2173 if (default_value == NULL)
2175 set_ab_value->tv_sec =
gnc_time (NULL);
2176 set_ab_value->tv_nsec = 0;
2179 *set_ab_value = *default_value;
2182 return set_ab_value->tv_sec;
2198 gnc_option_db_lookup_number_option(
GNCOptionDB *odb,
2199 const char *section,
2201 gdouble default_value)
2207 option = gnc_option_db_get_option_by_name(odb, section, name);
2211 getter = gnc_option_getter(option);
2212 if (getter != SCM_UNDEFINED)
2214 value = scm_call_0(getter);
2215 if (scm_is_number(value))
2216 return scm_to_double(value);
2220 return default_value;
2238 gboolean gnc_option_db_lookup_color_option(
GNCOptionDB *odb,
2239 const char *section,
2248 option = gnc_option_db_get_option_by_name(odb, section, name);
2250 return gnc_option_get_color_info(option, FALSE, red, green, blue, alpha);
2265 guint32 gnc_option_db_lookup_color_option_argb(
GNCOptionDB *odb,
2266 const char *section,
2268 guint32 default_value)
2272 option = gnc_option_db_get_option_by_name(odb, section, name);
2274 return default_value;
2276 return gnc_option_get_color_argb(option);
2292 gnc_option_db_lookup_list_option(
GNCOptionDB *odb,
2293 const char *section,
2295 GSList *default_value)
2298 GSList *list = NULL;
2303 option = gnc_option_db_get_option_by_name(odb, section, name);
2305 return default_value;
2307 getter = gnc_option_getter(option);
2308 if (getter == SCM_UNDEFINED)
2309 return default_value;
2311 value = scm_call_0(getter);
2312 while (scm_is_list(value) && !scm_is_null(value))
2314 item = SCM_CAR(value);
2315 value = SCM_CDR(value);
2317 if (!scm_is_symbol(item))
2319 gnc_free_list_option_value(list);
2321 return default_value;
2324 list = g_slist_prepend(list, gnc_scm_symbol_to_locale_string (item));
2327 if (!scm_is_list(value) || !scm_is_null(value))
2329 gnc_free_list_option_value(list);
2331 return default_value;
2350 gnc_option_db_lookup_currency_option(
GNCOptionDB *odb,
2351 const char *section,
2359 option = gnc_option_db_get_option_by_name(odb, section, name);
2361 return default_value;
2363 getter = gnc_option_getter(option);
2364 if (getter == SCM_UNDEFINED)
2365 return default_value;
2367 value = scm_call_0(getter);
2369 return gnc_scm_to_commodity (value);
2373 free_helper(gpointer
string, gpointer not_used)
2375 if (
string) free(
string);
2379 gnc_free_list_option_value(GSList *list)
2381 g_slist_foreach(list, free_helper, NULL);
2396 gnc_option_db_set_option_default(
GNCOptionDB *odb,
2397 const char *section,
2402 option = gnc_option_db_get_option_by_name(odb, section, name);
2404 gnc_option_set_default(option);
2421 const char *section,
2428 option = gnc_option_db_get_option_by_name(odb, section, name);
2432 value = gnc_option_valid_value(option, value);
2433 if (value == SCM_UNDEFINED)
2436 setter = gnc_option_setter(option);
2437 if (setter == SCM_UNDEFINED)
2440 scm_call_1(setter, value);
2459 const char *section,
2467 option = gnc_option_db_get_option_by_name(odb, section, name);
2471 scm_value = scm_from_double (value);
2473 scm_value = gnc_option_valid_value(option, scm_value);
2474 if (scm_value == SCM_UNDEFINED)
2477 setter = gnc_option_setter(option);
2478 if (setter == SCM_UNDEFINED)
2481 scm_call_1(setter, scm_value);
2498 gnc_option_db_set_boolean_option(
GNCOptionDB *odb,
2499 const char *section,
2507 option = gnc_option_db_get_option_by_name(odb, section, name);
2511 scm_value = SCM_BOOL(value);
2513 scm_value = gnc_option_valid_value(option, scm_value);
2514 if (scm_value == SCM_UNDEFINED)
2517 setter = gnc_option_setter(option);
2518 if (setter == SCM_UNDEFINED)
2521 scm_call_1(setter, scm_value);
2539 const char *section,
2547 option = gnc_option_db_get_option_by_name(odb, section, name);
2552 scm_value = scm_from_utf8_string(value);
2554 scm_value = SCM_BOOL_F;
2556 scm_value = gnc_option_valid_value(option, scm_value);
2557 if (scm_value == SCM_UNDEFINED)
2560 setter = gnc_option_setter(option);
2561 if (setter == SCM_UNDEFINED)
2564 scm_call_1(setter, scm_value);
2577 gnc_option_date_option_get_subtype(
GNCOption *option)
2581 initialize_getters();
2583 return gnc_scm_call_1_symbol_to_string(getters.date_option_subtype, option->guile_option);
2594 gnc_date_option_value_get_type (SCM option_value)
2598 initialize_getters();
2600 return gnc_scm_call_1_symbol_to_string (getters.date_option_value_type, option_value);
2611 gnc_date_option_value_get_absolute (SCM option_value)
2615 initialize_getters();
2617 value = scm_call_1 (getters.date_option_value_absolute, option_value);
2619 return gnc_timepair2timespec (value);
2630 gnc_date_option_value_get_relative (SCM option_value)
2632 initialize_getters();
2634 return scm_call_1 (getters.date_option_value_relative, option_value);
2648 gnc_option_db_set_option_selectable_by_name(SCM guile_option,
2649 const char *section,
2651 gboolean selectable)
2656 odb = gnc_option_db_find (guile_option);
2660 option = gnc_option_db_get_option_by_name(odb, section, name);
2664 gnc_option_set_selectable (option, selectable);
2671 gboolean gnc_dateformat_option_value_parse(SCM value,
QofDateFormat *format,
2673 gboolean *years,
char **custom)
2678 if (!scm_is_list(value) || scm_is_null(value))
2685 val = SCM_CAR(value);
2686 value = SCM_CDR(value);
2687 if (!scm_is_symbol(val))
2689 str = gnc_scm_symbol_to_locale_string (val);
2704 val = SCM_CAR(value);
2705 value = SCM_CDR(value);
2706 if (!scm_is_symbol(val))
2708 str = gnc_scm_symbol_to_locale_string (val);
2723 val = SCM_CAR(value);
2724 value = SCM_CDR(value);
2725 if (!scm_is_bool(val))
2729 *years = scm_is_true(val);
2732 val = SCM_CAR(value);
2733 value = SCM_CDR(value);
2734 if (!scm_is_string(val))
2736 if (!scm_is_null(value))
2740 *custom = gnc_scm_to_utf8_string (val);
2751 gboolean years,
const char *custom)
2753 SCM value = SCM_EOL;
2759 val = scm_from_utf8_string(custom);
2762 value = scm_cons(val, value);
2764 val = SCM_BOOL(years);
2765 value = scm_cons(val, value);
2767 str = gnc_date_monthformat_to_string(months);
2769 val = scm_from_locale_symbol(str);
2772 value = scm_cons(val, value);
2776 val = scm_from_locale_symbol(str);
2779 value = scm_cons(val, value);
2786 static GHashTable *kvp_registry = NULL;
2792 kvp_registry = g_hash_table_new(g_str_hash, g_str_equal);
2801 gnc_register_kvp_option_generator(
QofIdType id_type, SCM generator)
2805 list = g_hash_table_lookup(kvp_registry, id_type);
2806 list = g_list_prepend(list, generator);
2807 g_hash_table_insert(kvp_registry, (gpointer) id_type, list);
2808 scm_gc_protect_object(generator);
2817 SCM gnc_new_options = SCM_UNDEFINED;
2818 SCM options = SCM_UNDEFINED;
2821 list = g_hash_table_lookup(kvp_registry, id_type);
2822 gnc_new_options = scm_c_eval_string(
"gnc:new-options");
2823 options = scm_call_0(gnc_new_options);
2825 for (p = list; p; p = p->next)
2827 SCM generator = p->data;
2828 scm_call_1(generator, options);
gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format)
Converts the month format to a printable string.
const gchar * gnc_date_dateformat_to_string(QofDateFormat format)
The string->value versions return FALSE on success and TRUE on failure.
Use a 64-bit unsigned int timespec.
#define PERR(format, args...)
Account handling public routines.
struct KvpFrameImpl KvpFrame
time64 gnc_time(time64 *tbuf)
get the current local time
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
const gchar * QofLogModule