|
1 /* |
|
2 * Copyright (c) 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: Implementation of the CUpnpDownloadHandler class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // System |
|
21 #include <bautils.h> // BaflUtils |
|
22 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
23 |
|
24 // upnp stack api |
|
25 #include <upnpitem.h> // CUpnpItem |
|
26 #include <upnpcontainer.h> // CUpnpContainer |
|
27 #include <upnpstring.h> // UpnpString |
|
28 |
|
29 // upnpframework / avcontroller api |
|
30 #include "upnpavcontroller.h" // MUPnPAVController |
|
31 #include "upnpavcontrollerfactory.h" // UPnPAVControllerFactory |
|
32 #include "upnpavbrowsingsession.h" // MUPnPAVBrowsingSession |
|
33 #include "upnpfiledownloadsession.h" // MUPnPFileDownloadSession |
|
34 |
|
35 // upnpframework / avcontroller helper api |
|
36 #include "upnpconstantdefs.h" // upnp definitions |
|
37 |
|
38 // upnpframework / xml parser api |
|
39 #include "upnpxmlparser.h" // CUPnPXMLParser |
|
40 |
|
41 // upnpframework / internal api's |
|
42 #include "upnpcommonutils.h" // TUPnPItemType |
|
43 |
|
44 // filetransferengine internal |
|
45 #include "upnpdownloadhandler.h" |
|
46 #include "upnpnotehandler.h" |
|
47 #include "upnpplaylisthandler.h" // CUpnpPlaylistHandler |
|
48 |
|
49 _LIT( KComponentLogfile, "filetransferengine.txt"); |
|
50 #include "upnplog.h" |
|
51 |
|
52 // CONSTANTS |
|
53 const TInt KBrowseRequestCount = 1; |
|
54 const TInt KZero = 0; |
|
55 const TInt KProgressBaseValue = 100; |
|
56 |
|
57 |
|
58 // -------------------------------------------------------------------------- |
|
59 // CUpnpDownloadHandler::NewL |
|
60 // NewL. |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 CUpnpDownloadHandler* CUpnpDownloadHandler::NewL( |
|
64 MUPnPAVBrowsingSession* aBrowsingSession ) |
|
65 { |
|
66 __LOG( "[UpnpDownloadHandler] CUpnpDownloadHandler: NewL" ); |
|
67 |
|
68 // Check that the browsing session is valid and has target device set. |
|
69 if( !aBrowsingSession ) |
|
70 { |
|
71 User::Leave( KErrArgument ); |
|
72 } |
|
73 |
|
74 CUpnpDownloadHandler* self = NULL; |
|
75 self = new (ELeave) CUpnpDownloadHandler; |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL( aBrowsingSession ); |
|
78 CleanupStack::Pop( self ); |
|
79 __LOG( "[UpnpDownloadHandler] CUpnpDownloadHandler: NewL end" ); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // -------------------------------------------------------------------------- |
|
84 // Constuctor |
|
85 // -------------------------------------------------------------------------- |
|
86 // |
|
87 CUpnpDownloadHandler::CUpnpDownloadHandler() |
|
88 { |
|
89 __LOG( "[UpnpDownloadHandler] Constructor" ); |
|
90 iContainerCopy = EFalse; |
|
91 iBrowsePosition = -1; |
|
92 iFirstBrowse = ETrue; |
|
93 |
|
94 iDownloadedCount = KZero; |
|
95 __LOG( "[UpnpDownloadHandler] Constructor -end" ); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // Destructor |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 CUpnpDownloadHandler::~CUpnpDownloadHandler() |
|
103 { |
|
104 __LOG( "[UpnpDownloadHandler] Destructor" ); |
|
105 |
|
106 // If download session is running, stop it |
|
107 if( iAvController && |
|
108 iDownloadSession ) |
|
109 { |
|
110 iAvController->StopDownloadSession( *iDownloadSession ); |
|
111 } |
|
112 |
|
113 // Delete the note handler. |
|
114 delete iNoteHandler; |
|
115 |
|
116 // delete the UpnpAvControllerClient |
|
117 delete iAvController; |
|
118 |
|
119 // delete the container id |
|
120 delete iContainerId; |
|
121 |
|
122 delete iPlaylistHandler; |
|
123 iCopyItems.ResetAndDestroy(); |
|
124 iCopyItems.Close(); |
|
125 //iCopyItem.ResetAndDestroy(); |
|
126 // Restore the browse session observer |
|
127 if( iBrowsingSession && |
|
128 iBrowsingSessionObserverBackup ) |
|
129 { |
|
130 iBrowsingSession->RemoveObserver(); |
|
131 iBrowsingSession->SetObserver( *iBrowsingSessionObserverBackup ); |
|
132 } |
|
133 __LOG( "[UpnpDownloadHandler] Destructor -end" ); |
|
134 } |
|
135 |
|
136 // -------------------------------------------------------------------------- |
|
137 // CUpnpDownloadHandler::ConstructL |
|
138 // Second phase constructor |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 void CUpnpDownloadHandler::ConstructL( |
|
142 MUPnPAVBrowsingSession* aBrowsingSession ) |
|
143 { |
|
144 __LOG( "[UpnpDownloadHandler] ConstructL" ); |
|
145 |
|
146 if( !aBrowsingSession ) |
|
147 { |
|
148 User::Leave( KErrArgument ); |
|
149 } |
|
150 |
|
151 // Store the browsing session |
|
152 iBrowsingSession = aBrowsingSession; |
|
153 |
|
154 // Create UpnpAvControllerClient |
|
155 iAvController = UPnPAVControllerFactory::NewUPnPAVControllerL(); |
|
156 |
|
157 // Create download session |
|
158 iDownloadSession = &iAvController->StartDownloadSessionL( |
|
159 iBrowsingSession->Device() ); |
|
160 |
|
161 // Set this object to be the download session observer |
|
162 iDownloadSession->SetObserver( *this ); |
|
163 |
|
164 // Backup the browse session observer and set this object as an observer. |
|
165 iBrowsingSessionObserverBackup = iBrowsingSession->Observer(); |
|
166 iBrowsingSession->RemoveObserver(); |
|
167 iBrowsingSession->SetObserver( *this ); |
|
168 |
|
169 iNoteHandler = CUpnpNoteHandler::NewL( this ); |
|
170 |
|
171 iPlaylistHandler = CUpnpPlaylistHandler::NewL(); |
|
172 __LOG( "[UpnpDownloadHandler] ConstructL -end" ); |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CUpnpDownloadHandler::DownloadItemsL |
|
177 // Downloads the given objects to the handset, into the default target folder |
|
178 // (setting in the Home Media application). |
|
179 // -------------------------------------------------------------------------- |
|
180 // |
|
181 void CUpnpDownloadHandler::DownloadItemsL( CDesC8ArrayFlat* aObjectIds ) |
|
182 { |
|
183 |
|
184 __LOG( "[UpnpDownloadHandler] DownloadItemsL" ); |
|
185 // Check parameter |
|
186 if( !aObjectIds || |
|
187 aObjectIds->Count() <= KZero ) |
|
188 { |
|
189 User::Leave( KErrArgument ); |
|
190 } |
|
191 |
|
192 iTotalCount = aObjectIds->Count(); |
|
193 iObjectsToCopy = aObjectIds; |
|
194 |
|
195 // Initialise values |
|
196 iCopyPosition = -1; |
|
197 iCopyCompleteness = KZero; |
|
198 |
|
199 iStatusCode = KErrNone; |
|
200 |
|
201 // Start fetching the object metadata |
|
202 StartDownload(); |
|
203 |
|
204 if( iStatusCode == KErrNone ) |
|
205 { |
|
206 iNoteHandler->RunProgressNoteL( EUpnpCopyProgressNote ); |
|
207 } |
|
208 |
|
209 // Leave if there was an error |
|
210 if( iStatusCode != KErrNone ) |
|
211 { |
|
212 iDownloadSession->CancelAllTransfers(); |
|
213 User::Leave( iStatusCode ); |
|
214 } |
|
215 else |
|
216 { |
|
217 if( iContainerCopy ) |
|
218 { |
|
219 // If no files were copied, change the copy status code |
|
220 if( iPlaylistHandler->AudioItemCount() <= 0 && |
|
221 iPlaylistHandler->ImageItemCount() <= 0 && |
|
222 iPlaylistHandler->VideoItemCount() <= 0 && |
|
223 iStatusCode == KErrNone ) |
|
224 { |
|
225 iStatusCode = KErrNotFound; |
|
226 } |
|
227 |
|
228 // If files were copied, create playlists, albums and notify |
|
229 // Media Gallery |
|
230 else |
|
231 { |
|
232 // If audio files were copied, and the operation was to |
|
233 // copy a playlist, then create a MPX playlist |
|
234 if( iPlaylistHandler->AudioItemCount() > 0 && iPlayList ) |
|
235 { |
|
236 iPlaylistHandler->CreateMusicPlaylistL(); |
|
237 } |
|
238 |
|
239 // If image files were copied, create an image album |
|
240 if( iPlaylistHandler->ImageItemCount() > 0 ) |
|
241 { |
|
242 iPlaylistHandler->CreateImageAlbumL(); |
|
243 } |
|
244 |
|
245 // If video files were copied, create a video album |
|
246 if( iPlaylistHandler->VideoItemCount() > 0 ) |
|
247 { |
|
248 iPlaylistHandler->CreateVideoAlbumL(); |
|
249 } |
|
250 } |
|
251 |
|
252 // Reset the playlist handler |
|
253 iPlaylistHandler->Reset(); |
|
254 } |
|
255 } |
|
256 __LOG( "[UpnpDownloadHandler] DownloadItemsL -end" ); |
|
257 } |
|
258 |
|
259 // -------------------------------------------------------------------------- |
|
260 // CUpnpDownloadHandler::DialogDismissedL |
|
261 // ProgressDialog call back method. Get's called when a dialog is |
|
262 // dismissed. |
|
263 // -------------------------------------------------------------------------- |
|
264 // |
|
265 void CUpnpDownloadHandler::DialogDismissedL( ) |
|
266 { |
|
267 __LOG( "[UpnpDownloadHandler] DialogDismissedL" ); |
|
268 // Update the status code |
|
269 if( iStatusCode == KErrNone ) |
|
270 { |
|
271 iStatusCode = KErrCancel; |
|
272 } |
|
273 iBrowsingSession->CancelBrowse(); |
|
274 iDownloadSession->CancelAllTransfers(); |
|
275 __LOG( "[UpnpDownloadHandler] DialogDismissedL -end" ); |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // CUpnpDownloadHandler::MediaServerDisappeared |
|
280 // Notifies that the Media Server we have a session with has disappeared. |
|
281 // Session is now unusable and must be closed. |
|
282 // -------------------------------------------------------------------------- |
|
283 // |
|
284 void CUpnpDownloadHandler::MediaServerDisappeared( |
|
285 TUPnPDeviceDisconnectedReason aReason ) |
|
286 { |
|
287 __LOG( "[UpnpDownloadHandler]\t MediaServerDisappeared()" ); |
|
288 |
|
289 // Update the status code |
|
290 if( aReason == EDisconnected ) |
|
291 { |
|
292 iStatusCode = KErrSessionClosed; |
|
293 } |
|
294 else if( aReason == EWLANLost ) |
|
295 { |
|
296 iStatusCode = KErrDisconnected; |
|
297 } |
|
298 else |
|
299 { |
|
300 iStatusCode = KErrUnknown; |
|
301 } |
|
302 |
|
303 // Finish the progress note |
|
304 iNoteHandler->FinishProgressNote(); |
|
305 |
|
306 __LOG( "[UpnpDownloadHandler]\t MediaServerDisappeared() -end" ); |
|
307 } |
|
308 |
|
309 // -------------------------------------------------------------------------- |
|
310 // CUpnpDownloadHandler::BrowseResponse |
|
311 // Returns unprocessed browse results received from a Media Server. |
|
312 // -------------------------------------------------------------------------- |
|
313 // |
|
314 void CUpnpDownloadHandler::BrowseResponse( const TDesC8& aBrowseResponse, |
|
315 TInt aError, |
|
316 TInt /*aMatches*/, |
|
317 TInt aTotalCount, |
|
318 const TDesC8& /*aUpdateId*/ ) |
|
319 { |
|
320 __LOG( "[UpnpDownloadHandler] BrowseResponse()" ); |
|
321 |
|
322 if( aBrowseResponse != KNullDesC8 && |
|
323 aError == KErrNone ) |
|
324 { |
|
325 TRAP( aError, BrowseResponseL( aBrowseResponse, |
|
326 aTotalCount ) ); |
|
327 } |
|
328 else if( aBrowseResponse == KNullDesC8 && KErrNone!= aError ) |
|
329 { |
|
330 aError = KErrArgument; |
|
331 } |
|
332 |
|
333 // If parsing or sending the download action failed, exit |
|
334 if( aError != KErrNone ) |
|
335 { |
|
336 |
|
337 if( KErrCompletion == aError ) |
|
338 { |
|
339 iStatusCode = KErrNone; |
|
340 } |
|
341 else |
|
342 { |
|
343 iStatusCode = aError; |
|
344 } |
|
345 iNoteHandler->FinishProgressNote(); |
|
346 } |
|
347 |
|
348 |
|
349 |
|
350 __LOG( "[UpnpDownloadHandler] BrowseResponse() -end" ); |
|
351 } |
|
352 |
|
353 // -------------------------------------------------------------------------- |
|
354 // CUpnpDownloadHandler::BrowseResponseL |
|
355 // Returns unprocessed browse results received from a Media Server. |
|
356 // -------------------------------------------------------------------------- |
|
357 // |
|
358 void CUpnpDownloadHandler::BrowseResponseL( const TDesC8& aBrowseResponse, |
|
359 TInt aTotalCount ) |
|
360 |
|
361 { |
|
362 __LOG( "[UpnpDownloadHandler] BrowseResponseL()" ); |
|
363 |
|
364 //get the number of items in the container copy |
|
365 if( !iFirstBrowse && iContainerCopy ) |
|
366 { |
|
367 iTotalCount = aTotalCount; |
|
368 if( !iProgressBarMaxValueSet ) |
|
369 { |
|
370 iProgressBarMaxValueSet = ETrue; |
|
371 iNoteHandler->SetMaxValue( iTotalCount * KProgressBaseValue ); |
|
372 } |
|
373 |
|
374 } |
|
375 // Parse the result |
|
376 |
|
377 RPointerArray<CUpnpObject> array; |
|
378 CleanupResetAndDestroyPushL( array ); |
|
379 |
|
380 CUPnPXMLParser* parser = NULL; |
|
381 parser = CUPnPXMLParser::NewLC(); |
|
382 |
|
383 |
|
384 parser->ParseResultDataL( array, aBrowseResponse ); |
|
385 CleanupStack::PopAndDestroy( parser ); |
|
386 |
|
387 /** |
|
388 * Seldomly the aError is KErrNone, but no object in array |
|
389 * if this is for the container copying, return KErrArgument |
|
390 * otherwise, continue to browse the next item |
|
391 */ |
|
392 if( array.Count() > 0 ) |
|
393 { |
|
394 if( array[KZero]->ObjectType() == EUPnPItem ) |
|
395 { |
|
396 iFirstBrowse = EFalse; |
|
397 IsAnyItem = ETrue; |
|
398 |
|
399 if( !iProgressBarMaxValueSet ) |
|
400 { |
|
401 iProgressBarMaxValueSet = ETrue; |
|
402 iNoteHandler->SetMaxValue( iTotalCount * KProgressBaseValue ); |
|
403 } |
|
404 |
|
405 CUpnpItem* tempItem = NULL; |
|
406 tempItem = CUpnpItem::NewL(); |
|
407 tempItem->CopyL( *array[KZero] ); |
|
408 |
|
409 CleanupStack::PushL( tempItem ); |
|
410 |
|
411 iCopyItems.AppendL( tempItem ); //transfer ownership |
|
412 CleanupStack::Pop( tempItem ); |
|
413 |
|
414 // Start downloading the next object |
|
415 StartDownload(); |
|
416 } |
|
417 else if( array[KZero]->ObjectType() == EUPnPContainer ) |
|
418 { |
|
419 //To get the parent container Id |
|
420 if( iFirstBrowse ) |
|
421 { |
|
422 CUpnpContainer* sourseContainer = NULL; |
|
423 sourseContainer = ( CUpnpContainer* )array[KZero]; |
|
424 iPlayList = UPnPCommonUtils::IsPlaylistContainerL( |
|
425 *sourseContainer); |
|
426 |
|
427 iPlaylistHandler->Reset(); |
|
428 |
|
429 // Convert the container title to playlist name |
|
430 HBufC* titleUnicode = NULL; |
|
431 titleUnicode = UpnpString::ToUnicodeL( sourseContainer->Title() ); |
|
432 CleanupStack::PushL( titleUnicode ); |
|
433 iPlaylistHandler->SetPlaylistNameL( *titleUnicode ); |
|
434 CleanupStack::PopAndDestroy( titleUnicode ); |
|
435 |
|
436 iContainerCopy = ETrue; |
|
437 iBrowsePosition = -1; //reset the browes position |
|
438 iFirstBrowse = EFalse; |
|
439 delete iContainerId; iContainerId = NULL; |
|
440 iContainerId = array[KZero]->Id().AllocL(); |
|
441 } |
|
442 } |
|
443 } //if( array[KZero] > 0 ) |
|
444 else //if no items |
|
445 { |
|
446 if( iFirstBrowse ) |
|
447 { |
|
448 User::LeaveIfError( KErrArgument ); |
|
449 } |
|
450 } |
|
451 |
|
452 CleanupStack::PopAndDestroy( &array ); |
|
453 |
|
454 //try to start browsing next object |
|
455 if( iTotalCount > ++iBrowsePosition ) |
|
456 { |
|
457 if( !iContainerCopy ) |
|
458 { |
|
459 iBrowsingSession->BrowseL( iObjectsToCopy->MdcaPoint( |
|
460 iBrowsePosition ), |
|
461 KFilterFull(), |
|
462 MUPnPAVBrowsingSession::EMetadata, |
|
463 iBrowsePosition, |
|
464 KBrowseRequestCount, |
|
465 KSortCriteria() ); |
|
466 } |
|
467 else |
|
468 { |
|
469 // if we are copying a container, |
|
470 // browse the next item |
|
471 if( iContainerId ) |
|
472 { |
|
473 iBrowsingSession->BrowseL( |
|
474 *iContainerId, |
|
475 KFilterFull(), |
|
476 MUPnPAVBrowsingSession::EDirectChildren, |
|
477 iBrowsePosition, |
|
478 KBrowseRequestCount, |
|
479 KSortCriteria() ); |
|
480 } |
|
481 } |
|
482 } //if( iTotalCount > ++iBrowsePosition ) |
|
483 else //if there is no item in a container |
|
484 { |
|
485 if( iContainerCopy && !IsAnyItem ) |
|
486 { |
|
487 iNoteHandler->FinishProgressNote(); |
|
488 } |
|
489 } |
|
490 __LOG( "[UpnpDownloadHandler] BrowseResponseL() -end" ); |
|
491 } |
|
492 |
|
493 // -------------------------------------------------------------------------- |
|
494 // CUpnpDownloadHandler::TransferStarted |
|
495 // -------------------------------------------------------------------------- |
|
496 // |
|
497 void CUpnpDownloadHandler::TransferStarted( TInt aKey, |
|
498 TInt aStatus ) |
|
499 { |
|
500 __LOG( "[UpnpDownloadHandler] TransferStarted()" ); |
|
501 |
|
502 // If the transfer failed to start, exit |
|
503 |
|
504 if( aStatus != KErrNone) |
|
505 { |
|
506 iStatusCode = aStatus; |
|
507 } |
|
508 else if( aKey < 0 || aKey > iCopyPosition ) |
|
509 { |
|
510 iStatusCode = KErrGeneral; |
|
511 } |
|
512 |
|
513 if( KErrServerBusy == iStatusCode ) |
|
514 { |
|
515 iBrowsePosition--; |
|
516 iCopyPosition--; |
|
517 iStatusCode = KErrNone; |
|
518 } |
|
519 |
|
520 if( KErrNone != iStatusCode ) |
|
521 { |
|
522 iNoteHandler->FinishProgressNote(); //this is sychro. call |
|
523 } |
|
524 else |
|
525 { |
|
526 TRAP_IGNORE( iDownloadSession->StartTrackingProgressL( aKey ) ); |
|
527 } |
|
528 |
|
529 __LOG( "[UpnpDownloadHandler] TransferStarted() -end" ); |
|
530 } |
|
531 |
|
532 // -------------------------------------------------------------------------- |
|
533 // CUpnpDownloadHandler::TransferProgress |
|
534 // -------------------------------------------------------------------------- |
|
535 // |
|
536 void CUpnpDownloadHandler::TransferProgress( TInt aKey, |
|
537 TInt aBytes, |
|
538 TInt aTotalBytes ) |
|
539 { |
|
540 __LOG( "[UpnpDownloadHandler] TransferProgress()" ); |
|
541 if( aKey < 0 || aKey > iCopyPosition ) |
|
542 { |
|
543 iStatusCode = KErrGeneral; |
|
544 iNoteHandler->FinishProgressNote(); |
|
545 } |
|
546 else |
|
547 { |
|
548 float progress = ((float)aBytes / aTotalBytes) * 100; |
|
549 iNoteHandler->SetValue( iCopyCompleteness + (TInt)progress); |
|
550 } |
|
551 |
|
552 __LOG( "[UpnpDownloadHandler] TransferProgress() -end" ); |
|
553 } |
|
554 |
|
555 // -------------------------------------------------------------------------- |
|
556 // CUpnpDownloadHandler::TransferCompleted |
|
557 // -------------------------------------------------------------------------- |
|
558 // |
|
559 void CUpnpDownloadHandler::TransferCompleted( TInt aKey, |
|
560 TInt aStatus, |
|
561 const TDesC& aFilePath ) |
|
562 { |
|
563 __LOG( "[UpnpDownloadHandler] TransferCompleted()" ); |
|
564 |
|
565 |
|
566 iStatusCode = aStatus; |
|
567 iDownloadedCount++; |
|
568 |
|
569 if( KErrNone != iStatusCode || ( aKey < 0 || aKey > iCopyPosition ) || |
|
570 iTotalCount <= iDownloadedCount ) |
|
571 { |
|
572 iNoteHandler->FinishProgressNote(); |
|
573 } |
|
574 else |
|
575 { |
|
576 // Update the download completeness percentage value |
|
577 iCopyCompleteness = iDownloadedCount * KProgressBaseValue; |
|
578 // Update the progress note |
|
579 iNoteHandler->SetValue( iCopyCompleteness ); |
|
580 |
|
581 if( iCopyItems.Count() > aKey ) |
|
582 { |
|
583 CUpnpItem* obj = NULL; |
|
584 obj = (CUpnpItem*)iCopyItems[aKey]; |
|
585 if( obj ) |
|
586 { |
|
587 TRAP_IGNORE( NotifyMPXL( *obj, aFilePath ) ); |
|
588 |
|
589 delete iCopyItems[aKey]; |
|
590 iCopyItems[aKey] = NULL; |
|
591 } |
|
592 } |
|
593 |
|
594 } |
|
595 __LOG( "[UpnpDownloadHandler] TransferCompleted() -end" ); |
|
596 } |
|
597 |
|
598 // -------------------------------------------------------------------------- |
|
599 // CUpnpDownloadHandler::NotifyMPXL |
|
600 // Notify MPX when download is complete |
|
601 // -------------------------------------------------------------------------- |
|
602 // |
|
603 void CUpnpDownloadHandler::NotifyMPXL( |
|
604 const CUpnpItem& aObject, const TDesC& aFilePath ) |
|
605 { |
|
606 __LOG( "[UpnpDownloadHandler] NotifyMPXL()" ); |
|
607 TUPnPItemType itemType = ETypeOther; |
|
608 itemType = UPnPCommonUtils::ResolveFileTypeL( aFilePath ); |
|
609 |
|
610 // Nofity MPX of a new file |
|
611 if( itemType == ETypeAudio ) |
|
612 { |
|
613 if( iContainerCopy ) |
|
614 { |
|
615 iPlaylistHandler->AddAudioItemL( aFilePath ); |
|
616 } |
|
617 iPlaylistHandler->NotifyNewAudioFileL( aFilePath, aObject ); |
|
618 } |
|
619 |
|
620 if( iContainerCopy ) |
|
621 { |
|
622 if( itemType == ETypeVideo ) |
|
623 { |
|
624 iPlaylistHandler->AddVideoItemL( aFilePath); |
|
625 } |
|
626 else if( itemType == ETypeImage ) |
|
627 { |
|
628 iPlaylistHandler->AddImageItemL( aFilePath); |
|
629 } |
|
630 } |
|
631 __LOG( "[UpnpDownloadHandler] NotifyMPXL() end" ); |
|
632 } |
|
633 |
|
634 |
|
635 // -------------------------------------------------------------------------- |
|
636 // CUpnpDownloadHandler::StartDownload |
|
637 // Start download a file |
|
638 // -------------------------------------------------------------------------- |
|
639 // |
|
640 void CUpnpDownloadHandler::StartDownload() |
|
641 { |
|
642 __LOG( "[UpnpDownloadHandler] StartDownload()" ); |
|
643 if( iStatusCode == KErrNone ) |
|
644 { |
|
645 TRAP( iStatusCode, StartDownloadL() ); |
|
646 } |
|
647 |
|
648 |
|
649 // If the downloading of the next file failed (browse failed or there |
|
650 // are no more files), exit |
|
651 |
|
652 if( iStatusCode!= KErrNone ) |
|
653 { |
|
654 if( iStatusCode == KErrCompletion ) |
|
655 { |
|
656 iStatusCode = KErrNone; |
|
657 } |
|
658 iNoteHandler->FinishProgressNote(); |
|
659 } |
|
660 __LOG( "[UpnpDownloadHandler] StartDownload() end" ); |
|
661 } |
|
662 |
|
663 // -------------------------------------------------------------------------- |
|
664 // CUpnpDownloadHandler::StartDownloadL |
|
665 // Starts the next download. Leaves (KErrCompletion) if there are no more |
|
666 // objects to download. |
|
667 // -------------------------------------------------------------------------- |
|
668 // |
|
669 void CUpnpDownloadHandler::StartDownloadL() |
|
670 { |
|
671 __LOG( "[UpnpDownloadHandler] StartDownloadL()" ); |
|
672 |
|
673 if( !iFirstBrowse ) |
|
674 { |
|
675 //start downloading |
|
676 // check if there are any CUpnpObject left in the array |
|
677 if( iCopyItems.Count() > ++iCopyPosition ) |
|
678 { |
|
679 iDownloadSession-> |
|
680 StartDownloadL( *(CUpnpItem*)iCopyItems[iCopyPosition], |
|
681 iCopyPosition ); |
|
682 } |
|
683 else |
|
684 { |
|
685 User::Leave( KErrCompletion ); |
|
686 } |
|
687 } |
|
688 else //this is called only once at the beginning of copying |
|
689 { |
|
690 //start browsing |
|
691 iBrowsePosition++; |
|
692 |
|
693 iBrowsingSession->BrowseL( |
|
694 iObjectsToCopy->MdcaPoint( iBrowsePosition ), |
|
695 KFilterFull(), |
|
696 MUPnPAVBrowsingSession::EMetadata, |
|
697 iBrowsePosition, |
|
698 KBrowseRequestCount, |
|
699 KSortCriteria() ); |
|
700 |
|
701 } |
|
702 __LOG( "[UpnpDownloadHandler] StartDownloadL() -end" ); |
|
703 } |
|
704 |
|
705 // -------------------------------------------------------------------------- |
|
706 // CUpnpDownloadHandler::GetNumCopiedFiles |
|
707 // -------------------------------------------------------------------------- |
|
708 // |
|
709 TInt CUpnpDownloadHandler::GetNumCopiedFiles() const |
|
710 { |
|
711 return iDownloadedCount; |
|
712 } |
|
713 // End of file |