mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Update xswiftbus.conf when updating connection details
ref T434
This commit is contained in:
committed by
Klaus Basan
parent
e6981d9c28
commit
2843e20d54
@@ -11,11 +11,13 @@
|
||||
#include "ui_settingsxswiftbuscomponent.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/simulation/xplane/xswiftbusconfigwriter.h"
|
||||
|
||||
#include <QComboBox>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation::Settings;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -57,6 +59,9 @@ namespace BlackGui
|
||||
if (dBusAddress != m_xSwiftBusServerSetting.getThreadLocal())
|
||||
{
|
||||
const CStatusMessage msg = m_xSwiftBusServerSetting.setAndSave(dBusAddress);
|
||||
CXSwiftBusConfigWriter xswiftbusConfigWriter;
|
||||
xswiftbusConfigWriter.setDBusAddress(dBusAddress);
|
||||
xswiftbusConfigWriter.updateInAllXPlaneVersions();
|
||||
CLogMessage::preformatted(msg);
|
||||
}
|
||||
}
|
||||
|
||||
85
src/blackmisc/simulation/xplane/xswiftbusconfigwriter.cpp
Normal file
85
src/blackmisc/simulation/xplane/xswiftbusconfigwriter.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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
|
||||
|
||||
#include "blackmisc/simulation/xplane/xswiftbusconfigwriter.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace XPlane
|
||||
{
|
||||
CXSwiftBusConfigWriter::CXSwiftBusConfigWriter(QObject *parent) : QObject(parent)
|
||||
{ }
|
||||
|
||||
void CXSwiftBusConfigWriter::setDBusAddress(const QString &dBusAddress)
|
||||
{
|
||||
if (CDBusServer::isSessionOrSystemAddress(dBusAddress)) { m_dbusMode = "session"; }
|
||||
else { m_dbusMode = "p2p"; }
|
||||
|
||||
if (m_dbusMode == "p2p")
|
||||
{
|
||||
CDBusServer::dBusAddressToHostAndPort(dBusAddress, m_dbusAddress, m_dbusPort);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CXSwiftBusConfigWriter::updateInAllXPlaneVersions()
|
||||
{
|
||||
updateInXPlane9();
|
||||
updateInXPlane10();
|
||||
updateInXPlane11();
|
||||
}
|
||||
|
||||
void CXSwiftBusConfigWriter::updateInXPlane9()
|
||||
{
|
||||
QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane9Dir());
|
||||
if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CXSwiftBusConfigWriter::updateInXPlane10()
|
||||
{
|
||||
QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane10Dir());
|
||||
if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CXSwiftBusConfigWriter::updateInXPlane11()
|
||||
{
|
||||
QString path = CXPlaneUtil::xswiftbusPluginDir(CXPlaneUtil::xplane11Dir());
|
||||
if (!path.isEmpty()) { writeTo(path); }
|
||||
}
|
||||
|
||||
void CXSwiftBusConfigWriter::writeTo(const QString &filePath)
|
||||
{
|
||||
QString configFilePath = filePath + "/xswiftbus.conf";
|
||||
QFile configFile(configFilePath);
|
||||
configFile.remove();
|
||||
if (configFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QTextStream ts(&configFile);
|
||||
ts << "# DBus Mode - Options: p2p, session" << endl;
|
||||
ts << "dbusMode = " << m_dbusMode << endl;
|
||||
ts << endl;
|
||||
ts << "# DBus server address - relevant for P2P mode only" << endl;
|
||||
ts << "dbusAddress = " << m_dbusAddress << endl;
|
||||
ts << endl;
|
||||
ts << "# DBus server port - relevant for P2P mode only" << endl;
|
||||
ts << "dbusPort = " << m_dbusPort << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
src/blackmisc/simulation/xplane/xswiftbusconfigwriter.h
Normal file
61
src/blackmisc/simulation/xplane/xswiftbusconfigwriter.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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 BLACKMISC_SIMULATION_XPLANE_XSWIFTBUSCONFIGWRITER_H
|
||||
#define BLACKMISC_SIMULATION_XPLANE_XSWIFTBUSCONFIGWRITER_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace XPlane
|
||||
{
|
||||
//! XSwiftBus configuration file writer
|
||||
class BLACKMISC_EXPORT CXSwiftBusConfigWriter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Default constructor.
|
||||
CXSwiftBusConfigWriter(QObject *parent = nullptr);
|
||||
|
||||
//! Set new DBus address
|
||||
void setDBusAddress(const QString &dBusAddress);
|
||||
|
||||
//! Update xswiftbus.conf in all known X-Plane versions (XP9 - XP11 are supported)
|
||||
void updateInAllXPlaneVersions();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 9
|
||||
void updateInXPlane9();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 10
|
||||
void updateInXPlane10();
|
||||
|
||||
//! Update xswiftbus.conf in X-Plane 11
|
||||
void updateInXPlane11();
|
||||
|
||||
//! Write new xswiftbus.conf to filePath. Existing files are removed.
|
||||
void writeTo(const QString &filePath);
|
||||
|
||||
private:
|
||||
QString m_dbusMode = "p2p";
|
||||
QString m_dbusAddress = "127.0.0.1";
|
||||
QString m_dbusPort = "45001";
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -10,12 +10,14 @@
|
||||
#include "simulatorxplaneconfigwindow.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "ui_simulatorxplaneconfigwindow.h"
|
||||
#include "blackmisc/simulation/xplane/xswiftbusconfigwriter.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation::XPlane;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
@@ -39,9 +41,13 @@ namespace BlackSimPlugin
|
||||
void CSimulatorXPlaneConfigWindow::onSettingsAccepted()
|
||||
{
|
||||
const QString currentAddress = m_xswiftbusServerSetting.getThreadLocal();
|
||||
const QString updatedAddress = ui->comp_SettingsXSwiftBus->getDBusAddress();
|
||||
if (currentAddress != ui->comp_SettingsXSwiftBus->getDBusAddress())
|
||||
{
|
||||
m_xswiftbusServerSetting.set(ui->comp_SettingsXSwiftBus->getDBusAddress());
|
||||
m_xswiftbusServerSetting.set(updatedAddress);
|
||||
CXSwiftBusConfigWriter xswiftbusConfigWriter;
|
||||
xswiftbusConfigWriter.setDBusAddress(updatedAddress);
|
||||
xswiftbusConfigWriter.updateInAllXPlaneVersions();
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user