diff --git a/src/import-export/qif-import/druid-qif-import.c b/src/import-export/qif-import/druid-qif-import.c index 89e75e10f9..be811f4537 100644 --- a/src/import-export/qif-import/druid-qif-import.c +++ b/src/import-export/qif-import/druid-qif-import.c @@ -1456,6 +1456,34 @@ gnc_ui_qif_import_prepare_duplicates(QIFImportWindow * wind) } +/**************************************************************** + * gnc_ui_qif_import_convert_undo + * + * This function launches the Scheme procedure that un-imports + * any imported accounts and transactions. + ****************************************************************/ + +static void +gnc_ui_qif_import_convert_undo(QIFImportWindow * wind) +{ + SCM undo = scm_c_eval_string("qif-import:qif-to-gnc-undo"); + + /* Undo the conversion. */ + scm_call_1(undo, wind->imported_account_tree); + + /* There's no imported account tree any more. */ + scm_gc_unprotect_object(wind->imported_account_tree); + wind->imported_account_tree = SCM_BOOL_F; + scm_gc_protect_object(wind->imported_account_tree); + + + /* Get rid of the list of matched transactions. */ + scm_gc_unprotect_object(wind->match_transactions); + wind->match_transactions = SCM_BOOL_F; + scm_gc_protect_object(wind->match_transactions); +} + + /**************************************************************** * gnc_ui_qif_import_convert * @@ -1503,14 +1531,12 @@ gnc_ui_qif_import_convert(QIFImportWindow * wind) { /* An error occurred during conversion. */ - /* There's no imported account tree. */ - scm_gc_unprotect_object(wind->imported_account_tree); - wind->imported_account_tree = SCM_BOOL_F; - scm_gc_protect_object(wind->imported_account_tree); + /* Remove any converted data. */ + gnc_ui_qif_import_convert_undo(wind); /* We don't know what data structures may have become corrupted, * so we shouldn't allow further action. Display the failure - * page next, and just allow the user to cancel. */ + * page next, and only allow the user to cancel. */ gnome_druid_set_page(GNOME_DRUID(wind->druid), get_named_page(wind, "failed_page")); gnome_druid_set_buttons_sensitive(GNOME_DRUID(wind->druid), @@ -1539,6 +1565,11 @@ gnc_ui_qif_import_convert(QIFImportWindow * wind) if (retval == SCM_BOOL_F) { /* An error occurred during duplicate checking. */ + + /* Remove any converted data. */ + gnc_ui_qif_import_convert_undo(wind); + + /* Display the failure page. */ gnome_druid_set_page(GNOME_DRUID(wind->druid), get_named_page(wind, "failed_page")); gnome_druid_set_buttons_sensitive(GNOME_DRUID(wind->druid), @@ -2148,15 +2179,37 @@ gnc_ui_qif_import_finish_cb(GnomeDruidPage * gpage, gnc_ui_qif_import_druid_destroy(wind); } + +/**************************************************************** + * gnc_ui_qif_import_cancel_cb + * + * Invoked when the "Cancel" button is clicked. + ****************************************************************/ + static void -gnc_ui_qif_import_cancel_cb (GnomeDruid * druid, - gpointer user_data) +gnc_ui_qif_import_cancel_cb(GnomeDruid * druid, gpointer user_data) { - QIFImportWindow * wind = user_data; - + QIFImportWindow *wind = user_data; + GList *pageptr; + GnomeDruidPage *gtkpage; + QIFDruidPage *page; + + /* Remove any converted data. */ + gnc_ui_qif_import_convert_undo(wind); + + /* Remove any commodities created for druid pages. */ + for (pageptr = wind->commodity_pages; pageptr; pageptr=pageptr->next) + { + gtkpage = GNOME_DRUID_PAGE(pageptr->data); + page = g_object_get_data(G_OBJECT(gtkpage), "page_struct"); + gnc_commodity_destroy(page->commodity); + } + + /* Destroy the druid. */ gnc_ui_qif_import_druid_destroy(wind); } + SCM gnc_ui_qif_import_druid_get_mappings(QIFImportWindow * w) { diff --git a/src/import-export/qif-import/file-format.txt b/src/import-export/qif-import/file-format.txt index fab9c37c3d..23856c3518 100644 --- a/src/import-export/qif-import/file-format.txt +++ b/src/import-export/qif-import/file-format.txt @@ -264,18 +264,38 @@ the following: QIF N Line Notes ============ ===== +Aktab Same as ShrsOut. +AktSplit Same as StkSplit. +Aktzu Same as ShrsIn. Buy Buy shares. BuyX Buy shares. Used with an L line. Cash Miscellaneous cash transaction. Used with an L line. +CGMid Mid-term capital gains. +CGMidX Mid-term capital gains. For use with an L line. +CGLong Long-term capital gains. +CGLongX Long-term capital gains. For use with an L line. +CGShort Short-term capital gains. +CGShortX Short-term capital gains. For use with an L line. ContribX Same as XIn. Used for tax-advantaged accounts. CvrShrt Buy shares to cover a short sale. +CvrShrtX Buy shares to cover a short sale. Used with an L line. Div Dividend received. DivX Dividend received. For use with an L line. +Errinerg Same as Reminder. Exercise Exercise an option. +ExercisX Exercise an option. For use with an L line. Expire Mark an option as expired. (Uses D, N, Y & M lines) Grant Receive a grant of stock options. +Int Same as IntInc. +IntX Same as IntIncX. IntInc Interest received. IntIncX Interest received. For use with an L line. +K.gewsp Same as CGShort. (German) +K.gewspX Same as CGShortX. (German) +Kapgew Same as CGLong. Kapitalgewinnsteuer.(German) +KapgewX Same as CGLongX. Kapitalgewinnsteuer. (German) +Kauf Same as Buy. (German) +KaufX Same as BuyX. (German) MargInt Margin interest paid. MargIntX Margin interest paid. For use with an L line. MiscExp Miscellaneous expense. @@ -284,6 +304,13 @@ MiscInc Miscellaneous income. MiscIncX Miscellaneous income. For use with an L line. ReinvDiv Reinvested dividend. ReinvInt Reinvested interest. +ReinvLG Reinvested long-term capital gains. +Reinvkur Same as ReinvLG. +Reinvksp Same as ReinvSh. +ReinvMd Reinvested mid-term capital gains. +ReinvSG Same as ReinvSh. +ReinvSh Reinvested short-term capital gains. +Reinvzin Same as ReinvDiv. Reminder Reminder. (Uses D, N, C & M lines) RtrnCap Return of capital. RtrnCapX Return of capital. For use with an L line. @@ -293,9 +320,12 @@ ShtSell Short sale. ShrsIn Deposit shares. ShrsOut Withdraw shares. StkSplit Stock split. +Verkauf Same as Sell. (German) +VerkaufX Same as SellX. (German) +Vest Mark options as vested. (Uses N, Y, Q, C & M lines) +WithDrwX Same as XOut. Used for tax-advantaged accounts. XIn Transfer cash from another account. XOut Transfer cash to another account. -Vest Mark options as vested. (Uses N, Y, Q, C & M lines) Category/Transfer/Class line: ----------------------------- diff --git a/src/import-export/qif-import/qif-import.scm b/src/import-export/qif-import/qif-import.scm index c0cdf7f325..868ee07f42 100644 --- a/src/import-export/qif-import/qif-import.scm +++ b/src/import-export/qif-import/qif-import.scm @@ -35,7 +35,6 @@ (export make-qif-file) (export make-ticker-map) -(export qif-import:qif-to-gnc) (export qif-import:get-all-accts) (export qif-import:fix-from-acct) (export qif-import:any-new-accts?) @@ -43,6 +42,8 @@ (export qif-import:refresh-match-selection) (export qif-import:save-map-prefs) (export qif-import:load-map-prefs) +(export qif-import:qif-to-gnc) +(export qif-import:qif-to-gnc-undo) (export qif-map-entry:gnc-name) (export qif-map-entry:set-gnc-name!) diff --git a/src/import-export/qif-import/qif-to-gnc.scm b/src/import-export/qif-import/qif-to-gnc.scm index f34d8c605f..23a4b9e6ab 100644 --- a/src/import-export/qif-import/qif-to-gnc.scm +++ b/src/import-export/qif-import/qif-to-gnc.scm @@ -197,8 +197,9 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; qif-import:qif-to-gnc -;; this is the top-level of the back end conversion from -;; QIF to GNC. all the account mappings and so on should be +;; +;; This is the top-level of the back end conversion from QIF +;; to GnuCash. All the account mappings and so on should be ;; done before this is called. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -327,7 +328,7 @@ (splitloop (cdr splits)))))) (qif-file:xtns qif-file))) qif-files-list) - + (if (> work-to-do 100) (begin (set! progress-dialog (gnc-progress-dialog-new window #f)) @@ -351,7 +352,7 @@ (qif-import:mark-matching-xtns xtn rest)) (if (not (null? (cdr rest))) (xloop (car rest) (cdr rest))))) - + ;; iterate over files. Going in the sort order by number of ;; transactions should give us a small speed advantage. (for-each @@ -1178,3 +1179,22 @@ (loop (cdr splits))))) (if all-marked (qif-xtn:set-mark! xtn #t)))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; qif-import:qif-to-gnc-undo +;; +;; Cancel the import by removing all newly created accounts, +;; splits, and transactions. +;; +;; NOTE: Any new commodities should be destroyed by the druid. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define (qif-import:qif-to-gnc-undo root) + (if root + (let ((txns (gnc:account-tree-get-transactions root))) + ;; Destroy all the transactions and their splits. + (for-each (lambda (elt) (xaccTransDestroy elt)) txns) + + ;; Destroy the accounts + (xaccAccountBeginEdit root) + (xaccAccountDestroy root))))