gnucash maint: Rework default non-currency commodity namespace.
John Ralls
jralls at code.gnucash.org
Thu Mar 24 21:15:16 EDT 2022
Updated via https://github.com/Gnucash/gnucash/commit/109efe62 (commit)
from https://github.com/Gnucash/gnucash/commit/9cde35ae (commit)
commit 109efe62b880713a2fdfd2374613ba6928179ad5
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Mar 24 17:37:47 2022 -0700
Rework default non-currency commodity namespace.
Separate the "All noncurrency" convenience category in the commodity
selector and the default non-commodity namespace proposed by the QIF
importer because they have different functions.
Also remove the namespace guessing code from qif-dialog because with
only one default non-currency namespace there's nothing to guess.
diff --git a/bindings/guile/engine.scm b/bindings/guile/engine.scm
index 76be35339..c7697068e 100644
--- a/bindings/guile/engine.scm
+++ b/bindings/guile/engine.scm
@@ -37,9 +37,6 @@
(export account-full-name<?)
(export accounts-get-children-depth)
-(define-public GNC_COMMODITY_NS_CURRENCY "CURRENCY")
-(define-public GNC_COMMODITY_NS_NONCURRENCY (gettext "ALL NON-CURRENCY"))
-
(define (gnc-pricedb-lookup-latest-before-t64 . args)
(issue-deprecation-warning "gnc-pricedb-lookup-latest-before-t64 has been renamed to gnc-pricedb-lookup-nearest-before-t64")
(apply gnc-pricedb-lookup-nearest-before-t64 args))
diff --git a/gnucash/gnome-utils/dialog-commodity.c b/gnucash/gnome-utils/dialog-commodity.c
index 7e9f8a86b..e5474c380 100644
--- a/gnucash/gnome-utils/dialog-commodity.c
+++ b/gnucash/gnome-utils/dialog-commodity.c
@@ -617,7 +617,7 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
{
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
- GNC_COMMODITY_NS_NONCURRENCY, -1);
+ GNC_COMMODITY_NS_NONISO_GUI, -1);
}
/* add all others to the combobox */
diff --git a/gnucash/import-export/qif-imp/qif-dialog-utils.scm b/gnucash/import-export/qif-imp/qif-dialog-utils.scm
index 166884245..b7dd6a7c6 100644
--- a/gnucash/import-export/qif-imp/qif-dialog-utils.scm
+++ b/gnucash/import-export/qif-imp/qif-dialog-utils.scm
@@ -724,6 +724,11 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-dialog:default-namespace qif-symbol qif-type prefs)
+ (define (currency_ns? ns)
+ (or (string=? (GNC-COMMODITY-NS-CURRENCY) ns)
+ (string=? (GNC-COMMODITY-NS-LEGACY) ns)
+ (string=? (GNC-COMMODITY-NS-ISO4217) ns)))
+
;; Guess a namespace based on the symbol alone.
(define (guess-by-symbol s)
(if (string? s)
@@ -736,28 +741,19 @@
;; compatible with the QIF type?
(and (string=? s (caddr elt))
(not (and (string? qif-type)
- (string=? GNC_COMMODITY_NS_NONCURRENCY
- (cadr elt))
+ (not (currency_ns? (cadr elt))
(or (string-ci=? qif-type "stock")
- (string-ci=? qif-type "etf"))))))
+ (string-ci=? qif-type "etf")
+ (string-ci=? qif-type "mutual fund")
+ (string-ci=? qif-type "index")
+)))))
prefs)
- #f)))
+ #f))))
;; If a preferences match was found, use its namespace.
- (if pref-match (cadr pref-match))
- ;; There's no symbol. Default to a fund.
- GNC_COMMODITY_NS_NONCURRENCY)))
-
- ;; Was a QIF type given?
- (if (string? qif-type)
- ;; Yes. We might be able to definitely determine the namespace.
- (if (or
- (string-ci=? qif-type "mutual fund")
- (string-ci=? qif-type "index"))
- GNC_COMMODITY_NS_NONCURRENCY
- (guess-by-symbol qif-symbol)))
-
- ;; No QIF type was given, so guess a
- ;; default namespace by symbol alone.
+ (if pref-match (cadr pref-match)))
+ ;; There's no symbol. Use the built-in default.
+ (GNC-COMMODITY-NS-NONCURRENCY)))
+
(guess-by-symbol qif-symbol))
diff --git a/gnucash/import-export/qif-imp/qif-to-gnc.scm b/gnucash/import-export/qif-imp/qif-to-gnc.scm
index cc785e825..ec1040437 100644
--- a/gnucash/import-export/qif-imp/qif-to-gnc.scm
+++ b/gnucash/import-export/qif-imp/qif-to-gnc.scm
@@ -270,7 +270,7 @@
(default-currency
(gnc-commodity-table-find-full
(gnc-commodity-table-get-table (gnc-get-current-book))
- GNC_COMMODITY_NS_CURRENCY default-currency-name))
+ (GNC-COMMODITY-NS-CURRENCY) default-currency-name))
(sorted-accounts-list '())
(markable-xtns '())
(sorted-qif-files-list (sort qif-files-list
diff --git a/libgnucash/app-utils/options.scm b/libgnucash/app-utils/options.scm
index 52ab8cf3d..9e950dcfa 100644
--- a/libgnucash/app-utils/options.scm
+++ b/libgnucash/app-utils/options.scm
@@ -435,7 +435,7 @@ the option '~a'."))
(if (string? currency)
(gnc-commodity-table-lookup
(gnc-commodity-table-get-table (gnc-get-current-book))
- GNC_COMMODITY_NS_CURRENCY currency)
+ (GNC-COMMODITY-NS-CURRENCY) currency)
currency))
(let* ((value (currency->scm default-value))
@@ -561,7 +561,7 @@ the option '~a'."))
(define (commodity->scm commodity)
(if (string? commodity)
(list 'commodity-scm
- GNC_COMMODITY_NS_CURRENCY
+ (GNC-COMMODITY-NS-CURRENCY)
commodity)
(list 'commodity-scm
(gnc-commodity-get-namespace commodity)
@@ -1560,7 +1560,7 @@ the option '~a'."))
(if (string? currency-string)
(gnc-commodity-table-lookup
(gnc-commodity-table-get-table (gnc-get-current-book))
- GNC_COMMODITY_NS_CURRENCY currency-string)
+ (GNC-COMMODITY-NS-CURRENCY) currency-string)
#f))
(define (currency? val)
diff --git a/libgnucash/engine/gnc-commodity.c b/libgnucash/engine/gnc-commodity.c
index f36a7565b..df80a9b34 100644
--- a/libgnucash/engine/gnc-commodity.c
+++ b/libgnucash/engine/gnc-commodity.c
@@ -2212,7 +2212,7 @@ gnc_commodity_table_get_commodities(const gnc_commodity_table * table,
if (!table)
return NULL;
- if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONCURRENCY) == 0)
+ if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
return commodity_table_get_all_noncurrency_commodities(table);
ns = gnc_commodity_table_find_namespace(table, name_space);
if (!ns)
@@ -2510,7 +2510,6 @@ gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book)
gnc_commodity* c;
ENTER ("table=%p", table);
- gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NONCURRENCY, book);
gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book);
c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1);
gnc_commodity_table_insert(table, c);
diff --git a/libgnucash/engine/gnc-commodity.h b/libgnucash/engine/gnc-commodity.h
index d7f475db2..cafc331e7 100644
--- a/libgnucash/engine/gnc-commodity.h
+++ b/libgnucash/engine/gnc-commodity.h
@@ -109,7 +109,9 @@ GType gnc_commodity_namespace_get_type(void);
/* The ISO define is deprecated in favor of CURRENCY */
#define GNC_COMMODITY_NS_ISO "ISO4217"
#define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
-#define GNC_COMMODITY_NS_NONCURRENCY NC_("Commodity Type", "All non-currency")
+#define GNC_COMMODITY_NS_NONCURRENCY "NONCURRENCY"
+
+#define GNC_COMMODITY_NS_NONISO_GUI NC_("Commodity Type", "All non-currency")
#define GNC_COMMODITY_NS_ISO_GUI NC_("Commodity Type", "Currencies")
/** Max fraction is 10^9 because 10^10 would require changing it to an
Summary of changes:
bindings/guile/engine.scm | 3 --
gnucash/gnome-utils/dialog-commodity.c | 2 +-
gnucash/import-export/qif-imp/qif-dialog-utils.scm | 34 ++++++++++------------
gnucash/import-export/qif-imp/qif-to-gnc.scm | 2 +-
libgnucash/app-utils/options.scm | 6 ++--
libgnucash/engine/gnc-commodity.c | 3 +-
libgnucash/engine/gnc-commodity.h | 4 ++-
7 files changed, 24 insertions(+), 30 deletions(-)
More information about the gnucash-changes
mailing list