PasswordDelegate.qml (3834B)
1 /* 2 * Copyright (C) 2019 Daniel Vrátil <dvratil@kde.org> 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 18 import QtQuick 2.2 19 import QtQml.Models 2.2 20 import Sailfish.Silica 1.0 21 import harbour.safe 0.1 22 23 ListItem { 24 id: listItem 25 26 property var modelData 27 property var password : null 28 29 signal folderSelected() 30 31 contentHeight: password === null ? Theme.itemSizeSmall : Theme.itemSizeLarge 32 33 Row { 34 anchors { 35 fill: parent 36 leftMargin: Theme.horizontalPageMargin 37 rightMargin: Theme.horizontalPageMargin 38 verticalCenter: parent.verticalCenter 39 topMargin: Theme.paddingMedium 40 } 41 42 Column { 43 spacing: Theme.paddingSmall 44 width: parent.width 45 46 Row { 47 spacing: Theme.paddingMedium 48 49 Image { 50 anchors.verticalCenter: parent.verticalCenter 51 source: "image://theme/" 52 + ((modelData.type === PasswordsModel.FolderEntry) ? "icon-m-levels" : "icon-m-device-lock") 53 + "?" 54 + (listItem.highlighted ? Theme.highlightColor : Theme.primaryColor) 55 width: Theme.iconSizeSmall 56 height: width 57 } 58 59 Label { 60 id: label 61 text: modelData.name 62 } 63 } 64 65 Row { 66 visible: password !== null 67 width: parent.width 68 69 Label { 70 id: errorLabel 71 72 visible: password !== null && password.hasError 73 74 text: password ? password.error : "" 75 font.pixelSize: Theme.fontSizeTiny 76 } 77 78 Label { 79 id: okLabel 80 81 visible: password !== null && password.valid 82 83 text: qsTr("Password copied to clipboard") 84 font.pixelSize: Theme.fontSizeTiny 85 } 86 } 87 } 88 } 89 90 RemorseItem { 91 id: remorse 92 93 cancelText: qsTr("Expire password") 94 95 // HACK: override RemorseItem._execute() to act as cancel when the timer expires 96 function _execute(closeAfterExecute) { 97 cancel() 98 } 99 100 onCanceled: { 101 if (listItem.password) { 102 listItem.password.expirePassword(); 103 } 104 } 105 } 106 107 onClicked: { 108 if (modelData.type === PasswordsModel.FolderEntry) { 109 listItem.folderSelected() 110 } else { 111 modelData.password.requestPassword() 112 listItem.password = modelData.password 113 listItem.password.validChanged.connect(function() { 114 if (listItem.password.valid) { 115 remorse.execute(listItem, qsTr("Password will expire"), 116 function() { 117 if (listItem.password) { 118 listItem.password.expirePassword(); 119 } 120 }, listItem.password.defaultTimeout); 121 } 122 }); 123 } 124 } 125 }