Set window-title based on current contact-file

This commit is contained in:
Jaidyn Ann 2024-02-15 00:38:49 -06:00
parent 6100da7744
commit 51de5b4df2

View File

@ -56,10 +56,6 @@
(thread-join! qt-thread)))) (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. ;; Set up some global variables (for easier live REPL use), prepare the QT app.
(define (init-qt cli-args) (define (init-qt cli-args)
(set! *qt-app* (qt:init)) (set! *qt-app* (qt:init))
@ -69,9 +65,9 @@
;; 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-free-arg (condition-case (last (car cli-args)) (var () #f)))]
(when (string? last-arg) (when (string? last-free-arg)
(open-vcard-file *qt-win* last-arg)) (open-vcard-file *qt-win* last-free-arg))
qt-thread)) qt-thread))
@ -141,6 +137,8 @@
(if default-profile-pic (if default-profile-pic
(set! (qt:property (qt:find window "avatarLabel") "pixmap") (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 windows title.
(set-window-title! window "New contact")
;; Now prepare callbacks and show the window. ;; Now prepare callbacks and show the window.
(window-callbacks window) (window-callbacks window)
(qt:show window)) (qt:show window))
@ -214,6 +212,7 @@
;; Parse a vCard file and populate the windows forms with its contents. ;; Parse a vCard file and populate the windows forms with its contents.
(define (open-vcard-file window file) (define (open-vcard-file window file)
(set! *vcard-pathname* file) (set! *vcard-pathname* file)
(set-window-title! window (pathname-file file))
(thread-start! (thread-start!
(lambda () (lambda ()
(condition-case (condition-case
@ -223,12 +222,14 @@
vcard:read-vcard)) vcard:read-vcard))
[(vcard) [(vcard)
(set! *vcard-pathname* #f) (set! *vcard-pathname* #f)
(set-window-title! window "New contact")
(qt:message (qt:message
(string-join (list "This file doesnt seem to be a valid vCard file." (string-join (list "This file doesnt seem to be a valid vCard file."
"Please make sure you selected the right file, and take a look at it manually.")) "Please make sure you selected the right file, and take a look at it manually."))
title: "Parsing error" type: 'critical)] title: "Parsing error" type: 'critical)]
[exn (file) [exn (file)
(set! *vcard-pathname* #f) (set! *vcard-pathname* #f)
(set-window-title! window "New contact")
(qt:message (qt:message
(string-join (list "Failed to open the file." (string-join (list "Failed to open the file."
((condition-property-accessor 'exn 'message) exn))) ((condition-property-accessor 'exn 'message) exn)))
@ -277,7 +278,15 @@
(if avatar (u8vector->pixmap (cadr (last property))))]] (if avatar (u8vector->pixmap (cadr (last property))))]]
(when avatar (when avatar
(set! (qt:property avatar "pixmap") new-pixmap)))]))) (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 windows 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. ;; Given a image bytevector (u8vector), create a corresponding pixmap.