Error dialogues for invalid/unread vCard files
… instead of just being silent.
This commit is contained in:
parent
bf718e72c4
commit
6100da7744
34
contact.scm
34
contact.scm
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env -S csi -s
|
||||||
|
|
||||||
;; Copyright © 2024 Jaidyn Ann <jadedctrl@posteo.at>
|
;; Copyright © 2024 Jaidyn Ann <jadedctrl@posteo.at>
|
||||||
;;
|
;;
|
||||||
;; This program is free software: you can redistribute it and/or
|
;; This program is free software: you can redistribute it and/or
|
||||||
|
@ -62,12 +64,13 @@
|
||||||
(define (init-qt cli-args)
|
(define (init-qt cli-args)
|
||||||
(set! *qt-app* (qt:init))
|
(set! *qt-app* (qt:init))
|
||||||
(set! *qt-win* (create-window))
|
(set! *qt-win* (create-window))
|
||||||
|
(qt:char-encoding 'utf8)
|
||||||
(init-window *qt-win*)
|
(init-window *qt-win*)
|
||||||
;; Kick off the QT thread, then open the cli free-arg vCard file, if provided.
|
;; Kick off the QT thread, then open the cli free-arg vCard file, if provided.
|
||||||
;; That is, like `$ contact freeArgFile.vcf`.
|
;; That is, like `$ contact freeArgFile.vcf`.
|
||||||
(let [(qt-thread (thread-start! qt-loop))
|
(let [(qt-thread (thread-start! qt-loop))
|
||||||
(last-arg (last-free-arg cli-args))]
|
(last-arg (last-free-arg cli-args))]
|
||||||
(when (and (string? last-arg) (file-exists? last-arg))
|
(when (string? last-arg)
|
||||||
(open-vcard-file *qt-win* last-arg))
|
(open-vcard-file *qt-win* last-arg))
|
||||||
qt-thread))
|
qt-thread))
|
||||||
|
|
||||||
|
@ -210,13 +213,28 @@
|
||||||
|
|
||||||
;; Parse a vCard file and populate the window’s forms with its contents.
|
;; Parse a vCard file and populate the window’s forms with its contents.
|
||||||
(define (open-vcard-file window file)
|
(define (open-vcard-file window file)
|
||||||
(when (and (file-exists? file)
|
(set! *vcard-pathname* file)
|
||||||
(file-readable? file))
|
(thread-start!
|
||||||
(set! *vcard-pathname* file)
|
(lambda ()
|
||||||
(thread-start! (lambda () (populate-with-vcard
|
(condition-case
|
||||||
window
|
(populate-with-vcard
|
||||||
(with-input-from-file file
|
window
|
||||||
vcard:read-vcard))))))
|
(with-input-from-file file
|
||||||
|
vcard:read-vcard))
|
||||||
|
[(vcard)
|
||||||
|
(set! *vcard-pathname* #f)
|
||||||
|
(qt:message
|
||||||
|
(string-join (list "This file doesn’t seem to be a valid vCard file."
|
||||||
|
"Please make sure you selected the right file, and take a look at it manually."))
|
||||||
|
title: "Parsing error" type: 'critical)]
|
||||||
|
[exn (file)
|
||||||
|
(set! *vcard-pathname* #f)
|
||||||
|
(qt:message
|
||||||
|
(string-join (list "Failed to open the file."
|
||||||
|
((condition-property-accessor 'exn 'message) exn)))
|
||||||
|
title: "File error" type: 'critical)]))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; Simply map vCard property-names to their corresponding name in the window’s
|
;; Simply map vCard property-names to their corresponding name in the window’s
|
||||||
|
|
Ŝarĝante…
Reference in New Issue