Merge pull request #4700 from zhaowenlan1779/swkbd-2

applets/swkbd: Add callback support
This commit is contained in:
Pengfei Zhu 2019-04-20 22:18:15 +08:00 committed by GitHub
commit 536e4de499
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 156 additions and 94 deletions

View file

@ -39,10 +39,6 @@ ValidationError SoftwareKeyboard::ValidateFilters(const std::string& input) cons
// TODO: check the profanity filter
LOG_INFO(Frontend, "App requested swkbd profanity filter, but its not implemented.");
}
if (config.filters.enable_callback) {
// TODO: check the callback
LOG_INFO(Frontend, "App requested a swkbd callback, but its not implemented.");
}
return ValidationError::None;
}
@ -132,11 +128,21 @@ ValidationError SoftwareKeyboard::Finalize(const std::string& text, u8 button) {
return error;
}
data = {text, button};
data_ready = true;
return ValidationError::None;
}
void DefaultKeyboard::Setup(const Frontend::KeyboardConfig& config) {
SoftwareKeyboard::Setup(config);
bool SoftwareKeyboard::DataReady() const {
return data_ready;
}
const KeyboardData& SoftwareKeyboard::ReceiveData() {
data_ready = false;
return data;
}
void DefaultKeyboard::Execute(const Frontend::KeyboardConfig& config) {
SoftwareKeyboard::Execute(config);
auto cfg = Service::CFG::GetModule(Core::System::GetInstance());
ASSERT_MSG(cfg, "CFG Module missing!");
@ -157,4 +163,8 @@ void DefaultKeyboard::Setup(const Frontend::KeyboardConfig& config) {
}
}
void DefaultKeyboard::ShowError(const std::string& error) {
LOG_ERROR(Applet_SWKBD, "Default keyboard text is unaccepted! error: {}", error);
}
} // namespace Frontend

View file

@ -4,6 +4,7 @@
#pragma once
#include <atomic>
#include <unordered_map>
#include <utility>
#include <vector>
@ -82,13 +83,27 @@ enum class ValidationError {
class SoftwareKeyboard {
public:
virtual void Setup(const KeyboardConfig& config) {
this->config = KeyboardConfig(config);
/**
* Executes the software keyboard, configured with the given parameters.
*/
virtual void Execute(const KeyboardConfig& config) {
this->config = config;
}
const KeyboardData& ReceiveData() const {
return data;
}
/**
* Whether the result data is ready to be received.
*/
bool DataReady() const;
/**
* Receives the current result data stored in the applet, and clears the ready state.
*/
const KeyboardData& ReceiveData();
/**
* Shows an error text returned by the callback.
*/
virtual void ShowError(const std::string& error) = 0;
/**
* Validates if the provided string breaks any of the filter rules. This is meant to be called
@ -118,11 +133,14 @@ public:
protected:
KeyboardConfig config;
KeyboardData data;
std::atomic_bool data_ready = false;
};
class DefaultKeyboard final : public SoftwareKeyboard {
public:
void Setup(const KeyboardConfig& config) override;
void Execute(const KeyboardConfig& config) override;
void ShowError(const std::string& error) override;
};
} // namespace Frontend