mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Fixed a bug in last commit in qBittorrentPath()
- Optimized float to string conversions
This commit is contained in:
parent
c064e5877c
commit
105563ac5a
@ -51,7 +51,6 @@ class DLListDelegate: public QItemDelegate {
|
|||||||
~DLListDelegate(){}
|
~DLListDelegate(){}
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||||
switch(index.column()){
|
switch(index.column()){
|
||||||
case SIZE:
|
case SIZE:
|
||||||
@ -65,25 +64,21 @@ class DLListDelegate: public QItemDelegate {
|
|||||||
case UPSPEED:
|
case UPSPEED:
|
||||||
case DLSPEED:{
|
case DLSPEED:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
float speed = index.data().toDouble();
|
double speed = index.data().toDouble();
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.);
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s"));
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp)+QString::fromUtf8(" ")+tr("KiB/s"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RATIO:{
|
case RATIO:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
float ratio = index.data().toDouble();
|
double ratio = index.data().toDouble();
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1)));
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PROGRESS:{
|
case PROGRESS:{
|
||||||
QStyleOptionProgressBarV2 newopt;
|
QStyleOptionProgressBarV2 newopt;
|
||||||
float progress;
|
double progress = index.data().toDouble()*100.;
|
||||||
progress = index.data().toDouble()*100.;
|
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
|
|
||||||
newopt.rect = opt.rect;
|
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.progress = (int)progress;
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
|
@ -49,7 +49,6 @@ class FinishedListDelegate: public QItemDelegate {
|
|||||||
~FinishedListDelegate(){}
|
~FinishedListDelegate(){}
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||||
switch(index.column()){
|
switch(index.column()){
|
||||||
case F_SIZE:
|
case F_SIZE:
|
||||||
@ -58,25 +57,21 @@ class FinishedListDelegate: public QItemDelegate {
|
|||||||
break;
|
break;
|
||||||
case F_UPSPEED:{
|
case F_UPSPEED:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
float speed = index.data().toDouble();
|
double speed = index.data().toDouble();
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", speed/1024.);
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s"));
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp)+QString::fromUtf8(" ")+tr("KiB/s"));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case F_RATIO:{
|
case F_RATIO:{
|
||||||
QItemDelegate::drawBackground(painter, opt, index);
|
QItemDelegate::drawBackground(painter, opt, index);
|
||||||
float ratio = index.data().toDouble();
|
double ratio = index.data().toDouble();
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
|
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1)));
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8(tmp));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case F_PROGRESS:{
|
case F_PROGRESS:{
|
||||||
QStyleOptionProgressBarV2 newopt;
|
QStyleOptionProgressBarV2 newopt;
|
||||||
float progress;
|
double progress = index.data().toDouble()*100.;
|
||||||
progress = index.data().toDouble()*100.;
|
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
|
|
||||||
newopt.rect = opt.rect;
|
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.progress = (int)progress;
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
|
@ -1063,14 +1063,9 @@ void GUI::checkConnectionStatus() {
|
|||||||
// qDebug("Checking connection status");
|
// qDebug("Checking connection status");
|
||||||
// Update Ratio
|
// Update Ratio
|
||||||
downloadingTorrentTab->updateRatio();
|
downloadingTorrentTab->updateRatio();
|
||||||
// Update systemTray
|
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
char tmp2[MAX_CHAR_TMP];
|
|
||||||
// update global informations
|
// update global informations
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadUploadRate()/1024.);
|
|
||||||
snprintf(tmp2, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadDownloadRate()/1024.);
|
|
||||||
if(systrayIntegration) {
|
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();
|
session_status sessionStatus = BTSession->getSessionStatus();
|
||||||
if(sessionStatus.has_incoming_connections) {
|
if(sessionStatus.has_incoming_connections) {
|
||||||
|
@ -46,7 +46,6 @@ class PreviewListDelegate: public QItemDelegate {
|
|||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
|
|
||||||
switch(index.column()){
|
switch(index.column()){
|
||||||
case SIZE:
|
case SIZE:
|
||||||
@ -55,10 +54,9 @@ class PreviewListDelegate: public QItemDelegate {
|
|||||||
break;
|
break;
|
||||||
case PROGRESS:{
|
case PROGRESS:{
|
||||||
float progress = index.data().toDouble()*100.;
|
float progress = index.data().toDouble()*100.;
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
|
|
||||||
QStyleOptionProgressBarV2 newopt;
|
QStyleOptionProgressBarV2 newopt;
|
||||||
newopt.rect = opt.rect;
|
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.progress = (int)progress;
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
|
@ -58,7 +58,6 @@ class PropListDelegate: public QItemDelegate {
|
|||||||
~PropListDelegate(){}
|
~PropListDelegate(){}
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
|
||||||
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
|
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
|
||||||
switch(index.column()){
|
switch(index.column()){
|
||||||
@ -69,9 +68,8 @@ class PropListDelegate: public QItemDelegate {
|
|||||||
case PROGRESS:{
|
case PROGRESS:{
|
||||||
QStyleOptionProgressBarV2 newopt;
|
QStyleOptionProgressBarV2 newopt;
|
||||||
float progress = index.data().toDouble()*100.;
|
float progress = index.data().toDouble()*100.;
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", progress);
|
|
||||||
newopt.rect = opt.rect;
|
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.progress = (int)progress;
|
||||||
newopt.maximum = 100;
|
newopt.maximum = 100;
|
||||||
newopt.minimum = 0;
|
newopt.minimum = 0;
|
||||||
|
@ -307,7 +307,6 @@ QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DownloadingTorrents::updateRatio() {
|
void DownloadingTorrents::updateRatio() {
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
// Update ratio info
|
// Update ratio info
|
||||||
float ratio = 1.;
|
float ratio = 1.;
|
||||||
session_status sessionStatus = BTSession->getSessionStatus();
|
session_status sessionStatus = BTSession->getSessionStatus();
|
||||||
@ -321,8 +320,7 @@ void DownloadingTorrents::updateRatio() {
|
|||||||
if(ratio > 10.)
|
if(ratio > 10.)
|
||||||
ratio = 10.;
|
ratio = 10.;
|
||||||
}
|
}
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
|
LCD_Ratio->display(QString(QByteArray::number(ratio, 'f', 1)));
|
||||||
LCD_Ratio->display(tmp);
|
|
||||||
if(ratio < 0.5) {
|
if(ratio < 0.5) {
|
||||||
lbl_ratio_icon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/unhappy.png")));
|
lbl_ratio_icon->setPixmap(QPixmap(QString::fromUtf8(":/Icons/unhappy.png")));
|
||||||
}else{
|
}else{
|
||||||
@ -352,14 +350,9 @@ void DownloadingTorrents::sortProgressColumnDelayed() {
|
|||||||
// get information from torrent handles and
|
// get information from torrent handles and
|
||||||
// update download list accordingly
|
// update download list accordingly
|
||||||
void DownloadingTorrents::updateDlList() {
|
void DownloadingTorrents::updateDlList() {
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
char tmp2[MAX_CHAR_TMP];
|
|
||||||
// update global informations
|
// update global informations
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadUploadRate()/1024.);
|
LCD_UpSpeed->display(QString(QByteArray::number(BTSession->getPayloadUploadRate()/1024., 'f', 1))); // UP LCD
|
||||||
snprintf(tmp2, MAX_CHAR_TMP, "%.1f", BTSession->getPayloadDownloadRate()/1024.);
|
LCD_DownSpeed->display(QString(QByteArray::number(BTSession->getPayloadDownloadRate()/1024., 'f', 1))); // DL LCD
|
||||||
//BTSession->printPausedTorrents();
|
|
||||||
LCD_UpSpeed->display(QString::fromUtf8(tmp)); // UP LCD
|
|
||||||
LCD_DownSpeed->display(QString::fromUtf8(tmp2)); // DL LCD
|
|
||||||
// browse handles
|
// browse handles
|
||||||
QStringList unfinishedTorrents = BTSession->getUnfinishedTorrents();
|
QStringList unfinishedTorrents = BTSession->getUnfinishedTorrents();
|
||||||
QString hash;
|
QString hash;
|
||||||
|
11
src/misc.h
11
src/misc.h
@ -37,8 +37,6 @@
|
|||||||
#include "qtorrenthandle.h"
|
#include "qtorrenthandle.h"
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
#define MAX_CHAR_TMP 128
|
|
||||||
|
|
||||||
/* Miscellaneaous functions that can be useful */
|
/* Miscellaneaous functions that can be useful */
|
||||||
class misc : public QObject{
|
class misc : public QObject{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -109,25 +107,22 @@ class misc : public QObject{
|
|||||||
// see http://en.wikipedia.org/wiki/Kilobyte
|
// see http://en.wikipedia.org/wiki/Kilobyte
|
||||||
// value must be given in bytes
|
// value must be given in bytes
|
||||||
static QString friendlyUnit(float val) {
|
static QString friendlyUnit(float val) {
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
if(val < 0) {
|
if(val < 0) {
|
||||||
return tr("Unknown", "Unknown (size)");
|
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)")};
|
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) {
|
for(unsigned int i=0; i<5; ++i) {
|
||||||
if (val < 1024.) {
|
if (val < 1024.) {
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
|
return QString(QByteArray::number(val, 'f', 1)) + units[i];
|
||||||
return QString::fromUtf8(tmp) + units[i];
|
|
||||||
}
|
}
|
||||||
val /= 1024.;
|
val /= 1024.;
|
||||||
}
|
}
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f ", val);
|
return QString(QByteArray::number(val, 'f', 1)) + tr("TiB", "tebibytes (1024 gibibytes)");
|
||||||
return QString::fromUtf8(tmp) + tr("TiB", "tebibytes (1024 gibibytes)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return qBittorrent config path
|
// return qBittorrent config path
|
||||||
static QString qBittorrentPath() {
|
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
|
// Create dir if it does not exist
|
||||||
if(!QFile::exists(qBtPath)){
|
if(!QFile::exists(qBtPath)){
|
||||||
QDir dir(qBtPath);
|
QDir dir(qBtPath);
|
||||||
|
@ -76,7 +76,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
|
|||||||
//Trackers
|
//Trackers
|
||||||
loadTrackers();
|
loadTrackers();
|
||||||
// Session infos
|
// Session infos
|
||||||
char tmp[MAX_CHAR_TMP];
|
|
||||||
failed->setText(misc::friendlyUnit(h.total_failed_bytes()));
|
failed->setText(misc::friendlyUnit(h.total_failed_bytes()));
|
||||||
upTotal->setText(misc::friendlyUnit(h.total_payload_upload()));
|
upTotal->setText(misc::friendlyUnit(h.total_payload_upload()));
|
||||||
dlTotal->setText(misc::friendlyUnit(h.total_payload_download()));
|
dlTotal->setText(misc::friendlyUnit(h.total_payload_download()));
|
||||||
@ -93,8 +92,7 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h
|
|||||||
ratio = 10.;
|
ratio = 10.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf(tmp, MAX_CHAR_TMP, "%.1f", ratio);
|
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
|
||||||
shareRatio->setText(tmp);
|
|
||||||
loadTrackersErrors();
|
loadTrackersErrors();
|
||||||
std::vector<float> fp;
|
std::vector<float> fp;
|
||||||
h.file_progress(fp);
|
h.file_progress(fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user