Banish gnc_get_optiondb_from_dispatcher to gnc-report.cpp.

Puts it closer to its points of use and removes it with its Scheme
dependency from libgnucash.
This commit is contained in:
John Ralls 2022-03-13 15:51:16 -07:00
parent d4c3c30b1a
commit 572cb6b1d1
13 changed files with 79 additions and 67 deletions

View File

@ -35,12 +35,12 @@ extern "C"
#include "window-report.h"
#include "guile-mappings.h"
#include "gnc-guile-utils.h"
#include "gnc-report.h"
#include "gnc-ui.h"
}
#include "dialog-report-column-view.hpp"
#include <dialog-options.hpp>
#include <gnc-report.h>
#include <gnc-optiondb.h>
enum available_cols

View File

@ -37,10 +37,10 @@ extern "C"
#include "gnc-gtk-utils.h"
#include "gnc-gnome-utils.h"
#include "gnc-guile-utils.h"
#include "gnc-report.h"
#include "gnc-ui.h"
#include <guile-mappings.h>
}
#include "gnc-report.h"
#include <dialog-options.hpp>
#include <gnc-optiondb.h>

View File

@ -65,7 +65,6 @@ extern "C"
#include "gnc-plugin-page-report.h"
#include "gnc-plugin-file-history.h"
#include "gnc-prefs.h"
#include "gnc-report.h"
#include "gnc-session.h"
#include "gnc-ui-util.h"
#include "gnc-ui.h"
@ -79,6 +78,7 @@ extern "C"
#include <memory>
#include <gnc-report.h>
#include <gnc-optiondb-impl.hpp>
/* NW: you can add GNC_MOD_REPORT to gnc-engine.h

View File

@ -37,13 +37,13 @@ extern "C"
#include "swig-runtime.h"
#include "gnc-guile-utils.h"
#include "gnc-report.h"
#include "gnc-ui.h"
#include "window-report.h"
#include "guile-mappings.h"
#include "gnc-plugin-page-report.h"
}
#include "gnc-report.h"
#include "dialog-options.hpp"
#include "dialog-report-column-view.hpp"

View File

@ -37,7 +37,6 @@ extern "C" {
#include <gnc-prefs.h>
#include <gnc-prefs-utils.h>
#include <gnc-gnome-utils.h>
#include <gnc-report.h>
#include <gnc-session.h>
#include <qoflog.h>
}
@ -45,6 +44,7 @@ extern "C" {
#include <boost/locale.hpp>
#include <fstream>
#include <iostream>
#include <gnc-report.h>
namespace bl = boost::locale;

View File

@ -42,7 +42,6 @@ extern "C" {
#include <gnc-path.h>
#include <gnc-prefs.h>
#include <gnc-gsettings.h>
#include <gnc-report.h>
#include <gnc-splash.h>
#include <gnc-version.h>
#include "gnucash-locale-platform.h"
@ -53,6 +52,7 @@ extern "C" {
#include <iostream>
#include <string>
#include <vector>
#include <gnc-report.h>
namespace bl = boost::locale;

View File

@ -54,7 +54,6 @@ extern "C" {
#include <gnc-plugin-report-system.h>
#include <gnc-prefs.h>
#include <gnc-prefs-utils.h>
#include <gnc-report.h>
#include <gnc-session.h>
#include <gnc-splash.h>
#include <gnucash-register.h>
@ -68,6 +67,7 @@ extern "C" {
#include <boost/nowide/args.hpp>
#endif
#include <iostream>
#include <gnc-report.h>
#include <gnc-locale-utils.hpp>
namespace bl = boost::locale;

View File

@ -14,7 +14,7 @@ gnc_add_swig_guile_command (swig-report-c
)
set (report_SOURCES
gnc-report.c
gnc-report.cpp
)
add_library (gnc-report

View File

@ -30,19 +30,22 @@
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <libguile.h>
extern "C"
{
#include <stdio.h>
#include <string.h>
#include "gfec.h"
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include "gnc-filepath-utils.h"
#include "gnc-guile-utils.h"
#include <gfec.h>
#include <gnc-filepath-utils.h>
#include <gnc-guile-utils.h>
#include <gnc-engine.h>
}
#include "gnc-report.h"
#include "gnc-engine.h"
extern SCM scm_init_sw_report_module(void);
extern "C" SCM scm_init_sw_report_module(void);
static QofLogModule log_module = GNC_MOD_GUI;
@ -130,11 +133,11 @@ gnc_report_remove_by_id(gint id)
SCM gnc_report_find(gint id)
{
gpointer report = NULL;
SCM report = nullptr;
if (reports)
{
report = g_hash_table_lookup(reports, &id);
report = static_cast<SCM>(g_hash_table_lookup(reports, &id));
}
if (!report)
@ -303,9 +306,6 @@ gnc_saved_reports_write_internal (const gchar *file, const gchar *contents, gboo
{
gboolean success = TRUE;
gint fd;
#ifndef __MINGW32__
extern int errno;
#endif
ssize_t written;
gint length;
gint flags = O_WRONLY | O_CREAT | (overwrite ? O_TRUNC : O_APPEND);
@ -393,3 +393,27 @@ gnc_saved_reports_write_to_file (const gchar* report_def, gboolean overwrite)
return success;
}
GncOptionDB*
gnc_get_optiondb_from_dispatcher(SCM dispatcher)
{
SCM get_options = scm_c_eval_string("gnc:options-get");
if (dispatcher == SCM_BOOL_F)
return nullptr;
auto scm_ptr{scm_call_1(get_options, dispatcher)};
auto smob{!scm_is_null(scm_ptr) && SCM_INSTANCEP(scm_ptr) &&
scm_is_true(scm_slot_exists_p(scm_ptr, SCM_EOL)) ?
scm_slot_ref(scm_ptr, SCM_EOL) : (scm_ptr)};
void *c_ptr{nullptr};
if (!SCM_NULLP(smob))
{
if (SCM_POINTER_P(smob))
c_ptr = SCM_POINTER_VALUE(smob);
else
c_ptr = reinterpret_cast<void*>(SCM_CELL_WORD_1(smob));
}
auto u_ptr{static_cast<std::unique_ptr<GncOptionDB>*>(c_ptr)};
return u_ptr->get();
}

View File

@ -27,6 +27,11 @@
#include <glib.h>
#include <libguile.h>
#ifdef __cplusplus
#include <gnc-optiondb.hpp>
extern "C"
{
#endif
#define SAVED_REPORTS_FILE "saved-reports-2.8"
#define SAVED_REPORTS_FILE_OLD_REV "saved-reports-2.4"
@ -35,34 +40,54 @@
*
* Should be called once before using any of its features.
*/
void gnc_report_init (void);
void gnc_report_init(void);
gboolean gnc_run_report_with_error_handling (gint report_id,
gchar **data,
gchar **errmsg);
gboolean gnc_run_report_id_string_with_error_handling (const char * id_string,
char **data,
gchar **errmsg);
gboolean gnc_run_report_with_error_handling(gint report_id,
gchar** data,
gchar** errmsg);
gboolean gnc_run_report_id_string_with_error_handling(const char* id_string,
char** data,
gchar** errmsg);
/**
* @param report The SCM version of the report.
* @return a caller-owned copy of the name of the report, or NULL if report
* is invalid.
**/
gchar* gnc_report_name( SCM report );
gchar* gnc_report_name(SCM report);
/* returns #f if the report id cannot be found */
SCM gnc_report_find(gint id);
void gnc_report_remove_by_id(gint id);
gint gnc_report_add(SCM report);
void gnc_reports_flush_global(void);
GHashTable *gnc_reports_get_global(void);
GHashTable* gnc_reports_get_global(void);
gchar* gnc_get_default_report_font_family(void);
gboolean gnc_saved_reports_backup (void);
gboolean gnc_saved_reports_write_to_file (const gchar* report_def, gboolean overwrite);
gboolean gnc_saved_reports_backup(void);
gboolean gnc_saved_reports_write_to_file(const gchar* report_def, gboolean overwrite);
#ifdef __cplusplus
} //extern "C"
/**
* Obtain a GncOptionDB* from Scheme
*
* When report or stylesheet options are generated in Scheme the GncObjectDB is
* wrapped in a std::unique_ptr and then in a Guile SMOB by SWIG. The GUI code
* needs a reference to the GncObjectDB and we don't want to introduce swig
* library dependencies.
*
* @param dispatch The scheme dispatch function returned by gnc:new-options
* @return GncOptiondDB* Do not free this pointer!
*/
GncOptionDB* gnc_get_optiondb_from_dispatcher(SCM dispatcher);
#endif
#endif

