From bd4f5da0972b56b026b02c819dd0728f6bf89253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kamo=C5=84?= <70628259+mkamonMdt@users.noreply.github.com> Date: Tue, 1 Dec 2020 09:40:03 +0100 Subject: [PATCH] [EGD-4455] Desktop windows refactored (#1095) --- changelog.md | 2 + image/assets/lang/English.json | 2 +- .../data/AppDesktopStyle.hpp | 71 ++++++++-- .../widgets/PinLockHandler.cpp | 3 +- .../widgets/PinLockHandler.hpp | 4 + .../windows/DesktopMainWindow.cpp | 8 +- .../windows/LockedInfoWindow.cpp | 17 ++- .../windows/PinLockBaseWindow.cpp | 132 +++++++++++++++--- .../windows/PinLockBaseWindow.hpp | 36 ++++- .../windows/PinLockBox.hpp | 1 - .../windows/PinLockWindow.cpp | 21 ++- .../windows/PukLockBox.cpp | 80 ++++------- .../windows/PukLockBox.hpp | 3 +- .../windows/ScreenLockBox.cpp | 68 ++++----- .../windows/ScreenLockBox.hpp | 3 +- .../windows/SimLockBox.cpp | 79 +++-------- .../windows/SimLockBox.hpp | 3 +- 17 files changed, 314 insertions(+), 219 deletions(-) diff --git a/changelog.md b/changelog.md index 89ed363380bd8037ae1f4eae47adbbeaaf21d86e..f01020ddc5bddefa400210787e5d6b6aa6bd5f44 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,8 @@ ### Changed +* `[desktop]` Windows refactor + ### Fixed ### Other diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 0b5cbd434c47ac04b7957dbf71eb4f77d7d5af2a..732dc466d0eb12be8b39ad7a4017c2d7f5d39668 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -150,7 +150,7 @@ "app_desktop_unlock": "UNLOCK", "app_desktop_lock": "LOCK", "app_desktop_menu": "MENU", - "app_desktop_emergency": "EMERG.", + "app_desktop_emergency": "SOS", "app_desktop_screen_enter_passcode": "Enter passcode", "app_desktop_screen_wrong_pin": "Wrong passcode", "app_desktop_screen_allowed_attempts": "Allowed unlock attempts", diff --git a/module-apps/application-desktop/data/AppDesktopStyle.hpp b/module-apps/application-desktop/data/AppDesktopStyle.hpp index a12edc8c613eda09af4392ca6d0c4c077acb06b7..29f1ea1eb5a30a456e337a86d59f09454543b441 100644 --- a/module-apps/application-desktop/data/AppDesktopStyle.hpp +++ b/module-apps/application-desktop/data/AppDesktopStyle.hpp @@ -3,21 +3,62 @@ #pragma once -#include - namespace style::window::pin_lock { - constexpr inline auto image_x = 177; - constexpr inline auto image_y = 132; - constexpr inline auto title_label_y = 60; - constexpr inline auto title_label_h = 40; - constexpr inline auto label_size = 60; - constexpr inline auto label_margins = 10; - constexpr inline auto pin_label_x = 85; - constexpr inline auto pin_label_y = 450; - constexpr inline auto pin_label_y_screen = 400; - constexpr inline auto info_text_y = 294; - constexpr inline auto info_text_h_screen = 60; - constexpr inline auto info_text_h_sim = 150; - constexpr inline auto info_text_h_puk = 180; + namespace image + { + constexpr inline auto x = 177; + constexpr inline auto y = 132; + } // namespace image + + namespace pin_label + { + constexpr inline auto x = 85; + constexpr inline auto y = 400; + constexpr inline auto w = style::window_width - 2 * x; + + constexpr inline auto size = 60; + constexpr inline auto margin = 10; + } // namespace pin_label + + namespace title + { + constexpr inline auto x = 0; + constexpr inline auto y = 60; + constexpr inline auto w = style::window_width; + constexpr inline auto h = 50; + } // namespace title + + namespace ice + { + constexpr inline auto x = style::window::default_left_margin; + constexpr inline auto y = title::y; + constexpr inline auto w = 60; + constexpr inline auto h = title::h; + + constexpr inline auto margin = 3; + + namespace text + { + constexpr inline auto w = 40; + } + + } // namespace ice + + namespace primary_text + { + constexpr inline auto x = style::window::default_left_margin; + constexpr inline auto y = 294; + constexpr inline auto w = style::window_width - 2 * x; + constexpr inline auto h = 60; + } // namespace primary_text + + namespace secondary_text + { + constexpr inline auto x = style::window::default_left_margin; + constexpr inline auto y = primary_text::y + primary_text::h + 30; + constexpr inline auto w = style::window_width - 2 * x; + constexpr inline auto h = 90; + } // namespace secondary_text + } // namespace style::window::pin_lock diff --git a/module-apps/application-desktop/widgets/PinLockHandler.cpp b/module-apps/application-desktop/widgets/PinLockHandler.cpp index bed22f2a21bb272f6b771e8da8b29695bef4e1eb..7d2ac4bf641640ba9537c6465ed384402b4bd7c8 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.cpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.cpp @@ -73,6 +73,7 @@ namespace gui void PinLockHandler::handlePasscodeRequest(PinLock::LockType type, app::manager::actions::ActionParamsPtr &&data) { LOG_DEBUG("Handling on of PasscodeRequest actions"); + promptSimLockWindow = true; handlePasscodeParams(type, PinLock::LockState::PasscodeRequired, std::move(data)); if (!getStrongestLock().isType(PinLock::LockType::Screen)) { unlock(); @@ -129,9 +130,9 @@ namespace gui { auto lock = std::make_unique(getStrongestLock()); if (lock->isState(PinLock::LockState::PasscodeInvalidRetryRequired)) { + getStrongestLock().consumeState(); lock->onActivatedCallback = [this, onLockActivatedCallback](PinLock::LockType, const std::vector &) { - getStrongestLock().consumeState(); switchToPinLockWindow(onLockActivatedCallback); }; } diff --git a/module-apps/application-desktop/widgets/PinLockHandler.hpp b/module-apps/application-desktop/widgets/PinLockHandler.hpp index b02db9e243eb0df5ffb65fc4a0962e8487a2fa56..5a7e3ce8290562aafc9ee6799ff792e7fae0796d 100644 --- a/module-apps/application-desktop/widgets/PinLockHandler.hpp +++ b/module-apps/application-desktop/widgets/PinLockHandler.hpp @@ -59,6 +59,10 @@ namespace gui { return !screenLock.isState(PinLock::LockState::Unlocked); } + [[nodiscard]] auto isScreenBlocked() const noexcept -> bool + { + return screenLock.isState(PinLock::LockState::Blocked); + } void lockScreen(); void unlockScreen(); }; diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.cpp b/module-apps/application-desktop/windows/DesktopMainWindow.cpp index 5028b44e09377e0de1e99b0d7e903d9f56660586..a3ee1e80d25d136471fae3c037ca9b889fc83921 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.cpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.cpp @@ -91,8 +91,10 @@ namespace gui auto app = getAppDesktop(); if (app->lockHandler.isScreenLocked()) { bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("app_desktop_unlock")); - bottomBar->setActive(BottomBar::Side::LEFT, false); bottomBar->setActive(BottomBar::Side::RIGHT, false); + bottomBar->setText(BottomBar::Side::LEFT, + utils::localize.get("app_desktop_emergency"), + app->lockHandler.isScreenBlocked()); topBar->setActive(TopBar::Elements::LOCK, true); inputCallback = nullptr; setFocusItem(nullptr); @@ -194,6 +196,10 @@ namespace gui getAppDesktop()->lockHandler.unlockScreen(); return true; } + else if (inputEvent.is(KeyCode::KEY_LF) && bottomBar->isActive(BottomBar::Side::LEFT)) { + app::manager::Controller::sendAction(application, app::manager::actions::ShowEmergencyContacts); + return true; + } else if (enter_cache.storeEnter(inputEvent)) { return true; } diff --git a/module-apps/application-desktop/windows/LockedInfoWindow.cpp b/module-apps/application-desktop/windows/LockedInfoWindow.cpp index aeac0c791d9f42a73897918fa65bde8cd63ab1c4..9ad0bf32b2db6a6da8d0368153d53cfc14de36b9 100644 --- a/module-apps/application-desktop/windows/LockedInfoWindow.cpp +++ b/module-apps/application-desktop/windows/LockedInfoWindow.cpp @@ -63,23 +63,22 @@ void LockedInfoWindow::rebuild() void LockedInfoWindow::buildInterface() { + namespace lock_style = style::window::pin_lock; AppWindow::buildInterface(); bottomBar->setText(BottomBar::Side::LEFT, utils::localize.get("app_desktop_emergency")); bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back")); - lockImage = - new gui::Image(this, style::window::pin_lock::image_x, style::window::pin_lock::image_y, 0, 0, "pin_lock"); - - infoText = new Text(this, - 0, - style::window::pin_lock::info_text_y, - style::window_width, - style::window::pin_lock::info_text_h_screen); + lockImage = new gui::Image(this, lock_style::image::x, lock_style::image::y, 0, 0, "pin_lock"); + infoText = new Text(this, + lock_style::primary_text::x, + lock_style::primary_text::y, + lock_style::primary_text::w, + lock_style::primary_text::h); TextFormat format(FontManager::getInstance().getFont(style::window::font::medium)); text::RichTextParser rtParser; - auto parsedText = rtParser.parse(utils::localize.get("app_desktop_no_pin_lock"), &format); + auto parsedText = rtParser.parse(utils::localize.get("app_desktop_press_to_unlock"), &format); infoText->setText(std::move(parsedText)); infoText->setAlignment(Alignment::Horizontal::Center); diff --git a/module-apps/application-desktop/windows/PinLockBaseWindow.cpp b/module-apps/application-desktop/windows/PinLockBaseWindow.cpp index 023024553ab733d22ebc70a2597edeec19c1b3d6..bad5320e1ce54304aa63f682697e28d014f75d41 100644 --- a/module-apps/application-desktop/windows/PinLockBaseWindow.cpp +++ b/module-apps/application-desktop/windows/PinLockBaseWindow.cpp @@ -6,6 +6,8 @@ #include "application-desktop/widgets/PinLock.hpp" #include +#include "FontManager.hpp" + namespace lock_style = style::window::pin_lock; namespace gui { @@ -14,7 +16,8 @@ namespace gui { buildBottomBar(); buildTopBar(); - buildTitleLabel(); + buildTitleBar(); + buildInfoTexts(); } void PinLockBaseWindow::buildBottomBar() { @@ -29,23 +32,47 @@ namespace gui topBar->setActive(TopBar::Elements::BATTERY, true); topBar->setActive(TopBar::Elements::LOCK, true); } - void PinLockBaseWindow::buildTitleLabel() + void PinLockBaseWindow::buildTitleBar() { - titleLabel = new gui::Label(this, 0, lock_style::title_label_y, style::window_width, lock_style::title_label_h); - titleLabel->setFilled(false); - titleLabel->setVisible(false); - titleLabel->setBorderColor(gui::ColorFullBlack); - titleLabel->setFont(style::header::font::title); - titleLabel->setText(utils::localize.get("app_desktop_pin_info1")); - titleLabel->setEdges(RectangleEdge::None); - titleLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom)); + using namespace style::window::pin_lock; + + iceBox = new gui::HBox(this, ice::x, ice::y, ice::w, ice::h); + iceBox->setAlignment(Alignment(Alignment::Horizontal::Left, Alignment::Vertical::Center)); + iceBox->setEdges(RectangleEdge::None); + iceBox->setVisible(false); + + auto arrow = new gui::Image("left_label_arrow"); + arrow->activeItem = false; + arrow->setAlignment(Alignment(Alignment::Horizontal::Left, Alignment::Vertical::Center)); + arrow->setMargins(Margins(0, 0, ice::margin, 0)); + iceBox->addWidget(arrow); + + auto iceText = new gui::Text(nullptr, 0, 0, ice::text::w, ice::h); + iceText->activeItem = false; + iceText->setAlignment(Alignment(Alignment::Horizontal::Left, Alignment::Vertical::Center)); + iceText->setFont(style::window::font::verysmall); + iceText->setText(utils::localize.get("app_desktop_emergency")); + iceBox->addWidget(iceText); + + title = new gui::Text(this, title::x, title::y, title::w, title::h); + title->setFilled(false); + title->setBorderColor(gui::ColorFullBlack); + title->setFont(style::header::font::title); + title->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + title->setVisible(false); + title->setPenWidth(2); } - void PinLockBaseWindow::buildInfoText(unsigned int h) + void PinLockBaseWindow::buildInfoTexts() { - infoText = new Text(this, 0, lock_style::info_text_y, style::window_width, h); - infoText->setFont(style::window::font::medium); - infoText->setVisible(true); - infoText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); + using namespace style::window::pin_lock; + + primaryText = new Text(this, primary_text::x, primary_text::y, primary_text::w, primary_text::h); + primaryText->setFont(style::window::font::medium); + primaryText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); + + secondaryText = new Text(this, secondary_text::x, secondary_text::y, secondary_text::w, secondary_text::h); + secondaryText->setFont(style::window::font::medium); + secondaryText->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); } void PinLockBaseWindow::buildPinLabels(std::function itemBuilder, unsigned int pinSize, @@ -53,7 +80,7 @@ namespace gui unsigned int offsetY, unsigned int boxWidth) { - pinLabelsBox = new gui::HBox(this, offsetX, offsetY, boxWidth, lock_style::label_size); + pinLabelsBox = new gui::HBox(this, offsetX, offsetY, boxWidth, lock_style::pin_label::size); pinLabelsBox->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); if (pinSize == 0) { @@ -73,9 +100,8 @@ namespace gui } void PinLockBaseWindow::buildImages(const std::string &lockImg, const std::string &infoImg) { - lockImage = new gui::Image(this, lock_style::image_x, lock_style::image_y, 0, 0, lockImg); - infoImage = new gui::Image(this, lock_style::image_x, lock_style::image_y, 0, 0, infoImg); - infoImage->setVisible(false); + lockImage = new gui::Image(this, lock_style::image::x, lock_style::image::y, 0, 0, lockImg); + infoImage = new gui::Image(this, lock_style::image::x, lock_style::image::y, 0, 0, infoImg); } void PinLockBaseWindow::setBottomBarWidgetsActive(bool left, bool center, bool right) { @@ -88,8 +114,72 @@ namespace gui lockImage->setVisible(lockImg); infoImage->setVisible(infoImg); } - void PinLockBaseWindow::setBottomBarWidgetText(BottomBar::Side side, const UTF8 &txt) + + void PinLockBaseWindow::setTitleBar(bool isVisible, bool isIceActive) + { + iceBox->setVisible(isIceActive); + title->setVisible(isVisible); + if (isVisible) { + title->setEdges(RectangleEdge::Bottom); + } + else { + title->clear(); + title->setEdges(RectangleEdge::None); + } + } + + void PinLockBaseWindow::setText(const std::string &value, + TextType type, + bool isReach, + text::RichTextParser::TokenMap tokens) + { + auto text = getText(type); + text->setVisible(true); + if (isReach) { + TextFormat format(FontManager::getInstance().getFont(style::window::font::medium)); + text::RichTextParser rtParser; + auto parsedText = rtParser.parse(utils::localize.get(value), &format, std::move(tokens)); + text->setText(std::move(parsedText)); + } + else { + text->setText(utils::localize.get(value)); + } + } + + auto PinLockBaseWindow::getText(TextType type) noexcept -> gui::Text * + { + if (type == TextType::Title) { + return title; + } + else if (type == TextType::Primary) { + return primaryText; + } + return secondaryText; + } + + void PinLockBaseWindow::restore() noexcept + { + primaryText->setVisible(false); + secondaryText->setVisible(false); + lockImage->setVisible(false); + infoImage->setVisible(false); + pinLabelsBox->setVisible(false); + } + + auto PinLockBaseWindow::getToken(Token token) const -> std::string { - bottomBar->setText(side, txt, false); + if (token == Token::Sim) { + return "$SIM"; + } + else if (token == Token::Attempts) { + return "$ATTEMPTS"; + } + else if (token == Token::Mins) { + return "$MINUTES"; + } + else if (token == Token::CmeCode) { + return "$CMECODE"; + } + return std::string{}; } } // namespace gui diff --git a/module-apps/application-desktop/windows/PinLockBaseWindow.hpp b/module-apps/application-desktop/windows/PinLockBaseWindow.hpp index 753e0f3127b9ee58b28e8a1ed0759f037bb2c6b8..5b684859cf3476812f41fdb9d6f09cd12056fe34 100644 --- a/module-apps/application-desktop/windows/PinLockBaseWindow.hpp +++ b/module-apps/application-desktop/windows/PinLockBaseWindow.hpp @@ -6,6 +6,8 @@ #include "AppWindow.hpp" #include "Text.hpp" +#include "RichTextParser.hpp" + namespace gui { class PinLock; @@ -16,10 +18,25 @@ namespace gui class PinLockBaseWindow : public AppWindow { public: + enum class TextType + { + Title, + Primary, + Secondary + }; + + enum class Token + { + Sim, + Attempts, + Mins, + CmeCode + }; + PinLockBaseWindow(app::Application *app, std::string name) : AppWindow(app, name) {} void build(); - void buildInfoText(unsigned int textHight); + void buildInfoTexts(); void buildPinLabels(std::function itemBuilder, unsigned int pinSize, unsigned int offsetX, @@ -28,10 +45,18 @@ namespace gui void buildImages(const std::string &lockImg, const std::string &infoImg); void setBottomBarWidgetsActive(bool left, bool center, bool right); void setImagesVisible(bool lockImg, bool infoImg); - void setBottomBarWidgetText(BottomBar::Side side, const UTF8 &txt); + void setTitleBar(bool isVisible, bool isIceActive); + void setText(const std::string &value, + TextType type, + bool isReach = false, + text::RichTextParser::TokenMap tokens = text::RichTextParser::TokenMap{}); + void restore() noexcept; + [[nodiscard]] auto getToken(Token token) const -> std::string; - gui::Label *titleLabel = nullptr; - gui::Text *infoText = nullptr; + gui::HBox *iceBox = nullptr; + gui::Text *title = nullptr; + gui::Text *primaryText = nullptr; + gui::Text *secondaryText = nullptr; gui::Image *lockImage = nullptr; gui::Image *infoImage = nullptr; gui::HBox *pinLabelsBox = nullptr; @@ -41,6 +66,7 @@ namespace gui private: void buildBottomBar(); void buildTopBar(); - void buildTitleLabel(); + void buildTitleBar(); + [[nodiscard]] auto getText(TextType type) noexcept -> gui::Text *; }; } // namespace gui diff --git a/module-apps/application-desktop/windows/PinLockBox.hpp b/module-apps/application-desktop/windows/PinLockBox.hpp index 78c520e49678a66c760df416c9ba8dee92816a42..58882f6ab6d23507a00ff8869ef1edd340cea31a 100644 --- a/module-apps/application-desktop/windows/PinLockBox.hpp +++ b/module-apps/application-desktop/windows/PinLockBox.hpp @@ -29,7 +29,6 @@ namespace gui virtual void clear() = 0; virtual void setVisibleStateEnterPin(EnterPasscodeType type) = 0; - virtual void setVisibleStateVerifiedPin() = 0; virtual void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) = 0; virtual void setVisibleStateBlocked() = 0; diff --git a/module-apps/application-desktop/windows/PinLockWindow.cpp b/module-apps/application-desktop/windows/PinLockWindow.cpp index 0d8fd99e59ac10db0e7ee3d1b69d2aca082c2bfb..9744cbc76b2be93197bafa981a62ebd8a86fce31 100644 --- a/module-apps/application-desktop/windows/PinLockWindow.cpp +++ b/module-apps/application-desktop/windows/PinLockWindow.cpp @@ -47,15 +47,18 @@ namespace gui void PinLockWindow::invalidate() noexcept { - titleLabel = nullptr; + iceBox = nullptr; + title = nullptr; lockImage = nullptr; infoImage = nullptr; - infoText = nullptr; + primaryText = nullptr; + secondaryText = nullptr; pinLabelsBox = nullptr; } void PinLockWindow::setVisibleState() { + restore(); if (lock->isState(PinLock::LockState::PasscodeRequired)) { LockBox->setVisibleStateEnterPin(PinLockBox::EnterPasscodeType::ProvidePasscode); } @@ -83,11 +86,8 @@ namespace gui void PinLockWindow::onBeforeShow(ShowMode mode, SwitchData *data) { - if (mode == ShowMode::GUI_SHOW_INIT) { - rebuild(); - } if (auto lockData = dynamic_cast(data)) { - assert(lockData); + rebuild(); lockTimeoutApplication = lockData->getPreviousApplication(); lock = lockData->getLock(); assert(lock); @@ -111,7 +111,11 @@ namespace gui return AppWindow::onInput(inputEvent); } // accept only LF, enter, RF, #, and numeric values; - if (inputEvent.is(KeyCode::KEY_LF) && bottomBar->isActive(BottomBar::Side::LEFT)) { + if (inputEvent.is(KeyCode::KEY_LEFT) && iceBox->visible) { + app::manager::Controller::sendAction(application, app::manager::actions::ShowEmergencyContacts); + return true; + } + else if (inputEvent.is(KeyCode::KEY_LF) && bottomBar->isActive(BottomBar::Side::LEFT)) { app::manager::Controller::sendAction(application, app::manager::actions::ShowEmergencyContacts); return true; } @@ -143,6 +147,7 @@ namespace gui } else if (inputEvent.is(KeyCode::KEY_ENTER) && bottomBar->isActive(BottomBar::Side::CENTER)) { lock->activate(); + bottomBar->setActive(BottomBar::Side::CENTER, false); return true; } // check if any of the lower inheritance onInput methods catch the event @@ -157,6 +162,8 @@ namespace gui } else if (lockType == PinLock::LockType::SimPuk) { LockBox = std::make_unique(this); + setTitleBar(true, true); + setText("app_desktop_header_sim_setup", TextType::Title, true, {{getToken(Token::Sim), "SIM1"}}); } else if (lockType == PinLock::LockType::SimPin) { LockBox = std::make_unique(this); diff --git a/module-apps/application-desktop/windows/PukLockBox.cpp b/module-apps/application-desktop/windows/PukLockBox.cpp index ba476075e6e35127b970fcb751fc3046fe830d73..819db8a244abffddd0a72047cc38dd9acadb7e18 100644 --- a/module-apps/application-desktop/windows/PukLockBox.cpp +++ b/module-apps/application-desktop/windows/PukLockBox.cpp @@ -6,13 +6,11 @@ #include "PinLockBaseWindow.hpp" #include "application-desktop/widgets/PinLock.hpp" #include "application-desktop/data/AppDesktopStyle.hpp" -#include "gui/widgets/Label.hpp" #include "gui/widgets/Image.hpp" #include #include -namespace lock_style = style::window::pin_lock; - +namespace label_style = style::window::pin_lock::pin_label; namespace gui { void PukLockBox::popChar(unsigned int charNum) @@ -26,7 +24,6 @@ namespace gui void PukLockBox::buildLockBox(unsigned int pinSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - LockWindow->buildInfoText(lock_style::info_text_h_puk); buildPinLabels(0); } void PukLockBox::buildPinLabels(unsigned int pinSize) @@ -36,11 +33,7 @@ namespace gui return label; }; - LockWindow->buildPinLabels(itemBuilder, - pinSize, - lock_style::pin_label_x, - lock_style::pin_label_y, - style::window_width - 2 * lock_style::pin_label_x); + LockWindow->buildPinLabels(itemBuilder, pinSize, label_style::x, label_style::y, label_style::w); LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom); } @@ -53,80 +46,55 @@ namespace gui void PukLockBox::setVisibleStateEnterPin(EnterPasscodeType type) { LockWindow->pinLabelsBox->setVisible(true); - LockWindow->infoText->clear(); - switch (type) { - case PinLockBox::EnterPasscodeType::ProvidePasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_blocked")); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_type_puk")); + case PinLockBox::EnterPasscodeType::ProvidePasscode: { + LockWindow->setText("app_desktop_sim_setup_enter_puk", PinLockBaseWindow::TextType::Primary, true); break; - case PinLockBox::EnterPasscodeType::ProvideNewPasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_enter_pin")); + } + case PinLockBox::EnterPasscodeType::ProvideNewPasscode: { + LockWindow->setText("app_desktop_sim_enter_new_pin", PinLockBaseWindow::TextType::Primary); break; + } case PinLockBox::EnterPasscodeType::ConfirmNewPasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_confirm_pin")); + LockWindow->setText("app_desktop_sim_confirm_new_pin", PinLockBaseWindow::TextType::Primary); + break; } - LockWindow->infoText->setVisible(true); LockWindow->setImagesVisible(true, false); LockWindow->setBottomBarWidgetsActive(false, false, true); } - void PukLockBox::setVisibleStateVerifiedPin() - { - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->infoText->setVisible(false); - } void PukLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) { - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->infoText->clear(); - switch (type) { case PinLockBox::PasscodeErrorType::InvalidPasscode: - - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_wrong_puk")); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_you_have")); - LockWindow->infoText->addText(" "); - LockWindow->infoText->addText(std::to_string(value)); - LockWindow->infoText->addText(" "); - if (value > 1) { - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_plural")); + LockWindow->setText("app_desktop_sim_setup_wrong_puk", + PinLockBaseWindow::TextType::Primary, + true, + {{LockWindow->getToken(PinLockBaseWindow::Token::Attempts), value}}); } else { - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_singular")); - LockWindow->infoText->addText("\n\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_warning1")); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_warning2")); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_warning3")); + LockWindow->setText( + "app_desktop_sim_setup_wrong_puk_last_attempt", PinLockBaseWindow::TextType::Primary, true); + LockWindow->setText("app_desktop_sim_setup_wrong_puk_last_attempt_warning", + PinLockBaseWindow::TextType::Secondary, + true); } break; - case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: - LockWindow->infoText->setText(utils::localize.get("app_desktop_sim_wrong_pin")); + case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: { + LockWindow->setText("app_desktop_sim_wrong_pin", PinLockBaseWindow::TextType::Primary); break; + } case PinLockBox::PasscodeErrorType::UnhandledError: LOG_ERROR("No use case for UnhandledError in PukLockBox"); break; } - - LockWindow->infoText->setVisible(true); LockWindow->setImagesVisible(false, true); - LockWindow->setBottomBarWidgetsActive(true, true, false); + LockWindow->setBottomBarWidgetsActive(false, true, false); } void PukLockBox::setVisibleStateBlocked() { - LockWindow->pinLabelsBox->setVisible(false); - - LockWindow->infoText->clear(); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_blocked_info1")); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_blocked_info2")); - LockWindow->infoText->setVisible(true); - + LockWindow->setText("app_desktop_sim_puk_blocked", PinLockBaseWindow::TextType::Primary, true); LockWindow->setImagesVisible(false, true); LockWindow->setBottomBarWidgetsActive(true, false, false); } diff --git a/module-apps/application-desktop/windows/PukLockBox.hpp b/module-apps/application-desktop/windows/PukLockBox.hpp index 6ca72c0b98800c5048a16afb334beb07234c648e..c6d986121844f832abb3f1f107854ab6786ce529 100644 --- a/module-apps/application-desktop/windows/PukLockBox.hpp +++ b/module-apps/application-desktop/windows/PukLockBox.hpp @@ -22,10 +22,9 @@ namespace gui PinLockBaseWindow *LockWindow; void popChar(unsigned int charNum) final; void putChar(unsigned int charNum) final; - virtual void clear() final; + void clear() final; void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateVerifiedPin() final; void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; void setVisibleStateBlocked() final; diff --git a/module-apps/application-desktop/windows/ScreenLockBox.cpp b/module-apps/application-desktop/windows/ScreenLockBox.cpp index 0290397fa94cb2d3cce8db7550fff155ce31b7fb..8dfc072aa60e391dbadf03558194eccd7d7c2751 100644 --- a/module-apps/application-desktop/windows/ScreenLockBox.cpp +++ b/module-apps/application-desktop/windows/ScreenLockBox.cpp @@ -10,11 +10,13 @@ #include "gui/widgets/Image.hpp" #include -namespace lock_style = style::window::pin_lock; +namespace label_style = style::window::pin_lock::pin_label; namespace gui { + constexpr auto timeToUnlock = 10; + ScreenLockBox::PinLabel::PinLabel(Item *parent, uint32_t w, uint32_t h) : HBox(parent, 0, 0, w, h) {} void ScreenLockBox::PinLabel::setVisibleState(bool isImageVisible) @@ -46,7 +48,6 @@ namespace gui void ScreenLockBox::buildLockBox(unsigned int pinSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - LockWindow->buildInfoText(lock_style::info_text_h_screen); ScreenLockBox::buildPinLabels(pinSize); } void ScreenLockBox::buildPinLabels(unsigned int pinSize) @@ -58,80 +59,67 @@ namespace gui return; } - unsigned int singleLabelWidth = lock_style::label_size; - unsigned int maxNoMarginsLabelsWidth = pinLabelWidth - pinSize * 2 * lock_style::label_margins; + unsigned int singleLabelWidth = label_style::size; + unsigned int maxNoMarginsLabelsWidth = pinLabelWidth - pinSize * 2 * label_style::margin; if (pinSize * singleLabelWidth > maxNoMarginsLabelsWidth) { singleLabelWidth = maxNoMarginsLabelsWidth / pinSize; } auto itemBuilder = [this, singleLabelWidth]() { - auto label = new PinLabel(nullptr, singleLabelWidth, lock_style::label_size); + auto label = new PinLabel(nullptr, singleLabelWidth, label_style::size); label->setEdges(RectangleEdge::Bottom); - label->setMargins(Margins(lock_style::label_margins, 0, lock_style::label_margins, 0)); + label->setMargins(Margins(label_style::margin, 0, label_style::margin, 0)); pinLabels.push_back(label); return label; }; LockWindow->buildPinLabels( - itemBuilder, pinSize, style::window::default_left_margin, lock_style::pin_label_y_screen, pinLabelWidth); + itemBuilder, pinSize, style::window::default_left_margin, label_style::y, pinLabelWidth); LockWindow->pinLabelsBox->setEdges(RectangleEdge::None); } void ScreenLockBox::setVisibleStateEnterPin(EnterPasscodeType type) { LockWindow->pinLabelsBox->setVisible(true); - - LockWindow->infoText->clear(); - LockWindow->infoText->addText(utils::localize.get("app_desktop_screen_enter_passcode")); - LockWindow->infoText->setVisible(true); - + LockWindow->setText("app_desktop_screen_enter_passcode_to_unlock", PinLockBaseWindow::TextType::Primary, true); LockWindow->setImagesVisible(true, false); LockWindow->setBottomBarWidgetsActive(true, false, true); } - void ScreenLockBox::setVisibleStateVerifiedPin() - { - clear(); - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->titleLabel->setVisible(false); - } + void ScreenLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) { - clear(); - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->infoText->clear(); - LockWindow->titleLabel->setVisible(true); switch (type) { case PinLockBox::PasscodeErrorType::InvalidPasscode: - LockWindow->titleLabel->setText(utils::localize.get("app_desktop_screen_wrong_pin")); - - LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_sim_you_have"))); - LockWindow->infoText->addText(" "); - LockWindow->infoText->addText(std::to_string(value)); - LockWindow->infoText->addText(" "); - LockWindow->infoText->addText( - utils::localize.get(utils::localize.get("app_desktop_sim_attempt_left_plural"))); + LockWindow->setTitleBar(false, false); + if (value == 1) { + LockWindow->setText( + "app_desktop_screen_wrong_passcode_last_attempt", PinLockBaseWindow::TextType::Primary, true); + LockWindow->setText("app_desktop_screen_wrong_passcode_last_attempt_warning", + PinLockBaseWindow::TextType::Secondary, + true, + {{LockWindow->getToken(PinLockBaseWindow::Token::Mins), timeToUnlock}}); + } + else { + LockWindow->setText("app_desktop_screen_wrong_passcode", + PinLockBaseWindow::TextType::Primary, + true, + {{LockWindow->getToken(PinLockBaseWindow::Token::Attempts), value}}); + } break; + case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: - LockWindow->titleLabel->setText(utils::localize.get("app_desktop_screen_wrong_passcode")); + LockWindow->setText("app_desktop_screen_setup_wrong_passcode", PinLockBaseWindow::TextType::Primary, true); break; case PinLockBox::PasscodeErrorType::UnhandledError: LOG_ERROR("No use case for UnhandledError"); break; } - - LockWindow->infoText->setVisible(true); LockWindow->setImagesVisible(false, true); LockWindow->setBottomBarWidgetsActive(false, true, true); } void ScreenLockBox::setVisibleStateBlocked() { - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->titleLabel->setVisible(false); - - LockWindow->infoText->clear(); - LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_screen_blocked_info"))); - LockWindow->infoText->setVisible(true); - + LockWindow->setText("app_desktop_screen_blocked", PinLockBaseWindow::TextType::Primary); LockWindow->setImagesVisible(false, true); LockWindow->setBottomBarWidgetsActive(false, true, false); } diff --git a/module-apps/application-desktop/windows/ScreenLockBox.hpp b/module-apps/application-desktop/windows/ScreenLockBox.hpp index fb88316cea87acef8de9fdc577e079b88123ebf6..f58d01539361a19df1713e64acdfa87cfaf889d0 100644 --- a/module-apps/application-desktop/windows/ScreenLockBox.hpp +++ b/module-apps/application-desktop/windows/ScreenLockBox.hpp @@ -32,10 +32,9 @@ namespace gui PinLockBaseWindow *LockWindow; void popChar(unsigned int charNum) final; void putChar(unsigned int charNum) final; - virtual void clear() final; + void clear() final; void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateVerifiedPin() final; void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; void setVisibleStateBlocked() final; diff --git a/module-apps/application-desktop/windows/SimLockBox.cpp b/module-apps/application-desktop/windows/SimLockBox.cpp index 2405b64e346c0c2578c430fdee72682abc3f02b4..8eb9b20c8ab116c8a97fe618a256c6b1b8553ce0 100644 --- a/module-apps/application-desktop/windows/SimLockBox.cpp +++ b/module-apps/application-desktop/windows/SimLockBox.cpp @@ -6,14 +6,9 @@ #include "PinLockBaseWindow.hpp" #include "application-desktop/widgets/PinLock.hpp" #include "application-desktop/data/AppDesktopStyle.hpp" -#include "gui/widgets/Label.hpp" -#include "RichTextParser.hpp" -#include "FontManager.hpp" - -#include #include -namespace lock_style = style::window::pin_lock; +namespace label_style = style::window::pin_lock::pin_label; namespace gui { @@ -30,7 +25,6 @@ namespace gui void SimLockBox::buildLockBox(unsigned int pinSize) { LockWindow->buildImages("pin_lock", "pin_lock_info"); - LockWindow->buildInfoText(lock_style::info_text_h_sim); buildPinLabels(0); } void SimLockBox::buildPinLabels(unsigned int pinSize) @@ -40,11 +34,7 @@ namespace gui return label; }; - LockWindow->buildPinLabels(itemBuilder, - pinSize, - lock_style::pin_label_x, - lock_style::pin_label_y, - style::window_width - 2 * lock_style::pin_label_x); + LockWindow->buildPinLabels(itemBuilder, pinSize, label_style::x, label_style::y, label_style::w); LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom); } @@ -57,79 +47,56 @@ namespace gui void SimLockBox::setVisibleStateEnterPin(EnterPasscodeType type) { LockWindow->pinLabelsBox->setVisible(true); - LockWindow->infoText->clear(); - switch (type) { - case PinLockBox::EnterPasscodeType::ProvidePasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_to_unlock")); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_card")); - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_type_pin")); + case PinLockBox::EnterPasscodeType::ProvidePasscode: { + LockWindow->setText("app_desktop_sim_enter_pin_unlock", PinLockBaseWindow::TextType::Primary, true); break; + } case PinLockBox::EnterPasscodeType::ProvideNewPasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_enter_pin")); + LockWindow->setText("app_desktop_sim_enter_new_pin", PinLockBaseWindow::TextType::Primary); break; case PinLockBox::EnterPasscodeType::ConfirmNewPasscode: - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_confirm_pin")); + LockWindow->setText("app_desktop_sim_confirm_new_pin", PinLockBaseWindow::TextType::Primary); break; } - LockWindow->infoText->setVisible(true); LockWindow->setImagesVisible(true, false); LockWindow->setBottomBarWidgetsActive(false, false, true); } - void SimLockBox::setVisibleStateVerifiedPin() - { - LockWindow->infoText->clear(); - LockWindow->infoText->setVisible(false); - LockWindow->pinLabelsBox->setVisible(false); - } void SimLockBox::setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) { - LockWindow->pinLabelsBox->setVisible(false); - - LockWindow->infoText->clear(); - switch (type) { case PinLockBox::PasscodeErrorType::InvalidPasscode: - LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_sim_wrong_pin"))); - LockWindow->infoText->addText("\n"); - LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_sim_you_have"))); - LockWindow->infoText->addText(" "); - LockWindow->infoText->addText(std::to_string(value)); - LockWindow->infoText->addText(" "); - if (value > 1) { - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_plural")); + if (value == 1) { + LockWindow->setText( + "app_desktop_sim_setup_wrong_pin_last_attempt", PinLockBaseWindow::TextType::Primary, true); } else { - LockWindow->infoText->addText(utils::localize.get("app_desktop_sim_attempt_left_singular")); + LockWindow->setText("app_desktop_sim_setup_wrong_pin", + PinLockBaseWindow::TextType::Primary, + true, + {{LockWindow->getToken(PinLockBaseWindow::Token::Attempts), value}}); } - LockWindow->infoText->setVisible(true); - - LockWindow->setImagesVisible(false, true); - LockWindow->setBottomBarWidgetsActive(true, true, true); break; case PinLockBox::PasscodeErrorType::NewPasscodeConfirmFailed: - LockWindow->infoText->setText(utils::localize.get("app_desktop_sim_wrong_pin")); + LockWindow->setText("app_desktop_sim_wrong_pin", PinLockBaseWindow::TextType::Primary); break; case PinLockBox::PasscodeErrorType::UnhandledError: { - TextFormat format(FontManager::getInstance().getFont(style::window::font::medium)); - text::RichTextParser rtParser; - auto parsedText = rtParser.parse(utils::localize.get("app_desktop_sim_cme_error"), &format); - LockWindow->infoText->setText(std::move(parsedText)); - LockWindow->infoText->addText(std::to_string(value)); + LockWindow->setText("app_desktop_sim_cme_error", + PinLockBaseWindow::TextType::Primary, + true, + {{LockWindow->getToken(PinLockBaseWindow::Token::CmeCode), value}}); break; } } + LockWindow->setImagesVisible(false, true); + LockWindow->setBottomBarWidgetsActive(false, true, true); } void SimLockBox::setVisibleStateBlocked() { - LockWindow->pinLabelsBox->setVisible(false); - LockWindow->infoText->clear(); - LockWindow->infoText->addText(utils::localize.get(utils::localize.get("app_desktop_puk_lock1"))); - LockWindow->infoText->setVisible(true); - + LockWindow->setText("app_desktop_sim_puk_blocked", PinLockBaseWindow::TextType::Primary); LockWindow->setImagesVisible(false, true); - LockWindow->setBottomBarWidgetsActive(true, true, true); + LockWindow->setBottomBarWidgetsActive(false, true, true); } void SimLockBox::clear() diff --git a/module-apps/application-desktop/windows/SimLockBox.hpp b/module-apps/application-desktop/windows/SimLockBox.hpp index 3290409663fadcdae0d51791d4d0605395371748..32084178fbea92da6c60d8c829218e2680b4d950 100644 --- a/module-apps/application-desktop/windows/SimLockBox.hpp +++ b/module-apps/application-desktop/windows/SimLockBox.hpp @@ -22,10 +22,9 @@ namespace gui PinLockBaseWindow *LockWindow; void popChar(unsigned int charNum) final; void putChar(unsigned int charNum) final; - virtual void clear() final; + void clear() final; void setVisibleStateEnterPin(EnterPasscodeType type) final; - void setVisibleStateVerifiedPin() final; void setVisibleStateInvalidPin(PasscodeErrorType type, unsigned int value) final; void setVisibleStateBlocked() final;