swift
Loading...
Searching...
No Matches
vatsimsetup.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 <QStringList>
7
8using namespace swift::misc;
9using namespace swift::misc::network;
10
12
13namespace swift::core::data
14{
16
17 bool CVatsimSetup::setUrls(const CUrl &dataFileUrl, const CUrl &serverFileUrl, const CUrl &metarFileUrl)
18 {
19 const bool changed = (dataFileUrl != getDataFileUrl() || serverFileUrl != getServerFileUrl() ||
20 metarFileUrl != getMetarFileUrl());
21 this->setServerFileUrl(serverFileUrl);
22 this->setMetarFileUrl(metarFileUrl);
23 this->setDataFileUrl(dataFileUrl);
24 return changed;
25 }
26
27 bool CVatsimSetup::setServers(const CServerList &fsdServers, const CServerList &voiceServers)
28 {
29 const bool changed = (this->getVoiceServers() != voiceServers || this->getFsdServers() != fsdServers);
30 this->setFsdServers(fsdServers);
31 this->setVoiceServers(voiceServers);
32 return changed;
33 }
34
35 QString CVatsimSetup::convertToQString(bool i18n) const { return convertToQString(", ", i18n); }
36
37 QString CVatsimSetup::convertToQString(const QString &separator, bool i18n) const
38 {
39 QString s("timestamp: ");
41 s.append(separator);
42
43 s.append("VATSIM data file: ");
45 s.append(separator);
46
47 s.append("FSD servers: ");
49 return s;
50 }
51
53 {
54 if (index.isMyself())
55 {
56 return QVariant::fromValue(*this);
57 }
59 {
61 }
62
63 const auto i = index.frontCasted<ColumnIndex>();
64 switch (i)
65 {
66 case IndexFsdServers: return QVariant::fromValue(this->m_fsdServers);
67 case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrl);
68 default: return CValueObject::propertyByIndex(index);
69 }
70 }
71
73 {
74 if (index.isMyself())
75 {
76 (*this) = variant.value<CVatsimSetup>();
77 return;
78 }
80 {
82 return;
83 }
84
85 const auto i = index.frontCasted<ColumnIndex>();
86 switch (i)
87 {
88 case IndexFsdServers: this->m_fsdServers = variant.value<CServerList>(); break;
89 case IndexDataFiles: this->m_dataFileUrl = variant.value<CUrl>(); break;
90 default: CValueObject::setPropertyByIndex(index, variant); break;
91 }
92 }
93} // namespace swift::core::data
CVatsimSetup()
Default constructor.
void setServerFileUrl(const swift::misc::network::CUrl &url)
Set server file URL.
Definition vatsimsetup.h:56
const swift::misc::network::CUrl & getServerFileUrl() const
Server file URL.
Definition vatsimsetup.h:53
void setDataFileUrl(const swift::misc::network::CUrl &url)
Set VATSIM data file URL.
Definition vatsimsetup.h:50
const swift::misc::network::CUrl & getMetarFileUrl() const
METAR file URL.
Definition vatsimsetup.h:59
void setFsdServers(const swift::misc::network::CServerList &servers)
Set FSD servers.
Definition vatsimsetup.h:72
const swift::misc::network::CUrl & getDataFileUrl() const
VATSIM data file URL.
Definition vatsimsetup.h:47
bool setServers(const swift::misc::network::CServerList &fsdServers, const swift::misc::network::CServerList &voiceServers)
Set servers.
const swift::misc::network::CServerList & getVoiceServers() const
Voice servers.
Definition vatsimsetup.h:75
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
ColumnIndex
Properties by index.
Definition vatsimsetup.h:35
QString convertToQString(bool i18n=false) const
Cast as QString.
const swift::misc::network::CServerList & getFsdServers() const
FSD servers.
Definition vatsimsetup.h:69
void setVoiceServers(const swift::misc::network::CServerList &servers)
Set voice servers.
Definition vatsimsetup.h:78
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool setUrls(const swift::misc::network::CUrl &dataFileUrl, const swift::misc::network::CUrl &serverFileUrl, const swift::misc::network::CUrl &metarFileUrl)
Set all URLs and indicate if something has changed.
void setMetarFileUrl(const swift::misc::network::CUrl &url)
METAR file URL.
Definition vatsimsetup.h:62
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
ITimestampBased()=default
Constructor.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
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
Definition mixinstring.h:74
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
Core data traits (aka cached values) and classes.
Free functions in swift::misc.
QString & append(QChar ch)
QVariant fromValue(T &&value)
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67