qt_error.cpp 2.8 KB

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