- Renamed some ambiguous functions

- Reload torrents only when we need to enable full allocation mode (not everytime we change files selection)
This commit is contained in:
Christophe Dumez 2006-10-08 01:01:34 +00:00
parent 2f85dc29b5
commit 86dfbecd2e
4 changed files with 36 additions and 33 deletions

View File

@ -719,21 +719,21 @@ void GUI::saveWindowSize() const{
}
}
bool GUI::loadFilteredPieces(torrent_handle &h){
bool has_filtered_pieces = false;
bool GUI::loadFilteredFiles(torrent_handle &h){
bool has_filtered_files = false;
torrent_info torrentInfo = h.get_torrent_info();
QString fileName = QString(torrentInfo.name().c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
return has_filtered_pieces;
return has_filtered_files;
}
QByteArray pieces_selection = pieces_file.readAll();
pieces_file.close();
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n');
if(pieces_selection_list.size() != torrentInfo.num_files()+1){
std::cout << "Error: Corrupted pieces file\n";
return has_filtered_pieces;
return has_filtered_files;
}
std::vector<bool> selectionBitmask;
for(int i=0; i<torrentInfo.num_files(); ++i){
@ -744,14 +744,14 @@ bool GUI::loadFilteredPieces(torrent_handle &h){
selectionBitmask.push_back(isFiltered);
// h.filter_piece(i, isFiltered);
if(isFiltered){
has_filtered_pieces = true;
has_filtered_files = true;
}
}
h.filter_files(selectionBitmask);
return has_filtered_pieces;
return has_filtered_files;
}
bool GUI::hasFilteredPieces(const QString& fileName){
bool GUI::hasFilteredFiles(const QString& fileName){
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
@ -1332,7 +1332,7 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr
}
int row = DLListModel->rowCount();
// Adding files to bittorrent session
if(hasFilteredPieces(QString(t.name().c_str()))){
if(hasFilteredFiles(QString(t.name().c_str()))){
h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resume_data, false);
qDebug("Full allocation mode");
}else{
@ -1341,8 +1341,8 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr
}
h.set_max_connections(60);
h.set_max_uploads(-1);
// Load filtered pieces
loadFilteredPieces(h);
// Load filtered files
loadFilteredFiles(h);
//qDebug("Added to session");
torrent_status torrentStatus = h.status();
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
@ -1494,8 +1494,8 @@ void GUI::reloadTorrent(const torrent_handle &h, bool compact_mode){
handles.insert(QString(t.name().c_str()), new_h);
new_h.set_max_connections(60);
new_h.set_max_uploads(-1);
// Load filtered pieces
loadFilteredPieces(new_h);
// Load filtered Files
loadFilteredFiles(new_h);
// Adding torrent to download list
DLListModel->insertRow(row);
DLListModel->setData(DLListModel->index(row, NAME), QVariant(t.name().c_str()));
@ -1555,7 +1555,7 @@ void GUI::showProperties(const QModelIndex &index){
torrent_handle h = handles.value(fileName);
QStringList errors = trackerErrors.value(fileName, QStringList(tr("None")));
properties *prop = new properties(this, h, errors);
connect(prop, SIGNAL(changedFilteredPieces(torrent_handle, bool)), this, SLOT(reloadTorrent(torrent_handle, bool)));
connect(prop, SIGNAL(changedFilteredFiles(torrent_handle, bool)), this, SLOT(reloadTorrent(torrent_handle, bool)));
prop->show();
}

View File

@ -153,8 +153,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker);
void processDownloadedFile(QString url, QString file_path, int return_code, QString errorBuffer);
void downloadFromURLList(const QStringList& url_list);
bool loadFilteredPieces(torrent_handle &h);
bool hasFilteredPieces(const QString& fileName);
bool loadFilteredFiles(torrent_handle &h);
bool hasFilteredFiles(const QString& fileName);
void reloadTorrent(const torrent_handle &h, bool compact_mode = true);
// Search slots
void on_search_button_clicked();

View File

@ -131,7 +131,7 @@ properties::properties(QWidget *parent, torrent_handle h, QStringList trackerErr
PropListModel->setData(PropListModel->index(row, SIZE), QVariant((qlonglong)torrentInfo.file_at(i).size));
PropListModel->setData(PropListModel->index(row, PROGRESS), QVariant((double)fp[i]));
}
loadFilteredPieces();
loadFilteredFiles();
// Incremental download
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+QString(torrentInfo.name().c_str())+".incremental")){
incrementalDownload->setChecked(true);
@ -149,10 +149,11 @@ properties::~properties(){
delete PropListModel;
}
void properties::loadFilteredPieces(){
void properties::loadFilteredFiles(){
torrent_info torrentInfo = h.get_torrent_info();
QString fileName = QString(torrentInfo.name().c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
has_filtered_files = false;
// Read saved file
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
selectionBitmask.assign(torrentInfo.num_files(), 0);
@ -172,10 +173,10 @@ void properties::loadFilteredPieces(){
isFiltered = 0;
}
selectionBitmask.push_back(isFiltered);
// h.filter_piece(i, isFiltered);
if(isFiltered){
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(false));
setRowColor(i, "red");
has_filtered_files = true;
}else{
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(true));
setRowColor(i, "green");
@ -207,7 +208,6 @@ void properties::toggleSelectedState(const QModelIndex& index){
// File is selected
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
// h.filter_piece(row, false);
// Update list infos
setRowColor(row, "green");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
@ -215,14 +215,13 @@ void properties::toggleSelectedState(const QModelIndex& index){
// File is not selected
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
// h.filter_piece(row, true);
// Update list infos
setRowColor(row, "red");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
}
h.filter_files(selectionBitmask);
// Save filtered pieces to a file to remember them
saveFilteredPieces();
saveFilteredFiles();
}
void properties::on_incrementalDownload_stateChanged(int){
@ -252,7 +251,6 @@ void properties::on_select_clicked(){
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
h.filter_files(selectionBitmask);
// h.filter_piece(row, false);
// Update list infos
setRowColor(row, "green");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
@ -260,7 +258,7 @@ void properties::on_select_clicked(){
}
}
// Save filtered pieces to a file to remember them
saveFilteredPieces();
saveFilteredFiles();
}
void properties::on_okButton_clicked(){
@ -279,20 +277,19 @@ void properties::on_unselect_clicked(){
selectionBitmask.erase(selectionBitmask.begin()+row);
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
h.filter_files(selectionBitmask);
// h.filter_piece(row, true);
// Update list infos
setRowColor(row, "red");
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
}
}
}
// Save filtered pieces to a file to remember them
saveFilteredPieces();
// Save filtered files to a file to remember them
saveFilteredFiles();
}
void properties::saveFilteredPieces(){
void properties::saveFilteredFiles(){
torrent_info torrentInfo = h.get_torrent_info();
bool hasFilteredPieces = false;
bool hasFilteredFiles = false;
QString fileName = QString(torrentInfo.name().c_str());
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
// First, remove old file
@ -307,9 +304,14 @@ void properties::saveFilteredPieces(){
pieces_file.write(QByteArray("1\n"));
}else{
pieces_file.write(QByteArray("0\n"));
hasFilteredPieces = true;
hasFilteredFiles = true;
}
}
pieces_file.close();
emit changedFilteredPieces(h, !hasFilteredPieces);
if(!has_filtered_files){
// Don't need to reload torrent
// if already in full allocation mode
emit changedFilteredFiles(h, !hasFilteredFiles);
}
has_filtered_files = hasFilteredFiles;
}

View File

@ -39,6 +39,7 @@ class properties : public QDialog, private Ui::properties{
QStandardItemModel *PropListModel;
QTimer *updateProgressTimer;
std::vector<bool> selectionBitmask;
bool has_filtered_files;
protected slots:
void on_select_clicked();
@ -47,12 +48,12 @@ class properties : public QDialog, private Ui::properties{
void on_incrementalDownload_stateChanged(int);
void setRowColor(int row, QString color);
void toggleSelectedState(const QModelIndex& index);
void saveFilteredPieces();
void saveFilteredFiles();
void updateProgress();
void loadFilteredPieces();
void loadFilteredFiles();
signals:
void changedFilteredPieces(torrent_handle h, bool compact_mode);
void changedFilteredFiles(torrent_handle h, bool compact_mode);
public:
// Constructor