mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-09 07:40:19 +08:00
- Fixed size update when filtering files in a torrent (broken in svn)
This commit is contained in:
parent
4657ee9087
commit
c8e4894d85
3
TODO
3
TODO
@ -46,4 +46,5 @@
|
||||
- Allow to scan multiple directories
|
||||
- Fix all (or almost all) opened bugs in bug tracker
|
||||
- Fix sorting with Qt 4.3 - Reported to Trolltech, waiting for fix
|
||||
- update sorting when a new torrent is added
|
||||
- update sorting when a new torrent is added
|
||||
- properties: reload torrent only if priorities changed
|
18
src/GUI.cpp
18
src/GUI.cpp
@ -593,7 +593,7 @@ void GUI::restoreInDownloadList(torrent_handle h){
|
||||
// Adding torrent to download list
|
||||
DLListModel->insertRow(row);
|
||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(h.name().c_str()));
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)torrentEffectiveSize(hash)));
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)BTSession.torrentEffectiveSize(hash)));
|
||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.));
|
||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.));
|
||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant("0/0"));
|
||||
@ -1057,18 +1057,6 @@ void GUI::on_actionDelete_triggered(){
|
||||
}
|
||||
}
|
||||
|
||||
size_type GUI::torrentEffectiveSize(QString hash) const{
|
||||
torrent_handle h = BTSession.getTorrentHandle(hash);
|
||||
torrent_info t = h.get_torrent_info();
|
||||
unsigned short nbFiles = t.num_files();
|
||||
size_type effective_size = 0;
|
||||
for(unsigned int i=0; i<nbFiles; ++i){
|
||||
if(h.piece_priority(i) != 0)
|
||||
effective_size += t.file_at(i).size;
|
||||
}
|
||||
return effective_size;
|
||||
}
|
||||
|
||||
// Called when a torrent is added
|
||||
void GUI::torrentAdded(const QString& path, torrent_handle& h, bool fastResume){
|
||||
QString hash = QString(misc::toString(h.info_hash()).c_str());
|
||||
@ -1080,7 +1068,7 @@ void GUI::torrentAdded(const QString& path, torrent_handle& h, bool fastResume){
|
||||
// Adding torrent to download list
|
||||
DLListModel->insertRow(row);
|
||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(h.name().c_str()));
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)torrentEffectiveSize(hash)));
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)BTSession.torrentEffectiveSize(hash)));
|
||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.));
|
||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.));
|
||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant("0/0"));
|
||||
@ -1182,7 +1170,7 @@ void GUI::showProperties(const QModelIndex &index){
|
||||
|
||||
void GUI::updateFileSize(QString hash){
|
||||
int row = getRowFromHash(hash);
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)torrentEffectiveSize(hash)));
|
||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)BTSession.torrentEffectiveSize(hash)));
|
||||
}
|
||||
|
||||
// Set BT session configuration
|
||||
|
@ -131,7 +131,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
||||
void createTrayIcon();
|
||||
void addLogPeerBlocked(const QString&);
|
||||
// Torrent actions
|
||||
size_type torrentEffectiveSize(QString hash) const;
|
||||
void showProperties(const QModelIndex &index);
|
||||
void on_actionTorrent_Properties_triggered();
|
||||
void on_actionPause_triggered();
|
||||
|
@ -372,6 +372,40 @@ bool bittorrent::hasFilteredFiles(const QString& fileHash) const{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get the size of the torrent without the filtered files
|
||||
size_type bittorrent::torrentEffectiveSize(QString hash) const{
|
||||
torrent_handle h = getTorrentHandle(hash);
|
||||
torrent_info t = h.get_torrent_info();
|
||||
unsigned int nbFiles = t.num_files();
|
||||
if(!h.is_valid()){
|
||||
qDebug("/!\\ Error: Invalid handle");
|
||||
return t.total_size();
|
||||
}
|
||||
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities");
|
||||
// Read saved file
|
||||
if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)){
|
||||
qDebug("* Error: Couldn't open priorities file");
|
||||
return t.total_size();
|
||||
}
|
||||
QByteArray pieces_priorities = pieces_file.readAll();
|
||||
pieces_file.close();
|
||||
QList<QByteArray> pieces_priorities_list = pieces_priorities.split('\n');
|
||||
if((unsigned int)pieces_priorities_list.size() != nbFiles+1){
|
||||
std::cerr << "* Error: Corrupted priorities file\n";
|
||||
return t.total_size();
|
||||
}
|
||||
size_type effective_size = 0;
|
||||
for(unsigned int i=0; i<nbFiles; ++i){
|
||||
int priority = pieces_priorities_list.at(i).toInt();
|
||||
if( priority < 0 || priority > 7){
|
||||
priority = 1;
|
||||
}
|
||||
if(priority)
|
||||
effective_size += t.file_at(i).size;
|
||||
}
|
||||
return effective_size;
|
||||
}
|
||||
|
||||
// Return DHT state
|
||||
bool bittorrent::isDHTEnabled() const{
|
||||
return DHTEnabled;
|
||||
|
@ -84,6 +84,7 @@ class bittorrent : public QObject{
|
||||
QStringList getTorrentsToPauseAfterChecking() const;
|
||||
QStringList getUncheckedTorrentsList() const;
|
||||
long getETA(QString hash) const;
|
||||
size_type torrentEffectiveSize(QString hash) const;
|
||||
|
||||
public slots:
|
||||
void addTorrent(const QString& path, bool fromScanDir = false, bool onStartup = false, const QString& from_url = QString());
|
||||
|
Loading…
Reference in New Issue
Block a user