diff --git a/src/DLListDelegate.h b/src/DLListDelegate.h
index 871b5bfb5..52ecb9c94 100644
--- a/src/DLListDelegate.h
+++ b/src/DLListDelegate.h
@@ -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;
diff --git a/src/FinishedListDelegate.h b/src/FinishedListDelegate.h
index 68881ffb4..dacd4f4a8 100644
--- a/src/FinishedListDelegate.h
+++ b/src/FinishedListDelegate.h
@@ -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;
diff --git a/src/GUI.cpp b/src/GUI.cpp
index 297015073..62d33e1b3 100644
--- a/src/GUI.cpp
+++ b/src/GUI.cpp
@@ -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("")+tr("qBittorrent")+QString::fromUtf8("
")+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString::fromUtf8(tmp2))+QString::fromUtf8("
")+tr("UP speed: %1 KiB/s", "e.g: Upload speed: 10 KiB/s").arg(QString::fromUtf8(tmp))); // tray icon
+ myTrayIcon->setToolTip(QString::fromUtf8("")+tr("qBittorrent")+QString::fromUtf8("
")+tr("DL speed: %1 KiB/s", "e.g: Download speed: 10 KiB/s").arg(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1)))+QString::fromUtf8("
")+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) {
diff --git a/src/PreviewListDelegate.h b/src/PreviewListDelegate.h
index 135da7c8b..5144afe80 100644
--- a/src/PreviewListDelegate.h
+++ b/src/PreviewListDelegate.h
@@ -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;
diff --git a/src/PropListDelegate.h b/src/PropListDelegate.h
index 8268c1602..a4202ca08 100644
--- a/src/PropListDelegate.h
+++ b/src/PropListDelegate.h
@@ -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;
diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp
index de6aa79a3..ec69885e2 100644
--- a/src/downloadingTorrents.cpp
+++ b/src/downloadingTorrents.cpp
@@ -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;
diff --git a/src/misc.h b/src/misc.h
index 4b46145de..00e5059a0 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -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);
diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp
index c9122f21c..e2319b5e7 100644
--- a/src/properties_imp.cpp
+++ b/src/properties_imp.cpp
@@ -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 fp;
h.file_progress(fp);