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

@@ -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) {}