|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: VideoCollectionUtils class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 |
|
21 #include <qobject.h> |
|
22 #include "videocollectionutils.h" |
|
23 |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // instance |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 VideoCollectionUtils& VideoCollectionUtils::instance() |
|
30 { |
|
31 static VideoCollectionUtils _collectionUtilsInstance; |
|
32 return _collectionUtilsInstance; |
|
33 } |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // VideoCollectionUtils |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 VideoCollectionUtils::VideoCollectionUtils() |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // ~CVideoCollectionUtils |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 VideoCollectionUtils::~VideoCollectionUtils() |
|
49 { |
|
50 |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // prepareLengthString |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 QString VideoCollectionUtils::prepareLengthString(quint32 length) |
|
58 { |
|
59 const int secondsInMinute( 60 ); |
|
60 const int secondsInHour( 3600 ); |
|
61 QString lengthStr(""); |
|
62 |
|
63 if ( length > 0 ) |
|
64 { |
|
65 quint32 hours = length / secondsInHour; |
|
66 quint32 minutes = length / secondsInMinute % secondsInMinute; |
|
67 quint32 seconds = length % secondsInMinute; |
|
68 |
|
69 if ( hours > 0 ) |
|
70 { |
|
71 if(hours == 1) |
|
72 { |
|
73 lengthStr = QObject::tr("%1 hour ").arg(QString::number(hours)); //localisation |
|
74 } |
|
75 else |
|
76 { |
|
77 lengthStr += QObject::tr("%1 hours ").arg(QString::number(hours)); //localisation |
|
78 } |
|
79 } |
|
80 |
|
81 if ( minutes > 0 ) |
|
82 { |
|
83 if(minutes == 1) |
|
84 { |
|
85 lengthStr += QObject::tr("%1 minute ").arg(QString::number(minutes)); //localisation |
|
86 } |
|
87 else |
|
88 { |
|
89 lengthStr += QObject::tr("%1 minutes ").arg(QString::number(minutes)); //localisation |
|
90 } |
|
91 } |
|
92 if (seconds > 0 && hours == 0) |
|
93 { |
|
94 if(seconds == 1) |
|
95 { |
|
96 lengthStr += QObject::tr("%1 second").arg(QString::number(seconds)); //localisation |
|
97 } |
|
98 else |
|
99 { |
|
100 lengthStr += QObject::tr("%1 seconds").arg(QString::number(seconds)); //localisation |
|
101 } |
|
102 } |
|
103 } else { |
|
104 lengthStr += QObject::tr("0 seconds"); //TODO: Localisation |
|
105 } |
|
106 |
|
107 return lengthStr; |
|
108 } |
|
109 // ----------------------------------------------------------------------------- |
|
110 // VideoCollectionUtils::prepareLengthStrings() |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 const QStringList VideoCollectionUtils::prepareLengthStrings(quint32 total) |
|
114 { |
|
115 const int secondsInMinute( 60 ); |
|
116 const int secondsInHour( 3600 ); |
|
117 |
|
118 quint32 hours(0); |
|
119 quint32 minutes(0); |
|
120 quint32 seconds(0); |
|
121 |
|
122 QString hrs(""); |
|
123 QString mins(""); |
|
124 QString secs(""); |
|
125 |
|
126 if ( total > 0 ) |
|
127 { |
|
128 hours = (total / secondsInHour); |
|
129 total = total - (hours * secondsInHour); |
|
130 minutes = (total / secondsInMinute); |
|
131 seconds = (total % secondsInMinute); |
|
132 } |
|
133 |
|
134 hrs = QString::number(hours); |
|
135 |
|
136 if (minutes < 10) |
|
137 { |
|
138 mins = "0" + QString::number(minutes); |
|
139 |
|
140 } |
|
141 else |
|
142 { |
|
143 mins = QString::number(minutes); |
|
144 } |
|
145 |
|
146 if (seconds < 10) |
|
147 { |
|
148 secs = "0" + QString::number(seconds); |
|
149 |
|
150 } |
|
151 else |
|
152 { |
|
153 secs = QString::number(seconds); |
|
154 } |
|
155 |
|
156 QStringList retVal; |
|
157 |
|
158 retVal.append(hrs); |
|
159 retVal.append(mins); |
|
160 retVal.append(secs); |
|
161 |
|
162 return retVal; |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // prepareSizeString |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 QString VideoCollectionUtils::prepareSizeString(quint32 size) |
|
171 { |
|
172 const int videoSizeGB( 0x40000000 ); |
|
173 const int videoSizeHalfGB( 0x20000000 ); |
|
174 const int videoSizeMB( 0x100000 ); |
|
175 const int videoSizeHalfMB( 0x80000 ); |
|
176 const int videoSizeKB( 0x400 ); |
|
177 const int videoSizeHalfKB( 0x200 ); |
|
178 |
|
179 QString sizeStr(""); |
|
180 |
|
181 if ( size > 0 ) |
|
182 { |
|
183 quint32 dispSize = 0; |
|
184 |
|
185 if ( size >= videoSizeGB ) |
|
186 { |
|
187 dispSize = size + videoSizeHalfGB; |
|
188 dispSize /= videoSizeGB; |
|
189 sizeStr = QString(QObject::tr("%1 GB").arg(QString::number(dispSize))); //localisation |
|
190 } |
|
191 else if ( size >= videoSizeMB ) |
|
192 { |
|
193 dispSize = size + videoSizeHalfMB; |
|
194 dispSize /= videoSizeMB; |
|
195 sizeStr = QString(QObject::tr("%1 MB").arg(QString::number(dispSize))); //localisation |
|
196 } |
|
197 else if (size >= videoSizeKB) |
|
198 { |
|
199 dispSize = size + videoSizeHalfKB; |
|
200 dispSize /= videoSizeKB; |
|
201 sizeStr = QString(QObject::tr("%1 kB").arg(QString::number(dispSize))); //localisation |
|
202 } |
|
203 else |
|
204 { |
|
205 sizeStr = QString(QObject::tr("%1B").arg(QString::number(size))); //localisation |
|
206 } |
|
207 } |
|
208 |
|
209 return sizeStr; |
|
210 } |
|
211 |
|
212 // End of file |