Browse Source

- A lot of improvement and bug fixes in new torrent content selection

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
419b94f042
  1. 16
      src/PropListDelegate.h
  2. 110
      src/properties_imp.cpp
  3. 5
      src/properties_imp.h
  4. 111
      src/torrentAddition.h

16
src/PropListDelegate.h

@ -169,6 +169,10 @@ class PropListDelegate: public QItemDelegate {
model->setData(index, QVariant(IGNORED)); model->setData(index, QVariant(IGNORED));
if(filteredFilesChanged != 0) if(filteredFilesChanged != 0)
*filteredFilesChanged = true; *filteredFilesChanged = true;
} else {
// XXX: hack to force the model to send the itemChanged() signal
model->setData(index, QVariant(NORMAL));
model->setData(index, QVariant(IGNORED));
} }
break; break;
case 1: case 1:
@ -176,6 +180,9 @@ class PropListDelegate: public QItemDelegate {
model->setData(index, QVariant(NORMAL)); model->setData(index, QVariant(NORMAL));
if(filteredFilesChanged != 0) if(filteredFilesChanged != 0)
*filteredFilesChanged = true; *filteredFilesChanged = true;
} else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(NORMAL));
} }
break; break;
case 2: case 2:
@ -183,6 +190,9 @@ class PropListDelegate: public QItemDelegate {
model->setData(index, QVariant(HIGH)); model->setData(index, QVariant(HIGH));
if(filteredFilesChanged != 0) if(filteredFilesChanged != 0)
*filteredFilesChanged = true; *filteredFilesChanged = true;
} else {
model->setData(index, QVariant(NORMAL));
model->setData(index, QVariant(HIGH));
} }
break; break;
case 3: case 3:
@ -190,6 +200,9 @@ class PropListDelegate: public QItemDelegate {
model->setData(index, QVariant(MAXIMUM)); model->setData(index, QVariant(MAXIMUM));
if(filteredFilesChanged != 0) if(filteredFilesChanged != 0)
*filteredFilesChanged = true; *filteredFilesChanged = true;
} else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(MAXIMUM));
} }
break; break;
default: default:
@ -197,6 +210,9 @@ class PropListDelegate: public QItemDelegate {
model->setData(index, QVariant(NORMAL)); model->setData(index, QVariant(NORMAL));
if(filteredFilesChanged != 0) if(filteredFilesChanged != 0)
*filteredFilesChanged = true; *filteredFilesChanged = true;
} else {
model->setData(index, QVariant(HIGH));
model->setData(index, QVariant(NORMAL));
} }
} }
} }

110
src/properties_imp.cpp

