|
1 /* |
|
2 * Copyright (c) 2008 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: Plugin implementation of global list message query. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "AknSystemListMsgPopup.h" |
|
19 #include <AknNotifyStd.h> |
|
20 #include <AknsUtils.h> |
|
21 |
|
22 #include <avkon.rsg> |
|
23 #include <eikbtgpc.h> |
|
24 #include <eikenv.h> |
|
25 #include <avkon.hrh> |
|
26 #include <bautils.h> |
|
27 #include "AknListQueryNotificationDialog.h" |
|
28 #include "AknListMsgQueryNotificationDialog.h" |
|
29 #include <aknnotpi.rsg> |
|
30 #include <AknGlobalListMsgQuery.h> |
|
31 #include <s32mem.h> |
|
32 #include <uikon/eiksrvui.h> |
|
33 #include <AknNotifySignature.h> |
|
34 #include <aknmessagequerycontrol.h> |
|
35 |
|
36 #include <AknMediatorFacade.h> |
|
37 #include <aknSDData.h> |
|
38 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h> |
|
39 |
|
40 #include "AknAppsKeyCleanup.inl" |
|
41 |
|
42 const TInt KListQueryItemLength = 64; |
|
43 const TInt KCharsInTInt = 4; // TInt32 takes 4 chars. |
|
44 const TInt KItemArrayGranularity = 3; |
|
45 _LIT(KEmptyHeading, " "); |
|
46 |
|
47 CAknGlobalListMsgQuerySubject* CAknGlobalListMsgQuerySubject::NewL() |
|
48 { |
|
49 CAknGlobalListMsgQuerySubject* self = new (ELeave) CAknGlobalListMsgQuerySubject(); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CAknGlobalListMsgQuerySubject::CAknGlobalListMsgQuerySubject() |
|
57 : iPending(EFalse) |
|
58 { |
|
59 iStoredEikonEnv = CEikonEnv::Static(); |
|
60 } |
|
61 |
|
62 void CAknGlobalListMsgQuerySubject::ConstructL() |
|
63 { |
|
64 } |
|
65 |
|
66 CAknGlobalListMsgQuerySubject::~CAknGlobalListMsgQuerySubject() |
|
67 { |
|
68 //delete iDlg; |
|
69 Cancel(); |
|
70 |
|
71 // Complete the RMessage if we need to. |
|
72 if (iPending) |
|
73 { |
|
74 iMessage.Complete(KErrDied); |
|
75 } |
|
76 |
|
77 delete iArray; |
|
78 delete iHeading; |
|
79 delete iMsgText; |
|
80 } |
|
81 |
|
82 void CAknGlobalListMsgQuerySubject::Release() |
|
83 { |
|
84 delete this; |
|
85 } |
|
86 |
|
87 CAknGlobalListMsgQuerySubject::TNotifierInfo CAknGlobalListMsgQuerySubject::RegisterL() |
|
88 { |
|
89 iInfo.iUid = KAknGlobalListMsgQueryUid; |
|
90 iInfo.iChannel = EAknNotifierChannelListMsgQuery; |
|
91 iInfo.iPriority = ENotifierPriorityHigh; |
|
92 return iInfo; |
|
93 } |
|
94 |
|
95 CAknGlobalListMsgQuerySubject::TNotifierInfo CAknGlobalListMsgQuerySubject::Info() const |
|
96 { |
|
97 return iInfo; |
|
98 } |
|
99 |
|
100 TPtrC8 CAknGlobalListMsgQuerySubject::StartL(const TDesC8& /*aBuffer*/) |
|
101 { |
|
102 return KNullDesC8(); |
|
103 } |
|
104 |
|
105 void CAknGlobalListMsgQuerySubject::StartL(const TDesC8& aBuffer, TInt /*aReplySlot*/, |
|
106 const RMessagePtr2& aMessage) |
|
107 { |
|
108 if (iPending) |
|
109 { |
|
110 aMessage.Complete(KErrInUse); |
|
111 return; |
|
112 } |
|
113 |
|
114 RDesReadStream readStream(aBuffer); |
|
115 if (aBuffer.Length() < KCharsInTInt || readStream.ReadInt32L() != KAKNNOTIFIERSIGNATURE) |
|
116 { |
|
117 User::Leave(KErrArgument); |
|
118 } |
|
119 |
|
120 iMessage = aMessage; |
|
121 iSelectFirst = readStream.ReadInt16L(); |
|
122 TInt count = readStream.ReadInt16L(); |
|
123 |
|
124 // Create array |
|
125 delete iArray; |
|
126 iArray = 0; |
|
127 iArray = new (ELeave) CDesCArrayFlat(KItemArrayGranularity); |
|
128 |
|
129 TBuf<KListQueryItemLength> arrayItem; |
|
130 |
|
131 for (TInt ii = 0; ii < count; ii++) |
|
132 { |
|
133 readStream >> arrayItem; |
|
134 iArray->AppendL(arrayItem); |
|
135 } |
|
136 |
|
137 TInt headingLength = readStream.ReadInt16L(); |
|
138 delete iHeading; |
|
139 iHeading = 0; |
|
140 |
|
141 if (headingLength >= 0) |
|
142 { |
|
143 iHeading = HBufC::NewL(headingLength); |
|
144 TPtr ptr = iHeading->Des(); |
|
145 readStream >> ptr; |
|
146 } |
|
147 else if (headingLength != KErrNotFound) |
|
148 { |
|
149 User::Leave(KErrArgument); |
|
150 } |
|
151 |
|
152 // Enable listbox to have message under title. |
|
153 TInt msgTextLength = readStream.ReadInt16L(); |
|
154 delete iMsgText; |
|
155 iMsgText = 0; |
|
156 |
|
157 if (msgTextLength >= 0) |
|
158 { |
|
159 iMsgText = HBufC::NewL(msgTextLength); |
|
160 TPtr ptrMsg = iMsgText->Des(); |
|
161 readStream >> ptrMsg; |
|
162 } |
|
163 else if (msgTextLength != KErrNotFound) |
|
164 { |
|
165 User::Leave(KErrArgument); |
|
166 } |
|
167 |
|
168 TInt imageId = readStream.ReadInt16L(); |
|
169 TInt imageMaskId = readStream.ReadInt16L(); |
|
170 TInt tone = readStream.ReadInt16L(); |
|
171 TInt imageFileLength = readStream.ReadInt16L(); |
|
172 TFileName imageFile; |
|
173 if (imageFileLength) |
|
174 { |
|
175 readStream >> imageFile; |
|
176 } |
|
177 |
|
178 TInt skinsMajor = readStream.ReadInt32L(); |
|
179 TInt skinsMinor = readStream.ReadInt32L(); |
|
180 TInt softkeys = readStream.ReadInt32L(); |
|
181 TInt acceptKeyId = readStream.ReadInt32L(); |
|
182 TInt cancelKeyId = readStream.ReadInt32L(); |
|
183 |
|
184 if (!softkeys) |
|
185 { |
|
186 softkeys = R_AVKON_SOFTKEYS_OK_CANCEL__OK; |
|
187 } |
|
188 |
|
189 // Accept key cannot be EAknSoftkeyCancel and cancel key cannot be EAknSoftkeyOk. |
|
190 if (acceptKeyId == EAknSoftkeyCancel || cancelKeyId == EAknSoftkeyOk) |
|
191 { |
|
192 User::Leave(KErrArgument); |
|
193 } |
|
194 |
|
195 CAknSDData* sddata = 0; |
|
196 if (readStream.ReadInt8L()) |
|
197 { |
|
198 sddata = new (ELeave) CAknSDData(); |
|
199 CleanupStack::PushL(sddata); |
|
200 readStream >> *sddata; |
|
201 } |
|
202 |
|
203 delete iDlg; |
|
204 iDlg = NULL; |
|
205 |
|
206 iDlg = new (ELeave) CAknListMsgQueryNotificationDialog( |
|
207 &iListIndex, |
|
208 this, |
|
209 &iDlg, |
|
210 acceptKeyId, |
|
211 cancelKeyId); |
|
212 |
|
213 iDlg->SetTone(tone); |
|
214 |
|
215 if (sddata) |
|
216 { |
|
217 CArrayFixFlat<TInt>* array = 0; |
|
218 CleanupStack::PushL(array); // even as null |
|
219 if (sddata->iAdditionalData && |
|
220 sddata->iAdditionalData->Length() > 2*sizeof(TInt32)) // command id and count |
|
221 { |
|
222 RDesReadStream strm(*sddata->iAdditionalData); |
|
223 CleanupClosePushL(strm); |
|
224 TInt count = strm.ReadInt32L(); // recycling... |
|
225 if (count == EAknListQueryItemsInfo) |
|
226 { |
|
227 count = strm.ReadInt32L(); |
|
228 array = new (ELeave) CArrayFixFlat<TInt>(1); |
|
229 for (TInt i = 0; i < count; i++) |
|
230 { |
|
231 array->AppendL(strm.ReadInt32L()); |
|
232 } |
|
233 } |
|
234 CleanupStack::PopAndDestroy(&strm); |
|
235 |
|
236 // Tidy additional data so that there will not be two item arrays. |
|
237 TInt bytesToRemove = (count + 2) * 4; |
|
238 HBufC8* newDes = 0; |
|
239 if (bytesToRemove != sddata->iAdditionalData->Length()) |
|
240 { |
|
241 newDes = sddata->iAdditionalData->Mid(bytesToRemove).AllocL(); |
|
242 } |
|
243 delete sddata->iAdditionalData; |
|
244 sddata->iAdditionalData = newDes; |
|
245 } |
|
246 |
|
247 iDlg->PublishDialogL(sddata->iDialogIdx, sddata->iCategory, array); |
|
248 CleanupStack::Pop(array); // Ownership transferred to dialog successfully. |
|
249 if (sddata->iAdditionalData) |
|
250 { |
|
251 CAknMediatorFacade* cover_info = AknMediatorFacade(iDlg); |
|
252 if (cover_info) |
|
253 { |
|
254 cover_info->BufStream() << *(sddata->iAdditionalData); |
|
255 cover_info->BufStream().CommitL(); |
|
256 } |
|
257 } |
|
258 CleanupStack::PopAndDestroy(sddata); |
|
259 } |
|
260 else |
|
261 { |
|
262 // If secondary display data hasn't been defined, then the unidentified |
|
263 // list query identifier is published to the secondary display. |
|
264 iDlg->PublishDialogL(EAknUnidentifiedListQuery, KAknSecondaryDisplayCategory); |
|
265 } |
|
266 |
|
267 CEikImage* image = new (ELeave) CEikImage; |
|
268 CleanupStack::PushL(image); |
|
269 TAknsItemID id; |
|
270 id.Set(skinsMajor, skinsMinor); |
|
271 CFbsBitmap* bitmap = NULL; |
|
272 CFbsBitmap* mask = NULL; |
|
273 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
274 TRAPD(err, AknsUtils::CreateIconL(skin, id, bitmap, mask, imageFile, imageId, imageMaskId)); |
|
275 |
|
276 // Enable listbox to have message under title. |
|
277 if (!err) |
|
278 { |
|
279 image->SetPicture(bitmap,mask); |
|
280 } |
|
281 else |
|
282 { |
|
283 CleanupStack::PopAndDestroy(image); |
|
284 image = 0; |
|
285 } |
|
286 |
|
287 if (!iMsgText) |
|
288 { |
|
289 iMsgText = KNullDesC().AllocL(); |
|
290 } |
|
291 |
|
292 if (!iHeading || !iHeading->Length()) |
|
293 { |
|
294 delete iHeading; |
|
295 iHeading = NULL; |
|
296 iHeading = KEmptyHeading().AllocL(); |
|
297 } |
|
298 |
|
299 if (!iAppsKeySuppressed) |
|
300 { |
|
301 ((CAknNotifierAppServerAppUi*)(iStoredEikonEnv->EikAppUi()))->SuppressAppSwitching(ETrue); |
|
302 } |
|
303 |
|
304 CleanupStack::PushL(TCleanupItem(ReleaseAppsKey, 0)); |
|
305 |
|
306 iDlg->PrepareLC(R_GLOBAL_LIST_MSG_QUERY); |
|
307 iDlg->MessageBox()->SetMessageTextL(iMsgText); |
|
308 |
|
309 CAknListQueryControl* listControl = iDlg->ListControl(); |
|
310 CAknPopupHeadingPane* head = listControl->Heading(); |
|
311 head->SetHeaderImageOwnedL(image); |
|
312 head->SetTextL(iHeading->Des()); |
|
313 |
|
314 iDlg->SetOwnershipType(ELbmOwnsItemArray); |
|
315 iDlg->SetItemTextArray(iArray); |
|
316 TInt itemCount = iArray->Count(); |
|
317 iArray = 0; |
|
318 |
|
319 // The selection index must point to an existing item. Otherwise a panic will occur. |
|
320 if (iSelectFirst < 0 || iSelectFirst > itemCount - 1) |
|
321 { |
|
322 User::Leave(KErrArgument); |
|
323 } |
|
324 |
|
325 CEikListBox* listBox = iDlg->ListBox(); |
|
326 listBox->SetCurrentItemIndex(iSelectFirst); |
|
327 listBox->UpdateScrollBarsL(); |
|
328 |
|
329 // If softkeys are given, the resource id must point to a valid resource. |
|
330 // Trying to use invalid softkeys can cause panic. |
|
331 if (!(iStoredEikonEnv->IsResourceAvailableL(softkeys))) |
|
332 { |
|
333 User::Leave(KErrArgument); |
|
334 } |
|
335 iDlg->ButtonGroupContainer().SetCommandSetL(softkeys); |
|
336 |
|
337 iDlg->RunLD(); |
|
338 CleanupStack::Pop(); // Apps key cleanup. |
|
339 |
|
340 if (image) |
|
341 { |
|
342 CleanupStack::Pop(image); |
|
343 } |
|
344 |
|
345 iAppsKeySuppressed = ETrue; |
|
346 iPending = ETrue; |
|
347 } |
|
348 |
|
349 void CAknGlobalListMsgQuerySubject::Cancel() |
|
350 { |
|
351 delete iDlg; |
|
352 iDlg = NULL; |
|
353 TRAP_IGNORE(QueryDismissedL(EAknSoftkeyCancel)); |
|
354 } |
|
355 |
|
356 TPtrC8 CAknGlobalListMsgQuerySubject::UpdateL(const TDesC8& aBuffer) |
|
357 { |
|
358 if (!iDlg) |
|
359 { |
|
360 return KNullDesC8(); |
|
361 } |
|
362 |
|
363 // Get parameters. |
|
364 SAknNotifierPackage<SAknGlobalListQueryParams>* params |
|
365 = (SAknNotifierPackage<SAknGlobalListQueryParams>*)aBuffer.Ptr(); |
|
366 |
|
367 if (aBuffer.Length() < 0 |
|
368 || (TUint)aBuffer.Length() < sizeof(SAknNotifierPackage<SAknGlobalListQueryParams>) |
|
369 || params->iSignature != KAKNNOTIFIERSIGNATURE) |
|
370 { |
|
371 User::Leave(KErrArgument); |
|
372 } |
|
373 |
|
374 TInt cmd = params->iParamData.iCmd; |
|
375 TKeyEvent keyEvent; |
|
376 keyEvent.iRepeats = 0; |
|
377 TEventCode eventType = EEventKey; |
|
378 switch (cmd) |
|
379 { |
|
380 case EAknCancelGlobalQuery: |
|
381 delete iDlg; |
|
382 iDlg = NULL; |
|
383 QueryDismissedL(EAknSoftkeyCancel); |
|
384 return KNullDesC8(); |
|
385 case EAknMoveDownGlobalListQuery: |
|
386 keyEvent.iCode = EKeyDownArrow; |
|
387 break; |
|
388 case EAknMoveUpGlobalListQuery: |
|
389 keyEvent.iCode = EKeyUpArrow; |
|
390 break; |
|
391 case EAknSelectGlobalListQuery: |
|
392 keyEvent.iCode = EKeyOK; |
|
393 break; |
|
394 default: |
|
395 return KNullDesC8(); |
|
396 } |
|
397 |
|
398 iDlg->OfferKeyEventL(keyEvent, eventType); |
|
399 |
|
400 return KNullDesC8(); |
|
401 } |
|
402 |
|
403 void CAknGlobalListMsgQuerySubject::QueryDismissedL(TInt aResult) |
|
404 { |
|
405 if (iPending) |
|
406 { |
|
407 iMessage.Complete(aResult); |
|
408 } |
|
409 |
|
410 iPending = EFalse; |
|
411 iReturnVal = NULL; |
|
412 |
|
413 if (iAppsKeySuppressed) |
|
414 { |
|
415 ((CAknNotifierAppServerAppUi*)(iStoredEikonEnv->EikAppUi()))->SuppressAppSwitching(EFalse); |
|
416 } |
|
417 iAppsKeySuppressed = EFalse; |
|
418 } |
|
419 |
|
420 // End of file |