View File

@ -570,29 +570,6 @@ GncOptionDB::load_from_kvp(QofBook* book) noexcept
});
}
GncOptionDB*
gnc_get_optiondb_from_dispatcher(SCM dispatcher)
{
SCM get_options = scm_c_eval_string("gnc:options-get");
if (dispatcher == SCM_BOOL_F)
return nullptr;
auto scm_ptr{scm_call_1(get_options, dispatcher)};
auto smob{!scm_is_null(scm_ptr) && SCM_INSTANCEP(scm_ptr) &&
scm_is_true(scm_slot_exists_p(scm_ptr, SCM_EOL)) ?
scm_slot_ref(scm_ptr, SCM_EOL) : (scm_ptr)};
void *c_ptr{nullptr};
if (!SCM_NULLP(smob))
{
if (SCM_POINTER_P(smob))
c_ptr = SCM_POINTER_VALUE(smob);
else
c_ptr = reinterpret_cast<void*>(SCM_CELL_WORD_1(smob));
}
auto u_ptr{static_cast<std::unique_ptr<GncOptionDB>*>(c_ptr)};
return u_ptr->get();
}
void
gnc_register_string_option(GncOptionDB* db, const char* section,
const char* name, const char* key,

View File

@ -89,20 +89,6 @@ GncOptionDB* gnc_option_db_new(void);
*/
void gnc_option_db_destroy(GncOptionDB* odb);
/**
* Obtain a GncOptionDB* from Scheme
*
* When report or stylesheet options are generated in Scheme the GncObjectDB is
* wrapped in a std::unique_ptr and then in a Guile SMOB by SWIG. The GUI code
* needs a reference to the GncObjectDB and we don't want to introduce swig
* library dependencies.
*
* @param dispatch The scheme dispatch function returned by gnc:new-options
* @return GncOptiondDB* Do not free this pointer!
*/
GncOptionDB*
gnc_get_optiondb_from_dispatcher(SCM dispatcher);
/**
* Write all changed ui_item values to their options.
* @param odb The GncOptionDB.

View File

@ -439,7 +439,7 @@ gnucash/report/commodity-utilities.scm
gnucash/report/eguile-html-utilities.scm
gnucash/report/eguile.scm
gnucash/report/eguile-utilities.scm
gnucash/report/gnc-report.c
gnucash/report/gnc-report.cpp
gnucash/report/html-acct-table.scm
gnucash/report/html-anytag.scm
gnucash/report/html-chart.scm