Error dialogues for invalid/unread vCard files
… instead of just being silent.
This commit is contained in:
parent
bf718e72c4
commit
6100da7744
28
contact.scm
28
contact.scm
|
@ -1,3 +1,5 @@
|
|||
#!/usr/bin/env -S csi -s
|
||||
|
||||
;; Copyright © 2024 Jaidyn Ann <jadedctrl@posteo.at>
|
||||
;;
|
||||
;; This program is free software: you can redistribute it and/or
|
||||
|
@ -62,12 +64,13 @@
|
|||
(define (init-qt cli-args)
|
||||
(set! *qt-app* (qt:init))
|
||||
(set! *qt-win* (create-window))
|
||||
(qt:char-encoding 'utf8)
|
||||
(init-window *qt-win*)
|
||||
;; Kick off the QT thread, then open the cli free-arg vCard file, if provided.
|
||||
;; That is, like `$ contact freeArgFile.vcf`.
|
||||
(let [(qt-thread (thread-start! qt-loop))
|
||||
(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))
|
||||
qt-thread))
|
||||
|
||||
|
@ -210,13 +213,28 @@
|
|||
|
||||
;; Parse a vCard file and populate the window’s forms with its contents.
|
||||
(define (open-vcard-file window file)
|
||||
(when (and (file-exists? file)
|
||||
(file-readable? file))
|
||||
(set! *vcard-pathname* file)
|
||||
(thread-start! (lambda () (populate-with-vcard
|
||||
(thread-start!
|
||||
(lambda ()
|
||||
(condition-case
|
||||
(populate-with-vcard
|
||||
window
|
||||
(with-input-from-file file
|
||||
vcard:read-vcard))))))
|
||||
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
|
||||
|
|
Ŝarĝante…
Reference in New Issue