mpserviceplugins/mpxsqlitepodcastdbplugin/src/mpxpodcastdbplugin.cpp
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     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:  Implementation of podcast collection DB Plugin interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32cmn.h>
       
    21 #include <PCRes.rsg>
       
    22 #include <bautils.h>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 
       
    25 #include <mpxcmn.h>
       
    26 #include <mpxcollectionpluginobserver.h>
       
    27 #include <mpxmediacontainerdefs.h>
       
    28 #include <mpxmediamusicdefs.h>
       
    29 #include <mpxmediaaudiodefs.h>
       
    30 #include <mpxmediacollectiondetaildefs.h>
       
    31 #include <mpxcommandgeneraldefs.h>
       
    32 #include <mpxmessagecontainerdefs.h>
       
    33 #include <mpxcollectioncommanddefs.h>
       
    34 #include <mpxmedia.h>
       
    35 #include <mpxmediaarray.h>
       
    36 #include <mpxdrmmediautility.h>
       
    37 #include <mpxmediadrmdefs.h>
       
    38 #include <mpxlog.h>
       
    39 #ifdef RD_MULTIPLE_DRIVE
       
    40 #include <driveinfo.h>
       
    41 #endif //RD_MULTIPLE_DRIVE
       
    42 
       
    43 #include "mpxdbcommondef.h"
       
    44 #include "mpxresource.h"
       
    45 #include "mpxdbcommonstd.h"
       
    46 #include "mpxdbcommonutil.h"
       
    47 
       
    48 #include "mpxpodcastcollectiondbstd.h"
       
    49 #include "mpxpodcastdbhandler.h"
       
    50 #include "mpxdbutil.h"
       
    51 #include "mpxpodcastcollectiondbdef.h"
       
    52 #include "mpxpodcastcollectiondb.hrh"
       
    53 #include "mpxpodcastdbplugin.h"
       
    54 
       
    55 // CONSTANTS
       
    56 const TInt KIncrementalDeleteCount = 400;
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ==============================
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // Two-phased constructor.
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 CMPXPodcastDbPlugin* CMPXPodcastDbPlugin::NewL(
       
    65     TAny* /* aInitParams */)
       
    66     {
       
    67     MPX_FUNC("CMPXPodcastDbPlugin::NewL");
       
    68 
       
    69     CMPXPodcastDbPlugin* self = new (ELeave) CMPXPodcastDbPlugin();
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(self);
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // Destructor.
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CMPXPodcastDbPlugin::~CMPXPodcastDbPlugin()
       
    81     {
       
    82     MPX_FUNC("CMPXPodcastDbPlugin::~CMPXPodcastDbPlugin");
       
    83 
       
    84     iSelections.Reset();
       
    85     iSelections.Close();
       
    86     iFs.Close();
       
    87     delete iDbHandler;
       
    88     delete iDrmMediaUtility;
       
    89     if (iResource)
       
    90         {
       
    91         iResource->Release();
       
    92         }
       
    93     iPodcastLibraryMainMenuItemIds.Close();
       
    94     delete iPodcastLibraryMainMenuItemTitles;
       
    95     delete iPodcastLibraryTitles;
       
    96     iPodcastPublishDateIds.Close();
       
    97     delete iPodcastTitlePublishDateCat;
       
    98     iPodcastEpisodeViewPublishDateIds.Close();
       
    99     delete iPodcastEpisodeViewPublishDateTitle;
       
   100     delete iTitleMyPodcast;
       
   101     delete iTitleAllEpisodes;
       
   102     delete iTitlePubDate;
       
   103     delete iTitleTitles;
       
   104     delete iTitleAdded;
       
   105     delete iTitleUnplayed;
       
   106 
       
   107     if (iActiveTask)
       
   108         {
       
   109         iActiveTask->Cancel();
       
   110         delete iActiveTask;
       
   111         }
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // Constructor.
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 CMPXPodcastDbPlugin::CMPXPodcastDbPlugin()
       
   119     {
       
   120     MPX_FUNC("CMPXPodcastDbPlugin::CMPXPodcastDbPlugin");
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // Symbian 2nd phase constructor can leave.
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 void CMPXPodcastDbPlugin::ConstructL ()
       
   128     {
       
   129     MPX_FUNC("CMPXPodcastDbPlugin::ConstructL");
       
   130     iFirstDeleteStep = ETrue;
       
   131     User::LeaveIfError(iFs.Connect());
       
   132     iDrmMediaUtility = CMPXDrmMediaUtility::NewL();
       
   133 
       
   134     TParse parse;
       
   135     parse.Set( KMPXCollectionDbResourceFile, &KDC_APP_RESOURCE_DIR, NULL );
       
   136     TFileName resFile(parse.FullName());
       
   137     User::LeaveIfError(MPXUser::CompleteWithDllPath(resFile));
       
   138     BaflUtils::NearestLanguageFile(iFs, resFile);
       
   139     iResource = CMPXResource::NewL(resFile);
       
   140 
       
   141     iDbHandler = CMPXPodcastDbHandler::NewL(iFs, *iResource);
       
   142 
       
   143     iPodcastLibraryMainMenuItemTitles = iResource->ReadMenuArrayL(R_MC_MENU_ITEMS_ARRAY,
       
   144         iPodcastLibraryMainMenuItemIds);
       
   145     iPodcastTitlePublishDateCat = iResource->ReadMenuArrayL(R_MPX_QTN_NMP_PUBLISH_DATE_ARRAY,
       
   146         iPodcastPublishDateIds);
       
   147     iPodcastEpisodeViewPublishDateTitle = iResource->ReadMenuArrayL(
       
   148         R_MPX_QTN_NMP_EPISODES_TITLE_PUBLISHED_DATE_ARRAY, iPodcastEpisodeViewPublishDateIds);
       
   149     iTitleMyPodcast = iResource->ReadHBufCL(R_MPX_QTN_MP_TITLE_MY_PODCAST);
       
   150     iTitleAllEpisodes = iResource->ReadHBufCL(R_MPX_QTN_MP_TITLE_ALL_EPISODES);
       
   151     iTitlePubDate = iResource->ReadHBufCL(R_MPX_QTN_MUS_TITLE_PUBLISH_DATE);
       
   152     iTitleTitles = iResource->ReadHBufCL(R_MPX_QTN_MP_TITLE_PODCASTS);
       
   153     iTitleAdded = iResource->ReadHBufCL(R_MPX_QTN_MP_TITLE_RECENTLY_ADDED);
       
   154     iTitleUnplayed = iResource->ReadHBufCL(R_MPX_QTN_MP_TITLE_UNPLAYED);
       
   155     iPodcastLibraryTitles = iResource->ReadMenuArrayL(R_MC_MENU_TITLES_ARRAY,
       
   156         iPodcastLibraryMainMenuItemIds);
       
   157 
       
   158     iActiveTask = CMPXDbActiveTask::NewL(*this);
       
   159     }
       
   160 
       
   161 // ----------------------------------------------------------------------------
       
   162 // Navigates to the given path
       
   163 // ----------------------------------------------------------------------------
       
   164 //
       
   165 void CMPXPodcastDbPlugin::OpenL(
       
   166     const CMPXCollectionPath& aPath,
       
   167     const TArray<TMPXAttribute>& aAttrs,
       
   168     CMPXFilter* /*aFilter*/)
       
   169     {
       
   170     MPX_FUNC("CMPXPodcastDbPlugin::OpenL");
       
   171     MPX_DEBUG_PATH (aPath);
       
   172 
       
   173     RArray<TMPXAttribute> openAttrs;
       
   174     CleanupClosePushL(openAttrs);
       
   175 
       
   176     RArray<TInt> supportedIds;
       
   177     CleanupClosePushL(supportedIds);
       
   178 
       
   179     SetAttributesL(aPath, openAttrs, supportedIds);
       
   180 
       
   181     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
       
   182     CleanupStack::PopAndDestroy(&supportedIds);
       
   183     CleanupStack::PushL(entries);
       
   184 
       
   185     TInt error(KErrNone);
       
   186     TBool isEpisode(EFalse);
       
   187     CMPXCollectionPath* newPath(NULL);
       
   188 
       
   189     TBool openingForPlayback(EFalse);
       
   190 
       
   191     if(aAttrs.Count() == 1 &&
       
   192        aAttrs[0].ContentId() == KMPXMediaIdPodcast)
       
   193     {
       
   194         if(aAttrs[0].AttributeId() & EMPXMediaPodcastSetIsPlayingTrue)
       
   195         {
       
   196         openingForPlayback = ETrue;
       
   197         }
       
   198     }
       
   199 
       
   200     // Make sure we handle the correct open mode
       
   201     //
       
   202     TMPXOpenMode openmode = aPath.OpenNextMode();
       
   203     switch (openmode)
       
   204         {
       
   205         case EMPXOpenGroupOrPlaylist:
       
   206             {
       
   207             MPX_TRAP(error, isEpisode = DoOpenL (
       
   208                 aPath, openAttrs.Array(), *entries, openingForPlayback));
       
   209             break;
       
   210             }
       
   211 
       
   212         case EMPXOpenPlaylistOnly:
       
   213             {
       
   214             if( aPath.Count() > 0 )
       
   215                 {
       
   216                 // Try to open
       
   217                 MPX_TRAP(error, newPath = DoOpenPlaylistL(aPath, openAttrs.Array(), openingForPlayback));
       
   218                 CleanupStack::PushL(newPath);
       
   219                 isEpisode = ETrue;
       
   220                 }
       
   221             else // no items, so open in normal mode
       
   222                 {
       
   223                 MPX_TRAP(error, isEpisode = DoOpenL (
       
   224                     aPath, openAttrs.Array(), *entries, openingForPlayback));
       
   225                 }
       
   226             break;
       
   227             }
       
   228         default:
       
   229             // do nothing
       
   230             break;
       
   231         }
       
   232 
       
   233     if (isEpisode)
       
   234         {
       
   235         if (openmode == EMPXOpenGroupOrPlaylist)
       
   236             {
       
   237             iObs->HandleOpen(const_cast<CMPXCollectionPath*>(&aPath), error);
       
   238             }
       
   239         else // openmode == EMPXOpenPlaylistOnly
       
   240             {
       
   241             iObs->HandleOpen(newPath, error);
       
   242             }
       
   243         }
       
   244     else
       
   245         {
       
   246         MPX_DEBUG_PATH (aPath);
       
   247 
       
   248         entries->SetCObjectValueL(KMPXMediaGeneralContainerPath,
       
   249             const_cast<CMPXCollectionPath*>(&aPath));
       
   250         iObs->HandleOpen(entries, error);
       
   251         }
       
   252 
       
   253     if (newPath)
       
   254         {
       
   255         CleanupStack::PopAndDestroy(newPath);
       
   256         }
       
   257 
       
   258     CleanupStack::PopAndDestroy(entries);
       
   259     CleanupStack::PopAndDestroy(&openAttrs);
       
   260     }
       
   261 
       
   262 // ----------------------------------------------------------------------------
       
   263 // Get the extended properties of the current file (async)
       
   264 // ----------------------------------------------------------------------------
       
   265 //
       
   266 void CMPXPodcastDbPlugin::MediaL(
       
   267     const CMPXCollectionPath& aPath,
       
   268     const TArray<TMPXAttribute>& aAttrs,
       
   269     const TArray<TCapability>& /*aCaps*/,
       
   270     CMPXAttributeSpecs* /*aSpecs*/)
       
   271     {
       
   272     MPX_FUNC("CMPXPodcastDbPlugin::MediaL");
       
   273     MPX_DEBUG_PATH(aPath);
       
   274 
       
   275     RArray<TInt> supportedIds;
       
   276     CleanupClosePushL(supportedIds);
       
   277     if (aPath.Selection().Count())
       
   278         {
       
   279         // it's a container if there are multiple selection, else it's not a container
       
   280         supportedIds.AppendL(KMPXMediaIdContainer);
       
   281         }
       
   282     MPXDbCommonUtil::FillInSupportedUIDsL (aAttrs, supportedIds);
       
   283     CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
       
   284     CleanupStack::PopAndDestroy(&supportedIds);
       
   285     CleanupStack::PushL(entries);
       
   286 
       
   287     DoMediaL(aPath, aAttrs, *entries);
       
   288 
       
   289     // Also fetch collection details
       
   290     DoHandleOtherMediaAttributesL(aAttrs, aPath, *entries);
       
   291 
       
   292     iObs->HandleMedia(entries, KErrNone);
       
   293     CleanupStack::PopAndDestroy(entries);
       
   294     }
       
   295 
       
   296 // ----------------------------------------------------------------------------
       
   297 // Cancel outstanding request
       
   298 // ----------------------------------------------------------------------------
       
   299 //
       
   300 void CMPXPodcastDbPlugin::CancelRequest()
       
   301     {
       
   302     MPX_FUNC("CMPXPodcastDbPlugin::CancelRequest");
       
   303     iActiveTask->Cancel();
       
   304     }
       
   305 
       
   306 // ----------------------------------------------------------------------------
       
   307 // Executes the given command on the collection
       
   308 // ----------------------------------------------------------------------------
       
   309 //
       
   310 void CMPXPodcastDbPlugin::CommandL(
       
   311     TMPXCollectionCommand aCmd,
       
   312     TInt aArg /* = 0 */)
       
   313     {
       
   314     MPX_FUNC("CMPXPodcastDbPlugin::CommandL");
       
   315 
       
   316     switch (aCmd)
       
   317         {
       
   318         case EMcCmdRemoveAll:
       
   319             {
       
   320             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcCmdRemoveAll");
       
   321             // Remove EVERYthing from the collection
       
   322             iDbHandler->RemoveEntireCollectionL();
       
   323             break;
       
   324             }
       
   325         case EMcCmdClose:
       
   326         case EMcCloseCollection:
       
   327             {
       
   328             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcCloseCollection");
       
   329             // Close the specified database
       
   330  #ifdef RD_MULTIPLE_DRIVE
       
   331             MPX_DEBUG1("Multiple drives closing databases");
       
   332             if ( aArg <0)
       
   333                 {
       
   334                 DriveInfo::TDriveArray driveArray;
       
   335                 User::LeaveIfError ( DriveInfo::GetUserVisibleDrives ( iFs, driveArray));
       
   336                 TInt count( driveArray.Count ());
       
   337                 for (TInt i=0; i<count; ++i)
       
   338                     {
       
   339                     MPX_DEBUG2("At drive %i", driveArray[i]);
       
   340                     if ((driveArray[i] != EDriveC) && (!iDbHandler->IsRemoteDrive(static_cast<TDriveNumber>(driveArray[i])))) 
       
   341                         {
       
   342                         MPX_DEBUG2("Closing database %i", driveArray[i]);
       
   343                         TRAP_IGNORE( iDbHandler->CloseDatabaseL( driveArray[i] ) );
       
   344                         }
       
   345                     }
       
   346                 }
       
   347             else
       
   348                 {
       
   349                 iDbHandler->CloseDatabaseL (aArg);
       
   350                 }
       
   351  #else
       
   352             iDbHandler->CloseDatabaseL(aArg);
       
   353  #endif // RD_MULTIPLE_DRIVE
       
   354             break;
       
   355             }
       
   356         case EMcReOpenCollection:
       
   357             {
       
   358             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcReOpenCollection");
       
   359             // Open the specified database
       
   360 #ifdef RD_MULTIPLE_DRIVE
       
   361             MPX_DEBUG1("Multiple drives opening databases");
       
   362             DriveInfo::TDriveArray driveArray;
       
   363             User::LeaveIfError( DriveInfo::GetUserVisibleDrives( iFs, driveArray ) );
       
   364             TInt count( driveArray.Count() );
       
   365             for( TInt i=0; i<count; ++i )
       
   366                 {
       
   367                 MPX_DEBUG2("At drive %i", driveArray[i]);
       
   368                 if (( driveArray[i] != EDriveC ) && (!iDbHandler->IsRemoteDrive(static_cast<TDriveNumber>(driveArray[i])))) 
       
   369                     {
       
   370                     TUint driveStatus(0);
       
   371                     User::LeaveIfError( DriveInfo::GetDriveStatus(
       
   372                         iFs, driveArray[i], driveStatus ) );
       
   373                     if( driveStatus & DriveInfo::EDrivePresent )
       
   374                         {
       
   375                         MPX_DEBUG2("Opening database %i", driveArray[i]);
       
   376                         TRAP_IGNORE( iDbHandler->OpenDatabaseL( driveArray[i] ) );
       
   377                         }
       
   378                     }
       
   379                 }
       
   380 #else
       
   381             iDbHandler->OpenDatabaseL(aArg);
       
   382 #endif // RD_MULTIPLE_DRIVE
       
   383             break;
       
   384             }
       
   385         case EMcRefreshStarted:
       
   386             {
       
   387             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcRefreshStarted");
       
   388             iDbHandler->RefreshStartL();
       
   389             iRefreshing = ETrue;
       
   390             break;
       
   391             }
       
   392         case EMcRefreshEnded:
       
   393             {
       
   394             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcRefreshEnded");
       
   395             // ask the handler to finalize the transaction
       
   396             iDbHandler->RefreshEndL();
       
   397             iRefreshing = EFalse;
       
   398             break;
       
   399             }
       
   400          case EMcCmdReCreateDB:
       
   401             {
       
   402             // Recreate all databases
       
   403             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcCmdReCreateDB");
       
   404             iDbHandler->ReCreateDatabasesL();
       
   405             break;
       
   406             }
       
   407          case EMcCmdDbCorrupted:
       
   408             {
       
   409             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - EMcCmdDbCorrupted");
       
   410             iDbHandler->SetDBCorruptedL(ETrue);
       
   411             break;
       
   412             }
       
   413         case EMcCmdCollectionInit:
       
   414         case EMcCmdRefresh:
       
   415         case EMcCmdCollectionResyn:
       
   416             {
       
   417             // deprecated
       
   418             break;
       
   419             }
       
   420         case EMcCmdMtpStart:
       
   421             iMtpInUse = ETrue;
       
   422             break;
       
   423         case EMcCmdMtpEnd:
       
   424             iMtpInUse = EFalse;
       
   425             break;
       
   426         default:
       
   427             {
       
   428             User::Leave(KErrNotSupported);
       
   429             }
       
   430         }
       
   431     }
       
   432 
       
   433 // ----------------------------------------------------------------------------
       
   434 // Executes the given command on the collection
       
   435 // ----------------------------------------------------------------------------
       
   436 //
       
   437 void CMPXPodcastDbPlugin::CommandL(
       
   438     CMPXCommand& aCmd)
       
   439     {
       
   440     MPX_FUNC("CMPXPodcastDbPlugin::CommandL");
       
   441 
       
   442     if (!aCmd.IsSupported(KMPXCommandGeneralId))
       
   443         {
       
   444         User::Leave(KErrArgument);
       
   445         }
       
   446 
       
   447     TMPXCommandId commandId = aCmd.ValueTObjectL<TMPXCommandId>(KMPXCommandGeneralId);
       
   448 
       
   449     TBool syncOp(EFalse);
       
   450     if( aCmd.IsSupported(KMPXCommandGeneralDoSync) )
       
   451         {
       
   452         syncOp = aCmd.ValueTObjectL<TBool>(KMPXCommandGeneralDoSync);
       
   453         }
       
   454 
       
   455     // Handle this operation synchronously or asynchronously
       
   456     if( !syncOp )
       
   457         {
       
   458         iActiveTask->StartL(commandId, aCmd);
       
   459         }
       
   460     else  // Sync operation
       
   461         {
       
   462         switch (commandId)
       
   463             {
       
   464             case KMPXCommandIdCollectionRetrieveUriForDeletion:
       
   465                 {
       
   466                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionRetrieveUriForDeletion");
       
   467                 DoRetrieveUriForDeletionL(aCmd);
       
   468                 break;
       
   469                 }
       
   470             case KMPXCommandIdCollectionRemove:
       
   471                 {
       
   472                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionRemove");
       
   473                 if (iFirstDeleteStep )
       
   474                     {
       
   475                     iFirstDeleteStep = EFalse;
       
   476                     }
       
   477                 DoRemovePathL(aCmd);
       
   478                 break;
       
   479                 }
       
   480             case KMPXCommandIdCollectionRemoveMedia:
       
   481                 {
       
   482                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionRemoveMedia");
       
   483                 DoRemoveMediaL(aCmd);
       
   484                 break;
       
   485                 }
       
   486             case KMPXCommandIdCollectionCleanupDeletedMedias:
       
   487                 {
       
   488                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionCleanupDeletedMedias");
       
   489                 CleanupDeletedRecordsL(aCmd);
       
   490                 break;
       
   491                 }
       
   492             case KMPXCommandIdCollectionAdd:
       
   493                 {
       
   494                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectioAdd");
       
   495                 CMPXMedia* media = aCmd.Value<CMPXMedia>(KMPXCommandColAddMedia);
       
   496                 User::LeaveIfNull( media );
       
   497                 TInt id = DoAddL(*media);
       
   498                 aCmd.SetTObjectValueL<TMPXItemId>(KMPXCommandColAddRtnId, id);
       
   499                 break;
       
   500                 }
       
   501             case KMPXCommandIdCollectionSet:
       
   502                 {
       
   503                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionSet");
       
   504                 CMPXMedia* media = aCmd.Value<CMPXMedia>(KMPXCommandColSetMedia);
       
   505                 User::LeaveIfNull( media );
       
   506                 DoSetL(*media);
       
   507                 break;
       
   508                 }
       
   509             case KMPXCommandIdCollectionCompleteDelete:
       
   510                 {
       
   511                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdCollectionCompleteDelete");
       
   512                 DoHandleDeleteCompleteL(aCmd);
       
   513                 break;
       
   514                 }
       
   515             case KMPXCommandIdUpdateRefreshTime:
       
   516                 {
       
   517                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdUpdateRefreshTime");
       
   518                 TTime curTime;
       
   519                 curTime.HomeTime();
       
   520                 iDbHandler->SetLastRefreshedTimeL(curTime);
       
   521                 break;
       
   522                 }
       
   523             case KMPXCommandCollectionGetCount:
       
   524                 {
       
   525                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandCollectionGetCount");
       
   526                 DoGetCollectionCountL(aCmd);
       
   527                 break;
       
   528                 }
       
   529             case KMPXCommandCollectionGetURIs:
       
   530                 {
       
   531                 MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandCollectionGetURIs");
       
   532                 DoGetCollectionUriL(aCmd);
       
   533                 break;
       
   534                 }
       
   535             default:
       
   536                 {
       
   537                 User::Leave(KErrNotSupported);
       
   538                 }
       
   539             }
       
   540         }
       
   541     }
       
   542 
       
   543 // ----------------------------------------------------------------------------
       
   544 // Adds a podcast to the collection
       
   545 // ----------------------------------------------------------------------------
       
   546 //
       
   547 void CMPXPodcastDbPlugin::AddL(
       
   548     const CMPXMedia& aMedia)
       
   549     {
       
   550     MPX_FUNC("CMPXPodcastDbPlugin::AddL");
       
   551     DoAddL(aMedia);
       
   552     }
       
   553 
       
   554 // ----------------------------------------------------------------------------
       
   555 // Remove an item from the collection database using the given path
       
   556 // ----------------------------------------------------------------------------
       
   557 //
       
   558 void CMPXPodcastDbPlugin::RemoveL(
       
   559     const CMPXCollectionPath& aPath)
       
   560     {
       
   561     MPX_FUNC("CMPXPodcastDbPlugin::RemoveL(by path)");
       
   562     MPX_DEBUG_PATH(aPath);
       
   563 
       
   564     CMPXMessageArray* msgAry = CMPXMessageArray::NewL();
       
   565     CleanupStack::PushL( msgAry );
       
   566 
       
   567     // Return file path for deleted item(s)
       
   568     CDesCArray* fp = DoRemoveL(aPath,*msgAry);
       
   569 
       
   570     iObs->HandleRemove(*fp, KErrNone);
       
   571     delete fp;
       
   572 
       
   573     // Send Change Messages
       
   574     iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
   575     DoHandleChangeL(msgAry);
       
   576     CleanupStack::PopAndDestroy( msgAry );
       
   577     }
       
   578 
       
   579 // ----------------------------------------------------------------------------
       
   580 // Remove an item from the collection database using the given media properties
       
   581 // ----------------------------------------------------------------------------
       
   582 //
       
   583 void CMPXPodcastDbPlugin::RemoveL(
       
   584     const CMPXMedia& aMedia)
       
   585     {
       
   586     MPX_FUNC("CMPXPodcastDbPlugin::RemoveL(by media)");
       
   587     DoRemoveL(aMedia, EFalse);
       
   588     }
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // Sets/updates the media for an item in the collection
       
   592 // DEPRECATED for week 18
       
   593 // ----------------------------------------------------------------------------
       
   594 //
       
   595 void CMPXPodcastDbPlugin::SetL(
       
   596     const CMPXMedia& aMedia)
       
   597     {
       
   598     MPX_FUNC("CMPXPodcastDbPlugin::SetL");
       
   599     DoSetL(aMedia);
       
   600     }
       
   601 
       
   602 // ----------------------------------------------------------------------------
       
   603 // Find the items matching the media specifications
       
   604 // ----------------------------------------------------------------------------
       
   605 //
       
   606 void CMPXPodcastDbPlugin::FindAllL(
       
   607     const CMPXMedia& aCriteria,
       
   608     const TArray<TMPXAttribute>& aAttrs)
       
   609     {
       
   610     MPX_FUNC("CMPXPodcastDbPlugin::FindAllL");
       
   611 
       
   612     CMPXMedia* entries = FindAllSyncL(aCriteria, aAttrs);
       
   613 
       
   614     // notify client. if FindAllL leaves, framework will notify client of the error
       
   615     iObs->HandleFindAll(entries, KErrNone);
       
   616     delete entries;
       
   617     }
       
   618 
       
   619 // ----------------------------------------------------------------------------
       
   620 // Find the items matching the media specifications
       
   621 // ----------------------------------------------------------------------------
       
   622 //
       
   623 CMPXMedia* CMPXPodcastDbPlugin::FindAllSyncL(
       
   624     const CMPXMedia& aCriteria,
       
   625     const TArray<TMPXAttribute>& aAttrs)
       
   626     {
       
   627     MPX_FUNC("CMPXPodcastDbPlugin::FindAllSyncL");
       
   628 
       
   629     CMPXMedia* entries = iDbHandler->FindAllLC(aCriteria, aAttrs);
       
   630     CleanupStack::Pop(entries);
       
   631 
       
   632     return entries;
       
   633     }
       
   634 
       
   635 // ----------------------------------------------------------------------------
       
   636 // Get the list of supported capabilities
       
   637 // ----------------------------------------------------------------------------
       
   638 //
       
   639 TCollectionCapability CMPXPodcastDbPlugin::GetCapabilities()
       
   640     {
       
   641     // This one supports simple search
       
   642     return EMcSearch;
       
   643     }
       
   644 
       
   645 // ----------------------------------------------------------------------------
       
   646 // Get the list of supported capabilities
       
   647 // ----------------------------------------------------------------------------
       
   648 //
       
   649 TBool CMPXPodcastDbPlugin::HandleStepL()
       
   650     {
       
   651     MPX_FUNC("CMPXPodcastDbPlugin::HandleStepL");
       
   652 
       
   653     TBool done(ETrue);
       
   654 
       
   655     switch (iActiveTask->GetTask())
       
   656         {
       
   657         case KMPXCommandIdCollectionSet:
       
   658             {
       
   659             done = DoSetAsyncL();
       
   660             break;
       
   661             }
       
   662         case KMPXCommandIdCollectionAdd:
       
   663             {
       
   664             done = DoAddAsyncL();
       
   665             break;
       
   666             }
       
   667         case KMPXCommandIdCollectionRemove:
       
   668             {
       
   669             DoRemovePathL(iActiveTask->GetCommand());
       
   670             done = ETrue;
       
   671             break;
       
   672             }
       
   673         case KMPXCommandIdCollectionRemoveMedia:
       
   674             {
       
   675             DoRemoveMediaL(iActiveTask->GetCommand());
       
   676             done = ETrue;
       
   677             break;
       
   678             }
       
   679         case KMPXCommandIdCollectionRetrieveUriForDeletion:
       
   680             {
       
   681             DoRetrieveUriForDeletionL(iActiveTask->GetCommand());
       
   682             done = ETrue;
       
   683             break;
       
   684             }
       
   685         case KMPXCommandIdCollectionCleanupDeletedMedias:
       
   686             {
       
   687             CleanupDeletedRecordsL(iActiveTask->GetCommand());
       
   688             done = ETrue;
       
   689             break;
       
   690             }
       
   691         case KMPXCommandIdCollectionCompleteDelete:
       
   692             {
       
   693             DoHandleDeleteCompleteL( iActiveTask->GetCommand() );
       
   694             break;
       
   695             }
       
   696         case KMPXCommandIdUpdateRefreshTime:
       
   697             {
       
   698             MPX_DEBUG1("CMPXPodcastDbPlugin::CommandL - KMPXCommandIdUpdateRefreshTime");
       
   699             TTime curTime;
       
   700             curTime.HomeTime();
       
   701             iDbHandler->SetLastRefreshedTimeL(curTime);
       
   702             break;
       
   703             }
       
   704         default:
       
   705             {
       
   706             // Should never happen!
       
   707             ASSERT(0);
       
   708             break;
       
   709             }
       
   710         }
       
   711     return done;
       
   712     }
       
   713 
       
   714 // ----------------------------------------------------------------------------
       
   715 // Handler for async operations completed
       
   716 // ----------------------------------------------------------------------------
       
   717 //
       
   718 void CMPXPodcastDbPlugin::HandleOperationCompleted(
       
   719     TInt aErr)
       
   720     {
       
   721     MPX_FUNC("CMPXPodcastDbPlugin::HandleOperationCompleted");
       
   722     TRAP_IGNORE(DoHandleOperationCompletedL(aErr));
       
   723     }
       
   724 
       
   725 // ----------------------------------------------------------------------------
       
   726 // Process the OpenL command
       
   727 // ----------------------------------------------------------------------------
       
   728 //
       
   729 TBool CMPXPodcastDbPlugin::DoOpenL(
       
   730     const CMPXCollectionPath& aPath,
       
   731     const TArray<TMPXAttribute>& aAttrs,
       
   732 	CMPXMedia& aEntries,
       
   733 	TBool aFlagToSignalToBePlayed)
       
   734     {
       
   735     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenL");
       
   736 
       
   737     CMPXMediaArray* array = CMPXMediaArray::NewL();
       
   738     CleanupStack::PushL(array);
       
   739 
       
   740     TInt levels(aPath.Levels());
       
   741     TBool isEpisode(EFalse);
       
   742 
       
   743     aEntries.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, aPath.Id(levels - 1));
       
   744 
       
   745     if (1 == levels)
       
   746         {
       
   747         isEpisode = DoOpenBrowseTitleL(aPath, aAttrs, aEntries, *array);
       
   748         }
       
   749     else if (levels >= 2)
       
   750         {
       
   751         isEpisode = DoOpenBrowseTitleL(aPath, aAttrs, aEntries, *array);
       
   752         }
       
   753     else
       
   754         {
       
   755         User::Leave(KErrNotSupported);
       
   756         }
       
   757 
       
   758     if(isEpisode &&
       
   759        aFlagToSignalToBePlayed)
       
   760         {
       
   761         // opening an episode to be played so set the IsPlaying flag to
       
   762         // prevent this episode from being picked up as Not Yet Played
       
   763         // (need to do this because setting last playback position causes
       
   764         // visible change and the playlist to update)
       
   765         if(array->Count() == 1)
       
   766             {
       
   767             // ignore the error because if there is a problem
       
   768             // updating the media file, the error will show up
       
   769             // when opening the track for playing and be handled
       
   770             // properly by the playback engine and skipped
       
   771             TRAP_IGNORE(iDbHandler->SetIsPlayingL(*((*array)[0]), ETrue));
       
   772             }
       
   773         }
       
   774 
       
   775     aEntries.SetCObjectValueL(KMPXMediaArrayContents, array);
       
   776     aEntries.SetTObjectValueL(KMPXMediaArrayCount, array->Count());
       
   777 
       
   778     CleanupStack::PopAndDestroy(array);
       
   779 
       
   780     return isEpisode;
       
   781     }
       
   782 
       
   783 // ----------------------------------------------------------------------------
       
   784 // Handles OpenL called for EBrowseAll
       
   785 // ----------------------------------------------------------------------------
       
   786 //
       
   787 TBool CMPXPodcastDbPlugin::DoOpenBrowseAllL(
       
   788     const CMPXCollectionPath& aPath,
       
   789     const TArray<TMPXAttribute>& aAttrs,
       
   790     CMPXMedia& aEntries,
       
   791     CMPXMediaArray& aArray)
       
   792     {
       
   793     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenBrowseAllL");
       
   794 
       
   795     TInt levels(aPath.Levels());
       
   796     switch (levels)
       
   797        {
       
   798        // All Episodes
       
   799        case 2:
       
   800             {
       
   801             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseAllL_All);
       
   802 
       
   803             iDbHandler->GetAllEpisodesL(aAttrs, aArray);
       
   804             SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPodcastGroup, EMPXAll,
       
   805                 *iTitleAllEpisodes, aArray.Count());
       
   806 
       
   807             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseAllL_All);
       
   808             break;
       
   809             }
       
   810 
       
   811          // An episode in all episodes
       
   812          case 3:
       
   813             {
       
   814             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseAllL_Episode);
       
   815 
       
   816             iDbHandler->GetEpisodeL(aPath.Id(levels - 1), aAttrs, aArray);
       
   817 
       
   818             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseAllL_Episode);
       
   819             break;
       
   820             }
       
   821 
       
   822          default:
       
   823             {
       
   824             MPX_DEBUG2("CMPXPodcastDbPlugin_DoOpenBrowseAllL: Invalid levels[%d]", levels);
       
   825             User::Leave(KErrNotSupported);
       
   826             }
       
   827         }
       
   828 
       
   829     return (levels == 3);
       
   830     }
       
   831 
       
   832 // ----------------------------------------------------------------------------
       
   833 // Handles OpenL called for EBrowsePubDate
       
   834 // ----------------------------------------------------------------------------
       
   835 //
       
   836 TBool CMPXPodcastDbPlugin::DoOpenBrowsePubDateL(
       
   837     const CMPXCollectionPath& aPath,
       
   838     const TArray<TMPXAttribute>& aAttrs,
       
   839     CMPXMedia& aEntries,
       
   840     CMPXMediaArray& aArray)
       
   841     {
       
   842     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenBrowsePubDateL");
       
   843 
       
   844     TBool isEpisode(EFalse);
       
   845     TInt levels(aPath.Levels());
       
   846 
       
   847     switch (levels)
       
   848         {
       
   849         // All By Publish Date Categories
       
   850         case 2:
       
   851             {
       
   852             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_All);
       
   853 
       
   854             TInt numEpisodes(iDbHandler->GetEpisodesMatchingPublishPlaylistL(KPublishAllPlaylistUID, aAttrs,
       
   855                     EFalse, aArray));
       
   856             SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPodcastGroup, EMPXPubDate,
       
   857                 *iTitlePubDate);
       
   858             aEntries.SetTObjectValueL(KMPXMediaGeneralNonPermissibleActions, EMPXCache );
       
   859             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_All);
       
   860             break;
       
   861             }
       
   862         // All episodes within a specific By Publish Date category
       
   863         case 3:
       
   864             {
       
   865             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_Playlist);
       
   866             iNumberOfEpisodesInCurrentPublishDateCategory =
       
   867                 iDbHandler->GetEpisodesMatchingPublishPlaylistL(
       
   868                 (aPath.Id(levels - 1).iId2 & 0x00FFFFFF) + KPublishTodayPlaylistUID, // offset by KPublishTodayPlaylistUID
       
   869                 aAttrs, EFalse, aArray);
       
   870 
       
   871             SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXPodcastItem, EMPXEpisode,
       
   872                 iPodcastEpisodeViewPublishDateTitle->MdcaPoint(aPath.Id(levels - 1).iId2 & 0x00FFFFFF),
       
   873                 iNumberOfEpisodesInCurrentPublishDateCategory);
       
   874 
       
   875             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_Playlist);
       
   876             break;
       
   877             }
       
   878         // An episode
       
   879         case 4:
       
   880             {
       
   881             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_Episode);
       
   882 
       
   883             iDbHandler->GetEpisodeL(aPath.Id(levels - 1), aAttrs, aArray);
       
   884             isEpisode = ETrue;
       
   885 
       
   886             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowsePubDateL_Episode);
       
   887             break;
       
   888             }
       
   889         default:
       
   890             {
       
   891             MPX_DEBUG2("CMPXPodcastDbPlugin_DoOpenBrowsePubDateL: Invalid levels[%d]", levels);
       
   892             User::Leave(KErrNotSupported);
       
   893             }
       
   894         }
       
   895     return isEpisode;
       
   896     }
       
   897 
       
   898 // ----------------------------------------------------------------------------
       
   899 // Handles OpenL called for EBrowseTitle
       
   900 // ----------------------------------------------------------------------------
       
   901 //
       
   902 TBool CMPXPodcastDbPlugin::DoOpenBrowseTitleL(
       
   903     const CMPXCollectionPath& aPath,
       
   904     const TArray<TMPXAttribute>& aAttrs,
       
   905     CMPXMedia& aEntries,
       
   906     CMPXMediaArray& aArray)
       
   907     {
       
   908     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenBrowseTitleL");
       
   909 
       
   910     TBool isEpisode(EFalse);
       
   911     TInt levels(aPath.Levels());
       
   912 
       
   913     switch (levels)
       
   914          {
       
   915          // All Titles
       
   916 		 case 1:
       
   917             {
       
   918             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_All);
       
   919 
       
   920             iDbHandler->GetAllPodcastTitlesL(aAttrs, aArray);
       
   921 
       
   922             SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPodcastGroup, EMPXTitle,
       
   923                 *iTitleTitles);
       
   924 
       
   925             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_All);
       
   926             break;
       
   927             }
       
   928          // All episodes in a title
       
   929 		 case 2:
       
   930             {
       
   931             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_Title);
       
   932 
       
   933             iDbHandler->GetEpisodesMatchingTitleL(aPath.Id(levels - 1).iId2,
       
   934                 aAttrs, aArray);
       
   935 
       
   936             HBufC* title = iDbHandler->GetTitleNameMatchingIdL(aPath.Id(levels - 1));
       
   937             CleanupStack::PushL(title);
       
   938             SetMediaGeneralAttributesL(aEntries, EMPXItem, EMPXPodcastItem, EMPXEpisode,
       
   939                 *title, aArray.Count());
       
   940             CleanupStack::PopAndDestroy(title);
       
   941 
       
   942             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_Title);
       
   943             break;
       
   944             }
       
   945          // An episode within a title
       
   946          case 3:
       
   947             {
       
   948             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_Episode);
       
   949             iDbHandler->GetEpisodeL(aPath.Id(levels - 1), aAttrs, aArray);
       
   950             isEpisode = ETrue;
       
   951 
       
   952             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseTitleL_Episode);
       
   953             break;
       
   954             }
       
   955 
       
   956          default:
       
   957             {
       
   958             MPX_DEBUG2("CMPXPodcastDbPlugin_DoOpenBrowseTitleL: Invalid levels[%d]", levels);
       
   959             User::Leave(KErrNotSupported);
       
   960             }
       
   961        }
       
   962 
       
   963     return isEpisode;
       
   964     }
       
   965 
       
   966 // ----------------------------------------------------------------------------
       
   967 // Handles OpenL called for EBrowseRecentlyAdded
       
   968 // ----------------------------------------------------------------------------
       
   969 //
       
   970 TBool CMPXPodcastDbPlugin::DoOpenBrowseRecentlyAddedL(
       
   971     const CMPXCollectionPath& aPath,
       
   972     const TArray<TMPXAttribute>& aAttrs,
       
   973     CMPXMedia& aEntries,
       
   974     CMPXMediaArray& aArray)
       
   975     {
       
   976     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenBrowseRecentlyAddedL");
       
   977 
       
   978     TBool isEpisode(EFalse);
       
   979     TInt levels(aPath.Levels());
       
   980 
       
   981     switch (levels)
       
   982          {
       
   983          case 2:
       
   984             {
       
   985             // All recently added episodes
       
   986             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseRecentlyAddedL_All);
       
   987 
       
   988             TInt indexOfCurrentlyPlayingItem(KErrNotFound);
       
   989             iDbHandler->GetEpisodesMatchingPlaylistL(KRecentlyAddedPlaylistUID,
       
   990                     aAttrs, aArray, indexOfCurrentlyPlayingItem);
       
   991             SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPodcastGroup, EMPXRecentlyAdded,
       
   992                 *iTitleAdded, aArray.Count());
       
   993             aEntries.SetTObjectValueL(KMPXMediaPodcastCurrentlyPlayingIndex,
       
   994                 indexOfCurrentlyPlayingItem);
       
   995             // Fix for Autoplaylist, set the permission to not writable and cacheable
       
   996             aEntries.SetTObjectValueL<TMPXGeneralNonPermissibleActions>(
       
   997                 KMPXMediaGeneralNonPermissibleActions, (TMPXGeneralNonPermissibleActions)(EMPXWrite | EMPXCache));
       
   998 
       
   999             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseRecentlyAddedL_All);
       
  1000             break;
       
  1001             }
       
  1002          // An episode in the recently added episodes list
       
  1003          case 3:
       
  1004             {
       
  1005             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseRecentlyAddedL_Episode);
       
  1006             iDbHandler->GetEpisodeL(aPath.Id(levels - 1), aAttrs, aArray);
       
  1007             isEpisode = ETrue;
       
  1008 
       
  1009             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseRecentlyAddedL_Episode);
       
  1010             break;
       
  1011             }
       
  1012          default:
       
  1013             {
       
  1014             MPX_DEBUG2("CMPXPodcastDbPlugin_DoOpenBrowseRecentlyAddedL: Invalid levels[%d]", levels);
       
  1015             User::Leave(KErrNotSupported);
       
  1016             }
       
  1017         }
       
  1018 
       
  1019     return isEpisode;
       
  1020     }
       
  1021 
       
  1022 // ----------------------------------------------------------------------------
       
  1023 // Handles OpenL called for EBrowseNotPlayed
       
  1024 // ----------------------------------------------------------------------------
       
  1025 //
       
  1026 TBool CMPXPodcastDbPlugin::DoOpenBrowseNotPlayedL(
       
  1027     const CMPXCollectionPath& aPath,
       
  1028     const TArray<TMPXAttribute>& aAttrs,
       
  1029     CMPXMedia& aEntries,
       
  1030     CMPXMediaArray& aArray)
       
  1031     {
       
  1032     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenBrowseNotPlayedL");
       
  1033 
       
  1034     TBool isEpisode(EFalse);
       
  1035     TInt levels(aPath.Levels());
       
  1036 
       
  1037     switch (levels)
       
  1038          {
       
  1039          case 2:
       
  1040             {
       
  1041             // All episodes that haven't been played
       
  1042             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseNotPlayedL_All);
       
  1043 
       
  1044             TInt indexOfCurrentlyPlayingItem(KErrNotFound);
       
  1045             iDbHandler->GetEpisodesMatchingPlaylistL(KNotPlayedPlaylistUID, aAttrs, aArray,
       
  1046                 indexOfCurrentlyPlayingItem);
       
  1047             SetMediaGeneralAttributesL(aEntries, EMPXGroup, EMPXPodcastGroup, EMPXNotYetPlayed,
       
  1048                 *iTitleUnplayed, aArray.Count());
       
  1049             aEntries.SetTObjectValueL(KMPXMediaPodcastCurrentlyPlayingIndex,
       
  1050                 indexOfCurrentlyPlayingItem);
       
  1051             // Fix for Autoplaylist, set the permission to not writable and cacheable
       
  1052             aEntries.SetTObjectValueL<TMPXGeneralNonPermissibleActions>(
       
  1053                 KMPXMediaGeneralNonPermissibleActions, (TMPXGeneralNonPermissibleActions)(EMPXWrite | EMPXCache));
       
  1054 
       
  1055             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseNotPlayedL_All);
       
  1056             break;
       
  1057             }
       
  1058          // An episode in the recently added episodes list
       
  1059          case 3:
       
  1060             {
       
  1061             MPX_PERF_START(CMPXPodcastDbPlugin_DoOpenBrowseNotPlayedL_Episode);
       
  1062             iDbHandler->GetEpisodeL(aPath.Id(levels - 1), aAttrs, aArray);
       
  1063             isEpisode = ETrue;
       
  1064 
       
  1065             MPX_PERF_END(CMPXPodcastDbPlugin_DoOpenBrowseNotPlayedL_Episode);
       
  1066             break;
       
  1067             }
       
  1068          default:
       
  1069             {
       
  1070             MPX_DEBUG2("CMPXPodcastDbPlugin_DoOpenBrowseNotPlayedL: Invalid levels[%d]", levels);
       
  1071             User::Leave(KErrNotSupported);
       
  1072             }
       
  1073        }
       
  1074 
       
  1075     return isEpisode;
       
  1076     }
       
  1077 
       
  1078 // ----------------------------------------------------------------------------
       
  1079 // Process the OpenL method with open mode EMPXOpenPlaylistOnly
       
  1080 // ----------------------------------------------------------------------------
       
  1081 //
       
  1082 CMPXCollectionPath* CMPXPodcastDbPlugin::DoOpenPlaylistL(
       
  1083     const CMPXCollectionPath& aPath,
       
  1084     const TArray<TMPXAttribute>& aAttrs,
       
  1085     TBool aFlagToSignalToBePlayed)
       
  1086     {
       
  1087     MPX_FUNC("CMPXPodcastDbPlugin::DoOpenPlaylistL");
       
  1088 
       
  1089     RArray<TMPXItemId> ids;
       
  1090     CleanupClosePushL(ids);
       
  1091 
       
  1092     CMPXMedia* entries = CMPXMedia::NewL();
       
  1093     CleanupStack::PushL(entries);
       
  1094 
       
  1095     CMPXCollectionPath* path = CMPXCollectionPath::NewL( aPath );
       
  1096     CleanupStack::PushL( path );
       
  1097 
       
  1098     // Go through the browse path
       
  1099     TInt levels(aPath.Levels());
       
  1100     if (levels == 2)
       
  1101         {
       
  1102         // Create a new collection path
       
  1103         CleanupStack::PopAndDestroy(path);
       
  1104         path = CMPXCollectionPath::NewL();
       
  1105         CleanupStack::PushL(path);
       
  1106 
       
  1107         // Always return all episodes here
       
  1108         //
       
  1109         ids.Reset();
       
  1110         ids.AppendL( KDBPluginUid );
       
  1111         path->AppendL(ids.Array());
       
  1112         path->SelectL((TMPXItemId)KDBPluginUid);
       
  1113 
       
  1114         ids.Reset();
       
  1115         ids.AppendL(EBrowseAll);
       
  1116         path->AppendL(ids.Array());
       
  1117         path->SelectL((TMPXItemId) EBrowseAll);
       
  1118         path->Set(EMPXOpenPlaylistOnly);
       
  1119 
       
  1120         // Get all item IDs
       
  1121         CMPXMediaArray* array = CMPXMediaArray::NewL();
       
  1122         CleanupStack::PushL(array);
       
  1123 
       
  1124         DoOpenBrowseAllL(*path, aAttrs, *entries, *array);
       
  1125 
       
  1126         entries->SetCObjectValueL(KMPXMediaArrayContents, array);
       
  1127         entries->SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
       
  1128 
       
  1129         CleanupStack::PopAndDestroy(array);
       
  1130 
       
  1131         DoAppendLevelL(*path, *entries);
       
  1132         }
       
  1133     else if (levels > 2)
       
  1134         {
       
  1135         TInt selectedId(aPath.Id(1));
       
  1136         switch (selectedId)
       
  1137             {
       
  1138             case EBrowseAll:
       
  1139                 {
       
  1140                 path->Set(EMPXOpenPlaylistOnly);
       
  1141                 if(aFlagToSignalToBePlayed)
       
  1142                     {
       
  1143                     // Set the episode ID to be played
       
  1144                     entries->SetTObjectValueL( KMPXMediaGeneralId, aPath.Id(2) );
       
  1145 
       
  1146                     // ignore the error because if there is a problem
       
  1147                     // updating the media file, the error will show up
       
  1148                     // when opening the track for playing and be handled
       
  1149                     // properly by the playback engine and skipped
       
  1150                     TRAP_IGNORE(iDbHandler->SetIsPlayingL(*entries, ETrue));
       
  1151                     }
       
  1152                 break;
       
  1153                 }
       
  1154             case EBrowseTitle:
       
  1155             case EBrowsePubDate:
       
  1156             case EBrowseRecentlyAdded:
       
  1157             case EBrowseNotPlayed:
       
  1158                 {
       
  1159                 if (!DoOpenL(aPath, aAttrs, *entries, aFlagToSignalToBePlayed))
       
  1160                     {
       
  1161                     path->Set(EMPXOpenPlaylistOnly);
       
  1162                     // If it is not at a episode level
       
  1163                     // Append all entries to create collection path
       
  1164                     //
       
  1165                     DoAppendLevelL(*path, *entries);
       
  1166                     }
       
  1167                 break;
       
  1168                 }
       
  1169             default:
       
  1170                 {
       
  1171                 User::Leave(KErrNotSupported);
       
  1172                 }
       
  1173             }
       
  1174         }
       
  1175     else  // levels < 2
       
  1176         {
       
  1177         User::Leave(KErrNotSupported);
       
  1178         }
       
  1179 
       
  1180     // Cleanup
       
  1181     CleanupStack::Pop(path);
       
  1182     CleanupStack::PopAndDestroy(entries);
       
  1183     CleanupStack::PopAndDestroy(&ids);
       
  1184 
       
  1185     return path;
       
  1186     }
       
  1187 
       
  1188 // ----------------------------------------------------------------------------
       
  1189 // Process the MediaL command
       
  1190 // ----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CMPXPodcastDbPlugin::DoMediaL(
       
  1193     const CMPXCollectionPath& aPath,
       
  1194     const TArray<TMPXAttribute>& aAttrs,
       
  1195     CMPXMedia& aEntries)
       
  1196     {
       
  1197     MPX_FUNC("CMPXPodcastDbPlugin::DoMediaL");
       
  1198 
       
  1199 	CMPXMediaArray* array = CMPXMediaArray::NewL();
       
  1200 	CleanupStack::PushL(array);
       
  1201 
       
  1202 	DoTitlesMediaL(aPath, aAttrs, aEntries, *array);
       
  1203 
       
  1204 	if (array->Count() > 0)
       
  1205 		{
       
  1206 		aEntries.SetCObjectValueL(KMPXMediaArrayContents, array);
       
  1207 		aEntries.SetTObjectValueL<TInt>(KMPXMediaArrayCount, array->Count());
       
  1208 		}
       
  1209 	CleanupStack::PopAndDestroy(array);
       
  1210     }
       
  1211 
       
  1212 // ----------------------------------------------------------------------------
       
  1213 // Find the collection media for root level
       
  1214 // ----------------------------------------------------------------------------
       
  1215 //
       
  1216 void CMPXPodcastDbPlugin::DoRootMediaL(
       
  1217     const TArray<TMPXAttribute>& aAttrs,
       
  1218     CMPXMedia& aMedia)
       
  1219     {
       
  1220     MPX_FUNC("CMPXPodcastDbPlugin::DoRootMediaL");
       
  1221 #ifndef __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1222     aMedia.SetTObjectValueL<TMPXGeneralNonPermissibleActions> (
       
  1223             KMPXMediaGeneralNonPermissibleActions, (TMPXGeneralNonPermissibleActions)(EMPXWrite | EMPXCache) );
       
  1224 #endif // __ENABLE_PODCAST_IN_MUSIC_MENU
       
  1225     TInt count(aAttrs.Count());
       
  1226     for (TInt i = 0; i < count; ++i)
       
  1227         {
       
  1228         if (aAttrs[i].ContentId() == KMPXMediaIdGeneral)
       
  1229             {
       
  1230             TUint att = aAttrs[i].AttributeId();
       
  1231 
       
  1232             if (att & EMPXMediaGeneralTitle)
       
  1233                 {
       
  1234                 // set the collection plugin name
       
  1235                 HBufC* title(iResource->ReadHBufCL(R_MPX_QTN_MUS_PODCASTS));
       
  1236                 CleanupStack::PushL(title);
       
  1237                 aMedia.SetTextValueL(KMPXMediaGeneralTitle, *title);
       
  1238                 CleanupStack::PopAndDestroy(title);
       
  1239                 }
       
  1240             if (att & EMPXMediaGeneralSubTitle)
       
  1241                 {
       
  1242                 TInt numEpisodes(iDbHandler->NumberOfItemsL(EMPXEpisode));
       
  1243 
       
  1244                 HBufC* text(iResource->ReadHBufCL((numEpisodes == 1) ?
       
  1245                     R_MPX_QTN_MUS_PODCAST_ONE_EPISODE : R_MPX_QTN_MUS_PODCAST_NUM_EPISODES));
       
  1246                 CleanupStack::PushL(text);
       
  1247                 aMedia.SetTextValueL(KMPXMediaGeneralSubTitle, *text);
       
  1248                 aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralCount, numEpisodes);
       
  1249                 CleanupStack::PopAndDestroy(text);
       
  1250                 }
       
  1251             if (att & EMPXMediaGeneralIcon)
       
  1252                 {
       
  1253 /*
       
  1254                 // set the collection plugin icon
       
  1255                 TIconInfo icon;
       
  1256                 icon.bmpfile = KMPlayerDbPluginMbmFile;
       
  1257                 icon.bitmapId = EMbmMpxpodcastdbpluginQgn_graf_mup_dlst_podcast;
       
  1258                 icon.maskId = EMbmMpxpodcastdbpluginQgn_graf_mup_dlst_podcast_mask;
       
  1259                 aMedia.SetTObjectValueL<TIconInfo>(KMPXMediaGeneralIcon, icon );
       
  1260 */
       
  1261                 }
       
  1262             } // if
       
  1263         } // for
       
  1264     }
       
  1265 
       
  1266 // ----------------------------------------------------------------------------
       
  1267 // Find the collection media for all episodes category
       
  1268 // ----------------------------------------------------------------------------
       
  1269 //
       
  1270 void CMPXPodcastDbPlugin::DoAllEpisodesMediaL(
       
  1271     const CMPXCollectionPath& aPath,
       
  1272     const TArray<TMPXAttribute>& aAttrs,
       
  1273     CMPXMedia& aEntries,
       
  1274     CMPXMediaArray& aMediaArray)
       
  1275     {
       
  1276     MPX_FUNC("CMPXPodcastDbPlugin::DoAllEpisodesMediaL");
       
  1277 
       
  1278     TInt levels(aPath.Levels());
       
  1279     switch (levels)
       
  1280        {
       
  1281         // All episodes
       
  1282         case 2:
       
  1283             {
       
  1284             MPX_PERF_START(CMPXPodcastDbPlugin_DoAllEpisodesMediaL_All);
       
  1285             DoRootCategoryMediaL(aAttrs, aPath.Id(1), EMPXAll, aEntries);
       
  1286             MPX_PERF_END(CMPXPodcastDbPlugin_DoAllEpisodesMediaL_All);
       
  1287             break;
       
  1288             }
       
  1289         // An episode in all episodes
       
  1290         case 3:
       
  1291             {
       
  1292             MPX_PERF_START(CMPXPodcastDbPlugin_DoAllEpisodesMediaL_Episode);
       
  1293             GetEpisodeInfoL(aPath, aAttrs, aEntries, aMediaArray);
       
  1294             MPX_PERF_END(CMPXPodcastDbPlugin_DoAllEpisodesMediaL_Episode);
       
  1295             break;
       
  1296             }
       
  1297         default:
       
  1298             {
       
  1299             MPX_DEBUG2("CMPXPodcastDbPlugin_DoAllEpisodesMediaL: Invalid levels[%d]", levels);
       
  1300             User::Leave(KErrNotSupported);
       
  1301             }
       
  1302         } // end switch(levels)
       
  1303     }
       
  1304 
       
  1305 // ----------------------------------------------------------------------------
       
  1306 // Find the collection media for by publish date category
       
  1307 // ----------------------------------------------------------------------------
       
  1308 //
       
  1309 void CMPXPodcastDbPlugin::DoByPublishDateMediaL(
       
  1310     const CMPXCollectionPath& aPath,
       
  1311     const TArray<TMPXAttribute>& aAttrs,
       
  1312     CMPXMedia& aEntries,
       
  1313     CMPXMediaArray& aMediaArray)
       
  1314     {
       
  1315     MPX_FUNC("CMPXPodcastDbPlugin::DoByPublishDateMediaL");
       
  1316 
       
  1317     TInt levels(aPath.Levels());
       
  1318     TInt idIndex(levels - 1);
       
  1319 
       
  1320     // All By Publish Date Categories
       
  1321     if (levels == 2)
       
  1322         {
       
  1323         MPX_PERF_START(CMPXPodcastDbPlugin_DoByPublishDateMediaL_All);
       
  1324         DoRootCategoryMediaL(aAttrs, aPath.Id(1), EMPXPubDate, aEntries);
       
  1325         MPX_PERF_END(CMPXPodcastDbPlugin_DoByPublishDateMediaL_All);
       
  1326         }
       
  1327     else if (levels == 3) // by publish date category selected
       
  1328         {
       
  1329         MPX_PERF_START(CMPXPodcastDbPlugin_DoByPublishDateMediaL_Category);
       
  1330         const TDesC& title = iPodcastEpisodeViewPublishDateTitle->MdcaPoint(
       
  1331             aPath.Id(idIndex).iId2 & 0x00FFFFFF);
       
  1332         aEntries.SetTextValueL(KMPXMediaGeneralTitle, title);
       
  1333         MPX_PERF_END(CMPXPodcastDbPlugin_DoByPublishDateMediaL_Category);
       
  1334         }
       
  1335      else if (levels == 4) // an episode within the category
       
  1336         {
       
  1337         MPX_PERF_START(CMPXPodcastDbPlugin_DoByPublishDateMediaL_Episode);
       
  1338         GetEpisodeInfoL(aPath, aAttrs, aEntries, aMediaArray);
       
  1339         MPX_PERF_END(CMPXPodcastDbPlugin_DoByPublishDateMediaL_Episode);
       
  1340         }
       
  1341     else
       
  1342         {
       
  1343         MPX_DEBUG2("CMPXPodcastDbPlugin_DoByPublishDateMediaL: Invalid levels[%d]", levels);
       
  1344         User::Leave(KErrNotSupported);
       
  1345         }
       
  1346     }
       
  1347 
       
  1348 // ----------------------------------------------------------------------------
       
  1349 // Find the collection media for titles category
       
  1350 // ----------------------------------------------------------------------------
       
  1351 //
       
  1352 void CMPXPodcastDbPlugin::DoTitlesMediaL(
       
  1353     const CMPXCollectionPath& aPath,
       
  1354     const TArray<TMPXAttribute>& aAttrs,
       
  1355     CMPXMedia& aEntries,
       
  1356     CMPXMediaArray& aMediaArray)
       
  1357     {
       
  1358     MPX_FUNC("CMPXPodcastDbPlugin::DoTitlesMediaL");
       
  1359 
       
  1360     TInt levels(aPath.Levels());
       
  1361     TInt idIndex(levels - 1);
       
  1362 
       
  1363      // All Titles Categories
       
  1364     if (levels == 1)
       
  1365         {
       
  1366         MPX_PERF_START(CMPXPodcastDbPlugin_DoTitlesMediaL_All);
       
  1367         DoRootCategoryMediaL(aAttrs, aPath.Id(1), EMPXTitle, aEntries);
       
  1368         MPX_PERF_END(CMPXPodcastDbPlugin_DoTitlesMediaL_All);
       
  1369         }
       
  1370     else if (levels == 2) // All episodes within selected title
       
  1371         {
       
  1372         MPX_PERF_START (CMPXPodcastDbPlugin_DoTitlesMediaL_Title);
       
  1373         iDbHandler->GetAllPodcastTitlesL(aAttrs, aMediaArray);
       
  1374         HBufC* title = iDbHandler->GetTitleNameMatchingIdL(aPath.Id(idIndex));
       
  1375         CleanupStack::PushL(title);
       
  1376         aEntries.SetTextValueL(KMPXMediaGeneralTitle, *title);
       
  1377         CleanupStack::PopAndDestroy(title);
       
  1378         MPX_PERF_END (CMPXPodcastDbPlugin_DoTitlesMediaL_Title);
       
  1379         }
       
  1380      else if (levels == 3) // an episode within a selected title
       
  1381         {
       
  1382         MPX_PERF_START(CMPXPodcastDbPlugin_DoTitlesMediaL_Episode);
       
  1383         GetEpisodeInfoL (aPath, aAttrs, aEntries, aMediaArray);
       
  1384         MPX_PERF_END(CMPXPodcastDbPlugin_DoTitlesMediaL_Episode);
       
  1385         }
       
  1386      else
       
  1387         {
       
  1388         MPX_DEBUG2("CMPXPodcastDbPlugin_DoTitlesMediaL: Invalid levels[%d]", levels);
       
  1389         User::Leave(KErrNotSupported);
       
  1390         }
       
  1391     }
       
  1392 
       
  1393 // ----------------------------------------------------------------------------
       
  1394 // Find the collection media for recently added
       
  1395 // ----------------------------------------------------------------------------
       
  1396 //
       
  1397 void CMPXPodcastDbPlugin::DoRecentlyAddedMediaL(
       
  1398     const CMPXCollectionPath& aPath,
       
  1399     const TArray<TMPXAttribute>& aAttrs,
       
  1400     CMPXMedia& aEntries,
       
  1401     CMPXMediaArray& aMediaArray)
       
  1402     {
       
  1403     MPX_FUNC("CMPXPodcastDbPlugin::DoRecentlyAddedMediaL");
       
  1404 
       
  1405     switch (aPath.Levels())
       
  1406        {
       
  1407        // All episodes
       
  1408        case 2:
       
  1409             {
       
  1410             MPX_PERF_START(CMPXPodcastDbPlugin_DoRecentlyAddedMediaL_All);
       
  1411             DoRootCategoryMediaL(aAttrs, aPath.Id(1), EMPXRecentlyAdded, aEntries);
       
  1412             MPX_PERF_END(CMPXPodcastDbPlugin_DoRecentlyAddedMediaL_All);
       
  1413             break;
       
  1414             }
       
  1415 
       
  1416          // An episode that was recently added
       
  1417          case 3:
       
  1418             {
       
  1419             MPX_PERF_START(CMPXPodcastDbPlugin_DoRecentlyAddedMediaL_Episode);
       
  1420             GetEpisodeInfoL(aPath, aAttrs, aEntries, aMediaArray);
       
  1421             MPX_PERF_END(CMPXPodcastDbPlugin_DoRecentlyAddedMediaL_Episode);
       
  1422             break;
       
  1423             }
       
  1424 
       
  1425          default:
       
  1426             {
       
  1427             MPX_DEBUG2("CMPXPodcastDbPlugin_DoRecentlyAddedMediaL: Invalid levels[%d]", aPath.Levels());
       
  1428             User::Leave(KErrNotSupported);
       
  1429             }
       
  1430         } // end switch(levels)
       
  1431     }
       
  1432 
       
  1433 // ----------------------------------------------------------------------------
       
  1434 // Find the collection media for recently added
       
  1435 // ----------------------------------------------------------------------------
       
  1436 //
       
  1437 void CMPXPodcastDbPlugin::DoNotYetPlayedMediaL(
       
  1438     const CMPXCollectionPath& aPath,
       
  1439     const TArray<TMPXAttribute>& aAttrs,
       
  1440     CMPXMedia& aEntries,
       
  1441     CMPXMediaArray& aMediaArray)
       
  1442     {
       
  1443     MPX_FUNC("CMPXPodcastDbPlugin::DoNotYetPlayedMediaL");
       
  1444 
       
  1445     switch (aPath.Levels())
       
  1446        {
       
  1447        // All episodes
       
  1448        case 2:
       
  1449             {
       
  1450             MPX_PERF_START(CMPXPodcastDbPlugin_DoNotYetPlayedMediaL_All);
       
  1451             DoRootCategoryMediaL(aAttrs, aPath.Id(1), EMPXNotYetPlayed, aEntries);
       
  1452             MPX_PERF_END(CMPXPodcastDbPlugin_DoNotYetPlayedMediaL_All);
       
  1453             break;
       
  1454             }
       
  1455 
       
  1456          // An episode that was never played
       
  1457          case 3:
       
  1458             {
       
  1459             MPX_PERF_START(CMPXPodcastDbPlugin_DoNotYetPlayedMediaL_Episode);
       
  1460             MPX_TRAPD(err, GetEpisodeInfoL(aPath, aAttrs, aEntries, aMediaArray));
       
  1461 
       
  1462             if (err != KErrNotFound)
       
  1463                 {
       
  1464                 // it's o.k if the episode isn't found because the episode
       
  1465                 // might have finished playing and is no longer
       
  1466                 // part of the "Not yet played" playlist
       
  1467                 User::LeaveIfError(err);
       
  1468                 }
       
  1469 
       
  1470             MPX_PERF_END(CMPXPodcastDbPlugin_DoNotYetPlayedMediaL_Episode);
       
  1471             break;
       
  1472             }
       
  1473 
       
  1474          default:
       
  1475             {
       
  1476             MPX_DEBUG2("CMPXPodcastDbPlugin_DoNotYetPlayedMediaL: Invalid levels[%d]", aPath.Levels());
       
  1477             User::Leave(KErrNotSupported);
       
  1478             }
       
  1479         } // end switch(levels)
       
  1480     }
       
  1481 
       
  1482 // ----------------------------------------------------------------------------
       
  1483 // Find the collection media for the root menu
       
  1484 // ----------------------------------------------------------------------------
       
  1485 //
       
  1486 void CMPXPodcastDbPlugin::DoRootCategoryMediaL(
       
  1487     const TArray<TMPXAttribute>& aAttrs,
       
  1488     TMPXItemId aRootCategoryId,
       
  1489     TMPXPodcastCategory aCategory,
       
  1490     CMPXMedia& aEntries)
       
  1491     {
       
  1492     MPX_FUNC("CMPXPodcastDbPlugin::DoRootCategoryMediaL");
       
  1493 
       
  1494     TInt count(aAttrs.Count());
       
  1495     for (TInt i = 0; i < count; ++i)
       
  1496         {
       
  1497         if (aAttrs[i].ContentId() == KMPXMediaIdGeneral)
       
  1498             {
       
  1499             TUint att(aAttrs[i].AttributeId());
       
  1500 
       
  1501             if (att & EMPXMediaGeneralId)
       
  1502                 {
       
  1503                 aEntries.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId,
       
  1504                     aRootCategoryId);
       
  1505                 }
       
  1506             if (att & EMPXMediaGeneralTitle)
       
  1507                 {
       
  1508                 aEntries.SetTextValueL(KMPXMediaGeneralTitle,
       
  1509                     iPodcastLibraryTitles->MdcaPoint(BrowseTypeForCategory(aCategory)));
       
  1510                 }
       
  1511             } // end if
       
  1512         } // end for
       
  1513 
       
  1514     aEntries.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXGroup);
       
  1515     aEntries.SetTObjectValueL<TMPXPodcastCategory>(KMPXMediaGeneralCategory, aCategory);
       
  1516     }
       
  1517 
       
  1518 // ----------------------------------------------------------------------------
       
  1519 // Set all the attributes in CMPXMedia corresponding to KMPXMediaIdDrm
       
  1520 // ----------------------------------------------------------------------------
       
  1521 //
       
  1522 void CMPXPodcastDbPlugin::DoSetMediaDrmL(
       
  1523     CMPXMedia& aMedia,
       
  1524     TUint aDrmAttributes,
       
  1525     const TDesC& aLocation)
       
  1526     {
       
  1527     MPX_FUNC("CMPXPodcastDbPlugin::DoSetMediaDrmL");
       
  1528 
       
  1529     iDrmMediaUtility->InitL(aLocation);
       
  1530     CleanupClosePushL(*iDrmMediaUtility);
       
  1531     const CMPXMedia* drmMedia(iDrmMediaUtility->GetMediaL(aDrmAttributes));
       
  1532 
       
  1533     // Only get attributes if it's a DRM file
       
  1534     if (drmMedia)
       
  1535         {
       
  1536         if ((aDrmAttributes & EMPXMediaDrmType) &&
       
  1537             drmMedia->IsSupported(KMPXMediaDrmType))
       
  1538             {
       
  1539             aMedia.SetTObjectValueL(KMPXMediaDrmType,
       
  1540                 drmMedia->ValueTObjectL<TInt>(KMPXMediaDrmType));
       
  1541             }
       
  1542         if ((aDrmAttributes & EMPXMediaDrmRightsStatus) &&
       
  1543             drmMedia->IsSupported(KMPXMediaDrmRightsStatus))
       
  1544             {
       
  1545             aMedia.SetTObjectValueL(KMPXMediaDrmRightsStatus,
       
  1546                  drmMedia->ValueTObjectL<TInt>(KMPXMediaDrmRightsStatus));
       
  1547             }
       
  1548         if ((aDrmAttributes & EMPXMediaDrmRightsType) &&
       
  1549             drmMedia->IsSupported(KMPXMediaDrmRightsType))
       
  1550             {
       
  1551             aMedia.SetTObjectValueL(KMPXMediaDrmRightsType,
       
  1552                  drmMedia->ValueTObjectL<TInt>(KMPXMediaDrmRightsType));
       
  1553             }
       
  1554         if ((aDrmAttributes & EMPXMediaDrmCount) &&
       
  1555             drmMedia->IsSupported(KMPXMediaDrmCount))
       
  1556             {
       
  1557             aMedia.SetTObjectValueL(KMPXMediaDrmCount,
       
  1558                  drmMedia->ValueTObjectL<TInt>(KMPXMediaDrmCount));
       
  1559             }
       
  1560         if ((aDrmAttributes & EMPXMediaDrmProtected) &&
       
  1561             drmMedia->IsSupported(KMPXMediaDrmProtected))
       
  1562             {
       
  1563             aMedia.SetTObjectValueL(KMPXMediaDrmProtected,
       
  1564                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmProtected));
       
  1565             }
       
  1566         if ((aDrmAttributes & EMPXMediaDrmSendingAllowed) &&
       
  1567             drmMedia->IsSupported(KMPXMediaDrmSendingAllowed))
       
  1568             {
       
  1569             aMedia.SetTObjectValueL(KMPXMediaDrmSendingAllowed,
       
  1570                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmSendingAllowed));
       
  1571             }
       
  1572         if ((aDrmAttributes & EMPXMediaDrmCanSetAutomated) &&
       
  1573             drmMedia->IsSupported(KMPXMediaDrmCanSetAutomated))
       
  1574             {
       
  1575             aMedia.SetTObjectValueL(KMPXMediaDrmCanSetAutomated,
       
  1576                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmCanSetAutomated));
       
  1577             }
       
  1578         if ((aDrmAttributes & EMPXMediaDrmHasInfoUrl) &&
       
  1579             drmMedia->IsSupported(KMPXMediaDrmHasInfoUrl))
       
  1580             {
       
  1581             aMedia.SetTObjectValueL(KMPXMediaDrmHasInfoUrl,
       
  1582                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmHasInfoUrl));
       
  1583             }
       
  1584         if ((aDrmAttributes & EMPXMediaDrmHasPreviewUrl) &&
       
  1585             drmMedia->IsSupported(KMPXMediaDrmHasPreviewUrl))
       
  1586             {
       
  1587             aMedia.SetTObjectValueL(KMPXMediaDrmHasPreviewUrl,
       
  1588                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmHasPreviewUrl));
       
  1589             }
       
  1590         if ((aDrmAttributes & EMPXMediaDrmAboutToExpire) &&
       
  1591             drmMedia->IsSupported(KMPXMediaDrmAboutToExpire))
       
  1592             {
       
  1593             aMedia.SetTObjectValueL( KMPXMediaDrmAboutToExpire,
       
  1594                  drmMedia->ValueTObjectL<TBool>(KMPXMediaDrmAboutToExpire));
       
  1595             }
       
  1596         if ((aDrmAttributes & EMPXMediaDrmStartTime) &&
       
  1597             drmMedia->IsSupported(KMPXMediaDrmStartTime))
       
  1598             {
       
  1599             aMedia.SetTObjectValueL(KMPXMediaDrmStartTime,
       
  1600                  drmMedia->ValueTObjectL<TInt64>(KMPXMediaDrmStartTime));
       
  1601             }
       
  1602         if ((aDrmAttributes & EMPXMediaDrmEndTime) &&
       
  1603             drmMedia->IsSupported(KMPXMediaDrmEndTime))
       
  1604             {
       
  1605             aMedia.SetTObjectValueL( KMPXMediaDrmEndTime,
       
  1606                  drmMedia->ValueTObjectL<TInt64>(KMPXMediaDrmEndTime));
       
  1607             }
       
  1608         if ((aDrmAttributes & EMPXMediaDrmIntervalStartTime) &&
       
  1609             drmMedia->IsSupported(KMPXMediaDrmIntervalStartTime))
       
  1610             {
       
  1611             aMedia.SetTObjectValueL( KMPXMediaDrmIntervalStartTime,
       
  1612                  drmMedia->ValueTObjectL<TInt64>(KMPXMediaDrmIntervalStartTime));
       
  1613             }
       
  1614         if ((aDrmAttributes & EMPXMediaDrmAccumulatedTime) &&
       
  1615             drmMedia->IsSupported(KMPXMediaDrmAccumulatedTime))
       
  1616             {
       
  1617             aMedia.SetTObjectValueL(KMPXMediaDrmAccumulatedTime,
       
  1618                  drmMedia->ValueTObjectL<TInt64>(KMPXMediaDrmAccumulatedTime));
       
  1619             }
       
  1620         if ((aDrmAttributes & EMPXMediaDrmInterval) &&
       
  1621             drmMedia->IsSupported(KMPXMediaDrmInterval))
       
  1622             {
       
  1623             aMedia.SetTObjectValueL( KMPXMediaDrmInterval,
       
  1624                  drmMedia->ValueTObjectL<TTimeIntervalSeconds>(KMPXMediaDrmInterval));
       
  1625             }
       
  1626         }
       
  1627 
       
  1628     CleanupStack::PopAndDestroy(iDrmMediaUtility);
       
  1629     }
       
  1630 
       
  1631 // ----------------------------------------------------------------------------
       
  1632 // Add media objects to the array with attributes from episode details
       
  1633 // ----------------------------------------------------------------------------
       
  1634 //
       
  1635 void CMPXPodcastDbPlugin::GetEpisodeInfoL(
       
  1636     const CMPXCollectionPath& aPath,
       
  1637     const TArray<TMPXAttribute>& aAttrs,
       
  1638     CMPXMedia& aEntry,
       
  1639     CMPXMediaArray& aMediaArray)
       
  1640     {
       
  1641     MPX_FUNC("CMPXPodcastDbPlugin::GetEpisodeInfoL");
       
  1642 
       
  1643     RArray<TInt> supportedIds;
       
  1644     CleanupClosePushL(supportedIds);
       
  1645     MPXDbCommonUtil::FillInSupportedUIDsL(aAttrs, supportedIds);
       
  1646 
       
  1647     RArray<TMPXItemId> selections;
       
  1648     CleanupClosePushL(selections);
       
  1649     aPath.SelectionL(selections);
       
  1650 
       
  1651     TInt countSelection(aPath.Selection().Count());
       
  1652     if (countSelection)
       
  1653         {
       
  1654         for (TInt selectionIndex = 0; selectionIndex < countSelection; ++selectionIndex)
       
  1655             {
       
  1656             CMPXMedia* newEntry = CMPXMedia::NewL(supportedIds.Array());
       
  1657             CleanupStack::PushL(newEntry);
       
  1658 
       
  1659             DoGetEpisodeInfoL(aAttrs, selections[selectionIndex].iId2, *newEntry);
       
  1660 
       
  1661             aMediaArray.AppendL(*newEntry);
       
  1662             CleanupStack::PopAndDestroy(newEntry);
       
  1663             }
       
  1664         }
       
  1665     else
       
  1666         {
       
  1667         // No selection, get the attributes for the one song
       
  1668         DoGetEpisodeInfoL(aAttrs, aPath.Id(aPath.Levels() - 1).iId2, aEntry);
       
  1669         }
       
  1670 
       
  1671     CleanupStack::PopAndDestroy(&selections);
       
  1672     CleanupStack::PopAndDestroy(&supportedIds);
       
  1673     }
       
  1674 
       
  1675 // ----------------------------------------------------------------------------
       
  1676 // Retrieves the attributes for a media object.
       
  1677 // ----------------------------------------------------------------------------
       
  1678 //
       
  1679 void CMPXPodcastDbPlugin::DoGetEpisodeInfoL(
       
  1680     const TArray<TMPXAttribute>& aAttrs,
       
  1681     TInt aEntryId,
       
  1682     CMPXMedia& aEntry)
       
  1683     {
       
  1684     MPX_FUNC("CMPXPodcastDbPlugin::DoGetEpisodeInfoL");
       
  1685 
       
  1686     iDbHandler->GetEpisodeL(aEntryId, aAttrs, aEntry);
       
  1687 
       
  1688     const TDesC& location(aEntry.ValueText(KMPXMediaGeneralUri));
       
  1689 
       
  1690     // Check DRM Only if we have a location
       
  1691     if (location != KNullDesC)
       
  1692         {
       
  1693         TUint drmAttributes(0);
       
  1694 
       
  1695         // Compact the attribute set
       
  1696         TInt count(aAttrs.Count());
       
  1697         for (TInt i = 0; i < count; ++i)
       
  1698             {
       
  1699             if (aAttrs[i].ContentId() == KMPXMediaIdDrm)
       
  1700                 {
       
  1701                 drmAttributes |= aAttrs[i].AttributeId();
       
  1702                 }
       
  1703             }
       
  1704 
       
  1705         // Set the correct attributes to media, only if requested
       
  1706         if (drmAttributes)
       
  1707             {
       
  1708             DoSetMediaDrmL(aEntry, drmAttributes, location);
       
  1709             }
       
  1710         }
       
  1711     }
       
  1712 
       
  1713 // ----------------------------------------------------------------------------
       
  1714 // Retrieve the collection details
       
  1715 // ----------------------------------------------------------------------------
       
  1716 //
       
  1717 void CMPXPodcastDbPlugin::DoHandleOtherMediaAttributesL(
       
  1718     const TArray<TMPXAttribute>& aAttrs,
       
  1719     const CMPXCollectionPath& aPath,
       
  1720     CMPXMedia& aMedia)
       
  1721     {
       
  1722     MPX_FUNC("CMPXPodcastDbPlugin::DoHandleOtherMediaAttributesL");
       
  1723 
       
  1724     TInt count(aAttrs.Count());
       
  1725     for (TInt i = 0; i < count; ++i)
       
  1726         {
       
  1727         if (aAttrs[i].ContentId() == KMPXMediaIdCollectionDetails)
       
  1728             {
       
  1729             TUint att(aAttrs[i].AttributeId());
       
  1730 
       
  1731             if (att & EMPXMediaColDetailNumberOfItems)
       
  1732                 {
       
  1733                 aMedia.SetTObjectValueL(KMPXMediaColDetailNumberOfItems,
       
  1734                     iDbHandler->NumberOfItemsL(EMPXEpisode) );
       
  1735                 }
       
  1736             if (att & EMPXMediaColDetailDuration)
       
  1737                 {
       
  1738                 aMedia.SetTObjectValueL(KMPXMediaColDetailDuration,
       
  1739                     DoDurationL( aMedia, EMPXEpisode ) );
       
  1740                 }
       
  1741             if (att & EMPXMediaColTotalSize)
       
  1742                 {
       
  1743                 TInt totalSize(0);
       
  1744                 // todo
       
  1745                 aMedia.SetTObjectValueL(KMPXMediaColDetailTotalSize, totalSize );
       
  1746                 }
       
  1747             if (att & EMPXMediaLastRefreshed)
       
  1748                 {
       
  1749                 TTime lastRefreshed = iDbHandler->GetLastRefreshedTimeL();
       
  1750                 aMedia.SetTObjectValueL(KMPXMediaColDetailLastRefreshed,
       
  1751                     lastRefreshed.Int64() );
       
  1752                 }
       
  1753             if (att & EMPXMediaColDetailDBCreated)
       
  1754                 {
       
  1755                 aMedia.SetTObjectValueL(KMPXMediaColDetailDBCreated,
       
  1756                     iDbHandler->DatabaseCreated());
       
  1757                 }
       
  1758             if (att & EMPXMediaColDetailDBCorrupted)
       
  1759                 {
       
  1760                 aMedia.SetTObjectValueL(KMPXMediaColDetailDBCorrupted,
       
  1761                     iDbHandler->IsDBCorruptedL());
       
  1762                 }
       
  1763             }
       
  1764         else if (aAttrs[i] == KMPXMediaGeneralPath)
       
  1765             {
       
  1766             aMedia.SetCObjectValueL(KMPXMediaGeneralPath,
       
  1767                 const_cast<CMPXCollectionPath*>(&aPath));
       
  1768             }
       
  1769         }
       
  1770     }
       
  1771 
       
  1772 // ----------------------------------------------------------------------------
       
  1773 // Remove an item from the collection database using the given path
       
  1774 // ----------------------------------------------------------------------------
       
  1775 //
       
  1776 CDesCArray* CMPXPodcastDbPlugin::DoRemoveL(
       
  1777     const CMPXCollectionPath& aPath,
       
  1778     CMPXMessageArray& aChangeMsgArray)
       
  1779     {
       
  1780     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveL");
       
  1781 
       
  1782     if (aPath.Levels() <= 0)
       
  1783         {
       
  1784         User::Leave(KErrNotSupported);
       
  1785         }
       
  1786 
       
  1787     // Return file path for deleted item(s)
       
  1788     //
       
  1789     CDesCArray* fp = new(ELeave) CDesCArrayFlat(1);
       
  1790     CleanupStack::PushL(fp);
       
  1791 
       
  1792     // Ids of the selected items
       
  1793     RArray<TMPXItemId> selections;
       
  1794     CleanupClosePushL(selections);
       
  1795     aPath.SelectionL(selections);
       
  1796 
       
  1797     DoRemoveFromCategoriesL(aPath, selections.Array(), EMPXAlbum, *fp, aChangeMsgArray);
       
  1798 
       
  1799     MPX_DEBUG2("CMPXPodcastDbPlugin::DoRemoveL itemId[%d]", aPath.Id (aPath.Levels() - 1).iId2);
       
  1800 
       
  1801     CleanupStack::PopAndDestroy(&selections);
       
  1802     CleanupStack::Pop(fp);
       
  1803 
       
  1804     return fp;
       
  1805     }
       
  1806 
       
  1807 // ----------------------------------------------------------------------------
       
  1808 // Remove media by path through a command
       
  1809 // ----------------------------------------------------------------------------
       
  1810 //
       
  1811 void CMPXPodcastDbPlugin::DoRemoveL(
       
  1812     const CMPXMedia& aMedia,
       
  1813     TBool aDeleteRecord)
       
  1814     {
       
  1815     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveL(by command)");
       
  1816 
       
  1817     // Return deleted file paths to caller
       
  1818     CDesCArray* fp = new(ELeave) CDesCArrayFlat(1);
       
  1819     CleanupStack::PushL(fp);
       
  1820 
       
  1821     // a list of change event messages a result of the item being removed
       
  1822     CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  1823     CleanupStack::PushL(itemChangedMessages);
       
  1824 
       
  1825     TUint32 podcastEpisodeId(0);
       
  1826 
       
  1827     // Removing a container of items
       
  1828     //
       
  1829     if (aMedia.IsSupported(KMPXMediaArrayContents))
       
  1830         {
       
  1831         MPX_DEBUG1("CMPXPodcastDbPlugin::RemoveL -- Removing a container of items");
       
  1832         const CMPXMediaArray* media = (aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents));
       
  1833         if( !media )
       
  1834             {
       
  1835             User::Leave( KErrNoMemory );
       
  1836             }
       
  1837         const TInt mediaCount(media->Count());
       
  1838         for (TInt i = 0; i < mediaCount; ++i)
       
  1839             {
       
  1840             CMPXMedia* entry = media->AtL(i);
       
  1841             if( entry->IsSupported(KMPXMediaGeneralId))
       
  1842                 {
       
  1843                 podcastEpisodeId = entry->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  1844                 }
       
  1845             else if (entry->IsSupported(KMPXMediaGeneralUri))
       
  1846                 {
       
  1847                 podcastEpisodeId = iDbHandler->GetEpisodeIdMatchingUriL(
       
  1848                     entry->ValueText(KMPXMediaGeneralUri));
       
  1849                 }
       
  1850             else
       
  1851                 {
       
  1852                 // Unable to process this item
       
  1853                 continue;
       
  1854                 }
       
  1855 
       
  1856             iDbHandler->RemoveEpisodeL(podcastEpisodeId, *fp, *itemChangedMessages,
       
  1857                 aDeleteRecord);
       
  1858             }
       
  1859         }
       
  1860     // Removing an item with known item id
       
  1861     //
       
  1862     else if (aMedia.IsSupported(KMPXMediaGeneralId))
       
  1863         {
       
  1864         MPX_DEBUG1("CMPXPodcastDbPlugin::RemoveL -- Removing an item by item id");
       
  1865         podcastEpisodeId = aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  1866 
       
  1867         if ((podcastEpisodeId >> 28) != EMPXPlaylist)
       
  1868             {
       
  1869             iDbHandler->RemoveEpisodeL(podcastEpisodeId, *fp,
       
  1870                 *itemChangedMessages, aDeleteRecord);
       
  1871             }
       
  1872         else
       
  1873             {
       
  1874             MPX_DEBUG1("CMPXPodcastDbPlugin::RemoveL -- Playlists not supported within podcast collection");
       
  1875             User::Leave(KErrNotSupported);
       
  1876             }
       
  1877         }
       
  1878     // Removing an item with known uri
       
  1879     //
       
  1880     else if (aMedia.IsSupported(KMPXMediaGeneralUri))
       
  1881         {
       
  1882         MPX_DEBUG1("CMPXPodcastDbPlugin::RemoveL -- Removing an item by uri");
       
  1883         podcastEpisodeId = iDbHandler->GetEpisodeIdMatchingUriL(
       
  1884             aMedia.ValueText(KMPXMediaGeneralUri));
       
  1885         iDbHandler->RemoveEpisodeL(podcastEpisodeId, *fp, *itemChangedMessages,
       
  1886             aDeleteRecord);
       
  1887         }
       
  1888     else
       
  1889         {
       
  1890         MPX_DEBUG1("CMPXPodcastDbPlugin::RemoveL -- Unknown item for removal");
       
  1891         User::Leave(KErrNotSupported);
       
  1892         }
       
  1893 
       
  1894     iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
  1895     DoHandleChangeL(itemChangedMessages);
       
  1896 
       
  1897     CleanupStack::PopAndDestroy(itemChangedMessages);
       
  1898     CleanupStack::PopAndDestroy(fp);
       
  1899     }
       
  1900 
       
  1901 // ----------------------------------------------------------------------------
       
  1902 // Remove an item from the collection database using the given media properties
       
  1903 // ----------------------------------------------------------------------------
       
  1904 //
       
  1905 void CMPXPodcastDbPlugin::DoRemovePathL(
       
  1906     CMPXCommand& aCmd)
       
  1907     {
       
  1908     MPX_FUNC("CMPXPodcastDbPlugin::DoRemovePathL(by command)");
       
  1909 
       
  1910     TInt removeError(KErrNone);
       
  1911     TBool removeCompleted(ETrue);
       
  1912 
       
  1913     if (!aCmd.IsSupported(KMPXCommandCollectionRemovePath) ||
       
  1914         !aCmd.IsSupported(KMPXCommandCollectionRemoveMediaCount))
       
  1915         {
       
  1916         removeError = KErrArgument;
       
  1917         }
       
  1918     else
       
  1919         {
       
  1920         CMPXCollectionPath* path =
       
  1921             aCmd.ValueCObjectL<CMPXCollectionPath>(KMPXCommandCollectionRemovePath);
       
  1922         CleanupStack::PushL(path);
       
  1923 
       
  1924         // in order to support cancel delete for a category, we need to adjust path. If
       
  1925         // the path ends in a category, retrieve all episodes under the selected category
       
  1926         // and append a new level with all episodes under the selected category
       
  1927         DoAppendLevelL(*path);
       
  1928 
       
  1929         CMPXCollectionPath* iterationPath = CMPXCollectionPath::NewL(*path);
       
  1930         CleanupStack::PushL(iterationPath);
       
  1931         iterationPath->ClearSelection();
       
  1932 
       
  1933         // indices of the selected items
       
  1934         TArray<TInt> selectionIndices = path->Selection();
       
  1935         TInt count(selectionIndices.Count());
       
  1936 
       
  1937         // number of medias to remove in this iteration
       
  1938         TInt removeCount = (aCmd.ValueTObjectL<TInt>(KMPXCommandCollectionRemoveMediaCount));
       
  1939 
       
  1940         // remove all in one shut if removeCount is 0 or negative
       
  1941         if (removeCount <= 0)
       
  1942             {
       
  1943             removeCount = count;
       
  1944             }
       
  1945 
       
  1946         // If the given path contains multiple selections, remove the first n selected media
       
  1947         // and update the path so that client can use this path to call remove iteratively
       
  1948         // until all selections are processed
       
  1949         //
       
  1950         if (count)
       
  1951             {
       
  1952             for (TInt i = 0; i < removeCount; ++i)
       
  1953                 {
       
  1954                 TInt index(selectionIndices[i]);
       
  1955 
       
  1956                 MPX_DEBUG4(" path: selected item [index %d] [selectioncount %d] [remove count %d]", index, count, removeCount);
       
  1957 
       
  1958                 iterationPath->SelectL(index);
       
  1959                 path->Remove(index);
       
  1960                 }
       
  1961 
       
  1962             aCmd.SetCObjectValueL(KMPXCommandCollectionRemovePath, path);
       
  1963 
       
  1964             // indicate to the client that subsequent remove command is required
       
  1965             if ((count - removeCount) > 0)
       
  1966                 {
       
  1967                 removeCompleted = EFalse;
       
  1968                 }
       
  1969             }
       
  1970 
       
  1971         // Remove the media specified by the path
       
  1972         CDesCArray* fp(NULL);
       
  1973         TBool supressMsgs(EFalse);
       
  1974         CMPXMessageArray* msgAry(NULL);
       
  1975         if (aCmd.IsSupported(KMPXCommandCollectionRemoveSuppressMsgs) &&
       
  1976             aCmd.ValueTObjectL<TBool>(KMPXCommandCollectionRemoveSuppressMsgs) )
       
  1977             {
       
  1978             // Msgs are stored in the command
       
  1979             supressMsgs = ETrue;
       
  1980             CMPXMessageArray* msgs( aCmd.Value<CMPXMessageArray>(KMPXCommandCollectionChangeMsgs) );
       
  1981             User::LeaveIfNull( msgs );
       
  1982             fp = DoRemoveL(*iterationPath, *msgs );
       
  1983             }
       
  1984         else
       
  1985             {
       
  1986             // Msgs will be sent after delete
       
  1987             msgAry = CMPXMessageArray::NewL();
       
  1988             CleanupStack::PushL( msgAry );
       
  1989             fp = DoRemoveL(*iterationPath, *msgAry);
       
  1990             }
       
  1991 
       
  1992         CleanupStack::PushL(fp);
       
  1993         if (fp->MdcaCount() > removeCount)
       
  1994             {
       
  1995             removeError = KErrCorrupt;
       
  1996             }
       
  1997         CleanupStack::PopAndDestroy(fp);
       
  1998 
       
  1999         if (!supressMsgs)
       
  2000             {
       
  2001             // Send Change Messages
       
  2002             iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
  2003             DoHandleChangeL(msgAry);
       
  2004             CleanupStack::PopAndDestroy(msgAry);
       
  2005             }
       
  2006 
       
  2007         // Cleanup
       
  2008         CleanupStack::PopAndDestroy(iterationPath);
       
  2009         CleanupStack::PopAndDestroy(path);
       
  2010         }
       
  2011 
       
  2012     // mandatory return parameters
       
  2013     aCmd.SetTObjectValueL<TInt>(KMPXCommandCollectionRemoveError, removeError);
       
  2014     aCmd.SetTObjectValueL<TBool>(KMPXCommandCollectionRemoveCompleted, removeCompleted);
       
  2015     }
       
  2016 
       
  2017 // ----------------------------------------------------------------------------
       
  2018 // Remove media by CMPXMedia through a command
       
  2019 // ----------------------------------------------------------------------------
       
  2020 //
       
  2021 void CMPXPodcastDbPlugin::DoRemoveMediaL(
       
  2022     CMPXCommand& aCmd)
       
  2023     {
       
  2024     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveMediaL(by command)");
       
  2025 
       
  2026     TInt error(KErrArgument);
       
  2027 
       
  2028     if (aCmd.IsSupported(KMPXCommandCollectionRemoveMedia))
       
  2029         {
       
  2030         CMPXMedia* media = aCmd.ValueCObjectL<CMPXMedia>(KMPXCommandCollectionRemoveMedia);
       
  2031         CleanupStack::PushL(media);
       
  2032 
       
  2033         MPX_TRAP(error, DoRemoveL(*media,
       
  2034             aCmd.ValueTObjectL<TBool>(KMPXCommandCollectionRemoveMediaDeleteRecord)));
       
  2035 
       
  2036         CleanupStack::PopAndDestroy(media);
       
  2037         }
       
  2038 
       
  2039     aCmd.SetTObjectValueL<TInt>(KMPXCommandCollectionRemoveMediaError, error);
       
  2040     }
       
  2041 
       
  2042 // ----------------------------------------------------------------------------
       
  2043 // Remove a media/media items from All Episodes view
       
  2044 // ----------------------------------------------------------------------------
       
  2045 //
       
  2046 void CMPXPodcastDbPlugin::DoRemoveFromAllEpisodesL(
       
  2047     const CMPXCollectionPath& aPath,
       
  2048     const TArray<TMPXItemId>& aSelections,
       
  2049     CDesCArray& aUriArray,
       
  2050     CMPXMessageArray& aItemChangedMessages)
       
  2051     {
       
  2052     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveFromAllEpisodesL");
       
  2053 
       
  2054     switch (aPath.Levels())
       
  2055         {
       
  2056         case 2:
       
  2057             {
       
  2058             // when the collection is removed, it's intended not to delete the files
       
  2059             iDbHandler->RemoveEntireCollectionL();
       
  2060             }
       
  2061             break;
       
  2062 
       
  2063         case 3:
       
  2064             {
       
  2065             TInt count(aSelections.Count());
       
  2066             if (count)
       
  2067                 {
       
  2068                 for (TInt i = 0; i < count; ++i)
       
  2069                     {
       
  2070                     iDbHandler->RemoveEpisodeL (aSelections[i], aUriArray,
       
  2071                         aItemChangedMessages);
       
  2072                     } // end for
       
  2073                 }
       
  2074             else
       
  2075                 {
       
  2076                 iDbHandler->RemoveEpisodeL(aPath.Id(aPath.Levels() - 1), aUriArray,
       
  2077                     aItemChangedMessages);
       
  2078                 }
       
  2079             }
       
  2080             break;
       
  2081 
       
  2082         default:
       
  2083             {
       
  2084             MPX_DEBUG2("CMPXPodcastDbPlugin_DoRemoveFromAllEpisodesL: Invalid levels[%d]", aPath.Levels());
       
  2085             User::Leave(KErrNotSupported);
       
  2086             }
       
  2087         }
       
  2088     }
       
  2089 
       
  2090 // ----------------------------------------------------------------------------
       
  2091 // Remove a media/media items from By Publish Date view
       
  2092 // ----------------------------------------------------------------------------
       
  2093 //
       
  2094 void CMPXPodcastDbPlugin::DoRemoveFromPublishDateL(
       
  2095     const CMPXCollectionPath& aPath,
       
  2096     const TArray<TMPXItemId>& aSelections,
       
  2097     CDesCArray& aUriArray,
       
  2098     CMPXMessageArray& aItemChangedMessages)
       
  2099     {
       
  2100     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveFromPublishDateL");
       
  2101 
       
  2102     TInt levels(aPath.Levels());
       
  2103 
       
  2104     if (levels == 2)
       
  2105         {
       
  2106         // when the collection is removed, it's intended no to delete the files
       
  2107         iDbHandler->RemoveEntireCollectionL();
       
  2108         }
       
  2109     else
       
  2110         {
       
  2111         TInt count(aSelections.Count());
       
  2112         if (count)
       
  2113             {
       
  2114             for (TInt i = 0; i < count; ++i)
       
  2115                 {
       
  2116                 RemoveFromPublishDateL(aPath, aSelections[i].iId2, aUriArray, aItemChangedMessages);
       
  2117                 }
       
  2118             }
       
  2119         else
       
  2120             {
       
  2121             RemoveFromPublishDateL(aPath, aPath.Id(levels - 1).iId2, aUriArray, aItemChangedMessages);
       
  2122             }
       
  2123         }
       
  2124 
       
  2125     MPX_DEBUG2("CMPXPodcastDbPlugin__RemoveL__EBrowsePubDate: levels[%d]", aPath.Levels());
       
  2126     }
       
  2127 
       
  2128 // ----------------------------------------------------------------------------
       
  2129 // Remove a media item from By Publish Date view
       
  2130 // ----------------------------------------------------------------------------
       
  2131 //
       
  2132 void CMPXPodcastDbPlugin::RemoveFromPublishDateL(
       
  2133     const CMPXCollectionPath& aPath,
       
  2134     TInt aItemId,
       
  2135     CDesCArray& aUriArray,
       
  2136     CMPXMessageArray& aItemChangedMessages)
       
  2137     {
       
  2138     MPX_FUNC("CMPXPodcastDbPlugin::RemoveFromPublishDateL");
       
  2139 
       
  2140     switch (aPath.Levels())
       
  2141         {
       
  2142         case 3:
       
  2143             {
       
  2144             iDbHandler->RemoveEpisodesMatchingPublishDateCategoryL(aItemId, aUriArray,
       
  2145                 aItemChangedMessages);
       
  2146             break;
       
  2147             }
       
  2148         case 4:
       
  2149             {
       
  2150             iDbHandler->RemoveEpisodeL(aItemId, aUriArray,
       
  2151                 aItemChangedMessages);
       
  2152             break;
       
  2153             }
       
  2154         default:
       
  2155             {
       
  2156             User::Leave(KErrArgument);
       
  2157             }
       
  2158         }
       
  2159     }
       
  2160 
       
  2161 // ----------------------------------------------------------------------------
       
  2162 // Remove a media/media items from Titles/Genre etc.. view
       
  2163 // ----------------------------------------------------------------------------
       
  2164 //
       
  2165 void CMPXPodcastDbPlugin::DoRemoveFromCategoriesL(
       
  2166     const CMPXCollectionPath& aPath,
       
  2167     const TArray<TMPXItemId>& aSelections,
       
  2168     TMPXGeneralCategory aCategory,
       
  2169     CDesCArray& aUriArray,
       
  2170     CMPXMessageArray& aItemChangedMessages)
       
  2171     {
       
  2172     MPX_FUNC("CMPXPodcastDbPlugin::DoRemoveFromCategoriesL");
       
  2173 
       
  2174     TInt levels(aPath.Levels());
       
  2175     if (levels == 1)
       
  2176         {
       
  2177         // when the collection is removed, it's intended no to delete the files
       
  2178         iDbHandler->RemoveEntireCollectionL();
       
  2179         }
       
  2180     else
       
  2181         {
       
  2182         TInt count(aSelections.Count());
       
  2183         if (count)
       
  2184             {
       
  2185             for (TInt i = 0; i < count; ++i)
       
  2186                 {
       
  2187                 RemoveFromCategoriesL(aPath, aSelections[i], aCategory, aUriArray,
       
  2188                     aItemChangedMessages);
       
  2189                 }
       
  2190             }
       
  2191 
       
  2192         else
       
  2193             {
       
  2194             RemoveFromCategoriesL(aPath, aPath.Id (aPath.Levels() - 1), aCategory, aUriArray,
       
  2195                 aItemChangedMessages);
       
  2196             }
       
  2197         }
       
  2198 
       
  2199     MPX_DEBUG2("CMPXPodcastDbPlugin_DoRemoveFromCategoriesL: levels[%d]", aPath.Levels());
       
  2200     }
       
  2201 
       
  2202 // ----------------------------------------------------------------------------
       
  2203 // Remove a media item from Albums/Genres/Composers view
       
  2204 // ----------------------------------------------------------------------------
       
  2205 //
       
  2206 void CMPXPodcastDbPlugin::RemoveFromCategoriesL(
       
  2207     const CMPXCollectionPath& aPath,
       
  2208     TInt aItemId,
       
  2209     TMPXGeneralCategory aCategory,
       
  2210     CDesCArray& aUriArray,
       
  2211     CMPXMessageArray& aItemChangedMessages)
       
  2212     {
       
  2213     MPX_FUNC("CMPXPodcastDbPlugin::RemoveFromCategoriesL");
       
  2214 
       
  2215     switch (aPath.Levels())
       
  2216         {
       
  2217         case 2:
       
  2218             {
       
  2219             iDbHandler->RemoveEpisodesMatchingCategoryL(aCategory, aItemId,
       
  2220                 aUriArray, aItemChangedMessages);
       
  2221             break;
       
  2222             }
       
  2223         case 3:
       
  2224             {
       
  2225             iDbHandler->RemoveEpisodeL(aItemId, aUriArray, aItemChangedMessages);
       
  2226             break;
       
  2227             }
       
  2228         default:
       
  2229             {
       
  2230             User::Leave(KErrArgument);
       
  2231             }
       
  2232         }
       
  2233     }
       
  2234 
       
  2235 // ----------------------------------------------------------------------------
       
  2236 // Retrieve URIs associated with this file path for file deletion
       
  2237 // ----------------------------------------------------------------------------
       
  2238 //
       
  2239 void CMPXPodcastDbPlugin::DoRetrieveUriForDeletionL(
       
  2240     CMPXCommand& aCmd)
       
  2241     {
       
  2242     MPX_FUNC("CMPXPodcastDbPlugin::DoRetrieveUriForDeletionL");
       
  2243 
       
  2244     // initialize mandatory return parameters
       
  2245     aCmd.SetTObjectValueL<TInt>(KMPXCommandCollectionRetrieveUriError, KErrNone);
       
  2246 
       
  2247     if (!aCmd.IsSupported(KMPXCommandCollectionRetrievePath))
       
  2248         {
       
  2249         aCmd.SetTObjectValueL<TInt>(KMPXCommandCollectionRetrieveUriError, KErrArgument);
       
  2250         }
       
  2251     else
       
  2252         {
       
  2253         CMPXCollectionPath* path = aCmd.ValueCObjectL<CMPXCollectionPath>(
       
  2254             KMPXCommandCollectionRetrievePath);
       
  2255         CleanupStack::PushL(path);
       
  2256 
       
  2257         if (iFirstDeleteStep )
       
  2258             {
       
  2259             iSelections.Reset( );
       
  2260             // in order to support cancel delete for a category, we need to adjust path. If
       
  2261             // the path ends in a category, retrieve all songs under the selected category
       
  2262             // and append a new level with all songs under the selected category
       
  2263             DoAppendLevelL(*path );
       
  2264 
       
  2265             // Ids of the selected items
       
  2266             path->SelectionL(iSelections );
       
  2267 
       
  2268             // single selection
       
  2269             if (iSelections.Count()== 0 )
       
  2270                 {
       
  2271                 iSelections.AppendL(path->Id (path->Levels()- 1 ) );
       
  2272                 }
       
  2273             }
       
  2274         CDesCArray* fp = new(ELeave) CDesCArrayFlat(4);
       
  2275         CleanupStack::PushL(fp);
       
  2276 
       
  2277         TInt count = iSelections.Count();
       
  2278         TInt itemCount = count > KIncrementalDeleteCount ? KIncrementalDeleteCount : count;
       
  2279         for (TInt i = 0; i < itemCount; ++i)
       
  2280             {
       
  2281             HBufC* uri = iDbHandler->GetUriMatchingIdL(iSelections[0]);
       
  2282             CleanupStack::PushL(uri);
       
  2283             fp->AppendL(*uri);
       
  2284             CleanupStack::PopAndDestroy(uri);
       
  2285             iSelections.Remove(0);
       
  2286             
       
  2287             }
       
  2288         aCmd.SetNoNewLCObjectL (KMPXCommandCollectionRetrieveMediaUriArray, fp);
       
  2289         if (iFirstDeleteStep)
       
  2290             {
       
  2291             aCmd.SetCObjectValueL(KMPXCommandCollectionRetrievePath, path);
       
  2292             }
       
  2293         CleanupStack::PopAndDestroy(fp);
       
  2294         CleanupStack::PopAndDestroy(path);
       
  2295         }
       
  2296     }
       
  2297 
       
  2298 // ----------------------------------------------------------------------------
       
  2299 // Cleanup deleted medias
       
  2300 // ----------------------------------------------------------------------------
       
  2301 //
       
  2302 void CMPXPodcastDbPlugin::CleanupDeletedRecordsL(
       
  2303     CMPXCommand& aCmd)
       
  2304     {
       
  2305     MPX_FUNC("CMPXPodcastDbPlugin::CleanupDeletedRecordsL");
       
  2306 
       
  2307     MPX_TRAPD(error, iDbHandler->CleanupDeletedRecordsL());
       
  2308     aCmd.SetTObjectValueL<TInt>(KMPXCommandCollectionCleanupError, error);
       
  2309     }
       
  2310 
       
  2311 // ----------------------------------------------------------------------------
       
  2312 // Retrieve the duration
       
  2313 // ----------------------------------------------------------------------------
       
  2314 //
       
  2315 TInt CMPXPodcastDbPlugin::DoDurationL(
       
  2316     CMPXMedia& aMedia,
       
  2317     TMPXPodcastCategory aCategory,
       
  2318     TMPXItemId aId)
       
  2319     {
       
  2320     MPX_FUNC("CMPXPodcastDbPlugin::DoDurationL");
       
  2321 
       
  2322     TInt duration(0);
       
  2323     switch (aCategory)
       
  2324         {
       
  2325         case EMPXEpisode:
       
  2326             {
       
  2327             duration = iDbHandler->GetAllEpisodesDurationL();
       
  2328             break;
       
  2329             }
       
  2330         case EMPXTitle:
       
  2331             {
       
  2332             duration = iDbHandler->GetTitleDurationL(aId.iId2);
       
  2333             break;
       
  2334             }
       
  2335         case EMPXNotYetPlayed:
       
  2336             {
       
  2337             duration = iDbHandler->GetNotPlayedDurationL();
       
  2338             break;
       
  2339             }
       
  2340        case EMPXRecentlyAdded:
       
  2341             {
       
  2342             duration = iDbHandler->GetRecentlyAddedDurationL();
       
  2343             break;
       
  2344             }
       
  2345         default:
       
  2346             {
       
  2347             User::Leave(KErrNotSupported);
       
  2348             }
       
  2349         }
       
  2350 
       
  2351     aMedia.SetTObjectValueL<TInt>(KMPXMediaGeneralDuration, duration);
       
  2352     return duration;
       
  2353     }
       
  2354 
       
  2355 // ----------------------------------------------------------------------------
       
  2356 // Append a level to a collection path and set selection to the first level
       
  2357 // ----------------------------------------------------------------------------
       
  2358 //
       
  2359 TInt CMPXPodcastDbPlugin::DoAppendLevelL(
       
  2360     CMPXCollectionPath& aPath,
       
  2361     CMPXMedia& aMedia)
       
  2362     {
       
  2363     MPX_FUNC("CMPXPodcastDbPlugin::DoAppendLevelL");
       
  2364 
       
  2365     RArray<TMPXItemId> ids;
       
  2366     CleanupClosePushL(ids);
       
  2367 
       
  2368     // Extract media array, and get all item ids
       
  2369     //
       
  2370     const CMPXMediaArray* mediaArray = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  2371     if( !mediaArray )
       
  2372         {
       
  2373         User::Leave(KErrNoMemory);
       
  2374         }
       
  2375     TInt count(mediaArray->Count());
       
  2376 
       
  2377     if (count >= 0)
       
  2378         {
       
  2379         for (TInt i = 0; i < count; ++i)
       
  2380             {
       
  2381             TMPXItemId id = mediaArray->AtL(i)->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  2382             ids.AppendL(id);
       
  2383             }
       
  2384 
       
  2385         // Put item id array into the path and select the first one
       
  2386         aPath.AppendL(ids.Array());
       
  2387         if (count > 0)
       
  2388         	{
       
  2389 	        aPath.Set(0);
       
  2390         	}
       
  2391         }
       
  2392 
       
  2393     CleanupStack::PopAndDestroy(&ids);
       
  2394     return count;
       
  2395     }
       
  2396 
       
  2397 // ----------------------------------------------------------------------------
       
  2398 // Append a level to a collection path and set selection to all episodes under the selected category/categories
       
  2399 // ----------------------------------------------------------------------------
       
  2400 //
       
  2401 void CMPXPodcastDbPlugin::DoAppendLevelL(
       
  2402     CMPXCollectionPath& aPath)
       
  2403     {
       
  2404     MPX_FUNC("CMPXPodcastDbPlugin::DoAppendLevelL");
       
  2405 
       
  2406     TMPXItemId contextId(aPath.Id(1));
       
  2407     TInt levels(aPath.Levels());
       
  2408 
       
  2409     if (contextId == EBrowseAll)
       
  2410         {
       
  2411         return;
       
  2412         }
       
  2413     else if (levels == 2)
       
  2414         {
       
  2415         // retrieve episodes in the selected category
       
  2416         CMPXMediaArray* episodes = CMPXMediaArray::NewL();
       
  2417         CleanupStack::PushL(episodes);
       
  2418 
       
  2419         RArray<TMPXAttribute> attributes;
       
  2420         CleanupClosePushL(attributes);
       
  2421         attributes.AppendL(KMPXMediaGeneralId);
       
  2422 
       
  2423         // Ids of the selected items
       
  2424         RArray<TMPXItemId> selections;
       
  2425         CleanupClosePushL(selections);
       
  2426         aPath.SelectionL(selections);
       
  2427 
       
  2428         // single selection
       
  2429         if (selections.Count() == 0)
       
  2430             {
       
  2431             selections.AppendL(aPath.Id(aPath.Levels() - 1));
       
  2432             }
       
  2433 
       
  2434         TInt count(selections.Count());
       
  2435 
       
  2436         for (TInt i = 0; i < count; ++i)
       
  2437             {
       
  2438             iDbHandler->GetEpisodesMatchingTitleL(selections[i], attributes.Array(), *episodes);
       
  2439             }
       
  2440 
       
  2441         CleanupStack::PopAndDestroy(2, &attributes); // selections & attributes
       
  2442 
       
  2443         // transform from CMPXMediaArray to RArray
       
  2444         RArray<TMPXItemId> episodeIds;
       
  2445         CleanupClosePushL(episodeIds);
       
  2446 
       
  2447         TInt episodeCount(episodes->Count());
       
  2448         for (TInt i = 0; i < episodeCount; ++i)
       
  2449             {
       
  2450             CMPXMedia* episode = (*episodes)[i];
       
  2451 
       
  2452             if (episode->IsSupported(KMPXMediaGeneralId))
       
  2453                 {
       
  2454                 episodeIds.AppendL(episode->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId));
       
  2455                 }
       
  2456             }
       
  2457 
       
  2458         // modify the collection path. append another level with all episodes under the selected
       
  2459         // category/categories selected
       
  2460         episodeCount = episodeIds.Count();
       
  2461 
       
  2462         if (episodeCount)
       
  2463             {
       
  2464             aPath.ClearSelection();
       
  2465             aPath.AppendL(episodeIds.Array());
       
  2466 
       
  2467             // select all
       
  2468             for (TInt i = 0; i < episodeCount; ++i)
       
  2469                 {
       
  2470                 aPath.SelectL(episodeIds[i]);
       
  2471                 }
       
  2472             }
       
  2473 
       
  2474         CleanupStack::PopAndDestroy(2, episodes); // episodeIds & episodes
       
  2475         }
       
  2476     else
       
  2477         {
       
  2478         // else do nothing
       
  2479         }
       
  2480     }
       
  2481 
       
  2482 // ----------------------------------------------------------------------------
       
  2483 // Execute an Add task step
       
  2484 // ----------------------------------------------------------------------------
       
  2485 //
       
  2486 TBool CMPXPodcastDbPlugin::DoAddAsyncL()
       
  2487     {
       
  2488     MPX_FUNC("CMPXPodcastDbPlugin::DoAddAsyncL");
       
  2489 
       
  2490     TBool done(EFalse);
       
  2491     CMPXMedia* task = iActiveTask->GetCommand().Value<CMPXMedia>(KMPXCommandColAddMedia);
       
  2492     User::LeaveIfNull(task);
       
  2493 
       
  2494     CMPXMessageArray& msgArray = iActiveTask->GetChangeMessages();
       
  2495 
       
  2496     if (!task->IsSupported(KMPXMediaGeneralType))
       
  2497         {
       
  2498         User::Leave(KErrArgument);
       
  2499         }
       
  2500 
       
  2501     // Group of items or a single item
       
  2502     //
       
  2503     if (task->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) == EMPXGroup)
       
  2504         {
       
  2505         if(!task->IsSupported(KMPXMediaArrayContents))
       
  2506             {
       
  2507             User::Leave(KErrArgument);
       
  2508             }
       
  2509 
       
  2510         CMPXMediaArray* ary = task->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  2511         User::LeaveIfNull( ary );
       
  2512 
       
  2513         TInt step( iActiveTask->GetStep() );
       
  2514         DoAddItemL(*ary->AtL(step), msgArray);
       
  2515 
       
  2516         if (++step == ary->Count())
       
  2517             {
       
  2518             done = ETrue;
       
  2519             }
       
  2520         }
       
  2521     else // type == EMPXItem
       
  2522         {
       
  2523         TUint32 item = DoAddItemL( *task, msgArray );
       
  2524         iActiveTask->GetCommand().SetTObjectValueL<TMPXItemId>( KMPXCommandColAddRtnId, item );
       
  2525         done = ETrue;
       
  2526         }
       
  2527 
       
  2528     iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
  2529     return done;
       
  2530     }
       
  2531 
       
  2532 // ----------------------------------------------------------------------------
       
  2533 // Add an item to the collection
       
  2534 // ----------------------------------------------------------------------------
       
  2535 //
       
  2536 TUint32 CMPXPodcastDbPlugin::DoAddL(
       
  2537     const CMPXMedia& aMedia)
       
  2538     {
       
  2539     MPX_FUNC("CMPXPodcastDbPlugin::DoAddL");
       
  2540 
       
  2541     TUint32 itemId(0);
       
  2542     CMPXMessageArray* changeMsgAry = CMPXMessageArray::NewL();
       
  2543     CleanupStack::PushL( changeMsgAry );
       
  2544 
       
  2545     if (!aMedia.IsSupported(KMPXMediaGeneralType))
       
  2546         {
       
  2547         User::Leave(KErrArgument);
       
  2548         }
       
  2549 
       
  2550     // Group of items
       
  2551     //
       
  2552     if (aMedia.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) == EMPXGroup)
       
  2553         {
       
  2554         CMPXMediaArray* ary = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  2555         User::LeaveIfNull( ary );
       
  2556 
       
  2557         TInt count(ary->Count());
       
  2558         for (TInt i = 0; i < count; ++i)
       
  2559             {
       
  2560             DoAddItemL(*ary->AtL(i), *changeMsgAry);
       
  2561             }
       
  2562         }
       
  2563     else // single item
       
  2564         {
       
  2565         itemId = DoAddItemL(aMedia, *changeMsgAry);
       
  2566         }
       
  2567 
       
  2568     iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
  2569     DoHandleChangeL(changeMsgAry);
       
  2570     CleanupStack::PopAndDestroy(changeMsgAry);
       
  2571 
       
  2572     return itemId;
       
  2573     }
       
  2574 
       
  2575 // ----------------------------------------------------------------------------
       
  2576 // Add an item to the collection
       
  2577 // ----------------------------------------------------------------------------
       
  2578 //
       
  2579 TUint32 CMPXPodcastDbPlugin::DoAddItemL(
       
  2580     const CMPXMedia& aMedia,
       
  2581     CMPXMessageArray& aMessageArray)
       
  2582     {
       
  2583     MPX_FUNC("CMPXPodcastDbPlugin::DoAddItemL");
       
  2584 
       
  2585     TInt itemId(0);
       
  2586 
       
  2587     if (!aMedia.IsSupported(KMPXMediaGeneralCategory))
       
  2588         {
       
  2589         User::Leave(KErrArgument);
       
  2590         }
       
  2591 
       
  2592     switch ( aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory))
       
  2593         {
       
  2594         case EMPXPodcast:
       
  2595         case EMPXSong:
       
  2596             {
       
  2597             itemId = iDbHandler->AddEpisodeL(aMedia);
       
  2598             MPXDbCommonUtil::AddItemChangedMessageL(aMessageArray, itemId, EMPXItemInserted,
       
  2599                 EMPXPodcast, KDBPluginUid);
       
  2600             break;
       
  2601             }
       
  2602         default:
       
  2603             {
       
  2604             User::Leave(KErrNotSupported);
       
  2605             }
       
  2606         }
       
  2607 
       
  2608     return itemId;
       
  2609     }
       
  2610 // ----------------------------------------------------------------------------
       
  2611 // Sets/updates the media for an item in the collection
       
  2612 // ----------------------------------------------------------------------------
       
  2613 //
       
  2614 void CMPXPodcastDbPlugin::DoSetL(
       
  2615     const CMPXMedia& aMedia)
       
  2616     {
       
  2617     MPX_FUNC("CMPXPodcastDbPlugin::DoSetL");
       
  2618 
       
  2619     if (!aMedia.IsSupported(KMPXMediaGeneralType) ||
       
  2620         !aMedia.IsSupported(KMPXMediaGeneralCategory))
       
  2621         {
       
  2622         User::Leave(KErrArgument);
       
  2623         }
       
  2624 
       
  2625     CMPXDbActiveTask::TChangeVisibility visibleChange(CMPXDbActiveTask::ENotVisibile);
       
  2626 
       
  2627     switch ( aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory))
       
  2628         {
       
  2629         case EMPXPodcast:
       
  2630         case EMPXSong:
       
  2631             {
       
  2632             // a list of changed messages as a result of the episode being updated
       
  2633             CMPXMessageArray* itemChangedMessages = CMPXMediaArray::NewL();
       
  2634             CleanupStack::PushL(itemChangedMessages);
       
  2635 
       
  2636              if (aMedia.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) == EMPXGroup)
       
  2637                 {
       
  2638                 if (!aMedia.IsSupported(KMPXMediaArrayContents))
       
  2639                     {
       
  2640                     User::Leave(KErrArgument);
       
  2641                     }
       
  2642 
       
  2643                 CMPXMediaArray* array = aMedia.Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  2644                 User::LeaveIfNull( array );
       
  2645 
       
  2646                 TInt count(array->Count());
       
  2647                 for (TInt i = 0; i < count; ++i)
       
  2648                     {
       
  2649                     visibleChange = (CMPXDbActiveTask::TChangeVisibility)(visibleChange |
       
  2650                             iDbHandler->UpdateEpisodeL(*array->AtL(i), *itemChangedMessages));
       
  2651                     }
       
  2652                 }
       
  2653              else
       
  2654                 {
       
  2655                 visibleChange = iDbHandler->UpdateEpisodeL(aMedia,
       
  2656                     *itemChangedMessages);
       
  2657                 }
       
  2658 
       
  2659              if (visibleChange)
       
  2660                 {
       
  2661                 iActiveTask->SetVisibleChange(visibleChange);
       
  2662                 DoHandleChangeL(itemChangedMessages);
       
  2663                 }
       
  2664 
       
  2665             CleanupStack::PopAndDestroy(itemChangedMessages);
       
  2666             }
       
  2667             break;
       
  2668 
       
  2669         default:
       
  2670             {
       
  2671             User::Leave(KErrNotSupported);
       
  2672             }
       
  2673             break;
       
  2674         }
       
  2675     }
       
  2676 
       
  2677 // ----------------------------------------------------------------------------
       
  2678 // Execute a task step for async set
       
  2679 // ----------------------------------------------------------------------------
       
  2680 //
       
  2681 TBool CMPXPodcastDbPlugin::DoSetAsyncL()
       
  2682     {
       
  2683     MPX_FUNC("CMPXPodcastDbPlugin::DoSetAsyncL");
       
  2684 
       
  2685     TBool done(EFalse);
       
  2686     CMPXMedia* task = (iActiveTask->GetCommand().Value<CMPXMedia>(KMPXCommandColSetMedia));
       
  2687     User::LeaveIfNull( task );
       
  2688 
       
  2689     CMPXMessageArray& msgArray = iActiveTask->GetChangeMessages();
       
  2690     CMPXDbActiveTask::TChangeVisibility visibleChange(iActiveTask->GetVisibleChange());
       
  2691 
       
  2692     // Multiple steps can be in a transaction for faster response
       
  2693     if( iDbHandler && !iDbHandler->InTransaction() )
       
  2694         {
       
  2695         iDbHandler->BeginTransactionL();
       
  2696         }
       
  2697 
       
  2698     if (!task->IsSupported(KMPXMediaGeneralType))
       
  2699         {
       
  2700         User::Leave(KErrArgument);
       
  2701         }
       
  2702 
       
  2703     if (task->ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType) == EMPXGroup)
       
  2704         {
       
  2705         if (!task->IsSupported(KMPXMediaArrayContents))
       
  2706             {
       
  2707             User::Leave(KErrArgument);
       
  2708             }
       
  2709 
       
  2710         // Multiple items
       
  2711         CMPXMediaArray* array = task->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
  2712         User::LeaveIfNull( array );
       
  2713 
       
  2714         TInt step = iActiveTask->GetStep();
       
  2715         visibleChange = (CMPXDbActiveTask::TChangeVisibility)( visibleChange | iDbHandler->UpdateEpisodeL(*array->AtL(step), msgArray));
       
  2716 
       
  2717         if (++step == array->Count())
       
  2718             {
       
  2719             done = ETrue;
       
  2720             }
       
  2721         }
       
  2722     else // Single item
       
  2723         {
       
  2724         if(iDbHandler)
       
  2725             {		
       
  2726             visibleChange = iDbHandler->UpdateEpisodeL(*task, msgArray);
       
  2727             done = ETrue;
       
  2728             }
       
  2729         }
       
  2730     iActiveTask->SetVisibleChange(visibleChange);
       
  2731     return done;
       
  2732     }
       
  2733 
       
  2734 // ----------------------------------------------------------------------------
       
  2735 // Handle change events
       
  2736 // ----------------------------------------------------------------------------
       
  2737 //
       
  2738 void CMPXPodcastDbPlugin::HandleChangeL(
       
  2739     const CMPXMessage& aMessage)
       
  2740     {
       
  2741     MPX_FUNC("CMPXPodcastDbPlugin::HandleChange");
       
  2742 
       
  2743     // check if message is filled
       
  2744     if (aMessage.IsSupported(KMPXMessageGeneralId))
       
  2745         {
       
  2746 #ifdef _DEBUG
       
  2747         PrintMessagesL(aMessage);
       
  2748 #endif  // _DEBUG
       
  2749         if(iRefreshing)
       
  2750             {
       
  2751             if (aMessage.IsSupported(KMPXMessageArrayContents))
       
  2752                 {
       
  2753                 const CMPXMessageArray* messageArray = aMessage.Value<CMPXMessageArray>(KMPXMessageArrayContents);
       
  2754                 if(messageArray)
       
  2755                     {
       
  2756                     CMPXMessage& message = *((*messageArray)[0]);
       
  2757                     TMPXChangeEventType changeType( message.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) );
       
  2758                     TMPXGeneralCategory cat(message.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory));
       
  2759                     if(changeType == EMPXItemInserted && (cat == EMPXPodcast || cat == EMPXSong || cat == EMPXPlaylist))
       
  2760                         {
       
  2761                         iObs->HandleMessage(aMessage);
       
  2762                         }
       
  2763                     }
       
  2764                 }
       
  2765             else
       
  2766                 {
       
  2767                 TMPXChangeEventType changeType( aMessage.ValueTObjectL<TMPXChangeEventType>( KMPXMessageChangeEventType ) );
       
  2768                 TMPXGeneralCategory cat(aMessage.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory));
       
  2769                 if(changeType == EMPXItemInserted && (cat == EMPXPodcast || cat == EMPXSong || cat == EMPXPlaylist))
       
  2770                     {
       
  2771                     iObs->HandleMessage(aMessage);
       
  2772                     }
       
  2773                 }
       
  2774             }
       
  2775         else
       
  2776             {
       
  2777             if(!iMtpInUse)
       
  2778                 {
       
  2779                 iObs->HandleMessage(aMessage);
       
  2780                 }
       
  2781             }
       
  2782         }
       
  2783     }
       
  2784 
       
  2785 // ----------------------------------------------------------------------------
       
  2786 // Construct a CMPXMedia and call HandleChange
       
  2787 // ----------------------------------------------------------------------------
       
  2788 //
       
  2789 void CMPXPodcastDbPlugin::DoHandleChangeL(
       
  2790     CMPXMessageArray* aItemChangedMessages)
       
  2791     {
       
  2792     MPX_FUNC("CMPXPodcastDbPlugin::DoHandleChangeL");
       
  2793 
       
  2794     TMPXCommandId cmdId = iActiveTask->GetTask();
       
  2795     if((iActiveTask->GetVisibleChange() & CMPXDbActiveTask::EAllVisible)
       
  2796         && (cmdId == KMPXCommandIdCollectionSet ||
       
  2797             cmdId == KMPXCommandIdCollectionAdd ||
       
  2798             cmdId == KMPXCommandIdCollectionRemove ||
       
  2799             cmdId == KMPXCommandIdCollectionRemoveMedia ||
       
  2800             cmdId == KMPXCommandIdCollectionCompleteDelete ))
       
  2801         {
       
  2802         MPXDbCommonUtil::AddItemChangedMessageL(*aItemChangedMessages, EBrowseAll,
       
  2803                                                  EMPXItemModified, EMPXCollection, KDBPluginUid);
       
  2804         }
       
  2805 
       
  2806     // group change messages and send to collection client context
       
  2807     CMPXMessage* message = CMPXMessage::NewL();
       
  2808     CleanupStack::PushL(message);
       
  2809 
       
  2810     message->SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, KMPXMessageIdItemChanged);
       
  2811     message->SetCObjectValueL(KMPXMessageArrayContents, aItemChangedMessages);
       
  2812     message->SetTObjectValueL<TInt>(KMPXMessageArrayCount, aItemChangedMessages->Count());
       
  2813 
       
  2814     HandleChangeL(*message);
       
  2815 
       
  2816     CleanupStack::PopAndDestroy(message);
       
  2817     }
       
  2818 
       
  2819 // ----------------------------------------------------------------------------
       
  2820 // Handle out of disk events during db merging
       
  2821 // ----------------------------------------------------------------------------
       
  2822 //
       
  2823 void CMPXPodcastDbPlugin::HandleOutOfDiskMessageL()
       
  2824     {
       
  2825     MPX_FUNC("CMPXPodcastDbPlugin::HandleOutOfDiskMessageL");
       
  2826 
       
  2827     if (iObs)
       
  2828         {
       
  2829         // Create the msg
       
  2830         CMPXMessage* msg = CMPXMessage::NewL();
       
  2831         CleanupStack::PushL( msg );
       
  2832 
       
  2833         // Setup the message parameters
       
  2834         msg->SetTObjectValueL<TInt>(KMPXMessageGeneralId, KMPXCustomMessageId);
       
  2835         msg->SetTObjectValueL<TInt>(KMPXCustomMessageCollectionId, KDBPluginUid);
       
  2836         msg->SetTObjectValueL<TInt>(KMPXCustomMessageEventType, EMcsOpen);
       
  2837         msg->SetTObjectValueL<TInt>(KMPXCustomMessageErrorCode, KErrDiskFull);
       
  2838 
       
  2839         // Callback and Cleanup
       
  2840         iObs->HandleMessage(*msg);
       
  2841         CleanupStack::PopAndDestroy(msg);
       
  2842         }
       
  2843     }
       
  2844 
       
  2845 // ----------------------------------------------------------------------------
       
  2846 // Handle completion of operation
       
  2847 // ----------------------------------------------------------------------------
       
  2848 //
       
  2849 void CMPXPodcastDbPlugin::DoHandleOperationCompletedL(
       
  2850     TInt aErr)
       
  2851     {
       
  2852     MPX_FUNC("CMPXPodcastDbPlugin::DoHandleOperationCompletedL");
       
  2853 
       
  2854     if( iDbHandler && iDbHandler->InTransaction() )
       
  2855         {
       
  2856         // Commit if cancelled
       
  2857         TInt err(aErr);
       
  2858         if( err == KErrCancel )
       
  2859             {
       
  2860             err = KErrNone;
       
  2861             }
       
  2862         iDbHandler->EndTransactionL( err );
       
  2863         }
       
  2864     
       
  2865     // Broadcase change messages
       
  2866     //
       
  2867     if (iActiveTask->GetVisibleChange())
       
  2868         {
       
  2869         DoHandleChangeL(&iActiveTask->GetChangeMessages());
       
  2870         }
       
  2871 
       
  2872     // Callback to engine to signal completion
       
  2873     // NOTE: Collection server immediately completes the async message when
       
  2874     // Cancel is called, no need to callback to observer
       
  2875     if (aErr != KErrCancel)
       
  2876         {
       
  2877         iObs->HandleCommandComplete(NULL, aErr);
       
  2878         }    
       
  2879     }
       
  2880      
       
  2881 
       
  2882 // ----------------------------------------------------------------------------------------------------------
       
  2883 // Complete a delete operation
       
  2884 // ----------------------------------------------------------------------------------------------------------
       
  2885 //
       
  2886 void CMPXPodcastDbPlugin::DoHandleDeleteCompleteL(
       
  2887     CMPXCommand& aCmd)
       
  2888     {
       
  2889     MPX_FUNC("CMPXPodcastDbPlugin::DoHandleDeleteCompleteL");
       
  2890     iFirstDeleteStep = ETrue;
       
  2891     iSelections.Reset();
       
  2892     // Change messages
       
  2893     if (aCmd.IsSupported(KMPXCommandCollectionDeleteMsgArray))
       
  2894         {
       
  2895         CMPXMessageArray* msgs = aCmd.Value<CMPXMessageArray>(KMPXCommandCollectionDeleteMsgArray);
       
  2896         User::LeaveIfNull( msgs );
       
  2897         iActiveTask->SetVisibleChange(CMPXDbActiveTask::EAllVisible);
       
  2898         DoHandleChangeL(msgs);
       
  2899         }
       
  2900     }
       
  2901 
       
  2902 // ----------------------------------------------------------------------------
       
  2903 // Maps a given browse type to a category ID.
       
  2904 // ----------------------------------------------------------------------------
       
  2905 //
       
  2906 TMPXPodcastCategory CMPXPodcastDbPlugin::CategoryForBrowseType(
       
  2907     TMCBrowseType aBrowseType)
       
  2908     {
       
  2909     MPX_FUNC("CMPXPodcastDbPlugin::CategoryForBrowseType");
       
  2910 
       
  2911     TMPXPodcastCategory cat(EMPXUnknown);
       
  2912 
       
  2913     switch (aBrowseType)
       
  2914         {
       
  2915         case EBrowseAll:
       
  2916             {
       
  2917             cat = EMPXAll;
       
  2918             break;
       
  2919             }
       
  2920         case EBrowseTitle:
       
  2921             {
       
  2922             cat = EMPXTitle;
       
  2923             break;
       
  2924             }
       
  2925         case EBrowsePubDate:
       
  2926             {
       
  2927             cat = EMPXPubDate;
       
  2928             break;
       
  2929             }
       
  2930         case EBrowseRecentlyAdded:
       
  2931             {
       
  2932             cat = EMPXRecentlyAdded;
       
  2933             break;
       
  2934             }
       
  2935         case EBrowseNotPlayed:
       
  2936             {
       
  2937             cat = EMPXNotYetPlayed;
       
  2938             break;
       
  2939             }
       
  2940         default:
       
  2941             {
       
  2942             // do nothing
       
  2943             break;
       
  2944             }
       
  2945         }
       
  2946 
       
  2947     return cat;
       
  2948     }
       
  2949 
       
  2950 // ----------------------------------------------------------------------------
       
  2951 // Maps a given category ID to a browse type.
       
  2952 // ----------------------------------------------------------------------------
       
  2953 //
       
  2954 TMCBrowseType CMPXPodcastDbPlugin::BrowseTypeForCategory(
       
  2955     TMPXPodcastCategory aCategory)
       
  2956     {
       
  2957     MPX_FUNC("CMPXPodcastDbPlugin::BrowseTypeForCategory");
       
  2958 
       
  2959     TMCBrowseType browseType(EBrowseNotPlayed);
       
  2960 
       
  2961     switch (aCategory)
       
  2962         {
       
  2963         case EMPXAll:
       
  2964             {
       
  2965             browseType = EBrowseAll;
       
  2966             break;
       
  2967             }
       
  2968         case EMPXTitle:
       
  2969             {
       
  2970             browseType = EBrowseTitle;
       
  2971             break;
       
  2972             }
       
  2973         case EMPXPubDate:
       
  2974             {
       
  2975             browseType = EBrowsePubDate;
       
  2976             break;
       
  2977             }
       
  2978         case EMPXRecentlyAdded:
       
  2979             {
       
  2980             browseType = EBrowseRecentlyAdded;
       
  2981             break;
       
  2982             }
       
  2983         default:
       
  2984             {
       
  2985             // do nothing
       
  2986             break;
       
  2987             }
       
  2988         }
       
  2989 
       
  2990     return browseType;
       
  2991     }
       
  2992 
       
  2993 // ----------------------------------------------------------------------------
       
  2994 // Sets the type, category and title attributes in the specified media instance
       
  2995 // ----------------------------------------------------------------------------
       
  2996 //
       
  2997 void CMPXPodcastDbPlugin::SetMediaGeneralAttributesL(
       
  2998     CMPXMedia& aMedia,
       
  2999     TMPXGeneralType aGeneralType,
       
  3000     TMPXPodcastType aType,
       
  3001     TMPXPodcastCategory aCategory,
       
  3002     const TDesC& aTitle,
       
  3003     TInt aCount /* = -1 */)
       
  3004     {
       
  3005     MPX_FUNC("CMPXPodcastDbPlugin::SetMediaGeneralAttributesL");
       
  3006 
       
  3007     aMedia.SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, aGeneralType);
       
  3008     aMedia.SetTObjectValueL<TMPXPodcastType>(KMPXMediaPodcastType, aType);
       
  3009     aMedia.SetTObjectValueL<TMPXPodcastCategory>(KMPXMediaPodcastCategoryGroup, aCategory);
       
  3010     aMedia.SetTextValueL(KMPXMediaGeneralTitle, aTitle);
       
  3011 
       
  3012     if (aCount >= 0)
       
  3013         {
       
  3014         aMedia.SetTObjectValueL(KMPXMediaGeneralCount, aCount);
       
  3015         }
       
  3016     }
       
  3017 
       
  3018 // ----------------------------------------------------------------------------
       
  3019 // Sets the type, category and title attributes in the specified media instance
       
  3020 // ----------------------------------------------------------------------------
       
  3021 //
       
  3022 void CMPXPodcastDbPlugin::SetMediaGeneralAttributesL(
       
  3023     CMPXMedia& aMedia,
       
  3024     TMPXGeneralType aGeneralType,
       
  3025     TMPXPodcastType aType,
       
  3026     TMPXPodcastCategory aCategory,
       
  3027     TInt aId,
       
  3028     TInt aCount /* = -1 */)
       
  3029     {
       
  3030     MPX_FUNC("CMPXPodcastDbPlugin::SetMediaGeneralAttributesL");
       
  3031 
       
  3032     HBufC* title = iDbHandler->GetTitleNameMatchingIdL(aId);
       
  3033     CleanupStack::PushL(title);
       
  3034     SetMediaGeneralAttributesL(aMedia, aGeneralType, aType, aCategory, *title, aCount);
       
  3035     CleanupStack::PopAndDestroy(title);
       
  3036     }
       
  3037 
       
  3038 // ----------------------------------------------------------------------------------------------------------
       
  3039 // Get total podcast count for a database
       
  3040 // ----------------------------------------------------------------------------------------------------------
       
  3041 //
       
  3042 void CMPXPodcastDbPlugin::DoGetCollectionCountL( const CMPXCommand& aCmd )
       
  3043     {
       
  3044     MPX_FUNC("CMPXPodcastDbPlugin::DoGetCollectionCountL");
       
  3045     //as there is only one table containing uri data, KMPXCommandCollectionCountTable is ignored
       
  3046     if (!aCmd.IsSupported(KMPXCommandCollectionCountDrive))
       
  3047         {
       
  3048         User::Leave(KErrArgument);
       
  3049         }
       
  3050 
       
  3051     TInt drive = aCmd.ValueTObjectL<TInt>(KMPXCommandCollectionCountDrive);
       
  3052     TInt count = (TInt)iDbHandler->GetTotalCountL(drive);
       
  3053     ((CMPXMedia&)aCmd).SetTObjectValueL<TInt>(KMPXCommandCollectionCountValue, count);
       
  3054     }
       
  3055 
       
  3056 // ----------------------------------------------------------------------------------------------------------
       
  3057 // Get URIs for all podcasts in a database
       
  3058 // ----------------------------------------------------------------------------------------------------------
       
  3059 //
       
  3060 void CMPXPodcastDbPlugin::DoGetCollectionUriL( const CMPXCommand& aCmd )
       
  3061     {
       
  3062     MPX_FUNC("CMPXPodcastDbPlugin::DoGetCollectionCountL");
       
  3063     //as there is only one table containing uri data, KMPXCommandCollectionCountTable is ignored
       
  3064     if (!aCmd.IsSupported(KMPXCommandCollectionURIDrive) ||
       
  3065         !aCmd.IsSupported(KMPXCommandCollectionURIFromID) ||
       
  3066         !aCmd.IsSupported(KMPXCommandCollectionURIRecords) )
       
  3067         {
       
  3068         User::Leave(KErrArgument);
       
  3069         }
       
  3070 
       
  3071     TInt drive = aCmd.ValueTObjectL<TInt>(KMPXCommandCollectionURIDrive);
       
  3072     TInt fromID = aCmd.ValueTObjectL<TInt>(KMPXCommandCollectionURIFromID);
       
  3073     TInt recnum = aCmd.ValueTObjectL<TInt>(KMPXCommandCollectionURIRecords);
       
  3074 
       
  3075     CDesCArray* uris = new(ELeave) CDesCArrayFlat(4);
       
  3076     CleanupStack::PushL(uris);
       
  3077     TInt lastID = 0;
       
  3078 
       
  3079     iDbHandler->GetPodcastUriArrayL(drive, fromID, recnum, *uris, lastID);
       
  3080 
       
  3081     ((CMPXMedia&)aCmd).SetNoNewLCObjectL(KMPXCommandCollectionURIList, uris);
       
  3082     ((CMPXMedia&)aCmd).SetTObjectValueL(KMPXCommandCollectionURILastID, lastID);
       
  3083     CleanupStack::PopAndDestroy(uris);
       
  3084     }
       
  3085 
       
  3086 void CMPXPodcastDbPlugin::SetAttributesL(
       
  3087     const CMPXCollectionPath& aPath,
       
  3088     RArray<TMPXAttribute>& aAttrs,
       
  3089     RArray<TInt>& aSupportedIds )
       
  3090     {
       
  3091     CleanupClosePushL(aAttrs);
       
  3092     CleanupClosePushL(aSupportedIds);
       
  3093     
       
  3094     aAttrs.AppendL(TMPXAttribute(KMPXMediaIdGeneral, EMPXMediaGeneralTitle |
       
  3095         EMPXMediaGeneralDuration | EMPXMediaGeneralSize |
       
  3096         EMPXMediaGeneralType | EMPXMediaGeneralCategory | EMPXMediaGeneralId |
       
  3097         EMPXMediaGeneralUri | EMPXMediaGeneralFlags | EMPXMediaGeneralCount |
       
  3098         EMPXMediaGeneralPlayCount | EMPXMediaGeneralLastPlaybackPosition |
       
  3099         EMPXMediaGeneralCollectionId | EMPXMediaGeneralDate));
       
  3100     
       
  3101     aAttrs.AppendL(TMPXAttribute(KMPXMediaIdPodcast,
       
  3102         EMPXMediaPodcastType | EMPXMediaPodcastCategoryGroup | EMPXMediaPodcastIsPlaying));
       
  3103 
       
  3104     aSupportedIds.AppendL(KMPXMediaIdContainer);
       
  3105     aSupportedIds.AppendL(KMPXMediaIdGeneral);
       
  3106     aSupportedIds.AppendL(KMPXMediaIdPodcast);
       
  3107 
       
  3108     TInt levels(aPath.Levels());
       
  3109     if ( 1 < levels )
       
  3110         {
       
  3111         // All episodes in a title
       
  3112         aAttrs.AppendL( TMPXAttribute(KMPXMediaIdMusic, EMPXMediaMusicAlbumArtFileName ) );
       
  3113         aSupportedIds.AppendL( KMPXMediaIdMusic );
       
  3114         }
       
  3115     CleanupStack::Pop();
       
  3116     CleanupStack::Pop();
       
  3117     }
       
  3118 
       
  3119 #ifdef _DEBUG
       
  3120 
       
  3121 // ----------------------------------------------------------------------------
       
  3122 // Print change events
       
  3123 // ----------------------------------------------------------------------------
       
  3124 //
       
  3125 void CMPXPodcastDbPlugin::PrintMessagesL(
       
  3126     const CMPXMessage& aMessage)
       
  3127     {
       
  3128     MPX_FUNC("CMPXPodcastDbPlugin::PrintMessages");
       
  3129 
       
  3130     if (aMessage.IsSupported(KMPXMessageArrayContents))
       
  3131         {
       
  3132         const CMPXMessageArray* messageArray =
       
  3133             aMessage.Value<CMPXMessageArray>(KMPXMessageArrayContents);
       
  3134         if( !messageArray )
       
  3135             {
       
  3136             User::Leave( KErrNoMemory );
       
  3137             }
       
  3138 
       
  3139         TInt count(messageArray->Count());
       
  3140         MPX_DEBUG2("%d messages:", count);
       
  3141 
       
  3142         for (TInt i = 0; i < count; ++i)
       
  3143             {
       
  3144             PrintMessage(*((*messageArray)[i]));
       
  3145             }
       
  3146         }
       
  3147     else
       
  3148         {
       
  3149         PrintMessage(aMessage);
       
  3150         }
       
  3151     }
       
  3152 
       
  3153 // ----------------------------------------------------------------------------
       
  3154 // Print one change event
       
  3155 // ----------------------------------------------------------------------------
       
  3156 //
       
  3157 void CMPXPodcastDbPlugin::PrintMessage(
       
  3158     const CMPXMessage& aMessage)
       
  3159     {
       
  3160     MPX_FUNC("CMPXPodcastDbPlugin::PrintMessage");
       
  3161 
       
  3162     if (aMessage.IsSupported(KMPXMessageGeneralId))
       
  3163         {
       
  3164         TMPXItemId id = aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageGeneralId);
       
  3165         MPX_DEBUG3("    message id[0x%x, 0x%x]", id.iId1, id.iId2);
       
  3166         }
       
  3167 
       
  3168     if (aMessage.IsSupported(KMPXMessageCollectionId))
       
  3169         {
       
  3170         TUid uid = aMessage.ValueTObjectL<TUid>(KMPXMessageCollectionId);
       
  3171         MPX_DEBUG2("    uid [0x%x]", uid.iUid);
       
  3172         }
       
  3173 
       
  3174     if (aMessage.IsSupported(KMPXMessageChangeEventType))
       
  3175         {
       
  3176         MPX_DEBUG2("    change event type [%d]",
       
  3177              aMessage.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType));
       
  3178         }
       
  3179 
       
  3180     if (aMessage.IsSupported(KMPXMessageMediaGeneralCategory))
       
  3181         {
       
  3182         MPX_DEBUG2("    category [%d]",
       
  3183              aMessage.ValueTObjectL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory));
       
  3184         }
       
  3185 
       
  3186     if (aMessage.IsSupported(KMPXMessageMediaGeneralId))
       
  3187         {
       
  3188         TMPXItemId id = aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId);
       
  3189         MPX_DEBUG3("    media id[0x%x, 0x%x]", id.iId1, id.iId2);
       
  3190         }
       
  3191 
       
  3192     if (aMessage.IsSupported(KMPXMessageMediaDeprecatedId))
       
  3193         {
       
  3194         TMPXItemId id = aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId);
       
  3195         MPX_DEBUG3("    deprecated id [0x%x, 0x%x]", id.iId1, id.iId2);
       
  3196         }
       
  3197     }
       
  3198 
       
  3199 #endif// _DEBUG
       
  3200 
       
  3201 // End of file