~aleteoryx/muditaos

ref: 592d314418e4a805fe828031cc29b5b1072e16c1 muditaos/module-apps/application-settings/windows/network/NetworkWindow.cpp -rw-r--r-- 6.1 KiB
592d3144 — Lukasz Mastalerz [BH-1696] Charging notifications improvements 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NetworkWindow.hpp"

#include <application-settings/ApplicationSettings.hpp>
#include <application-settings/windows/WindowNames.hpp>
#include <OptionSetting.hpp>
#include <widgets/ButtonTriState.hpp>

namespace
{
    cellular::VolteState getVolteStateFromSettingsApp(app::ApplicationCommon *application)
    {
        return static_cast<app::ApplicationSettings *>(application)->getVolteState();
    }
} // namespace

namespace gui
{
    NetworkWindow::NetworkWindow(app::ApplicationCommon *app,
                                 app::settingsInterface::OperatorsSettings *operatorsSettings)
        : BaseSettingsWindow(app, gui::window::name::network), operatorsSettings(operatorsSettings)
    {
        setTitle(utils::translate("app_settings_net"));
    }

    void NetworkWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        BaseSettingsWindow::onBeforeShow(mode, data);
    }

    auto NetworkWindow::buildOptionsList() -> std::list<gui::Option>
    {
        std::list<gui::Option> optionsList;

        optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_sim_cards"),
            [=]([[maybe_unused]] gui::Item &item) {
                application->switchWindow(gui::window::name::sim_cards, nullptr);
                return true;
            },
            nullptr,
            nullptr,
            gui::option::SettingRightItem::ArrowWhite,
            false));

        optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            getVolteLabel(),
            [this]([[maybe_unused]] gui::Item &item) {
                const auto volteState = getVolteStateFromSettingsApp(application);
                if (!volteState.permitted) {
                    return true;
                }

                const auto settingsApp = static_cast<app::ApplicationSettings *>(application);
                switch (volteState.enablement) {
                case cellular::VolteState::Enablement::Off:
                    settingsApp->sendVolteChangeRequest(true);
                    break;
                case cellular::VolteState::Enablement::On:
                    settingsApp->sendVolteChangeRequest(false);
                    break;
                default:
                    LOG_INFO("VoLTE state is unsettled, skipping request");
                    break;
                }

                return true;
            },
            [&](Item &item) {
                std::string labelText{};
                if (!item.focus) {
                    labelText = utils::translate("common_select");
                }
                else if (getVolteStateFromSettingsApp(application).permitted) {
                    labelText = utils::translate("common_switch");
                }
                navBar->setText(nav_bar::Side::Center, labelText);
                return true;
            },
            nullptr,
            getRightItemSetting()));

#if DISABLED_SETTINGS_OPTIONS == 1
        auto operatorsOn = operatorsSettings->getOperatorsOn();
        optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_operator_auto_select"),
            [=](gui::Item &item) {
                operatorsSettings->setOperatorsOn(!operatorsOn);
                refreshOptionsList();
                return true;
            },
            nullptr,
            nullptr,
            operatorsOn ? gui::option::SettingRightItem::On : gui::option::SettingRightItem::Off));
        if (!operatorsOn) {
            optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
                utils::translate("app_settings_network_all_operators"),
                [=](gui::Item &item) {
                    this->application->switchWindow(gui::window::name::all_operators, nullptr);
                    return true;
                },
                nullptr,
                nullptr,
                gui::option::SettingRightItem::ArrowWhite,
                false));
        }
#endif // DISABLED_SETTINGS_OPTIONS

        optionsList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_apn_settings"),
            [=]([[maybe_unused]] gui::Item &item) {
                application->switchWindow(gui::window::name::apn_settings, nullptr);
                return true;
            },
            nullptr,
            nullptr,
            gui::option::SettingRightItem::ArrowWhite,
            false));

        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select));

        return optionsList;
    }

    auto NetworkWindow::getVolteLabel() -> std::string
    {
        const auto &volteState = getVolteStateFromSettingsApp(application);

        auto labelText = "<text>" + utils::translate("app_settings_network_voice_over_lte");
        if (!volteState.permitted) {
            if (volteState.enablement == cellular::VolteState::Enablement::On) {
                LOG_ERROR("VoLTE still enabled in modem despite not permitted by operator");
            }
            labelText += ": ";
            labelText += utils::translate("app_settings_network_volte_not_available");
        }
        else if (volteState.beta) {
            labelText += " <b>" + utils::translate("common_beta") + "</b>";
        }
        labelText += "</text>";

        return labelText;
    }

    auto NetworkWindow::getRightItemSetting() -> option::SettingRightItem
    {
        const auto &volteState = getVolteStateFromSettingsApp(application);

        if (!volteState.permitted) {
            return option::SettingRightItem::Disabled;
        }

        switch (volteState.enablement) {
        case cellular::VolteState::Enablement::Off:
            return option::SettingRightItem::Off;
        case cellular::VolteState::Enablement::On:
            return option::SettingRightItem::On;
        default:
            return option::SettingRightItem::Transiting;
        }
    }
} // namespace gui