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 status/[signals, status, keycard]
|
||||||
import view
|
import view
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "keycard-model"
|
||||||
|
|
||||||
type KeycardController* = ref object
|
type KeycardController* = ref object
|
||||||
view*: KeycardView
|
view*: KeycardView
|
||||||
variant*: QVariant
|
variant*: QVariant
|
||||||
|
@ -29,18 +32,22 @@ proc getCardState(self: KeycardController) =
|
||||||
|
|
||||||
if not appInfo.installed:
|
if not appInfo.installed:
|
||||||
self.view.cardState = NotKeycard
|
self.view.cardState = NotKeycard
|
||||||
|
self.view.cardNotKeycard()
|
||||||
elif not appInfo.initialized:
|
elif not appInfo.initialized:
|
||||||
self.view.cardState = PreInit
|
self.view.cardState = PreInit
|
||||||
|
self.view.cardPreInit()
|
||||||
elif self.attemptOpenSecureChannel():
|
elif self.attemptOpenSecureChannel():
|
||||||
|
# here we will also be able to check if the card is Frozen/Blocked
|
||||||
self.view.cardState = Paired
|
self.view.cardState = Paired
|
||||||
|
self.view.cardPaired()
|
||||||
elif appInfo.availableSlots > 0:
|
elif appInfo.availableSlots > 0:
|
||||||
self.view.cardState = Unpaired
|
self.view.cardState = Unpaired
|
||||||
|
self.view.cardUnpaired()
|
||||||
else:
|
else:
|
||||||
self.view.cardState = NoFreeSlots
|
self.view.cardState = NoFreeSlots
|
||||||
|
self.view.cardNoFreeSlots()
|
||||||
|
|
||||||
proc init*(self: KeycardController) =
|
proc init*(self: KeycardController) =
|
||||||
discard """
|
|
||||||
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
||||||
getCardState()
|
self.getCardState()
|
||||||
self.view.cardConnected()
|
self.view.cardConnected()
|
||||||
"""
|
|
|
@ -35,10 +35,15 @@ QtObject:
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc cardConnected*(self: KeycardView) {.signal.}
|
proc cardConnected*(self: KeycardView) {.signal.}
|
||||||
|
|
||||||
proc cardDisconnected*(self: KeycardView) {.signal.}
|
proc cardDisconnected*(self: KeycardView) {.signal.}
|
||||||
|
proc cardNotKeycard*(self: KeycardView) {.signal.}
|
||||||
proc cardStateChanged*(self: KeycardView, cardState: int) {.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.} =
|
proc startConnection*(self: KeycardView) {.slot.} =
|
||||||
discard self.status.keycard.start()
|
discard self.status.keycard.start()
|
||||||
|
@ -47,6 +52,10 @@ QtObject:
|
||||||
self.cardState = Disconnected
|
self.cardState = Disconnected
|
||||||
discard self.status.keycard.stop()
|
discard self.status.keycard.stop()
|
||||||
|
|
||||||
proc `cardState=`*(self: KeycardView, cardState: CardState) =
|
proc pair*(self: KeycardView, password: string) {.slot.} =
|
||||||
self.cardState = cardState
|
discard """
|
||||||
self.cardStateChanged(int(cardState))
|
on succesful pairing, save and change card state
|
||||||
|
otherwise throw error
|
||||||
|
|
||||||
|
self.status.keycard.pair(password)
|
||||||
|
"""
|
|
@ -17,21 +17,23 @@ Item {
|
||||||
CreatePINModal {
|
CreatePINModal {
|
||||||
id: createPinModal
|
id: createPinModal
|
||||||
onClosed: function () {
|
onClosed: function () {
|
||||||
pairingModal.open()
|
keycardView.onClosed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PairingModal {
|
PairingModal {
|
||||||
id: pairingModal
|
id: pairingModal
|
||||||
onClosed: function () {
|
onClosed: function () {
|
||||||
pinModal.open()
|
if (!pairingModal.submitted) {
|
||||||
|
keycardView.onClosed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PINModal {
|
PINModal {
|
||||||
id: pinModal
|
id: pinModal
|
||||||
onClosed: function () {
|
onClosed: function () {
|
||||||
keycardView.open()
|
keycardView.onClosed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,4 +43,48 @@ Item {
|
||||||
keycardView.onClosed()
|
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 {
|
ModalPopup {
|
||||||
property bool pairingPasswordFieldValid: false
|
property bool pairingPasswordFieldValid: false
|
||||||
|
property bool submitted: false
|
||||||
|
|
||||||
id: popup
|
id: popup
|
||||||
title: qsTr("Insert pairing code")
|
title: qsTr("Insert pairing code")
|
||||||
|
@ -57,7 +58,9 @@ ModalPopup {
|
||||||
enabled: pairingPasswordFieldValid
|
enabled: pairingPasswordFieldValid
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
submitted = true
|
||||||
|
keycardModel.pair(pairingPasswordField.text)
|
||||||
|
popup.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue