diff --git a/src/blackcore/data/vatsimsetup.cpp b/src/blackcore/data/vatsimsetup.cpp new file mode 100644 index 000000000..611b703e8 --- /dev/null +++ b/src/blackcore/data/vatsimsetup.cpp @@ -0,0 +1,87 @@ +/* Copyright (C) 2015 + * 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 "vatsimsetup.h" +#include + +using namespace BlackMisc; +using namespace BlackMisc::Network; + +namespace BlackCore +{ + namespace Data + { + CVatsimSetup::CVatsimSetup() : + ITimestampBased(0), + m_dataFileUrls(QStringList( { "http://info.vroute.net/vatsim-data.txt" })) + { } + + QString CVatsimSetup::convertToQString(bool i18n) const + { + return convertToQString(", ", i18n); + } + + QString CVatsimSetup::convertToQString(const QString &separator, bool i18n) const + { + QString s("timestamp: "); + s.append(this->getFormattedUtcTimestampYmdhms()); + s.append(separator); + + s.append("VATSIM data file: "); + s.append(getDataFileUrls().toQString(i18n)); + s.append(separator); + + s.append("FSD servers: "); + s.append(getFsdServers().toQString(i18n)); + return s; + } + + CVariant CVatsimSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexFsdServers: + return CVariant::fromValue(this->m_fsdServers); + case IndexDataFiles: + return CVariant::fromValue(this->m_dataFileUrls); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CVatsimSetup::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + if (ITimestampBased::canHandleIndex(index)) + { + ITimestampBased::setPropertyByIndex(variant, index); + return; + } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexFsdServers: + this->m_fsdServers = variant.value(); + break; + case IndexDataFiles: + this->m_dataFileUrls = variant.value(); + break; + default: + CValueObject::setPropertyByIndex(variant, index); + break; + } + } + + } // ns +} // ns diff --git a/src/blackcore/data/vatsimsetup.h b/src/blackcore/data/vatsimsetup.h new file mode 100644 index 000000000..22ac8d7ff --- /dev/null +++ b/src/blackcore/data/vatsimsetup.h @@ -0,0 +1,94 @@ +/* Copyright (C) 2015 + * 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 BLACKCORE_DATA_VATSIMDATA_H +#define BLACKCORE_DATA_VATSIMDATA_H + +#include "blackcore/blackcoreexport.h" +#include "blackmisc/datacache.h" +#include "blackmisc/network/serverlist.h" +#include "blackmisc/network/urllist.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/variant.h" +#include + +namespace BlackCore +{ + namespace Data + { + //! VATSIM data (servers, URLs) cached as last known good setup. + class BLACKCORE_EXPORT CVatsimSetup : + public BlackMisc::CValueObject, + public BlackMisc::ITimestampBased + { + public: + //! Properties by index + enum ColumnIndex + { + IndexFsdServers = BlackMisc::CPropertyIndex::GlobalIndexCGlobalSetup + 50, + IndexDataFiles + }; + + //! Default constructor + CVatsimSetup(); + + //! Destructor. + ~CVatsimSetup() {} + + //! VATSIM data file URLs + const BlackMisc::Network::CUrlList &getDataFileUrls() const { return m_dataFileUrls; } + + //! FSD test servers + const BlackMisc::Network::CServerList &getFsdServers() const { return m_fsdServers; } + + //! \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::CVariant &variant, const BlackMisc::CPropertyIndex &index); + + private: + BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CVatsimSetup) + + BlackMisc::Network::CUrlList m_dataFileUrls; //!< Overall VATSIM data file / merely for bootstrapping the first time + BlackMisc::Network::CServerList m_fsdServers; //!< FSD test servers + }; + + //! Trait for global setup data + struct VatsimSetup : public BlackMisc::CDataTrait + { + //! Key in data cache + static const char *key() { return "vatsim"; } + + //! Default value + static const CVatsimSetup &defaultValue() + { + static const CVatsimSetup gs; + return gs; + } + }; + + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackCore::Data::CVatsimSetup) +BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CVatsimSetup, ( + attr(o.m_dataFileUrls), + attr(o.m_fsdServers), + attr(o.m_timestampMSecsSinceEpoch) + )) +#endif // guard diff --git a/src/blackcore/registermetadata.cpp b/src/blackcore/registermetadata.cpp index d673ccdd6..1e1ac8fd0 100644 --- a/src/blackcore/registermetadata.cpp +++ b/src/blackcore/registermetadata.cpp @@ -12,6 +12,7 @@ #include "blackcore/webreaderflags.h" #include "blackcore/data/globalsetup.h" #include "blackcore/data/updateinfo.h" +#include "blackcore/data/vatsimsetup.h" #include "voicechannel.h" #include "network.h" #include "setupreader.h" @@ -30,5 +31,6 @@ namespace BlackCore BlackCore::Data::CGlobalSetup::registerMetadata(); BlackCore::Data::CUpdateInfo::registerMetadata(); + BlackCore::Data::CVatsimSetup::registerMetadata(); } } // namespace