|
1 /* |
|
2 * Copyright (c) 2002-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 query. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "AknSystemListPopup.h" |
|
19 #include <AknNotifyStd.h> |
|
20 |
|
21 #include <avkon.rsg> |
|
22 #include <eikbtgpc.h> |
|
23 #include <eikenv.h> |
|
24 #include <avkon.hrh> |
|
25 #include <bautils.h> |
|
26 #include "AknListQueryNotificationDialog.h" |
|
27 #include <aknnotpi.rsg> |
|
28 #include <AknGlobalListQuery.h> |
|
29 #include <s32mem.h> |
|
30 #include <uikon/eiksrvui.h> |
|
31 #include <AknNotifySignature.h> |
|
32 |
|
33 #include <AknMediatorFacade.h> |
|
34 #include <aknSDData.h> |
|
35 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h> |
|
36 |
|
37 #include "AknAppsKeyCleanup.inl" |
|
38 |
|
39 const TInt KListQueryItemLength = 64; |
|
40 const TInt KCharsInTInt = 4; // TInt32 takes 4 chars. |
|
41 const TInt KArrayGranularity = 3; |
|
42 |
|
43 CAknGlobalListQuerySubject* CAknGlobalListQuerySubject::NewL() |
|
44 { |
|
45 CAknGlobalListQuerySubject* self = new (ELeave) CAknGlobalListQuerySubject(); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CAknGlobalListQuerySubject::CAknGlobalListQuerySubject() |
|
53 : iPending(EFalse) |
|
54 { |
|
55 iStoredEikonEnv = CEikonEnv::Static(); |
|
56 } |
|
57 |
|
58 void CAknGlobalListQuerySubject::ConstructL() |
|
59 { |
|
60 } |
|
61 |
|
62 CAknGlobalListQuerySubject::~CAknGlobalListQuerySubject() |
|
63 { |
|
64 //delete iDlg; |
|
65 Cancel(); |
|
66 |
|
67 // Complete the RMessage if we need to. |
|
68 if (iPending) |
|
69 { |
|
70 iMessage.Complete(KErrDied); |
|
71 } |
|
72 |
|
73 delete iArray; |
|
74 delete iHeading; |
|
75 } |
|
76 |
|
77 void CAknGlobalListQuerySubject::Release() |
|
78 { |
|
79 delete this; |
|
80 } |
|
81 |
|
82 CAknGlobalListQuerySubject::TNotifierInfo CAknGlobalListQuerySubject::RegisterL() |
|
83 { |
|
84 iInfo.iUid = KAknGlobalListQueryUid; |
|
85 iInfo.iChannel = EAknNotifierChannelList; |
|
86 iInfo.iPriority = ENotifierPriorityHigh; |
|
87 return iInfo; |
|
88 } |
|
89 |
|
90 CAknGlobalListQuerySubject::TNotifierInfo CAknGlobalListQuerySubject::Info() const |
|
91 { |
|
92 return iInfo; |
|
93 } |
|
94 |
|
95 TPtrC8 CAknGlobalListQuerySubject::StartL(const TDesC8& /*aBuffer*/) |
|
96 { |
|
97 return KNullDesC8(); |
|
98 } |
|
99 |
|
100 void CAknGlobalListQuerySubject::StartL(const TDesC8& aBuffer, TInt /*aReplySlot*/, |
|
101 const RMessagePtr2& aMessage) |
|
102 { |
|
103 if (iPending) |
|
104 { |
|
105 aMessage.Complete(KErrInUse); |
|
106 return; |
|
107 } |
|
108 |
|
109 RDesReadStream readStream(aBuffer); |
|
110 if (aBuffer.Length() < KCharsInTInt || readStream.ReadInt32L() != KAKNNOTIFIERSIGNATURE) |
|
111 { |
|
112 User::Leave(KErrArgument); |
|
113 } |
|
114 |
|
115 iMessage = aMessage; |
|
116 iSelectFirst = readStream.ReadInt16L(); |
|
117 TInt count = readStream.ReadInt16L(); |
|
118 |
|
119 // Create array |
|
120 delete iArray; |
|
121 iArray = 0; |
|
122 iArray = new (ELeave) CDesCArrayFlat(KArrayGranularity); |
|
123 |
|
124 TBuf<KListQueryItemLength> arrayItem; |
|
125 |
|
126 for (TInt ii = 0; ii < count; ii++) |
|
127 { |
|
128 readStream >> arrayItem; |
|
129 iArray->AppendL(arrayItem); |
|
130 } |
|
131 |
|
132 TInt headingLength = readStream.ReadInt16L(); |
|
133 delete iHeading; |
|
134 iHeading = 0; |
|
135 |
|
136 if (headingLength != KErrNotFound) |
|
137 { |
|
138 iHeading = HBufC::NewL(headingLength); |
|
139 TPtr ptr = iHeading->Des(); |
|
140 readStream >> ptr; |
|
141 } |
|
142 |
|
143 CAknSDData* sddata = 0; |
|
144 if (readStream.ReadInt8L()) |
|
145 { |
|
146 sddata = new (ELeave) CAknSDData(); |
|
147 CleanupStack::PushL(sddata); |
|
148 readStream >> *sddata; |
|
149 } |
|
150 |
|
151 delete iDlg; |
|
152 iDlg = NULL; |
|
153 |
|
154 iDlg = new (ELeave) CAknListQueryNotificationDialog(&iListIndex, this, &iDlg); |
|
155 if (sddata) |
|
156 { |
|
157 CArrayFixFlat<TInt>* array = 0; |
|
158 CleanupStack::PushL(array); // even as null |
|
159 if (sddata->iAdditionalData && |
|
160 sddata->iAdditionalData->Length() > 2*sizeof(TInt32)) // command id and count |
|
161 { |
|
162 RDesReadStream strm(*sddata->iAdditionalData); |
|
163 CleanupClosePushL(strm); |
|
164 TInt count = strm.ReadInt32L(); // recycling... |
|
165 if (count == EAknListQueryItemsInfo) |
|
166 { |
|
167 count = strm.ReadInt32L(); |
|
168 array = new (ELeave) CArrayFixFlat<TInt>(1); |
|
169 for (TInt i = 0; i < count; i++) |
|
170 { |
|
171 array->AppendL(strm.ReadInt32L()); |
|
172 } |
|
173 } |
|
174 CleanupStack::PopAndDestroy(); |
|
175 |
|
176 // Tidy additional data so that there will not be two item arrays. |
|
177 TInt bytesToRemove = (count + 2) * 4; |
|
178 HBufC8* newDes = 0; |
|
179 if (bytesToRemove != sddata->iAdditionalData->Length()) |
|
180 { |
|
181 newDes = sddata->iAdditionalData->Mid(bytesToRemove).AllocL(); |
|
182 } |
|
183 delete sddata->iAdditionalData; |
|
184 sddata->iAdditionalData = newDes; |
|
185 } |
|
186 |
|
187 iDlg->PublishDialogL(sddata->iDialogIdx, sddata->iCategory, array); |
|
188 CleanupStack::Pop(); // Ownership transferred to dialog successfully. |
|
189 if (sddata->iAdditionalData) |
|
190 { |
|
191 CAknMediatorFacade* cover_info = AknMediatorFacade(iDlg); |
|
192 if (cover_info) |
|
193 { |
|
194 cover_info->BufStream() << *(sddata->iAdditionalData); |
|
195 cover_info->BufStream().CommitL(); |
|
196 } |
|
197 } |
|
198 CleanupStack::PopAndDestroy(sddata); |
|
199 } |
|
200 else |
|
201 { |
|
202 // If secondary display data hasn't been defined, then the unidentified |
|
203 // list query identifier is published to the secondary display. |
|
204 iDlg->PublishDialogL(EAknUnidentifiedListQuery, KAknSecondaryDisplayCategory); |
|
205 } |
|
206 |
|
207 if (!iAppsKeySuppressed) |
|
208 { |
|
209 ((CAknNotifierAppServerAppUi*)(iStoredEikonEnv->EikAppUi()))->SuppressAppSwitching(ETrue); |
|
210 } |
|
211 CleanupStack::PushL(TCleanupItem(ReleaseAppsKey, 0)); |
|
212 |
|
213 if (!iHeading) |
|
214 { |
|
215 iDlg->PrepareLC(R_GLOBAL_LIST_QUERY); |
|
216 } |
|
217 else |
|
218 { |
|
219 iDlg->PrepareLC(R_GLOBAL_LIST_QUERY_WITH_HEADING); |
|
220 iDlg->QueryHeading()->SetTextL(iHeading->Des()); |
|
221 } |
|
222 |
|
223 iDlg->SetOwnershipType(ELbmOwnsItemArray); |
|
224 iDlg->SetItemTextArray(iArray); |
|
225 TInt itemCount = iArray->Count(); |
|
226 iArray = 0; |
|
227 |
|
228 // If the list is not empty, the selection index must point to an existing item. |
|
229 // Otherwise a panic will occur. |
|
230 if (itemCount && (iSelectFirst < 0 || iSelectFirst > itemCount - 1)) |
|
231 { |
|
232 User::Leave(KErrArgument); |
|
233 } |
|
234 |
|
235 CEikListBox* listBox = iDlg->ListBox(); |
|
236 if (itemCount) |
|
237 { |
|
238 listBox->SetCurrentItemIndex(iSelectFirst); |
|
239 } |
|
240 listBox->UpdateScrollBarsL(); |
|
241 |
|
242 iDlg->RunLD(); |
|
243 |
|
244 CleanupStack::Pop(); // Apps key cleanup. |
|
245 iAppsKeySuppressed = ETrue; |
|
246 iPending = ETrue; |
|
247 } |
|
248 |
|
249 void CAknGlobalListQuerySubject::Cancel() |
|
250 { |
|
251 delete iDlg; |
|
252 iDlg = NULL; |
|
253 TRAP_IGNORE(QueryDismissedL(EAknSoftkeyCancel)); |
|
254 } |
|
255 |
|
256 TPtrC8 CAknGlobalListQuerySubject::UpdateL(const TDesC8& aBuffer) |
|
257 { |
|
258 if (!iDlg) |
|
259 { |
|
260 return KNullDesC8(); |
|
261 } |
|
262 |
|
263 // Get parameters. |
|
264 SAknNotifierPackage<SAknGlobalListQueryParams>* params |
|
265 = (SAknNotifierPackage<SAknGlobalListQueryParams>*)aBuffer.Ptr(); |
|
266 |
|
267 if (aBuffer.Length() < 0 |
|
268 || (TUint)aBuffer.Length() < sizeof(SAknNotifierPackage<SAknGlobalListQueryParams>) |
|
269 || params->iSignature != KAKNNOTIFIERSIGNATURE) |
|
270 { |
|
271 User::Leave(KErrArgument); |
|
272 } |
|
273 |
|
274 TInt cmd = params->iParamData.iCmd; |
|
275 TKeyEvent keyEvent; |
|
276 keyEvent.iRepeats = 0; |
|
277 TEventCode eventType = EEventKey; |
|
278 switch (cmd) |
|
279 { |
|
280 case EAknCancelGlobalQuery: |
|
281 delete iDlg; |
|
282 iDlg = NULL; |
|
283 QueryDismissedL(EAknSoftkeyCancel); |
|
284 return KNullDesC8(); |
|
285 case EAknMoveDownGlobalListQuery: |
|
286 keyEvent.iCode = EKeyDownArrow; |
|
287 break; |
|
288 case EAknMoveUpGlobalListQuery: |
|
289 keyEvent.iCode = EKeyUpArrow; |
|
290 break; |
|
291 case EAknSelectGlobalListQuery: |
|
292 keyEvent.iCode = EKeyOK; |
|
293 break; |
|
294 default: |
|
295 return KNullDesC8(); |
|
296 } |
|
297 iDlg->OfferKeyEventL(keyEvent, eventType); |
|
298 |
|
299 return KNullDesC8(); |
|
300 } |
|
301 |
|
302 void CAknGlobalListQuerySubject::QueryDismissedL(TInt aResult) |
|
303 { |
|
304 if (iPending) |
|
305 { |
|
306 iMessage.Complete(aResult); |
|
307 } |
|
308 |
|
309 iPending = EFalse; |
|
310 iReturnVal = NULL; |
|
311 |
|
312 if (iAppsKeySuppressed) |
|
313 { |
|
314 ((CAknNotifierAppServerAppUi*)(iStoredEikonEnv->EikAppUi()))->SuppressAppSwitching(EFalse); |
|
315 } |
|
316 iAppsKeySuppressed = EFalse; |
|
317 } |
|
318 |
|
319 // End of file |