libktorrent  2.1.1
torrentfileinterface.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (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 *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTTORRENTFILEINTERFACE_H
21 #define BTTORRENTFILEINTERFACE_H
22 
23 #include <qobject.h>
24 #include <qstring.h>
25 #include <ktorrent_export.h>
26 #include <util/constants.h>
27 
28 class QTextCodec;
29 
30 namespace bt
31 {
32 
39  class KTORRENT_EXPORT TorrentFileInterface : public QObject
40  {
41  Q_OBJECT
42  public:
49  TorrentFileInterface(Uint32 index,const QString & path,Uint64 size);
50  ~TorrentFileInterface() override;
51 
52  enum FileType
53  {
54  UNKNOWN,
55  AUDIO,
56  VIDEO,
57  NORMAL
58  };
59 
61  Uint32 getIndex() const {return index;}
62 
64  QString getPath() const {return path;}
65 
67  QString getPathOnDisk() const {return path_on_disk;}
68 
70  QString getMountPoint() const;
71 
73  void setMountPoint(const QString & path) {mount_point = path;}
74 
79  void setPathOnDisk(const QString & p) {path_on_disk = p;}
80 
82  QString getUserModifiedPath() const {return user_modified_path.isEmpty() ? path : user_modified_path;}
83 
85  void setUserModifiedPath(const QString & p) {user_modified_path = p;}
86 
88  Uint64 getSize() const {return size;}
89 
91  Uint32 getFirstChunk() const {return first_chunk;}
92 
94  Uint32 getLastChunk() const {return last_chunk;}
95 
97  Uint64 getFirstChunkOffset() const {return first_chunk_off;}
98 
100  Uint64 getLastChunkSize() const {return last_chunk_size;}
101 
103  bool isNull() const {return path.isNull();}
104 
106  virtual void setDoNotDownload(bool dnd) = 0;
107 
109  virtual bool doNotDownload() const = 0;
110 
112  virtual bool isMultimedia() const = 0;
113 
115  virtual Priority getPriority() const {return priority;}
116 
118  virtual void setPriority(Priority newpriority = NORMAL_PRIORITY) = 0;
119 
121  virtual void setEmitDownloadStatusChanged(bool show) = 0;
122 
124  virtual void emitDownloadStatusChanged() = 0;
125 
127  bool isPreExistingFile() const {return preexisting;}
128 
130  void setPreExisting(bool pe) {preexisting = pe;}
131 
133  float getDownloadPercentage() const;
134 
136  bool isPreviewAvailable() const {return preview;}
137 
139  void setUnencodedPath(const QList<QByteArray> up);
140 
142  void changeTextCodec(QTextCodec* codec);
143 
145  bool isVideo() const {return filetype == VIDEO;}
146 
148  bool isAudio() const {return filetype == AUDIO;}
149 
150  protected:
151  Uint32 index;
152  Uint32 first_chunk;
153  Uint32 last_chunk;
154  Uint32 num_chunks_downloaded;
155  Uint64 size;
156  Uint64 first_chunk_off;
157  Uint64 last_chunk_size;
158  bool preexisting;
159  bool emit_status_changed;
160  bool preview;
161  mutable FileType filetype;
162  Priority priority;
163  QString path;
164  QString path_on_disk;
165  QString user_modified_path;
166  mutable QString mount_point;
167  QList<QByteArray> unencoded_path;
168  };
169 
170 }
171 
172 #endif
bt::TorrentFileInterface::getDownloadPercentage
float getDownloadPercentage() const
Get the % of the file which is downloaded.
bt::TorrentFileInterface::setEmitDownloadStatusChanged
virtual void setEmitDownloadStatusChanged(bool show)=0
Wheather to emit signal when dl status changes or not.
bt::TorrentFileInterface::getPathOnDisk
QString getPathOnDisk() const
Get the path of a file on disk.
Definition: torrentfileinterface.h:67
bt::TorrentFileInterface
Interface for a file in a multifile torrent.
Definition: torrentfileinterface.h:40
bt::TorrentFileInterface::setPriority
virtual void setPriority(Priority newpriority=NORMAL_PRIORITY)=0
Sets the priority of the torrent.
bt::TorrentFileInterface::setMountPoint
void setMountPoint(const QString &path)
Set the mount point.
Definition: torrentfileinterface.h:73
bt::TorrentFileInterface::setUserModifiedPath
void setUserModifiedPath(const QString &p)
Set the user modified path.
Definition: torrentfileinterface.h:85
bt::TorrentFileInterface::isPreExistingFile
bool isPreExistingFile() const
Did this file exist before the torrent was loaded by KT.
Definition: torrentfileinterface.h:127
bt::TorrentFileInterface::isPreviewAvailable
bool isPreviewAvailable() const
See if preview is available.
Definition: torrentfileinterface.h:136
bt::TorrentFileInterface::getLastChunk
Uint32 getLastChunk() const
Get the last chunk of the file.
Definition: torrentfileinterface.h:94
bt::TorrentFileInterface::TorrentFileInterface
TorrentFileInterface(Uint32 index, const QString &path, Uint64 size)
bt::TorrentFileInterface::setUnencodedPath
void setUnencodedPath(const QList< QByteArray > up)
Set the unencoded path.
bt::TorrentFileInterface::changeTextCodec
void changeTextCodec(QTextCodec *codec)
Change the text codec.
bt::TorrentFileInterface::emitDownloadStatusChanged
virtual void emitDownloadStatusChanged()=0
Emits signal dlStatusChanged. Use it only with FileSelectDialog!
bt::TorrentFileInterface::getFirstChunk
Uint32 getFirstChunk() const
Get the index of the first chunk in which this file lies.
Definition: torrentfileinterface.h:91
bt::TorrentFileInterface::setPathOnDisk
void setPathOnDisk(const QString &p)
Definition: torrentfileinterface.h:79
bt::TorrentFileInterface::getPriority
virtual Priority getPriority() const
Gets the current priority of the torrent.
Definition: torrentfileinterface.h:115
bt::TorrentFileInterface::getSize
Uint64 getSize() const
Get the size of the file.
Definition: torrentfileinterface.h:88
bt::TorrentFileInterface::isAudio
bool isAudio() const
Is this an audio file.
Definition: torrentfileinterface.h:148
bt::TorrentFileInterface::getUserModifiedPath
QString getUserModifiedPath() const
Get user modified path (if isn't changed, the normal path is returned)
Definition: torrentfileinterface.h:82
bt::TorrentFileInterface::getPath
QString getPath() const
Get the path of the file.
Definition: torrentfileinterface.h:64
bt::TorrentFileInterface::getLastChunkSize
Uint64 getLastChunkSize() const
Get how many bytes the files takes up of the last chunk.
Definition: torrentfileinterface.h:100
bt::TorrentFileInterface::doNotDownload
virtual bool doNotDownload() const =0
Whether or not we have to not download this file.
bt::TorrentFileInterface::getFirstChunkOffset
Uint64 getFirstChunkOffset() const
Get the offset at which the file starts in the first chunk.
Definition: torrentfileinterface.h:97
bt::TorrentFileInterface::setPreExisting
void setPreExisting(bool pe)
Set whether this file is preexisting.
Definition: torrentfileinterface.h:130
bt::TorrentFileInterface::getMountPoint
QString getMountPoint() const
Get the mount point of the file on disk.
bt::TorrentFileInterface::isVideo
bool isVideo() const
Is this a video.
Definition: torrentfileinterface.h:145
bt::TorrentFileInterface::setDoNotDownload
virtual void setDoNotDownload(bool dnd)=0
Set whether we have to not download this file.
bt::TorrentFileInterface::isMultimedia
virtual bool isMultimedia() const =0
Checks if this file is multimedial.
bt::TorrentFileInterface::isNull
bool isNull() const
See if the TorrentFile is null.
Definition: torrentfileinterface.h:103
bt::TorrentFileInterface::getIndex
Uint32 getIndex() const
Get the index of the file.
Definition: torrentfileinterface.h:61