File: util.h

package info (click to toggle)
dc-qt 0.2.0.alpha-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,948 kB
  • ctags: 5,361
  • sloc: cpp: 28,936; makefile: 19
file content (30 lines) | stat: -rw-r--r-- 472 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef UTIL_H__
#define UTIL_H__

#include "global.h"
#include <QString>
#include <QStringList>

class Util
{
	public:
		static QString bytesToStr(qint64 bytes,int prec = 1)
		{
			double b = bytes;
			QStringList sl;
			sl+="%1 B";
			sl+="%1 KiB";
			sl+="%1 MiB";
			sl+="%1 GiB";
			sl+="%1 TiB";
			
			for(int i = 0;i<sl.size()-1;i++)
				if(b < 1024) return sl[i].arg(b,0,'f',prec); else b/=1024;
				
			return sl[sl.size()-1].arg(b,0,'f',prec);
		}

};


#endif