mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps] GlobalPreferences: change exam mode API
This commit is contained in:
committed by
LeaNumworks
parent
f4de842a86
commit
da735b93a4
@@ -168,7 +168,8 @@ bool AppsContainer::processEvent(Ion::Events::Event event) {
|
||||
// Warning: if the window is dirtied, you need to call window()->redraw()
|
||||
if (event == Ion::Events::USBPlug) {
|
||||
if (Ion::USB::isPlugged()) {
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
// TODO
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
|
||||
displayExamModePopUp(false);
|
||||
window()->redraw();
|
||||
} else {
|
||||
@@ -213,7 +214,8 @@ void AppsContainer::run() {
|
||||
* and it is visible when reflashing a N0100 (there is some noise on the
|
||||
* screen before the logo appears). */
|
||||
Ion::Display::pushRectUniform(screenRect, KDColorWhite);
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
// TODO
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
|
||||
activateExamMode();
|
||||
}
|
||||
refreshPreferences();
|
||||
@@ -291,7 +293,7 @@ void AppsContainer::shutdownDueToLowBattery() {
|
||||
}
|
||||
while (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) {
|
||||
Ion::Backlight::setBrightness(0);
|
||||
if (!GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
if (!GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
|
||||
/* Unless the LED is lit up for the exam mode, switch off the LED. IF the
|
||||
* low battery event happened during the Power-On Self-Test, a LED might
|
||||
* have stayed lit up. */
|
||||
|
||||
@@ -50,7 +50,8 @@ ExamPopUpController::ContentView::ContentView(Responder * parentResponder) :
|
||||
}, parentResponder), KDFont::SmallFont),
|
||||
m_okButton(parentResponder, I18n::Message::Ok, Invocation([](void * context, void * sender) {
|
||||
ExamPopUpController * controller = (ExamPopUpController *)context;
|
||||
GlobalPreferences::sharedGlobalPreferences()->setExamMode(controller->isActivatingExamMode());
|
||||
// TODO
|
||||
GlobalPreferences::sharedGlobalPreferences()->setExamMode(controller->isActivatingExamMode() ? GlobalPreferences::ExamMode::Dutch : GlobalPreferences::ExamMode::Off);
|
||||
AppsContainer * container = AppsContainer::sharedAppsContainer();
|
||||
if (controller->isActivatingExamMode()) {
|
||||
container->activateExamMode();
|
||||
|
||||
@@ -5,20 +5,24 @@ GlobalPreferences * GlobalPreferences::sharedGlobalPreferences() {
|
||||
return &globalPreferences;
|
||||
}
|
||||
|
||||
bool GlobalPreferences::examMode() const {
|
||||
GlobalPreferences::ExamMode GlobalPreferences::examMode() const {
|
||||
if (m_examMode == ExamMode::Unknown) {
|
||||
m_examMode = (ExamMode)Ion::ExamMode::FetchExamMode();
|
||||
}
|
||||
assert((int)m_examMode == 0 || (int)m_examMode == 1);
|
||||
return (bool)m_examMode;
|
||||
assert((int)m_examMode >= 0 && (int)m_examMode <= 2);
|
||||
return m_examMode;
|
||||
}
|
||||
|
||||
void GlobalPreferences::setExamMode(bool activateExamMode) {
|
||||
if (((bool)examMode()) == activateExamMode) {
|
||||
void GlobalPreferences::setExamMode(ExamMode mode) {
|
||||
if (examMode() == mode) {
|
||||
return;
|
||||
}
|
||||
Ion::ExamMode::ToggleExamMode();
|
||||
m_examMode = (ExamMode)activateExamMode;
|
||||
assert(mode != ExamMode::Unknown);
|
||||
int8_t deltaMode = (int8_t)mode - (int8_t)examMode();
|
||||
deltaMode = deltaMode < 0 ? deltaMode + 3 : deltaMode;
|
||||
assert(deltaMode > 0);
|
||||
Ion::ExamMode::IncrementExamMode(deltaMode);
|
||||
m_examMode = mode;
|
||||
}
|
||||
|
||||
void GlobalPreferences::setBrightnessLevel(int brightnessLevel) {
|
||||
|
||||
@@ -5,11 +5,18 @@
|
||||
|
||||
class GlobalPreferences {
|
||||
public:
|
||||
enum class ExamMode : int8_t {
|
||||
Unknown = -1,
|
||||
Off = 0,
|
||||
Standard = 1,
|
||||
Dutch = 2
|
||||
};
|
||||
static GlobalPreferences * sharedGlobalPreferences();
|
||||
I18n::Language language() const { return m_language; }
|
||||
void setLanguage(I18n::Language language) { m_language = language; }
|
||||
bool examMode() const;
|
||||
void setExamMode(bool activateExamMode);
|
||||
bool isInExamMode() const { return (int8_t)examMode() > 0; }
|
||||
ExamMode examMode() const;
|
||||
void setExamMode(ExamMode examMode);
|
||||
bool showPopUp() const { return m_showPopUp; }
|
||||
void setShowPopUp(bool showPopUp) { m_showPopUp = showPopUp; }
|
||||
int brightnessLevel() const { return m_brightnessLevel; }
|
||||
@@ -22,13 +29,8 @@ private:
|
||||
m_showPopUp(true),
|
||||
m_brightnessLevel(Ion::Backlight::MaxBrightness) {}
|
||||
I18n::Language m_language;
|
||||
enum class ExamMode : uint8_t {
|
||||
Deactivate = 0,
|
||||
Activate = 1,
|
||||
Unknown = 2
|
||||
};
|
||||
static_assert((uint8_t)GlobalPreferences::ExamMode::Deactivate == 0, "GlobalPreferences::setExamMode and examMode() are not right");
|
||||
static_assert((uint8_t)GlobalPreferences::ExamMode::Activate == 1, "GlobalPreferences::setExamMode and examMode() are not right");
|
||||
static_assert((int8_t)GlobalPreferences::ExamMode::Off == 0, "GlobalPreferences::isInExamMode() is not right");
|
||||
static_assert((int8_t)GlobalPreferences::ExamMode::Unknown < 0, "GlobalPreferences::isInExamMode() is not right");
|
||||
mutable ExamMode m_examMode;
|
||||
bool m_showPopUp;
|
||||
int m_brightnessLevel;
|
||||
|
||||
@@ -59,8 +59,7 @@ bool Controller::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
|
||||
AppsContainer * container = AppsContainer::sharedAppsContainer();
|
||||
::App::Snapshot * selectedSnapshot = container->appSnapshotAtIndex(selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1);
|
||||
// TODO: check that we are in Dutch exam mode
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode() && selectedSnapshot->descriptor()->name() == I18n::Message::CodeApp) {
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch && selectedSnapshot->descriptor()->name() == I18n::Message::CodeApp) {
|
||||
App::app()->displayWarning(I18n::Message::ForbidenAppInExamMode1, I18n::Message::ForbidenAppInExamMode2);
|
||||
} else {
|
||||
bool switched = container->switchTo(selectedSnapshot);
|
||||
|
||||
@@ -49,7 +49,7 @@ void LogoController::viewDidDisappear() {
|
||||
Ion::LED::setColor(m_previousLEDColor);
|
||||
/* TODO: instead of setting again the exam mode, put the previous led color
|
||||
* AND BLINKING.*/
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) { // TODO
|
||||
AppsContainer::sharedAppsContainer()->activateExamMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ int ExamModeController::reusableCellCount(int type) {
|
||||
|
||||
void ExamModeController::willDisplayCellForIndex(HighlightCell * cell, int index) {
|
||||
GenericSubController::willDisplayCellForIndex(cell, index);
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
// TODO
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
|
||||
MessageTableCell * myCell = (MessageTableCell *)cell;
|
||||
myCell->setMessage(I18n::Message::ExamModeActive);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void TitleBarView::layoutSubviews() {
|
||||
m_preferenceView.setFrame(KDRect(Metric::TitleBarExternHorizontalMargin, 0, m_preferenceView.minimalSizeForOptimalDisplay().width(), bounds().height()));
|
||||
KDSize batterySize = m_batteryView.minimalSizeForOptimalDisplay();
|
||||
m_batteryView.setFrame(KDRect(bounds().width() - batterySize.width() - Metric::TitleBarExternHorizontalMargin, (bounds().height()- batterySize.height())/2, batterySize));
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
|
||||
m_examModeIconView.setFrame(KDRect(k_examIconMargin, (bounds().height() - k_examIconHeight)/2, k_examIconWidth, k_examIconHeight));
|
||||
} else {
|
||||
m_examModeIconView.setFrame(KDRectZero);
|
||||
|
||||
Reference in New Issue
Block a user