1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick 2.6
import QtQuick.Dialogs 1.1 as Dialogs
import QtGraphicalEffects 1.12
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.5 as QQC2
import org.kde.kcm 1.2 as KCM
import org.kde.kirigami 2.13 as Kirigami
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.plasma.kcm.users 1.0
KCM.ScrollViewKCM {
id: root
title: i18n("Manage Users")
// Make the first page a sidebar
Kirigami.ColumnView.fillWidth: false
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
implicitWidth: Kirigami.Units.gridUnit * 30
implicitHeight: Kirigami.Units.gridUnit * 20
// Override default false value here as it doesn't really work with the
// layout we have here with two pages adjacent to one another
framedView: true
// QML cannot update avatar image when override. By increasing this number and
// appending it to image source with '?', we force avatar to reload
property int avatarVersion: 0
function createUser(userName, realName, password, isAdministrator) {
if (kcm.createUser(userName, realName, password, isAdministrator)) {
userList.indexToActivate = userList.count
}
}
function deleteUser(uid, deleteData) {
if (kcm.deleteUser(uid, deleteData)) {
userList.indexToActivate = userList.count-1
}
}
Connections {
target: kcm
function onApply() {
avatarVersion += 1
}
}
Component.onCompleted: {
kcm.columnWidth = Kirigami.Units.gridUnit * 15
kcm.push("UserDetailsPage.qml", {user: kcm.userModel.getLoggedInUser()})
}
view: ListView {
id: userList
model: kcm.userModel
property int indexToActivate: -1
onCountChanged: {
if (indexToActivate >= 0) {
kcm.pop();
currentIndex = Math.min(Math.max(0, indexToActivate), count - 1);
kcm.push("UserDetailsPage.qml", {user: currentItem.userObject});
indexToActivate = -1;
}
}
section {
property: "sectionHeader"
delegate: Kirigami.ListSectionHeader {
label: section
}
}
delegate: Kirigami.BasicListItem {
text: model.displayPrimaryName
subtitle: model.displaySecondaryName
reserveSpaceForSubtitle: true
property var userObject: model.userObject
highlighted: index == userList.currentIndex
onClicked: {
userList.currentIndex = index
kcm.pop(0)
kcm.push("UserDetailsPage.qml", {user: userObject})
}
Kirigami.Theme.colorSet: highlighted ? Kirigami.Theme.Selection : Kirigami.Theme.View
leading: Rectangle {
width: height
color: "transparent"
border.color: Kirigami.ColorUtils.adjustColor(Kirigami.Theme.textColor, {alpha: 0.4*255})
border.width: 1
radius: height/2
Kirigami.Avatar {
source: model.decoration + '?' + avatarVersion // force reload after saving
cache: false // avoid caching
name: model.displayPrimaryName
anchors {
fill: parent
margins: 1
}
}
}
}
}
footer: RowLayout {
QQC2.Button {
icon.name: "list-add"
text: i18n("Add New User")
onClicked: {
kcm.pop(0)
kcm.push("CreateUser.qml")
userList.currentIndex = -1
}
}
Item {
Layout.fillWidth: true
}
}
Item {} // For some reason, this being here keeps the layout from breaking.
}
|