diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 70ac5cbde..bee6ddd4e 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -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. */ diff --git a/apps/exam_pop_up_controller.cpp b/apps/exam_pop_up_controller.cpp index 38d6d90ce..a51286e81 100644 --- a/apps/exam_pop_up_controller.cpp +++ b/apps/exam_pop_up_controller.cpp @@ -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(); diff --git a/apps/global_preferences.cpp b/apps/global_preferences.cpp index b78102ba9..52572a469 100644 --- a/apps/global_preferences.cpp +++ b/apps/global_preferences.cpp @@ -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) { diff --git a/apps/global_preferences.h b/apps/global_preferences.h index f9fe8e044..a7d0790ea 100644 --- a/apps/global_preferences.h +++ b/apps/global_preferences.h @@ -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; diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index 221ba5ec9..00c2f287a 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -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); diff --git a/apps/on_boarding/logo_controller.cpp b/apps/on_boarding/logo_controller.cpp index 91ea5173e..56aabfb2d 100644 --- a/apps/on_boarding/logo_controller.cpp +++ b/apps/on_boarding/logo_controller.cpp @@ -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(); } } diff --git a/apps/settings/sub_menu/exam_mode_controller.cpp b/apps/settings/sub_menu/exam_mode_controller.cpp index 1590f04c4..83709a5b4 100644 --- a/apps/settings/sub_menu/exam_mode_controller.cpp +++ b/apps/settings/sub_menu/exam_mode_controller.cpp @@ -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); } diff --git a/apps/title_bar_view.cpp b/apps/title_bar_view.cpp index fc5c23992..53cee9ab5 100644 --- a/apps/title_bar_view.cpp +++ b/apps/title_bar_view.cpp @@ -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);