swift
Loading...
Searching...
No Matches
globalsetup.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QJsonObject>
7#include <QStringBuilder>
8#include <QStringList>
9#include <QSysInfo>
10#include <QVersionNumber>
11
12#include "config/buildconfig.h"
13#include "core/application.h"
14#include "misc/crashhandler.h"
15#include "misc/directoryutils.h"
16#include "misc/json.h"
17#include "misc/network/server.h"
18#include "misc/network/user.h"
19#include "misc/stringutils.h"
21
22using namespace swift::config;
23using namespace swift::misc;
24using namespace swift::misc::json;
25using namespace swift::misc::network;
26
28
29namespace swift::core::data
30{
31 namespace
32 {
33 CServer makeFscServer(const QString &name, const QString &address)
34 {
35 CServer s(name, "FSC e.V.", address, 6809, CUser(), CFsdSetup(), CEcosystem(CEcosystem::privateFsd()));
36 s.removeSendReceiveDetails(CFsdSetup::AllInterimPositions);
37 return s;
38 }
39 } // namespace
40
42
44
46
48
50
51 const CUrl &CGlobalSetup::getSwiftSharedUrl() const { return m_sharedUrl; }
53
54 CUrl CGlobalSetup::getHelpPageUrl() const { return m_onlineHelpUrl; }
55
57
59 {
61 .withAppendedPath("/service/jsonauthenticate.php")
62 .withSwitchedScheme("https", m_dbHttpsPort);
63 }
64
65 bool CGlobalSetup::dbDebugFlag() const { return m_dbDebugFlag && CBuildConfig::isLocalDeveloperDebugBuild(); }
66
67 void CGlobalSetup::setServerDebugFlag(bool debug) { m_dbDebugFlag = debug; }
68
73
75 {
76 // fixed servers in all builds, followed by the predefined servers from the bootstrap file
77 static const CServerList hardcoded({ makeFscServer("FSC 1", "server1.fsc-ev.de"),
78 makeFscServer("FSC 2", "server2.fsc-ev.de"), CServer::esTowerView() });
79 CServerList servers(hardcoded);
80 servers.addIfAddressNotExists(m_predefinedServers);
81 return servers;
82 }
83
85 {
86 if (m_mappingMinimumVersion.isEmpty())
87 {
88 return false;
89 }
91 return CBuildConfig::getVersion() >= min;
92 }
93
94 QString CGlobalSetup::convertToQString(bool i18n) const { return convertToQString(", ", i18n); }
95
96 QString CGlobalSetup::convertToQString(const QString &separator, bool i18n) const
97 {
98 QString s = u"Global setup loaded: " % separator % u"Mapping min.version: " %
99 this->getMappingMinimumVersionString() % separator
100
101 % u"Help URL: " % m_onlineHelpUrl.toQString(i18n) % separator;
102 s += u"DB root directory: " % getDbRootDirectoryUrl().toQString(i18n) % separator % u"ICAO DB reader: " %
103 getDbIcaoReaderUrl().toQString(i18n) % separator % u"Model DB reader: " %
104 getDbModelReaderUrl().toQString(i18n) % separator % u"Airport DB reader: " %
105 getDbAirportReaderUrl().toQString(i18n) % separator % u"DB home page: " %
106 getDbHomePageUrl().toQString(i18n) % separator % u"DB login service: " %
107 getDbLoginServiceUrl().toQString(i18n) % separator;
108 s += u"VATSIM METARs: " % getVatsimMetarsUrl().toQString(i18n) % separator % u"VATSIM data file: " %
109 getVatsimDataFileUrl().toQString(i18n) % separator % u"VATSIM server file: " %
110 getVatsimServerFileUrl().toQString(i18n) % separator
111
112 % u"Predefined servers: " % getPredefinedServers().toQString(i18n) % separator
113
114 % u"AFV voice server URL: " % getAfvApiServerUrl().toQString(i18n) % separator
115
116 % u"AFV map URL: " % getAfvMapUrl().toQString(i18n);
117
118 return s;
119 }
120
122 {
123 if (index.isMyself())
124 {
125 return CVariant::fromValue(*this);
126 }
127
128 const auto i = index.frontCasted<ColumnIndex>();
129 switch (i)
130 {
131 case IndexDbRootDirectory: return QVariant::fromValue(m_dbRootDirectoryUrl);
132 case IndexDbHttpsPort: return QVariant::fromValue(m_dbHttpsPort);
133 case IndexDbLoginService: return QVariant::fromValue(this->getDbLoginServiceUrl());
134 case IndexVatsimStatus: return QVariant::fromValue(m_vatsimStatusFileUrl);
135 case IndexVatsimData: return QVariant::fromValue(m_vatsimDataFileUrl);
136 case IndexVatsimServer: return QVariant::fromValue(m_vatsimServerFileUrl);
137 case IndexVatsimHttpFsd: return QVariant::fromValue(m_vatsimFsdHttpUrl);
138 case IndexVatsimMetars: return QVariant::fromValue(m_vatsimMetarsUrl);
139 case IndexSharedUrl: return QVariant::fromValue(m_sharedUrl);
140 case IndexOnlineHelpUrl: return QVariant::fromValue(m_onlineHelpUrl);
141 case IndexMappingMinimumVersion: return QVariant::fromValue(m_mappingMinimumVersion);
142 case IndexPredefinedServers: return QVariant::fromValue(m_predefinedServers);
143 case IndexAfvApiServerUrl: return QVariant::fromValue(m_afvApiServerUrl);
144 case IndexAfvMapUrl: return QVariant::fromValue(m_afvMapUrl);
145 default: return CValueObject::propertyByIndex(index);
146 }
147 }
148
150 {
151 if (index.isMyself())
152 {
153 (*this) = variant.value<CGlobalSetup>();
154 return;
155 }
156
157 const auto i = index.frontCasted<ColumnIndex>();
158 switch (i)
159 {
160 case IndexDbRootDirectory: m_dbRootDirectoryUrl.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
161 case IndexDbHttpsPort: m_dbHttpsPort = variant.toInt(); break;
162 case IndexDbLoginService: break; // cannot be changed
163 case IndexVatsimData: m_vatsimDataFileUrl = variant.value<CUrl>(); break;
164 case IndexVatsimServer: m_vatsimServerFileUrl = variant.value<CUrl>(); break;
165 case IndexVatsimHttpFsd: m_vatsimFsdHttpUrl = variant.value<CUrl>(); break;
166 case IndexVatsimMetars: m_vatsimMetarsUrl = variant.value<CUrl>(); break;
167 case IndexSharedUrl: m_sharedUrl = variant.value<CUrl>(); break;
168 case IndexOnlineHelpUrl: m_onlineHelpUrl = variant.value<CUrl>(); break;
169 case IndexMappingMinimumVersion: m_mappingMinimumVersion = variant.toString(); break;
170 case IndexPredefinedServers: m_predefinedServers = variant.value<CServerList>(); break;
171 case IndexAfvApiServerUrl: m_afvApiServerUrl = variant.value<CUrl>(); break;
172 case IndexAfvMapUrl: m_afvMapUrl = variant.value<CUrl>(); break;
173 default: CValueObject::setPropertyByIndex(index, variant); break;
174 }
175 }
176
178 {
179 // This is not the current swift version, but the schema version
180 static const QString v("0.7.0");
181 return v;
182 }
183} // namespace swift::core::data
static const QVersionNumber & getVersion()
Version as QVersionNumber.
static bool isLocalDeveloperDebugBuild()
Local build for developers.
const QString & getMappingMinimumVersionString() const
Creating mappings requires at least this version or higher.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
const swift::misc::network::CUrl & getSwiftSharedUrl() const
Shared URL.
swift::misc::network::CUrl getVatsimServerFileUrl() const
VATSIM server file URL.
bool dbDebugFlag() const
Debug flag.
bool isSwiftVersionMinimumMappingVersion() const
Meets the minimum mapping version.
CGlobalSetup()
Default constructor.
const swift::misc::network::CUrl & getVatsimDataFileUrl() const
VATSIM data file URL.
const swift::misc::network::CUrl & getVatsimMetarsUrl() const
VATSIM METAR URL.
Definition globalsetup.h:99
swift::misc::network::CUrl getDbIcaoReaderUrl() const
ICAO reader URL.
swift::misc::network::CUrl getDbAirportReaderUrl() const
Airport reader URL.
swift::misc::network::CUrl getDbHomePageUrl() const
Home page url.
swift::misc::network::CUrl getDbInfoReaderUrl() const
Info data reader URL.
ColumnIndex
Properties by index.
Definition globalsetup.h:35
swift::misc::network::CUrl getDbLoginServiceUrl() const
Login service.
swift::misc::network::CUrl getLegalDirectoryUrl() const
Legal directory URL.
const swift::misc::network::CUrl & getDbRootDirectoryUrl() const
Root directory of DB.
Definition globalsetup.h:65
void setServerDebugFlag(bool debug)
Set debug flag.
static const QString & schemaVersionString()
Schema version (shared files, bootstrap file).
swift::misc::network::CUrl getHelpPageUrl() const
Help page URL.
swift::misc::network::CServerList getPredefinedServersPlusHardcodedServers() const
Fixed servers (FSC, ES tower) followed by the predefined servers.
QString convertToQString(bool i18n=false) const
Cast as QString.
swift::misc::network::CUrl getDbModelReaderUrl() const
Model reader URL.
swift::misc::network::CUrl getAfvMapUrl() const
AFV map URL.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
swift::misc::network::CUrl getSharedDbDataDirectoryUrl()
Get shared DB data directory URL.
swift::misc::network::CUrl getAfvApiServerUrl() const
AFV voice server URL.
const swift::misc::network::CServerList & getPredefinedServers() const
Predefined servers.
CIdentifiable(const QString &objectName)
Use literal based object name.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
static CVariant fromValue(T &&value)
Construct a variant from a value.
Definition variant.h:139
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition mixinindex.h:167
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition mixinindex.h:180
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
static const CEcosystem & privateFsd()
FSD private.
Definition ecosystem.cpp:32
@ AllInterimPositions
all interim positions
Definition fsdsetup.h:53
static const CServer & esTowerView()
ES tower server.
Definition server.cpp:44
Value object encapsulating a list of servers.
Definition serverlist.h:23
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
CUrl withSwitchedScheme(const QString &protocol, int port) const
Switch protocol.
Definition url.cpp:162
CUrl withAppendedPath(const QString &path) const
Append path.
Definition url.cpp:151
Core data traits (aka cached values) and classes.
Free functions in swift::misc.
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const
T value() const &const
QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex)
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67