Warning, /plasma/polkit-kde-agent-1/qml/QuickAuthDialog.qml is written in an unsupported language. File is not indexed.
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Layouts 0010 import QtQuick.Controls as QQC2 0011 import org.kde.kirigami 2.19 as Kirigami 0012 import org.kde.polkitkde 1.0 0013 0014 Kirigami.AbstractApplicationWindow { 0015 id: root 0016 title: i18n("Authentication Required") 0017 0018 maximumHeight: intendedWindowHeight 0019 minimumHeight: intendedWindowHeight 0020 minimumWidth: intendedWindowWidth 0021 maximumWidth: intendedWindowWidth 0022 width: intendedWindowWidth 0023 height: intendedWindowHeight 0024 0025 property alias password: passwordField.text 0026 property alias inlineMessageType: inlineMessage.type 0027 property alias inlineMessageText: inlineMessage.text 0028 property alias inlineMessageIcon: inlineMessage.icon 0029 property alias identitiesModel: identitiesCombo.model 0030 property alias identitiesCurrentIndex: identitiesCombo.currentIndex 0031 property alias selectedIdentity: identitiesCombo.currentValue 0032 0033 // passed in by QuickAuthDialog.cpp 0034 property string mainText 0035 property string subtitle 0036 property string descriptionString 0037 property string descriptionActionId 0038 property string descriptionVendorName 0039 property string descriptionVendorUrl 0040 0041 signal accept() 0042 signal reject() 0043 0044 onAccept: { 0045 // disable password field while password is being checked 0046 if (passwordField.text !== "") { 0047 passwordField.enabled = false; 0048 } 0049 } 0050 0051 Shortcut { 0052 sequence: StandardKey.Cancel 0053 onActivated: root.reject() 0054 } 0055 0056 function authenticationFailure() { 0057 inlineMessage.type = Kirigami.MessageType.Error; 0058 inlineMessage.text = i18n("Authentication failure, please try again."); 0059 passwordField.clear() 0060 passwordField.enabled = true 0061 passwordField.focus = true 0062 rejectPasswordAnim.start(); 0063 } 0064 0065 readonly property real intendedWindowWidth: Kirigami.Units.gridUnit * 35 0066 // HACK: Window doesn't seem to automatically update height from binding, so manually set the height value 0067 readonly property real intendedWindowHeight: column.implicitHeight + column.anchors.topMargin + column.anchors.bottomMargin; 0068 onIntendedWindowHeightChanged: { 0069 minimumHeight = intendedWindowHeight; 0070 height = intendedWindowHeight; 0071 maximumHeight = intendedWindowHeight 0072 } 0073 0074 onActiveChanged: { 0075 if (active) { 0076 // immediately focus on password field when window is focused 0077 passwordField.forceActiveFocus(); 0078 } 0079 } 0080 0081 onVisibleChanged: { 0082 if (visible) { 0083 // immediately focus on password field on load 0084 passwordField.forceActiveFocus(); 0085 } else { 0086 // reject on close 0087 root.reject(); 0088 } 0089 } 0090 0091 // select user combobox, we are displaying its popup 0092 property QQC2.ComboBox selectIdentityCombobox: QQC2.ComboBox { 0093 id: identitiesCombo 0094 visible: false 0095 textRole: "display" 0096 valueRole: "userRole" 0097 enabled: count > 0 0098 model: IdentitiesModel { 0099 id: identitiesModel 0100 } 0101 } 0102 0103 // add separator to window decorations 0104 Kirigami.Separator { 0105 anchors.top: parent.top 0106 anchors.left: parent.left 0107 anchors.right: parent.right 0108 } 0109 0110 RejectPasswordAnimation { 0111 id: rejectPasswordAnim 0112 target: column 0113 } 0114 0115 // dialog contents 0116 ColumnLayout { 0117 id: column 0118 spacing: 0 0119 anchors.top: parent.top 0120 anchors.left: parent.left 0121 anchors.right: parent.right 0122 anchors.margins: Kirigami.Units.largeSpacing 0123 0124 RowLayout { 0125 Layout.fillWidth: true 0126 Layout.topMargin: Kirigami.Units.largeSpacing 0127 0128 Kirigami.Icon { 0129 Layout.leftMargin: Kirigami.Units.largeSpacing 0130 Layout.rightMargin: Kirigami.Units.gridUnit 0131 Layout.topMargin: Kirigami.Units.largeSpacing 0132 Layout.alignment: Qt.AlignTop 0133 source: "lock" 0134 implicitWidth: Kirigami.Units.iconSizes.huge 0135 implicitHeight: Kirigami.Units.iconSizes.huge 0136 } 0137 0138 ColumnLayout { 0139 Layout.fillWidth: true 0140 spacing: Kirigami.Units.largeSpacing 0141 0142 Kirigami.Heading { 0143 Layout.fillWidth: true 0144 level: 3 0145 text: root.mainText 0146 wrapMode: Text.Wrap 0147 font.weight: Font.Bold 0148 } 0149 0150 // user information, only shown if there is more than one user to select from 0151 Flow { 0152 spacing: Kirigami.Units.smallSpacing 0153 Layout.fillWidth: true 0154 Layout.bottomMargin: Kirigami.Units.smallSpacing 0155 0156 QQC2.Label { 0157 color: Kirigami.Theme.disabledTextColor 0158 text: i18n("Authenticating as %1", identitiesCombo.currentText) 0159 wrapMode: Text.Wrap 0160 } 0161 0162 Kirigami.LinkButton { 0163 id: switchButton 0164 text: i18n("Switch…") 0165 visible: identitiesCombo.count > 1 0166 onClicked: { 0167 identitiesCombo.popup.parent = switchButton; 0168 identitiesCombo.popup.open(); 0169 } 0170 } 0171 } 0172 0173 Kirigami.InlineMessage { 0174 id: inlineMessage 0175 Layout.fillWidth: true 0176 showCloseButton: true 0177 visible: text.length !== 0 0178 } 0179 0180 Kirigami.PasswordField { 0181 id: passwordField 0182 Layout.fillWidth: true 0183 onAccepted: root.accept() 0184 placeholderText: i18n("Password…") 0185 } 0186 0187 RowLayout { 0188 id: passwordRow 0189 Layout.fillWidth: true 0190 0191 QQC2.Button { 0192 id: details 0193 text: i18n("Details") 0194 icon.name: "documentinfo" 0195 checkable: true 0196 checked: false 0197 } 0198 0199 Item { 0200 Layout.fillWidth: true 0201 } 0202 0203 // TODO: I'm not using a DialogButtonBox right now since there is weird extra padding right on the component, is there a way to fix that? 0204 QQC2.Button { 0205 text: i18n("OK") 0206 icon.name: "dialog-ok" 0207 onClicked: root.accept() 0208 } 0209 0210 QQC2.Button { 0211 text: i18n("Cancel") 0212 icon.name: "dialog-cancel" 0213 onClicked: root.reject() 0214 } 0215 } 0216 } 0217 } 0218 0219 Kirigami.FormLayout { 0220 visible: details.checked 0221 Layout.bottomMargin: Kirigami.Units.largeSpacing 0222 QQC2.Label { 0223 Kirigami.FormData.label: i18n("Action:") 0224 text: descriptionString 0225 } 0226 QQC2.Label { 0227 Kirigami.FormData.label: i18n("ID:") 0228 text: descriptionActionId 0229 } 0230 Kirigami.UrlButton { 0231 Kirigami.FormData.label: i18n("Vendor:") 0232 text: descriptionVendorName 0233 url: descriptionVendorUrl 0234 } 0235 } 0236 } 0237 }