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