mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #217, Project class providing information for compile configuration
* changed .pro / .pri as required * Used info from project class in network_vatlib * Checks / info in GUI/core (e.g. console) * const * versions of systemNameAndVersion / simulators, as mentioned in https://dev.vatsim-germany.org/issues/217#note-4
This commit is contained in:
@@ -3,9 +3,7 @@ include (config.pri)
|
||||
TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
|
||||
contains(BLACK_CONFIG, BlackMisc) {
|
||||
SUBDIRS += src/blackmisc
|
||||
}
|
||||
|
||||
contains(BLACK_CONFIG, BlackSound) {
|
||||
SUBDIRS += src/blacksound
|
||||
|
||||
15
config.pri
15
config.pri
@@ -8,7 +8,8 @@
|
||||
BLACK_VER_MAJ = 0
|
||||
BLACK_VER_MIN = 4
|
||||
BLACK_VER_PAT = 0
|
||||
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VERSION}
|
||||
BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VER_PAT}
|
||||
DEFINES += BLACK_VERSION=$$BLACK_VERSION
|
||||
|
||||
###########################
|
||||
# Install paths
|
||||
@@ -19,7 +20,6 @@ BLACK_VERSION = $${BLACK_VER_MAJ}.$${BLACK_VER_MIN}.$${BLACK_VERSION}
|
||||
# Build configuration
|
||||
###########################
|
||||
|
||||
BLACK_CONFIG += BlackMisc
|
||||
BLACK_CONFIG += BlackCore
|
||||
BLACK_CONFIG += BlackGui
|
||||
BLACK_CONFIG += BlackSound
|
||||
@@ -29,3 +29,14 @@ BLACK_CONFIG += Unittests
|
||||
#BLACK_CONFIG += FSX
|
||||
#BLACK_CONFIG += XPlane
|
||||
#BLACK_CONFIG += Doxygen
|
||||
|
||||
################################
|
||||
# Defines, for compile time code
|
||||
################################
|
||||
|
||||
contains(BLACK_CONFIG, BlackSound) { DEFINES += WITH_BLACKSOUND }
|
||||
contains(BLACK_CONFIG, BlackSim) { DEFINES += WITH_BLACKSIM }
|
||||
contains(BLACK_CONFIG, BlackCore) { DEFINES += WITH_BLACKCORE }
|
||||
contains(BLACK_CONFIG, BlackGui) { DEFINES += WITH_BLACKGUI }
|
||||
contains(BLACK_CONFIG, FSX) { DEFINES += WITH_FSX }
|
||||
contains(BLACK_CONFIG, XPlane) { DEFINES += WITH_XPLANE }
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackcore/context_application_impl.h"
|
||||
#include "blackmisc/networkutils.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QMetaType>
|
||||
#include <QMetaMethod>
|
||||
@@ -29,6 +30,10 @@ int main(int argc, char *argv[])
|
||||
QApplication::setWindowIcon(icon);
|
||||
QTextStream cin(stdin);
|
||||
|
||||
qDebug() << BlackMisc::CProject::version();
|
||||
qDebug() << BlackMisc::CProject::compiledInfo();
|
||||
qDebug();
|
||||
|
||||
qDebug() << "1 + la/ra .. session DBus server (default)";
|
||||
qDebug() << "2 + la/ra .. system DBus server";
|
||||
qDebug() << "3 + la/ra .. P2P DBus server";
|
||||
|
||||
@@ -33,6 +33,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
||||
|
||||
// with frameless window, we shift menu and statusbar into central widget
|
||||
// http://stackoverflow.com/questions/18316710/frameless-and-transparent-window-qt5
|
||||
this->setWindowTitle(CProject::systemNameAndVersion());
|
||||
if (this->m_windowMode == GuiModes::WindowFrameless)
|
||||
{
|
||||
|
||||
@@ -151,6 +152,10 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig)
|
||||
// We don't receive signals from the past. So ask for it simulate an initial signal
|
||||
simulatorConnectionChanged(this->getIContextSimulator()->isConnected());
|
||||
|
||||
// info
|
||||
this->ui->te_StatusPageConsole->appendPlainText(CProject::systemNameAndVersion());
|
||||
this->ui->te_StatusPageConsole->appendPlainText(CProject::compiledInfo());
|
||||
|
||||
// do this as last statement, so it can be used as flag
|
||||
// whether init has been completed
|
||||
this->m_init = true;
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace BlackCore
|
||||
virtual void unloadSimulatorPlugin () = 0;
|
||||
|
||||
//! Simulator avialable?
|
||||
bool isSimulatorAvailable() const { return !getSimulatorInfo().isUnspecified(); }
|
||||
bool isSimulatorAvailable() const { return BlackMisc::CProject::isCompiledWithFlightSimulatorSupport() && !getSimulatorInfo().isUnspecified(); }
|
||||
|
||||
protected:
|
||||
//! \brief Constructor
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "network_vatlib.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include <vector>
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
@@ -11,10 +12,6 @@
|
||||
static_assert(! std::is_abstract<BlackCore::CNetworkVatlib>::value, "Must implement all pure virtuals");
|
||||
|
||||
//TODO just placeholders to allow this to compile
|
||||
#define CLIENT_NAME_VERSION "BlackBox 0.3"
|
||||
#define CLIENT_VERSION_MAJOR 0
|
||||
#define CLIENT_VERSION_MINOR 3
|
||||
#define CLIENT_SIMULATOR_NAME "None"
|
||||
#define CLIENT_PUBLIC_ID 0
|
||||
#define CLIENT_PRIVATE_KEY ""
|
||||
|
||||
@@ -25,6 +22,8 @@ namespace BlackCore
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc;
|
||||
|
||||
|
||||
void exceptionDispatcher(const char *caller);
|
||||
|
||||
@@ -66,8 +65,8 @@ namespace BlackCore
|
||||
capabilities += "=1";
|
||||
}
|
||||
|
||||
m_net->CreateNetworkSession(CLIENT_NAME_VERSION, CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR,
|
||||
CLIENT_SIMULATOR_NAME, CLIENT_PUBLIC_ID, CLIENT_PRIVATE_KEY, toFSD(capabilities));
|
||||
m_net->CreateNetworkSession(CProject::systemNameAndVersionChar(), CProject::versionMajor(), CProject::versionMinor(),
|
||||
CProject::simulatorsChar(), CLIENT_PUBLIC_ID, CLIENT_PRIVATE_KEY, toFSD(capabilities));
|
||||
|
||||
m_net->InstallOnConnectionStatusChangedEvent(onConnectionStatusChanged, this);
|
||||
m_net->InstallOnTextMessageReceivedEvent(onTextMessageReceived, this);
|
||||
|
||||
141
src/blackmisc/project.cpp
Normal file
141
src/blackmisc/project.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "project.h"
|
||||
#include <QStringList>
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
|
||||
#define BLACK_VERSION_STR_X(v) #v
|
||||
#define BLACK_VERSION_STR(v) BLACK_VERSION_STR_X(v)
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
bool CProject::isCompiledWithBlackCore()
|
||||
{
|
||||
#ifdef WITH_BLACKCORE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithBlackSound()
|
||||
{
|
||||
#ifdef WITH_BLACKSOUND
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFsxSupport()
|
||||
{
|
||||
#ifdef WITH_FSX
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithXPlaneSupport()
|
||||
{
|
||||
#ifdef WITH_XPLANE
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool CProject::isCompiledWithFlightSimulatorSupport()
|
||||
{
|
||||
return isCompiledWithFsxSupport() || isCompiledWithXPlaneSupport();
|
||||
}
|
||||
|
||||
bool BlackMisc::CProject::isCompiledWithGui()
|
||||
{
|
||||
#ifdef WITH_BLACKGUI
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
const QString &CProject::compiledInfo()
|
||||
{
|
||||
static QString info;
|
||||
if (info.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithBlackCore()) sl << "BlackCore";
|
||||
if (isCompiledWithBlackSound()) sl << "BlackSound";
|
||||
if (isCompiledWithGui()) sl << "BlackGui";
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
info = sl.join(", ");
|
||||
if (info.isEmpty()) info = "<none>";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
const QString &CProject::simulators()
|
||||
{
|
||||
static QString sims;
|
||||
if (sims.isEmpty())
|
||||
{
|
||||
static QStringList sl;
|
||||
if (isCompiledWithFsxSupport()) sl << "FSX";
|
||||
if (isCompiledWithXPlaneSupport()) sl << "XPlane";
|
||||
sims = sl.join(", ");
|
||||
if (sims.isEmpty()) sims = "<none>";
|
||||
}
|
||||
return sims;
|
||||
}
|
||||
|
||||
const char *CProject::simulatorsChar()
|
||||
{
|
||||
static const QByteArray a(simulators().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
const QString &CProject::version()
|
||||
{
|
||||
#ifdef BLACK_VERSION
|
||||
const static QString v(BLACK_VERSION_STR(BLACK_VERSION));
|
||||
#else
|
||||
const static QString v("?");
|
||||
#endif
|
||||
return v;
|
||||
}
|
||||
|
||||
const QString &CProject::systemNameAndVersion()
|
||||
{
|
||||
static QString s = QString("BlackBox %1").arg(version());
|
||||
return s;
|
||||
}
|
||||
|
||||
const char *CProject::systemNameAndVersionChar()
|
||||
{
|
||||
static const QByteArray a(systemNameAndVersion().toUtf8());
|
||||
return a.constData();
|
||||
}
|
||||
|
||||
int CProject::versionMajor()
|
||||
{
|
||||
return getMajorMinor(0);
|
||||
}
|
||||
|
||||
int CProject::versionMinor()
|
||||
{
|
||||
return getMajorMinor(1);
|
||||
}
|
||||
|
||||
int CProject::getMajorMinor(int index)
|
||||
{
|
||||
QString v = version();
|
||||
if (v.isEmpty() || !v.contains(".")) return -1;
|
||||
bool ok;
|
||||
int vi = v.split(".")[index].toInt(&ok);
|
||||
return ok ? vi : -1;
|
||||
}
|
||||
}
|
||||
|
||||
#undef BLACK_VERSION_STR
|
||||
#undef BLACK_VERSION_STR_X
|
||||
66
src/blackmisc/project.h
Normal file
66
src/blackmisc/project.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef BLACKMISC_CPROJECT_H
|
||||
#define BLACKMISC_CPROJECT_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Metadata about the project
|
||||
*/
|
||||
class CProject
|
||||
{
|
||||
public:
|
||||
//! with BlackCore?
|
||||
static bool isCompiledWithBlackCore();
|
||||
|
||||
//! with BlackSound?
|
||||
static bool isCompiledWithBlackSound();
|
||||
|
||||
//! with FSX support?
|
||||
static bool isCompiledWithFsxSupport();
|
||||
|
||||
//! with XPlane support?
|
||||
static bool isCompiledWithXPlaneSupport();
|
||||
|
||||
//! with any simulator libraries
|
||||
static bool isCompiledWithFlightSimulatorSupport();
|
||||
|
||||
//! with GUI?
|
||||
static bool isCompiledWithGui();
|
||||
|
||||
//! Compiled with as info string
|
||||
static const QString &compiledInfo();
|
||||
|
||||
//! Simulator String info
|
||||
static const QString &simulators();
|
||||
|
||||
//! Simulator String info
|
||||
static const char *simulatorsChar();
|
||||
|
||||
//! Version info
|
||||
static const QString &version();
|
||||
|
||||
//! System's name and version
|
||||
static const QString &systemNameAndVersion();
|
||||
|
||||
//! System's name and version
|
||||
static const char *systemNameAndVersionChar();
|
||||
|
||||
//! Version major
|
||||
static int versionMajor();
|
||||
|
||||
//! Version minor
|
||||
static int versionMinor();
|
||||
|
||||
private:
|
||||
//! Constructor
|
||||
CProject() {}
|
||||
|
||||
//! Split version
|
||||
static int getMajorMinor(int index);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user