Bug #511182: Commodity mapping preferences are now preserved correctly. In

addition, use of the misleading term "stock" has been replaced by "security"
throughout the C code. Also includes a small fix to prevent passing a null
pointer to xaccAccountGetType(), which caused some critical warnings to be
logged. Some comment and whitespace cleanup as well.
BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17074 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Charles Day 2008-04-10 20:37:41 +00:00
parent f034c41dfb
commit 54d94702d5
4 changed files with 326 additions and 290 deletions

View File

@ -118,8 +118,9 @@ struct _qifimportwindow {
SCM memo_display_info; SCM memo_display_info;
SCM gnc_acct_info; SCM gnc_acct_info;
SCM stock_hash; SCM security_hash;
SCM new_stocks; SCM security_prefs;
SCM new_securities;
SCM ticker_map; SCM ticker_map;
SCM imported_account_tree; SCM imported_account_tree;
@ -192,8 +193,9 @@ gnc_ui_qif_import_druid_destroy (QIFImportWindow * window)
scm_gc_unprotect_object(window->memo_map_info); scm_gc_unprotect_object(window->memo_map_info);
scm_gc_unprotect_object(window->acct_display_info); scm_gc_unprotect_object(window->acct_display_info);
scm_gc_unprotect_object(window->acct_map_info); scm_gc_unprotect_object(window->acct_map_info);
scm_gc_unprotect_object(window->stock_hash); scm_gc_unprotect_object(window->security_hash);
scm_gc_unprotect_object(window->new_stocks); scm_gc_unprotect_object(window->security_prefs);
scm_gc_unprotect_object(window->new_securities);
scm_gc_unprotect_object(window->ticker_map); scm_gc_unprotect_object(window->ticker_map);
scm_gc_unprotect_object(window->imported_account_tree); scm_gc_unprotect_object(window->imported_account_tree);
scm_gc_unprotect_object(window->match_transactions); scm_gc_unprotect_object(window->match_transactions);
@ -240,7 +242,7 @@ get_next_druid_page(QIFImportWindow * wind, GnomeDruidPage * page)
next = current->next; next = current->next;
while (!next || while (!next ||
(!wind->show_doc_pages && g_list_find(wind->doc_pages, next->data)) || (!wind->show_doc_pages && g_list_find(wind->doc_pages, next->data)) ||
(wind->new_stocks == SCM_BOOL_F && (wind->new_securities == SCM_BOOL_F &&
GNOME_DRUID_PAGE(next->data) == get_named_page(wind, "commodity_doc_page"))) { GNOME_DRUID_PAGE(next->data) == get_named_page(wind, "commodity_doc_page"))) {
if(next && next->next) { if(next && next->next) {
next = next->next; next = next->next;
@ -316,7 +318,7 @@ get_prev_druid_page(QIFImportWindow * wind, GnomeDruidPage * page)
* (c) the page is commodity related and the are no new commodities. */ * (c) the page is commodity related and the are no new commodities. */
while (!prev || while (!prev ||
(!wind->show_doc_pages && g_list_find(wind->doc_pages, prev->data)) || (!wind->show_doc_pages && g_list_find(wind->doc_pages, prev->data)) ||
(wind->new_stocks == SCM_BOOL_F && (wind->new_securities == SCM_BOOL_F &&
GNOME_DRUID_PAGE(prev->data) == get_named_page(wind, "commodity_doc_page"))) { GNOME_DRUID_PAGE(prev->data) == get_named_page(wind, "commodity_doc_page"))) {
/* We're either out of pages for this stage, or we've reached /* We're either out of pages for this stage, or we've reached
* an optional doc page that shouldn't be shown. */ * an optional doc page that shouldn't be shown. */
@ -333,7 +335,7 @@ get_prev_druid_page(QIFImportWindow * wind, GnomeDruidPage * page)
prev = g_list_last(wind->pre_comm_pages); prev = g_list_last(wind->pre_comm_pages);
break; break;
case 2: case 2:
if(wind->new_stocks != SCM_BOOL_F) { if(wind->new_securities != SCM_BOOL_F) {
prev = g_list_last(wind->commodity_pages); prev = g_list_last(wind->commodity_pages);
} }
else { else {
@ -1349,7 +1351,7 @@ gnc_ui_qif_import_commodity_update(QIFImportWindow * wind)
* each reference to the "old" commodity with a reference to the commodity * each reference to the "old" commodity with a reference to the commodity
* returned by gnc_commodity_table_insert? */ * returned by gnc_commodity_table_insert? */
if (old_commodity != page->commodity) if (old_commodity != page->commodity)
scm_hash_remove_x(wind->stock_hash, scm_makfrom0str(fullname)); scm_hash_remove_x(wind->security_hash, scm_makfrom0str(fullname));
} }
} }
@ -1456,7 +1458,7 @@ gnc_ui_qif_import_convert(QIFImportWindow * wind)
wind->acct_map_info, wind->acct_map_info,
wind->cat_map_info, wind->cat_map_info,
wind->memo_map_info, wind->memo_map_info,
wind->stock_hash, wind->security_hash,
scm_makfrom0str(currname), scm_makfrom0str(currname),
window), window),
SCM_EOL); SCM_EOL);
@ -1546,26 +1548,27 @@ static gboolean
gnc_ui_qif_import_new_securities(QIFImportWindow * wind) gnc_ui_qif_import_new_securities(QIFImportWindow * wind)
{ {
SCM updates; SCM updates;
SCM update_stock = scm_c_eval_string("qif-import:update-stock-hash"); SCM update_securities = scm_c_eval_string("qif-import:update-security-hash");
/* Get a list of any new QIF securities since the previous call. */ /* Get a list of any new QIF securities since the previous call. */
updates = scm_call_3(update_stock, wind->stock_hash, updates = scm_call_3(update_securities, wind->security_hash,
wind->ticker_map, wind->acct_map_info); wind->ticker_map, wind->acct_map_info);
if (updates != SCM_BOOL_F) if (updates != SCM_BOOL_F)
{ {
/* A list of new QIF securities was returned. Save it. */ /* A list of new QIF securities was returned. Save it. */
scm_gc_unprotect_object(wind->new_stocks); scm_gc_unprotect_object(wind->new_securities);
if (wind->new_stocks != SCM_BOOL_F) if (wind->new_securities != SCM_BOOL_F)
/* There is an existing list, so append the new list. */ /* There is an existing list, so append the new list. */
wind->new_stocks = scm_append(scm_list_2(wind->new_stocks, updates)); wind->new_securities = scm_append(scm_list_2(wind->new_securities,
updates));
else else
wind->new_stocks = updates; wind->new_securities = updates;
scm_gc_protect_object(wind->new_stocks); scm_gc_protect_object(wind->new_securities);
return TRUE; return TRUE;
} }
if (wind->new_stocks != SCM_BOOL_F) if (wind->new_securities != SCM_BOOL_F)
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -1592,7 +1595,7 @@ gnc_ui_qif_import_memo_next_cb(GnomeDruidPage * page,
return gnc_ui_qif_import_generic_next_cb(page, arg1, wind); return gnc_ui_qif_import_generic_next_cb(page, arg1, wind);
else else
{ {
/* if we need to look at stocks, do that, otherwise import /* If we need to look at securities do that; otherwise import
xtns and go to the duplicates page */ xtns and go to the duplicates page */
if (gnc_ui_qif_import_new_securities(wind)) if (gnc_ui_qif_import_new_securities(wind))
{ {
@ -1728,7 +1731,7 @@ gnc_ui_qif_import_comm_check_cb(GnomeDruidPage * page,
/******************************************************************** /********************************************************************
* gnc_ui_qif_import_commodity_prepare_cb * gnc_ui_qif_import_commodity_prepare_cb
* build a mapping of QIF stock name to a gnc_commodity * build a mapping of QIF security name to gnc_commodity
********************************************************************/ ********************************************************************/
static void static void
@ -1739,7 +1742,7 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page,
QIFImportWindow * wind = user_data; QIFImportWindow * wind = user_data;
SCM hash_ref = scm_c_eval_string("hash-ref"); SCM hash_ref = scm_c_eval_string("hash-ref");
SCM stocks; SCM securities;
SCM comm_ptr_token; SCM comm_ptr_token;
GList * current; GList * current;
@ -1748,7 +1751,7 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page,
QIFDruidPage * new_page; QIFDruidPage * new_page;
/* This shouldn't happen, but do the right thing if it does. */ /* This shouldn't happen, but do the right thing if it does. */
if (wind->new_stocks == SCM_BOOL_F || SCM_NULLP(wind->new_stocks)) if (wind->new_securities == SCM_BOOL_F || SCM_NULLP(wind->new_securities))
{ {
g_warning("QIF import: BUG DETECTED! Reached commodity doc page with nothing to do!"); g_warning("QIF import: BUG DETECTED! Reached commodity doc page with nothing to do!");
gnc_ui_qif_import_convert(wind); gnc_ui_qif_import_convert(wind);
@ -1759,9 +1762,9 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page,
* Make druid pages for each new QIF security. * Make druid pages for each new QIF security.
*/ */
gnc_set_busy_cursor(NULL, TRUE); gnc_set_busy_cursor(NULL, TRUE);
stocks = wind->new_stocks; securities = wind->new_securities;
current = wind->commodity_pages; current = wind->commodity_pages;
while (!SCM_NULLP(stocks) && (stocks != SCM_BOOL_F)) while (!SCM_NULLP(securities) && (securities != SCM_BOOL_F))
{ {
if (current) if (current)
{ {
@ -1773,8 +1776,8 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page,
{ {
/* Get the GnuCash commodity corresponding to the new QIF security. */ /* Get the GnuCash commodity corresponding to the new QIF security. */
comm_ptr_token = scm_call_2(hash_ref, comm_ptr_token = scm_call_2(hash_ref,
wind->stock_hash, wind->security_hash,
SCM_CAR(stocks)); SCM_CAR(securities));
#define FUNC_NAME "make_qif_druid_page" #define FUNC_NAME "make_qif_druid_page"
commodity = SWIG_MustGetPtr(comm_ptr_token, commodity = SWIG_MustGetPtr(comm_ptr_token,
SWIG_TypeQuery("_p_gnc_commodity"), 1, 0); SWIG_TypeQuery("_p_gnc_commodity"), 1, 0);
@ -1801,7 +1804,7 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page,
gtk_widget_show_all(new_page->page); gtk_widget_show_all(new_page->page);
} }
stocks = SCM_CDR(stocks); securities = SCM_CDR(securities);
} }
gnc_unset_busy_cursor(NULL); gnc_unset_busy_cursor(NULL);
@ -2086,8 +2089,9 @@ gnc_ui_qif_import_finish_cb(GnomeDruidPage * gpage,
/* Save the user's mapping preferences. */ /* Save the user's mapping preferences. */
scm_apply(save_map_prefs, scm_apply(save_map_prefs,
SCM_LIST4(wind->acct_map_info, wind->cat_map_info, SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
wind->memo_map_info, wind->stock_hash), wind->memo_map_info, wind->security_hash,
wind->security_prefs),
SCM_EOL); SCM_EOL);
/* Open an account tab in the main window if one doesn't exist already. */ /* Open an account tab in the main window if one doesn't exist already. */
@ -2283,8 +2287,8 @@ gnc_ui_qif_import_druid_make(void)
retval->acct_map_info = SCM_BOOL_F; retval->acct_map_info = SCM_BOOL_F;
retval->memo_display_info = SCM_BOOL_F; retval->memo_display_info = SCM_BOOL_F;
retval->memo_map_info = SCM_BOOL_F; retval->memo_map_info = SCM_BOOL_F;
retval->stock_hash = SCM_BOOL_F; retval->security_hash = SCM_BOOL_F;
retval->new_stocks = SCM_BOOL_F; retval->new_securities = SCM_BOOL_F;
retval->ticker_map = SCM_BOOL_F; retval->ticker_map = SCM_BOOL_F;
retval->imported_account_tree = SCM_BOOL_F; retval->imported_account_tree = SCM_BOOL_F;
retval->match_transactions = SCM_BOOL_F; retval->match_transactions = SCM_BOOL_F;
@ -2445,7 +2449,8 @@ gnc_ui_qif_import_druid_make(void)
retval->acct_map_info = scm_list_ref(mapping_info, scm_int2num(1)); retval->acct_map_info = scm_list_ref(mapping_info, scm_int2num(1));
retval->cat_map_info = scm_list_ref(mapping_info, scm_int2num(2)); retval->cat_map_info = scm_list_ref(mapping_info, scm_int2num(2));
retval->memo_map_info = scm_list_ref(mapping_info, scm_int2num(3)); retval->memo_map_info = scm_list_ref(mapping_info, scm_int2num(3));
retval->stock_hash = scm_list_ref(mapping_info, scm_int2num(4)); retval->security_hash = scm_list_ref(mapping_info, scm_int2num(4));
retval->security_prefs = scm_list_ref(mapping_info, scm_int2num(5));
create_ticker_map = scm_c_eval_string("make-ticker-map"); create_ticker_map = scm_c_eval_string("make-ticker-map");
retval->ticker_map = scm_call_0(create_ticker_map); retval->ticker_map = scm_call_0(create_ticker_map);
@ -2459,8 +2464,9 @@ gnc_ui_qif_import_druid_make(void)
scm_gc_protect_object(retval->memo_map_info); scm_gc_protect_object(retval->memo_map_info);
scm_gc_protect_object(retval->acct_display_info); scm_gc_protect_object(retval->acct_display_info);
scm_gc_protect_object(retval->acct_map_info); scm_gc_protect_object(retval->acct_map_info);
scm_gc_protect_object(retval->stock_hash); scm_gc_protect_object(retval->security_hash);
scm_gc_protect_object(retval->new_stocks); scm_gc_protect_object(retval->security_prefs);
scm_gc_protect_object(retval->new_securities);
scm_gc_protect_object(retval->ticker_map); scm_gc_protect_object(retval->ticker_map);
scm_gc_protect_object(retval->imported_account_tree); scm_gc_protect_object(retval->imported_account_tree);
scm_gc_protect_object(retval->match_transactions); scm_gc_protect_object(retval->match_transactions);

View File

@ -610,61 +610,59 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; qif-import:update-stock-hash ;; qif-import:update-security-hash
;; ;;
;; make new commodities for each new stock in acct-hash that isn't ;; Make new commodities for each new security in acct-hash
;; already in stock-hash. Return a list of the QIF names of the ;; that isn't already in security-hash. Return a list of
;; new stocks or #f if none. ;; the QIF names for which new commodities are created, or
;; #f if none.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:update-stock-hash stock-hash ticker-map acct-hash) (define (qif-import:update-security-hash security-hash ticker-map acct-hash)
(let ((names '())) (let ((names '()))
(hash-fold (hash-fold
(lambda (qif-name map-entry p) (lambda (qif-name map-entry p)
(let ((stock-name (qif-import:get-account-name qif-name))) (let ((security-name (qif-import:get-account-name qif-name)))
;; is it: a stock or mutual fund and displayed and not already in ;; is it: a stock or mutual fund and displayed and not already in
;; the stock-hash? ;; the security-hash?
(if (and (if (and
stock-name security-name
(qif-map-entry:display? map-entry) (qif-map-entry:display? map-entry)
(or (memv GNC-STOCK-TYPE (or (memv GNC-STOCK-TYPE
(qif-map-entry:allowed-types map-entry)) (qif-map-entry:allowed-types map-entry))
(memv GNC-MUTUAL-TYPE (memv GNC-MUTUAL-TYPE
(qif-map-entry:allowed-types map-entry))) (qif-map-entry:allowed-types map-entry)))
(not (hash-ref stock-hash stock-name))) (not (hash-ref security-hash security-name)))
(let* ((separator (string-ref (gnc-get-account-separator-string) 0)) (let ((existing-gnc-acct
(existing-gnc-acct
(gnc-account-lookup-by-full-name (gnc-account-lookup-by-full-name
(gnc-get-current-root-account) (gnc-get-current-root-account)
(qif-map-entry:gnc-name map-entry))) (qif-map-entry:gnc-name map-entry)))
(book (gnc-account-get-book (gnc-get-current-root-account))) (book (gnc-account-get-book (gnc-get-current-root-account))))
(existing-type
(xaccAccountGetType existing-gnc-acct)))
(if (and (not (null? existing-gnc-acct)) (if (and (not (null? existing-gnc-acct))
(memv existing-type (list GNC-STOCK-TYPE (memv (xaccAccountGetType existing-gnc-acct)
GNC-MUTUAL-TYPE))) (list GNC-STOCK-TYPE GNC-MUTUAL-TYPE)))
;; gnc account already exists... we *know* what the ;; gnc account already exists... we *know* what the
;; security is supposed to be ;; security is supposed to be
(let ((commodity (let ((commodity
(xaccAccountGetCommodity existing-gnc-acct))) (xaccAccountGetCommodity existing-gnc-acct)))
(hash-set! stock-hash stock-name commodity)) (hash-set! security-hash security-name commodity))
;; we know nothing about this security.. we need to ;; we know nothing about this security.. we need to
;; ask about it ;; ask about it
(let ((ticker-symbol (let ((ticker-symbol
(qif-ticker-map:lookup-ticker ticker-map (qif-ticker-map:lookup-ticker ticker-map
stock-name)) security-name))
(namespace GNC_COMMODITY_NS_MUTUAL)) (namespace GNC_COMMODITY_NS_MUTUAL))
(if (not ticker-symbol) (if (not ticker-symbol)
(set! ticker-symbol stock-name) (set! ticker-symbol security-name)
(set! namespace (set! namespace
(qif-dialog:default-namespace ticker-symbol))) (qif-dialog:default-namespace ticker-symbol)))
(set! names (cons stock-name names)) (set! names (cons security-name names))
(hash-set! (hash-set! security-hash
stock-hash stock-name security-name
(gnc-commodity-new book (gnc-commodity-new book
stock-name security-name
namespace namespace
ticker-symbol ticker-symbol
"" ""

View File

@ -33,7 +33,8 @@
;; - a hash of QIF category to gnucash account info ;; - a hash of QIF category to gnucash account info
;; - a hash of QIF memo/payee to gnucash account info ;; - a hash of QIF memo/payee to gnucash account info
;; (older saved prefs may not have this one) ;; (older saved prefs may not have this one)
;; - a hash of QIF stock name to gnc-commodity* ;; - a hash of QIF security name to gnc-commodity*
;; - a list of all previously saved security mappings
;; (older saved prefs may not have this one) ;; (older saved prefs may not have this one)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -80,18 +81,18 @@
(let ((qif-account-list #f) (let ((qif-account-list #f)
(qif-cat-list #f) (qif-cat-list #f)
(qif-memo-list #f) (qif-memo-list #f)
(qif-stock-list #f) (qif-security-list #f)
(qif-account-hash #f) (qif-account-hash #f)
(qif-cat-hash #f) (qif-cat-hash #f)
(qif-memo-hash #f) (qif-memo-hash #f)
(qif-stock-hash #f) (qif-security-hash #f)
(saved-sep #f)) (saved-sep #f))
;; Read the mapping file. ;; Read the mapping file.
(set! qif-account-list (safe-read)) (set! qif-account-list (safe-read))
(set! qif-cat-list (safe-read)) (set! qif-cat-list (safe-read))
(set! qif-memo-list (safe-read)) (set! qif-memo-list (safe-read))
(set! qif-stock-list (safe-read)) (set! qif-security-list (safe-read))
(set! saved-sep (safe-read)) (set! saved-sep (safe-read))
;; Process the QIF account mapping. ;; Process the QIF account mapping.
@ -114,22 +115,24 @@
saved-sep))) saved-sep)))
;; Process the QIF security mapping. ;; Process the QIF security mapping.
(if (not (list? qif-stock-list)) (if (not (list? qif-security-list))
(set! qif-stock-hash (make-hash-table 20)) (set! qif-security-hash (make-hash-table 20))
(set! qif-stock-hash (qif-import:read-commodities (set! qif-security-hash (qif-import:read-securities
qif-stock-list))) qif-security-list)))
;; Put all the mappings together in a list. ;; Put all the mappings together in a list.
(set! results (list qif-account-hash (set! results (list qif-account-hash
qif-cat-hash qif-cat-hash
qif-memo-hash qif-memo-hash
qif-stock-hash))))) qif-security-hash
qif-security-list)))))
;; Otherwise, we can't get any saved mappings. Use empty tables. ;; Otherwise, we can't get any saved mappings. Use empty tables.
(set! results (list (make-hash-table 20) (set! results (list (make-hash-table 20)
(make-hash-table 20) (make-hash-table 20)
(make-hash-table 20) (make-hash-table 20)
(make-hash-table 20)))) (make-hash-table 20)
'())))
;; Build the list of all known account names. ;; Build the list of all known account names.
(let* ((all-accounts (gnc-get-current-root-account)) (let* ((all-accounts (gnc-get-current-root-account))
@ -180,20 +183,22 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; qif-import:read-commodities ;; qif-import:read-securities
;; ;;
;; This procedure examines a list of previously seen commodities ;; This procedure examines a list of previously seen security
;; and returns a hash table of them, if they still exist. ;; mappings and returns a hash table pairing QIF security names
;; with existing GnuCash commodities.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:read-commodities commlist) (define (qif-import:read-securities security-list)
(let ((table (make-hash-table 20))) (let ((table (make-hash-table 20)))
(for-each (for-each
(lambda (entry) (lambda (entry)
(if (and (list? entry) (if (and (list? entry)
(= 3 (length entry))) (= 3 (length entry)))
;; The saved information about each commodity is a ;; The saved information about each security mapping is a
;; list of three items: name, namespace, and mnemonic. ;; list of three items: the QIF name, and the GnuCash
;; namespace and mnemonic (symbol) to which it maps.
;; Example: ("McDonald's" "NYSE" "MCD") ;; Example: ("McDonald's" "NYSE" "MCD")
(let ((commodity (gnc-commodity-table-lookup (let ((commodity (gnc-commodity-table-lookup
(gnc-commodity-table-get-table (gnc-commodity-table-get-table
@ -201,26 +206,47 @@
(cadr entry) (cadr entry)
(caddr entry)))) (caddr entry))))
(if (and commodity (not (null? commodity))) (if (and commodity (not (null? commodity)))
;; The commodity is defined in GnuCash. ;; There is an existing GnuCash commodity for this
;; combination of namespace and symbol.
(hash-set! table (car entry) commodity))))) (hash-set! table (car entry) commodity)))))
commlist) security-list)
table)) table))
(define (qif-import:write-commodities hashtab)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; qif-import:write-securities
;;
;; This procedure writes a mapping QIF security names to
;; GnuCash commodity namespaces and mnemonics (symbols).
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:write-securities security-hash security-prefs)
(let ((table '())) (let ((table '()))
;; For each security that has been paired with an existing
;; GnuCash commodity, create a list containing the QIF name
;; and the commodity's namespace and mnemonic (symbol).
(hash-fold (hash-fold
(lambda (key value p) (lambda (key value p)
;;FIXME: we used to type-check the values, like: ;;FIXME: we used to type-check the values, like:
;; (gw:wcp-is-of-type? <gnc:commodity*> value) ;; (gw:wcp-is-of-type? <gnc:commodity*> value)
(if (and value #t) (if (and value #t)
(set! table (set! table (cons (list key
(cons (list key
(gnc-commodity-get-namespace value) (gnc-commodity-get-namespace value)
(gnc-commodity-get-mnemonic value)) (gnc-commodity-get-mnemonic value))
table)) table))
(gnc:warn "qif-import:write-commodities:" (gnc:warn "qif-import:write-securities:"
" something funny in hash table.")) " something funny in hash table."))
#f) #f hashtab) #f)
#f security-hash)
;; Add on the rest of the saved security mapping preferences.
(for-each
(lambda (m)
(if (not (hash-ref security-hash (car m)))
(set! table (cons m table))))
security-prefs)
;; Write out the mappings.
(write table))) (write table)))
@ -233,7 +259,8 @@
;; user cancels the import instead. ;; user cancels the import instead.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:save-map-prefs acct-map cat-map memo-map stock-map) (define (qif-import:save-map-prefs acct-map cat-map memo-map
security-map security-prefs)
(let* ((pref-filename (gnc-build-dotgnucash-path "qif-accounts-map"))) (let* ((pref-filename (gnc-build-dotgnucash-path "qif-accounts-map")))
;; does the file exist? if not, create it; in either case, ;; does the file exist? if not, create it; in either case,
;; make sure it's a directory and we have write and execute ;; make sure it's a directory and we have write and execute
@ -241,26 +268,31 @@
(with-output-to-file pref-filename (with-output-to-file pref-filename
(lambda () (lambda ()
(display ";;; qif-accounts-map\n") (display ";;; qif-accounts-map\n")
(display ";;; automatically generated by GNUcash. DO NOT EDIT\n") (display ";;; Automatically generated by GnuCash. DO NOT EDIT.\n")
(display ";;; (unless you really, really want to).\n") (display ";;; (Unless you really, really want to.)\n")
(display ";;; map from QIF accounts to GNC accounts") (newline) (display ";;; Map QIF accounts to GnuCash accounts")
(newline)
(qif-import:write-map acct-map) (qif-import:write-map acct-map)
(newline) (newline)
(display ";;; map from QIF categories to GNC accounts") (newline) (display ";;; Map QIF categories to GnuCash accounts")
(newline)
(qif-import:write-map cat-map) (qif-import:write-map cat-map)
(newline) (newline)
(display ";;; map from QIF payee/memo to GNC accounts") (newline) (display ";;; Map QIF payee/memo to GnuCash accounts")
(newline)
(qif-import:write-map memo-map) (qif-import:write-map memo-map)
(newline) (newline)
(display ";;; map from QIF stock name to GNC commodity") (newline) (display ";;; Map QIF security names to GnuCash commodities")
(qif-import:write-commodities stock-map) (newline)
(qif-import:write-securities security-map security-prefs)
(newline) (newline)
(display ";;; GnuCash separator used in these mappings") (newline) (display ";;; GnuCash separator used in these mappings")
(newline)
(write (string-ref (gnc-get-account-separator-string) 0)) (write (string-ref (gnc-get-account-separator-string) 0))
(newline))))) (newline)))))

View File

@ -39,7 +39,7 @@
(export qif-import:get-all-accts) (export qif-import:get-all-accts)
(export qif-import:fix-from-acct) (export qif-import:fix-from-acct)
(export qif-import:any-new-accts?) (export qif-import:any-new-accts?)
(export qif-import:update-stock-hash) (export qif-import:update-security-hash)
(export qif-import:refresh-match-selection) (export qif-import:refresh-match-selection)
(export qif-import:save-map-prefs) (export qif-import:save-map-prefs)
(export qif-import:load-map-prefs) (export qif-import:load-map-prefs)