Skip to content

Commit

Permalink
- Improved trackers errors code a lot and moved it to Bittorrent class
Browse files Browse the repository at this point in the history
- When using startAll() command and when only some torrents are paused : already started torrents are not displayed as connecting untill next refresh anymore (they keep their current state).
  • Loading branch information
Christophe Dumez committed Jul 27, 2007
1 parent ff9b9d7 commit f839d6f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 53 deletions.
8 changes: 5 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@
// in v1.1.0
- Tabs support in search
- Have a look at libcommoncpp2 to see if it can be useful for other stuff than url downloading
- Allow to hide columns?
- Allow to scan multiple directories?

// in v1.0.0 (partial) - WIP
- Check storage st creation + hasher in torrent creation
- test IPv6 support (How? Who uses IPv6?)
- Sorting in Download Status column should be smarter than just an alphabetical sort
- Allow to scan multiple directories?
- Fix all (or almost all) opened bugs in bug tracker
- Fix column sorting with Qt 4.3 - Reported to Trolltech, waiting for their fix
- update sorting when a new torrent is added?
- Allow to hide columns?
- Add a checking icon in dl list to differenciate from connecting.
- Complete documentation and english translation
* beta3
- Windows port (Chris - Peerkoel)
- Translations update
- Optimize and cleanup code
- document url seeds
- Improve trackers edition code
- check painting problems in dl list
- Wait for some bug fixes in libtorrent :
- upload/download limit per torrent
- double free or corruption on exit
Expand Down
3 changes: 1 addition & 2 deletions src/FinishedTorrents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ void FinishedTorrents::showProperties(const QModelIndex &index){
int row = index.row();
QString fileHash = finishedListModel->data(finishedListModel->index(row, F_HASH)).toString();
torrent_handle h = BTSession->getTorrentHandle(fileHash);
QStringList errors = ((GUI*)parent)->trackerErrors.value(fileHash, QStringList(tr("None", "i.e: No error message")));
properties *prop = new properties(this, BTSession, h, errors);
properties *prop = new properties(this, BTSession, h);
connect(prop, SIGNAL(mustHaveFullAllocationMode(torrent_handle)), BTSession, SLOT(reloadTorrent(torrent_handle)));
connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString)));
prop->show();
Expand Down
23 changes: 5 additions & 18 deletions src/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
connect(BTSession, SIGNAL(finishedTorrent(torrent_handle&)), this, SLOT(finishedTorrent(torrent_handle&)));
connect(BTSession, SIGNAL(fullDiskError(torrent_handle&)), this, SLOT(fullDiskError(torrent_handle&)));
connect(BTSession, SIGNAL(portListeningFailure()), this, SLOT(portListeningFailure()));
connect(BTSession, SIGNAL(trackerError(QString, QString, QString)), this, SLOT(trackerError(QString, QString, QString)));
connect(BTSession,SIGNAL(allTorrentsFinishedChecking()), this, SLOT(sortProgressColumnDelayed()));
connect(BTSession, SIGNAL(trackerAuthenticationRequired(torrent_handle&)), this, SLOT(trackerAuthenticationRequired(torrent_handle&)));
connect(BTSession, SIGNAL(peerBlocked(QString)), this, SLOT(addLogPeerBlocked(const QString)));
Expand Down Expand Up @@ -1231,8 +1230,7 @@ void GUI::showProperties(const QModelIndex &index){
int row = index.row();
QString fileHash = DLListModel->data(DLListModel->index(row, HASH)).toString();
torrent_handle h = BTSession->getTorrentHandle(fileHash);
QStringList errors = trackerErrors.value(fileHash, QStringList(tr("None", "i.e: No error message")));
properties *prop = new properties(this, BTSession, h, errors);
properties *prop = new properties(this, BTSession, h);
connect(prop, SIGNAL(mustHaveFullAllocationMode(torrent_handle)), BTSession, SLOT(reloadTorrent(torrent_handle)));
connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString)));
prop->show();
Expand Down Expand Up @@ -1429,10 +1427,10 @@ void GUI::on_actionStart_All_triggered(){
for(unsigned int i=0; i<nbRows; ++i){
fileHash = DLListModel->data(DLListModel->index(i, HASH)).toString();
// Remove .paused file
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
// Update DL list items
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(i, "grey");
if(QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(i, "grey");
}
}
setInfoBar(tr("All downloads were resumed."));
}
Expand Down Expand Up @@ -1530,17 +1528,6 @@ void GUI::portListeningFailure(){
setInfoBar(tr("Couldn't listen on any of the given ports."), "red");
}

