qt_error.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <QDateTime>
  4. #include "yuzu/applets/qt_error.h"
  5. #include "yuzu/main.h"
  6. QtErrorDisplay::QtErrorDisplay(GMainWindow& parent) {
  7. connect(this, &QtErrorDisplay::MainWindowDisplayError, &parent,
  8. &GMainWindow::ErrorDisplayDisplayError, Qt::QueuedConnection);
  9. connect(&parent, &GMainWindow::ErrorDisplayFinished, this,
  10. &QtErrorDisplay::MainWindowFinishedError, Qt::DirectConnection);
  11. }
  12. QtErrorDisplay::~QtErrorDisplay() = default;
  13. void QtErrorDisplay::ShowError(Result error, FinishedCallback finished) const {
  14. callback = std::move(finished);
  15. emit MainWindowDisplayError(
  16. tr("Error Code: %1-%2 (0x%3)")
  17. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  18. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  19. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  20. tr("An error has occurred.\nPlease try again or contact the developer of the software."));
  21. }
  22. void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
  23. FinishedCallback finished) const {
  24. callback = std::move(finished);
  25. const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
  26. emit MainWindowDisplayError(
  27. tr("Error Code: %1-%2 (0x%3)")
  28. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  29. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  30. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  31. tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
  32. "software.")
  33. .arg(date_time.toString(QStringLiteral("dddd, MMMM d, yyyy")))
  34. .arg(date_time.toString(QStringLiteral("h:mm:ss A"))));
  35. }
  36. void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text,
  37. std::string fullscreen_text,
  38. FinishedCallback finished) const {
  39. callback = std::move(finished);
  40. emit MainWindowDisplayError(
  41. tr("Error Code: %1-%2 (0x%3)")
  42. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  43. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  44. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  45. tr("An error has occurred.\n\n%1\n\n%2")
  46. .arg(QString::fromStdString(dialog_text))
  47. .arg(QString::fromStdString(fullscreen_text)));
  48. }
  49. void QtErrorDisplay::MainWindowFinishedError() {
  50. callback();
  51. }