serviceproviders/sapi_mediamanagement/tsrc/dev/tmediamgmttest/src/mgitemslist.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 24 Nov 2009 08:56:33 +0200
changeset 33 50974a8b132e
parent 19 989d2f495d90
permissions -rw-r--r--
Revision: 200945 Kit: 200948

/*
* Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   Implements CLiwIterable type
*
*/



#include <MCLFItem.h>
#include <MCLFItemListModel.h>

#include "mgitemslist.h"
#include "mgmediaitemfactory.h"
#include "mgmediaitem.h"


_LIT8( KMgFileNameAndPath, "FileNameAndPath" );

const TInt KStartItemIndex = -1;

// ---------------------------------------------------------------------------
// CMgItemsList::CMgItemsList
// Parameterised constructor
// ---------------------------------------------------------------------------
//
 
CMgItemsList::CMgItemsList( MCLFItemListModel* aItemListModel, TMgCmdId aCmdId )
    {
    iItemListModel = aItemListModel; 
    iCount = iItemListModel->ItemCount(); 
    iCurrent = KStartItemIndex; 
    iCmdId = aCmdId; 
    iMediaItem = NULL; 
    
    }
// ---------------------------------------------------------------------------
// CMgItemsList::NewL
// Two-phased constructor
// ---------------------------------------------------------------------------
//
 
CMgItemsList* CMgItemsList::NewL( MCLFItemListModel* aItemListModel, TMgCmdId aCmdId )
    {
    CMgItemsList* self = new( ELeave ) CMgItemsList( aItemListModel, aCmdId);
    CleanupStack::PushL( self );
    self->ConstructL();
    CleanupStack::Pop( self );
    return self;
    }

// ---------------------------------------------------------------------------
// CMgItemsList::ConstructL
// Two-phased constructor
// ---------------------------------------------------------------------------
//
 
void CMgItemsList::ConstructL()
    {
    iMGMediaItemFactory = CMgMediaItemFactory::NewL();
    }
// ---------------------------------------------------------------------------
// CMgItemsList::~CMgItemsList
// Class destructor
// ---------------------------------------------------------------------------
//
CMgItemsList::~CMgItemsList()
    {
  	if( iItemListModel )
	  	{
	  	delete iItemListModel;
	  	iItemListModel = NULL;
	  	}
  	
  	if( iMGMediaItemFactory )
	  	{
	  	delete iMGMediaItemFactory;
		iMGMediaItemFactory = NULL;	
	  	}
	  	
  	if( iMediaItem )
	  	{
	  	delete iMediaItem;
		iMediaItem = NULL;	
	  	}
	
	}
// ---------------------------------------------------------------------------
// CMgItemsList::Reset
// Resets the iterator to point to the beginning of list
// ---------------------------------------------------------------------------
//

void CMgItemsList::Reset() 
    {
    iCurrent = KStartItemIndex;// if user resets the list
    }
    

// ---------------------------------------------------------------------------
// CMgItemsList::NextL
// Constructs the next media item in the form of a map
// ---------------------------------------------------------------------------
//
TBool CMgItemsList::NextL( TLiwVariant& aItem )
    {
    iCurrent++;
    if( iCurrent<iCount )
        {
        const MCLFItem& item = iItemListModel->Item( iCurrent );
        TPtrC fullPath;
        item.GetField(ECLFFieldIdFileNameAndPath, fullPath );
        CLiwDefaultMap *outputMap = CLiwDefaultMap::NewL();
        outputMap->InsertL(KMgFileNameAndPath,TLiwVariant(fullPath));
        if( iCmdId==EMgGetFilesInfo )// if user requests for file metadata
            {
            if( NULL == iMediaItem ) 
                {
            	iMediaItem = iMGMediaItemFactory->GetMediaItemL( item );
                }
           	if( NULL == iMediaItem )
           	    {
           		return KErrNotSupported;
           	    }
           	iMediaItem->FillInfo( outputMap, item ); 
            }
	    aItem.SetL(TLiwVariant(outputMap)); 
        return ETrue;	
        }
    else
        {
        return EFalse;	
        }
    }