qBittorrent
torrentinfo.h
Go to the documentation of this file.
1 /*
2  * Bittorrent Client using Qt and libtorrent.
3  * Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * In addition, as a special exception, the copyright holders give permission to
20  * link this program with the OpenSSL project's "OpenSSL" library (or with
21  * modified versions of it that use the same license as the "OpenSSL" library),
22  * and distribute the linked executables. You must obey the GNU General Public
23  * License in all respects for all of the code used other than "OpenSSL". If you
24  * modify file(s), you may extend this exception to your version of the file(s),
25  * but you are not obligated to do so. If you do not wish to do so, delete this
26  * exception statement from your version.
27  */
28 
29 #pragma once
30 
31 #include <libtorrent/torrent_info.hpp>
32 
33 #include <QCoreApplication>
34 #include <QtContainerFwd>
35 
37 #include "base/indexrange.h"
38 #include "torrentcontentlayout.h"
39 
40 class QByteArray;
41 class QDateTime;
42 class QString;
43 class QUrl;
44 
45 namespace BitTorrent
46 {
47  class InfoHash;
48  struct TrackerEntry;
49 
51  {
52  Q_DECLARE_TR_FUNCTIONS(TorrentInfo)
53 
54  public:
55  TorrentInfo() = default;
56  TorrentInfo(const TorrentInfo &other);
57 
58  explicit TorrentInfo(const lt::torrent_info &nativeInfo);
59 
60  static nonstd::expected<TorrentInfo, QString> load(const QByteArray &data) noexcept;
61  static nonstd::expected<TorrentInfo, QString> loadFromFile(const QString &path) noexcept;
62  nonstd::expected<void, QString> saveToFile(const QString &path) const;
63 
64  TorrentInfo &operator=(const TorrentInfo &other);
65 
66  bool isValid() const;
67  InfoHash infoHash() const;
68  QString name() const;
69  QDateTime creationDate() const;
70  QString creator() const;
71  QString comment() const;
72  bool isPrivate() const;
73  qlonglong totalSize() const;
74  int filesCount() const;
75  int pieceLength() const;
76  int pieceLength(int index) const;
77  int piecesCount() const;
78  QString filePath(int index) const;
79  QStringList filePaths() const;
80  qlonglong fileSize(int index) const;
81  qlonglong fileOffset(int index) const;
82  QVector<TrackerEntry> trackers() const;
83  QVector<QUrl> urlSeeds() const;
84  QByteArray metadata() const;
85  QStringList filesForPiece(int pieceIndex) const;
86  QVector<int> fileIndicesForPiece(int pieceIndex) const;
87  QVector<QByteArray> pieceHashes() const;
88 
90  // returns pair of the first and the last pieces into which
91  // the given file extends (maybe partially).
92  PieceRange filePieces(const QString &file) const;
93  PieceRange filePieces(int fileIndex) const;
94 
95  QString rootFolder() const;
96  bool hasRootFolder() const;
97 
98  std::shared_ptr<lt::torrent_info> nativeInfo() const;
99  QVector<lt::file_index_t> nativeIndexes() const;
100 
101  private:
102  // returns file index or -1 if fileName is not found
103  int fileIndex(const QString &fileName) const;
105 
106  std::shared_ptr<const lt::torrent_info> m_nativeInfo;
107 
108  // internal indexes of files (payload only, excluding any .pad files)
109  // by which they are addressed in libtorrent
110  QVector<lt::file_index_t> m_nativeIndexes;
111  };
112 }
113 
114 Q_DECLARE_METATYPE(BitTorrent::TorrentInfo)
QVector< QUrl > urlSeeds() const
static nonstd::expected< TorrentInfo, QString > load(const QByteArray &data) noexcept
Definition: torrentinfo.cpp:89
QStringList filesForPiece(int pieceIndex) const
qlonglong totalSize() const
QVector< lt::file_index_t > nativeIndexes() const
QVector< TrackerEntry > trackers() const
QString comment() const
qlonglong fileOffset(int index) const
QString filePath(int index) const
InfoHash infoHash() const
int fileIndex(const QString &fileName) const
QVector< lt::file_index_t > m_nativeIndexes
Definition: torrentinfo.h:110
TorrentInfo & operator=(const TorrentInfo &other)
Definition: torrentinfo.cpp:74
TorrentContentLayout contentLayout() const
PieceRange filePieces(const QString &file) const
std::shared_ptr< lt::torrent_info > nativeInfo() const
QStringList filePaths() const
QDateTime creationDate() const
QByteArray metadata() const
std::shared_ptr< const lt::torrent_info > m_nativeInfo
Definition: torrentinfo.h:106
bool hasRootFolder() const
QString name() const
QString rootFolder() const
QVector< QByteArray > pieceHashes() const
QString creator() const
qlonglong fileSize(int index) const
QVector< int > fileIndicesForPiece(int pieceIndex) const
nonstd::expected< void, QString > saveToFile(const QString &path) const
static nonstd::expected< TorrentInfo, QString > loadFromFile(const QString &path) noexcept
QString fileName(const QString &filePath)
Definition: fs.cpp:87
file(GLOB QBT_TS_FILES "${qBittorrent_SOURCE_DIR}/src/lang/*.ts") set_source_files_properties($
Definition: CMakeLists.txt:5