2024-02-05 15:50:59 -06:00
|
|
|
|
;; Copyright © 2024 Jaidyn Ann <jadedctrl@posteo.at>
|
2024-02-04 20:42:34 -06:00
|
|
|
|
;;
|
|
|
|
|
;; This program is free software: you can redistribute it and/or
|
|
|
|
|
;; modify it under the terms of the GNU General Public License as
|
|
|
|
|
;; published by the Free Software Foundation, either version 3 of
|
|
|
|
|
;; the License, or (at your option) any later version.
|
|
|
|
|
;;
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
;;
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2024-02-08 12:00:06 -06:00
|
|
|
|
(import scheme
|
|
|
|
|
(chicken base)
|
|
|
|
|
(chicken file)
|
|
|
|
|
(chicken io)
|
|
|
|
|
(chicken repl)
|
2024-02-05 18:10:17 -06:00
|
|
|
|
(chicken repl)
|
2024-02-04 21:47:56 -06:00
|
|
|
|
(chicken string)
|
2024-02-05 18:10:17 -06:00
|
|
|
|
(chicken time)
|
2024-02-08 12:00:06 -06:00
|
|
|
|
srfi-1
|
2024-02-05 18:10:17 -06:00
|
|
|
|
srfi-18
|
|
|
|
|
nrepl
|
2024-02-08 12:00:06 -06:00
|
|
|
|
qt-light
|
|
|
|
|
(prefix uri-common uri:)
|
|
|
|
|
(prefix vcarded vcard:))
|
2024-02-04 20:42:34 -06:00
|
|
|
|
|
|
|
|
|
|
2024-02-05 18:10:17 -06:00
|
|
|
|
(define qt-app #f) ;; The <qt-application> object.
|
|
|
|
|
(define qt-win #f) ;; The <qt-window> object.
|
|
|
|
|
|
|
|
|
|
|
2024-02-04 20:42:34 -06:00
|
|
|
|
;; Start & run the application.
|
|
|
|
|
(define (init)
|
2024-02-05 18:10:17 -06:00
|
|
|
|
;; Set up some global state, prepare the QT app.
|
|
|
|
|
(set! qt-app (qt:init))
|
|
|
|
|
(set! qt-win (create-window))
|
|
|
|
|
(init-window qt-win)
|
|
|
|
|
|
|
|
|
|
(let ;; Start QT loop.
|
|
|
|
|
[(qt-thread (thread-start! qt-loop))
|
|
|
|
|
;; Kick off the remote-REPL…
|
|
|
|
|
(nrepl-thread (thread-start! (lambda () (nrepl 1234))))]
|
|
|
|
|
;; … and also provide a local REPL.
|
|
|
|
|
(repl)
|
|
|
|
|
;; Wait for the QT program, even after stdin is closed off.
|
|
|
|
|
(thread-join! qt-thread)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Loop through QT’s processing, again and again.
|
|
|
|
|
(define (qt-loop)
|
|
|
|
|
(qt:run #t)
|
|
|
|
|
(qt-loop))
|
2024-02-04 20:42:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Create the application window.
|
|
|
|
|
(define (create-window)
|
|
|
|
|
(qt:widget (window-contents)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Return the UI’s XML, read from “contacts.ui”.
|
|
|
|
|
;; We could generate this XML ourselves, and write a nice s-expr front-end,
|
|
|
|
|
;; maybe… `o`
|
|
|
|
|
(define (window-contents)
|
|
|
|
|
(call-with-input-file
|
|
|
|
|
"contact.ui"
|
|
|
|
|
(lambda (in-port) (read-string #f in-port))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Initialize the window.
|
|
|
|
|
(define (init-window window)
|
2024-02-04 20:54:58 -06:00
|
|
|
|
(window-callbacks window)
|
2024-02-04 20:42:34 -06:00
|
|
|
|
(qt:show window))
|
|
|
|
|
|
|
|
|
|
|
2024-02-04 20:54:58 -06:00
|
|
|
|
;; Connect callback functions to widgets’ signals.
|
|
|
|
|
(define (window-callbacks window)
|
2024-02-08 12:00:06 -06:00
|
|
|
|
(menubar-callbacks window))
|
2024-02-04 22:00:06 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Connect callback functions to menubar items.
|
|
|
|
|
(define (menubar-callbacks window)
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(let* [(menu-file-exit (qt:find window "actionQuit"))
|
2024-02-08 12:00:06 -06:00
|
|
|
|
(menu-file-save (qt:find window "actionSave"))
|
|
|
|
|
(menu-file-open (qt:find window "actionOpen"))]
|
2024-02-04 21:47:56 -06:00
|
|
|
|
;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(if menu-file-exit
|
2024-02-04 20:54:58 -06:00
|
|
|
|
(qt:connect
|
2024-02-05 15:50:59 -06:00
|
|
|
|
menu-file-exit "triggered()"
|
2024-02-04 22:00:06 -06:00
|
|
|
|
(qt:receiver exit)))
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(if menu-file-save
|
2024-02-04 22:00:06 -06:00
|
|
|
|
(qt:connect
|
2024-02-05 15:50:59 -06:00
|
|
|
|
menu-file-save "triggered()"
|
2024-02-04 22:00:06 -06:00
|
|
|
|
(qt:receiver
|
|
|
|
|
(lambda ()
|
2024-02-08 12:00:06 -06:00
|
|
|
|
(qt:message "Saving is not implemented.")))))
|
|
|
|
|
(if menu-file-open
|
|
|
|
|
(qt:connect
|
|
|
|
|
menu-file-open "triggered()"
|
|
|
|
|
(qt:receiver
|
|
|
|
|
(lambda ()
|
|
|
|
|
(open-vcard-file
|
|
|
|
|
window
|
|
|
|
|
(qt:get-open-filename "birdo" "/home/jaidyn/Contacts"))))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Parse a vCard file and populate the window’s forms with its contents.
|
|
|
|
|
(define (open-vcard-file window file)
|
|
|
|
|
(if (and (file-exists? file)
|
|
|
|
|
(file-readable? file))
|
|
|
|
|
(thread-start! (lambda () (populate-with-vcard
|
|
|
|
|
window
|
|
|
|
|
(with-input-from-file file
|
|
|
|
|
vcard:read-vcard))))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Simply map vCard property-names to their corresponding name in the window’s
|
|
|
|
|
;; fields.
|
|
|
|
|
(define property->formname-alist
|
|
|
|
|
'((FN . "name")
|
|
|
|
|
(ADR . "address")
|
|
|
|
|
(TEL . "homePhone")
|
|
|
|
|
(TEL . "workPhone")
|
|
|
|
|
(EMAIL . "eMail")
|
|
|
|
|
(URL . "url")
|
|
|
|
|
(NICKNAME . "nickname")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Given a parsed vCard in vcarded’s alist format, populate the window’s fields.
|
|
|
|
|
;; Here’s the format:
|
|
|
|
|
;; ((PROPERTY (ATTRIBUTES) VALUE)
|
|
|
|
|
;; (FN () "A. Dmytryshyn")
|
|
|
|
|
;; (ADR ("TYPE=home") ("" "" "1234 Abc.", "", "", "", "")))
|
|
|
|
|
(define (populate-with-vcard window vcard-alist)
|
|
|
|
|
(map (lambda (property)
|
|
|
|
|
(print property)
|
|
|
|
|
(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)))))
|
|
|
|
|
vcard-alist))
|
2024-02-04 20:54:58 -06:00
|
|
|
|
|
|
|
|
|
|
2024-02-04 20:42:34 -06:00
|
|
|
|
(init)
|