Browse Source

- Improved trackers errors code a lot and moved it to Bittorrent class

- 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).
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
f839d6fe41
  1. 8
      TODO
  2. 3
      src/FinishedTorrents.cpp
  3. 23
      src/GUI.cpp
  4. 15
      src/GUI.h
  5. 14
      src/bittorrent.cpp
  6. 4
      src/bittorrent.h
  7. 31
      src/properties_imp.cpp
  8. 7
      src/properties_imp.h

8
TODO

@ -27,22 +27,24 @@ @@ -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

3
src/FinishedTorrents.cpp

@ -237,8 +237,7 @@ void FinishedTorrents::showProperties(const QModelIndex &index){ @@ -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();

23
src/GUI.cpp

@ -138,7 +138,6 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ @@ -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)));
@ -1231,8 +1230,7 @@ void GUI::showProperties(const QModelIndex &index){ @@ -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();
@ -1429,10 +1427,10 @@ void GUI::on_actionStart_All_triggered(){ @@ -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."));
}
@ -1530,17 +1528,6 @@ void GUI::portListeningFailure(){ @@ -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){

15
src/GUI.h

@ -52,9 +52,6 @@ namespace fs = boost::filesystem; @@ -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;
@ -78,21 +75,10 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -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;
@ -185,7 +171,6 @@ class GUI : public QMainWindow, private Ui::MainWindow{ @@ -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);

14
src/bittorrent.cpp

@ -167,6 +167,8 @@ void bittorrent::deleteTorrent(QString hash, bool permanent){ @@ -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);
@ -900,8 +902,12 @@ void bittorrent::readAlerts(){ @@ -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);
@ -920,6 +926,10 @@ void bittorrent::readAlerts(){ @@ -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");

4
src/bittorrent.h

@ -23,6 +23,8 @@ @@ -23,6 +23,8 @@
#include <QHash>
#include <QTimer>
#include <QList>
#include <QPair>
#include <QStringList>
#include <libtorrent/torrent_handle.hpp>
@ -52,6 +54,7 @@ class bittorrent : public QObject{ @@ -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);
@ -78,6 +81,7 @@ class bittorrent : public QObject{ @@ -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());

31
src/properties_imp.cpp

@ -31,7 +31,7 @@ @@ -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;
@ -100,10 +100,7 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h @@ -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
@ -125,18 +122,31 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h @@ -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();
@ -424,7 +434,7 @@ void properties::lowerSelectedTracker(){ @@ -424,7 +434,7 @@ void properties::lowerSelectedTracker(){
}
}
void properties::updateProgress(){
void properties::updateInfos(){
std::vector<float> fp;
try{
h.file_progress(fp);
@ -436,6 +446,7 @@ void properties::updateProgress(){ @@ -436,6 +446,7 @@ void properties::updateProgress(){
// torrent was removed, closing properties
close();
}
loadTrackersErrors();
}
// Set the color of a row in data model

7
src/properties_imp.h

@ -39,7 +39,7 @@ class properties : public QDialog, private Ui::properties{ @@ -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;
@ -50,7 +50,7 @@ class properties : public QDialog, private Ui::properties{ @@ -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();
@ -68,6 +68,7 @@ class properties : public QDialog, private Ui::properties{ @@ -68,6 +68,7 @@ class properties : public QDialog, private Ui::properties{
void saveWebSeeds();
void loadWebSeedsFromFile();
void deleteSelectedUrlSeeds();
void loadTrackersErrors();
signals:
void filteredFilesChanged(QString fileHash);
@ -76,7 +77,7 @@ class properties : public QDialog, private Ui::properties{ @@ -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();
};

Loading…
Cancel
Save