Commit df120641 authored by Nate Graham's avatar Nate Graham
Browse files

Allow more error page parameters to be customized to suit the error

Some errors might benefit from showing different explanatory text, or
having the button look different or take the user to a different page.
parent 17c8b6f7
......@@ -39,6 +39,7 @@
#include <KCrash>
#include <KLocalizedContext>
#include <KLocalizedString>
#include <KOSRelease>
#include <KSharedConfig>
#include <KStatusNotifierItem>
#include <KUiServerV2JobTracker>
......@@ -148,11 +149,16 @@ DiscoverObject::DiscoverObject(CompactMode mode, const QVariantMap &initialPrope
for (auto b : backends)
found |= b->hasApplications();
if (!found)
Q_EMIT openErrorPage(
i18n("Discover currently cannot be used to install any apps "
"because none of its app backends are available. Please "
"report this issue to the packagers of your distribution."));
if (!found) {
const QString errorText = i18n("Discover currently cannot be used to install "
"any apps because none of its app backends are available.");
const QString errorExplanation;
const QString buttonIcon = QStringLiteral("tools-report-bug");
const QString buttonText = i18n("Report This Issue");
const QString buttonUrl = KOSRelease().bugReportUrl();
Q_EMIT openErrorPage(errorText, errorExplanation, buttonText, buttonIcon, buttonUrl);
}
},
this);
......@@ -306,11 +312,15 @@ void DiscoverObject::openApplication(const QUrl &url)
openApplication(QUrl(QStringLiteral("appstream://org.kde.discover.snap")));
showPassiveNotification(i18n("Please make sure Snap support is installed"));
} else {
Q_EMIT openErrorPage(
i18n("Could not open %1 because it was not found in any "
"available software repositories. Please report this "
"issue to the packagers of your distribution.",
url.toDisplayString()));
const QString errorText = i18n("Could not open %1 because it "
"was not found in any available software repositories.",
url.toDisplayString());
const QString errorExplanation = i18n("Please report this "
"issue to the packagers of your distribution.");
QString buttonIcon = QStringLiteral("tools-report-bug");
QString buttonText = i18n("Report This Issue");
QString buttonUrl = KOSRelease().bugReportUrl();
Q_EMIT openErrorPage(errorText, errorExplanation, buttonText, buttonIcon, buttonUrl);
}
});
},
......
......@@ -80,7 +80,7 @@ Q_SIGNALS:
void compactModeChanged(DiscoverObject::CompactMode compactMode);
void unableToFind(const QString &resid);
void openErrorPage(const QString &errorMessage);
void openErrorPage(const QString &errorMessage, const QString &errorExplanation, const QString &buttonText, const QString &buttonIcon, const QString &buttonURL);
private:
void showLoadingPage();
......
......@@ -138,10 +138,10 @@ Kirigami.ApplicationWindow
Navigation.openApplicationList({search: search})
}
function onOpenErrorPage(errorMessage) {
function onOpenErrorPage(errorMessage, errorExplanation, buttonText, buttonIcon, buttonUrl) {
Navigation.clearStack()
console.warn("error", errorMessage)
window.stack.push(errorPageComponent, { error: errorMessage, title: i18n("Error") })
console.warn("Error: " + errorMessage + "\n" + errorExplanation + "\n" + "Please visit " + buttonUrl)
window.stack.push(errorPageComponent, { title: i18n("Error"), errorMessage: errorMessage, errorExplanation: errorExplanation, buttonText: buttonText, buttonIcon: buttonIcon, buttonUrl: buttonUrl })
}
function onUnableToFind(resid) {
......@@ -187,7 +187,11 @@ Kirigami.ApplicationWindow
id: errorPageComponent
Kirigami.Page {
id: page
property string error: ""
property string errorMessage: ""
property string errorExplanation: ""
property string buttonText: ""
property string buttonIcon: ""
property string buttonUrl: ""
readonly property bool isHome: true
function searchFor(text) {
if (text.length === 0)
......@@ -197,14 +201,15 @@ Kirigami.ApplicationWindow
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
width: parent.width - (Kirigami.Units.largeSpacing * 8)
visible: page.error !== ""
icon.name: "error"
text: page.error
visible: page.errorMessage !== ""
icon.name: "dialog-error"
text: page.errorMessage
explanation: page.errorExplanation
helpfulAction: Kirigami.Action {
icon.name: "tools-report-bug"
text: i18n("Report this issue")
icon.name: page.buttonIcon
text: page.buttonText
onTriggered: {
Qt.openUrlExternally(ResourcesModel.distroBugReportUrl())
Qt.openUrlExternally(page.buttonUrl)
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment