libktorrent  2.1.1
chunkmanager.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 BTCHUNKMANAGER_H
21 #define BTCHUNKMANAGER_H
22 
23 #include <QMap>
24 #include <QSet>
25 #include <QString>
26 #include <QObject>
27 #include <vector>
28 #include <util/bitset.h>
29 #include <torrent/torrent.h>
30 #include <ktorrent_export.h>
31 #include "chunk.h"
32 
33 
34 class QStringList;
35 
36 namespace bt
37 {
38  class TorrentFile;
39  class PreallocationThread;
40  class TorrentFileInterface;
41  class CacheFactory;
42  class Job;
43 
45  {
46  unsigned int index; // the Chunks index
47  unsigned int deprecated; // offset in cache file
48  };
49 
60  class KTORRENT_EXPORT ChunkManager : public QObject
61  {
62  Q_OBJECT
63  public:
64  ChunkManager(Torrent& tor,
65  const QString& tmpdir,
66  const QString& datadir,
67  bool custom_output_name,
68  CacheFactory* fac);
69  ~ChunkManager() override;
70 
72  const Torrent& getTorrent() const
73  {
74  return tor;
75  }
76 
78  QString getDataDir() const;
79 
81  QString getOutputPath() const;
82 
83  void changeOutputPath(const QString& output_path);
84 
87 
92  void changeDataDir(const QString& data_dir);
93 
98  Job* moveDataFiles(const QString& ndir);
99 
105 
110  Job* moveDataFiles(const QMap<TorrentFileInterface*, QString> & files);
111 
112 
118  void moveDataFilesFinished(const QMap<TorrentFileInterface*, QString> & files, Job* job);
119 
125 
131  void createFiles(bool check_priority = false);
132 
137  bool hasMissingFiles(QStringList& sl);
138 
144 
148  void start();
149 
153  void stop();
154 
160  Chunk* getChunk(unsigned int i);
161 
166  void resetChunk(unsigned int i);
167 
172  void chunkDownloaded(unsigned int i);
173 
179  Uint64 bytesLeft() const;
180 
184  Uint64 bytesLeftToDownload() const;
185 
190  Uint64 bytesExcluded() const;
191 
197  Uint32 chunksLeft() const;
198 
204  bool haveAllChunks() const;
205 
210  Uint32 chunksExcluded() const;
211 
216  Uint32 chunksDownloaded() const;
217 
221  Uint32 onlySeedChunks() const;
222 
226  const BitSet& getBitSet() const
227  {
228  return bitset;
229  }
230 
234  const BitSet& getExcludedBitSet() const
235  {
236  return excluded_chunks;
237  }
238 
242  const BitSet& getOnlySeedBitSet() const
243  {
244  return only_seed_chunks;
245  }
246 
248  Uint32 getNumChunks() const
249  {
250  return tor.getNumChunks();
251  }
252 
255 
261  void prioritise(Uint32 from, Uint32 to, Priority priority);
262 
268  void exclude(Uint32 from, Uint32 to);
269 
276  void include(Uint32 from, Uint32 to);
277 
278 
286  void dataChecked(const BitSet& ok_chunks, Uint32 from, Uint32 to);
287 
289  bool hasExistingFiles() const;
290 
293 
296 
299 
302 
304  bool completed() const;
305 
307  static void setPreviewSizes(Uint32 audio, Uint32 video);
308 
310  Uint64 diskUsage();
311 
313  Uint32 previewChunkRangeSize(const TorrentFile& tf) const;
314 
316  Uint32 previewChunkRangeSize() const;
317 
319  void downloadPriorityChanged(TorrentFile* tf, Priority newpriority, Priority oldpriority);
320 
322  bool isStorageMounted(QStringList& missing);
323 
324  Q_SIGNALS:
330  void excluded(Uint32 from, Uint32 to);
331 
337  void included(Uint32 from, Uint32 to);
338 
343  void updateStats();
344 
349  void corrupted(Uint32 chunk);
350 
351  private:
352  static Uint32 preview_size_audio;
353  static Uint32 preview_size_video;
354 
355  class Private;
356  Private* d;
357  Torrent& tor;
358  BitSet bitset;
359  BitSet excluded_chunks;
360  BitSet only_seed_chunks;
361  };
362 
363 }
364 
365 #endif
bt::ChunkManager::dndMissingFiles
void dndMissingFiles()
Set missing files as do not download.
bt::CacheFactory
Definition: cachefactory.h:57
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:55
bt::Torrent::getNumChunks
Uint32 getNumChunks() const
Get the number of chunks.
Definition: torrent.h:128
bt::ChunkManager::start
void start()
bt::ChunkManager::diskUsage
Uint64 diskUsage()
Get the current disk usage of all the files in this torrent.
bt::ChunkManager::onlySeedChunks
Uint32 onlySeedChunks() const
bt::NewChunkHeader
Definition: chunkmanager.h:45
bt::ChunkManager::completed
bool completed() const
Are all not deselected chunks downloaded.
bt::ChunkManager::exclude
void exclude(Uint32 from, Uint32 to)
bt::ChunkManager::include
void include(Uint32 from, Uint32 to)
bt::ChunkManager
Definition: chunkmanager.h:61
bt::ChunkManager::chunksDownloaded
Uint32 chunksDownloaded() const
bt::Chunk
Keep track of a piece of the file.
Definition: chunk.h:64
bt::ChunkManager::preparePreallocation
void preparePreallocation(PreallocationThread *prealloc)
bt::ChunkManager::markExistingFilesAsDownloaded
void markExistingFilesAsDownloaded()
Mark all existing files as downloaded.
bt::ChunkManager::updateStats
void updateStats()
bt::Job
Definition: job.h:38
bt::ChunkManager::hasExistingFiles
bool hasExistingFiles() const
Test if the torrent has existing files, only works the first time a torrent is loaded.
bt::ChunkManager::stop
void stop()
bt::ChunkManager::dataChecked
void dataChecked(const BitSet &ok_chunks, Uint32 from, Uint32 to)
bt::ChunkManager::prioritise
void prioritise(Uint32 from, Uint32 to, Priority priority)
bt::ChunkManager::changeDataDir
void changeDataDir(const QString &data_dir)
bt::ChunkManager::bytesLeftToDownload
Uint64 bytesLeftToDownload() const
bt::ChunkManager::createFiles
void createFiles(bool check_priority=false)
bt::ChunkManager::getNumChunks
Uint32 getNumChunks() const
Get the number of chunks into the file.
Definition: chunkmanager.h:248
bt::ChunkManager::previewChunkRangeSize
Uint32 previewChunkRangeSize(const TorrentFile &tf) const
Get the size in chunks of the preview range of a file of the torrent.
bt::ChunkManager::bytesLeft
Uint64 bytesLeft() const
bt::ChunkManager::debugPrintMemUsage
void debugPrintMemUsage()
Print memory usage to log file.
bt::ChunkManager::previewChunkRangeSize
Uint32 previewChunkRangeSize() const
Get the size in chunks of the preview range for a single file torrent.
bt::ChunkManager::excluded
void excluded(Uint32 from, Uint32 to)
bt::ChunkManager::downloadPriorityChanged
void downloadPriorityChanged(TorrentFile *tf, Priority newpriority, Priority oldpriority)
The download priority of a file has changed.
bt::TorrentFile
Definition: torrentfile.h:61
bt::ChunkManager::moveDataFilesFinished
void moveDataFilesFinished(const QMap< TorrentFileInterface *, QString > &files, Job *job)
bt::PreallocationThread
Definition: preallocationthread.h:60
bt::ChunkManager::getChunk
Chunk * getChunk(unsigned int i)
bt::Torrent
Loads a .torrent file.
Definition: torrent.h:80
bt::ChunkManager::corrupted
void corrupted(Uint32 chunk)
bt::ChunkManager::chunksExcluded
Uint32 chunksExcluded() const
bt::ChunkManager::hasMissingFiles
bool hasMissingFiles(QStringList &sl)
bt::ChunkManager::isStorageMounted
bool isStorageMounted(QStringList &missing)
Is the storage mounted ?
bt::ChunkManager::deleteDataFiles
Job * deleteDataFiles()
Delete all data files.
bt::ChunkManager::chunkDownloaded
void chunkDownloaded(unsigned int i)
bt::ChunkManager::moveDataFiles
Job * moveDataFiles(const QString &ndir)
bt::ChunkManager::getOutputPath
QString getOutputPath() const
Get the actual output path.
bt::ChunkManager::getBitSet
const BitSet & getBitSet() const
Definition: chunkmanager.h:226
bt::ChunkManager::getOnlySeedBitSet
const BitSet & getOnlySeedBitSet() const
Definition: chunkmanager.h:242
bt::ChunkManager::getTorrent
const Torrent & getTorrent() const
Get the torrent.
Definition: chunkmanager.h:72
bt::ChunkManager::included
void included(Uint32 from, Uint32 to)
bt::ChunkManager::chunksLeft
Uint32 chunksLeft() const
bt::ChunkManager::moveDataFiles
Job * moveDataFiles(const QMap< TorrentFileInterface *, QString > &files)
bt::ChunkManager::bytesExcluded
Uint64 bytesExcluded() const
bt::ChunkManager::getExcludedBitSet
const BitSet & getExcludedBitSet() const
Definition: chunkmanager.h:234
bt::ChunkManager::haveAllChunks
bool haveAllChunks() const
bt::ChunkManager::resetChunk
void resetChunk(unsigned int i)
bt::ChunkManager::loadIndexFile
void loadIndexFile()
bt::ChunkManager::setPreviewSizes
static void setPreviewSizes(Uint32 audio, Uint32 video)
Set the preview sizes for audio and video files.
bt::ChunkManager::recreateMissingFiles
void recreateMissingFiles()
Recreates missing files.
bt::ChunkManager::moveDataFilesFinished
void moveDataFilesFinished(Job *job)
bt::ChunkManager::checkMemoryUsage
void checkMemoryUsage()
Remove obsolete chunks.
bt::ChunkManager::getDataDir
QString getDataDir() const
Get the data dir.