From d0037d90f455e80afd3a36ec3f47c10420213957 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Tue, 29 Dec 2009 16:36:36 +0000 Subject: [PATCH] FEATURE: uTorrent compatible tracker list support (use torrentz.com url as a default) --- Changelog | 1 + src/trackerlist.h | 6 +- src/trackersadditiondlg.h | 105 +++++++++++++++++++++++++++++----- src/ui/trackersadditiondlg.ui | 88 ++++++++++++++++++++++------ 4 files changed, 165 insertions(+), 35 deletions(-) diff --git a/Changelog b/Changelog index 70cde96aa..c1b8ace6d 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ - FEATURE: Peer Exchange (PeX) can be disabled from preferences - FEATURE: Append !.qB extension to incomplete files option (libtorrent >= v0.15 only) - FEATURE: Torrent files/folders can be renamed + - FEATURE: uTorrent compatible tracker list support (use torrentz.com url as a default) - COSMETIC: Use checkboxes to filter torrent content instead of comboboxes - COSMETIC: Use alternating row colors in transfer list (set in program preferences) - COSMETIC: Added a spin box to speed limiting dialog for manual input diff --git a/src/trackerlist.h b/src/trackerlist.h index 985e6810d..6ad0a5ec3 100644 --- a/src/trackerlist.h +++ b/src/trackerlist.h @@ -221,10 +221,10 @@ public slots: // Ask the user for new trackers and add them to the torrent void askForTrackers(){ - QStringList trackers = TrackersAdditionDlg::askForTrackers(); + QTorrentHandle h = properties->getCurrentTorrent(); + if(!h.is_valid()) return; + QStringList trackers = TrackersAdditionDlg::askForTrackers(h); if(!trackers.empty()) { - QTorrentHandle h = properties->getCurrentTorrent(); - if(!h.is_valid()) return; foreach(const QString& tracker, trackers) { announce_entry url(tracker.toStdString()); url.tier = 0; diff --git a/src/trackersadditiondlg.h b/src/trackersadditiondlg.h index 4d4058af1..25de7850a 100644 --- a/src/trackersadditiondlg.h +++ b/src/trackersadditiondlg.h @@ -33,30 +33,105 @@ #include #include +#include +#include +#include +#include "misc.h" #include "ui_trackersadditiondlg.h" +#include "downloadthread.h" +#include "qtorrenthandle.h" class TrackersAdditionDlg : public QDialog, private Ui::TrackersAdditionDlg{ Q_OBJECT - public: - TrackersAdditionDlg(QWidget *parent=0): QDialog(parent){ - setupUi(this); - } - - ~TrackersAdditionDlg(){} +private: + QTorrentHandle h; + +public: + TrackersAdditionDlg(QTorrentHandle h, QWidget *parent=0): QDialog(parent), h(h) { + setupUi(this); + // As a default, use torrentz.com link + list_url->setText("http://www.torrentz.com/announce_"+h.hash()); + list_url->setCursorPosition(0); + } + + ~TrackersAdditionDlg(){} - QStringList newTrackers() const { - return trackers_list->toPlainText().trimmed().split("\n"); + QStringList newTrackers() const { + return trackers_list->toPlainText().trimmed().split("\n"); + } + +public slots: + void on_uTorrentListButton_clicked() { + downloadThread *d = new downloadThread(this); + connect(d, SIGNAL(downloadFinished(QString,QString)), this, SLOT(parseUTorrentList(QString,QString))); + connect(d, SIGNAL(downloadFailure(QString,QString)), this, SLOT(getTrackerError(QString,QString))); + //Just to show that it takes times + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + d->downloadUrl("http://www.torrentz.com/announce_"+h.hash()); + } + + void parseUTorrentList(QString, QString path) { + QFile list_file(path); + if (!list_file.open(QFile::ReadOnly)) { + QMessageBox::warning(this, tr("I/O Error"), tr("Error while trying to open the downloaded file."), QMessageBox::Ok); + return; + } + QList existingTrackers; + // Load from torrent handle + std::vector tor_trackers = h.trackers(); + std::vector::iterator itr = tor_trackers.begin(); + while(itr != tor_trackers.end()) { + existingTrackers << QUrl(misc::toQString(itr->url)); + itr++; } - - static QStringList askForTrackers() { - QStringList trackers; - TrackersAdditionDlg dlg; - if(dlg.exec() == QDialog::Accepted) { - return dlg.newTrackers(); + // Load from current user list + QStringList tmp = trackers_list->toPlainText().split("\n"); + foreach(QString user_url_str, tmp) { + QUrl user_url(user_url_str); + if(!existingTrackers.contains(user_url)) + existingTrackers << user_url; + } + // Add new trackers to the list + if(!trackers_list->toPlainText().isEmpty() && !trackers_list->toPlainText().endsWith("\n")) + trackers_list->insertPlainText("\n"); + int nb = 0; + while (!list_file.atEnd()) { + QByteArray line = list_file.readLine().trimmed(); + if(line.isEmpty()) continue; + QUrl url(line); + if (!existingTrackers.contains(url)) { + trackers_list->insertPlainText(line + "\n"); + ++nb; } - return trackers; } + // Clean up + list_file.close(); + list_file.remove(); + //To restore the cursor ... + QApplication::restoreOverrideCursor(); + // Display information message if necessary + if(nb == 0) { + QMessageBox::information(this, tr("No change"), tr("No additional trackers were found."), QMessageBox::Ok); + } + } + + void getTrackerError(QString, QString error) { + //To restore the cursor ... + QApplication::restoreOverrideCursor(); + QMessageBox::warning(this, tr("Download error"), tr("The trackers list could not be downloaded, reason: %1").arg(error), QMessageBox::Ok); + } + +public: + + static QStringList askForTrackers(QTorrentHandle h) { + QStringList trackers; + TrackersAdditionDlg dlg(h); + if(dlg.exec() == QDialog::Accepted) { + return dlg.newTrackers(); + } + return trackers; + } }; #endif diff --git a/src/ui/trackersadditiondlg.ui b/src/ui/trackersadditiondlg.ui index 363158018..cb7a52cb3 100644 --- a/src/ui/trackersadditiondlg.ui +++ b/src/ui/trackersadditiondlg.ui @@ -1,41 +1,95 @@ - + + TrackersAdditionDlg - - + + 0 0 367 - 201 + 274 - + Trackers addition dialog - + - - + + List of trackers to add (one per line): - + + + QTextEdit::NoWrap + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> + + + false + + + + + + + µTorrent compatible list URL: + + + + + + + + + + + + + 31 + 31 + + + + + 31 + 31 + + + + + + + + :/Icons/oxygen/download.png:/Icons/oxygen/download.png + + + + - - + + Qt::Horizontal - + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + + + buttonBox @@ -43,11 +97,11 @@ TrackersAdditionDlg accept() - + 248 254 - + 157 274 @@ -59,11 +113,11 @@ TrackersAdditionDlg reject() - + 316 260 - + 286 274