@ -32,7 +32,7 @@
#include <QStandardItemModel> #include <QStandardItemModel>
// Constructor // Constructor
properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h): QDialog(parent), h(h), BTSession(BTSession), changedFilteredfiles(false), hash(h.hash()), editParentsOnly(false) { properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h): QDialog(parent), h(h), BTSession(BTSession), changedFilteredfiles(false), hash(h.hash()) {
setupUi(this); setupUi(this);
lbl_priorities->setText(tr("Priorities:")+"<ul><li>"+tr("Ignored: file is not downloaded at all")+"</li><li>"+tr("Normal: normal priority. Download order is dependent on availability")+"</li><li>"+tr("High: higher than normal priority. Pieces are preferred over pieces with the same availability, but not over pieces with lower availability")+"</li><li>"+tr("Maximum: maximum priority, availability is disregarded, the piece is preferred over any other piece with lower priority")+"</li></ul>"); lbl_priorities->setText(tr("Priorities:")+"<ul><li>"+tr("Ignored: file is not downloaded at all")+"</li><li>"+tr("Normal: normal priority. Download order is dependent on availability")+"</li><li>"+tr("High: higher than normal priority. Pieces are preferred over pieces with the same availability, but not over pieces with lower availability")+"</li><li>"+tr("Maximum: maximum priority, availability is disregarded, the piece is preferred over any other piece with lower priority")+"</li></ul>");
// set icons // set icons
@ -104,7 +104,7 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem()); addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem());
delete arb; delete arb;
delete prioritiesTab; delete prioritiesTab;
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateChildrenPriority(QStandardItem*))); connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
filesList->expandAll(); filesList->expandAll();
// List web seeds // List web seeds
loadWebSeedsFromFile(); loadWebSeedsFromFile();
@ -155,62 +155,82 @@ void properties::addFilesToTree(file *root, QStandardItem *parent) {
} }
} }
void properties::updateChildrenPriority(QStandardItem *item) { // priority is the new priority of given item
qDebug("Priority changed"); void properties::updateParentsPriority(QStandardItem *item, int priority) {
QStandardItem *parent = item->parent(); QStandardItem *parent = item->parent();
int row = item->row(); if(!parent) return;
if(!parent) { // Check if children have different priorities
parent = PropListModel->invisibleRootItem(); // then folder must have NORMAL priority
} unsigned int rowCount = parent->rowCount();
bool is_dir = (parent->child(row, INDEX)->text().toInt() == -1); for(unsigned int i=0; i<rowCount; ++i) {
int priority = parent->child(row, PRIORITY)->text().toInt(); if(parent->child(i, PRIORITY)->text().toInt() != priority) {
// Update parent priority
if(item->parent()) {
bool parentUpdate = true;
unsigned int rowCount = parent->rowCount();
for(unsigned int i=0; i<rowCount; ++i) {
if(parent->child(i, PRIORITY)->text().toInt() != priority) {
// Check if parent priority is NORMAL
QStandardItem *grandFather = parent->parent();
if(!grandFather) {
grandFather = PropListModel->invisibleRootItem();
}
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
editParentsOnly = true;
parentPrio->setText(misc::toQString(NORMAL));
editParentsOnly = false;
parentUpdate = false;
break;
}
}
if(parentUpdate) {
QStandardItem *grandFather = parent->parent(); QStandardItem *grandFather = parent->parent();
if(!grandFather) { if(!grandFather) {
grandFather = PropListModel->invisibleRootItem(); grandFather = PropListModel->invisibleRootItem();
} }
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY); QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
editParentsOnly = true; if(parentPrio->text().toInt() != NORMAL) {
parentPrio->setText(misc::toQString(priority)); parentPrio->setText(misc::toQString(NORMAL));
editParentsOnly = false; // Recursively update ancesters of this parent too
updateParentsPriority(grandFather->child(parent->row()), priority);
}
return;
} }
} }
if(editParentsOnly) return; // All the children have the same priority
if(!is_dir) return; // Parent folder should have the same priority too
// Updating children QStandardItem *grandFather = parent->parent();
qDebug("Priority changed for a folder to %d", priority); if(!grandFather) {
parent = parent->child(row); grandFather = PropListModel->invisibleRootItem();
}
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
if(parentPrio->text().toInt() != priority) {
parentPrio->setText(misc::toQString(priority));
// Recursively update ancesters of this parent too
updateParentsPriority(grandFather->child(parent->row()), priority);
}
}
void properties::updateChildrenPriority(QStandardItem *item, int priority) {
QStandardItem *parent = item->parent();
if(!parent) {
parent = PropListModel->invisibleRootItem();
}
parent = parent->child(item->row());
unsigned int rowCount = parent->rowCount(); unsigned int rowCount = parent->rowCount();
qDebug("The folder has %d children", rowCount);
for(unsigned int i=0; i<rowCount; ++i) { for(unsigned int i=0; i<rowCount; ++i) {
// get child priority QStandardItem * childPrio = parent->child(i, PRIORITY);
QStandardItem *child = parent->child(i, PRIORITY); if(childPrio->text().toInt() != priority) {
int child_prio = child->text().toInt(); childPrio->setText(misc::toQString(priority));
qDebug("Child priority is %d", child_prio); // recursively update children of this child too
if(child_prio != priority) { updateChildrenPriority(parent->child(i), priority);
child->setText(misc::toQString(priority));
} }
} }
} }
void properties::updatePriorities(QStandardItem *item) {
qDebug("Priority changed");
// First we disable the signal/slot on item edition
// temporarily so that it doesn't mess with our manual updates
disconnect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
QStandardItem *parent = item->parent();
if(!parent) {
parent = PropListModel->invisibleRootItem();
}
int priority = parent->child(item->row(), PRIORITY)->text().toInt();
// Update parents priorities
updateParentsPriority(item, priority);
// If this is not a directory, then there are
// no children to update
if(parent->child(item->row(), INDEX)->text().toInt() == -1) {
// Updating children
qDebug("Priority changed for a folder to %d", priority);
updateChildrenPriority(item, priority);
}
// Reconnect the signal/slot on item edition so that we
// get future updates
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
}
void properties::loadTrackersErrors(){ void properties::loadTrackersErrors(){
// Tracker Errors // Tracker Errors

5
src/properties_imp.h

@ -45,7 +45,6 @@ class properties : public QDialog, private Ui::properties{
QStandardItemModel *PropListModel; QStandardItemModel *PropListModel;
QTimer *updateInfosTimer; QTimer *updateInfosTimer;
bool has_filtered_files; bool has_filtered_files;
bool editParentsOnly;
QStringList urlSeeds; QStringList urlSeeds;
protected slots: protected slots:
@ -71,7 +70,9 @@ class properties : public QDialog, private Ui::properties{
void deleteSelectedUrlSeeds(); void deleteSelectedUrlSeeds();
void loadTrackersErrors(); void loadTrackersErrors();
void addFilesToTree(file *root, QStandardItem *parent); void addFilesToTree(file *root, QStandardItem *parent);
void updateChildrenPriority(QStandardItem *item); void updateChildrenPriority(QStandardItem *item, int priority);
void updateParentsPriority(QStandardItem *item, int priority);
void updatePriorities(QStandardItem *item);
void getPriorities(QStandardItem *parent, int *priorities); void getPriorities(QStandardItem *parent, int *priorities);
signals: signals:

111
src/torrentAddition.h

@ -57,10 +57,9 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
QStandardItemModel *PropListModel; QStandardItemModel *PropListModel;
PropListDelegate *PropDelegate; PropListDelegate *PropDelegate;
unsigned int nbFiles; unsigned int nbFiles;
bool editParentsOnly;
public: public:
torrentAdditionDialog(QWidget *parent) : QDialog(parent), editParentsOnly(false){ torrentAdditionDialog(QWidget *parent) : QDialog(parent) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
// Set Properties list model // Set Properties list model
@ -120,7 +119,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
arborescence *arb = new arborescence(t); arborescence *arb = new arborescence(t);
addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem()); addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem());
delete arb; delete arb;
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateChildrenPriority(QStandardItem*))); connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
torrentContentList->expandAll(); torrentContentList->expandAll();
}catch (invalid_torrent_file&){ // Raised by torrent_info constructor }catch (invalid_torrent_file&){ // Raised by torrent_info constructor
// Display warning to tell user we can't decode the torrent file // Display warning to tell user we can't decode the torrent file
@ -188,62 +187,82 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
public slots: public slots:
void updateChildrenPriority(QStandardItem *item) { // priority is the new priority of given item
qDebug("Priority changed"); void updateParentsPriority(QStandardItem *item, int priority) {
QStandardItem *parent = item->parent(); QStandardItem *parent = item->parent();
int row = item->row(); if(!parent) return;
if(!parent) { // Check if children have different priorities
parent = PropListModel->invisibleRootItem(); // then folder must have NORMAL priority
} unsigned int rowCount = parent->rowCount();
bool is_dir = (parent->child(row, INDEX)->text().toInt() == -1); for(unsigned int i=0; i<rowCount; ++i) {
int priority = parent->child(row, PRIORITY)->text().toInt(); if(parent->child(i, PRIORITY)->text().toInt() != priority) {
// Update parent priority
if(item->parent()) {
bool parentUpdate = true;
unsigned int rowCount = parent->rowCount();
for(unsigned int i=0; i<rowCount; ++i) {
if(parent->child(i, PRIORITY)->text().toInt() != priority) {
// Check if parent priority is NORMAL
QStandardItem *grandFather = parent->parent();
if(!grandFather) {
grandFather = PropListModel->invisibleRootItem();
}
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
editParentsOnly = true;
parentPrio->setText(misc::toQString(NORMAL));
editParentsOnly = false;
parentUpdate = false;
break;
}
}
if(parentUpdate) {
QStandardItem *grandFather = parent->parent(); QStandardItem *grandFather = parent->parent();
if(!grandFather) { if(!grandFather) {
grandFather = PropListModel->invisibleRootItem(); grandFather = PropListModel->invisibleRootItem();
} }
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY); QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
editParentsOnly = true; if(parentPrio->text().toInt() != NORMAL) {
parentPrio->setText(misc::toQString(priority)); parentPrio->setText(misc::toQString(NORMAL));
editParentsOnly = false; // Recursively update ancesters of this parent too
updateParentsPriority(grandFather->child(parent->row()), priority);
}
return;
} }
} }
if(editParentsOnly) return; // All the children have the same priority
if(!is_dir) return; // Parent folder should have the same priority too
// Updating children QStandardItem *grandFather = parent->parent();
qDebug("Priority changed for a folder to %d", priority); if(!grandFather) {
parent = parent->child(row); grandFather = PropListModel->invisibleRootItem();
}
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
if(parentPrio->text().toInt() != priority) {
parentPrio->setText(misc::toQString(priority));
// Recursively update ancesters of this parent too
updateParentsPriority(grandFather->child(parent->row()), priority);
}
}
void updateChildrenPriority(QStandardItem *item, int priority) {
QStandardItem *parent = item->parent();
if(!parent) {
parent = PropListModel->invisibleRootItem();
}
parent = parent->child(item->row());
unsigned int rowCount = parent->rowCount(); unsigned int rowCount = parent->rowCount();
qDebug("The folder has %d children", rowCount);
for(unsigned int i=0; i<rowCount; ++i) { for(unsigned int i=0; i<rowCount; ++i) {
// get child priority QStandardItem * childPrio = parent->child(i, PRIORITY);
QStandardItem *child = parent->child(i, PRIORITY); if(childPrio->text().toInt() != priority) {
int child_prio = child->text().toInt(); childPrio->setText(misc::toQString(priority));
qDebug("Child priority is %d", child_prio); // recursively update children of this child too
if(child_prio != priority) { updateChildrenPriority(parent->child(i), priority);
child->setText(misc::toQString(priority));
} }
} }
} }
void updatePriorities(QStandardItem *item) {
qDebug("Priority changed");
// First we disable the signal/slot on item edition
// temporarily so that it doesn't mess with our manual updates
disconnect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
QStandardItem *parent = item->parent();
if(!parent) {
parent = PropListModel->invisibleRootItem();
}
int priority = parent->child(item->row(), PRIORITY)->text().toInt();
// Update parents priorities
updateParentsPriority(item, priority);
// If this is not a directory, then there are
// no children to update
if(parent->child(item->row(), INDEX)->text().toInt() == -1) {
// Updating children
qDebug("Priority changed for a folder to %d", priority);
updateChildrenPriority(item, priority);
}
// Reconnect the signal/slot on item edition so that we
// get future updates
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
}
void on_browseButton_clicked(){ void on_browseButton_clicked(){
QString dir; QString dir;

Loading…
Cancel
Save