Browse Source

- Commit some tracker changes. Work is not completed and this is probably buggy. I will complete this later.

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
0dd84c37a1
  1. 28
      src/bittorrent.cpp
  2. 4
      src/bittorrent.h
  3. 124
      src/properties.ui
  4. 28
      src/properties_imp.cpp
  5. 1
      src/properties_imp.h

28
src/bittorrent.cpp

@ -1163,18 +1163,30 @@ void bittorrent::readAlerts() { @@ -1163,18 +1163,30 @@ void bittorrent::readAlerts() {
// Level: fatal
QTorrentHandle h(p->handle);
if(h.is_valid()){
// Authentication
if(p->status_code != 401) {
QString hash = h.hash();
QList<QPair<QString, QString> > errors = trackersErrors.value(hash, QList<QPair<QString, QString> >());
if(errors.size() > MAX_TRACKER_ERRORS)
errors.removeAt(0);
errors << QPair<QString,QString>(QTime::currentTime().toString("hh:mm:ss"), QString::fromUtf8(a->msg().c_str()));
qDebug("Received a tracker error for %s", (const char*)h.current_tracker().toUtf8());
QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>());
// p->url requires at least libtorrent v0.13.1
errors[misc::toQString(p->url)] = QString::fromUtf8(a->msg().c_str());
trackersErrors[hash] = errors;
// Authentication
if(p->status_code == 401) {
} else {
emit trackerAuthenticationRequired(h);
}
}
}
else if (tracker_reply_alert* p = dynamic_cast<tracker_reply_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
qDebug("Received a tracker reply from %s", (const char*)h.current_tracker().toUtf8());
QString hash = h.hash();
QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>());
// p->url requires at least libtorrent v0.13.1
errors.remove(h.current_tracker());
trackersErrors[hash] = errors;
}
}
else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) {
emit UPnPError(QString(p->msg().c_str()));
}
@ -1218,8 +1230,8 @@ void bittorrent::readAlerts() { @@ -1218,8 +1230,8 @@ void bittorrent::readAlerts() {
}
}
QList<QPair<QString, QString> > bittorrent::getTrackersErrors(QString hash) const{
return trackersErrors.value(hash, QList<QPair<QString, QString> >());
QHash<QString, QString> bittorrent::getTrackersErrors(QString hash) const{
return trackersErrors.value(hash, QHash<QString, QString>());
}
QStringList bittorrent::getTorrentsToPauseAfterChecking() const{

4
src/bittorrent.h

@ -54,7 +54,7 @@ class bittorrent : public QObject{ @@ -54,7 +54,7 @@ class bittorrent : public QObject{
QHash<QString, QDateTime> TorrentsStartTime;
QHash<QString, size_type> TorrentsStartData;
QHash<QString, QPair<size_type,size_type> > ratioData;
QHash<QString, QList<QPair<QString, QString> > > trackersErrors;
QHash<QString, QHash<QString, QString> > trackersErrors;
deleteThread *deleter;
QStringList finishedTorrents;
QStringList unfinishedTorrents;
@ -86,7 +86,7 @@ class bittorrent : public QObject{ @@ -86,7 +86,7 @@ class bittorrent : public QObject{
qlonglong getETA(QString hash) const;
float getRealRatio(QString hash) const;
session* getSession() const;
QList<QPair<QString, QString> > getTrackersErrors(QString hash) const;
QHash<QString, QString> getTrackersErrors(QString hash) const;
QStringList getFinishedTorrents() const;
QStringList getUnfinishedTorrents() const;
bool isFinished(QString hash) const;

124
src/properties.ui

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
<item>
<widget class="QTabWidget" name="torrentContent" >
<property name="currentIndex" >
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_1" >
<attribute name="title" >
@ -573,65 +573,6 @@ @@ -573,65 +573,6 @@
<string>Trackers</string>
</attribute>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>0</width>
<height>170</height>
</size>
</property>
<property name="font" >
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
<weight>75</weight>
<italic>false</italic>
<bold>true</bold>
<underline>false</underline>
<strikeout>false</strikeout>
</font>
</property>
<property name="title" >
<string>Tracker</string>
</property>
<layout class="QVBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>9</number>
</property>
<property name="topMargin" >
<number>9</number>
</property>
<property name="rightMargin" >
<number>9</number>
</property>
<property name="bottomMargin" >
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
@ -687,7 +628,7 @@ @@ -687,7 +628,7 @@
<item>
<widget class="QListWidget" name="trackersURLS" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -864,50 +805,6 @@ @@ -864,50 +805,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="leftMargin" >
<number>0</number>
</property>
<property name="topMargin" >
<number>0</number>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_10" >
<property name="font" >
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<underline>false</underline>
<strikeout>false</strikeout>
</font>
</property>
<property name="text" >
<string>Errors:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="trackerErrors" >
<property name="lineWrapMode" >
<enum>QTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" >
<property name="spacing" >
@ -977,8 +874,21 @@ @@ -977,8 +874,21 @@
</item>
</layout>
</item>
</layout>
</widget>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>

28
src/properties_imp.cpp

@ -99,7 +99,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h @@ -99,7 +99,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
}
}
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
loadTrackersErrors();
std::vector<float> fp;
h.file_progress(fp);
int *prioritiesTab = loadPiecesPriorities();
@ -278,19 +277,6 @@ void properties::updatePriorities(QStandardItem *item) { @@ -278,19 +277,6 @@ void properties::updatePriorities(QStandardItem *item) {
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
}
void properties::loadTrackersErrors(){
// Tracker Errors
QList<QPair<QString, QString> > errors = BTSession->getTrackersErrors(hash);
unsigned int nbTrackerErrors = errors.size();
trackerErrors->clear();
for(unsigned int i=0; i < nbTrackerErrors; ++i){
QPair<QString, QString> pair = errors.at(i);
trackerErrors->append(QString::fromUtf8("<font color='grey'>")+pair.first+QString::fromUtf8("</font> - <font color='red'>")+pair.second+QString::fromUtf8("</font>"));
}
if(!nbTrackerErrors)
trackerErrors->append(tr("None", "i.e: No error message"));
}
void properties::loadWebSeeds(){
QString url_seed;
// Clear url seeds list
@ -449,9 +435,19 @@ void properties::loadTrackers(){ @@ -449,9 +435,19 @@ void properties::loadTrackers(){
//Trackers
std::vector<announce_entry> trackers = h.trackers();
trackersURLS->clear();
QHash<QString, QString> errors = BTSession->getTrackersErrors(h.hash());
unsigned int nbTrackers = trackers.size();
for(unsigned int i=0; i<nbTrackers; ++i){
trackersURLS->addItem(misc::toQString(trackers[i].url));
QString current_tracker = misc::toQString(trackers[i].url);
QListWidgetItem *item = new QListWidgetItem(current_tracker, trackersURLS);
// IsThere any errors ?
if(errors.contains(current_tracker)) {
item->setForeground(QBrush(QColor("red")));
// Set tooltip
item->setToolTip(errors[current_tracker]);
} else {
item->setForeground(QBrush(QColor("green")));
}
}
QString tracker = h.current_tracker().trimmed();
if(!tracker.isEmpty()){
@ -633,6 +629,8 @@ void properties::updateInfos(){ @@ -633,6 +629,8 @@ void properties::updateInfos(){
}else{
trackerURL->setText(tr("None - Unreachable?"));
}
// XXX: This causes selection problems
//loadTrackers();
}catch(invalid_handle e){
// torrent was removed, closing properties
close();

1
src/properties_imp.h

@ -72,7 +72,6 @@ class properties : public QDialog, private Ui::properties{ @@ -72,7 +72,6 @@ class properties : public QDialog, private Ui::properties{
void saveWebSeeds();
void loadWebSeedsFromFile();
void deleteSelectedUrlSeeds();
void loadTrackersErrors();
void addFilesToTree(torrent_file *root, QStandardItem *parent);
void updateChildrenPriority(QStandardItem *item, int priority);
void updateParentsPriority(QStandardItem *item, int priority);

Loading…
Cancel
Save