You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
settings/src/qml/User/Main.qml

213 lines
6.9 KiB
QML

/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: revenmartin <revenmartin@gmail.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
* 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 <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Qt5Compat.GraphicalEffects
import FishUI 1.0 as FishUI
import Cutefish.Settings 1.0
import Cutefish.Accounts 1.0
import "../"
ItemPage {
headerTitle: qsTr("User")
UserAccount {
id: loggedUser
}
UsersModel {
id: userModel
}
AccountsManager {
id: accountsManager
onUserAdded: {
if (account.userName === userNameField.text) {
account.passwordMode = UserAccount.RegularPasswordMode
account.setPassword(Password.cryptPassword(passwordField.text))
newUserItem.clear()
}
}
}
Scrollable {
id: _scrollable
anchors.fill: parent
contentHeight: layout.implicitHeight
ColumnLayout {
id: layout
anchors.fill: parent
spacing: FishUI.Units.largeSpacing * 2
ListView {
id: _userView
model: userModel
Layout.fillWidth: true
spacing: FishUI.Units.largeSpacing * 2
interactive: false
Layout.preferredHeight: {
var totalHeight = 0
for (var i = 0; i < _userView.visibleChildren.length; ++i) {
totalHeight += _userView.visibleChildren[i].height
}
return totalHeight
}
delegate: UserDelegateItem {
width: _userView.width
}
}
// Add new user.
RoundedItem {
id: newUserItem
visible: false
function clear() {
userNameField.clear()
passwordField.clear()
verifyPasswordField.clear()
accountTypeCombo.currentIndex = 0
}
ColumnLayout {
id: _mainLayout
spacing: FishUI.Units.largeSpacing * 1.5
Label {
text: qsTr("Add new user")
}
GridLayout {
columns: 2
columnSpacing: FishUI.Units.largeSpacing * 2
rowSpacing: FishUI.Units.smallSpacing * 2
Label {
text: qsTr("User name")
Layout.alignment: Qt.AlignRight
}
TextField {
id: userNameField
placeholderText: qsTr("User name")
Layout.fillWidth: true
Layout.alignment: Qt.AlignRight
selectByMouse: true
}
Label {
text: qsTr("Password")
Layout.alignment: Qt.AlignRight
}
TextField {
id: passwordField
placeholderText: qsTr("Password")
echoMode: TextField.Password
Layout.fillWidth: true
selectByMouse: true
}
Label {
text: qsTr("Verify password")
Layout.alignment: Qt.AlignRight
}
TextField {
id: verifyPasswordField
placeholderText: qsTr("Verify password")
echoMode: TextField.Password
Layout.fillWidth: true
selectByMouse: true
}
Label {
text: qsTr("Account type")
Layout.alignment: Qt.AlignRight
}
ComboBox {
id: accountTypeCombo
model: [qsTr("Standard"), qsTr("Administrator")]
Layout.fillWidth: true
topInset: 0
bottomInset: 0
}
}
RowLayout {
id: footerLayout
spacing: FishUI.Units.largeSpacing
Button {
id: cancelButton
text: qsTr("Cancel")
onClicked: {
newUserItem.visible = false
newUserItem.clear()
}
Layout.fillWidth: true
}
Button {
id: addButton
text: qsTr("Add")
enabled: userNameField.text != "" &&
passwordField.text != "" &&
passwordField.text == verifyPasswordField.text
Layout.fillWidth: true
flat: true
onClicked: {
if (accountsManager.createUser(userNameField.text, "", accountTypeCombo.currentIndex)) {
newUserItem.visible = false
}
}
}
}
}
}
StandardButton {
id: _addUserButton
text: qsTr("Add user")
Layout.fillWidth: true
visible: !newUserItem.visible
onClicked: {
newUserItem.visible = true
userNameField.forceActiveFocus()
_scrollable.contentY = Math.max(newUserItem.y,
_scrollable.contentHeight)
}
}
Item {
height: FishUI.Units.largeSpacing
}
}
}
}