|
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 Recurrence field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "emailtrace.h" |
|
19 #include "cesmrrecurencefield.h" |
|
20 |
|
21 #include <eiklabel.h> |
|
22 #include <barsread.h> |
|
23 #include <esmrgui.rsg> |
|
24 #include <avkon.hrh> |
|
25 //<cmail> |
|
26 #include "esmrdef.h" |
|
27 //</cmail> |
|
28 #include <AknUtils.h> |
|
29 |
|
30 #include "cesmrrecurrence.h" |
|
31 #include "cesmrborderlayer.h" |
|
32 #include "mesmrlistobserver.h" |
|
33 #include "cesmrlistquery.h" |
|
34 #include "mesmrmeetingrequestentry.h" |
|
35 #include "mesmrfieldvalidator.h" |
|
36 #include "cesmrglobalnote.h" |
|
37 |
|
38 // Unnamed namespace for local definitions |
|
39 namespace { // codescanner::namespace |
|
40 |
|
41 #ifdef _DEBUG |
|
42 |
|
43 /** Panic code literal */ |
|
44 _LIT( KESMRRecurenceFieldPanicTxt, "ESMRRecurenceField" ); |
|
45 |
|
46 /** Panic code enumeration */ |
|
47 enum TESMRRecurenceFieldPanic |
|
48 { |
|
49 /** Observer is not set */ |
|
50 EESMRRecurenceFieldNoObserver = 0 |
|
51 }; |
|
52 |
|
53 /** |
|
54 * Raises system panic. |
|
55 * @param aPanic CESMRRecurenceField panic code. |
|
56 */ |
|
57 void Panic( TESMRRecurenceFieldPanic aPanic ) |
|
58 { |
|
59 User::Panic( KESMRRecurenceFieldPanicTxt, aPanic ); |
|
60 } |
|
61 |
|
62 #endif // DEBUG |
|
63 |
|
64 } |
|
65 |
|
66 // ======== MEMBER FUNCTIONS ======== |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CESMRRecurrenceField::CESMRRecurrenceField |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 CESMRRecurenceField::CESMRRecurenceField( |
|
73 MESMRFieldValidator* aValidator ) |
|
74 : iValidator( aValidator), |
|
75 iIndex( 0 ) |
|
76 { |
|
77 FUNC_LOG; |
|
78 //do nothing |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CESMRRecurrenceField::~CESMRRecurrenceField |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CESMRRecurenceField::~CESMRRecurenceField( ) |
|
86 { |
|
87 FUNC_LOG; |
|
88 iArray.ResetAndDestroy(); |
|
89 iArray.Close(); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CESMRRecurrenceField::NewL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CESMRRecurenceField* CESMRRecurenceField::NewL( |
|
97 MESMRFieldValidator* aValidator ) |
|
98 { |
|
99 FUNC_LOG; |
|
100 CESMRRecurenceField* self = |
|
101 new (ELeave) CESMRRecurenceField( aValidator ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CESMRRecurrenceField::ConstructL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CESMRRecurenceField::ConstructL( ) |
|
113 { |
|
114 FUNC_LOG; |
|
115 _LIT(KEmptyText, "" ); |
|
116 SetFieldId ( EESMRFieldRecurrence ); |
|
117 iRecurence = new (ELeave) CEikLabel(); |
|
118 iRecurence->SetTextL( KEmptyText ); |
|
119 CESMRIconField::ConstructL ( |
|
120 KAknsIIDQgnFscalIndiRecurrence, |
|
121 iRecurence ); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // CESMRRecurrenceField::InitializeL |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CESMRRecurenceField::InitializeL() |
|
129 { |
|
130 FUNC_LOG; |
|
131 iRecurence->SetFont ( iLayout->Font( iCoeEnv, iFieldId ) ); |
|
132 |
|
133 iRecurence->SetLabelAlignment( |
|
134 CESMRLayoutManager::IsMirrored() ? |
|
135 ELayoutAlignRight : ELayoutAlignLeft ); |
|
136 |
|
137 AknLayoutUtils::OverrideControlColorL( |
|
138 *iRecurence, |
|
139 EColorLabelText, |
|
140 iLayout->GeneralListAreaTextColor() ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CESMRRecurrenceField::InternalizeL |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CESMRRecurenceField::InternalizeL( |
|
148 MESMRCalEntry& aEntry ) |
|
149 { |
|
150 FUNC_LOG; |
|
151 if ( aEntry.CanSetRecurrenceL() ) |
|
152 { |
|
153 CCoeEnv* env = CCoeEnv::Static ( ); |
|
154 TResourceReader reader; |
|
155 env->CreateResourceReaderLC( reader, R_ESMREDITOR_RECURRENCE ); |
|
156 |
|
157 TESMRRecurrenceValue recurrenceVal; |
|
158 TTime until; |
|
159 aEntry.GetRecurrenceL(recurrenceVal, until ); |
|
160 |
|
161 iArray.ResetAndDestroy( ); |
|
162 TInt count = reader.ReadInt16 ( ); |
|
163 for (TInt i(0); i < count; ++i ) |
|
164 { |
|
165 CESMRRecurrence* recurrence = new (ELeave) CESMRRecurrence; |
|
166 CleanupStack::PushL( recurrence ); |
|
167 recurrence->ConstructFromResourceL( env, reader ); |
|
168 iArray.AppendL( recurrence ); |
|
169 CleanupStack::Pop( recurrence ); |
|
170 // set default recurrence |
|
171 if ( recurrence->RecurrenceValue() == recurrenceVal ) |
|
172 { |
|
173 iIndex = i; |
|
174 SetRecurrenceL ( iIndex ); |
|
175 } |
|
176 } |
|
177 // resource reader |
|
178 CleanupStack::PopAndDestroy(); // codescanner::cleanup |
|
179 } |
|
180 else |
|
181 { |
|
182 __ASSERT_DEBUG( iObserver, Panic( EESMRRecurenceFieldNoObserver ) ); |
|
183 iObserver->RemoveControl ( iFieldId ); |
|
184 } |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CESMRRecurenceField::SetOutlineFocusL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CESMRRecurenceField::SetOutlineFocusL( TBool aFocus ) |
|
192 { |
|
193 FUNC_LOG; |
|
194 CESMRField::SetOutlineFocusL ( aFocus ); |
|
195 |
|
196 //Focus gained |
|
197 if ( aFocus ) |
|
198 { |
|
199 ChangeMiddleSoftKeyL(EESMRCmdOpenRecurrenceQuery, R_QTN_MSK_OPEN); |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CESMRRecurenceField::ExecuteGenericCommandL |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 void CESMRRecurenceField::ExecuteGenericCommandL( TInt aCommand ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 if (aCommand == EESMRCmdOpenRecurrenceQuery || |
|
211 aCommand == EAknCmdOpen ) |
|
212 { |
|
213 ExecuteRecurrenceQueryL(); |
|
214 } |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CESMRRecurenceField::ExecuteRecurrenceQueryL |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CESMRRecurenceField::ExecuteRecurrenceQueryL() |
|
222 { |
|
223 FUNC_LOG; |
|
224 TInt ret = CESMRListQuery::ExecuteL(CESMRListQuery::EESMRRecurrenceQuery ); |
|
225 |
|
226 if ( ret != KErrCancel ) |
|
227 { |
|
228 SetRecurrenceL( ret ); |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CESMRRecurrenceField::OfferKeyEventL |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 TKeyResponse CESMRRecurenceField::OfferKeyEventL( |
|
238 const TKeyEvent& aEvent, |
|
239 TEventCode aType ) |
|
240 { |
|
241 FUNC_LOG; |
|
242 TKeyResponse response( EKeyWasNotConsumed); |
|
243 if ( EEventKey == aType ) |
|
244 { |
|
245 switch ( aEvent.iScanCode ) |
|
246 { |
|
247 case EStdKeyLeftArrow: |
|
248 { |
|
249 if ( iIndex > 0 ) |
|
250 { |
|
251 SetRecurrenceL ( iIndex - 1 ); |
|
252 response = EKeyWasConsumed; |
|
253 } |
|
254 } |
|
255 break; |
|
256 |
|
257 case EStdKeyRightArrow: |
|
258 { |
|
259 if ( iIndex < (iArray.Count() - 1) ) |
|
260 { |
|
261 SetRecurrenceL ( iIndex + 1 ); |
|
262 response = EKeyWasConsumed; |
|
263 } |
|
264 } |
|
265 break; |
|
266 |
|
267 default: |
|
268 break; |
|
269 } |
|
270 } |
|
271 return response; |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CESMRRecurrenceField::SetRecurrence |
|
276 // --------------------------------------------------------------------------- |
|
277 // |
|
278 void CESMRRecurenceField::SetRecurrenceL( |
|
279 TInt aIndex ) |
|
280 { |
|
281 FUNC_LOG; |
|
282 if ( aIndex < 0 || aIndex >= iArray.Count() ) |
|
283 { |
|
284 User::Leave( KErrArgument ); |
|
285 } |
|
286 |
|
287 CESMRRecurrence* rec = iArray[ aIndex ]; |
|
288 TRAPD( err, iValidator->RecurrenceChangedL( rec->RecurrenceValue() ) ); |
|
289 if ( err == KErrNone ) |
|
290 { |
|
291 iRecurence->SetTextL ( rec->RecurrenceText() ); |
|
292 iBorder->DrawDeferred ( ); |
|
293 |
|
294 iIndex = aIndex; |
|
295 |
|
296 if ( rec->RecurrenceValue() != ERecurrenceNot ) |
|
297 { |
|
298 // if recurrence is switched "on", the end date should be removed |
|
299 iObserver->RemoveControl ( EESMRFieldStopDate ); |
|
300 iObserver->InsertControl ( EESMRFieldRecurrenceDate ); |
|
301 } |
|
302 else |
|
303 { |
|
304 // if recurrence is switched off, end date should be visible |
|
305 iObserver->InsertControl ( EESMRFieldStopDate ); |
|
306 iObserver->RemoveControl ( EESMRFieldRecurrenceDate ); |
|
307 } |
|
308 } |
|
309 else |
|
310 { |
|
311 // Error occured |
|
312 CESMRGlobalNote::ExecuteL( |
|
313 CESMRGlobalNote::EESMRRepeatDifferentStartAndEndDate ); |
|
314 } |
|
315 } |
|
316 |
|
317 // EOF |
|
318 |