KNewStuff

ErrorDisplayer.qml
1/*
2 SPDX-FileCopyrightText: 2020 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9import org.kde.kirigami as Kirigami
10import org.kde.newstuff as NewStuff
11
12Kirigami.PromptDialog {
13 id: component
14
15 title: i18ndc("knewstuff6", "Title for a dialog box which shows error messages", "An Error Occurred");
16 standardButtons: Kirigami.Dialog.NoButton
17
18 property bool active: true
19 property NewStuff.Engine engine
20
21 readonly property Connections connection: Connections {
22 target: component.engine
23 function onErrorCode(errorCode, message, metadata) {
24 component.showError(errorCode, message, metadata);
25 }
26 }
27
28 property var errorsToShow: []
29 function showError(errorCode, errorMessage, errorMetadata) {
30 if (active === true) {
31 errorsToShow.push({
32 code: errorCode,
33 message: errorMessage,
34 metadata: errorMetadata
35 });
36 showNextError();
37 }
38 }
39 onVisibleChanged: displayThrottle.start()
40 property QtObject displayThrottle: Timer {
41 interval: Kirigami.Units.shortDuration
42 onTriggered: showNextError()
43 }
44 function showNextError() {
45 if (visible === false && errorsToShow.length > 0) {
46 currentError = errorsToShow.shift();
47 open();
48 }
49 }
50
51 property var currentError: null
52
53 RowLayout {
54 implicitWidth: Kirigami.Units.gridUnit * 10
55 spacing: Kirigami.Units.largeSpacing
56
57 Kirigami.Icon {
58 Layout.alignment: Qt.AlignVCenter
59 visible: source !== ""
60 source: {
61 if (currentError === null) {
62 return "";
63 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
64 return "accept_time_event";
65 } else {
66 return "dialog-warning";
67 }
68 }
69 }
70
71 Kirigami.SelectableLabel {
72 Layout.fillWidth: true
73 Layout.alignment: Qt.AlignVCenter
74 wrapMode: Text.Wrap
75 textFormat: TextEdit.AutoText
76 onLinkActivated: link => Qt.openUrlExternally(link)
77
78 text: {
79 if (currentError === null) {
80 return "";
81 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
82 return currentError.message + "\n\n" + i18n("Please try again later.")
83 } else {
84 return currentError.message;
85 }
86 }
87 }
88 }
89}
QString i18n(const char *text, const TYPE &arg...)
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
KIOCORE_EXPORT CopyJob * link(const QList< QUrl > &src, const QUrl &destDir, JobFlags flags=DefaultFlags)
const QList< QKeySequence > & open()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.