Browse Source

- Added ratio column

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
86a0e68f46
  1. 1
      Changelog
  2. 2
      TODO
  3. 8
      src/DLListDelegate.h
  4. 5
      src/FinishedTorrents.cpp
  5. 21
      src/GUI.cpp
  6. 83
      src/bittorrent.cpp
  7. 4
      src/bittorrent.h
  8. 11
      src/properties_imp.cpp

1
Changelog

@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
- FEATURE: Added a way to link against static libtorrent (useful for deb packages)
- FEATURE: Allow to set global upload/download limits from tray icon menu
- FEATURE: IPv6 is now fully supported
- FEATURE: Real torrent share ratio is now displayed in transfer list
- I18N: Added Hungarian translation
- BUGFIX: Progress of paused torrents is now correct on restart
- BUGFIX: Progress column gets sorted on restart it is was during last execution

2
TODO

@ -35,7 +35,6 @@ @@ -35,7 +35,6 @@
- Check storage st creation + hasher in torrent creation
- test IPv6 support
- Display Url seeds in torrent properties and allow to edit them
- Improve ratio display / calculation / saving / per torrent... (beta2?)
- Sorting in Download Status column should be smarter than just an alphabetical sort
- Windows port : http://www.peerweb.nl/qbittorrent/experimentalbuild/testing.zip
- Write documentation
@ -43,6 +42,7 @@ @@ -43,6 +42,7 @@
- Fix all (or almost all) opened bugs in bug tracker
- Fix sorting with Qt 4.3 - Reported to Trolltech, waiting for fix
- update sorting when a new torrent is added?
- Allow to hide columns
* beta2
- Wait for some bug fixes in libtorrent :
- upload/download limit per torrent

