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 QtObject engine
20 property QtObject connection: Connections {
21 target: engine
22 function onErrorCode(errorCode, message, metadata) {
23 component.showError(errorCode, message, metadata);
24 }
25 }
26
27 property var errorsToShow: []
28 function showError(errorCode, errorMessage, errorMetadata) {
29 if (active === true) {
30 errorsToShow.push({
31 code: errorCode,
32 message: errorMessage,
33 metadata: errorMetadata
34 });
35 showNextError();
36 }
37 }
38 onVisibleChanged: displayThrottle.start()
39 property QtObject displayThrottle: Timer {
40 interval: Kirigami.Units.shortDuration
41 onTriggered: showNextError()
42 }
43 function showNextError() {
44 if (visible === false && errorsToShow.length > 0) {
45 currentError = errorsToShow.shift();
46 open();
47 }
48 }
49
50 property var currentError: null
51
52 RowLayout {
53 implicitWidth: Kirigami.Units.gridUnit * 10
54 spacing: Kirigami.Units.largeSpacing
55
56 Kirigami.Icon {
57 Layout.alignment: Qt.AlignVCenter
58 visible: source !== ""
59 source: {
60 if (currentError === null) {
61 return "";
62 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
63 return "accept_time_event";
64 } else {
65 return "dialog-warning";
66 }
67 }
68 }
69
70 Kirigami.SelectableLabel {
71 Layout.fillWidth: true
72 Layout.alignment: Qt.AlignVCenter
73 wrapMode: Text.Wrap
74 textFormat: TextEdit.AutoText
75 onLinkActivated: link => Qt.openUrlExternally(link)
76
77 text: {
78 if (currentError === null) {
79 return "";
80 } else if (currentError.code === NewStuff.ErrorCode.TryAgainLaterError) {
81 return currentError.message + "\n\n" + i18n("Please try again later.")
82 } else {
83 return currentError.message;
84 }
85 }
86 }
87 }
88}
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)
QAction * open(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:54:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.