mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:50:05 +00:00
Add audio settings
This commit is contained in:
parent
9486d2364a
commit
ec97231bca
6 changed files with 206 additions and 3 deletions
131
scwx-qt/source/scwx/qt/settings/audio_settings.cpp
Normal file
131
scwx-qt/source/scwx/qt/settings/audio_settings.cpp
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
#include <scwx/qt/settings/audio_settings.hpp>
|
||||
#include <scwx/qt/settings/settings_definitions.hpp>
|
||||
#include <scwx/qt/settings/settings_variable.hpp>
|
||||
#include <scwx/qt/types/alert_types.hpp>
|
||||
#include <scwx/qt/types/location_types.hpp>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
|
||||
static const std::string logPrefix_ = "scwx::qt::settings::audio_settings";
|
||||
|
||||
static const bool kDefaultAlertEnabled_ {false};
|
||||
static const awips::Phenomenon kDefaultPhenomenon_ {
|
||||
awips::Phenomenon::FlashFlood};
|
||||
|
||||
class AudioSettings::Impl
|
||||
{
|
||||
public:
|
||||
explicit Impl()
|
||||
{
|
||||
std::string defaultAlertLocationMethodValue =
|
||||
types::GetLocationMethodName(types::LocationMethod::Fixed);
|
||||
|
||||
boost::to_lower(defaultAlertLocationMethodValue);
|
||||
|
||||
alertLocationMethod_.SetDefault(defaultAlertLocationMethodValue);
|
||||
alertLatitude_.SetDefault(0.0);
|
||||
alertLongitude_.SetDefault(0.0);
|
||||
|
||||
alertLatitude_.SetMinimum(-90.0);
|
||||
alertLatitude_.SetMaximum(90.0);
|
||||
alertLongitude_.SetMinimum(-180.0);
|
||||
alertLongitude_.SetMaximum(180.0);
|
||||
|
||||
alertLocationMethod_.SetValidator(
|
||||
SCWX_SETTINGS_ENUM_VALIDATOR(types::LocationMethod,
|
||||
types::LocationMethodIterator(),
|
||||
types::GetLocationMethodName));
|
||||
|
||||
for (auto& phenomenon : types::GetAlertAudioPhenomena())
|
||||
{
|
||||
std::string phenomenonCode = awips::GetPhenomenonCode(phenomenon);
|
||||
std::string name = fmt::format("{}_enabled", phenomenonCode);
|
||||
|
||||
auto result =
|
||||
alertEnabled_.emplace(phenomenon, SettingsVariable<bool> {name});
|
||||
|
||||
SettingsVariable<bool>& variable = result.first->second;
|
||||
|
||||
variable.SetDefault(kDefaultAlertEnabled_);
|
||||
|
||||
variables_.push_back(&variable);
|
||||
}
|
||||
}
|
||||
|
||||
~Impl() {}
|
||||
|
||||
SettingsVariable<std::string> alertLocationMethod_ {"alert_location_method"};
|
||||
SettingsVariable<double> alertLatitude_ {"alert_latitude"};
|
||||
SettingsVariable<double> alertLongitude_ {"alert_longitude"};
|
||||
|
||||
std::unordered_map<awips::Phenomenon, SettingsVariable<bool>>
|
||||
alertEnabled_ {};
|
||||
std::vector<SettingsVariableBase*> variables_ {};
|
||||
};
|
||||
|
||||
AudioSettings::AudioSettings() :
|
||||
SettingsCategory("audio"), p(std::make_unique<Impl>())
|
||||
{
|
||||
RegisterVariables(
|
||||
{&p->alertLocationMethod_, &p->alertLatitude_, &p->alertLongitude_});
|
||||
RegisterVariables(p->variables_);
|
||||
SetDefaults();
|
||||
|
||||
p->variables_.clear();
|
||||
}
|
||||
AudioSettings::~AudioSettings() = default;
|
||||
|
||||
AudioSettings::AudioSettings(AudioSettings&&) noexcept = default;
|
||||
AudioSettings& AudioSettings::operator=(AudioSettings&&) noexcept = default;
|
||||
|
||||
SettingsVariable<std::string>& AudioSettings::alert_location_method() const
|
||||
{
|
||||
return p->alertLocationMethod_;
|
||||
}
|
||||
|
||||
SettingsVariable<double>& AudioSettings::alert_latitude() const
|
||||
{
|
||||
return p->alertLatitude_;
|
||||
}
|
||||
|
||||
SettingsVariable<double>& AudioSettings::alert_longitude() const
|
||||
{
|
||||
return p->alertLongitude_;
|
||||
}
|
||||
|
||||
SettingsVariable<bool>&
|
||||
AudioSettings::alert_enabled(awips::Phenomenon phenomenon) const
|
||||
{
|
||||
auto alert = p->alertEnabled_.find(phenomenon);
|
||||
if (alert == p->alertEnabled_.cend())
|
||||
{
|
||||
alert = p->alertEnabled_.find(kDefaultPhenomenon_);
|
||||
}
|
||||
return alert->second;
|
||||
}
|
||||
|
||||
AudioSettings& AudioSettings::Instance()
|
||||
{
|
||||
static AudioSettings audioSettings_;
|
||||
return audioSettings_;
|
||||
}
|
||||
|
||||
bool operator==(const AudioSettings& lhs, const AudioSettings& rhs)
|
||||
{
|
||||
return (lhs.p->alertLocationMethod_ == rhs.p->alertLocationMethod_ &&
|
||||
lhs.p->alertLatitude_ == rhs.p->alertLatitude_ &&
|
||||
lhs.p->alertLongitude_ == rhs.p->alertLongitude_ &&
|
||||
lhs.p->alertEnabled_ == rhs.p->alertEnabled_);
|
||||
}
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
45
scwx-qt/source/scwx/qt/settings/audio_settings.hpp
Normal file
45
scwx-qt/source/scwx/qt/settings/audio_settings.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/settings/settings_category.hpp>
|
||||
#include <scwx/qt/settings/settings_variable.hpp>
|
||||
#include <scwx/awips/phenomenon.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace settings
|
||||
{
|
||||
|
||||
class AudioSettings : public SettingsCategory
|
||||
{
|
||||
public:
|
||||
explicit AudioSettings();
|
||||
~AudioSettings();
|
||||
|
||||
AudioSettings(const AudioSettings&) = delete;
|
||||
AudioSettings& operator=(const AudioSettings&) = delete;
|
||||
|
||||
AudioSettings(AudioSettings&&) noexcept;
|
||||
AudioSettings& operator=(AudioSettings&&) noexcept;
|
||||
|
||||
SettingsVariable<std::string>& alert_location_method() const;
|
||||
SettingsVariable<double>& alert_latitude() const;
|
||||
SettingsVariable<double>& alert_longitude() const;
|
||||
SettingsVariable<bool>& alert_enabled(awips::Phenomenon phenomenon) const;
|
||||
|
||||
static AudioSettings& Instance();
|
||||
|
||||
friend bool operator==(const AudioSettings& lhs, const AudioSettings& rhs);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> p;
|
||||
};
|
||||
|
||||
} // namespace settings
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
20
scwx-qt/source/scwx/qt/settings/settings_definitions.hpp
Normal file
20
scwx-qt/source/scwx/qt/settings/settings_definitions.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#define SCWX_SETTINGS_ENUM_VALIDATOR(Type, Iterator, ToName) \
|
||||
[](const std::string& value) \
|
||||
{ \
|
||||
for (Type enumValue : Iterator) \
|
||||
{ \
|
||||
/* If the value is equal to a lower case name */ \
|
||||
std::string enumName = ToName(enumValue); \
|
||||
boost::to_lower(enumName); \
|
||||
if (value == enumName) \
|
||||
{ \
|
||||
/* Regard as a match, valid */ \
|
||||
return true; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* No match found, invalid */ \
|
||||
return false; \
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue