From 3a1b9aa543286b4f1e56f24da232919261cd1a82 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:49:41 -0600 Subject: [PATCH] =?UTF-8?q?Parse=20and=20display=20contacts=E2=80=99=20pro?= =?UTF-8?q?file-photos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contact.scm | 33 ++++++++++++++++++++++++++++++--- contact.ui | 6 ++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/contact.scm b/contact.scm index 83c8e87..0620bd2 100644 --- a/contact.scm +++ b/contact.scm @@ -25,6 +25,7 @@ (chicken string) (chicken time) (srfi 1) + (srfi 4) (srfi 13) (srfi 18) (prefix getopt-long getopt:) @@ -209,7 +210,7 @@ ;; fields. (define property->formname-alist '((FN . "name") - (ADR . "address") +;; (ADR . "address") (TEL . "homePhone") (TEL . "workPhone") (EMAIL . "eMail") @@ -227,9 +228,35 @@ (let* [(formname (alist-ref (car property) property->formname-alist)) (lineEditName (conc formname "LineEdit")) (lineEditWidget (if formname (qt:find window lineEditName) #f))] - (if lineEditWidget - (set! (qt:property lineEditWidget "text") (last property))))) + (cond + [lineEditWidget + (set! (qt:property lineEditWidget "text") (last property))] + [(and (eq? (car property) 'PHOTO) + (list? (last property))) + (let* [(avatar (qt:find window "avatarLabel")) + (old-pixmap (if avatar (qt:property avatar "pixmap"))) + [new-pixmap (if avatar (u8vector->pixmap (cadr (last property))))]] + (when avatar + (set! (qt:property avatar "pixmap") new-pixmap) + (qt:delete old-pixmap)))]))) vcard-alist)) +;; Given a image bytevector (u8vector), create a corresponding pixmap. +(define (u8vector->pixmap vector) + (let* ([temp-file (write-temporary-file vector)] + [pixmap (qt:pixmap temp-file)]) + (delete-file* temp-file) + pixmap)) + + +;; Given a u8vector for file-contents, create a tempory file and write the +;; contents to it. Returns the pathname. +(define (write-temporary-file u8vector-contents) + (let [(temp-file (create-temporary-file))] + (with-output-to-file temp-file + (lambda () (map write-byte (u8vector->list u8vector-contents)))) + temp-file)) + + (init) diff --git a/contact.ui b/contact.ui index 702c94f..595cc8e 100644 --- a/contact.ui +++ b/contact.ui @@ -22,6 +22,12 @@ + + + 100 + 100 + + Profile picture