From 6100da774477fe29d62e1b7244e462a706deb30a Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 13 Feb 2024 18:02:08 -0600 Subject: [PATCH] Error dialogues for invalid/unread vCard files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … instead of just being silent. --- contact.scm | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/contact.scm b/contact.scm index 4ce57dc..ca41499 100755 --- a/contact.scm +++ b/contact.scm @@ -1,3 +1,5 @@ +#!/usr/bin/env -S csi -s + ;; Copyright © 2024 Jaidyn Ann ;; ;; 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 - window - (with-input-from-file file - vcard:read-vcard)))))) + (set! *vcard-pathname* file) + (thread-start! + (lambda () + (condition-case + (populate-with-vcard + window + (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