|
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 boolean field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmrbooleanfield.h" |
|
20 |
|
21 #include <eiklabel.h> |
|
22 #include <StringLoader.h> |
|
23 #include <avkon.hrh> |
|
24 #include <esmrgui.rsg> |
|
25 #include <AknUtils.h> |
|
26 #include "mesmrcalentry.h" |
|
27 #include "mesmrlistobserver.h" |
|
28 #include "mesmrfieldvalidator.h" |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CESMRBooleanField::NewL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CESMRBooleanField* CESMRBooleanField::NewL( MESMRFieldValidator* aValidator ) |
|
37 { |
|
38 FUNC_LOG; |
|
39 CESMRBooleanField* self = new (ELeave) CESMRBooleanField( aValidator ); |
|
40 CleanupStack::PushL ( self ); |
|
41 self->ConstructL ( ); |
|
42 CleanupStack::Pop ( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CESMRBooleanField::~CESMRBooleanField |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CESMRBooleanField::~CESMRBooleanField( ) |
|
51 { |
|
52 FUNC_LOG; |
|
53 //do nothing |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CESMRBooleanField::InitializeL |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void CESMRBooleanField::InitializeL() |
|
61 { |
|
62 FUNC_LOG; |
|
63 iLabel->SetFont ( iLayout->Font (iCoeEnv, iFieldId ) ); |
|
64 iLabel->SetLabelAlignment (CESMRLayoutManager::IsMirrored ( ) ? ELayoutAlignRight |
|
65 : ELayoutAlignLeft ); |
|
66 AknLayoutUtils::OverrideControlColorL ( *iLabel, |
|
67 EColorLabelText, |
|
68 iLayout->GeneralListAreaTextColor() ); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CESMRBooleanField::InternalizeL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 void CESMRBooleanField::InternalizeL( MESMRCalEntry& aEntry ) |
|
76 { |
|
77 FUNC_LOG; |
|
78 if (aEntry.IsStoredL ( ) ) // entry is already stored in db |
|
79 { |
|
80 MESMRCalEntry::TESMRAlarmType alarmType; |
|
81 TTime alarmTime; |
|
82 aEntry.GetAlarmL (alarmType, alarmTime ); |
|
83 |
|
84 switch (alarmType ) |
|
85 { |
|
86 //flow through |
|
87 case MESMRCalEntry::EESMRAlarmAbsolute: |
|
88 case MESMRCalEntry::EESMRAlarmRelative: // Show alarm as - ON |
|
89 { |
|
90 iStatus = ETrue; |
|
91 } |
|
92 break; |
|
93 //flow through |
|
94 case MESMRCalEntry::EESMRAlarmNotFound: |
|
95 default: // Show alarm as - OFF |
|
96 { |
|
97 iStatus = EFalse; |
|
98 } |
|
99 break; |
|
100 } |
|
101 } |
|
102 else // This is a new entry and default implementation is required |
|
103 { |
|
104 switch (aEntry.Type ( ) ) |
|
105 { |
|
106 case MESMRCalEntry::EESMRCalEntryTodo: // To-do |
|
107 { |
|
108 TTime alarmTime; |
|
109 MESMRCalEntry::TESMRAlarmType alarmType; |
|
110 aEntry.GetAlarmL (alarmType, alarmTime ); |
|
111 |
|
112 // Change status to "ON" if alarm has been set by default |
|
113 iStatus = alarmType != MESMRCalEntry::EESMRAlarmNotFound; |
|
114 } |
|
115 break; |
|
116 // Flow through |
|
117 case MESMRCalEntry::EESMRCalEntryMeetingRequest: // Meeting request |
|
118 case MESMRCalEntry::EESMRCalEntryMeeting: // Meeting |
|
119 { |
|
120 iStatus = ETrue;// Change the status to "ON" for these dialog default |
|
121 } |
|
122 break; |
|
123 |
|
124 case MESMRCalEntry::EESMRCalEntryAnniversary: // Anniversary |
|
125 { |
|
126 iStatus = ETrue;// Change the status to "ON" for these dialog default |
|
127 } |
|
128 break; |
|
129 // Flow through |
|
130 case MESMRCalEntry::EESMRCalEntryMemo: // Memo |
|
131 case MESMRCalEntry::EESMRCalEntryReminder: // Reminder |
|
132 |
|
133 default: |
|
134 iStatus = EFalse; // Change the status to "OFF" for these dialog default |
|
135 break; |
|
136 } |
|
137 } |
|
138 ResetFieldL ( ); |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CESMRBooleanField::OfferKeyEventL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TKeyResponse CESMRBooleanField::OfferKeyEventL(const TKeyEvent& aEvent, |
|
146 TEventCode aType ) |
|
147 { |
|
148 FUNC_LOG; |
|
149 TKeyResponse response( EKeyWasNotConsumed); |
|
150 if ( aType == EEventKey ) |
|
151 { |
|
152 switch ( aEvent.iScanCode ) |
|
153 { |
|
154 // Flowthrough, doesn't matter which key was pressed since |
|
155 // the value is always changes from "off" to "on" or vice versus. |
|
156 case EStdKeyDevice3: // selection key |
|
157 case EStdKeyLeftArrow: |
|
158 case EStdKeyRightArrow: |
|
159 iStatus = !iStatus; // change status |
|
160 ResetFieldL ( ); |
|
161 response = EKeyWasConsumed; |
|
162 break; |
|
163 |
|
164 default: |
|
165 break; |
|
166 } |
|
167 } |
|
168 return response; |
|
169 } |
|
170 |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // CESMRBooleanField::SetOutlineFocusL |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CESMRBooleanField::SetOutlineFocusL( TBool aFocus ) |
|
177 { |
|
178 FUNC_LOG; |
|
179 CESMRField::SetOutlineFocusL( aFocus ); |
|
180 |
|
181 if (aFocus) //Focus is gained on the field |
|
182 { |
|
183 if (iStatus) |
|
184 { |
|
185 ChangeMiddleSoftKeyL(EESMRCmdAlarmOff,R_QTN_MEET_REQ_ALARM_OFF); //R_TEXT_SOFTKEY_OFF |
|
186 } |
|
187 else |
|
188 { |
|
189 ChangeMiddleSoftKeyL(EESMRCmdAlarmOn,R_QTN_MEET_REQ_ALARM_ON); //R_TEXT_SOFTKEY_ON |
|
190 } |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CESMRBooleanField::MakeVisible |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CESMRBooleanField::MakeVisible(TBool aVisible ) |
|
199 { |
|
200 FUNC_LOG; |
|
201 CCoeControl::MakeVisible (aVisible ); |
|
202 if ( iObserver ) |
|
203 { |
|
204 TRAP_IGNORE(ResetFieldL ( ) ); |
|
205 } |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // CESMRBooleanField::ExecuteGenericCommandL() |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void CESMRBooleanField::ExecuteGenericCommandL( TInt aCommand ) |
|
213 { |
|
214 FUNC_LOG; |
|
215 if( aCommand == EESMRCmdAlarmOn || aCommand == EESMRCmdAlarmOff ) |
|
216 { |
|
217 SwitchMiddleSoftKeyL(); |
|
218 } |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // CESMRBooleanField::SwitchMiddleSoftKeyL |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void CESMRBooleanField::SwitchMiddleSoftKeyL() |
|
226 { |
|
227 FUNC_LOG; |
|
228 iStatus = !iStatus; // change status |
|
229 ResetFieldL ( ); |
|
230 if (iStatus) |
|
231 { |
|
232 ChangeMiddleSoftKeyL(EESMRCmdAlarmOff,R_QTN_MEET_REQ_ALARM_OFF); |
|
233 } |
|
234 else |
|
235 { |
|
236 ChangeMiddleSoftKeyL(EESMRCmdAlarmOn,R_QTN_MEET_REQ_ALARM_ON); |
|
237 } |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CESMRBooleanField::CESMRBooleanField |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 CESMRBooleanField::CESMRBooleanField( MESMRFieldValidator* aValidator ) : |
|
245 iValidator( aValidator) |
|
246 { |
|
247 FUNC_LOG; |
|
248 iStatus = ETrue; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CESMRBooleanField::ConstructL |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CESMRBooleanField::ConstructL( ) |
|
256 { |
|
257 FUNC_LOG; |
|
258 _LIT(KEmptyText, "" ); |
|
259 SetFieldId ( EESMRFieldAlarmOnOff ); |
|
260 iLabel = new (ELeave) CEikLabel(); |
|
261 iLabel->SetTextL (KEmptyText ); |
|
262 |
|
263 CESMRIconField::ConstructL (KAknsIIDQgnMeetReqIndiAlarm, iLabel ); |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CESMRBooleanField::ResetFieldL |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CESMRBooleanField::ResetFieldL( ) |
|
271 { |
|
272 FUNC_LOG; |
|
273 iValidator->SetAlarmOnOffL( iStatus ); |
|
274 |
|
275 HBufC* buf = StringLoader::LoadLC ( iStatus ? |
|
276 R_QTN_MEET_REQ_ALARM_ON : |
|
277 R_QTN_MEET_REQ_ALARM_OFF ); |
|
278 |
|
279 iLabel->SetTextL ( *buf ); |
|
280 CleanupStack::PopAndDestroy ( buf ); |
|
281 |
|
282 // if status on 'on', add time and date fields for |
|
283 // all day event alert, otherwise remove them. |
|
284 // if this field is not visible -> alldayevent not set |
|
285 // let's not show the date and time fields either. |
|
286 if ( iStatus && IsVisible ( ) ) |
|
287 { |
|
288 iObserver->InsertControl ( EESMRFieldAlarmTime ); |
|
289 iObserver->InsertControl ( EESMRFieldAlarmDate ); |
|
290 } |
|
291 else |
|
292 { |
|
293 iObserver->RemoveControl ( EESMRFieldAlarmTime ); |
|
294 iObserver->RemoveControl ( EESMRFieldAlarmDate ); |
|
295 } |
|
296 |
|
297 iLabel->DrawDeferred ( ); |
|
298 } |
|
299 |
|
300 // EOF |
|
301 |