Support base-level opening of vCard files

Fields are filled naively and unreliably; this
just lays the groundwork.
Also removes the old testing callbacks for textboxes.
This commit is contained in:
Jaidyn Ann 2024-02-08 12:00:06 -06:00
parent a06bd33f9d
commit b91590133c
2 changed files with 64 additions and 33 deletions

View File

@ -13,13 +13,20 @@
;; You should have received a copy of the GNU General Public License ;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(import (chicken io) (import scheme
(chicken base)
(chicken file)
(chicken io)
(chicken repl)
(chicken repl) (chicken repl)
(chicken string) (chicken string)
(chicken time) (chicken time)
srfi-1
srfi-18 srfi-18
nrepl nrepl
qt-light) qt-light
(prefix uri-common uri:)
(prefix vcarded vcard:))
(define qt-app #f) ;; The <qt-application> object. (define qt-app #f) ;; The <qt-application> object.
@ -71,14 +78,14 @@
;; Connect callback functions to widgets signals. ;; Connect callback functions to widgets signals.
(define (window-callbacks window) (define (window-callbacks window)
(menubar-callbacks window) (menubar-callbacks window))
(textbox-callbacks window))
;; Connect callback functions to menubar items. ;; Connect callback functions to menubar items.
(define (menubar-callbacks window) (define (menubar-callbacks window)
(let* [(menu-file-exit (qt:find window "actionQuit")) (let* [(menu-file-exit (qt:find window "actionQuit"))
(menu-file-save (qt:find window "actionSave"))] (menu-file-save (qt:find window "actionSave"))
(menu-file-open (qt:find window "actionOpen"))]
;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered ;; We connect to https://doc.qt.io/qt-6/qaction.html#triggered
(if menu-file-exit (if menu-file-exit
(qt:connect (qt:connect
@ -89,36 +96,53 @@
menu-file-save "triggered()" menu-file-save "triggered()"
(qt:receiver (qt:receiver
(lambda () (lambda ()
(qt:message "Saving is not implemented."))))))) (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"))))))))
;; Connect a text-printing callback to each textbox. ;; Parse a vCard file and populate the windows forms with its contents.
(define (textbox-callbacks window) (define (open-vcard-file window file)
(let* [(property-names (if (and (file-exists? file)
'("address" "city" "company" "country" "eMail" "fax" (file-readable? file))
"homePhone" "name" "nickname" "state" "url" (thread-start! (lambda () (populate-with-vcard
"workPhone" "zip")) window
(textboxes (with-input-from-file file
;; The texbox widgets are all named like “countryLineEdit”. vcard:read-vcard))))))
(map (lambda (property)
(qt:find window (conc property "LineEdit")))
property-names))] ;; Simply map vCard property-names to their corresponding name in the windows
;; Cycle through each textbox, connecting them to a callback that prints ;; fields.
;; their contents each time you type in text. (define property->formname-alist
(map (lambda (textbox) '((FN . "name")
;; We connect to https://doc.qt.io/qt-6/qlineedit.html#textChanged (ADR . "address")
;; … and print the value of https://doc.qt.io/qt-6/qlineedit.html#text-prop (TEL . "homePhone")
;; Also enable the File→Save menu-item (since, yknow, the user (TEL . "workPhone")
;; changed something). It defaults to disabled in the contact.ui file. (EMAIL . "eMail")
(if textbox (URL . "url")
(qt:connect textbox "textChanged(QString)" (NICKNAME . "nickname")))
(qt:receiver
(lambda ()
(let [(menu-file-save (qt:find window "actionSave"))] ;; Given a parsed vCard in vcardeds alist format, populate the windows fields.
(if menu-file-save ;; Heres the format:
(set! (qt:property menu-file-save "enabled") #t))) ;; ((PROPERTY (ATTRIBUTES) VALUE)
(print (qt:property textbox "text"))))))) ;; (FN () "A. Dmytryshyn")
textboxes))) ;; (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))
(init) (init)

View File

@ -225,7 +225,9 @@
<property name="title"> <property name="title">
<string>File</string> <string>File</string>
</property> </property>
<addaction name="actionOpen"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
@ -244,6 +246,11 @@
<string>Save</string> <string>Save</string>
</property> </property>
</action> </action>
<action name="actionOpen">
<property name="text">
<string>Open…</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>