From c3171d0cf1a249618f0763fe141ab84d8a4be240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Tue, 15 Aug 2023 11:56:40 +0200 Subject: [PATCH] qt: Make toLogString helper public * lang/qt/src/util.h: Move toLogString ... * lang/qt/src/debug.h: ... here. * lang/qt/tests/run-importjob.cpp (main): Use toLogString. -- This allows using the helper in dependent projects without duplicating it everywhere. GnuPG-bug-id: 6584 --- lang/qt/src/debug.h | 16 ++++++++++++++++ lang/qt/src/util.h | 9 --------- lang/qt/tests/run-importjob.cpp | 6 ++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lang/qt/src/debug.h b/lang/qt/src/debug.h index 791726ca..03894768 100644 --- a/lang/qt/src/debug.h +++ b/lang/qt/src/debug.h @@ -36,6 +36,8 @@ #include "qgpgme_export.h" +#include + namespace GpgME { class Error; @@ -45,4 +47,18 @@ class QDebug; QGPGME_EXPORT QDebug operator<<(QDebug debug, const GpgME::Error &err); +namespace QGpgME +{ +/** + * Helper to log GpgME objects which provide the output stream operator. + */ +template +std::string toLogString(const GpgMEClass &object) +{ + std::stringstream stream; + stream << object; + return stream.str(); +} +} + #endif // QGPGME_DEBUG_H diff --git a/lang/qt/src/util.h b/lang/qt/src/util.h index 475d477b..626de3df 100644 --- a/lang/qt/src/util.h +++ b/lang/qt/src/util.h @@ -38,7 +38,6 @@ #include -#include #include #include @@ -56,12 +55,4 @@ std::vector toStrings(const QStringList &l); QStringList toFingerprints(const std::vector &keys); -template -std::string toLogString(const Result &result) -{ - std::stringstream stream; - stream << result; - return stream.str(); -} - #endif // __QGPGME_UTIL_H__ diff --git a/lang/qt/tests/run-importjob.cpp b/lang/qt/tests/run-importjob.cpp index b1814fa0..0ae92b09 100644 --- a/lang/qt/tests/run-importjob.cpp +++ b/lang/qt/tests/run-importjob.cpp @@ -34,6 +34,7 @@ #include "config.h" #endif +#include #include #include #include @@ -44,7 +45,6 @@ #include #include -#include GpgME::Protocol guessProtocol(const QString &filename) { @@ -90,9 +90,7 @@ int main(int argc, char **argv) auto job = (protocol == GpgME::CMS ? QGpgME::smime() : QGpgME::openpgp())->importJob(); const auto result = job->exec(keyData); qDebug() << "Result error:" << result.error().asString(); - std::ostringstream ostr; - ostr << result; - for (const auto &line : QString::fromStdString(ostr.str()).split('\n')) { + for (const auto &line : QString::fromStdString(QGpgME::toLogString(result)).split('\n')) { qDebug().noquote() << line; } return 0;