|
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 the License "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 My Videos collection Plugin interface* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32cmn.h> |
|
22 #include <s32mem.h> |
|
23 #include <mpxlog.h> |
|
24 #include <mpxmediacontainerdefs.h> |
|
25 #include <mpxmediageneraldefs.h> |
|
26 #include <mpxmediageneralextdefs.h> |
|
27 #include <mpxcollectionpluginobserver.h> |
|
28 #include <mpxmessagegeneraldefs.h> |
|
29 #include <mpxcommandgeneraldefs.h> |
|
30 #include <mpxcollectioncommanddefs.h> |
|
31 #include <mpxmessagecontainerdefs.h> |
|
32 #include <vcxmyvideosuids.h> |
|
33 #include <drmutility.h> |
|
34 #include <bautils.h> |
|
35 #include "vcxmyvideoscollectionplugin.h" |
|
36 #include "vcxmyvideoscollection.hrh" |
|
37 #include "vcxmyvideoscollectionutil.h" |
|
38 #include "vcxmyvideosdownloadutil.h" |
|
39 #include "vcxmyvideosvideocache.h" |
|
40 #include "vcxmyvideoscategories.h" |
|
41 #include "vcxmyvideosmessagelist.h" |
|
42 #include "vcxmyvideosasyncfileoperations.h" |
|
43 #include "vcxmyvideosopenhandler.h" |
|
44 |
|
45 const TInt KMaxFileDeleteAttempts = 4; |
|
46 const TInt KFileDeleteLoopDelay = 100000; |
|
47 |
|
48 // Add 2000 new videos to memory card. Reboot phone, mds starts harvesting, |
|
49 // open my videos -> mds server crashes and lots of events is sent to client. |
|
50 // If one waits until all are harvested before opening my videos, it works. |
|
51 |
|
52 |
|
53 // ============================ MEMBER FUNCTIONS ============================== |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // Two-phased constructor. |
|
57 // ---------------------------------------------------------------------------- |
|
58 // |
|
59 CVcxMyVideosCollectionPlugin* CVcxMyVideosCollectionPlugin::NewL( |
|
60 TAny* /* aInitParams */) |
|
61 { |
|
62 MPX_FUNC("CVcxMyVideosCollectionPlugin::NewL"); |
|
63 |
|
64 CVcxMyVideosCollectionPlugin* self = new (ELeave) CVcxMyVideosCollectionPlugin(); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ---------------------------------------------------------------------------- |
|
72 // Destructor. |
|
73 // ---------------------------------------------------------------------------- |
|
74 // |
|
75 CVcxMyVideosCollectionPlugin::~CVcxMyVideosCollectionPlugin() |
|
76 { |
|
77 MPX_FUNC("CVcxMyVideosCollectionPlugin::~CVcxMyVideosCollectionPlugin"); |
|
78 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: this = %x", this); |
|
79 |
|
80 delete iMyVideosMdsDb; |
|
81 delete iDownloadUtil; |
|
82 delete iCache; |
|
83 delete iMessageList; |
|
84 delete iCategories; |
|
85 delete iAsyncFileOperations; |
|
86 delete iActiveTask; |
|
87 delete iOpenHandler; |
|
88 iFs.Close(); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // Constructor. |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 CVcxMyVideosCollectionPlugin::CVcxMyVideosCollectionPlugin() |
|
96 { |
|
97 MPX_FUNC("CVcxMyVideosCollectionPlugin::CVcxMyVideosCollectionPlugin"); |
|
98 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: this = %x", this); |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // Symbian 2nd phase constructor can leave. |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 void CVcxMyVideosCollectionPlugin::ConstructL () |
|
106 { |
|
107 MPX_FUNC("CVcxMyVideosCollectionPlugin::ConstructL"); |
|
108 |
|
109 User::LeaveIfError( iFs.Connect() ); |
|
110 |
|
111 iMyVideosMdsDb = CVcxMyVideosMdsDb::NewL( this, iFs ); |
|
112 iActiveTask = CVcxMyVideosActiveTask::NewL( *this ); |
|
113 iCache = CVcxMyVideosVideoCache::NewL( *this ); |
|
114 iMessageList = CVcxMyVideosMessageList::NewL( *this ); |
|
115 iOpenHandler = CVcxMyVideosOpenHandler::NewL( *this, *iCache, *iMyVideosMdsDb ); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------------------------------- |
|
119 // Navigates to the given path |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 void CVcxMyVideosCollectionPlugin::OpenL( |
|
123 const CMPXCollectionPath& aPath, |
|
124 const TArray<TMPXAttribute>& /* aAttrs */, |
|
125 CMPXFilter* /*aFilter*/) |
|
126 { |
|
127 iOpenHandler->OpenL( aPath ); |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------------- |
|
131 // Get the extended properties of the current file (async) |
|
132 // ---------------------------------------------------------------------------- |
|
133 // |
|
134 void CVcxMyVideosCollectionPlugin::MediaL( |
|
135 const CMPXCollectionPath& aPath, |
|
136 const TArray<TMPXAttribute>& aAttrs, |
|
137 const TArray<TCapability>& /*aCaps*/, |
|
138 CMPXAttributeSpecs* /*aSpecs*/) |
|
139 { |
|
140 MPX_FUNC("CMPXMyVideosDbPlugin::MediaL"); |
|
141 MPX_DEBUG_PATH(aPath); |
|
142 |
|
143 RArray<TInt> supportedIds; |
|
144 CleanupClosePushL( supportedIds ); // 1-> |
|
145 |
|
146 if ( aPath.Selection().Count() > 1 ) |
|
147 { |
|
148 // it's a container if there are multiple selections, else it's not a container |
|
149 //supportedIds.AppendL(KMPXMediaIdContainer); |
|
150 //multiple selections not supported yet |
|
151 CleanupStack::PopAndDestroy( &supportedIds ); // <-1 |
|
152 iObs->HandleMedia( NULL, KErrNotSupported ); |
|
153 return; |
|
154 } |
|
155 |
|
156 RArray<TMPXItemId> ids; |
|
157 CleanupClosePushL(ids); // 2-> |
|
158 |
|
159 aPath.SelectionL( ids ); |
|
160 |
|
161 // MPX playback server asks it by path without selecting the media. |
|
162 if ( ids.Count() == 0 && aPath.Id() != KMPXInvalidItemId ) |
|
163 { |
|
164 CMPXCollectionPath* path = CMPXCollectionPath::NewL( aPath ); |
|
165 CleanupStack::PushL( path ); |
|
166 path->SelectL( aPath.Id() ); |
|
167 path->SelectionL( ids ); |
|
168 CleanupStack::PopAndDestroy( path ); |
|
169 } |
|
170 |
|
171 if ( ids.Count() == 0 ) |
|
172 { |
|
173 MPX_DEBUG1("CMPXMyVideosDbPlugin:: request didn't contain any items ids, aborting"); |
|
174 |
|
175 iObs->HandleMedia( NULL, KErrArgument ); |
|
176 CleanupStack::PopAndDestroy( &ids ); // <-2 |
|
177 CleanupStack::PopAndDestroy( &supportedIds ); // <-1 |
|
178 return; |
|
179 } |
|
180 |
|
181 TBool useCachedVideo( EFalse ); |
|
182 |
|
183 TInt pos; |
|
184 CMPXMedia* videoInCache = iCache->FindVideoByMdsIdL( ids[0].iId1, pos ); |
|
185 |
|
186 if ( videoInCache ) |
|
187 { |
|
188 // 0 attributes means "get all" -> can't use cache |
|
189 MPX_DEBUG2("CMPXMyVideosDbPlugin:: client is requesting %d attributes", aAttrs.Count()); |
|
190 if ( aAttrs.Count() > 0 ) |
|
191 { |
|
192 TBool nonSupportedAttrCanBeFoundFromMds; |
|
193 if ( TVcxMyVideosCollectionUtil::AreSupported( *videoInCache, aAttrs, |
|
194 nonSupportedAttrCanBeFoundFromMds ) ) |
|
195 { |
|
196 MPX_DEBUG1("CMPXMyVideosDbPlugin:: all attributes found from cache"); |
|
197 useCachedVideo = ETrue; |
|
198 } |
|
199 else |
|
200 { |
|
201 MPX_DEBUG1("CMPXMyVideosDbPlugin:: all attributes NOT found from cache"); |
|
202 if ( !nonSupportedAttrCanBeFoundFromMds ) |
|
203 { |
|
204 MPX_DEBUG1("CMPXMyVideosDbPlugin:: none of the non cached attrs can be found from MDS -> use cached version"); |
|
205 useCachedVideo = ETrue; |
|
206 } |
|
207 else |
|
208 { |
|
209 MPX_DEBUG1("CMPXMyVideosDbPlugin:: at least one of the non cached attributes can be found from MDS"); |
|
210 } |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 CMPXMedia* video; |
|
216 |
|
217 if ( useCachedVideo ) |
|
218 { |
|
219 MPX_DEBUG1("CMPXMyVideosDbPlugin:: using cached video"); |
|
220 video = CMPXMedia::CopyL( *videoInCache ); |
|
221 } |
|
222 else |
|
223 { |
|
224 MPX_DEBUG1("CMPXMyVideosDbPlugin:: fetching from MDS"); |
|
225 video = iMyVideosMdsDb->CreateVideoL( ids[0].iId1, ETrue /* full details */ ); |
|
226 } |
|
227 |
|
228 iObs->HandleMedia( video, KErrNone ); |
|
229 |
|
230 CleanupStack::PopAndDestroy( &ids ); // <-2 |
|
231 CleanupStack::PopAndDestroy( &supportedIds ); // <-1 |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------------------------------- |
|
235 // Cancel the pending request, this is called by mpx framework when client calls |
|
236 // Cancel. |
|
237 // ---------------------------------------------------------------------------- |
|
238 // |
|
239 void CVcxMyVideosCollectionPlugin::CancelRequest() |
|
240 { |
|
241 MPX_FUNC("CVcxMyVideosCollectionPlugin::CancelRequest"); |
|
242 |
|
243 iActiveTask->Cancel(); |
|
244 iMyVideosMdsDb->Cancel(); |
|
245 } |
|
246 |
|
247 // ---------------------------------------------------------------------------- |
|
248 // Executes the given command on the collection |
|
249 // ---------------------------------------------------------------------------- |
|
250 // |
|
251 void CVcxMyVideosCollectionPlugin::CommandL( |
|
252 CMPXCommand& aCmd) |
|
253 { |
|
254 MPX_FUNC("CVcxMyVideosCollectionPlugin::CommandL 2"); |
|
255 |
|
256 if ( !aCmd.IsSupported( KMPXCommandGeneralId ) ) |
|
257 { |
|
258 User::Leave( KErrArgument ); |
|
259 } |
|
260 |
|
261 TMPXCommandId commandId = *aCmd.Value<TMPXCommandId>(KMPXCommandGeneralId); |
|
262 |
|
263 TBool syncOp( EFalse ); |
|
264 if( aCmd.IsSupported( KMPXCommandGeneralDoSync ) ) |
|
265 { |
|
266 syncOp = *aCmd.Value<TBool>( KMPXCommandGeneralDoSync ); |
|
267 } |
|
268 |
|
269 if ( !syncOp ) |
|
270 { |
|
271 // async |
|
272 iActiveTask->StartL( commandId, aCmd ); |
|
273 } |
|
274 else |
|
275 { |
|
276 // sync, operations to a single media object only |
|
277 TMPXCommandId commandId = *aCmd.Value<TMPXCommandId>(KMPXCommandGeneralId); |
|
278 |
|
279 switch ( commandId ) |
|
280 { |
|
281 case KMPXCommandIdCollectionAdd: |
|
282 { |
|
283 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: sync KMPXCommandIdCollectionAdd arrived"); |
|
284 |
|
285 #ifdef _DEBUG |
|
286 CMPXMedia* video = aCmd.Value<CMPXMedia>( KMPXCommandColAddMedia ); |
|
287 TUint32 mdsId( 0 ); |
|
288 iMyVideosMdsDb->AddVideoL( *video, mdsId ); |
|
289 #else |
|
290 User::Leave( KErrNotSupported ); |
|
291 #endif |
|
292 } |
|
293 break; |
|
294 |
|
295 case KMPXCommandIdCollectionSet: |
|
296 { |
|
297 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: sync KMPXCommandIdCollectionSet arrived"); |
|
298 |
|
299 CMPXMedia* video = aCmd.Value<CMPXMedia>( KMPXCommandColSetMedia ); |
|
300 SetVideoL( *video ); |
|
301 } |
|
302 break; |
|
303 |
|
304 case KVcxCommandIdMyVideos: |
|
305 { |
|
306 switch ( aCmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosCommandId ) ) |
|
307 { |
|
308 case KVcxCommandMyVideosCancelMoveOrCopy: |
|
309 { |
|
310 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: sync KVcxCommandMyVideosCancelMoveOrCopy arrived"); |
|
311 iActiveTask->Cancel(); |
|
312 } |
|
313 break; |
|
314 |
|
315 case KVcxCommandMyVideosCancelDelete: |
|
316 { |
|
317 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: sync KVcxCommandMyVideosCancelDelete arrived"); |
|
318 iActiveTask->Cancel(); |
|
319 } |
|
320 break; |
|
321 } |
|
322 } |
|
323 break; |
|
324 |
|
325 default: |
|
326 { |
|
327 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: UNKNOWN SYNC COMMAND ARRIVED"); |
|
328 User::Leave( KErrNotSupported ); |
|
329 } |
|
330 } |
|
331 } |
|
332 |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // Find the items matching the media specifications |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 void CVcxMyVideosCollectionPlugin::FindAllL( |
|
340 const CMPXMedia& /* aCriteria */, |
|
341 const TArray<TMPXAttribute>& /* aAttrs */) |
|
342 { |
|
343 MPX_FUNC("CVcxMyVideosCollectionPlugin::FindAllL"); |
|
344 } |
|
345 |
|
346 // ---------------------------------------------------------------------------- |
|
347 // Find the items matching the media specifications |
|
348 // ---------------------------------------------------------------------------- |
|
349 // |
|
350 CMPXMedia* CVcxMyVideosCollectionPlugin::FindAllSyncL( |
|
351 const CMPXMedia& /* aCriteria */, |
|
352 const TArray<TMPXAttribute>& /* aAttrs */) |
|
353 { |
|
354 MPX_FUNC("CVcxMyVideosCollectionPlugin::FindAllSyncL"); |
|
355 return NULL; |
|
356 } |
|
357 |
|
358 // ---------------------------------------------------------------------------- |
|
359 // Get the list of supported capabilities |
|
360 // ---------------------------------------------------------------------------- |
|
361 // |
|
362 TCollectionCapability CVcxMyVideosCollectionPlugin::GetCapabilities() |
|
363 { |
|
364 // This one supports simple search |
|
365 return EMcSearch; |
|
366 } |
|
367 |
|
368 // ---------------------------------------------------------------------------------------------------------- |
|
369 // CVcxMyVideosCollectionPlugin::SendMessages |
|
370 // ---------------------------------------------------------------------------------------------------------- |
|
371 // |
|
372 void CVcxMyVideosCollectionPlugin::SendMessages( CMPXMessage& aMessages ) |
|
373 { |
|
374 #if _DEBUG |
|
375 TRAP_IGNORE( |
|
376 |
|
377 if ( aMessages.IsSupported( KMPXMessageArrayContents ) ) |
|
378 { |
|
379 const CMPXMessageArray* messageArray = |
|
380 aMessages.Value<CMPXMessageArray>(KMPXMessageArrayContents); |
|
381 |
|
382 for( TInt i = 0; i < messageArray->Count(); i++ ) |
|
383 { |
|
384 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: sending message ID: %d in array", ++iTotalMessagesSent); |
|
385 messageArray->AtL( i )->SetTObjectValueL<TUint32>( KVcxMediaMyVideosMessageId, iTotalMessagesSent ); |
|
386 iMessagesInArraySent++; |
|
387 } |
|
388 |
|
389 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: total messages sent (MSG ID): %d, messages in array sent: %d", |
|
390 iTotalMessagesSent, iMessagesInArraySent); |
|
391 } |
|
392 else |
|
393 { |
|
394 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: NO ARRAY IN MESSAGE!!!"); |
|
395 return; |
|
396 } |
|
397 |
|
398 ); |
|
399 #endif |
|
400 |
|
401 iObs->HandleMessage( aMessages ); |
|
402 } |
|
403 |
|
404 // ---------------------------------------------------------------------------------------------------------- |
|
405 // CVcxMyVideosCollectionPlugin::HandleMyVideosDbEvent |
|
406 // ---------------------------------------------------------------------------------------------------------- |
|
407 // |
|
408 void CVcxMyVideosCollectionPlugin::HandleMyVideosDbEvent( |
|
409 TMPXChangeEventType aEvent, |
|
410 RArray<TUint32>& aId ) |
|
411 { |
|
412 //MPX_FUNC("CVcxMyVideosCollectionPlugin::HandleMyVideosDbEvent"); |
|
413 TRAPD( err, DoHandleMyVideosDbEventL( aEvent, aId )); |
|
414 if ( err != KErrNone ) |
|
415 { |
|
416 MPX_DEBUG2("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() leaved with error code: %d", err); |
|
417 } |
|
418 } |
|
419 |
|
420 // ---------------------------------------------------------------------------------------------------------- |
|
421 // CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL |
|
422 // ---------------------------------------------------------------------------------------------------------- |
|
423 // |
|
424 void CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL( |
|
425 TMPXChangeEventType aEvent, |
|
426 RArray<TUint32>& aId ) |
|
427 { |
|
428 MPX_FUNC("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL"); |
|
429 |
|
430 switch ( aEvent ) |
|
431 { |
|
432 case EMPXItemDeleted: |
|
433 { |
|
434 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() --------------------------------------------."); |
|
435 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() Items from MDS deleted, deleting from cache |" ); |
|
436 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() --------------------------------------------'"); |
|
437 |
|
438 iCache->RemoveL( aId ); |
|
439 } |
|
440 break; |
|
441 |
|
442 case EMPXItemInserted: |
|
443 { |
|
444 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() ------------------------------------."); |
|
445 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() Items added to MDS, adding to cache |"); |
|
446 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() ------------------------------------'"); |
|
447 |
|
448 if ( iMyVideosMdsDb->iVideoListFetchingIsOngoing ) |
|
449 { |
|
450 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: video list fetching is ongoing, ignoring add event"); |
|
451 return; |
|
452 } |
|
453 |
|
454 TBool videoListFetchingWasCancelled = EFalse; |
|
455 |
|
456 // After the call, aId will contain only items which were actually inserted to cache. |
|
457 // We receive add events for all object types. When fetching the item from MDS we use |
|
458 // video condition and only video objects are added to cache. |
|
459 iCache->AddVideosFromMdsL( aId, videoListFetchingWasCancelled ); |
|
460 if ( videoListFetchingWasCancelled ) |
|
461 { |
|
462 RestartVideoListFetchingL(); |
|
463 } |
|
464 |
|
465 SyncWithDownloadsL( aId ); |
|
466 } |
|
467 break; |
|
468 |
|
469 case EMPXItemModified: |
|
470 { |
|
471 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() --------------------------------------."); |
|
472 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() Items modified in MDS, updating cache |"); |
|
473 MPX_DEBUG1("CVcxMyVideosCollectionPlugin::DoHandleMyVideosDbEventL() --------------------------------------'"); |
|
474 CMPXMedia* video; |
|
475 for ( TInt i = 0; i < aId.Count(); i++ ) |
|
476 { |
|
477 video = iMyVideosMdsDb->CreateVideoL( aId[i], ETrue /* full details */ ); |
|
478 |
|
479 if ( video ) |
|
480 { |
|
481 CleanupStack::PushL( video ); // 1-> |
|
482 iCache->UpdateVideoL( *video ); |
|
483 CleanupStack::PopAndDestroy( video ); // <-1 |
|
484 } |
|
485 else |
|
486 { |
|
487 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: couldn't find the modified item from MDS"); |
|
488 } |
|
489 } |
|
490 } |
|
491 SyncWithDownloadsL( aId ); |
|
492 break; |
|
493 } |
|
494 |
|
495 TInt pos; |
|
496 for ( TInt i = 0; i < aId.Count(); i++ ) |
|
497 { |
|
498 if ( aEvent == EMPXItemInserted ) |
|
499 { |
|
500 // add item from cache to the message if we have it. |
|
501 CMPXMedia* video = iCache->FindVideoByMdsIdL( aId[i], pos ); |
|
502 TRAP_IGNORE( iMessageList->AddEventL( TMPXItemId( aId[i], 0), aEvent, 0, video ) ); |
|
503 } |
|
504 else |
|
505 { |
|
506 TRAP_IGNORE( iMessageList->AddEventL( TMPXItemId( aId[i], 0), aEvent ) ); |
|
507 } |
|
508 } |
|
509 |
|
510 iMessageList->SendL(); |
|
511 } |
|
512 |
|
513 // ---------------------------------------------------------------------------- |
|
514 // CVcxMyVideosCollectionPlugin::HandleStepL |
|
515 // ---------------------------------------------------------------------------- |
|
516 // |
|
517 TBool CVcxMyVideosCollectionPlugin::HandleStepL() |
|
518 { |
|
519 MPX_FUNC("CVcxMyVideosCollectionPlugin::HandleStepL"); |
|
520 |
|
521 TBool done(ETrue); |
|
522 |
|
523 switch ( iActiveTask->GetTask() ) |
|
524 { |
|
525 case KMPXCommandIdCollectionSet: |
|
526 { |
|
527 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: async KMPXCommandIdCollectionSet in"); |
|
528 |
|
529 CMPXMedia* video = CMPXMedia::NewL( *(iActiveTask->GetCommand().Value<CMPXMedia>( |
|
530 KMPXCommandColSetMedia)) ); |
|
531 |
|
532 CleanupStack::PushL( video ); |
|
533 |
|
534 SetVideoL( *video ); |
|
535 |
|
536 CleanupStack::PopAndDestroy( video ); |
|
537 |
|
538 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: async KMPXCommandIdCollectionSet out"); |
|
539 |
|
540 done = ETrue; |
|
541 |
|
542 break; |
|
543 } |
|
544 case KVcxCommandIdMyVideos: |
|
545 { |
|
546 CMPXCommand& cmd = iActiveTask->GetCommand(); |
|
547 if ( !cmd.IsSupported( KVcxMediaMyVideosCommandId ) ) |
|
548 { |
|
549 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxMediaMyVideosCommandId attribute not supported in cmd, aborting"); |
|
550 User::Leave( KErrArgument ); |
|
551 } |
|
552 |
|
553 TInt myVideosCmd( cmd.ValueTObjectL<TUint>( KVcxMediaMyVideosCommandId ) ); |
|
554 |
|
555 switch ( myVideosCmd ) |
|
556 { |
|
557 case KVcxCommandMyVideosStartDownload: |
|
558 { |
|
559 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: Handling KVcxCommandMyVideosStartDownload command."); |
|
560 |
|
561 CMPXMedia* video = CMPXMedia::NewL( *(iActiveTask->GetCommand().Value<CMPXMedia>( |
|
562 KMPXCommandColAddMedia)) ); |
|
563 CleanupStack::PushL( video ); // 1-> |
|
564 |
|
565 if ( !iCache->iVideoList ) |
|
566 { |
|
567 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: iVideoListCache = NULL -> creating new empty iVideoListCache"); |
|
568 iCache->iVideoListIsPartial = ETrue; |
|
569 iCache->iVideoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL(); |
|
570 } |
|
571 |
|
572 TBool resume = EFalse; |
|
573 |
|
574 if ( video->IsSupported( KVcxMediaMyVideosDownloadId ) ) |
|
575 { |
|
576 TUint32 downloadId = video->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ); |
|
577 if ( downloadId != 0 ) |
|
578 { |
|
579 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: download id %d given by the client -> this is download resume", |
|
580 downloadId); |
|
581 resume = ETrue; |
|
582 |
|
583 // load the existing item to cache if its not there already |
|
584 } |
|
585 } |
|
586 |
|
587 if ( !resume ) |
|
588 { |
|
589 if ( !video->IsSupported( KVcxMediaMyVideosRemoteUrl ) ) |
|
590 { |
|
591 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxMediaMyVideosRemoteUrl not supported -> leaving with KErrArgument"); |
|
592 User::Leave( KErrArgument ); |
|
593 } |
|
594 |
|
595 if ( video->ValueText( KVcxMediaMyVideosRemoteUrl ).Length() > |
|
596 KVcxMvcMaxUrlLength ) |
|
597 { |
|
598 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: url longer than 1024 -> leaving with KErrArgument"); |
|
599 User::Leave( KErrArgument ); |
|
600 } |
|
601 |
|
602 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: starting download for url: %S", |
|
603 &video->ValueText( KVcxMediaMyVideosRemoteUrl ) ); |
|
604 |
|
605 video->SetTObjectValueL<TUint8>( KVcxMediaMyVideosOrigin, EVcxMyVideosOriginDownloaded ); |
|
606 video->SetTObjectValueL<TUint8>( KVcxMediaMyVideosDownloadState, |
|
607 static_cast<TUint8>(EVcxMyVideosDlStateDownloading) ); |
|
608 video->SetTObjectValueL<TUint32>( KMPXMediaGeneralFlags, EVcxMyVideosVideoNew ); |
|
609 |
|
610 HBufC* fileName = DownloadUtilL().CreateFilePathL( *video ); |
|
611 CleanupStack::PushL( fileName ); // 2-> |
|
612 video->SetTextValueL( KMPXMediaGeneralUri, *fileName ); |
|
613 CleanupStack::PopAndDestroy( fileName ); // <-2 |
|
614 } |
|
615 |
|
616 TRAPD( err, DownloadUtilL().StartDownloadL( *video ) ); //download id is written to video object |
|
617 |
|
618 if ( err != KErrNone ) |
|
619 { |
|
620 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: StartDownloadL left: %d", err); |
|
621 User::Leave( err ); |
|
622 } |
|
623 |
|
624 if ( !resume ) |
|
625 { |
|
626 TUint32 newDownloadId = video->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ); |
|
627 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: new download ID: %d", |
|
628 newDownloadId); |
|
629 |
|
630 AddVideoToMdsAndCacheL( *video ); |
|
631 } |
|
632 else |
|
633 { |
|
634 // clear old error codes from the dl item |
|
635 TInt pos; |
|
636 |
|
637 CMPXMedia* videoInCache = iCache->FindVideoByMdsIdL( |
|
638 TVcxMyVideosCollectionUtil::IdL( *video ), pos ); |
|
639 if ( videoInCache ) |
|
640 { |
|
641 videoInCache->SetTObjectValueL<TInt>( KVcxMediaMyVideosDownloadError, 0 ); |
|
642 videoInCache->SetTObjectValueL<TInt>( KVcxMediaMyVideosDownloadGlobalError, 0 ); |
|
643 } |
|
644 } |
|
645 |
|
646 CleanupStack::PopAndDestroy( video ); // <-1 |
|
647 done = ETrue; |
|
648 } |
|
649 break; |
|
650 |
|
651 case KVcxCommandMyVideosCancelDownload: |
|
652 { |
|
653 // Error code is returned to client if dl item was left to system. |
|
654 // If file delete fails, then mds item is also left to system. |
|
655 |
|
656 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: Handling KVcxCommandMyVideosCancelDownload command."); |
|
657 |
|
658 CMPXMedia* video = CMPXMedia::NewL( *(iActiveTask->GetCommand().Value<CMPXMedia>( |
|
659 KMPXCommandColAddMedia)) ); |
|
660 CleanupStack::PushL( video ); // 1-> |
|
661 |
|
662 if ( !video->IsSupported( KVcxMediaMyVideosDownloadId ) || |
|
663 !video->IsSupported( KMPXMediaGeneralId ) || |
|
664 !video->IsSupported( KMPXMediaGeneralUri ) ) |
|
665 { |
|
666 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: parameter missing, can't cancel dl, leaving with KErrArgument"); |
|
667 User::Leave( KErrArgument ); |
|
668 } |
|
669 |
|
670 TUint32 downloadId = video->ValueTObjectL<TUint32>( |
|
671 KVcxMediaMyVideosDownloadId ); |
|
672 DownloadUtilL().CancelDownload( downloadId, ETrue /* remove file */ ); |
|
673 |
|
674 if ( BaflUtils::FileExists( iFs, video->ValueText( KMPXMediaGeneralUri ) ) ) |
|
675 { |
|
676 TMPXItemId mpxItemId = video->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ); |
|
677 TInt err( KErrNone ); |
|
678 |
|
679 for ( TInt i = 0; i < KMaxFileDeleteAttempts; i++ ) |
|
680 { |
|
681 TRAP( err, AsyncFileOperationsL().DeleteVideoL( mpxItemId.iId1, ETrue ) ); |
|
682 |
|
683 if ( err == KErrInUse ) |
|
684 { |
|
685 MPX_DEBUG1( "CVcxMyVideosCollectionPlugin:: file is already in use, waiting a moment and try again"); |
|
686 User::After( KFileDeleteLoopDelay ); |
|
687 } |
|
688 else |
|
689 { |
|
690 break; |
|
691 } |
|
692 } |
|
693 |
|
694 if ( err != KErrNone && err != KErrNotFound ) |
|
695 { |
|
696 #ifdef _DEBUG |
|
697 if ( err == KErrInUse ) |
|
698 { |
|
699 TVcxMyVideosCollectionUtil::PrintOpenFileHandlesL( |
|
700 video->ValueText( KMPXMediaGeneralUri ), iFs ); |
|
701 } |
|
702 #endif |
|
703 |
|
704 // Some error occured when cancelling download operation, dl item is however gone and file is left |
|
705 // -> change dl id to 0 and leave mpx collection item there. Report operation to client as a success. |
|
706 MPX_DEBUG1( "CVcxMyVideosCollectionPlugin:: dl item is gone from dl manager, file and mpx item are left, setting dl id to 0"); |
|
707 TRAP_IGNORE( SetDownloadIdToZeroL( downloadId ) ); |
|
708 } |
|
709 } |
|
710 |
|
711 CleanupStack::PopAndDestroy( video ); // <-1 |
|
712 done = ETrue; |
|
713 } |
|
714 break; |
|
715 |
|
716 case KVcxCommandMyVideosPauseDownload: |
|
717 { |
|
718 CMPXMedia& cmd = iActiveTask->GetCommand(); |
|
719 if ( !cmd.IsSupported( KVcxMediaMyVideosDownloadId ) ) |
|
720 { |
|
721 User::Leave( KErrArgument ); |
|
722 } |
|
723 else |
|
724 { |
|
725 TInt err = DownloadUtilL().PauseDownload( |
|
726 cmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) ); |
|
727 User::LeaveIfError( err ); |
|
728 } |
|
729 done = ETrue; |
|
730 } |
|
731 break; |
|
732 |
|
733 case KVcxCommandMyVideosGetMediaFullDetailsByMpxId: |
|
734 { |
|
735 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosGetMediaFullDetailsByMpxId received"); |
|
736 CMPXMedia& cmd = iActiveTask->GetCommand(); |
|
737 TMPXItemId mpxId( TVcxMyVideosCollectionUtil::IdL( cmd ) ); |
|
738 if ( !mpxId.iId1 && !mpxId.iId2 ) |
|
739 { |
|
740 User::Leave( KErrArgument ); |
|
741 } |
|
742 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosGetMediaFullDetailsByMpxId cmd: MDS ID %d requested", mpxId.iId1 ); |
|
743 |
|
744 CMPXMedia* video = iMyVideosMdsDb->CreateVideoL( |
|
745 mpxId.iId1, ETrue /* full details */ ); |
|
746 |
|
747 if ( !video ) |
|
748 { |
|
749 User::Leave( KErrGeneral ); |
|
750 } |
|
751 |
|
752 CleanupStack::PushL( video ); // 1-> |
|
753 |
|
754 TBool eventsAdded; |
|
755 SyncVideoWithDownloadsL( *video, eventsAdded, |
|
756 EFalse /* dont add event to iMessageList */ ); |
|
757 |
|
758 cmd.SetCObjectValueL<CMPXMedia>( KMPXCommandColAddMedia, video ); |
|
759 CleanupStack::PopAndDestroy( video ); // <-1 |
|
760 |
|
761 cmd.SetTObjectValueL<TUid>(KMPXMessageCollectionId, TUid::Uid( |
|
762 KVcxUidMyVideosMpxCollection)); |
|
763 |
|
764 done = ETrue; |
|
765 } |
|
766 break; |
|
767 |
|
768 case KVcxCommandMyVideosGetMediasByMpxId: |
|
769 { |
|
770 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosGetMediasByMpxId received"); |
|
771 |
|
772 // Get ids from the request |
|
773 CMPXMedia& cmd = iActiveTask->GetCommand(); |
|
774 if ( !cmd.IsSupported( KMPXMediaArrayContents ) ) |
|
775 { |
|
776 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: error, no array defined"); |
|
777 User::Leave( KErrArgument ); |
|
778 } |
|
779 |
|
780 CMPXMediaArray* idMediaArray = cmd.Value<CMPXMediaArray>( |
|
781 KMPXMediaArrayContents ); |
|
782 |
|
783 if ( idMediaArray->Count() == 0 ) |
|
784 { |
|
785 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: error, no items in array "); |
|
786 User::Leave( KErrArgument ); |
|
787 } |
|
788 |
|
789 TMPXItemId mpxId; |
|
790 RArray<TUint32> mdsIds; |
|
791 RArray<TUint32> mdsIds2; |
|
792 mdsIds.Reset(); |
|
793 CleanupClosePushL( mdsIds ); // 1-> |
|
794 mdsIds2.Reset(); |
|
795 CleanupClosePushL( mdsIds2 ); // 2-> |
|
796 |
|
797 for ( TInt i = 0; i < idMediaArray->Count(); i++ ) |
|
798 { |
|
799 mpxId = (*idMediaArray)[i]->ValueTObjectL<TMPXItemId>( |
|
800 KMPXMessageMediaGeneralId ); |
|
801 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosGetMediasByMpxId cmd: MDS ID %d requested", |
|
802 mpxId.iId1 ); |
|
803 mdsIds.AppendL( mpxId.iId1 ); |
|
804 mdsIds2.AppendL( mpxId.iId1 ); |
|
805 } |
|
806 |
|
807 if ( !iCache->iVideoList ) |
|
808 { |
|
809 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: iVideoListCache = NULL -> creating new empty iCache->iVideoList"); |
|
810 iCache->iVideoListIsPartial = ETrue; |
|
811 iCache->iVideoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL(); |
|
812 } |
|
813 |
|
814 TBool videoListFetchingWasCancelled = EFalse; |
|
815 |
|
816 if ( iCache->iVideoListIsPartial ) |
|
817 { |
|
818 // Load items to cache |
|
819 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: loading requested items to iCache->iVideoList"); |
|
820 |
|
821 iCache->AddVideosFromMdsL( mdsIds, videoListFetchingWasCancelled ); |
|
822 if ( mdsIds.Count() > 0 ) |
|
823 { |
|
824 SyncWithDownloadsL( mdsIds ); |
|
825 } |
|
826 } |
|
827 else |
|
828 { |
|
829 // iCache->iVideoList contains all |
|
830 } |
|
831 |
|
832 CMPXMessage* message = iCache->GetVideosL( mdsIds2 ); |
|
833 CleanupStack::PushL( message ); // 3-> |
|
834 |
|
835 // Set message attributes |
|
836 // |
|
837 TMPXItemId itemId; |
|
838 itemId.iId1 = KVcxCommandIdMyVideos; |
|
839 message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, itemId ); |
|
840 message->SetTObjectValueL<TInt>( KVcxMediaMyVideosCommandId, |
|
841 KVcxMessageMyVideosGetMediasByMpxIdResp ); |
|
842 |
|
843 SetTransactionIdL( cmd, *message ); |
|
844 |
|
845 iMessageList->AddL( message ); |
|
846 iMessageList->SendL(); |
|
847 |
|
848 if ( videoListFetchingWasCancelled ) |
|
849 { |
|
850 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: video list fetching was cancelled, restarting"); |
|
851 RestartVideoListFetchingL(); |
|
852 } |
|
853 |
|
854 CleanupStack::Pop( message ); // <-3 |
|
855 CleanupStack::PopAndDestroy( &mdsIds2 ); // <-2 |
|
856 CleanupStack::PopAndDestroy( &mdsIds ); // <-1 |
|
857 |
|
858 done = ETrue; |
|
859 } |
|
860 break; |
|
861 |
|
862 case KVcxCommandMyVideosCopy: |
|
863 case KVcxCommandMyVideosMove: |
|
864 { |
|
865 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosMove or Copy step"); |
|
866 done = AsyncFileOperationsL().HandleMoveOrCopyStepL(); |
|
867 } |
|
868 break; |
|
869 |
|
870 case KVcxCommandMyVideosDelete: |
|
871 { |
|
872 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: KVcxCommandMyVideosDelete step"); |
|
873 done = AsyncFileOperationsL().HandleDeleteStepL(); |
|
874 } |
|
875 break; |
|
876 } |
|
877 } |
|
878 break; |
|
879 |
|
880 |
|
881 case KMPXCommandIdCollectionRemoveMedia: |
|
882 { |
|
883 TMPXItemId mpxId = iActiveTask->GetCommand().ValueTObjectL<TMPXItemId>( |
|
884 KMPXMediaGeneralId ); |
|
885 AsyncFileOperationsL().DeleteVideoL( mpxId.iId1 ); |
|
886 done = ETrue; |
|
887 break; |
|
888 } |
|
889 |
|
890 default: |
|
891 { |
|
892 // Should never happen! |
|
893 ASSERT(0); |
|
894 break; |
|
895 } |
|
896 } |
|
897 return done; |
|
898 } |
|
899 |
|
900 |
|
901 // ---------------------------------------------------------------------------- |
|
902 // Handler for async operations completed |
|
903 // ---------------------------------------------------------------------------- |
|
904 // |
|
905 void CVcxMyVideosCollectionPlugin::HandleOperationCompleted( |
|
906 TInt aErr ) |
|
907 { |
|
908 MPX_FUNC("CVcxMyVideosCollectionPlugin::HandleOperationCompleted"); |
|
909 |
|
910 if ( aErr != KErrNone ) |
|
911 { |
|
912 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: Leave or cancel happened during the operation: %d", aErr); |
|
913 TRAPD( err, AsyncFileOperationsL().CancelOperationL( aErr ) ); // generates resp message for move,copy or delete operations |
|
914 if ( err != KErrNone ) |
|
915 { |
|
916 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: failed to generate resp msg: %d", err); |
|
917 } |
|
918 } |
|
919 |
|
920 |
|
921 |
|
922 CMPXCommand& cmd = iActiveTask->GetCommand(); |
|
923 TRAP_IGNORE( cmd.SetTObjectValueL<TInt32>( KVcxMediaMyVideosInt32Value, aErr ) ); |
|
924 |
|
925 iObs->HandleCommandComplete( &cmd, KErrNone ); |
|
926 } |
|
927 |
|
928 // ---------------------------------------------------------------------------- |
|
929 // CVcxMyVideosCollectionPlugin::HandleDlEvent |
|
930 // From CVcxMyVideosDownloadUtilObserver |
|
931 // ---------------------------------------------------------------------------- |
|
932 // |
|
933 void CVcxMyVideosCollectionPlugin::HandleDlEvent( TVcxMyVideosDownloadState aState, |
|
934 TUint32 aDownloadId, |
|
935 TInt aProgress, |
|
936 TInt64 aDownloaded, |
|
937 TInt32 aError, |
|
938 TInt32 aGlobalError ) |
|
939 { |
|
940 TRAPD( err, DoHandleDlEventL( aState, aDownloadId, aProgress, |
|
941 aDownloaded, aError, aGlobalError ) ); |
|
942 if ( err != KErrNone ) |
|
943 { |
|
944 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: DoHandleDlEventL left with error code: %d", err); |
|
945 } |
|
946 } |
|
947 |
|
948 // ---------------------------------------------------------------------------- |
|
949 // CVcxMyVideosCollectionPlugin::DoHandleDlEventL |
|
950 // ---------------------------------------------------------------------------- |
|
951 // |
|
952 void CVcxMyVideosCollectionPlugin::DoHandleDlEventL( TVcxMyVideosDownloadState aState, |
|
953 TUint32 aDownloadId, |
|
954 TInt aProgress, |
|
955 TInt64 aDownloaded, |
|
956 TInt32 aError, |
|
957 TInt32 aGlobalError ) |
|
958 { |
|
959 MPX_FUNC("CVcxMyVideosCollectionPlugin::DoHandleDlEventL"); |
|
960 |
|
961 CMPXMedia* video = iCache->FindVideoByDownloadIdL( aDownloadId ); |
|
962 |
|
963 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: dl event for download ID %d, pointer = %x) arrived.", aDownloadId, video); |
|
964 |
|
965 TBool sendEvent = EFalse; |
|
966 if ( video ) |
|
967 { |
|
968 TMPXItemId mpxId( TVcxMyVideosCollectionUtil::IdL( *video ) ); |
|
969 MPX_DEBUG4("CVcxMyVideosCollectionPlugin:: MPX item (MDS ID %d) (DL ID %d) %S", |
|
970 mpxId.iId1, aDownloadId, &TVcxMyVideosCollectionUtil::Title( *video ) ); |
|
971 |
|
972 TUint8 currentState = TVcxMyVideosCollectionUtil::DownloadStateL( *video ); |
|
973 |
|
974 if ( currentState == EVcxMyVideosDlStateDownloaded ) |
|
975 { |
|
976 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: already in Downloaded state, discarding event"); |
|
977 return; |
|
978 } |
|
979 |
|
980 if ( currentState != aState ) |
|
981 { |
|
982 MPX_DEBUG5("CVcxMyVideosCollectionPlugin:: updating (mds id: %d) (dl id: %d) state: %S -> %S", |
|
983 mpxId.iId1, aDownloadId, &DownloadState( currentState ), &DownloadState( aState ) ); |
|
984 video->SetTObjectValueL<TUint8>( KVcxMediaMyVideosDownloadState, static_cast<TUint8>(aState) ); |
|
985 sendEvent = ETrue; |
|
986 |
|
987 if ( aState == EVcxMyVideosDlStateDownloaded ) |
|
988 { |
|
989 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: downloaded state received -> setting download id to 0"); |
|
990 |
|
991 //1. set download id to 0 |
|
992 video->SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId, 0 ); |
|
993 |
|
994 //2. update drm flag |
|
995 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
996 RFile64 dlFile; |
|
997 #else |
|
998 RFile dlFile; |
|
999 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1000 TInt err = dlFile.Open( iFs, video->ValueText( KMPXMediaGeneralUri ), EFileRead ); |
|
1001 if ( err == KErrNone ) |
|
1002 { |
|
1003 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: file opened ok for drm reading"); |
|
1004 CleanupClosePushL( dlFile ); // 1-> |
|
1005 DRM::CDrmUtility* drmUtil = DRM::CDrmUtility::NewLC(); // 2-> |
|
1006 if ( drmUtil->IsProtectedL( dlFile ) ) |
|
1007 { |
|
1008 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: file is DRM protected, setting the property flag"); |
|
1009 TUint32 flags = video->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags ); |
|
1010 flags |= EVcxMyVideosVideoDrmProtected; |
|
1011 video->SetTObjectValueL<TUint32>( KMPXMediaGeneralFlags, flags ); |
|
1012 } |
|
1013 else |
|
1014 { |
|
1015 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: file is not DRM protected"); |
|
1016 } |
|
1017 CleanupStack::PopAndDestroy( drmUtil ); // <-2 |
|
1018 CleanupStack::PopAndDestroy( &dlFile ); // <-1 |
|
1019 } |
|
1020 else |
|
1021 { |
|
1022 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: file didnt open for drm reading, %d", err); |
|
1023 } |
|
1024 NotifyDownloadCompletedL( *video ); |
|
1025 |
|
1026 //3. Update file size using iCache->UpdateVideoL function since it changes item position and |
|
1027 // sends category modified events if necessarry. |
|
1028 CMPXMedia* updateObject = CMPXMedia::NewL(); |
|
1029 CleanupStack::PushL( updateObject ); // 1-> |
|
1030 updateObject->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, mpxId ); |
|
1031 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1032 updateObject->SetTObjectValueL<TInt64>( KMPXMediaGeneralExtSizeInt64, |
|
1033 static_cast<TInt64>( aDownloaded ) ); |
|
1034 // set current value to 0 to force event sending and video list position updating |
|
1035 video->SetTObjectValueL<TInt64>( KMPXMediaGeneralExtSizeInt64, 0 ); |
|
1036 #else |
|
1037 updateObject->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, |
|
1038 static_cast<TInt>( aDownloaded ) ); |
|
1039 // set current value to 0 to force event sending and video list position updating |
|
1040 video->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, 0 ); |
|
1041 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1042 iCache->UpdateVideoL( *updateObject ); |
|
1043 CleanupStack::PopAndDestroy( updateObject ); // <-1 |
|
1044 // find video again since it might have been deleted in iCache->UpdateVideoL |
|
1045 TInt pos; |
|
1046 video = iCache->FindVideoByMdsIdL( mpxId.iId1, pos ); |
|
1047 |
|
1048 //file size and download id are saved to database |
|
1049 iMyVideosMdsDb->UpdateVideoL( *video ); |
|
1050 sendEvent = EFalse; // MDS will send the event, this avoids duplicate |
|
1051 } |
|
1052 |
|
1053 if ( aState == EVcxMyVideosDlStateFailed ) |
|
1054 { |
|
1055 video->SetTObjectValueL<TInt32>( KVcxMediaMyVideosDownloadError, aError ); |
|
1056 video->SetTObjectValueL<TInt32>( KVcxMediaMyVideosDownloadGlobalError, |
|
1057 aGlobalError ); |
|
1058 } |
|
1059 } |
|
1060 else |
|
1061 { |
|
1062 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: state was already same(%S), skipping state update.", &DownloadState( currentState )); |
|
1063 } |
|
1064 |
|
1065 TInt8 currentProgress = video->ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress ); |
|
1066 if ( currentProgress != aProgress ) |
|
1067 { |
|
1068 MPX_DEBUG4("CVcxMyVideosCollectionPlugin:: (dl id: %d) progress: %d -> %d", |
|
1069 aDownloadId, currentProgress, aProgress ); |
|
1070 |
|
1071 video->SetTObjectValueL<TInt8>( KVcxMediaMyVideosDownloadProgress, |
|
1072 static_cast<TInt8>( aProgress ) ); |
|
1073 // Don't send the update event for progress. |
|
1074 //sendEvent = ETrue; |
|
1075 } |
|
1076 else |
|
1077 { |
|
1078 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: progress was already same(%d), skipping progress update.", currentProgress); |
|
1079 } |
|
1080 |
|
1081 TInt64 currentFileSize = 0; |
|
1082 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1083 if ( video->IsSupported( KMPXMediaGeneralExtSizeInt64 ) ) |
|
1084 { |
|
1085 currentFileSize = video->ValueTObjectL<TInt64>( KMPXMediaGeneralExtSizeInt64 ); |
|
1086 } |
|
1087 #else |
|
1088 if ( video->IsSupported( KMPXMediaGeneralSize ) ) |
|
1089 { |
|
1090 currentFileSize = video->ValueTObjectL<TInt>( KMPXMediaGeneralSize ); |
|
1091 } |
|
1092 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1093 if ( currentFileSize != aDownloaded ) |
|
1094 { |
|
1095 MPX_DEBUG4("CVcxMyVideosCollectionPlugin:: updating (dl id: %d) size: %ld -> %ld", |
|
1096 aDownloadId, currentFileSize, aDownloaded ); |
|
1097 |
|
1098 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1099 video->SetTObjectValueL<TInt64>( KMPXMediaGeneralExtSizeInt64, aDownloaded ); |
|
1100 #else |
|
1101 TInt newFileSize( aDownloaded ); |
|
1102 video->SetTObjectValueL<TInt>( KMPXMediaGeneralSize, newFileSize ); |
|
1103 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
1104 //sendEvent = ETrue; |
|
1105 } |
|
1106 |
|
1107 if ( sendEvent ) |
|
1108 { |
|
1109 iMessageList->AddEventL( mpxId, EMPXItemModified ); |
|
1110 iMessageList->SendL(); |
|
1111 } |
|
1112 } |
|
1113 else |
|
1114 { |
|
1115 if ( (aState != EVcxMyVideosDlStateDownloaded) && (aProgress < 100) && |
|
1116 !iCache->iVideoListIsPartial ) |
|
1117 { |
|
1118 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -----------------------------------------------------------------------."); |
|
1119 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: Event for progressing download arrived, but the MPX/MDS item not found!|"); |
|
1120 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -> deleting download. |"); |
|
1121 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -----------------------------------------------------------------------'"); |
|
1122 |
|
1123 RHttpDownload* download = DownloadUtilL().Download( aDownloadId ); |
|
1124 if ( download ) |
|
1125 { |
|
1126 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: Download ID (%d) not found from MPX/MDS, deleting download!", |
|
1127 aDownloadId ); |
|
1128 DownloadUtilL().DeleteDownloadAsync( aDownloadId, ETrue ); |
|
1129 } |
|
1130 } |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 // ---------------------------------------------------------------------------- |
|
1135 // CVcxMyVideosCollectionPlugin::SyncWithDownloadsL |
|
1136 // ---------------------------------------------------------------------------- |
|
1137 // |
|
1138 void CVcxMyVideosCollectionPlugin::SyncWithDownloadsL( |
|
1139 RArray<TUint32>& aItemsInCache ) |
|
1140 { |
|
1141 MPX_FUNC("CVcxMyVideosCollectionPlugin::SyncWithDownloadsL()"); |
|
1142 |
|
1143 TBool eventsAdded = EFalse; |
|
1144 for ( TInt i = 0; i < aItemsInCache.Count(); i++ ) |
|
1145 { |
|
1146 TInt pos; |
|
1147 CMPXMedia* video = iCache->FindVideoByMdsIdL( aItemsInCache[i], pos ); |
|
1148 if ( video ) |
|
1149 { |
|
1150 SyncVideoWithDownloadsL( *video, eventsAdded ); |
|
1151 } |
|
1152 } |
|
1153 if ( eventsAdded ) |
|
1154 { |
|
1155 iMessageList->SendL(); |
|
1156 } |
|
1157 } |
|
1158 |
|
1159 // ---------------------------------------------------------------------------- |
|
1160 // CVcxMyVideosCollectionPlugin::SyncVideoWithDownloadsL |
|
1161 // ---------------------------------------------------------------------------- |
|
1162 // |
|
1163 void CVcxMyVideosCollectionPlugin::SyncVideoWithDownloadsL( CMPXMedia& aVideo, |
|
1164 TBool& aEventAdded, TBool aAddEvent ) |
|
1165 { |
|
1166 TInt downloadId( TVcxMyVideosCollectionUtil::DownloadIdL( aVideo ) ); |
|
1167 |
|
1168 if ( downloadId ) |
|
1169 { |
|
1170 RHttpDownload* download( DownloadUtilL().Download( downloadId ) ); |
|
1171 |
|
1172 if ( download ) |
|
1173 { |
|
1174 MPX_DEBUG2("CVcxMyVideosCollectionPlugin::SyncVideoWithDownloadsL() item (DL ID: %d) found from dl manager", downloadId); |
|
1175 |
|
1176 TBool modified = EFalse; |
|
1177 SyncVideoAndDownloadL( aVideo, *download, modified ); |
|
1178 if ( modified && aAddEvent ) |
|
1179 { |
|
1180 iMessageList->AddEventL( TVcxMyVideosCollectionUtil::IdL( aVideo ), |
|
1181 EMPXItemModified ); |
|
1182 aEventAdded = ETrue; |
|
1183 } |
|
1184 } |
|
1185 else |
|
1186 { |
|
1187 //download id != 0 and it is not found from download manager -> we set download id to 0 |
|
1188 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: download id %d != 0 and no corresponding download found from Download Manager", |
|
1189 downloadId); |
|
1190 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -> setting download id to 0"); |
|
1191 aVideo.SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId, 0 ); |
|
1192 iMyVideosMdsDb->UpdateVideoL( aVideo ); // if video list fetching is ongoing, this will leave with KErrNotReady |
|
1193 } |
|
1194 } |
|
1195 } |
|
1196 |
|
1197 // ---------------------------------------------------------------------------- |
|
1198 // CVcxMyVideosCollectionPlugin::SyncVideoAndDownloadL |
|
1199 // ---------------------------------------------------------------------------- |
|
1200 // |
|
1201 void CVcxMyVideosCollectionPlugin::SyncVideoAndDownloadL( |
|
1202 CMPXMedia& aVideo, |
|
1203 RHttpDownload& aDownload, |
|
1204 TBool& aModified ) |
|
1205 { |
|
1206 MPX_FUNC("CVcxMyVideosCollectionPlugin::SyncVideoAndDownloadL()"); |
|
1207 |
|
1208 aModified = EFalse; |
|
1209 |
|
1210 TBuf<KMaxUrlLength> downloadUrl; |
|
1211 aDownload.GetStringAttribute( EDlAttrReqUrl, downloadUrl ); |
|
1212 if ( aVideo.ValueText( KVcxMediaMyVideosRemoteUrl ) |
|
1213 != downloadUrl ) |
|
1214 { |
|
1215 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: urls in MPX and DL Manager differ!"); |
|
1216 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: remote url in MPX: %S", |
|
1217 &(aVideo.ValueText( KVcxMediaMyVideosRemoteUrl ))); |
|
1218 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: remote url in DL Manager: %S", |
|
1219 &downloadUrl); |
|
1220 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -> updating MPX cache"); |
|
1221 |
|
1222 aVideo.SetTextValueL( KVcxMediaMyVideosRemoteUrl, downloadUrl ); |
|
1223 aModified = ETrue; |
|
1224 } |
|
1225 else |
|
1226 { |
|
1227 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: remote urls already same in dl manager and mpx"); |
|
1228 } |
|
1229 |
|
1230 // KVcxMediaMyVideosDownloadState |
|
1231 TVcxMyVideosDownloadState dlStateInDlManager; |
|
1232 DownloadUtilL().GetDownloadState( aDownload, dlStateInDlManager ); |
|
1233 |
|
1234 TUint8 dlStateInMpxCache; |
|
1235 if ( aVideo.IsSupported( KVcxMediaMyVideosDownloadState )) |
|
1236 { |
|
1237 dlStateInMpxCache = aVideo.ValueTObjectL<TUint8>( KVcxMediaMyVideosDownloadState ); |
|
1238 } |
|
1239 else |
|
1240 { |
|
1241 dlStateInMpxCache = static_cast<TUint8>( EVcxMyVideosDlStateNone ); |
|
1242 } |
|
1243 |
|
1244 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: dl state in dl manager: %S", &DownloadState( dlStateInDlManager )); |
|
1245 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: dl state in mpx cache: %S", &DownloadState( dlStateInMpxCache )); |
|
1246 |
|
1247 if ( static_cast<TUint8>( dlStateInDlManager ) != dlStateInMpxCache ) |
|
1248 { |
|
1249 if ( dlStateInDlManager == EVcxMyVideosDlStateDownloaded ) |
|
1250 { |
|
1251 // Download finished event has arrived when we weren't around, call event handler to get things right. |
|
1252 // Collection is updated and download is deleted from Download Manager. |
|
1253 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: Download is in Finished state and collection has download id != 0"); |
|
1254 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: -> we have missed download finished event, lets generate it by ourselves."); |
|
1255 |
|
1256 TUint64 downloaded( 0 ); |
|
1257 TUint8 progress( DownloadUtilL().DownloadProgress( aDownload, downloaded, EFalse ) ); |
|
1258 TUint32 downloadId( aVideo.ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) ); |
|
1259 HandleDlEvent( dlStateInDlManager, downloadId, |
|
1260 progress, downloaded, KErrNone, KErrNone ); |
|
1261 DownloadUtilL().DeleteDownloadAsync( downloadId, EFalse /* don't delete content */ ); |
|
1262 } |
|
1263 else |
|
1264 { |
|
1265 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: dl state in dl manager differs of mpx cache-> updating mpx cache"); |
|
1266 aVideo.SetTObjectValueL<TUint8>( KVcxMediaMyVideosDownloadState, |
|
1267 static_cast<TUint8>( dlStateInDlManager ) ); |
|
1268 aModified = ETrue; |
|
1269 } |
|
1270 } |
|
1271 else |
|
1272 { |
|
1273 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: download state already same in dl manager and mds"); |
|
1274 } |
|
1275 |
|
1276 // KVcxMediaMyVideosDownloadProgress |
|
1277 TUint64 downloaded = 0; |
|
1278 TInt8 dlProgressInDlManager = DownloadUtilL().DownloadProgress( |
|
1279 aDownload, downloaded, EFalse ); |
|
1280 |
|
1281 TInt8 dlProgressInMpxCache; |
|
1282 if ( aVideo.IsSupported( KVcxMediaMyVideosDownloadProgress ) ) |
|
1283 { |
|
1284 dlProgressInMpxCache = aVideo.ValueTObjectL<TInt8>( KVcxMediaMyVideosDownloadProgress ); |
|
1285 } |
|
1286 else |
|
1287 { |
|
1288 aVideo.SetTObjectValueL<TInt8>( KVcxMediaMyVideosDownloadProgress, 0 ); |
|
1289 dlProgressInMpxCache = 0; |
|
1290 } |
|
1291 |
|
1292 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: dl progress in dl manager: %d", dlProgressInDlManager); |
|
1293 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: dl progress in mpx cache: %d", dlProgressInMpxCache); |
|
1294 |
|
1295 if ( dlProgressInDlManager != dlProgressInMpxCache ) |
|
1296 { |
|
1297 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: dl progress in dl manager differs of mpx cache-> updating mpx cache"); |
|
1298 aVideo.SetTObjectValueL<TInt8>( KVcxMediaMyVideosDownloadProgress, |
|
1299 static_cast<TInt8>( dlProgressInDlManager ) ); |
|
1300 aModified = ETrue; |
|
1301 } |
|
1302 else |
|
1303 { |
|
1304 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: download progress already same in dl manager and mds"); |
|
1305 } |
|
1306 } |
|
1307 |
|
1308 // ---------------------------------------------------------------------------- |
|
1309 // CVcxMyVideosCollectionPlugin::SyncVideoListWithDownloadsL |
|
1310 // ---------------------------------------------------------------------------- |
|
1311 // |
|
1312 void CVcxMyVideosCollectionPlugin::SyncVideoListWithDownloadsL( CMPXMedia& aVideoList, |
|
1313 TBool aSendEvents, TInt aStartPos ) |
|
1314 { |
|
1315 MPX_FUNC("CVcxMyVideosCollectionPlugin::SyncVideoListWithDownloadsL"); |
|
1316 |
|
1317 CMPXMediaArray* videoArray = aVideoList.Value<CMPXMediaArray>( |
|
1318 KMPXMediaArrayContents); |
|
1319 |
|
1320 CMPXMedia* video; |
|
1321 |
|
1322 TBool eventsAdded = EFalse; |
|
1323 for ( TInt i = aStartPos; i < videoArray->Count(); i++ ) |
|
1324 { |
|
1325 video = (*videoArray)[i]; |
|
1326 SyncVideoWithDownloadsL( *video, eventsAdded, aSendEvents ); |
|
1327 } |
|
1328 if ( eventsAdded ) |
|
1329 { |
|
1330 iMessageList->SendL(); |
|
1331 } |
|
1332 } |
|
1333 |
|
1334 // ---------------------------------------------------------------------------- |
|
1335 // CVcxMyVideosCollectionPlugin::DownloadUtil |
|
1336 // ---------------------------------------------------------------------------- |
|
1337 // |
|
1338 CVcxMyVideosDownloadUtil& CVcxMyVideosCollectionPlugin::DownloadUtilL() |
|
1339 { |
|
1340 if ( !iDownloadUtil ) |
|
1341 { |
|
1342 iDownloadUtil = CVcxMyVideosDownloadUtil::NewL( *this, iFs ); |
|
1343 } |
|
1344 |
|
1345 if ( !iOrphanDownloadsCleared ) |
|
1346 { |
|
1347 if ( !iCache->iVideoListIsPartial ) |
|
1348 { |
|
1349 iOrphanDownloadsCleared = ETrue; |
|
1350 iDownloadUtil->ClearOrphanDownloadsL( *iCache->iVideoList ); |
|
1351 } |
|
1352 } |
|
1353 |
|
1354 return *iDownloadUtil; |
|
1355 } |
|
1356 |
|
1357 // ---------------------------------------------------------------------------- |
|
1358 // CVcxMyVideosCollectionPlugin::CategoriesL |
|
1359 // ---------------------------------------------------------------------------- |
|
1360 // |
|
1361 CVcxMyVideosCategories& CVcxMyVideosCollectionPlugin::CategoriesL() |
|
1362 { |
|
1363 if ( !iCategories ) |
|
1364 { |
|
1365 iCategories = CVcxMyVideosCategories::NewL( *this ); |
|
1366 } |
|
1367 return *iCategories; |
|
1368 } |
|
1369 |
|
1370 // ---------------------------------------------------------------------------- |
|
1371 // CVcxMyVideosCollectionPlugin::HandleCreateVideoListResp |
|
1372 // ---------------------------------------------------------------------------- |
|
1373 // |
|
1374 void CVcxMyVideosCollectionPlugin::HandleCreateVideoListResp( |
|
1375 CMPXMedia* aVideoList, TInt aNewItemsStartIndex, TBool aComplete ) |
|
1376 { |
|
1377 TRAPD( err, iOpenHandler->DoHandleCreateVideoListRespL( aVideoList, aNewItemsStartIndex, aComplete )); |
|
1378 if ( err != KErrNone ) |
|
1379 { |
|
1380 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: DoHandleCreateVideoListRespL() left with error code: %d", err ); |
|
1381 } |
|
1382 } |
|
1383 |
|
1384 // ---------------------------------------------------------------------------- |
|
1385 // CVcxMyVideosCollectionPlugin::RestartVideoListFetchingL |
|
1386 // Called when video list fetching is interrupted due to "get item by mpx id" |
|
1387 // request, or sorting order change. Or by some other reason that requires |
|
1388 // new video list fetching. iCache->iVideoList media array has been reset, Ie lists are the |
|
1389 // the same but items have been deleted. |
|
1390 // ---------------------------------------------------------------------------- |
|
1391 // |
|
1392 void CVcxMyVideosCollectionPlugin::RestartVideoListFetchingL() |
|
1393 { |
|
1394 MPX_FUNC("CVcxMyVideosCollectionPlugin::RestartVideoListFetchingL()"); |
|
1395 |
|
1396 // Client already had something on the list. |
|
1397 // -> tell client to fetch everything from scratch again. |
|
1398 MPX_DEBUG1("CVcxMyVideosCollectionPlugin:: open was not pending, client had something on the list"); |
|
1399 MPX_DEBUG1(" -> telling client to fetch everything from the scratch again"); |
|
1400 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: adding modify event for path root, extra info = %d", |
|
1401 EVcxMyVideosVideoListOrderChanged ); |
|
1402 |
|
1403 iCache->ResetVideoListL(); |
|
1404 |
|
1405 iMessageList->AddEventL( TMPXItemId( KVcxUidMyVideosMpxCollection, |
|
1406 KVcxUidMyVideosMpxCollection ), EMPXItemModified, |
|
1407 EVcxMyVideosVideoListOrderChanged ); |
|
1408 iMessageList->SendL(); |
|
1409 } |
|
1410 |
|
1411 // ---------------------------------------------------------------------------- |
|
1412 // CVcxMyVideosCollectionPlugin::SetVideoL |
|
1413 // ---------------------------------------------------------------------------- |
|
1414 // |
|
1415 void CVcxMyVideosCollectionPlugin::SetVideoL( CMPXMedia& aVideo ) |
|
1416 { |
|
1417 TRAPD( leave, iCache->UpdateVideoL( aVideo ) ); |
|
1418 |
|
1419 if ( leave == KErrNone ) |
|
1420 { |
|
1421 TMPXItemId mpxId( TVcxMyVideosCollectionUtil::IdL( aVideo ) ); |
|
1422 |
|
1423 TInt pos; |
|
1424 CMPXMedia* videoInCache = iCache->FindVideoByMdsIdL( mpxId, pos ); |
|
1425 |
|
1426 if ( videoInCache ) |
|
1427 { |
|
1428 iMyVideosMdsDb->UpdateVideoL( *videoInCache ); |
|
1429 } |
|
1430 } |
|
1431 else if ( leave == KErrNotFound ) |
|
1432 { |
|
1433 iMyVideosMdsDb->UpdateVideoL( aVideo ); |
|
1434 } |
|
1435 else |
|
1436 { |
|
1437 User::Leave( leave ); |
|
1438 } |
|
1439 } |
|
1440 |
|
1441 // ---------------------------------------------------------------------------- |
|
1442 // CVcxMyVideosCollectionPlugin::NotifyDownloadCompletedL |
|
1443 // ---------------------------------------------------------------------------- |
|
1444 // |
|
1445 void CVcxMyVideosCollectionPlugin::NotifyDownloadCompletedL( CMPXMedia& aVideo ) |
|
1446 { |
|
1447 const TInt KMediaExtSize( 8 ); |
|
1448 |
|
1449 HBufC8* buffer = HBufC8::NewL( KMediaExtSize ); |
|
1450 CleanupStack::PushL( buffer ); |
|
1451 TPtr8 des = buffer->Des(); |
|
1452 |
|
1453 RDesWriteStream stream; |
|
1454 CleanupClosePushL( stream ); |
|
1455 stream.Open( des ); |
|
1456 |
|
1457 aVideo.ExternalizeL( stream ); |
|
1458 |
|
1459 stream.CommitL(); |
|
1460 |
|
1461 CleanupStack::PopAndDestroy( &stream ); |
|
1462 |
|
1463 DownloadUtilL().NotifyDownloadCompleted( *buffer ); |
|
1464 |
|
1465 CleanupStack::PopAndDestroy( buffer ); |
|
1466 } |
|
1467 |
|
1468 // ---------------------------------------------------------------------------- |
|
1469 // CVcxMyVideosCollectionPlugin::NotifyNewVideosCountDecreasedL |
|
1470 // ---------------------------------------------------------------------------- |
|
1471 // |
|
1472 void CVcxMyVideosCollectionPlugin::NotifyNewVideosCountDecreasedL( CMPXMedia& aVideo ) |
|
1473 { |
|
1474 const TInt KMediaExtSize( 8 ); |
|
1475 |
|
1476 HBufC8* buffer = HBufC8::NewL( KMediaExtSize ); |
|
1477 CleanupStack::PushL( buffer ); |
|
1478 TPtr8 des = buffer->Des(); |
|
1479 |
|
1480 RDesWriteStream stream; |
|
1481 CleanupClosePushL( stream ); |
|
1482 stream.Open( des ); |
|
1483 |
|
1484 aVideo.ExternalizeL( stream ); |
|
1485 |
|
1486 stream.CommitL(); |
|
1487 |
|
1488 CleanupStack::PopAndDestroy( &stream ); |
|
1489 |
|
1490 DownloadUtilL().NotifyNewVideosCountDecreased( *buffer ); |
|
1491 |
|
1492 CleanupStack::PopAndDestroy( buffer ); |
|
1493 } |
|
1494 |
|
1495 // ---------------------------------------------------------------------------- |
|
1496 // CVcxMyVideosCollectionPlugin::AddVideoToMdsAndCacheL |
|
1497 // ---------------------------------------------------------------------------- |
|
1498 // |
|
1499 void CVcxMyVideosCollectionPlugin::AddVideoToMdsAndCacheL( CMPXMedia& aVideo ) |
|
1500 { |
|
1501 MPX_FUNC("CVcxMyVideosCollectionPlugin::AddVideoToMdsAndCacheL"); |
|
1502 |
|
1503 TMPXItemId mpxId; |
|
1504 iMyVideosMdsDb->AddVideoL( aVideo, mpxId.iId1 ); |
|
1505 |
|
1506 aVideo.SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, mpxId ); |
|
1507 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: new MDS ID: %d", mpxId.iId1 ); |
|
1508 |
|
1509 RArray<TUint32> ids; |
|
1510 ids.Reset(); |
|
1511 CleanupClosePushL( ids ); // 1-> |
|
1512 ids.AppendL( mpxId.iId1 ); |
|
1513 HandleMyVideosDbEvent( EMPXItemInserted, ids ); //this will fetch from mds to cache and sync with downloads |
|
1514 CleanupStack::PopAndDestroy( &ids ); // <-1 |
|
1515 } |
|
1516 |
|
1517 // ---------------------------------------------------------------------------- |
|
1518 // CVcxMyVideosCollectionPlugin::SetTransactionIdL |
|
1519 // ---------------------------------------------------------------------------- |
|
1520 // |
|
1521 void CVcxMyVideosCollectionPlugin::SetTransactionIdL( CMPXMedia& aRequest, CMPXMedia& aResp ) |
|
1522 { |
|
1523 if ( aRequest.IsSupported( KVcxMediaMyVideosTransactionId ) ) |
|
1524 { |
|
1525 TUint32 transactionId( aRequest.ValueTObjectL<TUint32>( KVcxMediaMyVideosTransactionId )); |
|
1526 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: transaction ID: %d", transactionId ); |
|
1527 aResp.SetTObjectValueL<TUint32>( KVcxMediaMyVideosTransactionId, transactionId ); |
|
1528 } |
|
1529 } |
|
1530 |
|
1531 // ---------------------------------------------------------------------------- |
|
1532 // CVcxMyVideosCollectionPlugin::SendMyVideosMessageL |
|
1533 // ---------------------------------------------------------------------------- |
|
1534 // |
|
1535 void CVcxMyVideosCollectionPlugin::SendMyVideosMessageL( |
|
1536 TUint32 aMessageId, CMPXCommand* aCommand ) |
|
1537 { |
|
1538 CMPXMessage* message = CMPXMessage::NewL(); |
|
1539 CleanupStack::PushL( message ); // 1-> |
|
1540 TMPXItemId itemId; |
|
1541 itemId.iId1 = KVcxCommandIdMyVideos; |
|
1542 message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, itemId ); |
|
1543 message->SetTObjectValueL<TInt>( KVcxMediaMyVideosCommandId, |
|
1544 aMessageId ); |
|
1545 |
|
1546 if ( aCommand ) |
|
1547 { |
|
1548 SetTransactionIdL( *aCommand, *message ); |
|
1549 } |
|
1550 else |
|
1551 { |
|
1552 message->SetTObjectValueL<TUint32>( KVcxMediaMyVideosTransactionId, 0 ); |
|
1553 } |
|
1554 |
|
1555 iMessageList->AddL( message ); |
|
1556 CleanupStack::Pop( message ); // <-1 |
|
1557 iMessageList->SendL(); |
|
1558 } |
|
1559 |
|
1560 // ---------------------------------------------------------------------------- |
|
1561 // CVcxMyVideosCollectionPlugin::AsyncFileOperationsL |
|
1562 // ---------------------------------------------------------------------------- |
|
1563 // |
|
1564 CVcxMyVideosAsyncFileOperations& CVcxMyVideosCollectionPlugin::AsyncFileOperationsL() |
|
1565 { |
|
1566 if ( !iAsyncFileOperations ) |
|
1567 { |
|
1568 iAsyncFileOperations = CVcxMyVideosAsyncFileOperations::NewL( *this ); |
|
1569 } |
|
1570 return *iAsyncFileOperations; |
|
1571 } |
|
1572 |
|
1573 // ---------------------------------------------------------------------------- |
|
1574 // CVcxMyVideosCollectionPlugin::HandleObjectPresentNotification |
|
1575 // From MVcxMyVideosMdsDbObserver. Called when media is inserted/removed. |
|
1576 // ---------------------------------------------------------------------------- |
|
1577 // |
|
1578 void CVcxMyVideosCollectionPlugin::HandleObjectPresentNotification() |
|
1579 { |
|
1580 TRAPD( err, DoHandleObjectPresentNotificationL() ); |
|
1581 |
|
1582 if ( err != KErrNone ) |
|
1583 { |
|
1584 MPX_DEBUG2("CVcxMyVideosCollectionPlugin::DoHandleObjectPresentNotificationL() left with code %d", err); |
|
1585 } |
|
1586 } |
|
1587 |
|
1588 // ---------------------------------------------------------------------------- |
|
1589 // CVcxMyVideosCollectionPlugin::DoHandleObjectPresentNotificationL |
|
1590 // ---------------------------------------------------------------------------- |
|
1591 // |
|
1592 void CVcxMyVideosCollectionPlugin::DoHandleObjectPresentNotificationL() |
|
1593 { |
|
1594 iCache->ResetVideoListL(); |
|
1595 |
|
1596 MPX_DEBUG2("CVcxMyVideosCollectionPlugin:: adding modify event for path root, extra info = %d", |
|
1597 EVcxMyVideosVideoListOrderChanged ); |
|
1598 iMessageList->AddEventL( TMPXItemId( KVcxUidMyVideosMpxCollection, |
|
1599 KVcxUidMyVideosMpxCollection ), EMPXItemModified, EVcxMyVideosVideoListOrderChanged ); |
|
1600 |
|
1601 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: adding modify event for category[%d], extra info = %d", |
|
1602 KVcxMvcCategoryIdAll, EVcxMyVideosVideoListOrderChanged ); |
|
1603 iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdAll, 1 ), EMPXItemModified, |
|
1604 EVcxMyVideosVideoListOrderChanged ); |
|
1605 |
|
1606 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: adding modify event for category[%d], extra info = %d", |
|
1607 KVcxMvcCategoryIdDownloads, EVcxMyVideosVideoListOrderChanged ); |
|
1608 iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdDownloads, 1 ), EMPXItemModified, |
|
1609 EVcxMyVideosVideoListOrderChanged ); |
|
1610 |
|
1611 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: adding modify event for category[%d], extra info = %d", |
|
1612 KVcxMvcCategoryIdTvRecordings, EVcxMyVideosVideoListOrderChanged ); |
|
1613 iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdTvRecordings, 1 ), EMPXItemModified, |
|
1614 EVcxMyVideosVideoListOrderChanged ); |
|
1615 |
|
1616 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: adding modify event for category[%d], extra info = %d", |
|
1617 KVcxMvcCategoryIdCaptured, EVcxMyVideosVideoListOrderChanged ); |
|
1618 iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdCaptured, 1 ), EMPXItemModified, |
|
1619 EVcxMyVideosVideoListOrderChanged ); |
|
1620 |
|
1621 MPX_DEBUG3("CVcxMyVideosCollectionPlugin:: adding modify event for category[%d], extra info = %d", |
|
1622 KVcxMvcCategoryIdOther, EVcxMyVideosVideoListOrderChanged ); |
|
1623 iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdOther, 1 ), EMPXItemModified, |
|
1624 EVcxMyVideosVideoListOrderChanged ); |
|
1625 |
|
1626 iMessageList->SendL(); |
|
1627 } |
|
1628 |
|
1629 // ---------------------------------------------------------------------------- |
|
1630 // CVcxMyVideosCollectionPlugin::SetDownloadIdToZeroL |
|
1631 // ---------------------------------------------------------------------------- |
|
1632 // |
|
1633 void CVcxMyVideosCollectionPlugin::SetDownloadIdToZeroL( TUint aDownloadId ) |
|
1634 { |
|
1635 CMPXMedia* video = iCache->FindVideoByDownloadIdL( aDownloadId ); |
|
1636 if ( video ) |
|
1637 { |
|
1638 video->SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId, 0 ); |
|
1639 video->SetTObjectValueL<TUint8>( KVcxMediaMyVideosDownloadState, |
|
1640 static_cast<TUint8>( EVcxMyVideosDlStateNone ) ); |
|
1641 iMyVideosMdsDb->UpdateVideoL( *video ); |
|
1642 iMessageList->AddEventL( TVcxMyVideosCollectionUtil::IdL( |
|
1643 *video ), EMPXItemModified ); |
|
1644 iMessageList->SendL(); |
|
1645 } |
|
1646 } |
|
1647 |
|
1648 #ifdef _DEBUG |
|
1649 // ---------------------------------------------------------------------------- |
|
1650 // CVcxMyVideosCollectionPlugin::DownloadState |
|
1651 // ---------------------------------------------------------------------------- |
|
1652 // |
|
1653 const TDesC& CVcxMyVideosCollectionPlugin::DownloadState( TUint8 aDlState ) |
|
1654 { |
|
1655 _LIT(KDlStateNoneDes, "None"); |
|
1656 _LIT(KDlStateDownloadingDes, "Downloading"); |
|
1657 _LIT(KDlStateFailedDes, "Failed"); |
|
1658 _LIT(KDlStatePausedDes, "Paused"); |
|
1659 _LIT(KDlStateDownloadedDes, "Downloaded"); |
|
1660 |
|
1661 switch ( aDlState ) |
|
1662 { |
|
1663 case EVcxMyVideosDlStateNone: |
|
1664 return KDlStateNoneDes; |
|
1665 case EVcxMyVideosDlStateDownloading: |
|
1666 return KDlStateDownloadingDes; |
|
1667 case EVcxMyVideosDlStateFailed: |
|
1668 return KDlStateFailedDes; |
|
1669 case EVcxMyVideosDlStatePaused: |
|
1670 return KDlStatePausedDes; |
|
1671 case EVcxMyVideosDlStateDownloaded: |
|
1672 return KDlStateDownloadedDes; |
|
1673 default: |
|
1674 return KNullDesC; |
|
1675 } |
|
1676 } |
|
1677 #endif |
|
1678 |