Browse Source

FEATURE: uTorrent compatible tracker list support (use torrentz.com url as a default)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
d0037d90f4
  1. 1
      Changelog
  2. 4
      src/trackerlist.h
  3. 81
      src/trackersadditiondlg.h
  4. 60
      src/ui/trackersadditiondlg.ui

1
Changelog

@ -5,6 +5,7 @@ @@ -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

4
src/trackerlist.h

@ -221,10 +221,10 @@ public slots: @@ -221,10 +221,10 @@ public slots:
// Ask the user for new trackers and add them to the torrent
void askForTrackers(){
QStringList trackers = TrackersAdditionDlg::askForTrackers();
if(!trackers.empty()) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
QStringList trackers = TrackersAdditionDlg::askForTrackers(h);
if(!trackers.empty()) {
foreach(const QString& tracker, trackers) {
announce_entry url(tracker.toStdString());
url.tier = 0;

81
src/trackersadditiondlg.h

@ -33,14 +33,26 @@ @@ -33,14 +33,26 @@
#include <QDialog>
#include <QStringList>
#include <QMessageBox>
#include <QFile>
#include <QUrl>
#include "misc.h"
#include "ui_trackersadditiondlg.h"
#include "downloadthread.h"
#include "qtorrenthandle.h"
class TrackersAdditionDlg : public QDialog, private Ui::TrackersAdditionDlg{
Q_OBJECT
private:
QTorrentHandle h;
public:
TrackersAdditionDlg(QWidget *parent=0): QDialog(parent){
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(){}
@ -49,9 +61,72 @@ class TrackersAdditionDlg : public QDialog, private Ui::TrackersAdditionDlg{ @@ -49,9 +61,72 @@ class TrackersAdditionDlg : public QDialog, private Ui::TrackersAdditionDlg{
return trackers_list->toPlainText().trimmed().split("\n");
}
static QStringList askForTrackers() {
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<QUrl> existingTrackers;
// Load from torrent handle
std::vector<announce_entry> tor_trackers = h.trackers();
std::vector<announce_entry>::iterator itr = tor_trackers.begin();
while(itr != tor_trackers.end()) {
existingTrackers << QUrl(misc::toQString(itr->url));
itr++;
}
// 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;
}
}
// 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;
TrackersAdditionDlg dlg(h);
if(dlg.exec() == QDialog::Accepted) {
return dlg.newTrackers();
}

60
src/ui/trackersadditiondlg.ui

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TrackersAdditionDlg</class>
<widget class="QDialog" name="TrackersAdditionDlg">
@ -6,7 +7,7 @@ @@ -6,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>367</width>
<height>201</height>
<height>274</height>
</rect>
</property>
<property name="windowTitle">
@ -21,7 +22,58 @@ @@ -21,7 +22,58 @@
</widget>
</item>
<item>
<widget class="QTextEdit" name="trackers_list" />
<widget class="QTextEdit" name="trackers_list">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>µTorrent compatible list URL:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="list_url"/>
</item>
<item>
<widget class="QPushButton" name="uTorrentListButton">
<property name="minimumSize">
<size>
<width>31</width>
<height>31</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>31</width>
<height>31</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/download.png</normaloff>:/Icons/oxygen/download.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
@ -35,7 +87,9 @@ @@ -35,7 +87,9 @@
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>

Loading…
Cancel
Save