2010-07-03 00:25:22 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2012-2015 Mnemosyne LLC
|
2010-07-03 00:25:22 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-07-03 00:25:22 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:41:36 +00:00
|
|
|
#include <cstdint> // int64_t
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
#include <QCoreApplication>
|
2010-07-03 00:25:22 +00:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
class Speed;
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class Formatter
|
2010-07-03 00:25:22 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Formatter)
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2015-06-12 22:12:12 +00:00
|
|
|
enum Size
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
B,
|
|
|
|
KB,
|
|
|
|
MB,
|
|
|
|
GB,
|
|
|
|
TB
|
2015-06-12 22:12:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
SPEED,
|
|
|
|
SIZE,
|
|
|
|
MEM
|
2015-06-12 22:12:12 +00:00
|
|
|
};
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
|
|
|
static QString memToString(int64_t bytes);
|
|
|
|
static QString sizeToString(int64_t bytes);
|
2017-04-20 16:02:19 +00:00
|
|
|
static QString speedToString(Speed const& speed);
|
2017-04-19 12:04:45 +00:00
|
|
|
static QString percentToString(double x);
|
|
|
|
static QString ratioToString(double ratio);
|
|
|
|
static QString timeToString(int seconds);
|
2017-04-20 16:02:19 +00:00
|
|
|
static QString uploadSpeedToString(Speed const& up);
|
|
|
|
static QString downloadSpeedToString(Speed const& down);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
static QString unitStr(Type t, Size s)
|
|
|
|
{
|
|
|
|
return unitStrings[t][s];
|
|
|
|
}
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void initUnits();
|
2010-07-07 00:30:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2013-02-09 18:59:05 +00:00
|
|
|
static QString unitStrings[3][5];
|
2010-07-03 00:25:22 +00:00
|
|
|
};
|