mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #697 BlackMisc settings renamed and reorganized.
This commit is contained in:
@@ -21,6 +21,6 @@
|
||||
#include "blackmisc/audio/audiodeviceinfolist.h"
|
||||
#include "blackmisc/audio/voiceroom.h"
|
||||
#include "blackmisc/audio/voiceroomlist.h"
|
||||
#include "blackmisc/audio/settings/settingsaudio.h"
|
||||
#include "blackmisc/audio/audiosettings.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
59
src/blackmisc/audio/audiosettings.cpp
Normal file
59
src/blackmisc/audio/audiosettings.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/audio/audiosettings.h"
|
||||
|
||||
#include <QChar>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc::Audio;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
CSettings::CSettings()
|
||||
{
|
||||
this->initDefaultValues();
|
||||
}
|
||||
|
||||
bool CSettings::getNotificationFlag(CNotificationSounds::Notification notification) const
|
||||
{
|
||||
const int i = static_cast<int>(notification);
|
||||
if (i >= m_notificationFlags.length()) return true; // default
|
||||
QChar f = m_notificationFlags.at(i);
|
||||
return '1' == f;
|
||||
}
|
||||
|
||||
QString CSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("Notification flags:");
|
||||
s.append(" ").append(m_notificationFlags);
|
||||
return s;
|
||||
}
|
||||
|
||||
void CSettings::initDefaultValues()
|
||||
{
|
||||
this->initNotificationFlags();
|
||||
}
|
||||
|
||||
void CSettings::initNotificationFlags()
|
||||
{
|
||||
// if we add flags in the future, we automatically extend ...
|
||||
constexpr int l = 1 + static_cast<int>(CNotificationSounds::Notification::NotificationsLoadSounds);
|
||||
if (this->m_notificationFlags.length() < l)
|
||||
{
|
||||
int cl = m_notificationFlags.length();
|
||||
this->m_notificationFlags.append(QString(l - cl, '1'));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
65
src/blackmisc/audio/audiosettings.h
Normal file
65
src/blackmisc/audio/audiosettings.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AUDIO_SETTINGS_H
|
||||
#define BLACKMISC_AUDIO_SETTINGS_H
|
||||
|
||||
#include "blackmisc/audio/notificationsounds.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
//! Value object encapsulating information of audio related settings.
|
||||
class BLACKMISC_EXPORT CSettings : public CValueObject<CSettings>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CSettings();
|
||||
|
||||
//! Notification flag (play notification?)
|
||||
bool getNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification) const;
|
||||
|
||||
//! Notification flag (play notification?)
|
||||
void setNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification, bool value);
|
||||
|
||||
//! Settings value
|
||||
BlackMisc::CStatusMessage value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag);
|
||||
|
||||
//! Init with meaningful default values
|
||||
void initDefaultValues();
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_notificationFlags; //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..)
|
||||
void initNotificationFlags(); //!< init flags
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettings,
|
||||
BLACK_METAMEMBER(notificationFlags)
|
||||
);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Audio::CSettings)
|
||||
|
||||
#endif // guard
|
||||
@@ -23,7 +23,7 @@ namespace BlackMisc
|
||||
CAudioDeviceInfoList::registerMetadata();
|
||||
CVoiceRoom::registerMetadata();
|
||||
CVoiceRoomList::registerMetadata();
|
||||
Settings::CSettingsAudio::registerMetadata();
|
||||
CSettings::registerMetadata();
|
||||
qDBusRegisterMetaType<BlackMisc::Audio::CNotificationSounds::PlayMode>();
|
||||
qDBusRegisterMetaType<BlackMisc::Audio::CNotificationSounds::Notification>();
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/audio/settings/settingsaudio.h"
|
||||
|
||||
#include <QChar>
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc::Audio;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingsAudio::CSettingsAudio()
|
||||
{
|
||||
this->initDefaultValues();
|
||||
}
|
||||
|
||||
bool CSettingsAudio::getNotificationFlag(CNotificationSounds::Notification notification) const
|
||||
{
|
||||
const int i = static_cast<int>(notification);
|
||||
if (i >= m_notificationFlags.length()) return true; // default
|
||||
QChar f = m_notificationFlags.at(i);
|
||||
return '1' == f;
|
||||
}
|
||||
|
||||
QString CSettingsAudio::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("Notification flags:");
|
||||
s.append(" ").append(m_notificationFlags);
|
||||
return s;
|
||||
}
|
||||
|
||||
void CSettingsAudio::initDefaultValues()
|
||||
{
|
||||
this->initNotificationFlags();
|
||||
}
|
||||
|
||||
void CSettingsAudio::initNotificationFlags()
|
||||
{
|
||||
// if we add flags in the future, we automatically extend ...
|
||||
constexpr int l = 1 + static_cast<int>(CNotificationSounds::Notification::NotificationsLoadSounds);
|
||||
if (this->m_notificationFlags.length() < l)
|
||||
{
|
||||
int cl = m_notificationFlags.length();
|
||||
this->m_notificationFlags.append(QString(l - cl, '1'));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -1,69 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AUDIO_SETTINGS_AUDIO_H
|
||||
#define BLACKMISC_AUDIO_SETTINGS_AUDIO_H
|
||||
|
||||
#include "blackmisc/audio/notificationsounds.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/metaclass.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Value object encapsulating information of audio related settings.
|
||||
class BLACKMISC_EXPORT CSettingsAudio : public CValueObject<CSettingsAudio>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CSettingsAudio();
|
||||
|
||||
//! Notification flag (play notification?)
|
||||
bool getNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification) const;
|
||||
|
||||
//! Notification flag (play notification?)
|
||||
void setNotificationFlag(BlackMisc::Audio::CNotificationSounds::Notification notification, bool value);
|
||||
|
||||
//! Settings value
|
||||
BlackMisc::CStatusMessage value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag);
|
||||
|
||||
//! Init with meaningful default values
|
||||
void initDefaultValues();
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
QString m_notificationFlags; //!< play notification for notification x, a little trick to use a string here (streamable, hashable, ..)
|
||||
void initNotificationFlags(); //!< init flags
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsAudio,
|
||||
BLACK_METAMEMBER(notificationFlags)
|
||||
);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Audio::Settings::CSettingsAudio)
|
||||
|
||||
#endif // guard
|
||||
@@ -28,7 +28,6 @@ TRANSLATIONS += translations/blackmisc_i18n_de.ts \
|
||||
|
||||
HEADERS += *.h \
|
||||
$$PWD/audio/*.h \
|
||||
$$PWD/audio/settings/*.h \
|
||||
$$PWD/aviation/*.h \
|
||||
$$PWD/db/*.h \
|
||||
$$PWD/geo/*.h \
|
||||
@@ -38,7 +37,6 @@ HEADERS += *.h \
|
||||
$$PWD/pq/*.h \
|
||||
$$PWD/simulation/*.h \
|
||||
$$PWD/simulation/data/*.h \
|
||||
$$PWD/simulation/settings/*.h \
|
||||
$$PWD/simulation/fscommon/*.h \
|
||||
$$PWD/simulation/fsx/*.h \
|
||||
$$PWD/simulation/xplane/*.h \
|
||||
@@ -46,7 +44,6 @@ HEADERS += *.h \
|
||||
|
||||
SOURCES += *.cpp \
|
||||
$$PWD/audio/*.cpp \
|
||||
$$PWD/audio/settings/*.cpp \
|
||||
$$PWD/aviation/*.cpp \
|
||||
$$PWD/db/*.cpp \
|
||||
$$PWD/geo/*.cpp \
|
||||
@@ -55,7 +52,6 @@ SOURCES += *.cpp \
|
||||
$$PWD/network/*.cpp \
|
||||
$$PWD/pq/*.cpp \
|
||||
$$PWD/simulation/*.cpp \
|
||||
$$PWD/simulation/settings/*.cpp \
|
||||
$$PWD/simulation/data/*.cpp \
|
||||
$$PWD/simulation/fscommon/*.cpp \
|
||||
$$PWD/simulation/fsx/*.cpp \
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace BlackMisc
|
||||
|
||||
/*!
|
||||
* Class template for accessing a specific value in the CSettingsCache.
|
||||
* \tparam Trait A subclass of BlackMisc::CSettingTrait that identifies the value's key and other metadata.
|
||||
* \tparam Trait A subclass of BlackMisc::TSettingTrait that identifies the value's key and other metadata.
|
||||
*/
|
||||
template <typename Trait>
|
||||
class CSetting : public BlackMisc::CCached<typename Trait::type>
|
||||
@@ -91,7 +91,7 @@ namespace BlackMisc
|
||||
|
||||
/*!
|
||||
* Class template for accessing a specific value in the CSettingsCache.
|
||||
* \tparam Trait A subclass of BlackMisc::CSettingTrait that identifies the value's key and other metadata.
|
||||
* \tparam Trait A subclass of BlackMisc::TSettingTrait that identifies the value's key and other metadata.
|
||||
*/
|
||||
template <typename Trait>
|
||||
class CSettingReadOnly : public BlackMisc::CSetting<Trait>
|
||||
@@ -115,7 +115,7 @@ namespace BlackMisc
|
||||
* Base class for traits to be used as template argument to BlackMisc::CSetting.
|
||||
*/
|
||||
template <typename T>
|
||||
struct CSettingTrait
|
||||
struct TSettingTrait
|
||||
{
|
||||
//! Data type of the value.
|
||||
using type = T;
|
||||
@@ -135,13 +135,13 @@ namespace BlackMisc
|
||||
static const T &defaultValue() { static const T def {}; return def; }
|
||||
|
||||
//! Deleted default constructor.
|
||||
CSettingTrait() = delete;
|
||||
TSettingTrait() = delete;
|
||||
|
||||
//! Deleted copy constructor.
|
||||
CSettingTrait(const CSettingTrait &) = delete;
|
||||
TSettingTrait(const TSettingTrait &) = delete;
|
||||
|
||||
//! Deleted copy assignment operator.
|
||||
CSettingTrait &operator =(const CSettingTrait &) = delete;
|
||||
TSettingTrait &operator =(const TSettingTrait &) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <QtGlobal>
|
||||
|
||||
using namespace BlackMisc::Simulation::Data;
|
||||
using namespace BlackMisc::Simulation::Settings;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
#include "blackmisc/simulation/settings/settingssimulator.h"
|
||||
#include "blackmisc/simulation/simulationsettings.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace BlackMisc
|
||||
std::atomic<bool> m_cancelLoading { false }; //!< flag
|
||||
std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress
|
||||
BlackMisc::Simulation::Data::CModelCaches m_caches { this }; //!< caches
|
||||
BlackMisc::Simulation::Settings::CMultiSimulatorSimulatorSettings m_settings { this }; //!< settings
|
||||
BlackMisc::Simulation::CMultiSimulatorSettings m_settings { this }; //!< settings
|
||||
|
||||
protected slots:
|
||||
//! Loading finished
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::Settings;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackMisc
|
||||
|
||||
@@ -9,12 +9,11 @@
|
||||
|
||||
#include "registermetadatasimulation.h"
|
||||
#include "simulation.h"
|
||||
#include "blackmisc/simulation/settings/settingssimulator.h"
|
||||
#include "blackmisc/simulation/simulationsettings.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Simulation::Settings;
|
||||
using namespace BlackMisc::Simulation::Fsx;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
|
||||
@@ -42,7 +41,7 @@ namespace BlackMisc
|
||||
CSimulatorSetup::registerMetadata();
|
||||
CVPilotModelRule::registerMetadata();
|
||||
CVPilotModelRuleSet::registerMetadata();
|
||||
CSettingsSimulator::registerMetadata();
|
||||
CSettings::registerMetadata();
|
||||
CSettingsSimulatorMessages::registerMetadata();
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -1,442 +0,0 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "settingssimulator.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingsSimulator::CSettingsSimulator()
|
||||
{ }
|
||||
|
||||
void CSettingsSimulator::setSimulatorDirectory(const QString &simulatorDirectory)
|
||||
{
|
||||
this->m_simulatorDirectory = simulatorDirectory.trimmed();
|
||||
}
|
||||
|
||||
const QString &CSettingsSimulator::getSimulatorDirectory() const
|
||||
{
|
||||
return this->m_simulatorDirectory;
|
||||
}
|
||||
|
||||
void CSettingsSimulator::setModelDirectories(const QStringList &modelDirectories)
|
||||
{
|
||||
this->m_modelDirectories = modelDirectories;
|
||||
}
|
||||
|
||||
void CSettingsSimulator::setModelDirectory(const QString &modelDirectory)
|
||||
{
|
||||
this->m_modelDirectories = QStringList({ modelDirectory });
|
||||
}
|
||||
|
||||
const QStringList &CSettingsSimulator::getModelDirectories() const
|
||||
{
|
||||
return this->m_modelDirectories;
|
||||
}
|
||||
|
||||
void CSettingsSimulator::setModelExcludeDirectories(const QStringList &excludeDirectories)
|
||||
{
|
||||
this->m_excludeDirectoryPatterns = excludeDirectories;
|
||||
}
|
||||
|
||||
const QStringList &CSettingsSimulator::getModelExcludeDirectoryPatterns() const
|
||||
{
|
||||
return m_excludeDirectoryPatterns;
|
||||
}
|
||||
|
||||
void CSettingsSimulator::resetPaths()
|
||||
{
|
||||
this->m_excludeDirectoryPatterns.clear();
|
||||
this->m_modelDirectories.clear();
|
||||
this->m_simulatorDirectory.clear();
|
||||
}
|
||||
|
||||
QString CSettingsSimulator::convertToQString(bool i18n) const
|
||||
{
|
||||
return convertToQString(", ", i18n);
|
||||
}
|
||||
|
||||
QString CSettingsSimulator::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("model directories: ");
|
||||
s.append(this->m_modelDirectories.join(','));
|
||||
s.append(separator);
|
||||
s.append("exclude directories: ");
|
||||
s.append(this->m_excludeDirectoryPatterns.join(','));
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CSettingsSimulator::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSimulatorDirectory:
|
||||
return CVariant::fromValue(this->m_simulatorDirectory);
|
||||
case IndexModelDirectory:
|
||||
return CVariant::fromValue(this->m_modelDirectories);
|
||||
case IndexModelExcludeDirectoryPatterns:
|
||||
return CVariant::fromValue(this->m_excludeDirectoryPatterns);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulator::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsSimulator>(); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSimulatorDirectory:
|
||||
this->setSimulatorDirectory(variant.toQString());
|
||||
break;
|
||||
case IndexModelDirectory:
|
||||
this->setSimulatorDirectory(variant.toQString());
|
||||
break;
|
||||
case IndexModelExcludeDirectoryPatterns:
|
||||
this->m_excludeDirectoryPatterns = variant.value<QStringList>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CMultiSimulatorSimulatorSettings::CMultiSimulatorSimulatorSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
CSettingsSimulator CMultiSimulatorSimulatorSettings::getSettings(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.get();
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.get();
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.get();
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.get();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CSettingsSimulator();
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSimulatorSettings::setSettings(const CSettingsSimulator &settings, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.set(settings);
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.set(settings);
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.set(settings);
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.set(settings);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSimulatorSettings::setAndSaveSettings(const CSettingsSimulator &settings, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.setAndSave(settings);
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.setAndSave(settings);
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.setAndSave(settings);
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.setAndSave(settings);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSimulatorSettings::saveSettings(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.save();
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.save();
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.save();
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.save();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSimulatorSettings::getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettingsSimulator s = this->getSettings(simulator);
|
||||
if (s.getSimulatorDirectory().isEmpty())
|
||||
{
|
||||
return this->getDefaultSimulatorDirectory(simulator);
|
||||
}
|
||||
return s.getSimulatorDirectory();
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSimulatorSettings::getDefaultSimulatorDirectory(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9Dir();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxDir();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dDir();
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneRootDir(); //! check XP
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettingsSimulator s = this->getSettings(simulator);
|
||||
if (s.getModelDirectories().isEmpty())
|
||||
{
|
||||
return this->getDefaultModelDirectories(simulator);
|
||||
}
|
||||
return s.getModelDirectories();
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSimulatorSettings::getFirstModelDirectoryOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const QStringList models(getModelDirectoriesOrDefault(simulator));
|
||||
if (models.isEmpty()) { return ""; }
|
||||
return models.first();
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSimulatorSettings::getDefaultModelDirectories(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
static const QStringList e;
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fs9AircraftDir() });
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fsxSimObjectsDir() });
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::p3dSimObjectsDir()});
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelDirectories();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSimulatorSettings::getModelExcludeDirectoryPatternsOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettingsSimulator s = this->getSettings(simulator);
|
||||
QStringList exclude(s.getModelExcludeDirectoryPatterns());
|
||||
if (!exclude.isEmpty()) { return exclude; }
|
||||
exclude = this->getDefaultModelExcludeDirectoryPatterns(simulator);
|
||||
return exclude;
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSimulatorSettings::getDefaultModelExcludeDirectoryPatterns(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelExcludeDirectoryPatterns();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
void CMultiSimulatorSimulatorSettings::resetToDefaults(const CSimulatorInfo &simulator)
|
||||
{
|
||||
CSettingsSimulator s = this->getSettings(simulator);
|
||||
s.resetPaths();
|
||||
this->setAndSaveSettings(s, simulator);
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::CSettingsSimulatorMessages()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
this->m_technicalLogLevel = static_cast<int>(severity);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::disableTechnicalMessages()
|
||||
{
|
||||
this->m_technicalLogLevel = -1;
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedErrorsMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityError);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedWarningMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedInfoMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTechnicalMessages() const
|
||||
{
|
||||
return (this->m_technicalLogLevel >= 0);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setRelayedTextMessages(CSettingsSimulatorMessages::TextMessageType messageType)
|
||||
{
|
||||
this->m_messageType = static_cast<int>(messageType);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedSupervisorTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedPrivateTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedUnicomTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom1TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom2TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTextMessage(const Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const
|
||||
{
|
||||
if (msg.isEmpty()) { return false; }
|
||||
if (!this->isGloballyEnabled()) { return false; }
|
||||
if (this->m_messageType == NoTextMessages) { return false; }
|
||||
|
||||
const TextMessageType mt = static_cast<TextMessageType>(this->m_messageType);
|
||||
if (msg.isPrivateMessage() && mt.testFlag(TextMessagePrivate)) { return true; }
|
||||
if (msg.isSupervisorMessage() && (mt.testFlag(TextMessagePrivate) || mt.testFlag(TextMessageSupervisor))) { return true; }
|
||||
if (msg.isSendToUnicom() && mt.testFlag(TextMessagesUnicom)) { return true; }
|
||||
|
||||
if (msg.isRadioMessage())
|
||||
{
|
||||
const CFrequency f(msg.getFrequency());
|
||||
if (mt.testFlag(TextMessagesCom1))
|
||||
{
|
||||
if (aircraft.getCom1System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
if (mt.testFlag(TextMessagesCom2))
|
||||
{
|
||||
if (aircraft.getCom2System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::TextMessageType CSettingsSimulatorMessages::getRelayedTextMessageTypes() const
|
||||
{
|
||||
return static_cast<CSettingsSimulatorMessages::TextMessageType>(this->m_messageType);
|
||||
}
|
||||
|
||||
QString CSettingsSimulatorMessages::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("Enabled %1, text messages: %2, severity: %3");
|
||||
QString severity;
|
||||
if (this->isRelayedTechnicalMessages())
|
||||
{
|
||||
severity = "No tech. msgs";
|
||||
}
|
||||
else
|
||||
{
|
||||
severity = CStatusMessage::severityToString(static_cast<CStatusMessage::StatusSeverity>(this->m_technicalLogLevel));
|
||||
}
|
||||
return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity);
|
||||
}
|
||||
|
||||
CVariant CSettingsSimulatorMessages::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
return CVariant::fromValue(this->m_technicalLogLevel);
|
||||
case IndexTextMessageRelay:
|
||||
return CVariant::from(this->m_messageType);
|
||||
case IndexGloballyEnabled:
|
||||
return CVariant::from(this->m_globallyEnabled);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsSimulatorMessages>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
this->setTechnicalLogSeverity(static_cast<CStatusMessage::StatusSeverity>(variant.toInt()));
|
||||
break;
|
||||
case IndexTextMessageRelay:
|
||||
this->setRelayedTextMessages(static_cast<CSettingsSimulatorMessages::TextMessageType>(variant.toInt()));
|
||||
break;
|
||||
case IndexGloballyEnabled:
|
||||
this->setGloballyEnabled(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
@@ -1,304 +0,0 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_SETTINGSSIMULATOR_H
|
||||
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
class CSimulatedAircraft;
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
//! Settings for simulator
|
||||
//! Driver independent part also used in loaders (such as directories)
|
||||
class BLACKMISC_EXPORT CSettingsSimulator :
|
||||
public BlackMisc::CValueObject<CSettingsSimulator>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexSimulatorDirectory = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings,
|
||||
IndexModelDirectory,
|
||||
IndexModelExcludeDirectoryPatterns
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CSettingsSimulator();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsSimulator() {}
|
||||
|
||||
//! Set simulator directory
|
||||
void setSimulatorDirectory(const QString &simulatorDirectory);
|
||||
|
||||
//! Simulator directory
|
||||
const QString &getSimulatorDirectory() const;
|
||||
|
||||
//! Set model directories
|
||||
void setModelDirectories(const QStringList &modelDirectories);
|
||||
|
||||
//! Set single model directory
|
||||
void setModelDirectory(const QString &modelDirectory);
|
||||
|
||||
//! Model directory
|
||||
const QStringList &getModelDirectories() const;
|
||||
|
||||
//! Set exclude directories
|
||||
void setModelExcludeDirectories(const QStringList &excludeDirectories);
|
||||
|
||||
//! Margins for given dock widget
|
||||
const QStringList &getModelExcludeDirectoryPatterns() const;
|
||||
|
||||
//! Reset the paths
|
||||
void resetPaths();
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! To string
|
||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
QString m_simulatorDirectory; //! Simulator directory
|
||||
QStringList m_modelDirectories; //!< Model directory
|
||||
QStringList m_excludeDirectoryPatterns; //!< Exclude model directory
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsSimulator,
|
||||
BLACK_METAMEMBER(simulatorDirectory),
|
||||
BLACK_METAMEMBER(modelDirectories),
|
||||
BLACK_METAMEMBER(excludeDirectoryPatterns)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct SettingsSimulatorFsx : public BlackMisc::CSettingTrait<CSettingsSimulator>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorfsx"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct SettingsSimulatorFs9 : public BlackMisc::CSettingTrait<CSettingsSimulator>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorfs9"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct SettingsSimulatorP3D : public BlackMisc::CSettingTrait<CSettingsSimulator>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorp3d"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct SettingsSimulatorXP : public BlackMisc::CSettingTrait<CSettingsSimulator>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorxplane"; }
|
||||
};
|
||||
|
||||
//! Bundle of settings for all simulators
|
||||
class BLACKMISC_EXPORT CMultiSimulatorSimulatorSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Construtor
|
||||
CMultiSimulatorSimulatorSettings(QObject *parent = nullptr);
|
||||
|
||||
//! Settings per simulator
|
||||
CSettingsSimulator getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage setSettings(const BlackMisc::Simulation::Settings::CSettingsSimulator &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage setAndSaveSettings(const BlackMisc::Simulation::Settings::CSettingsSimulator &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage saveSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Simulator directory or default model path per simulator
|
||||
QString getSimulatorDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default simulator path per simulator
|
||||
QString getDefaultSimulatorDirectory(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Model directory or default model path per simulator
|
||||
QStringList getModelDirectoriesOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! First model directoy
|
||||
QString getFirstModelDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default model path per simulator
|
||||
QStringList getDefaultModelDirectories(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Model exclude paths per simulator
|
||||
QStringList getModelExcludeDirectoryPatternsOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default model exclude paths per simulator
|
||||
QStringList getDefaultModelExcludeDirectoryPatterns(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Reset to defaults
|
||||
void resetToDefaults(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
private:
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorFsx> m_simSettingsFsx {this}; //!< FSX cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorFs9> m_simSettingsFs9 {this}; //!< FS9 cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorP3D> m_simSettingsP3D {this}; //!< P3D cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::Settings::SettingsSimulatorXP> m_simSettingsXP {this}; //!< XP cache
|
||||
};
|
||||
|
||||
//! Settings regarding message handling.
|
||||
//! Driver independent part, related to network
|
||||
class BLACKMISC_EXPORT CSettingsSimulatorMessages :
|
||||
public BlackMisc::CValueObject<CSettingsSimulatorMessages>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexTechnicalLogSeverity = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorMessageSettings,
|
||||
IndexTextMessageRelay,
|
||||
IndexGloballyEnabled
|
||||
};
|
||||
|
||||
//! Enabled matching mode flags
|
||||
enum TextMessageTypeFlag
|
||||
{
|
||||
NoTextMessages = 0,
|
||||
TextMessagesUnicom = 1 << 0,
|
||||
TextMessagesCom1 = 1 << 1,
|
||||
TextMessagesCom2 = 1 << 2,
|
||||
TextMessagePrivate = 1 << 3,
|
||||
TextMessageSupervisor = 1 << 4,
|
||||
TextMessagesAll = TextMessagesUnicom | TextMessagesCom1 | TextMessagesCom2 | TextMessagePrivate
|
||||
};
|
||||
Q_DECLARE_FLAGS(TextMessageType, TextMessageTypeFlag)
|
||||
|
||||
//! Default constructor
|
||||
CSettingsSimulatorMessages();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsSimulatorMessages() {}
|
||||
|
||||
//! Log severity
|
||||
void setTechnicalLogSeverity(BlackMisc::CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Globally enable / disable
|
||||
void setGloballyEnabled(bool enabled) { this->m_globallyEnabled = enabled; }
|
||||
|
||||
//! Globally enabled?
|
||||
bool isGloballyEnabled() const { return this->m_globallyEnabled; }
|
||||
|
||||
//! No technical messages
|
||||
void disableTechnicalMessages();
|
||||
|
||||
//! Relay (technical) error messages
|
||||
bool isRelayedErrorsMessages() const;
|
||||
|
||||
//! Relay (technical) warning messages
|
||||
bool isRelayedWarningMessages() const;
|
||||
|
||||
//! Relay (technical) info messages
|
||||
bool isRelayedInfoMessages() const;
|
||||
|
||||
//! Relay any message
|
||||
bool isRelayedTechnicalMessages() const;
|
||||
|
||||
//! Relay the following message types
|
||||
void setRelayedTextMessages(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType messageType);
|
||||
|
||||
//! Relay supervisor messages
|
||||
bool isRelayedSupervisorTextMessages() const;
|
||||
|
||||
//! Relay private messages
|
||||
bool isRelayedPrivateTextMessages() const;
|
||||
|
||||
//! Relay UNICOM messages
|
||||
bool isRelayedUnicomTextMessages() const;
|
||||
|
||||
//! Relay given text message
|
||||
bool isRelayedTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
//! Relay COM1 text message
|
||||
bool isRelayedCom1TextMessages() const;
|
||||
|
||||
//! Relay COM2 text message
|
||||
bool isRelayedCom2TextMessages() const;
|
||||
|
||||
//! Relayed text messages
|
||||
CSettingsSimulatorMessages::TextMessageType getRelayedTextMessageTypes() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
int m_technicalLogLevel = BlackMisc::CStatusMessage::SeverityError; //!< Simulator directory
|
||||
int m_messageType = static_cast<int>(TextMessagePrivate | TextMessageSupervisor);
|
||||
bool m_globallyEnabled = true; //!< messsage relay enabled to simulator
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsSimulatorMessages,
|
||||
BLACK_METAMEMBER(technicalLogLevel),
|
||||
BLACK_METAMEMBER(messageType)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for simulator message settings
|
||||
struct SettingsSimulatorMessages : public BlackMisc::CSettingTrait<CSettingsSimulatorMessages>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatormessages"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulator)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSettingsSimulator>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSettingsSimulator>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::Settings::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageTypeFlag)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::Settings::CSettingsSimulatorMessages::TextMessageType)
|
||||
|
||||
#endif // guard
|
||||
439
src/blackmisc/simulation/simulationsettings.cpp
Normal file
439
src/blackmisc/simulation/simulationsettings.cpp
Normal file
@@ -0,0 +1,439 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "simulationsettings.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/fscommon/fscommonutil.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Simulation::FsCommon;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CSettings::CSettings()
|
||||
{ }
|
||||
|
||||
void CSettings::setSimulatorDirectory(const QString &simulatorDirectory)
|
||||
{
|
||||
this->m_simulatorDirectory = simulatorDirectory.trimmed();
|
||||
}
|
||||
|
||||
const QString &CSettings::getSimulatorDirectory() const
|
||||
{
|
||||
return this->m_simulatorDirectory;
|
||||
}
|
||||
|
||||
void CSettings::setModelDirectories(const QStringList &modelDirectories)
|
||||
{
|
||||
this->m_modelDirectories = modelDirectories;
|
||||
}
|
||||
|
||||
void CSettings::setModelDirectory(const QString &modelDirectory)
|
||||
{
|
||||
this->m_modelDirectories = QStringList({ modelDirectory });
|
||||
}
|
||||
|
||||
const QStringList &CSettings::getModelDirectories() const
|
||||
{
|
||||
return this->m_modelDirectories;
|
||||
}
|
||||
|
||||
void CSettings::setModelExcludeDirectories(const QStringList &excludeDirectories)
|
||||
{
|
||||
this->m_excludeDirectoryPatterns = excludeDirectories;
|
||||
}
|
||||
|
||||
const QStringList &CSettings::getModelExcludeDirectoryPatterns() const
|
||||
{
|
||||
return m_excludeDirectoryPatterns;
|
||||
}
|
||||
|
||||
void CSettings::resetPaths()
|
||||
{
|
||||
this->m_excludeDirectoryPatterns.clear();
|
||||
this->m_modelDirectories.clear();
|
||||
this->m_simulatorDirectory.clear();
|
||||
}
|
||||
|
||||
QString CSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
return convertToQString(", ", i18n);
|
||||
}
|
||||
|
||||
QString CSettings::convertToQString(const QString &separator, bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("model directories: ");
|
||||
s.append(this->m_modelDirectories.join(','));
|
||||
s.append(separator);
|
||||
s.append("exclude directories: ");
|
||||
s.append(this->m_excludeDirectoryPatterns.join(','));
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CSettings::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSimulatorDirectory:
|
||||
return CVariant::fromValue(this->m_simulatorDirectory);
|
||||
case IndexModelDirectory:
|
||||
return CVariant::fromValue(this->m_modelDirectories);
|
||||
case IndexModelExcludeDirectoryPatterns:
|
||||
return CVariant::fromValue(this->m_excludeDirectoryPatterns);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettings>(); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSimulatorDirectory:
|
||||
this->setSimulatorDirectory(variant.toQString());
|
||||
break;
|
||||
case IndexModelDirectory:
|
||||
this->setSimulatorDirectory(variant.toQString());
|
||||
break;
|
||||
case IndexModelExcludeDirectoryPatterns:
|
||||
this->m_excludeDirectoryPatterns = variant.value<QStringList>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CMultiSimulatorSettings::CMultiSimulatorSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
CSettings CMultiSimulatorSettings::getSettings(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.get();
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.get();
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.get();
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.get();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CSettings();
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSettings::setSettings(const CSettings &settings, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.set(settings);
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.set(settings);
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.set(settings);
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.set(settings);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSettings::setAndSaveSettings(const CSettings &settings, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.setAndSave(settings);
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.setAndSave(settings);
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.setAndSave(settings);
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.setAndSave(settings);
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
CStatusMessage CMultiSimulatorSettings::saveSettings(const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return this->m_simSettingsFs9.save();
|
||||
case CSimulatorInfo::FSX: return this->m_simSettingsFsx.save();
|
||||
case CSimulatorInfo::P3D: return this->m_simSettingsP3D.save();
|
||||
case CSimulatorInfo::XPLANE: return this->m_simSettingsXP.save();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return CStatusMessage({ CLogCategory::settings() }, CStatusMessage::SeverityError, "wrong simulator");
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSettings::getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettings s = this->getSettings(simulator);
|
||||
if (s.getSimulatorDirectory().isEmpty())
|
||||
{
|
||||
return this->getDefaultSimulatorDirectory(simulator);
|
||||
}
|
||||
return s.getSimulatorDirectory();
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSettings::getDefaultSimulatorDirectory(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9Dir();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxDir();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dDir();
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneRootDir(); //! check XP
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSettings::getModelDirectoriesOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettings s = this->getSettings(simulator);
|
||||
if (s.getModelDirectories().isEmpty())
|
||||
{
|
||||
return this->getDefaultModelDirectories(simulator);
|
||||
}
|
||||
return s.getModelDirectories();
|
||||
}
|
||||
|
||||
QString CMultiSimulatorSettings::getFirstModelDirectoryOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const QStringList models(getModelDirectoriesOrDefault(simulator));
|
||||
if (models.isEmpty()) { return ""; }
|
||||
return models.first();
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSettings::getDefaultModelDirectories(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
static const QStringList e;
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fs9AircraftDir() });
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::fsxSimObjectsDir() });
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsDir().isEmpty() ? e : QStringList({ CFsCommonUtil::p3dSimObjectsDir()});
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelDirectories();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSettings::getModelExcludeDirectoryPatternsOrDefault(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
const CSettings s = this->getSettings(simulator);
|
||||
QStringList exclude(s.getModelExcludeDirectoryPatterns());
|
||||
if (!exclude.isEmpty()) { return exclude; }
|
||||
exclude = this->getDefaultModelExcludeDirectoryPatterns(simulator);
|
||||
return exclude;
|
||||
}
|
||||
|
||||
QStringList CMultiSimulatorSettings::getDefaultModelExcludeDirectoryPatterns(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FS9: return CFsCommonUtil::fs9AircraftObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::FSX: return CFsCommonUtil::fsxSimObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::P3D: return CFsCommonUtil::p3dSimObjectsExcludeDirectoryPatterns();
|
||||
case CSimulatorInfo::XPLANE: return CXPlaneUtil::xplaneModelExcludeDirectoryPatterns();
|
||||
default:
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||
break;
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
void CMultiSimulatorSettings::resetToDefaults(const CSimulatorInfo &simulator)
|
||||
{
|
||||
CSettings s = this->getSettings(simulator);
|
||||
s.resetPaths();
|
||||
this->setAndSaveSettings(s, simulator);
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::CSettingsSimulatorMessages()
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
this->m_technicalLogLevel = static_cast<int>(severity);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::disableTechnicalMessages()
|
||||
{
|
||||
this->m_technicalLogLevel = -1;
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedErrorsMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityError);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedWarningMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityWarning);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedInfoMessages() const
|
||||
{
|
||||
if (this->m_technicalLogLevel < 0) { return false; }
|
||||
return (this->m_technicalLogLevel <= CStatusMessage::SeverityInfo);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTechnicalMessages() const
|
||||
{
|
||||
return (this->m_technicalLogLevel >= 0);
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setRelayedTextMessages(CSettingsSimulatorMessages::TextMessageType messageType)
|
||||
{
|
||||
this->m_messageType = static_cast<int>(messageType);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedSupervisorTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessageSupervisor);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedPrivateTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagePrivate);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedUnicomTextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesUnicom);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom1TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom1);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedCom2TextMessages() const
|
||||
{
|
||||
return this->getRelayedTextMessageTypes().testFlag(TextMessagesCom2);
|
||||
}
|
||||
|
||||
bool CSettingsSimulatorMessages::isRelayedTextMessage(const Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const
|
||||
{
|
||||
if (msg.isEmpty()) { return false; }
|
||||
if (!this->isGloballyEnabled()) { return false; }
|
||||
if (this->m_messageType == NoTextMessages) { return false; }
|
||||
|
||||
const TextMessageType mt = static_cast<TextMessageType>(this->m_messageType);
|
||||
if (msg.isPrivateMessage() && mt.testFlag(TextMessagePrivate)) { return true; }
|
||||
if (msg.isSupervisorMessage() && (mt.testFlag(TextMessagePrivate) || mt.testFlag(TextMessageSupervisor))) { return true; }
|
||||
if (msg.isSendToUnicom() && mt.testFlag(TextMessagesUnicom)) { return true; }
|
||||
|
||||
if (msg.isRadioMessage())
|
||||
{
|
||||
const CFrequency f(msg.getFrequency());
|
||||
if (mt.testFlag(TextMessagesCom1))
|
||||
{
|
||||
if (aircraft.getCom1System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
if (mt.testFlag(TextMessagesCom2))
|
||||
{
|
||||
if (aircraft.getCom2System().isActiveFrequencyWithin8_33kHzChannel(f)) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CSettingsSimulatorMessages::TextMessageType CSettingsSimulatorMessages::getRelayedTextMessageTypes() const
|
||||
{
|
||||
return static_cast<CSettingsSimulatorMessages::TextMessageType>(this->m_messageType);
|
||||
}
|
||||
|
||||
QString CSettingsSimulatorMessages::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s("Enabled %1, text messages: %2, severity: %3");
|
||||
QString severity;
|
||||
if (this->isRelayedTechnicalMessages())
|
||||
{
|
||||
severity = "No tech. msgs";
|
||||
}
|
||||
else
|
||||
{
|
||||
severity = CStatusMessage::severityToString(static_cast<CStatusMessage::StatusSeverity>(this->m_technicalLogLevel));
|
||||
}
|
||||
return s.arg(boolToOnOff(this->m_globallyEnabled)).arg(this->m_messageType).arg(severity);
|
||||
}
|
||||
|
||||
CVariant CSettingsSimulatorMessages::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
return CVariant::fromValue(this->m_technicalLogLevel);
|
||||
case IndexTextMessageRelay:
|
||||
return CVariant::from(this->m_messageType);
|
||||
case IndexGloballyEnabled:
|
||||
return CVariant::from(this->m_globallyEnabled);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulatorMessages::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsSimulatorMessages>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexTechnicalLogSeverity:
|
||||
this->setTechnicalLogSeverity(static_cast<CStatusMessage::StatusSeverity>(variant.toInt()));
|
||||
break;
|
||||
case IndexTextMessageRelay:
|
||||
this->setRelayedTextMessages(static_cast<CSettingsSimulatorMessages::TextMessageType>(variant.toInt()));
|
||||
break;
|
||||
case IndexGloballyEnabled:
|
||||
this->setGloballyEnabled(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
301
src/blackmisc/simulation/simulationsettings.h
Normal file
301
src/blackmisc/simulation/simulationsettings.h
Normal file
@@ -0,0 +1,301 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_H
|
||||
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
#include "blackmisc/network/textmessage.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
class CSimulatedAircraft;
|
||||
|
||||
//! Settings for simulator
|
||||
//! Driver independent part also used in loaders (such as directories)
|
||||
class BLACKMISC_EXPORT CSettings :
|
||||
public BlackMisc::CValueObject<CSettings>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexSimulatorDirectory = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorSettings,
|
||||
IndexModelDirectory,
|
||||
IndexModelExcludeDirectoryPatterns
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CSettings();
|
||||
|
||||
//! Destructor.
|
||||
~CSettings() {}
|
||||
|
||||
//! Set simulator directory
|
||||
void setSimulatorDirectory(const QString &simulatorDirectory);
|
||||
|
||||
//! Simulator directory
|
||||
const QString &getSimulatorDirectory() const;
|
||||
|
||||
//! Set model directories
|
||||
void setModelDirectories(const QStringList &modelDirectories);
|
||||
|
||||
//! Set single model directory
|
||||
void setModelDirectory(const QString &modelDirectory);
|
||||
|
||||
//! Model directory
|
||||
const QStringList &getModelDirectories() const;
|
||||
|
||||
//! Set exclude directories
|
||||
void setModelExcludeDirectories(const QStringList &excludeDirectories);
|
||||
|
||||
//! Margins for given dock widget
|
||||
const QStringList &getModelExcludeDirectoryPatterns() const;
|
||||
|
||||
//! Reset the paths
|
||||
void resetPaths();
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! To string
|
||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
QString m_simulatorDirectory; //! Simulator directory
|
||||
QStringList m_modelDirectories; //!< Model directory
|
||||
QStringList m_excludeDirectoryPatterns; //!< Exclude model directory
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettings,
|
||||
BLACK_METAMEMBER(simulatorDirectory),
|
||||
BLACK_METAMEMBER(modelDirectories),
|
||||
BLACK_METAMEMBER(excludeDirectoryPatterns)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct TSimulatorFsx : public BlackMisc::TSettingTrait<CSettings>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorfsx"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct TSimulatorFs9 : public BlackMisc::TSettingTrait<CSettings>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorfs9"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct TSimulatorP3D : public BlackMisc::TSettingTrait<CSettings>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorp3d"; }
|
||||
};
|
||||
|
||||
//! Trait for simulator settings
|
||||
struct TSimulatorXP : public BlackMisc::TSettingTrait<CSettings>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatorxplane"; }
|
||||
};
|
||||
|
||||
//! Bundle of settings for all simulators
|
||||
class BLACKMISC_EXPORT CMultiSimulatorSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Construtor
|
||||
CMultiSimulatorSettings(QObject *parent = nullptr);
|
||||
|
||||
//! Settings per simulator
|
||||
CSettings getSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage setSettings(const BlackMisc::Simulation::CSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage setAndSaveSettings(const BlackMisc::Simulation::CSettings &settings, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Set settings per simulator
|
||||
BlackMisc::CStatusMessage saveSettings(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Simulator directory or default model path per simulator
|
||||
QString getSimulatorDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default simulator path per simulator
|
||||
QString getDefaultSimulatorDirectory(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Model directory or default model path per simulator
|
||||
QStringList getModelDirectoriesOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! First model directoy
|
||||
QString getFirstModelDirectoryOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default model path per simulator
|
||||
QStringList getDefaultModelDirectories(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Model exclude paths per simulator
|
||||
QStringList getModelExcludeDirectoryPatternsOrDefault(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Default model exclude paths per simulator
|
||||
QStringList getDefaultModelExcludeDirectoryPatterns(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Reset to defaults
|
||||
void resetToDefaults(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
private:
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorFsx> m_simSettingsFsx {this}; //!< FSX cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorFs9> m_simSettingsFs9 {this}; //!< FS9 cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorP3D> m_simSettingsP3D {this}; //!< P3D cache
|
||||
BlackMisc::CSetting<BlackMisc::Simulation::TSimulatorXP> m_simSettingsXP {this}; //!< XP cache
|
||||
};
|
||||
|
||||
//! Settings regarding message handling.
|
||||
//! Driver independent part, related to network
|
||||
class BLACKMISC_EXPORT CSettingsSimulatorMessages :
|
||||
public BlackMisc::CValueObject<CSettingsSimulatorMessages>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexTechnicalLogSeverity = BlackMisc::CPropertyIndex::GlobalIndexCSimulatorMessageSettings,
|
||||
IndexTextMessageRelay,
|
||||
IndexGloballyEnabled
|
||||
};
|
||||
|
||||
//! Enabled matching mode flags
|
||||
enum TextMessageTypeFlag
|
||||
{
|
||||
NoTextMessages = 0,
|
||||
TextMessagesUnicom = 1 << 0,
|
||||
TextMessagesCom1 = 1 << 1,
|
||||
TextMessagesCom2 = 1 << 2,
|
||||
TextMessagePrivate = 1 << 3,
|
||||
TextMessageSupervisor = 1 << 4,
|
||||
TextMessagesAll = TextMessagesUnicom | TextMessagesCom1 | TextMessagesCom2 | TextMessagePrivate
|
||||
};
|
||||
Q_DECLARE_FLAGS(TextMessageType, TextMessageTypeFlag)
|
||||
|
||||
//! Default constructor
|
||||
CSettingsSimulatorMessages();
|
||||
|
||||
//! Destructor.
|
||||
~CSettingsSimulatorMessages() {}
|
||||
|
||||
//! Log severity
|
||||
void setTechnicalLogSeverity(BlackMisc::CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Globally enable / disable
|
||||
void setGloballyEnabled(bool enabled) { this->m_globallyEnabled = enabled; }
|
||||
|
||||
//! Globally enabled?
|
||||
bool isGloballyEnabled() const { return this->m_globallyEnabled; }
|
||||
|
||||
//! No technical messages
|
||||
void disableTechnicalMessages();
|
||||
|
||||
//! Relay (technical) error messages
|
||||
bool isRelayedErrorsMessages() const;
|
||||
|
||||
//! Relay (technical) warning messages
|
||||
bool isRelayedWarningMessages() const;
|
||||
|
||||
//! Relay (technical) info messages
|
||||
bool isRelayedInfoMessages() const;
|
||||
|
||||
//! Relay any message
|
||||
bool isRelayedTechnicalMessages() const;
|
||||
|
||||
//! Relay the following message types
|
||||
void setRelayedTextMessages(BlackMisc::Simulation::CSettingsSimulatorMessages::TextMessageType messageType);
|
||||
|
||||
//! Relay supervisor messages
|
||||
bool isRelayedSupervisorTextMessages() const;
|
||||
|
||||
//! Relay private messages
|
||||
bool isRelayedPrivateTextMessages() const;
|
||||
|
||||
//! Relay UNICOM messages
|
||||
bool isRelayedUnicomTextMessages() const;
|
||||
|
||||
//! Relay given text message
|
||||
bool isRelayedTextMessage(const BlackMisc::Network::CTextMessage &msg, const BlackMisc::Simulation::CSimulatedAircraft &aircraft) const;
|
||||
|
||||
//! Relay COM1 text message
|
||||
bool isRelayedCom1TextMessages() const;
|
||||
|
||||
//! Relay COM2 text message
|
||||
bool isRelayedCom2TextMessages() const;
|
||||
|
||||
//! Relayed text messages
|
||||
CSettingsSimulatorMessages::TextMessageType getRelayedTextMessageTypes() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
private:
|
||||
int m_technicalLogLevel = BlackMisc::CStatusMessage::SeverityError; //!< Simulator directory
|
||||
int m_messageType = static_cast<int>(TextMessagePrivate | TextMessageSupervisor);
|
||||
bool m_globallyEnabled = true; //!< messsage relay enabled to simulator
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsSimulatorMessages,
|
||||
BLACK_METAMEMBER(technicalLogLevel),
|
||||
BLACK_METAMEMBER(messageType)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for simulator message settings
|
||||
struct TSimulatorMessages : public BlackMisc::TSettingTrait<CSettingsSimulatorMessages>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "settingssimulatormessages"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSettings)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CSettings>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CSettings>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSettingsSimulatorMessages)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Simulation::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::CSettingsSimulatorMessages>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSettingsSimulatorMessages::TextMessageTypeFlag)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CSettingsSimulatorMessages::TextMessageType)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CSettingsSimulatorMessages::TextMessageType)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user