mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Small refactoring of scm config loading.
- Remove and cleanup duplicate code - C++-ify - Run code in gnucash-cli commands related to reports. Users may want to load modified report code via config-user.scm which they want to access while executing cli commands
This commit is contained in:
parent
881d3dcd23
commit
047673a493
@ -30,6 +30,7 @@
|
||||
#endif
|
||||
|
||||
#include "gnucash-commands.hpp"
|
||||
#include "gnucash-core-app.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <gnc-engine-guile.h>
|
||||
@ -173,8 +174,7 @@ scm_run_report (void *data,
|
||||
scm_c_use_module ("gnucash reports");
|
||||
|
||||
gnc_report_init ();
|
||||
// load_system_config();
|
||||
// load_user_config();
|
||||
Gnucash::gnc_load_scm_config();
|
||||
gnc_prefs_init ();
|
||||
qof_event_suspend ();
|
||||
|
||||
@ -303,6 +303,7 @@ scm_report_show (void *data,
|
||||
scm_c_use_module ("gnucash app-utils");
|
||||
scm_c_use_module ("gnucash reports");
|
||||
gnc_report_init ();
|
||||
Gnucash::gnc_load_scm_config();
|
||||
|
||||
if (!args->file_to_load.empty())
|
||||
{
|
||||
@ -334,6 +335,7 @@ scm_report_list ([[maybe_unused]] void *data,
|
||||
scm_c_use_module ("gnucash app-utils");
|
||||
scm_c_use_module ("gnucash reports");
|
||||
gnc_report_init ();
|
||||
Gnucash::gnc_load_scm_config();
|
||||
|
||||
scm_call_1 (scm_c_eval_string ("gnc:cmdline-report-list"),
|
||||
scm_current_output_port ());
|
||||
|
@ -40,5 +40,9 @@ namespace Gnucash {
|
||||
int report_list (void);
|
||||
int report_show (const bo_str& file_to_load,
|
||||
const bo_str& run_report);
|
||||
|
||||
// A helper function to load scm config files (SYSCONFIGDIR/config
|
||||
// and USERCONFIGDIR/config-user.scm) on demand
|
||||
void gnc_load_scm_config(void);
|
||||
}
|
||||
#endif
|
||||
|
@ -86,25 +86,6 @@ gnc_print_unstable_message(void)
|
||||
<< bl::format (bl::translate ("To find the last stable version, please refer to {1}")) % PACKAGE_URL << "\n";
|
||||
}
|
||||
|
||||
static gboolean
|
||||
try_load_config_array(const gchar *fns[])
|
||||
{
|
||||
gchar *filename;
|
||||
int i;
|
||||
|
||||
for (i = 0; fns[i]; i++)
|
||||
{
|
||||
filename = gnc_build_userdata_path(fns[i]);
|
||||
if (gfec_try_load(filename))
|
||||
{
|
||||
g_free(filename);
|
||||
return TRUE;
|
||||
}
|
||||
g_free(filename);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
update_message(const gchar *msg)
|
||||
{
|
||||
@ -112,52 +93,28 @@ update_message(const gchar *msg)
|
||||
g_message("%s", msg);
|
||||
}
|
||||
|
||||
static void
|
||||
load_system_config(void)
|
||||
void
|
||||
Gnucash::gnc_load_scm_config (void)
|
||||
{
|
||||
static int is_system_config_loaded = FALSE;
|
||||
gchar *system_config_dir;
|
||||
gchar *system_config;
|
||||
|
||||
if (is_system_config_loaded) return;
|
||||
|
||||
update_message("loading system configuration");
|
||||
system_config_dir = gnc_path_get_pkgsysconfdir();
|
||||
system_config = g_build_filename(system_config_dir, "config", nullptr);
|
||||
is_system_config_loaded = gfec_try_load(system_config);
|
||||
g_free(system_config_dir);
|
||||
g_free(system_config);
|
||||
}
|
||||
|
||||
static void
|
||||
load_user_config(void)
|
||||
{
|
||||
/* Don't continue adding to this list. When 3.0 rolls around bump
|
||||
the 2.4 files off the list. */
|
||||
static const gchar *saved_report_files[] =
|
||||
static auto is_system_config_loaded = false;
|
||||
if (!is_system_config_loaded)
|
||||
{
|
||||
SAVED_REPORTS_FILE, SAVED_REPORTS_FILE_OLD_REV, NULL
|
||||
};
|
||||
static const gchar *stylesheet_files[] = { "stylesheets-2.0", NULL};
|
||||
static int is_user_config_loaded = FALSE;
|
||||
|
||||
if (is_user_config_loaded)
|
||||
return;
|
||||
else is_user_config_loaded = TRUE;
|
||||
|
||||
update_message("loading user configuration");
|
||||
{
|
||||
gchar *config_filename;
|
||||
config_filename = g_build_filename (gnc_userconfig_dir (),
|
||||
"config-user.scm", (char *)NULL);
|
||||
gfec_try_load(config_filename);
|
||||
g_free(config_filename);
|
||||
update_message ("loading system scm configuration");
|
||||
auto system_config_dir = gnc_path_get_pkgsysconfdir ();
|
||||
auto system_config = g_build_filename (system_config_dir, "config", nullptr);
|
||||
is_system_config_loaded = gfec_try_load (system_config);
|
||||
g_free (system_config_dir);
|
||||
g_free (system_config);
|
||||
}
|
||||
|
||||
update_message("loading saved reports");
|
||||
try_load_config_array(saved_report_files);
|
||||
update_message("loading stylesheets");
|
||||
try_load_config_array(stylesheet_files);
|
||||
static auto is_user_config_loaded = false;
|
||||
if (!is_user_config_loaded)
|
||||
{
|
||||
update_message("loading user scm configuration");
|
||||
auto config_filename = g_build_filename (gnc_userconfig_dir (), "config-user.scm", nullptr);
|
||||
is_user_config_loaded = gfec_try_load (config_filename);
|
||||
g_free (config_filename);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -70,5 +70,6 @@ private:
|
||||
char *sys_locale = nullptr;
|
||||
};
|
||||
|
||||
void gnc_load_scm_config(void);
|
||||
}
|
||||
#endif
|
||||
|
@ -73,56 +73,6 @@ namespace bl = boost::locale;
|
||||
static QofLogModule log_module = GNC_MOD_GUI;
|
||||
static gchar *userdata_migration_msg = NULL;
|
||||
|
||||
static void
|
||||
update_message(const gchar *msg)
|
||||
{
|
||||
gnc_update_splash_screen(msg, GNC_SPLASH_PERCENTAGE_UNKNOWN);
|
||||
g_message("%s", msg);
|
||||
}
|
||||
|
||||
static void
|
||||
load_system_config(void)
|
||||
{
|
||||
static int is_system_config_loaded = FALSE;
|
||||
gchar *system_config_dir;
|
||||
gchar *system_config;
|
||||
|
||||
if (is_system_config_loaded) return;
|
||||
|
||||
update_message("loading system configuration");
|
||||
system_config_dir = gnc_path_get_pkgsysconfdir();
|
||||
system_config = g_build_filename(system_config_dir, "config", nullptr);
|
||||
is_system_config_loaded = gfec_try_load(system_config);
|
||||
g_free(system_config_dir);
|
||||
g_free(system_config);
|
||||
}
|
||||
|
||||
static void
|
||||
load_user_config(void)
|
||||
{
|
||||
/* Don't continue adding to this list. When 3.0 rolls around bump
|
||||
the 2.4 files off the list. */
|
||||
static const gchar *saved_report_files[] =
|
||||
{
|
||||
SAVED_REPORTS_FILE, SAVED_REPORTS_FILE_OLD_REV, NULL
|
||||
};
|
||||
static const gchar *stylesheet_files[] = { "stylesheets-2.0", NULL};
|
||||
static int is_user_config_loaded = FALSE;
|
||||
|
||||
if (is_user_config_loaded)
|
||||
return;
|
||||
else is_user_config_loaded = TRUE;
|
||||
|
||||
update_message("loading user configuration");
|
||||
{
|
||||
gchar *config_filename;
|
||||
config_filename = g_build_filename (gnc_userconfig_dir (),
|
||||
"config-user.scm", (char *)NULL);
|
||||
gfec_try_load(config_filename);
|
||||
g_free(config_filename);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_gnucash_plugins()
|
||||
{
|
||||
@ -207,11 +157,10 @@ scm_run_gnucash (void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **
|
||||
load_gnucash_plugins();
|
||||
load_gnucash_modules();
|
||||
|
||||
/* Load the config before starting up the gui. This insures that
|
||||
/* Load the scm config files before starting up the gui. This ensures that
|
||||
* custom reports have been read into memory before the Reports
|
||||
* menu is created. */
|
||||
load_system_config();
|
||||
load_user_config();
|
||||
Gnucash::gnc_load_scm_config();
|
||||
|
||||
/* Setting-up the report menu must come after the module
|
||||
loading but before the gui initializat*ion. */
|
||||
|
Loading…
Reference in New Issue
Block a user