Warning, /frameworks/knewstuff/src/qtquick/qml/private/ErrorDisplayer.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 import QtQuick
0008 import QtQuick.Layouts
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.newstuff as NewStuff
0011 
0012 Kirigami.PromptDialog {
0013     id: component
0014 
0015     title: i18ndc("knewstuff6", "Title for a dialog box which shows error messages", "An Error Occurred");
0016     standardButtons: Kirigami.Dialog.NoButton
0017 
0018     property bool active: true;
0019     property QtObject engine;
0020     property QtObject connection: Connections {
0021         target: engine
0022         function onErrorCode(errorCode, message, metadata) {
0023             component.showError(errorCode, message, metadata);
0024         }
0025     }
0026 
0027     property var errorsToShow: []
0028     function showError(errorCode, errorMessage, errorMetadata) {
0029         if (active === true) {
0030             errorsToShow.push({
0031                 code: errorCode,
0032                 message: errorMessage,
0033                 metadata: errorMetadata
0034             });
0035             showNextError();
0036         }
0037     }
0038     onVisibleChanged: displayThrottle.start()
0039     property QtObject displayThrottle: Timer {
0040         interval: Kirigami.Units.shortDuration
0041         onTriggered: showNextError();
0042     }
0043     function showNextError() {
0044         if (visible === false && errorsToShow.length > 0) {
0045             currentError = errorsToShow.shift();
0046             open();
0047         }
0048     }
0049 
0050     property var currentError: null
0051 
0052     RowLayout {
0053         implicitWidth: Kirigami.Units.gridUnit * 10
0054         spacing: Kirigami.Units.largeSpacing
0055 
0056         Kirigami.Icon {
0057             Layout.alignment: Qt.AlignVCenter
0058             visible: source !== ""
0059             source: {
0060                 if (currentError === null) {
0061                     return "";
0062                 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
0063                     return "accept_time_event";
0064                 } else {
0065                     return "dialog-warning";
0066                 }
0067             }
0068         }
0069 
0070         Kirigami.SelectableLabel {
0071             Layout.fillWidth: true
0072             Layout.alignment: Qt.AlignVCenter
0073             wrapMode: Text.Wrap
0074             textFormat: TextEdit.AutoText
0075             onLinkActivated: link => Qt.openUrlExternally(link)
0076 
0077             text: {
0078                 if (currentError === null) {
0079                     return "";
0080                 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
0081                     return currentError.message + "\n\n" + i18n("Please try again later.")
0082                 } else {
0083                     return currentError.message;
0084                 }
0085             }
0086         }
0087     }
0088 }