handle signals and card states
This commit is contained in:
parent
a22d936df7
commit
ce1be698a6
|
@ -2,6 +2,9 @@ import NimQml, chronicles, std/wrapnils
|
|||
import status/[signals, status, keycard]
|
||||
import view
|
||||
|
||||
logScope:
|
||||
topics = "keycard-model"
|
||||
|
||||
type KeycardController* = ref object
|
||||
view*: KeycardView
|
||||
variant*: QVariant
|
||||
|
@ -29,18 +32,22 @@ proc getCardState(self: KeycardController) =
|
|||
|
||||
if not appInfo.installed:
|
||||
self.view.cardState = NotKeycard
|
||||
self.view.cardNotKeycard()
|
||||
elif not appInfo.initialized:
|
||||
self.view.cardState = PreInit
|
||||
self.view.cardPreInit()
|
||||
elif self.attemptOpenSecureChannel():
|
||||
# here we will also be able to check if the card is Frozen/Blocked
|
||||
self.view.cardState = Paired
|
||||
self.view.cardPaired()
|
||||
elif appInfo.availableSlots > 0:
|
||||
self.view.cardState = Unpaired
|
||||
self.view.cardUnpaired()
|
||||
else:
|
||||
self.view.cardState = NoFreeSlots
|
||||
self.view.cardNoFreeSlots()
|
||||
|
||||
proc init*(self: KeycardController) =
|
||||
discard """
|
||||
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
||||
getCardState()
|
||||
self.getCardState()
|
||||
self.view.cardConnected()
|
||||
"""
|
|
@ -35,10 +35,15 @@ QtObject:
|
|||
result.setup
|
||||
|
||||
proc cardConnected*(self: KeycardView) {.signal.}
|
||||
|
||||
proc cardDisconnected*(self: KeycardView) {.signal.}
|
||||
|
||||
proc cardStateChanged*(self: KeycardView, cardState: int) {.signal.}
|
||||
proc cardNotKeycard*(self: KeycardView) {.signal.}
|
||||
proc cardPreInit*(self: KeycardView) {.signal.}
|
||||
proc cardUnpaired*(self: KeycardView) {.signal.}
|
||||
proc cardNoFreeSlots*(self: KeycardView) {.signal.}
|
||||
proc cardPaired*(self: KeycardView) {.signal.}
|
||||
proc cardFrozen*(self: KeycardView) {.signal.}
|
||||
proc cardBlocked*(self: KeycardView) {.signal.}
|
||||
proc cardAuthenticated*(self: KeycardView) {.signal.}
|
||||
|
||||
proc startConnection*(self: KeycardView) {.slot.} =
|
||||
discard self.status.keycard.start()
|
||||
|
@ -47,6 +52,10 @@ QtObject:
|
|||
self.cardState = Disconnected
|
||||
discard self.status.keycard.stop()
|
||||
|
||||
proc `cardState=`*(self: KeycardView, cardState: CardState) =
|
||||
self.cardState = cardState
|
||||
self.cardStateChanged(int(cardState))
|
||||
proc pair*(self: KeycardView, password: string) {.slot.} =
|
||||
discard """
|
||||
on succesful pairing, save and change card state
|
||||
otherwise throw error
|
||||
|
||||
self.status.keycard.pair(password)
|
||||
"""
|
|
@ -17,21 +17,23 @@ Item {
|
|||
CreatePINModal {
|
||||
id: createPinModal
|
||||
onClosed: function () {
|
||||
pairingModal.open()
|
||||
keycardView.onClosed()
|
||||
}
|
||||
}
|
||||
|
||||
PairingModal {
|
||||
id: pairingModal
|
||||
onClosed: function () {
|
||||
pinModal.open()
|
||||
if (!pairingModal.submitted) {
|
||||
keycardView.onClosed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PINModal {
|
||||
id: pinModal
|
||||
onClosed: function () {
|
||||
keycardView.open()
|
||||
keycardView.onClosed()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,4 +43,48 @@ Item {
|
|||
keycardView.onClosed()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: connection
|
||||
target: keycardModel
|
||||
ignoreUnknownSignals: true
|
||||
|
||||
onCardUnpaired: {
|
||||
pairingModal.open()
|
||||
}
|
||||
|
||||
onCardPaired: {
|
||||
|
||||
}
|
||||
|
||||
//TODO: support the states below
|
||||
|
||||
onCardPreInit: {
|
||||
keycardView.onClosed()
|
||||
}
|
||||
|
||||
onCardFrozen: {
|
||||
keycardView.onClosed()
|
||||
|
||||
}
|
||||
|
||||
onCardBlocked: {
|
||||
keycardView.onClosed()
|
||||
}
|
||||
|
||||
// TODO: handle these by showing an error an prompting for another card
|
||||
// later add factory reset option for the NoFreeSlots case
|
||||
|
||||
onCardNoFreeSlots: {
|
||||
//status-lib currently always returns availableSlots = 0 so we end up here
|
||||
//keycardView.onClosed()
|
||||
pairingModal.open()
|
||||
}
|
||||
|
||||
onCardNotKeycard: {
|
||||
keycardView.onClosed()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import "../../shared"
|
|||
|
||||
ModalPopup {
|
||||
property bool pairingPasswordFieldValid: false
|
||||
property bool submitted: false
|
||||
|
||||
id: popup
|
||||
title: qsTr("Insert pairing code")
|
||||
|
@ -57,7 +58,9 @@ ModalPopup {
|
|||
enabled: pairingPasswordFieldValid
|
||||
|
||||
onClicked: {
|
||||
|
||||
submitted = true
|
||||
keycardModel.pair(pairingPasswordField.text)
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue