|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 from PyQt4.QtCore import QCoreApplication |
|
7 |
|
8 def timeString(timeRemaining): |
|
9 """ |
|
10 Module function to format the given time. |
|
11 |
|
12 @param timeRemaining time to be formatted (float) |
|
13 @return time string (string) |
|
14 """ |
|
15 if timeRemaining > 60: |
|
16 minutes = int(timeRemaining / 60) |
|
17 seconds = int(timeRemaining % 60) |
|
18 remaining = QCoreApplication.translate("DownloadUtilities", |
|
19 "%n:{0:02} minutes remaining""", "", QCoreApplication.UnicodeUTF8, minutes)\ |
|
20 .format(seconds) |
|
21 else: |
|
22 seconds = int(timeRemaining) |
|
23 remaining = QCoreApplication.translate("DownloadUtilities", |
|
24 "%n seconds remaining", "", QCoreApplication.UnicodeUTF8, seconds) |
|
25 |
|
26 return remaining |
|
27 |
|
28 def dataString(size): |
|
29 """ |
|
30 Module function to generate a formatted size string. |
|
31 |
|
32 @param size size to be formatted (integer) |
|
33 @return formatted data string (string) |
|
34 """ |
|
35 unit = "" |
|
36 if size < 1024: |
|
37 unit = QCoreApplication.translate("DownloadUtilities", "Bytes") |
|
38 elif size < 1024 * 1024: |
|
39 size /= 1024 |
|
40 unit = QCoreApplication.translate("DownloadUtilities", "KiB") |
|
41 elif size < 1024 * 1024 * 1024: |
|
42 size /= 1024 * 1024 |
|
43 unit = QCoreApplication.translate("DownloadUtilities", "MiB") |
|
44 else: |
|
45 size /= 1024 * 1024 * 1024 |
|
46 unit = QCoreApplication.translate("DownloadUtilities", "GiB") |
|
47 return "{0:.1f} {1}".format(size, unit) |