Browse Source

- Implemented files prioritizing in a torrent (Part I: Torrent Properties), still need to work on torrent addition dialog

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
ff3575c7ac
  1. 1
      Changelog
  2. 6
      TODO
  3. 88
      src/PropListDelegate.h
  4. 51
      src/bittorrent.cpp
  5. 59
      src/properties.ui
  6. 116
      src/properties_imp.cpp
  7. 9
      src/properties_imp.h

1
Changelog

@ -1,6 +1,7 @@
* Unknown - Christophe Dumez <chris@qbittorrent.org> - v0.10.0 * Unknown - Christophe Dumez <chris@qbittorrent.org> - v0.10.0
- FEATURE: Added UPnP / NAT-PMP port forwarding support - FEATURE: Added UPnP / NAT-PMP port forwarding support
- FEATURE: Added RSS support - FEATURE: Added RSS support
- FEATURE: Support files prioritizing in a torrent
- FEATURE: Finished torrents are now moved to another tab for seeding - FEATURE: Finished torrents are now moved to another tab for seeding
- FEATURE: Display more infos about the torrent in its properties - FEATURE: Display more infos about the torrent in its properties
- FEATURE: Allow the user to edit torrents' trackers - FEATURE: Allow the user to edit torrents' trackers

6
TODO

@ -29,7 +29,7 @@
- Add a torrent scheduler - Add a torrent scheduler
- Improve Ipfilter.dat parser (move to a thread ? - too slow to load qBT and more importantly options) - Improve Ipfilter.dat parser (move to a thread ? - too slow to load qBT and more importantly options)
// in v0.11 // in v1.1.0
- Tabs support in search - Tabs support in search
// in v1.0.0 (partial) - WIP // in v1.0.0 (partial) - WIP
@ -41,8 +41,8 @@
- Use tooltips to explain options? - Use tooltips to explain options?
- Display more info in log (UPnP) - Display more info in log (UPnP)
- Update to libtorrent SVN (0.13) - DONE - Update to libtorrent SVN (0.13) - DONE
- Use its UPnP/NAT-PMP built-in support instead of ours ALMOST - Use its UPnP/NAT-PMP built-in support instead of ours DONE (enabled as a default)
- Use its piece prioritization support - Use its piece prioritization support (debug)
- Get upload/download limit per torrent (uncomment some code) ALMOST - Get upload/download limit per torrent (uncomment some code) ALMOST
- Improve ratio display / calculation / saving / per torrent... - Improve ratio display / calculation / saving / per torrent...
- Display the sum of the size of the selected files in the torrent instead of the whole torrent size in download list - Display the sum of the size of the selected files in the torrent instead of the whole torrent size in download list

88
src/PropListDelegate.h

