2010-07-03 00:25:22 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2012-2014 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_UNITS
|
|
|
|
#define QTR_UNITS
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QIcon>
|
|
|
|
|
2013-09-08 18:39:37 +00:00
|
|
|
#include <stdint.h> // int64_t
|
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
class Speed;
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
class Formatter: public QObject
|
2010-07-03 00:25:22 +00:00
|
|
|
{
|
2013-02-09 18:59:05 +00:00
|
|
|
Q_OBJECT
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
public:
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
Formatter() {}
|
|
|
|
virtual ~Formatter() {}
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
public:
|
2010-07-03 00:25:22 +00:00
|
|
|
|
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);
|
|
|
|
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
|
|
|
public:
|
2010-07-03 00:25:22 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
typedef enum { B, KB, MB, GB, TB } Size;
|
|
|
|
typedef enum { SPEED, SIZE, MEM } Type;
|
|
|
|
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:
|
2010-07-07 00:30:42 +00:00
|
|
|
|
2013-02-09 18:59:05 +00:00
|
|
|
static QString unitStrings[3][5];
|
2010-07-03 00:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|