2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
// UIModeController.cpp
|
|
|
|
//
|
|
|
|
// Handling of application user interface modes (full, kiosk and kid).
|
|
|
|
// This includes switching the mode when the UI mode passkey was used.
|
|
|
|
//
|
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
#include "UIModeController.h"
|
|
|
|
|
|
|
|
#include "utils/StringUtil.h"
|
|
|
|
#include "views/ViewController.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Window.h"
|
|
|
|
|
|
|
|
UIModeController * UIModeController::sInstance = NULL;
|
|
|
|
|
|
|
|
UIModeController * UIModeController::getInstance()
|
|
|
|
{
|
|
|
|
if (sInstance == NULL)
|
|
|
|
sInstance = new UIModeController();
|
|
|
|
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIModeController::UIModeController()
|
|
|
|
:mPassKeyCounter(0)
|
|
|
|
{
|
|
|
|
mPassKeySequence = Settings::getInstance()->getString("UIMode_passkey");
|
|
|
|
mCurrentUIMode = Settings::getInstance()->getString("UIMode");
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModeController::monitorUIMode()
|
|
|
|
{
|
|
|
|
std::string uimode = Settings::getInstance()->getString("UIMode");
|
2020-06-06 14:48:05 +00:00
|
|
|
// UI mode was changed.
|
|
|
|
if (uimode != mCurrentUIMode) {
|
2017-11-18 22:23:56 +00:00
|
|
|
mCurrentUIMode = uimode;
|
|
|
|
ViewController::get()->ReloadAndGoToStart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIModeController::listen(InputConfig * config, Input input)
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
// Reads the current input to listen for the passkey sequence to unlock
|
|
|
|
// the UI mode. The progress is saved in mPassKeyCounter.
|
2017-11-18 22:23:56 +00:00
|
|
|
if (Settings::getInstance()->getBool("Debug"))
|
|
|
|
logInput(config, input);
|
|
|
|
|
|
|
|
if ((Settings::getInstance()->getString("UIMode") == "Full") || !isValidInput(config, input))
|
|
|
|
return false; // Already unlocked, or invalid input, nothing to do here.
|
|
|
|
|
|
|
|
if (!inputIsMatch(config, input))
|
2020-06-06 14:48:05 +00:00
|
|
|
mPassKeyCounter = 0; // Current input is incorrect, reset counter.
|
2017-11-18 22:23:56 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
if (mPassKeyCounter == (int)mPassKeySequence.length()) {
|
2017-11-18 22:23:56 +00:00
|
|
|
unlockUIMode();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIModeController::inputIsMatch(InputConfig * config, Input input)
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
for (auto valstring : mInputVals) {
|
2018-11-15 16:38:20 +00:00
|
|
|
if (config->isMappedLike(valstring, input) &&
|
2020-06-06 14:48:05 +00:00
|
|
|
(mPassKeySequence[mPassKeyCounter] == valstring[0])) {
|
2017-11-18 22:23:56 +00:00
|
|
|
mPassKeyCounter++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// When we have reached the end of the list, trigger UI_mode unlock.
|
2017-11-18 22:23:56 +00:00
|
|
|
void UIModeController::unlockUIMode()
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
LOG(LogDebug) <<
|
|
|
|
" UIModeController::listen(): Passkey sequence completed, switching UIMode to full";
|
2017-11-18 22:23:56 +00:00
|
|
|
Settings::getInstance()->setString("UIMode", "Full");
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
mPassKeyCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIModeController::isUIModeFull()
|
|
|
|
{
|
|
|
|
return ((mCurrentUIMode == "Full") && !Settings::getInstance()->getBool("ForceKiosk"));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UIModeController::isUIModeKid()
|
|
|
|
{
|
|
|
|
return (Settings::getInstance()->getBool("ForceKid") ||
|
|
|
|
((mCurrentUIMode == "Kid") && !Settings::getInstance()->getBool("ForceKiosk")));
|
|
|
|
}
|
|
|
|
|
2019-01-19 08:11:19 +00:00
|
|
|
bool UIModeController::isUIModeKiosk()
|
|
|
|
{
|
|
|
|
return (Settings::getInstance()->getBool("ForceKiosk") ||
|
|
|
|
((mCurrentUIMode == "Kiosk") && !Settings::getInstance()->getBool("ForceKid")));
|
|
|
|
}
|
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
std::string UIModeController::getFormattedPassKeyStr()
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
// Supported sequence-inputs: u (up), d (down), l (left), r (right), a, b, x, y.
|
2017-11-18 22:23:56 +00:00
|
|
|
|
|
|
|
std::string out = "";
|
2020-06-06 14:48:05 +00:00
|
|
|
for (auto c : mPassKeySequence) {
|
|
|
|
out += (out == "") ? "" : ", "; // Add a comma after the first entry.
|
2017-11-18 22:23:56 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
switch (c) {
|
2017-11-18 22:23:56 +00:00
|
|
|
case 'u':
|
2020-06-06 14:48:05 +00:00
|
|
|
out += Utils::String::unicode2Chars(0x2191); // Arrow pointing up.
|
2017-11-18 22:23:56 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2020-06-06 14:48:05 +00:00
|
|
|
out += Utils::String::unicode2Chars(0x2193); // Arrow pointing down.
|
2017-11-18 22:23:56 +00:00
|
|
|
break;
|
|
|
|
case 'l':
|
2020-06-06 14:48:05 +00:00
|
|
|
out += Utils::String::unicode2Chars(0x2190); // Arrow pointing left.
|
2017-11-18 22:23:56 +00:00
|
|
|
break;
|
|
|
|
case 'r':
|
2020-06-06 14:48:05 +00:00
|
|
|
out += Utils::String::unicode2Chars(0x2192); // Arrow pointing right.
|
2017-11-18 22:23:56 +00:00
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
out += "A";
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
out += "B";
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
out += "X";
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
out += "Y";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIModeController::logInput(InputConfig * config, Input input)
|
|
|
|
{
|
|
|
|
std::string mapname = "";
|
|
|
|
std::vector<std::string> maps = config->getMappedTo(input);
|
2020-06-06 14:48:05 +00:00
|
|
|
|
|
|
|
for (auto mn : maps) {
|
2017-11-18 22:23:56 +00:00
|
|
|
mapname += mn;
|
|
|
|
mapname += ", ";
|
|
|
|
}
|
2020-06-06 14:48:05 +00:00
|
|
|
|
|
|
|
LOG(LogDebug) << "UIModeController::logInput( " << config->getDeviceName() <<
|
|
|
|
" ):" << input.string() << ", isMappedTo= " << mapname << ", value=" << input.value;
|
2017-11-18 22:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UIModeController::isValidInput(InputConfig * config, Input input)
|
|
|
|
{
|
2020-06-06 14:48:05 +00:00
|
|
|
if ((config->getMappedTo(input).size() == 0) || // Not a mapped input, so ignore..
|
|
|
|
(input.type == TYPE_HAT) || // Ignore all hat inputs.
|
|
|
|
(!input.value)) // Not a key-down event.
|
2017-11-18 22:23:56 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return true;
|
2020-06-06 14:48:05 +00:00
|
|
|
}
|