email/mail/ViewerSrc/CMailViewManager.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Plug-in view manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include 	"MailLog.h"
       
    22 #include    "CMailViewManager.h"
       
    23 #include    "CMailViewFactory.h"
       
    24 #include 	"CMailBaseControlAdapter.h"
       
    25 #include    "CMailMsgBaseControlAdapter.h"
       
    26 #include    "MMailMsgBaseControl.h"
       
    27 
       
    28 #include 	<MsgBaseControl.h>
       
    29 #include 	<MsgEditorView.h>
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMailViewManager::CMailViewManager
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CMailViewManager::CMailViewManager()
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CMailViewManager::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CMailViewManager::ConstructL()
       
    49     {
       
    50     iMailViewArray = MailViewFactory::CreateViewPluginsL();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMailViewManager::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CMailViewManager* CMailViewManager::NewL()
       
    59     {
       
    60     CMailViewManager* self = new( ELeave ) CMailViewManager;
       
    61     
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop();
       
    65 
       
    66     return self;
       
    67     }
       
    68 
       
    69     
       
    70 // Destructor
       
    71 CMailViewManager::~CMailViewManager()
       
    72     {
       
    73     if (iMailViewArray)
       
    74         {
       
    75         iMailViewArray->ResetAndDestroy();	
       
    76         delete iMailViewArray;
       
    77         }
       
    78     delete iAdapter;
       
    79     REComSession::FinalClose();
       
    80     }
       
    81 
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CMailViewManager::MessageLoadL
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CMailViewManager::MessageLoadL( TInt aStatus, CMailMessage& aMessage )
       
    88     {
       
    89     for (TInt i=0; i<iMailViewArray->Count(); i++)
       
    90         {
       
    91         CMailMessageView* view = iMailViewArray->At(i);
       
    92         
       
    93         if(view)
       
    94         	{
       
    95         	LOG2("CMailViewManager::MessageLoadL @ aStatus: %d, i:%d", 
       
    96         		aStatus, i);
       
    97         	TRAPD(error, view->MessageLoadL(aStatus, aMessage));
       
    98 
       
    99        		if (error != KErrNone)
       
   100        			{
       
   101        			// remove problem plugin
       
   102        			delete view;
       
   103        			iMailViewArray->Delete(i);
       
   104        			iMailViewArray->Compress();
       
   105        			}
       
   106         	}
       
   107         }   
       
   108     }
       
   109     
       
   110 // -----------------------------------------------------------------------------
       
   111 // CMailViewManager::AddBodyControlL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CMailViewManager::AddBodyControlL( 
       
   115 	CMsgEditorView* aParent, CCoeControl& aControl )
       
   116     {    
       
   117     CMsgBaseControl* adapter = CMailBaseControlAdapter::NewL(aParent, aControl);
       
   118     CleanupStack::PushL(adapter);
       
   119         
       
   120     AddBodyControlL(aParent, *adapter);    
       
   121         
       
   122     CleanupStack::Pop(); // adapter
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CMailViewManager::AddBodyControlL
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CMailViewManager::AddBodyControlL( 
       
   130 	CMsgEditorView* aParent, MMailMsgBaseControl& aControl )
       
   131     {
       
   132     CMsgBaseControl* adapter = 
       
   133         CMailMsgBaseControlAdapter::NewL(aParent, aControl);             
       
   134     CleanupStack::PushL(adapter);
       
   135         
       
   136     AddBodyControlL(aParent, *adapter);     
       
   137     CleanupStack::Pop(); // adapter
       
   138     }
       
   139   
       
   140 // -----------------------------------------------------------------------------
       
   141 // CMailViewManager::ViewPlugin
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CMailMessageView* CMailViewManager::ViewPlugin()
       
   145     {
       
   146      // Use first view plugin
       
   147  	return PluginCount() ? iMailViewArray->At(0) : NULL;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CMailViewManager::PluginCount
       
   152 // -----------------------------------------------------------------------------
       
   153 //    
       
   154 TInt CMailViewManager::PluginCount()
       
   155 	{
       
   156 	return iMailViewArray->Count();
       
   157 	}
       
   158 	
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMailViewManager::RemovePlugin
       
   161 // -----------------------------------------------------------------------------
       
   162 //    
       
   163 void CMailViewManager::RemovePlugin()
       
   164 	{
       
   165 	// remove first plugin
       
   166 	if (PluginCount())
       
   167 		{
       
   168 		delete iMailViewArray->At(0);
       
   169 		iMailViewArray->Delete(0);
       
   170 		iMailViewArray->Compress();	
       
   171 		}
       
   172 	
       
   173 	}  
       
   174 	
       
   175 // -----------------------------------------------------------------------------
       
   176 // CMailViewManager::AddBodyControlL
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 void CMailViewManager::AddBodyControlL( 
       
   180 	CMsgEditorView* aParent, CMsgBaseControl& aControl )
       
   181     {           
       
   182     // replace defaul base body control
       
   183     CMsgBaseControl* bodycontrol = aParent->RemoveControlL(EMsgComponentIdBody);
       
   184     delete bodycontrol;
       
   185     bodycontrol = NULL;
       
   186     
       
   187     aParent->AddControlL(
       
   188         &aControl,
       
   189         EMsgComponentIdBody,
       
   190         EMsgAppendControl, 
       
   191         EMsgBody);
       
   192     }  	
       
   193 //  End of File