Skip to content

Commit

Permalink
- Make use of new torrent_checked_alert that was just included in lib…
Browse files Browse the repository at this point in the history
…torrent. This allowed to improve torrent that just finished checking handling and progress column sorting. Also allowed to optimize cpu/memory usage a little.
  • Loading branch information
Christophe Dumez committed Aug 17, 2007
1 parent 55834ba commit 13f21ef
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 80 deletions.
6 changes: 3 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@
- wait for fastresume data on exit should be in a thread?
* beta5
- Translations update (IN PROGRESS)
- make use of finishedChecking alert if hydri applies my patch for this
- Clean up delayed progress column sorting code
- Clean up pause after checking code
- Check incremental download (looks broken)
- improve torrentFinishedList with new alert
- Wait for some bug fixes in libtorrent :
- upload/download limit per torrent (Ticket #83)

Expand All @@ -69,6 +67,8 @@ LANGUAGES UPDATED:

beta4->beta5 changelog:
- FEATURE: Supports Bittorrent FAST extension
- FEATURE: Improved code handling torrents that have just finished checking
- FEATURE: Improved progress column sorting code
- BUGFIX: Wait for torrent_paused_alert before saving fast resume data on exit
- BUGFIX: Wait for torrent_paused_alert before reloading a torrent for full allocation mode
- BUFFIG: Fixed overflow causing ratio data to be negative
Expand Down
17 changes: 0 additions & 17 deletions src/FinishedTorrents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,6 @@ void FinishedTorrents::updateFinishedList(){
std::cerr << "ERROR: Can't find torrent in finished list\n";
continue;
}
if(BTSession->getTorrentsToPauseAfterChecking().indexOf(hash) != -1){
// Pause torrent if it finished checking and it is was supposed to be paused.
// This is a trick to see the progress of the pause torrents on startup
if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){
qDebug("Paused torrent finished checking with state: %d", torrentStatus.state);
finishedListModel->setData(finishedListModel->index(row, F_PROGRESS), QVariant((double)torrentStatus.progress));
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
setRowColor(row, "red");
BTSession->pauseTorrent(hash);
continue;
}
}
if(BTSession->getUncheckedTorrentsList().indexOf(hash) != -1){
if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){
BTSession->setTorrentFinishedChecking(hash);
}
}
if(h.is_paused()) continue;
if(torrentStatus.state == torrent_status::downloading || (torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking && torrentStatus.progress != 1.)) {
// What are you doing here? go back to download tab!
Expand Down
64 changes: 40 additions & 24 deletions src/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect(BTSession, SIGNAL(finishedTorrent(torrent_handle&)), this, SLOT(finishedTorrent(torrent_handle&)));
connect(BTSession, SIGNAL(fullDiskError(torrent_handle&)), this, SLOT(fullDiskError(torrent_handle&)));
connect(BTSession, SIGNAL(portListeningFailure()), this, SLOT(portListeningFailure()));
connect(BTSession,SIGNAL(allTorrentsFinishedChecking()), this, SLOT(sortProgressColumnDelayed()));
connect(BTSession, SIGNAL(trackerAuthenticationRequired(torrent_handle&)), this, SLOT(trackerAuthenticationRequired(torrent_handle&)));
connect(BTSession, SIGNAL(peerBlocked(QString)), this, SLOT(addLogPeerBlocked(const QString)));
connect(BTSession, SIGNAL(fastResumeDataRejected(QString)), this, SLOT(addFastResumeRejectedAlert(QString)));
Expand All @@ -147,6 +146,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect(BTSession, SIGNAL(downloadFromUrlFailure(QString, QString)), this, SLOT(handleDownloadFromUrlFailure(QString, QString)));
connect(BTSession, SIGNAL(aboutToDownloadFromUrl(QString)), this, SLOT(displayDownloadingUrlInfos(QString)));
connect(BTSession, SIGNAL(urlSeedProblem(QString, QString)), this, SLOT(addUrlSeedError(QString, QString)));
connect(BTSession, SIGNAL(torrentFinishedChecking(QString)), this, SLOT(torrentChecked(QString)));
// creating options
options = new options_imp(this);
connect(options, SIGNAL(status_changed(QString, bool)), this, SLOT(OptionsSaved(QString, bool)));
Expand Down Expand Up @@ -562,23 +562,6 @@ void GUI::updateDlList(bool force){
row = getRowFromHash(fileHash);
}
Q_ASSERT(row != -1);
if(BTSession->getTorrentsToPauseAfterChecking().indexOf(fileHash) != -1){
// Pause torrent if it finished checking and it is was supposed to be paused.
// This is a trick to see the progress of the pause torrents on startup
if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){
qDebug("Paused torrent finished checking with state: %d", torrentStatus.state);
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
setRowColor(row, "red");
BTSession->pauseTorrent(fileHash);
continue;
}
}
if(delayedSorting && BTSession->getUncheckedTorrentsList().indexOf(fileHash) != -1){
if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){
BTSession->setTorrentFinishedChecking(fileHash);
}
}
// No need to update a paused torrent
if(h.is_paused()) continue;
// Parse download state
Expand Down Expand Up @@ -924,7 +907,7 @@ void GUI::dropEvent(QDropEvent *event){
}
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, bool, QString)));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QString)), this, SLOT(setInfoBar(QString, QString)));
dialog->showLoad(file);
}else{
Expand Down Expand Up @@ -963,7 +946,7 @@ void GUI::on_actionOpen_triggered(){
for(unsigned int i=0; i<listSize; ++i){
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, bool, QString)));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QString)), this, SLOT(setInfoBar(QString, QString)));
dialog->showLoad(pathsList.at(i));
}else{
Expand Down Expand Up @@ -1184,7 +1167,7 @@ void GUI::processParams(const QStringList& params){
}else{
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, bool, QString)));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QString)), this, SLOT(setInfoBar(QString, QString)));
dialog->showLoad(param);
}else{
Expand All @@ -1201,7 +1184,7 @@ void GUI::processScannedFiles(const QStringList& params){
foreach(param, params){
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, bool, QString)));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QString)), this, SLOT(setInfoBar(QString, QString)));
dialog->showLoad(param, true);
}else{
Expand All @@ -1215,11 +1198,11 @@ void GUI::processDownloadedFiles(QString path, QString url){
bool useTorrentAdditionDialog = settings.value("Options/Misc/TorrentAdditionDialog/Enabled", true).toBool();
if(useTorrentAdditionDialog){
torrentAdditionDialog *dialog = new torrentAdditionDialog(this);
connect(dialog, SIGNAL(torrentAddition(QString, bool, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, bool, QString)));
connect(dialog, SIGNAL(torrentAddition(QString, bool, QString)), BTSession, SLOT(addTorrent(QString, bool, QString)));
connect(dialog, SIGNAL(setInfoBarGUI(QString, QString)), this, SLOT(setInfoBar(QString, QString)));
dialog->showLoad(path, false, url);
}else{
BTSession->addTorrent(path, false, false, url);
BTSession->addTorrent(path, false, url);
}
}

Expand Down Expand Up @@ -1614,6 +1597,39 @@ void GUI::finishedTorrent(torrent_handle& h){
}
}

