From bc660e5f81fc5e767dfeb74eedd6b3d36969ad44 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Wed, 1 Dec 2021 22:48:22 +0100 Subject: [PATCH] Extract method to convert between FlightRules and FlightType --- src/blackcore/fsd/fsdclient.cpp | 22 +++++++++++++--------- src/blackcore/fsd/fsdclient.h | 3 +++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/blackcore/fsd/fsdclient.cpp b/src/blackcore/fsd/fsdclient.cpp index 6a01a87c2..3b28f2347 100644 --- a/src/blackcore/fsd/fsdclient.cpp +++ b/src/blackcore/fsd/fsdclient.cpp @@ -704,15 +704,7 @@ namespace BlackCore::Fsd QString act = flightPlan.getCombinedPrefixIcaoSuffix(); if (act.isEmpty()) { act = flightPlan.getAircraftIcao().getDesignator(); } // fallback - FlightType flightType = FlightType::IFR; - switch (flightPlan.getFlightRules()) - { - case CFlightPlan::IFR: flightType = FlightType::IFR; break; - case CFlightPlan::VFR: flightType = FlightType::VFR; break; - case CFlightPlan::SVFR: flightType = FlightType::SVFR; break; - case CFlightPlan::DVFR: flightType = FlightType::DVFR; break; - default: flightType = FlightType::IFR; break; - } + FlightType flightType = getFlightType(flightPlan.getFlightRules()); const QList timePartsEnroute = flightPlan.getEnrouteTime().getHrsMinSecParts(); const QList timePartsFuel = flightPlan.getFuelTime().getHrsMinSecParts(); @@ -2409,6 +2401,18 @@ namespace BlackCore::Fsd return copy.remove(':'); } + FlightType CFSDClient::getFlightType(CFlightPlan::FlightRules flightRules) + { + switch (flightRules) + { + case CFlightPlan::IFR: return FlightType::IFR; + case CFlightPlan::VFR: return FlightType::VFR; + case CFlightPlan::SVFR: return FlightType::SVFR; + case CFlightPlan::DVFR: return FlightType::DVFR; + default: return FlightType::IFR; + } + } + const QString &CFSDClient::messageTypeToString(MessageType mt) const { QHash::const_iterator i = m_messageTypeMapping.constBegin(); diff --git a/src/blackcore/fsd/fsdclient.h b/src/blackcore/fsd/fsdclient.h index 9dfdea44b..fdeb69277 100644 --- a/src/blackcore/fsd/fsdclient.h +++ b/src/blackcore/fsd/fsdclient.h @@ -461,6 +461,9 @@ namespace BlackCore::Fsd //! Get a short-lived, one-time-use token from Vatsim web service, to avoid sending plaintext password to FSD void getVatsimAuthToken(const QString &cid, const QString &password, const BlackMisc::CSlot &callback); + //! Convert FlightRules to FlightType + static FlightType getFlightType(BlackMisc::Aviation::CFlightPlan::FlightRules flightRule); + vatsim_auth *m_clientAuth = nullptr; vatsim_auth *m_serverAuth = nullptr; QString m_lastServerAuthChallenge;