- Fixed a bug in last commit in qBittorrentPath()

- Optimized float to string conversions
This commit is contained in:
Christophe Dumez 2007-08-28 18:05:20 +00:00
parent c064e5877c
commit 105563ac5a
8 changed files with 22 additions and 55 deletions

View File

@ -51,7 +51,6 @@ class DLListDelegate: public QItemDelegate {
~DLListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
char tmp[MAX_CHAR_TMP];
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()){
case SIZE:
@ -65,25 +64,21 @@ class DLListDelegate: public QItemDelegate {
case UPSPEED:
case DLSPEED:{
QItemDelegate::drawBackground(painter, opt, index);
float speed = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.);
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp)+QString::fromUtf8(" ")+tr("KiB/s"));
double speed = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s"));
break;
}
case RATIO:{
QItemDelegate::drawBackground(painter, opt, index);
float ratio = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp));
double ratio = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1)));
break;
}
case PROGRESS:{
QStyleOptionProgressBarV2 newopt;
float progress;
progress = index.data().toDouble()*100.;
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
double progress = index.data().toDouble()*100.;
newopt.rect = opt.rect;
newopt.text = QString::fromUtf8(tmp)+QString::fromUtf8("%");
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;

View File

@ -49,7 +49,6 @@ class FinishedListDelegate: public QItemDelegate {
~FinishedListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
char tmp[MAX_CHAR_TMP];
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()){
case F_SIZE:
@ -58,25 +57,21 @@ class FinishedListDelegate: public QItemDelegate {
break;
case F_UPSPEED:{
QItemDelegate::drawBackground(painter, opt, index);
float speed = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.);
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp)+QString::fromUtf8(" ")+tr("KiB/s"));
double speed = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s"));
break;
}
case F_RATIO:{
QItemDelegate::drawBackground(painter, opt, index);
float ratio = index.data().toDouble();
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp));
double ratio = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1)));
break;
}
case F_PROGRESS:{
QStyleOptionProgressBarV2 newopt;
float progress;
progress = index.data().toDouble()*100.;
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
double progress = index.data().toDouble()*100.;
newopt.rect = opt.rect;
newopt.text = QString::fromUtf8(tmp)+QString::fromUtf8("%");
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;

View File

@ -1063,14 +1063,9 @@ void GUI::checkConnectionStatus() {
// qDebug("Checking connection status");
// Update Ratio
downloadingTorrentTab->updateRatio();
// Update systemTray
char tmp[MAX_CHAR_TMP];
char tmp2[MAX_CHAR_TMP];
// update global informations
snprintf(tmp, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadUploadRate()/1024.);
snprintf(tmp2, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadDownloadRate()/1024.);
if(systrayIntegration) {
myTrayIcon->setToolTip(QString::fromUtf8("<b>")+tr("qBittorrent")+QString::fromUtf8("</b><br>")+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::fromUtf8(tmp2))+QString::fromUtf8("<br>")+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::fromUtf8(tmp))); // tray icon
myTrayIcon->setToolTip(QString::fromUtf8("<b>")+tr("qBittorrent")+QString::fromUtf8("</b><br>")+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1)))+QString::fromUtf8("<br>")+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1)))); // tray icon
}
session_status sessionStatus = BTSession->getSessionStatus();
if(sessionStatus.has_incoming_connections) {

View File

@ -46,7 +46,6 @@ class PreviewListDelegate: public QItemDelegate {
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
char tmp[MAX_CHAR_TMP];
switch(index.column()){
case SIZE:
@ -55,10 +54,9 @@ class PreviewListDelegate: public QItemDelegate {
break;
case PROGRESS:{
float progress = index.data().toDouble()*100.;
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
QStyleOptionProgressBarV2 newopt;
newopt.rect = opt.rect;
newopt.text = QString::fromUtf8(tmp)+QString::fromUtf8("%");
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;

View File

@ -58,7 +58,6 @@ class PropListDelegate: public QItemDelegate {
~PropListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
char tmp[MAX_CHAR_TMP];
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
switch(index.column()){
@ -69,9 +68,8 @@ class PropListDelegate: public QItemDelegate {
case PROGRESS:{
QStyleOptionProgressBarV2 newopt;
float progress = index.data().toDouble()*100.;
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
newopt.rect = opt.rect;
newopt.text = QString::fromUtf8(tmp)+QString::fromUtf8("%");
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;

View File

@ -307,7 +307,6 @@ QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{
}
void DownloadingTorrents::updateRatio() {
char tmp[MAX_CHAR_TMP];
// Update ratio info
float ratio = 1.;
session_status sessionStatus = BTSession->getSessionStatus();
@ -321,8 +320,7 @@ void DownloadingTorrents::updateRatio() {
if(ratio > 10.)
ratio = 10.;
}
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
LCD_Ratio->display(tmp);
LCD_Ratio->display(QString(QByteArray::number(ratio, 'f', 1)));
if(ratio < 0.5) {
lbl_ratio_icon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/unhappy.png")));
}else{
@ -352,14 +350,9 @@ void DownloadingTorrents::sortProgressColumnDelayed() {
// get information from torrent handles and
// update download list accordingly
void DownloadingTorrents::updateDlList() {
char tmp[MAX_CHAR_TMP];
char tmp2[MAX_CHAR_TMP];
// update global informations
snprintf(tmp, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadUploadRate()/1024.);
snprintf(tmp2, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadDownloadRate()/1024.);
//BTSession->printPausedTorrents();
LCD_UpSpeed->display(QString::fromUtf8(tmp)); // UP LCD
LCD_DownSpeed->display(QString::fromUtf8(tmp2)); // DL LCD
LCD_UpSpeed->display(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1))); // UP LCD
LCD_DownSpeed->display(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1))); // DL LCD
// browse handles
QStringList unfinishedTorrents = BTSession->getUnfinishedTorrents();
QString hash;

View File

@ -37,8 +37,6 @@
#include "qtorrenthandle.h"
using namespace libtorrent;
#define MAX_CHAR_TMP 128
/* Miscellaneaous functions that can be useful */
class misc : public QObject{
Q_OBJECT
@ -109,25 +107,22 @@ class misc : public QObject{
// see http://en.wikipedia.org/wiki/Kilobyte
// value must be given in bytes
static QString friendlyUnit(float val) {
char tmp[MAX_CHAR_TMP];
if(val < 0) {
return tr("Unknown", "Unknown (size)");
}
const QString units[4] = {tr("B", "bytes"), tr("KiB", "kibibytes (1024 bytes)"), tr("MiB", "mebibytes (1024 kibibytes)"), tr("GiB", "gibibytes (1024 mibibytes)")};
for(unsigned int i=0; i<5; ++i) {
if (val < 1024.) {
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
return QString::fromUtf8(tmp) + units[i];
return QString(QByteArray::number(val, 'f', 1)) + units[i];
}
val /= 1024.;
}
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
return QString::fromUtf8(tmp) + tr("TiB", "tebibytes (1024 gibibytes)");
return QString(QByteArray::number(val, 'f', 1)) + tr("TiB", "tebibytes (1024 gibibytes)");
}
// return qBittorrent config path
static QString qBittorrentPath() {
QString qBtPath = QDir::cleanPath(QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator());
QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
// Create dir if it does not exist
if(!QFile::exists(qBtPath)){
QDir dir(qBtPath);

View File

@ -76,7 +76,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
//Trackers
loadTrackers();
// Session infos
char tmp[MAX_CHAR_TMP];
failed->setText(misc::friendlyUnit(h.total_failed_bytes()));
upTotal->setText(misc::friendlyUnit(h.total_payload_upload()));
dlTotal->setText(misc::friendlyUnit(h.total_payload_download()));
@ -93,8 +92,7 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
ratio = 10.;
}
}
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
shareRatio->setText(tmp);
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
loadTrackersErrors();
std::vector<float> fp;
h.file_progress(fp);