qt_error.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(this, &QtErrorDisplay::MainWindowRequestExit, &parent,
  10. &GMainWindow::ErrorDisplayRequestExit, Qt::QueuedConnection);
  11. connect(&parent, &GMainWindow::ErrorDisplayFinished, this,
  12. &QtErrorDisplay::MainWindowFinishedError, Qt::DirectConnection);
  13. }
  14. QtErrorDisplay::~QtErrorDisplay() = default;
  15. void QtErrorDisplay::Close() const {
  16. callback = {};
  17. emit MainWindowRequestExit();
  18. }
  19. void QtErrorDisplay::ShowError(Result error, FinishedCallback finished) const {
  20. callback = std::move(finished);
  21. emit MainWindowDisplayError(
  22. tr("Error Code: %1-%2 (0x%3)")
  23. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  24. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  25. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  26. tr("An error has occurred.\nPlease try again or contact the developer of the software."));
  27. }
  28. void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
  29. FinishedCallback finished) const {
  30. callback = std::move(finished);
  31. const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
  32. emit MainWindowDisplayError(
  33. tr("Error Code: %1-%2 (0x%3)")
  34. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  35. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  36. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  37. tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
  38. "software.")
  39. .arg(date_time.toString(QStringLiteral("dddd, MMMM d, yyyy")))
  40. .arg(date_time.toString(QStringLiteral("h:mm:ss A"))));
  41. }
  42. void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text,
  43. std::string fullscreen_text,
  44. FinishedCallback finished) const {
  45. callback = std::move(finished);
  46. emit MainWindowDisplayError(
  47. tr("Error Code: %1-%2 (0x%3)")
  48. .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0'))
  49. .arg(error.description, 4, 10, QChar::fromLatin1('0'))
  50. .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
  51. tr("An error has occurred.\n\n%1\n\n%2")
  52. .arg(QString::fromStdString(dialog_text))
  53. .arg(QString::fromStdString(fullscreen_text)));
  54. }
  55. void QtErrorDisplay::MainWindowFinishedError() {
  56. if (callback) {
  57. callback();
  58. }
  59. }