r17542 - gnucash/branches/2.2/src/import-export/qif-import - [r17477] Bug #548891: QIF Import: Prevent crashing when the mapping preferences can't be saved.
Andreas Köhler
andi5 at cvs.gnucash.org
Wed Sep 17 13:22:12 EDT 2008
Author: andi5
Date: 2008-09-17 13:22:12 -0400 (Wed, 17 Sep 2008)
New Revision: 17542
Trac: http://svn.gnucash.org/trac/changeset/17542
Modified:
gnucash/branches/2.2/src/import-export/qif-import/druid-qif-import.c
gnucash/branches/2.2/src/import-export/qif-import/qif-guess-map.scm
Log:
[r17477] Bug #548891: QIF Import: Prevent crashing when the mapping preferences can't be saved.
Committed by cedayiv.
Modified: gnucash/branches/2.2/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/branches/2.2/src/import-export/qif-import/druid-qif-import.c 2008-09-17 17:22:04 UTC (rev 17541)
+++ gnucash/branches/2.2/src/import-export/qif-import/druid-qif-import.c 2008-09-17 17:22:12 UTC (rev 17542)
@@ -2997,9 +2997,10 @@
gpointer arg1,
gpointer user_data)
{
- 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 prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
+ 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 prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
+ SCM scm_result;
QIFImportWindow * wind = user_data;
GncPluginPage *page;
@@ -3020,11 +3021,14 @@
gnc_resume_gui_refresh();
/* Save the user's mapping preferences. */
- scm_apply(save_map_prefs,
- SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
- wind->memo_map_info, wind->security_hash,
- wind->security_prefs),
- SCM_EOL);
+ scm_result = scm_apply(save_map_prefs,
+ SCM_LIST5(wind->acct_map_info, wind->cat_map_info,
+ wind->memo_map_info, wind->security_hash,
+ wind->security_prefs),
+ 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. */
gnc_main_window_foreach_page(gnc_ui_qif_import_check_acct_tree,
Modified: gnucash/branches/2.2/src/import-export/qif-import/qif-guess-map.scm
===================================================================
--- gnucash/branches/2.2/src/import-export/qif-import/qif-guess-map.scm 2008-09-17 17:22:04 UTC (rev 17541)
+++ gnucash/branches/2.2/src/import-export/qif-import/qif-guess-map.scm 2008-09-17 17:22:12 UTC (rev 17542)
@@ -265,46 +265,53 @@
;; file. This only gets called when the user clicks the Apply
;; button in the druid, so any new mappings will be lost if the
;; 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
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")
- (display ";;; Map QIF accounts to GnuCash accounts")
- (newline)
- (qif-import:write-map acct-map)
- (newline)
+ ;; 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")
+ (newline)
+ (qif-import:write-map acct-map)
+ (newline)
- (display ";;; Map QIF categories to GnuCash accounts")
- (newline)
- (qif-import:write-map cat-map)
- (newline)
+ (display ";;; Map QIF categories to GnuCash accounts")
+ (newline)
+ (qif-import:write-map cat-map)
+ (newline)
- (display ";;; Map QIF payee/memo to GnuCash accounts")
- (newline)
- (qif-import:write-map memo-map)
- (newline)
+ (display ";;; Map QIF payee/memo to GnuCash accounts")
+ (newline)
+ (qif-import:write-map memo-map)
+ (newline)
- (display ";;; Map QIF security names to GnuCash commodities")
- (newline)
- (qif-import:write-securities security-map security-prefs)
- (newline)
+ (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)
- (write (gnc-get-account-separator-string))
- (newline)))))
+ (display ";;; GnuCash separator used in these mappings")
+ (newline)
+ (write (gnc-get-account-separator-string))
+ (newline)))
+ #t)
+ ;; Safely save the file.
+ (gnc:backtrace-if-exception private-save))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; here's where we do all the guessing. We really want to find the
;; match in the hash table, but failing that we guess intelligently
More information about the gnucash-changes
mailing list