upnpsharing/upnpcontentserver/src/upnpcontentsharingao.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:      CUpnpContentSharingAo class implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 //  Include Files
       
    24 #include <upnpcontainer.h>
       
    25 #include <upnpfilesharing.h>
       
    26 #include <upnpcontainer.h>
       
    27 #include <upnpitem.h>
       
    28 #include <upnpitemlist.h>
       
    29 #include <upnpobject.h>
       
    30 #include <upnpstring.h>
       
    31 #include <s32file.h>
       
    32 #include <f32file.h>
       
    33 #include "upnpcommonutils.h" // FindContainerByTitle
       
    34 #include "upnpcdsreselementutility.h"
       
    35 // CLF headers
       
    36 #include <MCLFContentListingEngine.h>
       
    37 #include <ContentListingFactory.h>
       
    38 #include <MCLFItemListModel.h>
       
    39 #include <CLFContentListing.hrh>
       
    40 
       
    41 //#include <clfcontentlistingextended.hrh>
       
    42 
       
    43 #include <MCLFItem.h>
       
    44 
       
    45 #include "upnpcontentsharingao.h"
       
    46 #include "upnpcontentmetadatautility.h"
       
    47 #include "upnpselectionwriter.h"
       
    48 #include "upnpcontainercheckerao.h"
       
    49 #include "upnpcontentserverdefs.h"
       
    50 #include "upnpunsharerao.h"
       
    51 
       
    52 _LIT( KComponentLogfile, "contentserver.txt");
       
    53 #include "upnplog.h"
       
    54 
       
    55 // FORWARD DECLARATIONS
       
    56 class UPnPCommonUtils;
       
    57 
       
    58 // CONSTANTS
       
    59 
       
    60 const TInt KUiSelectionOffset = 2;
       
    61 const TInt KDefaultGranularity( 10 );
       
    62 
       
    63 // KContentDirCommitAmount should be in sync with KCommitEveryNum in
       
    64 // upnpcontentdirectoryglobals.h which is not exported
       
    65 const TInt KContentDirCommitAmount = 10;
       
    66 
       
    67 using namespace UpnpContentServer;
       
    68 
       
    69 // ============================ MEMBER FUNCTIONS =============================
       
    70 
       
    71 // --------------------------------------------------------------------------
       
    72 // CUpnpContentSharingAo::CUpnpContentSharingAo
       
    73 // C++ default constructor can NOT contain any code, that
       
    74 // might leave.
       
    75 // --------------------------------------------------------------------------
       
    76 //
       
    77 CUpnpContentSharingAo::CUpnpContentSharingAo(
       
    78     MUpnpSharingCallback* aEngine,
       
    79     CUpnpContentMetadataUtility* aMetadata )
       
    80     : CActive( CActive::EPriorityStandard )
       
    81     {
       
    82     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
    83 
       
    84     iEngine = aEngine;
       
    85     iMetadataUtility = aMetadata;
       
    86     iContainerId = KErrNotFound;
       
    87     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
    88     }
       
    89 
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CUpnpContentSharingAo::NewL
       
    93 // Two-phased constructor.
       
    94 // --------------------------------------------------------------------------
       
    95 //
       
    96 CUpnpContentSharingAo* CUpnpContentSharingAo::NewL(
       
    97     MUpnpSharingCallback* aEngine,
       
    98     CUpnpContentMetadataUtility* aMetadata )
       
    99     {
       
   100     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   101 
       
   102     CUpnpContentSharingAo* self = new (ELeave)
       
   103         CUpnpContentSharingAo( aEngine, aMetadata );
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL();
       
   106     CleanupStack::Pop( self );
       
   107     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   108     return self;
       
   109     }
       
   110 
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // CUpnpContentSharingAo::ConstructL
       
   114 // Symbian 2nd phase constructor can leave.
       
   115 // --------------------------------------------------------------------------
       
   116 //
       
   117 void CUpnpContentSharingAo::ConstructL()
       
   118     {
       
   119     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   120 
       
   121     iContainerIdx = 0;
       
   122     iObjectIdx = 0;
       
   123     iVideoIndex = 0;
       
   124     iImageIndex = 0;
       
   125     iAllVideosShared = EFalse;
       
   126     iAllImagesShared = EFalse;
       
   127 
       
   128     CActiveScheduler::Add( this );
       
   129 
       
   130     iFileSharing = CUpnpFileSharing::NewL();
       
   131     ConnectMediaServer();
       
   132     iWriter = CUpnpSelectionWriter::NewL( iContainerType );
       
   133     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   134     }
       
   135 
       
   136 
       
   137 // Destructor
       
   138 CUpnpContentSharingAo::~CUpnpContentSharingAo()
       
   139     {
       
   140     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   141 
       
   142     iMediaServer.Close();
       
   143     delete iFileSharing;
       
   144     iFileSharing = NULL;
       
   145 
       
   146 
       
   147     if ( IsActive() )
       
   148         {
       
   149         __LOG1("CUpnpContentSharingAo destructor IsActive==\
       
   150 true iSharingState: %d", iSharingState );
       
   151         iSharingState = ENotActive;
       
   152         TRequestStatus* stat = &iStatus;
       
   153         User::RequestComplete( stat, KErrNone );
       
   154         }
       
   155 
       
   156     Cancel();
       
   157     iEngine = NULL;
       
   158     iContainerIds = NULL;
       
   159 
       
   160     delete iTmpContainer;
       
   161     delete iSharedContainerIds;
       
   162     delete iWriter;
       
   163     DeleteListUpnpObject();
       
   164     delete iFileNameArr;   
       
   165     delete iTmpItem;
       
   166     delete iPlaylists;
       
   167     delete iCollections;
       
   168 
       
   169     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   170     }
       
   171 
       
   172 // --------------------------------------------------------------------------
       
   173 // CUpnpContentSharingAo::RunL
       
   174 // Called when asyncronous request is ready
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 void CUpnpContentSharingAo::RunL()
       
   178     {
       
   179     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   180 
       
   181     __LOG8_1( "iStatus", iStatus.Int() );
       
   182     if ( iStatus.Int() == KErrCorrupt ||
       
   183         iStatus.Int() == KErrDiskFull ||
       
   184         iStatus.Int() == KErrNoMemory )
       
   185         {
       
   186         iSharingState = ENotActive;
       
   187         }
       
   188     if ( iStopRequested == MUpnpSharingCallback::ESharingPause )
       
   189         {
       
   190         TInt err = iMediaServer.Stop(
       
   191             RUpnpMediaServerClient::EStopSilent );
       
   192         __LOG1( "Error: %d", err );
       
   193         err = iMediaServer.StartOffline();
       
   194         __LOG1( "Error: %d", err );
       
   195         
       
   196         iStopRequested = MUpnpSharingCallback::ESharingNoStop;
       
   197         }
       
   198 
       
   199     switch ( iSharingState )
       
   200         {
       
   201     case EUnshareContainers :
       
   202         {
       
   203         // Unshare the container structure
       
   204         UnshareContainersL();
       
   205         }
       
   206         break;
       
   207     case EShareContainers :
       
   208         {
       
   209         // Share the container structure
       
   210         ShareContainersL();
       
   211         }
       
   212         break;
       
   213     case EShareContainersResult :
       
   214         {
       
   215         // advance to next container or share items
       
   216         ShareContainersResultL();
       
   217         }
       
   218         break;
       
   219     case EShareItems :
       
   220         {
       
   221         // coming here after all containers are shared
       
   222         // then at least once per container
       
   223         HandleSharingSubstatesL();
       
   224         }
       
   225         break;
       
   226     case EShareItemsResult :
       
   227         {
       
   228         // advance to next item or end
       
   229         ShareItemsResultL();
       
   230         }
       
   231         break;
       
   232     case EShareAllItems :
       
   233         {
       
   234         //..coming to here once "All files" is selected and
       
   235         // individual albums are already shared
       
   236         HandleSharingSubstatesL();
       
   237         }
       
   238         break;
       
   239     case EShareAllItemsResult :
       
   240         {
       
   241         // advance to next item set or end
       
   242         AllItemsResultL();
       
   243         }
       
   244         break;
       
   245     case ENotActive :
       
   246         // informs handler that we are done
       
   247         {
       
   248         TInt err ( iStatus.Int() );
       
   249         if ( iStopRequested == MUpnpSharingCallback::ESharingFullStop )
       
   250             {
       
   251             // normal case
       
   252             err = KErrCancel;
       
   253             iStopRequested = EFalse;
       
   254             }
       
   255 
       
   256         TRAP_IGNORE( 
       
   257             iEngine->CompleteSharingOperationL( err,
       
   258                                                 iContainerType ));
       
   259         }
       
   260         break;
       
   261 
       
   262     default :
       
   263         {
       
   264         __LOG( "RunL - default" );
       
   265         }
       
   266         break;
       
   267         }
       
   268 
       
   269     __LOG( "RunL - end" );
       
   270     }
       
   271 
       
   272 // --------------------------------------------------------------------------
       
   273 // CUpnpContentSharingAo::DoCancel
       
   274 // Cancels active object
       
   275 // --------------------------------------------------------------------------
       
   276 //
       
   277 void CUpnpContentSharingAo::DoCancel()
       
   278     {
       
   279     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   280 
       
   281     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   282     }
       
   283 
       
   284 // --------------------------------------------------------------------------
       
   285 // CUpnpContentSharingAo::RunError
       
   286 // Cancels active object
       
   287 // --------------------------------------------------------------------------
       
   288 //
       
   289 TInt CUpnpContentSharingAo::RunError( TInt aError )
       
   290     {
       
   291     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   292     __LOG8_1( "RunError = ", aError );
       
   293     if ( aError == KErrNoMemory ||
       
   294          aError == KErrDiskFull ||
       
   295          aError == KErrCorrupt )
       
   296         {
       
   297         iSharingState = ENotActive;
       
   298         }
       
   299     if ( iSharingState == EUnshareContainers )
       
   300         {
       
   301         if ( iShareAllSelection == EShareNone )
       
   302             {
       
   303             iSharingState = ENotActive;
       
   304             TRAP_IGNORE( iWriter->SaveSharingStateL( EShareNone ) );
       
   305             }
       
   306         else
       
   307             {
       
   308             iSharingState = EShareContainers;
       
   309             }
       
   310         }
       
   311     else
       
   312         {
       
   313         iSharingState = ENotActive;
       
   314         }
       
   315     if ( iSharingState != EEnumerateSelections )
       
   316         {
       
   317         SelfComplete( aError );
       
   318         }
       
   319 
       
   320     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   321     return KErrNone;
       
   322     }
       
   323 
       
   324 // --------------------------------------------------------------------------
       
   325 // CUpnpContentSharingAo::IsActive()
       
   326 // ( other items are commented in header )
       
   327 // --------------------------------------------------------------------------
       
   328 //
       
   329 TBool CUpnpContentSharingAo::IsActive() const
       
   330     {
       
   331     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   332     TBool ret( CActive::IsActive());
       
   333     if ( !ret )
       
   334         {
       
   335         ret = iProfilerActive;
       
   336         }
       
   337     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   338     return ret;
       
   339     }
       
   340 
       
   341 // --------------------------------------------------------------------------
       
   342 // CUpnpContentSharingAo::HandleSharingSubstatesL
       
   343 // ( other items are commented in header )
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 void CUpnpContentSharingAo::HandleSharingSubstatesL()
       
   347     {
       
   348     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   349     if ( iSharingSubState == EIdle )
       
   350         {
       
   351         if ( iSharingState == EShareItems )
       
   352             {
       
   353             ShareItemsL();
       
   354             }
       
   355         else if ( iSharingState == EShareAllItems )
       
   356             {
       
   357             ShareAllItemsL();
       
   358             }
       
   359         else
       
   360             {
       
   361             }
       
   362         }
       
   363     else if ( iSharingSubState == EProfileItemList )
       
   364         {
       
   365         ProfileItemListL();
       
   366         }
       
   367     else if ( iSharingSubState == EProfileItemListResult )
       
   368         {
       
   369         ProfileItemListResult();
       
   370         }
       
   371     else if ( iSharingSubState == EShareItemList )
       
   372         {
       
   373         TInt parentId( KErrNotFound );
       
   374         if ( iSharingState == EShareItems )
       
   375             {
       
   376             parentId = iSharedContainerIds->operator[]( iContainerIdx );
       
   377             }
       
   378         else if ( iSharingState == EShareAllItems )
       
   379             {
       
   380             parentId = iContainerId;
       
   381             }
       
   382         else
       
   383             {
       
   384             }
       
   385         ShareItemListL( parentId );
       
   386         }
       
   387     else if ( iSharingSubState == EShareItemListResult )
       
   388         {
       
   389         ShareItemListResultL();
       
   390         }
       
   391     else
       
   392         {
       
   393         }
       
   394     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   395     }
       
   396 
       
   397 // --------------------------------------------------------------------------
       
   398 // CUpnpContentSharingAo::ShareFilesL
       
   399 // Starts file sharing
       
   400 // --------------------------------------------------------------------------
       
   401 //
       
   402 void CUpnpContentSharingAo::InitializeL(
       
   403     TUpnpMediaType aContainerType,
       
   404     const RArray<TInt>& aCurrentSelection,
       
   405     CDesCArray& aPlaylistIds,
       
   406     CDesCArray& aPlaylistNames,    
       
   407     const TInt aContainerId )
       
   408     {
       
   409     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   410 
       
   411     // Initialize values
       
   412     iObjectIdx = 0;
       
   413     iContainerIdx = 0;
       
   414     iVideoIndex = 0;
       
   415     iImageIndex = 0;
       
   416     iAllVideosShared = EFalse;
       
   417     iAllImagesShared = EFalse;
       
   418     iSharingProgress = 0;
       
   419 
       
   420     iContainerType = aContainerType;
       
   421 
       
   422     delete iWriter;
       
   423     iWriter = NULL;
       
   424     iWriter = CUpnpSelectionWriter::NewL( iContainerType );
       
   425 
       
   426     AdjustShareAllSelection( aCurrentSelection );
       
   427     iCurrentSelections = aCurrentSelection;
       
   428     iContainerIds = &aPlaylistIds;
       
   429     iContainerNames = &aPlaylistNames;
       
   430     iContainerId = aContainerId;
       
   431 
       
   432     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   433     }
       
   434 
       
   435 // --------------------------------------------------------------------------
       
   436 // CUpnpContentSharingAo::ShareFilesL
       
   437 // Starts file sharing
       
   438 // --------------------------------------------------------------------------
       
   439 //
       
   440 void CUpnpContentSharingAo::ShareFiles( )
       
   441     {
       
   442     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   443 
       
   444     // Open file sharing session from mediaserver.
       
   445     // Start offline if not started.
       
   446     TInt status( RUpnpMediaServerClient::EStopped );
       
   447     iMediaServer.Status( status );
       
   448     if ( status == RUpnpMediaServerClient::EStopped )
       
   449         {
       
   450         iMediaServer.StartOffline();
       
   451         }
       
   452     iSharingState = EUnshareContainers;
       
   453     SelfComplete( KErrNone );
       
   454     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   455     }
       
   456 
       
   457 // --------------------------------------------------------------------------
       
   458 // CUPnPSettingsEngineAO::CreateContainerL
       
   459 // creates container
       
   460 // --------------------------------------------------------------------------
       
   461 //
       
   462 CUpnpContainer* CUpnpContentSharingAo::CreateContainerL(
       
   463     TUpnpMediaType aContainerType,
       
   464     const TDesC8& aTitle ) const
       
   465     {
       
   466     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   467     CUpnpContainer* cont= CUpnpContainer::NewL();
       
   468     CleanupStack::PushL( cont );
       
   469     cont->SetParentIdL( KRootContainerIdDesc8 );
       
   470     cont->SetTitleL( aTitle );
       
   471     switch ( aContainerType )
       
   472         {
       
   473     case EImageAndVideo :
       
   474         {
       
   475         cont->SetObjectClassL( KImageVideoContainerClass );
       
   476         }
       
   477         break;
       
   478     case EPlaylist :
       
   479         {
       
   480         cont->SetObjectClassL( KStorageFolderContainerClass );
       
   481         }
       
   482         break;
       
   483     default :
       
   484         {
       
   485         __LOG( "CreateContainerL - default");
       
   486         }
       
   487         break;
       
   488         }
       
   489     CleanupStack::Pop( cont );
       
   490     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   491     return cont;
       
   492     }
       
   493 
       
   494 
       
   495 // --------------------------------------------------------------------------
       
   496 // CUpnpContentSharingAo::CloseFileSharingSession
       
   497 // Closes mediaserver and file sharing session
       
   498 // --------------------------------------------------------------------------
       
   499 //
       
   500 void CUpnpContentSharingAo::CloseFileSharingSession()
       
   501     {
       
   502     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   503 
       
   504     iMediaServer.Close();
       
   505     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   506     }
       
   507 
       
   508 
       
   509 // --------------------------------------------------------------------------
       
   510 // CUpnpContentSharingAo::UnshareContainersL
       
   511 // Unshares objects, this should only be called from RunL
       
   512 // --------------------------------------------------------------------------
       
   513 //
       
   514 void CUpnpContentSharingAo::UnshareContainersL( )
       
   515     {
       
   516     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   517 
       
   518     // All old containers unshred, move to next state
       
   519     if ( iShareAllSelection == EShareNone )
       
   520         {
       
   521         iSharingState = ENotActive;
       
   522         iWriter->SaveSharingStateL( EShareNone );
       
   523         }
       
   524     else
       
   525         {
       
   526         iSharingState = EShareContainers;
       
   527         }
       
   528 
       
   529     // All old containers unshred, move to next state
       
   530     SelfComplete( KErrNone );
       
   531     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   532     }
       
   533 
       
   534 
       
   535 // --------------------------------------------------------------------------
       
   536 // CUpnpContentSharingAo::ConnectMediaServer
       
   537 // ( other items are commented in header )
       
   538 // --------------------------------------------------------------------------
       
   539 //
       
   540 TInt CUpnpContentSharingAo::ConnectMediaServer()
       
   541     {
       
   542     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   543 
       
   544     TInt error = iMediaServer.Connect();
       
   545     __LOG8_1( "ConnectMediaServer error %d", error );
       
   546     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   547     return error;
       
   548     }
       
   549 
       
   550 // --------------------------------------------------------------------------
       
   551 // CUpnpContentSharingAo::AdjustShareAllSelection
       
   552 // ( other items are commented in header )
       
   553 // --------------------------------------------------------------------------
       
   554 //
       
   555 void CUpnpContentSharingAo::AdjustShareAllSelection(
       
   556     const RArray<TInt>& aSelections )
       
   557     {
       
   558     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   559     if ( aSelections.Count() == 1 )
       
   560         {
       
   561 
       
   562         if ( aSelections[0] == 0 )
       
   563             {
       
   564             __LOG("CUpnpContentSharingAo::AdjustShareAllSelection: \
       
   565 EShareNone");
       
   566             iShareAllSelection = EShareNone;
       
   567             }
       
   568         else if ( aSelections[0] == 1 )
       
   569             {
       
   570             __LOG("CUpnpContentSharingAo::AdjustShareAllSelection: \
       
   571 EShareAll");
       
   572             iShareAllSelection = EShareAll;
       
   573             }
       
   574         else
       
   575             {
       
   576             __LOG("CUpnpContentSharingAo::AdjustShareAllSelection: \
       
   577 EShareMany");
       
   578             iShareAllSelection = EShareMany;
       
   579             }
       
   580         }
       
   581     else
       
   582         {
       
   583         __LOG("CUpnpContentSharingAo::AdjustShareAllSelection: EShareMany");
       
   584         iShareAllSelection = EShareMany;
       
   585         }
       
   586     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   587     }
       
   588 
       
   589 // --------------------------------------------------------------------------
       
   590 // CUpnpContentSharingAo::ShareContainersL
       
   591 // ( other items are commented in header )
       
   592 // --------------------------------------------------------------------------
       
   593 //
       
   594 void CUpnpContentSharingAo::ShareContainersL()
       
   595     {
       
   596     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   597  /*   iMetadataUtility->ClearPostFiltersL();
       
   598 
       
   599     TInt ind( 0 );
       
   600     // Theres is still containers to share
       
   601     switch ( iContainerType )
       
   602         {
       
   603     case EImageAndVideo :
       
   604         {
       
   605         // get the correct index for CLF
       
   606         ind = GetContainerIndexL();
       
   607         HBufC8* albumName( NULL );
       
   608         if (  ind != KErrNotFound )
       
   609             {
       
   610             albumName = UpnpString::FromUnicodeL( 
       
   611                 iContainerNames->MdcaPoint( ind ) );
       
   612             CleanupStack::PushL( albumName );
       
   613 
       
   614             TInt plErr( KErrNone );
       
   615 
       
   616                 
       
   617             if ( !plErr )
       
   618                 {
       
   619                 iWriter->AppendItemL( iContainerIds->MdcaPoint( ind ) );
       
   620 
       
   621                 iTmpContainer = CreateContainerL( iContainerType,
       
   622                                                   *albumName );
       
   623 
       
   624                 iFileSharing->ShareContainerL(
       
   625                     *UPnPCommonUtils::IntToDesC8LC ( iContainerId ),
       
   626                     *iTmpContainer,
       
   627                     iStatus );
       
   628                 CleanupStack::PopAndDestroy(); //UPnPCommonUtils::IntToDesC8LC
       
   629                 CleanupStack::PopAndDestroy( albumName );
       
   630                 SetActive();
       
   631                 }
       
   632             else
       
   633                 {
       
   634                 SelfComplete( KErrNotFound );
       
   635                 }
       
   636             }
       
   637         else
       
   638             {
       
   639             SelfComplete( KErrNone );
       
   640             }
       
   641         }
       
   642             break;
       
   643     case EPlaylist :
       
   644         {
       
   645 
       
   646         // get the correct index for CLF
       
   647         ind = GetContainerIndexL();
       
   648         if ( ind != KErrNotFound )
       
   649             {
       
   650             HBufC8* playlistName( NULL );
       
   651             playlistName = UpnpString::FromUnicodeL( 
       
   652                 iContainerNames->MdcaPoint( ind ) );
       
   653             CleanupStack::PushL( playlistName  );
       
   654 
       
   655             TInt plErr( KErrNone );
       
   656             if ( !plErr )
       
   657                 {
       
   658                 // do the id..
       
   659                 iWriter->AppendItemL( iContainerIds->MdcaPoint( ind ) );
       
   660 
       
   661                 // ..then do the name for the container
       
   662                 iTmpContainer = CreateContainerL( iContainerType,
       
   663                                                   *playlistName );
       
   664 
       
   665                 iFileSharing->ShareContainerL(
       
   666                     *UPnPCommonUtils::IntToDesC8LC( iContainerId ),
       
   667                     *iTmpContainer,
       
   668                     iStatus );
       
   669 
       
   670                 CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
   671 
       
   672                 SetActive();
       
   673                 }
       
   674             else
       
   675                 {
       
   676                 SelfComplete( KErrNotFound );
       
   677                 }
       
   678             CleanupStack::PopAndDestroy( playlistName );
       
   679             }
       
   680         else
       
   681             {
       
   682             SelfComplete( KErrNone );
       
   683             }
       
   684         }
       
   685         break;
       
   686     default :
       
   687         break;
       
   688         }
       
   689 
       
   690     iSharingState = EShareContainersResult;
       
   691     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );*/
       
   692     }
       
   693 
       
   694 // --------------------------------------------------------------------------
       
   695 // CUpnpContentSharingAo::ShareItemsL
       
   696 // ( other items are commented in header )
       
   697 // --------------------------------------------------------------------------
       
   698 //
       
   699 void CUpnpContentSharingAo::ShareItemsL()
       
   700     {
       
   701     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   702 
       
   703     delete iFileNameArr;
       
   704     iFileNameArr = NULL;
       
   705     iFileNameArr = new (ELeave)
       
   706     CDesCArrayFlat( 4 );
       
   707     DeleteListUpnpObject();
       
   708     iItemList = CUpnpItemList::NewL();
       
   709     TInt ind( 0 );
       
   710 
       
   711 
       
   712     TInt parentId( 0 );
       
   713 
       
   714     switch ( iContainerType )
       
   715         {
       
   716     case EImageAndVideo :
       
   717         {
       
   718         if ( !iCollections ) 
       
   719             {
       
   720             iCollections = CUPnPAlbumServices::NewL();
       
   721             }
       
   722 
       
   723         // get the correct index for CLF
       
   724         ind  = GetContainerIndexL();
       
   725 
       
   726         // ..then do the name for the container
       
   727         CDesCArray* items = new (ELeave) CDesCArrayFlat(4);
       
   728         CleanupStack::PushL( items );
       
   729         TInt itemCount( 0 );
       
   730         if ( ind < iContainerIds->MdcaCount() && ind != KErrNotFound )
       
   731             {
       
   732             TPtrC plId( iContainerIds->MdcaPoint( ind ) );
       
   733             TRAPD( albErr,  iCollections->OpenAlbumL( plId, 
       
   734                                                       *items ));
       
   735             delete iCollections;
       
   736             iCollections = NULL;
       
   737 
       
   738             if( !albErr )
       
   739                 {
       
   740                 itemCount = items->MdcaCount();
       
   741                 }
       
   742             }
       
   743 
       
   744         if ( itemCount )
       
   745             {
       
   746 
       
   747             parentId =
       
   748                 iSharedContainerIds->operator[]( iContainerIdx );
       
   749             TInt i = iObjectIdx;
       
   750 
       
   751             delete iFileNameArr;
       
   752             iFileNameArr = NULL;
       
   753             iFileNameArr = new (ELeave)
       
   754                 CDesCArrayFlat( 4 );
       
   755             TBool canAppend = items->MdcaCount();
       
   756 
       
   757             while ( i < itemCount && canAppend )
       
   758                 {
       
   759                 // process all items in curret collection
       
   760                 HBufC8* id = UPnPCommonUtils::IntToDesC8LC( parentId );
       
   761                 TPtrC item( items->MdcaPoint( i ) );
       
   762                 TRAPD( itemErr,
       
   763                        iTmpItem = iMetadataUtility->CreateItemL(
       
   764                            item,
       
   765                            *id ));
       
   766                 if ( !itemErr && iTmpItem )
       
   767                     {
       
   768                     if ( !itemErr )
       
   769                         {
       
   770                         if( !iMetadataUtility->UpdateMetadataL( 
       
   771                             EPhotoFile,
       
   772                             iTmpItem,
       
   773                             item ))
       
   774                             {
       
   775                             // The item was not found from prev model
       
   776                             if( !iMetadataUtility->UpdateMetadataL( 
       
   777                                 EVideoFile,
       
   778                                 iTmpItem,
       
   779                                 item ) )
       
   780                                 {
       
   781                                 iTmpItem->SetObjectClassL( 
       
   782                                     KImageItemObjectClass );
       
   783                                 }
       
   784                             }
       
   785                         iItemList->AppendObjectL( *iTmpItem );
       
   786                         iFileNameArr->AppendL(
       
   787                             item );
       
   788                         // transfer ownership
       
   789                         }
       
   790                     else
       
   791                         {
       
   792                         delete iTmpItem;
       
   793                         }
       
   794                     iTmpItem = NULL;
       
   795                     i++;
       
   796                     if ( iItemList->ObjectCount() >
       
   797                          KContentDirCommitAmount )
       
   798                         {
       
   799                         // the list is full, next share it
       
   800                         canAppend = EFalse;
       
   801                         // save the current position in list for
       
   802                         // next run
       
   803                         iObjectIdx = i;
       
   804                         }
       
   805                     }
       
   806                 else
       
   807                     {
       
   808                     i++;
       
   809                     iTmpItem = NULL;
       
   810                     }
       
   811                 CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
   812 
       
   813                 }
       
   814             }
       
   815         CleanupStack::PopAndDestroy( items );     
       
   816 
       
   817         if ( iItemList->ObjectCount() <= KContentDirCommitAmount )
       
   818             {
       
   819             // next time start with new album
       
   820             iSharingProgress += iObjectIdx;
       
   821             iObjectIdx = 0;
       
   822             iMetadataUtility->ClearPostFiltersL();
       
   823             }
       
   824 
       
   825         if ( iItemList->ObjectCount() )
       
   826             {
       
   827             iSharingSubState = EProfileItemList;
       
   828             SelfComplete( KErrNone );
       
   829             }
       
   830         else
       
   831             {
       
   832             // update indexes
       
   833             iMetadataUtility->ClearPostFiltersL();
       
   834             iSharingSubState = EShareItemListResult;
       
   835             SelfComplete( KErrNone );
       
   836             }
       
   837         }
       
   838         break;
       
   839     case EPlaylist :
       
   840         {
       
   841         if ( !iPlaylists ) 
       
   842             {
       
   843             iPlaylists = CUPnPPlaylistServices::NewL();
       
   844             }
       
   845 
       
   846         // get the correct index for CLF
       
   847         ind  = GetContainerIndexL();
       
   848 
       
   849         // ..then do the name for the container
       
   850         CDesCArray* items = new (ELeave) CDesCArrayFlat(4);
       
   851         CleanupStack::PushL( items );
       
   852         TInt itemCount( 0 );
       
   853         if ( ind < iContainerIds->MdcaCount() && ind != KErrNotFound )
       
   854             {
       
   855             TPtrC plId( iContainerIds->MdcaPoint( ind ) );
       
   856             TRAPD( plErr, iPlaylists->OpenPlaylistL( plId, 
       
   857                                                      *items ) );
       
   858             delete iPlaylists;
       
   859             iPlaylists = NULL;
       
   860 
       
   861             if( !plErr )
       
   862                 {
       
   863                 itemCount = items->MdcaCount();
       
   864                 }
       
   865             }
       
   866 
       
   867         if ( itemCount )
       
   868             {
       
   869 
       
   870             parentId =
       
   871                 iSharedContainerIds->operator[]( iContainerIdx );
       
   872             TInt i = iObjectIdx;
       
   873 
       
   874             TBool canAppend = items->MdcaCount();
       
   875 
       
   876             while ( i < itemCount && canAppend )
       
   877                 {
       
   878                 // process all items in curret collection
       
   879                 HBufC8* id = UPnPCommonUtils::IntToDesC8LC( parentId );
       
   880                 TPtrC item( items->MdcaPoint( i ) );
       
   881                 TRAPD( plErr,
       
   882                        iTmpItem = iMetadataUtility->CreateItemL(
       
   883                            item,
       
   884                            *id ));
       
   885                 if ( !plErr && iTmpItem )
       
   886                     {
       
   887                     if ( !plErr )
       
   888                         {
       
   889                         iMetadataUtility->UpdateMetadataL( 
       
   890                             EMusicFile,
       
   891                             iTmpItem,
       
   892                             item );
       
   893                         iTmpItem->SetObjectClassL( 
       
   894                             KMusicItemObjectClass );
       
   895                         iItemList->AppendObjectL( *iTmpItem );
       
   896                         iFileNameArr->AppendL(
       
   897                             item );
       
   898                         // transfer ownership
       
   899                         }
       
   900                     else
       
   901                         {
       
   902                         delete iTmpItem;
       
   903                         }
       
   904                     iTmpItem = NULL;
       
   905                     i++;
       
   906                     if ( iItemList->ObjectCount() >
       
   907                          KContentDirCommitAmount )
       
   908                         {
       
   909                         // the list is full, next share it
       
   910                         canAppend = EFalse;
       
   911                         // save the current position in list for
       
   912                         // next run
       
   913                         iObjectIdx = i;
       
   914                         }
       
   915                     }
       
   916                 else
       
   917                     {
       
   918                     i++;
       
   919                     iTmpItem = NULL;
       
   920                     }
       
   921                 CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
   922 
       
   923                 }
       
   924             }
       
   925         CleanupStack::PopAndDestroy( items );
       
   926 
       
   927         if ( iItemList->ObjectCount() <= KContentDirCommitAmount )
       
   928             {
       
   929             // next time start with new album
       
   930             iSharingProgress += iObjectIdx;
       
   931             iObjectIdx = 0;
       
   932             iMetadataUtility->ClearPostFiltersL();
       
   933             }
       
   934 
       
   935 
       
   936         if ( iItemList->ObjectCount() )
       
   937             {
       
   938             iSharingSubState = EProfileItemList;
       
   939             SelfComplete( KErrNone );
       
   940             }
       
   941         else
       
   942             {
       
   943             // goto RunL and update indexes
       
   944             iMetadataUtility->ClearPostFiltersL();
       
   945             iSharingSubState = EShareItemListResult;
       
   946             SelfComplete( KErrNone );
       
   947             }
       
   948         }
       
   949         break;
       
   950     default :
       
   951         break;
       
   952         }
       
   953     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
   954     }
       
   955 
       
   956 // --------------------------------------------------------------------------
       
   957 // CUpnpContentSharingAo::ShareAllItemsL
       
   958 // ( other items are commented in header )
       
   959 // --------------------------------------------------------------------------
       
   960 //
       
   961 void CUpnpContentSharingAo::ShareAllItemsL()
       
   962     {
       
   963     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
   964 
       
   965     delete iFileNameArr;
       
   966     iFileNameArr = NULL;
       
   967     iFileNameArr = new (ELeave)
       
   968         CDesCArrayFlat( 4 );
       
   969 
       
   970     DeleteListUpnpObject();
       
   971     iItemList = CUpnpItemList::NewL();
       
   972 
       
   973     switch ( iContainerType )
       
   974         {
       
   975     case EImageAndVideo:
       
   976         {
       
   977         if ( !iAllImagesShared )
       
   978             {
       
   979             AppendImageFilesToListL();
       
   980             }
       
   981 
       
   982         // do not share videos if the list is already full
       
   983         if ( !iAllVideosShared &&
       
   984              iItemList->ObjectCount() <= KContentDirCommitAmount )
       
   985             {
       
   986             AppendVideoFilesToListL();
       
   987             }
       
   988         }
       
   989         break;
       
   990     case EPlaylist:
       
   991         {
       
   992         const MCLFItemListModel* list(NULL);
       
   993         list = &iMetadataUtility->MusicFiles();
       
   994         if ( !list )
       
   995             {
       
   996             User::Leave( KErrArgument );
       
   997             }
       
   998         TInt musicCount = list->ItemCount();
       
   999 
       
  1000         if ( iObjectIdx < musicCount )
       
  1001             {
       
  1002             // sharing images
       
  1003             TBool canAppend( list->ItemCount() );
       
  1004             TInt i( iObjectIdx );
       
  1005 
       
  1006             while ( i < list->ItemCount() && canAppend )
       
  1007                 {
       
  1008                 // process all items in curret collection
       
  1009                 HBufC8* id = UPnPCommonUtils::IntToDesC8LC(
       
  1010                     iContainerId );
       
  1011                 TRAPD( plErr, iTmpItem = iMetadataUtility->CreateItemL(
       
  1012                            list->Item( i ),
       
  1013                            *id ));
       
  1014                 if ( !plErr && iTmpItem )
       
  1015                     {
       
  1016                     TPtrC fullFileName;
       
  1017                     list->Item( i ).GetField( ECLFFieldIdFileNameAndPath,
       
  1018                                               fullFileName );
       
  1019 
       
  1020                     if ( !plErr )
       
  1021                         {
       
  1022                         iMetadataUtility->UpdateMetadataL( 
       
  1023                             EMusicFile,
       
  1024                             iTmpItem,
       
  1025                             fullFileName );
       
  1026                         iTmpItem->SetObjectClassL( KMusicItemObjectClass );
       
  1027                         iItemList->AppendObjectL( *iTmpItem );
       
  1028                         iFileNameArr->AppendL( fullFileName );
       
  1029                         }
       
  1030                     else
       
  1031                         {
       
  1032                         delete iTmpItem;
       
  1033                         }
       
  1034                     iTmpItem = NULL;
       
  1035                     i++;
       
  1036                     if ( iItemList->ObjectCount() >
       
  1037                          KContentDirCommitAmount )
       
  1038                         {
       
  1039                         // the list is full, next share it
       
  1040                         canAppend = EFalse;
       
  1041                         }
       
  1042                     }
       
  1043                 else
       
  1044                     {
       
  1045                     i++;
       
  1046                     iTmpItem = NULL;
       
  1047                     }
       
  1048 
       
  1049                 CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
  1050                 }
       
  1051             // save the current position in list, for next run
       
  1052             iObjectIdx = i;
       
  1053             }
       
  1054 
       
  1055         }
       
  1056         break;
       
  1057     default :
       
  1058         break;
       
  1059         }
       
  1060 
       
  1061     // do not share empty list
       
  1062     if ( iItemList->ObjectCount() )
       
  1063         {
       
  1064         iSharingSubState = EProfileItemList;
       
  1065         SelfComplete( KErrNone );
       
  1066         }
       
  1067     else
       
  1068         {
       
  1069         // update indexes
       
  1070         iSharingSubState = EShareItemListResult;
       
  1071         SelfComplete( KErrNone );
       
  1072         }
       
  1073 
       
  1074     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1075 
       
  1076     }
       
  1077 
       
  1078 // --------------------------------------------------------------------------
       
  1079 // CUpnpContentSharingAo::ProfileItemListL
       
  1080 // ( other items are commented in header )
       
  1081 // --------------------------------------------------------------------------
       
  1082 //
       
  1083 void CUpnpContentSharingAo::ProfileItemListL()
       
  1084     {
       
  1085     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1086 
       
  1087     if ( iProfileInd < iItemList->ObjectCount() )
       
  1088         {
       
  1089         iProfilerActive = ETrue;
       
  1090 
       
  1091         CUpnpItem*
       
  1092             tmpItem = static_cast<CUpnpItem*>(
       
  1093                 iItemList->operator[]( iProfileInd ));
       
  1094 
       
  1095         TPtrC fileName = iFileNameArr->MdcaPoint( iProfileInd );
       
  1096 
       
  1097         iSharingSubState = EProfileItemListResult;
       
  1098 
       
  1099         TRAPD( err, UpnpCdsResElementUtility::AddResElementL(
       
  1100                    *tmpItem,
       
  1101                    fileName ));
       
  1102         if ( iDeletePending )
       
  1103             {
       
  1104             DeleteListUpnpObject();
       
  1105             delete iFileNameArr;
       
  1106             iFileNameArr = NULL;
       
  1107             }
       
  1108         else
       
  1109             {
       
  1110             SetActive();
       
  1111             TRequestStatus* stat = &iStatus;
       
  1112             User::RequestComplete( stat, err );
       
  1113             }
       
  1114 #ifdef _DEBUG
       
  1115         HBufC* log = HBufC::NewLC(512);
       
  1116         log->Des().Append(_L("CUpnpContentSharingAo: Profiling: "));
       
  1117         log->Des().Append( fileName );
       
  1118         __LOG16( *log );
       
  1119         __LOG2( "CUpnpContentSharingAo: Profile index: (%d of %d)", 
       
  1120                        iProfileInd, 
       
  1121                        iItemList->ObjectCount());
       
  1122         CleanupStack::PopAndDestroy( log );
       
  1123 #endif
       
  1124         iProfilerActive = EFalse;
       
  1125         }
       
  1126     else
       
  1127         {
       
  1128         // update indexes
       
  1129         iProfileInd = 0;
       
  1130         iSharingSubState = EShareItemListResult;
       
  1131         SelfComplete( KErrNone );
       
  1132         }
       
  1133     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1134     }
       
  1135 
       
  1136 // --------------------------------------------------------------------------
       
  1137 // CUpnpContentSharingAo::ProfileItemListResult
       
  1138 // ( other items are commented in header )
       
  1139 // --------------------------------------------------------------------------
       
  1140 //
       
  1141 void CUpnpContentSharingAo::ProfileItemListResult()
       
  1142     {
       
  1143     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1144     if ( iStatus.Int() )
       
  1145         {
       
  1146         CUpnpItem* tmpItem = static_cast<CUpnpItem*>(
       
  1147             iItemList->operator[]( iProfileInd ));
       
  1148         TPtrC8 id( tmpItem->Id() );
       
  1149         iItemList->RemoveAndDestroy( id );
       
  1150         
       
  1151         iFileNameArr->Delete(iProfileInd);  
       
  1152         }
       
  1153     else
       
  1154         {
       
  1155         iProfileInd++; 
       
  1156         }
       
  1157 
       
  1158     if ( iProfileInd < iItemList->ObjectCount() )
       
  1159         {
       
  1160         iSharingSubState = EProfileItemList;
       
  1161         }
       
  1162     else
       
  1163         {
       
  1164         iProfileInd = 0;
       
  1165         delete iFileNameArr;
       
  1166         iFileNameArr = NULL;
       
  1167         iSharingSubState = EShareItemList;
       
  1168         }
       
  1169     SelfComplete( KErrNone );
       
  1170     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1171     }
       
  1172 
       
  1173 // --------------------------------------------------------------------------
       
  1174 // CUpnpContentSharingAo::ShareItemListL
       
  1175 // ( other items are commented in header )
       
  1176 // --------------------------------------------------------------------------
       
  1177 //
       
  1178 void CUpnpContentSharingAo::ShareItemListL( const TInt& aParentId )
       
  1179     {
       
  1180     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1181     // do not share empty list
       
  1182     if ( iItemList && iItemList->ObjectCount() )
       
  1183         {
       
  1184         iFileSharing->ShareItemListL(
       
  1185             *UPnPCommonUtils::IntToDesC8LC( aParentId ),
       
  1186             *iItemList,
       
  1187             iSharedContainersCount, iStatus );
       
  1188         CleanupStack::PopAndDestroy(); // UPnPCommonUtils::IntToDesC8LC
       
  1189         iSharingSubState = EShareItemListResult;
       
  1190         SetActive();
       
  1191         }
       
  1192     else
       
  1193         {
       
  1194         // update indexes
       
  1195         iSharingSubState = EShareItemListResult;
       
  1196         SelfComplete( KErrNone );
       
  1197         }
       
  1198     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1199     }
       
  1200 
       
  1201 // --------------------------------------------------------------------------
       
  1202 // CUpnpContentSharingAo::ShareItemListResultL
       
  1203 // ( other items are commented in header )
       
  1204 // --------------------------------------------------------------------------
       
  1205 //
       
  1206 void CUpnpContentSharingAo::ShareItemListResultL()
       
  1207     {
       
  1208     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1209 
       
  1210     iTmpItem = NULL;
       
  1211     if ( iSharingState == EShareItems )
       
  1212         {
       
  1213         ShareItemsResultL();
       
  1214         }
       
  1215     else if ( iSharingState == EShareAllItems )
       
  1216         {
       
  1217         AllItemsResultL();
       
  1218         }
       
  1219     iSharingSubState = EIdle;
       
  1220     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1221     }
       
  1222 
       
  1223 
       
  1224 // --------------------------------------------------------------------------
       
  1225 // CUpnpContentSharingAo::AllItemsResultL
       
  1226 // ( other items are commented in header )
       
  1227 // --------------------------------------------------------------------------
       
  1228 //
       
  1229 void CUpnpContentSharingAo::AllItemsResultL()
       
  1230     {
       
  1231     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1232 
       
  1233     TInt totalItemCount( 0 );
       
  1234 
       
  1235     if ( iItemList )
       
  1236         {
       
  1237         // This updates the field needed in UI for progress
       
  1238         iSharingProgress += iItemList->ObjectCount();
       
  1239         iEngine->SetProgressL( iSharingProgress );
       
  1240         DeleteListUpnpObject();
       
  1241         delete iFileNameArr;
       
  1242         iFileNameArr = NULL;
       
  1243         }
       
  1244     iTmpItem = NULL;
       
  1245 
       
  1246     switch ( iContainerType )
       
  1247         {
       
  1248     case EImageAndVideo:
       
  1249         {
       
  1250         totalItemCount = iMetadataUtility->ImageFiles().ItemCount() +
       
  1251             iMetadataUtility->VideoFiles().ItemCount();
       
  1252         }
       
  1253         break;
       
  1254     case EPlaylist :
       
  1255         {
       
  1256         totalItemCount = iMetadataUtility->MusicFiles().ItemCount();
       
  1257         }
       
  1258         break;
       
  1259     default :
       
  1260         break;
       
  1261         }
       
  1262     // Fix EYSN-7CWDZ5 error in UPnP FW2.1  
       
  1263     // Have not changed it in UPnP FW2.5 because the FW 2.5 have 
       
  1264     // so much change. 
       
  1265     if ( iObjectIdx < totalItemCount )
       
  1266         {
       
  1267         // Continue sharing process since not everything is shared yet.
       
  1268         iSharingState = EShareAllItems;
       
  1269         }
       
  1270     else
       
  1271         {
       
  1272         if ( !iWriter )
       
  1273             {
       
  1274             User::Leave( KErrGeneral );
       
  1275             }
       
  1276         iWriter->SaveSharingStateL( iShareAllSelection );
       
  1277         iSharingState = ENotActive;
       
  1278 
       
  1279         }
       
  1280 
       
  1281     SelfComplete( KErrNone );
       
  1282     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1283     }
       
  1284 
       
  1285 // --------------------------------------------------------------------------
       
  1286 // CUpnpContentSharingAo::ShareContainersResultL
       
  1287 // ( other items are commented in header )
       
  1288 // --------------------------------------------------------------------------
       
  1289 //
       
  1290 void CUpnpContentSharingAo::ShareContainersResultL()
       
  1291     {
       
  1292     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1293 
       
  1294 
       
  1295     if ( !iStatus.Int() )
       
  1296         {
       
  1297         // previous container shared OK, save the album name
       
  1298         iWriter->AppendStatusL( iContainerIdx );
       
  1299         }
       
  1300 
       
  1301     if ( iTmpContainer )
       
  1302         {
       
  1303         TInt newId = UPnPCommonUtils::DesC8ToInt( iTmpContainer->Id() );
       
  1304         __LOG1("CUpnpContentSharingAo::ShareContainersResultL:\
       
  1305  id: %d", newId );
       
  1306         if ( !iSharedContainerIds )
       
  1307             {
       
  1308             iSharedContainerIds =
       
  1309                 new (ELeave) CArrayFixFlat<TInt>( 10 );
       
  1310             }
       
  1311         iSharedContainerIds->AppendL( newId );
       
  1312         delete iTmpContainer;
       
  1313         iTmpContainer = NULL;
       
  1314         }
       
  1315 
       
  1316     TInt totalContainers( 0 );
       
  1317     // determine next state
       
  1318     if ( iShareAllSelection == EShareAll )
       
  1319         {
       
  1320         switch ( iContainerType )
       
  1321             {
       
  1322             // totalContainers is used as index -> -1
       
  1323         case EImageAndVideo :
       
  1324             {
       
  1325             totalContainers = iContainerIds->MdcaCount() -1;
       
  1326             }
       
  1327             break;
       
  1328         case EPlaylist :
       
  1329             {
       
  1330             totalContainers = iContainerIds->MdcaCount() -1;
       
  1331             }
       
  1332             break;
       
  1333         default:
       
  1334             break;
       
  1335             }
       
  1336         }
       
  1337     else if ( iShareAllSelection == EShareMany )
       
  1338         {
       
  1339         totalContainers = iCurrentSelections.Count() -1;
       
  1340         }
       
  1341 
       
  1342     if ( iContainerIdx < totalContainers )
       
  1343         {
       
  1344         iContainerIdx++;
       
  1345         iSharingState = EShareContainers;
       
  1346         }
       
  1347     else
       
  1348         {
       
  1349         // all selected containers shared, next share items
       
  1350         iContainerIdx = 0;
       
  1351         iSharingState = EShareItems;
       
  1352         }
       
  1353     SelfComplete( KErrNone );
       
  1354     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1355 
       
  1356     }
       
  1357 
       
  1358 // --------------------------------------------------------------------------
       
  1359 // CUpnpContentSharingAo::ShareItemsResultL
       
  1360 // ( other items are commented in header )
       
  1361 // --------------------------------------------------------------------------
       
  1362 void CUpnpContentSharingAo::ShareItemsResultL()
       
  1363     {
       
  1364     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1365     if ( !iMetadataUtility )
       
  1366         {
       
  1367         User::Leave( KErrGeneral );
       
  1368         }
       
  1369 
       
  1370     if ( iItemList )
       
  1371         {
       
  1372         // This updates the field needed in UI for progress
       
  1373         iSharingProgress += iItemList->ObjectCount();
       
  1374         iEngine->SetProgressL( iSharingProgress );
       
  1375         DeleteListUpnpObject();
       
  1376         delete iFileNameArr;
       
  1377         iFileNameArr = NULL;
       
  1378         }
       
  1379     iTmpItem = NULL;
       
  1380     iSharingState = EShareItems;
       
  1381 
       
  1382     TInt totalContainers( 0 );
       
  1383     // Clear postfilters, they are re-set if needed: ShareItemsL/
       
  1384     // ShareAllItemsL
       
  1385     iMetadataUtility->ClearPostFiltersL();
       
  1386     // determine next state
       
  1387     if ( iShareAllSelection == EShareAll )
       
  1388         {
       
  1389         switch ( iContainerType )
       
  1390             {
       
  1391         case EImageAndVideo :
       
  1392             {
       
  1393             totalContainers = iContainerIds->MdcaCount() -1;
       
  1394             }
       
  1395             break;
       
  1396         case EPlaylist :
       
  1397             {
       
  1398             totalContainers = iContainerIds->MdcaCount() -1;
       
  1399                 
       
  1400             }
       
  1401             break;
       
  1402         default:
       
  1403             break;
       
  1404             }
       
  1405         }
       
  1406     else if ( iShareAllSelection == EShareMany )
       
  1407         {
       
  1408         if( iSharedContainerIds )
       
  1409             {
       
  1410             totalContainers = iSharedContainerIds->Count() -1;
       
  1411             }
       
  1412         else
       
  1413             {
       
  1414             // sharing of all containers failed or the containers under 
       
  1415             // sharing were deleted
       
  1416             totalContainers = KErrNotFound;
       
  1417             }
       
  1418         }
       
  1419 
       
  1420 
       
  1421     if ( !iObjectIdx )
       
  1422         {
       
  1423 
       
  1424         // all files were shared from current container
       
  1425         if ( iContainerIdx < totalContainers )
       
  1426             {
       
  1427             // more items in the selected..
       
  1428             iContainerIdx++;
       
  1429             }
       
  1430         else
       
  1431             {
       
  1432             // all selected containers shared..
       
  1433             if ( iShareAllSelection == EShareAll )
       
  1434                 {
       
  1435                 // next share individual files
       
  1436                 iSharingState = EShareAllItems;
       
  1437                 }
       
  1438             else
       
  1439                 {
       
  1440                 // sharing process is done.
       
  1441                 if ( totalContainers == KErrNotFound )
       
  1442                     {
       
  1443                     iShareAllSelection = EShareNone;
       
  1444                     }
       
  1445                 iWriter->SaveSharingStateL( iShareAllSelection );
       
  1446                 iSharingState = ENotActive;
       
  1447                 }
       
  1448             }
       
  1449         }
       
  1450 
       
  1451     SelfComplete( KErrNone );
       
  1452     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1453     }
       
  1454 
       
  1455 // --------------------------------------------------------------------------
       
  1456 // CUpnpContentSharingAo::SelectionObjectCountL
       
  1457 // ( other items are commented in header )
       
  1458 // --------------------------------------------------------------------------
       
  1459 //
       
  1460 TInt CUpnpContentSharingAo::SelectionObjectCountL(
       
  1461     const TUpnpMediaType aContainerType )
       
  1462     {
       
  1463     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1464 
       
  1465     TInt totalCount( 0);
       
  1466     if ( iShareAllSelection != EShareNone )
       
  1467         {
       
  1468         switch ( aContainerType )
       
  1469             {
       
  1470         case EImageAndVideo :
       
  1471             {
       
  1472             if ( !iCollections ) 
       
  1473                 {
       
  1474                 iCollections = CUPnPAlbumServices::NewL();
       
  1475                 }
       
  1476             __LOG("albumserv created");
       
  1477             CDesCArray* collIds = new ( ELeave ) CDesCArrayFlat( 
       
  1478                 KDefaultGranularity );
       
  1479             CleanupStack::PushL( collIds );
       
  1480             CDesCArray* collNames = new ( ELeave ) CDesCArrayFlat( 
       
  1481                 KDefaultGranularity );
       
  1482             CleanupStack::PushL( collNames );
       
  1483             iCollections->ListAlbumsL( *collIds, *collNames );
       
  1484             __LOG("albums listed");
       
  1485             collNames->Reset();
       
  1486 
       
  1487             if ( iShareAllSelection == EShareAll )
       
  1488                 {
       
  1489                 __LOG("EShareAll");
       
  1490                 for( TInt i(0); i<collIds->MdcaCount(); i++ )
       
  1491                     {
       
  1492                     TPtrC id( collIds->MdcaPoint( i ) );
       
  1493                     RDebug::Print(_L("id: %S"), &id );
       
  1494                     TRAPD( lcode, iCollections->OpenAlbumL( id,
       
  1495                                                             *collNames ));
       
  1496                     if( !lcode )
       
  1497                         {
       
  1498                         totalCount += collNames->MdcaCount();
       
  1499                         }
       
  1500                     else
       
  1501                         {
       
  1502                         }
       
  1503                     collNames->Reset();
       
  1504                     __LOG("Loop cycle end");
       
  1505                     }
       
  1506                 __LOG("Loop done");
       
  1507                 // Add individual files count
       
  1508                 const MCLFItemListModel* imgList =
       
  1509                     &iMetadataUtility->ImageFiles();
       
  1510                 totalCount += imgList->ItemCount();
       
  1511                 const MCLFItemListModel* vidList =
       
  1512                     &iMetadataUtility->VideoFiles();
       
  1513                 totalCount += vidList->ItemCount();
       
  1514                 __LOG("EShareAll done");
       
  1515                 }
       
  1516             else if ( iShareAllSelection == EShareMany )
       
  1517                 {
       
  1518                 for( iContainerIdx = 0; 
       
  1519                      iContainerIdx < iCurrentSelections.Count();
       
  1520                      iContainerIdx++ )
       
  1521                     {
       
  1522                     TInt ind = GetContainerIndexL(); 
       
  1523 
       
  1524                     if ( ind != KErrNotFound )
       
  1525                         {
       
  1526                         TPtrC id = iContainerIds->MdcaPoint( ind );
       
  1527                         TRAPD( openErr, iCollections->OpenAlbumL( 
       
  1528                                    id, 
       
  1529                                    *collNames ));
       
  1530                         if( !openErr )
       
  1531                             {
       
  1532                             totalCount += collNames->MdcaCount();
       
  1533                             collNames->Reset();
       
  1534                             }
       
  1535                         }
       
  1536                     __LOG("end for(..)");
       
  1537                     }
       
  1538                 iContainerIdx = 0;
       
  1539                 }
       
  1540             delete iCollections;
       
  1541             iCollections = NULL;
       
  1542             __LOG("iCollections deleted");
       
  1543             CleanupStack::PopAndDestroy( collNames );
       
  1544             CleanupStack::PopAndDestroy( collIds );
       
  1545             }
       
  1546             break;
       
  1547         case EPlaylist :
       
  1548             {
       
  1549             if ( !iPlaylists ) 
       
  1550                 {
       
  1551                 iPlaylists = CUPnPPlaylistServices::NewL();
       
  1552                 }
       
  1553 
       
  1554             CDesCArray* plIds = new ( ELeave ) CDesCArrayFlat( 
       
  1555                 KDefaultGranularity );
       
  1556             CleanupStack::PushL( plIds );
       
  1557             CDesCArray* plNames = new ( ELeave ) CDesCArrayFlat( 
       
  1558                 KDefaultGranularity );
       
  1559             CleanupStack::PushL( plNames );
       
  1560             iPlaylists->ListPlaylistsL( *plIds, *plNames );
       
  1561             plNames->Reset();
       
  1562 
       
  1563             if ( iShareAllSelection == EShareAll )
       
  1564                 {
       
  1565                 for( TInt i(0); i<plIds->MdcaCount(); i++ )
       
  1566                     {
       
  1567                     TPtrC id( plIds->MdcaPoint( i ) );
       
  1568                     iPlaylists->OpenPlaylistL( id,
       
  1569                                                *plNames );
       
  1570 
       
  1571                     totalCount += plNames->MdcaCount();
       
  1572                     plNames->Reset();
       
  1573                     }
       
  1574                 // Add individual files count
       
  1575                 const MCLFItemListModel* musicList =
       
  1576                     &iMetadataUtility->MusicFiles();
       
  1577                 totalCount += musicList->ItemCount();
       
  1578                 }
       
  1579             else if ( iShareAllSelection == EShareMany )
       
  1580                 {
       
  1581                 for( iContainerIdx = 0; 
       
  1582                      iContainerIdx < iCurrentSelections.Count();
       
  1583                      iContainerIdx++ )
       
  1584                     {
       
  1585                     TInt ind = GetContainerIndexL(); 
       
  1586 
       
  1587                     if ( ind != KErrNotFound )
       
  1588                         {
       
  1589                         TPtrC id = iContainerIds->MdcaPoint( ind );
       
  1590                         iPlaylists->OpenPlaylistL( id, 
       
  1591                                                    *plNames );
       
  1592                         totalCount += plNames->MdcaCount();
       
  1593                         plNames->Reset();
       
  1594                         }
       
  1595                     
       
  1596                     }
       
  1597                 iContainerIdx = 0;
       
  1598                 }
       
  1599             delete iPlaylists;
       
  1600             iPlaylists = NULL;
       
  1601             CleanupStack::PopAndDestroy( plNames );
       
  1602             CleanupStack::PopAndDestroy( plIds );
       
  1603             }
       
  1604             break;
       
  1605         default :
       
  1606             {
       
  1607             }
       
  1608             break;
       
  1609             }
       
  1610         }
       
  1611     __LOG1("CUpnpContentSharingAo::SelectionObjectCountL: totalCount: %d",
       
  1612         totalCount );
       
  1613 
       
  1614     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1615     return totalCount;
       
  1616     }
       
  1617 
       
  1618 // --------------------------------------------------------------------------
       
  1619 // CUpnpContentSharingAo::SharingProgress
       
  1620 // ( other items are commented in header )
       
  1621 // --------------------------------------------------------------------------
       
  1622 //
       
  1623 TInt CUpnpContentSharingAo::SharingProgress(
       
  1624     TUpnpMediaType& aContainerType ) const
       
  1625     {
       
  1626     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1627     aContainerType = iContainerType;
       
  1628     __LOG1("CUpnpContentSharingAo::SharingProgress: iObjectIdx: %d",
       
  1629         iSharingProgress );
       
  1630     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1631     return iSharingProgress;
       
  1632     }
       
  1633 
       
  1634 
       
  1635 // --------------------------------------------------------------------------
       
  1636 // CUpnpContentSharingAo::GetContainerIndexL
       
  1637 // Returns IntValue for aObject
       
  1638 // --------------------------------------------------------------------------
       
  1639 //
       
  1640 TInt CUpnpContentSharingAo::GetContainerIndexL()
       
  1641     {
       
  1642     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1643     TInt ind( KErrNone );
       
  1644     if ( iShareAllSelection == EShareAll )
       
  1645         {
       
  1646         if( iContainerIds->MdcaCount() )
       
  1647             {
       
  1648             ind = iContainerIdx;
       
  1649             }
       
  1650         else
       
  1651             {
       
  1652             ind = KErrNotFound;
       
  1653             }
       
  1654         }
       
  1655     else if ( iContainerIdx >= iCurrentSelections.Count() ||
       
  1656         ( iCurrentSelections[ iContainerIdx ]- KUiSelectionOffset 
       
  1657           >= iContainerIds->MdcaCount() ))
       
  1658         {
       
  1659         ind = KErrNotFound;
       
  1660         }
       
  1661     else
       
  1662         {
       
  1663         if ( iShareAllSelection == EShareMany )
       
  1664             {
       
  1665             ind = iCurrentSelections[ iContainerIdx ] 
       
  1666                 - KUiSelectionOffset;
       
  1667             
       
  1668             }
       
  1669         else
       
  1670             {
       
  1671             User::Leave( KErrArgument );
       
  1672             }
       
  1673         }
       
  1674     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1675     return ind; // correct index or KErrNotFound
       
  1676     }
       
  1677 
       
  1678 
       
  1679 // --------------------------------------------------------------------------
       
  1680 // CUpnpContentSharingAo::SelfComplete
       
  1681 // Complete own request
       
  1682 // --------------------------------------------------------------------------
       
  1683 //
       
  1684 void CUpnpContentSharingAo::SelfComplete( const TInt aError )
       
  1685     {
       
  1686     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1687     if ( iStopRequested )
       
  1688         {
       
  1689         iSharingState = ENotActive;
       
  1690         }
       
  1691     SetActive();
       
  1692     TRequestStatus* stat = &iStatus;
       
  1693     User::RequestComplete( stat, aError );
       
  1694     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1695     }
       
  1696 
       
  1697 
       
  1698 // --------------------------------------------------------------------------
       
  1699 // CUpnpContentSharingAo::AppendImageFilesToListL
       
  1700 // ( other items are commented in header )
       
  1701 // --------------------------------------------------------------------------
       
  1702 //
       
  1703 void CUpnpContentSharingAo::AppendImageFilesToListL()
       
  1704     {
       
  1705     // Obtain list of image files from CLF
       
  1706     const MCLFItemListModel* list(NULL);
       
  1707     list = &iMetadataUtility->ImageFiles();
       
  1708     if ( !list )
       
  1709         {
       
  1710         User::Leave( KErrArgument );
       
  1711         }
       
  1712 
       
  1713     // check if the iImageIndex is still less than the number of images
       
  1714     //       -> there are still images to be shared
       
  1715     TInt imageCount = list->ItemCount();
       
  1716     if ( !imageCount )
       
  1717         {
       
  1718         iAllImagesShared = ETrue;
       
  1719         return;
       
  1720         }
       
  1721 
       
  1722     if ( iImageIndex < imageCount )
       
  1723         {
       
  1724 
       
  1725         // Prepare storage for filenames
       
  1726         // Loop until all images are processed or until we have
       
  1727         // KContentDirCommitAmount files in the list of objects to be shared.
       
  1728         while ( !iAllImagesShared &&
       
  1729                 iItemList->ObjectCount() <= KContentDirCommitAmount )
       
  1730             {
       
  1731             // Create an item with parent id of Images&Videos container.
       
  1732             HBufC8* id = UPnPCommonUtils::IntToDesC8LC(
       
  1733                 iContainerId );
       
  1734             TRAPD( imgErr, iTmpItem = iMetadataUtility->CreateItemL(
       
  1735                        list->Item( iImageIndex ),
       
  1736                        *id ) );
       
  1737 
       
  1738             if ( !imgErr && iTmpItem )
       
  1739                 {
       
  1740                 TPtrC fullFileName;
       
  1741                 list->Item( iImageIndex ).GetField( 
       
  1742                     ECLFFieldIdFileNameAndPath,
       
  1743                     fullFileName );
       
  1744 
       
  1745                 if ( !imgErr && iTmpItem )
       
  1746                     {
       
  1747                     // Update item's metadata and append it to iItemList.
       
  1748                     iMetadataUtility->UpdateMetadataL( 
       
  1749                         EPhotoFile,
       
  1750                         iTmpItem,
       
  1751                         fullFileName );
       
  1752                     iTmpItem->SetObjectClassL( KImageItemObjectClass );
       
  1753                     iItemList->AppendObjectL( *iTmpItem );
       
  1754                     iFileNameArr->AppendL( fullFileName );
       
  1755                     }
       
  1756                 else
       
  1757                     {
       
  1758                     delete iTmpItem;
       
  1759                     }
       
  1760                 }
       
  1761             else
       
  1762                 {
       
  1763                 }
       
  1764 
       
  1765             // set iTmpItem to NULL
       
  1766             iTmpItem = NULL;
       
  1767 
       
  1768             // clean up
       
  1769             CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
  1770 
       
  1771             // increment counter to process next image.
       
  1772             iImageIndex++;
       
  1773 
       
  1774             if ( iImageIndex >= imageCount )
       
  1775                 {
       
  1776                 iAllImagesShared = ETrue;
       
  1777                 }
       
  1778             }
       
  1779 
       
  1780         }
       
  1781     // update iObjectIdx to keep the progressbar ok.
       
  1782     iObjectIdx = iImageIndex;
       
  1783     }
       
  1784 
       
  1785 // --------------------------------------------------------------------------
       
  1786 // CUpnpContentSharingAo::AppendVideoFilesToListL
       
  1787 // ( other items are commented in header )
       
  1788 // --------------------------------------------------------------------------
       
  1789 //
       
  1790 void CUpnpContentSharingAo::AppendVideoFilesToListL()
       
  1791     {
       
  1792     // Obtain list of video files from CLF
       
  1793     const MCLFItemListModel* list(NULL);
       
  1794     list = &iMetadataUtility->VideoFiles();
       
  1795     if ( !list )
       
  1796         {
       
  1797         User::Leave( KErrArgument );
       
  1798         }
       
  1799 
       
  1800     // Obtain the number of video file items in the list.
       
  1801     TInt videoCount( list->ItemCount() );
       
  1802     if ( !videoCount )
       
  1803         {
       
  1804         iAllVideosShared = ETrue;
       
  1805         return;
       
  1806         }
       
  1807 
       
  1808     // Check that there are still videos to be shared.
       
  1809     if ( iVideoIndex < videoCount )
       
  1810         {
       
  1811 
       
  1812         if ( !iFileNameArr )
       
  1813             {
       
  1814             iFileNameArr = new (ELeave)
       
  1815                 CDesCArrayFlat( 4 );
       
  1816             }
       
  1817         // Loop until all videos are processed or until we have
       
  1818         // KContentDirCommitAmount files in the list of objects to be shared.
       
  1819         while ( !iAllVideosShared &&
       
  1820                 iItemList->ObjectCount() <= KContentDirCommitAmount )
       
  1821             {
       
  1822             // Create an item with parent id of Images&Videos container.
       
  1823             HBufC8* id = UPnPCommonUtils::IntToDesC8LC(
       
  1824                 iContainerId );
       
  1825             TRAPD( vidErr, iTmpItem = iMetadataUtility->CreateItemL(
       
  1826                        list->Item( iVideoIndex ),
       
  1827                        *id ) );
       
  1828 
       
  1829             if ( !vidErr && iTmpItem )
       
  1830                 {
       
  1831                 TPtrC fullFileName;
       
  1832                 list->Item( iVideoIndex ).GetField( 
       
  1833                     ECLFFieldIdFileNameAndPath,
       
  1834                     fullFileName );
       
  1835                
       
  1836 
       
  1837                 if ( !vidErr && iTmpItem )
       
  1838                     {
       
  1839                     // Update item's metadata and append it to iItemList.
       
  1840                     iMetadataUtility->UpdateMetadataL( 
       
  1841                         EVideoFile,
       
  1842                         iTmpItem,
       
  1843                         fullFileName );
       
  1844                     iTmpItem->SetObjectClassL( KVideoItemObjectClass );
       
  1845                     iItemList->AppendObjectL( *iTmpItem );
       
  1846                     iFileNameArr->AppendL( fullFileName );
       
  1847                     }
       
  1848                 else
       
  1849                     {
       
  1850                     delete iTmpItem;
       
  1851                     iTmpItem = NULL;
       
  1852                     }
       
  1853                 }
       
  1854             else
       
  1855                 {
       
  1856                 }
       
  1857 
       
  1858             // set iTmpItem to NULL
       
  1859             iTmpItem = NULL;
       
  1860 
       
  1861             // clean up
       
  1862             CleanupStack::PopAndDestroy(); // IntToDesC8LC
       
  1863 
       
  1864             // increment counter to process next video.
       
  1865             iVideoIndex++;
       
  1866 
       
  1867             if ( iVideoIndex >= videoCount )
       
  1868                 {
       
  1869                 // all videos are processed.
       
  1870                 // Set iAllVideosShared -> ETrue to end the while loop.
       
  1871                 iAllVideosShared = ETrue;
       
  1872                 }
       
  1873             }
       
  1874         }
       
  1875 
       
  1876     // update iObjectIdx to keep the progressbar ok.
       
  1877     // Remember to add iImageIndex here!
       
  1878     iObjectIdx = iImageIndex + iVideoIndex;
       
  1879     }
       
  1880 
       
  1881 // --------------------------------------------------------------------------
       
  1882 // CUpnpContentSharingAo::RequestStop
       
  1883 // ( other items are commented in header )
       
  1884 // --------------------------------------------------------------------------
       
  1885 //
       
  1886 void CUpnpContentSharingAo::RequestStop( 
       
  1887     MUpnpSharingCallback::TSharingStopType aStopType )
       
  1888     {
       
  1889     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1890     iStopRequested = aStopType;
       
  1891     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1892     }
       
  1893 
       
  1894 // --------------------------------------------------------------------------
       
  1895 // CUpnpContentSharingAo::GetPlaylistNameByIdL
       
  1896 // ( other items are commented in header )
       
  1897 // --------------------------------------------------------------------------
       
  1898 //
       
  1899 TInt CUpnpContentSharingAo::GetContainerNameByIdL( const TDesC& aId,
       
  1900                                                    TDes8& aPlaylistName,
       
  1901                                                    const TInt aContainerType )
       
  1902     {
       
  1903     __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ );
       
  1904     TInt err( KErrNone );
       
  1905     CDesCArray* newIds = new ( ELeave )CDesCArrayFlat( 4 );
       
  1906     CleanupStack::PushL(newIds);
       
  1907     CDesCArray* newNames = new ( ELeave )CDesCArrayFlat( 4 );
       
  1908     CleanupStack::PushL(newNames);
       
  1909 
       
  1910     if( aContainerType == EImageAndVideo )
       
  1911         {
       
  1912         if ( !iCollections ) 
       
  1913             {
       
  1914             iCollections = CUPnPAlbumServices::NewL();
       
  1915             }
       
  1916         iCollections->ListAlbumsL( *newIds, *newNames );
       
  1917         delete iCollections;
       
  1918         iCollections = NULL;
       
  1919         }
       
  1920     else if ( aContainerType == EPlaylist )
       
  1921         {
       
  1922         if ( !iPlaylists ) 
       
  1923             {
       
  1924             iPlaylists = CUPnPPlaylistServices::NewL();
       
  1925             }
       
  1926         iPlaylists->ListPlaylistsL( *newIds, *newNames );
       
  1927         delete iPlaylists;
       
  1928         iPlaylists = NULL;
       
  1929         }
       
  1930 
       
  1931     if ( !newIds->MdcaCount() )
       
  1932         {
       
  1933         err = KErrGeneral;
       
  1934         }
       
  1935     else
       
  1936         {
       
  1937         for ( TInt i(0); i<newIds->MdcaCount();i++ )
       
  1938             {
       
  1939             if ( aId.Compare( newIds->MdcaPoint( i ) ) == 0 )
       
  1940                 {
       
  1941                 HBufC8* name8 = 
       
  1942                     UpnpString::FromUnicodeL( newNames->MdcaPoint( i ) );
       
  1943                 CleanupStack::PushL( name8 );
       
  1944                 TPtr8 name8tmp = name8->Des();
       
  1945                 aPlaylistName = name8tmp;
       
  1946                 CleanupStack::PopAndDestroy( name8 );
       
  1947                 }
       
  1948             }
       
  1949         }
       
  1950     CleanupStack::PopAndDestroy( newNames );
       
  1951     CleanupStack::PopAndDestroy( newIds );
       
  1952     __LOG8_1( "%s end.", __PRETTY_FUNCTION__ );
       
  1953     return err;
       
  1954     }
       
  1955 
       
  1956 void CUpnpContentSharingAo::DeleteListUpnpObject()
       
  1957     {
       
  1958     if ( iItemList )
       
  1959         {
       
  1960         TInt count = iItemList->ObjectCount();
       
  1961         for ( TInt i = count - 1; i >= 0; --i )
       
  1962             {
       
  1963             CUpnpItem* tmpItem = static_cast<CUpnpItem*>(
       
  1964                 iItemList->operator[]( i ));
       
  1965             TPtrC8 id( tmpItem->Id() );
       
  1966             iItemList->RemoveAndDestroy( id ); 
       
  1967             } 
       
  1968         delete iItemList;
       
  1969         iItemList = NULL;
       
  1970         }
       
  1971     }
       
  1972 // End of file