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
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#ifndef QTR_FORMATTER_H
|
|
|
|
#define QTR_FORMATTER_H
|
|
|
|
|
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
|
|
|
{
|
2015-06-12 22:12:12 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS (Formatter)
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
public:
|
2015-06-12 22:12:12 +00:00
|
|
|
enum Size
|
|
|
|
{
|
|
|
|
B,
|
|
|
|
KB,
|
|
|
|
MB,
|
|
|
|
GB,
|
|
|
|
TB
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
SPEED,
|
|
|
|
SIZE,
|
|
|
|
MEM
|
|
|
|
};
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
public:
|
2013-08-29 00:37:37 +00:00
|
|
|
static QString memToString (int64_t bytes);
|
|
|
|
static QString sizeToString (int64_t bytes);
|
2013-02-09 18:59:05 +00:00
|
|
|
static QString speedToString (const Speed& speed);
|
|
|
|
static QString percentToString (double x);
|
|
|
|
static QString ratioToString (double ratio);
|
|
|
|
static QString timeToString (int seconds);
|
2015-06-12 22:12:12 +00:00
|
|
|
static QString uploadSpeedToString (const Speed& up);
|
|
|
|
static QString downloadSpeedToString (const Speed& down);
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
static QString unitStr (Type t, Size s) { return unitStrings[t][s]; }
|
|
|
|
static void initUnits ();
|
2010-07-07 00:30:42 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
private:
|
|
|
|
static QString unitStrings[3][5];
|
2010-07-03 00:25:22 +00:00
|
|
|
};
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#endif // QTR_FORMATTER_H
|