email/pop3andsmtpmtm/clientmtms/src/IAPPrefs.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <iapprefs.h>
       
    17 #include <e32panic.h>
       
    18 
       
    19 
       
    20 EXPORT_C CImIAPPreferences* CImIAPPreferences::NewLC()
       
    21 /** Allocates and creates a new CImIAPPreferences object, leaving the object on 
       
    22 the cleanup stack.
       
    23 
       
    24 @return New CImIAPPreferences object */
       
    25 	{
       
    26 	CImIAPPreferences* self = new (ELeave) CImIAPPreferences();
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	return self;
       
    30 	}
       
    31 
       
    32 EXPORT_C TInt CImIAPPreferences::Version() const
       
    33 /** Gets the version number of the preferences structure.
       
    34 
       
    35 @return The version number of the preferences structure */
       
    36 	{
       
    37 	return iVersion;
       
    38 	}
       
    39 
       
    40 void CImIAPPreferences::Reset()
       
    41 	{
       
    42 	iChoices->Reset();	
       
    43 	}
       
    44 
       
    45 
       
    46 EXPORT_C TInt CImIAPPreferences::NumberOfIAPs() const
       
    47 /** Gets the number of IAPs that are assigned to the current service entry.
       
    48 
       
    49 @return Number of IAPs */
       
    50 	{
       
    51 	return iChoices->Count();
       
    52 	}
       
    53 
       
    54 EXPORT_C TImIAPChoice CImIAPPreferences::IAPPreference(TInt aPreference) const
       
    55 /** Gets the IAP choice of the given preference value.
       
    56 
       
    57 Note that preference values run from 0 to n, with 0 being the first choice. 
       
    58 Currently the number of IAPs per service is limited to two. 
       
    59 
       
    60 @param aPreference Preference value
       
    61 @return IAP choice for the given preference value */
       
    62 	{
       
    63 	return (*iChoices)[aPreference];
       
    64 	}
       
    65 
       
    66 EXPORT_C void CImIAPPreferences::AddIAPL(TImIAPChoice aIap, TInt aIndex)
       
    67 /** Adds the given IAP with the given preference value. 
       
    68 
       
    69 Any existing IAPs of equal or lower preference will have their preference 
       
    70 lowered further to make way for the new IAP. For example, if an IAP of preference 
       
    71 value 0 is already associated with the current service and another IAP of 
       
    72 preference 0 is added, then the existing IAP will be relegated to preference 
       
    73 value 1. Currently the number of IAPs per service is limited to two.
       
    74 
       
    75 @param aIap IAP
       
    76 @param aIndex Preference value for this IAP 
       
    77 @leave Leaves with KErrNotSupported if a SNAP is defined*/
       
    78 	{
       
    79 	if (iSnapId)
       
    80 		{
       
    81 		User::Leave(KErrNotSupported);
       
    82 		}
       
    83 	iChoices->InsertL(aIndex, aIap);
       
    84 	}
       
    85 
       
    86 EXPORT_C void CImIAPPreferences::RemoveIAPL(TInt aPreferenceNumber)
       
    87 /** Removes the IAP of the given preference.
       
    88 
       
    89 Any existing IAPs of lower preference will have their preference increased 
       
    90 to fill the gap created by the IAP that has been removed. For example, if 
       
    91 two IAPs are associated with the current service with the preference values 
       
    92 0 and 1. If the IAP of preference value 0 is later removed, then the other 
       
    93 IAP is promoted to preference value 0. It should be noted that adding or removing 
       
    94 an IAP from a CImIAPPreferences object does not change any global IAP settings, 
       
    95 it only changes the behaviour associated with a particular with a particular 
       
    96 email service. 
       
    97 
       
    98 @param aPreferenceNumber Preference value */
       
    99 	{
       
   100 	iChoices->Delete(aPreferenceNumber);
       
   101 	}
       
   102 
       
   103 EXPORT_C TInt CImIAPPreferences::FindIAPL(TUint32 aIAP, TInt &aLocation) const
       
   104 /** Finds the preference value for a specified IAP.
       
   105  
       
   106 @param aIAP The identifier of the IAP to find, as specified in the CommDb record for the IAP
       
   107 @param aLocation On return, if the specified IAP was found, its preference value
       
   108 @return KErrNone if the specified IAP was found; KErrNotFound if not.
       
   109 */
       
   110 	{
       
   111 	TInt count=iChoices->Count();
       
   112 	for(TInt i=0;i<count;i++)
       
   113 		{
       
   114 		if(aIAP==(*iChoices)[i].iIAP)
       
   115 			{
       
   116 			aLocation=i;
       
   117 			return(KErrNone);
       
   118 			}
       
   119 		}
       
   120 	return(KErrNotFound);
       
   121 	}
       
   122 
       
   123 EXPORT_C void CImIAPPreferences::ReplaceIAPL(TInt aPreferenceNumber,TImIAPChoice aIap)
       
   124 /** Replaces the current IAP at a specified preference value.
       
   125  
       
   126 A panic occurs if an IAP is not already set for the preference value. 
       
   127 @param aPreferenceNumber The preference value for which to set the IAP
       
   128 @param aIap The new IAP value for the preference value
       
   129 */	
       
   130 	{
       
   131 	(*iChoices)[aPreferenceNumber]=aIap;
       
   132 	}
       
   133 
       
   134 /**
       
   135 Used to check if SNAP settings are defined for this Email account.
       
   136 
       
   137 @param None
       
   138 
       
   139 @return A boolean is returned set as ETrue if a SNAP has been provisioned for the email account.
       
   140 */
       
   141 EXPORT_C TBool CImIAPPreferences::SNAPDefined() const
       
   142 	{
       
   143 	if (iSnapId)
       
   144 		{
       
   145 		return ETrue;
       
   146 		}
       
   147 	return EFalse;
       
   148 	}
       
   149 
       
   150 /**
       
   151 Returns the current SNAP Id for the email account.
       
   152 
       
   153 @param None
       
   154 
       
   155 @return The current SNAP id for the email account.
       
   156 */	
       
   157 EXPORT_C TUint32 CImIAPPreferences::SNAPPreference() const
       
   158 	{
       
   159 	return iSnapId;
       
   160 	}
       
   161 
       
   162 /**
       
   163 Sets the SNAP id for the email account, to the value specified in aSnap.
       
   164 
       
   165 @param aSnap
       
   166 Specifies the new SNAP id to be used by this email account.
       
   167 @leave Leaves with KErrNotSupported if IAP list already defined
       
   168 @return A boolean is returned set as ETrue if a SNAP has been provisioned for the email account.
       
   169 */
       
   170 EXPORT_C void CImIAPPreferences::SetSNAPL(TUint32 aSnap)
       
   171 	{
       
   172 	// Check that an IAP does not already exist
       
   173 	if (iChoices->Count())
       
   174 		{
       
   175 		User::Leave(KErrNotSupported);
       
   176 		}
       
   177 	iSnapId = aSnap;
       
   178 	}
       
   179 
       
   180 /**
       
   181 Removes the SNAP id for this Email account.
       
   182 
       
   183 @param None
       
   184 
       
   185 @return A boolean is returned set as ETrue if a SNAP has been provisioned for the email account.
       
   186 */	
       
   187 EXPORT_C void CImIAPPreferences::RemoveSNAP()
       
   188 	{
       
   189 	iSnapId = 0;
       
   190 	}
       
   191 
       
   192 EXPORT_C CImIAPPreferences::~CImIAPPreferences()
       
   193 /** Destructor. */
       
   194 	{
       
   195 	delete iChoices;
       
   196 	}
       
   197 
       
   198 CImIAPPreferences::CImIAPPreferences()
       
   199 	{
       
   200 	iVersion = KImIAPPreferencesVersion;
       
   201 	}
       
   202 
       
   203 void CImIAPPreferences::ConstructL()
       
   204 	{
       
   205 	iChoices = new(ELeave) CArrayFixFlat<TImIAPChoice>(5);
       
   206 	}
       
   207 
       
   208 void CImIAPPreferences::Panic(int err) const
       
   209 	{
       
   210 	User::Panic(_L("IAPPrefs"), err);
       
   211 	}