2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-12 00:39:20 +01:00
|
|
|
|
|
|
|
#include <QDateTime>
|
2021-07-14 06:29:12 +02:00
|
|
|
#include "yuzu/applets/qt_error.h"
|
2019-03-12 00:39:20 +01:00
|
|
|
#include "yuzu/main.h"
|
|
|
|
|
|
|
|
QtErrorDisplay::QtErrorDisplay(GMainWindow& parent) {
|
|
|
|
connect(this, &QtErrorDisplay::MainWindowDisplayError, &parent,
|
|
|
|
&GMainWindow::ErrorDisplayDisplayError, Qt::QueuedConnection);
|
|
|
|
connect(&parent, &GMainWindow::ErrorDisplayFinished, this,
|
|
|
|
&QtErrorDisplay::MainWindowFinishedError, Qt::DirectConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
QtErrorDisplay::~QtErrorDisplay() = default;
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
void QtErrorDisplay::ShowError(Result error, std::function<void()> finished) const {
|
2020-12-05 14:37:13 +01:00
|
|
|
callback = std::move(finished);
|
2019-03-12 00:39:20 +01:00
|
|
|
emit MainWindowDisplayError(
|
2021-03-26 11:07:27 +01:00
|
|
|
tr("Error Code: %1-%2 (0x%3)")
|
2019-03-12 00:39:20 +01:00
|
|
|
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
|
|
|
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
2021-03-26 11:07:27 +01:00
|
|
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
|
|
|
tr("An error has occurred.\nPlease try again or contact the developer of the software."));
|
2019-03-12 00:39:20 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
|
2019-03-12 00:39:20 +01:00
|
|
|
std::function<void()> finished) const {
|
2020-12-05 14:37:13 +01:00
|
|
|
callback = std::move(finished);
|
2019-05-25 02:56:58 +02:00
|
|
|
|
|
|
|
const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
|
2019-03-12 00:39:20 +01:00
|
|
|
emit MainWindowDisplayError(
|
2021-03-26 11:07:27 +01:00
|
|
|
tr("Error Code: %1-%2 (0x%3)")
|
2019-03-12 00:39:20 +01:00
|
|
|
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
|
|
|
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
2021-03-26 11:07:27 +01:00
|
|
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
|
|
|
tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
|
|
|
|
"software.")
|
|
|
|
.arg(date_time.toString(QStringLiteral("dddd, MMMM d, yyyy")))
|
|
|
|
.arg(date_time.toString(QStringLiteral("h:mm:ss A"))));
|
2019-03-12 00:39:20 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 05:44:19 +02:00
|
|
|
void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text,
|
2019-03-12 00:39:20 +01:00
|
|
|
std::string fullscreen_text,
|
|
|
|
std::function<void()> finished) const {
|
2020-12-05 14:37:13 +01:00
|
|
|
callback = std::move(finished);
|
2019-03-12 00:39:20 +01:00
|
|
|
emit MainWindowDisplayError(
|
2021-03-26 11:07:27 +01:00
|
|
|
tr("Error Code: %1-%2 (0x%3)")
|
2019-03-12 00:39:20 +01:00
|
|
|
.arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
|
|
|
|
.arg(error.description, 4, 10, QChar::fromLatin1('0'))
|
2021-03-26 11:07:27 +01:00
|
|
|
.arg(error.raw, 8, 16, QChar::fromLatin1('0')),
|
|
|
|
tr("An error has occurred.\n\n%1\n\n%2")
|
2019-03-12 00:39:20 +01:00
|
|
|
.arg(QString::fromStdString(dialog_text))
|
|
|
|
.arg(QString::fromStdString(fullscreen_text)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtErrorDisplay::MainWindowFinishedError() {
|
|
|
|
callback();
|
|
|
|
}
|