// Called when we receive an error from tracker
void GUI::trackerError(QString hash, QString time, QString msg){
// Check trackerErrors list size and clear it if it is too big
if(trackerErrors.size() > 50){
trackerErrors.clear();
}
QStringList errors = trackerErrors.value(hash, QStringList());
errors.append("<font color='grey'>"+time+"</font> - <font color='red'>"+msg+"</font>");
trackerErrors.insert(hash, errors);
}

// Called when a tracker requires authentication
void GUI::trackerAuthenticationRequired(torrent_handle& h){
if(unauthenticated_trackers.indexOf(QPair<torrent_handle,std::string>(h, h.status().current_tracker)) < 0){
Expand Down
15 changes: 0 additions & 15 deletions src/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ namespace fs = boost::filesystem;
class GUI : public QMainWindow, private Ui::MainWindow{
Q_OBJECT

public:
QHash<QString, QStringList> trackerErrors;

private:
// Bittorrent
bittorrent *BTSession;
Expand All @@ -78,21 +75,10 @@ class GUI : public QMainWindow, private Ui::MainWindow{
bool delayedSorting;
Qt::SortOrder delayedSortingOrder;
// Keyboard shortcuts
QShortcut *createShortcut;
QShortcut *openShortcut;
QShortcut *quitShortcut;
QShortcut *switchSearchShortcut;
QShortcut *switchDownShortcut;
QShortcut *switchUpShortcut;
QShortcut *switchRSSShortcut;
QShortcut *propertiesShortcut;
QShortcut *optionsShortcut;
QShortcut *delShortcut;
QShortcut *delPermShortcut;
QShortcut *startShortcut;
QShortcut *startAllShortcut;
QShortcut *pauseShortcut;
QShortcut *pauseAllPermShortcut;
// Preview
previewSelect *previewSelection;
QProcess *previewProcess;
Expand Down Expand Up @@ -185,7 +171,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{
void finishedTorrent(torrent_handle& h);
void fullDiskError(torrent_handle& h);
void portListeningFailure();
void trackerError(QString hash, QString time, QString msg);
void trackerAuthenticationRequired(torrent_handle& h);
void setTabText(int index, QString text);
void updateFileSize(QString hash);
Expand Down
14 changes: 12 additions & 2 deletions src/bittorrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ void bittorrent::deleteTorrent(QString hash, bool permanent){
// Remove it from ETAs hash tables
ETAstats.take(hash);
ETAs.take(hash);
// Remove tracker errors
trackersErrors.take(hash);
// Remove it from ratio table
ratioData.take(hash);
int index = fullAllocationModeList.indexOf(hash);
Expand Down Expand Up @@ -900,8 +902,12 @@ void bittorrent::readAlerts(){
}
else if (tracker_alert* p = dynamic_cast<tracker_alert*>(a.get())){
// Level: fatal
QString fileHash = QString(misc::toString(p->handle.info_hash()).c_str());
emit trackerError(fileHash, QTime::currentTime().toString("hh:mm:ss"), QString(a->msg().c_str()));
QString hash = QString(misc::toString(p->handle.info_hash()).c_str());
QList<QPair<QString, QString> > errors = trackersErrors.value(hash, QList<QPair<QString, QString> >());
if(errors.size() > 5)
errors.removeAt(0);
errors << QPair<QString,QString>(QTime::currentTime().toString("hh:mm:ss"), QString(a->msg().c_str()));
trackersErrors[hash] = errors;
// Authentication
if(p->status_code == 401){
emit trackerAuthenticationRequired(p->handle);
Expand All @@ -920,6 +926,10 @@ void bittorrent::readAlerts(){
}
}

QList<QPair<QString, QString> > bittorrent::getTrackersErrors(QString hash) const{
return trackersErrors.value(hash, QList<QPair<QString, QString> >());
}

// Reload a torrent with full allocation mode
void bittorrent::reloadTorrent(const torrent_handle &h){
qDebug("** Reloading a torrent");
Expand Down
4 changes: 4 additions & 0 deletions src/bittorrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <QHash>
#include <QTimer>
#include <QList>
#include <QPair>
#include <QStringList>

#include <libtorrent/torrent_handle.hpp>
Expand Down Expand Up @@ -52,6 +54,7 @@ class bittorrent : public QObject{
QHash<QString, QPair<size_type,size_type> > ratioData;
QTimer ETARefresher;
QList<QString> fullAllocationModeList;
QHash<QString, QList<QPair<QString, QString> > > trackersErrors;

protected:
QString getSavePath(QString hash);
Expand All @@ -78,6 +81,7 @@ class bittorrent : public QObject{
bool inFullAllocationMode(QString hash) const;
float getRealRatio(QString hash) const;
session* getSession() const;
QList<QPair<QString, QString> > getTrackersErrors(QString hash) const;

public slots:
void addTorrent(QString path, bool fromScanDir = false, bool onStartup = false, QString from_url = QString());
Expand Down
31 changes: 21 additions & 10 deletions src/properties_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QStandardItemModel>

// Constructor
properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h, QStringList trackerErrors): QDialog(parent), h(h){
properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h): QDialog(parent), h(h){
setupUi(this);
this->BTSession = BTSession;
changedFilteredfiles = false;
Expand Down Expand Up @@ -100,10 +100,7 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h
}
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
shareRatio->setText(tmp);
// Tracker Errors
for(int i=0; i < trackerErrors.size(); ++i){
this->trackerErrors->append(trackerErrors.at(i));
}
loadTrackersErrors();
std::vector<float> fp;
h.file_progress(fp);
// List files in torrent
Expand All @@ -125,18 +122,31 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h
}else{
incrementalDownload->setChecked(false);
}
updateProgressTimer = new QTimer(this);
connect(updateProgressTimer, SIGNAL(timeout()), this, SLOT(updateProgress()));
updateProgressTimer->start(2000);
updateInfosTimer = new QTimer(this);
connect(updateInfosTimer, SIGNAL(timeout()), this, SLOT(updateInfos()));
updateInfosTimer->start(2000);
}

properties::~properties(){
qDebug("Properties destroyed");
delete updateProgressTimer;
delete updateInfosTimer;
delete PropDelegate;
delete PropListModel;
}

void properties::loadTrackersErrors(){
// Tracker Errors
QList<QPair<QString, QString> > errors = BTSession->getTrackersErrors(fileHash);
unsigned int nbTrackerErrors = errors.size();
trackerErrors->clear();
for(unsigned int i=0; i < nbTrackerErrors; ++i){
QPair<QString, QString> pair = errors.at(i);
trackerErrors->append("<font color='grey'>"+pair.first+"</font> - <font color='red'>"+pair.second+"</font>");
}
if(!nbTrackerErrors)
trackerErrors->append(tr("None", "i.e: No error message"));
}

void properties::loadWebSeeds(){
QString url_seed;
torrent_info torrentInfo = h.get_torrent_info();
Expand Down Expand Up @@ -424,7 +434,7 @@ void properties::lowerSelectedTracker(){
}
}

void properties::updateProgress(){
void properties::updateInfos(){
std::vector<float> fp;
try{
h.file_progress(fp);
Expand All @@ -436,6 +446,7 @@ void properties::updateProgress(){
// torrent was removed, closing properties
close();
}
loadTrackersErrors();
}

// Set the color of a row in data model
Expand Down
7 changes: 4 additions & 3 deletions src/properties_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class properties : public QDialog, private Ui::properties{
QString fileHash;
PropListDelegate *PropDelegate;
QStandardItemModel *PropListModel;
QTimer *updateProgressTimer;
QTimer *updateInfosTimer;
bool has_filtered_files;
bool changedFilteredfiles;
bittorrent *BTSession;
Expand All @@ -50,7 +50,7 @@ class properties : public QDialog, private Ui::properties{
void on_incrementalDownload_stateChanged(int);
void setRowColor(int row, QString color);
void savePiecesPriorities();
void updateProgress();
void updateInfos();
void loadPiecesPriorities();
void setAllPiecesState(unsigned short priority);
void askForTracker();
Expand All @@ -68,6 +68,7 @@ class properties : public QDialog, private Ui::properties{
void saveWebSeeds();
void loadWebSeedsFromFile();
void deleteSelectedUrlSeeds();
void loadTrackersErrors();

signals:
void filteredFilesChanged(QString fileHash);
Expand All @@ -76,7 +77,7 @@ class properties : public QDialog, private Ui::properties{

public:
// Constructor
properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h, QStringList trackerErrors = QStringList());
properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h);
~properties();
};

Expand Down

0 comments on commit f839d6f

Please sign in to comment.