mmappcomponents/collectionhelper/src/mpxcollectionhelperimp.cpp
changeset 0 a2952bb97e68
child 17 780c925249c1
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     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:  Main collection helper interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <eikenv.h>
       
    21 #include <badesca.h>
       
    22 #include <mpxcollectionpath.h>
       
    23 #include <mpxmedia.h>
       
    24 #include <mpxmediaarray.h>
       
    25 #include <mpxcollectionutility.h>
       
    26 #include <mpxharvesterutility.h>
       
    27 #include <mpxmediageneraldefs.h>
       
    28 #include <mpxmediacontainerdefs.h>
       
    29 #include <mpxuser.h>
       
    30 #include <mpxcollectionplugin.hrh>
       
    31 #include <mpxcommandgeneraldefs.h>
       
    32 #include <mpxcollectioncommanddefs.h>
       
    33 
       
    34 #include <mpxlog.h>
       
    35 #include "mpxcollectionhelperfactory.h"
       
    36 #include "mpxcollectionhelperimp.h"
       
    37 #include "mpxcollectionhelpercommon.h"
       
    38 #include "mpxcollectionmediator.h"
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CMPXCollectionHelperImp::CMPXCollectionHelperImp()
       
    48     {
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // 2nd Phased Constructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CMPXCollectionHelperImp::ConstructL()
       
    57     {
       
    58     iHvsUtility = CMPXHarvesterFactory::NewL();
       
    59     iCollectionUtil = MMPXCollectionUtility::NewL();
       
    60     iMediator = CMPXCollectionMediator::NewL( iCollectionUtil->Collection(),
       
    61                                               this );
       
    62 
       
    63     RArray<TUid> ary;
       
    64     CleanupClosePushL( ary );
       
    65     ary.AppendL( TUid::Uid(EMPXCollectionPluginMusic) );
       
    66     iMusicCollectionId = iCollectionUtil->CollectionIDL( ary.Array() );
       
    67     CleanupStack::PopAndDestroy( &ary );
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Two-Phased Constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CMPXCollectionHelperImp* CMPXCollectionHelperImp::NewL()
       
    76     {
       
    77     CMPXCollectionHelperImp* self = new( ELeave ) CMPXCollectionHelperImp();
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Two-Phased Constructor
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CMPXCollectionHelperImp* CMPXCollectionHelperImp::NewLC()
       
    90     {
       
    91     CMPXCollectionHelperImp* self = new( ELeave ) CMPXCollectionHelperImp();
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     return self;
       
    95     }
       
    96 
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Virtual Destructor
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CMPXCollectionHelperImp::~CMPXCollectionHelperImp()
       
   103     {
       
   104     if( iHvsUtility )
       
   105         {
       
   106         iHvsUtility->Close();
       
   107         }
       
   108 
       
   109     if( iCollectionUtil )
       
   110         {
       
   111         iCollectionUtil->Close();
       
   112         }
       
   113     delete iMediator;
       
   114     }
       
   115 
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // Issue collection initialization command to collection framework.
       
   119 // This is necessary when collection helper serves as an intermediator
       
   120 // between collection framework and Podcast App or MTP, etc.
       
   121 // There is, currently, no way to check the merge status of the collections
       
   122 // through the collection utility API.  Therefore, collectionhelper issue
       
   123 // an EMcCmdCollectionInit(or merge) command before any collectionhelper
       
   124 // functionality, which expects collection is in valid state, is excuted.
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Add a File to the collection
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CMPXCollectionHelperImp::AddL( const TDesC& aFile,
       
   133                                     MMPXCollectionHelperObserver* aObserver )
       
   134     {
       
   135     MPX_FUNC("CMPXCollectionHelperImp::AddL");
       
   136     MPX_DEBUG2("aFile %S", &aFile);
       
   137 
       
   138     // Since this is a file, we must get the harvester to parse the file
       
   139     // On callback, add the file to collection
       
   140     //
       
   141     iObserver = aObserver;
       
   142     iHvsUtility->GetMediaForFileL(aFile,this);
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // Add a Media Property to the collection
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CMPXCollectionHelperImp::AddL( CMPXMedia* aMedia )
       
   150     {
       
   151     MPX_DEBUG1("CMPXCollectionHelperImp::AddL <--");
       
   152 
       
   153     //
       
   154     // leave if the given media doesn't contain the following attributes
       
   155     //
       
   156     if (!aMedia->IsSupported(KMPXMediaGeneralType) ||
       
   157         !aMedia->IsSupported(KMPXMediaGeneralCategory) ||
       
   158         !aMedia->IsSupported(KMPXMediaGeneralUri))
       
   159         {
       
   160         User::Leave( KErrArgument );
       
   161         }
       
   162 
       
   163     const TDesC& path = aMedia->ValueText(KMPXMediaGeneralUri);
       
   164 
       
   165     //
       
   166     // For now, the default collection to add this playlist is
       
   167     // EMPXCollectionPluginMusic. This will be revised later when there is a
       
   168     // generic way of resolving collections aside from using file extension
       
   169     // or UID.
       
   170     //
       
   171     if ( aMedia->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) == EMPXItem &&
       
   172          aMedia->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) == EMPXPlaylist )
       
   173         {
       
   174         aMedia->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId,
       
   175                                         iMusicCollectionId );
       
   176         }
       
   177 
       
   178     //
       
   179     // Adding a song
       
   180     //
       
   181     else
       
   182         {
       
   183         TInt colUid = iHvsUtility->GetColUidForFileL(path);
       
   184 
       
   185         MPX_DEBUG2("CMPXCollectionHelperImp::AddL: collection id = %i",colUid);
       
   186         // Add to collection, make sure we set the collection ID
       
   187         //
       
   188         aMedia->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId,
       
   189                                        TUid::Uid( colUid ) );
       
   190         }
       
   191 
       
   192     MPX_DEBUG1("CMPXCollectionHelperImp::AddL: calling DoAddToCollectionL( aMedia )");
       
   193     TRAPD(err,DoAddToCollectionL( aMedia ));
       
   194     MPX_DEBUG2("CMPXCollectionHelperImp::AddL: DoAddToCollectionL( aMedia ); called error %d", err);
       
   195 
       
   196     //
       
   197     // When MTP adds a playlist, the playlist content is represented by the
       
   198     // given CMPXMedia and a 0-length .pla file is added to the file system
       
   199     // for syncing with WMP. The URI of the playlist CMPXMedia will contain
       
   200     // .pla extension. This file will not be added to the harvester database
       
   201     // because there is no pla playlist plugin supplied and harvester does
       
   202     // not scan .pla files. It is intentional not to have a pla playlist
       
   203     // plugin to prevent users from transferring real .pla files to the
       
   204     // device's file system through USB and have them shown with music icons
       
   205     // when they cannot be understood by the system.
       
   206     //
       
   207     if (err == KErrNone &&
       
   208         aMedia->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory) != EMPXPlaylist)
       
   209         {
       
   210         // Add to harvester
       
   211         iHvsUtility->AddFileL(aMedia);
       
   212         MPX_DEBUG2("    successfully registered %S with harvester", &path);
       
   213         }
       
   214 
       
   215     MPX_DEBUG1("CMPXCollectionHelperImp::AddL -->");
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Remove a file from the collection
       
   220 // ---------------------------------------------------------------------------
       
   221 //
       
   222 void CMPXCollectionHelperImp::RemoveL( const TDesC& aFile,
       
   223                                        TMPXGeneralCategory aItemCat )
       
   224     {
       
   225     MPX_FUNC("CMPXCollectionHelperImp::RemoveL");
       
   226     MPX_DEBUG3("aFile %S, category %d", &aFile, aItemCat);
       
   227 
       
   228     if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist)
       
   229         {
       
   230         User::Leave(KErrArgument);
       
   231         }
       
   232 
       
   233     //
       
   234     // ask harvester to remove the file if any of the following is true:
       
   235     // 1) removing a song
       
   236     // 2) removing a playlist scanned through file system.
       
   237     //
       
   238     //    There are 3 types of playlists. The ones created from the device
       
   239     //    are virtual playlists which have file extension .vir. There are
       
   240     //    no physical playlist files associated with them; hence not
       
   241     //    registered with harvester. For virtual playlists, IsPlaylistL
       
   242     //    will return EFalse because there is not a playlist plugin that
       
   243     //    deals with .vir playlist files.
       
   244     //
       
   245     //    The ones synced from PC through MTP have file extension .pla.
       
   246     //    There are 0-byte .pla files associated with them but they
       
   247     //    are not registered with harvester either. IsPlaylistL will also
       
   248     //    return EFalse because there is not a playlist plugin that deals
       
   249     //    with .pla.
       
   250     //
       
   251     //    The 3rd type of playlists is .m3u on the file system. They are
       
   252     //    added to the collection through file scan and registered with
       
   253     //    harvester. IsPlaylistL will return ETrue.
       
   254     //
       
   255     //    For now virtual playlists and synced playlists are assumed to
       
   256     //    be in the music collection for now until there is a generic way
       
   257     //    resolving collections aside from using file extension or UID.
       
   258     //
       
   259     TInt collection(iMusicCollectionId.iUid);
       
   260     if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile))
       
   261         {
       
   262         // Remove from the harvester
       
   263         collection = iHvsUtility->RemoveFileL( aFile );
       
   264         }
       
   265 
       
   266     // Remove from the collection
       
   267     // Construct a CMPXMedia object with URI, collection id, type and category
       
   268     //
       
   269     RArray<TInt> contID;
       
   270     CleanupClosePushL( contID );
       
   271     contID.AppendL( KMPXMediaIdGeneral );
       
   272     CMPXMedia* media = CMPXMedia::NewL( contID.Array() );
       
   273     CleanupStack::PushL( media );
       
   274 
       
   275     media->SetTextValueL( KMPXMediaGeneralUri, aFile );
       
   276     media->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid( collection ) );
       
   277     media->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
       
   278     media->SetTObjectValueL( KMPXMediaGeneralCategory, aItemCat );
       
   279 
       
   280     // Remove the item via CMPXCommand
       
   281     //
       
   282     CMPXCommand* cmd = CMPXCommand::NewL();
       
   283     CleanupStack::PushL( cmd );
       
   284     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId,
       
   285                            collection );
       
   286     cmd->SetTObjectValueL( KMPXCommandGeneralId,
       
   287                            KMPXCommandIdCollectionRemoveMedia );
       
   288     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
   289     cmd->SetCObjectValueL( KMPXCommandCollectionRemoveMedia, media );
       
   290     cmd->SetTObjectValueL( KMPXCommandCollectionRemoveMediaDeleteRecord,
       
   291                            ETrue );
       
   292     iCollectionUtil->Collection().CommandL( *cmd );
       
   293     CleanupStack::PopAndDestroy( cmd );
       
   294 
       
   295     CleanupStack::PopAndDestroy( media );
       
   296     CleanupStack::PopAndDestroy( &contID );
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // Remove all files from harvester, music and podcast db
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CMPXCollectionHelperImp::RemoveAllL()
       
   304     {
       
   305     MPX_FUNC("CMPXCollectionHelperImp::RemoveAllL");
       
   306 
       
   307     // Remove all from harvester
       
   308     iHvsUtility->RemoveAllFilesL();
       
   309 
       
   310     // Remove all from music collection
       
   311     iCollectionUtil->Collection().CommandL( EMcCmdRemoveAll,
       
   312                                             iMusicCollectionId.iUid );
       
   313 
       
   314     // Remove all from podcast collection
       
   315     //iCollectionUtil->Collection().CommandL( EMcCmdRemoveAll,
       
   316     //                                        KPodCastCollecionID);
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // Delete all records marked as deleted
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 void CMPXCollectionHelperImp::CleanupDeletedMediasL()
       
   324     {
       
   325     User::Leave(KErrNotSupported);
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // update the media property based on file path
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CMPXCollectionHelperImp::SetL( CMPXMedia*& aMedia )
       
   333     {
       
   334     MPX_FUNC("CMPXCollectionHelperImp::SetL");
       
   335 
       
   336     //
       
   337     // leave if the given media doesn't contain the following attributes
       
   338     //
       
   339     if (!aMedia->IsSupported(KMPXMediaGeneralType) ||
       
   340         !aMedia->IsSupported(KMPXMediaGeneralCategory) ||
       
   341         !aMedia->IsSupported(KMPXMediaGeneralUri))
       
   342         {
       
   343         User::Leave( KErrArgument );
       
   344         }
       
   345 
       
   346     //
       
   347     // leave if not updating a song or a playlist
       
   348     //
       
   349     TMPXGeneralCategory category =
       
   350         aMedia->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory);
       
   351 
       
   352     if ((aMedia->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) != EMPXItem) ||
       
   353         (category != EMPXSong && category != EMPXPlaylist))
       
   354         {
       
   355         User::Leave( KErrArgument );
       
   356         }
       
   357 
       
   358     //
       
   359     // Playlists synced from MTP were not added to harvester's database;
       
   360     // hence we cannot look up the collection Id through harvester. These
       
   361     // playlists contain .pla extension when there is no pla playlist
       
   362     // plugin, so we cannot resolve the collection plugins by extensions
       
   363     // either. For now, the default collection to add this playlist is
       
   364     // EMPXCollectionPluginMusic for playlists. This will be revised later
       
   365     // when there is a generic way of resolving collections aside from using
       
   366     // file extension or UID. Same for virtual playlists.
       
   367     //
       
   368     // Fetch collection id from harvester for songs or scanned playlist
       
   369     // files.
       
   370     //
       
   371     TInt col(iMusicCollectionId.iUid);
       
   372     const TDesC& path = aMedia->ValueText(KMPXMediaGeneralUri);
       
   373 
       
   374     // Fetch collection id from harvester
       
   375     if (category == EMPXSong || iHvsUtility->IsPlaylistL(path))
       
   376         {
       
   377         col = iHvsUtility->FindCollectionIdL( path );
       
   378         }
       
   379 
       
   380     // Proxy to collection after we get the correct collection ID
       
   381     //
       
   382     aMedia->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId,
       
   383                                    TUid::Uid( col ) );
       
   384 
       
   385     // update collection
       
   386     iMediator->SetItemL( aMedia );
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // rename a media object
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 void CMPXCollectionHelperImp::RenameL( const TDesC& aOldUri,
       
   394                                        const TDesC& aNewUri,
       
   395                                        TMPXGeneralCategory aItemCat )
       
   396     {
       
   397     MPX_FUNC("CMPXCollectionHelperImp::RenameL");
       
   398     MPX_DEBUG3("aOldUri = %S, aNewUri = %S", &aOldUri, &aNewUri);
       
   399 
       
   400     if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist)
       
   401         {
       
   402         User::Leave(KErrArgument);
       
   403         }
       
   404 
       
   405     // find the media using the old URI
       
   406     RArray<TMPXAttribute> attributes;
       
   407     CleanupClosePushL( attributes );
       
   408     attributes.AppendL(KMPXMediaGeneralId);
       
   409 
       
   410     CMPXMedia* media = GetL(aOldUri, attributes.Array(), aItemCat);
       
   411     CleanupStack::PopAndDestroy(&attributes);
       
   412     CleanupStack::PushL(media);
       
   413 
       
   414     // change file path to the new file path
       
   415     media->SetTextValueL(KMPXMediaGeneralUri, aNewUri);
       
   416 
       
   417     // ask harvester to rename the file if any of the following is true:
       
   418     // 1) renaming a song
       
   419     // 2) renaming a playlist scanned through file system.
       
   420     //
       
   421     //    There are 3 types of playlists. The ones created from the device
       
   422     //    are virtual playlists which have file extension .vir. There are
       
   423     //    no physical playlist files associated with them; hence not
       
   424     //    registered with harvester. For virtual playlists, IsPlaylistL
       
   425     //    will return EFalse because there is not a playlist plugin that
       
   426     //    deals with .vir playlist files.
       
   427     //
       
   428     //    The ones synced from PC through MTP have file extension .pla.
       
   429     //    There are 0-byte .pla files associated with them but they
       
   430     //    are not registered with harvester either. IsPlaylistL will also
       
   431     //    return EFalse because there is not a playlist plugin that deals
       
   432     //    with .pla.
       
   433     //
       
   434     //    The 3rd type of playlists is .m3u on the file system. They are
       
   435     //    added to the collection through file scan and registered with
       
   436     //    harvester. IsPlaylistL will return ETrue.
       
   437     if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aOldUri))
       
   438         {
       
   439         const TUid& collection =
       
   440              media->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId);
       
   441         iHvsUtility->RenameFileL( aOldUri, aNewUri, collection.iUid );
       
   442         }
       
   443 
       
   444     // Update collection via CMPXCommand
       
   445     //
       
   446     CMPXCommand* cmd = CMPXCommand::NewL();
       
   447     CleanupStack::PushL( cmd );
       
   448     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet );
       
   449     TUid colId (media->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId) );
       
   450     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   451     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
   452     cmd->SetCObjectValueL( KMPXCommandColSetMedia, media );
       
   453     iCollectionUtil->Collection().CommandL( *cmd );
       
   454     CleanupStack::PopAndDestroy( cmd );
       
   455 
       
   456     CleanupStack::PopAndDestroy(media);
       
   457     }
       
   458 
       
   459 // ---------------------------------------------------------------------------
       
   460 // Retrieve a media object based on file path
       
   461 // ---------------------------------------------------------------------------
       
   462 //
       
   463 CMPXMedia* CMPXCollectionHelperImp::GetL( const TDesC& aFile,
       
   464                                           const TArray<TMPXAttribute>& aAttrs,
       
   465                                           TMPXGeneralCategory aItemCat )
       
   466     {
       
   467     MPX_FUNC("CMPXCollectionHelperImp::GetL");
       
   468     MPX_DEBUG2("aFile %S", &aFile);
       
   469 
       
   470     if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist)
       
   471         {
       
   472         User::Leave(KErrArgument);
       
   473         }
       
   474 
       
   475     // Playlists synced through MTP contains .pla extension and there
       
   476     // is no pla playlist plugin. We can no longer reply on harvester
       
   477     // utility's IsPlaylistL to determine if this is a playlist.
       
   478     // For now, the default collection to get this playlist is
       
   479     // EMPXCollectionPluginMusic for playlists. This will be revised
       
   480     // later when there is a generic way of resolving collections aside
       
   481     // from using file extension or UID. Same for virtual playlists.
       
   482     //
       
   483     // Find the collection Id from harvester for songs or playlists
       
   484     // scanned from the file system
       
   485     TInt col(iMusicCollectionId.iUid);
       
   486     if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile))
       
   487         {
       
   488         col = iHvsUtility->FindCollectionIdL( aFile );
       
   489         }
       
   490 
       
   491     // Search criteria
       
   492     //
       
   493     CMPXMedia* search = CMPXMedia::NewL();
       
   494     CleanupStack::PushL( search );
       
   495     search->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
       
   496     search->SetTObjectValueL( KMPXMediaGeneralCategory, aItemCat );
       
   497     search->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid(col) );
       
   498     search->SetTextValueL( KMPXMediaGeneralUri, aFile );
       
   499 
       
   500     // Search in synch mode
       
   501     //
       
   502     CMPXMedia* result = iCollectionUtil->Collection().FindAllL( *search, aAttrs );
       
   503     CleanupStack::PopAndDestroy( search );
       
   504     CleanupStack::PushL(result);
       
   505 
       
   506     const CMPXMediaArray* ary(NULL);
       
   507     if( result->IsSupported( KMPXMediaArrayContents ) )
       
   508       {
       
   509       ary = result->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   510       if( !ary )
       
   511           {
       
   512           User::Leave(KErrNoMemory);
       
   513           }
       
   514       }
       
   515 
       
   516     CMPXMedia* foundMedia(NULL);
       
   517 
       
   518     switch ( ary && ary->Count() )  //lint !e961
       
   519         {
       
   520         case 0:
       
   521             User::Leave(KErrNotFound);
       
   522         case 1:
       
   523             {
       
   524             foundMedia = CMPXMedia::NewL(*ary->AtL(0));
       
   525             CleanupStack::PushL(foundMedia);
       
   526             foundMedia->SetTObjectValueL<TUid>(
       
   527                 KMPXMediaGeneralCollectionId, TUid::Uid(col) );
       
   528             CleanupStack::Pop(foundMedia);
       
   529             break;
       
   530             }
       
   531         default:
       
   532             User::Leave(KErrCorrupt);
       
   533         }
       
   534 
       
   535     CleanupStack::PopAndDestroy(result);
       
   536 
       
   537     return foundMedia;
       
   538     }
       
   539 
       
   540 // ---------------------------------------------------------------------------
       
   541 // Gets the attributes of some media object
       
   542 // ---------------------------------------------------------------------------
       
   543 //
       
   544 const CMPXMedia& CMPXCollectionHelperImp::GetL( const TDesC& /*aFile*/,
       
   545                                                 TMPXGeneralCategory /*aItemCat*/ )
       
   546     {
       
   547     User::Leave(KErrNotSupported);
       
   548 
       
   549     /* avoid compilation warnings */
       
   550     CMPXMedia* dummy(NULL);
       
   551     return *dummy;
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------------------------
       
   555 // Find function to return a list of songs
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 CMPXMedia* CMPXCollectionHelperImp::FindAllL( CMPXMedia& aCriteria,
       
   559                                               const TArray<TMPXAttribute>& aAttrs )
       
   560     {
       
   561     MPX_FUNC("CMPXCollectionHelperImp::FindAllL");
       
   562 
       
   563     // Search criteria, add the collection to search from
       
   564     //
       
   565     aCriteria.SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId,
       
   566                                       iMusicCollectionId );
       
   567 
       
   568     // Search in synch mode
       
   569     //
       
   570     return iCollectionUtil->Collection().FindAllL( aCriteria, aAttrs );
       
   571     }
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // Handles completion of playlist export
       
   575 // to-do: this should be changed to HandlePlaylistExportCompleted
       
   576 // ---------------------------------------------------------------------------
       
   577 //
       
   578 void CMPXCollectionHelperImp::HandlePlaylistExportCompletedL( CMPXMedia* aMedia,
       
   579                                                               TInt /*aErr*/ )
       
   580     {
       
   581     // Not used
       
   582     delete aMedia;
       
   583     }
       
   584 
       
   585 // ---------------------------------------------------------------------------
       
   586 // From MMPXHarvesterUtilityObserver
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 void CMPXCollectionHelperImp::HandlePlaylistImportCompletedL( CMPXMedia* aMedia,
       
   590                                                               TInt /*aErr*/ )
       
   591     {
       
   592     // Not used
       
   593     delete aMedia;
       
   594     }
       
   595 
       
   596 // ---------------------------------------------------------------------------
       
   597 // From MMPXHarvesterUtilityObserver
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 void CMPXCollectionHelperImp::HandleFileAddCompletedL( CMPXMedia* aMedia,
       
   601                                                        TInt aErr )
       
   602     {
       
   603     MPX_FUNC("CMPXCollectionHelperImp::HandleFileAddCompletedL");
       
   604     MPX_DEBUG2("err = %d", aErr);
       
   605 
       
   606     CleanupStack::PushL( aMedia );
       
   607 
       
   608     // Add to collection
       
   609     //
       
   610     TInt err( aErr );
       
   611     if( aErr == KErrNone )
       
   612         {
       
   613         TRAP( err, DoAddToCollectionL( aMedia ) );
       
   614         }
       
   615 
       
   616     // Callback to the observer
       
   617     //
       
   618     if( iObserver )
       
   619         {
       
   620         iObserver->HandleAddFileCompleteL( err );
       
   621         iObserver = NULL;
       
   622         }
       
   623     CleanupStack::PopAndDestroy( aMedia );
       
   624     }
       
   625 
       
   626 // ---------------------------------------------------------------------------
       
   627 // From MMPXHarvesterUtilityObserver
       
   628 // ---------------------------------------------------------------------------
       
   629 //
       
   630 void CMPXCollectionHelperImp::HandleDeleteCompletedL( TInt /*aErr*/ )
       
   631     {
       
   632     // not used.
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------------------------
       
   636 // From MMPXHarvesterUtilityObserver
       
   637 // ---------------------------------------------------------------------------
       
   638 //
       
   639 void CMPXCollectionHelperImp::HandleFileImportCompletedL( CMPXMedia* aMedia,
       
   640                                                          TInt /*aErr*/  )
       
   641     {
       
   642     delete aMedia;
       
   643     // not used
       
   644     }
       
   645 
       
   646 // ---------------------------------------------------------------------------
       
   647 // From MMPXHarvesterUtilityObserver
       
   648 // ---------------------------------------------------------------------------
       
   649 //
       
   650 void CMPXCollectionHelperImp::HandleFileGetMediaCompletedL( CMPXMedia* aMedia,
       
   651                                                          TInt aErr  )
       
   652     {
       
   653     MPX_FUNC("CMPXCollectionHelperImp::HandleFileGetMediaCompletedL");
       
   654     MPX_DEBUG2("err = %d", aErr);
       
   655 
       
   656     CleanupStack::PushL( aMedia );
       
   657 
       
   658     // Add to collection
       
   659     TInt err(aErr);
       
   660     if( err == KErrNone )
       
   661         {
       
   662         if (!aMedia->IsSupported(KMPXMediaGeneralCollectionId))
       
   663             {
       
   664             if (aMedia->IsSupported(KMPXMediaGeneralUri))
       
   665                 {
       
   666                 TRAP(err,
       
   667                      aMedia->SetTObjectValueL<TUid>(KMPXMediaGeneralCollectionId,
       
   668                         TUid::Uid(iHvsUtility->GetColUidForFileL(aMedia->ValueText(KMPXMediaGeneralUri))));
       
   669                     );
       
   670                 }
       
   671             else
       
   672                 {
       
   673                 err = KErrArgument;
       
   674                 }
       
   675             }
       
   676         }
       
   677     if ( err == KErrNone )
       
   678         {
       
   679         TRAP(err, DoAddToCollectionL( aMedia ));
       
   680         }
       
   681     if( err == KErrNone )
       
   682         {
       
   683         // Add to harvester
       
   684         TRAP(err,iHvsUtility->AddFileL(aMedia));
       
   685         }
       
   686 
       
   687     // Callback to the observer
       
   688     //
       
   689     if( iObserver )
       
   690         {
       
   691         iObserver->HandleAddFileCompleteL( err );
       
   692         iObserver = NULL;
       
   693         }
       
   694     CleanupStack::PopAndDestroy( aMedia );
       
   695     }
       
   696 
       
   697 // ---------------------------------------------------------------------------
       
   698 // From MMPXMediatorObserver
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 void CMPXCollectionHelperImp::HandleMediatorPathUpdatedL( CMPXMedia*& aMedia,
       
   702                                                           TUid  /*aOldPath*/ )
       
   703     {
       
   704     iHvsUtility->UpdateFileL( aMedia );
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 // Add a file to the collection through the mediator
       
   709 // ---------------------------------------------------------------------------
       
   710 //
       
   711 void CMPXCollectionHelperImp::DoAddToCollectionL( CMPXMedia* aMedia )
       
   712     {
       
   713     iMediator->AddItemL( aMedia );
       
   714     }
       
   715 
       
   716 // ---------------------------------------------------------------------------
       
   717 // Frees this object
       
   718 // ---------------------------------------------------------------------------
       
   719 //
       
   720 void CMPXCollectionHelperImp::Close()
       
   721     {
       
   722     delete this;
       
   723     }
       
   724 
       
   725 // End of file