gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Fri Aug 14 10:25:33 EDT 2020
Updated via https://github.com/Gnucash/gnucash/commit/d1976fc7 (commit)
via https://github.com/Gnucash/gnucash/commit/79476ba6 (commit)
from https://github.com/Gnucash/gnucash/commit/237626f0 (commit)
commit d1976fc7fed9ca1e7bddb7e040509be9f1bb916c
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Aug 14 22:23:00 2020 +0800
[gnc-plugin-page-report.c] set dialog parent properly
diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c
index e5c1a1e4f..b797b1cf1 100644
--- a/gnucash/gnome/gnc-plugin-page-report.c
+++ b/gnucash/gnome/gnc-plugin-page-report.c
@@ -1426,7 +1426,7 @@ gnc_plugin_page_report_stop_cb( GtkAction *action, GncPluginPageReport *report )
/* Returns SCM_BOOL_F if cancel. Returns SCM_BOOL_T if html.
* Otherwise returns pair from export_types. */
static SCM
-gnc_get_export_type_choice (SCM export_types)
+gnc_get_export_type_choice (SCM export_types, GtkWindow *parent)
{
GList * choices = NULL;
gboolean bad = FALSE;
@@ -1469,9 +1469,9 @@ gnc_get_export_type_choice (SCM export_types)
choices = g_list_prepend (choices, g_strdup (_("HTML")));
choice = gnc_choose_radio_option_dialog
- (NULL, _("Choose export format"),
- _("Choose the export format for this report:"),
- NULL, 0, choices);
+ (GTK_WIDGET (parent), _("Choose export format"),
+ _("Choose the export format for this report:"),
+ NULL, 0, choices);
}
else
choice = -1;
@@ -1494,7 +1494,7 @@ gnc_get_export_type_choice (SCM export_types)
}
static char *
-gnc_get_export_filename (SCM choice)
+gnc_get_export_filename (SCM choice, GtkWindow *parent)
{
char * filepath;
GStatBuf statbuf;
@@ -1513,8 +1513,8 @@ gnc_get_export_filename (SCM choice)
title = g_strdup_printf (_("Save %s To File"), type);
default_dir = gnc_get_default_directory(GNC_PREFS_GROUP_REPORT);
- filepath = gnc_file_dialog (gnc_ui_get_main_window (NULL),
- title, NULL, default_dir, GNC_FILE_DIALOG_EXPORT);
+ filepath = gnc_file_dialog (parent, title, NULL, default_dir,
+ GNC_FILE_DIALOG_EXPORT);
if (filepath != NULL) // test for cancel pressed
{
@@ -1541,7 +1541,7 @@ gnc_get_export_filename (SCM choice)
/* %s is the strerror(3) string of the error that occurred. */
const char *format = _("You cannot save to that filename.\n\n%s");
- gnc_error_dialog (NULL, format, strerror(errno));
+ gnc_error_dialog (parent, format, strerror(errno));
g_free(filepath);
return NULL;
}
@@ -1551,7 +1551,7 @@ gnc_get_export_filename (SCM choice)
{
const char *message = _("You cannot save to that file.");
- gnc_error_dialog (NULL, "%s", message);
+ gnc_error_dialog (parent, "%s", message);
g_free(filepath);
return NULL;
}
@@ -1561,7 +1561,7 @@ gnc_get_export_filename (SCM choice)
const char *format = _("The file %s already exists. "
"Are you sure you want to overwrite it?");
- if (!gnc_verify_dialog (NULL, FALSE, format, filepath))
+ if (!gnc_verify_dialog (parent, FALSE, format, filepath))
{
g_free(filepath);
return NULL;
@@ -1642,6 +1642,8 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
SCM export_thunk;
gboolean result;
SCM choice;
+ GtkWindow *parent = GTK_WINDOW (gnc_plugin_page_get_window
+ (GNC_PLUGIN_PAGE (report)));
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
export_types = scm_call_1 (scm_c_eval_string ("gnc:report-export-types"),
@@ -1651,14 +1653,14 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
priv->cur_report);
if (scm_is_list (export_types) && scm_is_procedure (export_thunk))
- choice = gnc_get_export_type_choice (export_types);
+ choice = gnc_get_export_type_choice (export_types, parent);
else
choice = SCM_BOOL_T;
if (choice == SCM_BOOL_F)
return;
- filepath = gnc_get_export_filename (choice);
+ filepath = gnc_get_export_filename (choice, parent);
if (!filepath)
return;
@@ -1681,7 +1683,7 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
{
const char *fmt = _("Could not open the file %s. "
"The error is: %s");
- gnc_error_dialog( NULL, fmt, filepath ? filepath : "(null)",
+ gnc_error_dialog (parent, fmt, filepath ? filepath : "(null)",
strerror (errno) ? strerror (errno) : "" );
}
commit 79476ba6dc92ae94a3c0e91f0718f383009d682f
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Fri Aug 14 15:45:42 2020 +0800
don't crash if objects are built with invalid fieldnames
(gnc:define-report
'version 3
'name "Test Report Template4"
'invalid-field-name 'x
'report-guid "xxx")
gnc:define-report and other constructors will not crash when fieldname
is invalid.
diff --git a/gnucash/report/html-style-info.scm b/gnucash/report/html-style-info.scm
index a2f92d87b..20f34e640 100644
--- a/gnucash/report/html-style-info.scm
+++ b/gnucash/report/html-style-info.scm
@@ -61,6 +61,8 @@
retval))
(define (gnc:html-markup-style-info-set! style . rest)
+ (define allowable-fields (record-type-fields <html-markup-style-info>))
+ (define (not-a-field? fld) (not (memq fld allowable-fields)))
(let loop ((arglist rest))
(match arglist
(('attribute (key val) . rest)
@@ -71,6 +73,9 @@
(gnc:html-markup-style-info-set-attribute! style key #f)
(loop rest))
+ (((? not-a-field? fld) . _)
+ (gnc:error "gnc:html-markup-style-info-set! " fld " is not a valid field"))
+
((field value . rest)
((record-modifier <html-markup-style-info> field) style value)
(loop rest))
diff --git a/gnucash/report/html-style-sheet.scm b/gnucash/report/html-style-sheet.scm
index b0384e7e4..afd3322d9 100644
--- a/gnucash/report/html-style-sheet.scm
+++ b/gnucash/report/html-style-sheet.scm
@@ -56,13 +56,20 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (gnc:define-html-style-sheet . args)
+ (define allowable-fields (record-type-fields <html-style-sheet-template>))
+ (define (not-a-field? fld) (not (memq fld allowable-fields)))
(let loop ((args args) (ss (make-ss-template #f #f #f #f)))
(match args
+ (()
+ (hash-set! *gnc:_style-sheet-templates_*
+ (gnc:html-style-sheet-template-name ss) ss))
+
+ (((? not-a-field? fld) . _)
+ (gnc:error "gnc:define-html-style-sheet " fld " is not a valid field"))
+
((field value . rest)
((record-modifier <html-style-sheet-template> field) ss value)
- (loop rest ss))
- (_ (hash-set! *gnc:_style-sheet-templates_*
- (gnc:html-style-sheet-template-name ss) ss)))))
+ (loop rest ss)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; <html-style-sheet> methods
diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index 1715e6bea..a1529bb9c 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -155,29 +155,33 @@ not found.")))
;; set of options, and generates the report. the renderer must
;; return as its final value an <html-document> object.
(define report-rec (make-report-template))
+ (define allowable-fields (record-type-fields <report-template>))
+ (define (not-a-field? fld) (not (memq fld allowable-fields)))
(let loop ((args args))
(match args
- (() #f)
- ((field val . rest)
- ((record-modifier <report-template> field) report-rec val)
- (loop rest))))
+ (()
+ (let ((report-guid (gnc:report-template-report-guid report-rec))
+ (report-name (gnc:report-template-name report-rec)))
+ (cond
+ ;; missing report-guid: is an error
+ ((not report-guid)
+ (gui-error (string-append rpterr-guid1 report-name rpterr-guid2)))
- (let* ((report-guid (gnc:report-template-report-guid report-rec))
- (report-name (gnc:report-template-name report-rec)))
- (cond
+ ;; dupe: report-guid is a duplicate
+ ((hash-ref *gnc:_report-templates_* report-guid)
+ (gui-error (string-append rpterr-dupe report-guid)))
- ;; missing report-guid: is an error
- ((not report-guid)
- (gui-error (string-append rpterr-guid1 report-name rpterr-guid2)))
+ ;; good: new report definition, store into report-templates hash
+ (else
+ (hash-set! *gnc:_report-templates_* report-guid report-rec)))))
- ;; dupe: report-guid is a duplicate
- ((hash-ref *gnc:_report-templates_* report-guid)
- (gui-error (string-append rpterr-dupe report-guid)))
+ (((? not-a-field? fld) . _)
+ (gnc:error "gnc:define-report: " fld " is not a valid field"))
- ;; good: new report definition, store into report-templates hash
- (else
- (hash-set! *gnc:_report-templates_* report-guid report-rec)))))
+ ((field val . rest)
+ ((record-modifier <report-template> field) report-rec val)
+ (loop rest)))))
(define (gnc:report-template-new-options/report-guid template-id template-name)
(let ((templ (hash-ref *gnc:_report-templates_* template-id)))
diff --git a/gnucash/report/test/test-report.scm b/gnucash/report/test/test-report.scm
index d2d0efa4c..80a24ef49 100644
--- a/gnucash/report/test/test-report.scm
+++ b/gnucash/report/test/test-report.scm
@@ -10,6 +10,7 @@
;; if (test-runner-factory gnc:test-runner) is commented out, this
;; will create Testing/Temporary/test-asset-performance.log
(test-check1)
+ (test-check-invalid-field)
(test-check2)
(test-check3)
(test-check4)
@@ -30,6 +31,15 @@
1
(length (gnc:all-report-template-guids))))
+(define (test-check-invalid-field)
+ (gnc:define-report 'version 3
+ 'name "Test Report Template4"
+ 'invalid-field-name 'x
+ 'report-guid "xxx")
+ (test-equal "report with invalid field name: didn't crash"
+ 1
+ (length (gnc:all-report-template-guids))))
+
;; -----------------------------------------------------------------------
(define (test-check2)
Summary of changes:
gnucash/gnome/gnc-plugin-page-report.c | 28 ++++++++++++++------------
gnucash/report/html-style-info.scm | 5 +++++
gnucash/report/html-style-sheet.scm | 13 +++++++++---
gnucash/report/report-core.scm | 36 +++++++++++++++++++---------------
gnucash/report/test/test-report.scm | 10 ++++++++++
5 files changed, 60 insertions(+), 32 deletions(-)
More information about the gnucash-changes
mailing list