~aleteoryx/muditaos

ref: 1340e6949c0762585b0de844863c91c859fb19b1 muditaos/module-apps/apps-common/ApplicationCommonPopupBlueprints.cpp -rw-r--r-- 7.9 KiB
1340e694 — Bartosz Revert "[MOS-578] Fix incorrect logic with SMS notifications" 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AppWindow.hpp"
#include "ApplicationCommon.hpp"
#include "data/AlarmPopupRequestParams.hpp"
#include "service-db/Settings.hpp"
#include "service-db/agents/settings/SystemSettings.hpp"
#include "popups/data/PopupData.hpp"

namespace app
{
    void ApplicationCommon::registerPopupBlueprints()
    {
        using namespace gui::popup;

        popupBlueprint.registerBlueprint(
            ID::PhoneModes, [&](gui::popup::ID /*id*/, std::unique_ptr<gui::PopupRequestParams> &params) {
                auto popupParams = dynamic_cast<gui::PhoneModePopupRequestParams *>(params.get());
                if (popupParams == nullptr) {
                    return false;
                }
                const auto &mode = popupParams->getPhoneMode();
                auto flightModeSetting =
                    settings->getValue(settings::Cellular::offlineMode, settings::SettingsScope::Global);
                bool flightMode = flightModeSetting == "1";

                const auto &popupName = resolveWindowName(gui::popup::ID::PhoneModes);
                if (const auto currentWindowName = getCurrentWindow()->getName(); currentWindowName == popupName) {
                    updateCurrentWindow(std::make_unique<gui::ModesPopupData>(mode, flightMode));
                }
                else {
                    switchWindowPopup(popupName,
                                      popupParams->getDisposition(),
                                      std::make_unique<gui::ModesPopupData>(mode, flightMode),
                                      SwitchReason::Popup);
                }
                return true;
            });

        popupBlueprint.registerBlueprint(
            ID::Volume, [&](gui::popup::ID /*id*/, std::unique_ptr<gui::PopupRequestParams> &params) {
                auto volumeParams = dynamic_cast<const gui::VolumePopupRequestParams *>(params.get());
                if (volumeParams == nullptr) {
                    return false;
                }
                LOG_INFO("Playback: %s, volume: %s",
                         audio::str(volumeParams->getAudioContext().second).c_str(),
                         std::to_string(volumeParams->getVolume()).c_str());
                auto volume    = volumeParams->getVolume();
                auto context   = volumeParams->getAudioContext();
                auto source    = volumeParams->getRequestSource();
                auto popupData = std::make_unique<gui::VolumePopupData>(volume, context, source);

                const auto popupName = resolveWindowName(gui::popup::ID::Volume);
                if (const auto currentWindowName = getCurrentWindow()->getName(); currentWindowName == popupName) {
                    updateCurrentWindow(std::move(popupData));
                }
                else {
                    switchWindowPopup(
                        popupName, volumeParams->getDisposition(), std::move(popupData), SwitchReason::Popup);
                }
                return true;
            });

        popupBlueprint.registerBlueprint(
            ID::BluetoothAuthenticate, [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &params) {
                switchWindowPopup(resolveWindowName(id),
                                  gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::High),
                                  std::move(params),
                                  SwitchReason::Popup);
                return true;
            });
        popupBlueprint.registerBlueprint(
            ID::BluetoothInfo, [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &params) {
                switchWindowPopup(resolveWindowName(id),
                                  gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::High),
                                  std::move(params),
                                  SwitchReason::Popup);
                return true;
            });

        popupBlueprint.registerBlueprint(
            ID::PhoneLock, [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> & /*params*/) {
                switchWindowPopup(resolveWindowName(id),
                                  gui::popup::popupDisposition(id, gui::popup::Disposition::Priority::Normal),
                                  nullptr,
                                  SwitchReason::PhoneLock);
                return true;
            });
        auto phoneLockBlueprint = [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &params) {
            auto popupParams = dynamic_cast<gui::PhoneUnlockInputRequestParams *>(params.get());
            if (popupParams == nullptr) {
                LOG_ERROR("this is most probably due to wrong unique_ptr handling - please check");
                return false;
            }

            popupParams->setDisposition(gui::popup::Disposition{gui::popup::Disposition::Priority::Normal,
                                                                gui::popup::Disposition::WindowType::Popup,
                                                                params->getPopupId()});
            switchWindowPopup(
                gui::popup::resolveWindowName(id),
                popupParams->getDisposition(),
                std::make_unique<locks::LockData>(popupParams->getLock(), popupParams->getPhoneLockInputTypeAction()));
            return true;
        };
        popupBlueprint.registerBlueprint(ID::PhoneLockInput, phoneLockBlueprint);
        popupBlueprint.registerBlueprint(ID::PhoneLockChangeInfo, phoneLockBlueprint);

        auto simLockBlueprint = [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &params) {
            auto popupParams = dynamic_cast<const gui::SimUnlockInputRequestParams *>(params.get());
            if (popupParams == nullptr) {
                return false;
            }
            switchWindowPopup(gui::popup::resolveWindowName(id),
                              popupParams->getDisposition(),
                              std::make_unique<locks::SimLockData>(popupParams->getLock(),
                                                                   popupParams->getSimInputTypeAction(),
                                                                   popupParams->getErrorCode()));
            return true;
        };
        popupBlueprint.registerBlueprint(ID::SimLock, simLockBlueprint);
        popupBlueprint.registerBlueprint(ID::SimInfo, simLockBlueprint);
        popupBlueprint.registerBlueprint(
            ID::Alarm, [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &params) {
                auto popupParams = dynamic_cast<gui::AlarmPopupRequestParams *>(params.get());
                if (popupParams == nullptr) {
                    return false;
                }
                popupParams->setDisposition(gui::popup::Disposition{gui::popup::Disposition::Priority::High,
                                                                    gui::popup::Disposition::WindowType::Popup,
                                                                    params->getPopupId()});
                switchWindowPopup(gui::popup::resolveWindowName(id),
                                  popupParams->getDisposition(),
                                  std::make_unique<gui::AlarmPopupRequestParams>(popupParams));
                return true;
            });
    }

    std::optional<gui::popup::Blueprint> ApplicationCommon::popupBlueprintFallback(gui::popup::ID id)
    {
        popupBlueprint.registerBlueprint(
            id, [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> &p) -> bool {
                switchWindowPopup(
                    gui::popup::resolveWindowName(id), p->getDisposition(), nullptr, SwitchReason::PhoneLock);
                return true;
            });
        return *popupBlueprint.getBlueprint(id);
    }
} // namespace app