diff --git a/contact.scm b/contact.scm index d43f3d6..25c3c78 100755 --- a/contact.scm +++ b/contact.scm @@ -168,11 +168,7 @@ menu-file-save "triggered()" (qt:receiver (lambda () - (call-with-output-file *vcard-pathname* - (lambda (in-port) - (vcard:write-vcard - (populate-vcard-with-window window *vcard-alist*) - in-port))))))) + (save-vcard-file window))))) ;; If they want a new contact, create a new, blank, window. ;; That is, a new process. (if menu-file-new @@ -246,6 +242,26 @@ title: "File error" type: 'critical)])))) +;; Save the window contents to the currently-selected file-path in vCard format. +(define (save-vcard-file window) + (thread-start! + (lambda () + (condition-case + (begin + (set! *vcard-alist* (populate-vcard-with-window window *vcard-alist*)) + (call-with-output-file *vcard-pathname* + (lambda (in-port) + (vcard:write-vcard *vcard-alist* + in-port)))) + [exn () + (qt:message + (string-join (list "Failed to save the file:" + ((condition-property-accessor 'exn 'message) exn) + "Try saving to a another location with “File→Save as…”.") + "\n") + title: "Saving error")])))) + + ;; Simply map vCard property-names to their corresponding name in the window’s ;; fields. (define property->formname-alist