email/mail/UtilsSrc/CMailViewFactory.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Factory for view plug-ins.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "MailLog.h"
       
    21 #include <e32std.h>
       
    22 #include <ecom/ecom.h>
       
    23 #include "CMailViewFactory.h"
       
    24 #include <CMailMessageView.h>
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // MailViewFactory::CreateAdaptersL
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C CArrayPtr<CMailMessageView>* MailViewFactory::CreateViewPluginsL()
       
    35     {
       
    36     LOG("MailViewFactory::CreateViewPluginsL()");
       
    37     // Create an array for adapter information
       
    38     RImplInfoPtrArray implArray;
       
    39     CleanupStack::PushL( TCleanupItem( CleanupImplArray, &implArray ) );
       
    40 
       
    41     // Get the list of adapters
       
    42     CMailMessageView::ListL( implArray );
       
    43 
       
    44     // Sort them in priority order
       
    45     implArray.Sort(
       
    46         TLinearOrder<CImplementationInformation>( MailViewFactory::Compare ) );
       
    47 
       
    48     // Create an array for adapters
       
    49 	LOG1( "CreateViewPluginsL: implArray.Count():%d", implArray.Count() );
       
    50     CArrayPtr<CMailMessageView>* views =
       
    51         new(ELeave) CArrayPtrFlat<CMailMessageView>( Max( 1, implArray.Count() ) );
       
    52     CleanupStack::PushL( TCleanupItem( CleanupAdapterArray, views ) );
       
    53     // Create the adapters
       
    54     for( TInt i( 0 ); i < implArray.Count(); i++ )
       
    55         {
       
    56         CImplementationInformation& info = *implArray[i];
       
    57         TUid implementation( info.ImplementationUid() );
       
    58         
       
    59        	CMailMessageView* view = NULL;
       
    60        	//Create the plug-in view
       
    61 		view = CMailMessageView::NewL( implementation );
       
    62 		
       
    63         if( view )
       
    64             {
       
    65             CleanupStack::PushL( view );
       
    66             views->AppendL( view );
       
    67             LOG("CreateViewPluginsL: views->AppendL");
       
    68             CleanupStack::Pop( view );
       
    69             }
       
    70         }
       
    71 
       
    72     CleanupStack::Pop( views );
       
    73     CleanupStack::PopAndDestroy(); // implArray
       
    74 
       
    75     return views;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // MailViewFactory::CleanupImplArray
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void MailViewFactory::CleanupImplArray( TAny* aAny )
       
    83     {
       
    84     RImplInfoPtrArray* implArray =
       
    85         reinterpret_cast<RImplInfoPtrArray*>( aAny );
       
    86     implArray->ResetAndDestroy();
       
    87     implArray->Close();
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // MailViewFactory::CleanupAdapterArray
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void MailViewFactory::CleanupAdapterArray( TAny* aAny )
       
    95     {
       
    96     CArrayPtr<CMailMessageView>* views =
       
    97         reinterpret_cast<CArrayPtr<CMailMessageView>*>( aAny );
       
    98     views->ResetAndDestroy();
       
    99     delete views;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // MailViewFactory::Compare
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TInt MailViewFactory::Compare( const CImplementationInformation& aImpl1,
       
   107                                const CImplementationInformation& aImpl2 )
       
   108     {
       
   109     // Compare the numerical values of opaque_data
       
   110     TLex8 lex( aImpl1.OpaqueData() );
       
   111     TInt impl1( KMaxTInt );
       
   112     if( lex.Val( impl1 ) != KErrNone )
       
   113         {
       
   114         impl1 = KMaxTInt;
       
   115         }
       
   116 
       
   117     lex.Assign( aImpl2.OpaqueData() );
       
   118     TInt impl2( KMaxTInt );
       
   119     if( lex.Val( impl2 ) != KErrNone )
       
   120         {
       
   121         impl2 = KMaxTInt;
       
   122         }
       
   123 
       
   124     return impl1 - impl2;
       
   125     }
       
   126 
       
   127 //  End of File