RptCleanup - use generic report loader for locale-specific reports

This requires a bit glue code to determine which locale we're interested in.
Advantage: another gnc-module dropped (gncmod-locale-specific).
This commit is contained in:
Geert Janssens 2019-06-14 17:43:52 +02:00
parent 0a8e0d2928
commit 528bbff8da
15 changed files with 69 additions and 254 deletions

View File

@ -503,7 +503,6 @@ load_gnucash_modules()
{ "gnucash/import-export/bi-import", 0, TRUE},
{ "gnucash/import-export/customer-import", 0, TRUE},
{ "gnucash/report", 0, FALSE },
{ "gnucash/report/locale-specific", 0, FALSE },
{ "gnucash/python", 0, TRUE },
};

View File

@ -1,5 +1,4 @@
add_subdirectory(locale-specific)
add_subdirectory(standard/test)
add_subdirectory(support)
@ -60,6 +59,13 @@ set(reports_example_SCHEME
example/welcome-to-gnucash.scm
)
set(reports_us_SCHEME
locale-specific/us/taxtxf.scm
)
set(reports_de_DE_SCHEME
locale-specific/de_DE/taxtxf.scm
)
set(scm_rpts_GUILE_DEPENDS
gncmod-html
@ -83,6 +89,18 @@ set(scm_rpt_example_GUILE_DEPENDS
scm-report
)
set(scm_rpt_locale_specific_GUILE_DEPENDS
gncmod-html
scm-core-utils
scm-gettext
scm-gnc-module
scm-scm
scm-test-core
scm-tax-us
scm-report
scm-gnome-utils
)
set(scm_rpt_std_GUILE_DEPENDS
${scm_rpts_GUILE_DEPENDS}
scm-app-utils
@ -112,7 +130,6 @@ gnc_add_scheme_targets(scm-reports-standard
TRUE
)
gnc_add_scheme_targets(scm-reports-example
"${reports_example_SCHEME}"
"gnucash/reports/example"
@ -120,14 +137,30 @@ gnc_add_scheme_targets(scm-reports-example
TRUE
)
gnc_add_scheme_targets(scm-reports-us
"${reports_us_SCHEME}"
"gnucash/reports/locale-specific/us"
"${scm_rpt_locale_specific_GUILE_DEPENDS}"
TRUE
)
gnc_add_scheme_targets(scm-reports-de_DE
"${reports_de_DE_SCHEME}"
"gnucash/reports/locale-specific/de_DE"
"${scm_rpt_locale_specific_GUILE_DEPENDS}"
TRUE
)
add_custom_target(scm-reports ALL DEPENDS
scm-reports-standard
scm-reports-example
scm-reports-common
scm-rpt-reports
scm-reports-locale-specific)
scm-reports-us
scm-reports-de_DE)
set_local_dist(reports_DIST_local CMakeLists.txt ${reports_SCHEME}
${reports_common_SCHEME} ${reports_standard_SCHEME} ${reports_example_SCHEME})
set(reports_DIST ${reports_DIST_local} ${reports_locale_specific_DIST}
${reports_support_DIST} ${test_reports_standard_DIST} PARENT_SCOPE)
${reports_common_SCHEME} ${reports_standard_SCHEME} ${reports_example_SCHEME}
${reports_us_SCHEME} ${reports_de_DE_SCHEME})
set(reports_DIST ${reports_DIST_local} ${reports_support_DIST}
${test_reports_standard_DIST} PARENT_SCOPE)

View File

@ -1,53 +0,0 @@
add_subdirectory(test)
set(locale_specific_SOURCES
gncmod-locale-specific.c
)
add_library(gncmod-locale-specific ${locale_specific_SOURCES})
target_link_libraries(gncmod-locale-specific gnc-module gncmod-app-utils gncmod-gnome-utils
${GUILE_LDFLAGS} ${GLIB2_LDFLAGS})
target_compile_definitions(gncmod-locale-specific PRIVATE -DG_LOG_DOMAIN=\"gnc.report.locale\")
if (APPLE)
set_target_properties (gncmod-locale-specific PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/gnucash")
endif()
install(TARGETS gncmod-locale-specific
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/gnucash
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# No headers to install
# Scheme
set(gncmod_locale_reports_SCHEME taxtxf.scm taxtxf-de_DE.scm)
set(GUILE_DEPENDS
gncmod-html
scm-core-utils
scm-gettext
scm-gnc-module
scm-scm
scm-test-core
scm-tax-us
scm-report
scm-gnome-utils
)
gnc_add_scheme_targets(scm-reports-locale-specific-1
"${gncmod_locale_reports_SCHEME}"
gnucash/reports/locale-specific
"${GUILE_DEPENDS}"
FALSE
)
add_custom_target(scm-reports-locale-specific ALL DEPENDS scm-reports-locale-specific-1)
set_local_dist(reports_locale_specific_DIST_local CMakeLists.txt
${locale_specific_SOURCES} ${gncmod_locale_reports_SCHEME})
set(reports_locale_specific_DIST ${reports_locale_specific_DIST_local} ${test_locale_specific_DIST} PARENT_SCOPE)

View File

@ -66,7 +66,7 @@
;; depends must be outside module scope -- and should eventually go away.
(define-module (gnucash reports locale-specific taxtxf-de_DE))
(define-module (gnucash reports locale-specific de_DE taxtxf))
(use-modules (gnucash utilities))
(use-modules (srfi srfi-1))
(use-modules (gnucash core-utils)) ; for gnc:version

View File

@ -1,119 +0,0 @@
/*********************************************************************
* gncmod-locale-reports.c
* module definition/initialization for the locale specific reports
*
* Copyright (c) 2001 Linux Developers Group, Inc.
*********************************************************************/
/********************************************************************\
* 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 *
* *
\********************************************************************/
#include <config.h>
#include <string.h>
#include <locale.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_locale_specific)
/* version of the gnc module system interface we require */
int libgncmod_locale_specific_gnc_module_system_interface = 0;
/* module versioning uses libtool semantics. */
int libgncmod_locale_specific_gnc_module_current = 0;
int libgncmod_locale_specific_gnc_module_revision = 0;
int libgncmod_locale_specific_gnc_module_age = 0;
char *
libgncmod_locale_specific_gnc_module_path(void)
{
/* const char *thislocale = setlocale(LC_ALL, NULL);
if (strncmp(thislocale, "de_DE", 5) == 0)
return g_strdup("gnucash/report/locale-specific/de_DE");
else */
return g_strdup("gnucash/report/locale-specific");
}
char *
libgncmod_locale_specific_gnc_module_description(void)
{
return g_strdup("US income tax reports and related material");
}
int
libgncmod_locale_specific_gnc_module_init(int refcount)
{
const gchar *tax_module, *report_taxtxf;
/* load the tax info */
/* This is a very simple hack that loads the (new, special) German
tax definition file in a German locale, or (default) loads the
US tax file. */
# ifdef G_OS_WIN32
gchar *thislocale = g_win32_getlocale();
gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
g_free(thislocale);
# else /* !G_OS_WIN32 */
const char *thislocale = setlocale(LC_ALL, NULL);
gboolean is_de_DE = (strncmp(thislocale, "de_DE", 5) == 0);
# endif /* G_OS_WIN32 */
if (is_de_DE)
{
tax_module = "gnucash/tax/de_DE";
report_taxtxf = "(use-modules (gnucash reports locale-specific taxtxf-de_DE))";
}
else
{
tax_module = "gnucash/tax/us";
report_taxtxf = "(use-modules (gnucash reports locale-specific taxtxf))";
}
/* The gchar* cast is only because the function declaration expects
a non-const string -- probably an api error. */
if (!gnc_module_load((gchar*)tax_module, 0))
{
return FALSE;
}
/* load the report system */
if (!gnc_module_load("gnucash/report", 0))
{
return FALSE;
}
/* load the report generation scheme code */
if (scm_c_eval_string(report_taxtxf)
== SCM_BOOL_F)
{
g_warning("failed to load %s\n", report_taxtxf);
return FALSE;
}
return TRUE;
}
int
libgncmod_locale_specific_gnc_module_end(int refcount)
{
return TRUE;
}

View File

@ -1,23 +0,0 @@
set(LOCALE_SPECIFIC_US_TEST_INCLUDE_DIRS "")
set(LOCALE_SPECIFIC_US_TEST_LIBS)
gnc_add_test(test-link-module-report-locale-specific-us test-link-module.c
LOCALE_SPECIFIC_US_TEST_INCLUDE_DIRS LOCALE_SPECIFIC_US_TEST_LIBS
)
set(GUILE_DEPENDS
scm-app-utils
gnc-core-utils
gnc-module
gncmod-engine
)
gnc_add_scheme_test_targets(test-load-report-locale-specific-module
"test-load-report-locale-specific-module.scm"
"tests"
"${GUILE_DEPENDS}"
FALSE
)
gnc_add_scheme_tests(test-load-report-locale-specific-module.scm)
set_dist_list(test_locale_specific_DIST CMakeLists.txt test-link-module.c test-load-report-locale-specific-module.scm)

View File

@ -1,26 +0,0 @@
/********************************************************************\
* 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 *
* *
\********************************************************************/
int
main(int argc, char ** argv)
{
return 0;
}

View File

@ -1,14 +0,0 @@
(setenv "GNC_UNINSTALLED" "1")
(use-modules (gnucash gnc-module))
(gnc:module-system-init)
(display " testing US locale-specific report module load ... ")
(display " (done with precursor) ... ")
(if (gnc:module-load "gnucash/tax/us" 0)
(begin
(display "ok\n")
(exit 0))
(begin
(display "failed\n")
(exit -1)))

View File

@ -98,7 +98,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash reports locale-specific taxtxf))
(define-module (gnucash reports locale-specific us taxtxf))
(use-modules (gnucash utilities))
(use-modules (srfi srfi-1))
(use-modules (gnucash gnc-module))

View File

@ -37,16 +37,17 @@
(export gnc:receivables-report-create)
(export gnc:owner-report-create)
;(re-export payables-report-create-internal
;receivables-report-create-internal
;owner-report-create)
(define report-dirs (list
'(gnucash reports standard) ; base directory for standard reports included in gnucash
'(gnucash reports example) ; base directory for example reports included in gnucash
'(gnucash reports standard) ; prefix for standard reports included in gnucash
'(gnucash reports example) ; rexample for example reports included in gnucash
))
(report-module-loader report-dirs)
; Determine which locale-specific prefix to add to the list above
; and then load all reports found in the given prefixes
(let* ((loc (gnc-locale-name))
(loc-spec (if (string-prefix? "de_DE" loc) 'de_DE 'us))
(all-dirs (append report-dirs (list (list 'gnucash 'reports 'locale-specific loc-spec)))))
(report-module-loader all-dirs))
(use-modules (gnucash gnc-module))
(gnc:module-load "gnucash/engine" 0)

View File

@ -95,6 +95,9 @@ gchar * gnc_locale_to_utf8(const gchar *);
const char * gnc_locale_default_iso_currency_code (void);
%newobject gnc_locale_name;
gchar *gnc_locale_name (void);
#if defined(SWIGGUILE)
%rename ("gnc-utf8?") wrap_gnc_utf8_validate;
%inline %{

View File

@ -53,6 +53,7 @@
(re-export gnc-scm-log-msg)
(re-export gnc-scm-log-debug)
(re-export gnc-locale-default-iso-currency-code)
(re-export gnc-locale-name)
(re-export gnc-prefs-set-bool)
(re-export gnc-prefs-set-int)

View File

@ -150,3 +150,13 @@ gnc_locale_decimal_places (void)
return places;
}
gchar *gnc_locale_name (void)
{
# ifdef G_OS_WIN32
return g_win32_getlocale();
# else /* !G_OS_WIN32 */
return g_strdup (setlocale(LC_ALL, NULL));
# endif /* G_OS_WIN32 */
}

View File

@ -37,4 +37,8 @@ const char * gnc_locale_default_iso_currency_code (void);
/* Returns the number of decimal place to print in the current locale */
int gnc_locale_decimal_places (void);
/* Return the name of the currently set locale.
* The returned string should be freed by the caller. */
gchar *gnc_locale_name (void);
#endif /* GNC_LOCALE_UTILS_H */

View File

@ -448,9 +448,8 @@ gnucash/report/reports/example/daily-reports.scm
gnucash/report/reports/example/hello-world.scm
gnucash/report/reports/example/sample-graphs.scm
gnucash/report/reports/example/welcome-to-gnucash.scm
gnucash/report/reports/locale-specific/gncmod-locale-specific.c
gnucash/report/reports/locale-specific/taxtxf-de_DE.scm
gnucash/report/reports/locale-specific/taxtxf.scm
gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
gnucash/report/reports/locale-specific/us/taxtxf.scm
gnucash/report/reports/reports.scm
gnucash/report/reports/standard/account-piecharts.scm
gnucash/report/reports/standard/account-summary.scm