31
31
#include <stdlib.h>
32
32
#include <bcodec/bdecoder.h>
33
33
#include <bcodec/bnode.h>
34
#include <interfaces/monitorinterface.h>
35
36
#include <klocale.h>
40
Torrent::Torrent() : piece_length(0),file_length(0),priv_torrent(false)
41
Torrent::Torrent() : piece_length(0),file_length(0),priv_torrent(false),pos_cache_chunk(0),pos_cache_file(0),tmon(0)
42
43
text_codec = QTextCodec::codecForName("utf-8");
45
file_prio_listener = 0;
195
197
if (v->data().getType() == Value::INT || v->data().getType() == Value::INT64)
197
199
Uint64 s = v->data().toInt64();
198
TorrentFile file(idx,path,file_length,s,piece_length);
200
TorrentFile file(this,idx,path,file_length,s,piece_length);
199
201
file.setUnencodedPath(unencoded_path);
201
203
// update file_length
432
436
void Torrent::calcChunkPos(Uint32 chunk,QList<Uint32> & file_list) const
434
438
file_list.clear();
435
439
if (chunk >= (Uint32)hash_pieces.size() || files.empty())
438
for (int i = 0;i < files.count();i++)
442
int start = (chunk >= this->pos_cache_chunk) ? this->pos_cache_file : 0;
443
int end = (files.count() - 1);
444
int mid = start + (end - start) / 2;
445
while (start != mid && mid != end)
447
//printf("start = %i ; end = %i ; mid = %i\n",start,end,mid);
448
const TorrentFile & f = files[mid];
449
if (chunk >= f.getFirstChunk() && chunk <= f.getLastChunk())
455
const TorrentFile & tf = files[i];
456
if (!(chunk >= tf.getFirstChunk() && chunk <= tf.getLastChunk()))
467
if (chunk > f.getLastChunk())
469
// chunk comes after file
471
mid = start + (end - start) / 2;
475
// chunk comes before file
477
mid = start + (end - start) / 2;
482
for (int i = mid;i < files.count();i++)
440
484
const TorrentFile & f = files[i];
441
485
if (chunk >= f.getFirstChunk() && chunk <= f.getLastChunk() && f.getSize() != 0)
442
487
file_list.append(f.getIndex());
489
else if (chunk < f.getFirstChunk())
493
pos_cache_chunk = chunk;
494
pos_cache_file = file_list.at(0);
446
497
bool Torrent::isMultimedia() const
492
543
name_suggestion = text_codec->toUnicode(unencoded_name);
546
void Torrent::downloadPriorityChanged(TorrentFile* tf,Priority newpriority,Priority oldpriority)
548
if (file_prio_listener)
549
file_prio_listener->downloadPriorityChanged(tf,newpriority,oldpriority);
552
void Torrent::filePercentageChanged(TorrentFile* tf,float perc)
555
tmon->filePercentageChanged(tf,perc);
558
void Torrent::filePreviewChanged(TorrentFile* tf,bool preview)
561
tmon->filePreviewChanged(tf,preview);