From 51de5b4df25e382b7f680223d22f50f8b55323d3 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Thu, 15 Feb 2024 00:38:49 -0600 Subject: [PATCH] Set window-title based on current contact-file --- contact.scm | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/contact.scm b/contact.scm index ca41499..65cab24 100755 --- a/contact.scm +++ b/contact.scm @@ -56,10 +56,6 @@ (thread-join! qt-thread)))) -(define (last-free-arg cli-args) - (condition-case (last (car cli-args)) (var () #f))) - - ;; Set up some global variables (for easier live REPL use), prepare the QT app. (define (init-qt cli-args) (set! *qt-app* (qt:init)) @@ -69,9 +65,9 @@ ;; 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 (string? last-arg) - (open-vcard-file *qt-win* last-arg)) + (last-free-arg (condition-case (last (car cli-args)) (var () #f)))] + (when (string? last-free-arg) + (open-vcard-file *qt-win* last-free-arg)) qt-thread)) @@ -140,7 +136,9 @@ (or (qt:theme-icon "person") (qt:theme-icon "contact-new")))] (if default-profile-pic (set! (qt:property (qt:find window "avatarLabel") "pixmap") - (qt:icon->pixmap default-profile-pic 100 100)))) + (qt:icon->pixmap default-profile-pic 100 100)))) + ;; Set the window’s title. + (set-window-title! window "New contact") ;; Now prepare callbacks and show the window. (window-callbacks window) (qt:show window)) @@ -214,6 +212,7 @@ ;; Parse a vCard file and populate the window’s forms with its contents. (define (open-vcard-file window file) (set! *vcard-pathname* file) + (set-window-title! window (pathname-file file)) (thread-start! (lambda () (condition-case @@ -223,12 +222,14 @@ vcard:read-vcard)) [(vcard) (set! *vcard-pathname* #f) + (set-window-title! window "New contact") (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) + (set-window-title! window "New contact") (qt:message (string-join (list "Failed to open the file." ((condition-property-accessor 'exn 'message) exn))) @@ -277,7 +278,15 @@ (if avatar (u8vector->pixmap (cadr (last property))))]] (when avatar (set! (qt:property avatar "pixmap") new-pixmap)))]))) - vcard-alist)) + vcard-alist) + (when (alist-ref 'FN vcard-alist) + (set-window-title! window (last (alist-ref 'FN vcard-alist))))) + + +;; Set a QT window’s title, suffixing with the program name (Contact). +(define (set-window-title! window title) + (set! (qt:property window "windowTitle") + (string-concatenate (list title " - Contact")))) ;; Given a image bytevector (u8vector), create a corresponding pixmap.