diff --git a/src/import-export/qif-import/druid-qif-import.c b/src/import-export/qif-import/druid-qif-import.c index 7205f39a98..1842db3c54 100644 --- a/src/import-export/qif-import/druid-qif-import.c +++ b/src/import-export/qif-import/druid-qif-import.c @@ -118,8 +118,9 @@ struct _qifimportwindow { SCM memo_display_info; SCM gnc_acct_info; - SCM stock_hash; - SCM new_stocks; + SCM security_hash; + SCM security_prefs; + SCM new_securities; SCM ticker_map; 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->acct_display_info); scm_gc_unprotect_object(window->acct_map_info); - scm_gc_unprotect_object(window->stock_hash); - scm_gc_unprotect_object(window->new_stocks); + scm_gc_unprotect_object(window->security_hash); + 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->imported_account_tree); scm_gc_unprotect_object(window->match_transactions); @@ -240,7 +242,7 @@ get_next_druid_page(QIFImportWindow * wind, GnomeDruidPage * page) next = current->next; while (!next || (!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"))) { if(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. */ while (!prev || (!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"))) { /* We're either out of pages for this stage, or we've reached * 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); break; case 2: - if(wind->new_stocks != SCM_BOOL_F) { + if(wind->new_securities != SCM_BOOL_F) { prev = g_list_last(wind->commodity_pages); } 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 * returned by gnc_commodity_table_insert? */ 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->cat_map_info, wind->memo_map_info, - wind->stock_hash, + wind->security_hash, scm_makfrom0str(currname), window), SCM_EOL); @@ -1546,26 +1548,27 @@ static gboolean gnc_ui_qif_import_new_securities(QIFImportWindow * wind) { 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. */ - 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); if (updates != SCM_BOOL_F) { /* A list of new QIF securities was returned. Save it. */ - scm_gc_unprotect_object(wind->new_stocks); - if (wind->new_stocks != SCM_BOOL_F) + scm_gc_unprotect_object(wind->new_securities); + if (wind->new_securities != SCM_BOOL_F) /* 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 - wind->new_stocks = updates; - scm_gc_protect_object(wind->new_stocks); + wind->new_securities = updates; + scm_gc_protect_object(wind->new_securities); return TRUE; } - if (wind->new_stocks != SCM_BOOL_F) + if (wind->new_securities != SCM_BOOL_F) return TRUE; 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); 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 */ 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 - * build a mapping of QIF stock name to a gnc_commodity + * build a mapping of QIF security name to gnc_commodity ********************************************************************/ static void @@ -1739,7 +1742,7 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page, QIFImportWindow * wind = user_data; SCM hash_ref = scm_c_eval_string("hash-ref"); - SCM stocks; + SCM securities; SCM comm_ptr_token; GList * current; @@ -1748,7 +1751,7 @@ gnc_ui_qif_import_commodity_prepare_cb(GnomeDruidPage * page, QIFDruidPage * new_page; /* 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!"); 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. */ gnc_set_busy_cursor(NULL, TRUE); - stocks = wind->new_stocks; + securities = wind->new_securities; current = wind->commodity_pages; - while (!SCM_NULLP(stocks) && (stocks != SCM_BOOL_F)) + while (!SCM_NULLP(securities) && (securities != SCM_BOOL_F)) { 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. */ comm_ptr_token = scm_call_2(hash_ref, - wind->stock_hash, - SCM_CAR(stocks)); + wind->security_hash, + SCM_CAR(securities)); #define FUNC_NAME "make_qif_druid_page" commodity = SWIG_MustGetPtr(comm_ptr_token, 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); } - stocks = SCM_CDR(stocks); + securities = SCM_CDR(securities); } gnc_unset_busy_cursor(NULL); @@ -2086,8 +2089,9 @@ gnc_ui_qif_import_finish_cb(GnomeDruidPage * gpage, /* Save the user's mapping preferences. */ scm_apply(save_map_prefs, - SCM_LIST4(wind->acct_map_info, wind->cat_map_info, - wind->memo_map_info, wind->stock_hash), + SCM_LIST5(wind->acct_map_info, wind->cat_map_info, + wind->memo_map_info, wind->security_hash, + wind->security_prefs), SCM_EOL); /* 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->memo_display_info = SCM_BOOL_F; retval->memo_map_info = SCM_BOOL_F; - retval->stock_hash = SCM_BOOL_F; - retval->new_stocks = SCM_BOOL_F; + retval->security_hash = SCM_BOOL_F; + retval->new_securities = SCM_BOOL_F; retval->ticker_map = SCM_BOOL_F; retval->imported_account_tree = 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->cat_map_info = scm_list_ref(mapping_info, scm_int2num(2)); 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"); 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->acct_display_info); scm_gc_protect_object(retval->acct_map_info); - scm_gc_protect_object(retval->stock_hash); - scm_gc_protect_object(retval->new_stocks); + scm_gc_protect_object(retval->security_hash); + 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->imported_account_tree); scm_gc_protect_object(retval->match_transactions); diff --git a/src/import-export/qif-import/qif-dialog-utils.scm b/src/import-export/qif-import/qif-dialog-utils.scm index c557ddab51..4c80d8273f 100644 --- a/src/import-export/qif-import/qif-dialog-utils.scm +++ b/src/import-export/qif-import/qif-dialog-utils.scm @@ -1,9 +1,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; qif-dialog-utils.scm -;;; build qif->gnc account maps and put them in a displayable -;;; form. +;;; build qif->gnc account maps and put them in a displayable +;;; form. ;;; -;;; Bill Gribble 20 Feb 2000 +;;; Bill Gribble 20 Feb 2000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (default-stock-acct brokerage security) @@ -14,15 +14,15 @@ brokerage (gnc-get-account-separator-string) security)) -(define (default-interest-acct brokerage security) +(define (default-interest-acct brokerage security) (string-append (_ "Interest") (gnc-get-account-separator-string) brokerage - (if (string=? security "") - "" - (string-append (gnc-get-account-separator-string) - security)))) + (if (string=? security "") + "" + (string-append (gnc-get-account-separator-string) + security)))) -(define (default-capital-return-acct brokerage security) +(define (default-capital-return-acct brokerage security) (string-append (_ "Cap Return") (gnc-get-account-separator-string) brokerage (gnc-get-account-separator-string) security)) @@ -44,13 +44,13 @@ (define (default-equity-holding security) (_ "Retained Earnings")) -(define (default-equity-account) (_ "Retained Earnings")) +(define (default-equity-account) (_ "Retained Earnings")) -(define (default-commission-acct brokerage) +(define (default-commission-acct brokerage) (string-append (_ "Commissions") (gnc-get-account-separator-string) brokerage)) -(define (default-margin-interest-acct brokerage) +(define (default-margin-interest-acct brokerage) (string-append (_ "Margin Interest") (gnc-get-account-separator-string) brokerage)) @@ -59,7 +59,7 @@ (define (qif-import:gnc-account-exists map-entry acct-list) (let ((retval #f)) - (for-each + (for-each (lambda (acct) (if (string=? (qif-map-entry:gnc-name map-entry) (cadr acct)) @@ -73,16 +73,16 @@ ;; xtns with that account name, and column 3 is the guess for the ;; translation. Sorted on # transactions, then alpha. -(define (qif-dialog:make-account-display qif-files acct-hash gnc-acct-info) +(define (qif-dialog:make-account-display qif-files acct-hash gnc-acct-info) ;; first, clear the "display" flags in the acct-hash and set up the ;; new-file? flags. If there's nothing to show any more, don't. - (hash-fold + (hash-fold (lambda (k v p) (qif-map-entry:set-display?! v #f) #f) #f acct-hash) - (let ((retval '())) + (let ((retval '())) ;; we want to make two passes here. The first pass picks the ;; explicit Account descriptions out of each file. These are the ;; best sources of info because we will have types and so on for @@ -91,31 +91,31 @@ ;; we'll have most of the accounts already located by that point. ;; Otherwise, we have to guess them. - ;; acct-hash hashes the qif name to a object. + ;; acct-hash hashes the qif name to a object. ;; guess-acct returns one. - (for-each + (for-each (lambda (file) - ;; first, get the explicit account references. - (for-each + ;; first, get the explicit account references. + (for-each (lambda (acct) (let ((entry (hash-ref acct-hash (qif-acct:name acct)))) (if (not entry) - (set! entry - (qif-import:guess-acct (qif-acct:name acct) + (set! entry + (qif-import:guess-acct (qif-acct:name acct) (qif-acct:type acct) gnc-acct-info))) (qif-map-entry:set-description! entry (qif-acct:description acct)) (hash-set! acct-hash (qif-acct:name acct) entry))) (qif-file:accounts file))) qif-files) - - ;; now make the second pass through the files, looking at the + + ;; now make the second pass through the files, looking at the ;; transactions. Hopefully the accounts are all there already. ;; stock accounts can have both a category/account and another - ;; account ref from the security name. - (for-each + ;; account ref from the security name. + (for-each (lambda (file) - (for-each + (for-each (lambda (xtn) (let ((stock-acct (qif-xtn:security-name xtn)) (action (qif-xtn:action xtn)) @@ -123,7 +123,7 @@ (qif-account #f) (qif-account-types #f) (entry #f)) - + (if (and stock-acct action) ;; stock transactions are weird. there can be several ;; accounts associated with stock xtns: the security, @@ -133,16 +133,16 @@ ;; in the map. (begin ;; first: figure out what the near-end account is. - ;; it's generally the security account, but could be + ;; it's generally the security account, but could be ;; an interest, dividend, or CG account. (case action - ((buy buyx sell sellx reinvint reinvdiv reinvsh reinvsg + ((buy buyx sell sellx reinvint reinvdiv reinvsh reinvsg reinvlg reinvmd shrsin shrsout stksplit) - (set! qif-account + (set! qif-account (default-stock-acct from-acct stock-acct)) - (set! qif-account-types (list GNC-STOCK-TYPE + (set! qif-account-types (list GNC-STOCK-TYPE GNC-MUTUAL-TYPE))) - ((div cgshort cgmid cglong intinc miscinc miscexp + ((div cgshort cgmid cglong intinc miscinc miscexp margint rtrncap xin xout) (set! qif-account from-acct) (set! qif-account-types (list GNC-BANK-TYPE @@ -150,10 +150,10 @@ GNC-CASH-TYPE GNC-ASSET-TYPE GNC-LIABILITY-TYPE))) - + ((divx cgshortx cgmidx cglongx intincx margintx rtrncapx) - (set! qif-account - (qif-split:category + (set! qif-account + (qif-split:category (car (qif-xtn:splits xtn)))) (set! qif-account-types (list GNC-BANK-TYPE GNC-CCARD-TYPE @@ -161,40 +161,40 @@ GNC-ASSET-TYPE GNC-LIABILITY-TYPE))) ((miscincx miscexpx) - (set! qif-account - (qif-split:miscx-category + (set! qif-account + (qif-split:miscx-category (car (qif-xtn:splits xtn)))) (set! qif-account-types (list GNC-BANK-TYPE GNC-CCARD-TYPE GNC-CASH-TYPE GNC-ASSET-TYPE GNC-LIABILITY-TYPE)))) - - ;; now reference the near-end account + + ;; now reference the near-end account (if qif-account (begin (set! entry (hash-ref acct-hash qif-account)) (if (not entry) - (set! entry + (set! entry (qif-import:guess-acct qif-account qif-account-types gnc-acct-info))) (qif-map-entry:set-display?! entry #t) (hash-set! acct-hash qif-account entry))) - + ;; now figure out the other end of the transaction. ;; the far end will be the brokerage for buy, sell, ;; etc, or the "L"-referenced account for buyx, ;; sellx, etc, or an equity account for ShrsIn/ShrsOut - - ;; miscintx and miscexpx are very, very "special" - ;; cases ... I'm not sure this is right. + + ;; miscintx and miscexpx are very, very "special" + ;; cases ... I'm not sure this is right. ;; the L line looks like : ;; LCategory/class [Account]/class - ;; so I assume near-acct is Account and far acct - ;; is Category. This matches the intincx/divx + ;; so I assume near-acct is Account and far acct + ;; is Category. This matches the intincx/divx ;; behavior. - + (set! qif-account #f) (case action ((buy sell) @@ -205,19 +205,19 @@ GNC-ASSET-TYPE GNC-LIABILITY-TYPE))) ((buyx sellx xin xout) - (set! qif-account - (qif-split:category + (set! qif-account + (qif-split:category (car (qif-xtn:splits xtn)))) (set! qif-account-types (list GNC-BANK-TYPE GNC-CCARD-TYPE GNC-CASH-TYPE GNC-ASSET-TYPE GNC-LIABILITY-TYPE))) - + ((stksplit) - (set! qif-account + (set! qif-account (default-stock-acct from-acct stock-acct)) - (set! qif-account-types (list GNC-STOCK-TYPE + (set! qif-account-types (list GNC-STOCK-TYPE GNC-MUTUAL-TYPE GNC-ASSET-TYPE GNC-LIABILITY-TYPE))) @@ -225,27 +225,27 @@ (set! qif-account (default-cgshort-acct from-acct stock-acct)) (set! qif-account-types (list GNC-INCOME-TYPE))) - + ((cgmid cgmidx reinvmd) (set! qif-account (default-cgmid-acct from-acct stock-acct)) (set! qif-account-types (list GNC-INCOME-TYPE))) - + ((cglong cglongx reinvlg) (set! qif-account (default-cglong-acct from-acct stock-acct)) (set! qif-account-types (list GNC-INCOME-TYPE))) - + ((intinc intincx reinvint) (set! qif-account (default-interest-acct from-acct stock-acct)) (set! qif-account-types (list GNC-INCOME-TYPE))) - + ((div divx reinvdiv) (set! qif-account (default-dividend-acct from-acct stock-acct)) (set! qif-account-types (list GNC-INCOME-TYPE))) - + ((rtrncap rtrncapx) (set! qif-account (default-capital-return-acct from-acct stock-acct)) @@ -260,14 +260,14 @@ (set! qif-account (default-margin-interest-acct from-acct)) (set! qif-account-types (list GNC-EXPENSE-TYPE))) - + ((miscinc miscexp miscincx miscexpx) - ;; these reference a category on the other end + ;; these reference a category on the other end (set! qif-account #f))) - - ;; now reference the far-end account - (if qif-account - (begin + + ;; now reference the far-end account + (if qif-account + (begin (set! entry (hash-ref acct-hash qif-account)) (if (not entry) (set! entry (qif-import:guess-acct @@ -276,23 +276,23 @@ (qif-map-entry:set-display?! entry #t) (hash-set! acct-hash qif-account entry))) - ;; if there's a commission, reference the + ;; if there's a commission, reference the ;; commission account - (if (qif-xtn:commission xtn) - (begin - (set! qif-account + (if (qif-xtn:commission xtn) + (begin + (set! qif-account (default-commission-acct from-acct)) - (set! entry + (set! entry (hash-ref acct-hash qif-account)) (if (not entry) - (set! entry - (qif-import:guess-acct - qif-account + (set! entry + (qif-import:guess-acct + qif-account (list GNC-EXPENSE-TYPE) gnc-acct-info))) (qif-map-entry:set-display?! entry #t) (hash-set! acct-hash qif-account entry)))) - + ;; non-stock transactions. these are a bit easier. ;; the near-end account (from) is always in the ;; transaction, and the far end(s) are in the splits. @@ -300,8 +300,8 @@ (set! entry (hash-ref acct-hash from-acct)) (if (not entry) (set! entry (qif-import:guess-acct - from-acct - (list + from-acct + (list GNC-BANK-TYPE GNC-CCARD-TYPE GNC-CASH-TYPE @@ -310,22 +310,22 @@ gnc-acct-info))) (qif-map-entry:set-display?! entry #t) (hash-set! acct-hash from-acct entry) - - ;; iterate over the splits doing the same thing. - (for-each + + ;; iterate over the splits doing the same thing. + (for-each (lambda (split) (let ((xtn-is-acct (qif-split:category-is-account? split)) (xtn-acct #f) (entry #f)) - (if xtn-is-acct - (begin + (if xtn-is-acct + (begin (set! xtn-acct (qif-split:category split)) (set! entry (hash-ref acct-hash xtn-acct)) (if (not entry) - (set! entry + (set! entry (qif-import:guess-acct - xtn-acct - (list + xtn-acct + (list GNC-BANK-TYPE GNC-CCARD-TYPE GNC-CASH-TYPE @@ -337,35 +337,35 @@ (qif-xtn:splits xtn)))))) (qif-file:xtns file))) qif-files) - - ;; now that the hash table is filled, make the display list - (hash-fold + + ;; now that the hash table is filled, make the display list + (hash-fold (lambda (k v p) (if (qif-map-entry:display? v) (begin - (qif-map-entry:set-new-acct?! + (qif-map-entry:set-new-acct?! v (not (qif-import:gnc-account-exists v gnc-acct-info))) (set! retval (cons v retval)))) #f) #f acct-hash) - - ;; sort by number of transactions with that account so the + + ;; sort by number of transactions with that account so the ;; most important are at the top - (set! retval - (sort retval + (set! retval + (sort retval (lambda (a b) (stringlist hash-table)) retval)) -(define (qif-import:fix-from-acct qif-file new-acct-name) - (for-each +(define (qif-import:fix-from-acct qif-file new-acct-name) + (for-each (lambda (xtn) (if (not (qif-xtn:from-acct xtn)) (qif-xtn:set-from-acct! xtn new-acct-name))) @@ -610,68 +610,66 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; qif-import:update-stock-hash +;; qif-import:update-security-hash ;; -;; make new commodities for each new stock in acct-hash that isn't -;; already in stock-hash. Return a list of the QIF names of the -;; new stocks or #f if none. +;; Make new commodities for each new security in acct-hash +;; that isn't already in security-hash. Return a list of +;; 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 '())) - (hash-fold + (hash-fold (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 - ;; the stock-hash? - (if (and - stock-name + ;; the security-hash? + (if (and + security-name (qif-map-entry:display? map-entry) - (or (memv GNC-STOCK-TYPE + (or (memv GNC-STOCK-TYPE (qif-map-entry:allowed-types map-entry)) - (memv GNC-MUTUAL-TYPE + (memv GNC-MUTUAL-TYPE (qif-map-entry:allowed-types map-entry))) - (not (hash-ref stock-hash stock-name))) - (let* ((separator (string-ref (gnc-get-account-separator-string) 0)) - (existing-gnc-acct - (gnc-account-lookup-by-full-name + (not (hash-ref security-hash security-name))) + (let ((existing-gnc-acct + (gnc-account-lookup-by-full-name (gnc-get-current-root-account) (qif-map-entry:gnc-name map-entry))) - (book (gnc-account-get-book (gnc-get-current-root-account))) - (existing-type - (xaccAccountGetType existing-gnc-acct))) - (if (and (not (null? existing-gnc-acct)) - (memv existing-type (list GNC-STOCK-TYPE - GNC-MUTUAL-TYPE))) - ;; gnc account already exists... we *know* what the - ;; security is supposed to be - (let ((commodity + (book (gnc-account-get-book (gnc-get-current-root-account)))) + (if (and (not (null? existing-gnc-acct)) + (memv (xaccAccountGetType existing-gnc-acct) + (list GNC-STOCK-TYPE GNC-MUTUAL-TYPE))) + ;; gnc account already exists... we *know* what the + ;; security is supposed to be + (let ((commodity (xaccAccountGetCommodity existing-gnc-acct))) - (hash-set! stock-hash stock-name commodity)) - - ;; we know nothing about this security.. we need to + (hash-set! security-hash security-name commodity)) + + ;; we know nothing about this security.. we need to ;; ask about it (let ((ticker-symbol (qif-ticker-map:lookup-ticker ticker-map - stock-name)) + security-name)) (namespace GNC_COMMODITY_NS_MUTUAL)) (if (not ticker-symbol) - (set! ticker-symbol stock-name) + (set! ticker-symbol security-name) (set! namespace (qif-dialog:default-namespace ticker-symbol))) - (set! names (cons stock-name names)) - (hash-set! - stock-hash stock-name - (gnc-commodity-new book - stock-name - namespace - ticker-symbol - "" - 100000)))))) + (set! names (cons security-name names)) + (hash-set! security-hash + security-name + (gnc-commodity-new book + security-name + namespace + ticker-symbol + "" + 100000)))))) #f)) #f acct-hash) - + (if (not (null? names)) (sort names string value) - (if (and value #t) - (set! table - (cons (list key - (gnc-commodity-get-namespace value) - (gnc-commodity-get-mnemonic value)) - table)) - (gnc:warn "qif-import:write-commodities:" - " something funny in hash table.")) - #f) #f hashtab) + (lambda (key value p) + ;;FIXME: we used to type-check the values, like: + ;; (gw:wcp-is-of-type? value) + (if (and value #t) + (set! table (cons (list key + (gnc-commodity-get-namespace value) + (gnc-commodity-get-mnemonic value)) + table)) + (gnc:warn "qif-import:write-securities:" + " something funny in hash table.")) + #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))) @@ -233,7 +259,8 @@ ;; 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"))) ;; does the file exist? if not, create it; in either case, ;; make sure it's a directory and we have write and execute @@ -241,26 +268,31 @@ (with-output-to-file pref-filename (lambda () (display ";;; qif-accounts-map\n") - (display ";;; automatically generated by GNUcash. DO NOT EDIT\n") - (display ";;; (unless you really, really want to).\n") + (display ";;; Automatically generated by GnuCash. DO NOT EDIT.\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) (newline) - (display ";;; map from QIF categories to GNC accounts") (newline) + (display ";;; Map QIF categories to GnuCash accounts") + (newline) (qif-import:write-map cat-map) (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) (newline) - (display ";;; map from QIF stock name to GNC commodity") (newline) - (qif-import:write-commodities stock-map) + (display ";;; Map QIF security names to GnuCash commodities") + (newline) + (qif-import:write-securities security-map security-prefs) (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)) (newline))))) diff --git a/src/import-export/qif-import/qif-import.scm b/src/import-export/qif-import/qif-import.scm index 37dc2f9b31..c0cdf7f325 100644 --- a/src/import-export/qif-import/qif-import.scm +++ b/src/import-export/qif-import/qif-import.scm @@ -1,8 +1,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; qif-import.scm -;;; virtual loader for QIF import facility +;;; virtual loader for QIF import facility ;;; -;;; Bill Gribble 20 Feb 2000 +;;; Bill Gribble 20 Feb 2000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-module (gnucash import-export qif-import)) @@ -24,14 +24,14 @@ (gnc:module-load "gnucash/app-utils" 0) (gnc:module-load "gnucash/gnome-utils" 0) -(load-from-path "qif-import/qif-objects.scm") ;; class definitions +(load-from-path "qif-import/qif-objects.scm") ;; class definitions (load-from-path "qif-import/qif-parse.scm") ;; string-to-value -(load-from-path "qif-import/qif-utils.scm") -(load-from-path "qif-import/qif-file.scm") ;; actual file reading -(load-from-path "qif-import/qif-dialog-utils.scm") ;; build displays +(load-from-path "qif-import/qif-utils.scm") +(load-from-path "qif-import/qif-file.scm") ;; actual file reading +(load-from-path "qif-import/qif-dialog-utils.scm") ;; build displays (load-from-path "qif-import/qif-guess-map.scm") ;; build acct mappings -(load-from-path "qif-import/qif-to-gnc.scm") ;; conv QIF xtns to GNC -(load-from-path "qif-import/qif-merge-groups.scm") ;; merge into user's acct +(load-from-path "qif-import/qif-to-gnc.scm") ;; conv QIF xtns to GNC +(load-from-path "qif-import/qif-merge-groups.scm") ;; merge into user's acct (export make-qif-file) (export make-ticker-map) @@ -39,7 +39,7 @@ (export qif-import:get-all-accts) (export qif-import:fix-from-acct) (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:save-map-prefs) (export qif-import:load-map-prefs)