|
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: SmilPlayerTimeIndicatorTimer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <AknUtils.h> // AknTextUtils |
|
22 #include <StringLoader.h> // StringLoader |
|
23 #include <avkon.rsg> // R_QTN_TIME_DURAT_MIN_SEC |
|
24 #include <SmilPlayer.rsg> // R_SMILPLAYER_PRESENTATION_DURATION |
|
25 |
|
26 #include "SmilPlayerTimeIndicatorTimer.h" |
|
27 #include "SmilPlayerTimeObserver.h" |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KTimeControlIntToMicroSec = 1000000; |
|
31 const TInt KMaxTimeInSeconds = 3599; |
|
32 const TInt KTimeControlStartDelay = 500000; //0.5 sec |
|
33 const TInt KTimeControlProceedingTime = 200000; //0.2 sec |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CSmilPlayerTimeIndicatorTimer::CSmilPlayerTimeIndicatorTimer |
|
40 // C++ constructor. |
|
41 // ---------------------------------------------------------------------------- |
|
42 // |
|
43 CSmilPlayerTimeIndicatorTimer::CSmilPlayerTimeIndicatorTimer( MSmilPlayerTimeObserver* aObserver, |
|
44 CCoeEnv* aCoeEnv ) : |
|
45 CTimer( EPriorityStandard ), |
|
46 iTimeObserver( aObserver ), |
|
47 iCurrentValue( 0 ), |
|
48 iState( EReadyForAction ), |
|
49 iCoeEnv( aCoeEnv ) |
|
50 { |
|
51 CActiveScheduler::Add( this ); |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CSmilPlayerTimeIndicatorTimer::ConstructL |
|
56 // Symbian 2nd phase constructor. Initializes timer and loads corret resource string |
|
57 // for localizable time string. |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 void CSmilPlayerTimeIndicatorTimer::ConstructL() |
|
61 { |
|
62 CTimer::ConstructL(); |
|
63 |
|
64 StringLoader::Load( iTimeDuratMinSecWithZero, R_QTN_TIME_DURAT_MIN_SEC, iCoeEnv ); |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CSmilPlayerTimeIndicatorTimer::NewL |
|
69 // Symbian two phased constructor |
|
70 // ---------------------------------------------------------------------------- |
|
71 // |
|
72 CSmilPlayerTimeIndicatorTimer* CSmilPlayerTimeIndicatorTimer::NewL( MSmilPlayerTimeObserver* aObserver, |
|
73 CCoeEnv* aCoeEnv ) |
|
74 { |
|
75 CSmilPlayerTimeIndicatorTimer* self = new(ELeave) CSmilPlayerTimeIndicatorTimer( aObserver, |
|
76 aCoeEnv ); |
|
77 |
|
78 CleanupStack::PushL( self ); |
|
79 self->ConstructL(); |
|
80 CleanupStack::Pop( self ); |
|
81 |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CSmilPlayerTimeIndicatorTimer::~CSmilPlayerTimeIndicatorTimer |
|
87 // Destructor |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 CSmilPlayerTimeIndicatorTimer::~CSmilPlayerTimeIndicatorTimer() |
|
91 { |
|
92 iTimeObserver = NULL; //For LINT |
|
93 iCoeEnv = NULL; // For LINT |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // CSmilPlayerTimeIndicatorTimer::RunL |
|
98 // Called when timer triggers to update time indicator string if approriate. |
|
99 // Also resets inactivity timer so that sceensaver is not triggered during |
|
100 // playback. |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 void CSmilPlayerTimeIndicatorTimer::RunL() |
|
104 { |
|
105 TInt previousTotalDuration( iDurationValue ); |
|
106 TInt previousTime( iCurrentValue ); |
|
107 |
|
108 // Updating current time |
|
109 TInt newTime( iTimeObserver->CurrentTime() ); |
|
110 |
|
111 // Check to see if we are preparing to end even |
|
112 // if state is not updated correctly. |
|
113 if ( iState == ERunning && |
|
114 iCurrentValue == (iDurationValue - 1) && |
|
115 iCurrentValue != newTime ) |
|
116 { |
|
117 iState = EPreparingForEnd; |
|
118 } |
|
119 |
|
120 if ( iState == EPreparingForEnd ) |
|
121 { |
|
122 newTime = iDurationValue; |
|
123 previousTime = 0; // Force update |
|
124 } |
|
125 |
|
126 // Updating duration |
|
127 if ( !iTimeObserver->IsDurationFinite() ) |
|
128 { |
|
129 iCurrentValue = newTime; |
|
130 iDurationValue = 0; |
|
131 } |
|
132 else |
|
133 { |
|
134 //store current time to the member |
|
135 iCurrentValue = newTime; |
|
136 |
|
137 //store current duration to the member |
|
138 iDurationValue = iTimeObserver->PresentationDuration(); |
|
139 } |
|
140 |
|
141 //check here is the current time or duration has changed |
|
142 if ( previousTime != iCurrentValue || |
|
143 previousTotalDuration != iDurationValue ) |
|
144 { |
|
145 // Reset inactivity timer. |
|
146 User::ResetInactivityTime(); |
|
147 |
|
148 CreateNewTimeStringL(); |
|
149 } |
|
150 |
|
151 // start the timer again |
|
152 After( KTimeControlProceedingTime );//0.2sec |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CSmilPlayerTimeIndicatorTimer::Start |
|
157 // Cancels the old time indicator refreshing is ongoing. |
|
158 // Sets current time to zero and tries to create new time string so that new time value is |
|
159 // refreshed immediatelly to indicator. Error on creating time string are ignored |
|
160 // since time string update is not critical task and allowing leaves from function |
|
161 // would create multiple TRAPs to other places. |
|
162 // After this timer is started to update the time indicator and state is set to running. |
|
163 // ---------------------------------------------------------------------------- |
|
164 // |
|
165 void CSmilPlayerTimeIndicatorTimer::Start() |
|
166 { |
|
167 Cancel(); |
|
168 |
|
169 iCurrentValue = 0; |
|
170 TRAP_IGNORE( CreateNewTimeStringL() ); |
|
171 |
|
172 After( KTimeControlStartDelay ); |
|
173 iState = ERunning; |
|
174 } |
|
175 |
|
176 // ---------------------------------------------------------------------------- |
|
177 // CSmilPlayerTimeIndicatorTimer::Pause |
|
178 // Pauses time string update. |
|
179 // ---------------------------------------------------------------------------- |
|
180 // |
|
181 void CSmilPlayerTimeIndicatorTimer::Pause() |
|
182 { |
|
183 iState = EPaused; |
|
184 Cancel(); |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CSmilPlayerTimeIndicatorTimer::Resume |
|
189 // Continues time string update. |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 void CSmilPlayerTimeIndicatorTimer::Resume() |
|
193 { |
|
194 iState = ERunning; |
|
195 After( KTimeControlProceedingTime ); |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CSmilPlayerTimeIndicatorTimer::Stop |
|
200 // Stops time string update. Tries to update current value if possible. |
|
201 // ---------------------------------------------------------------------------- |
|
202 // |
|
203 void CSmilPlayerTimeIndicatorTimer::Stop() |
|
204 { |
|
205 // Updating current time |
|
206 iCurrentValue = iTimeObserver->CurrentTime(); |
|
207 |
|
208 TRAP_IGNORE( CreateNewTimeStringL() ); |
|
209 iState = EReadyForAction; |
|
210 Cancel(); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CSmilPlayerTimeIndicatorTimer::EndReached |
|
215 // Indicates that presentation end has been reached. Sets timer state to preparing |
|
216 // for end. |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void CSmilPlayerTimeIndicatorTimer::EndReached() |
|
220 { |
|
221 iState = EPreparingForEnd; |
|
222 iCurrentValue = iDurationValue; |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CSmilPlayerTimeIndicatorTimer::CreateNewTimeStringL |
|
227 // Constructs new time string and updates it to observer. |
|
228 // ---------------------------------------------------------------------------- |
|
229 // |
|
230 void CSmilPlayerTimeIndicatorTimer::CreateNewTimeStringL() |
|
231 { |
|
232 // do not draw any time ( for example interactive presentation ) |
|
233 if ( iCurrentValue != 0 || iDurationValue != 0 ) |
|
234 { |
|
235 HBufC* timeBuffer = NULL; |
|
236 |
|
237 TBuf<KTimeControlMaxLength> timeString; |
|
238 |
|
239 TInt64 timeValue = MAKE_TINT64( 0, Min( KMaxTimeInSeconds, iCurrentValue ) ); |
|
240 timeValue *= KTimeControlIntToMicroSec; |
|
241 |
|
242 TTime time( timeValue ); |
|
243 time.FormatL( timeString, iTimeDuratMinSecWithZero ); |
|
244 |
|
245 // checks if needed to draw total duration |
|
246 // and load localised string from resources |
|
247 if( iDurationValue != 0 ) |
|
248 { |
|
249 TBuf<KTimeControlMaxLength> durationString; |
|
250 TInt64 durationValue = MAKE_TINT64( 0, Min( KMaxTimeInSeconds, iDurationValue ) ); |
|
251 durationValue *= KTimeControlIntToMicroSec; |
|
252 TTime duration( durationValue ); |
|
253 duration.FormatL( durationString, |
|
254 iTimeDuratMinSecWithZero ); |
|
255 |
|
256 //load localised string for presentation duration |
|
257 CDesCArrayFlat* array = new(ELeave) CDesCArrayFlat( 2 ); |
|
258 CleanupStack::PushL( array ); |
|
259 |
|
260 AknTextUtils::LanguageSpecificNumberConversion( timeString ); |
|
261 array->AppendL( timeString ); |
|
262 |
|
263 AknTextUtils::LanguageSpecificNumberConversion( durationString ); |
|
264 array->AppendL( durationString ); |
|
265 |
|
266 timeBuffer = StringLoader::LoadL( R_SMILPLAYER_PRESENTATION_DURATION, |
|
267 *array, |
|
268 iCoeEnv ); |
|
269 |
|
270 CleanupStack::PopAndDestroy( array ); |
|
271 } |
|
272 else |
|
273 { |
|
274 //only current time is drawn (no duration) |
|
275 //and localisation string is not needed to be used |
|
276 AknTextUtils::LanguageSpecificNumberConversion( timeString ); |
|
277 timeBuffer = timeString.AllocL(); |
|
278 } |
|
279 |
|
280 CleanupStack::PushL( timeBuffer ); |
|
281 iTimeObserver->TimeChangedL( *timeBuffer ); |
|
282 CleanupStack::PopAndDestroy( timeBuffer ); |
|
283 } |
|
284 } |
|
285 |
|
286 // End of file |