mpxplugins/viewplugins/views/commoncontainer/src/mpxcommoncontainermediahelper.cpp
changeset 0 ff3acec5bc43
child 21 a1247965635c
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 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:  Implementation of MPX common container Media helper.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mpxcollectionpath.h>
       
    20 #include <mpxcollectionutility.h>
       
    21 #include <mpxmediageneraldefs.h>
       
    22 #include <mpxmediacontainerdefs.h>
       
    23 #include <mpxmediamusicdefs.h>
       
    24 #include <mpxcommandgeneraldefs.h>
       
    25 #include <mpxlog.h>
       
    26 #include "mpxcommoncontainer.h"
       
    27 #include "mpxcommoncontainermediahelper.h"
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // Two-phased constructor
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CMPXCommonContainerMediaHelper* CMPXCommonContainerMediaHelper::NewL( 
       
    36     MMPXCommonContainer* aCommonContainer )
       
    37     {    
       
    38     CMPXCommonContainerMediaHelper* self = 
       
    39         new (ELeave) CMPXCommonContainerMediaHelper( aCommonContainer );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // Constructor. 
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 CMPXCommonContainerMediaHelper::CMPXCommonContainerMediaHelper(
       
    51     MMPXCommonContainer* aCommonContainer )
       
    52     : iCommonContainer( aCommonContainer )
       
    53     {
       
    54     }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // 2nd phase constructor. 
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CMPXCommonContainerMediaHelper::ConstructL()
       
    61     {
       
    62     iCollectionUtility = MMPXCollectionUtility::NewL( this );
       
    63 
       
    64 #ifdef __USE_MESSAGE_SUBSCRIPTION
       
    65     // This class does not care about collection messages
       
    66     iCollectionUtility->Collection().ClearSubscriptionsL();
       
    67 #endif
       
    68     }
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // Destructor
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 CMPXCommonContainerMediaHelper::~CMPXCommonContainerMediaHelper()
       
    75     {
       
    76     if ( iCollectionUtility )
       
    77         {
       
    78         iCollectionUtility->Close();
       
    79         }
       
    80     }
       
    81     
       
    82 // ----------------------------------------------------------------------------
       
    83 // Retrieves the media given the current path, and upon return,
       
    84 // either calls back the observer, or broadcasts the message to 
       
    85 // the given client list
       
    86 // ----------------------------------------------------------------------------
       
    87 void CMPXCommonContainerMediaHelper::MediaL( 
       
    88     const TMPXItemId& aItemId, 
       
    89     RArray<TMPXAttribute> aAttrs,
       
    90     CMPXMedia* aAttrSpecs )
       
    91     {
       
    92     MPX_DEBUG1("CMPXCommonContainerMediaHelper::MediaL(): Entering");
       
    93 
       
    94     CMPXCollectionPath* cPath = iCollectionUtility->Collection().PathL();  
       
    95     CleanupStack::PushL( cPath );
       
    96     cPath->Set( aItemId );
       
    97     iCollectionUtility->Collection().MediaL( *cPath, aAttrs.Array(), aAttrSpecs );
       
    98     CleanupStack::PopAndDestroy( cPath );
       
    99 
       
   100     MPX_DEBUG1("CMPXCommonContainerMediaHelper::MediaL(): Exiting");
       
   101     }
       
   102 
       
   103 // ----------------------------------------------------------------------------
       
   104 // Updates the specified media with the results from the search
       
   105 // criteria
       
   106 // ----------------------------------------------------------------------------
       
   107 void CMPXCommonContainerMediaHelper::UpdateMediaL( 
       
   108     CMPXMedia* aMedia, 
       
   109     RArray<TMPXAttribute> aSearchAttrs,
       
   110     CMPXMedia* aSearchAttrSpecs )
       
   111     {
       
   112     MPX_DEBUG1("CMPXCommonContainerMediaHelper::UpdateMediaL(): Entering");
       
   113 
       
   114     CMPXMedia* mediaQuery = CMPXMedia::NewL();
       
   115     CleanupStack::PushL( mediaQuery );
       
   116     mediaQuery->SetTObjectValueL(KMPXMediaGeneralType, EMPXGroup);        
       
   117     mediaQuery->SetTObjectValueL<TMPXGeneralCategory>(
       
   118         KMPXMediaGeneralCategory, EMPXSong);
       
   119     TMPXItemId mediaId = *aMedia->Value<TMPXItemId>( KMPXMediaGeneralId );
       
   120     mediaQuery->SetTObjectValueL(KMPXMediaGeneralId, mediaId );
       
   121     mediaQuery->SetTObjectValueL(KMPXMediaGeneralContainerId, mediaId );
       
   122     mediaQuery->SetCObjectValueL<CMPXAttributeSpecs>(
       
   123         KMPXCommandMediaAttributeSpecs, aSearchAttrSpecs );
       
   124 
       
   125     // Find the attributes associated with the media
       
   126     CMPXMedia* queryResult = iCollectionUtility->Collection().FindAllL( 
       
   127         *mediaQuery, aSearchAttrs.Array() );
       
   128     CleanupStack::PopAndDestroy( mediaQuery );
       
   129     
       
   130     CleanupStack::PushL( queryResult );
       
   131     
       
   132     // update media with the query results
       
   133     const CMPXMediaArray* medias =
       
   134         queryResult->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   135     User::LeaveIfNull(const_cast<CMPXMediaArray*>(medias));
       
   136     
       
   137     aMedia->SetCObjectValueL(
       
   138         KMPXMediaArrayContents, const_cast<CMPXMediaArray*>(medias));
       
   139     aMedia->SetTObjectValueL(
       
   140         KMPXMediaArrayCount, medias->Count());
       
   141         
       
   142     CleanupStack::PopAndDestroy( queryResult );
       
   143 
       
   144     MPX_DEBUG1("CMPXCommonContainerMediaHelper::UpdateMediaL(): Exiting");
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // Cancels all outstanding requests
       
   149 // ----------------------------------------------------------------------------
       
   150 void CMPXCommonContainerMediaHelper::CancelRequests()
       
   151     {
       
   152     MPX_FUNC_EX("CMPXCommonContainerMediaHelper::CancelRequests()");
       
   153     if ( iCollectionUtility )
       
   154         {
       
   155         iCollectionUtility->Collection().CancelRequest();
       
   156         }
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // From MMPXCollectionObserver
       
   161 // ----------------------------------------------------------------------------
       
   162 void CMPXCommonContainerMediaHelper::HandleCollectionMessage( 
       
   163     CMPXMessage* /*aMsg*/,
       
   164     TInt /*aErr*/)
       
   165     {
       
   166     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleCollectionMessageL(CMPXMessage): Entering");
       
   167     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleCollectionMessageL(CMPXMessage): Exiting");
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // From MMPXCollectionObserver
       
   172 // ----------------------------------------------------------------------------
       
   173 void CMPXCommonContainerMediaHelper::HandleOpenL( 
       
   174     const CMPXMedia& /*aEntries*/,
       
   175     TInt /*aIndex*/, 
       
   176     TBool /*aComplete*/, 
       
   177     TInt /*aError*/ )
       
   178     {
       
   179     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleOpenL(): Entering");
       
   180     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleOpenL(): Exiting");
       
   181     }
       
   182     
       
   183 // ----------------------------------------------------------------------------
       
   184 // From MMPXCollectionObserver
       
   185 // ----------------------------------------------------------------------------
       
   186 void CMPXCommonContainerMediaHelper::HandleOpenL( 
       
   187     const CMPXCollectionPlaylist& /*aPlaylist*/,
       
   188     TInt /*aError*/ )
       
   189     {
       
   190     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleOpenL(): Entering");
       
   191     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleOpenL(): Exiting");
       
   192     }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // From MMPXCollectionObserver
       
   196 // ----------------------------------------------------------------------------
       
   197 void CMPXCommonContainerMediaHelper::HandleCommandComplete( 
       
   198     CMPXCommand* /*aCommandResult*/, 
       
   199     TInt /*aError*/ )
       
   200     {
       
   201     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleCommandComplete(): Entering");
       
   202     MPX_DEBUG1("CMPXCommonContainerMediaHelper::HandleCommandComplete(): Exiting");
       
   203     }
       
   204 
       
   205 // ----------------------------------------------------------------------------
       
   206 // From MMPXCollectionMediaObserver
       
   207 // ----------------------------------------------------------------------------
       
   208 //
       
   209 void CMPXCommonContainerMediaHelper::HandleCollectionMediaL(
       
   210     const CMPXMedia& aMedia, 
       
   211     TInt aError )    
       
   212     {
       
   213     MPX_FUNC_EX("CMPXCommonContainerMediaHelper::HandleCollectionMediaL");
       
   214     MPX_DEBUG2("CMPXCommonContainerMediaHelper::HandleCollectionMediaL(): error %d", aError);
       
   215 
       
   216     if( aError == KErrNone )
       
   217         {
       
   218         // Find the media in the common container
       
   219         if( aMedia.IsSupported( KMPXMediaGeneralId ) )
       
   220             {
       
   221             const TMPXItemId mediaId( 
       
   222                 aMedia.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
   223 
       
   224             const CMPXMediaArray& mediaArray = 
       
   225                 iCommonContainer->ListBoxArray()->MediaArray();
       
   226             const TInt count( mediaArray.Count() );
       
   227             
       
   228             for( TInt index = 0; index < count; index++ )
       
   229                 {
       
   230                 CMPXMedia* media( mediaArray.AtL( index ) );
       
   231                 if( media->IsSupported( KMPXMediaGeneralId ) )
       
   232                     {
       
   233                     TMPXItemId containerId(
       
   234                         media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
   235                     if ( mediaId == containerId )
       
   236                         {
       
   237                         // Update the list box item
       
   238                         *media = aMedia;
       
   239                         // Refresh the list box item
       
   240                         iCommonContainer->DrawLbxItem( index );
       
   241                         break;
       
   242                         }
       
   243                     }
       
   244                 }
       
   245             }
       
   246         }
       
   247     }
       
   248 
       
   249 //End of file