@ -36,7 +36,12 @@
#define NAME 0 #define NAME 0
#define SIZE 1 #define SIZE 1
#define PROGRESS 2 #define PROGRESS 2
#define SELECTED 3 #define PRIORITY 3
#define IGNORED 0
#define NORMAL 1
#define HIGH 2
#define MAXIMUM 7
class PropListDelegate: public QItemDelegate { class PropListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT
@ -103,19 +108,27 @@ class PropListDelegate: public QItemDelegate {
painter->drawText(option.rect, Qt::AlignCenter, newopt.text); painter->drawText(option.rect, Qt::AlignCenter, newopt.text);
break; break;
} }
case SELECTED:{ case PRIORITY:{
QStyleOptionComboBox newopt; QStyleOptionComboBox newopt;
newopt.rect = opt.rect; newopt.rect = opt.rect;
if(index.data().toBool()){ switch(index.data().toInt()){
// painter->drawText(option.rect, Qt::AlignCenter, tr("True")); case IGNORED:
newopt.currentText = tr("True"); newopt.currentText = tr("Ignored");
}else{ break;
// painter->drawText(option.rect, Qt::AlignCenter, tr("False")); case NORMAL:
newopt.currentText = tr("False"); newopt.currentText = tr("Normal", "Normal (priority)");
break;
case HIGH:
newopt.currentText = tr("High", "High (priority)");
break;
case MAXIMUM:
newopt.currentText = tr("Maximum", "Maximum (priority)");
break;
default:
qDebug("Unhandled priority, setting NORMAL");
newopt.currentText = tr("Normal", "Normal (priority)");
} }
newopt.state |= QStyle::State_Enabled; newopt.state |= QStyle::State_Enabled;
// newopt.frame = true;
// newopt.editable = true;
QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &newopt, QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &newopt,
painter); painter);
opt.palette.setColor(QPalette::Text, QColor("black")); opt.palette.setColor(QPalette::Text, QColor("black"));
@ -129,29 +142,38 @@ class PropListDelegate: public QItemDelegate {
} }
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const { QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index) const {
if(index.column() != SELECTED) return 0; if(index.column() != PRIORITY) return 0;
QComboBox* editor = new QComboBox(parent); QComboBox* editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus); editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("True")); editor->addItem(tr("Ignored"));
editor->addItem(tr("False")); editor->addItem(tr("Normal", "Normal (priority)"));
editor->addItem(tr("High", "High (priority)"));
editor->addItem(tr("Maximum", "Maximum (priority)"));
return editor; return editor;
} }
void setEditorData(QWidget *editor, const QModelIndex &index) const { void setEditorData(QWidget *editor, const QModelIndex &index) const {
bool value = index.model()->data(index, Qt::DisplayRole).toBool(); unsigned short val = index.model()->data(index, Qt::DisplayRole).toInt();
QComboBox *combobox = static_cast<QComboBox*>(editor); QComboBox *combobox = static_cast<QComboBox*>(editor);
if(value) { switch(val){
combobox->setCurrentIndex(0); case IGNORED:
} else { combobox->setCurrentIndex(0);
combobox->setCurrentIndex(1); break;
case NORMAL:
combobox->setCurrentIndex(1);
break;
case HIGH:
combobox->setCurrentIndex(2);
break;
case MAXIMUM:
combobox->setCurrentIndex(3);
break;
default:
qDebug("Unhandled priority, setting to NORMAL");
combobox->setCurrentIndex(1);
} }
} }
// bool editorEvent(QEvent * event, QAbstractItemModel * model, const QStyleOptionViewItem & option, const QModelIndex & index ){
// qDebug("Event!!!!");
// return false;
// }
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{ QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{
QVariant value = index.data(Qt::FontRole); QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font; QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
@ -168,13 +190,27 @@ class PropListDelegate: public QItemDelegate {
int value = combobox->currentIndex(); int value = combobox->currentIndex();
qDebug("Setting combobox value in index: %d", value); qDebug("Setting combobox value in index: %d", value);
QString color; QString color;
if(value == 0) { if(value) {
model->setData(index, true);
color = "green"; color = "green";
} else { } else {
model->setData(index, false);
color = "red"; color = "red";
} }
switch(value){
case 0:
model->setData(index, QVariant(IGNORED));
break;
case 1:
model->setData(index, QVariant(NORMAL));
break;
case 2:
model->setData(index, QVariant(HIGH));
break;
case 3:
model->setData(index, QVariant(MAXIMUM));
break;
default:
model->setData(index, QVariant(NORMAL));
}
for(int i=0; i<model->columnCount(); ++i){ for(int i=0; i<model->columnCount(); ++i){
model->setData(model->index(index.row(), i), QVariant(QColor(color)), Qt::TextColorRole); model->setData(model->index(index.row(), i), QVariant(QColor(color)), Qt::TextColorRole);
} }

51
src/bittorrent.cpp

@ -162,8 +162,9 @@ void bittorrent::deleteTorrent(const QString& hash, bool permanent){
torrentBackup.remove(hash+".fastresume"); torrentBackup.remove(hash+".fastresume");
torrentBackup.remove(hash+".paused"); torrentBackup.remove(hash+".paused");
torrentBackup.remove(hash+".incremental"); torrentBackup.remove(hash+".incremental");
torrentBackup.remove(hash+".pieces"); torrentBackup.remove(hash+".priorities");
torrentBackup.remove(hash+".savepath"); torrentBackup.remove(hash+".savepath");
torrentBackup.remove(hash+".trackers");
if(permanent){ if(permanent){
// Remove from Hard drive // Remove from Hard drive
qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName)); qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName));
@ -249,11 +250,11 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString
if(torrentBackup.exists(QString(t.name().c_str())+".torrent")){ if(torrentBackup.exists(QString(t.name().c_str())+".torrent")){
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".torrent", torrentBackup.path()+QDir::separator()+hash+".torrent"); QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".torrent", torrentBackup.path()+QDir::separator()+hash+".torrent");
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".fastresume", torrentBackup.path()+QDir::separator()+hash+".fastresume"); QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".fastresume", torrentBackup.path()+QDir::separator()+hash+".fastresume");
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".pieces", torrentBackup.path()+QDir::separator()+hash+".pieces");
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".savepath", torrentBackup.path()+QDir::separator()+hash+".savepath"); QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".savepath", torrentBackup.path()+QDir::separator()+hash+".savepath");
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".paused", torrentBackup.path()+QDir::separator()+hash+".paused"); QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".paused", torrentBackup.path()+QDir::separator()+hash+".paused");
QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".incremental", torrentBackup.path()+QDir::separator()+hash+".incremental"); QFile::rename(torrentBackup.path()+QDir::separator()+QString(t.name().c_str())+".incremental", torrentBackup.path()+QDir::separator()+hash+".incremental");
file = torrentBackup.path() + QDir::separator() + hash + ".torrent"; file = torrentBackup.path() + QDir::separator() + hash + ".torrent";
} }
//Getting fast resume data if existing //Getting fast resume data if existing
if(torrentBackup.exists(hash+".fastresume")){ if(torrentBackup.exists(hash+".fastresume")){
@ -364,23 +365,24 @@ void bittorrent::setMaxConnections(int maxConnec){
s->set_max_connections(maxConnec); s->set_max_connections(maxConnec);
} }
// Check in .pieces file if the user filtered files // Check in .priorities file if the user filtered files
// in this torrent. // in this torrent.
bool bittorrent::hasFilteredFiles(const QString& fileHash) const{ bool bittorrent::hasFilteredFiles(const QString& fileHash) const{
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".pieces"); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".priorities");
// Read saved file // Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){ if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
return false; return false;
} }
QByteArray pieces_selection = pieces_file.readAll(); QByteArray pieces_text = pieces_file.readAll();
pieces_file.close(); pieces_file.close();
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n'); QList<QByteArray> pieces_priorities_list = pieces_text.split('\n');
for(int i=0; i<pieces_selection_list.size()-1; ++i){ unsigned int listSize = pieces_priorities_list.size();
int isFiltered = pieces_selection_list.at(i).toInt(); for(unsigned int i=0; i<listSize-1; ++i){
if( isFiltered < 0 || isFiltered > 1){ int priority = pieces_priorities_list.at(i).toInt();
isFiltered = 0; if( priority < 0 || priority > 7){
} priority = 1;
if(isFiltered){ }
if(!priority){
return true; return true;
} }
} }
@ -419,36 +421,35 @@ void bittorrent::disableDHT(){
} }
} }
// Read filtered pieces from .pieces file // Read pieces priorities from .priorities file
// and ask torrent_handle to filter them // and ask torrent_handle to consider them
void bittorrent::loadFilteredFiles(torrent_handle &h){ void bittorrent::loadFilteredFiles(torrent_handle &h){
torrent_info torrentInfo = h.get_torrent_info(); torrent_info torrentInfo = h.get_torrent_info();
unsigned int nbTorrents = torrentInfo.num_files();
if(!h.is_valid()){ if(!h.is_valid()){
qDebug("/!\\ Error: Invalid handle"); qDebug("/!\\ Error: Invalid handle");
return; return;
} }
QString fileHash = QString(misc::toString(torrentInfo.info_hash()).c_str()); QString fileHash = QString(misc::toString(torrentInfo.info_hash()).c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".pieces"); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".priorities");
// Read saved file // Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){ if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
return; return;
} }
QByteArray pieces_selection = pieces_file.readAll(); QByteArray pieces_priorities = pieces_file.readAll();
pieces_file.close(); pieces_file.close();
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n'); QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
if(pieces_selection_list.size() != torrentInfo.num_files()+1){ if((unsigned int)pieces_priorities_list.size() != nbTorrents+1){
std::cerr << "Error: Corrupted pieces file\n"; std::cerr << "Error: Corrupted pieces file\n";
return; return;
} }
std::vector<bool> selectionBitmask; for(unsigned int i=0; i<nbTorrents; ++i){
for(int i=0; i<torrentInfo.num_files(); ++i){ int priority = pieces_priorities_list.at(i).toInt();
int isFiltered = pieces_selection_list.at(i).toInt(); if( priority < 0 || priority > 7){
if( isFiltered < 0 || isFiltered > 1){ priority = 1;
isFiltered = 0;
} }
selectionBitmask.push_back(isFiltered); h.piece_priority(i, priority);
} }
h.filter_files(selectionBitmask);
} }
// Save fastresume data for all torrents // Save fastresume data for all torrents

