From 3c15f2ad894520e0ff61a3e66397df16cc58ddda Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 28 Apr 2015 01:02:24 +0200 Subject: [PATCH] refs #395, refs #411 fixes found in course of DBus testing * set infobar status correctly when GUI connects after the core has been started * more detailed information in information statusbar * allow to obtain currently connected server in network context * made many network vatlib slots normal member functions * fixed rendered aircraft flag setting in FSX driver --- src/blackcore/context_network.h | 5 +++- src/blackcore/context_network_empty.h | 7 +++++ src/blackcore/context_network_impl.cpp | 12 ++++++++ src/blackcore/context_network_impl.h | 10 +++---- src/blackcore/context_network_proxy.cpp | 5 ++++ src/blackcore/context_network_proxy.h | 3 ++ src/blackcore/network.h | 15 ++++++---- src/blackcore/network_vatlib.cpp | 2 +- src/blackcore/network_vatlib.h | 11 +++---- src/blackcore/simulator.h | 1 + .../components/infobarstatuscomponent.cpp | 30 +++++++++++++------ .../components/infobarstatuscomponent.h | 4 +-- .../components/maininfoareacomponent.ui | 2 +- src/blackmisc/aviation/aircrafticao.cpp | 10 +++++++ src/blackmisc/aviation/aircrafticao.h | 26 +++++----------- src/blackmisc/network/server.h | 2 +- src/plugins/simulator/fsx/simulator_fsx.cpp | 7 +++-- 17 files changed, 100 insertions(+), 52 deletions(-) diff --git a/src/blackcore/context_network.h b/src/blackcore/context_network.h index cb0ccb135..e2ce3c1d0 100644 --- a/src/blackcore/context_network.h +++ b/src/blackcore/context_network.h @@ -194,10 +194,13 @@ namespace BlackCore virtual BlackMisc::Aviation::CCallsignSet getFastPositionEnabledCallsigns() = 0; //! Connect to Network - //! \return messages gererated during connecting + //! \return messages generated during connecting //! \see INetwork::LoginMode virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint loginMode) = 0; + //! Server which is connected, if not connected empty default object. + virtual BlackMisc::Network::CServer getConnectedServer() const = 0; + //! Disconnect from network //! \return messages generated during disconnecting virtual BlackMisc::CStatusMessage disconnectFromNetwork() = 0; diff --git a/src/blackcore/context_network_empty.h b/src/blackcore/context_network_empty.h index c9dd98a6f..0b56cb6ba 100644 --- a/src/blackcore/context_network_empty.h +++ b/src/blackcore/context_network_empty.h @@ -104,6 +104,13 @@ namespace BlackCore return false; } + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override + { + logEmptyContextWarning(Q_FUNC_INFO); + return BlackMisc::Network::CServer(); + } + //! \copydoc IContextNetwork::sendTextMessages() virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &textMessages) override { diff --git a/src/blackcore/context_network_impl.cpp b/src/blackcore/context_network_impl.cpp index 7b227be15..94d9c317a 100644 --- a/src/blackcore/context_network_impl.cpp +++ b/src/blackcore/context_network_impl.cpp @@ -189,6 +189,18 @@ namespace BlackCore } } + CServer CContextNetwork::getConnectedServer() const + { + if (this->isConnected()) + { + return this->m_network->getPresetServer(); + } + else + { + return CServer(); + } + } + CStatusMessage CContextNetwork::disconnectFromNetwork() { if (this->isDebugEnabled()) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; } diff --git a/src/blackcore/context_network_impl.h b/src/blackcore/context_network_impl.h index 2e0aa7893..569fa3247 100644 --- a/src/blackcore/context_network_impl.h +++ b/src/blackcore/context_network_impl.h @@ -127,6 +127,9 @@ namespace BlackCore //! \copydoc IContextNetwork::connectToNetwork() virtual BlackMisc::CStatusMessage connectToNetwork(const BlackMisc::Network::CServer &server, uint mode) override; + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override; + //! \copydoc IContextNetwork::disconnectFromNetwork() virtual BlackMisc::CStatusMessage disconnectFromNetwork() override; @@ -256,13 +259,8 @@ namespace BlackCore //! Check if a supervisor message was received void ps_checkForSupervisiorTextMessage(const BlackMisc::Network::CTextMessageList &messages); - /*! - * \brief Connection status changed? - * \param from old status - * \param to new status - */ + //! Connection status changed void ps_fsdConnectionStatusChanged(INetwork::ConnectionStatus from, INetwork::ConnectionStatus to); - }; } diff --git a/src/blackcore/context_network_proxy.cpp b/src/blackcore/context_network_proxy.cpp index ade3513f8..7c1acbeca 100644 --- a/src/blackcore/context_network_proxy.cpp +++ b/src/blackcore/context_network_proxy.cpp @@ -243,6 +243,11 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1Literal("isConnected")); } + CServer CContextNetworkProxy::getConnectedServer() const + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("getConnectedServer")); + } + bool CContextNetworkProxy::parseCommandLine(const QString &commandLine, const QString &originator) { return this->m_dBusInterface->callDBusRet(QLatin1Literal("commandLineEntered"), commandLine, originator); diff --git a/src/blackcore/context_network_proxy.h b/src/blackcore/context_network_proxy.h index 9ffa39439..206e09fd2 100644 --- a/src/blackcore/context_network_proxy.h +++ b/src/blackcore/context_network_proxy.h @@ -84,6 +84,9 @@ namespace BlackCore //! \copydoc IContextNetwork::isConnected() virtual bool isConnected() const override; + //! \copydoc IContextNetwork::getConnectedServer + virtual BlackMisc::Network::CServer getConnectedServer() const override; + //! \copydoc IContextNetwork::parseCommandLine virtual bool parseCommandLine(const QString &commandLine, const QString &originator) override; diff --git a/src/blackcore/network.h b/src/blackcore/network.h index 246452d91..d65974334 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -139,23 +139,26 @@ namespace BlackCore status == DisconnectedFailed || status == DisconnectedLost; } + //////////////////////////////////////////////////////////////// + //! \name Network slots + //! @{ + //////////////////////////////////////////////////////////////// /*! * Returns true if the current ConnectionStatus is a connected state. */ virtual bool isConnected() const = 0; + /*! + * Get preset server. + */ + virtual BlackMisc::Network::CServer getPresetServer() const = 0; + /*! * Returns true if the current ConnectionStatus is in transition, e.g. connecting. */ virtual bool isPendingConnection() const = 0; - public slots: - //////////////////////////////////////////////////////////////// - //! \name Network slots - //! @{ - //////////////////////////////////////////////////////////////// - /*! * Set the server which will be connected to. * \pre Network must be disconnected when calling this function. diff --git a/src/blackcore/network_vatlib.cpp b/src/blackcore/network_vatlib.cpp index 1b0c25e59..957ed279c 100644 --- a/src/blackcore/network_vatlib.cpp +++ b/src/blackcore/network_vatlib.cpp @@ -277,7 +277,7 @@ namespace BlackCore } /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ - /********************************** INetwork slots ************************************/ + /********************************** INetwork functions ************************************/ /********************************** * * * * * * * * * * * * * * * * * * * ************************************/ void CNetworkVatlib::presetServer(const CServer &server) diff --git a/src/blackcore/network_vatlib.h b/src/blackcore/network_vatlib.h index 7504a652a..5182f21f9 100644 --- a/src/blackcore/network_vatlib.h +++ b/src/blackcore/network_vatlib.h @@ -39,9 +39,10 @@ namespace BlackCore //! Destructor virtual ~CNetworkVatlib(); - //! \name Network slots + //! \name Network functions //! @{ virtual bool isConnected() const override { return m_status == vatStatusConnected; } + virtual BlackMisc::Network::CServer getPresetServer() const override { return m_server; } virtual bool isPendingConnection() const override { return m_status == vatStatusConnecting; } virtual void presetLoginMode(LoginMode mode) override; virtual void presetServer(const BlackMisc::Network::CServer &server) override; @@ -62,12 +63,12 @@ namespace BlackCore virtual void sendAircraftConfigQuery(const BlackMisc::Aviation::CCallsign &callsign) override; //! @} - //! \name Text message slots + //! \name Text message functions //! @{ virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override; //! @} - //! \name ATC slots + //! \name ATC functions //! @{ virtual void sendAtcQuery(const BlackMisc::Aviation::CCallsign &callsign) override; virtual void sendAtisQuery(const BlackMisc::Aviation::CCallsign &callsign) override; @@ -75,7 +76,7 @@ namespace BlackCore virtual void sendFlightPlanQuery(const BlackMisc::Aviation::CCallsign &callsign) override; //! @} - //! \name Aircraft slots + //! \name Aircraft functions //! @{ virtual void sendCapabilitiesQuery(const BlackMisc::Aviation::CCallsign &callsign) override; virtual void sendIcaoCodesQuery(const BlackMisc::Aviation::CCallsign &callsign) override; @@ -84,7 +85,7 @@ namespace BlackCore virtual void sendInterimPositions(const BlackMisc::Aviation::CCallsignSet &receiver) override; //! @} - //! \name Weather slots + //! \name Weather functions //! @{ virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override; virtual void sendWeatherDataQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override; diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index c79f05fab..836ffa57e 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -38,6 +38,7 @@ namespace BlackCore //! ISimulator status enum SimulatorStatus { + Disconnected = 0, Connected = 1 << 0, //!< Is the plugin connected to the simulator? Running = 1 << 1, //!< Is the simulator actually simulating? Paused = 1 << 2, //!< Is the simulator paused? diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index acb0f0581..20767b4b4 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -78,11 +78,15 @@ namespace BlackGui { connect(this->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::ps_onSimulatorStatusChanged); connect(this->getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CInfoBarStatusComponent::ps_onMapperReady); + + // initial values + this->ps_onMapperReady(); + bool connected = this->getIContextSimulator()->isConnected(); + this->ps_onSimulatorStatusChanged(connected ? ISimulator::Connected : ISimulator::Disconnected); } if (this->getIContextNetwork()) { - this->ui->led_Simulator->setOn(this->getIContextSimulator()->isConnected()); connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_onNetworkConnectionChanged); } @@ -98,19 +102,20 @@ namespace BlackGui } } - void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(quint8 status) + void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(int status) { -// if (connected && running) - if (status & (ISimulator::Connected | ISimulator::Running)) { + if (status > 0) + { this->ui->led_Simulator->setOn(true); - } else if (status & ISimulator::Connected) { - this->ui->led_Simulator->setTriState(); - } else { + this->ui->led_Simulator->setOnToolTip(getIContextSimulator()->getSimulatorPluginInfo().getDescription()); + } + else + { this->ui->led_Simulator->setOn(false); } } - void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(uint from, uint to) + void CInfoBarStatusComponent::ps_onNetworkConnectionChanged(int from, int to) { INetwork::ConnectionStatus fromStatus = static_cast(from); INetwork::ConnectionStatus toStatus = static_cast(to); @@ -126,6 +131,7 @@ namespace BlackGui break; case INetwork::Connected: this->ui->led_Network->setOn(true); + this->ui->led_Network->setOnToolTip("Connected: " + getIContextNetwork()->getConnectedServer().getName()); break; case INetwork::Connecting: this->ui->led_Network->setTriStateColor(CLedWidget::Yellow); @@ -179,8 +185,14 @@ namespace BlackGui return; } - bool on = this->getIContextSimulator()->getInstalledModelsCount() > 0; + int models = this->getIContextSimulator()->getInstalledModelsCount(); + bool on = (models > 0); this->ui->led_MapperReady->setOn(on); + if (on) + { + QString m = QString("Mapper with %1 models").arg(models); + this->ui->led_MapperReady->setToolTip(m); + } } } // namespace } // namespace diff --git a/src/blackgui/components/infobarstatuscomponent.h b/src/blackgui/components/infobarstatuscomponent.h index 9e74eaf1d..3cf2b94e9 100644 --- a/src/blackgui/components/infobarstatuscomponent.h +++ b/src/blackgui/components/infobarstatuscomponent.h @@ -55,10 +55,10 @@ namespace BlackGui private slots: //! Simulator connection has been changed - void ps_onSimulatorStatusChanged(quint8 status); + void ps_onSimulatorStatusChanged(int status); //! Network connection has been changed - void ps_onNetworkConnectionChanged(uint from, uint to); + void ps_onNetworkConnectionChanged(int from, int to); //! Context menu requested void ps_customAudioContextMenuRequested(const QPoint &position); diff --git a/src/blackgui/components/maininfoareacomponent.ui b/src/blackgui/components/maininfoareacomponent.ui index 8f263e52a..caae9ddac 100644 --- a/src/blackgui/components/maininfoareacomponent.ui +++ b/src/blackgui/components/maininfoareacomponent.ui @@ -389,7 +389,7 @@ 0 - 0 + 2 0 diff --git a/src/blackmisc/aviation/aircrafticao.cpp b/src/blackmisc/aviation/aircrafticao.cpp index fc06ee936..83e371a17 100644 --- a/src/blackmisc/aviation/aircrafticao.cpp +++ b/src/blackmisc/aviation/aircrafticao.cpp @@ -20,6 +20,10 @@ namespace BlackMisc namespace Aviation { + CAircraftIcao::CAircraftIcao(const QString &icao, const QString &airline) + : m_aircraftDesignator(icao.trimmed().toUpper()), m_airlineDesignator(airline.trimmed().toUpper()) + {} + QString CAircraftIcao::convertToQString(bool i18n) const { Q_UNUSED(i18n); @@ -41,6 +45,12 @@ namespace BlackMisc return (this->hasAircraftDesignator() && this->getAircraftDesignator() != "ZZZZ"); } + QString CAircraftIcao::getEngineType() const + { + if (this->m_aircraftCombinedType.length() != 3) return ""; + return this->m_aircraftCombinedType.right(1); + } + QString CAircraftIcao::asString() const { if (this->m_aircraftDesignator.isEmpty()) { return ""; } diff --git a/src/blackmisc/aviation/aircrafticao.h b/src/blackmisc/aviation/aircrafticao.h index a5e75d3eb..0794f8ada 100644 --- a/src/blackmisc/aviation/aircrafticao.h +++ b/src/blackmisc/aviation/aircrafticao.h @@ -42,14 +42,10 @@ namespace BlackMisc //! Constructor. explicit CAircraftIcao(const QString &icao) : m_aircraftDesignator(icao.trimmed().toUpper()) {} - /*! - * Constructor. - * \param icao "B737" - * \param airline "DLH" - */ - CAircraftIcao(const QString &icao, const QString &airline) - : m_aircraftDesignator(icao.trimmed().toUpper()), m_airlineDesignator(airline.trimmed().toUpper()) - {} + //! Constructor. + //! \param icao "B737" + //! \param airline "DLH" + CAircraftIcao(const QString &icao, const QString &airline); /*! * Constructor. @@ -115,16 +111,10 @@ namespace BlackMisc bool hasAircraftCombinedType() const { return this->getAircraftCombinedType().length() == 3; } //! Get engine type, e.g. "J" - QString getEngineType() const - { - if (this->m_aircraftCombinedType.length() != 3) return ""; - return this->m_aircraftCombinedType.right(1); - } + QString getEngineType() const; - /*! - * \brief As string for GUI representation by index - * \remarks Different from toQString() - */ + //! As string for GUI representation by index + //! \remarks Different from toQString() QString asString() const; //! Set type @@ -175,7 +165,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraftIcao, ( o.m_airlineDesignator, o.m_livery, o.m_aircraftColor - )) + )) #endif // guard diff --git a/src/blackmisc/network/server.h b/src/blackmisc/network/server.h index c1d42352c..47a8f3b1b 100644 --- a/src/blackmisc/network/server.h +++ b/src/blackmisc/network/server.h @@ -40,7 +40,7 @@ namespace BlackMisc CServer() : m_port(-1), m_isAcceptingConnections(true) {} //! Constructor. - CServer(const QString &name, const QString &description, const QString &address, qint32 port, const CUser &user, bool isAcceptingConnections = true) + CServer(const QString &name, const QString &description, const QString &address, int port, const CUser &user, bool isAcceptingConnections = true) : m_name(name), m_description(description), m_address(address), m_port(port), m_user(user), m_isAcceptingConnections(isAcceptingConnections) {} //! Get address. diff --git a/src/plugins/simulator/fsx/simulator_fsx.cpp b/src/plugins/simulator/fsx/simulator_fsx.cpp index cad81bf98..3c0a13fd0 100644 --- a/src/plugins/simulator/fsx/simulator_fsx.cpp +++ b/src/plugins/simulator/fsx/simulator_fsx.cpp @@ -164,7 +164,8 @@ namespace BlackSimPlugin // matched models CAircraftModel aircraftModel = modelMatching(newRemoteAircraftCopy); Q_ASSERT_X(newRemoteAircraft.getCallsign() == aircraftModel.getCallsign(), Q_FUNC_INFO, "mismatching callsigns"); - this->updateAircraftModel(newRemoteAircraft.getCallsign(), aircraftModel, simulatorOriginator()); + this->updateAircraftModel(callsign, aircraftModel, simulatorOriginator()); + this->updateAircraftRendered(callsign, true, simulatorOriginator()); CSimulatedAircraft aircraftAfterModelApplied(getAircraftInRangeForCallsign(newRemoteAircraft.getCallsign())); aircraftAfterModelApplied.setRendered(true); emit modelMatchingCompleted(aircraftAfterModelApplied); @@ -172,7 +173,7 @@ namespace BlackSimPlugin // create AI if (isSimulating()) { - //! \todo if exists, recreate (new model?, new ICAO code) + //! \todo FSX driver if exists, recreate (new model?, new ICAO code) QByteArray m = aircraftModel.getModelString().toLocal8Bit(); HRESULT hr = SimConnect_AICreateNonATCAircraft(m_hSimConnect, m.constData(), qPrintable(callsign.toQString().left(12)), initialPosition, static_cast(simObj.getRequestId())); if (hr != S_OK) { CLogMessage(this).error("SimConnect, can not create AI traffic"); } @@ -832,6 +833,8 @@ namespace BlackSimPlugin { Q_CONSTEXPR int QueryInterval = 5 * 1000; // 5 seconds m_timer->setInterval(QueryInterval); + this->setObjectName("CSimulatorFsxListener"); + this->m_timer->setObjectName(this->objectName().append(":m_timer")); connect(m_timer, &QTimer::timeout, [this]() {