|
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 dialog implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include <StringLoader.h> |
|
25 #include <avkon.mbg> |
|
26 #include <eikclbd.h> |
|
27 #include <aknlists.h> |
|
28 #include <AknsUtils.h> |
|
29 #include <eikcmbut.h> |
|
30 #include "upnpappmultiselectiondialog.h" |
|
31 #include "upnpfilesharingengine.h" |
|
32 |
|
33 #include "cupnpmultiselectionui.hrh" |
|
34 #include <cupnpmultiselectionui.rsg> |
|
35 |
|
36 _LIT( KComponentLogfile, "multiselectionui.txt"); |
|
37 #include "upnplog.h" |
|
38 |
|
39 |
|
40 //CONSTANTS |
|
41 const TInt KOkSoftkeyCode = 63585; |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // -------------------------------------------------------------------------- |
|
46 // CUPnPAppMultiselectionDialog::NewL |
|
47 // Two-phased constructor. |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 CUPnPAppMultiselectionDialog* CUPnPAppMultiselectionDialog::NewL( |
|
51 THomeConnectMediaType aMediaType, |
|
52 CUPnPFileSharingEngine* aFileSharingEngine, |
|
53 CArrayFix<TInt>* aSelectionIndexArray ) |
|
54 { |
|
55 __LOG("CUPnPAppMultiselectionDialog::NewL begin"); |
|
56 |
|
57 CUPnPAppMultiselectionDialog* self = |
|
58 new(ELeave) CUPnPAppMultiselectionDialog(); |
|
59 |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL( aMediaType, aFileSharingEngine, aSelectionIndexArray ); |
|
62 CleanupStack::Pop(self); |
|
63 __LOG("CUPnPAppMultiselectionDialog::NewL end"); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CUPnPAppMultiselectionDialog::ConstructL |
|
70 // Symbian 2nd phase constructor can leave. |
|
71 // -------------------------------------------------------------------------- |
|
72 // |
|
73 void CUPnPAppMultiselectionDialog::ConstructL( |
|
74 THomeConnectMediaType aMediaType, |
|
75 CUPnPFileSharingEngine* aFileSharingEngine, |
|
76 CArrayFix<TInt>* aSelectionIndexArray ) |
|
77 { |
|
78 __LOG("CUPnPAppMultiselectionDialog::ConstructL begin"); |
|
79 CAknSelectionListDialog::ConstructL( R_AVKON_SOFTKEYS_EMPTY ); |
|
80 iMediaType = aMediaType; |
|
81 iFileSharingEngine = aFileSharingEngine; |
|
82 |
|
83 iMarkedItems = aSelectionIndexArray; |
|
84 iUtility = new (ELeave) CUpnpMultiselectionUtility(); |
|
85 |
|
86 iMskSelectText = |
|
87 StringLoader::LoadL( R_UPNP_MULTISELECTION_SELECT_TEXT ); |
|
88 iMskUnselectText = |
|
89 StringLoader::LoadL( R_UPNP_MULTISELECTION_UNSELECT_TEXT ); |
|
90 |
|
91 __LOG("CUPnPAppMultiselectionDialog::ConstructL end"); |
|
92 } |
|
93 |
|
94 |
|
95 // -------------------------------------------------------------------------- |
|
96 // CUPnPAppMultiselectionDialog::CUPnPAppMultiselectionDialog |
|
97 // C++ default constructor can NOT contain any code, that |
|
98 // might leave. |
|
99 // -------------------------------------------------------------------------- |
|
100 // |
|
101 CUPnPAppMultiselectionDialog::CUPnPAppMultiselectionDialog() |
|
102 : CAknSelectionListDialog(iSelectedItem, NULL, NULL), iSelectedItem(0) |
|
103 { |
|
104 __LOG("CUPnPAppMultiselectionDialog::CUPnPAppMultiselectionDialog"); |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CUPnPAppMultiselectionDialog::CUPnPAppMultiselectionDialog |
|
109 // C++ default destructor. |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 CUPnPAppMultiselectionDialog::~CUPnPAppMultiselectionDialog() |
|
113 { |
|
114 __LOG("CUPnPAppMultiselectionDialog::~CUPnPAppMultiselectionDialog"); |
|
115 |
|
116 iFileSharingEngine = NULL; |
|
117 |
|
118 delete iUtility; |
|
119 delete iMskSelectText; |
|
120 delete iMskUnselectText; |
|
121 |
|
122 __LOG("CUPnPAppMultiselectionDialog::~CUPnPAppMultiselectionDialog end"); |
|
123 } |
|
124 |
|
125 |
|
126 // -------------------------------------------------------------------------- |
|
127 // CUPnPAppMultiselectionDialog::OkToExitL(TInt aButtonId) |
|
128 // called by framework when the softkey is pressed |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 TBool CUPnPAppMultiselectionDialog::OkToExitL(TInt aButtonId) |
|
132 { |
|
133 __LOG("CUPnPAppMultiselectionDialog::OkToExitL begin"); |
|
134 TBool ret( EFalse ); |
|
135 if ( aButtonId == EAknSoftkeyOk ) |
|
136 { |
|
137 TBool showWaitNote( ETrue ); |
|
138 |
|
139 const CArrayFix<TInt>* selected; |
|
140 |
|
141 //get the true indexes of marked items |
|
142 CAknListBoxFilterItems* filter |
|
143 = static_cast < CAknFilteredTextListBoxModel* > |
|
144 ( iListBox->Model() )->Filter(); |
|
145 if ( filter ) |
|
146 { |
|
147 // Filter knows all. |
|
148 filter->UpdateSelectionIndexesL(); |
|
149 selected = filter->SelectionIndexes(); |
|
150 } |
|
151 else |
|
152 { |
|
153 // No filter. |
|
154 selected = ListBox()->View()->SelectionIndexes(); |
|
155 } |
|
156 |
|
157 // Show wait note if needed. |
|
158 CAknWaitNoteWrapper* waitNoteWrapper( NULL ); |
|
159 if ( selected->Count() == 1 && selected->At( 0 ) == 0 ) |
|
160 { |
|
161 showWaitNote = EFalse; |
|
162 } |
|
163 if ( showWaitNote ) |
|
164 { |
|
165 waitNoteWrapper = CAknWaitNoteWrapper::NewL(); |
|
166 CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper)); |
|
167 waitNoteWrapper->ExecuteL( |
|
168 R_UPNP_MULTISELECTION_COLLECTING_FILES_NOTE, // TInt aResId, |
|
169 *this, // MAknBackgroundProcess& aBackgroundProcess |
|
170 ETrue); |
|
171 } |
|
172 |
|
173 // give the selection indexes to filesharing engine |
|
174 iMarkedItems->Reset(); |
|
175 for( TInt i(0); i<selected->Count(); i++ ) |
|
176 { |
|
177 iMarkedItems->AppendL( selected->At( i ) ); |
|
178 } |
|
179 iUtility->ConvertSelectionsForEngineL( *iMarkedItems ); |
|
180 |
|
181 if ( showWaitNote ) |
|
182 { |
|
183 CleanupStack::PopAndDestroy(waitNoteWrapper); |
|
184 } |
|
185 ret = ETrue; |
|
186 } |
|
187 |
|
188 else if ( aButtonId == EAknSoftkeySelect ) |
|
189 { |
|
190 // msk event |
|
191 __LOG("CUPnPAppMultiselectionDialog::msk event"); |
|
192 TKeyEvent tmpEvent; |
|
193 tmpEvent.iCode = EKeyOK; |
|
194 tmpEvent.iModifiers = 0; |
|
195 tmpEvent.iRepeats = 0; |
|
196 tmpEvent.iScanCode = 0; |
|
197 TEventCode eventType = EEventKey; |
|
198 OfferKeyEventL( tmpEvent, eventType ); |
|
199 |
|
200 } |
|
201 else if ( aButtonId == EAknSoftkeyBack ) |
|
202 { |
|
203 ret = ETrue; |
|
204 } |
|
205 |
|
206 __LOG("CUPnPAppMultiselectionDialog::OkToExitL end"); |
|
207 return ret; |
|
208 } |
|
209 |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CUPnPAppMultiselectionDialog::PreLayoutDynInitL(); |
|
213 // called by framework before dialog is shown |
|
214 // -------------------------------------------------------------------------- |
|
215 // |
|
216 void CUPnPAppMultiselectionDialog::PreLayoutDynInitL() |
|
217 { |
|
218 __LOG("CUPnPAppMultiselectionDialog::PreLayoutDynInitL begin"); |
|
219 |
|
220 iListBox = static_cast<CAknSingleGraphicStyleListBox*> |
|
221 (Control(EMultiSelectionListBoxId)); |
|
222 |
|
223 // display find box |
|
224 SetupFind( CAknSelectionListDialog::EAdaptiveFind ); |
|
225 |
|
226 // get pointer to listbox data array |
|
227 iModel = STATIC_CAST( |
|
228 CAknFilteredTextListBoxModel*, iListBox->Model() ); |
|
229 iSettingsTextArray = static_cast<CDesCArray*>( |
|
230 iModel->ItemTextArray() ); |
|
231 |
|
232 iUtility->AppendShareAllSelectionL( iSettingsTextArray ); |
|
233 |
|
234 |
|
235 iFileSharingEngine->RequestSelectionContentL( iMediaType ); |
|
236 iState = ELoadContent; |
|
237 |
|
238 CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL(); |
|
239 CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper)); |
|
240 waitNoteWrapper->ExecuteL( |
|
241 R_UPNP_MULTISELECTION_SEARCHING_FILES_NOTE, // TInt aResId, |
|
242 *this, // MAknBackgroundProcess& aBackgroundProcess |
|
243 EFalse); // ETrue = Show immediately |
|
244 |
|
245 CleanupStack::PopAndDestroy(waitNoteWrapper); |
|
246 |
|
247 CAknIconArray* icons = new (ELeave) CAknIconArray(2); |
|
248 CleanupStack::PushL( icons ); |
|
249 |
|
250 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
251 TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) ); |
|
252 |
|
253 iUtility->AppendIconToArrayL( icons, skin, |
|
254 iconsPath, |
|
255 KAknsIIDQgnPropCheckboxOn, |
|
256 EMbmAvkonQgn_prop_checkbox_on, |
|
257 EMbmAvkonQgn_prop_checkbox_on_mask ); |
|
258 |
|
259 iUtility->AppendIconToArrayL( icons, skin, |
|
260 iconsPath, |
|
261 KAknsIIDQgnPropCheckboxOff, |
|
262 EMbmAvkonQgn_prop_checkbox_off, |
|
263 EMbmAvkonQgn_prop_checkbox_off_mask ); |
|
264 |
|
265 |
|
266 iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons ); |
|
267 CleanupStack::Pop( icons ); |
|
268 |
|
269 iListBox->ActivateL(); |
|
270 |
|
271 |
|
272 // set dialog title |
|
273 CEikStatusPane* statusPane = |
|
274 (( CAknAppUi* )iEikonEnv->EikAppUi() )->StatusPane(); |
|
275 iTitlePane = (CAknTitlePane*)statusPane->ControlL( |
|
276 TUid::Uid(EEikStatusPaneUidTitle)); |
|
277 |
|
278 if ( iMediaType == EImageAndVideo ) |
|
279 { |
|
280 iTitlePane->SetTextL( *StringLoader::LoadLC( |
|
281 R_UPNP_MULTISELECTION_SHARING_VISUAL_TITLE_TEXT) ); |
|
282 } |
|
283 else |
|
284 { |
|
285 iTitlePane->SetTextL( *StringLoader::LoadLC( |
|
286 R_UPNP_MULTISELECTION_SHARING_MUSIC_TITLE_TEXT) ); |
|
287 } |
|
288 CleanupStack::PopAndDestroy(); |
|
289 |
|
290 CAknSelectionListDialog::PreLayoutDynInitL(); |
|
291 __LOG("CUPnPAppMultiselectionDialog::PreLayoutDynInitL end"); |
|
292 } |
|
293 |
|
294 |
|
295 // -------------------------------------------------------------------------- |
|
296 // CUPnPAppMultiselectionDialog::PostLayoutDynInitL() |
|
297 // Called by framework before dialog is shown. |
|
298 // Needed because filter is not active until PreLayoutDynInitL(). |
|
299 // -------------------------------------------------------------------------- |
|
300 // |
|
301 void CUPnPAppMultiselectionDialog::PostLayoutDynInitL() |
|
302 { |
|
303 __LOG("CUPnPAppMultiselectionDialog::PostLayoutDynInitL begin"); |
|
304 |
|
305 // Get state of do not share and share all selections and set them |
|
306 // to utility. |
|
307 TShareSelectionState selectionState = |
|
308 iUtility->ShareSelectionStateFromArray( *iMarkedItems ); |
|
309 iUtility->SetShareSelectionState( selectionState ); |
|
310 |
|
311 // filter out the first character of the search string |
|
312 FindBox()->SetListColumnFilterFlags(0xFFFFFFFE); |
|
313 |
|
314 //mark selected albums |
|
315 if ( iMarkedItems ) |
|
316 { |
|
317 if ( iMarkedItems->Count() ) |
|
318 { |
|
319 // |
|
320 iListBox->SetSelectionIndexesL( iMarkedItems ); |
|
321 } |
|
322 } |
|
323 iUtility->CollectSelectedItemsL( iListBox, ETrue ); |
|
324 |
|
325 //set msk's label depending on is item selected or not |
|
326 HBufC* mskLabel( iMskSelectText ); |
|
327 if( iListBox->View()->ItemIsSelected( iListBox->CurrentItemIndex() ) ) |
|
328 { |
|
329 mskLabel = iMskUnselectText; |
|
330 } |
|
331 ButtonGroupContainer().SetCommandL( EAknSoftkeySelect, *mskLabel ); |
|
332 |
|
333 __LOG("CUPnPAppMultiselectionDialog::PostLayoutDynInitL end"); |
|
334 } |
|
335 |
|
336 |
|
337 // -------------------------------------------------------------------------- |
|
338 // CUPnPAppMultiselectionDialog::OfferKeyEventL(); |
|
339 // called by framework when key is pressed |
|
340 // -------------------------------------------------------------------------- |
|
341 // |
|
342 TKeyResponse CUPnPAppMultiselectionDialog::OfferKeyEventL( |
|
343 const TKeyEvent &aKeyEvent, |
|
344 TEventCode aType) |
|
345 { |
|
346 __LOG("CUPnPAppMultiselectionDialog::OfferKeyEventL begin"); |
|
347 |
|
348 TKeyResponse status( EKeyWasNotConsumed ); |
|
349 if ( aType == EEventKey ) // Is not key event |
|
350 { |
|
351 if (aKeyEvent.iCode == EKeyOK) |
|
352 { |
|
353 status = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
354 iUtility->CollectSelectedItemsL( iListBox ); |
|
355 } |
|
356 else if (aKeyEvent.iCode == KOkSoftkeyCode) |
|
357 { |
|
358 // disable draw |
|
359 iListBox->View()->SetDisableRedraw(ETrue); |
|
360 status = CAknSelectionListDialog::OfferKeyEventL(aKeyEvent,aType); |
|
361 } |
|
362 else |
|
363 { |
|
364 // Let the Akn dialog handle the key event. |
|
365 // EKeyEscape key event deletes this dialog. |
|
366 status = CAknSelectionListDialog::OfferKeyEventL(aKeyEvent,aType); |
|
367 } |
|
368 } |
|
369 |
|
370 // |
|
371 // Set msk's label depending on is item selected or not. |
|
372 // |
|
373 // In case of EKeyEscape we cannot access objects in heap any more. |
|
374 // Only local variables in stack. This is because CAknSelectionListDialog |
|
375 // ::OfferKeyEventL deletes this dialog. When call returns heap memory is cleared |
|
376 // and we cannot rely on values of member variables. |
|
377 // |
|
378 if ( status == EKeyWasConsumed && |
|
379 aKeyEvent.iCode != EKeyEscape ) |
|
380 { |
|
381 HBufC* mskLabel(iMskSelectText); |
|
382 if( iListBox->View()->ItemIsSelected( |
|
383 iListBox->CurrentItemIndex() ) ) |
|
384 { |
|
385 mskLabel = iMskUnselectText; |
|
386 } |
|
387 ButtonGroupContainer().SetCommandL( EAknSoftkeySelect, *mskLabel ); |
|
388 ButtonGroupContainer().DrawDeferred(); |
|
389 } |
|
390 |
|
391 __LOG("CUPnPAppMultiselectionDialog::OfferKeyEventL end"); |
|
392 return status; |
|
393 } |
|
394 |
|
395 |
|
396 // -------------------------------------------------------------------------- |
|
397 // CUPnPAppMultiselectionDialog::StepL |
|
398 // Step done during wait note |
|
399 // -------------------------------------------------------------------------- |
|
400 // |
|
401 void CUPnPAppMultiselectionDialog::StepL(void) |
|
402 { |
|
403 switch ( iState ) |
|
404 { |
|
405 case ELoadContent: |
|
406 { |
|
407 TRAPD( err, iFileSharingEngine->GetSelectionContentL( |
|
408 *iSettingsTextArray ) ); |
|
409 if ( err == KErrNone ) |
|
410 { |
|
411 iState = ELoadIndexes; |
|
412 iFileSharingEngine->RequestSelectionIndexesL( iMediaType ); |
|
413 } |
|
414 else if ( err == KErrInUse ) |
|
415 { |
|
416 //do nothing, request is being proceeded |
|
417 } |
|
418 else |
|
419 { |
|
420 User::Leave( err ); |
|
421 } |
|
422 break; |
|
423 } |
|
424 case ELoadIndexes: |
|
425 { |
|
426 TRAPD( err, iFileSharingEngine->GetSelectionIndexesL( |
|
427 *iMarkedItems ) ); |
|
428 if ( err == KErrNone ) |
|
429 { |
|
430 iState = ELoadDone; |
|
431 iDone = ETrue; |
|
432 } |
|
433 else if ( err == KErrInUse ) |
|
434 { |
|
435 //do nothing, request is being proceeded |
|
436 } |
|
437 else |
|
438 { |
|
439 User::Leave( err ); |
|
440 } |
|
441 break; |
|
442 } |
|
443 case ELoadDone: |
|
444 { |
|
445 break; |
|
446 } |
|
447 default: |
|
448 { |
|
449 __PANICD( __FILE__, __LINE__ ); |
|
450 break; |
|
451 } |
|
452 } |
|
453 } |
|
454 |
|
455 |
|
456 // -------------------------------------------------------------------------- |
|
457 // CUPnPAppMultiselectionDialog::IsProcessDone |
|
458 // Returns ETrue if process finished |
|
459 // -------------------------------------------------------------------------- |
|
460 // |
|
461 TBool CUPnPAppMultiselectionDialog::IsProcessDone(void) const |
|
462 { |
|
463 return iDone; |
|
464 } |
|
465 |
|
466 // End of file |