From f4c27d4494e16055cae5fd9896b35c5c33bea6d0 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 12 Jul 2022 13:13:41 -0700 Subject: [PATCH] Move gnc_ui_account_get_tax_info_string to gnc-locale-tax.c To prevent a circular dependency between libgnc-app-utils and libgnucash-guile. --- bindings/CMakeLists.txt | 1 + .../app-utils => bindings}/app-utils.i | 4 +- bindings/expressions.i | 72 +++++ bindings/guile/CMakeLists.txt | 109 +++++++- .../guile}/app-utils.scm | 2 +- .../guile}/c-interface.scm | 0 .../guile}/date-utilities.scm | 2 +- .../guile}/expressions.i | 0 .../app-utils => bindings/guile}/fin.scm | 0 .../guile}/gnc-helpers.c | 0 .../guile}/gnc-helpers.h | 0 .../guile}/gnc-optiondb.i | 0 .../app-utils => bindings/guile}/options.scm | 2 +- bindings/guile/test/CMakeLists.txt | 51 ++++ .../guile}/test/test-c-interface.scm | 0 .../guile}/test/test-date-utilities.scm | 0 .../test/test-gnc-option-scheme-output.scm | 0 .../guile}/test/test-gnc-optiondb.scm | 4 +- .../test/test-load-app-utils-module.scm | 0 .../guile}/test/test-options.scm | 2 +- .../guile}/test/test-print-queries.cpp | 0 .../guile}/test/test-scm-query-string.cpp | 0 bindings/python/CMakeLists.txt | 40 +++ gnucash/gnome-utils/CMakeLists.txt | 1 + gnucash/gnome-utils/dialog-account.c | 2 +- gnucash/gnome-utils/gnc-tree-model-account.c | 1 + libgnucash/app-utils/CMakeLists.txt | 144 +--------- libgnucash/app-utils/gnc-option-impl.hpp | 1 - libgnucash/app-utils/gnc-option.hpp | 1 - libgnucash/app-utils/gnc-optiondb.cpp | 1 - libgnucash/app-utils/gnc-optiondb.h | 2 - libgnucash/app-utils/gnc-optiondb.hpp | 1 - libgnucash/app-utils/gnc-ui-util.c | 261 ----------------- libgnucash/app-utils/gnc-ui-util.h | 3 - libgnucash/app-utils/test/CMakeLists.txt | 44 --- libgnucash/tax/CMakeLists.txt | 3 + libgnucash/tax/gnc-locale-tax.c | 262 +++++++++++++++++- libgnucash/tax/gnc-locale-tax.h | 4 + po/POTFILES.in | 12 +- 39 files changed, 559 insertions(+), 473 deletions(-) rename {libgnucash/app-utils => bindings}/app-utils.i (99%) create mode 100644 bindings/expressions.i rename {libgnucash/app-utils => bindings/guile}/app-utils.scm (95%) rename {libgnucash/app-utils => bindings/guile}/c-interface.scm (100%) rename {libgnucash/app-utils => bindings/guile}/date-utilities.scm (99%) rename {libgnucash/app-utils => bindings/guile}/expressions.i (100%) rename {libgnucash/app-utils => bindings/guile}/fin.scm (100%) rename {libgnucash/app-utils => bindings/guile}/gnc-helpers.c (100%) rename {libgnucash/app-utils => bindings/guile}/gnc-helpers.h (100%) rename {libgnucash/app-utils => bindings/guile}/gnc-optiondb.i (100%) rename {libgnucash/app-utils => bindings/guile}/options.scm (99%) rename {libgnucash/app-utils => bindings/guile}/test/test-c-interface.scm (100%) rename {libgnucash/app-utils => bindings/guile}/test/test-date-utilities.scm (100%) rename {libgnucash/app-utils => bindings/guile}/test/test-gnc-option-scheme-output.scm (100%) rename {libgnucash/app-utils => bindings/guile}/test/test-gnc-optiondb.scm (99%) rename {libgnucash/app-utils => bindings/guile}/test/test-load-app-utils-module.scm (100%) rename {libgnucash/app-utils => bindings/guile}/test/test-options.scm (94%) rename {libgnucash/app-utils => bindings/guile}/test/test-print-queries.cpp (100%) rename {libgnucash/app-utils => bindings/guile}/test/test-scm-query-string.cpp (100%) diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index 6510379562..13ae396d07 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(python) set_local_dist(bindings_DIST_local CMakeLists.txt + app-utils.i business-core.i core-utils.i engine.i diff --git a/libgnucash/app-utils/app-utils.i b/bindings/app-utils.i similarity index 99% rename from libgnucash/app-utils/app-utils.i rename to bindings/app-utils.i index 6e1430bc66..b97690fe15 100644 --- a/libgnucash/app-utils/app-utils.i +++ b/bindings/app-utils.i @@ -30,11 +30,13 @@ extern "C" #include #include #include +#if defined(SWIGGUILE) #include +#include "gnc-engine-guile.h" +#endif #include #include -#include "gnc-engine-guile.h" #ifdef __cplusplus } #endif diff --git a/bindings/expressions.i b/bindings/expressions.i new file mode 100644 index 0000000000..ff629d93f2 --- /dev/null +++ b/bindings/expressions.i @@ -0,0 +1,72 @@ +/********************************************************************\ + * 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 of * + * the License, 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, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * + * Boston, MA 02110-1301, USA gnu@gnu.org * + * * +\********************************************************************/ + +%module sw_expressions +%{ +#include + +SCM scm_init_sw_expressions_module (void); + +static GDate +gnc_time64_to_GDate(SCM x) +{ + time64 time = scm_to_int64 (x); + return time64_to_gdate(time); +} + + +static SCM +gnc_guid2scm(GncGUID guid) +{ + char string[GUID_ENCODING_LENGTH + 1]; + + if (!guid_to_string_buff(&guid, string)) + return SCM_BOOL_F; + + return scm_from_utf8_string(string); +} + +static SCM +gnc_numeric_to_scm(gnc_numeric arg) +{ + return gnc_numeric_check (arg) ? SCM_BOOL_F : + scm_divide (scm_from_int64 (arg.num), scm_from_int64 (arg.denom)); +} +%} + +%typemap(out) GHashTable * { + SCM table = scm_c_make_hash_table (g_hash_table_size($1) + 17); + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init (&iter, $1); + while (g_hash_table_iter_next (&iter, &key, &value)) { + const GncGUID* c_guid = (const GncGUID*) key; + const gnc_numeric* c_numeric = (const gnc_numeric*) value; + SCM scm_guid = gnc_guid2scm(*c_guid); + SCM scm_numeric = gnc_numeric_to_scm(*c_numeric); + + scm_hash_set_x(table, scm_guid, scm_numeric); + } + g_hash_table_destroy($1); + $result = table; +} +GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_end); +%clear GHashTable *; diff --git a/bindings/guile/CMakeLists.txt b/bindings/guile/CMakeLists.txt index 004a24be9d..3211458097 100644 --- a/bindings/guile/CMakeLists.txt +++ b/bindings/guile/CMakeLists.txt @@ -1,6 +1,6 @@ add_subdirectory(test) -# Command to generate the swig-core-utils-guile.c wrapper file +# Generate the swig-core-utils-guile.c wrapper file gnc_swig_extract_header_files (gnc-core-utils CORE_UTILS_HEADERS) gnc_add_swig_guile_command (swig-core-utils-guile-c SWIG_CORE_UTILS_GUILE_C swig-core-utils-guile.c @@ -9,7 +9,7 @@ gnc_add_swig_guile_command (swig-core-utils-guile-c ${CORE_UTILS_HEADERS} ) -# Command to generate the swig-engine.c wrapper file +# Generate the swig-engine.c wrapper file gnc_swig_extract_header_files (gnc-engine ENGINE_HEADERS) gnc_add_swig_guile_command (swig-engine-c SWIG_ENGINE_C swig-engine.c @@ -20,10 +20,28 @@ gnc_add_swig_guile_command (swig-engine-c ${CMAKE_SOURCE_DIR}/bindings/engine-common.i ) +# Generate the swig-app-utils-guile.cpp wrapper file +set(SWIG_ARGS "-c++" "-procdoc" "sw-gnc-option-doc" "-procdocformat" "plain") +gnc_add_swig_guile_command (swig-apputils-guile-cpp #target + SWIG_APP_UTILS_GUILE_CPP swig-app-utils-guile.cpp #outvar, output + ${CMAKE_CURRENT_SOURCE_DIR}/../app-utils.i #input + "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/libgnucash/app-utils" #includes + ${CMAKE_CURRENT_SOURCE_DIR}/gnc-optiondb.i #additional dependencies + ) +unset(SWIG_ARGS) + +#Generate the swig-expressions-guile.c wrapper file +gnc_add_swig_guile_command(swig-expressions-guile-c #target + SWIG_EXPRESSIONS_GUILE_C swig-expressions-guile.c #outvar, output + ${CMAKE_CURRENT_SOURCE_DIR}/expressions.i #input + "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/libgnucash/app-utils;${CMAKE_SOURCE_DIR}/libgnucash/expressions" #includes + ) + set(guile_HEADERS glib-guile.h gnc-engine-guile.h gnc-guile-utils.h + gnc-helpers.h gnc-kvp-guile.h) set(guile_SOURCES @@ -31,13 +49,15 @@ set(guile_SOURCES gnc-engine-guile.c gnc-guile-bindings.c gnc-guile-utils.c + gnc-helpers.c gnc-kvp-guile.cpp) add_library(gnucash-guile SHARED ${guile_SOURCES} ${guile_HEADERS} ${SWIG_CORE_UTILS_GUILE_C} - ${SWIG_ENGINE_C}) + ${SWIG_ENGINE_C} + ${SWIG_APP_UTILS_GUILE_CPP}) add_dependencies(gnucash-guile swig-runtime-h) @@ -57,6 +77,7 @@ target_link_libraries(gnucash-guile PRIVATE gnc-core-utils gnc-engine + gnc-app-utils ${GLIB2_LDFLAGS}) install(TARGETS gnucash-guile @@ -65,6 +86,28 @@ install(TARGETS gnucash-guile RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) +add_library(gnc-expressions-guile SHARED + ${SWIG_EXPRESSIONS_GUILE_C}) + +target_include_directories(gnc-expressions-guile + PUBLIC + ${CMAKE_SOURCE_DIR}/libgnucash/expressions + ${GUILE_INCLUDE_DIRS} + ${GLIB2_INCLUDE_DIRS}) + +target_link_libraries(gnc-expressions-guile + gnc-expressions + gnc-engine + gnc-app-utils + ${GUILE_LDFLAGS} + ${GLIB2_LDFLAGS}) + +install(TARGETS gnc-expressions-guile + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + # Scheme set (core_utils_SCHEME core-utils.scm) @@ -126,6 +169,57 @@ gnc_add_scheme_targets(scm-engine-2 add_custom_target(scm-engine ALL DEPENDS scm-engine-2 scm-engine-1 scm-engine-0) +set (app_utils_SCHEME_1 + c-interface.scm + date-utilities.scm + ) + +set (app_utils_SCHEME_1a + options.scm + ) + +set (app_utils_SCHEME_2 + app-utils.scm + ) + + +set(GUILE_DEPENDS + gnc-app-utils + scm-core-utils + scm-engine) + +gnc_add_scheme_targets(scm-app-utils-1 + SOURCES "${app_utils_SCHEME_1}" + OUTPUT_DIR "gnucash/app-utils" + DEPENDS "${GUILE_DEPENDS}" + MAKE_LINKS) + +gnc_add_scheme_targets(scm-app-utils-1a + SOURCES "${app_utils_SCHEME_1a}" + OUTPUT_DIR "gnucash/app-utils" + DEPENDS "scm-app-utils-1" + MAKE_LINKS) + +gnc_add_scheme_targets(scm-app-utils-2 + SOURCES "${app_utils_SCHEME_2}" + OUTPUT_DIR "gnucash" + DEPENDS "scm-app-utils-1a" + MAKE_LINKS) + +add_custom_target(scm-app-utils ALL DEPENDS scm-app-utils-2 scm-app-utils-1) + +set(expressions_SCHEME + fin.scm) + +set(GUILE_INTERNAL_DEPENDS + scm-app-utils-1) + +gnc_add_scheme_targets(scm-expressions + SOURCES "${expressions_SCHEME}" + OUTPUT_DIR "gnucash/app-utils" + DEPENDS "${GUILE_INTERNAL_DEPENDS}" + MAKE_LINKS) + set_local_dist(guile_DIST_local CMakeLists.txt core-utils.scm @@ -133,7 +227,14 @@ set_local_dist(guile_DIST_local ${guile_HEADERS} ${engine_SCHEME_0} ${engine_SCHEME_1} - ${engine_SCHEME_2}) + ${engine_SCHEME_2} + ${app_utils_SCHEME_1} + ${app_utils_SCHEME_1a} + ${app_utils_SCHEME_1b} + ${app_utils_SCHEME_1c} + ${app_utils_SCHEME_2} + ${app_utils_SCHEME_3} + expressions.i) set(guile_DIST ${guile_DIST_local} ${test_guile_DIST} PARENT_SCOPE) diff --git a/libgnucash/app-utils/app-utils.scm b/bindings/guile/app-utils.scm similarity index 95% rename from libgnucash/app-utils/app-utils.scm rename to bindings/guile/app-utils.scm index cb77eb7a66..aee1e8610e 100644 --- a/libgnucash/app-utils/app-utils.scm +++ b/bindings/guile/app-utils.scm @@ -18,7 +18,7 @@ (define-module (gnucash app-utils)) (eval-when (compile load eval expand) - (load-extension "libgnc-app-utils" "scm_init_sw_app_utils_module")) + (load-extension "libgnucash-guile" "scm_init_sw_app_utils_module")) (use-modules (srfi srfi-1)) (use-modules (gnucash utilities)) diff --git a/libgnucash/app-utils/c-interface.scm b/bindings/guile/c-interface.scm similarity index 100% rename from libgnucash/app-utils/c-interface.scm rename to bindings/guile/c-interface.scm diff --git a/libgnucash/app-utils/date-utilities.scm b/bindings/guile/date-utilities.scm similarity index 99% rename from libgnucash/app-utils/date-utilities.scm rename to bindings/guile/date-utilities.scm index 9395bac5f7..f5a4e77662 100644 --- a/libgnucash/app-utils/date-utilities.scm +++ b/bindings/guile/date-utilities.scm @@ -24,7 +24,7 @@ (define-module (gnucash app-utils date-utilities)) (eval-when (compile load eval expand) - (load-extension "libgnc-app-utils" "scm_init_sw_app_utils_module")) + (load-extension "libgnucash-guile" "scm_init_sw_app_utils_module")) (use-modules (gnucash engine)) (use-modules (gnucash core-utils)) diff --git a/libgnucash/app-utils/expressions.i b/bindings/guile/expressions.i similarity index 100% rename from libgnucash/app-utils/expressions.i rename to bindings/guile/expressions.i diff --git a/libgnucash/app-utils/fin.scm b/bindings/guile/fin.scm similarity index 100% rename from libgnucash/app-utils/fin.scm rename to bindings/guile/fin.scm diff --git a/libgnucash/app-utils/gnc-helpers.c b/bindings/guile/gnc-helpers.c similarity index 100% rename from libgnucash/app-utils/gnc-helpers.c rename to bindings/guile/gnc-helpers.c diff --git a/libgnucash/app-utils/gnc-helpers.h b/bindings/guile/gnc-helpers.h similarity index 100% rename from libgnucash/app-utils/gnc-helpers.h rename to bindings/guile/gnc-helpers.h diff --git a/libgnucash/app-utils/gnc-optiondb.i b/bindings/guile/gnc-optiondb.i similarity index 100% rename from libgnucash/app-utils/gnc-optiondb.i rename to bindings/guile/gnc-optiondb.i diff --git a/libgnucash/app-utils/options.scm b/bindings/guile/options.scm similarity index 99% rename from libgnucash/app-utils/options.scm rename to bindings/guile/options.scm index 390c52dad6..d7a5e5d879 100644 --- a/libgnucash/app-utils/options.scm +++ b/bindings/guile/options.scm @@ -20,7 +20,7 @@ (define-module (gnucash app-utils options)) (eval-when (compile load eval expand) - (load-extension "libgnc-app-utils" "scm_init_sw_app_utils_module")) + (load-extension "libgnucash-guile" "scm_init_sw_app_utils_module")) (use-modules (gnucash core-utils)) (use-modules (gnucash engine)) diff --git a/bindings/guile/test/CMakeLists.txt b/bindings/guile/test/CMakeLists.txt index ebbb2f90a1..bce963a283 100644 --- a/bindings/guile/test/CMakeLists.txt +++ b/bindings/guile/test/CMakeLists.txt @@ -6,15 +6,20 @@ set(ENGINE_TEST_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libgnucash/engine/test-core ${CMAKE_BINARY_DIR}/common # for config.h ${CMAKE_SOURCE_DIR}/common/test-core # for unittest-support.h + ${CMAKE_SOURCE_DIR}/libgnucash/app-utils ${CMAKE_SOURCE_DIR}/bindings/guile # for gnc-engine-guile.h ${GLIB2_INCLUDE_DIRS} + ${GUILE_INCLUDE_DIRS} ) set(ENGINE_TEST_LIBS gnc-engine + gnc-app-utils gnc-test-engine test-core gnucash-guile + ${GIO_LDFLAGS} + ${GUILE_LDFLAGS} ${LIBXML2_LDFLAGS} -lm) @@ -105,11 +110,57 @@ set(test_engine_SCHEME_DIST test-business-core.scm ) +set(test_app_utils_scheme_SOURCES + test-c-interface.scm + test-load-app-utils-module.scm + ) + +set (test_app_utils_scheme_SRFI64_SOURCES + test-date-utilities.scm + test-options.scm + ) + +gnc_add_scheme_test_targets(scm-test-load-app-utils-module + SOURCES "test-load-app-utils-module.scm" + OUTPUT_DIR "tests" + DEPENDS "${GUILE_DEPENDS}") + +gnc_add_scheme_test_targets(scm-test-c-interface + SOURCES "test-c-interface.scm" + OUTPUT_DIR "tests" + DEPENDS "${GUILE_DEPENDS}") + +gnc_add_scheme_tests("${test_app_utils_scheme_SOURCES}") + +if (HAVE_SRFI64) + gnc_add_scheme_test_targets(scm-test-app-utils-srfi64 + SOURCES "${test_app_utils_scheme_SRFI64_SOURCES}" + OUTPUT_DIR "tests" + DEPENDS "${GUILE_DEPENDS};scm-srfi64-extras") + + gnc_add_scheme_test_targets(scm-test-gnc-optiondb + SOURCES "test-gnc-optiondb.scm" "test-gnc-option-scheme-output.scm" + OUTPUT_DIR "tests" + DEPENDS "swig-apputils-guile-cpp;scm-srfi64-extras") + gnc_add_scheme_tests("test-gnc-optiondb.scm") + gnc_add_scheme_tests("test-gnc-option-scheme-output.scm") + gnc_add_scheme_tests("${test_app_utils_scheme_SRFI64_SOURCES}") +endif() + +gnc_add_test_with_guile(test-print-queries test-print-queries.cpp ENGINE_TEST_INCLUDE_DIRS ENGINE_TEST_LIBS) +gnc_add_test_with_guile(test-scm-query-string test-scm-query-string.cpp + ENGINE_TEST_INCLUDE_DIRS ENGINE_TEST_LIBS + ) + set_local_dist(test_guile_DIST_local CMakeLists.txt + test-print-queries.cpp test-scm-query.cpp + test-scm-query-string.cpp ${test_engine_SCHEME_DIST} ${test_scm_SCHEME} + ${test_app_utils_scheme_SOURCES} + ${test_app_utils_scheme_SRFI64_SOURCES} ) set(test_guile_DIST ${test_guile_DIST_local} diff --git a/libgnucash/app-utils/test/test-c-interface.scm b/bindings/guile/test/test-c-interface.scm similarity index 100% rename from libgnucash/app-utils/test/test-c-interface.scm rename to bindings/guile/test/test-c-interface.scm diff --git a/libgnucash/app-utils/test/test-date-utilities.scm b/bindings/guile/test/test-date-utilities.scm similarity index 100% rename from libgnucash/app-utils/test/test-date-utilities.scm rename to bindings/guile/test/test-date-utilities.scm diff --git a/libgnucash/app-utils/test/test-gnc-option-scheme-output.scm b/bindings/guile/test/test-gnc-option-scheme-output.scm similarity index 100% rename from libgnucash/app-utils/test/test-gnc-option-scheme-output.scm rename to bindings/guile/test/test-gnc-option-scheme-output.scm diff --git a/libgnucash/app-utils/test/test-gnc-optiondb.scm b/bindings/guile/test/test-gnc-optiondb.scm similarity index 99% rename from libgnucash/app-utils/test/test-gnc-optiondb.scm rename to bindings/guile/test/test-gnc-optiondb.scm index 7174a4f537..f19af10088 100644 --- a/libgnucash/app-utils/test/test-gnc-optiondb.scm +++ b/bindings/guile/test/test-gnc-optiondb.scm @@ -39,7 +39,7 @@ ;; Load the C++ option implementation, avoiding the options.scm ones. (eval-when (compile load eval expand) - (load-extension "libgnc-app-utils" "scm_init_sw_app_utils_module")) + (load-extension "libgnucash-guile" "scm_init_sw_app_utils_module")) (use-modules (gnucash engine)) (use-modules (sw_app_utils)) @@ -246,4 +246,4 @@ (gnc-register-report-placement-option option-db "foo" "bar") (gnc-set-option option-db "foo" "bar" rp) (test-equal report2 (car (cadr (gnc-option-value option-db "foo" "bar"))))) - (test-end "test-gnc-report-placement-option")) \ No newline at end of file + (test-end "test-gnc-report-placement-option")) diff --git a/libgnucash/app-utils/test/test-load-app-utils-module.scm b/bindings/guile/test/test-load-app-utils-module.scm similarity index 100% rename from libgnucash/app-utils/test/test-load-app-utils-module.scm rename to bindings/guile/test/test-load-app-utils-module.scm diff --git a/libgnucash/app-utils/test/test-options.scm b/bindings/guile/test/test-options.scm similarity index 94% rename from libgnucash/app-utils/test/test-options.scm rename to bindings/guile/test/test-options.scm index 8e28da9199..f243e195f8 100644 --- a/libgnucash/app-utils/test/test-options.scm +++ b/bindings/guile/test/test-options.scm @@ -2,7 +2,7 @@ ;; Load the C++ option implementation, avoiding the options.scm ones. (eval-when (compile load eval expand) - (load-extension "libgnc-app-utils" "scm_init_sw_app_utils_module")) + (load-extension "libgnucash-guile" "scm_init_sw_app_utils_module")) (use-modules (sw_app_utils)) (use-modules (srfi srfi-64)) (use-modules (tests srfi64-extras)) diff --git a/libgnucash/app-utils/test/test-print-queries.cpp b/bindings/guile/test/test-print-queries.cpp similarity index 100% rename from libgnucash/app-utils/test/test-print-queries.cpp rename to bindings/guile/test/test-print-queries.cpp diff --git a/libgnucash/app-utils/test/test-scm-query-string.cpp b/bindings/guile/test/test-scm-query-string.cpp similarity index 100% rename from libgnucash/app-utils/test/test-scm-query-string.cpp rename to bindings/guile/test/test-scm-query-string.cpp diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 4e7480495e..19c7ee043f 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -55,6 +55,13 @@ gnc_add_swig_python_command (swig-core-utils-python ${CORE_UTILS_HEADERS} ) +# Command to generate the swig-app-utils-python.c wrapper file +gnc_add_swig_python_command (swig-app-utils-python + SWIG_APP_UTILS_PYTHON_C SWIG_APP_UTILS_PYTHON_PY + swig-app-utils-python.c sw_app_utils.py + ${CMAKE_CURRENT_SOURCE_DIR}/../app-utils.i "" + ) + if(WITH_PYTHON) ### gnucash_core_c @@ -146,6 +153,39 @@ if(WITH_PYTHON) COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR_BUILD}/gnucash/_sw_core_utils${CMAKE_SHARED_MODULE_SUFFIX} ${PYTHON_SYSCONFIG_BUILD}/gnucash DEPENDS sw_core_utils) + ### App-utils + set(PYEXEC_FILES sw_app_utils.py) + add_library (sw_app_utils MODULE ${SWIG_APP_UTILS_PYTHON_C}) + + target_link_libraries(sw_app_utils gnc-app-utils ${app_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES}) + set_target_properties(sw_app_utils PROPERTIES PREFIX "_") + if (HAVE_STRINGOP_TRUNCATION) + target_compile_options(sw_app_utils PRIVATE -Wno-error=stringop-truncation) + endif() + + add_custom_target(sw-app-utils-py ALL + COMMAND ${CMAKE_COMMAND} -E copy ${SWIG_APP_UTILS_PYTHON_PY} ${PYTHON_SYSCONFIG_BUILD}/gnucash + DEPENDS ${SWIG_APP_UTILS_PYTHON_C}) + + target_include_directories (sw_app_utils + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${app_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS} + ) + target_compile_definitions (sw_app_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.app-utils\") + + if (APPLE) + set_target_properties (sw_app_utils PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}") + endif() + + install(TARGETS sw_app_utils + LIBRARY DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash + ARCHIVE DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash + ) + + add_custom_target(sw-app-utils-build ALL + COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR_BUILD}/gnucash/_sw_app_utils${CMAKE_SHARED_MODULE_SUFFIX} ${PYTHON_SYSCONFIG_BUILD}/gnucash + DEPENDS sw_app_utils) + endif() set(python_bindings_DATA ${PYEXEC_FILES} diff --git a/gnucash/gnome-utils/CMakeLists.txt b/gnucash/gnome-utils/CMakeLists.txt index a2bc8adb47..2ef9caf49a 100644 --- a/gnucash/gnome-utils/CMakeLists.txt +++ b/gnucash/gnome-utils/CMakeLists.txt @@ -207,6 +207,7 @@ target_link_libraries(gnc-gnome-utils gnc-app-utils gnc-engine gnc-expressions + gnc-locale-tax gnc-backend-xml-utils gnucash-guile PkgConfig::GTK3 diff --git a/gnucash/gnome-utils/dialog-account.c b/gnucash/gnome-utils/dialog-account.c index 4f79f08cfc..63ab3808a0 100644 --- a/gnucash/gnome-utils/dialog-account.c +++ b/gnucash/gnome-utils/dialog-account.c @@ -49,7 +49,7 @@ #include "gnc-tree-view-account.h" #include "gnc-ui.h" #include "gnc-ui-util.h" - +#include #define DIALOG_NEW_ACCOUNT_CM_CLASS "dialog-new-account" #define DIALOG_EDIT_ACCOUNT_CM_CLASS "dialog-edit-account" diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c index e04eac9adc..c8345fef41 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.c +++ b/gnucash/gnome-utils/gnc-tree-model-account.c @@ -41,6 +41,7 @@ #include "gnc-gobject-utils.h" #include "gnc-ui-balances.h" #include "gnc-ui-util.h" +#include #define TREE_MODEL_ACCOUNT_CM_CLASS "tree-model-account" diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt index 338fd83622..987831737e 100644 --- a/libgnucash/app-utils/CMakeLists.txt +++ b/libgnucash/app-utils/CMakeLists.txt @@ -17,7 +17,6 @@ set (app_utils_noinst_HEADERS set (app_utils_HEADERS QuickFill.h file-utils.h - gfec.h gnc-basic-gobject.h gnc-account-merge.h gnc-accounting-period.h @@ -26,7 +25,6 @@ set (app_utils_HEADERS gnc-euro.h gnc-gsettings.h gnc-help-utils.h - gnc-helpers.h gnc-option.hpp gnc-optiondb.h gnc-optiondb.hpp @@ -36,34 +34,15 @@ set (app_utils_HEADERS gnc-ui-balances.h ) -# Command to generate the swig-app-utils-guile.c wrapper file -set(SWIG_ARGS "-c++" "-procdoc" "sw-gnc-option-doc" "-procdocformat" "plain") -gnc_add_swig_guile_command (swig-apputils-guile-cpp #target - SWIG_APP_UTILS_GUILE_CPP swig-app-utils-guile.cpp #outvar, output - ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i #input - "${CMAKE_SOURCE_DIR}/bindings;${CMAKE_SOURCE_DIR}/bindings/guile" #includes - ${CMAKE_CURRENT_SOURCE_DIR}/gnc-optiondb.i #additional dependencies -) -unset(SWIG_ARGS) - -# Command to generate the swig-app-utils-python.c wrapper file -gnc_add_swig_python_command (swig-app-utils-python - SWIG_APP_UTILS_PYTHON_C SWIG_APP_UTILS_PYTHON_PY - swig-app-utils-python.c sw_app_utils.py - ${CMAKE_CURRENT_SOURCE_DIR}/app-utils.i "" -) - set (app_utils_SOURCES QuickFill.c file-utils.c - gfec.c gnc-account-merge.c gnc-accounting-period.c gnc-addr-quickfill.c gnc-entry-quickfill.c gnc-euro.c gnc-gsettings.cpp - gnc-helpers.c gnc-option-date.cpp gnc-option.cpp gnc-option-impl.cpp @@ -84,8 +63,6 @@ endif() set(app_utils_ALL_SOURCES ${app_utils_SOURCES} ${app_utils_HEADERS} ${app_utils_noinst_HEADERS}) set(app_utils_ALL_LIBRARIES gnc-engine - gnc-locale-tax - gnucash-guile ${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${LIBXML2_LDFLAGS} @@ -130,44 +107,10 @@ install(TARGETS gnc-app-utils RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) -if (WITH_PYTHON) - set(PYEXEC_FILES sw_app_utils.py) - add_library (sw_app_utils MODULE ${SWIG_APP_UTILS_PYTHON_C}) - - target_link_libraries(sw_app_utils gnc-app-utils ${app_utils_ALL_LIBRARIES} ${PYTHON_LIBRARIES}) - set_target_properties(sw_app_utils PROPERTIES PREFIX "_") - if (HAVE_STRINGOP_TRUNCATION) - target_compile_options(sw_app_utils PRIVATE -Wno-error=stringop-truncation) - endif() - - target_include_directories (sw_app_utils - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${app_utils_ALL_INCLUDES} ${PYTHON_INCLUDE_DIRS} - ) - target_compile_definitions (sw_app_utils PRIVATE -DG_LOG_DOMAIN=\"gnc.app-utils\") - - if (APPLE) - set_target_properties (sw_app_utils PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}") - endif() - - install(TARGETS sw_app_utils - LIBRARY DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash - ARCHIVE DESTINATION ${PYTHON_SYSCONFIG_OUTPUT}/gnucash - ) - - add_custom_target(sw-app-utils-py ALL - COMMAND ${CMAKE_COMMAND} -E copy ${SWIG_APP_UTILS_PYTHON_PY} ${PYTHON_SYSCONFIG_BUILD}/gnucash - DEPENDS ${SWIG_APP_UTILS_PYTHON_C}) - - add_custom_target(sw-app-utils-build ALL - COMMAND ${CMAKE_COMMAND} -E copy ${LIBDIR_BUILD}/gnucash/_sw_app_utils${CMAKE_SHARED_MODULE_SUFFIX} ${PYTHON_SYSCONFIG_BUILD}/gnucash - DEPENDS sw_app_utils) - -endif() - set(expressions_SOURCES calculation/expression_parser.c calculation/fin.c + gfec.c gnc-exp-parser.c gnc-sx-instance-model.c ) @@ -179,6 +122,7 @@ set(expressions_noinstall_HEADERS calculation/fin_static_proto.h ) set(expressions_HEADERS + gfec.h gnc-exp-parser.h gnc-sx-instance-model.h ) @@ -206,8 +150,8 @@ target_include_directories(gnc-expressions target_link_libraries(gnc-expressions PUBLIC gnc-engine - gnucash-guile gnc-app-utils + gnucash-guile ${GUILE_LDFLAGS} ${GLIB2_LDFLAGS}) @@ -217,90 +161,9 @@ install(TARGETS gnc-expressions RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) -#Generate the swig-expressions-guile.c wrapper file -gnc_add_swig_guile_command(swig-expressions-guile-c #target - SWIG_EXPRESSIONS_GUILE_C swig-expressions-guile.c #outvar, output - ${CMAKE_CURRENT_SOURCE_DIR}/expressions.i #input - "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/libgnucash/app-utils;${CMAKE_SOURCE_DIR}/libgnucash/expressions" #includes - ) - -add_library(gnc-expressions-guile SHARED - ${SWIG_EXPRESSIONS_GUILE_C}) - -target_include_directories(gnc-expressions-guile - PUBLIC - ${CMAKE_SOURCE_DIR}/libgnucash/expressions - ${GUILE_INCLUDE_DIRS} - ${GLIB2_INCLUDE_DIRS}) - -target_link_libraries(gnc-expressions-guile - gnc-expressions - gnc-engine - gnc-app-utils - ${GUILE_LDFLAGS} - ${GLIB2_LDFLAGS}) - -install(TARGETS gnc-expressions-guile - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) install(FILES ${app_utils_HEADERS} ${expressions_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gnucash) - -# And now handle scheme files - -set (app_utils_SCHEME_1 - c-interface.scm - date-utilities.scm -) - -set (app_utils_SCHEME_1a - options.scm -) - -set (app_utils_SCHEME_2 - app-utils.scm -) - -set(GUILE_DEPENDS - gnc-app-utils - scm-core-utils - scm-engine) - -gnc_add_scheme_targets(scm-app-utils-1 - SOURCES "${app_utils_SCHEME_1}" - OUTPUT_DIR "gnucash/app-utils" - DEPENDS "${GUILE_DEPENDS}" - MAKE_LINKS) - -gnc_add_scheme_targets(scm-app-utils-1a - SOURCES "${app_utils_SCHEME_1a}" - OUTPUT_DIR "gnucash/app-utils" - DEPENDS "scm-app-utils-1" - MAKE_LINKS) - -gnc_add_scheme_targets(scm-app-utils-2 - SOURCES "${app_utils_SCHEME_2}" - OUTPUT_DIR "gnucash" - DEPENDS "scm-app-utils-1a" - MAKE_LINKS) - -add_custom_target(scm-app-utils ALL DEPENDS scm-app-utils-2 scm-app-utils-1) - -set(expressions_SCHEME - fin.scm) - -set(GUILE_INTERNAL_DEPENDS - scm-app-utils-1) - -gnc_add_scheme_targets(scm-expressions - SOURCES "${expressions_SCHEME}" - OUTPUT_DIR "gnucash/app-utils" - DEPENDS "${GUILE_INTERNAL_DEPENDS}" - MAKE_LINKS) - set_local_dist(app_utils_DIST_local ${app_utils_ALL_SOURCES} ${app_utils_SCHEME_1} @@ -313,6 +176,7 @@ set_local_dist(app_utils_DIST_local ${expressions_SCHEME} app-utils.i gnc-optiondb.i expressions.i CMakeLists.txt gnc-help-utils.c) + set(app_utils_DIST ${app_utils_DIST_local} ${test_app_utils_DIST} diff --git a/libgnucash/app-utils/gnc-option-impl.hpp b/libgnucash/app-utils/gnc-option-impl.hpp index 75dd9d41ff..9102f3e58a 100644 --- a/libgnucash/app-utils/gnc-option-impl.hpp +++ b/libgnucash/app-utils/gnc-option-impl.hpp @@ -43,7 +43,6 @@ extern "C" #include } #include -#include #include #include #include diff --git a/libgnucash/app-utils/gnc-option.hpp b/libgnucash/app-utils/gnc-option.hpp index 9cb97acff3..138b3fbc67 100644 --- a/libgnucash/app-utils/gnc-option.hpp +++ b/libgnucash/app-utils/gnc-option.hpp @@ -34,7 +34,6 @@ #define GNC_OPTION_HPP_ #include -#include #include #include #include diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index dcec0e1098..d94e1f6509 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -21,7 +21,6 @@ * * \********************************************************************/ -#include #include #include #include diff --git a/libgnucash/app-utils/gnc-optiondb.h b/libgnucash/app-utils/gnc-optiondb.h index 88d12300d5..4048e51aa8 100644 --- a/libgnucash/app-utils/gnc-optiondb.h +++ b/libgnucash/app-utils/gnc-optiondb.h @@ -63,8 +63,6 @@ typedef struct GncOption GncOption; typedef struct GncOptionDB GncOptionDB; #endif -#include - #ifdef __cplusplus extern "C" { diff --git a/libgnucash/app-utils/gnc-optiondb.hpp b/libgnucash/app-utils/gnc-optiondb.hpp index 25920f4c2a..2fbb3237a1 100644 --- a/libgnucash/app-utils/gnc-optiondb.hpp +++ b/libgnucash/app-utils/gnc-optiondb.hpp @@ -38,7 +38,6 @@ #include #include #include -#include extern "C" { #include diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c index c0279eebcd..8b060d17e7 100644 --- a/libgnucash/app-utils/gnc-ui-util.c +++ b/libgnucash/app-utils/gnc-ui-util.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -45,18 +44,15 @@ #include "qof.h" -#include "guile-mappings.h" #include "gnc-prefs.h" #include "Account.h" #include "Transaction.h" #include "gnc-engine.h" #include "gnc-features.h" #include "gnc-hooks.h" -#include "gnc-locale-tax.h" #include "gnc-session.h" #include "engine-helpers.h" #include "gnc-locale-utils.h" -#include "gnc-guile-utils.h" #define GNC_PREF_CURRENCY_CHOICE_LOCALE "currency-choice-locale" #define GNC_PREF_CURRENCY_CHOICE_OTHER "currency-choice-other" @@ -467,263 +463,6 @@ gnc_account_lookup_for_register(const Account *base_account, const char *name) return gnc_account_lookup_by_full_name (base_account, name); } - -/* Caller is responsible for g_free'ing returned memory */ -char * -gnc_ui_account_get_tax_info_string (const Account *account) -{ - static SCM get_form = SCM_UNDEFINED; - static SCM get_desc = SCM_UNDEFINED; - - gboolean tax_related = FALSE; - const char *code; - - if (!account) - return NULL; - - tax_related = xaccAccountGetTaxRelated (account); - code = xaccAccountGetTaxUSCode (account); - - if (!code) - { - if (!tax_related) - return NULL; - /* tax_related && !code */ - else - /* Translators: This and the following strings appear on - the account tab if the Tax Info column is displayed, - i.e. if the user wants to record the tax form number - and location on that tax form which corresponds to this - gnucash account. For the US Income Tax support in - gnucash, each tax code that can be assigned to an - account generally corresponds to a specific line number - on a paper form and each form has a unique - identification (e.g., Form 1040, Schedule A). */ - return g_strdup (_("Tax-related but has no tax code")); - } - else /* with tax code */ - { - const gchar *tax_type; - GNCAccountType atype; - SCM tax_entity_type; - SCM category; - gchar *num_code = NULL; - const gchar *prefix = "N"; - gchar *return_string = NULL; - - tax_type = gnc_get_current_book_tax_type (); - if (tax_type == NULL || (g_strcmp0 (tax_type, "") == 0)) - return g_strdup (_("Tax entity type not specified")); - - atype = xaccAccountGetType (account); - tax_entity_type = scm_from_utf8_string (tax_type); - - if (get_form == SCM_UNDEFINED) - { - const gchar *tax_module; - /* load the tax info */ - gnc_locale_tax_init (); - - get_form = scm_c_eval_string - ("(false-if-exception gnc:txf-get-form)"); - get_desc = scm_c_eval_string - ("(false-if-exception gnc:txf-get-description)"); - } - - g_return_val_if_fail (scm_is_procedure (get_form), NULL); - g_return_val_if_fail (scm_is_procedure (get_desc), NULL); - - category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ? - "txf-income-categories" : - (atype == ACCT_TYPE_EXPENSE ? - "txf-expense-categories" : - (((atype == ACCT_TYPE_BANK) || - (atype == ACCT_TYPE_CASH) || - (atype == ACCT_TYPE_ASSET) || - (atype == ACCT_TYPE_STOCK) || - (atype == ACCT_TYPE_MUTUAL) || - (atype == ACCT_TYPE_RECEIVABLE)) ? - "txf-asset-categories" : - (((atype == ACCT_TYPE_CREDIT) || - (atype == ACCT_TYPE_LIABILITY) || - (atype == ACCT_TYPE_EQUITY) || - (atype == ACCT_TYPE_PAYABLE)) ? - "txf-liab-eq-categories" : "")))); - - if (g_str_has_prefix (code, prefix)) - { - const gchar *num_code_tmp; - num_code_tmp = g_strdup (code); - num_code_tmp++; /* to lose the leading N */ - num_code = g_strdup (num_code_tmp); - num_code_tmp--; - g_free ((gpointer *) num_code_tmp); - } - else - { - num_code = g_strdup (code); - } - - if (category == SCM_UNDEFINED) - { - if (tax_related) - return_string = g_strdup_printf - (_("Tax type %s: invalid code %s for account type"), - tax_type, num_code); - else - return_string = g_strdup_printf - (_("Not tax-related; tax type %s: invalid code %s for account type"), - tax_type, num_code); - } - else - { - SCM code_scm; - SCM form_scm; - code_scm = scm_from_locale_symbol (code); - form_scm = scm_call_3 (get_form, category, code_scm, tax_entity_type); - if (!scm_is_string (form_scm)) - { - if (tax_related) - return_string = g_strdup_printf - (_("Invalid code %s for tax type %s"), - num_code, tax_type); - else - return_string = g_strdup_printf - (_("Not tax-related; invalid code %s for tax type %s"), - num_code, tax_type); - } - else - { - gchar *form = NULL; - - /* Note: using scm_to_utf8_stringn directly here instead - of our wrapper gnc_scm_to_utf8_string. 'form' should - be freed with 'free' instead of 'g_free'. This will - be taken care of automatically during scm_dynwind_end, - because we inform guile of this memory allocation via - scm_dynwind_free a little further. */ - form = scm_to_utf8_stringn (form_scm, NULL); - if (!form) - { - if (tax_related) - return_string = g_strdup_printf - (_("No form: code %s, tax type %s"), num_code, - tax_type); - else - return_string = g_strdup_printf - (_("Not tax-related; no form: code %s, tax type %s"), - num_code, tax_type); - } - else - { - SCM desc_scm; - - /* Create a dynwind context because we will be calling (scm) functions - that potentially exit non-locally */ - scm_dynwind_begin (0); - scm_dynwind_free (form); - desc_scm = scm_call_3 (get_desc, category, code_scm, - tax_entity_type); - if (!scm_is_string (desc_scm)) - { - if (tax_related) - return_string = g_strdup_printf - (_("No description: form %s, code %s, tax type %s"), - form, num_code, tax_type); - else - return_string = g_strdup_printf - (_("Not tax-related; no description: form %s, code %s, tax type %s"), - form, num_code, tax_type); - } - else - { - gchar *desc = NULL; - desc = gnc_scm_to_utf8_string (desc_scm); - if (!desc) - { - if (tax_related) - return_string = g_strdup_printf - (_("No description: form %s, code %s, tax type %s"), - form, num_code, tax_type); - else - return_string = g_strdup_printf - (_("Not tax-related; no description: form %s, code %s, tax type %s"), - form, num_code, tax_type); - } - else - { - gint64 copy_number; - gchar *copy_txt = NULL; - copy_number = xaccAccountGetTaxUSCopyNumber (account); - copy_txt = (copy_number == 1) ? - g_strdup ("") : - g_strdup_printf ("(%d)", - (gint) copy_number); - if (tax_related) - { - if (g_strcmp0 (form, "") == 0) - return_string = g_strdup_printf ("%s", desc); - else - return_string = g_strdup_printf ("%s%s: %s", - form, copy_txt, desc); - } - else - { - return_string = g_strdup_printf - (_("Not tax-related; %s%s: %s (code %s, tax type %s)"), - form, copy_txt, desc, num_code, tax_type); - } - g_free (copy_txt); - } - g_free (desc); - } - scm_dynwind_end (); - } - } - } - g_free (num_code); - return return_string; - } -} - -/* Caller is responsible for g_free'ing returned memory */ -char * -gnc_ui_account_get_tax_info_sub_acct_string (const Account *account) -{ - GList *descendant, *account_descendants; - - if (!account) - return NULL; - - account_descendants = gnc_account_get_descendants (account); - if (account_descendants) - { - gint sub_acct_tax_number = 0; - for (descendant = account_descendants; descendant; - descendant = g_list_next(descendant)) - { - if (xaccAccountGetTaxRelated (descendant->data)) - sub_acct_tax_number++; - } - g_list_free (account_descendants); - g_list_free (descendant); - /* Translators: This and the following strings appear on - the account tab if the Tax Info column is displayed, - i.e. if the user wants to record the tax form number - and location on that tax form which corresponds to this - gnucash account. For the US Income Tax support in - gnucash, each tax code that can be assigned to an - account generally corresponds to a specific line number - on a paper form and each form has a unique - identification (e.g., Form 1040, Schedule A). */ - return (sub_acct_tax_number == 0) ? NULL : - g_strdup_printf (_("(Tax-related subaccounts: %d)"), - sub_acct_tax_number); - } - else - return NULL; -} - /********************************************************************\ * gnc_get_reconcile_str * * return the i18n'd string for the given reconciled flag * diff --git a/libgnucash/app-utils/gnc-ui-util.h b/libgnucash/app-utils/gnc-ui-util.h index 768b0bad1e..3c137371d1 100644 --- a/libgnucash/app-utils/gnc-ui-util.h +++ b/libgnucash/app-utils/gnc-ui-util.h @@ -142,9 +142,6 @@ gchar *gnc_get_account_name_for_split_register(const Account *account, * of things like stock account values from share * values to an amount the requested currency. */ -char *gnc_ui_account_get_tax_info_string (const Account *account); - -char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account); const char * gnc_get_reconcile_str (char reconciled_flag); const char * gnc_get_reconcile_valid_flags (void); diff --git a/libgnucash/app-utils/test/CMakeLists.txt b/libgnucash/app-utils/test/CMakeLists.txt index 03ed9c2cd7..9c5d89247d 100644 --- a/libgnucash/app-utils/test/CMakeLists.txt +++ b/libgnucash/app-utils/test/CMakeLists.txt @@ -26,11 +26,6 @@ gnc_add_test_with_guile(test-exp-parser test-exp-parser.c APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS ) add_app_utils_test(test-print-parse-amount test-print-parse-amount.cpp) -# FIXME Why is this test not run ? -#gnc_add_test_with_guile(test-print-queries test-print-queries.cpp APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS) -gnc_add_test_with_guile(test-scm-query-string test-scm-query-string.cpp - APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS -) add_app_utils_test(test-sx test-sx.cpp) set(gtest_gnc_option_SOURCES @@ -62,49 +57,10 @@ set(GUILE_DEPENDS gncmod-backend-xml ) -set(test_app_utils_scheme_SOURCES - test-c-interface.scm - test-load-app-utils-module.scm -) - -set (test_app_utils_scheme_SRFI64_SOURCES - test-date-utilities.scm - test-options.scm -) - -gnc_add_scheme_test_targets(scm-test-load-app-utils-module - SOURCES "test-load-app-utils-module.scm" - OUTPUT_DIR "tests" - DEPENDS "${GUILE_DEPENDS}") - -gnc_add_scheme_test_targets(scm-test-c-interface - SOURCES "test-c-interface.scm" - OUTPUT_DIR "tests" - DEPENDS "${GUILE_DEPENDS}") - -gnc_add_scheme_tests("${test_app_utils_scheme_SOURCES}") - -if (HAVE_SRFI64) - gnc_add_scheme_test_targets(scm-test-app-utils-srfi64 - SOURCES "${test_app_utils_scheme_SRFI64_SOURCES}" - OUTPUT_DIR "tests" - DEPENDS "${GUILE_DEPENDS};scm-srfi64-extras") - - gnc_add_scheme_test_targets(scm-test-gnc-optiondb - SOURCES "test-gnc-optiondb.scm" "test-gnc-option-scheme-output.scm" - OUTPUT_DIR "tests" - DEPENDS "swig-apputils-guile-cpp;scm-srfi64-extras") - gnc_add_scheme_tests("test-gnc-optiondb.scm") - gnc_add_scheme_tests("test-gnc-option-scheme-output.scm") - gnc_add_scheme_tests("${test_app_utils_scheme_SRFI64_SOURCES}") -endif() - set_dist_list(test_app_utils_DIST CMakeLists.txt test-exp-parser.c test-print-parse-amount.cpp - test-print-queries.cpp - test-scm-query-string.cpp test-sx.cpp gtest-gnc-option.cpp gtest-gnc-optiondb.cpp diff --git a/libgnucash/tax/CMakeLists.txt b/libgnucash/tax/CMakeLists.txt index c1e33b39ed..0e93ac5682 100644 --- a/libgnucash/tax/CMakeLists.txt +++ b/libgnucash/tax/CMakeLists.txt @@ -7,6 +7,9 @@ set_source_files_properties (${locale_tax_SOURCES} PROPERTIES OBJECT_DEPENDS ${C add_library(gnc-locale-tax ${locale_tax_SOURCES}) target_link_libraries(gnc-locale-tax + gnc-engine + gnc-app-utils + gnucash-guile ${GLIB2_LDFLAGS} ${GUILE_LDFLAGS}) diff --git a/libgnucash/tax/gnc-locale-tax.c b/libgnucash/tax/gnc-locale-tax.c index f40e223186..ced2dfeba5 100644 --- a/libgnucash/tax/gnc-locale-tax.c +++ b/libgnucash/tax/gnc-locale-tax.c @@ -30,7 +30,11 @@ #include #include #include - +#include +#include +#include +#include +#include #include "gnc-locale-tax.h" @@ -54,3 +58,259 @@ gnc_locale_tax_init(void) else scm_c_use_module("gnucash locale us tax"); } + +/* Caller is responsible for g_free'ing returned memory */ +char * +gnc_ui_account_get_tax_info_string (const Account *account) +{ + static SCM get_form = SCM_UNDEFINED; + static SCM get_desc = SCM_UNDEFINED; + + gboolean tax_related = FALSE; + const char *code; + + if (!account) + return NULL; + + tax_related = xaccAccountGetTaxRelated (account); + code = xaccAccountGetTaxUSCode (account); + + if (!code) + { + if (!tax_related) + return NULL; + /* tax_related && !code */ + else + /* Translators: This and the following strings appear on + the account tab if the Tax Info column is displayed, + i.e. if the user wants to record the tax form number + and location on that tax form which corresponds to this + gnucash account. For the US Income Tax support in + gnucash, each tax code that can be assigned to an + account generally corresponds to a specific line number + on a paper form and each form has a unique + identification (e.g., Form 1040, Schedule A). */ + return g_strdup (_("Tax-related but has no tax code")); + } + else /* with tax code */ + { + const gchar *tax_type; + GNCAccountType atype; + SCM tax_entity_type; + SCM category; + gchar *num_code = NULL; + const gchar *prefix = "N"; + gchar *return_string = NULL; + + tax_type = gnc_get_current_book_tax_type (); + if (tax_type == NULL || (g_strcmp0 (tax_type, "") == 0)) + return g_strdup (_("Tax entity type not specified")); + + atype = xaccAccountGetType (account); + tax_entity_type = scm_from_utf8_string (tax_type); + + if (get_form == SCM_UNDEFINED) + { + const gchar *tax_module; + /* load the tax info */ + gnc_locale_tax_init (); + + get_form = scm_c_eval_string + ("(false-if-exception gnc:txf-get-form)"); + get_desc = scm_c_eval_string + ("(false-if-exception gnc:txf-get-description)"); + } + + g_return_val_if_fail (scm_is_procedure (get_form), NULL); + g_return_val_if_fail (scm_is_procedure (get_desc), NULL); + + category = scm_c_eval_string (atype == ACCT_TYPE_INCOME ? + "txf-income-categories" : + (atype == ACCT_TYPE_EXPENSE ? + "txf-expense-categories" : + (((atype == ACCT_TYPE_BANK) || + (atype == ACCT_TYPE_CASH) || + (atype == ACCT_TYPE_ASSET) || + (atype == ACCT_TYPE_STOCK) || + (atype == ACCT_TYPE_MUTUAL) || + (atype == ACCT_TYPE_RECEIVABLE)) ? + "txf-asset-categories" : + (((atype == ACCT_TYPE_CREDIT) || + (atype == ACCT_TYPE_LIABILITY) || + (atype == ACCT_TYPE_EQUITY) || + (atype == ACCT_TYPE_PAYABLE)) ? + "txf-liab-eq-categories" : "")))); + + if (g_str_has_prefix (code, prefix)) + { + const gchar *num_code_tmp; + num_code_tmp = g_strdup (code); + num_code_tmp++; /* to lose the leading N */ + num_code = g_strdup (num_code_tmp); + num_code_tmp--; + g_free ((gpointer *) num_code_tmp); + } + else + { + num_code = g_strdup (code); + } + + if (category == SCM_UNDEFINED) + { + if (tax_related) + return_string = g_strdup_printf + (_("Tax type %s: invalid code %s for account type"), + tax_type, num_code); + else + return_string = g_strdup_printf + (_("Not tax-related; tax type %s: invalid code %s for account type"), + tax_type, num_code); + } + else + { + SCM code_scm; + SCM form_scm; + code_scm = scm_from_locale_symbol (code); + form_scm = scm_call_3 (get_form, category, code_scm, tax_entity_type); + if (!scm_is_string (form_scm)) + { + if (tax_related) + return_string = g_strdup_printf + (_("Invalid code %s for tax type %s"), + num_code, tax_type); + else + return_string = g_strdup_printf + (_("Not tax-related; invalid code %s for tax type %s"), + num_code, tax_type); + } + else + { + gchar *form = NULL; + + /* Note: using scm_to_utf8_stringn directly here instead + of our wrapper gnc_scm_to_utf8_string. 'form' should + be freed with 'free' instead of 'g_free'. This will + be taken care of automatically during scm_dynwind_end, + because we inform guile of this memory allocation via + scm_dynwind_free a little further. */ + form = scm_to_utf8_stringn (form_scm, NULL); + if (!form) + { + if (tax_related) + return_string = g_strdup_printf + (_("No form: code %s, tax type %s"), num_code, + tax_type); + else + return_string = g_strdup_printf + (_("Not tax-related; no form: code %s, tax type %s"), + num_code, tax_type); + } + else + { + SCM desc_scm; + + /* Create a dynwind context because we will be calling (scm) functions + that potentially exit non-locally */ + scm_dynwind_begin (0); + scm_dynwind_free (form); + desc_scm = scm_call_3 (get_desc, category, code_scm, + tax_entity_type); + if (!scm_is_string (desc_scm)) + { + if (tax_related) + return_string = g_strdup_printf + (_("No description: form %s, code %s, tax type %s"), + form, num_code, tax_type); + else + return_string = g_strdup_printf + (_("Not tax-related; no description: form %s, code %s, tax type %s"), + form, num_code, tax_type); + } + else + { + gchar *desc = NULL; + desc = gnc_scm_to_utf8_string (desc_scm); + if (!desc) + { + if (tax_related) + return_string = g_strdup_printf + (_("No description: form %s, code %s, tax type %s"), + form, num_code, tax_type); + else + return_string = g_strdup_printf + (_("Not tax-related; no description: form %s, code %s, tax type %s"), + form, num_code, tax_type); + } + else + { + gint64 copy_number; + gchar *copy_txt = NULL; + copy_number = xaccAccountGetTaxUSCopyNumber (account); + copy_txt = (copy_number == 1) ? + g_strdup ("") : + g_strdup_printf ("(%d)", + (gint) copy_number); + if (tax_related) + { + if (g_strcmp0 (form, "") == 0) + return_string = g_strdup_printf ("%s", desc); + else + return_string = g_strdup_printf ("%s%s: %s", + form, copy_txt, desc); + } + else + { + return_string = g_strdup_printf + (_("Not tax-related; %s%s: %s (code %s, tax type %s)"), + form, copy_txt, desc, num_code, tax_type); + } + g_free (copy_txt); + } + g_free (desc); + } + scm_dynwind_end (); + } + } + } + g_free (num_code); + return return_string; + } +} + +/* Caller is responsible for g_free'ing returned memory */ +char * +gnc_ui_account_get_tax_info_sub_acct_string (const Account *account) +{ + GList *descendant, *account_descendants; + + if (!account) + return NULL; + + account_descendants = gnc_account_get_descendants (account); + if (account_descendants) + { + gint sub_acct_tax_number = 0; + for (descendant = account_descendants; descendant; + descendant = g_list_next(descendant)) + { + if (xaccAccountGetTaxRelated (descendant->data)) + sub_acct_tax_number++; + } + g_list_free (account_descendants); + g_list_free (descendant); + /* Translators: This and the following strings appear on + the account tab if the Tax Info column is displayed, + i.e. if the user wants to record the tax form number + and location on that tax form which corresponds to this + gnucash account. For the US Income Tax support in + gnucash, each tax code that can be assigned to an + account generally corresponds to a specific line number + on a paper form and each form has a unique + identification (e.g., Form 1040, Schedule A). */ + return (sub_acct_tax_number == 0) ? NULL : + g_strdup_printf (_("(Tax-related subaccounts: %d)"), + sub_acct_tax_number); + } + else + return NULL; +} diff --git a/libgnucash/tax/gnc-locale-tax.h b/libgnucash/tax/gnc-locale-tax.h index 0e6de189a5..664e931e97 100644 --- a/libgnucash/tax/gnc-locale-tax.h +++ b/libgnucash/tax/gnc-locale-tax.h @@ -24,7 +24,11 @@ #ifndef GNC_LOCALE_TAX_H_ #define GNC_LOCALE_TAX_H_ +#include +#include void gnc_locale_tax_init (void); +char *gnc_ui_account_get_tax_info_string (const Account *account); +char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account); #endif diff --git a/po/POTFILES.in b/po/POTFILES.in index 0c92f8781b..e49d54a694 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,14 +1,20 @@ # This is a list of files which contain translatable strings. # This file was autogenerated by cmake. +bindings/guile/app-utils.scm bindings/guile/business-core.scm +bindings/guile/c-interface.scm bindings/guile/core-utils.scm +bindings/guile/date-utilities.scm bindings/guile/engine.scm +bindings/guile/fin.scm bindings/guile/glib-guile.c bindings/guile/gnc-engine-guile.c bindings/guile/gnc-guile-bindings.c bindings/guile/gnc-guile-utils.c +bindings/guile/gnc-helpers.c bindings/guile/gnc-kvp-guile.cpp bindings/guile/gnc-numeric.scm +bindings/guile/options.scm bindings/guile/utilities.scm bindings/python/app_utils.py bindings/python/deprecation.py @@ -497,13 +503,9 @@ gnucash/report/stylesheets/footer.scm gnucash/report/stylesheets/head-or-tail.scm gnucash/report/stylesheets/plain.scm gnucash/report/trep-engine.scm -libgnucash/app-utils/app-utils.scm libgnucash/app-utils/calculation/expression_parser.c libgnucash/app-utils/calculation/fin.c -libgnucash/app-utils/c-interface.scm -libgnucash/app-utils/date-utilities.scm libgnucash/app-utils/file-utils.c -libgnucash/app-utils/fin.scm libgnucash/app-utils/gfec.c libgnucash/app-utils/gnc-accounting-period.c libgnucash/app-utils/gnc-account-merge.c @@ -512,7 +514,6 @@ libgnucash/app-utils/gnc-entry-quickfill.c libgnucash/app-utils/gnc-euro.c libgnucash/app-utils/gnc-exp-parser.c libgnucash/app-utils/gnc-gsettings.cpp -libgnucash/app-utils/gnc-helpers.c libgnucash/app-utils/gnc-help-utils.c libgnucash/app-utils/gnc-option.cpp libgnucash/app-utils/gnc-option-date.cpp @@ -523,7 +524,6 @@ libgnucash/app-utils/gnc-state.c libgnucash/app-utils/gnc-sx-instance-model.c libgnucash/app-utils/gnc-ui-balances.c libgnucash/app-utils/gnc-ui-util.c -libgnucash/app-utils/options.scm libgnucash/app-utils/QuickFill.c libgnucash/backend/dbi/gnc-backend-dbi.cpp libgnucash/backend/dbi/gnc-dbisqlconnection.cpp