1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/***************************************************************************
* Copyright (C) 2005 by *
* Joris Guisson <joris.guisson@gmail.com> *
* Ivan Vasic <ivasic@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef BTTORRENTFILE_H
#define BTTORRENTFILE_H
#include <tqstring.h>
#include <util/constants.h>
#include <interfaces/torrentfileinterface.h>
namespace bt
{
class BitSet;
/**
* @author Joris Guisson
*
* File in a multi file torrent. Keeps track of the path of the file,
* it's size, offset into the cache and between which chunks it lies.
*/
class TorrentFile : public kt::TorrentFileInterface
{
Q_OBJECT
TQ_OBJECT
Uint32 index;
Uint64 cache_offset;
Uint64 first_chunk_off;
Uint64 last_chunk_size;
Priority priority;
Priority old_priority;
bool missing;
enum FileType
{
UNKNOWN,
MULTIMEDIA,
NORMAL
};
mutable FileType filetype;
public:
/**
* Default constructor. Creates a null TorrentFile.
*/
TorrentFile();
/**
* Constructor.
* @param index Index number of the file
* @param path Path of the file
* @param off Offset into the torrent
* (i.e. how many bytes were all the previous files in the torrent combined)
* @param size Size of the file
* @param chunk_size Size of each chunk
*/
TorrentFile(Uint32 index,const TQString & path,Uint64 off,Uint64 size,Uint64 chunk_size);
/**
* Copy constructor.
* @param tf The TorrentFile to copy
*/
TorrentFile(const TorrentFile & tf);
virtual ~TorrentFile();
/// Get the index of the file
Uint32 getIndex() const {return index;}
/// Get the offset into the torrent
Uint64 getCacheOffset() const {return cache_offset;}
/// Get the offset at which the file starts in the first chunk
Uint64 getFirstChunkOffset() const {return first_chunk_off;}
/// Get how many bytes the files takes up of the last chunk
Uint64 getLastChunkSize() const {return last_chunk_size;}
/// Check if this file doesn't have to be downloaded
bool doNotDownload() const
{if(priority == EXCLUDED) return true; else return false;}
/// Set wether we have to not download this file
void setDoNotDownload(bool dnd);
/// Checks if this file is multimedial
bool isMultimedia() const;
/// Gets the priority of the file
Priority getPriority() const {return priority;}
/// Sets the priority of the file
void setPriority(Priority newpriority = NORMAL_PRIORITY);
/// Get the previous priority value
Priority getOldPriority() const {return old_priority;}
/// emits signal.
void emitDownloadStatusChanged();
void setEmitDownloadStatusChanged(bool show) { m_emitDlStatusChanged = show; }
/**
* Assignment operator
* @param tf The file to copy
* @return *this
*/
TorrentFile & operator = (const TorrentFile & tf);
/// See if the file is missing
bool isMissing() const {return missing;}
/// Set the file to be missing or not
void setMissing(bool m) {missing = m;}
/**
* Calculate the offset of a chunk in the file
* @param cindex Index of chunk
* @param chunk_size Size of each chunk
*/
Uint64 fileOffset(Uint32 cindex,Uint64 chunk_size) const;
static TorrentFile null;
/**
* Update the number of downloaded chunks for this file.
* @param bs The current bitset of all chunks
*/
void updateNumDownloadedChunks(const BitSet & bs);
signals:
/**
* Signal emitted when the Priority variable changes.
* @param tf The TorrentFile which emitted the signal
* @param newpriority THe new priority of the file
* @param oldpriority Previous priority
*/
void downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority);
};
}
#endif
|