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

0001 /*
0002     SPDX-FileCopyrightText: 2009 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef BT_JOB_H
0008 #define BT_JOB_H
0009 
0010 #include "torrentstats.h"
0011 #include <KIO/Job>
0012 #include <ktorrent_export.h>
0013 
0014 class KJobTrackerInterface;
0015 
0016 namespace bt
0017 {
0018 class TorrentControl;
0019 
0020 /**
0021     A Job is a KIO::Job which runs on a torrent
0022 */
0023 class KTORRENT_EXPORT Job : public KIO::Job
0024 {
0025     Q_OBJECT
0026 public:
0027     Job(bool stop_torrent, TorrentControl *tc);
0028     ~Job() override;
0029 
0030     /// Do we need to stop the torrent when the job is running
0031     bool stopTorrent() const
0032     {
0033         return stop_torrent;
0034     }
0035 
0036     void start() override;
0037     virtual void kill(bool quietly = true);
0038 
0039     /// Return the status of the torrent during the job (default implementation returns INVALID_STATUS)
0040     virtual TorrentStatus torrentStatus() const;
0041 
0042     /// Get the torrent associated with this job
0043     TorrentControl *torrent()
0044     {
0045         return tc;
0046     }
0047 
0048     /// Set the torrent associated with this job
0049     void setTorrent(TorrentControl *t)
0050     {
0051         tc = t;
0052     }
0053 
0054     /// Set the job tracker
0055     static void setJobTracker(KJobTrackerInterface *trk);
0056 
0057 protected:
0058     /// Register the job with the tracker
0059     void registerWithTracker();
0060 
0061 private:
0062     TorrentControl *tc;
0063     bool stop_torrent;
0064 
0065     static KJobTrackerInterface *tracker;
0066 };
0067 
0068 }
0069 
0070 #endif // BT_JOB_H