2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 by Savoir-faire Linux
|
|
|
|
* Author: Yang Wang <yang.wang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
import QtQuick.Controls.Styles 1.4
|
|
|
|
import net.jami.Models 1.0
|
2020-09-04 17:53:24 -04:00
|
|
|
import net.jami.Adapters 1.0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
import "../constant"
|
2020-09-03 21:19:10 -04:00
|
|
|
|
|
|
|
// PasswordDialog for changing password and exporting account
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
Dialog {
|
2020-09-03 21:19:10 -04:00
|
|
|
id: root
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
enum PasswordEnteringPurpose {
|
|
|
|
ChangePassword,
|
|
|
|
ExportAccount,
|
|
|
|
SetPassword
|
|
|
|
}
|
|
|
|
readonly property int successCode: 200
|
|
|
|
signal doneSignal(int code, int currentPurpose)
|
|
|
|
|
|
|
|
property string path: ""
|
|
|
|
property int purpose: PasswordDialog.ChangePassword
|
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
header : Rectangle {
|
2020-09-03 21:19:10 -04:00
|
|
|
id: dialogHeader
|
2020-08-17 22:38:19 -04:00
|
|
|
width: parent.width
|
|
|
|
height: 64
|
|
|
|
color: "transparent"
|
|
|
|
Text {
|
2020-09-03 21:19:10 -04:00
|
|
|
anchors.fill: parent
|
|
|
|
anchors.leftMargin: JamiTheme.preferredMarginSize
|
|
|
|
anchors.topMargin: JamiTheme.preferredMarginSize
|
2020-08-17 22:38:19 -04:00
|
|
|
|
|
|
|
text: {
|
|
|
|
switch(purpose){
|
|
|
|
case PasswordDialog.ExportAccount:
|
|
|
|
return qsTr("Enter the password of this account")
|
|
|
|
case PasswordDialog.ChangePassword:
|
|
|
|
return qsTr("Changing password")
|
|
|
|
case PasswordDialog.SetPassword:
|
|
|
|
return qsTr("Set password")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font.pointSize: JamiTheme.headerFontSize
|
2020-09-03 21:19:10 -04:00
|
|
|
wrapMode: Text.Wrap
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openDialog(purposeIn, exportPathIn = ""){
|
|
|
|
purpose = purposeIn
|
|
|
|
path = exportPathIn
|
|
|
|
currentPasswordEdit.clear()
|
2020-08-17 22:38:19 -04:00
|
|
|
passwordEdit.borderColorMode = InfoLineEdit.NORMAL
|
|
|
|
confirmPasswordEdit.borderColorMode = InfoLineEdit.NORMAL
|
2020-08-03 13:27:42 -04:00
|
|
|
passwordEdit.clear()
|
|
|
|
confirmPasswordEdit.clear()
|
2020-09-03 21:19:10 -04:00
|
|
|
root.open()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function haveDone(code, currentPurpose) {
|
|
|
|
done(code)
|
|
|
|
doneSignal(code, currentPurpose)
|
|
|
|
}
|
|
|
|
|
|
|
|
function validatePassword() {
|
|
|
|
var acceptablePassword = (passwordEdit.text === confirmPasswordEdit.text)
|
|
|
|
btnChangePasswordConfirm.enabled = acceptablePassword
|
|
|
|
|
|
|
|
if (acceptablePassword) {
|
|
|
|
passwordEdit.borderColorMode = InfoLineEdit.RIGHT
|
|
|
|
confirmPasswordEdit.borderColorMode = InfoLineEdit.RIGHT
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
passwordEdit.borderColorMode = InfoLineEdit.ERROR
|
|
|
|
confirmPasswordEdit.borderColorMode = InfoLineEdit.ERROR
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer{
|
|
|
|
id: timerToOperate
|
|
|
|
|
|
|
|
interval: 200
|
|
|
|
repeat: false
|
|
|
|
|
|
|
|
onTriggered: {
|
|
|
|
if ((purpose === PasswordDialog.ChangePassword) || (purpose === PasswordDialog.SetPassword)) {
|
|
|
|
savePasswordQML()
|
|
|
|
} else if(purpose === PasswordDialog.ExportAccount) {
|
|
|
|
exportAccountQML()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function exportAccountQML() {
|
|
|
|
var success = false
|
2020-09-04 14:51:39 -04:00
|
|
|
if (path.length > 0) {
|
2020-09-04 17:53:24 -04:00
|
|
|
success = AccountAdapter.exportToFile(
|
2020-09-04 14:51:39 -04:00
|
|
|
UtilsAdapter.getCurrAccId(),
|
|
|
|
path,
|
|
|
|
currentPasswordEdit.text)
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (success) {
|
2020-09-03 21:19:10 -04:00
|
|
|
haveDone(successCode, root.purpose)
|
2020-08-03 13:27:42 -04:00
|
|
|
} else {
|
|
|
|
btnChangePasswordConfirm.enabled = false
|
2020-08-17 22:38:19 -04:00
|
|
|
currentPasswordEdit.borderColorMode = InfoLineEdit.ERROR
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
2020-09-03 21:19:10 -04:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
function savePasswordQML() {
|
|
|
|
var success = false
|
2020-09-04 17:53:24 -04:00
|
|
|
success = AccountAdapter.savePassword(
|
2020-09-04 14:51:39 -04:00
|
|
|
UtilsAdapter.getCurrAccId(),
|
|
|
|
currentPasswordEdit.text,
|
|
|
|
passwordEdit.text)
|
2020-08-03 13:27:42 -04:00
|
|
|
if (success) {
|
2020-09-04 17:53:24 -04:00
|
|
|
AccountAdapter.setArchiveHasPassword(passwordEdit.text.length !== 0)
|
|
|
|
haveDone(successCode, passwordDialog.purpose)
|
2020-08-03 13:27:42 -04:00
|
|
|
} else {
|
2020-08-17 22:38:19 -04:00
|
|
|
currentPasswordEdit.borderColorMode = InfoLineEdit.ERROR
|
2020-08-03 13:27:42 -04:00
|
|
|
btnChangePasswordConfirm.enabled = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
visible: false
|
|
|
|
x: (parent.width - width) / 2
|
|
|
|
y: (parent.height - height) / 2
|
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
contentItem: Rectangle {
|
2020-09-03 21:19:10 -04:00
|
|
|
implicitHeight: contentLayout.implicitHeight + dialogHeader.height + JamiTheme.preferredMarginSize
|
|
|
|
implicitWidth: 350
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
ColumnLayout {
|
2020-08-17 22:38:19 -04:00
|
|
|
id: contentLayout
|
2020-08-03 13:27:42 -04:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
MaterialLineEdit {
|
|
|
|
id: currentPasswordEdit
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
Layout.maximumHeight: visible ?
|
|
|
|
48 :
|
|
|
|
0
|
|
|
|
Layout.fillWidth: true
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
visible: purpose === PasswordDialog.ChangePassword || purpose === PasswordDialog.ExportAccount
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
placeholderText: qsTr("Enter Current Password")
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
onTextChanged: {
|
|
|
|
if (purpose === PasswordDialog.ChangePassword) {
|
|
|
|
validatePassword()
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
if (currentPasswordEdit.text.length == 0) {
|
|
|
|
btnChangePasswordConfirm.enabled = false
|
|
|
|
} else {
|
|
|
|
btnChangePasswordConfirm.enabled = true
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
MaterialLineEdit {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: passwordEdit
|
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: JamiTheme.preferredMarginSize / 2
|
2020-08-17 22:38:19 -04:00
|
|
|
fieldLayoutHeight: 48
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
visible: purpose === PasswordDialog.ChangePassword || purpose === PasswordDialog.SetPassword
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
|
|
|
|
placeholderText: qsTr("Enter New Password")
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
validatePassword()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
MaterialLineEdit {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: confirmPasswordEdit
|
|
|
|
|
2020-09-03 21:19:10 -04:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.topMargin: JamiTheme.preferredMarginSize / 2
|
2020-08-17 22:38:19 -04:00
|
|
|
fieldLayoutHeight: 48
|
2020-08-03 13:27:42 -04:00
|
|
|
layoutFillwidth: true
|
|
|
|
|
|
|
|
visible: purpose === PasswordDialog.ChangePassword || purpose === PasswordDialog.SetPassword
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
|
|
|
|
placeholderText: qsTr("Confirm New Password")
|
|
|
|
|
|
|
|
onTextChanged: {
|
|
|
|
validatePassword()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
2020-09-03 21:19:10 -04:00
|
|
|
Layout.topMargin: JamiTheme.preferredMarginSize / 2
|
2020-08-17 22:38:19 -04:00
|
|
|
Layout.alignment: Qt.AlignRight
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
Button {
|
|
|
|
id: btnChangePasswordConfirm
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
contentItem: Text {
|
|
|
|
text: qsTr("CONFIRM")
|
|
|
|
color: JamiTheme.buttonTintedBlue
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
background: Rectangle {
|
|
|
|
color: "transparent"
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
timerToOperate.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
Button {
|
2020-08-03 13:27:42 -04:00
|
|
|
id: btnChangePasswordCancel
|
2020-09-03 21:19:10 -04:00
|
|
|
Layout.leftMargin: JamiTheme.preferredMarginSize / 2
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
contentItem: Text {
|
|
|
|
text: qsTr("CANCEL")
|
|
|
|
color: JamiTheme.buttonTintedBlue
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-17 22:38:19 -04:00
|
|
|
background: Rectangle {
|
|
|
|
color: "transparent"
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
onClicked: {
|
2020-09-03 21:19:10 -04:00
|
|
|
root.reject()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|