mirror of
https://github.com/mudita/MuditaOS.git
synced 2025-12-31 09:58:00 -05:00
Added error handling in case the file selected in the vertical list is either corrupted or deleted.
163 lines
8.2 KiB
C++
163 lines
8.2 KiB
C++
// Copyright (c) 2017-2024, 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 "data/AudioErrorParams.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> ¶ms) {
|
|
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> ¶ms) {
|
|
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> ¶ms) {
|
|
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> ¶ms) {
|
|
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> ¶ms) {
|
|
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;
|
|
}
|
|
|
|
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> ¶ms) {
|
|
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> ¶ms) {
|
|
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;
|
|
});
|
|
|
|
auto audioErrorBlueprint = [&](gui::popup::ID id, std::unique_ptr<gui::PopupRequestParams> ¶ms) {
|
|
auto popupParams = dynamic_cast<gui::AudioErrorParams *>(params.get());
|
|
if (popupParams == nullptr) {
|
|
return false;
|
|
}
|
|
switchWindowPopup(gui::popup::resolveWindowName(id),
|
|
popupParams->getDisposition(),
|
|
std::make_unique<gui::AudioErrorParams>(popupParams),
|
|
SwitchReason::Popup);
|
|
return true;
|
|
};
|
|
popupBlueprint.registerBlueprint(ID::AudioError, audioErrorBlueprint);
|
|
}
|
|
|
|
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
|