mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
- Fixed a bug in last commit in qBittorrentPath()
- Optimized float to string conversions
This commit is contained in:
parent
c064e5877c
commit
105563ac5a
8 changed files with 22 additions and 55 deletions
11
src/misc.h
11
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue