Line data Source code
1 : /*
2 : threadedjobmixin.cpp
3 :
4 : This file is part of qgpgme, the Qt API binding for gpgme
5 : Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 : Copyright (c) 2016 Intevation GmbH
7 :
8 : QGpgME is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU General Public License as
10 : published by the Free Software Foundation; either version 2 of the
11 : License, or (at your option) any later version.
12 :
13 : QGpgME is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 :
22 : In addition, as a special exception, the copyright holders give
23 : permission to link the code of this program with any edition of
24 : the Qt library by Trolltech AS, Norway (or with modified versions
25 : of Qt that use the same license as Qt), and distribute linked
26 : combinations including the two. You must obey the GNU General
27 : Public License in all respects for all of the code used other than
28 : Qt. If you modify this file, you may extend this exception to
29 : your version of the file, but you are not obligated to do so. If
30 : you do not wish to do so, delete this exception statement from
31 : your version.
32 : */
33 :
34 : #ifdef HAVE_CONFIG_H
35 : #include "config.h"
36 : #endif
37 :
38 : #include "threadedjobmixin.h"
39 :
40 : #include "dataprovider.h"
41 :
42 : #include "data.h"
43 :
44 : #include <QString>
45 : #include <QStringList>
46 : #include <QByteArray>
47 :
48 :
49 : #include <algorithm>
50 : #include <iterator>
51 :
52 : using namespace QGpgME;
53 : using namespace GpgME;
54 :
55 : static const unsigned int GetAuditLogFlags = Context::AuditLogWithHelp | Context::HtmlAuditLog;
56 :
57 0 : QString _detail::audit_log_as_html(Context *ctx, GpgME::Error &err)
58 : {
59 0 : assert(ctx);
60 0 : QGpgME::QByteArrayDataProvider dp;
61 0 : Data data(&dp);
62 0 : assert(!data.isNull());
63 0 : if ((err = ctx->lastError()) || (err = ctx->getAuditLog(data, GetAuditLogFlags))) {
64 0 : return QString::fromLocal8Bit(err.asString());
65 : }
66 0 : const QByteArray ba = dp.data();
67 0 : return QString::fromUtf8(ba.data(), ba.size());
68 : }
69 :
70 0 : static QList<QByteArray> from_sl(const QStringList &sl)
71 : {
72 0 : QList<QByteArray> result;
73 0 : Q_FOREACH (const QString &str, sl) {
74 0 : result.append(str.toUtf8());
75 : }
76 :
77 : #if 0
78 : std::transform(sl.begin(), sl.end(), std::back_inserter(result),
79 : mem_fn(static_cast<QByteArray()const>(&QString::toUtf8)));
80 : #endif
81 0 : return result;
82 : }
83 :
84 0 : static QList<QByteArray> single(const QByteArray &ba)
85 : {
86 0 : QList<QByteArray> result;
87 0 : result.push_back(ba);
88 0 : return result;
89 : }
90 :
91 0 : _detail::PatternConverter::PatternConverter(const QByteArray &ba)
92 0 : : m_list(single(ba)), m_patterns(0) {}
93 0 : _detail::PatternConverter::PatternConverter(const QString &s)
94 0 : : m_list(single(s.toUtf8())), m_patterns(0) {}
95 0 : _detail::PatternConverter::PatternConverter(const QList<QByteArray> &lba)
96 0 : : m_list(lba), m_patterns(0) {}
97 0 : _detail::PatternConverter::PatternConverter(const QStringList &sl)
98 0 : : m_list(from_sl(sl)), m_patterns(0) {}
99 :
100 0 : const char **_detail::PatternConverter::patterns() const
101 : {
102 0 : if (!m_patterns) {
103 0 : m_patterns = new const char *[ m_list.size() + 1 ];
104 0 : const char **end = std::transform(m_list.begin(), m_list.end(), m_patterns,
105 0 : std::mem_fn(&QByteArray::constData));
106 0 : *end = 0;
107 : }
108 0 : return m_patterns;
109 : }
110 :
111 0 : _detail::PatternConverter::~PatternConverter()
112 : {
113 0 : delete [] m_patterns;
114 0 : }
|