mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +08:00
refs #209, added remove file method to application context and some finetuning of the file methods
This commit is contained in:
@@ -117,6 +117,10 @@ namespace BlackCore
|
|||||||
|
|
||||||
//! Remote enable version of reading a text file
|
//! Remote enable version of reading a text file
|
||||||
virtual QString readFromFile(const QString &fileName) = 0;
|
virtual QString readFromFile(const QString &fileName) = 0;
|
||||||
|
|
||||||
|
//! Remote enable version of deleting a file
|
||||||
|
virtual bool removeFile(const QString &fileName) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ namespace BlackCore
|
|||||||
bool CContextApplication::writeToFile(const QString &fileName, const QString &content)
|
bool CContextApplication::writeToFile(const QString &fileName, const QString &content)
|
||||||
{
|
{
|
||||||
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName, content.left(25));
|
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName, content.left(25));
|
||||||
|
if (fileName.isEmpty()) return false;
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text)))
|
||||||
@@ -78,6 +79,7 @@ namespace BlackCore
|
|||||||
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName);
|
if (this->getRuntime()->isSlotLogForApplicationEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, fileName);
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
QString content;
|
QString content;
|
||||||
|
if (fileName.isEmpty()) return content;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
if ((success = file.open(QIODevice::ReadOnly | QIODevice::Text)))
|
if ((success = file.open(QIODevice::ReadOnly | QIODevice::Text)))
|
||||||
{
|
{
|
||||||
@@ -88,4 +90,10 @@ namespace BlackCore
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CContextApplication::removeFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
if (fileName.isEmpty()) return false;
|
||||||
|
return QFile::remove(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextApplication::readFromFile
|
//! \copydoc IContextApplication::readFromFile
|
||||||
virtual QString readFromFile(const QString &fileName) override;
|
virtual QString readFromFile(const QString &fileName) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::removeFile
|
||||||
|
virtual bool removeFile(const QString &fileName) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content)
|
bool CContextApplicationProxy::writeToFile(const QString &fileName, const QString &content)
|
||||||
{
|
{
|
||||||
|
if (fileName.isEmpty()) return false;
|
||||||
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("writeToFile"), fileName, content);
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("writeToFile"), fileName, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,16 @@ namespace BlackCore
|
|||||||
*/
|
*/
|
||||||
QString CContextApplicationProxy::readFromFile(const QString &fileName)
|
QString CContextApplicationProxy::readFromFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
|
if (fileName.isEmpty()) return "";
|
||||||
return this->m_dBusInterface->callDBusRet<QString>(QLatin1Literal("readFromFile"), fileName);
|
return this->m_dBusInterface->callDBusRet<QString>(QLatin1Literal("readFromFile"), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Delete file
|
||||||
|
*/
|
||||||
|
bool CContextApplicationProxy::removeFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
if (fileName.isEmpty()) return false;
|
||||||
|
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("deleteFile"), fileName);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextApplication::readFromFile
|
//! \copydoc IContextApplication::readFromFile
|
||||||
virtual QString readFromFile(const QString &fileName) override;
|
virtual QString readFromFile(const QString &fileName) override;
|
||||||
|
|
||||||
|
//! \copydoc IContextApplication::removeFile
|
||||||
|
virtual bool removeFile(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