|
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: Multiselection popup implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <avkon.mbg> |
|
21 #include <aknlists.h> |
|
22 |
|
23 #include "cmmediaserverfull.h" |
|
24 #include "msmultiselectionpopup.h" |
|
25 #include "msconstants.h" |
|
26 #include "msdebug.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KSoftkeyOk = 63585; |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CMSMultiselectionPopup::NewL |
|
33 // Two-phased constructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CMSMultiselectionPopup* CMSMultiselectionPopup::NewL( |
|
37 TBool aUploadCapabilitySupport, |
|
38 RPointerArray<CCmMediaServerFull>* aMediaServerArray, |
|
39 CListBoxView::CSelectionIndexArray* aSelectionIndexArray ) |
|
40 { |
|
41 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::NewL begin")); |
|
42 |
|
43 CMSMultiselectionPopup* self = CMSMultiselectionPopup::NewLC( |
|
44 aUploadCapabilitySupport, |
|
45 aMediaServerArray, |
|
46 aSelectionIndexArray ); |
|
47 |
|
48 CleanupStack::Pop( self ); |
|
49 |
|
50 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::NewL end")); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CMSMultiselectionPopup::NewLC |
|
56 // Two-phased constructor. |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 CMSMultiselectionPopup* CMSMultiselectionPopup::NewLC( |
|
60 TBool aUploadCapabilitySupport, |
|
61 RPointerArray<CCmMediaServerFull>* aMediaServerArray, |
|
62 CListBoxView::CSelectionIndexArray* aSelectionIndexArray ) |
|
63 { |
|
64 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::NewLC begin")); |
|
65 |
|
66 CMSMultiselectionPopup* self = |
|
67 new(ELeave) CMSMultiselectionPopup( aUploadCapabilitySupport, |
|
68 aMediaServerArray, |
|
69 aSelectionIndexArray ); |
|
70 |
|
71 CleanupStack::PushL(self); |
|
72 self->ConstructL(); |
|
73 |
|
74 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::NewLC end")); |
|
75 return self; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CMSMultiselectionPopup::ConstructL |
|
80 // Symbian 2nd phase constructor can leave. |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CMSMultiselectionPopup::ConstructL() |
|
84 { |
|
85 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::ConstructL begin")); |
|
86 |
|
87 for (TInt i=0;i<iServers->Count();i++) |
|
88 { |
|
89 if ( iUploadCapabilitySupport && (*iServers)[i]->StoreUsage() ) |
|
90 { |
|
91 iPreviousSelection->AppendL(i); |
|
92 } |
|
93 else if (!iUploadCapabilitySupport && (*iServers)[i]->FillUsage() ) |
|
94 { |
|
95 iPreviousSelection->AppendL(i); |
|
96 } |
|
97 else |
|
98 { |
|
99 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::ConstructL \ |
|
100 server not used")); |
|
101 } |
|
102 } |
|
103 |
|
104 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::ConstructL end")); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CMSMultiselectionPopup::CMSMultiselectionPopup |
|
109 // C++ default constructor can NOT contain any code, that |
|
110 // might leave. |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CMSMultiselectionPopup::CMSMultiselectionPopup( |
|
114 TBool aUploadCapabilitySupport, |
|
115 RPointerArray<CCmMediaServerFull>* aMediaServerArray, |
|
116 CListBoxView::CSelectionIndexArray* aSelectionIndexArray ) |
|
117 : CAknListQueryDialog( aSelectionIndexArray ), |
|
118 iUploadCapabilitySupport ( aUploadCapabilitySupport ), |
|
119 iServers( aMediaServerArray ), |
|
120 iPreviousSelection( aSelectionIndexArray ) |
|
121 { |
|
122 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
123 CMSMultiselectionPopup")); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMSMultiselectionPopup::~CMSMultiselectionPopup |
|
128 // C++ default destructor. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 CMSMultiselectionPopup::~CMSMultiselectionPopup() |
|
132 { |
|
133 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
134 ~CMSMultiselectionPopup")); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CMSMultiselectionPopup::UpdateAndDrawPopupL |
|
139 // |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CMSMultiselectionPopup::UpdateAndDrawPopupL( |
|
143 CCmMediaServerFull* aMediaServer ) |
|
144 { |
|
145 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
146 UpdateAndDrawPopupL begin")); |
|
147 |
|
148 // Listbox items |
|
149 CDesCArray* device_array = static_cast<CDesCArray*> |
|
150 (ListControl()->listbox()->Model()->ItemTextArray()); |
|
151 |
|
152 HBufC* item = CreateListBoxItemLC( aMediaServer ); |
|
153 device_array->AppendL( *item ); |
|
154 CleanupStack::PopAndDestroy( item ); |
|
155 |
|
156 iListBox->HandleItemAdditionL(); // Update listbox |
|
157 |
|
158 Layout(); |
|
159 SizeChanged(); |
|
160 DrawNow(); |
|
161 |
|
162 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
163 UpdateAndDrawPopupL ends")); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CMSMultiselectionPopup::HandlePointerEventL |
|
168 // |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CMSMultiselectionPopup::HandlePointerEventL |
|
172 ( const TPointerEvent& aPointerEvent ) |
|
173 { |
|
174 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
175 |
|
176 if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
177 { |
|
178 TKeyEvent keyEvent; |
|
179 keyEvent.iCode = EKeyOK; |
|
180 this->OfferKeyEventL( keyEvent, EEventKey ); |
|
181 } |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------------------------- |
|
185 // CMSMultiselectionPopup::AppendIconToArrayL |
|
186 // |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void CMSMultiselectionPopup::AppendIconToArrayL( CAknIconArray* aArray, |
|
190 MAknsSkinInstance* aSkin, |
|
191 const TDesC& aMbmFile, |
|
192 const TAknsItemID& aID, |
|
193 TInt aBitmapId, |
|
194 TInt aMaskId ) const |
|
195 { |
|
196 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
197 AppendIconToArrayL begin")); |
|
198 |
|
199 __ASSERT_DEBUG( aArray, User::Leave(KErrArgument) ); |
|
200 |
|
201 CFbsBitmap* bitmap = NULL; |
|
202 CFbsBitmap* mask = NULL; |
|
203 |
|
204 AknsUtils::CreateIconLC(aSkin, aID, |
|
205 bitmap, mask, aMbmFile, aBitmapId, aMaskId); |
|
206 |
|
207 CGulIcon* icon = CGulIcon::NewL(bitmap, mask); |
|
208 icon->SetBitmapsOwnedExternally(EFalse); |
|
209 |
|
210 // icon now owns the bitmaps, no need to keep on cleanup stack. |
|
211 CleanupStack::Pop(2); // mask, bitmap |
|
212 bitmap = NULL; |
|
213 mask = NULL; |
|
214 |
|
215 CleanupStack::PushL(icon); |
|
216 |
|
217 // ownership transferred |
|
218 aArray->AppendL(icon); |
|
219 |
|
220 // aArray now owns the icon, no need to delete. |
|
221 CleanupStack::Pop(icon); |
|
222 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
223 AppendIconToArrayL end")); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CMSMultiselectionPopup::OkToExitL(TInt aButtonId) |
|
228 // called by framework when the softkey is pressed |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 TBool CMSMultiselectionPopup::OkToExitL( TInt /*aButtonId*/ ) |
|
232 { |
|
233 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::OkToExitL")); |
|
234 return ETrue; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CMSMultiselectionPopup::AppendMediaServersL |
|
239 // Appends items to the listbox |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 void CMSMultiselectionPopup::AppendMediaServersL() |
|
243 { |
|
244 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
245 AppendMediaServersL begin")); |
|
246 |
|
247 TInt serverCount = iServers->Count(); |
|
248 |
|
249 CDesCArray* listBoxArray = static_cast<CDesCArray*> |
|
250 (ListControl()->listbox()->Model()->ItemTextArray()); |
|
251 |
|
252 for ( TInt i = 0; i < serverCount; i++ ) |
|
253 { |
|
254 CCmMediaServerFull* server = (*iServers)[i]; |
|
255 |
|
256 HBufC* item = CreateListBoxItemLC( server ); |
|
257 |
|
258 listBoxArray->AppendL( *item ); |
|
259 |
|
260 CleanupStack::PopAndDestroy( item ); |
|
261 } |
|
262 |
|
263 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
264 AppendMediaServersL end")); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // CMSMultiselectionPopup::PreLayoutDynInitL() |
|
269 // called by framework before dialog is shown |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 void CMSMultiselectionPopup::PreLayoutDynInitL() |
|
273 { |
|
274 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
275 PreLayoutDynInitL begin")); |
|
276 |
|
277 CAknListQueryDialog::PreLayoutDynInitL(); |
|
278 |
|
279 CAknIconArray* icons = new (ELeave) CAknIconArray( EIconLast ); |
|
280 CleanupStack::PushL( icons ); |
|
281 |
|
282 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
283 TFileName iconsPath( AknIconUtils::AvkonIconFileName() ); |
|
284 |
|
285 AppendIconToArrayL( icons, skin, |
|
286 iconsPath, |
|
287 KAknsIIDQgnPropCheckboxOn, |
|
288 EMbmAvkonQgn_indi_checkbox_on, |
|
289 EMbmAvkonQgn_indi_checkbox_on_mask ); |
|
290 |
|
291 AppendIconToArrayL( icons, skin, |
|
292 iconsPath, |
|
293 KAknsIIDQgnPropCheckboxOff, |
|
294 EMbmAvkonQgn_indi_checkbox_off, |
|
295 EMbmAvkonQgn_indi_checkbox_off_mask ); |
|
296 |
|
297 AppendIconToArrayL( icons, skin, |
|
298 iconsPath, |
|
299 KAknsIIDQgnIndiNaviArrowRight, |
|
300 EMbmAvkonQgn_indi_navi_arrow_right, |
|
301 EMbmAvkonQgn_indi_navi_arrow_right_mask ); |
|
302 |
|
303 CAknListQueryDialog::SetIconArrayL( icons ); |
|
304 |
|
305 CleanupStack::Pop( icons ); |
|
306 |
|
307 iListBox = ListBox(); |
|
308 SetOwnershipType( ELbmOwnsItemArray ); |
|
309 |
|
310 AppendMediaServersL(); |
|
311 |
|
312 iListBox->ActivateL(); |
|
313 |
|
314 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
315 PreLayoutDynInitL end")); |
|
316 } |
|
317 |
|
318 // --------------------------------------------------------------------------- |
|
319 // CMSMultiselectionPopup::PostLayoutDynInitL() |
|
320 // Called by framework before dialog is shown. |
|
321 // Needed because filter is not active until PreLayoutDynInitL(). |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 void CMSMultiselectionPopup::PostLayoutDynInitL() |
|
325 { |
|
326 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
327 PostLayoutDynInitL begin")); |
|
328 |
|
329 CAknListQueryDialog::PostLayoutDynInitL(); |
|
330 ListBox()->ActivateL(); |
|
331 |
|
332 if ( iPreviousSelection && iPreviousSelection->Count() ) |
|
333 { |
|
334 iListBox->SetSelectionIndexesL( iPreviousSelection ); |
|
335 } |
|
336 |
|
337 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
338 PostLayoutDynInitL end")); |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // CMSMultiselectionPopup::OfferKeyEventL() |
|
343 // called by framework when key is pressed |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 TKeyResponse CMSMultiselectionPopup::OfferKeyEventL ( |
|
347 const TKeyEvent &aKeyEvent, |
|
348 TEventCode aType ) |
|
349 { |
|
350 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::OfferKeyEventL begin")); |
|
351 |
|
352 TKeyResponse status( EKeyWasNotConsumed ); |
|
353 |
|
354 // check if user has selected something |
|
355 if (aKeyEvent.iCode == EKeyOK) |
|
356 { |
|
357 status = ListBox()->OfferKeyEventL( aKeyEvent, aType ); |
|
358 |
|
359 TInt itemNbr = iListBox->CurrentItemIndex(); |
|
360 if( iListBox->View()->ItemIsSelected( itemNbr ) ) |
|
361 { |
|
362 iPreviousSelection->AppendL( itemNbr ); |
|
363 } |
|
364 else |
|
365 { |
|
366 TKeyArrayFix sortKey( 0, ECmpTInt ); |
|
367 TInt itemIndex( 0 ); |
|
368 |
|
369 if( iPreviousSelection->Find( |
|
370 itemNbr, sortKey, itemIndex ) == 0 ) |
|
371 { |
|
372 // remove selection |
|
373 iPreviousSelection->Delete( itemIndex ); |
|
374 } |
|
375 } |
|
376 } |
|
377 else |
|
378 { |
|
379 // prevents to mark item if dialog is accepted with OK key |
|
380 if ( aKeyEvent.iCode == KSoftkeyOk ) |
|
381 { |
|
382 iListBox->View()->SetDisableRedraw(ETrue); |
|
383 } |
|
384 |
|
385 status = CAknListQueryDialog::OfferKeyEventL(aKeyEvent,aType); |
|
386 } |
|
387 |
|
388 LOG(_L("[MediaServant]\t CMSMultiselectionPopup::OfferKeyEventL end")); |
|
389 return status; |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // CMSMultiselectionPopup::CreateListBoxItemLC() |
|
394 // Creates listbox item |
|
395 // --------------------------------------------------------------------------- |
|
396 // |
|
397 HBufC* CMSMultiselectionPopup::CreateListBoxItemLC( |
|
398 const CCmMediaServerFull* aServer ) |
|
399 { |
|
400 LOG(_L("[MediaServant]\t CMSMultiselectionPopup:: \ |
|
401 CreateListBoxItemLC")); |
|
402 |
|
403 TBuf<KMaxFileName> serverName; |
|
404 serverName.Copy( aServer->MediaServerName().Left( KMaxFileName ) ); |
|
405 |
|
406 HBufC* item = HBufC::NewLC( serverName.Size() + |
|
407 sizeof( KSingleGraphicStyleFormatStringNoTrailIcons() ) ); |
|
408 item->Des().Format( KSingleGraphicStyleFormatStringNoTrailIcons, |
|
409 EUnCheckedBox, |
|
410 &serverName ); |
|
411 |
|
412 return item; |
|
413 } |
|
414 |
|
415 // End of file |