Warning, /plasma/plasma-desktop/desktoppackage/contents/applet/AppletError.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
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 import QtQuick.Controls 2.15 as QQC2
0011 import org.kde.plasma.core as PlasmaCore
0012 import org.kde.plasma.components 3.0 as PC3
0013 import org.kde.kirigami 2.20 as Kirigami
0014 import org.kde.plasma.plasmoid 2.0
0015
0016 PlasmoidItem {
0017 id: root
0018
0019 enum LayoutType {
0020 HorizontalPanel,
0021 VerticalPanel,
0022 Desktop,
0023 DesktopCompact
0024 }
0025
0026 property var errorInformation
0027
0028 readonly property real minimumPreferredWidth: Kirigami.Units.gridUnit * 12
0029 readonly property real minimumPreferredHeight: Kirigami.Units.gridUnit * 12
0030
0031 // To properly show the error message in panel
0032 readonly property int layoutForm: {
0033 if (fullRepresentationItem.width >= root.minimumPreferredWidth) {
0034 if (fullRepresentationItem.height >= root.minimumPreferredHeight) {
0035 return AppletError.Desktop;
0036 } else if (fullRepresentationItem.height >= Kirigami.Units.iconSizes.huge + root.fullRepresentationItem.buttonLayout.implicitHeight) {
0037 return AppletError.DesktopCompact;
0038 }
0039 }
0040
0041 return Plasmoid.formFactor === PlasmaCore.Types.Vertical ? AppletError.VerticalPanel : AppletError.HorizontalPanel;
0042 }
0043 preloadFullRepresentation: true
0044 fullRepresentation: GridLayout {
0045 id: fullRep
0046 property alias buttonLayout: buttonLayout
0047 Layout.minimumWidth: {
0048 switch (root.layoutForm) {
0049 case AppletError.Desktop:
0050 case AppletError.DesktopCompact:
0051 // [Icon] [Text]
0052 // [Button]
0053 // [Information]
0054 return Math.max(root.minimumPreferredWidth, buttonLayout.implicitWidth);
0055 case AppletError.VerticalPanel:
0056 // [Icon]
0057 // [Copy]
0058 // [Open]
0059 return Math.max(headerIcon.implicitWidth, buttonLayout.implicitWidth);
0060 case AppletError.HorizontalPanel:
0061 // [Icon] [Copy] [Open]
0062 return headingLayout.implicitWidth + rowSpacing + buttonLayout.implicitWidth;
0063 }
0064 }
0065 Layout.minimumHeight: {
0066 switch (root.layoutForm) {
0067 case AppletError.Desktop:
0068 return headingLayout.implicitHeight + fullRep.columnSpacing + buttonLayout.implicitHeight + fullRep.columnSpacing + fullContentView.implicitHeight;
0069 case AppletError.DesktopCompact:
0070 return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);
0071 case AppletError.VerticalPanel:
0072 return headingLayout.implicitHeight + fullRep.columnSpacing + buttonLayout.implicitHeight;
0073 case AppletError.HorizontalPanel:
0074 return Math.max(headingLayout.implicitHeight, buttonLayout.implicitHeight);
0075 }
0076 }
0077 // Same as systray popups
0078 Layout.preferredWidth: Kirigami.Units.gridUnit * 24
0079 Layout.preferredHeight: Kirigami.Units.gridUnit * 24
0080 Layout.maximumWidth: Kirigami.Units.gridUnit * 34
0081 Layout.maximumHeight: Kirigami.Units.gridUnit * 34
0082
0083 rowSpacing: textArea.topPadding
0084 columnSpacing: rowSpacing
0085 flow: {
0086 switch (root.layoutForm) {
0087 case AppletError.HorizontalPanel:
0088 return GridLayout.LeftToRight;
0089 default:
0090 return GridLayout.TopToBottom;
0091 }
0092 }
0093
0094 RowLayout {
0095 id: headingLayout
0096
0097 Layout.margins: root.layoutForm !== AppletError.Desktop ? 0 : Kirigami.Units.gridUnit
0098 Layout.maximumWidth: fullRep.width
0099 spacing: 0
0100 Layout.fillWidth: true
0101
0102 Kirigami.Icon {
0103 id: headerIcon
0104 implicitWidth: Math.min(Kirigami.Units.iconSizes.huge, fullRep.width, fullRep.height)
0105 implicitHeight: implicitWidth
0106
0107 activeFocusOnTab: true
0108 source: "dialog-error"
0109
0110 Accessible.description: heading.text
0111
0112 PlasmaCore.ToolTipArea {
0113 anchors.fill: parent
0114 enabled: !heading.visible || heading.truncated
0115 mainText: heading.text
0116 textFormat: Text.PlainText
0117 }
0118 }
0119
0120 Kirigami.Heading {
0121 id: heading
0122 visible: root.layoutForm !== AppletError.VerticalPanel
0123 // Descent is equal to the amount of space above and below capital letters.
0124 // Add descent to the sides to make the spacing around Latin text look more even.
0125 leftPadding: headingFontMetrics.descent
0126 rightPadding: headingFontMetrics.descent
0127 text: root.errorInformation && root.errorInformation.appletName ?
0128 i18nd("plasma_shell_org.kde.plasma.desktop", "Sorry! There was an error loading %1.", root.errorInformation.appletName)
0129 // This is just to suppress warnings. Users should never see this.
0130 : "No error information."
0131 textFormat: Text.PlainText
0132 level: 2
0133 wrapMode: Text.Wrap
0134 horizontalAlignment: Text.AlignHCenter
0135 verticalAlignment: Text.AlignVCenter
0136 elide: Text.ElideRight
0137 Layout.fillWidth: true
0138 Layout.maximumHeight: headerIcon.implicitHeight
0139
0140 FontMetrics {
0141 id: headingFontMetrics
0142 font: heading.font
0143 }
0144 }
0145 }
0146
0147 GridLayout {
0148 id: buttonLayout
0149
0150 Layout.alignment: Qt.AlignCenter
0151
0152 rowSpacing: fullRep.rowSpacing
0153 columnSpacing: parent.columnSpacing
0154 flow: {
0155 switch (root.layoutForm) {
0156 case AppletError.HorizontalPanel:
0157 case AppletError.VerticalPanel:
0158 return fullRep.flow;
0159 default:
0160 return GridLayout.LeftToRight;
0161 }
0162 }
0163
0164 PC3.Button {
0165 id: copyButton
0166 display: root.layoutForm === AppletError.HorizontalPanel || root.layoutForm === AppletError.VerticalPanel ? PC3.AbstractButton.IconOnly : PC3.AbstractButton.TextBesideIcon
0167 text: i18nd("plasma_shell_org.kde.plasma.desktop", "Copy to Clipboard")
0168 icon.name: "edit-copy"
0169 onClicked: {
0170 textArea.selectAll()
0171 textArea.copy()
0172 textArea.deselect()
0173 }
0174
0175 PlasmaCore.ToolTipArea {
0176 anchors.fill: parent
0177 enabled: parent.display === PC3.AbstractButton.IconOnly
0178 mainText: parent.text
0179 textFormat: Text.PlainText
0180 }
0181 }
0182
0183 Loader {
0184 id: compactContentLoader
0185 active: root.layoutForm !== AppletError.Desktop
0186 visible: active
0187 sourceComponent: PC3.Button {
0188 display: copyButton.display
0189 icon.name: "window-new"
0190 text: i18nd("plasma_shell_org.kde.plasma.desktop", "View Error Details…")
0191 checked: dialog.visible
0192 onClicked: dialog.visible = !dialog.visible
0193
0194 PlasmaCore.ToolTipArea {
0195 anchors.fill: parent
0196 enabled: parent.display === PC3.AbstractButton.IconOnly
0197 mainText: parent.text
0198 textFormat: Text.PlainText
0199 }
0200
0201 QQC2.ApplicationWindow {
0202 id: dialog
0203 flags: Qt.Dialog | Qt.WindowStaysOnTopHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint
0204 minimumWidth: dialogFontMetrics.height * 12
0205 + dialogTextArea.leftPadding + dialogTextArea.rightPadding
0206 minimumHeight: dialogFontMetrics.height * 12
0207 + dialogTextArea.topPadding + dialogTextArea.bottomPadding
0208 width: Kirigami.Units.gridUnit * 24
0209 height: Kirigami.Units.gridUnit * 24
0210 color: palette.base
0211 QQC2.ScrollView {
0212 id: dialogScrollView
0213 anchors.fill: parent
0214 QQC2.TextArea {
0215 id: dialogTextArea
0216 // HACK: silence binding loop warnings.
0217 // contentWidth seems to be causing the binding loop,
0218 // but contentWidth is read-only and we have no control
0219 // over how it is calculated.
0220 implicitWidth: 0
0221 wrapMode: TextEdit.Wrap
0222 text: textArea.text
0223 font.family: "monospace"
0224 readOnly: true
0225 selectByMouse: true
0226 background: null
0227 FontMetrics {
0228 id: dialogFontMetrics
0229 font: dialogTextArea.font
0230 }
0231 }
0232 background: null
0233 }
0234 }
0235 }
0236 }
0237 }
0238
0239 PC3.ScrollView {
0240 id: fullContentView
0241 // Not handled by a Loader because we need
0242 // TextEdit::copy() to copy to clipboard.
0243 visible: !compactContentLoader.active
0244 Layout.fillHeight: true
0245 Layout.fillWidth: true
0246 PC3.TextArea {
0247 id: textArea
0248 // HACK: silence binding loop warnings.
0249 // contentWidth seems to be causing the binding loop,
0250 // but contentWidth is read-only and we have no control
0251 // over how it is calculated.
0252 implicitWidth: 0
0253 wrapMode: TextEdit.Wrap
0254 text: root.errorInformation && root.errorInformation.errors ?
0255 root.errorInformation.errors.join("\n\n")
0256 // This is just to suppress warnings. Users should never see this.
0257 : "No error information."
0258 font.family: "monospace"
0259 readOnly: true
0260 selectByMouse: true
0261 }
0262 }
0263 }
0264 }