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. 30
      src/bittorrent.cpp
  2. 4
      src/bittorrent.h
  3. 714
      src/properties.ui
  4. 28
      src/properties_imp.cpp
  5. 1
      src/properties_imp.h

30
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()){
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()));
trackersErrors[hash] = errors;
// Authentication // Authentication
if(p->status_code == 401) { if(p->status_code != 401) {
QString hash = h.hash();
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;
} else {
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;

714
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,412 +573,322 @@
<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> <item>
<widget class="QGroupBox" name="groupBox_2" > <layout class="QHBoxLayout" >
<property name="sizePolicy" > <property name="spacing" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" > <number>6</number>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property> </property>
<property name="minimumSize" > <property name="leftMargin" >
<size> <number>0</number>
<width>0</width>
<height>170</height>
</size>
</property> </property>
<property name="font" > <property name="topMargin" >
<font> <number>0</number>
<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>
<property name="title" > <property name="rightMargin" >
<string>Tracker</string> <number>0</number>
</property> </property>
<layout class="QVBoxLayout" > <property name="bottomMargin" >
<property name="spacing" > <number>0</number>
<number>6</number> </property>
</property> <item>
<property name="leftMargin" > <widget class="QLabel" name="label_9" >
<number>9</number> <property name="font" >
</property> <font>
<property name="topMargin" > <family>Sans Serif</family>
<number>9</number> <pointsize>9</pointsize>
</property> <weight>50</weight>
<property name="rightMargin" > <italic>false</italic>
<number>9</number> <bold>false</bold>
</property> <underline>false</underline>
<property name="bottomMargin" > <strikeout>false</strikeout>
<number>9</number> </font>
</property> </property>
<item> <property name="text" >
<layout class="QHBoxLayout" > <string>Trackers:</string>
<property name="spacing" > </property>
<number>6</number> </widget>
</property> </item>
<property name="leftMargin" > <item>
<number>0</number> <layout class="QVBoxLayout" >
</property> <property name="spacing" >
<property name="topMargin" > <number>6</number>
<number>0</number> </property>
</property> <property name="leftMargin" >
<property name="rightMargin" > <number>0</number>
<number>0</number> </property>
</property> <property name="topMargin" >
<property name="bottomMargin" > <number>0</number>
<number>0</number> </property>
</property> <property name="rightMargin" >
<item> <number>0</number>
<widget class="QLabel" name="label_9" > </property>
<property name="font" > <property name="bottomMargin" >
<font> <number>0</number>
<family>Sans Serif</family> </property>
<pointsize>9</pointsize> <item>
<weight>50</weight> <widget class="QListWidget" name="trackersURLS" >
<italic>false</italic> <property name="sizePolicy" >
<bold>false</bold> <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<underline>false</underline> <horstretch>0</horstretch>
<strikeout>false</strikeout> <verstretch>0</verstretch>
</font> </sizepolicy>
</property> </property>
<property name="text" > </widget>
<string>Trackers:</string> </item>
</property> <item>
</widget> <layout class="QHBoxLayout" >
</item> <property name="spacing" >
<item> <number>6</number>
<layout class="QVBoxLayout" > </property>
<property name="spacing" > <property name="leftMargin" >
<number>6</number> <number>0</number>
</property> </property>
<property name="leftMargin" > <property name="topMargin" >
<number>0</number> <number>0</number>
</property> </property>
<property name="topMargin" > <property name="rightMargin" >
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin" > <property name="bottomMargin" >
<number>0</number> <number>0</number>
</property> </property>
<property name="bottomMargin" > <item>
<number>0</number> <spacer>
</property> <property name="orientation" >
<item> <enum>Qt::Horizontal</enum>
<widget class="QListWidget" name="trackersURLS" > </property>
<property name="sizePolicy" > <property name="sizeHint" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" > <size>
<horstretch>0</horstretch> <width>40</width>
<verstretch>0</verstretch> <height>20</height>
</sizepolicy> </size>
</property> </property>
</widget> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" > <widget class="QPushButton" name="removeTracker_button" >
<property name="spacing" > <property name="minimumSize" >
<number>6</number> <size>
</property> <width>24</width>
<property name="leftMargin" > <height>24</height>
<number>0</number> </size>
</property> </property>
<property name="topMargin" > <property name="maximumSize" >
<number>0</number> <size>
</property> <width>24</width>
<property name="rightMargin" > <height>24</height>
<number>0</number> </size>
</property> </property>
<property name="bottomMargin" > <property name="text" >
<number>0</number> <string/>
</property> </property>
<item> </widget>
<spacer> </item>
<property name="orientation" > <item>
<enum>Qt::Horizontal</enum> <widget class="QPushButton" name="addTracker_button" >
</property> <property name="minimumSize" >
<property name="sizeHint" > <size>
<size> <width>24</width>
<width>40</width> <height>24</height>
<height>20</height> </size>
</size> </property>
</property> <property name="maximumSize" >
</spacer> <size>
</item> <width>24</width>
<item> <height>24</height>
<widget class="QPushButton" name="removeTracker_button" > </size>
<property name="minimumSize" > </property>
<size> <property name="text" >
<width>24</width> <string/>
<height>24</height> </property>
</size> </widget>
</property> </item>
<property name="maximumSize" > <item>
<size> <spacer>
<width>24</width> <property name="orientation" >
<height>24</height> <enum>Qt::Horizontal</enum>
</size> </property>
</property> <property name="sizeHint" >
<property name="text" > <size>
<string/> <width>40</width>
</property> <height>20</height>
</widget> </size>
</item> </property>
<item> </spacer>
<widget class="QPushButton" name="addTracker_button" > </item>
<property name="minimumSize" > </layout>
<size> </item>
<width>24</width> </layout>
<height>24</height> </item>
</size> <item>
</property> <layout class="QVBoxLayout" >
<property name="maximumSize" > <property name="spacing" >
<size> <number>6</number>
<width>24</width> </property>
<height>24</height> <property name="leftMargin" >
</size> <number>0</number>
</property> </property>
<property name="text" > <property name="topMargin" >
<string/> <number>0</number>
</property> </property>
</widget> <property name="rightMargin" >
</item> <number>0</number>
<item> </property>
<spacer> <property name="bottomMargin" >
<property name="orientation" > <number>0</number>
<enum>Qt::Horizontal</enum> </property>
</property> <item>
<property name="sizeHint" > <spacer>
<size> <property name="orientation" >
<width>40</width> <enum>Qt::Vertical</enum>
<height>20</height> </property>
</size> <property name="sizeHint" >
</property> <size>
</spacer> <width>20</width>
</item> <height>40</height>
</layout> </size>
</item> </property>
</layout> </spacer>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" > <widget class="QPushButton" name="riseTracker_button" >
<property name="spacing" > <property name="minimumSize" >
<number>6</number> <size>
</property> <width>24</width>
<property name="leftMargin" > <height>24</height>
<number>0</number> </size>
</property> </property>
<property name="topMargin" > <property name="maximumSize" >
<number>0</number> <size>
</property> <width>24</width>
<property name="rightMargin" > <height>24</height>
<number>0</number> </size>
</property> </property>
<property name="bottomMargin" > <property name="text" >
<number>0</number> <string/>
</property> </property>
<item> </widget>
<spacer> </item>
<property name="orientation" > <item>
<enum>Qt::Vertical</enum> <widget class="QPushButton" name="lowerTracker_button" >
</property> <property name="minimumSize" >
<property name="sizeHint" > <size>
<size> <width>24</width>
<width>20</width> <height>24</height>
<height>40</height> </size>
</size> </property>
</property> <property name="maximumSize" >
</spacer> <size>
</item> <width>24</width>
<item> <height>24</height>
<widget class="QPushButton" name="riseTracker_button" > </size>
<property name="minimumSize" > </property>
<size> <property name="text" >
<width>24</width> <string/>
<height>24</height> </property>
</size> </widget>
</property> </item>
<property name="maximumSize" > <item>
<size> <spacer>
<width>24</width> <property name="orientation" >
<height>24</height> <enum>Qt::Vertical</enum>
</size> </property>
</property> <property name="sizeHint" >
<property name="text" > <size>
<string/> <width>20</width>
</property> <height>40</height>
</widget> </size>
</item> </property>
<item> </spacer>
<widget class="QPushButton" name="lowerTracker_button" > </item>
<property name="minimumSize" > </layout>
<size> </item>
<width>24</width> </layout>
<height>24</height> </item>
</size> <item>
</property> <layout class="QHBoxLayout" >
<property name="maximumSize" > <property name="spacing" >
<size> <number>6</number>
<width>24</width> </property>
<height>24</height> <property name="leftMargin" >
</size> <number>0</number>
</property> </property>
<property name="text" > <property name="topMargin" >
<string/> <number>0</number>
</property> </property>
</widget> <property name="rightMargin" >
</item> <number>0</number>
<item> </property>
<spacer> <property name="bottomMargin" >
<property name="orientation" > <number>0</number>
<enum>Qt::Vertical</enum> </property>
</property> <item>
<property name="sizeHint" > <widget class="QLabel" name="label_2" >
<size> <property name="maximumSize" >
<width>20</width> <size>
<height>40</height> <width>16777215</width>
</size> <height>16</height>
</property> </size>
</spacer> </property>
</item> <property name="font" >
</layout> <font>
</item> <family>Sans Serif</family>
</layout> <pointsize>9</pointsize>
</item> <weight>50</weight>
<item> <italic>false</italic>
<layout class="QHBoxLayout" > <bold>false</bold>
<property name="spacing" > <underline>false</underline>
<number>6</number> <strikeout>false</strikeout>
</property> </font>
<property name="leftMargin" > </property>
<number>0</number> <property name="text" >
</property> <string>Current tracker:</string>
<property name="topMargin" > </property>
<number>0</number> </widget>
</property> </item>
<property name="rightMargin" > <item>
<number>0</number> <widget class="QLabel" name="trackerURL" >
</property> <property name="maximumSize" >
<property name="bottomMargin" > <size>
<number>0</number> <width>16777215</width>
</property> <height>16</height>
<item> </size>
<widget class="QLabel" name="label_10" > </property>
<property name="font" > <property name="text" >
<font> <string/>
<family>Sans Serif</family> </property>
<pointsize>9</pointsize> </widget>
<weight>50</weight> </item>
<italic>false</italic> <item>
<bold>false</bold> <spacer>
<underline>false</underline> <property name="orientation" >
<strikeout>false</strikeout> <enum>Qt::Horizontal</enum>
</font> </property>
</property> <property name="sizeHint" >
<property name="text" > <size>
<string>Errors:</string> <width>40</width>
</property> <height>20</height>
</widget> </size>
</item> </property>
<item> </spacer>
<widget class="QTextBrowser" name="trackerErrors" > </item>
<property name="lineWrapMode" > </layout>
<enum>QTextEdit::NoWrap</enum> </item>
</property> <item>
</widget> <spacer>
</item> <property name="orientation" >
</layout> <enum>Qt::Vertical</enum>
</item> </property>
<item> <property name="sizeType" >
<layout class="QHBoxLayout" > <enum>QSizePolicy::Minimum</enum>
<property name="spacing" > </property>
<number>6</number> <property name="sizeHint" >
</property> <size>
<property name="leftMargin" > <width>20</width>
<number>0</number> <height>40</height>
</property> </size>
<property name="topMargin" > </property>
<number>0</number> </spacer>
</property>
<property name="rightMargin" >
<number>0</number>
</property>
<property name="bottomMargin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>16</height>
</size>
</property>
<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>Current tracker:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="trackerURL" >
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>16</height>
</size>
</property>
<property name="text" >
<string/>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</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();
@ -277,19 +276,6 @@ void properties::updatePriorities(QStandardItem *item) {
// get future updates // get future updates
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;
@ -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