diff --git a/TODO b/TODO index 9a48b3c9c..a8cd37d2b 100644 --- a/TODO +++ b/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 \ No newline at end of file +- update sorting when a new torrent is added +- properties: reload torrent only if priorities changed \ No newline at end of file diff --git a/src/GUI.cpp b/src/GUI.cpp index cf66e88c8..22525430a 100644 --- a/src/GUI.cpp +++ b/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; iinsertRow(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 diff --git a/src/GUI.h b/src/GUI.h index 80cef8d1c..9a58114cd 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -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(); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 6f22fd1a1..127706b7a 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -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 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 7){ + priority = 1; + } + if(priority) + effective_size += t.file_at(i).size; + } + return effective_size; +} + // Return DHT state bool bittorrent::isDHTEnabled() const{ return DHTEnabled; diff --git a/src/bittorrent.h b/src/bittorrent.h index 3888dfc6c..3160aaef4 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -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());