|
1 /* |
|
2 * Copyright (c) 2002-2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "AknGroupedNotifierNote.h" |
|
19 #include <eikbtgpc.h> |
|
20 #include <avkon.rsg> |
|
21 #include <avkon.hrh> |
|
22 #include <eikfrlb.h> |
|
23 #include <eikfrlbd.h> |
|
24 #include <aknenv.h> |
|
25 #include <aknnotpi.rsg> |
|
26 #include <viewcli.h> |
|
27 #include <StringLoader.h> |
|
28 #include <aknlists.h> |
|
29 #include <coreapplicationuisdomainpskeys.h> // KCoreAppUIsAutolockStatus |
|
30 |
|
31 #include "AknCapServerEntry.h" |
|
32 |
|
33 /// Maximum allocated space for custom softkeys. |
|
34 const TInt KAknMaxCustomSoftkeyLength = 30; |
|
35 |
|
36 void CAknGroupedNotifierNote::ConstructL(MAknGroupedNotifierNoteObserver* aObserver) |
|
37 { |
|
38 iNoteObserver = aObserver; |
|
39 iOrder = new(ELeave) CArrayFixFlat<TInt>(4); |
|
40 |
|
41 iAutoLockStatus = EAutolockOff; |
|
42 RProperty autolockProperty; |
|
43 autolockProperty.Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, iAutoLockStatus); |
|
44 } |
|
45 |
|
46 void CAknGroupedNotifierNote::ActivateL() |
|
47 { |
|
48 CEikDialog::ActivateL(); |
|
49 } |
|
50 |
|
51 void CAknGroupedNotifierNote::PreLayoutDynInitL() |
|
52 { |
|
53 CAknListQueryDialog::PreLayoutDynInitL(); |
|
54 iTexts = iCoeEnv->ReadDesCArrayResourceL(R_GROUPED_NOTIFIER_TEXTS); |
|
55 if (iNoteObserver) |
|
56 { |
|
57 // Allow observer to add new texts |
|
58 iNoteObserver->AddItemsL( *iTexts, *iOrder ); |
|
59 } |
|
60 |
|
61 iTextsPlural = iCoeEnv->ReadDesCArrayResourceL(R_GROUPED_NOTIFIER_TEXTS_PLURAL); |
|
62 SetItemTextArray(this); |
|
63 SetOwnershipType(ELbmDoesNotOwnItemArray); |
|
64 |
|
65 CEikListBox* listbox = ListBox(); |
|
66 if (listbox) |
|
67 { |
|
68 listbox->SetObserver(this); |
|
69 } |
|
70 |
|
71 #ifdef RD_SCALABLE_UI_V2 |
|
72 if ( AknLayoutUtils::PenEnabled() ) |
|
73 { |
|
74 SetGloballyCapturing(ETrue); |
|
75 SetPointerCapture(ETrue); |
|
76 } |
|
77 #endif |
|
78 } |
|
79 |
|
80 void CAknGroupedNotifierNote::PostLayoutDynInitL() |
|
81 { |
|
82 // A focused custom note might require different softkeys than the default ones. |
|
83 UpdateSoftkeysL(); |
|
84 } |
|
85 |
|
86 void CAknGroupedNotifierNote::ProcessCommandL(TInt aCommandId) |
|
87 { |
|
88 // Note about to complete, so signal the notifier |
|
89 if (iNoteObserver) |
|
90 { |
|
91 // This should also inform the selected item to the observer! |
|
92 iNoteObserver->GroupedNoteCompletedL(aCommandId); |
|
93 } |
|
94 TryExitL(aCommandId); |
|
95 } |
|
96 |
|
97 CAknGroupedNotifierNote::CAknGroupedNotifierNote() |
|
98 : CAknListQueryDialog(&iSelectedItem) |
|
99 { |
|
100 } |
|
101 |
|
102 CAknGroupedNotifierNote::~CAknGroupedNotifierNote() |
|
103 { |
|
104 delete iTexts; |
|
105 delete iTextsPlural; |
|
106 delete iOrder; |
|
107 } |
|
108 |
|
109 void CAknGroupedNotifierNote::HandlePointerEventL( |
|
110 const TPointerEvent& aPointerEvent |
|
111 ) |
|
112 { |
|
113 if (!Rect().Contains(aPointerEvent.iPosition) && |
|
114 aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
115 { |
|
116 return; |
|
117 } |
|
118 |
|
119 CAknListQueryDialog::HandlePointerEventL(aPointerEvent); |
|
120 } |
|
121 |
|
122 TKeyResponse CAknGroupedNotifierNote::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
123 { |
|
124 if (aType == EEventKey) |
|
125 { |
|
126 // Send number keys to phone app, and bring it for foreground |
|
127 if ((aKeyEvent.iCode >= '0' && aKeyEvent.iCode <= '9') |
|
128 || aKeyEvent.iCode == '#' |
|
129 || aKeyEvent.iCode == '*') |
|
130 { |
|
131 if (aKeyEvent.iRepeats == 0) |
|
132 { |
|
133 MAknPhoneKeyForwarder* keyf = STATIC_CAST( |
|
134 CAknCapAppServerAppUi*, CEikonEnv::Static()->AppUi())->AsKeyForwarder(); |
|
135 |
|
136 keyf->ForwardKeyToPhoneAppL(aKeyEvent); |
|
137 iNoteObserver->GroupedNoteCompletedL(KErrCancel); |
|
138 delete this; |
|
139 } |
|
140 return EKeyWasConsumed; |
|
141 } |
|
142 } |
|
143 |
|
144 if (aKeyEvent.iCode == EKeyEscape) |
|
145 { |
|
146 // Workaround the current problem where the SecUI sends an EKeyEscape |
|
147 // to the control stack when it wants to remove it's own dialog |
|
148 return EKeyWasNotConsumed; |
|
149 } |
|
150 |
|
151 return CAknListQueryDialog::OfferKeyEventL(aKeyEvent, aType); |
|
152 } |
|
153 |
|
154 TBool CAknGroupedNotifierNote::OkToExitL(TInt aButtonId) |
|
155 { |
|
156 // Generic method used to find out whether the command belongs to "cancel" commands. |
|
157 TInt mappedCommandId = MappedCommandId(aButtonId); |
|
158 |
|
159 TNoteAction noteAction = EDoNothing; |
|
160 |
|
161 if (mappedCommandId == EEikBidCancel || |
|
162 mappedCommandId == EAknSoftkeyExit || |
|
163 mappedCommandId == EAknSoftkeyCancel || |
|
164 mappedCommandId == EAknSoftkeyBack || |
|
165 mappedCommandId == EAknSoftkeyNo || |
|
166 mappedCommandId == EAknSoftkeyClose || |
|
167 mappedCommandId == EAknSoftkeyQuit || |
|
168 mappedCommandId == EAknSoftkeyDone) |
|
169 { |
|
170 // The command is a cancelling command. |
|
171 noteAction = EExitNote; |
|
172 } |
|
173 else if (iCustomNoteAcceptKeyId) |
|
174 { |
|
175 // The grouped note item is a custom item. Check whether the command |
|
176 // is the accept key defined for that custom item. |
|
177 if (mappedCommandId == iCustomNoteAcceptKeyId || mappedCommandId == EAknSoftkeyOk) |
|
178 { |
|
179 noteAction = ELaunchItemHandler; |
|
180 } |
|
181 } |
|
182 else |
|
183 { |
|
184 // The grouped note item is not a custom item. Only "Show" or "Ok" commands |
|
185 // are used to launch the note. |
|
186 if (mappedCommandId == EAknSoftkeyShow || mappedCommandId == EAknSoftkeyOk) |
|
187 { |
|
188 noteAction = ELaunchItemHandler; |
|
189 } |
|
190 } |
|
191 |
|
192 // Now make the action... |
|
193 |
|
194 if (noteAction == ELaunchItemHandler) |
|
195 { |
|
196 TInt itemindex = ListBox()->CurrentItemIndex(); |
|
197 __ASSERT_DEBUG(itemindex != -1, Panic(EAknPanicOutOfRange)); |
|
198 |
|
199 #ifdef RD_SCALABLE_UI_V2 |
|
200 if (AknLayoutUtils::PenEnabled()) |
|
201 { |
|
202 SetGloballyCapturing(EFalse); |
|
203 SetPointerCapture(EFalse); |
|
204 } |
|
205 #endif |
|
206 |
|
207 if (itemindex == -1) |
|
208 { |
|
209 iNoteObserver->GroupedNoteCompletedL(EAknSoftkeyExit, EMaxItem); |
|
210 return ETrue; |
|
211 } |
|
212 |
|
213 // Use always Ok command. |
|
214 iNoteObserver->GroupedNoteCompletedL( |
|
215 EAknSoftkeyOk, |
|
216 TAknGroupedNotifierItem(iOrder->At(itemindex))); |
|
217 |
|
218 return ETrue; |
|
219 } |
|
220 else if (noteAction == EExitNote) |
|
221 { |
|
222 #ifdef RD_SCALABLE_UI_V2 |
|
223 if (AknLayoutUtils::PenEnabled()) |
|
224 { |
|
225 SetGloballyCapturing(EFalse); |
|
226 SetPointerCapture(EFalse); |
|
227 } |
|
228 #endif |
|
229 // Use always Exit command. |
|
230 iNoteObserver->GroupedNoteCompletedL(EAknSoftkeyExit, EMaxItem); |
|
231 return ETrue; |
|
232 } |
|
233 |
|
234 else |
|
235 { |
|
236 // Unknown command, do nothing. |
|
237 return EFalse; |
|
238 } |
|
239 } |
|
240 |
|
241 void CAknGroupedNotifierNote::SetItemAmountL(TAknGroupedNotifierItem aItem, TInt aAmount, |
|
242 TBool aHighlight) |
|
243 { |
|
244 TInt arrayIndex = aItem - EMissedCalls; |
|
245 TBool isDynamicText(EFalse); |
|
246 |
|
247 if (arrayIndex >= 0 && arrayIndex < EMaxItem) // traditional types |
|
248 { |
|
249 iCount[arrayIndex] = aAmount; |
|
250 } |
|
251 else |
|
252 { |
|
253 arrayIndex = aItem; |
|
254 isDynamicText = ETrue; |
|
255 } |
|
256 |
|
257 TKeyArrayFix key(0,ECmpTInt); |
|
258 TInt item; |
|
259 if (iOrder->Find(arrayIndex, key, item) == 0) |
|
260 { |
|
261 iOrder->Delete(item); |
|
262 if (isDynamicText) |
|
263 { // if it is in iOrder, it is also in iTexts |
|
264 iTexts->Delete(item); |
|
265 return; // only deletion of item is allowed in this method. |
|
266 } |
|
267 } |
|
268 |
|
269 if (aAmount > 0) |
|
270 { |
|
271 iOrder->AppendL(arrayIndex); |
|
272 } |
|
273 |
|
274 if (aHighlight) |
|
275 { |
|
276 if (aAmount) |
|
277 { |
|
278 iHighlightedItem = iOrder->Count() - 1; |
|
279 } |
|
280 else |
|
281 { |
|
282 iHighlightedItem = 0; |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 |
|
288 TInt CAknGroupedNotifierNote::MdcaCount() const |
|
289 { |
|
290 return iOrder->Count(); |
|
291 } |
|
292 |
|
293 TPtrC CAknGroupedNotifierNote::MdcaPoint(TInt aIndex) const |
|
294 { |
|
295 // can I play with constness ;) |
|
296 TDes &des = MUTABLE_CAST(TBuf<KAknMaxGroupedNoteItemTextLength>&, iBuffer); |
|
297 des.Zero(); |
|
298 TPtrC listItemText; |
|
299 TInt numOfItems = 0; |
|
300 |
|
301 TInt itemType = iOrder->At(aIndex); |
|
302 |
|
303 if (itemType >= 0 && itemType < EMaxItem) // traditional types |
|
304 { |
|
305 numOfItems = iCount[itemType]; |
|
306 |
|
307 __ASSERT_DEBUG(numOfItems > 0, Panic(EAknPanicOutOfRange)); |
|
308 // choose the item to show |
|
309 if (numOfItems == 1) |
|
310 { |
|
311 listItemText.Set(iTexts->MdcaPoint(itemType)); |
|
312 } |
|
313 else |
|
314 { |
|
315 listItemText.Set(iTextsPlural->MdcaPoint(itemType)); |
|
316 } |
|
317 } |
|
318 else // "Dynamic" texts |
|
319 { |
|
320 // count text index |
|
321 for (TInt i = 0; i < EMaxItem; i++) |
|
322 { |
|
323 if (iCount[i] > 0) // static text in iOrder |
|
324 { |
|
325 aIndex--; |
|
326 } |
|
327 } |
|
328 |
|
329 aIndex += EMaxItem; // jump over static texts |
|
330 |
|
331 __ASSERT_ALWAYS(aIndex >= 0, User::Invariant()); |
|
332 listItemText.Set(iTexts->MdcaPoint(aIndex)); |
|
333 } |
|
334 |
|
335 // replace %N with the number |
|
336 _LIT(KNumber,"%N"); |
|
337 TInt pos = listItemText.Find(KNumber); |
|
338 |
|
339 if (pos != KErrNotFound) |
|
340 { |
|
341 StringLoader::Format(des, listItemText, -1, numOfItems); |
|
342 } |
|
343 else |
|
344 { |
|
345 des.Append(listItemText.Left(KAknMaxGroupedNoteItemTextLength)); |
|
346 } |
|
347 |
|
348 // return result |
|
349 return iBuffer; |
|
350 } |
|
351 |
|
352 TBool CAknGroupedNotifierNote::AutoLockEnabled() |
|
353 { |
|
354 return EFalse; |
|
355 } |
|
356 |
|
357 void CAknGroupedNotifierNote::CEikDialog_Reserved_1() |
|
358 { |
|
359 } |
|
360 |
|
361 void CAknGroupedNotifierNote::CEikDialog_Reserved_2() |
|
362 { |
|
363 } |
|
364 |
|
365 void CAknGroupedNotifierNote::CAknDialog_Reserved() |
|
366 { |
|
367 } |
|
368 |
|
369 void CAknGroupedNotifierNote::CAknQueryDialog_Reserved() |
|
370 { |
|
371 } |
|
372 |
|
373 void CAknGroupedNotifierNote::HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType) |
|
374 { |
|
375 if (aEventType == EEventStateChanged) |
|
376 { |
|
377 // Focused item has changed, softkeys might require updating. |
|
378 UpdateSoftkeysL(); |
|
379 } |
|
380 |
|
381 CAknListQueryDialog::HandleControlEventL(aControl, aEventType); |
|
382 } |
|
383 |
|
384 void CAknGroupedNotifierNote::UpdateSoftkeysL() |
|
385 { |
|
386 CEikListBox* listbox = ListBox(); |
|
387 if (listbox) |
|
388 { |
|
389 // Get the focused item and check that it is in valid range. |
|
390 TInt itemindex = listbox->CurrentItemIndex(); |
|
391 __ASSERT_DEBUG(itemindex >= 0 && itemindex < MdcaCount(), Panic(EAknPanicOutOfRange)); |
|
392 |
|
393 if (itemindex >= 0 && itemindex < MdcaCount()) |
|
394 { |
|
395 // If the focused item is a custom note, this method returns its resource id. |
|
396 TAknGroupedNotifierItem item = TAknGroupedNotifierItem(iOrder->At(itemindex)); |
|
397 |
|
398 HBufC* leftSK = HBufC::NewLC( KAknMaxCustomSoftkeyLength ); |
|
399 HBufC* rightSK = HBufC::NewLC( KAknMaxCustomSoftkeyLength ); |
|
400 |
|
401 TInt newSoftkeys = 0; |
|
402 if (item > EMaxItem || item < 0) |
|
403 { |
|
404 // Note is out of "static" range, i.e. a custom note. |
|
405 TPtr left( leftSK->Des() ); |
|
406 TPtr right( rightSK->Des() ); |
|
407 iNoteObserver->SoftkeysForCustomItem(item, newSoftkeys, |
|
408 iCustomNoteAcceptKeyId, left, right ); |
|
409 } |
|
410 |
|
411 if (!newSoftkeys) |
|
412 { |
|
413 newSoftkeys = R_AVKON_SOFTKEYS_SHOW_EXIT__SHOW; |
|
414 iCustomNoteAcceptKeyId = 0; |
|
415 } |
|
416 |
|
417 // Update softkeys only if necessary. |
|
418 if( newSoftkeys != iCustomNoteSoftkeys || |
|
419 iCustomNoteSoftkeysAssigned || // custom text was used (force update) |
|
420 leftSK->Length() > 0 || |
|
421 rightSK->Length() > 0 ) |
|
422 { |
|
423 CEikButtonGroupContainer& buttonGroup = ButtonGroupContainer(); |
|
424 buttonGroup.SetCommandSetL(newSoftkeys); |
|
425 buttonGroup.DrawDeferred(); |
|
426 iCustomNoteSoftkeys = newSoftkeys; |
|
427 |
|
428 iCustomNoteSoftkeysAssigned = EFalse; |
|
429 MEikButtonGroup* buttonGrp = buttonGroup.ButtonGroup(); |
|
430 if( buttonGrp ) |
|
431 { |
|
432 if( leftSK->Length() > 0 ) |
|
433 { |
|
434 buttonGroup.SetCommandL( buttonGrp->CommandId( |
|
435 CEikButtonGroupContainer::ELeftSoftkeyPosition ), |
|
436 *leftSK ); |
|
437 iCustomNoteSoftkeysAssigned = ETrue; |
|
438 } |
|
439 if( rightSK->Length() > 0 ) |
|
440 { |
|
441 buttonGroup.SetCommandL( buttonGrp->CommandId( |
|
442 CEikButtonGroupContainer::ERightSoftkeyPosition ), |
|
443 *rightSK ); |
|
444 iCustomNoteSoftkeysAssigned = ETrue; |
|
445 } |
|
446 } |
|
447 } |
|
448 CleanupStack::PopAndDestroy( 2, leftSK ); // rightSK |
|
449 } |
|
450 } |
|
451 |
|
452 // If we are going to display the grouped list notification on the top of Autolock App, |
|
453 // So we need to invisible the softkey buttons. |
|
454 if (AknLayoutUtils::PenEnabled() && iAutoLockStatus > EAutolockOff) |
|
455 { |
|
456 CEikButtonGroupContainer& bgc = ButtonGroupContainer(); |
|
457 MEikButtonGroup* buttonGrp = bgc.ButtonGroup(); |
|
458 if (buttonGrp) |
|
459 { |
|
460 bgc.SetCommandL(buttonGrp->CommandId(CEikButtonGroupContainer::ELeftSoftkeyPosition), KNullDesC); |
|
461 bgc.SetCommandL(buttonGrp->CommandId(CEikButtonGroupContainer::ERightSoftkeyPosition), KNullDesC); |
|
462 } |
|
463 } |
|
464 } |
|
465 |
|
466 // End of file |