1 /* |
|
2 * Copyright (c) 2005 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: Provides blid utils class methods. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <StringLoader.h> |
|
21 #include <e32math.h> |
|
22 #include <f32file.h> |
|
23 #include <eikenv.h> |
|
24 #include <aknViewAppUi.h> |
|
25 #include <apparc.h> |
|
26 #include <eikapp.h> |
|
27 #include "bliduiconsts.h" |
|
28 #include "Blidutils.h" |
|
29 |
|
30 //CONSTANTS |
|
31 _LIT( KTimeFormatString,":%02d%02d%02d." ); |
|
32 _LIT( KDistanceFormatTReal1, "%.1f" ); |
|
33 _LIT( KDistanceFormatInt, "%d" ); |
|
34 |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 // ---------------------------------------------------------------------------- |
|
38 // BlidUtils::TRealToTInt |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 TInt BlidUtils::TRealToTInt( const TReal aSrc, TInt& aResult ) |
|
42 { |
|
43 TReal resultTReal(0); |
|
44 TInt error(0); |
|
45 |
|
46 error = Math::Round( resultTReal, aSrc, 0 ); |
|
47 if ( error != KErrNone ) |
|
48 { |
|
49 aResult = 0; |
|
50 return error; |
|
51 } |
|
52 |
|
53 TInt32 resultTInt(0); |
|
54 error = Math::Int( resultTInt, resultTReal ); |
|
55 if ( error != KErrNone ) |
|
56 { |
|
57 aResult = 0; |
|
58 return error; |
|
59 } |
|
60 aResult = resultTInt; |
|
61 return error; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // BlidUtils::FormatStringToTime |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 TInt BlidUtils::FormatStringToTime( TDes& aTimeString, |
|
69 const TReal aSeconds ) |
|
70 { |
|
71 TInt tempInt(0); |
|
72 TReal tempTReal(0); |
|
73 TInt32 timeHours(0); |
|
74 TInt32 timeMinutes(0); |
|
75 TInt32 timeSeconds(0); |
|
76 TInt error(0); |
|
77 TInt seconds; |
|
78 |
|
79 error = TRealToTInt( aSeconds, seconds ); |
|
80 if ( error != KErrNone ) |
|
81 { |
|
82 aTimeString.Zero(); |
|
83 return error; |
|
84 } |
|
85 |
|
86 if ( (seconds < KDayToSeconds) && (seconds >= 0)) // less than day |
|
87 { |
|
88 // calculate hours |
|
89 error = Math::Int(timeHours,( seconds / KHourToSeconds )); |
|
90 if ( error != KErrNone ) |
|
91 { |
|
92 aTimeString.Zero(); |
|
93 return error; |
|
94 } |
|
95 |
|
96 // calculate minutes |
|
97 tempInt = seconds - (timeHours*KHourToSeconds); |
|
98 error = Math::Int(timeMinutes, ( tempInt / KMinuteToSeconds )); |
|
99 if ( error != KErrNone ) |
|
100 { |
|
101 aTimeString.Zero(); |
|
102 return error; |
|
103 } |
|
104 |
|
105 // calculate seconds |
|
106 error = Math::Mod( tempTReal, seconds, KMinuteToSeconds ); |
|
107 if ( error != KErrNone ) |
|
108 { |
|
109 aTimeString.Zero(); |
|
110 return error; |
|
111 } |
|
112 |
|
113 // convert TReal to TInt |
|
114 error = Math::Int( timeSeconds, tempTReal ); |
|
115 if ( error != KErrNone ) |
|
116 { |
|
117 aTimeString.Zero(); |
|
118 return error; |
|
119 } |
|
120 |
|
121 } |
|
122 |
|
123 aTimeString.Format( KTimeFormatString, |
|
124 timeHours, |
|
125 timeMinutes, |
|
126 timeSeconds ); |
|
127 return error; |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // BlidUtils::SecondsToDays |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 TInt BlidUtils::SecondsToDays( const TReal aSrc, TInt& aResult ) |
|
135 { |
|
136 TInt error(0); |
|
137 TInt seconds; |
|
138 |
|
139 error = TRealToTInt( aSrc, seconds ); |
|
140 if ( error != KErrNone ) |
|
141 { |
|
142 aResult = 0; |
|
143 return error; |
|
144 } |
|
145 |
|
146 TInt32 days(0); |
|
147 error = Math::Int( days, (seconds / KDayToSeconds) ); |
|
148 if ( error != KErrNone ) |
|
149 { |
|
150 aResult = 0; |
|
151 return error; |
|
152 } |
|
153 aResult = days; |
|
154 return error; |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // BlidUtils::DistanceFormat |
|
159 // ---------------------------------------------------------------------------- |
|
160 // |
|
161 void BlidUtils::DistanceFormat( TDes& aDistanceString, |
|
162 const TReal aDistance, |
|
163 TBool aIstobeDecimal ) |
|
164 { |
|
165 TReal distance( aDistance ); |
|
166 |
|
167 if( aIstobeDecimal ) |
|
168 { |
|
169 aDistanceString.Format( KDistanceFormatTReal1, distance ); |
|
170 } |
|
171 else |
|
172 { |
|
173 aDistanceString.Format( KDistanceFormatInt, ( TInt )distance ); |
|
174 } |
|
175 } |
|
176 |
|
177 // ---------------------------------------------------------------------------- |
|
178 // BlidUtils::GetBitmapFilenameL |
|
179 // ---------------------------------------------------------------------------- |
|
180 // |
|
181 HBufC* BlidUtils::GetBitmapFilenameLC() |
|
182 { |
|
183 // Path and file name: |
|
184 TFileName* file = new( ELeave ) TFileName; |
|
185 CleanupStack::PushL( file ); |
|
186 file->Append( KBlidSystemMbmPath ); // always safe |
|
187 file->Append( KBlidBitmapFileName ); // always safe |
|
188 |
|
189 // Drive: |
|
190 TBuf<10> aApp; |
|
191 CEikAppUi *appUi = (CEikAppUi *)(CEikonEnv::Static()->AppUi()); |
|
192 TFileName full = appUi->Application()->AppFullName(); |
|
193 |
|
194 TParsePtr ptr(full); |
|
195 aApp.Copy(ptr.Drive()); |
|
196 |
|
197 |
|
198 // Add drive to path & file name: |
|
199 TParse parse; |
|
200 User::LeaveIfError( parse.Set( *file, &aApp, NULL ) ); |
|
201 CleanupStack::PopAndDestroy(); // file |
|
202 |
|
203 return parse.FullName().AllocLC(); |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // BlidUtils::FormatTimeToString |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 TInt BlidUtils::FormatTimeToString( TDes& aTimeString, |
|
211 const TReal aSeconds ) |
|
212 { |
|
213 TInt tempInt(0); |
|
214 TReal tempTReal(0); |
|
215 TInt32 timeHours(0); |
|
216 TInt32 timeMinutes(0); |
|
217 TInt32 timeSeconds(0); |
|
218 TInt error(0); |
|
219 TInt seconds; |
|
220 |
|
221 error = TRealToTInt( aSeconds, seconds ); |
|
222 if ( error != KErrNone ) |
|
223 { |
|
224 aTimeString.Zero(); |
|
225 return error; |
|
226 } |
|
227 |
|
228 if (seconds >= 0) |
|
229 { |
|
230 // calculate hours |
|
231 error = Math::Int(timeHours,( seconds / KHourToSeconds )); |
|
232 if ( error != KErrNone ) |
|
233 { |
|
234 aTimeString.Zero(); |
|
235 return error; |
|
236 } |
|
237 |
|
238 // calculate minutes |
|
239 tempInt = seconds - (timeHours*KHourToSeconds); |
|
240 error = Math::Int(timeMinutes, ( tempInt / KMinuteToSeconds )); |
|
241 if ( error != KErrNone ) |
|
242 { |
|
243 aTimeString.Zero(); |
|
244 return error; |
|
245 } |
|
246 |
|
247 // calculate seconds |
|
248 error = Math::Mod( tempTReal, seconds, KMinuteToSeconds ); |
|
249 if ( error != KErrNone ) |
|
250 { |
|
251 aTimeString.Zero(); |
|
252 return error; |
|
253 } |
|
254 |
|
255 // convert TReal to TInt |
|
256 error = Math::Int( timeSeconds, tempTReal ); |
|
257 if ( error != KErrNone ) |
|
258 { |
|
259 aTimeString.Zero(); |
|
260 return error; |
|
261 } |
|
262 |
|
263 } |
|
264 |
|
265 aTimeString.Format( KTimeFormatString, |
|
266 timeHours, |
|
267 timeMinutes, |
|
268 timeSeconds ); |
|
269 return error; |
|
270 } |
|
271 |
|
272 |
|
273 // End of File |
|