Browse Source

- Fixed a bug in torrent content selection when there is only one file in the torrent

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
488bd90303
  1. 13
      src/arborescence.h
  2. 5
      src/torrentAddition.h

13
src/arborescence.h

@ -39,7 +39,8 @@ class file {
int index; // Index in torrent_info int index; // Index in torrent_info
public: public:
file(file *parent, QString path, bool dir, size_type size=0, float progress=0., int priority=1, int index=-1): parent(parent), is_dir(dir), size(size), progress(progress), priority(priority), index(index){ file(file *parent, QString path, bool dir, size_type size=0, int index=-1, float progress=0., int priority=1): parent(parent), is_dir(dir), size(size), progress(progress), priority(priority), index(index){
qDebug("created a file with index %d", index);
rel_path = QDir::cleanPath(path); rel_path = QDir::cleanPath(path);
if(parent) { if(parent) {
parent->updateProgress(); parent->updateProgress();
@ -121,10 +122,10 @@ class file {
parent->addBytes(b); parent->addBytes(b);
} }
file* addChild(QString fileName, bool dir, size_type size=0, float progress=0., int priority=1, int index = -1) { file* addChild(QString fileName, bool dir, size_type size=0, int index = -1, float progress=0., int priority=1) {
Q_ASSERT(is_dir); Q_ASSERT(is_dir);
qDebug("Adding a new child of size: %ld", (long)size); qDebug("Adding a new child of size: %ld", (long)size);
file *f = new file(this, QDir::cleanPath(rel_path+QDir::separator()+fileName), dir, size, progress, priority, index); file *f = new file(this, QDir::cleanPath(rel_path+QDir::separator()+fileName), dir, size, index, progress, priority);
children << f; children << f;
if(size) { if(size) {
addBytes(size); addBytes(size);
@ -184,10 +185,12 @@ class arborescence {
arborescence(torrent_info t, std::vector<float> fp, int *prioritiesTab) { arborescence(torrent_info t, std::vector<float> fp, int *prioritiesTab) {
torrent_info::file_iterator fi = t.begin_files(); torrent_info::file_iterator fi = t.begin_files();
if(t.num_files() > 1) { if(t.num_files() > 1) {
qDebug("More than one file in the torrent, setting a folder as root");
root = new file(0, misc::toQString(t.name()), true); root = new file(0, misc::toQString(t.name()), true);
} else { } else {
// XXX: Will crash if there is no file in torrent // XXX: Will crash if there is no file in torrent
root = new file(0, misc::toQString(t.name()), false, fi->size, fp[0], prioritiesTab[0], 0); qDebug("one file in the torrent, setting it as root with index 0");
root = new file(0, misc::toQString(t.name()), false, fi->size, 0, fp[0], prioritiesTab[0]);
return; return;
} }
int i = 0; int i = 0;
@ -240,7 +243,7 @@ class arborescence {
child = dad->addChild(fileName, true); child = dad->addChild(fileName, true);
} else { } else {
// File // File
child = dad->addChild(fileName, false, file_size, progress, priority, index); child = dad->addChild(fileName, false, file_size, index, progress, priority);
} }
} }
dad = child; dad = child;

5
src/torrentAddition.h

@ -352,9 +352,11 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
QStandardItem *item = parent->child(i, INDEX); QStandardItem *item = parent->child(i, INDEX);
int index = item->text().toInt(); int index = item->text().toInt();
if(index < 0) { if(index < 0) {
getPriorities(parent->child(i, NAME), priorities); qDebug("getPriorities(), found a folder, checking its children");
getPriorities(parent->child(i), priorities);
} else { } else {
item = parent->child(i, PRIORITY); item = parent->child(i, PRIORITY);
qDebug("getPriorities(), found priority %d for file at index %d", item->text().toInt(), index);
priorities[index] = item->text().toInt(); priorities[index] = item->text().toInt();
} }
} }
@ -373,6 +375,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
return; return;
} }
for(unsigned int i=0; i<nbFiles; ++i) { for(unsigned int i=0; i<nbFiles; ++i) {
qDebug("%d ", priorities[i]);
pieces_file.write(misc::toQByteArray(priorities[i])+misc::toQByteArray("\n")); pieces_file.write(misc::toQByteArray(priorities[i])+misc::toQByteArray("\n"));
} }
pieces_file.close(); pieces_file.close();

Loading…
Cancel
Save