~aleteoryx/muditaos

muditaos/module-apps/application-messages/windows/SearchResults.cpp -rw-r--r-- 2.6 KiB
a405cad6Aleteoryx trim readme 6 days 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-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "ApplicationMessages.hpp"
#include "MessagesStyle.hpp"
#include "SearchResults.hpp"
#include "SMSTextToSearch.hpp"
#include "ThreadRecord.hpp"

#include <i18n/i18n.hpp>
#include <queries/messages/threads/QueryThreadsSearchForList.hpp>
#include <service-db/QueryMessage.hpp>

namespace gui
{
    SearchResults::SearchResults(app::ApplicationCommon *app) : AppWindow(app, name::window::search_results)
    {
        namespace msgThreadStyle = style::messages::threads;

        AppWindow::buildInterface();
        setTitle(utils::translate("app_messages_title_main"));
        navBar->setActive(nav_bar::Side::Center, true);
        navBar->setActive(nav_bar::Side::Right, true);
        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::search));
        navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));
        body = new gui::Item();
        body->setBoundingBox(bodySize());
        addWidget(body);

        model = std::make_shared<model::ThreadsSearchResultsModel>(application);

        list = new gui::ListView(this,
                                 msgThreadStyle::listPositionX,
                                 msgThreadStyle::ListPositionY,
                                 msgThreadStyle::listWidth,
                                 msgThreadStyle::listHeight,
                                 model,
                                 listview::ScrollBarType::Fixed);
        list->setScrollTopMargin(style::margins::small);
        setFocusItem(list);

        list->emptyListCallback = [this]() { showEmptyResults(); };
    }

    void SearchResults::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (mode == ShowMode::GUI_SHOW_INIT && data != nullptr) {
            if (auto search_data = dynamic_cast<SMSTextToSearch *>(data)) {
                if (listViewRequest(search_data->getTextToSearch()) == false) {
                    showEmptyResults();
                }
            }
        }
    }

    bool SearchResults::listViewRequest(const std::string &text)
    {
        if (text.length() != 0u) {
            model->setSearchValue(text);
            list->rebuildList();
            setFocusItem(list);
            return true;
        }
        return false;
    }

    bool SearchResults::showEmptyResults()
    {
        auto app = dynamic_cast<app::ApplicationMessages *>(application);
        assert(app);
        return app->searchEmpty();
    }
}; // namespace gui