mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-18 12:04:03 -04:00
Applications configure the top bar once for all their windows. Sometimes, windows need to configure top bars with its configuration.
86 lines
2.8 KiB
C++
86 lines
2.8 KiB
C++
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "PhonebookSearch.hpp"
|
|
#include "application-phonebook/ApplicationPhonebook.hpp"
|
|
#include "application-phonebook/data/PhonebookItemData.hpp"
|
|
#include "widgets/InputBox.hpp"
|
|
|
|
namespace gui
|
|
{
|
|
PhonebookSearch::PhonebookSearch(app::Application *app) : AppWindow(app, gui::window::name::search)
|
|
{
|
|
buildInterface();
|
|
}
|
|
|
|
void PhonebookSearch::buildInterface()
|
|
{
|
|
AppWindow::buildInterface();
|
|
|
|
setTitle(utils::localize.get("app_phonebook_title_main"));
|
|
|
|
inputField = inputBox(this, utils::localize.get("common_search_uc"), "search");
|
|
inputField->setInputMode(new InputMode(
|
|
{InputMode::ABC, InputMode::abc, InputMode::digit},
|
|
[=](const UTF8 &Text) { application->getCurrentWindow()->bottomBarTemporaryMode(Text); },
|
|
[=]() { application->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
|
|
[=]() { application->getCurrentWindow()->selectSpecialCharacter(); }));
|
|
|
|
bottomBar->setActive(BottomBar::Side::LEFT, false);
|
|
bottomBar->setActive(BottomBar::Side::CENTER, true);
|
|
bottomBar->setActive(BottomBar::Side::RIGHT, true);
|
|
|
|
bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::search));
|
|
bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
|
|
|
|
setFocusItem(inputField);
|
|
}
|
|
|
|
auto PhonebookSearch::handleSwitchData(SwitchData *data) -> bool
|
|
{
|
|
if (data == nullptr) {
|
|
LOG_ERROR("Received null pointer");
|
|
return false;
|
|
}
|
|
|
|
auto item = dynamic_cast<PhonebookSearchQuery *>(data);
|
|
assert(item != nullptr);
|
|
inputField->setText(item->getQuery());
|
|
|
|
return true;
|
|
}
|
|
|
|
void PhonebookSearch::onBeforeShow(ShowMode mode, SwitchData *data)
|
|
{
|
|
inputField->clear();
|
|
setFocusItem(inputField);
|
|
}
|
|
|
|
auto PhonebookSearch::onInput(const InputEvent &inputEvent) -> bool
|
|
{
|
|
if (AppWindow::onInput(inputEvent)) {
|
|
return true;
|
|
}
|
|
if (!inputEvent.isShortPress()) {
|
|
return false;
|
|
}
|
|
if (!inputEvent.is(gui::KeyCode::KEY_ENTER)) {
|
|
return false;
|
|
}
|
|
|
|
std::string searchFilter = utils::trim(inputField->getText());
|
|
if (searchFilter.empty()) {
|
|
return false;
|
|
}
|
|
|
|
auto app = dynamic_cast<app::ApplicationPhonebook *>(application);
|
|
if (app == nullptr) {
|
|
LOG_ERROR("Failed to get phonebook application.");
|
|
return false;
|
|
}
|
|
|
|
app->onSearchRequest(searchFilter);
|
|
return true;
|
|
}
|
|
} // namespace gui
|