// Called when a torrent finished checking
void GUI::torrentChecked(QString hash){
// Check if the torrent was paused after checking
if(BTSession->isPaused(hash)){
// Was paused, change its icon/color
if(finishedTorrentTab->getFinishedSHAs().indexOf(hash) != -1){
// In finished list
qDebug("Automatically paused torrent was in finished list");
int row = finishedTorrentTab->getRowFromHash(hash);
finishedTorrentTab->getFinishedListModel()->setData(finishedTorrentTab->getFinishedListModel()->index(row, F_UPSPEED), QVariant((double)0.0));
finishedTorrentTab->getFinishedListModel()->setData(finishedTorrentTab->getFinishedListModel()->index(row, F_NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
finishedTorrentTab->setRowColor(row, "red");
}else{
// In download list
int row = getRowFromHash(hash);
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
DLListModel->setData(DLListModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
setRowColor(row, "red");
}
}
if(finishedTorrentTab->getFinishedSHAs().indexOf(hash) == -1) {
// Update progress in download list
torrent_handle h = BTSession->getTorrentHandle(hash);
torrent_status torrentStatus = h.status();
int row = getRowFromHash(hash);
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
// Delayed Sorting
sortProgressColumnDelayed();
}
}

// Notification when disk is full
void GUI::fullDiskError(torrent_handle& h){
QSettings settings("qBittorrent", "qBittorrent");
Expand Down
1 change: 1 addition & 0 deletions src/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void processDownloadedFiles(QString path, QString url);
void downloadFromURLList(const QStringList& urls);
void displayDownloadingUrlInfos(QString url);
void torrentChecked(QString hash);
// Utils slots
void setRowColor(int row, QString color);
// Options slots
Expand Down
46 changes: 18 additions & 28 deletions src/bittorrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ bool bittorrent::pauseTorrent(QString hash){
int index = torrentsToPauseAfterChecking.indexOf(hash);
if(index != -1) {
torrentsToPauseAfterChecking.removeAt(index);
qDebug("A torrent was paused just after checking, good");
}
return change;
}
Expand Down Expand Up @@ -273,7 +272,7 @@ void bittorrent::loadWebSeeds(QString fileHash){
}

// Add a torrent to the bittorrent session
void bittorrent::addTorrent(QString path, bool fromScanDir, bool onStartup, QString from_url){
void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url){
torrent_handle h;
entry resume_data;
bool fastResume=false;
Expand Down Expand Up @@ -303,10 +302,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, bool onStartup, QStr
// Getting torrent file informations
torrent_info t(e);
QString hash = QString(misc::toString(t.info_hash()).c_str());
if(onStartup){
qDebug("Added a hash to the unchecked torrents list");
torrentsUnchecked << hash;
}
if(s->find_torrent(t.info_hash()).is_valid()){
// Update info Bar
if(!fromScanDir){
Expand Down Expand Up @@ -436,10 +431,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, bool onStartup, QStr
}
}

QStringList bittorrent::getTorrentsToPauseAfterChecking() const{
return torrentsToPauseAfterChecking;
}

// Set the maximum number of opened connections
void bittorrent::setMaxConnections(int maxConnec){
s->set_max_connections(maxConnec);
Expand Down Expand Up @@ -695,7 +686,7 @@ void bittorrent::saveFastResumeAndRatioData(){
h.pause();
QString fileHash = QString(misc::toString(h.info_hash()).c_str());
while(!receivedPausedAlert(fileHash)){
qDebug("Sleeping while waiting that %s is paused", misc::toString(h.info_hash()).c_str());
//qDebug("Sleeping while waiting that %s is paused", misc::toString(h.info_hash()).c_str());
//printPausedTorrents();
SleeperThread::msleep(500);
readAlerts();
Expand Down Expand Up @@ -968,6 +959,17 @@ void bittorrent::readAlerts(){
else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a.get())){
emit urlSeedProblem(QString(p->url.c_str()), QString(p->msg().c_str()));
}
else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())){
QString hash = QString(misc::toString(p->handle.info_hash()).c_str());
qDebug("%s have just finished checking", (const char*)hash.toUtf8());
int index = torrentsToPauseAfterChecking.indexOf(hash);
if(index != -1){
// Pause torrent
pauseTorrent(hash);
qDebug("%s was paused after checking", (const char*)hash.toUtf8());
}
emit torrentFinishedChecking(hash);
}
a = s->pop_alert();
}
}
Expand All @@ -976,6 +978,10 @@ QList<QPair<QString, QString> > bittorrent::getTrackersErrors(QString hash) cons
return trackersErrors.value(hash, QList<QPair<QString, QString> >());
}

QStringList bittorrent::getTorrentsToPauseAfterChecking() const{
return torrentsToPauseAfterChecking;
}

// Function to reload the torrent async after the torrent is actually
// paused so that we can get fastresume data
void bittorrent::pauseAndReloadTorrent(const torrent_handle &h){
Expand Down Expand Up @@ -1166,22 +1172,6 @@ std::vector<torrent_handle> bittorrent::getTorrentHandles() const{
return s->get_torrents();
}

QStringList bittorrent::getUncheckedTorrentsList() const{
return torrentsUnchecked;
}

void bittorrent::setTorrentFinishedChecking(QString hash){
int index = torrentsUnchecked.indexOf(hash);
qDebug("torrent %s finished checking", (const char*)hash.toUtf8());
if(index != -1){
torrentsUnchecked.removeAt(index);
qDebug("Still %d unchecked torrents", torrentsUnchecked.size());
if(torrentsUnchecked.size() == 0){
emit allTorrentsFinishedChecking();
}
}
}

// Save DHT entry to hard drive
void bittorrent::saveDHTEntry(){
// Save DHT entry
Expand Down Expand Up @@ -1219,7 +1209,7 @@ void bittorrent::resumeUnfinishedTorrents(){
}
// Resume downloads
foreach(fileName, filePaths){
addTorrent(fileName, false, true);
addTorrent(fileName, false);
}
qDebug("Unfinished torrents resumed");
}
7 changes: 2 additions & 5 deletions src/bittorrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class bittorrent : public QObject{
QStringList supported_preview_extensions;
QString defaultSavePath;
QStringList torrentsToPauseAfterChecking;
QStringList torrentsUnchecked;
QStringList reloadingTorrents;
QHash<QString, QList<long> > ETAstats;
QHash<QString, long> ETAs;
Expand Down Expand Up @@ -77,7 +76,6 @@ class bittorrent : public QObject{
session_status getSessionStatus() const;
int getListenPort() const;
QStringList getTorrentsToPauseAfterChecking() const;
QStringList getUncheckedTorrentsList() const;
long getETA(QString hash) const;
size_type torrentEffectiveSize(QString hash) const;
bool inFullAllocationMode(QString hash) const;
Expand All @@ -88,7 +86,7 @@ class bittorrent : public QObject{
void printPausedTorrents();

public slots:
void addTorrent(QString path, bool fromScanDir = false, bool onStartup = false, QString from_url = QString());
void addTorrent(QString path, bool fromScanDir = false, QString from_url = QString());
void downloadFromUrl(QString url);
void downloadFromURLList(const QStringList& url_list);
void deleteTorrent(QString hash, bool permanent = false);
Expand All @@ -104,7 +102,6 @@ class bittorrent : public QObject{
void enableIPFilter(ip_filter filter);
void disableIPFilter();
void pauseAndReloadTorrent(const torrent_handle &h);
void setTorrentFinishedChecking(QString hash);
void resumeUnfinishedTorrents();
void updateETAs();
void saveTorrentSpeedLimits(QString hash);
Expand Down Expand Up @@ -149,11 +146,11 @@ class bittorrent : public QObject{
void newDownloadedTorrent(QString path, QString url);
void aboutToDownloadFromUrl(QString url);
void updateFileSize(QString hash);
void allTorrentsFinishedChecking();
void peerBlocked(QString);
void downloadFromUrlFailure(QString url, QString reason);
void fastResumeDataRejected(QString name);
void urlSeedProblem(QString url, QString msg);
void torrentFinishedChecking(QString hash);

};

Expand Down
5 changes: 2 additions & 3 deletions src/torrentAddition.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{

signals:
void setInfoBarGUI(QString info, QString color);
void torrentAddition(QString filePath, bool fromScanDir, bool onStartup, QString from_url);
void torrentAddition(QString filePath, bool fromScanDir, QString from_url);

private:
QString fileName;
Expand Down Expand Up @@ -335,8 +335,7 @@ class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
// save filtered files
savePiecesPriorities();
// Add to download list
// TODO : quick fix
emit torrentAddition(filePath, fromScanDir, false, from_url);
emit torrentAddition(filePath, fromScanDir, from_url);
close();
}

Expand Down

0 comments on commit 13f21ef

Please sign in to comment.