swift
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 
8 using namespace swift::misc;
9 using namespace swift::misc::network;
10 
12 
13 namespace swift::core::data
14 {
15  CVatsimSetup::CVatsimSetup() : ITimestampBased(0) {}
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: ");
40  s.append(this->getFormattedUtcTimestampYmdhms());
41  s.append(separator);
42 
43  s.append("VATSIM data file: ");
44  s.append(getDataFileUrl().toQString(i18n));
45  s.append(separator);
46 
47  s.append("FSD servers: ");
48  s.append(getFsdServers().toQString(i18n));
49  return s;
50  }
51 
53  {
54  if (index.isMyself()) { return QVariant::fromValue(*this); }
56 
57  const ColumnIndex i = index.frontCasted<ColumnIndex>();
58  switch (i)
59  {
60  case IndexFsdServers: return QVariant::fromValue(this->m_fsdServers);
61  case IndexDataFiles: return QVariant::fromValue(this->m_dataFileUrl);
62  default: return CValueObject::propertyByIndex(index);
63  }
64  }
65 
66  void CVatsimSetup::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
67  {
68  if (index.isMyself())
69  {
70  (*this) = variant.value<CVatsimSetup>();
71  return;
72  }
74  {
76  return;
77  }
78 
79  const ColumnIndex i = index.frontCasted<ColumnIndex>();
80  switch (i)
81  {
82  case IndexFsdServers: this->m_fsdServers = variant.value<CServerList>(); break;
83  case IndexDataFiles: this->m_dataFileUrl = variant.value<CUrl>(); break;
84  default: CValueObject::setPropertyByIndex(index, variant); break;
85  }
86  }
87 } // namespace swift::core::data
VATSIM data (servers, URLs) cached as last known good setup.
Definition: vatsimsetup.h:31
const swift::misc::network::CServerList & getVoiceServers() const
Voice servers.
Definition: vatsimsetup.h:75
const swift::misc::network::CUrl & getServerFileUrl() const
Server file URL.
Definition: vatsimsetup.h:53
void setServerFileUrl(const swift::misc::network::CUrl &url)
Set server file URL.
Definition: vatsimsetup.h:56
void setDataFileUrl(const swift::misc::network::CUrl &url)
Set VATSIM data file URL.
Definition: vatsimsetup.h:50
const swift::misc::network::CServerList & getFsdServers() const
FSD servers.
Definition: vatsimsetup.h:69
void setFsdServers(const swift::misc::network::CServerList &servers)
Set FSD servers.
Definition: vatsimsetup.h:72
bool setServers(const swift::misc::network::CServerList &fsdServers, const swift::misc::network::CServerList &voiceServers)
Set servers.
Definition: vatsimsetup.cpp:27
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
Definition: vatsimsetup.cpp:52
ColumnIndex
Properties by index.
Definition: vatsimsetup.h:35
QString convertToQString(bool i18n=false) const
Cast as QString.
Definition: vatsimsetup.cpp:35
const swift::misc::network::CUrl & getMetarFileUrl() const
METAR file URL.
Definition: vatsimsetup.h:59
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.
Definition: vatsimsetup.cpp:66
const swift::misc::network::CUrl & getDataFileUrl() const
VATSIM data file URL.
Definition: vatsimsetup.h:47
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.
Definition: vatsimsetup.cpp:17
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.
Entity with timestamp.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
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:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:76
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.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67