Ref T401, crash info can be saved as file

This commit is contained in:
Klaus Basan
2019-02-20 20:19:49 +01:00
committed by Mat Sutcliffe
parent 10fff29f97
commit df3ac2b02d
3 changed files with 41 additions and 3 deletions

View File

@@ -8,6 +8,9 @@
*/
#include "blackmisc/crashinfo.h"
#include "fileutils.h"
#include <QFile>
#include <QStringBuilder>
namespace BlackMisc
@@ -27,6 +30,11 @@ namespace BlackMisc
m_info += u' ' % extraInfo;
}
void CCrashInfo::setLogPathAndFileName(const QString &fileName)
{
m_logFileAndPath = fileName;
}
CVariant CCrashInfo::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
@@ -69,4 +77,18 @@ namespace BlackMisc
default: return CValueObject::comparePropertyByIndex(index.copyFrontRemoved(), compareValue);
}
}
void CCrashInfo::triggerWritingFile()
{
if (m_logFileAndPath.isEmpty()) { return; }
CFileUtils::writeStringToFileInBackground(summary(), m_logFileAndPath);
}
QString CCrashInfo::summary() const
{
return (m_userName.isEmpty() ? QStringLiteral("") : u"user name: " % m_userName % u"\n") %
(m_simulatorString.isEmpty() ? QStringLiteral("") : u"simulator: " % m_simulatorString % u"\n") %
(m_flightNetwork.isEmpty() ? QStringLiteral("") : u"network: " % m_flightNetwork % u"\n") %
(m_info.isEmpty() ? QStringLiteral("") : u"info: " % m_info % u"\n");
}
} // ns

View File

@@ -41,6 +41,9 @@ namespace BlackMisc
//! User name
void setUserName(const QString &userName) { m_userName = userName; }
//! Any info available?
bool hasInfo() const { return !m_info.isEmpty(); }
//! Get the info
const QString &getInfo() const { return m_info; }
@@ -62,6 +65,9 @@ namespace BlackMisc
//! Append some info
void appendInfo(const QString &extraInfo);
//! Set path and file name
void setLogPathAndFileName(const QString &fileName);
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
@@ -74,16 +80,26 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
int comparePropertyByIndex(const CPropertyIndex &index, const CCrashInfo &compareValue) const;
//! Trigger writing this to file
void triggerWritingFile();
//! Summary
QString summary() const;
private:
QString m_userName;
QString m_info;
QString m_simulatorString;
QString m_flightNetwork;
QString m_logFileAndPath;
BLACK_METACLASS(
CCrashInfo,
BLACK_METAMEMBER(userName),
BLACK_METAMEMBER(info)
BLACK_METAMEMBER(info),
BLACK_METAMEMBER(simulatorString),
BLACK_METAMEMBER(flightNetwork),
BLACK_METAMEMBER(logFileAndPath)
);
};
} // ns

View File

@@ -102,9 +102,9 @@ namespace BlackMisc
bool CFileUtils::writeStringToFileInBackground(const QString &content, const QString &fileNameAndPath)
{
if (fileNameAndPath.isEmpty()) { return false; }
CWorker *worker = BlackMisc::CWorker::fromTask(QCoreApplication::instance(), "writeStringToFileInBackground", [content, fileNameAndPath]()
CWorker *worker = CWorker::fromTask(QCoreApplication::instance(), "writeStringToFileInBackground", [content, fileNameAndPath]()
{
bool s = CFileUtils::writeStringToFile(content, fileNameAndPath);
const bool s = CFileUtils::writeStringToFile(content, fileNameAndPath);
Q_UNUSED(s);
});
return worker ? true : false;