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
This commit is contained in:
parent
7a2a3f317b
commit
c3171d0cf1
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "qgpgme_export.h"
|
#include "qgpgme_export.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace GpgME
|
namespace GpgME
|
||||||
{
|
{
|
||||||
class Error;
|
class Error;
|
||||||
@ -45,4 +47,18 @@ class QDebug;
|
|||||||
|
|
||||||
QGPGME_EXPORT QDebug operator<<(QDebug debug, const GpgME::Error &err);
|
QGPGME_EXPORT QDebug operator<<(QDebug debug, const GpgME::Error &err);
|
||||||
|
|
||||||
|
namespace QGpgME
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Helper to log GpgME objects which provide the output stream operator.
|
||||||
|
*/
|
||||||
|
template<class GpgMEClass>
|
||||||
|
std::string toLogString(const GpgMEClass &object)
|
||||||
|
{
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << object;
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QGPGME_DEBUG_H
|
#endif // QGPGME_DEBUG_H
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
#include <gpgme.h>
|
#include <gpgme.h>
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -56,12 +55,4 @@ std::vector<std::string> toStrings(const QStringList &l);
|
|||||||
|
|
||||||
QStringList toFingerprints(const std::vector<GpgME::Key> &keys);
|
QStringList toFingerprints(const std::vector<GpgME::Key> &keys);
|
||||||
|
|
||||||
template<class Result>
|
|
||||||
std::string toLogString(const Result &result)
|
|
||||||
{
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << result;
|
|
||||||
return stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // __QGPGME_UTIL_H__
|
#endif // __QGPGME_UTIL_H__
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <debug.h>
|
||||||
#include <importjob.h>
|
#include <importjob.h>
|
||||||
#include <importresult.h>
|
#include <importresult.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
@ -44,7 +45,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
GpgME::Protocol guessProtocol(const QString &filename)
|
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();
|
auto job = (protocol == GpgME::CMS ? QGpgME::smime() : QGpgME::openpgp())->importJob();
|
||||||
const auto result = job->exec(keyData);
|
const auto result = job->exec(keyData);
|
||||||
qDebug() << "Result error:" << result.error().asString();
|
qDebug() << "Result error:" << result.error().asString();
|
||||||
std::ostringstream ostr;
|
for (const auto &line : QString::fromStdString(QGpgME::toLogString(result)).split('\n')) {
|
||||||
ostr << result;
|
|
||||||
for (const auto &line : QString::fromStdString(ostr.str()).split('\n')) {
|
|
||||||
qDebug().noquote() << line;
|
qDebug().noquote() << line;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user