59
src/properties.ui

@ -874,57 +874,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <widget class="QLabel" name="lbl_priorities" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="unselect" >
<property name="text" >
<string> Unselect</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="select" >
<property name="text" >
<string> Select</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_7" >
<property name="font" > <property name="font" >
<font> <font>
<family>Sans Serif</family> <family>Sans Serif</family>
@ -937,10 +887,13 @@
</font> </font>
</property> </property>
<property name="text" > <property name="text" >
<string>You can select here precisely which files you want to download in current torrent.</string> <string/>
</property> </property>
<property name="alignment" > <property name="alignment" >
<set>Qt::AlignCenter</set> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>

116
src/properties_imp.cpp

@ -27,9 +27,8 @@
// Constructor // Constructor
properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerErrors): QDialog(parent), h(h){ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerErrors): QDialog(parent), h(h){
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>");
// set icons // set icons
unselect->setIcon(QIcon(QString::fromUtf8(":/Icons/button_cancel.png")));
select->setIcon(QIcon(QString::fromUtf8(":/Icons/button_ok.png")));
addTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png"))); addTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/add.png")));
removeTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png"))); removeTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/remove.png")));
lowerTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/downarrow.png"))); lowerTracker_button->setIcon(QIcon(QString::fromUtf8(":/Icons/downarrow.png")));
@ -37,10 +36,10 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
// Set Properties list model // Set Properties list model
PropListModel = new QStandardItemModel(0,4); PropListModel = new QStandardItemModel(0,4);
PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File Name")); PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File name"));
PropListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size")); PropListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
PropListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress")); PropListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
PropListModel->setHeaderData(SELECTED, Qt::Horizontal, tr("Selected")); PropListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Priority"));
filesList->setModel(PropListModel); filesList->setModel(PropListModel);
PropDelegate = new PropListDelegate(); PropDelegate = new PropListDelegate();
filesList->setItemDelegate(PropDelegate); filesList->setItemDelegate(PropDelegate);
@ -92,7 +91,7 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr
PropListModel->setData(PropListModel->index(row, SIZE), QVariant((qlonglong)torrentInfo.file_at(i).size)); PropListModel->setData(PropListModel->index(row, SIZE), QVariant((qlonglong)torrentInfo.file_at(i).size));
PropListModel->setData(PropListModel->index(row, PROGRESS), QVariant((double)fp[i])); PropListModel->setData(PropListModel->index(row, PROGRESS), QVariant((double)fp[i]));
} }
loadFilteredFiles(); loadPiecesPriorities();
// Incremental download // Incremental download
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".incremental")){ if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".incremental")){
incrementalDownload->setChecked(true); incrementalDownload->setChecked(true);
@ -111,42 +110,40 @@ properties::~properties(){
delete PropListModel; delete PropListModel;
} }
void properties::loadFilteredFiles(){ void properties::loadPiecesPriorities(){
torrent_info torrentInfo = h.get_torrent_info(); torrent_info torrentInfo = h.get_torrent_info();
unsigned int nbFiles = torrentInfo.num_files();
QString fileName = QString(torrentInfo.name().c_str()); QString fileName = QString(torrentInfo.name().c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".pieces"); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".priorities");
has_filtered_files = false; has_filtered_files = false;
qDebug("Loading filtered state of files"); qDebug("Loading pieces priorities");
// Read saved file // Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){ if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug("Could not find pieces file"); qDebug("Could not find pieces file");
setAllPiecesState(true); setAllPiecesState(NORMAL);
selectionBitmask.assign(torrentInfo.num_files(), 0);
return; return;
} }
QByteArray pieces_selection = pieces_file.readAll(); QByteArray pieces_text = pieces_file.readAll();
pieces_file.close(); pieces_file.close();
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n'); QList<QByteArray> pieces_priority_list = pieces_text.split('\n');
if(pieces_selection_list.size() != torrentInfo.num_files()+1){ if((unsigned int)pieces_priority_list.size() != nbFiles+1){
std::cerr << "Error: Corrupted pieces file\n"; std::cerr << "Error: Corrupted pieces file\n";
setAllPiecesState(true); setAllPiecesState(NORMAL);
selectionBitmask.assign(torrentInfo.num_files(), 0);
return; return;
} }
for(int i=0; i<torrentInfo.num_files(); ++i){ for(unsigned int i=0; i<nbFiles; ++i){
int isFiltered = pieces_selection_list.at(i).toInt(); int priority = pieces_priority_list.at(i).toInt();
if( isFiltered < 0 || isFiltered > 1){ if( priority < 0 || priority > 7){
isFiltered = 0; // Normal priority as default
priority = 1;
} }
selectionBitmask.push_back(isFiltered); if(!priority){
if(isFiltered){
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(false));
setRowColor(i, "red"); setRowColor(i, "red");
has_filtered_files = true; has_filtered_files = true;
}else{ }else{
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(true));
setRowColor(i, "green"); setRowColor(i, "green");
} }
PropListModel->setData(PropListModel->index(i, PRIORITY), QVariant(priority));
} }
} }
@ -290,15 +287,15 @@ void properties::setRowColor(int row, QString color){
} }
} }
void properties::setAllPiecesState(bool selected){ void properties::setAllPiecesState(unsigned short priority){
torrent_info torrentInfo = h.get_torrent_info(); torrent_info torrentInfo = h.get_torrent_info();
for(int i=0; i<torrentInfo.num_files(); ++i){ for(int i=0; i<torrentInfo.num_files(); ++i){
if(selected){ if(priority){
setRowColor(i, "green"); setRowColor(i, "green");
}else{ }else{
setRowColor(i, "red"); setRowColor(i, "red");
} }
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(selected)); PropListModel->setData(PropListModel->index(i, PRIORITY), QVariant(priority));
} }
} }
@ -317,77 +314,32 @@ void properties::on_incrementalDownload_stateChanged(int){
} }
} }
// Resume download of specified files of torrent
void properties::on_select_clicked(){
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index;
foreach(index, selectedIndexes){
if(index.column() == NAME){
int row = index.row();
if(selectionBitmask.at(row)){
// File is selected
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
h.filter_files(selectionBitmask);
// Update list infos
setRowColor(row, "green");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
}
}
}
// Save filtered pieces to a file to remember them
if(selectedIndexes.size() != 0){
saveFilteredFiles();
}
}
void properties::on_okButton_clicked(){ void properties::on_okButton_clicked(){
savePiecesPriorities();
close(); close();
} }
// Cancel download of specified files of torrent void properties::savePiecesPriorities(){
void properties::on_unselect_clicked(){ qDebug("Saving pieces priorities");
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedIndexes();
QModelIndex index;
foreach(index, selectedIndexes){
if(index.column() == NAME){
int row = index.row();
if(!selectionBitmask.at(row)){
// File is selected
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
h.filter_files(selectionBitmask);
// Update list infos
setRowColor(row, "red");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
}
}
}
// Save filtered files to a file to remember them
if(selectedIndexes.size() != 0){
saveFilteredFiles();
}
}
void properties::saveFilteredFiles(){
torrent_info torrentInfo = h.get_torrent_info(); torrent_info torrentInfo = h.get_torrent_info();
bool hasFilteredFiles = false; bool hasFilteredFiles = false;
QString fileName = QString(torrentInfo.name().c_str()); QString fileName = QString(torrentInfo.name().c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".pieces"); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".priorities");
// First, remove old file // First, remove old file
pieces_file.remove(); pieces_file.remove();
// Write new files // Write new files
if(!pieces_file.open(QIODevice::WriteOnly | QIODevice::Text)){ if(!pieces_file.open(QIODevice::WriteOnly | QIODevice::Text)){
std::cerr << "Error: Could not save filtered pieces\n"; std::cerr << "Error: Could not save pieces priorities\n";
return; return;
} }
for(int i=0; i<torrentInfo.num_files(); ++i){ unsigned int nbRows = PropListModel->rowCount();
if(selectionBitmask.at(i)){ for(unsigned int i=0; i<nbRows; ++i){
pieces_file.write(QByteArray("1\n")); QStandardItem *item = PropListModel->item(i, PRIORITY);
}else{ unsigned short priority = item->text().toInt();
pieces_file.write(QByteArray("0\n")); if(!priority) {
hasFilteredFiles = true; hasFilteredFiles = true;
} }
pieces_file.write(QByteArray((misc::toString(priority)+"\n").c_str()));
} }
pieces_file.close(); pieces_file.close();
if(!has_filtered_files){ if(!has_filtered_files){

9
src/properties_imp.h

@ -39,19 +39,16 @@ class properties : public QDialog, private Ui::properties{
PropListDelegate *PropDelegate; PropListDelegate *PropDelegate;
QStandardItemModel *PropListModel; QStandardItemModel *PropListModel;
QTimer *updateProgressTimer; QTimer *updateProgressTimer;
std::vector<bool> selectionBitmask;
bool has_filtered_files; bool has_filtered_files;
protected slots: protected slots:
void on_select_clicked();
void on_unselect_clicked();
void on_okButton_clicked(); void on_okButton_clicked();
void on_incrementalDownload_stateChanged(int); void on_incrementalDownload_stateChanged(int);
void setRowColor(int row, QString color); void setRowColor(int row, QString color);
void saveFilteredFiles(); void savePiecesPriorities();
void updateProgress(); void updateProgress();
void loadFilteredFiles(); void loadPiecesPriorities();
void setAllPiecesState(bool selected); void setAllPiecesState(unsigned short priority);
void askForTracker(); void askForTracker();
void loadTrackers(); void loadTrackers();
void deleteSelectedTrackers(); void deleteSelectedTrackers();

Loading…
Cancel
Save