diff -r 000000000000 -r 72b543305e3a email/mail/UtilsSrc/CMailViewFactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/email/mail/UtilsSrc/CMailViewFactory.cpp Thu Dec 17 08:44:11 2009 +0200 @@ -0,0 +1,127 @@ +/* +* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "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: Factory for view plug-ins. +* +*/ + + +// INCLUDE FILES +#include "MailLog.h" +#include +#include +#include "CMailViewFactory.h" +#include + +// CONSTANTS + +// ============================ MEMBER FUNCTIONS =============================== + +// ----------------------------------------------------------------------------- +// MailViewFactory::CreateAdaptersL +// ----------------------------------------------------------------------------- +// +EXPORT_C CArrayPtr* MailViewFactory::CreateViewPluginsL() + { + LOG("MailViewFactory::CreateViewPluginsL()"); + // Create an array for adapter information + RImplInfoPtrArray implArray; + CleanupStack::PushL( TCleanupItem( CleanupImplArray, &implArray ) ); + + // Get the list of adapters + CMailMessageView::ListL( implArray ); + + // Sort them in priority order + implArray.Sort( + TLinearOrder( MailViewFactory::Compare ) ); + + // Create an array for adapters + LOG1( "CreateViewPluginsL: implArray.Count():%d", implArray.Count() ); + CArrayPtr* views = + new(ELeave) CArrayPtrFlat( Max( 1, implArray.Count() ) ); + CleanupStack::PushL( TCleanupItem( CleanupAdapterArray, views ) ); + // Create the adapters + for( TInt i( 0 ); i < implArray.Count(); i++ ) + { + CImplementationInformation& info = *implArray[i]; + TUid implementation( info.ImplementationUid() ); + + CMailMessageView* view = NULL; + //Create the plug-in view + view = CMailMessageView::NewL( implementation ); + + if( view ) + { + CleanupStack::PushL( view ); + views->AppendL( view ); + LOG("CreateViewPluginsL: views->AppendL"); + CleanupStack::Pop( view ); + } + } + + CleanupStack::Pop( views ); + CleanupStack::PopAndDestroy(); // implArray + + return views; + } + +// ----------------------------------------------------------------------------- +// MailViewFactory::CleanupImplArray +// ----------------------------------------------------------------------------- +// +void MailViewFactory::CleanupImplArray( TAny* aAny ) + { + RImplInfoPtrArray* implArray = + reinterpret_cast( aAny ); + implArray->ResetAndDestroy(); + implArray->Close(); + } + +// ----------------------------------------------------------------------------- +// MailViewFactory::CleanupAdapterArray +// ----------------------------------------------------------------------------- +// +void MailViewFactory::CleanupAdapterArray( TAny* aAny ) + { + CArrayPtr* views = + reinterpret_cast*>( aAny ); + views->ResetAndDestroy(); + delete views; + } + +// ----------------------------------------------------------------------------- +// MailViewFactory::Compare +// ----------------------------------------------------------------------------- +// +TInt MailViewFactory::Compare( const CImplementationInformation& aImpl1, + const CImplementationInformation& aImpl2 ) + { + // Compare the numerical values of opaque_data + TLex8 lex( aImpl1.OpaqueData() ); + TInt impl1( KMaxTInt ); + if( lex.Val( impl1 ) != KErrNone ) + { + impl1 = KMaxTInt; + } + + lex.Assign( aImpl2.OpaqueData() ); + TInt impl2( KMaxTInt ); + if( lex.Val( impl2 ) != KErrNone ) + { + impl2 = KMaxTInt; + } + + return impl1 - impl2; + } + +// End of File