Pass code and credential as properties to CredentialItem instead of modelData

This commit is contained in:
Emil Lundberg 2017-11-21 16:33:48 +01:00
parent 2367850930
commit ac85a2bbc1
No known key found for this signature in database
GPG Key ID: 5B9688125FF0B636
2 changed files with 23 additions and 21 deletions

View File

@ -3,9 +3,10 @@ import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
Rectangle { Rectangle {
property var code
property var credential
property bool expired: true property bool expired: true
property bool isSelected: false property bool isSelected: false
property var model
property color textColor: (isSelected property color textColor: (isSelected
? palette.highlightedText ? palette.highlightedText
: palette.windowText : palette.windowText
@ -13,8 +14,8 @@ Rectangle {
property bool timerRunning: false property bool timerRunning: false
property color unselectedColor property color unselectedColor
signal singleClick(var mouse, var entry) signal singleClick(var mouse)
signal doubleClick(var mouse, var entry) signal doubleClick(var mouse)
signal refresh(bool force) signal refresh(bool force)
color: { color: {
@ -27,15 +28,15 @@ Rectangle {
Layout.minimumHeight: ( Layout.minimumHeight: (
10 + issuerLbl.height + codeLbl.height + nameLbl.height 10 + issuerLbl.height + codeLbl.height + nameLbl.height
+ (hasCustomTimeBar(model.credential) ? 10 : 0) + (hasCustomTimeBar(credential) ? 10 : 0)
) )
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: singleClick(mouse, model) onClicked: singleClick(mouse)
onDoubleClicked: doubleClick(mouse, model) onDoubleClicked: doubleClick(mouse)
acceptedButtons: Qt.RightButton | Qt.LeftButton acceptedButtons: Qt.RightButton | Qt.LeftButton
} }
@ -48,31 +49,31 @@ Rectangle {
spacing: 0 spacing: 0
Label { Label {
id: issuerLbl id: issuerLbl
visible: model.credential.issuer != null visible: credential.issuer != null
&& model.credential.issuer.length > 0 && credential.issuer.length > 0
text: qsTr("") + model.credential.issuer text: qsTr("") + credential.issuer
color: textColor color: textColor
} }
Label { Label {
id: codeLbl id: codeLbl
opacity: expired ? 0.6 : 1 opacity: expired ? 0.6 : 1
visible: model.code !== null visible: code !== null
text: qsTr("") + getSpacedCredential(model.code && model.code.value) text: qsTr("") + getSpacedCredential(code && code.value)
font.pointSize: issuerLbl.font.pointSize * 1.8 font.pointSize: issuerLbl.font.pointSize * 1.8
color: textColor color: textColor
} }
Label { Label {
id: nameLbl id: nameLbl
text: model.credential.name text: credential.name
color: textColor color: textColor
} }
Timer { Timer {
interval: 100 interval: 100
repeat: true repeat: true
running: timerRunning && hasCustomTimeBar(model.credential) running: timerRunning && hasCustomTimeBar(credential)
triggeredOnStart: true triggeredOnStart: true
onTriggered: { onTriggered: {
var timeLeft = model.code.valid_to - (Date.now() / 1000) var timeLeft = code.valid_to - (Date.now() / 1000)
if (timeLeft <= 0 && customTimeLeftBar.value > 0) { if (timeLeft <= 0 && customTimeLeftBar.value > 0) {
refresh(true) refresh(true)
} }
@ -81,13 +82,13 @@ Rectangle {
} }
ProgressBar { ProgressBar {
id: customTimeLeftBar id: customTimeLeftBar
visible: hasCustomTimeBar(model.credential) visible: hasCustomTimeBar(credential)
Layout.topMargin: 3 Layout.topMargin: 3
Layout.fillWidth: true Layout.fillWidth: true
Layout.minimumHeight: 7 Layout.minimumHeight: 7
Layout.maximumHeight: 7 Layout.maximumHeight: 7
Layout.alignment: Qt.AlignBottom Layout.alignment: Qt.AlignBottom
maximumValue: model.credential.period || 0 maximumValue: credential.period || 0
rotation: 180 rotation: 180
} }
} }

View File

@ -275,9 +275,10 @@ ApplicationWindow {
model: filteredCredentials(credentials) model: filteredCredentials(credentials)
CredentialItem { CredentialItem {
code: modelData.code
credential: modelData.credential
expired: isExpired(modelData) expired: isExpired(modelData)
isSelected: selected != null && selected.credential.key === modelData.credential.key isSelected: selected != null && selected.credential.key === modelData.credential.key
model: modelData
timerRunning: displayTimersRunning timerRunning: displayTimersRunning
unselectedColor: { unselectedColor: {
if (index % 2 == 0) { if (index % 2 == 0) {
@ -292,7 +293,7 @@ ApplicationWindow {
// A double-click should select the credential, // A double-click should select the credential,
// then generate if needed and copy the code. // then generate if needed and copy the code.
selectCredential(entry, index) selectCredential(modelData, index)
generateOrCopy() generateOrCopy()
} }
@ -303,16 +304,16 @@ ApplicationWindow {
// Left click, select or deselect credential. // Left click, select or deselect credential.
if (mouse.button & Qt.LeftButton) { if (mouse.button & Qt.LeftButton) {
if (selected != null && selected.credential.key === entry.credential.key) { if (selected != null && selected.credential.key === credential.key) {
deselectCredential() deselectCredential()
} else { } else {
selectCredential(entry, index) selectCredential(modelData, index)
} }
} }
// Right-click, select credential and open popup menu. // Right-click, select credential and open popup menu.
if (mouse.button & Qt.RightButton) { if (mouse.button & Qt.RightButton) {
selectCredential(entry, index) selectCredential(modelData, index)
credentialMenu.popup() credentialMenu.popup()
} }
} }