~aleteoryx/muditaos

ref: b95894a8abc10cddf0b58dda4b2569b01eec0d7e muditaos/module-apps/application-notes/windows/SearchEngineWindow.cpp -rw-r--r-- 2.8 KiB
b95894a8 — Lefucjusz [MOS-1064] Fix no input language selected for French/Spanish 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SearchEngineWindow.hpp"

#include <application-notes/ApplicationNotes.hpp>
#include <module-apps/application-notes/data/NotesFoundData.hpp>
#include <apps-common/widgets/InputBox.hpp>

#include <i18n/i18n.hpp>

namespace app::notes
{
    SearchEngineWindow::SearchEngineWindow(ApplicationCommon *application,
                                           std::unique_ptr<SearchEngineWindowContract::Presenter> &&windowPresenter)
        : gui::AppWindow{application, gui::name::window::notes_search}, presenter{std::move(windowPresenter)}
    {
        presenter->attach(this);
        buildInterface();
    }

    SearchEngineWindow::~SearchEngineWindow() noexcept
    {
        destroyInterface();
    }

    void SearchEngineWindow::buildInterface()
    {
        AppWindow::buildInterface();
        setTitle(utils::translate("app_notes_title_main"));

        navBar->setActive(gui::nav_bar::Side::Center, true);
        navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::search));
        navBar->setActive(gui::nav_bar::Side::Right, true);
        navBar->setText(gui::nav_bar::Side::Right, utils::translate(style::strings::common::back));

        input = gui::inputBox(this, utils::translate("common_search_uc"), "search_32px_W_G");
        input->setInputMode(new InputMode(
            {InputMode::Abc, InputMode::ABC, InputMode::abc, InputMode::digit},
            [=](const UTF8 &text) { application->getCurrentWindow()->navBarTemporaryMode(text); },
            [=]() { application->getCurrentWindow()->navBarRestoreFromTemporaryMode(); },
            [=]() { application->getCurrentWindow()->selectSpecialCharacter(); },
            [=](std::function<void()> restoreFunction) {
                application->getCurrentWindow()->startInputModeRestoreTimer(std::move(restoreFunction));
            }));
        setFocusItem(input);
    }

    void SearchEngineWindow::destroyInterface()
    {
        erase();
        input = nullptr;
    }

    bool SearchEngineWindow::onInput(const gui::InputEvent &inputEvent)
    {
        if (inputEvent.isShortRelease(gui::KeyCode::KEY_ENTER)) {
            presenter->searchFor(input->getText());
            return true;
        }
        return AppWindow::onInput(inputEvent);
    }

    void SearchEngineWindow::emptySearch()
    {
        application->switchWindow(gui::name::window::notes_search_result, std::make_unique<NotesFoundData>(""));
    }

    void SearchEngineWindow::processValidSearch(const std::string &searchText)
    {
        application->switchWindow(gui::name::window::notes_search_result, std::make_unique<NotesFoundData>(searchText));
    }
} // namespace app::notes