2010-07-03 00:25:22 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2010 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_UNITS
|
|
|
|
#define QTR_UNITS
|
|
|
|
|
2010-07-26 00:22:07 +00:00
|
|
|
#include <inttypes.h> /* uint64_t */
|
|
|
|
|
2010-07-03 00:25:22 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QIcon>
|
|
|
|
|
|
|
|
class Speed;
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
class Formatter: public QObject
|
2010-07-03 00:25:22 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-07-03 01:10:36 +00:00
|
|
|
Formatter( ) { }
|
|
|
|
virtual ~Formatter( ) { }
|
2010-07-03 00:25:22 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-07-25 20:36:33 +00:00
|
|
|
static QString memToString( uint64_t bytes );
|
|
|
|
static QString sizeToString( uint64_t bytes );
|
2010-07-03 00:25:22 +00:00
|
|
|
static QString speedToString( const Speed& speed );
|
|
|
|
static QString percentToString( double x );
|
|
|
|
static QString ratioToString( double ratio );
|
|
|
|
static QString timeToString( int seconds );
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-07-07 00:30:42 +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( );
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2010-07-24 02:43:06 +00:00
|
|
|
static QString unitStrings[3][5];
|
2010-07-03 00:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|