File indexing completed on 2024-04-14 04:52:02

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 #ifndef VERIFICATION_THREAD_H
0021 #define VERIFICATION_THREAD_H
0022 
0023 #include <QUrl>
0024 #include <kio/global.h>
0025 
0026 #include <QMutex>
0027 #include <QThread>
0028 
0029 class VerificationThread : public QThread
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     VerificationThread(QObject *parent = nullptr);
0035     ~VerificationThread() override;
0036 
0037     void verify(const QString &type, const QString &checksum, const QUrl &file);
0038 
0039     void findBrokenPieces(const QString &type, const QList<QString> checksums, KIO::filesize_t length, const QUrl &file);
0040 
0041 private:
0042     enum WorkType { Nothing, Verify, BrokenPieces };
0043 
0044     void doVerify();
0045     void doBrokenPieces();
0046 
0047 Q_SIGNALS:
0048     /**
0049      * Emitted when the verification of a file finishes, connect to this signal
0050      * if you do the verification for one file only and do not want to bother with
0051      * file and type
0052      */
0053     void verified(bool verified);
0054 
0055     void verified(const QString &type, bool verified, const QUrl &file);
0056 
0057     void brokenPieces(const QList<KIO::fileoffset_t> &offsets, KIO::filesize_t length);
0058 
0059 protected:
0060     void run() override;
0061 
0062 private:
0063     QMutex m_mutex;
0064     bool m_abort;
0065     QStringList m_types;
0066     QStringList m_checksums;
0067     QList<QUrl> m_files;
0068     KIO::filesize_t m_length;
0069     WorkType m_type;
0070 };
0071 
0072 #endif