diff --git a/src/blackcore/context_network_aircraft.cpp b/src/blackcore/context_network_aircraft.cpp index bd3dbb006..760b44be0 100644 --- a/src/blackcore/context_network_aircraft.cpp +++ b/src/blackcore/context_network_aircraft.cpp @@ -51,15 +51,17 @@ namespace BlackCore aircraft.setCallsign(callsign); aircraft.setSituation(situation); aircraft.setTransponder(transponder); - aircraft.calculcateDistanceToPlane(this->ownAircraft().getPosition()); - this->m_vatsimDataFileReader->getAircrafts().updateFromVatsimDataFileAircraft(aircraft); - + aircraft.setCalculcatedDistanceToPosition(this->ownAircraft().getPosition()); // distance from myself + this->m_vatsimDataFileReader->updateWithVatsimDataFileData(aircraft); this->m_aircraftsInRange.push_back(aircraft); // and new client, there is a chance it has been created by // custom package first if (!this->m_otherClients.contains(&CClient::getCallsign, callsign)) - this->m_otherClients.push_back(CClient(callsign)); // initial, will be filled by data later + { + CClient c(callsign); + this->m_otherClients.push_back(c); // initial, will be filled by data later + } if (this->isConnected()) { @@ -75,7 +77,7 @@ namespace BlackCore else { // update - CLength distance = this->ownAircraft().calculcateDistanceToPlane(situation.getPosition()); + CLength distance = this->ownAircraft().calculcateDistanceToPosition(situation.getPosition()); distance.switchUnit(CLengthUnit::NM()); CIndexVariantMap vm; vm.addValue(CAircraft::IndexTransponder, transponder); diff --git a/src/blackcore/context_network_atc.cpp b/src/blackcore/context_network_atc.cpp index ebecaf26b..9e6b5351b 100644 --- a/src/blackcore/context_network_atc.cpp +++ b/src/blackcore/context_network_atc.cpp @@ -45,7 +45,7 @@ namespace BlackCore */ void CContextNetwork::psReceivedBookings(const CAtcStationList &bookedStations) { - const int interval = 60 * 1000; + const int interval = 180 * 1000; if (this->m_vatsimBookingReader->interval() < interval) this->m_vatsimBookingReader->setInterval(interval); this->m_atcStationsBooked.clear(); foreach(CAtcStation bookedStation, bookedStations) @@ -266,15 +266,20 @@ namespace BlackCore { QString trimmedUrl = url.trimmed(); CIndexVariantMap vm(CAtcStation::IndexVoiceRoomUrl, trimmedUrl); - this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); - this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); + if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) + { + this->m_atcStationsBooked.applyIf(&CAtcStation::getCallsign, callsign, vm); + emit this->changedAtcStationsBooked(); + } if (this->m_atcStationsOnline.contains(&CAtcStation::getCallsign, callsign)) { + this->m_atcStationsOnline.applyIf(&CAtcStation::getCallsign, callsign, vm); CAtcStation station = this->m_atcStationsOnline.findFirstByCallsign(callsign); emit this->changedAtcStationsBooked(); emit this->changedAtcStationOnlineConnectionStatus(station, true); } - if (this->m_atcStationsBooked.contains(&CAtcStation::getCallsign, callsign)) emit this->changedAtcStationsBooked(); + vm = CIndexVariantMap(CClient::IndexVoiceCapabilities, CVoiceCapabilities(CVoiceCapabilities::Voice).toQVariant()); + this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm); } /* diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index 2c69d81a9..e95cc36dc 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -40,24 +40,24 @@ namespace BlackCore // 1. Init by "network driver" this->m_network = new CNetworkVatlib(this); - // 3. Init VATSIM bookings + // 2. Init VATSIM bookings this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this); this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::psReceivedBookings); - this->m_vatsimBookingReader->setInterval(10 * 1000); // first read + this->m_vatsimBookingReader->setInterval(15 * 1000); // first read - // 4. VATSIM data file + // 3. VATSIM data file QStringList dataFileUrls; dataFileUrls << "http://info.vroute.net/vatsim-data.txt"; this->m_vatsimDataFileReader = new CVatsimDataFileReader(dataFileUrls, this); this->connect(this->m_vatsimDataFileReader, &CVatsimDataFileReader::dataRead, this, &CContextNetwork::psDataFileRead); this->m_vatsimDataFileReader->setInterval(5 * 1000); // first read, will be fixed when first read to longer period - // 5. Update timer for data (network data such as frequency) + // 4. Update timer for data (network data such as frequency) this->m_dataUpdateTimer = new QTimer(this); this->connect(this->m_dataUpdateTimer, &QTimer::timeout, this, &CContextNetwork::requestDataUpdates); this->m_dataUpdateTimer->start(30 * 1000); - // 6. connect signals and slots + // 5. connect signals and slots this->connect(this->m_network, &INetwork::connectionStatusChanged, this, &CContextNetwork::psFsdConnectionStatusChanged); this->connect(this->m_network, &INetwork::atcPositionUpdate, this, &CContextNetwork::psFsdAtcPositionUpdate); this->connect(this->m_network, &INetwork::atisReplyReceived, this, &CContextNetwork::psFsdAtisQueryReceived); @@ -375,12 +375,12 @@ namespace BlackCore } /* - * Data file has been read + * Data file (VATSIM) has been read */ void CContextNetwork::psDataFileRead() { if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO); - const int interval = 60 * 1000; + const int interval = 90 * 1000; if (this->m_vatsimDataFileReader->interval() < interval) this->m_vatsimDataFileReader->setInterval(interval); this->getIContextApplication()->sendStatusMessage(CStatusMessage::getInfoMessage("Read VATSIM data file", CStatusMessage::TypeTrafficNetwork)); } diff --git a/src/blackcore/vatsimdatafilereader.cpp b/src/blackcore/vatsimdatafilereader.cpp index 0dc9f3339..2b329953f 100644 --- a/src/blackcore/vatsimdatafilereader.cpp +++ b/src/blackcore/vatsimdatafilereader.cpp @@ -122,10 +122,12 @@ namespace BlackCore /* * Data file read from XML + * Example: http://info.vroute.net/vatsim-data.txt */ void CVatsimDataFileReader::parseVatsimFileInBackground(QNetworkReply *nwReply) { - // Example: http://info.vroute.net/vatsim-data.txt + QStringList illegalIcaoCodes; + if (nwReply->error() == QNetworkReply::NoError) { const QString dataFileData = nwReply->readAll(); @@ -211,8 +213,7 @@ namespace BlackCore } else { - const QString w = QString("Illegal ICAO code in VATSIM data file: %1").arg(icaoCode); - qWarning(w.toLatin1()); + illegalIcaoCodes.append(icaoCode); } } @@ -265,6 +266,13 @@ namespace BlackCore nwReply->close(); nwReply->deleteLater(); // we are responsible for reading this emit this->dataRead(); + + // warnings, if required + if (!illegalIcaoCodes.isEmpty()) + { + const QString w = QString("Illegal ICAO code(s) in VATSIM data file: %1").arg(illegalIcaoCodes.join(", ")); + qWarning(w.toLatin1()); + } } const QMap CVatsimDataFileReader::clientPartsToMap(const QString ¤tLine, const QStringList &clientSectionAttributes) diff --git a/src/blackgui/atcstationcomponent.cpp b/src/blackgui/atcstationcomponent.cpp index 86e5306d9..53e0297d9 100644 --- a/src/blackgui/atcstationcomponent.cpp +++ b/src/blackgui/atcstationcomponent.cpp @@ -71,13 +71,22 @@ namespace BlackGui Q_ASSERT(this->ui->tvp_AtcStationsBooked); Q_ASSERT(this->getIContextNetwork()); - this->ui->tvp_AtcStationsBooked->update(this->getIContextNetwork()->getAtcStationsBooked()); - this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc(); + QObject *sender = QObject::sender(); + if (sender == this->ui->pb_ReloadAtcStationsBooked && this->getIContextNetwork()) + { + this->getIContextNetwork()->readAtcBookingsFromSource(); // trigger new read + QTimer::singleShot(7500, this, SLOT(reloadAtcStationsBooked())); // deferred loading + } + else + { + this->ui->tvp_AtcStationsBooked->update(this->getIContextNetwork()->getAtcStationsBooked()); + this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc(); + } } void CAtcStationComponent::changedAtcStationsOnline() { - // just update timestamp, data will be pulled by time + // just update timestamp, data will be pulled by time // the timestamp will tell if there are newer data this->m_timestampOnlineStationsChanged = QDateTime::currentDateTimeUtc(); }