Bug #548891: QIF Import: Prevent crashing when the mapping preferences can't be saved.

BP


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17477 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Charles Day 2008-08-21 17:47:10 +00:00
parent a8820e769b
commit fd987c0b3d
2 changed files with 48 additions and 37 deletions

View File

@ -3000,6 +3000,7 @@ gnc_ui_qif_import_finish_cb(GnomeDruidPage * gpage,
SCM save_map_prefs = scm_c_eval_string("qif-import:save-map-prefs"); SCM save_map_prefs = scm_c_eval_string("qif-import:save-map-prefs");
SCM cat_and_merge = scm_c_eval_string("gnc:account-tree-catenate-and-merge"); SCM cat_and_merge = scm_c_eval_string("gnc:account-tree-catenate-and-merge");
SCM prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions"); SCM prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
SCM scm_result;
QIFImportWindow * wind = user_data; QIFImportWindow * wind = user_data;
GncPluginPage *page; GncPluginPage *page;
@ -3020,11 +3021,14 @@ gnc_ui_qif_import_finish_cb(GnomeDruidPage * gpage,
gnc_resume_gui_refresh(); gnc_resume_gui_refresh();
/* Save the user's mapping preferences. */ /* Save the user's mapping preferences. */
scm_apply(save_map_prefs, scm_result = scm_apply(save_map_prefs,
SCM_LIST5(wind->acct_map_info, wind->cat_map_info, SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
wind->memo_map_info, wind->security_hash, wind->memo_map_info, wind->security_hash,
wind->security_prefs), wind->security_prefs),
SCM_EOL); SCM_EOL);
if (scm_result == SCM_BOOL_F)
gnc_warning_dialog(wind->window,
_("GnuCash was unable to save your mapping preferences."));
/* 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. */
gnc_main_window_foreach_page(gnc_ui_qif_import_check_acct_tree, gnc_main_window_foreach_page(gnc_ui_qif_import_check_acct_tree,

View File

@ -265,20 +265,23 @@
;; file. This only gets called when the user clicks the Apply ;; file. This only gets called when the user clicks the Apply
;; button in the druid, so any new mappings will be lost if the ;; button in the druid, so any new mappings will be lost if the
;; user cancels the import instead. ;; user cancels the import instead.
;;
;; Returns #t upon success or #f on failure.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:save-map-prefs acct-map cat-map memo-map (define (qif-import:save-map-prefs acct-map cat-map memo-map
security-map security-prefs) 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
;; permission.
(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")
;; This procedure does all the work. We'll define it, then call it safely.
(define (private-save)
(with-output-to-file (gnc-build-dotgnucash-path "qif-accounts-map")
(lambda ()
(display ";;; qif-accounts-map")
(newline)
(display ";;; Automatically generated by GnuCash. DO NOT EDIT.")
(newline)
(display ";;; (Unless you really, really want to.)")
(newline)
(display ";;; Map QIF accounts to GnuCash accounts") (display ";;; Map QIF accounts to GnuCash accounts")
(newline) (newline)
(qif-import:write-map acct-map) (qif-import:write-map acct-map)
@ -302,7 +305,11 @@
(display ";;; GnuCash separator used in these mappings") (display ";;; GnuCash separator used in these mappings")
(newline) (newline)
(write (gnc-get-account-separator-string)) (write (gnc-get-account-separator-string))
(newline))))) (newline)))
#t)
;; Safely save the file.
(gnc:backtrace-if-exception private-save))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;