File indexing completed on 2024-02-18 04:58:18

0001 /**************************************************************************
0002  *   Copyright (C) 2009-2011 Matthias Fuchs <mat69@gmx.net>                *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #include "signaturethread.h"
0021 #include "signature_p.h"
0022 
0023 #include "kget_debug.h"
0024 #include <QDebug>
0025 
0026 SignatureThread::SignatureThread(QObject *parent)
0027     : QThread(parent)
0028     , m_abort(false)
0029 {
0030 }
0031 
0032 SignatureThread::~SignatureThread()
0033 {
0034     m_mutex.lock();
0035     m_abort = true;
0036     m_mutex.unlock();
0037 
0038     wait();
0039 }
0040 
0041 bool SignatureThread::isValid() const
0042 {
0043 #ifdef HAVE_QGPGME
0044     return true;
0045 #else // HAVE_QGPGME
0046     return false;
0047 #endif // HAVE_QGPGME
0048 }
0049 
0050 void SignatureThread::verify(const QUrl &dest, const QByteArray &sig)
0051 {
0052     QMutexLocker locker(&m_mutex);
0053     m_dest.append(dest);
0054     m_sig.append(sig);
0055 
0056     if (!isRunning()) {
0057         start();
0058     }
0059 }
0060 
0061 void SignatureThread::run()
0062 {
0063 #ifdef HAVE_QGPGME
0064     while (!m_abort && m_dest.count()) {
0065         m_mutex.lock();
0066         const QUrl dest = m_dest.takeFirst();
0067         const QByteArray sig = m_sig.takeFirst();
0068         m_mutex.unlock();
0069 
0070         GpgME::VerificationResult result = SignaturePrivate::verify(dest, sig);
0071 
0072         if (!m_abort) {
0073             Q_EMIT verified(result);
0074         }
0075     }
0076 #else // HAVE_QGPGME
0077     qCWarning(KGET_DEBUG) << "No QGPGME support.";
0078 #endif // HAVE_QGPGME
0079 }
0080 
0081 #include "moc_signaturethread.cpp"