|
1 /* |
|
2 * Copyright (c) 2006 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: Simple plugin to cache media objects |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32cmn.h> |
|
21 #include <mpxcollectionpath.h> |
|
22 #include <mpxcollectionpluginobserver.h> |
|
23 #include <mpxcmn.h> |
|
24 #include <mpxmediageneraldefs.h> |
|
25 #include <mpxmediacontainerdefs.h> |
|
26 #include <mpxmediamusicdefs.h> |
|
27 #include <mpxmediaaudiodefs.h> |
|
28 #include <mpxmessagegeneraldefs.h> |
|
29 #include <mpxcollectionmessagedefs.h> |
|
30 #include <mpxmediacollectiondetaildefs.h> |
|
31 #include <mpxcollectioncommanddefs.h> |
|
32 #include <mpxcommandgeneraldefs.h> |
|
33 #include <mpxmedia.h> |
|
34 #include <mpxmediaarray.h> |
|
35 #include <mpxdrmmediautility.h> |
|
36 #include <mpxmediadrmdefs.h> |
|
37 #include <mpxlog.h> |
|
38 |
|
39 #include "mpxinmemoryplugin.h" |
|
40 |
|
41 // CONSTANTS |
|
42 const TInt KIMPluginUid = 0x101FFCD8; |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS ============================== |
|
45 // ---------------------------------------------------------------------------- |
|
46 // Two-phased constructor. |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CMPXInMemoryPlugin* CMPXInMemoryPlugin::NewL() |
|
50 { |
|
51 CMPXInMemoryPlugin* p = new (ELeave) CMPXInMemoryPlugin(); |
|
52 CleanupStack::PushL(p); |
|
53 p->ConstructL(); |
|
54 CleanupStack::Pop(p); |
|
55 return p; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // Destructor |
|
60 // ---------------------------------------------------------------------------- |
|
61 // |
|
62 CMPXInMemoryPlugin::~CMPXInMemoryPlugin() |
|
63 { |
|
64 delete iDrmMediaUtility; |
|
65 |
|
66 // Cleanup Arrays |
|
67 iTemporaryData.ResetAndDestroy(); |
|
68 iTemporaryData.Close(); |
|
69 iEmbeddedContext.Reset(); |
|
70 iEmbeddedContext.Close(); |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // Constructor |
|
75 // ---------------------------------------------------------------------------- |
|
76 // |
|
77 CMPXInMemoryPlugin::CMPXInMemoryPlugin() |
|
78 { |
|
79 } |
|
80 |
|
81 // ---------------------------------------------------------------------------- |
|
82 // Symbian 2nd phase constructor can leave. |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 void CMPXInMemoryPlugin::ConstructL() |
|
86 { |
|
87 iDrmMediaUtility = CMPXDrmMediaUtility::NewL(); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // Navigates to the given path |
|
92 // ---------------------------------------------------------------------------- |
|
93 // |
|
94 void CMPXInMemoryPlugin::OpenL( |
|
95 const CMPXCollectionPath& aPath, |
|
96 const TArray<TMPXAttribute>& /*aAttrs*/, |
|
97 CMPXFilter* /*aFilter*/) |
|
98 { |
|
99 // Media object to return |
|
100 RArray<TInt> supportedIds; |
|
101 CleanupClosePushL(supportedIds); |
|
102 supportedIds.AppendL(KMPXMediaIdContainer); |
|
103 supportedIds.AppendL(KMPXMediaIdGeneral); |
|
104 CMPXMedia* entries=CMPXMedia::NewL(supportedIds.Array()); |
|
105 CleanupStack::PushL(entries); |
|
106 |
|
107 // Media array for items |
|
108 CMPXMediaArray* array=CMPXMediaArray::NewL(); |
|
109 CleanupStack::PushL(array); |
|
110 |
|
111 // Based on Path, what is the embedded client context id? |
|
112 TInt depth = aPath.Levels(); |
|
113 TBool oneSong = EFalse; |
|
114 TInt err = KErrNone; |
|
115 switch( depth ) |
|
116 { |
|
117 case 1: // should not have anything |
|
118 { |
|
119 User::Leave( KErrArgument ); |
|
120 break; |
|
121 } |
|
122 case 2: // an item or a playlist |
|
123 { |
|
124 TInt context = aPath.Id(1); |
|
125 TInt contextIndex = iEmbeddedContext.Find( context ); |
|
126 if( contextIndex >= KErrNone ) |
|
127 { |
|
128 CMPXMedia& media = *iTemporaryData[contextIndex]; |
|
129 |
|
130 TMPXGeneralCategory cat = *media.Value<TMPXGeneralCategory>( KMPXMediaGeneralCategory ); |
|
131 if( cat == EMPXPlaylist ) |
|
132 { |
|
133 const CMPXMediaArray* plarray = media.Value<CMPXMediaArray>( KMPXMediaArrayContents ); |
|
134 for( TInt i=0; i<plarray->Count(); ++i ) |
|
135 { |
|
136 CMPXMedia* item = (*plarray)[i]; |
|
137 CMPXMedia* copy = CMPXMedia::NewL(*item); |
|
138 |
|
139 // item id is the index in the array |
|
140 copy->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, i ); |
|
141 array->AppendL( copy ); // ownership x-fer |
|
142 } |
|
143 |
|
144 |
|
145 // Insert dummy media objects if the "specified" count is > actual |
|
146 // number of media objects |
|
147 TInt count(0); |
|
148 if( media.IsSupported(KMPXMediaArrayCount) ) |
|
149 { |
|
150 count = *media.Value<TInt>(KMPXMediaArrayCount); |
|
151 } |
|
152 if( count > 0 && count > plarray->Count() ) |
|
153 { |
|
154 for( TInt i=plarray->Count(); i<count; ++i ) |
|
155 { |
|
156 // Insert dummies |
|
157 CMPXMedia* copy = CMPXMedia::NewL(); |
|
158 copy->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, i ); |
|
159 copy->SetTObjectValueL( KMPXMediaGeneralType, |
|
160 EMPXItem ); |
|
161 copy->SetTObjectValueL( KMPXMediaGeneralCategory, |
|
162 EMPXSong ); |
|
163 array->AppendL( copy ); // ownership x-fer |
|
164 } |
|
165 } |
|
166 |
|
167 // Set the title for the playlist |
|
168 // |
|
169 if( media.IsSupported( KMPXMediaGeneralTitle ) ) |
|
170 { |
|
171 const TDesC& title = media.ValueText( KMPXMediaGeneralTitle ); |
|
172 entries->SetTextValueL( KMPXMediaGeneralTitle, |
|
173 title ); |
|
174 } |
|
175 } |
|
176 else // assume it is an item then |
|
177 { |
|
178 // Set one song to true |
|
179 oneSong = ETrue; |
|
180 } |
|
181 } |
|
182 else |
|
183 { |
|
184 err = KErrNotFound; |
|
185 } |
|
186 break; |
|
187 } |
|
188 case 3: // item in a playlist |
|
189 { |
|
190 oneSong = ETrue; |
|
191 break; |
|
192 } |
|
193 default: |
|
194 break; |
|
195 } |
|
196 |
|
197 // Set array if not one song |
|
198 if( !oneSong ) |
|
199 { |
|
200 entries->SetCObjectValueL(KMPXMediaArrayContents,array); |
|
201 entries->SetTObjectValueL(KMPXMediaArrayCount, |
|
202 array->Count()); |
|
203 entries->SetTObjectValueL( KMPXMediaGeneralType, |
|
204 EMPXGroup ); |
|
205 entries->SetTObjectValueL( KMPXMediaGeneralCategory, |
|
206 EMPXPlaylist ); |
|
207 } |
|
208 else |
|
209 { |
|
210 entries->SetTObjectValueL( KMPXMediaGeneralType, |
|
211 EMPXItem ); |
|
212 entries->SetTObjectValueL( KMPXMediaGeneralCategory, |
|
213 EMPXSong ); |
|
214 } |
|
215 |
|
216 if(oneSong) |
|
217 { |
|
218 iObs->HandleOpen(const_cast<CMPXCollectionPath*>(&aPath), err ); |
|
219 } |
|
220 else |
|
221 { |
|
222 entries->SetCObjectValueL( KMPXMediaGeneralContainerPath, |
|
223 const_cast<CMPXCollectionPath*>(&aPath) ); |
|
224 iObs->HandleOpen(entries, err ); |
|
225 } |
|
226 CleanupStack::PopAndDestroy(array); |
|
227 CleanupStack::PopAndDestroy(entries); |
|
228 CleanupStack::PopAndDestroy(&supportedIds); |
|
229 } |
|
230 |
|
231 // ---------------------------------------------------------------------------- |
|
232 // Extended properties of the current file (async) |
|
233 // ---------------------------------------------------------------------------- |
|
234 // |
|
235 void CMPXInMemoryPlugin::MediaL ( |
|
236 const CMPXCollectionPath& aPath, |
|
237 const TArray<TMPXAttribute>& aAttrs, |
|
238 const TArray<TCapability>& /*aCaps*/, |
|
239 CMPXAttributeSpecs* /*aSpecs*/) |
|
240 { |
|
241 RArray<TInt> supportedIds; |
|
242 CleanupClosePushL(supportedIds); |
|
243 supportedIds.AppendL(KMPXMediaIdGeneral); |
|
244 CMPXMedia* entries=CMPXMedia::NewL(supportedIds.Array()); |
|
245 CleanupStack::PopAndDestroy(&supportedIds); |
|
246 CleanupStack::PushL(entries); |
|
247 |
|
248 // Based on Path, what is the embedded client context id? |
|
249 // |
|
250 TInt err = KErrNone; |
|
251 TInt depth = aPath.Levels(); |
|
252 switch( depth ) |
|
253 { |
|
254 case 2: // Playlist / Song level |
|
255 case 3: // Song in a playlist level, fall through |
|
256 { |
|
257 TInt context = aPath.Id(1); |
|
258 TInt contextIndex = iEmbeddedContext.Find( context ); |
|
259 if( contextIndex >= KErrNone ) |
|
260 { |
|
261 CMPXMedia& media = *iTemporaryData[contextIndex]; |
|
262 |
|
263 TMPXGeneralCategory cat; |
|
264 cat = *media.Value<TMPXGeneralCategory>( KMPXMediaGeneralCategory ); |
|
265 |
|
266 // Playlist media |
|
267 // |
|
268 if( cat == EMPXPlaylist && depth == 2) |
|
269 { |
|
270 // Get |
|
271 const TDesC& title = media.ValueText( KMPXMediaGeneralTitle ); |
|
272 const TDesC& uri = media.ValueText( KMPXMediaGeneralUri ); |
|
273 // Set |
|
274 entries->SetTextValueL( KMPXMediaGeneralTitle, |
|
275 title ); |
|
276 entries->SetTextValueL( KMPXMediaGeneralUri, |
|
277 uri ); |
|
278 entries->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId, |
|
279 TUid::Uid(KIMPluginUid) ); |
|
280 } |
|
281 // Item in a playlist media |
|
282 // |
|
283 else if( cat == EMPXPlaylist && depth == 3 ) |
|
284 { |
|
285 const CMPXMediaArray* plarray = media.Value<CMPXMediaArray>( |
|
286 KMPXMediaArrayContents ); |
|
287 TInt selection = aPath.Id( 2 ); |
|
288 TInt count = plarray->Count(); |
|
289 if( selection < count ) |
|
290 { |
|
291 *entries = *(*plarray)[selection]; |
|
292 |
|
293 entries->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId, |
|
294 TUid::Uid(KIMPluginUid) ); |
|
295 } |
|
296 else |
|
297 { |
|
298 // Bounds check |
|
299 err = KErrArgument; |
|
300 } |
|
301 } |
|
302 // Otherwise, assume it is a song |
|
303 // |
|
304 else // cat == song/image/video/etc |
|
305 { |
|
306 *entries = media; |
|
307 |
|
308 entries->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId, |
|
309 TUid::Uid(KIMPluginUid) ); |
|
310 } |
|
311 } |
|
312 break; |
|
313 } |
|
314 default: |
|
315 { |
|
316 // Return Nothing because a MediaL at this depth contains nothing |
|
317 break; |
|
318 } |
|
319 } |
|
320 // |
|
321 for (TInt i=aAttrs.Count();--i>=0;) |
|
322 { |
|
323 if (aAttrs[i]==KMPXMediaGeneralPath) |
|
324 { |
|
325 entries->SetCObjectValueL(KMPXMediaGeneralPath, |
|
326 const_cast<CMPXCollectionPath*>(&aPath)); |
|
327 break; |
|
328 } |
|
329 } |
|
330 |
|
331 // Full metadata is not available from this plugin |
|
332 entries->SetTObjectValueL( KMPXMediaColDetailMediaNotAvailable, |
|
333 ETrue ); |
|
334 // |
|
335 iObs->HandleMedia(entries, err ); |
|
336 CleanupStack::PopAndDestroy(entries); |
|
337 } |
|
338 |
|
339 // ---------------------------------------------------------------------------- |
|
340 // Cancel outstanding request |
|
341 // ---------------------------------------------------------------------------- |
|
342 // |
|
343 void CMPXInMemoryPlugin::CancelRequest() |
|
344 { |
|
345 } |
|
346 |
|
347 // ---------------------------------------------------------------------------- |
|
348 // Executes a command on the selected collection |
|
349 // ---------------------------------------------------------------------------- |
|
350 // |
|
351 void CMPXInMemoryPlugin::CommandL(TMPXCollectionCommand /*aCmd*/, TInt /*aArg*/) |
|
352 { |
|
353 } |
|
354 |
|
355 // ---------------------------------------------------------------------------- |
|
356 // Executes a command on the selected collection |
|
357 // ---------------------------------------------------------------------------- |
|
358 // |
|
359 void CMPXInMemoryPlugin::CommandL(CMPXCommand& aCmd) |
|
360 { |
|
361 if (!aCmd.IsSupported(TMPXAttribute(KMPXCommandContentIdGeneral, EMPXCommandGeneralId))) |
|
362 { |
|
363 User::Leave(KErrArgument); |
|
364 } |
|
365 |
|
366 TMPXCommandId commandId = |
|
367 *aCmd.Value<TMPXCommandId>( |
|
368 TMPXAttribute(KMPXCommandContentIdGeneral, EMPXCommandGeneralId)); |
|
369 |
|
370 TBool syncOp(EFalse); |
|
371 if( aCmd.IsSupported(KMPXCommandGeneralDoSync) ) |
|
372 { |
|
373 syncOp = *aCmd.Value<TBool>(KMPXCommandGeneralDoSync); |
|
374 } |
|
375 |
|
376 // Handle each operation |
|
377 // |
|
378 switch( commandId ) |
|
379 { |
|
380 case KMPXCommandIdCollectionAdd: |
|
381 { |
|
382 DoAddL( *aCmd.Value<CMPXMedia>(KMPXCommandColAddMedia) ); |
|
383 break; |
|
384 } |
|
385 case KMPXCommandIdCollectionSet: |
|
386 { |
|
387 DoSetL( *aCmd.Value<CMPXMedia>(KMPXCommandColSetMedia) ); |
|
388 break; |
|
389 } |
|
390 default: |
|
391 { |
|
392 User::Leave(KErrNotSupported); |
|
393 } |
|
394 } |
|
395 |
|
396 // Complete Async operations |
|
397 // |
|
398 if( !syncOp ) |
|
399 { |
|
400 iObs->HandleCommandComplete( NULL, KErrNone ); |
|
401 } |
|
402 } |
|
403 |
|
404 // ---------------------------------------------------------------------------- |
|
405 // Adds item(s) to the collection |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 void CMPXInMemoryPlugin::AddL( |
|
409 const CMPXMedia& aNewMedia) |
|
410 { |
|
411 DoAddL( aNewMedia ); |
|
412 } |
|
413 |
|
414 // ---------------------------------------------------------------------------- |
|
415 // Remove by collection path |
|
416 // ---------------------------------------------------------------------------- |
|
417 // |
|
418 void CMPXInMemoryPlugin::RemoveL(const CMPXCollectionPath& aPath ) |
|
419 { |
|
420 (void) aPath; |
|
421 } |
|
422 |
|
423 // ---------------------------------------------------------------------------- |
|
424 // Remove an item or items under a group from the collection |
|
425 // ---------------------------------------------------------------------------- |
|
426 // |
|
427 void CMPXInMemoryPlugin::RemoveL(const CMPXMedia& aMedia) |
|
428 { |
|
429 (void)aMedia; |
|
430 } |
|
431 |
|
432 // ---------------------------------------------------------------------------- |
|
433 // Sets/updates the media for the item |
|
434 // ---------------------------------------------------------------------------- |
|
435 // |
|
436 void CMPXInMemoryPlugin::SetL( |
|
437 const CMPXMedia& aMedia) |
|
438 { |
|
439 DoSetL( aMedia ); |
|
440 } |
|
441 |
|
442 // ---------------------------------------------------------------------------- |
|
443 // Find based on media properties |
|
444 // ---------------------------------------------------------------------------- |
|
445 // |
|
446 void CMPXInMemoryPlugin::FindAllL(const CMPXMedia& aMedia, |
|
447 const TArray<TMPXAttribute>& aAttrs ) |
|
448 { |
|
449 (void)aMedia; |
|
450 (void)aAttrs; |
|
451 } |
|
452 |
|
453 // ---------------------------------------------------------------------------- |
|
454 // Find based on media properties |
|
455 // ---------------------------------------------------------------------------- |
|
456 // |
|
457 CMPXMedia* CMPXInMemoryPlugin::FindAllSyncL(const CMPXMedia& aMedia, |
|
458 const TArray<TMPXAttribute>& aAttrs ) |
|
459 { |
|
460 (void)aMedia; |
|
461 (void)aAttrs; |
|
462 User::Leave(KErrNotSupported); |
|
463 return NULL; |
|
464 } |
|
465 |
|
466 // ---------------------------------------------------------------------------- |
|
467 // Find the capabilities of this plugin |
|
468 // ---------------------------------------------------------------------------- |
|
469 // |
|
470 TCollectionCapability CMPXInMemoryPlugin::GetCapabilities() |
|
471 { |
|
472 return 0; // nothing special supported |
|
473 } |
|
474 |
|
475 // ---------------------------------------------------------------------------------------------------------- |
|
476 // Handle change |
|
477 // ---------------------------------------------------------------------------------------------------------- |
|
478 // |
|
479 void CMPXInMemoryPlugin::HandleChangeL(const TMPXItemId& aId, TMPXChangeEventType aChange ) |
|
480 { |
|
481 // Construct the message |
|
482 // |
|
483 CMPXMessage* message = CMPXMedia::NewL(); |
|
484 CleanupStack::PushL( message ); |
|
485 |
|
486 // Set attributes |
|
487 // |
|
488 message->SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, KMPXMessageIdItemChanged); |
|
489 |
|
490 message->SetTObjectValueL<TUid>(KMPXMessageCollectionId, TUid::Uid(KIMPluginUid)); |
|
491 |
|
492 message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, aChange); |
|
493 |
|
494 message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, aId); |
|
495 |
|
496 // Callback to observer and destroy |
|
497 // |
|
498 iObs->HandleMessage( *message ); |
|
499 CleanupStack::PopAndDestroy( message ); |
|
500 } |
|
501 |
|
502 // ---------------------------------------------------------------------------- |
|
503 // Adds item(s) to the collection |
|
504 // ---------------------------------------------------------------------------- |
|
505 // |
|
506 void CMPXInMemoryPlugin::DoAddL( |
|
507 const CMPXMedia& aNewMedia) |
|
508 { |
|
509 TInt context = *aNewMedia.Value<TInt>( TMPXAttribute(KMPXMediaIdGeneral, |
|
510 EMPXMediaGeneralId ) ); |
|
511 |
|
512 // Only 1 set of data per embedded context |
|
513 TInt index = iEmbeddedContext.Find( context ); |
|
514 if( index != KErrNotFound ) |
|
515 { |
|
516 iEmbeddedContext.Remove( index ); |
|
517 iTemporaryData.Remove( index ); |
|
518 iEmbeddedContext.Compress(); |
|
519 iTemporaryData.Compress(); |
|
520 } |
|
521 // Push onto list |
|
522 iEmbeddedContext.Append( context ); |
|
523 |
|
524 CMPXMedia* copy = CMPXMedia::NewL(); |
|
525 *copy = aNewMedia; |
|
526 iTemporaryData.AppendL( copy ); // ownership transferred. |
|
527 } |
|
528 |
|
529 // ---------------------------------------------------------------------------- |
|
530 // Sets/updates the media for the item |
|
531 // ---------------------------------------------------------------------------- |
|
532 // |
|
533 void CMPXInMemoryPlugin::DoSetL( |
|
534 const CMPXMedia& aMedia) |
|
535 { |
|
536 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL <---"); |
|
537 if( !aMedia.IsSupported(KMPXMediaGeneralId) ) |
|
538 { |
|
539 User::Leave( KErrArgument ); |
|
540 } |
|
541 |
|
542 TInt context = *aMedia.Value<TMPXItemId>(KMPXMediaGeneralId); |
|
543 TInt index = iEmbeddedContext.Find( context ); |
|
544 |
|
545 MPX_DEBUG2("CMPXInMemoryPlugin::DoSetL index %i", index); |
|
546 if( index != KErrNotFound ) |
|
547 { |
|
548 TMPXAttribute att( KMPXMediaArrayContents ); |
|
549 |
|
550 // Make sure it has a media array |
|
551 // |
|
552 if( aMedia.IsSupported( att ) ) |
|
553 { |
|
554 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 1"); |
|
555 |
|
556 // Grab the 2 media arrays |
|
557 // |
|
558 CMPXMediaArray* currentMedia = |
|
559 const_cast<CMPXMediaArray*>(iTemporaryData[index]->Value<CMPXMediaArray>(att)); |
|
560 const CMPXMediaArray* newMedia = aMedia.Value<CMPXMediaArray>(att); |
|
561 |
|
562 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 2"); |
|
563 // Copy all entries from newMedia into currentMedia |
|
564 // |
|
565 TInt newCount = newMedia->Count(); |
|
566 for( TInt i=0; i<newCount; ++i ) |
|
567 { |
|
568 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 3"); |
|
569 CMPXMedia* copy = CMPXMedia::NewL(*(*newMedia)[i]); |
|
570 CleanupStack::PushL( copy ); |
|
571 |
|
572 // If the item contains an item ID, we use it as an index to insert |
|
573 // into the array, otherwise, append item to the end |
|
574 // |
|
575 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 4"); |
|
576 if( copy->IsSupported(KMPXMediaGeneralId) ) |
|
577 { |
|
578 TInt index = *copy->Value<TMPXItemId>(KMPXMediaGeneralId); |
|
579 MPX_DEBUG2("CMPXInMemoryPlugin::DoSetL index count %i", index); |
|
580 // index is 0th based, like an array |
|
581 // |
|
582 TInt currentCount = currentMedia->Count(); |
|
583 if( index > currentCount ) |
|
584 { |
|
585 // Fill in blanks then append the item we want |
|
586 // |
|
587 for( TInt j=currentCount; j<index; ++j ) |
|
588 { |
|
589 CMPXMedia* blank = CMPXMedia::NewL(); |
|
590 CleanupStack::PushL( blank ); |
|
591 currentMedia->AppendL( blank ); // ownership xfer |
|
592 CleanupStack::Pop( blank ); |
|
593 } |
|
594 currentMedia->AppendL( copy ); // ownership xfer |
|
595 } |
|
596 else |
|
597 { |
|
598 // Replace item at index with this new version |
|
599 // |
|
600 currentMedia->Remove(index); |
|
601 currentMedia->Insert( copy, index ); // ownership xfer |
|
602 } |
|
603 } |
|
604 else |
|
605 { |
|
606 currentMedia->AppendL( copy ); // ownership xfer |
|
607 } |
|
608 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 5"); |
|
609 CleanupStack::Pop(copy); |
|
610 } |
|
611 |
|
612 // Set the new array into the media |
|
613 // |
|
614 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 6"); |
|
615 iTemporaryData[index]->SetCObjectValueL(att, currentMedia ); |
|
616 |
|
617 // Tell collection client context that something was added |
|
618 // |
|
619 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 7"); |
|
620 HandleChangeL( context, EMPXItemInserted ); |
|
621 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL 8"); |
|
622 } |
|
623 } |
|
624 else |
|
625 { |
|
626 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL KErrArgument"); |
|
627 User::Leave( KErrArgument ); |
|
628 } |
|
629 MPX_DEBUG1("CMPXInMemoryPlugin::DoSetL --->"); |
|
630 } |
|
631 |
|
632 // End of file |