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/>.
|
|
|
|
|
|
|
|
|
|
(import (chicken io)
|
2024-02-04 21:47:56 -06:00
|
|
|
|
(chicken string)
|
2024-02-04 20:42:34 -06:00
|
|
|
|
qt-light)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Start & run the application.
|
|
|
|
|
(define (init)
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(let [(qt-app (qt:init))
|
|
|
|
|
(qt-win (create-window))]
|
2024-02-04 20:42:34 -06:00
|
|
|
|
(init-window qt-win)
|
|
|
|
|
(qt:run)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 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-04 22:00:06 -06:00
|
|
|
|
(menubar-callbacks window)
|
|
|
|
|
(textbox-callbacks window))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 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"))
|
|
|
|
|
(menu-file-save (qt:find window "actionSave"))]
|
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-05 15:50:59 -06:00
|
|
|
|
(qt:message "Saving is not implemented.")))))))
|
2024-02-04 21:47:56 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Connect a text-printing callback to each textbox.
|
|
|
|
|
(define (textbox-callbacks window)
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(let* [(property-names
|
|
|
|
|
'("address" "city" "company" "country" "eMail" "fax"
|
2024-02-04 21:47:56 -06:00
|
|
|
|
"homePhone" "name" "nickname" "state" "url"
|
2024-02-05 15:50:59 -06:00
|
|
|
|
"workPhone" "zip"))
|
|
|
|
|
(textboxes
|
2024-02-04 21:47:56 -06:00
|
|
|
|
;; The texbox widgets are all named like “countryLineEdit”.
|
|
|
|
|
(map (lambda (property)
|
|
|
|
|
(qt:find window (conc property "LineEdit")))
|
2024-02-05 15:50:59 -06:00
|
|
|
|
property-names))]
|
2024-02-04 21:47:56 -06:00
|
|
|
|
;; Cycle through each textbox, connecting them to a callback that prints
|
|
|
|
|
;; their contents each time you type in text.
|
|
|
|
|
(map (lambda (textbox)
|
2024-02-04 22:00:06 -06:00
|
|
|
|
;; We connect to https://doc.qt.io/qt-6/qlineedit.html#textChanged
|
|
|
|
|
;; … and print the value of https://doc.qt.io/qt-6/qlineedit.html#text-prop
|
|
|
|
|
;; Also enable the File→Save menu-item (since, y’know, the user
|
|
|
|
|
;; changed something). It defaults to disabled in the contact.ui file.
|
2024-02-04 21:47:56 -06:00
|
|
|
|
(if textbox
|
|
|
|
|
(qt:connect textbox "textChanged(QString)"
|
|
|
|
|
(qt:receiver
|
2024-02-04 22:00:06 -06:00
|
|
|
|
(lambda ()
|
2024-02-05 15:50:59 -06:00
|
|
|
|
(let [(menu-file-save (qt:find window "actionSave"))]
|
|
|
|
|
(if menu-file-save
|
|
|
|
|
(set! (qt:property menu-file-save "enabled") #t)))
|
2024-02-04 22:00:06 -06:00
|
|
|
|
(print (qt:property textbox "text")))))))
|
2024-02-04 21:47:56 -06:00
|
|
|
|
textboxes)))
|
2024-02-04 20:54:58 -06:00
|
|
|
|
|
|
|
|
|
|
2024-02-04 20:42:34 -06:00
|
|
|
|
(init)
|