omacp/omacpadapters/EmailAdapter/src/CWPEmailAdapter.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:  Class for handling provisioning message
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CWPEmailAdapter.h"
       
    22 #include "CWPEmailItem.h"
       
    23 #include "CWPEmailSaveSmtpImapItem.h"
       
    24 #include "CWPEmailSaveSmtpPopItem.h"
       
    25 #include "EmailAdapter.pan"  // Panic codes
       
    26 #include "WPEmail.hrh"
       
    27 #include <wpemailadapterresource.rsg>
       
    28 #include "Cwplog.h"
       
    29 
       
    30 #include <WPAdapterUtil.h> // Adapter utils
       
    31 #include <CWPAdapter.h>
       
    32 #include <CWPCharacteristic.h>
       
    33 #include <CWPParameter.h>
       
    34 
       
    35 #include <commdb.h>
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KFirstArrayIndex = 0;
       
    39 const TInt KArrayGranularity = 5;
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CWPEmailAdapter::CWPEmailAdapter
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CWPEmailAdapter::CWPEmailAdapter() : CWPAdapter()
       
    50 	{
       
    51 	}
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CWPEmailAdapter::ConstructL
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CWPEmailAdapter::ConstructL()
       
    59     {
       
    60     iSession = CMsvSession::OpenSyncL(*this);
       
    61     
       
    62     // Usually 1 or 2 settings.
       
    63     iEmailSettings = new(ELeave) CArrayPtrFlat<CWPEmailItem>(KArrayGranularity);
       
    64     
       
    65     iEmailSettingPair = 
       
    66                  new(ELeave) CArrayPtrFlat<CWPEmailSaveItem>(KArrayGranularity);
       
    67         
       
    68     TFileName fileName;
       
    69     Dll::FileName( fileName );
       
    70     iTitle = WPAdapterUtil::ReadHBufCL( fileName, 
       
    71                                         KAdapterName, 
       
    72                                         R_QTN_SM_TITLE_EMAIL_SETTINGS );
       
    73 	}
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CWPEmailAdapter::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CWPEmailAdapter* CWPEmailAdapter::NewL()
       
    81 	{
       
    82 	CWPEmailAdapter* self = new(ELeave) CWPEmailAdapter; 
       
    83 	CleanupStack::PushL(self);
       
    84 	self->ConstructL();
       
    85 	CleanupStack::Pop(self);
       
    86 	return self;
       
    87 	}
       
    88 	
       
    89 // -----------------------------------------------------------------------------
       
    90 // Destructor
       
    91 // -----------------------------------------------------------------------------
       
    92 CWPEmailAdapter::~CWPEmailAdapter()
       
    93 	{
       
    94     delete iSession;
       
    95     delete iCommsDb;
       
    96     delete iCurrentItem;
       
    97     delete iTitle;
       
    98 
       
    99     if ( iEmailSettings )
       
   100         {
       
   101         iEmailSettings->ResetAndDestroy();
       
   102         delete iEmailSettings;
       
   103         }
       
   104     if ( iEmailSettingPair )
       
   105         {
       
   106         iEmailSettingPair->ResetAndDestroy();
       
   107         delete iEmailSettingPair;
       
   108         }
       
   109 	}
       
   110 // -----------------------------------------------------------------------------
       
   111 // CWPEmailAdapter::AcceptedSettingGroup
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TBool CWPEmailAdapter::AcceptedSettingGroup()
       
   115     {
       
   116     return ( iCurrentItem->IsValid() );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CWPEmailAdapter::AddSmtpImapSettingsL
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CWPEmailAdapter::AddSmtpImapSettingsL(	CWPEmailItem* aSmtpItem, 
       
   124                                             CWPEmailItem* aImapItem )
       
   125     {
       
   126     CWPEmailSaveItem* settingPair = CSaveSmtpImapItem::NewLC( aSmtpItem, 
       
   127                                                               aImapItem );
       
   128     if ( settingPair->ValidateL() )
       
   129         {
       
   130         iEmailSettingPair->AppendL( settingPair );
       
   131         CleanupStack::Pop(); //settingPair
       
   132         }
       
   133     else
       
   134         {
       
   135         //not valid  so delete
       
   136         CleanupStack::PopAndDestroy(); //settingPair
       
   137         }
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CWPEmailAdapter::AddSmtpPopSettingsL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CWPEmailAdapter::AddSmtpPopSettingsL( CWPEmailItem* aSmtpItem, 
       
   145                                            CWPEmailItem* aPopItem )
       
   146     {
       
   147     CWPEmailSaveItem* settingPair = CSaveSmtpPopItem::NewLC( aSmtpItem, 
       
   148                                                              aPopItem );
       
   149     if ( settingPair->ValidateL() )
       
   150         {
       
   151         iEmailSettingPair->AppendL(settingPair);
       
   152         CleanupStack::Pop(); //settingPair
       
   153         }
       
   154     else
       
   155         {
       
   156         //not valid  so delete
       
   157         CleanupStack::PopAndDestroy(); //settingPair
       
   158         }
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CWPEmailAdapter::CreateSettingsL
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CWPEmailAdapter::CreateSettingsL( CWPEmailItem* aItem )
       
   166     {
       
   167     // All settings
       
   168     TInt count = iEmailSettings->Count();
       
   169     const TDesC& newItemID = aItem->ParameterValue( EWPParameterAppID );
       
   170 
       
   171     for (TInt i(KFirstArrayIndex); i < count; ++i)
       
   172         {        
       
   173         const TDesC& appId = iEmailSettings->At(i)->
       
   174             ParameterValue( EWPParameterAppID );
       
   175 
       
   176         // SMTP item
       
   177 		if ( newItemID == KEmailSettingPortSMTP)
       
   178 			{
       
   179             if ( appId == KEmailSettingPortIMAP )
       
   180 				{
       
   181 				AddSmtpImapSettingsL( aItem, iEmailSettings->At(i) );
       
   182 				}
       
   183 			if ( appId == KEmailSettingPortPOP )
       
   184 				{
       
   185 				AddSmtpPopSettingsL( aItem, iEmailSettings->At(i) );
       
   186 				}
       
   187 			}
       
   188 		// POP/IMAP item
       
   189 		else
       
   190 			{
       
   191 			if ( appId == KEmailSettingPortSMTP )
       
   192 				{
       
   193  				if ( newItemID == KEmailSettingPortIMAP )
       
   194 					{
       
   195 					AddSmtpImapSettingsL( iEmailSettings->At(i), aItem );
       
   196 					}
       
   197 				if ( newItemID == KEmailSettingPortPOP )
       
   198 					{
       
   199 					AddSmtpPopSettingsL( iEmailSettings->At(i), aItem );
       
   200 					}
       
   201 				}			
       
   202 			}
       
   203 		}
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CWPEmailAdapter::HandleSessionEventL
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CWPEmailAdapter::HandleSessionEventL( TMsvSessionEvent /*aEvent*/, 
       
   211                                            TAny* /*aArg1*/, 
       
   212                                            TAny* /*aArg2*/, 
       
   213                                            TAny* /*aArg3*/ )
       
   214     {
       
   215 	// From MMsvSessionObserver. Ignore session events
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CWPEmailAdapter::ItemCount
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TInt CWPEmailAdapter::ItemCount() const
       
   223     {
       
   224     return iEmailSettingPair->Count();
       
   225     }
       
   226 // -----------------------------------------------------------------------------
       
   227 // CWPEmailAdapter::SummaryTitle
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 const TDesC16& CWPEmailAdapter::SummaryTitle( TInt /*aIndex*/ ) const
       
   231 	{
       
   232     // title text is always same
       
   233 	return *iTitle;
       
   234 	}
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CWPEmailAdapter::SummaryText
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 const TDesC16& CWPEmailAdapter::SummaryText( TInt aIndex ) const
       
   241 	{
       
   242     if ( ItemCount() == 0 )
       
   243         {
       
   244         return KNullDesC;
       
   245         }
       
   246 	return iEmailSettingPair->At(aIndex)->SummaryText();
       
   247 	}
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CWPEmailAdapter::SaveL
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CWPEmailAdapter::SaveL( TInt aItem )
       
   254 	{
       
   255     __ASSERT_DEBUG(aItem < ItemCount() && 
       
   256         aItem >= KFirstArrayIndex, Panic( EMailAdapterArgument ));
       
   257 	
       
   258     // Create the commsdb when the save is initiated first time.
       
   259 	// This stays alive until the adapter is destroyed.
       
   260 	if ( !iCommsDb )
       
   261 		{
       
   262 		iCommsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   263 		}    
       
   264     User::LeaveIfNull(iCommsDb);
       
   265     iEmailSettingPair->At(aItem)->SetCommsDataBase( *iCommsDb );
       
   266     iEmailSettingPair->At(aItem)->SaveL( iSession );
       
   267 	}
       
   268 	
       
   269 // -----------------------------------------------------------------------------
       
   270 // CWPEmailAdapter::CanSetAsDefault
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 TBool CWPEmailAdapter::CanSetAsDefault( TInt aItem ) const
       
   274     {
       
   275     // always set first setting as default
       
   276     return (aItem == KFirstArrayIndex && ItemCount());
       
   277     }
       
   278     
       
   279 // -----------------------------------------------------------------------------
       
   280 // CWPEmailAdapter::SetAsDefaultL
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CWPEmailAdapter::SetAsDefaultL( TInt /*aItem*/ )
       
   284     {
       
   285     // set always first setting as default
       
   286     iEmailSettingPair->At(KFirstArrayIndex)->SetAsDefaultL();
       
   287     }
       
   288     
       
   289 // -----------------------------------------------------------------------------
       
   290 // CWPEmailAdapter::DetailsL
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 TInt CWPEmailAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/ )
       
   294     {
       
   295     return KErrNotSupported;
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CWPEmailAdapter::ContextExtension
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 TInt CWPEmailAdapter::ContextExtension( MWPContextExtension*& aExtension )
       
   303     {
       
   304     aExtension = this;
       
   305     return KErrNone;
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CWPEmailAdapter::VisitL
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CWPEmailAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   313 	{
       
   314 	TInt type = aCharacteristic.Type();    
       
   315 	// Are we dealing with application specific data.
       
   316     if ( type == KWPApplication ) 
       
   317 		{
       
   318         iCurrentItem = CWPEmailItem::NewL();
       
   319         aCharacteristic.AcceptL( *iCurrentItem );
       
   320         
       
   321         if( AcceptedSettingGroup() )
       
   322             {
       
   323 			CreateSettingsL( iCurrentItem );
       
   324             iEmailSettings->AppendL( iCurrentItem );
       
   325             }
       
   326         else
       
   327             {
       
   328             delete iCurrentItem;
       
   329             }
       
   330         iCurrentItem = NULL;
       
   331         }
       
   332 	}
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CWPEmailAdapter::VisitL
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CWPEmailAdapter::VisitL( CWPParameter& /*aParameter*/)
       
   339 	{
       
   340 	// parameters are handled in the CWPEmailItem.
       
   341 	}
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CWPEmailAdapter::VisitL
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CWPEmailAdapter::VisitLinkL( CWPCharacteristic& /*aParameter*/)
       
   348     {
       
   349     // visit link is handled in the CWPEmailItem.
       
   350     }
       
   351     
       
   352 // -----------------------------------------------------------------------------
       
   353 // CWPEmailAdapter::SaveDataL
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 const TDesC8& CWPEmailAdapter::SaveDataL( TInt aIndex ) const
       
   357     {
       
   358 	//	From MWPContextExtension
       
   359     return iEmailSettingPair->At(aIndex)->SaveData();
       
   360     }
       
   361     
       
   362 // -----------------------------------------------------------------------------
       
   363 // CWPEmailAdapter::DeleteL
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 void CWPEmailAdapter::DeleteL( const TDesC8& aSaveData )
       
   367     {
       
   368     //	From MWPContextExtension
       
   369     TPckgBuf<CWPEmailSaveItem::TSettingId> uids;
       
   370     uids.Copy( aSaveData );
       
   371 
       
   372     TInt32 smtpId = uids().iSmtpId;
       
   373     TInt32 popimapId = uids().iPopImapId;
       
   374     iSession->RemoveEntry( popimapId );
       
   375     // removing POP/IMAP entry removes also 
       
   376     // SMTP entry, but lets make sure it is deleted
       
   377     iSession->RemoveEntry(smtpId);
       
   378     
       
   379     LOG2("CWPEmailAdapter::DeleteL, popimapId: %d, smtpId: %d", popimapId, smtpId);
       
   380     }
       
   381     
       
   382 // -----------------------------------------------------------------------------
       
   383 // CWPEmailAdapter::Uid
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 TUint32 CWPEmailAdapter::Uid() const
       
   387     {
       
   388     return iDtor_ID_Key.iUid; 
       
   389     }
       
   390 
       
   391 //  End of File