2010-07-03 00:25:22 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2010-07-03 00:25:22 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2010-07-03 00:25:22 +00:00
|
|
|
*
|
|
|
|
* $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:
|
|
|
|
|
2011-05-12 20:21:27 +00:00
|
|
|
static QString memToString( int64_t bytes );
|
|
|
|
static QString sizeToString( int64_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
|