omacp/omacpadapters/EmailAdapter/src/CWPEmailItem.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     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:  Email settin data object
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CWPEmailItem.h"
       
    22 #include "CWPCharacteristic.h"
       
    23 #include "CWPParameter.h"
       
    24 #include "EmailAdapter.pan"
       
    25 #include "WPEmail.hrh"
       
    26 #include "Cwplog.h"
       
    27 #include    "../../../group/omacplogger.h"
       
    28 
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KArrayGranularity = 10;
       
    32 
       
    33 
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CWPEmailItem::NewL
       
    39 // Two-phased constructor.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CWPEmailItem* CWPEmailItem::NewL()
       
    43 	{
       
    44 	CWPEmailItem* self = CWPEmailItem::NewLC(); 
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 CWPEmailItem* CWPEmailItem::NewLC()
       
    50 	{
       
    51 	CWPEmailItem* self = new(ELeave) CWPEmailItem; 
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // Destructor
       
    58 CWPEmailItem::~CWPEmailItem()
       
    59 	{
       
    60 	delete iEmailSettingParams;
       
    61 	}
       
    62 // Constructor
       
    63 CWPEmailItem::CWPEmailItem()
       
    64 	{
       
    65 	}
       
    66 // -----------------------------------------------------------------------------
       
    67 // CWPEmailItem::ConstructL
       
    68 // Symbian 2nd phase constructor can leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CWPEmailItem::ConstructL()
       
    72 	{
       
    73 	// average setting contains 10 items
       
    74 	iEmailSettingParams = new(ELeave) CArrayPtrFlat<CWPParameter>(
       
    75         KArrayGranularity);
       
    76 	}
       
    77 
       
    78 
       
    79 const TDesC& CWPEmailItem::ParameterValue(TInt aParamID) const
       
    80     {
       
    81 	TInt count = iEmailSettingParams->Count();
       
    82 	for (TInt i=0; i < count; ++i)
       
    83 		{
       
    84 		if ( iEmailSettingParams->At(i)->ID() == aParamID )
       
    85 			{
       
    86 			return iEmailSettingParams->At(i)->Value();
       
    87 			}
       
    88 		}
       
    89     return KNullDesC;
       
    90     }
       
    91 
       
    92 
       
    93 HBufC* CWPEmailItem::AssociatedIapNameL()
       
    94     {    
       
    95     HBufC* string = NULL;
       
    96     
       
    97     if ( iNapDef )
       
    98         {
       
    99         // We have only 1 IAP
       
   100         CArrayFix<TPtrC>* name = new(ELeave) CArrayFixFlat<TPtrC>(1);
       
   101         CleanupStack::PushL(name);
       
   102         
       
   103         // iap name
       
   104         iNapDef->ParameterL(EWPParameterName, name);
       
   105         
       
   106         if (name->Count() > 0)
       
   107             {
       
   108             // IAP name is found from index 0
       
   109             string = name->At(0).AllocL();
       
   110             }
       
   111         
       
   112         CleanupStack::PopAndDestroy(); // name
       
   113         }
       
   114        
       
   115 	return string;
       
   116     }
       
   117 
       
   118 TUint32 CWPEmailItem::AssociatedIapId()
       
   119     {
       
   120     TPckgBuf<TUint32> pckg;
       
   121     pckg() = 0;
       
   122 
       
   123     if ( iNapDef )
       
   124         {
       
   125         const TDesC8& data = iNapDef->Data();
       
   126         pckg.Copy( data );	
       
   127         }
       
   128 	
       
   129     return pckg();
       
   130     }
       
   131 
       
   132 TBool CWPEmailItem::IsValid() const
       
   133     {
       
   134     // Check AppID and IAP
       
   135     // if IAP not defined, then  system tries to use default IAP from CommsDB.
       
   136     const TDesC& appID = ParameterValue(EWPParameterAppID);
       
   137     if ( appID == KEmailSettingPortSMTP ||
       
   138         appID == KEmailSettingPortPOP ||
       
   139         appID == KEmailSettingPortIMAP )
       
   140         {
       
   141         LOG("CWPEmailItem::IsValid");
       
   142         return ETrue;
       
   143         }
       
   144     LOG("CWPEmailItem::IsNotValid");
       
   145     return EFalse;
       
   146     }
       
   147 
       
   148 void CWPEmailItem::VisitL(CWPCharacteristic& aCharacteristic)
       
   149 	{
       
   150 	switch ( aCharacteristic.Type() )
       
   151 		{	
       
   152 		case KWPAppAddr:
       
   153 			// FALLTROUGH
       
   154 		case KWPAppAuth:
       
   155             // FALLTROUGH
       
   156 		case KWPPort:
       
   157 			aCharacteristic.AcceptL( *this );
       
   158             LOG1("CWPEmailItem::AcceptL: CWPCharacteristic Type: %d", 
       
   159                 aCharacteristic.Type());
       
   160 			break;
       
   161 	
       
   162 		default:
       
   163             LOG1("CWPEmailItem::Ignore: CWPCharacteristic Type: %d", 
       
   164                 aCharacteristic.Type());
       
   165 			// do nothing
       
   166 			break;
       
   167 		}
       
   168 	
       
   169 	}
       
   170 
       
   171 
       
   172 void CWPEmailItem::VisitL(CWPParameter& aParameter)
       
   173 	{
       
   174 	switch( aParameter.ID() )
       
   175 		{
       
   176         // read these parameters
       
   177         case EWPParameterAppID:
       
   178         case EWPParameterName:
       
   179         case EWPParameterProviderID:            
       
   180 		case EWPParameterAddr:
       
   181 		case EWPParameterPortNbr:
       
   182 		case EWPParameterService:
       
   183 		case EWPParameterAAuthType:
       
   184 		case EWPParameterAAuthName:
       
   185 		case EWPParameterAAuthSecret:
       
   186         case EWPParameterFrom:
       
   187 			iEmailSettingParams->AppendL(&aParameter);
       
   188             LOG2("CWPEmailItem::AppendL: CWPParameter id: %d value: %S", 
       
   189                 aParameter.ID(), &aParameter.Value());
       
   190 			break;
       
   191 			
       
   192         case EWPNamedParameter:
       
   193             {
       
   194             TPtrC namedParam(aParameter.Name());
       
   195             LOGSTRING2( "[Provisioning] CWPEmailItem::VisitL: Parameter Name, %i", namedParam);
       
   196             
       
   197             if (namedParam.CompareF(KParamEMN) == 0 || namedParam.CompareF(
       
   198                     KParamCS) == 0 || namedParam.CompareF(KParamLMS) == 0
       
   199                     || namedParam.CompareF(KParamPOLL) == 0
       
   200                     || namedParam.CompareF(KParamONLINE) == 0)
       
   201                 {
       
   202                 iEmailSettingParams->AppendL(&aParameter);
       
   203 				LOG2("CWPEmailItem::VisitL: Named Parameter %S: value: %S", &aParameter.Name(),
       
   204                         &aParameter.Value());
       
   205                 }
       
   206             break;
       
   207             }
       
   208 		 
       
   209 		default:
       
   210             LOG2("CWPEmailItem::Ignore: CWPParameter id: %d value: %S",
       
   211                 aParameter.ID(), &aParameter.Value());
       
   212 			// Do nothing
       
   213 			break;
       
   214 		}
       
   215 
       
   216 	}
       
   217 
       
   218 void CWPEmailItem::VisitLinkL(CWPCharacteristic& aCharacteristic )
       
   219     {
       
   220     if ( aCharacteristic.Type() ==  KWPNapDef )
       
   221         {
       
   222         // Link to the IAP settings 
       
   223         iNapDef = &aCharacteristic;
       
   224         LOG("iNapDef is set");
       
   225         }
       
   226 	}
       
   227 
       
   228 const TDesC& CWPEmailItem::ParameterValue(const TDesC& aParamName)
       
   229     {
       
   230     TInt count = iEmailSettingParams->Count();
       
   231     for (TInt i=0; i < count; ++i)
       
   232         {
       
   233         if ( iEmailSettingParams->At(i)->Name().CompareF(aParamName) == 0 )
       
   234             {
       
   235             return iEmailSettingParams->At(i)->Value();
       
   236             }
       
   237         }
       
   238     return KNullDesC;
       
   239     }
       
   240 
       
   241 //  End of File