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/>.
|
|
|
|
*/
|
|
|
|
|
2020-10-06 13:58:44 +02:00
|
|
|
import QtQuick 2.14
|
2020-08-03 13:27:42 -04:00
|
|
|
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-09-07 17:44:57 +02:00
|
|
|
BaseDialog {
|
2020-09-03 21:19:10 -04:00
|
|
|
id: root
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
enum PasswordEnteringPurpose {
|
|
|
|
ChangePassword,
|
|
|
|
ExportAccount,
|
|
|
|
SetPassword
|
|
|
|
}
|
|
|
|
|
|
|
|
property string path: ""
|
|
|
|
property int purpose: PasswordDialog.ChangePassword
|
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
signal doneSignal(bool success, int currentPurpose)
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
function openDialog(purposeIn, exportPathIn = "") {
|
2020-08-03 13:27:42 -04:00
|
|
|
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-07 17:44:57 +02:00
|
|
|
validatePassword()
|
|
|
|
open()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function validatePassword() {
|
2020-09-07 17:44:57 +02:00
|
|
|
switch (purpose) {
|
|
|
|
case PasswordDialog.ExportAccount:
|
|
|
|
btnConfirm.enabled = currentPasswordEdit.length > 0
|
|
|
|
break
|
|
|
|
case PasswordDialog.SetPassword:
|
|
|
|
btnConfirm.enabled = passwordEdit.length > 0 &&
|
|
|
|
passwordEdit.text === confirmPasswordEdit.text
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
btnConfirm.enabled = currentPasswordEdit.length > 0 &&
|
|
|
|
passwordEdit.text === confirmPasswordEdit.text
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-23 12:54:48 +02:00
|
|
|
AccountAdapter.currentAccountId,
|
2020-09-04 14:51:39 -04:00
|
|
|
path,
|
|
|
|
currentPasswordEdit.text)
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-09-07 17:44:57 +02:00
|
|
|
doneSignal(success, purpose)
|
|
|
|
close()
|
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-23 12:54:48 +02:00
|
|
|
AccountAdapter.currentAccountId,
|
2020-09-04 14:51:39 -04:00
|
|
|
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)
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-09-07 17:44:57 +02:00
|
|
|
doneSignal(success, purpose)
|
|
|
|
close()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
title: {
|
|
|
|
switch(purpose){
|
|
|
|
case PasswordDialog.ExportAccount:
|
|
|
|
return JamiStrings.enterPassword
|
|
|
|
case PasswordDialog.ChangePassword:
|
|
|
|
return JamiStrings.changePassword
|
|
|
|
case PasswordDialog.SetPassword:
|
|
|
|
return JamiStrings.setPassword
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Timer {
|
|
|
|
id: timerToOperate
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
interval: 200
|
|
|
|
repeat: false
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
onTriggered: {
|
|
|
|
if (purpose === PasswordDialog.ExportAccount) {
|
|
|
|
exportAccountQML()
|
|
|
|
} else {
|
|
|
|
savePasswordQML()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
contentItem: Rectangle {
|
|
|
|
id: passwordDialogContentRect
|
|
|
|
|
|
|
|
implicitWidth: JamiTheme.preferredDialogWidth
|
|
|
|
implicitHeight: JamiTheme.preferredDialogHeight
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: JamiTheme.preferredMarginSize
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
MaterialLineEdit {
|
|
|
|
id: currentPasswordEdit
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: JamiTheme.preferredFieldWidth
|
|
|
|
Layout.preferredHeight: visible ? 48 : 0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
visible: purpose === PasswordDialog.ChangePassword ||
|
|
|
|
purpose === PasswordDialog.ExportAccount
|
|
|
|
echoMode: TextInput.Password
|
|
|
|
placeholderText: JamiStrings.enterCurrentPassword
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
onTextChanged: {
|
|
|
|
validatePassword()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-09-07 17:44:57 +02:00
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
MaterialLineEdit {
|
|
|
|
id: passwordEdit
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: JamiTheme.preferredFieldWidth
|
|
|
|
Layout.preferredHeight: visible ? 48 : 0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
visible: purpose === PasswordDialog.ChangePassword ||
|
|
|
|
purpose === PasswordDialog.SetPassword
|
|
|
|
echoMode: TextInput.Password
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
placeholderText: JamiStrings.enterNewPassword
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
onTextChanged: {
|
|
|
|
validatePassword()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-09-07 17:44:57 +02:00
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
MaterialLineEdit {
|
|
|
|
id: confirmPasswordEdit
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: JamiTheme.preferredFieldWidth
|
|
|
|
Layout.preferredHeight: visible ? 48 : 0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
visible: purpose === PasswordDialog.ChangePassword ||
|
|
|
|
purpose === PasswordDialog.SetPassword
|
|
|
|
echoMode: TextInput.Password
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
placeholderText: JamiStrings.confirmNewPassword
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
onTextChanged: {
|
|
|
|
validatePassword()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
2020-09-07 17:44:57 +02:00
|
|
|
spacing: 16
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
MaterialButton {
|
|
|
|
id: btnConfirm
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: JamiTheme.preferredFieldWidth / 2 - 8
|
|
|
|
Layout.preferredHeight: JamiTheme.preferredFieldHeight
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
color: enabled? JamiTheme.buttonTintedBlack : JamiTheme.buttonTintedGrey
|
|
|
|
hoveredColor: JamiTheme.buttonTintedBlackHovered
|
|
|
|
pressedColor: JamiTheme.buttonTintedBlackPressed
|
|
|
|
outlined: true
|
|
|
|
enabled: purpose === PasswordDialog.SetPassword
|
|
|
|
|
|
|
|
text: (purpose === PasswordDialog.ExportAccount) ? JamiStrings.exportAccount :
|
|
|
|
JamiStrings.change
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
onClicked: {
|
2020-09-07 17:44:57 +02:00
|
|
|
btnConfirm.enabled = false
|
2020-08-03 13:27:42 -04:00
|
|
|
timerToOperate.restart()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
MaterialButton {
|
|
|
|
id: btnCancel
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
Layout.preferredWidth: JamiTheme.preferredFieldWidth / 2 - 8
|
|
|
|
Layout.preferredHeight: JamiTheme.preferredFieldHeight
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
color: JamiTheme.buttonTintedBlack
|
|
|
|
hoveredColor: JamiTheme.buttonTintedBlackHovered
|
|
|
|
pressedColor: JamiTheme.buttonTintedBlackPressed
|
|
|
|
outlined: true
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-07 17:44:57 +02:00
|
|
|
text: qsTr("Cancel")
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
onClicked: {
|
2020-09-07 17:44:57 +02:00
|
|
|
close()
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|