Warning, /plasma/plasma-workspace/components/dialogs/SystemDialog.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
0003 *
0004 * SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15
0009 import QtQuick.Layouts 1.15
0010 import QtQuick.Window 2.15
0011 import Qt5Compat.GraphicalEffects
0012 import org.kde.kirigami 2.18 as Kirigami
0013 import org.kde.plasma.lookandfeel 1.0
0014
0015 /**
0016 * Component to create CSD dialogs that come from the system.
0017 */
0018 Kirigami.AbstractApplicationWindow {
0019 id: root
0020
0021 title: mainText
0022 /**
0023 * Main text of the dialog.
0024 */
0025 property string mainText: title
0026
0027 /**
0028 * Subtitle of the dialog.
0029 */
0030 property string subtitle: ""
0031
0032 /**
0033 * This property holds the icon used in the dialog.
0034 */
0035 property string iconName: ""
0036
0037 /**
0038 * This property holds the list of actions for this dialog.
0039 *
0040 * Each action will be rendered as a button that the user will be able
0041 * to click.
0042 */
0043 property list<Kirigami.Action> actions
0044
0045 default property Item mainItem
0046
0047 /**
0048 * This property holds the QQC2 DialogButtonBox used in the footer of the dialog.
0049 */
0050 readonly property DialogButtonBox dialogButtonBox: contentDialog.item.dialogButtonBox
0051
0052 /**
0053 * Provides dialogButtonBox.standardButtons
0054 *
0055 * Useful to be able to set it as dialogButtonBox will be null as the object gets built
0056 */
0057 property var standardButtons: contentDialog.item?.dialogButtonBox.standardButtons
0058
0059 /**
0060 * Controls whether the accept button is enabled
0061 */
0062 property bool acceptable: true
0063
0064
0065 /**
0066 * The layout of the action buttons in the footer of the dialog.
0067 *
0068 * By default, if there are more than 3 actions, it will have `Qt.Vertical`.
0069 *
0070 * Otherwise, with zero to 2 actions, it will have `Qt.Horizontal`.
0071 *
0072 * This will only affect mobile dialogs.
0073 */
0074 property int /*Qt.Orientation*/ layout: actions.length > 3 ? Qt.Vertical : Qt.Horizontal
0075
0076 flags: contentDialog.item.flags
0077 width: contentDialog.implicitWidth
0078 height: contentDialog.implicitHeight
0079 visible: false
0080 minimumHeight: contentDialog.item.minimumHeight
0081 minimumWidth: contentDialog.item.minimumWidth
0082
0083 function present() {
0084 contentDialog.item.present()
0085 }
0086 signal accept()
0087 signal reject()
0088 property bool accepted: false
0089 onAccept: {
0090 accepted = true
0091 close()
0092 }
0093 onReject: close()
0094
0095 onVisibleChanged: {
0096 if (!visible && !accepted) {
0097 root.reject()
0098 }
0099 width = Qt.binding(() => contentDialog.implicitWidth)
0100 height = Qt.binding(() => contentDialog.implicitHeight)
0101 }
0102
0103 Binding {
0104 target: dialogButtonBox.standardButton(DialogButtonBox.Ok)
0105 property: "enabled"
0106 when: dialogButtonBox.standardButton(DialogButtonBox.Ok)
0107 value: root.acceptable
0108 }
0109
0110 Loader {
0111 id: contentDialog
0112 anchors.fill: parent
0113 Component.onCompleted: {
0114 var component = LookAndFeel.fileUrl("systemdialogscript")
0115 setSource(component, {
0116 window: root,
0117 mainText: root.mainText,
0118 subtitle: root.subtitle,
0119 actions: root.actions,
0120 iconName: root.iconName,
0121 mainItem: root.mainItem,
0122 standardButtons: root.standardButtons
0123 })
0124 }
0125
0126 focus: true
0127
0128 function accept() {
0129 const button = dialogButtonBox.standardButton(DialogButtonBox.Ok);
0130 if (button && button.enabled) {
0131 root.accept()
0132 }
0133 }
0134 Keys.onEnterPressed: accept()
0135 Keys.onReturnPressed: accept()
0136 Keys.onEscapePressed: root.reject()
0137 }
0138 }