From 4908458729a8fc1a1a9a185f468849211b46b700 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 27 Nov 2009 15:59:49 +0000 Subject: [PATCH] - Fixed share ratio display in properties widget and in Web UI --- src/eventmanager.cpp | 6 +++++- src/propertieswidget.cpp | 18 +++++------------- src/webui/scripts/dynamicTable.js | 10 ++++++++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp index 104449f23..518b636ff 100644 --- a/src/eventmanager.cpp +++ b/src/eventmanager.cpp @@ -258,7 +258,11 @@ void EventManager::modifiedTorrent(QTorrentHandle h) leechs += " ("+QString::number(h.num_incomplete())+")"; event["num_leechs"] = QVariant(leechs); event["seed"] = QVariant(h.is_seed()); - event["ratio"] = QVariant(QString::number(BTSession->getRealRatio(hash), 'f', 1)); + double ratio = BTSession->getRealRatio(hash); + if(ratio > 100.) + QString::fromUtf8("∞"); + else + event["ratio"] = QVariant(QString::number(ratio, 'f', 1)); event["hash"] = QVariant(hash); event_list[hash] = event; } diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index c93fa309c..f4e06315f 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -320,19 +320,11 @@ void PropertiesWidget::loadDynamicData() { else lbl_connections->setText(QString::number(h.num_connections())); // Update ratio info - float ratio; - if(h.total_payload_download() == 0){ - if(h.total_payload_upload() == 0) - ratio = 1.; - else - ratio = 10.; // Max ratio - }else{ - ratio = (double)h.total_payload_upload()/(double)h.total_payload_download(); - if(ratio > 10.){ - ratio = 10.; - } - } - shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); + double ratio = BTSession->getRealRatio(h.hash()); + if(ratio > 100.) + shareRatio->setText(QString::fromUtf8("∞")); + else + shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); if(!h.is_seed()) { // Downloaded pieces downloaded_pieces->setProgress(h.pieces()); diff --git a/src/webui/scripts/dynamicTable.js b/src/webui/scripts/dynamicTable.js index bbd80863e..0f89086ca 100644 --- a/src/webui/scripts/dynamicTable.js +++ b/src/webui/scripts/dynamicTable.js @@ -101,10 +101,16 @@ var dynamicTable = new Class ({ else return (tr2.getElements('td')[i].get('html').split(' ')[0].toInt() - tr1.getElements('td')[i].get('html').split(' ')[0].toInt()); default: // Ratio + var ratio1 = tr1.getElements('td')[i].get('html'); + if(ratio1 == '∞') + ratio1 = '101.0'; + var ratio2 = tr2.getElements('td')[i].get('html'); + if(ratio2 == '∞') + ratio2 = '101.0'; if(order == "ASC") - return (tr1.getElements('td')[i].get('html').toFloat() - tr2.getElements('td')[i].get('html')).toFloat(); + return (ratio1.toFloat() - ratio2.toFloat()); else - return (tr2.getElements('td')[i].get('html').toFloat() - tr1.getElements('td')[i].get('html')).toFloat(); + return (ratio2.toFloat() - ratio1.toFloat()); } },