mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #207, added remote file read/write
* write simconnect.cfg either local or remote * update in GUI to use new methods
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "guimodeenums.h"
|
#include "guimodeenums.h"
|
||||||
#include "blackcore/context_runtime_config.h"
|
#include "blackcore/context_runtime_config.h"
|
||||||
|
#include "blacksim/blacksimfreefunctions.h"
|
||||||
#include "blackmisc/blackmiscfreefunctions.h"
|
#include "blackmisc/blackmiscfreefunctions.h"
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -20,6 +22,7 @@ int main(int argc, char *argv[])
|
|||||||
Q_INIT_RESOURCE(blackgui);
|
Q_INIT_RESOURCE(blackgui);
|
||||||
BlackMisc::initResources();
|
BlackMisc::initResources();
|
||||||
BlackMisc::registerMetadata();
|
BlackMisc::registerMetadata();
|
||||||
|
BlackSim::registerMetadata();
|
||||||
// BlackMisc::displayAllUserMetatypesTypes();
|
// BlackMisc::displayAllUserMetatypesTypes();
|
||||||
|
|
||||||
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm");
|
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "blackcore/context_network.h"
|
#include "blackcore/context_network.h"
|
||||||
#include "blackmisc/hwkeyboardkey.h"
|
#include "blackmisc/hwkeyboardkey.h"
|
||||||
#include "blackmisc/networkutils.h"
|
#include "blackmisc/networkutils.h"
|
||||||
|
#include "blacksim/fsx/fsxsimulatorsetup.h"
|
||||||
#include "blacksim/fsx/simconnectutilities.h"
|
#include "blacksim/fsx/simconnectutilities.h"
|
||||||
|
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
@@ -184,6 +185,7 @@ void MainWindow::testSimConnectConnection()
|
|||||||
|
|
||||||
void MainWindow::saveSimConnectCfg()
|
void MainWindow::saveSimConnectCfg()
|
||||||
{
|
{
|
||||||
|
if (!this->m_rt->getIContextSimulator()) return;
|
||||||
QString address = this->ui->le_SettingsSimulatorFsxAddress->text().trimmed();
|
QString address = this->ui->le_SettingsSimulatorFsxAddress->text().trimmed();
|
||||||
QString port = this->ui->le_SettingsSimulatorFsxPort->text().trimmed();
|
QString port = this->ui->le_SettingsSimulatorFsxPort->text().trimmed();
|
||||||
|
|
||||||
@@ -203,15 +205,21 @@ void MainWindow::saveSimConnectCfg()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
quint16 p = port.toUInt();
|
quint16 p = port.toUInt();
|
||||||
QString file = CSimConnectUtilities::getLocalSimConnectCfgFilename();
|
QString fileName = this->m_rt->getIContextSimulator()->getSimulatorInfo().getSimulatorSetupValueAsString(CFsxSimulatorSetup::SetupSimConnectCfgFile);
|
||||||
if (CSimConnectUtilities::writeSimConnectCfg(file, address, p))
|
Q_ASSERT(!fileName.isEmpty());
|
||||||
|
// write either local or remote file
|
||||||
|
bool local = this->m_rt->getIContextSimulator()->usingLocalObjects();
|
||||||
|
bool success = local ?
|
||||||
|
BlackSim::Fsx::CSimConnectUtilities::writeSimConnectCfg(fileName, address, p) :
|
||||||
|
this->m_rt->getIContextApplication()->writeToFile(fileName, CSimConnectUtilities::simConnectCfg(address, p));
|
||||||
|
if (success)
|
||||||
{
|
{
|
||||||
QString m = QString("Written ").append(file);
|
QString m = QString("Written ").append(local ? " local " : "remote ").append(fileName);
|
||||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m));
|
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityInfo, m));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QString m = QString("Cannot write ").append(file);
|
QString m = QString("Cannot write ").append(fileName);
|
||||||
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, m));
|
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,12 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! A component has changed its state
|
//! A component has changed its state
|
||||||
virtual void notifyAboutComponentChange(uint component, uint action) = 0;
|
virtual void notifyAboutComponentChange(uint component, uint action) = 0;
|
||||||
|
|
||||||
|
//! Remote enable version of writing a text file
|
||||||
|
virtual bool writeToFile(const QString &fileName, const QString &content) = 0;
|
||||||
|
|
||||||
|
//! Remote enable version of reading a text file
|
||||||
|
virtual QString readFromFile(const QString &fileName) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "context_runtime.h"
|
#include "context_runtime.h"
|
||||||
#include "blackmisc/settingutilities.h"
|
#include "blackmisc/settingutilities.h"
|
||||||
#include <QtMsgHandler>
|
#include <QtMsgHandler>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
|
||||||
@@ -48,7 +49,43 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
void CContextApplication::notifyAboutComponentChange(uint component, uint action)
|
void CContextApplication::notifyAboutComponentChange(uint component, uint action)
|
||||||
{
|
{
|
||||||
|
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, QString::number(component), QString::number(action));
|
||||||
this->componentChanged(component, action);
|
this->componentChanged(component, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String to file
|
||||||
|
*/
|
||||||
|
bool CContextApplication::writeToFile(const QString &fileName, const QString &content)
|
||||||
|
{
|
||||||
|
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName, content.left(25));
|
||||||
|
QFile file(fileName);
|
||||||
|
bool success = false;
|
||||||
|
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
||||||
|
{
|
||||||
|
QTextStream out(&file);
|
||||||
|
out << content;
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* File to string
|
||||||
|
*/
|
||||||
|
QString CContextApplication::readFromFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName);
|
||||||
|
QFile file(fileName);
|
||||||
|
QString content;
|
||||||
|
bool success = false;
|
||||||
|
if ((success = file.open(QIODevice::ReadOnly | QIODevice::Text)))
|
||||||
|
{
|
||||||
|
QTextStream in(&file);
|
||||||
|
in >> content;
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextApplication::notifyAboutComponentChange
|
//! \copydoc IContextApplication::notifyAboutComponentChange
|
||||||
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::writeToFile
|
||||||
|
virtual bool writeToFile(const QString &fileName, const QString &content) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::readFromFile
|
||||||
|
virtual QString readFromFile(const QString &fileName) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||||
|
|||||||
@@ -70,4 +70,19 @@ namespace BlackCore
|
|||||||
this->m_dBusInterface->callDBus(QLatin1Literal("notifyAboutComponentChange"), component, action);
|
this->m_dBusInterface->callDBus(QLatin1Literal("notifyAboutComponentChange"), component, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To file
|
||||||
|
*/
|
||||||
|
bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content)
|
||||||
|
{
|
||||||
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("writeToFile"), fileName, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From file
|
||||||
|
*/
|
||||||
|
QString CContextApplicationProxy::readFromFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
return this->m_dBusInterface->callDBusRet<QString>(QLatin1Literal("readFromFile"), fileName);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextApplication::notifyAboutComponentChange
|
//! \copydoc IContextApplication::notifyAboutComponentChange
|
||||||
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
virtual void notifyAboutComponentChange(uint component, uint action) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::writeToFile
|
||||||
|
virtual bool writeToFile(const QString &fileName, const QString &content) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::readFromFile
|
||||||
|
virtual QString readFromFile(const QString &fileName) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CContextApplicationProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplicationBase(mode, runtime), m_dBusInterface(nullptr) {}
|
CContextApplicationProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplicationBase(mode, runtime), m_dBusInterface(nullptr) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user