Compare commits

..

No commits in common. "1dcb30ea7e801e2b283bdf7f1588b20218bae16b" and "bb7816727e6143c8a1d0ff0d03df59e96dfbfe4d" have entirely different histories.

View File

@ -68,7 +68,7 @@
(let [(qt-thread (thread-start! qt-loop)) (let [(qt-thread (thread-start! qt-loop))
(last-free-arg (condition-case (last (car cli-args)) (var () #f)))] (last-free-arg (condition-case (last (car cli-args)) (var () #f)))]
(when (string? last-free-arg) (when (string? last-free-arg)
(open-vcard-file *qt-win* last-free-arg #t)) (open-vcard-file *qt-win* last-free-arg))
qt-thread)) qt-thread))
@ -168,7 +168,11 @@
menu-file-save "triggered()" menu-file-save "triggered()"
(qt:receiver (qt:receiver
(lambda () (lambda ()
(save-vcard-file window))))) (call-with-output-file *vcard-pathname*
(lambda (in-port)
(vcard:write-vcard
(populate-vcard-with-window window *vcard-alist*)
in-port)))))))
;; If they want a new contact, create a new, blank, window. ;; If they want a new contact, create a new, blank, window.
;; That is, a new process. ;; That is, a new process.
(if menu-file-new (if menu-file-new
@ -211,7 +215,7 @@
;; Parse a vCard file and populate the windows forms with its contents. ;; Parse a vCard file and populate the windows forms with its contents.
(define (open-vcard-file window file . exit-on-fail?) (define (open-vcard-file window file)
(set! *vcard-pathname* file) (set! *vcard-pathname* file)
(set-window-title! window (pathname-file file)) (set-window-title! window (pathname-file file))
(thread-start! (thread-start!
@ -227,38 +231,19 @@
(set! *vcard-pathname* #f) (set! *vcard-pathname* #f)
(set! *vcard-alist* #f) (set! *vcard-alist* #f)
(set-window-title! window "New contact") (set-window-title! window "New contact")
(error-message "Parsing error" (qt:message
(string-join (string-join (list "This file doesnt seem to be a valid vCard file."
(list "This file doesnt seem to be a valid vCard file." "Please make sure you selected the right file, and take a look at it manually."))
"Please make sure you selected the right file, and take a look at it manually.") title: "Parsing error" type: 'critical)]
"\n")
#f exit-on-fail?)]
;; … complain harder, harder!! ;; … complain harder, harder!!
[exn (file) [exn (file)
(set! *vcard-pathname* #f) (set! *vcard-pathname* #f)
(set! *vcard-alist* #f) (set! *vcard-alist* #f)
(set-window-title! window "New contact") (set-window-title! window "New contact")
(error-message "File error" (qt:message
"Failed to open the file." (string-join (list "Failed to open the file."
exn exit-on-fail?)])))) ((condition-property-accessor 'exn 'message) exn)))
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 ()
(error-message
"Export error"
"Failed to save the file.\nTry saving to another location with “File→Save as…”."
exn)]))))
;; Simply map vCard property-names to their corresponding name in the windows ;; Simply map vCard property-names to their corresponding name in the windows
@ -331,20 +316,6 @@
vcard-alist) vcard-alist)
;; Display an error-message dialogue, optionally exiting after the user
;; dismisses it.
(define (error-message title description #!optional (exn #f) (exit-after-message? #f))
(let [(exn-message (if exn ((condition-property-accessor 'exn 'message) exn)
#f))]
(qt:message
(if exn-message
(string-concatenate (list description "\n“" exn-message "”"))
description)
title: title
type: 'critical)
(when exit-after-message? (exit))))
;; Set a QT windows title, suffixing with the program name (Contact). ;; Set a QT windows title, suffixing with the program name (Contact).
(define (set-window-title! window title) (define (set-window-title! window title)
(set! (qt:property window "windowTitle") (set! (qt:property window "windowTitle")