Warning, /plasma/kdeplasma-addons/applets/userswitcher/package/contents/ui/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Layouts 1.15
0009 import QtQuick.Window 2.15
0010 
0011 import org.kde.coreaddons 1.0 as KCoreAddons // kuser
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.config as KConfig  // KAuthorized.authorizeControlModule
0014 import org.kde.plasma.components 3.0 as PlasmaComponents3
0015 import org.kde.plasma.core as PlasmaCore
0016 import org.kde.kirigami 2.20 as Kirigami
0017 import org.kde.kirigamiaddons.components 1.0 as KirigamiComponents
0018 import org.kde.plasma.plasmoid 2.0
0019 
0020 import org.kde.plasma.private.sessions 2.0 as Sessions
0021 
0022 PlasmoidItem {
0023     id: root
0024 
0025     readonly property bool isVertical: Plasmoid.formFactor === PlasmaCore.Types.Vertical
0026     readonly property bool inPanel: (Plasmoid.location === PlasmaCore.Types.TopEdge
0027         || Plasmoid.location === PlasmaCore.Types.RightEdge
0028         || Plasmoid.location === PlasmaCore.Types.BottomEdge
0029         || Plasmoid.location === PlasmaCore.Types.LeftEdge)
0030 
0031 
0032     readonly property string displayedName: showFullName ? kuser.fullName : kuser.loginName
0033 
0034     readonly property bool showFace: Plasmoid.configuration.showFace
0035     readonly property bool showName: Plasmoid.configuration.showName
0036     readonly property string avatarIcon: kuser.faceIconUrl.toString()
0037 
0038     readonly property bool showFullName: Plasmoid.configuration.showFullName
0039 
0040     // TTY number and X display
0041     readonly property bool showTechnicalInfo: Plasmoid.configuration.showTechnicalInfo
0042 
0043     switchWidth: Kirigami.Units.gridUnit * 10
0044     switchHeight: Kirigami.Units.gridUnit * 12
0045 
0046     toolTipTextFormat: Text.StyledText
0047     toolTipSubText: i18n("You are logged in as <b>%1</b>", displayedName)
0048 
0049     // revert to the Plasmoid icon if no face given
0050     Plasmoid.icon: kuser.faceIconUrl.toString() || (inPanel ? "system-switch-user-symbolic" : "preferences-system-users" )
0051 
0052     KCoreAddons.KUser {
0053         id: kuser
0054     }
0055 
0056     compactRepresentation: MouseArea {
0057         id: compactRoot
0058 
0059         // Taken from DigitalClock to ensure uniform sizing when next to each other
0060         readonly property bool tooSmall: Plasmoid.formFactor === PlasmaCore.Types.Horizontal && Math.round(2 * (compactRoot.height / 5)) <= Kirigami.Theme.smallFont.pixelSize
0061 
0062         Layout.minimumWidth: isVertical ? 0 : compactRow.implicitWidth
0063         Layout.maximumWidth: isVertical ? Infinity : Layout.minimumWidth
0064         Layout.preferredWidth: isVertical ? -1 : Layout.minimumWidth
0065 
0066         Layout.minimumHeight: isVertical ? label.height : Kirigami.Theme.smallFont.pixelSize
0067         Layout.maximumHeight: isVertical ? Layout.minimumHeight : Infinity
0068         Layout.preferredHeight: isVertical ? Layout.minimumHeight : Kirigami.Units.iconSizes.sizeForLabels * 2
0069 
0070         property bool wasExpanded
0071         onPressed: wasExpanded = root.expanded
0072         onClicked: root.expanded = !wasExpanded
0073 
0074         Row {
0075             id: compactRow
0076 
0077             anchors.centerIn: parent
0078             spacing: Kirigami.Units.smallSpacing
0079 
0080             KirigamiComponents.Avatar {
0081                 id: icon
0082 
0083                 anchors.verticalCenter: parent.verticalCenter
0084                 height: compactRoot.height - Math.round(Kirigami.Units.smallSpacing / 2)
0085                 width: height
0086 
0087                 name: root.displayedName
0088 
0089                 source: visible ? root.avatarIcon : ""
0090                 visible: root.showFace
0091             }
0092 
0093             PlasmaComponents3.Label {
0094                 id: label
0095 
0096                 width: root.isVertical ? compactRoot.width : contentWidth
0097                 height: root.isVertical ? contentHeight : compactRoot.height
0098 
0099                 text: root.displayedName
0100                 textFormat: Text.PlainText
0101                 horizontalAlignment: Text.AlignHCenter
0102                 verticalAlignment: Text.AlignVCenter
0103                 wrapMode: Text.NoWrap
0104                 fontSizeMode: root.isVertical ? Text.HorizontalFit : Text.VerticalFit
0105                 font.pixelSize: tooSmall ? Kirigami.Theme.defaultFont.pixelSize : Kirigami.Units.iconSizes.roundedIconSize(Kirigami.Units.gridUnit * 2)
0106                 minimumPointSize: Kirigami.Theme.smallFont.pointSize
0107                 visible: root.showName
0108             }
0109         }
0110     }
0111 
0112     fullRepresentation: Item {
0113         id: fullRoot
0114 
0115         implicitHeight: column.implicitHeight
0116         implicitWidth: column.implicitWidth
0117 
0118         Layout.preferredWidth: Kirigami.Units.gridUnit * 12
0119         Layout.preferredHeight: implicitHeight
0120         Layout.minimumWidth: Layout.preferredWidth
0121         Layout.minimumHeight: Layout.preferredHeight
0122         Layout.maximumWidth: Layout.preferredWidth
0123         Layout.maximumHeight: Screen.height / 2
0124 
0125         Sessions.SessionManagement {
0126             id: sm
0127         }
0128 
0129         Sessions.SessionsModel {
0130             id: sessionsModel
0131         }
0132 
0133         ColumnLayout {
0134             id: column
0135 
0136             anchors.fill: parent
0137             spacing: 0
0138 
0139             UserListDelegate {
0140                 id: currentUserItem
0141                 text: root.displayedName
0142                 subText: i18n("Current user")
0143                 source: root.avatarIcon
0144                 hoverEnabled: false
0145             }
0146 
0147             PlasmaComponents3.ScrollView {
0148                 id: scroll
0149 
0150                 Layout.fillWidth: true
0151                 Layout.fillHeight: true
0152 
0153                 // HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
0154                 PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
0155 
0156                 ListView {
0157                     id: userList
0158                     model: sessionsModel
0159 
0160                     focus: true
0161                     interactive: true
0162                     keyNavigationWraps: true
0163 
0164                     delegate: UserListDelegate {
0165                         width: ListView.view.width
0166 
0167                         activeFocusOnTab: true
0168 
0169                         text: {
0170                             if (!model.session) {
0171                                 return i18nc("Nobody logged in on that session", "Unused")
0172                             }
0173 
0174                             if (model.realName && root.showFullName) {
0175                                 return model.realName
0176                             }
0177 
0178                             return model.name
0179                         }
0180                         source: model.icon
0181                         subText: {
0182                             if (!root.showTechnicalInfo) {
0183                                 return ""
0184                             }
0185 
0186                             if (model.isTty) {
0187                                 return i18nc("User logged in on console number", "TTY %1", model.vtNumber)
0188                             } else if (model.displayNumber) {
0189                                 return i18nc("User logged in on console (X display number)", "on %1 (%2)", model.vtNumber, model.displayNumber)
0190                             }
0191                             return ""
0192                         }
0193 
0194                         KeyNavigation.up: index === 0 ? currentUserItem.nextItemInFocusChain() : userList.itemAtIndex(index - 1)
0195                         KeyNavigation.down: index === userList.count - 1 ? newSessionButton : userList.itemAtIndex(index + 1)
0196 
0197                         Accessible.description: i18nc("@action:button", "Switch to User %1", text)
0198 
0199                         onClicked: sessionsModel.switchUser(model.vtNumber, sessionsModel.shouldLock)
0200                     }
0201                 }
0202             }
0203 
0204             ActionListDelegate {
0205                 id: newSessionButton
0206                 text: i18nc("@action", "New Session")
0207                 icon.name: "system-switch-user"
0208                 visible: sessionsModel.canStartNewSession
0209 
0210                 KeyNavigation.up: userList.count > 0 ? userList.itemAtIndex(userList.count - 1) : currentUserItem.nextItemInFocusChain()
0211                 KeyNavigation.down: lockScreenButton
0212 
0213                 onClicked: sessionsModel.startNewSession(sessionsModel.shouldLock)
0214             }
0215 
0216             ActionListDelegate {
0217                 id: lockScreenButton
0218                 text: i18nc("@action", "Lock Screen")
0219                 icon.name: "system-lock-screen"
0220                 visible: sm.canLock
0221 
0222                 KeyNavigation.up: newSessionButton
0223                 KeyNavigation.down: leaveButton
0224 
0225                 onClicked: sm.lock()
0226             }
0227 
0228             ActionListDelegate {
0229                 id: leaveButton
0230                 text: i18nc("Show a dialog with options to logout/shutdown/restart", "Log Out")
0231                 icon.name: "system-log-out"
0232                 visible: sm.canLogout
0233 
0234                 KeyNavigation.up: lockScreenButton
0235 
0236                 onClicked: sm.requestLogout()
0237             }
0238         }
0239 
0240         Connections {
0241             target: root
0242             function onExpandedChanged() {
0243                 if (root.expanded) {
0244                     sessionsModel.reload();
0245                 }
0246             }
0247         }
0248     }
0249 }