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:
Klaus Basan
2014-04-14 12:30:29 +02:00
parent 17a6607781
commit d58be30600
7 changed files with 85 additions and 4 deletions

View File

@@ -2,7 +2,9 @@
#include "mainwindow.h"
#include "guimodeenums.h"
#include "blackcore/context_runtime_config.h"
#include "blacksim/blacksimfreefunctions.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <QtGlobal>
#include <QApplication>
#include <QMessageBox>
@@ -20,6 +22,7 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(blackgui);
BlackMisc::initResources();
BlackMisc::registerMetadata();
BlackSim::registerMetadata();
// BlackMisc::displayAllUserMetatypesTypes();
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm");

View File

@@ -5,6 +5,7 @@
#include "blackcore/context_network.h"
#include "blackmisc/hwkeyboardkey.h"
#include "blackmisc/networkutils.h"
#include "blacksim/fsx/fsxsimulatorsetup.h"
#include "blacksim/fsx/simconnectutilities.h"
using namespace BlackCore;
@@ -184,6 +185,7 @@ void MainWindow::testSimConnectConnection()
void MainWindow::saveSimConnectCfg()
{
if (!this->m_rt->getIContextSimulator()) return;
QString address = this->ui->le_SettingsSimulatorFsxAddress->text().trimmed();
QString port = this->ui->le_SettingsSimulatorFsxPort->text().trimmed();
@@ -203,15 +205,21 @@ void MainWindow::saveSimConnectCfg()
return;
}
quint16 p = port.toUInt();
QString file = CSimConnectUtilities::getLocalSimConnectCfgFilename();
if (CSimConnectUtilities::writeSimConnectCfg(file, address, p))
QString fileName = this->m_rt->getIContextSimulator()->getSimulatorInfo().getSimulatorSetupValueAsString(CFsxSimulatorSetup::SetupSimConnectCfgFile);
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));
}
else
{
QString m = QString("Cannot write ").append(file);
QString m = QString("Cannot write ").append(fileName);
this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, m));
}
}

View File

@@ -111,6 +111,12 @@ namespace BlackCore
//! A component has changed its state
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;
};
}

View File

@@ -7,6 +7,7 @@
#include "context_runtime.h"
#include "blackmisc/settingutilities.h"
#include <QtMsgHandler>
#include <QFile>
using namespace BlackMisc;
@@ -48,7 +49,43 @@ namespace BlackCore
*/
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);
}
/*
* 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

View File

@@ -36,6 +36,12 @@ namespace BlackCore
//! \copydoc IContextApplication::notifyAboutComponentChange
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:
//! Constructor
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);

View File

@@ -70,4 +70,19 @@ namespace BlackCore
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

View File

@@ -37,6 +37,12 @@ namespace BlackCore
//! \copydoc IContextApplication::notifyAboutComponentChange
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:
//! Constructor
CContextApplicationProxy(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplicationBase(mode, runtime), m_dBusInterface(nullptr) {}