~aleteoryx/muditaos

ref: 6665a43d2b901b89809c4f18338d8ea6c0b08df7 muditaos/module-apps/application-phonebook/windows/PhonebookSearchResults.cpp -rw-r--r-- 4.4 KiB
6665a43d — Lefucjusz [BH-1780] Fix uncaught std::filesystem::file_size exception 2 years 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PhonebookSearchResults.hpp"
#include <Icon.hpp>
#include "application-phonebook/ApplicationPhonebook.hpp"
#include "application-phonebook/data/PhonebookStyle.hpp"

#include <service-db/QueryMessage.hpp>
#include <queries/phonebook/QueryContactGet.hpp>

namespace gui
{
    PhonebookSearchResults::PhonebookSearchResults(app::ApplicationCommon *app)
        : AppWindow(app, gui::window::name::search_results)
    {
        buildInterface();
    }

    void PhonebookSearchResults::rebuild()
    {
        destroyInterface();
        buildInterface();
    }

    void PhonebookSearchResults::buildInterface()
    {

        AppWindow::buildInterface();

        searchResultList = new gui::PhonebookListView(this,
                                                      phonebookStyle::searchResultsWindow::searchResultList::x,
                                                      phonebookStyle::searchResultsWindow::searchResultList::y,
                                                      phonebookStyle::searchResultsWindow::searchResultList::w,
                                                      phonebookStyle::searchResultsWindow::searchResultList::h,
                                                      phonebookModel);
        searchResultList->setBoundaries(Boundaries::Continuous);
        setFocusItem(searchResultList);

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

        icon = new Icon(this,
                        style::window::default_left_margin,
                        style::window::default_vertical_pos,
                        style::window::default_body_width,
                        style::window::default_body_height,
                        "",
                        "");

        icon->text->addRichText(utils::translate("app_phonebook_search_no_results"));
        icon->image->set("search_128px_W_G");
        icon->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
        icon->image->setMargins(Margins(0, icon::image_top_margin, 0, icon::image_bottom_margin));
        icon->setVisible(false);

        setTitle(utils::translate("common_results_prefix"));
    }

    void PhonebookSearchResults::destroyInterface()
    {
        erase();
    }

    PhonebookSearchResults::~PhonebookSearchResults()
    {
        destroyInterface();
    }

    void PhonebookSearchResults::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        // Model's data might have changed between calls
        if (mode == ShowMode::GUI_SHOW_RETURN) {
            handleContentUpdate();
        }
        searchResultList->rebuildList();
    }

    auto PhonebookSearchResults::handleSwitchData(SwitchData *data) -> bool
    {
        if (data == nullptr) {
            return false;
        }

        const auto searchResultsData = dynamic_cast<PhonebookSearchResultsData *>(data);
        assert(searchResultsData != nullptr);

        phonebookModel     = searchResultsData->phonebookModel;
        searchRequestModel = searchResultsData->searchRequestModel;
        searchResultList->setProvider(phonebookModel);
        handleContentUpdate();

        return true;
    }
    void PhonebookSearchResults::handleContentUpdate()
    {
        setTitle(utils::translate("common_results_prefix") + "\"" + phonebookModel->getFilter() + "\"");

        if (phonebookModel->requestRecordsCount() > 0) {
            navBar->setActive(nav_bar::Side::Left, true);
            navBar->setText(nav_bar::Side::Left, utils::translate(style::strings::common::call));
            navBar->setActive(nav_bar::Side::Center, true);
            if (searchRequestModel->requestedSearch()) {
                navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select));
            }
            else {
                navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::open));
            }

            setFocusItem(searchResultList);
        }
        else {
            navBar->setActive(nav_bar::Side::Left, false);
            navBar->setActive(nav_bar::Side::Center, false);
            setFocusItem(icon);
        }
    }

} /* namespace gui */