citra_qt/applets/swkbd: QtKeyboard and misc fixes
* Addressed comments and removed the applet interface * swkbd: address @lioncash's comments * core: more fixes ** Moved registered_swkbd to System ** Removed an usused virtual ** Removed functionality of DrawScreenKeyboard ** Removed src/core/settings.h change * swkbd: address @lioncash's 2nd review * swkbd: update logging macro * QtKeyboard: Make dialog modal and hide help
This commit is contained in:
parent
f23443b921
commit
5407ed8b5e
15 changed files with 369 additions and 255 deletions
|
@ -3,11 +3,10 @@
|
|||
// Refer to the license.txt file included.
|
||||
|
||||
#include "core/frontend/applets/default_applets.h"
|
||||
#include "core/frontend/applets/interface.h"
|
||||
#include "core/frontend/applets/swkbd.h"
|
||||
|
||||
namespace Frontend {
|
||||
void RegisterDefaultApplets() {
|
||||
RegisterFrontendApplet(std::make_shared<DefaultCitraKeyboard>(), AppletType::SoftwareKeyboard);
|
||||
RegisterSoftwareKeyboard(std::make_shared<DefaultCitraKeyboard>());
|
||||
}
|
||||
} // namespace Frontend
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <unordered_map>
|
||||
#include "core/frontend/applets/interface.h"
|
||||
|
||||
namespace Frontend {
|
||||
|
||||
std::unordered_map<AppletType, std::shared_ptr<AppletInterface>> registered_applets;
|
||||
|
||||
void RegisterFrontendApplet(std::shared_ptr<AppletInterface> applet, AppletType type) {
|
||||
registered_applets[type] = applet;
|
||||
}
|
||||
|
||||
void UnregisterFrontendApplet(AppletType type) {
|
||||
registered_applets.erase(type);
|
||||
}
|
||||
|
||||
std::shared_ptr<AppletInterface> GetRegisteredApplet(AppletType type) {
|
||||
return registered_applets.at(type);
|
||||
}
|
||||
|
||||
} // namespace Frontend
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright 2018 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
namespace Frontend {
|
||||
|
||||
enum class AppletType {
|
||||
SoftwareKeyboard,
|
||||
};
|
||||
|
||||
class AppletConfig {};
|
||||
class AppletData {};
|
||||
|
||||
// TODO(jroweboy) add ability to draw to framebuffer
|
||||
class AppletInterface {
|
||||
public:
|
||||
virtual ~AppletInterface() = default;
|
||||
|
||||
/**
|
||||
* On applet start, the applet specific configuration will be passed in along with the
|
||||
* framebuffer.
|
||||
*/
|
||||
virtual void Setup(const AppletConfig*) = 0;
|
||||
|
||||
/**
|
||||
* Checked every update to see if the applet is still running. When the applet is done, the core
|
||||
* will call ReceiveData
|
||||
*/
|
||||
virtual bool IsRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the core to receive the result data of this applet.
|
||||
* Frontend implementation **should** block until the data is ready.
|
||||
*/
|
||||
virtual const AppletData* ReceiveData() = 0;
|
||||
|
||||
protected:
|
||||
std::atomic<bool> running = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Frontends call this method to pass a frontend applet implementation to the core. If the core
|
||||
* already has a applet registered, then this replaces the old applet
|
||||
*
|
||||
* @param applet - Frontend Applet implementation that the HLE applet code will launch
|
||||
* @param type - Which type of applet
|
||||
*/
|
||||
void RegisterFrontendApplet(std::shared_ptr<AppletInterface> applet, AppletType type);
|
||||
|
||||
/**
|
||||
* Frontends call this to prevent future requests
|
||||
*/
|
||||
void UnregisterFrontendApplet(AppletType type);
|
||||
|
||||
/**
|
||||
* Returns the Frontend Applet for the provided type
|
||||
*/
|
||||
std::shared_ptr<AppletInterface> GetRegisteredApplet(AppletType type);
|
||||
|
||||
} // namespace Frontend
|
|
@ -2,13 +2,16 @@
|
|||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core.h"
|
||||
#include "core/frontend/applets/swkbd.h"
|
||||
|
||||
namespace Frontend {
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
|
||||
ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) const {
|
||||
if (config.filters.prevent_digit) {
|
||||
if (std::any_of(input.begin(), input.end(),
|
||||
[](unsigned char c) { return std::isdigit(c); })) {
|
||||
|
@ -41,7 +44,7 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) {
|
|||
return ValidationError::None;
|
||||
}
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
||||
ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) const {
|
||||
ValidationError error;
|
||||
if ((error = ValidateFilters(input)) != ValidationError::None) {
|
||||
return error;
|
||||
|
@ -52,11 +55,9 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
|||
return ValidationError::MaxLengthExceeded;
|
||||
}
|
||||
|
||||
auto is_blank = [&] {
|
||||
return std::all_of(input.begin(), input.end(),
|
||||
[](unsigned char c) { return std::isspace(c); });
|
||||
};
|
||||
auto is_empty = [&] { return input.empty(); };
|
||||
bool is_blank =
|
||||
std::all_of(input.begin(), input.end(), [](unsigned char c) { return std::isspace(c); });
|
||||
bool is_empty = input.empty();
|
||||
switch (config.accept_mode) {
|
||||
case AcceptedInput::FixedLength:
|
||||
if (input.size() != config.max_text_length) {
|
||||
|
@ -64,20 +65,20 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
|||
}
|
||||
break;
|
||||
case AcceptedInput::NotEmptyAndNotBlank:
|
||||
if (is_blank()) {
|
||||
if (is_blank) {
|
||||
return ValidationError::BlankInputNotAllowed;
|
||||
}
|
||||
if (is_empty()) {
|
||||
if (is_empty) {
|
||||
return ValidationError::EmptyInputNotAllowed;
|
||||
}
|
||||
break;
|
||||
case AcceptedInput::NotBlank:
|
||||
if (is_blank()) {
|
||||
if (is_blank) {
|
||||
return ValidationError::BlankInputNotAllowed;
|
||||
}
|
||||
break;
|
||||
case AcceptedInput::NotEmpty:
|
||||
if (is_empty()) {
|
||||
if (is_empty) {
|
||||
return ValidationError::EmptyInputNotAllowed;
|
||||
}
|
||||
break;
|
||||
|
@ -85,15 +86,15 @@ ValidationError SoftwareKeyboard::ValidateInput(const std::string& input) {
|
|||
return ValidationError::None;
|
||||
default:
|
||||
// TODO(jroweboy): What does hardware do in this case?
|
||||
NGLOG_CRITICAL(Frontend, "Application requested unknown validation method. Method: {}",
|
||||
static_cast<u32>(config.accept_mode));
|
||||
LOG_CRITICAL(Frontend, "Application requested unknown validation method. Method: {}",
|
||||
static_cast<u32>(config.accept_mode));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
return ValidationError::None;
|
||||
}
|
||||
|
||||
ValidationError SoftwareKeyboard::ValidateButton(u8 button) {
|
||||
ValidationError SoftwareKeyboard::ValidateButton(u8 button) const {
|
||||
switch (config.button_config) {
|
||||
case ButtonConfig::None:
|
||||
return ValidationError::None;
|
||||
|
@ -127,7 +128,32 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) {
|
|||
return error;
|
||||
}
|
||||
data = {text, button};
|
||||
running = false;
|
||||
}
|
||||
|
||||
void DefaultCitraKeyboard::Setup(const Frontend::KeyboardConfig* config) {
|
||||
SoftwareKeyboard::Setup(config);
|
||||
switch (this->config.button_config) {
|
||||
case ButtonConfig::None:
|
||||
case ButtonConfig::Single:
|
||||
Finalize("Citra", 0);
|
||||
break;
|
||||
case ButtonConfig::Dual:
|
||||
Finalize("Citra", 1);
|
||||
break;
|
||||
case ButtonConfig::Triple:
|
||||
Finalize("Citra", 2);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
void RegisterSoftwareKeyboard(std::shared_ptr<SoftwareKeyboard> applet) {
|
||||
Core::System::GetInstance().RegisterSoftwareKeyboard(applet);
|
||||
}
|
||||
|
||||
std::shared_ptr<SoftwareKeyboard> GetRegisteredSoftwareKeyboard() {
|
||||
return Core::System::GetInstance().GetSoftwareKeyboard();
|
||||
}
|
||||
|
||||
} // namespace Frontend
|
||||
|
|
|
@ -4,18 +4,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "common/assert.h"
|
||||
#include "core/frontend/applets/interface.h"
|
||||
|
||||
namespace Frontend {
|
||||
|
||||
enum class AcceptedInput {
|
||||
Anything = 0, /// All inputs are accepted.
|
||||
Anything, /// All inputs are accepted.
|
||||
NotEmpty, /// Empty inputs are not accepted.
|
||||
NotEmptyAndNotBlank, /// Empty or blank inputs (consisting solely of whitespace) are not
|
||||
/// accepted.
|
||||
|
@ -26,25 +23,20 @@ enum class AcceptedInput {
|
|||
};
|
||||
|
||||
enum class ButtonConfig {
|
||||
Single = 0, /// Ok button
|
||||
Dual, /// Cancel | Ok buttons
|
||||
Triple, /// Cancel | I Forgot | Ok buttons
|
||||
None, /// No button (returned by swkbdInputText in special cases)
|
||||
Single, /// Ok button
|
||||
Dual, /// Cancel | Ok buttons
|
||||
Triple, /// Cancel | I Forgot | Ok buttons
|
||||
None, /// No button (returned by swkbdInputText in special cases)
|
||||
};
|
||||
|
||||
/// Default English button text mappings. Frontends may need to copy this to internationalize it.
|
||||
static const char* BUTTON_OKAY = "Ok";
|
||||
static const char* BUTTON_CANCEL = "Cancel";
|
||||
static const char* BUTTON_FORGOT = "I Forgot";
|
||||
static const std::unordered_map<ButtonConfig, std::vector<std::string>> DEFAULT_BUTTON_MAPPING = {
|
||||
{ButtonConfig::Single, {BUTTON_OKAY}},
|
||||
{ButtonConfig::Dual, {BUTTON_CANCEL, BUTTON_OKAY}},
|
||||
{ButtonConfig::Triple, {BUTTON_CANCEL, BUTTON_FORGOT, BUTTON_OKAY}},
|
||||
};
|
||||
constexpr char BUTTON_OKAY[] = "Ok";
|
||||
constexpr char BUTTON_CANCEL[] = "Cancel";
|
||||
constexpr char BUTTON_FORGOT[] = "I Forgot";
|
||||
|
||||
/// Configuration thats relevent to frontend implementation of applets. Anything missing that we
|
||||
/// later learn is needed can be added here and filled in by the backend HLE applet
|
||||
struct KeyboardConfig : public AppletConfig {
|
||||
struct KeyboardConfig {
|
||||
ButtonConfig button_config;
|
||||
AcceptedInput accept_mode; /// What kinds of input are accepted (blank/empty/fixed width)
|
||||
bool multiline_mode; /// True if the keyboard accepts multiple lines of input
|
||||
|
@ -61,16 +53,13 @@ struct KeyboardConfig : public AppletConfig {
|
|||
bool prevent_backslash; /// Disallow the use of the \ sign.
|
||||
bool prevent_profanity; /// Disallow profanity using Nintendo's profanity filter.
|
||||
bool enable_callback; /// Use a callback in order to check the input.
|
||||
} filters;
|
||||
};
|
||||
Filters filters;
|
||||
};
|
||||
|
||||
class KeyboardData : public AppletData {
|
||||
public:
|
||||
struct KeyboardData {
|
||||
std::string text;
|
||||
u8 button{};
|
||||
|
||||
KeyboardData(std::string text, u8 button) : text(std::move(text)), button(button) {}
|
||||
KeyboardData() = default;
|
||||
};
|
||||
|
||||
enum class ValidationError {
|
||||
|
@ -91,35 +80,33 @@ enum class ValidationError {
|
|||
EmptyInputNotAllowed,
|
||||
};
|
||||
|
||||
class SoftwareKeyboard : public AppletInterface {
|
||||
class SoftwareKeyboard {
|
||||
public:
|
||||
explicit SoftwareKeyboard() : AppletInterface() {}
|
||||
void Setup(const AppletConfig* config) override {
|
||||
this->config = KeyboardConfig(*static_cast<const KeyboardConfig*>(config));
|
||||
virtual void Setup(const KeyboardConfig* config) {
|
||||
this->config = KeyboardConfig(*config);
|
||||
}
|
||||
const AppletData* ReceiveData() override {
|
||||
const KeyboardData* ReceiveData() {
|
||||
return &data;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Validates if the provided string breaks any of the filter rules. This is meant to be called
|
||||
* whenever the user input changes to check to see if the new input is valid. Frontends can
|
||||
* decide if they want to check the input continuously or once before submission
|
||||
*/
|
||||
ValidationError ValidateFilters(const std::string& input);
|
||||
ValidationError ValidateFilters(const std::string& input) const;
|
||||
|
||||
/**
|
||||
* Validates the the provided string doesn't break any extra rules like "input must not be
|
||||
* empty". This will be called by Finalize but can be called earlier if the frontend needs
|
||||
*/
|
||||
ValidationError ValidateInput(const std::string& input);
|
||||
ValidationError ValidateInput(const std::string& input) const;
|
||||
|
||||
/**
|
||||
* Verifies that the selected button is valid. This should be used as the last check before
|
||||
* closing.
|
||||
*/
|
||||
ValidationError ValidateButton(u8 button);
|
||||
ValidationError ValidateButton(u8 button) const;
|
||||
|
||||
/**
|
||||
* Runs all validation phases. If successful, stores the data so that the HLE applet in core can
|
||||
|
@ -127,29 +114,18 @@ protected:
|
|||
*/
|
||||
ValidationError Finalize(const std::string& text, u8 button);
|
||||
|
||||
protected:
|
||||
KeyboardConfig config;
|
||||
KeyboardData data;
|
||||
};
|
||||
|
||||
class DefaultCitraKeyboard final : public SoftwareKeyboard {
|
||||
public:
|
||||
void Setup(const AppletConfig* config) override {
|
||||
SoftwareKeyboard::Setup(config);
|
||||
switch (this->config.button_config) {
|
||||
case ButtonConfig::None:
|
||||
case ButtonConfig::Single:
|
||||
Finalize("Citra", 0);
|
||||
break;
|
||||
case ButtonConfig::Dual:
|
||||
Finalize("Citra", 1);
|
||||
break;
|
||||
case ButtonConfig::Triple:
|
||||
Finalize("Citra", 2);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
void Setup(const KeyboardConfig* config) override;
|
||||
};
|
||||
|
||||
void RegisterSoftwareKeyboard(std::shared_ptr<SoftwareKeyboard> applet);
|
||||
|
||||
std::shared_ptr<SoftwareKeyboard> GetRegisteredSoftwareKeyboard();
|
||||
|
||||
} // namespace Frontend
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue