Browse Source

- Optimized function that transform a number of seconds to a duration(days, hours, minutes, secs)

- Improved ETA calculation to avoid overflows (Added asserts to make sure it doesn't happen)
adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
21908e0a03
  1. 1
      TODO
  2. 13
      src/bittorrent.cpp
  3. 4
      src/bittorrent.h
  4. 38
      src/misc.h
  5. 8
      src/src.pro

1
TODO

@ -81,5 +81,6 @@ beta5->beta6 changelog:
- BUGFIX: Prevent downloadFromUrl flooding - BUGFIX: Prevent downloadFromUrl flooding
- BUGFIX: Made finished list context menu more similar to the download list one - BUGFIX: Made finished list context menu more similar to the download list one
- BUGFIX: Fixed Pause/Start action in lists context menus - BUGFIX: Fixed Pause/Start action in lists context menus
- BUGFIX: Improved ETA calculation
- BUGFIX: Display the torrent that are being checked as 'checking' in seeding list - BUGFIX: Display the torrent that are being checked as 'checking' in seeding list
- I18N: Removed no longer maintained Traditional chinese translation - I18N: Removed no longer maintained Traditional chinese translation

13
src/bittorrent.cpp

@ -112,19 +112,22 @@ void bittorrent::updateETAs() {
QTorrentHandle h = handles[i]; QTorrentHandle h = handles[i];
if(h.is_valid()) { if(h.is_valid()) {
QString hash = h.hash(); QString hash = h.hash();
QList<long> listEtas = ETAstats.value(hash, QList<long>()); QList<qlonglong> listEtas = ETAstats.value(hash, QList<qlonglong>());
if(listEtas.size() == ETAS_MAX_VALUES) { if(listEtas.size() == ETAS_MAX_VALUES) {
listEtas.removeFirst(); listEtas.removeFirst();
} }
if(h.download_payload_rate() != 0) { if(h.download_payload_rate()) {
listEtas << (long)((h.total_size()-h.total_done())/(double)h.download_payload_rate()); listEtas << (qlonglong)((h.total_size()-h.total_done())/(double)h.download_payload_rate());
ETAstats[hash] = listEtas; ETAstats[hash] = listEtas;
long moy = 0; long moy = 0;
long val; long val;
unsigned int nbETAs = listEtas.size();
Q_ASSERT(nbETAs);
foreach(val, listEtas) { foreach(val, listEtas) {
moy += val; moy += (qlonglong)((double)val/(double)nbETAs);
Q_ASSERT(moy >= 0);
} }
ETAs[hash] = (long) ((double)moy/(double)listEtas.size()); ETAs[hash] = moy;
} }
} }
} }

4
src/bittorrent.h

@ -49,8 +49,8 @@ class bittorrent : public QObject{
QString defaultSavePath; QString defaultSavePath;
QStringList torrentsToPauseAfterChecking; QStringList torrentsToPauseAfterChecking;
QStringList reloadingTorrents; QStringList reloadingTorrents;
QHash<QString, QList<long> > ETAstats; QHash<QString, QList<qlonglong> > ETAstats;
QHash<QString, long> ETAs; QHash<QString, qlonglong> ETAs;
QHash<QString, QPair<size_type,size_type> > ratioData; QHash<QString, QPair<size_type,size_type> > ratioData;
QTimer *ETARefresher; QTimer *ETARefresher;
QStringList fullAllocationModeList; QStringList fullAllocationModeList;

38
src/misc.h

@ -285,28 +285,36 @@ class misc : public QObject{
// Take a number of seconds and return an user-friendly // Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m". // time duration like "1d 2h 10m".
static QString userFriendlyDuration(const long int seconds) { static QString userFriendlyDuration(qlonglong seconds) {
if(seconds < 0) { if(seconds < 0 or seconds > 8640000) {
return tr("Unknown"); return tr("Unknown");
} }
if(seconds < 60) { int level = 0;
int days = int(seconds / 86400.);
if(!days)
level = 1;
else
seconds -= days * 86400;
int hours = int(seconds / 3600.);
if(!hours)
level = 2;
else
seconds -= hours * 3600;
int minutes = int(seconds / 60.0);
if(!minutes)
level = 3;
else
seconds -= minutes * 60;
switch(level){
case 3:
return tr("< 1m", "< 1 minute"); return tr("< 1m", "< 1 minute");
} case 2:
int minutes = seconds / 60;
if(minutes < 60) {
return tr("%1m","e.g: 10minutes").arg(QString::QString::fromUtf8(misc::toString(minutes).c_str())); return tr("%1m","e.g: 10minutes").arg(QString::QString::fromUtf8(misc::toString(minutes).c_str()));
} case 1:
int hours = minutes / 60;
minutes = minutes - hours*60;
if(hours < 24) {
return tr("%1h%2m", "e.g: 3hours 5minutes").arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str())); return tr("%1h%2m", "e.g: 3hours 5minutes").arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str()));
} default:
int days = hours / 24;
hours = hours - days * 24;
if(days < 100) {
return tr("%1d%2h%3m", "e.g: 2days 10hours 2minutes").arg(QString::fromUtf8(misc::toString(days).c_str())).arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str())); return tr("%1d%2h%3m", "e.g: 2days 10hours 2minutes").arg(QString::fromUtf8(misc::toString(days).c_str())).arg(QString::fromUtf8(misc::toString(hours).c_str())).arg(QString::fromUtf8(misc::toString(minutes).c_str()));
} }
return tr("Unknown");
} }
}; };

8
src/src.pro

@ -19,15 +19,15 @@ DEFINES += VERSION_BUGFIX=0
contains(DEBUG_MODE, 1){ contains(DEBUG_MODE, 1){
CONFIG += debug CONFIG += debug
CONFIG -= release CONFIG -= release
QMAKE_CXXFLAGS_RELEASE += -O1 QMAKE_CXXFLAGS_RELEASE += -fwrapv -O1
QMAKE_CXXFLAGS_DEBUG += -O1 QMAKE_CXXFLAGS_DEBUG += -fwrapv -O1
message(Debug build!) message(Debug build!)
} }
contains(DEBUG_MODE, 0){ contains(DEBUG_MODE, 0){
CONFIG -= debug CONFIG -= debug
CONFIG += release CONFIG += release
QMAKE_CXXFLAGS_RELEASE += -O2 QMAKE_CXXFLAGS_RELEASE += -fwrapv -O2
QMAKE_CXXFLAGS_DEBUG += -O2 QMAKE_CXXFLAGS_DEBUG += -fwrapv -O2
message(Release build!) message(Release build!)
} }

Loading…
Cancel
Save