Enable customizing the save statistics time interval
[qBittorrent.git] / src / base / bittorrent / torrentcreator.h
blobe4377a57328c5cb7763831ae86d2bc11ce5b962b
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2024 Radu Carpa <radu.carpa@cern.ch>
5 * Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #pragma once
33 #include <atomic>
35 #include <QObject>
36 #include <QRunnable>
37 #include <QStringList>
39 #include "base/path.h"
41 namespace BitTorrent
43 #ifdef QBT_USES_LIBTORRENT2
44 enum class TorrentFormat
46 V1,
47 V2,
48 Hybrid
50 #endif
52 struct TorrentCreatorParams
54 bool isPrivate = false;
55 #ifdef QBT_USES_LIBTORRENT2
56 TorrentFormat torrentFormat = TorrentFormat::Hybrid;
57 #else
58 bool isAlignmentOptimized = false;
59 int paddedFileSizeLimit = 0;
60 #endif
61 int pieceSize = 0;
62 Path sourcePath;
63 Path torrentFilePath;
64 QString comment;
65 QString source;
66 QStringList trackers;
67 QStringList urlSeeds;
70 struct TorrentCreatorResult
72 Path torrentFilePath;
73 Path savePath;
74 int pieceSize;
77 class TorrentCreator final : public QObject, public QRunnable
79 Q_OBJECT
80 Q_DISABLE_COPY_MOVE(TorrentCreator)
82 public:
83 explicit TorrentCreator(const TorrentCreatorParams &params, QObject *parent = nullptr);
85 const TorrentCreatorParams &params() const;
86 bool isInterruptionRequested() const;
88 void run() override;
90 #ifdef QBT_USES_LIBTORRENT2
91 static int calculateTotalPieces(const Path &inputPath, int pieceSize, TorrentFormat torrentFormat);
92 #else
93 static int calculateTotalPieces(const Path &inputPath, const int pieceSize
94 , const bool isAlignmentOptimized, int paddedFileSizeLimit);
95 #endif
97 public slots:
98 void requestInterruption();
100 signals:
101 void started();
102 void creationFailure(const QString &msg);
103 void creationSuccess(const TorrentCreatorResult &result);
104 void progressUpdated(int progress);
106 private:
107 void sendProgressSignal(int currentPieceIdx, int totalPieces);
108 void checkInterruptionRequested() const;
110 TorrentCreatorParams m_params;
111 std::atomic_bool m_interruptionRequested;