Warning, /plasma/plasma-workspace/kcms/users/src/ui/main.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de> 0003 SPDX-FileCopyrightText: 2020 Carson Black <uhhadd@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 import QtQuick 2.6 0009 import QtQuick.Layouts 1.3 0010 import QtQuick.Controls 2.5 as QQC2 0011 0012 import org.kde.kcmutils as KCM 0013 import org.kde.kirigami as Kirigami 0014 import org.kde.kirigamiaddons.components as KirigamiComponents 0015 import org.kde.plasma.kcm.users 1.0 as UsersKCM 0016 0017 KCM.ScrollViewKCM { 0018 id: root 0019 0020 title: i18n("Users") 0021 0022 sidebarMode: true 0023 LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft 0024 LayoutMirroring.childrenInherit: true 0025 0026 implicitWidth: Kirigami.Units.gridUnit * 15 0027 implicitHeight: Kirigami.Units.gridUnit * 27 0028 0029 actions: Kirigami.Action { 0030 icon.name: "list-add-symbolic" 0031 text: i18nc("@action:button As in, 'add new user'", "Add New") 0032 0033 onTriggered: { 0034 kcm.pop(); 0035 kcm.push("CreateUser.qml"); 0036 userList.currentIndex = -1; 0037 } 0038 } 0039 0040 // QML cannot update avatar image when override. By increasing this number and 0041 // appending it to image source with '?', we force avatar to reload 0042 property int avatarVersion: 0 0043 0044 function createUser(userName, realName, password, isAdministrator) { 0045 if (kcm.createUser(userName, realName, password, isAdministrator)) { 0046 userList.indexToActivate = userList.count; 0047 } 0048 } 0049 function deleteUser(uid, deleteData) { 0050 if (kcm.deleteUser(uid, deleteData)) { 0051 userList.indexToActivate = userList.count - 1; 0052 } 0053 } 0054 0055 Connections { 0056 target: kcm 0057 function onApply() { 0058 avatarVersion += 1 0059 } 0060 } 0061 0062 Component.onCompleted: { 0063 kcm.columnWidth = Kirigami.Units.gridUnit * 15 0064 kcm.push("UserDetailsPage.qml", { user: kcm.userModel.getLoggedInUser() }) 0065 } 0066 0067 view: ListView { 0068 id: userList 0069 0070 property int indexToActivate: -1 0071 0072 model: kcm.userModel 0073 0074 onCountChanged: { 0075 if (indexToActivate >= 0) { 0076 kcm.pop(); 0077 currentIndex = Math.min(indexToActivate, count - 1); 0078 const modelIndex = kcm.userModel.index(currentIndex, 0); 0079 const user = kcm.userModel.data(modelIndex, UsersKCM.UserModel.UserRole); 0080 kcm.push("UserDetailsPage.qml", { user }); 0081 indexToActivate = -1; 0082 } 0083 } 0084 section { 0085 property: "sectionHeader" 0086 delegate: Kirigami.ListSectionHeader { 0087 width: userList.width 0088 label: section 0089 } 0090 } 0091 0092 delegate: Kirigami.SubtitleDelegate { 0093 id: delegate 0094 0095 required property var model 0096 required property int index 0097 0098 property UsersKCM.User user: model.userObject 0099 0100 width: ListView.view.width 0101 0102 text: model.displayPrimaryName 0103 subtitle: model.displaySecondaryName 0104 0105 highlighted: index === userList.currentIndex 0106 0107 Accessible.description: `${delegate.ListView.section}, ${i18nc("@info:usagetip", "Press Space to edit the user profile")}` 0108 0109 onClicked: { 0110 userList.currentIndex = index; 0111 kcm.pop(); 0112 kcm.push("UserDetailsPage.qml", { user }); 0113 } 0114 0115 contentItem: RowLayout { 0116 spacing: Kirigami.Units.smallSpacing 0117 0118 KirigamiComponents.Avatar { 0119 source: model.decoration + '?' + avatarVersion // force reload after saving 0120 cache: false // avoid caching 0121 name: model.displayPrimaryName 0122 } 0123 0124 Kirigami.TitleSubtitle { 0125 Layout.fillWidth: true 0126 title: delegate.text 0127 subtitle: delegate.subtitle 0128 reserveSpaceForSubtitle: true 0129 selected: delegate.highlighted 0130 } 0131 } 0132 } 0133 } 0134 }