File indexing completed on 2025-01-05 04:37:09

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef BTDATACHECKER_H
0007 #define BTDATACHECKER_H
0008 
0009 #include <QObject>
0010 #include <ktorrent_export.h>
0011 #include <util/bitset.h>
0012 
0013 class QString;
0014 
0015 namespace bt
0016 {
0017 class Torrent;
0018 
0019 /**
0020  * @author Joris Guisson
0021  *
0022  * Checks which data is downloaded, given a torrent and a file or directory containing
0023  * files of the torrent.
0024  */
0025 class KTORRENT_EXPORT DataChecker : public QObject
0026 {
0027     Q_OBJECT
0028 public:
0029     DataChecker(bt::Uint32 from, bt::Uint32 to);
0030     ~DataChecker() override;
0031 
0032     /**
0033      * Check to see which chunks have been downloaded of a torrent, and which chunks fail.
0034      * The corresponding bitsets should be filled with this information.
0035      * If anything goes wrong and Error should be thrown.
0036      * @param path path to the file or dir (this needs to end with the name suggestion of the torrent)
0037      * @param tor The torrent
0038      * @param dnddir DND dir, optional argument if we know this
0039      * @param current_status Current status of the torrent
0040      */
0041     virtual void check(const QString &path, const Torrent &tor, const QString &dnddir, const BitSet &current_status) = 0;
0042 
0043     /**
0044      * Get the BitSet representing all the downloaded chunks and which is the result of the data check.
0045      */
0046     const BitSet &getResult() const
0047     {
0048         return result;
0049     }
0050 
0051     /// Stop an ongoing check
0052     void stop()
0053     {
0054         need_to_stop = true;
0055     }
0056 
0057 Q_SIGNALS:
0058     /**
0059      * Emitted when a chunk has been proccessed.
0060      * @param num The number processed
0061      * @param total The total number of pieces to process
0062      */
0063     void progress(quint32 num, quint32 total);
0064 
0065     /**
0066      * Emitted when a failed or dowloaded chunk is found.
0067      * @param num_failed The number of failed chunks
0068      * @param num_found The number of found chunks
0069      * @param num_downloaded Number of downloaded chunks
0070      * @param num_not_downloaded Number of not downloaded chunks
0071      */
0072     void status(quint32 num_failed, quint32 num_found, quint32 num_downloaded, quint32 num_not_downloaded);
0073 
0074 protected:
0075     BitSet result;
0076     Uint32 failed, found, downloaded, not_downloaded;
0077     bool need_to_stop;
0078     bt::Uint32 from;
0079     bt::Uint32 to;
0080 };
0081 
0082 }
0083 
0084 #endif