8
src/DLListDelegate.h

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
#define DLSPEED 3
#define UPSPEED 4
#define SEEDSLEECH 5
#define STATUS 6
#define RATIO 6
#define ETA 7
#define HASH 8
@ -92,6 +92,12 @@ class DLListDelegate: public QAbstractItemDelegate { @@ -92,6 +92,12 @@ class DLListDelegate: public QAbstractItemDelegate {
painter->drawText(option.rect, Qt::AlignCenter, QString(tmp)+" "+tr("KiB/s"));
break;
}
case RATIO:{
float ratio = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
painter->drawText(option.rect, Qt::AlignCenter, QString(tmp));
break;
}
case PROGRESS:{
QStyleOptionProgressBarV2 newopt;
float progress;

5
src/FinishedTorrents.cpp

@ -38,7 +38,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){ @@ -38,7 +38,7 @@ FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){
finishedListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("DL Speed", "i.e: Download speed"));
finishedListModel->setHeaderData(UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed"));
finishedListModel->setHeaderData(SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechs", "i.e: full/partial sources"));
finishedListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status"));
finishedListModel->setHeaderData(RATIO, Qt::Horizontal, tr("Ratio"));
finishedListModel->setHeaderData(ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left"));
finishedList->setModel(finishedListModel);
// Hide ETA & hash column
@ -89,6 +89,7 @@ void FinishedTorrents::addFinishedSHA(QString hash){ @@ -89,6 +89,7 @@ void FinishedTorrents::addFinishedSHA(QString hash){
finishedListModel->setData(finishedListModel->index(row, DLSPEED), QVariant((double)0.));
finishedListModel->setData(finishedListModel->index(row, UPSPEED), QVariant((double)0.));
finishedListModel->setData(finishedListModel->index(row, SEEDSLEECH), QVariant("0/0"));
finishedListModel->setData(finishedListModel->index(row, RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(hash)).c_str())));
finishedListModel->setData(finishedListModel->index(row, ETA), QVariant((qlonglong)-1));
finishedListModel->setData(finishedListModel->index(row, HASH), QVariant(hash));
finishedListModel->setData(finishedListModel->index(row, PROGRESS), QVariant((double)1.));
@ -99,7 +100,6 @@ void FinishedTorrents::addFinishedSHA(QString hash){ @@ -99,7 +100,6 @@ void FinishedTorrents::addFinishedSHA(QString hash){
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused");
}
}
finishedListModel->setData(finishedListModel->index(row, STATUS), QVariant(tr("Finished", "i.e: Torrent has finished downloading")));
finishedListModel->setData(finishedListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
setRowColor(row, "orange");
// Create .finished file
@ -263,6 +263,7 @@ void FinishedTorrents::updateFinishedList(){ @@ -263,6 +263,7 @@ void FinishedTorrents::updateFinishedList(){
}
finishedListModel->setData(finishedListModel->index(row, UPSPEED), QVariant((double)torrentStatus.upload_payload_rate));
finishedListModel->setData(finishedListModel->index(row, SEEDSLEECH), QVariant(QString(misc::toString(torrentStatus.num_seeds, true).c_str())+"/"+QString(misc::toString(torrentStatus.num_peers - torrentStatus.num_seeds, true).c_str())));
finishedListModel->setData(finishedListModel->index(row, RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(hash)).c_str())));
}
}

21
src/GUI.cpp

@ -131,7 +131,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ @@ -131,7 +131,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){
DLListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("DL Speed", "i.e: Download speed"));
DLListModel->setHeaderData(UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed"));
DLListModel->setHeaderData(SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechs", "i.e: full/partial sources"));
DLListModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status"));
DLListModel->setHeaderData(RATIO, Qt::Horizontal, tr("Ratio"));
DLListModel->setHeaderData(ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left"));
downloadList->setModel(DLListModel);
DLDelegate = new DLListDelegate(downloadList);
@ -305,7 +305,6 @@ void GUI::togglePausedState(const QModelIndex& index){ @@ -305,7 +305,6 @@ void GUI::togglePausedState(const QModelIndex& index){
QString fileHash = DLListModel->data(DLListModel->index(row, HASH)).toString();
if(BTSession->isPaused(fileHash)){
BTSession->resumeTorrent(fileHash);
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting...")));
setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str())));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
@ -313,7 +312,6 @@ void GUI::togglePausedState(const QModelIndex& index){ @@ -313,7 +312,6 @@ void GUI::togglePausedState(const QModelIndex& index){
BTSession->pauseTorrent(fileHash);
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
setInfoBar(tr("'%1' paused.", "xxx.avi paused.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str())));
DLListModel->setData(DLListModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
@ -524,7 +522,6 @@ void GUI::updateDlList(bool force){ @@ -524,7 +522,6 @@ void GUI::updateDlList(bool force){
if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){
qDebug("Paused torrent finished checking with state: %d", torrentStatus.state);
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
setRowColor(row, "red");
BTSession->pauseTorrent(fileHash);
@ -555,7 +552,6 @@ void GUI::updateDlList(bool force){ @@ -555,7 +552,6 @@ void GUI::updateDlList(bool force){
continue;
case torrent_status::checking_files:
case torrent_status::queued_for_checking:
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Checking...", "i.e: Checking already downloaded parts...")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress));
@ -563,12 +559,10 @@ void GUI::updateDlList(bool force){ @@ -563,12 +559,10 @@ void GUI::updateDlList(bool force){
case torrent_status::connecting_to_tracker:
if(torrentStatus.download_payload_rate > 0){
// Display "Downloading" status when connecting if download speed > 0
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Downloading...")));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(fileHash)));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/downloading.png")), Qt::DecorationRole);
setRowColor(row, "green");
}else{
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting...")));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
@ -580,12 +574,10 @@ void GUI::updateDlList(bool force){ @@ -580,12 +574,10 @@ void GUI::updateDlList(bool force){
case torrent_status::downloading:
case torrent_status::downloading_metadata:
if(torrentStatus.download_payload_rate > 0){
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Downloading...")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/downloading.png")), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(fileHash)));
setRowColor(row, "green");
}else{
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Stalled", "i.e: State of a torrent whose download speed is 0kb/s")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/stalled.png")), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
setRowColor(row, "black");
@ -598,6 +590,7 @@ void GUI::updateDlList(bool force){ @@ -598,6 +590,7 @@ void GUI::updateDlList(bool force){
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
}
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant(QString(misc::toString(torrentStatus.num_seeds, true).c_str())+"/"+QString(misc::toString(torrentStatus.num_peers - torrentStatus.num_seeds, true).c_str())));
DLListModel->setData(DLListModel->index(row, RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(fileHash)).c_str())));
}catch(invalid_handle e){
continue;
}
@ -619,11 +612,9 @@ void GUI::restoreInDownloadList(torrent_handle h){ @@ -619,11 +612,9 @@ void GUI::restoreInDownloadList(torrent_handle h){
DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash));
// Pause torrent if it was paused last time
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")){
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
setRowColor(row, "red");
}else{
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting...")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
}
@ -1093,15 +1084,14 @@ void GUI::torrentAdded(const QString& path, torrent_handle& h, bool fastResume){ @@ -1093,15 +1084,14 @@ void GUI::torrentAdded(const QString& path, torrent_handle& h, bool fastResume){
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.));
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.));
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant("0/0"));
DLListModel->setData(DLListModel->index(row, RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(hash)).c_str())));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash));
// Pause torrent if it was paused last time
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")){
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
setRowColor(row, "red");
}else{
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting...")));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
}
@ -1337,7 +1327,6 @@ void GUI::on_actionPause_All_triggered(){ @@ -1337,7 +1327,6 @@ void GUI::on_actionPause_All_triggered(){
// Update DL list items
DLListModel->setData(DLListModel->index(i, DLSPEED), QVariant((double)0.));
DLListModel->setData(DLListModel->index(i, UPSPEED), QVariant((double)0.));
DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(i, ETA), QVariant((qlonglong)-1));
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/paused.png")), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(i, SEEDSLEECH), QVariant("0/0"));
@ -1362,7 +1351,6 @@ void GUI::on_actionPause_triggered(){ @@ -1362,7 +1351,6 @@ void GUI::on_actionPause_triggered(){
int row = index.row();
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
setInfoBar(tr("'%1' paused.", "xxx.avi paused.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str())));
DLListModel->setData(DLListModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
@ -1385,7 +1373,6 @@ void GUI::on_actionStart_All_triggered(){ @@ -1385,7 +1373,6 @@ void GUI::on_actionStart_All_triggered(){
// Remove .paused file
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
// Update DL list items
DLListModel->setData(DLListModel->index(i, STATUS), QVariant(tr("Connecting...", "i.e: Connecting to the tracker...")));
DLListModel->setData(DLListModel->index(i, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(i, "grey");
}
@ -1408,7 +1395,6 @@ void GUI::on_actionStart_triggered(){ @@ -1408,7 +1395,6 @@ void GUI::on_actionStart_triggered(){
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused");
// Update DL status
int row = index.row();
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Connecting...")));
setInfoBar(tr("'%1' resumed.", "e.g: xxx.avi resumed.").arg(QString(BTSession->getTorrentHandle(fileHash).name().c_str())));
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/connecting.png")), Qt::DecorationRole);
setRowColor(row, "grey");
@ -1474,7 +1460,6 @@ void GUI::fullDiskError(torrent_handle& h){ @@ -1474,7 +1460,6 @@ void GUI::fullDiskError(torrent_handle& h){
int row = getRowFromHash(QString(misc::toString(h.info_hash()).c_str()));
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.0));
DLListModel->setData(DLListModel->index(row, STATUS), QVariant(tr("Paused")));
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
setInfoBar(tr("An error occured (full disk?), '%1' paused.", "e.g: An error occured (full disk?), 'xxx.avi' paused.").arg(QString(h.get_torrent_info().name().c_str())));
DLListModel->setData(DLListModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);

83
src/bittorrent.cpp

@ -146,9 +146,12 @@ void bittorrent::deleteTorrent(const QString& hash, bool permanent){ @@ -146,9 +146,12 @@ void bittorrent::deleteTorrent(const QString& hash, bool permanent){
torrentBackup.remove(hash+".savepath");
torrentBackup.remove(hash+".trackers");
torrentBackup.remove(hash+".speedLimits");
torrentBackup.remove(hash+".ratio");
// Remove it from ETAs hash tables
ETAstats.take(hash);
ETAs.take(hash);
// Remove it from ratio table
ratioData.take(hash);
int index = fullAllocationModeList.indexOf(hash);
if(index != -1)
fullAllocationModeList.removeAt(index);
@ -290,6 +293,8 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, bool onStartu @@ -290,6 +293,8 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, bool onStartu
loadFilesPriorities(h);
// Load speed limit from hard drive
loadTorrentSpeedLimits(hash);
// Load ratio data
loadDownloadUploadForTorrent(hash);
// Load trackers
bool loaded_trackers = loadTrackerFile(hash);
// Doing this to order trackers well
@ -528,6 +533,61 @@ void bittorrent::loadFilesPriorities(torrent_handle &h){ @@ -528,6 +533,61 @@ void bittorrent::loadFilesPriorities(torrent_handle &h){
h.prioritize_files(v);
}
void bittorrent::loadDownloadUploadForTorrent(QString hash){
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
// Checking if torrentBackup Dir exists
// create it if it is not
if(! torrentBackup.exists()){
torrentBackup.mkpath(torrentBackup.path());
}
qDebug("Loading ratio data for %s", (const char*)hash.toUtf8());
QFile ratio_file(torrentBackup.path()+QDir::separator()+ hash + ".ratio");
if(!ratio_file.open(QIODevice::ReadOnly | QIODevice::Text)){
return;
}
QByteArray data = ratio_file.readAll();
QList<QByteArray> data_list = data.split(' ');
if(data_list.size() != 2){
std::cerr << "Corrupted ratio file for torrent: " << hash.toStdString() << '\n';
return;
}
QPair<size_type,size_type> downUp;
downUp.first = (size_type)data_list.at(0).toLong();
downUp.second = (size_type)data_list.at(1).toLong();
ratioData[hash] = downUp;
}
// To remember share ratio or a torrent, we must save current
// total_upload and total_upload and reload them on startup
void bittorrent::saveDownloadUploadForTorrent(QString hash){
qDebug("Saving ratio data");
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
// Checking if torrentBackup Dir exists
// create it if it is not
if(! torrentBackup.exists()){
torrentBackup.mkpath(torrentBackup.path());
}
torrent_handle h = getTorrentHandle(hash);
if(!h.is_valid()){
qDebug("/!\\ Error: Invalid handle");
return;
}
torrent_status torrentStatus = h.status();
QString fileHash = QString(misc::toString(h.info_hash()).c_str());
QPair<size_type,size_type> ratioInfo = ratioData.value(fileHash, QPair<size_type, size_type>(0,0));
long download = torrentStatus.total_payload_download;
download += ratioInfo.first;
long upload = torrentStatus.total_payload_upload;
upload += ratioInfo.second;
QFile ratio_file(torrentBackup.path()+QDir::separator()+ fileHash + ".ratio");
if(!ratio_file.open(QIODevice::WriteOnly | QIODevice::Text)){
std::cerr << "Couldn't save ratio data for torrent: " << fileHash.toStdString() << '\n';
return;
}
ratio_file.write(QByteArray(misc::toString(download).c_str()) + QByteArray(" ") + QByteArray(misc::toString(upload).c_str()));
ratio_file.close();
}
// Save fastresume data for all torrents
// and remove them from the session
void bittorrent::saveFastResumeData(){
@ -562,6 +622,8 @@ void bittorrent::saveFastResumeData(){ @@ -562,6 +622,8 @@ void bittorrent::saveFastResumeData(){
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), resumeData);
}
// Save ratio data
saveDownloadUploadForTorrent(fileHash);
// Save trackers
saveTrackerFile(fileHash);
}
@ -869,6 +931,8 @@ void bittorrent::reloadTorrent(const torrent_handle &h){ @@ -869,6 +931,8 @@ void bittorrent::reloadTorrent(const torrent_handle &h){
loadFilesPriorities(new_h);
// Load speed limit from hard drive
loadTorrentSpeedLimits(fileHash);
// Load ratio data
loadDownloadUploadForTorrent(fileHash);
// Pause torrent if it was paused last time
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+fileHash+".paused")){
new_h.pause();
@ -884,6 +948,25 @@ int bittorrent::getListenPort() const{ @@ -884,6 +948,25 @@ int bittorrent::getListenPort() const{
return s->listen_port();
}
float bittorrent::getRealRatio(QString hash) const{
QPair<size_type,size_type> downUpInfo = ratioData.value(hash, QPair<size_type,size_type>(0,0));
size_type download = downUpInfo.first;
size_type upload = downUpInfo.second;
torrent_handle h = getTorrentHandle(hash);
torrent_status torrentStatus = h.status();
download += torrentStatus.total_payload_download;
upload += torrentStatus.total_payload_upload;
if(download == 0){
if(upload == 0)
return 1.;
return 10.;
}
float ratio = (float)upload / (float)download;
if(ratio > 10.)
ratio = 10.;
return ratio;
}
session_status bittorrent::getSessionStatus() const{
return s->status();
}

4
src/bittorrent.h

@ -61,6 +61,7 @@ class bittorrent : public QObject{ @@ -61,6 +61,7 @@ class bittorrent : public QObject{
QStringList torrentsUnchecked;
QHash<QString, QList<long> > ETAstats;
QHash<QString, long> ETAs;
QHash<QString, QPair<size_type,size_type> > ratioData;
QTimer ETARefresher;
QList<QString> fullAllocationModeList;
@ -87,6 +88,7 @@ class bittorrent : public QObject{ @@ -87,6 +88,7 @@ class bittorrent : public QObject{
long getETA(QString hash) const;
size_type torrentEffectiveSize(QString hash) const;
bool inFullAllocationMode(const QString& hash) const;
float getRealRatio(QString hash) const;
session* getSession() const;
public slots:
@ -113,6 +115,8 @@ class bittorrent : public QObject{ @@ -113,6 +115,8 @@ class bittorrent : public QObject{
void updateETAs();
void saveTorrentSpeedLimits(QString hash);
void loadTorrentSpeedLimits(QString hash);
void saveDownloadUploadForTorrent(QString hash);
void loadDownloadUploadForTorrent(QString hash);
// Session configuration - Setters
void setListeningPortsRange(std::pair<unsigned short, unsigned short> ports);
void setMaxConnections(int maxConnec);

11
src/properties_imp.cpp

@ -69,17 +69,20 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h @@ -69,17 +69,20 @@ properties::properties(QWidget *parent, bittorrent *BTSession, torrent_handle &h
upTotal->setText(misc::friendlyUnit(torrentStatus.total_payload_upload));
dlTotal->setText(misc::friendlyUnit(torrentStatus.total_payload_download));
// Update ratio info
if(torrentStatus.total_payload_download <= 0 || torrentStatus.total_payload_upload <= 0){
shareRatio->setText(tr("Unknown"));
float ratio;
if(torrentStatus.total_payload_download == 0){
if(torrentStatus.total_payload_upload == 0)
ratio = 1.;
else
ratio = 10.; // Max ratio
}else{
float ratio = 1.;
ratio = (float)torrentStatus.total_payload_upload/(float)torrentStatus.total_payload_download;
if(ratio > 10.){
ratio = 10.;
}
}
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));

Loading…
Cancel
Save