mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-03-13 05:41:17 +00:00
- 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:
parent
2f85dc29b5
commit
86dfbecd2e
26
src/GUI.cpp
26
src/GUI.cpp
@ -719,21 +719,21 @@ void GUI::saveWindowSize() const{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUI::loadFilteredPieces(torrent_handle &h){
|
bool GUI::loadFilteredFiles(torrent_handle &h){
|
||||||
bool has_filtered_pieces = false;
|
bool has_filtered_files = false;
|
||||||
torrent_info torrentInfo = h.get_torrent_info();
|
torrent_info torrentInfo = h.get_torrent_info();
|
||||||
QString fileName = QString(torrentInfo.name().c_str());
|
QString fileName = QString(torrentInfo.name().c_str());
|
||||||
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
||||||
// Read saved file
|
// Read saved file
|
||||||
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
return has_filtered_pieces;
|
return has_filtered_files;
|
||||||
}
|
}
|
||||||
QByteArray pieces_selection = pieces_file.readAll();
|
QByteArray pieces_selection = pieces_file.readAll();
|
||||||
pieces_file.close();
|
pieces_file.close();
|
||||||
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n');
|
QList<QByteArray> pieces_selection_list = pieces_selection.split('\n');
|
||||||
if(pieces_selection_list.size() != torrentInfo.num_files()+1){
|
if(pieces_selection_list.size() != torrentInfo.num_files()+1){
|
||||||
std::cout << "Error: Corrupted pieces file\n";
|
std::cout << "Error: Corrupted pieces file\n";
|
||||||
return has_filtered_pieces;
|
return has_filtered_files;
|
||||||
}
|
}
|
||||||
std::vector<bool> selectionBitmask;
|
std::vector<bool> selectionBitmask;
|
||||||
for(int i=0; i<torrentInfo.num_files(); ++i){
|
for(int i=0; i<torrentInfo.num_files(); ++i){
|
||||||
@ -744,14 +744,14 @@ bool GUI::loadFilteredPieces(torrent_handle &h){
|
|||||||
selectionBitmask.push_back(isFiltered);
|
selectionBitmask.push_back(isFiltered);
|
||||||
// h.filter_piece(i, isFiltered);
|
// h.filter_piece(i, isFiltered);
|
||||||
if(isFiltered){
|
if(isFiltered){
|
||||||
has_filtered_pieces = true;
|
has_filtered_files = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.filter_files(selectionBitmask);
|
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");
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
||||||
// Read saved file
|
// Read saved file
|
||||||
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
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();
|
int row = DLListModel->rowCount();
|
||||||
// Adding files to bittorrent session
|
// 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);
|
h = s->add_torrent(t, fs::path(saveDir.path().toStdString()), resume_data, false);
|
||||||
qDebug("Full allocation mode");
|
qDebug("Full allocation mode");
|
||||||
}else{
|
}else{
|
||||||
@ -1341,8 +1341,8 @@ void GUI::addTorrents(const QStringList& pathsList, bool fromScanDir, const QStr
|
|||||||
}
|
}
|
||||||
h.set_max_connections(60);
|
h.set_max_connections(60);
|
||||||
h.set_max_uploads(-1);
|
h.set_max_uploads(-1);
|
||||||
// Load filtered pieces
|
// Load filtered files
|
||||||
loadFilteredPieces(h);
|
loadFilteredFiles(h);
|
||||||
//qDebug("Added to session");
|
//qDebug("Added to session");
|
||||||
torrent_status torrentStatus = h.status();
|
torrent_status torrentStatus = h.status();
|
||||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
|
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);
|
handles.insert(QString(t.name().c_str()), new_h);
|
||||||
new_h.set_max_connections(60);
|
new_h.set_max_connections(60);
|
||||||
new_h.set_max_uploads(-1);
|
new_h.set_max_uploads(-1);
|
||||||
// Load filtered pieces
|
// Load filtered Files
|
||||||
loadFilteredPieces(new_h);
|
loadFilteredFiles(new_h);
|
||||||
// Adding torrent to download list
|
// Adding torrent to download list
|
||||||
DLListModel->insertRow(row);
|
DLListModel->insertRow(row);
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(t.name().c_str()));
|
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);
|
torrent_handle h = handles.value(fileName);
|
||||||
QStringList errors = trackerErrors.value(fileName, QStringList(tr("None")));
|
QStringList errors = trackerErrors.value(fileName, QStringList(tr("None")));
|
||||||
properties *prop = new properties(this, h, errors);
|
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();
|
prop->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
|||||||
void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker);
|
void addUnauthenticatedTracker(QPair<torrent_handle,std::string> tracker);
|
||||||
void processDownloadedFile(QString url, QString file_path, int return_code, QString errorBuffer);
|
void processDownloadedFile(QString url, QString file_path, int return_code, QString errorBuffer);
|
||||||
void downloadFromURLList(const QStringList& url_list);
|
void downloadFromURLList(const QStringList& url_list);
|
||||||
bool loadFilteredPieces(torrent_handle &h);
|
bool loadFilteredFiles(torrent_handle &h);
|
||||||
bool hasFilteredPieces(const QString& fileName);
|
bool hasFilteredFiles(const QString& fileName);
|
||||||
void reloadTorrent(const torrent_handle &h, bool compact_mode = true);
|
void reloadTorrent(const torrent_handle &h, bool compact_mode = true);
|
||||||
// Search slots
|
// Search slots
|
||||||
void on_search_button_clicked();
|
void on_search_button_clicked();
|
||||||
|
@ -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, 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]));
|
||||||
}
|
}
|
||||||
loadFilteredPieces();
|
loadFilteredFiles();
|
||||||
// Incremental download
|
// Incremental download
|
||||||
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+QString(torrentInfo.name().c_str())+".incremental")){
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+QString(torrentInfo.name().c_str())+".incremental")){
|
||||||
incrementalDownload->setChecked(true);
|
incrementalDownload->setChecked(true);
|
||||||
@ -149,10 +149,11 @@ properties::~properties(){
|
|||||||
delete PropListModel;
|
delete PropListModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void properties::loadFilteredPieces(){
|
void properties::loadFilteredFiles(){
|
||||||
torrent_info torrentInfo = h.get_torrent_info();
|
torrent_info torrentInfo = h.get_torrent_info();
|
||||||
QString fileName = QString(torrentInfo.name().c_str());
|
QString fileName = QString(torrentInfo.name().c_str());
|
||||||
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
||||||
|
has_filtered_files = false;
|
||||||
// Read saved file
|
// Read saved file
|
||||||
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||||
selectionBitmask.assign(torrentInfo.num_files(), 0);
|
selectionBitmask.assign(torrentInfo.num_files(), 0);
|
||||||
@ -172,10 +173,10 @@ void properties::loadFilteredPieces(){
|
|||||||
isFiltered = 0;
|
isFiltered = 0;
|
||||||
}
|
}
|
||||||
selectionBitmask.push_back(isFiltered);
|
selectionBitmask.push_back(isFiltered);
|
||||||
// h.filter_piece(i, isFiltered);
|
|
||||||
if(isFiltered){
|
if(isFiltered){
|
||||||
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(false));
|
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(false));
|
||||||
setRowColor(i, "red");
|
setRowColor(i, "red");
|
||||||
|
has_filtered_files = true;
|
||||||
}else{
|
}else{
|
||||||
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(true));
|
PropListModel->setData(PropListModel->index(i, SELECTED), QVariant(true));
|
||||||
setRowColor(i, "green");
|
setRowColor(i, "green");
|
||||||
@ -207,7 +208,6 @@ void properties::toggleSelectedState(const QModelIndex& index){
|
|||||||
// File is selected
|
// File is selected
|
||||||
selectionBitmask.erase(selectionBitmask.begin()+row);
|
selectionBitmask.erase(selectionBitmask.begin()+row);
|
||||||
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
|
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
|
||||||
// h.filter_piece(row, false);
|
|
||||||
// Update list infos
|
// Update list infos
|
||||||
setRowColor(row, "green");
|
setRowColor(row, "green");
|
||||||
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
|
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
|
||||||
@ -215,14 +215,13 @@ void properties::toggleSelectedState(const QModelIndex& index){
|
|||||||
// File is not selected
|
// File is not selected
|
||||||
selectionBitmask.erase(selectionBitmask.begin()+row);
|
selectionBitmask.erase(selectionBitmask.begin()+row);
|
||||||
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
|
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
|
||||||
// h.filter_piece(row, true);
|
|
||||||
// Update list infos
|
// Update list infos
|
||||||
setRowColor(row, "red");
|
setRowColor(row, "red");
|
||||||
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
|
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
|
||||||
}
|
}
|
||||||
h.filter_files(selectionBitmask);
|
h.filter_files(selectionBitmask);
|
||||||
// Save filtered pieces to a file to remember them
|
// Save filtered pieces to a file to remember them
|
||||||
saveFilteredPieces();
|
saveFilteredFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void properties::on_incrementalDownload_stateChanged(int){
|
void properties::on_incrementalDownload_stateChanged(int){
|
||||||
@ -252,7 +251,6 @@ void properties::on_select_clicked(){
|
|||||||
selectionBitmask.erase(selectionBitmask.begin()+row);
|
selectionBitmask.erase(selectionBitmask.begin()+row);
|
||||||
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
|
selectionBitmask.insert(selectionBitmask.begin()+row, 0);
|
||||||
h.filter_files(selectionBitmask);
|
h.filter_files(selectionBitmask);
|
||||||
// h.filter_piece(row, false);
|
|
||||||
// Update list infos
|
// Update list infos
|
||||||
setRowColor(row, "green");
|
setRowColor(row, "green");
|
||||||
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(true));
|
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
|
// Save filtered pieces to a file to remember them
|
||||||
saveFilteredPieces();
|
saveFilteredFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void properties::on_okButton_clicked(){
|
void properties::on_okButton_clicked(){
|
||||||
@ -279,20 +277,19 @@ void properties::on_unselect_clicked(){
|
|||||||
selectionBitmask.erase(selectionBitmask.begin()+row);
|
selectionBitmask.erase(selectionBitmask.begin()+row);
|
||||||
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
|
selectionBitmask.insert(selectionBitmask.begin()+row, 1);
|
||||||
h.filter_files(selectionBitmask);
|
h.filter_files(selectionBitmask);
|
||||||
// h.filter_piece(row, true);
|
|
||||||
// Update list infos
|
// Update list infos
|
||||||
setRowColor(row, "red");
|
setRowColor(row, "red");
|
||||||
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
|
PropListModel->setData(PropListModel->index(row, SELECTED), QVariant(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Save filtered pieces to a file to remember them
|
// Save filtered files to a file to remember them
|
||||||
saveFilteredPieces();
|
saveFilteredFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
void properties::saveFilteredPieces(){
|
void properties::saveFilteredFiles(){
|
||||||
torrent_info torrentInfo = h.get_torrent_info();
|
torrent_info torrentInfo = h.get_torrent_info();
|
||||||
bool hasFilteredPieces = 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()+fileName+".pieces");
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileName+".pieces");
|
||||||
// First, remove old file
|
// First, remove old file
|
||||||
@ -307,9 +304,14 @@ void properties::saveFilteredPieces(){
|
|||||||
pieces_file.write(QByteArray("1\n"));
|
pieces_file.write(QByteArray("1\n"));
|
||||||
}else{
|
}else{
|
||||||
pieces_file.write(QByteArray("0\n"));
|
pieces_file.write(QByteArray("0\n"));
|
||||||
hasFilteredPieces = true;
|
hasFilteredFiles = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pieces_file.close();
|
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;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ class properties : public QDialog, private Ui::properties{
|
|||||||
QStandardItemModel *PropListModel;
|
QStandardItemModel *PropListModel;
|
||||||
QTimer *updateProgressTimer;
|
QTimer *updateProgressTimer;
|
||||||
std::vector<bool> selectionBitmask;
|
std::vector<bool> selectionBitmask;
|
||||||
|
bool has_filtered_files;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_select_clicked();
|
void on_select_clicked();
|
||||||
@ -47,12 +48,12 @@ class properties : public QDialog, private Ui::properties{
|
|||||||
void on_incrementalDownload_stateChanged(int);
|
void on_incrementalDownload_stateChanged(int);
|
||||||
void setRowColor(int row, QString color);
|
void setRowColor(int row, QString color);
|
||||||
void toggleSelectedState(const QModelIndex& index);
|
void toggleSelectedState(const QModelIndex& index);
|
||||||
void saveFilteredPieces();
|
void saveFilteredFiles();
|
||||||
void updateProgress();
|
void updateProgress();
|
||||||
void loadFilteredPieces();
|
void loadFilteredFiles();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changedFilteredPieces(torrent_handle h, bool compact_mode);
|
void changedFilteredFiles(torrent_handle h, bool compact_mode);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user