|
1 /* |
|
2 * Copyright (c) 2007-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: ESMR alarm field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmralarmfield.h" |
|
20 |
|
21 #include <eiklabel.h> |
|
22 #include <avkon.hrh> |
|
23 #include <e32keys.h> |
|
24 #include <barsc.h> |
|
25 #include <barsread.h> |
|
26 #include <calentry.h> |
|
27 #include <calalarm.h> |
|
28 #include <esmrgui.rsg> |
|
29 //<cmail> |
|
30 #include "esmrdef.h" |
|
31 //</cmail> |
|
32 #include <AknUtils.h> |
|
33 |
|
34 #include "cesmrborderlayer.h" |
|
35 #include "cesmralarm.h" |
|
36 #include "esmrcommands.h" |
|
37 #include "cesmrglobalnote.h" |
|
38 #include "mesmrfieldvalidator.h" |
|
39 #include "cesmrlistquery.h" |
|
40 |
|
41 // Unnamed namespace for local definitions |
|
42 namespace{ // codescanner::namespace |
|
43 |
|
44 _LIT( KNoText, "" ); |
|
45 const TInt KMinuteInMicroSeconds(60000000); |
|
46 |
|
47 }//namespace |
|
48 |
|
49 // ======== MEMBER FUNCTIONS ======== |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CESMRAlarmField::NewL |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CESMRAlarmField* CESMRAlarmField::NewL( MESMRFieldValidator* aValidator ) |
|
56 { |
|
57 FUNC_LOG; |
|
58 CESMRAlarmField* self = new (ELeave)CESMRAlarmField( aValidator ); |
|
59 CleanupStack::PushL ( self ); |
|
60 self->ConstructL ( ); |
|
61 CleanupStack::Pop ( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CESMRAlarmField::~CESMRAlarmField |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CESMRAlarmField::~CESMRAlarmField( ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 iArray.ResetAndDestroy ( ); |
|
73 iArray.Close ( ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CESMRAlarmField::InitializeL |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CESMRAlarmField::InitializeL() |
|
81 { |
|
82 FUNC_LOG; |
|
83 iAlarm->SetFont( iLayout->Font(iCoeEnv, iFieldId ) ); |
|
84 iAlarm->SetLabelAlignment( CESMRLayoutManager::IsMirrored() |
|
85 ? ELayoutAlignRight : ELayoutAlignLeft ); |
|
86 |
|
87 // Update text color |
|
88 AknLayoutUtils::OverrideControlColorL(*iAlarm, |
|
89 EColorLabelText, |
|
90 iLayout->GeneralListAreaTextColor() ); |
|
91 } |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CESMRAlarmField::InternalizeL |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CESMRAlarmField::InternalizeL( MESMRCalEntry& aEntry ) |
|
98 { |
|
99 FUNC_LOG; |
|
100 CCoeEnv* env = CCoeEnv::Static ( ); |
|
101 // esmrgui.rss |
|
102 TResourceReader reader; |
|
103 env->CreateResourceReaderLC ( reader, R_ESMREDITOR_ALARMS ); |
|
104 |
|
105 // Read alarm items to array |
|
106 iArray.ResetAndDestroy( ); |
|
107 TInt count = reader.ReadInt16 ( ); |
|
108 for (TInt i(0); i < count; i++ ) |
|
109 { |
|
110 CESMRAlarm* alarm = new (ELeave) CESMRAlarm; |
|
111 CleanupStack::PushL ( alarm ); |
|
112 alarm->ConstructFromResourceL ( reader ); |
|
113 alarm->LoadTextL ( env ); |
|
114 CleanupStack::Pop ( alarm ); |
|
115 iArray.Append ( alarm ); |
|
116 } |
|
117 |
|
118 // reader |
|
119 CleanupStack::PopAndDestroy(); // codescanner::cleanup |
|
120 |
|
121 // if alarm is relative then set the text on right index. |
|
122 MESMRCalEntry::TESMRAlarmType alarmType; |
|
123 TTime alarmTime; |
|
124 aEntry.GetAlarmL (alarmType, alarmTime ); |
|
125 |
|
126 switch (alarmType ) |
|
127 { |
|
128 case MESMRCalEntry::EESMRAlarmRelative: |
|
129 {// Show relative alarm field and set its time. |
|
130 // time units can be minutes, hours or days |
|
131 TInt timeInMins = 0; |
|
132 CCalEntry& entry = aEntry.Entry ( ); |
|
133 TTime entryTime= entry.StartTimeL().TimeLocalL ( ); |
|
134 timeInMins = (entryTime.Int64() - alarmTime.Int64())/ KMinuteInMicroSeconds; |
|
135 // Loop through iArray and get the relevent item |
|
136 for (TInt i(0); i < iArray.Count ( ); i++ ) |
|
137 { |
|
138 if ( iArray[i]->Relative ( )== timeInMins ) |
|
139 { |
|
140 iAlarm->SetTextL ( *(iArray[i]->Text()) ); |
|
141 iOptIndex = i; // update current alarm index. |
|
142 |
|
143 // Let's also update the current alarm offset to iValidator |
|
144 TBool handleAlarmChange( EFalse ); |
|
145 iValidator->RelativeAlarmChangedL( |
|
146 iArray[ iOptIndex ]->RelativeTimeInMinutes(), |
|
147 handleAlarmChange, |
|
148 iRelativeAlarmValid ); |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 break; |
|
154 //flow through |
|
155 case MESMRCalEntry::EESMRAlarmAbsolute: |
|
156 case MESMRCalEntry::EESMRAlarmNotFound: |
|
157 default: |
|
158 { // Search the default value (EAlarmFifteenMinutes) and set it |
|
159 for (TInt i(0); i < iArray.Count ( ); i++ ) |
|
160 { |
|
161 if ( iArray[i]->Id ( )== EAlarmOff ) |
|
162 { |
|
163 iAlarm->SetTextL ( *(iArray[i]->Text()) ); |
|
164 iOptIndex = i; // update current alarm index. |
|
165 |
|
166 // Let's also update the current alarm offset to iValidator |
|
167 TBool handleAlarmChange( EFalse ); |
|
168 iValidator->RelativeAlarmChangedL( |
|
169 iArray[ iOptIndex ]->RelativeTimeInMinutes(), |
|
170 handleAlarmChange, |
|
171 iRelativeAlarmValid ); |
|
172 break; |
|
173 } |
|
174 }// End For loop |
|
175 } |
|
176 break; |
|
177 } |
|
178 |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CESMRAlarmField::ExternalizeL |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 void CESMRAlarmField::ExternalizeL( MESMRCalEntry& aEntry ) |
|
186 { |
|
187 FUNC_LOG; |
|
188 if ( iRelativeAlarmValid ) |
|
189 { |
|
190 CESMRAlarm* alarm = iArray[ iOptIndex ]; |
|
191 // if alarm is set |
|
192 if ( alarm->Id()!= EAlarmOff ) |
|
193 {// All Day event has absolute alarm handled in validator class |
|
194 // if not visible, this entry has absolute alarm. |
|
195 if ( IsVisible() ) |
|
196 { |
|
197 CCalAlarm* calAlarm = CCalAlarm::NewL(); |
|
198 CleanupStack::PushL( calAlarm ); |
|
199 calAlarm->SetTimeOffset( alarm->RelativeTimeInMinutes() ); |
|
200 |
|
201 CCalEntry& entry = aEntry.Entry(); |
|
202 entry.SetAlarmL( calAlarm ); |
|
203 CleanupStack::PopAndDestroy( calAlarm ); |
|
204 } |
|
205 } |
|
206 else |
|
207 { |
|
208 CCalEntry& entry = aEntry.Entry( ); |
|
209 entry.SetAlarmL( NULL ); |
|
210 } |
|
211 } |
|
212 else |
|
213 { |
|
214 CCalEntry& entry = aEntry.Entry(); |
|
215 entry.SetAlarmL( NULL ); |
|
216 } |
|
217 |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CESMRAlarmField::OkToLoseFocusL |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 TBool CESMRAlarmField::OkToLoseFocusL( |
|
225 TESMREntryFieldId /*aNextItem*/ ) |
|
226 { |
|
227 FUNC_LOG; |
|
228 return TriggerValidatorL(); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CESMRAlarmField::OfferKeyEventL |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 TKeyResponse CESMRAlarmField::OfferKeyEventL(const TKeyEvent& aEvent, |
|
236 TEventCode aType ) |
|
237 { |
|
238 FUNC_LOG; |
|
239 TKeyResponse response( EKeyWasNotConsumed); |
|
240 |
|
241 if ( aType == EEventKey ) |
|
242 { |
|
243 switch ( aEvent.iScanCode ) |
|
244 { |
|
245 case EStdKeyLeftArrow: |
|
246 { |
|
247 // next alert item |
|
248 if ( iOptIndex > 0 ) |
|
249 { |
|
250 UpdateAlarmLabelL ( --iOptIndex ); |
|
251 response = EKeyWasConsumed; |
|
252 } |
|
253 } |
|
254 break; |
|
255 |
|
256 case EStdKeyRightArrow: |
|
257 { |
|
258 // next alert item |
|
259 if ( iOptIndex < (iArray.Count() - 1) ) |
|
260 { |
|
261 UpdateAlarmLabelL ( ++iOptIndex ); |
|
262 response = EKeyWasConsumed; |
|
263 } |
|
264 } |
|
265 break; |
|
266 |
|
267 default: |
|
268 break; |
|
269 } |
|
270 } |
|
271 return response; |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CESMRAlarmField::CESMRAlarmField |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 CESMRAlarmField::CESMRAlarmField( MESMRFieldValidator* aValidator ) |
|
279 : iOptIndex(0), |
|
280 iValidator( aValidator ), |
|
281 iRelativeAlarmValid( ETrue ) |
|
282 { |
|
283 FUNC_LOG; |
|
284 //do nothing |
|
285 } |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // CESMRAlarmField::ConstructL |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 void CESMRAlarmField::ConstructL( ) |
|
292 { |
|
293 FUNC_LOG; |
|
294 SetFieldId ( EESMRFieldAlarm ); |
|
295 iAlarm = new (ELeave) CEikLabel; // base class takes ownership |
|
296 iAlarm->SetTextL ( KNoText ); |
|
297 CESMRIconField::ConstructL (KAknsIIDQgnMeetReqIndiAlarm, iAlarm ); |
|
298 } |
|
299 |
|
300 // --------------------------------------------------------------------------- |
|
301 // CESMRAlarmField::UpdateAlarmLabelL |
|
302 // --------------------------------------------------------------------------- |
|
303 // |
|
304 void CESMRAlarmField::UpdateAlarmLabelL( TInt aIndex ) |
|
305 { |
|
306 FUNC_LOG; |
|
307 if (aIndex < iArray.Count() ) |
|
308 { |
|
309 HBufC* txt = iArray[ aIndex ]->Text ( ); |
|
310 iAlarm->SetTextL ( *txt ); |
|
311 |
|
312 // Let's only update the current alarm offset to iValidator |
|
313 TBool handleAlarmChange( EFalse ); |
|
314 if (iValidator) |
|
315 { |
|
316 iValidator->RelativeAlarmChangedL( |
|
317 iArray[ aIndex ]->RelativeTimeInMinutes(), |
|
318 handleAlarmChange, |
|
319 iRelativeAlarmValid ); |
|
320 } |
|
321 } |
|
322 iBorder->DrawDeferred ( ); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CESMRAlarmField::UpdateAlarmToFirstValidValueL |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 void CESMRAlarmField::UpdateAlarmToFirstValidValueL() |
|
330 { |
|
331 FUNC_LOG; |
|
332 // Changing the alarm to first valid value |
|
333 for (TInt i(0); i <= iOptIndex; i++ ) |
|
334 { |
|
335 TTimeIntervalMinutes alarmOffset = |
|
336 iArray[ iOptIndex - i ]->RelativeTimeInMinutes(); //codescanner::accessArrayElementWithoutCheck2 |
|
337 |
|
338 if ( iValidator->IsRelativeAlarmValid( alarmOffset ) ) |
|
339 { |
|
340 iOptIndex = iOptIndex - i; |
|
341 break; |
|
342 } |
|
343 } |
|
344 |
|
345 UpdateAlarmLabelL( iOptIndex ); |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // CESMRAlarmField::SetOutlineFocusL |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 void CESMRAlarmField::SetOutlineFocusL( TBool aFocus ) |
|
353 { |
|
354 FUNC_LOG; |
|
355 CESMRField::SetOutlineFocusL ( aFocus ); |
|
356 |
|
357 //Focus is gained on the field |
|
358 if (aFocus) |
|
359 { |
|
360 ChangeMiddleSoftKeyL(EESMRCmdOpenAlarmQuery,R_QTN_MSK_OPEN); |
|
361 } |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // CESMRAlarmField::ExecuteGenericCommandL |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void CESMRAlarmField::ExecuteGenericCommandL( TInt aCommand ) |
|
369 { |
|
370 FUNC_LOG; |
|
371 if(aCommand == EESMRCmdOpenAlarmQuery || |
|
372 aCommand == EAknCmdOpen ) |
|
373 { |
|
374 ExecuteMSKCommandL(); |
|
375 } |
|
376 } |
|
377 |
|
378 // --------------------------------------------------------------------------- |
|
379 // CESMRAlarmField::ExecuteMskCommandL |
|
380 // --------------------------------------------------------------------------- |
|
381 // |
|
382 void CESMRAlarmField::ExecuteMSKCommandL() |
|
383 { |
|
384 FUNC_LOG; |
|
385 DoAlarmTimeQueryL(); |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 // CESMRAlarmField::DoAlarmTimeQueryL |
|
390 // --------------------------------------------------------------------------- |
|
391 // |
|
392 void CESMRAlarmField::DoAlarmTimeQueryL() |
|
393 { |
|
394 FUNC_LOG; |
|
395 TInt ret( CESMRListQuery::ExecuteL( |
|
396 CESMRListQuery::EESMRRelativeAlarmTimeQuery ) ); |
|
397 if ( ret != KErrCancel ) |
|
398 { |
|
399 iOptIndex = ret; |
|
400 UpdateAlarmLabelL( iOptIndex ); |
|
401 } |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // CESMRAlarmField::TriggerValidatorL |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 TBool CESMRAlarmField::TriggerValidatorL() |
|
409 { |
|
410 FUNC_LOG; |
|
411 TBool entryOk( ETrue ); |
|
412 |
|
413 // Let's handle the relative alarm change in iValidator |
|
414 TRAPD(err, iValidator->RelativeAlarmChangedL( |
|
415 iArray[ iOptIndex ]->RelativeTimeInMinutes(), //codescanner::accessArrayElementWithoutCheck2 |
|
416 ETrue, // handleAlarmChange |
|
417 iRelativeAlarmValid ) ); |
|
418 |
|
419 if ( err != KErrNone ) |
|
420 { |
|
421 entryOk = EFalse; |
|
422 CESMRGlobalNote::ExecuteL ( CESMRGlobalNote::EESMRAlarmAlreadyPassed ); |
|
423 UpdateAlarmToFirstValidValueL(); |
|
424 } |
|
425 |
|
426 return entryOk; |
|
427 } |
|
428 |
|
429 // EOF |
|
430 |