From df3ac2b02de618522defc1c41109edbf89ee3d99 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 20 Feb 2019 20:19:49 +0100 Subject: [PATCH] Ref T401, crash info can be saved as file --- src/blackmisc/crashinfo.cpp | 22 ++++++++++++++++++++++ src/blackmisc/crashinfo.h | 18 +++++++++++++++++- src/blackmisc/fileutils.cpp | 4 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/crashinfo.cpp b/src/blackmisc/crashinfo.cpp index 950d1795e..b0503d2b7 100644 --- a/src/blackmisc/crashinfo.cpp +++ b/src/blackmisc/crashinfo.cpp @@ -8,6 +8,9 @@ */ #include "blackmisc/crashinfo.h" +#include "fileutils.h" + +#include #include 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 diff --git a/src/blackmisc/crashinfo.h b/src/blackmisc/crashinfo.h index 9c9fae188..9021e5686 100644 --- a/src/blackmisc/crashinfo.h +++ b/src/blackmisc/crashinfo.h @@ -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 diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index b009a968d..08fad28ea 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -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;