gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Sat May 30 03:34:09 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/18adb572 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/780c4b4e (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d57a1cfa (commit)
	from  https://github.com/Gnucash/gnucash/commit/30450e4d (commit)



commit 18adb5723cce158efa46a7a01f40bb09eaacd5fa
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri May 29 22:55:37 2020 +0200

    C++ tweaks
    
    - use auto where possible
    - replace goto with function to call

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 39362ef9d..029ede5e7 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -48,16 +48,28 @@ namespace bl = boost::locale;
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
 
+static void
+scm_cleanup_and_exit_with_failure (QofSession *session)
+{
+    if (session)
+    {
+        if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
+            g_warning ("Session Error: %s",
+                       qof_session_get_error_message (session));
+            qof_session_destroy (session);
+    }
+    qof_event_resume();
+    gnc_shutdown (1);
+}
+
 static void
 scm_add_quotes(void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
 {
-    const char* add_quotes_file = static_cast<const char*>(data);
-    SCM mod, add_quotes, scm_book, scm_result = SCM_BOOL_F;
-    QofSession *session = NULL;
+    auto add_quotes_file = static_cast<const std::string*>(data);
 
     scm_c_eval_string("(debug-set! stack 200000)");
 
-    mod = scm_c_resolve_module("gnucash price-quotes");
+    auto mod = scm_c_resolve_module("gnucash price-quotes");
     scm_set_current_module(mod);
 
     gnc_prefs_init ();
@@ -68,45 +80,39 @@ scm_add_quotes(void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **ar
     {
         std::cerr << bl::translate ("No quotes retrieved. Finance::Quote isn't "
                                     "installed properly.") << "\n";
-        goto fail;
+        scm_cleanup_and_exit_with_failure (nullptr);
     }
 
-    add_quotes = scm_c_eval_string("gnc:book-add-quotes");
-    session = gnc_get_current_session();
-    if (!session) goto fail;
+    auto add_quotes = scm_c_eval_string("gnc:book-add-quotes");
+    auto session = gnc_get_current_session();
+    if (!session)
+        scm_cleanup_and_exit_with_failure (session);
 
-    qof_session_begin(session, add_quotes_file, FALSE, FALSE, FALSE);
-    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;
+    qof_session_begin(session, add_quotes_file->c_str(), FALSE, FALSE, FALSE);
+    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
     qof_session_load(session, NULL);
-    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;
+    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
-    scm_book = gnc_book_to_scm(qof_session_get_book(session));
-    scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book);
+    auto scm_book = gnc_book_to_scm(qof_session_get_book(session));
+    auto scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book);
 
     qof_session_save(session, NULL);
-    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail;
+    if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
     qof_session_destroy(session);
     if (!scm_is_true(scm_result))
     {
-        g_warning("Failed to add quotes to %s.", add_quotes_file);
-        goto fail;
+        g_warning("Failed to add quotes to %s.", add_quotes_file->c_str());
+        scm_cleanup_and_exit_with_failure (session);
     }
 
     qof_event_resume();
     gnc_shutdown(0);
     return;
-fail:
-    if (session)
-    {
-        if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
-            g_warning("Session Error: %s",
-                      qof_session_get_error_message(session));
-        qof_session_destroy(session);
-    }
-    qof_event_resume();
-    gnc_shutdown(1);
 }
 
 static void
@@ -132,7 +138,6 @@ scm_run_report (void *data,
                 [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
 {
     auto args = static_cast<run_report_args*>(data);
-    QofSession *session = nullptr;
 
     scm_c_eval_string("(debug-set! stack 200000)");
     scm_c_use_module ("gnucash utilities");
@@ -155,18 +160,21 @@ scm_run_report (void *data,
 
     /* dry-run? is #t: try report, check validity of options */
     if (scm_is_false (scm_call_4 (cmdline, report, type, file, SCM_BOOL_T)))
-        goto fail;
+        scm_cleanup_and_exit_with_failure (nullptr);
 
     fprintf (stderr, "Loading datafile %s...\n", datafile);
 
-    session = gnc_get_current_session ();
-    if (!session) goto fail;
+    auto session = gnc_get_current_session ();
+    if (!session)
+        scm_cleanup_and_exit_with_failure (session);
 
     qof_session_begin (session, datafile, TRUE, FALSE, FALSE);
-    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR) goto fail;
+    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
     qof_session_load (session, report_session_percentage);
-    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR) goto fail;
+    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
     fprintf (stderr, "\n");
 
@@ -174,31 +182,21 @@ scm_run_report (void *data,
     scm_call_4 (cmdline, report, type, file, SCM_BOOL_F);
 
     qof_session_end (session);
-    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR) goto fail;
+    if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
+        scm_cleanup_and_exit_with_failure (session);
 
     qof_session_destroy (session);
 
     qof_event_resume ();
     gnc_shutdown (0);
     return;
-fail:
-    if (session)
-    {
-        if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
-            g_warning ("Session Error: %d %s",
-                       qof_session_get_error (session),
-                       qof_session_get_error_message (session));
-        qof_session_destroy (session);
-    }
-    qof_event_resume ();
-    gnc_shutdown (1);
 }
 
 int
-Gnucash::add_quotes (std::string &uri)
+Gnucash::add_quotes (const std::string& uri)
 {
-    if (not uri.empty())
-        scm_boot_guile (0, nullptr, scm_add_quotes, (void *)uri.c_str());
+    if (!uri.empty())
+        scm_boot_guile (0, nullptr, scm_add_quotes, (void *)&uri);
 
     return 0;
 }
@@ -211,7 +209,7 @@ Gnucash::run_report (const std::string& file_to_load,
 {
     auto args = run_report_args { file_to_load, run_report,
                                   export_type, output_file };
-    if (not run_report.empty())
+    if (!run_report.empty())
         scm_boot_guile (0, nullptr, scm_run_report, &args);
 
     return 0;
diff --git a/gnucash/gnucash-commands.hpp b/gnucash/gnucash-commands.hpp
index 9c59d74b6..e400aca78 100644
--- a/gnucash/gnucash-commands.hpp
+++ b/gnucash/gnucash-commands.hpp
@@ -29,7 +29,7 @@
 
 namespace Gnucash {
 
-    int add_quotes (std::string &uri);
+    int add_quotes (const std::string& uri);
     int run_report (const std::string& file_to_load,
                     const std::string& run_report,
                     const std::string& export_type,

commit 780c4b4e2b1551927ead1210b4ebd389b90d59ab
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat May 30 09:22:42 2020 +0200

    Small tweaks that got left out by mistake
    
    Among others this will fix the missing saved reports in
    gnucash-cli --run-report

diff --git a/gnucash/gnucash-cli.cpp b/gnucash/gnucash-cli.cpp
index 809e2230f..153cb2d19 100644
--- a/gnucash/gnucash-cli.cpp
+++ b/gnucash/gnucash-cli.cpp
@@ -93,7 +93,7 @@ Gnucash::GnucashCli::parse_command_line (int argc, char **argv)
 void
 Gnucash::GnucashCli::configure_program_options (void)
 {
-    bpo::options_description quotes_options(_("Price Retrieval Options"));
+    bpo::options_description quotes_options(_("Price Quotes Retrieval Options"));
     quotes_options.add_options()
     ("add-price-quotes", bpo::bool_switch(),
      N_("Add price quotes to given GnuCash datafile.\n"))
@@ -101,7 +101,7 @@ Gnucash::GnucashCli::configure_program_options (void)
      N_("Regular expression determining which namespace commodities will be retrieved"));
     m_opt_desc->add (quotes_options);
 
-    bpo::options_description report_options(_("Run Report Options"));
+    bpo::options_description report_options(_("Report Generation Options"));
     report_options.add_options()
     ("run-report", bpo::value<std::string>(),
      N_("Runs a report\n"))
diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 61ee94318..39362ef9d 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -36,6 +36,7 @@ extern "C" {
 #include <gnc-prefs.h>
 #include <gnc-prefs-utils.h>
 #include <gnc-gnome-utils.h>
+#include <gnc-report.h>
 #include <gnc-session.h>
 }
 
@@ -44,13 +45,6 @@ extern "C" {
 
 namespace bl = boost::locale;
 
-struct run_report_args {
-    const std::string& file_to_load;
-    const std::string& run_report;
-    const std::string& export_type;
-    const std::string& output_file;
-};
-
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
 
@@ -126,33 +120,38 @@ report_session_percentage (const char *message, double percent)
     return;
 }
 
+struct run_report_args {
+    const std::string& file_to_load;
+    const std::string& run_report;
+    const std::string& export_type;
+    const std::string& output_file;
+};
+
 static void
 scm_run_report (void *data,
                 [[maybe_unused]] int argc, [[maybe_unused]] char **argv)
 {
     auto args = static_cast<run_report_args*>(data);
-    QofSession *session = NULL;
-    SCM cmdline, report, type, file;
-    const gchar *datafile;
+    QofSession *session = nullptr;
 
     scm_c_eval_string("(debug-set! stack 200000)");
     scm_c_use_module ("gnucash utilities");
     scm_c_use_module ("gnucash app-utils");
-    scm_c_use_module ("gnucash report");
     scm_c_use_module ("gnucash reports");
 
-    // gnc_report_init ();
+    gnc_report_init ();
     // load_system_config();
     // load_user_config();
     gnc_prefs_init ();
     qof_event_suspend ();
-    datafile = args->file_to_load.c_str();
-
-    cmdline = scm_c_eval_string ("gnc:cmdline-run-report");
-    report = scm_from_utf8_string (args->run_report.c_str());
 
-    type = !args->export_type.empty() ? scm_from_utf8_string (args->export_type.c_str()) : SCM_BOOL_F;
-    file = !args->output_file.empty() ? scm_from_utf8_string (args->output_file.c_str()) : SCM_BOOL_F;
+    auto datafile = args->file_to_load.c_str();
+    auto cmdline = scm_c_eval_string ("gnc:cmdline-run-report");
+    auto report = scm_from_utf8_string (args->run_report.c_str());
+    auto type = !args->export_type.empty() ?
+                scm_from_utf8_string (args->export_type.c_str()) : SCM_BOOL_F;
+    auto file = !args->output_file.empty() ?
+                scm_from_utf8_string (args->output_file.c_str()) : SCM_BOOL_F;
 
     /* dry-run? is #t: try report, check validity of options */
     if (scm_is_false (scm_call_4 (cmdline, report, type, file, SCM_BOOL_T)))

commit d57a1cfaec3432ddb5a16d3178b16350a3dd4718
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri May 29 22:24:43 2020 +0200

    Move saved report loading to report initialization code

diff --git a/gnucash/gnucash.cpp b/gnucash/gnucash.cpp
index 2469ebbfb..4be796cbe 100644
--- a/gnucash/gnucash.cpp
+++ b/gnucash/gnucash.cpp
@@ -69,25 +69,6 @@ namespace bl = boost::locale;
 static QofLogModule log_module = GNC_MOD_GUI;
 static gchar *userdata_migration_msg = NULL;
 
-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)
 {
@@ -136,11 +117,6 @@ load_user_config(void)
         gfec_try_load(config_filename);
         g_free(config_filename);
     }
-
-    update_message("loading saved reports");
-    try_load_config_array(saved_report_files);
-    update_message("loading stylesheets");
-    try_load_config_array(stylesheet_files);
 }
 
 static void
diff --git a/gnucash/report/gnc-report.c b/gnucash/report/gnc-report.c
index 94d4ba9be..45065f422 100644
--- a/gnucash/report/gnc-report.c
+++ b/gnucash/report/gnc-report.c
@@ -50,12 +50,63 @@ static QofLogModule log_module = GNC_MOD_GUI;
 static GHashTable *reports = NULL;
 static gint report_next_serial_id = 0;
 
+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)
+{
+    //gnc_update_splash_screen(msg, GNC_SPLASH_PERCENTAGE_UNKNOWN);
+    g_message("%s", msg);
+}
+
+static void
+load_custom_reports_stylesheets(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 saved reports");
+    try_load_config_array(saved_report_files);
+    update_message("loading stylesheets");
+    try_load_config_array(stylesheet_files);
+}
+
 void
 gnc_report_init (void)
 {
     scm_init_sw_report_module();
     scm_c_use_module ("gnucash report");
+    scm_c_use_module ("gnucash reports");
     scm_c_eval_string("(report-module-loader (list '(gnucash report stylesheets)))");
+
+    load_custom_reports_stylesheets();
 }
 
 



Summary of changes:
 gnucash/gnucash-cli.cpp      |   4 +-
 gnucash/gnucash-commands.cpp | 127 +++++++++++++++++++++----------------------
 gnucash/gnucash-commands.hpp |   2 +-
 gnucash/gnucash.cpp          |  24 --------
 gnucash/report/gnc-report.c  |  51 +++++++++++++++++
 5 files changed, 116 insertions(+), 92 deletions(-)



More information about the gnucash-changes mailing list