citra/src/citra_qt/applets/swkbd.h
Pengfei Zhu 60669a7dd8
swkbd: Fix a bug where clicking Cancel hangs the game (#5294)
* swkbd: Fix a bug where clicking Cancel hangs the game

The text is validated in `Finalize`. If the validation fails, an error is returned and the applet is not actually finalized. This can result in hangs.

This is usually not a problem as the frontend is expected to validate the text passed to `Finalize`. However, when the user clicked on `Cancel`, the text is ignored and the frontend won't do any validation. Therefore, we should skip the validation here as well.

Also fixed a potential data race. All these functions should now be called on the same thread

* Address review comments

Renamed the fields
Remove close button
2020-05-04 11:31:17 +02:00

71 lines
1.6 KiB
C++

// Copyright 2018 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <QDialog>
#include <QValidator>
#include "core/frontend/applets/swkbd.h"
class QDialogButtonBox;
class QLabel;
class QLineEdit;
class QVBoxLayout;
class QtKeyboard;
class QtKeyboardValidator final : public QValidator {
public:
explicit QtKeyboardValidator(QtKeyboard* keyboard);
State validate(QString& input, int& pos) const override;
private:
QtKeyboard* keyboard;
};
class QtKeyboardDialog final : public QDialog {
Q_OBJECT
public:
QtKeyboardDialog(QWidget* parent, QtKeyboard* keyboard);
void Submit();
private:
void HandleValidationError(Frontend::ValidationError error);
QDialogButtonBox* buttons;
QLabel* label;
QLineEdit* line_edit;
QVBoxLayout* layout;
QtKeyboard* keyboard;
QString text;
u8 button;
friend class QtKeyboard;
};
class QtKeyboard final : public QObject, public Frontend::SoftwareKeyboard {
Q_OBJECT
public:
explicit QtKeyboard(QWidget& parent);
void Execute(const Frontend::KeyboardConfig& config) override;
void ShowError(const std::string& error) override;
private:
Q_INVOKABLE void OpenInputDialog();
Q_INVOKABLE void ShowErrorDialog(QString message);
/// Index of the buttons
u8 ok_id;
static constexpr u8 forgot_id = 1;
static constexpr u8 cancel_id = 0;
QWidget& parent;
std::string result_text;
int result_button;
friend class QtKeyboardDialog;
friend class QtKeyboardValidator;
};