ui/uiengine/medialistwrapper/src/glxtitlefetcher.cpp
changeset 33 1ee2af37811f
child 45 863223ea6961
equal deleted inserted replaced
29:2c833fc9e98f 33:1ee2af37811f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Title fetcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include "glxtitlefetcher.h"
       
    24 
       
    25 #include <mpxcollectionpath.h>
       
    26 #include <mpxmediageneraldefs.h>
       
    27 #include <mglxmedialist.h>
       
    28 #include <glxattributecontext.h>
       
    29 #include <glxuistd.h>
       
    30 #include "glxlog.h"
       
    31 #include "glxtracer.h"
       
    32 
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CGlxTitleFetcher::CGlxTitleFetcher(MGlxTitleFetcherObserver& aObserver,
       
    42                         CMPXCollectionPath* aPath) :
       
    43    iObserver(aObserver), iPath(aPath)
       
    44     {
       
    45     TRACER("CGlxTitleFetcher::CGlxTitleFetcher");
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // ---------------------------------------------------------------------------
       
    51 // 
       
    52     
       
    53 void CGlxTitleFetcher::ConstructL()
       
    54     {
       
    55     TRACER("CGlxTitleFetcher::ConstructL");
       
    56     // Go back one level to obtain the ID
       
    57     iPathId = iPath->Id();
       
    58     // Go back another level from which to create a media list containing 
       
    59     // this path
       
    60     iPath->Back();
       
    61     
       
    62     if( iPath->Levels() < 0 )
       
    63         {
       
    64         return;
       
    65         }
       
    66     
       
    67     iBackMediaList = MGlxMediaList::InstanceL(*iPath);
       
    68     
       
    69     /// @todo: This idSpaceId must be calculated properly
       
    70     TGlxIdSpaceId idSpaceId = iBackMediaList->IdSpaceId(0);
       
    71     
       
    72     TGlxMediaId id(iPathId);
       
    73     TBool requestAttributes = ETrue;
       
    74     TInt index = iBackMediaList->Index(idSpaceId, id);
       
    75     
       
    76     if ( index != KErrNotFound )
       
    77         {
       
    78         const TGlxMedia& item = iBackMediaList->Item(index);
       
    79     	const CGlxMedia* media = item.Properties();
       
    80 
       
    81     	// get the Title from the attribute if it is already present
       
    82     	if (media && media->IsSupported(KMPXMediaGeneralTitle)
       
    83     	    && index != KErrNotFound)
       
    84     		{
       
    85             const TDesC&  title = media->ValueText(KMPXMediaGeneralTitle);
       
    86             // notify the observer		
       
    87             iObserver.HandleTitleAvailableL(title); 
       
    88             requestAttributes = EFalse;
       
    89     		}
       
    90     	}
       
    91     
       
    92     if ( requestAttributes )
       
    93 	    {
       
    94         // Otherwise add a context setting range to cover all items
       
    95         iContext = CGlxDefaultAttributeContext::NewL();
       
    96         iContext->SetRangeOffsets(10000,10000);
       
    97         iContext->AddAttributeL(KMPXMediaGeneralTitle);
       
    98         // Add the context at a high priority
       
    99         iBackMediaList->AddContextL( iContext,
       
   100                                      KGlxFetchContextPriorityTitleFetcher );
       
   101         // Set self as observer
       
   102         iBackMediaList->AddMediaListObserverL(this);
       
   103 	    }
       
   104 	}
       
   105 
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Two-phased constructor.
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CGlxTitleFetcher* CGlxTitleFetcher::NewL(MGlxTitleFetcherObserver& aObserver,
       
   112                         CMPXCollectionPath* aPath)
       
   113     {
       
   114     CGlxTitleFetcher* self = new (ELeave) CGlxTitleFetcher(aObserver, aPath);
       
   115     CleanupStack::PushL(self);
       
   116     self->ConstructL();
       
   117     CleanupStack::Pop(self);
       
   118     return self;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Destructor
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CGlxTitleFetcher::~CGlxTitleFetcher()
       
   126     {
       
   127     TRACER("CGlxTitleFetcher::~CGlxTitleFetcher ()");
       
   128 
       
   129     if(iBackMediaList)
       
   130         {
       
   131         if(iContext)
       
   132             {
       
   133             iBackMediaList->RemoveContext(iContext);
       
   134             delete iContext;
       
   135             }
       
   136         iBackMediaList->RemoveMediaListObserver(this);           
       
   137 		iBackMediaList->Close();
       
   138         }
       
   139     
       
   140     }
       
   141 // ---------------------------------------------------------------------------
       
   142 // CGlxTitleFetcher::HandleItemAddedL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CGlxTitleFetcher::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex,
       
   146         MGlxMediaList* aList)  
       
   147     {    
       
   148     TRACER("CGlxTitleFetcher::HandleItemAddedL ()");
       
   149     if(aList == iBackMediaList)
       
   150            {
       
   151            for(TInt index = aStartIndex;index <= aEndIndex;index++)
       
   152            // Is it the item (path) that we want
       
   153                {
       
   154                if(aList->Item(index).Id().Value() == (TUint32)iPathId)
       
   155                        {
       
   156                        const TGlxMedia& item = aList->Item(index);
       
   157                        const CGlxMedia* media = item.Properties();
       
   158                        // get the Title from the attribute
       
   159                        if (media && media->IsSupported(KMPXMediaGeneralTitle))
       
   160                            {
       
   161                            const TDesC&  title = media->ValueText(KMPXMediaGeneralTitle);
       
   162                            // notify the observer      
       
   163                            iObserver.HandleTitleAvailableL(title); 
       
   164                            iBackMediaList->RemoveContext(iContext);
       
   165                            delete iContext;
       
   166                            iContext = NULL;                
       
   167                            }
       
   168                        }
       
   169                 }
       
   170            }
       
   171     }
       
   172 // ---------------------------------------------------------------------------
       
   173 // CGlxTitleFetcher::HandleAttributesAvailableL
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CGlxTitleFetcher::HandleAttributesAvailableL(TInt aItemIndex, 	
       
   177 		const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* aList)
       
   178     {
       
   179     TRACER("CGlxTitleFetcher::HandleAttributesAvailableL ()");
       
   180     // Is it the list that we want    
       
   181     if(aList == iBackMediaList)
       
   182         {
       
   183         // Is it the item (path) that we want
       
   184         if(aList->Item(aItemIndex).Id().Value() == (TUint32)iPathId)
       
   185             {
       
   186             const TGlxMedia& item = aList->Item(aItemIndex);
       
   187 			const CGlxMedia* media = item.Properties();
       
   188 			// get the Title from the attribute
       
   189 			if (media && media->IsSupported(KMPXMediaGeneralTitle))
       
   190 				{
       
   191                 const TDesC&  title = media->ValueText(KMPXMediaGeneralTitle);
       
   192 	            // notify the observer		
       
   193                 iObserver.HandleTitleAvailableL(title); 
       
   194                 iBackMediaList->RemoveContext(iContext);
       
   195                 delete iContext;
       
   196                 iContext = NULL;
       
   197 		        
       
   198 				}
       
   199             }
       
   200         }
       
   201     }
       
   202 
       
   203 
       
   204 
       
   205 //  End of File