add password dialog
This commit is contained in:
@@ -36,6 +36,7 @@ qt_add_qml_module(apparchpack
|
||||
qml/console/ConsoleBar.qml
|
||||
qml/console/ConsolePanel.qml
|
||||
qml/lists/PackageList.qml
|
||||
qml/dialogs/PasswordDialog.qml
|
||||
SOURCES
|
||||
cpp/utils/utils.hpp
|
||||
cpp/utils/utils.cpp
|
||||
|
||||
24
Main.qml
24
Main.qml
@@ -5,6 +5,7 @@ import QtQuick.Layouts
|
||||
import "qml/components" as Components
|
||||
import "qml/pages" as Pages
|
||||
import "qml/buttons" as Buttons
|
||||
import "qml/dialogs" as Dialogs
|
||||
|
||||
ApplicationWindow {
|
||||
id: root
|
||||
@@ -108,21 +109,28 @@ ApplicationWindow {
|
||||
// consoleLogData: root.consoleLogData
|
||||
// }
|
||||
|
||||
Dialogs.PasswordDialog {
|
||||
id: passwordDialog
|
||||
onPasswordEntered: (password) => {
|
||||
root.sessionPassword = password
|
||||
root.runPrivileged(passwordDialog.action, passwordDialog.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
function requestPrivileged(action, packageName) {
|
||||
if (root.sessionPassword !== "") {
|
||||
root.runPrivileged(action, packageName, root.sessionPassword)
|
||||
root.runPrivileged(action, packageName)
|
||||
return
|
||||
}
|
||||
|
||||
console.log("requestPrivileged")
|
||||
// passwordDialog.action = action
|
||||
// passwordDialog.packageName = packageName
|
||||
// passwordDialog.open()
|
||||
passwordDialog.action = action
|
||||
passwordDialog.packageName = packageName
|
||||
passwordDialog.open()
|
||||
}
|
||||
|
||||
function runPrivileged(action, packageName, password) {
|
||||
console.log("runPrivileged")
|
||||
// if (action == "update") UpdateManager.update(password, root.packageManager)
|
||||
function runPrivileged(action, packageName) {
|
||||
console.log("runPrivileged", root.sessionPassword)
|
||||
if (action == "update") UpdateManager.update(root.sessionPassword, root.packageManager)
|
||||
// else if (action === "install") UpdateManager.installPackage(packageName, password)
|
||||
// else UpdateManager.removePackage(packageName, password)
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ class UpdateManager : public QObject
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void checkUpdates();
|
||||
Q_INVOKABLE void update(const QString& password, const QString& packageManager);
|
||||
|
||||
private:
|
||||
void set_packages(const QVariantList& value);
|
||||
|
||||
144
qml/dialogs/PasswordDialog.qml
Normal file
144
qml/dialogs/PasswordDialog.qml
Normal file
@@ -0,0 +1,144 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import archpack
|
||||
|
||||
Dialog {
|
||||
id: root
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
width: 380
|
||||
padding: 16
|
||||
modal: true
|
||||
parent: Overlay.overlay
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
|
||||
// "update" — обновление системы, "install" — установка одного пакета.
|
||||
property string action: "update"
|
||||
property string packageName: ""
|
||||
|
||||
// Диалог только сообщает введённый пароль: какое действие запускать
|
||||
// и запоминать ли пароль на сеанс, решает Main.qml.
|
||||
signal passwordEntered(string password)
|
||||
|
||||
background: Rectangle {
|
||||
color: Theme.color1
|
||||
radius: 3
|
||||
border.width: 1
|
||||
border.color: Theme.color4
|
||||
}
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 10
|
||||
|
||||
Label {
|
||||
text: root.action === "install" ? "Для установки нужны права root" : root.action === "remove" ? "Для удаления нужны права root" : "Для обновления нужны права root"
|
||||
color: Theme.color2
|
||||
font.pixelSize: 15
|
||||
font.bold: true
|
||||
wrapMode: Text.WordWrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Label {
|
||||
text: "Пароль пользователя:"
|
||||
color: Theme.color14
|
||||
font.pixelSize: 12
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: passwordField
|
||||
Layout.fillWidth: true
|
||||
placeholderText: "пароль"
|
||||
placeholderTextColor: Theme.color3
|
||||
echoMode: TextInput.Password
|
||||
selectByMouse: true
|
||||
color: Theme.color2
|
||||
font.pixelSize: 13
|
||||
|
||||
background: Rectangle {
|
||||
color: Theme.color5
|
||||
radius: 3
|
||||
border.width: 1
|
||||
border.color: passwordField.activeFocus ? Theme.color5 : Theme.color4
|
||||
}
|
||||
|
||||
onAccepted: if (okButton.enabled) root.accept()
|
||||
}
|
||||
}
|
||||
|
||||
footer: Item {
|
||||
implicitHeight: footerRow.implicitHeight + 22
|
||||
|
||||
RowLayout {
|
||||
id: footerRow
|
||||
anchors.fill: parent
|
||||
anchors.rightMargin: 18
|
||||
spacing: 8
|
||||
|
||||
Item { Layout.fillWidth: true }
|
||||
|
||||
Button {
|
||||
id: cancelButton
|
||||
text: "✕ Отмена"
|
||||
leftPadding: 14
|
||||
rightPadding: 14
|
||||
topPadding: 8
|
||||
bottomPadding: 8
|
||||
|
||||
onClicked: root.reject()
|
||||
|
||||
background: Rectangle {
|
||||
radius: 4
|
||||
color: cancelButton.down ? Theme.color4 : cancelButton.hovered ? Theme.color4 : Theme.colorTransparent
|
||||
border.width: 1
|
||||
border.color: Theme.color4
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
text: cancelButton.text
|
||||
font.pixelSize: 13
|
||||
color: Theme.color2
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: okButton
|
||||
text: root.action === "install" ? "✓ Установить" : root.action === "remove" ? "✓ Удалить" : "✓ Обновить"
|
||||
enabled: passwordField.text.length > 0
|
||||
leftPadding: 14
|
||||
rightPadding: 14
|
||||
topPadding: 8
|
||||
bottomPadding: 8
|
||||
|
||||
onClicked: root.accept()
|
||||
|
||||
background: Rectangle {
|
||||
radius: 4
|
||||
color: !okButton.enabled ? Theme.color5 : okButton.down ? Theme.color11 : okButton.hovered ? Theme.color6 : Theme.color10
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
text: okButton.text
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
color: okButton.enabled ? Theme.color8 : Theme.color12
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onOpened: passwordField.forceActiveFocus()
|
||||
|
||||
onAccepted: {
|
||||
root.passwordEntered(passwordField.text)
|
||||
}
|
||||
|
||||
onClosed: passwordField.text = ""
|
||||
}
|
||||
@@ -17,6 +17,7 @@ QtObject {
|
||||
readonly property color color11: "#6f8fd8"
|
||||
readonly property color color12: "#585b70"
|
||||
readonly property color color13: "#a6e3a1"
|
||||
readonly property color color14: "#a6adc8"
|
||||
|
||||
readonly property int fontSize: 12
|
||||
readonly property int fontTitleSize: 20
|
||||
|
||||
Reference in New Issue
Block a user