File indexing completed on 2025-01-05 04:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTTORRENTFILEINTERFACE_H 0007 #define BTTORRENTFILEINTERFACE_H 0008 0009 #include <ktorrent_export.h> 0010 #include <qobject.h> 0011 #include <qstring.h> 0012 #include <util/constants.h> 0013 0014 class QTextCodec; 0015 0016 namespace bt 0017 { 0018 /** 0019 * @author Joris Guisson 0020 * @brief Interface for a file in a multifile torrent 0021 * 0022 * This class is the interface for a file in a multifile torrent. 0023 */ 0024 class KTORRENT_EXPORT TorrentFileInterface : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 /** 0029 * Constructor, set the path and size. 0030 * @param index The index of the file in the torrent 0031 * @param path The path 0032 * @param size The size 0033 */ 0034 TorrentFileInterface(Uint32 index, const QString &path, Uint64 size); 0035 ~TorrentFileInterface() override; 0036 0037 enum FileType { 0038 UNKNOWN, 0039 AUDIO, 0040 VIDEO, 0041 NORMAL, 0042 }; 0043 0044 /// Get the index of the file 0045 Uint32 getIndex() const 0046 { 0047 return index; 0048 } 0049 0050 /// Get the path of the file 0051 QString getPath() const 0052 { 0053 return path; 0054 } 0055 0056 /// Get the path of a file on disk 0057 QString getPathOnDisk() const 0058 { 0059 return path_on_disk; 0060 } 0061 0062 /// Get the mount point of the file on disk 0063 QString getMountPoint() const; 0064 0065 /// Set the mount point 0066 void setMountPoint(const QString &path) 0067 { 0068 mount_point = path; 0069 } 0070 0071 /** 0072 * Set the actual path of the file on disk. 0073 * @param p The path 0074 */ 0075 void setPathOnDisk(const QString &p) 0076 { 0077 path_on_disk = p; 0078 } 0079 0080 /// Get user modified path (if isn't changed, the normal path is returned) 0081 QString getUserModifiedPath() const 0082 { 0083 return user_modified_path.isEmpty() ? path : user_modified_path; 0084 } 0085 0086 /// Set the user modified path 0087 void setUserModifiedPath(const QString &p) 0088 { 0089 user_modified_path = p; 0090 } 0091 0092 /// Get the size of the file 0093 Uint64 getSize() const 0094 { 0095 return size; 0096 } 0097 0098 /// Get the index of the first chunk in which this file lies 0099 Uint32 getFirstChunk() const 0100 { 0101 return first_chunk; 0102 } 0103 0104 /// Get the last chunk of the file 0105 Uint32 getLastChunk() const 0106 { 0107 return last_chunk; 0108 } 0109 0110 /// Get the offset at which the file starts in the first chunk 0111 Uint64 getFirstChunkOffset() const 0112 { 0113 return first_chunk_off; 0114 } 0115 0116 /// Get how many bytes the files takes up of the last chunk 0117 Uint64 getLastChunkSize() const 0118 { 0119 return last_chunk_size; 0120 } 0121 0122 /// See if the TorrentFile is null. 0123 bool isNull() const 0124 { 0125 return path.isNull(); 0126 } 0127 0128 /// Set whether we have to not download this file 0129 virtual void setDoNotDownload(bool dnd) = 0; 0130 0131 /// Whether or not we have to not download this file 0132 virtual bool doNotDownload() const = 0; 0133 0134 /// Checks if this file is multimedial 0135 virtual bool isMultimedia() const = 0; 0136 0137 /// Gets the current priority of the torrent 0138 virtual Priority getPriority() const 0139 { 0140 return priority; 0141 } 0142 0143 /// Sets the priority of the torrent 0144 virtual void setPriority(Priority newpriority = NORMAL_PRIORITY) = 0; 0145 0146 /// Wheather to emit signal when dl status changes or not. 0147 virtual void setEmitDownloadStatusChanged(bool show) = 0; 0148 0149 /// Emits signal dlStatusChanged. Use it only with FileSelectDialog! 0150 virtual void emitDownloadStatusChanged() = 0; 0151 0152 /// Did this file exist before the torrent was loaded by KT 0153 bool isPreExistingFile() const 0154 { 0155 return preexisting; 0156 } 0157 0158 /// Set whether this file is preexisting 0159 void setPreExisting(bool pe) 0160 { 0161 preexisting = pe; 0162 } 0163 0164 /// Get the % of the file which is downloaded 0165 float getDownloadPercentage() const; 0166 0167 /// See if preview is available 0168 bool isPreviewAvailable() const 0169 { 0170 return preview; 0171 } 0172 0173 /// Set the unencoded path 0174 void setUnencodedPath(const QList<QByteArray> up); 0175 0176 /// Change the text codec 0177 void changeTextCodec(QTextCodec *codec); 0178 0179 /// Is this a video 0180 bool isVideo() const 0181 { 0182 return filetype == VIDEO; 0183 } 0184 0185 /// Is this an audio file 0186 bool isAudio() const 0187 { 0188 return filetype == AUDIO; 0189 } 0190 0191 protected: 0192 Uint32 index; 0193 Uint32 first_chunk; 0194 Uint32 last_chunk; 0195 Uint32 num_chunks_downloaded; 0196 Uint64 size; 0197 Uint64 first_chunk_off; 0198 Uint64 last_chunk_size; 0199 bool preexisting; 0200 bool emit_status_changed; 0201 bool preview; 0202 mutable FileType filetype; 0203 Priority priority; 0204 QString path; 0205 QString path_on_disk; 0206 QString user_modified_path; 0207 mutable QString mount_point; 0208 QList<QByteArray> unencoded_path; 0209 }; 0210 0211 } 0212 0213 #endif