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

4
src/bittorrent.h

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

124
src/properties.ui

@ -31,7 +31,7 @@
<item> <item>
<widget class="QTabWidget" name="torrentContent" > <widget class="QTabWidget" name="torrentContent" >
<property name="currentIndex" > <property name="currentIndex" >
<number>0</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="tab_1" > <widget class="QWidget" name="tab_1" >
<attribute name="title" > <attribute name="title" >
@ -573,65 +573,6 @@
<string>Trackers</string> <string>Trackers</string>
</attribute> </attribute>
<layout class="QVBoxLayout" > <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> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="spacing" > <property name="spacing" >
@ -687,7 +628,7 @@
<item> <item>
<widget class="QListWidget" name="trackersURLS" > <widget class="QListWidget" name="trackersURLS" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" > <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -864,50 +805,6 @@
</item> </item>
</layout> </layout>
</item> </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> <item>
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<property name="spacing" > <property name="spacing" >
@ -977,8 +874,21 @@
</item> </item>
</layout> </layout>
</item> </item>
</layout> <item>
</widget> <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> </item>
</layout> </layout>
</widget> </widget>

28
src/properties_imp.cpp

@ -99,7 +99,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
} }
} }
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
loadTrackersErrors();
std::vector<float> fp; std::vector<float> fp;
h.file_progress(fp); h.file_progress(fp);
int *prioritiesTab = loadPiecesPriorities(); int *prioritiesTab = loadPiecesPriorities();
@ -278,19 +277,6 @@ void properties::updatePriorities(QStandardItem *item) {
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*))); 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(){ void properties::loadWebSeeds(){
QString url_seed; QString url_seed;
// Clear url seeds list // Clear url seeds list
@ -449,9 +435,19 @@ void properties::loadTrackers(){
//Trackers //Trackers
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
trackersURLS->clear(); trackersURLS->clear();
QHash<QString, QString> errors = BTSession->getTrackersErrors(h.hash());
unsigned int nbTrackers = trackers.size(); unsigned int nbTrackers = trackers.size();
for(unsigned int i=0; i<nbTrackers; ++i){ 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(); QString tracker = h.current_tracker().trimmed();
if(!tracker.isEmpty()){ if(!tracker.isEmpty()){
@ -633,6 +629,8 @@ void properties::updateInfos(){
}else{ }else{
trackerURL->setText(tr("None - Unreachable?")); trackerURL->setText(tr("None - Unreachable?"));
} }
// XXX: This causes selection problems
//loadTrackers();
}catch(invalid_handle e){ }catch(invalid_handle e){
// torrent was removed, closing properties // torrent was removed, closing properties
close(); close();

1
src/properties_imp.h

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

Loading…
Cancel
Save