|
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 Unified editor field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cmrunifiededitorfield.h" |
|
19 #include "cmrimage.h" |
|
20 #include "cmrlabel.h" |
|
21 #include "cesmrtextitem.h" |
|
22 #include "cesmrlistquery.h" |
|
23 #include "nmrlayoutmanager.h" |
|
24 #include "mesmrlistobserver.h" |
|
25 #include "cesmrglobalnote.h" |
|
26 |
|
27 #include <esmrgui.rsg> |
|
28 #include <stringloader.h> |
|
29 #include <barsread.h> |
|
30 #include <avkon.hrh> |
|
31 #include <aknutils.h> |
|
32 #include <calentry.h> |
|
33 #include <caleninterimutils2.h> |
|
34 // DEBUG |
|
35 #include "emailtrace.h" |
|
36 |
|
37 namespace |
|
38 { |
|
39 /** |
|
40 * Maps listbox selection index to correct command id |
|
41 */ |
|
42 TInt MapIndexToCommandId( TInt aIndex ) |
|
43 { |
|
44 TInt command = KErrNotFound; |
|
45 |
|
46 switch ( aIndex ) |
|
47 { |
|
48 case EMRTypeMeetingRequest: |
|
49 { |
|
50 command = EMRCommandSwitchToMR; |
|
51 break; |
|
52 } |
|
53 |
|
54 case EMRTypeMeeting: |
|
55 { |
|
56 command = EMRCommandSwitchToMeeting; |
|
57 break; |
|
58 } |
|
59 |
|
60 case EMRTypeMemo: |
|
61 { |
|
62 command = EMRCommandSwitchToMemo; |
|
63 break; |
|
64 } |
|
65 |
|
66 case EMRTypeAnniversary: |
|
67 { |
|
68 command = EMRCommandSwitchToAnniversary; |
|
69 break; |
|
70 } |
|
71 |
|
72 case EMRTypeToDo: |
|
73 { |
|
74 command = EMRCommandSwitchToTodo; |
|
75 break; |
|
76 } |
|
77 |
|
78 default: |
|
79 { |
|
80 ASSERT( EFalse ); |
|
81 break; |
|
82 } |
|
83 } |
|
84 |
|
85 return command; |
|
86 } |
|
87 |
|
88 } // namespace |
|
89 |
|
90 // ======== MEMBER FUNCTIONS ======== |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CMRUnifiedEditorField::NewL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CMRUnifiedEditorField* CMRUnifiedEditorField::NewL( ) |
|
97 { |
|
98 FUNC_LOG; |
|
99 CMRUnifiedEditorField* self = new (ELeave) CMRUnifiedEditorField; |
|
100 CleanupStack::PushL ( self ); |
|
101 self->ConstructL ( ); |
|
102 CleanupStack::Pop ( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CMRUnifiedEditorField::~CMRUnifiedEditorField |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 CMRUnifiedEditorField::~CMRUnifiedEditorField( ) |
|
111 { |
|
112 FUNC_LOG; |
|
113 iArray.ResetAndDestroy ( ); |
|
114 iArray.Close ( ); |
|
115 iFilter.Reset(); |
|
116 |
|
117 delete iIcon; |
|
118 delete iLockIcon; |
|
119 } |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CMRUnifiedEditorField::InternalizeL |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 void CMRUnifiedEditorField::InternalizeL( MESMRCalEntry& aEntry ) |
|
126 { |
|
127 FUNC_LOG; |
|
128 |
|
129 if ( aEntry.IsRecurrentEventL() |
|
130 && aEntry.RecurrenceModRule() == MESMRCalEntry::EESMRThisOnly ) |
|
131 { |
|
132 // Hide Unified editor type field |
|
133 iObserver->HideControl( EESMRFieldUnifiedEditor ); |
|
134 } |
|
135 else |
|
136 { |
|
137 // Make sure field is visible |
|
138 iObserver->ShowControl( EESMRFieldUnifiedEditor ); |
|
139 |
|
140 TInt eventValue = aEntry.Type(); |
|
141 iFilter.Reset(); |
|
142 |
|
143 // Checking if mailbox has been defined and unified editor |
|
144 // field value can be changed to Meeting Request |
|
145 CCalenInterimUtils2* calUtils = CCalenInterimUtils2::NewL(); |
|
146 CleanupStack::PushL( calUtils ); |
|
147 TBool mrEnabled = calUtils->MRViewersEnabledL( ETrue ); |
|
148 CleanupStack::PopAndDestroy(); |
|
149 |
|
150 if ( !mrEnabled ) |
|
151 { |
|
152 iFilter.AppendL( 0 ); |
|
153 } |
|
154 |
|
155 // esmrgui.rss |
|
156 TResourceReader reader; |
|
157 iCoeEnv->CreateResourceReaderLC ( reader, R_ESMREDITOR_UNIFIED ); |
|
158 |
|
159 // Read event type items to array |
|
160 iArray.ResetAndDestroy( ); |
|
161 TInt count = reader.ReadInt16 ( ); |
|
162 iArray.ReserveL( count ); |
|
163 |
|
164 for (TInt i(0); i < count; i++ ) |
|
165 { |
|
166 CESMRTextItem* event = new (ELeave) CESMRTextItem(); |
|
167 CleanupStack::PushL( event ); |
|
168 event->ConstructFromResourceL ( reader ); |
|
169 iArray.AppendL ( event ); |
|
170 CleanupStack::Pop( event ); |
|
171 if ( eventValue == event->Id ( ) ) |
|
172 { |
|
173 iIndex = i; |
|
174 iType->SetTextL ( event->TextL ( ) ); |
|
175 |
|
176 // Adding current event type to filter, not to be shown in popup |
|
177 iFilter.AppendL( event->Id() ); |
|
178 } |
|
179 } |
|
180 // resource reader |
|
181 CleanupStack::PopAndDestroy(); // codescanner::cleanup |
|
182 |
|
183 SetIconL( aEntry ); |
|
184 } |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CMRUnifiedEditorField::SetOutlineFocusL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 void CMRUnifiedEditorField::SetOutlineFocusL( TBool aFocus ) |
|
192 { |
|
193 FUNC_LOG; |
|
194 CESMRField::SetOutlineFocusL ( aFocus ); |
|
195 |
|
196 //Focus gained |
|
197 if ( aFocus ) |
|
198 { |
|
199 ChangeMiddleSoftKeyL(EESMRCmdOpenUnifiedEditorQuery, R_QTN_MSK_OPEN); |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CMRUnifiedEditorField::ExecuteGenericCommandL |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 TBool CMRUnifiedEditorField::ExecuteGenericCommandL( TInt aCommand ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 TBool isUsed( EFalse ); |
|
211 if(aCommand == EESMRCmdOpenUnifiedEditorQuery || |
|
212 aCommand == EAknCmdOpen ) |
|
213 { |
|
214 if( IsLocked() ) |
|
215 { |
|
216 HandleTactileFeedbackL(); |
|
217 |
|
218 CESMRGlobalNote::ExecuteL( |
|
219 CESMRGlobalNote::EESMRUnableToEdit ); |
|
220 isUsed = ETrue; |
|
221 } |
|
222 else |
|
223 { |
|
224 HandleTactileFeedbackL(); |
|
225 |
|
226 ExecuteTypeQueryL(); |
|
227 isUsed = ETrue; |
|
228 } |
|
229 } |
|
230 return isUsed; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CMRUnifiedEditorField::LockL |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CMRUnifiedEditorField::LockL() |
|
238 { |
|
239 FUNC_LOG; |
|
240 if( IsLocked() ) |
|
241 { |
|
242 return; |
|
243 } |
|
244 |
|
245 CESMRField::LockL(); |
|
246 |
|
247 delete iLockIcon; |
|
248 iLockIcon = NULL; |
|
249 iLockIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue ); |
|
250 iLockIcon->SetParent( this ); |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // CMRUnifiedEditorField::ExecuteTypeQueryL |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 void CMRUnifiedEditorField::ExecuteTypeQueryL() |
|
258 { |
|
259 FUNC_LOG; |
|
260 |
|
261 TInt ret = |
|
262 CESMRListQuery::ExecuteL( CESMRListQuery::EESMRUnifiedEditorPopup, |
|
263 iFilter ); |
|
264 |
|
265 if ( ret != KErrCancel ) |
|
266 { |
|
267 // Send command to dialog |
|
268 NotifyEventAsyncL( MapIndexToCommandId( ret ) ); |
|
269 } |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CMRUnifiedEditorField::CMRUnifiedEditorField |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 CMRUnifiedEditorField::CMRUnifiedEditorField( ) : |
|
277 iIndex(0) |
|
278 { |
|
279 FUNC_LOG; |
|
280 SetFieldId( EESMRFieldUnifiedEditor ); |
|
281 SetFocusType( EESMRHighlightFocus ); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CMRUnifiedEditorField::ConstructL |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 void CMRUnifiedEditorField::ConstructL( ) |
|
289 { |
|
290 FUNC_LOG; |
|
291 iType = CMRLabel::NewL(); |
|
292 CESMRField::ConstructL( iType ); |
|
293 iType->SetTextL( KNullDesC() ); |
|
294 |
|
295 TGulAlignment align; |
|
296 align.SetHAlignment( EHLeft ); |
|
297 align.SetVAlignment( EVCenter ); |
|
298 iType->SetAlignment( align ); |
|
299 |
|
300 // An icon is required for layouting the field. Actual correct icon |
|
301 // is set after InternalizeL. |
|
302 iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapEventTypeMeeting ); |
|
303 } |
|
304 |
|
305 // --------------------------------------------------------------------------- |
|
306 // CMRUnifiedEditorField::UpdateLabelL |
|
307 // --------------------------------------------------------------------------- |
|
308 // |
|
309 void CMRUnifiedEditorField::UpdateLabelL( TInt aIndex ) |
|
310 { |
|
311 FUNC_LOG; |
|
312 CESMRTextItem* event = iArray[ aIndex ]; |
|
313 iType->SetTextL( event->TextL() ); |
|
314 iType->DrawDeferred(); |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // CMRUnifiedEditorField::CountComponentControls |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 TInt CMRUnifiedEditorField::CountComponentControls() const |
|
322 { |
|
323 FUNC_LOG; |
|
324 TInt count( 0 ); |
|
325 if ( iIcon ) |
|
326 { |
|
327 ++count; |
|
328 } |
|
329 |
|
330 if ( iType ) |
|
331 { |
|
332 ++count; |
|
333 } |
|
334 |
|
335 if ( iLockIcon ) |
|
336 { |
|
337 ++count; |
|
338 } |
|
339 return count; |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------------------------- |
|
343 // CMRUnifiedEditorField::ComponentControl |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 CCoeControl* CMRUnifiedEditorField::ComponentControl( TInt aIndex ) const |
|
347 { |
|
348 FUNC_LOG; |
|
349 CCoeControl* control = NULL; |
|
350 switch( aIndex ) |
|
351 { |
|
352 case 0: |
|
353 { |
|
354 control = iType; |
|
355 break; |
|
356 } |
|
357 case 1: |
|
358 { |
|
359 control = iIcon; |
|
360 break; |
|
361 } |
|
362 case 2: |
|
363 { |
|
364 control = iLockIcon; |
|
365 break; |
|
366 } |
|
367 default: |
|
368 ASSERT( EFalse ); |
|
369 } |
|
370 |
|
371 return control; |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // CMRUnifiedEditorField::SizeChanged |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CMRUnifiedEditorField::SizeChanged() |
|
379 { |
|
380 FUNC_LOG; |
|
381 TRect rect( Rect() ); |
|
382 TAknLayoutRect iconLayout( NMRLayoutManager::GetLayoutRect( |
|
383 rect, NMRLayoutManager::EMRLayoutTextEditorIcon ) ); |
|
384 iIcon->SetRect( iconLayout.Rect() ); |
|
385 |
|
386 // Layouting lock icon |
|
387 if( iLockIcon ) |
|
388 { |
|
389 TAknWindowComponentLayout iconLayout( |
|
390 NMRLayoutManager::GetWindowComponentLayout( |
|
391 NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) ); |
|
392 AknLayoutUtils::LayoutImage( iLockIcon, rect, iconLayout ); |
|
393 } |
|
394 |
|
395 // Layouting label |
|
396 TAknLayoutText viewerLayoutText; |
|
397 if( iLockIcon ) |
|
398 { |
|
399 viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, |
|
400 NMRLayoutManager::EMRTextLayoutSingleRowEditorText ); |
|
401 } |
|
402 else |
|
403 { |
|
404 viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, |
|
405 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
406 } |
|
407 |
|
408 TRect viewerRect( viewerLayoutText.TextRect() ); |
|
409 iType->SetRect( viewerRect ); |
|
410 |
|
411 // Move focus rect so that it's relative to field's position. |
|
412 viewerRect.Move( -Position() ); |
|
413 SetFocusRect( viewerRect ); |
|
414 |
|
415 TAknTextComponentLayout editorLayout( |
|
416 NMRLayoutManager::GetTextComponentLayout( |
|
417 NMRLayoutManager::EMRTextLayoutTextEditor ) ); |
|
418 AknLayoutUtils::LayoutLabel( iType, rect, editorLayout ); |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // CMRUnifiedEditorField::SetIconL |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 void CMRUnifiedEditorField::SetIconL( MESMRCalEntry& aEntry ) |
|
426 { |
|
427 FUNC_LOG; |
|
428 NMRBitmapManager::TMRBitmapId bitmapId( |
|
429 NMRBitmapManager::EMRBitmapNotSet ); |
|
430 |
|
431 CCalEntry& entry = aEntry.Entry(); |
|
432 |
|
433 switch ( entry.EntryTypeL() ) |
|
434 { |
|
435 case CCalEntry::EAppt: |
|
436 { |
|
437 if( CCalenInterimUtils2::IsMeetingRequestL( entry ) ) |
|
438 { |
|
439 bitmapId = NMRBitmapManager::EMRBitmapEventTypeMR; |
|
440 } |
|
441 else |
|
442 { |
|
443 bitmapId = NMRBitmapManager::EMRBitmapEventTypeMeeting; |
|
444 } |
|
445 break; |
|
446 } |
|
447 |
|
448 case CCalEntry::ETodo: |
|
449 { |
|
450 bitmapId = NMRBitmapManager::EMRBitmapEventTypeTodo; |
|
451 break; |
|
452 } |
|
453 |
|
454 case CCalEntry::EEvent: // Memo |
|
455 { |
|
456 bitmapId = NMRBitmapManager::EMRBitmapEventTypeMemo; |
|
457 break; |
|
458 } |
|
459 |
|
460 case CCalEntry::EAnniv: |
|
461 { |
|
462 bitmapId = NMRBitmapManager::EMRBitmapEventTypeAnniversary; |
|
463 break; |
|
464 } |
|
465 |
|
466 default: |
|
467 { |
|
468 ASSERT( EFalse ); |
|
469 break; |
|
470 } |
|
471 } |
|
472 |
|
473 delete iIcon; |
|
474 iIcon = NULL; |
|
475 iIcon = CMRImage::NewL( bitmapId ); |
|
476 } |
|
477 |
|
478 // EOF |
|
479 |