From e86111ed55781502832d58539471f7e6ea360fa8 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Tue, 22 Jun 2021 12:18:37 +0200 Subject: [PATCH] Move error list to settings page (as overlaysheet) --- src/CMakeLists.txt | 1 + src/qml/DownloadSwipePage.qml | 9 ---- src/qml/ErrorListOverlay.qml | 99 +++++++++++++++++++++++++++++++++++ src/qml/ErrorListPage.qml | 86 ------------------------------ src/qml/ErrorNotification.qml | 52 ++++++++++++++++++ src/qml/SettingsPage.qml | 14 ++++- src/qml/main.qml | 26 +++------ src/resources.qrc | 3 +- 8 files changed, 173 insertions(+), 117 deletions(-) create mode 100644 src/qml/ErrorListOverlay.qml delete mode 100644 src/qml/ErrorListPage.qml create mode 100644 src/qml/ErrorNotification.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index def5e0c3..b0b52048 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,7 @@ if(ANDROID) arrow-down overflow-menu checkbox + error ) else() target_link_libraries(kasts PRIVATE Qt::Widgets Qt::DBus) diff --git a/src/qml/DownloadSwipePage.qml b/src/qml/DownloadSwipePage.qml index 4f2e96d5..5908c29d 100644 --- a/src/qml/DownloadSwipePage.qml +++ b/src/qml/DownloadSwipePage.qml @@ -55,11 +55,6 @@ Kirigami.Page { height: tabBarHeight text: i18n("Completed") } - Controls.TabButton { - width: parent.parent.width / parent.count - height: tabBarHeight - text: i18n("Error Log") - } } } @@ -84,9 +79,5 @@ Kirigami.Page { title: i18n("Completed") episodeType: EpisodeModel.Downloaded } - - ErrorListPage { - title: i18n("Error Log") - } } } diff --git a/src/qml/ErrorListOverlay.qml b/src/qml/ErrorListOverlay.qml new file mode 100644 index 00000000..b4237642 --- /dev/null +++ b/src/qml/ErrorListOverlay.qml @@ -0,0 +1,99 @@ +/** + * SPDX-FileCopyrightText: 2021 Bart De Vries + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +import QtQuick 2.14 +import QtQuick.Controls 2.14 as Controls +import QtQuick.Layouts 1.14 +import QtGraphicalEffects 1.15 + +import org.kde.kirigami 2.15 as Kirigami + +import org.kde.kasts 1.0 + +Kirigami.OverlaySheet { + id: errorOverlay + + showCloseButton: true + + header: Kirigami.Heading { + text: i18n("Error Log") + level: 2 + wrapMode: Text.Wrap + } + + footer: Controls.DialogButtonBox { + Controls.Button { + text: i18n("Clear All Errors") + icon.name: "edit-clear-all" + onClicked: ErrorLogModel.clearAll() + enabled: errorList.count > 0 + } + } + + + Kirigami.PlaceholderMessage { + id: placeholder + visible: errorList.count == 0 + + text: i18n("No Errors Logged") + } + + ListView { + id: errorList + visible: errorList.count > 0 + implicitWidth: Kirigami.Units.gridUnit * 20 + model: ErrorLogModel + + Component { + id: errorListDelegate + Kirigami.SwipeListItem { + // workaround to get rid of "_swipeFilter" errors + alwaysVisibleActions: true + contentItem: RowLayout { + Kirigami.Icon { + source: "data-error" + property int size: Kirigami.Units.iconSizes.medium + Layout.preferredHeight: size + Layout.preferredWidth: size + } + ColumnLayout { + spacing: Kirigami.Units.smallSpacing + Layout.fillWidth: true + Layout.alignment: Qt.AlignVCenter + Controls.Label { + text: error.description + " · " + error.date.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + " · " + error.date.toLocaleTimeString(Qt.locale(), Locale.NarrowFormat) + Layout.fillWidth: true + elide: Text.ElideRight + font: Kirigami.Theme.smallFont + opacity: 0.7 + } + Controls.Label { + text: error.title + Layout.fillWidth: true + elide: Text.ElideRight + font.weight: Font.Normal + opacity: 1 + } + Controls.Label { + text: i18n("Error Code: ") + error.code + (error.message ? " · " + error.message : "") + Layout.fillWidth: true + elide: Text.ElideRight + font: Kirigami.Theme.smallFont + opacity: 0.7 + } + } + } + } + } + + delegate: Kirigami.DelegateRecycler { + width: errorList.width + sourceComponent: errorListDelegate + } + } + + contentItem: errorList.count > 0 ? errorList : placeholder +} diff --git a/src/qml/ErrorListPage.qml b/src/qml/ErrorListPage.qml deleted file mode 100644 index 268db1c6..00000000 --- a/src/qml/ErrorListPage.qml +++ /dev/null @@ -1,86 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2021 Bart De Vries - * - * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL - */ - -import QtQuick 2.14 -import QtQuick.Controls 2.14 as Controls -import QtQuick.Layouts 1.14 -import QtGraphicalEffects 1.15 - -import org.kde.kirigami 2.15 as Kirigami - -import org.kde.kasts 1.0 - -Kirigami.ScrollablePage { - - padding: 0 - - Kirigami.PlaceholderMessage { - visible: errorList.count === 0 - - width: Kirigami.Units.gridUnit * 20 - anchors.centerIn: parent - - text: i18n("No Errors Logged") - } - - Component { - id: errorListDelegate - Kirigami.SwipeListItem { - contentItem: RowLayout { - Kirigami.Icon { - source: "data-error" - property int size: Kirigami.Units.iconSizes.medium - Layout.preferredHeight: size - Layout.preferredWidth: size - } - ColumnLayout { - spacing: Kirigami.Units.smallSpacing - Layout.fillWidth: true - Layout.alignment: Qt.AlignVCenter - Controls.Label { - text: error.description + " · " + error.date.toLocaleDateString(Qt.locale(), Locale.NarrowFormat) + " · " + error.date.toLocaleTimeString(Qt.locale(), Locale.NarrowFormat) - Layout.fillWidth: true - elide: Text.ElideRight - font: Kirigami.Theme.smallFont - opacity: 0.7 - } - Controls.Label { - text: error.title - Layout.fillWidth: true - elide: Text.ElideRight - font.weight: Font.Normal - opacity: 1 - } - Controls.Label { - text: i18n("Error Code: ") + error.code + (error.message ? " · " + error.message : "") - Layout.fillWidth: true - elide: Text.ElideRight - font: Kirigami.Theme.smallFont - opacity: 0.7 - } - } - } - } - } - - ListView { - id: errorList - anchors.fill: parent - visible: count !== 0 - model: ErrorLogModel - - delegate: Kirigami.DelegateRecycler { - width: errorList.width - sourceComponent: errorListDelegate - } - } - actions.main: Kirigami.Action { - text: i18n("Clear All Errors") - iconName: "edit-clear-all" - visible: errorList.count > 0 - onTriggered: ErrorLogModel.clearAll() - } -} \ No newline at end of file diff --git a/src/qml/ErrorNotification.qml b/src/qml/ErrorNotification.qml new file mode 100644 index 00000000..26eaf57f --- /dev/null +++ b/src/qml/ErrorNotification.qml @@ -0,0 +1,52 @@ +/** + * SPDX-FileCopyrightText: 2021 Bart De Vries + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +import QtQuick 2.14 +import QtQuick.Layouts 1.14 +import QtQuick.Controls 2.14 as Controls + +import org.kde.kirigami 2.15 as Kirigami + +import org.kde.kasts 1.0 + +Kirigami.InlineMessage { + id: inlineMessage + anchors { + bottom: parent.bottom + right: parent.right + left: parent.left + margins: Kirigami.Units.gridUnit + bottomMargin: bottomMessageSpacing + } + type: Kirigami.MessageType.Error + showCloseButton: true + + actions: [ + Kirigami.Action { + icon.name: "error" + text: "Show Error Log" + onTriggered: errorOverlay.open() + } + ] + + Timer { + id: hideTimer + + interval: 10000 + repeat: false + + onTriggered: inlineMessage.visible = false; + } + + Connections { + target: ErrorLogModel + function onNewErrorLogged(error) { + inlineMessage.text = error.description; + inlineMessage.visible = true; + hideTimer.start(); + } + } +} diff --git a/src/qml/SettingsPage.qml b/src/qml/SettingsPage.qml index cd4a10cc..d2486da8 100644 --- a/src/qml/SettingsPage.qml +++ b/src/qml/SettingsPage.qml @@ -10,13 +10,12 @@ import QtQuick.Controls 2.14 as Controls import QtQuick.Layouts 1.14 import org.kde.kirigami 2.12 as Kirigami + import org.kde.kasts 1.0 Kirigami.ScrollablePage { title: i18n("Settings") - // TODO: Remove old kasts settings from the kcfg and the qml code - Kirigami.FormLayout { Kirigami.Heading { @@ -104,5 +103,16 @@ Kirigami.ScrollablePage { onToggled: SettingsManager.articleFontUseSystem = checked } + + Kirigami.Heading { + Kirigami.FormData.isSection: true + text: i18n("Errors") + } + + Controls.Button { + icon.name: "error" + text: i18n("Show Error Log") + onClicked: errorOverlay.open() + } } } diff --git a/src/qml/main.qml b/src/qml/main.qml index b5731ed8..5bd2d1d5 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -203,28 +203,16 @@ Kirigami.ApplicationWindow { anchors { horizontalCenter: parent.horizontalCenter bottom: parent.bottom - bottomMargin: bottomMessageSpacing + ( inlineMessage.visible ? inlineMessage.height + Kirigami.Units.largeSpacing : 0 ) + bottomMargin: bottomMessageSpacing + ( errorNotification.visible ? errorNotification.height + Kirigami.Units.largeSpacing : 0 ) } } - Kirigami.InlineMessage { - id: inlineMessage - anchors { - bottom: parent.bottom - right: parent.right - left: parent.left - margins: Kirigami.Units.gridUnit - bottomMargin: bottomMessageSpacing - } - type: Kirigami.MessageType.Error - showCloseButton: true + ErrorNotification { + id: errorNotification + } - Connections { - target: ErrorLogModel - function onNewErrorLogged(error) { - inlineMessage.text = error.description + "\n" + i18n("Check Error Log Tab (under Downloads) for more details"); - inlineMessage.visible = true; - } - } + // overlay with log of all errors that have happened + ErrorListOverlay { + id: errorOverlay } } diff --git a/src/resources.qrc b/src/resources.qrc index 0f5a5c1b..16e7f489 100755 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -16,7 +16,7 @@ qml/FooterBar.qml qml/QueuePage.qml qml/EpisodeListPage.qml - qml/ErrorListPage.qml + qml/ErrorListOverlay.qml qml/EpisodeSwipePage.qml qml/DownloadSwipePage.qml qml/GenericHeader.qml @@ -24,6 +24,7 @@ qml/ImageWithFallback.qml qml/UpdateNotification.qml qml/HeaderBar.qml + qml/ErrorNotification.qml qtquickcontrols2.conf ../kasts.svg