mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #297 Added new network settings.
This commit is contained in:
@@ -53,7 +53,7 @@ namespace BlackCore
|
||||
connect(this->m_network, &INetwork::textMessageSent, this, &CContextNetwork::textMessageSent);
|
||||
|
||||
// 2. VATSIM bookings
|
||||
this->m_vatsimBookingReader = new CVatsimBookingReader(this, this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl());
|
||||
this->m_vatsimBookingReader = new CVatsimBookingReader(this);
|
||||
connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::ps_receivedBookings);
|
||||
this->m_vatsimBookingReader->start();
|
||||
this->m_vatsimBookingReader->setInterval(180 * 1000);
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace BlackCore
|
||||
CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())
|
||||
);
|
||||
this->m_ownAircraft.setSituation(situation);
|
||||
this->m_ownAircraft.setPilot(this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer().getUser());
|
||||
this->m_ownAircraft.setPilot(this->m_currentNetworkServer.get().getUser());
|
||||
|
||||
// from simulator, if available
|
||||
this->m_ownAircraft.setCallsign(CCallsign("SWIFT")); // would come from settings
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "blackcore/context_settings.h"
|
||||
#include "blackcore/context_runtime.h"
|
||||
#include "blackcore/dbus_server.h"
|
||||
#include "blackcore/settings/network.h"
|
||||
#include "blackmisc/aviation/atcstation.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
#include "blackmisc/identifiable.h"
|
||||
@@ -145,6 +146,8 @@ namespace BlackCore
|
||||
QString m_voiceRoom2UrlOverride; //!< overridden voice room url
|
||||
mutable QReadWriteLock m_lockAircraft; //!< lock aircraft
|
||||
|
||||
CSetting<Settings::Network::CurrentTrafficServer> m_currentNetworkServer { this };
|
||||
|
||||
//! Init my very own aircraft with some defaults, before overridden by simulator
|
||||
void initOwnAircraft();
|
||||
|
||||
|
||||
@@ -45,16 +45,9 @@ namespace BlackCore
|
||||
// upfront reading of settings, as DBus server already relies on settings
|
||||
QString dbusAddress;
|
||||
|
||||
//! \todo Change when settings ready RW: We are allocating a full settings context in order to get the DBus address. I wonder if this can be done cleaner.
|
||||
//! \todo Change when settings ready RW: I wonder if this can be done cleaner.
|
||||
if (config.hasDBusAddress()) { dbusAddress = config.getDBusAddress(); } // bootstrap / explicit
|
||||
if (config.hasLocalSettings())
|
||||
{
|
||||
auto *settings = new CContextSettings(config.getModeSettings(), this);
|
||||
if (settings) settings->read();
|
||||
if (dbusAddress.isEmpty()) dbusAddress = settings->getNetworkSettings().getDBusServerAddress();
|
||||
|
||||
settings->deleteLater();
|
||||
}
|
||||
else { dbusAddress = m_dbusServerAddress.get(); }
|
||||
|
||||
// DBus
|
||||
if (config.requiresDBusSever()) { this->initDBusServer(dbusAddress); }
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackcoreexport.h"
|
||||
#include "blackcore/context_runtime_config.h"
|
||||
#include "blackcore/settings/network.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/simulation/ownaircraftprovider.h"
|
||||
@@ -158,6 +159,8 @@ namespace BlackCore
|
||||
private:
|
||||
bool m_init = false; //!< flag
|
||||
|
||||
CSetting<Settings::Network::DBusServerAddress> m_dbusServerAddress { this };
|
||||
|
||||
// DBus
|
||||
CDBusServer *m_dbusServer = nullptr;
|
||||
QDBusConnection m_dbusConnection = QDBusConnection("default");
|
||||
|
||||
69
src/blackcore/settings/network.h
Normal file
69
src/blackcore/settings/network.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKCORE_SETTINGS_NETWORK_H
|
||||
#define BLACKCORE_SETTINGS_NETWORK_H
|
||||
|
||||
#include "blackcore/settingscache.h"
|
||||
#include "blackmisc/network/serverlist.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
namespace Network
|
||||
{
|
||||
//! Virtual air traffic servers
|
||||
struct TrafficServers : public CSettingTrait<BlackMisc::Network::CServerList>
|
||||
{
|
||||
//! \copydoc BlackCore::CSetting::key
|
||||
static const char *key() { return "network/trafficservers"; }
|
||||
};
|
||||
|
||||
//! Currently selected virtual air traffic server
|
||||
struct CurrentTrafficServer : public CSettingTrait<BlackMisc::Network::CServer>
|
||||
{
|
||||
//! \copydoc BlackCore::CSetting::key
|
||||
static const char *key() { return "network/currenttrafficserver"; }
|
||||
|
||||
//! \copydoc BlackCore::CSetting::defaultValue
|
||||
static const BlackMisc::Network::CServer &defaultValue()
|
||||
{
|
||||
using namespace BlackMisc::Network;
|
||||
static const CServer dv("Testserver", "Client project testserver", "vatsim-germany.org", 6809, CUser("guest", "Guest Client project", "", "guest"));
|
||||
return dv;
|
||||
}
|
||||
};
|
||||
|
||||
//! Booking service URL
|
||||
struct BookingService : public CSettingTrait<QString>
|
||||
{
|
||||
//! \copydoc BlackCore::CSetting::key
|
||||
static const char *key() { return "network/bookingservice"; }
|
||||
|
||||
//! \copydoc BlackCore::CSetting::defaultValue
|
||||
static const QString &defaultValue() { static const QString dv("http://vatbook.euroutepro.com/xml2.php"); return dv; }
|
||||
};
|
||||
|
||||
//! DBus server address
|
||||
struct DBusServerAddress : public CSettingTrait<QString>
|
||||
{
|
||||
//! \copydoc BlackCore::CSetting::key
|
||||
static const char *key() { return "network/dbusserver"; }
|
||||
|
||||
//! \copydoc BlackCore::CSetting::defaultValue
|
||||
static const QString &defaultValue() { static const QString dv("session"); return dv; }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,9 +21,8 @@ using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
CVatsimBookingReader::CVatsimBookingReader(QObject *owner, const QString &url) :
|
||||
CThreadedReader(owner, "CVatsimBookingReader"),
|
||||
m_serviceUrl(url)
|
||||
CVatsimBookingReader::CVatsimBookingReader(QObject *owner) :
|
||||
CThreadedReader(owner, "CVatsimBookingReader")
|
||||
{
|
||||
this->m_networkManager = new QNetworkAccessManager(this);
|
||||
this->connect(this->m_networkManager, &QNetworkAccessManager::finished, this, &CVatsimBookingReader::ps_parseBookings);
|
||||
@@ -40,7 +39,7 @@ namespace BlackCore
|
||||
void CVatsimBookingReader::ps_read()
|
||||
{
|
||||
this->threadAssertCheck();
|
||||
QUrl url(this->m_serviceUrl);
|
||||
QUrl url(this->m_serviceUrl.get());
|
||||
if (url.isEmpty()) return;
|
||||
Q_ASSERT(this->m_networkManager);
|
||||
QNetworkRequest request(url);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKCORE_VATSIMBOOKINGREADER_H
|
||||
|
||||
#include "blackcoreexport.h"
|
||||
#include "blackcore/settings/network.h"
|
||||
#include "blackmisc/threadedreader.h"
|
||||
#include "blackmisc/aviation/atcstationlist.h"
|
||||
|
||||
@@ -30,7 +31,7 @@ namespace BlackCore
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CVatsimBookingReader(QObject *owner, const QString &url);
|
||||
explicit CVatsimBookingReader(QObject *owner);
|
||||
|
||||
//! Read / re-read bookings
|
||||
void readInBackgroundThread();
|
||||
@@ -44,7 +45,7 @@ namespace BlackCore
|
||||
void ps_read();
|
||||
|
||||
private:
|
||||
QString m_serviceUrl; //!< URL of the service
|
||||
CSetting<Settings::Network::BookingService> m_serviceUrl { this };
|
||||
QNetworkAccessManager *m_networkManager = nullptr;
|
||||
|
||||
signals:
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace BlackGui
|
||||
ps_validateAircraftValues();
|
||||
ps_validateVatsimValues();
|
||||
ps_onVatsimDataFileLoaded();
|
||||
CServerList otherServers = this->getIContextSettings()->getNetworkSettings().getTrafficNetworkServers();
|
||||
CServerList otherServers = this->m_trafficNetworkServers.get();
|
||||
this->ui->cbp_OtherServers->setServers(otherServers);
|
||||
}
|
||||
|
||||
@@ -447,7 +447,7 @@ namespace BlackGui
|
||||
void CLoginComponent::ps_onSettingsChanged(uint settingsType)
|
||||
{
|
||||
if (settingsType != static_cast<uint>(IContextSettings::SettingsNetwork)) { return; }
|
||||
CServerList otherServers = this->getIContextSettings()->getNetworkSettings().getTrafficNetworkServers();
|
||||
CServerList otherServers = this->m_trafficNetworkServers.get();
|
||||
this->ui->cbp_OtherServers->setServers(otherServers);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "enableforruntime.h"
|
||||
#include "blackcore/settings/network.h"
|
||||
#include "blackmisc/aviation/aircraft.h"
|
||||
#include "blackmisc/network/server.h"
|
||||
#include <QFrame>
|
||||
@@ -150,6 +151,8 @@ namespace BlackGui
|
||||
QScopedPointer<Ui::CLoginComponent> ui;
|
||||
const int LogoffIntervalSeconds = 10;
|
||||
QTimer *m_logoffCountdownTimer = nullptr;
|
||||
|
||||
BlackCore::CSetting<BlackCore::Settings::Network::TrafficServers> m_trafficNetworkServers { this };
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -50,11 +50,8 @@ namespace BlackGui
|
||||
|
||||
void CSettingsNetworkServersComponent::reloadSettings()
|
||||
{
|
||||
// local copy
|
||||
CSettingsNetwork nws = this->getIContextSettings()->getNetworkSettings();
|
||||
|
||||
// update servers
|
||||
this->ui->tvp_SettingsTnServers->updateContainer(nws.getTrafficNetworkServers());
|
||||
this->ui->tvp_SettingsTnServers->updateContainer(m_trafficNetworkServers.get());
|
||||
}
|
||||
|
||||
void CSettingsNetworkServersComponent::ps_networkServerSelected(QModelIndex index)
|
||||
@@ -75,16 +72,17 @@ namespace BlackGui
|
||||
return;
|
||||
}
|
||||
|
||||
const QString path = CSettingUtilities::appendPaths(IContextSettings::PathNetworkSettings(), CSettingsNetwork::ValueTrafficServers());
|
||||
CServerList serverList = m_trafficNetworkServers.get();
|
||||
QObject *sender = QObject::sender();
|
||||
if (sender == this->ui->pb_SettingsTnServersRemoveServer)
|
||||
{
|
||||
this->getIContextSettings()->value(path, CSettingUtilities::CmdRemove(), CVariant::from(server));
|
||||
serverList.removeIf(&CServer::getName, server.getName());
|
||||
}
|
||||
else if (sender == this->ui->pb_SettingsTnServersSaveServer)
|
||||
{
|
||||
this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), CVariant::from(server));
|
||||
serverList.replaceOrAdd(&CServer::getName, server.getName(), server);
|
||||
}
|
||||
m_trafficNetworkServers.set(serverList);
|
||||
}
|
||||
|
||||
void CSettingsNetworkServersComponent::ps_changedSettings(uint typeValue)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/components/enableforruntime.h"
|
||||
#include "blackcore/settings/network.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
|
||||
@@ -57,6 +58,8 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CSettingsNetworkServersComponent> ui;
|
||||
|
||||
BlackCore::CSetting<BlackCore::Settings::Network::TrafficServers> m_trafficNetworkServers { this };
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user