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.
This commit is contained in:
John Ralls 2022-03-24 17:37:47 -07:00
parent 9cde35aed8
commit 109efe62b8
7 changed files with 23 additions and 29 deletions

View File

@ -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))

View File

@ -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 */

View File

@ -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)))
(if pref-match (cadr pref-match)))
;; There's no symbol. Use the built-in default.
(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.
(guess-by-symbol qif-symbol))

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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