34
|
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: CVideoCollectionUtils class implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
|
|
20 |
|
|
21 |
#include <qobject.h>
|
|
22 |
#include "videocollectionutils.h"
|
36
|
23 |
#include <QTime>
|
|
24 |
#include <hbextendedlocale.h>
|
34
|
25 |
|
|
26 |
QString VideoCollectionUtils::mPrepareLengthStringReturnValue = "test duration";
|
|
27 |
QString VideoCollectionUtils::mPrepareSizeStringReturnValue = "test size";
|
|
28 |
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
// instance
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
VideoCollectionUtils& VideoCollectionUtils::instance()
|
|
34 |
{
|
|
35 |
static VideoCollectionUtils _collectionUtilsInstance;
|
|
36 |
return _collectionUtilsInstance;
|
|
37 |
}
|
|
38 |
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
// CVideoCollectionUtils
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
VideoCollectionUtils::VideoCollectionUtils()
|
|
44 |
{
|
|
45 |
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// ~CVideoCollectionUtils
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
VideoCollectionUtils::~VideoCollectionUtils()
|
|
53 |
{
|
|
54 |
|
|
55 |
}
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// prepareLengthString
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
QString VideoCollectionUtils::prepareLengthString(quint32 length)
|
|
62 |
{
|
|
63 |
const int secondsInMinute( 60 );
|
|
64 |
const int secondsInHour( 3600 );
|
|
65 |
QString lengthStr("");
|
|
66 |
|
|
67 |
if ( length > 0 )
|
|
68 |
{
|
|
69 |
quint32 hours = length / secondsInHour;
|
|
70 |
quint32 minutes = length / secondsInMinute % secondsInMinute;
|
|
71 |
quint32 seconds = length % secondsInMinute;
|
|
72 |
|
|
73 |
if ( hours > 0 )
|
|
74 |
{
|
|
75 |
if(hours == 1)
|
|
76 |
{
|
|
77 |
lengthStr = QObject::tr("%1 hour ").arg(QString::number(hours));
|
|
78 |
}
|
|
79 |
else
|
|
80 |
{
|
|
81 |
lengthStr += QObject::tr("%1 hours ").arg(QString::number(hours));
|
|
82 |
}
|
|
83 |
}
|
|
84 |
|
|
85 |
if ( minutes > 0 )
|
|
86 |
{
|
|
87 |
if(minutes == 1)
|
|
88 |
{
|
|
89 |
lengthStr += QObject::tr("%1 minute ").arg(QString::number(minutes));
|
|
90 |
}
|
|
91 |
else
|
|
92 |
{
|
|
93 |
lengthStr += QObject::tr("%1 minutes ").arg(QString::number(minutes));
|
|
94 |
}
|
|
95 |
}
|
|
96 |
if (seconds > 0 && hours == 0)
|
|
97 |
{
|
|
98 |
if(seconds == 1)
|
|
99 |
{
|
|
100 |
lengthStr += QObject::tr("%1 second").arg(QString::number(seconds));
|
|
101 |
}
|
|
102 |
else
|
|
103 |
{
|
|
104 |
lengthStr += QObject::tr("%1 seconds").arg(QString::number(seconds));
|
|
105 |
}
|
|
106 |
}
|
|
107 |
} else {
|
|
108 |
lengthStr += QObject::tr("0 seconds");
|
|
109 |
}
|
|
110 |
|
|
111 |
return lengthStr;
|
|
112 |
}
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
36
|
115 |
// VideoCollectionUtils::prepareShortLengthString()
|
34
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
//
|
36
|
118 |
const QString VideoCollectionUtils::prepareShortLengthString(quint32 total)
|
34
|
119 |
{
|
36
|
120 |
const int secondsInMinute( 60 );
|
|
121 |
const int secondsInHour( 3600 );
|
34
|
122 |
|
36
|
123 |
int hour = total / secondsInHour;
|
|
124 |
total = total % secondsInHour;
|
|
125 |
int minutes = total / secondsInMinute;
|
|
126 |
total = total % secondsInMinute;
|
|
127 |
int second = total;
|
|
128 |
|
|
129 |
QTime time( hour ,minutes ,second );
|
|
130 |
QString str;
|
|
131 |
|
|
132 |
HbExtendedLocale locale = HbExtendedLocale::system();
|
|
133 |
|
|
134 |
str = locale.format( time, r_qtn_time_durat_long_with_zero );
|
|
135 |
|
|
136 |
return str;
|
34
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
// -----------------------------------------------------------------------------
|
|
141 |
// prepareSizeString
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
QString VideoCollectionUtils::prepareSizeString(quint32 size)
|
|
145 |
{
|
|
146 |
const int videoSizeGB( 0x40000000 );
|
|
147 |
const int videoSizeHalfGB( 0x20000000 );
|
|
148 |
const int videoSizeMB( 0x100000 );
|
|
149 |
const int videoSizeHalfMB( 0x80000 );
|
|
150 |
const int videoSizeKB( 0x400 );
|
|
151 |
const int videoSizeHalfKB( 0x200 );
|
|
152 |
|
|
153 |
QString sizeStr("");
|
|
154 |
|
|
155 |
if ( size > 0 )
|
|
156 |
{
|
|
157 |
quint32 dispSize = 0;
|
|
158 |
|
|
159 |
if ( size >= videoSizeGB )
|
|
160 |
{
|
|
161 |
dispSize = size + videoSizeHalfGB;
|
|
162 |
dispSize /= videoSizeGB;
|
|
163 |
sizeStr = QString(QObject::tr("%1 GB").arg(QString::number(dispSize)));
|
|
164 |
}
|
|
165 |
else if ( size >= videoSizeMB )
|
|
166 |
{
|
|
167 |
dispSize = size + videoSizeHalfMB;
|
|
168 |
dispSize /= videoSizeMB;
|
|
169 |
sizeStr = QString(QObject::tr("%1 MB").arg(QString::number(dispSize)));
|
|
170 |
}
|
|
171 |
else if (size >= videoSizeKB)
|
|
172 |
{
|
|
173 |
dispSize = size + videoSizeHalfKB;
|
|
174 |
dispSize /= videoSizeKB;
|
|
175 |
sizeStr = QString(QObject::tr("%1 kB").arg(QString::number(dispSize)));
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
sizeStr = QString(QObject::tr("%1B").arg(QString::number(size)));
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
return sizeStr;
|
|
184 |
}
|
|
185 |
|
|
186 |
// End of file
|