LCOV - code coverage report
Current view: top level - lang/qt/src - threadedjobmixin.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 36 69.4 %
Date: 2016-09-12 13:07:23 Functions: 5 9 55.6 %

          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             : #include "threadedjobmixin.h"
      35             : 
      36             : #include "dataprovider.h"
      37             : 
      38             : #include "data.h"
      39             : 
      40             : #include <QString>
      41             : #include <QStringList>
      42             : #include <QByteArray>
      43             : 
      44             : 
      45             : #include <algorithm>
      46             : #include <iterator>
      47             : 
      48             : using namespace QGpgME;
      49             : using namespace GpgME;
      50             : 
      51             : static const unsigned int GetAuditLogFlags = Context::AuditLogWithHelp | Context::HtmlAuditLog;
      52             : 
      53          22 : QString _detail::audit_log_as_html(Context *ctx, GpgME::Error &err)
      54             : {
      55          22 :     assert(ctx);
      56          22 :     QGpgME::QByteArrayDataProvider dp;
      57          44 :     Data data(&dp);
      58          22 :     assert(!data.isNull());
      59          22 :     if ((err = ctx->lastError()) || (err = ctx->getAuditLog(data, GetAuditLogFlags))) {
      60          22 :         return QString::fromLocal8Bit(err.asString());
      61             :     }
      62           0 :     const QByteArray ba = dp.data();
      63          22 :     return QString::fromUtf8(ba.data(), ba.size());
      64             : }
      65             : 
      66          11 : static QList<QByteArray> from_sl(const QStringList &sl)
      67             : {
      68          11 :     QList<QByteArray> result;
      69          22 :     Q_FOREACH (const QString &str, sl) {
      70          11 :         result.append(str.toUtf8());
      71          11 :     }
      72             : 
      73             : #if 0
      74             :     std::transform(sl.begin(), sl.end(), std::back_inserter(result),
      75             :                    mem_fn(static_cast<QByteArray()const>(&QString::toUtf8)));
      76             : #endif
      77          11 :     return result;
      78             : }
      79             : 
      80           0 : static QList<QByteArray> single(const QByteArray &ba)
      81             : {
      82           0 :     QList<QByteArray> result;
      83           0 :     result.push_back(ba);
      84           0 :     return result;
      85             : }
      86             : 
      87           0 : _detail::PatternConverter::PatternConverter(const QByteArray &ba)
      88           0 :     : m_list(single(ba)), m_patterns(0) {}
      89           0 : _detail::PatternConverter::PatternConverter(const QString &s)
      90           0 :     : m_list(single(s.toUtf8())), m_patterns(0) {}
      91           0 : _detail::PatternConverter::PatternConverter(const QList<QByteArray> &lba)
      92           0 :     : m_list(lba), m_patterns(0) {}
      93          11 : _detail::PatternConverter::PatternConverter(const QStringList &sl)
      94          11 :     :  m_list(from_sl(sl)), m_patterns(0) {}
      95             : 
      96          11 : const char **_detail::PatternConverter::patterns() const
      97             : {
      98          11 :     if (!m_patterns) {
      99          11 :         m_patterns = new const char *[ m_list.size() + 1 ];
     100             :         const char **end = std::transform(m_list.begin(), m_list.end(), m_patterns,
     101          11 :                                           std::mem_fn(&QByteArray::constData));
     102          11 :         *end = 0;
     103             :     }
     104          11 :     return m_patterns;
     105             : }
     106             : 
     107          22 : _detail::PatternConverter::~PatternConverter()
     108             : {
     109          11 :     delete [] m_patterns;
     110          11 : }

Generated by: LCOV version 1.11