email/imum/Utils/Src/IMSSettingsItemApprover.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2006 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:  IMSSettingsItemApprover.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <msvstd.hrh>                   // KUidMsvServiceEntryValue
       
    23 #include <MuiuMsvUiServiceUtilities.h>  // MsvUiServiceUtilities
       
    24 #include <StringLoader.h>               // StringLoader
       
    25 #include <ImumUtils.rsg>
       
    26 #include "MuiuDynamicSettingItemBase.h"      // CMuiuSettingBase
       
    27 #include "MuiuDynamicSettingItemEditValue.h" // CMuiuSettingEditValue
       
    28 #include "MuiuDynamicSettingItemEditText.h"  // CMuiuSettingEditText
       
    29 #include "MuiuDynamicSettingItemLink.h"      // CMuiuSettingLink
       
    30 #include "MuiuDynamicSettingItemExtLink.h"   // CMuiuSettingExtLink
       
    31 
       
    32 #include "IMSSettingsItemApprover.h"
       
    33 #include "ImumInMailboxUtilitiesImpl.h"
       
    34 #include "ImumInternalApi.h"
       
    35 #include "ImumInSettingsData.h"
       
    36 #include "IMSSettingsDialog.h"
       
    37 #include "EmailUtils.H"
       
    38 #include "IMASPageIds.hrh"
       
    39 #include "EmailFeatureUtils.h"
       
    40 #include "Imas.hrh"
       
    41 #include "ImumUtilsLogging.h"
       
    42 #include "ImumPanic.h"
       
    43 
       
    44 
       
    45 // EXTERNAL DATA STRUCTURES
       
    46 // EXTERNAL FUNCTION PROTOTYPES
       
    47 // CONSTANTS
       
    48 // MACROS
       
    49 // LOCAL CONSTANTS AND MACROS
       
    50 // MODULE DATA STRUCTURES
       
    51 // LOCAL FUNCTION PROTOTYPES
       
    52 // FORWARD DECLARATIONS
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // CIMSSettingsItemApprover::CIMSSettingsItemApprover()
       
    58 // ----------------------------------------------------------------------------
       
    59 CIMSSettingsItemApprover::CIMSSettingsItemApprover(
       
    60     CImumInternalApi& aMailboxApi,
       
    61     CMsvCommDbUtilities& aCommsDb,
       
    62     CIMSSettingsNoteUi& aNoteUi,
       
    63     CIMSSettingsBaseUI& aDialog )
       
    64     :
       
    65     iMailboxApi( aMailboxApi ),
       
    66     iCommsDbUtils( aCommsDb ),
       
    67     iNoteUi( aNoteUi ),
       
    68     iDialog( aDialog ),
       
    69     iTempText( NULL )
       
    70     {
       
    71     IMUM_CONTEXT( CIMSSettingsItemApprover::CIMSSettingsItemApprover, 0, KLogUi );
       
    72 
       
    73     }
       
    74 
       
    75 // ----------------------------------------------------------------------------
       
    76 // CIMSSettingsItemApprover::ConstructL()
       
    77 // ----------------------------------------------------------------------------
       
    78 //
       
    79 void CIMSSettingsItemApprover::ConstructL()
       
    80     {
       
    81     IMUM_CONTEXT( CIMSSettingsItemApprover::ConstructL, 0, KLogUi );
       
    82 
       
    83     iTempText = new ( ELeave ) TMuiuSettingsText();
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // CIMSSettingsItemApprover::~CIMSSettingsItemApprover()
       
    88 // ----------------------------------------------------------------------------
       
    89 //
       
    90 CIMSSettingsItemApprover::~CIMSSettingsItemApprover()
       
    91     {
       
    92     IMUM_CONTEXT( CIMSSettingsItemApprover::~CIMSSettingsItemApprover, 0, KLogUi );
       
    93 
       
    94     delete iTempText;
       
    95     iTempText = NULL;
       
    96     }
       
    97 
       
    98 // ----------------------------------------------------------------------------
       
    99 // CIMSSettingsItemApprover::NewL()
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 CIMSSettingsItemApprover* CIMSSettingsItemApprover::NewL(
       
   103     CImumInternalApi& aMailboxApi,
       
   104     CMsvCommDbUtilities& aCommsDb,
       
   105     CIMSSettingsNoteUi& aNoteUi,
       
   106     CIMSSettingsBaseUI& aDialog )
       
   107     {
       
   108     IMUM_STATIC_CONTEXT( CIMSSettingsItemApprover::NewL, 0, utils, KLogUi );
       
   109 
       
   110     CIMSSettingsItemApprover* self = NewLC(
       
   111         aMailboxApi, aCommsDb, aNoteUi, aDialog );
       
   112     CleanupStack::Pop( self );
       
   113 
       
   114     return self;
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // CIMSSettingsItemApprover::NewLC()
       
   119 // ----------------------------------------------------------------------------
       
   120 //
       
   121 CIMSSettingsItemApprover* CIMSSettingsItemApprover::NewLC(
       
   122     CImumInternalApi& aMailboxApi,
       
   123     CMsvCommDbUtilities& aCommsDb,
       
   124     CIMSSettingsNoteUi& aNoteUi,
       
   125     CIMSSettingsBaseUI& aDialog )
       
   126     {
       
   127     IMUM_STATIC_CONTEXT( CIMSSettingsItemApprover::NewLC, 0, utils, KLogUi );
       
   128 
       
   129     CIMSSettingsItemApprover* self =
       
   130         new ( ELeave ) CIMSSettingsItemApprover(
       
   131             aMailboxApi, aCommsDb, aNoteUi, aDialog );
       
   132     CleanupStack::PushL( self );
       
   133     self->ConstructL();
       
   134 
       
   135     return self;
       
   136     }
       
   137 
       
   138 /******************************************************************************
       
   139 
       
   140     Common item validating
       
   141 
       
   142 ******************************************************************************/
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CIMSSettingsItemApprover::ValidateType()
       
   146 // ----------------------------------------------------------------------------
       
   147 //
       
   148 TIMSErrors CIMSSettingsItemApprover::ValidateType(
       
   149     const CMuiuSettingBase& aBaseItem,
       
   150     TDes& aNewText,
       
   151     TInt& aNewValue )
       
   152     {
       
   153     IMUM_CONTEXT( CIMSSettingsItemApprover::ValidateType, 0, KLogUi );
       
   154     IMUM_IN();
       
   155 
       
   156     // Handle the item, based on the type
       
   157     switch ( aBaseItem.Type() )
       
   158         {
       
   159         // Text editor
       
   160         case EMuiuDynSetItemEditText:
       
   161         	IMUM_OUT();
       
   162             return ValidateText( aBaseItem, aNewText );
       
   163 
       
   164         // Number editor
       
   165         case EMuiuDynSetCheckBoxArray:
       
   166         case EMuiuDynSetItemEditValue:
       
   167         	IMUM_OUT();
       
   168             return ValidateValue( aBaseItem, aNewValue );
       
   169 
       
   170         case EMuiuDynSetRadioButtonArray:
       
   171         	IMUM_OUT();
       
   172             return ValidateRadioButtons( aNewValue );
       
   173 
       
   174         // Type is not recognized or not supported
       
   175         default:
       
   176             break;
       
   177         }
       
   178 
       
   179     IMUM_OUT();
       
   180     return EIMSNoError;
       
   181     }
       
   182 
       
   183 /******************************************************************************
       
   184 
       
   185     Special item validating
       
   186 
       
   187 ******************************************************************************/
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // CIMSSettingsItemApprover::EvaluateAccountName()
       
   191 // ----------------------------------------------------------------------------
       
   192 //
       
   193 TIMSErrors CIMSSettingsItemApprover::EvaluateAccountName(
       
   194     const CMuiuSettingBase& aBaseItem,
       
   195     TDes& aNewText )
       
   196     {
       
   197     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateAccountName, 0, KLogUi );
       
   198 
       
   199     // First make basic test
       
   200     TIMSErrors result = ValidateText( aBaseItem, aNewText );
       
   201 
       
   202     // Setting has been written, try to check
       
   203     if ( result == EIMSNoError )
       
   204         {
       
   205         // Do not allow leaving, as it might interrupt initialization phase
       
   206         TRAPD( error,
       
   207             MsvEmailMtmUiUtils::CheckAccountNameL(
       
   208                 iMailboxApi,
       
   209                 aNewText,
       
   210                 iDialog.CurrentMailboxId(),
       
   211                 aBaseItem.iItemFlags.Flag( EIMSApproverGenerate ) ) );
       
   212         result = ( error == KErrNone ) ? EIMSNoError : EIMSMailboxNameExists;
       
   213         }
       
   214     else
       
   215         {
       
   216         result = EIMSMailboxNameEmpty;
       
   217         }
       
   218 
       
   219     return result;
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CIMSSettingsItemApprover::EvaluateServerAddress()
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 TIMSErrors CIMSSettingsItemApprover::EvaluateServerAddress(
       
   227     const CMuiuSettingBase& aBaseItem,
       
   228     const TDesC& aNewText )
       
   229     {
       
   230     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateServerAddress, 0, KLogUi );
       
   231 
       
   232     TIMSErrors result = ValidateText( aBaseItem, aNewText );
       
   233 
       
   234     // Check that dot isn't in start of the server address
       
   235     if ( result == EIMSNoError )
       
   236         {
       
   237         TBool ok = EFalse;
       
   238         TRAPD( error, ok = MsvUiServiceUtilities::IsValidDomainL( aNewText ) );
       
   239 
       
   240         result = ( error == KErrNone ) && ok ? EIMSNoError : EIMSItemInvalid;
       
   241         }
       
   242 
       
   243     return result;
       
   244     }
       
   245 
       
   246 // ----------------------------------------------------------------------------
       
   247 // CIMSSettingsItemApprover::EvaluateEmailAddress()
       
   248 // ----------------------------------------------------------------------------
       
   249 //
       
   250 TIMSErrors CIMSSettingsItemApprover::EvaluateEmailAddress(
       
   251     const CMuiuSettingBase& aBaseItem,
       
   252     const TDesC& aNewText )
       
   253     {
       
   254     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateEmailAddress, 0, KLogUi );
       
   255 
       
   256     // First make basic test
       
   257     TIMSErrors result = ValidateText( aBaseItem, aNewText );
       
   258 
       
   259     // If text check was successful and the address is given, validate the
       
   260     // email address
       
   261     if ( result == EIMSNoError && aNewText.Length() )
       
   262         {
       
   263         // Trap any errors to prevent leaving
       
   264         TBool ok = EFalse;
       
   265         TRAPD( error, ok =
       
   266             MsvUiServiceUtilities::IsValidEmailAddressL( aNewText ) );
       
   267 
       
   268         result = ( ok && error == KErrNone ) ? EIMSNoError : EIMSItemInvalid;
       
   269         }
       
   270 
       
   271     return result;
       
   272     }
       
   273 
       
   274 /******************************************************************************
       
   275 
       
   276     Brand new validating code
       
   277 
       
   278 ******************************************************************************/
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CIMSSettingsItemApprover::EvaluateSettingItems()
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 TIMSErrors CIMSSettingsItemApprover::EvaluateSettingItems(
       
   285     TIMSApproverEvent& aEvent,
       
   286     const CMuiuSettingBase& aBaseItem,
       
   287     TDes& aNewText,
       
   288     TInt& aNewValue )
       
   289     {
       
   290     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateSettingItems, 0, KLogUi );
       
   291 
       
   292     // Incoming settings
       
   293     switch ( aBaseItem.iItemId.iUid )
       
   294         {
       
   295         // No validating
       
   296         case EIMASUserFolderSubscription:
       
   297         	break;
       
   298 
       
   299         // Special validating
       
   300         case EIMASUserUnixPath:
       
   301         case EIMASUserOwnName:
       
   302         	return EvaluateFreeText( aNewText );
       
   303 
       
   304         case EIMASIncomingMailboxName:
       
   305             return EvaluateAccountName( aBaseItem, aNewText );
       
   306 
       
   307         case EIMASIncomingMailServer:
       
   308         case EIMASOutgoingMailServer:
       
   309             return EvaluateServerAddress( aBaseItem, aNewText );
       
   310 
       
   311         case EIMASOutgoingEmailAddress:
       
   312         case EIMASUserReplyTo:
       
   313             return EvaluateEmailAddress( aBaseItem, aNewText );
       
   314 
       
   315         // When clearing the username and password, it must be checked
       
   316         // that the always online and mail message notification is off.
       
   317         // Otherwise user must be reminded of always online or mail message
       
   318         // notification requiring username and password in connection.
       
   319         case EIMASIncomingUserPwd:
       
   320         case EIMASIncomingUserName:
       
   321             return EvaluateUsernameOrPassword( aEvent, aNewText );
       
   322 
       
   323         // If the OMA EMN is attempted to turn on, check that
       
   324         // current state of settings allows it
       
   325         case EIMASMailNotifications:
       
   326             return CheckItemOnlineSettingsCheckTurnOn(
       
   327                 aEvent, aNewValue, ETrue );
       
   328 
       
   329         // If the Always Online is attempted to turn on, check that
       
   330         // current state of settings allows it
       
   331         case EIMASAORolling:
       
   332             return CheckItemOnlineSettingsCheckTurnOn(
       
   333                 aEvent, aNewValue, EFalse );
       
   334 
       
   335         case EIMASAODays:
       
   336             break;
       
   337 
       
   338         case EIMASAOHours:
       
   339             break;
       
   340 
       
   341         default:
       
   342             break;
       
   343         }
       
   344 
       
   345     return ValidateType( aBaseItem, aNewText, aNewValue );
       
   346     }
       
   347 
       
   348 // ----------------------------------------------------------------------------
       
   349 // CIMSSettingsItemApprover::EvaluateWizardItems()
       
   350 // ----------------------------------------------------------------------------
       
   351 //
       
   352 TIMSErrors CIMSSettingsItemApprover::EvaluateWizardItems(
       
   353     TIMSApproverEvent& /* aEvent */,
       
   354     const CMuiuSettingBase& aBaseItem,
       
   355     TDes& aNewText,
       
   356     TInt& aNewValue )
       
   357     {
       
   358     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateWizardItems, 0, KLogUi );
       
   359 
       
   360     switch ( aBaseItem.iItemId.iUid )
       
   361         {
       
   362         case EIMAWEmailAddress:
       
   363             return EvaluateEmailAddress( aBaseItem, aNewText );
       
   364 
       
   365         case EIMAWSendingServer:
       
   366         case EIMAWReceivingServer:
       
   367             return EvaluateServerAddress( aBaseItem, aNewText );
       
   368 
       
   369         case EIMAWMailboxName:
       
   370             return EvaluateAccountName( aBaseItem, aNewText );
       
   371 
       
   372         case EIMAWProtocol:
       
   373         case EIMAWIap:
       
   374         default:
       
   375             break;
       
   376         }
       
   377 
       
   378     return ValidateType( aBaseItem, aNewText, aNewValue );
       
   379     }
       
   380 
       
   381 // ----------------------------------------------------------------------------
       
   382 // CIMSSettingsItemApprover::EvaluateItem()
       
   383 // ----------------------------------------------------------------------------
       
   384 //
       
   385 TMuiuPageEventResult CIMSSettingsItemApprover::EvaluateItem(
       
   386     TIMSApproverEvent& aEvent,
       
   387     const CMuiuSettingBase& aBaseItem,
       
   388     TDes& aNewText,
       
   389     TInt& aNewValue )
       
   390     {
       
   391     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateItem, 0, KLogUi );
       
   392 
       
   393     TIMSErrors error = EIMSNoError;
       
   394 
       
   395     if ( iDialog.Flag( EImumSettingsWizard ) )
       
   396         {
       
   397         error = EvaluateWizardItems( aEvent, aBaseItem, aNewText, aNewValue );
       
   398         }
       
   399     else
       
   400         {
       
   401         error = EvaluateSettingItems( aEvent, aBaseItem, aNewText, aNewValue );
       
   402         }
       
   403 
       
   404     return iNoteUi.ShowDialog( aBaseItem, error, aNewText );
       
   405     }
       
   406 
       
   407 // ----------------------------------------------------------------------------
       
   408 // CIMSSettingsItemApprover::EvaluateText()
       
   409 // ----------------------------------------------------------------------------
       
   410 //
       
   411 TMuiuPageEventResult CIMSSettingsItemApprover::EvaluateText(
       
   412     TIMSApproverEvent& aEvent,
       
   413     const CMuiuSettingBase& aBaseItem,
       
   414     TDes& aNewText )
       
   415     {
       
   416     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateText, 0, KLogUi );
       
   417 
       
   418     aEvent = EIMSApproverNoEvent;
       
   419     TInt nothing = 0;
       
   420     return EvaluateItem( aEvent, aBaseItem, aNewText, nothing );
       
   421     }
       
   422 
       
   423  // ----------------------------------------------------------------------------
       
   424 // CIMSSettingsItemApprover::EvaluateValue()
       
   425 // ----------------------------------------------------------------------------
       
   426 //
       
   427 TMuiuPageEventResult CIMSSettingsItemApprover::EvaluateValue(
       
   428     TIMSApproverEvent& aEvent,
       
   429     const CMuiuSettingBase& aBaseItem,
       
   430     TInt& aNewValue )
       
   431     {
       
   432     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateValue, 0, KLogUi );
       
   433 
       
   434     aEvent = EIMSApproverNoEvent;
       
   435     TMuiuSettingsText nothing;
       
   436     return EvaluateItem( aEvent, aBaseItem, nothing, aNewValue );
       
   437     }
       
   438 
       
   439 /******************************************************************************
       
   440 
       
   441     Common code
       
   442 
       
   443 ******************************************************************************/
       
   444 
       
   445 // ----------------------------------------------------------------------------
       
   446 // CIMSSettingsItemApprover::IsItemFilled()
       
   447 // ----------------------------------------------------------------------------
       
   448 //
       
   449 TBool CIMSSettingsItemApprover::IsItemFilled(
       
   450     const CMuiuSettingBase& aBaseItem,
       
   451     const TInt aLength )
       
   452     {
       
   453     IMUM_CONTEXT( CIMSSettingsItemApprover::IsItemFilled, 0, KLogUi );
       
   454 
       
   455     // At first, check if the item can be left empty
       
   456     TBool ok =
       
   457         !( aBaseItem.iItemFlags.Flag( EMuiuDynItemMustFill ) ||
       
   458            aBaseItem.iItemFlags.Flag( EMuiuDynItemForceMustFill ) );
       
   459 
       
   460     // The text field is considered filled, when:
       
   461     // A: Item has NO must fill -flags on
       
   462     // B: Item has must fill -flags on and length is higher than 0
       
   463     return ok || ( !ok && aLength > 0 );
       
   464     }
       
   465 
       
   466 // ----------------------------------------------------------------------------
       
   467 // CIMSSettingsItemApprover::ValidateRadioButton()
       
   468 // ----------------------------------------------------------------------------
       
   469 //
       
   470 TIMSErrors CIMSSettingsItemApprover::ValidateRadioButtons(
       
   471     const TInt aNewValue )
       
   472     {
       
   473     IMUM_CONTEXT( CIMSSettingsItemApprover::ValidateRadioButtons, 0, KLogUi );
       
   474     IMUM_IN();
       
   475     IMUM_OUT();
       
   476 
       
   477     // Make sure item is checked
       
   478     return ( aNewValue != KErrNotFound ) ? EIMSNoError : EIMSItemEmpty;
       
   479     }
       
   480 
       
   481 // ----------------------------------------------------------------------------
       
   482 // CIMSSettingsItemApprover::ValidateValue()
       
   483 // ----------------------------------------------------------------------------
       
   484 //
       
   485 TIMSErrors CIMSSettingsItemApprover::ValidateValue(
       
   486     const CMuiuSettingBase& aBaseItem,
       
   487     TInt& aNewValue )
       
   488     {
       
   489     IMUM_CONTEXT( CIMSSettingsItemApprover::ValidateValue, 0, KLogUi );
       
   490     IMUM_IN();
       
   491     IMUM_OUT();
       
   492 
       
   493     // This check makes sure, that the provided value is larger than 0
       
   494     return IsItemFilled( aBaseItem, aNewValue ) ?
       
   495         EIMSNoError : EIMSItemInvalid;
       
   496     }
       
   497 
       
   498 // ----------------------------------------------------------------------------
       
   499 // CIMSSettingsItemApprover::ValidateTextL()
       
   500 // ----------------------------------------------------------------------------
       
   501 //
       
   502 TIMSErrors CIMSSettingsItemApprover::ValidateText(
       
   503     const CMuiuSettingBase& aBaseItem,
       
   504     const TDesC& aNewText )
       
   505     {
       
   506     IMUM_CONTEXT( CIMSSettingsItemApprover::ValidateText, 0, KLogUi );
       
   507     IMUM_IN();
       
   508     IMUM_OUT();
       
   509 
       
   510     TBool result = IsItemFilled( aBaseItem, aNewText.Length() );
       
   511 
       
   512     if( result )
       
   513     	{
       
   514     	// Checks if the name of the mailbox contains only
       
   515     	// white space characters.
       
   516     	TInt length = aNewText.Length();
       
   517 
       
   518 		// we should not test empty string
       
   519 		// result was that the item is filled, but it may
       
   520 		// still be allowed to be empty
       
   521     	if( !length )
       
   522     		{
       
   523     		return EIMSNoError;
       
   524     		}
       
   525 
       
   526     	TUint currentAscii;
       
   527 
       
   528     	for( TInt i = 0 ; i < length ; i++ )
       
   529     		{
       
   530     		currentAscii = aNewText[i];
       
   531     		TChar tempChar( currentAscii );
       
   532 
       
   533     		if( !tempChar.IsSpace() )
       
   534     			{
       
   535     			// If the character isn't a white space character
       
   536     			// then EIMSNoError will be returned.
       
   537     			return EIMSNoError;
       
   538     			}
       
   539     		}
       
   540     		return EIMSItemEmpty;
       
   541     	}
       
   542     else
       
   543     	{
       
   544     	return EIMSItemEmpty;
       
   545     	}
       
   546     }
       
   547 
       
   548 /******************************************************************************
       
   549 
       
   550     Individual item code
       
   551 
       
   552 ******************************************************************************/
       
   553 
       
   554 // ----------------------------------------------------------------------------
       
   555 // CIMSSettingsItemApprover::EvaluateUsernameOrPassword()
       
   556 // ----------------------------------------------------------------------------
       
   557 //
       
   558 TIMSErrors CIMSSettingsItemApprover::EvaluateUsernameOrPassword(
       
   559     TIMSApproverEvent& aEvent,
       
   560     TDes& aNewText )
       
   561     {
       
   562     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateUsernameOrPassword, 0, KLogUi );
       
   563 
       
   564     TBool ok = aNewText.Length() > 0;
       
   565     TBool isAoOn = iDialog.Flag( EDialogAlwaysOnlineOn );
       
   566     TBool isEmnOn = iDialog.Flag( EDialogOmaEmnOn );
       
   567 
       
   568     MsvEmailMtmUiUtils::StripCharacters( aNewText );
       
   569 
       
   570     // If the field is deleted and always online or oma emn is on
       
   571     if ( !ok && ( isAoOn || isEmnOn ) )
       
   572         {
       
   573         // Prepare the correct event
       
   574         aEvent = isAoOn ?
       
   575             EIMSApproverRemoveAlwaysOnline : EIMSApproverRemoveOmaEmn;
       
   576         return EIMSAoNoLogin;
       
   577         }
       
   578 
       
   579     return EIMSNoError;
       
   580     }
       
   581 
       
   582 // ----------------------------------------------------------------------------
       
   583 // CIMSSettingsItemApprover::EvaluateFreeText()
       
   584 // ----------------------------------------------------------------------------
       
   585 //
       
   586 TIMSErrors CIMSSettingsItemApprover::EvaluateFreeText( TDes& aNewText )
       
   587     {
       
   588     IMUM_CONTEXT( CIMSSettingsItemApprover::EvaluateFreeText, 0, KLogUi );
       
   589     IMUM_IN();
       
   590 
       
   591     MsvEmailMtmUiUtils::StripCharacters( aNewText );
       
   592 
       
   593     IMUM_OUT();
       
   594     return EIMSNoError;
       
   595     }
       
   596 
       
   597 // ----------------------------------------------------------------------------
       
   598 // CIMSSettingsItemApprover::CheckItemAOCheckTurnOn()
       
   599 // ----------------------------------------------------------------------------
       
   600 //
       
   601 TIMSErrors CIMSSettingsItemApprover::CheckItemOnlineSettingsCheckTurnOn(
       
   602     TIMSApproverEvent& aEvent,
       
   603     const TInt aNewValue,
       
   604     TBool aIsEmn )
       
   605     {
       
   606     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemOnlineSettingsCheckTurnOn, 0, KLogUi );
       
   607 
       
   608     TIMSErrors result = EIMSNoError;
       
   609 
       
   610     // If Always Online or OMA EMN state is changed from off to on, check that
       
   611     // the current state of settings allows it
       
   612     TBool ao = ( aNewValue != EMailAoOff &&
       
   613         !iDialog.Flag( EDialogAlwaysOnlineOn ) && !aIsEmn );
       
   614 
       
   615     TBool emn = ( aNewValue != EMailEmnOff &&
       
   616         !iDialog.Flag( EDialogOmaEmnOn ) && aIsEmn );
       
   617 
       
   618     if ( ao || emn )
       
   619         {
       
   620         TRAPD( error,
       
   621             result = CheckItemOnlineSettingsCheckTurnOnL( aEvent, aIsEmn ) );
       
   622 
       
   623         // If leave occurred, don't accept the setting
       
   624         if ( error != KErrNone )
       
   625             {
       
   626             // Panic on debug to spot any errors
       
   627             __ASSERT_DEBUG( EFalse, User::Panic(
       
   628                 KIMSSettingsApproverPanic, error ) );
       
   629 
       
   630             aEvent = EIMSApproverNoEvent;
       
   631             result = EIMSItemInvalid;
       
   632             }
       
   633         }
       
   634     // Always online or OMA EMN is turned off, or the on state is changed in
       
   635     // case of always online, simply continue
       
   636     else
       
   637         {
       
   638         result = EIMSNoError;
       
   639         }
       
   640 
       
   641     return result;
       
   642     }
       
   643 
       
   644 // ----------------------------------------------------------------------------
       
   645 // CIMSSettingsItemApprover::CheckItemOnlineSettingsCheckTurnOnL()
       
   646 // ----------------------------------------------------------------------------
       
   647 //
       
   648 TIMSErrors CIMSSettingsItemApprover::CheckItemOnlineSettingsCheckTurnOnL(
       
   649     TIMSApproverEvent& aEvent,
       
   650     TBool aIsEmn )
       
   651     {
       
   652     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemOnlineSettingsCheckTurnOnL, 0, KLogUi );
       
   653 
       
   654     // Make packet Data check
       
   655     TIMSErrors result = CheckItemAoConnectionTypeL();
       
   656 
       
   657     // Number of access point mailboxes has to be less than 2
       
   658     if ( result == EIMSNoError && !aIsEmn )
       
   659         {
       
   660         result = CheckItemAoCountOkL();
       
   661         }
       
   662 
       
   663     // Always ask not acceptable, require valid access point
       
   664     // IAP user name and password check is not allowed
       
   665     if ( result == EIMSNoError )
       
   666         {
       
   667         result = CheckItemAoAccessPointOkL();
       
   668         }
       
   669 
       
   670     // Oma EMN not allowed for the AO mailbox
       
   671     // AO not allowed for the Oma EMN mailbox
       
   672     if ( result == EIMSNoError )
       
   673         {
       
   674         result = CheckItemAoOmaEmnOffL( aIsEmn );
       
   675         }
       
   676 
       
   677     // Check for incoming username and password
       
   678     if ( result == EIMSNoError )
       
   679         {
       
   680         result = CheckItemAoUsernameAndPasswordL();
       
   681         }
       
   682 
       
   683     // Query the user, if the header limit needs to be ignored
       
   684     if ( result == EIMSNoError && !aIsEmn )
       
   685         {
       
   686         result = CheckItemAOFixFetchL();
       
   687         }
       
   688 
       
   689     aEvent = EIMSApproverNoEvent;
       
   690 
       
   691     return result;
       
   692     }
       
   693 
       
   694 // ----------------------------------------------------------------------------
       
   695 // CIMSSettingsItemApprover::CheckItemAoCountOkL()
       
   696 // ----------------------------------------------------------------------------
       
   697 //
       
   698 TIMSErrors CIMSSettingsItemApprover::CheckItemAoCountOkL()
       
   699     {
       
   700     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAoCountOkL, 0, KLogUi );
       
   701 
       
   702     // Number of always online mailboxes has to be less than 2
       
   703     TBool on = MsvEmailMtmUiUtils::CheckActiveAOLimitsL(
       
   704         iMailboxApi, iDialog.CurrentMailboxId() );
       
   705 
       
   706     // Show error note in case of any errors
       
   707     if ( !on )
       
   708         {
       
   709         return EIMSAoManyAlwaysOnline;
       
   710         }
       
   711 
       
   712     return EIMSNoError;
       
   713     }
       
   714 
       
   715 // ----------------------------------------------------------------------------
       
   716 // CIMSSettingsItemApprover::CheckItemAoAccessPointOkL()
       
   717 // ----------------------------------------------------------------------------
       
   718 //
       
   719 TIMSErrors CIMSSettingsItemApprover::CheckItemAoAccessPointOkL()
       
   720     {
       
   721     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAoAccessPointOkL, 0, KLogUi );
       
   722     TIMSErrors result = EIMSNoError;
       
   723 
       
   724     return result;
       
   725     }
       
   726 
       
   727 // ----------------------------------------------------------------------------
       
   728 // CIMSSettingsItemApprover::CheckItemAoOmaEmnOffL()
       
   729 // ----------------------------------------------------------------------------
       
   730 //
       
   731 TIMSErrors CIMSSettingsItemApprover::CheckItemAoOmaEmnOffL( TBool aIsEmn )
       
   732     {
       
   733     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAoOmaEmnOffL, 0, KLogUi );
       
   734 
       
   735     TIMSErrors result = EIMSNoError;
       
   736 
       
   737     // AO is tried to turn on
       
   738     if ( !aIsEmn )
       
   739         {
       
   740         CMuiuSettingsLinkExtended* omaEmnNotification = NULL;
       
   741         User::LeaveIfError( iDialog.FindItem(
       
   742             omaEmnNotification, TUid::Uid( EIMASMailNotifications ) ) );
       
   743 
       
   744         // Show error note in case of any errors
       
   745         if ( omaEmnNotification->Value() != EMailEmnOff )
       
   746             {
       
   747             result = EIMSAoOmaEmnOn;
       
   748             }
       
   749         }
       
   750     // OMA EMN is tried to turn on
       
   751     else
       
   752         {
       
   753         CMuiuSettingsLinkExtended* ao = NULL;
       
   754         User::LeaveIfError( iDialog.FindItem(
       
   755             ao, TUid::Uid( EIMASAORolling ) ) );
       
   756 
       
   757         // Show error note in case of any errors
       
   758         if ( ao->Value() != EMailAoOff )
       
   759             {
       
   760             result = EIMSOmaEmnAoOn;
       
   761             }
       
   762         }
       
   763 
       
   764     return result;
       
   765     }
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // CIMSSettingsItemApprover::CheckItemAoUsernameAndPasswordL()
       
   769 // ----------------------------------------------------------------------------
       
   770 //
       
   771 TIMSErrors CIMSSettingsItemApprover::CheckItemAoUsernameAndPasswordL()
       
   772     {
       
   773     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAoUsernameAndPasswordL, 0, KLogUi );
       
   774 
       
   775     // Initialize incoming settings array before accessing username and
       
   776     // password
       
   777     CMuiuSettingsLinkExtended* username = NULL;
       
   778     CMuiuSettingsLinkExtended* password = NULL;
       
   779     User::LeaveIfError( iDialog.FindItem(
       
   780         username, TUid::Uid( EIMASIncomingUserName ) ) );
       
   781     User::LeaveIfError( iDialog.FindItem(
       
   782         password, TUid::Uid( EIMASIncomingUserPwd ) ) );
       
   783 
       
   784     TBool on = password->Text() && password->Text()->Length() > 0 &&
       
   785         username->Text() && username->Text()->Length() > 0;
       
   786 
       
   787     // Show error note in case of any errors
       
   788     if ( !on )
       
   789         {
       
   790         return EIMSAoNoLogin;
       
   791         }
       
   792 
       
   793     return EIMSNoError;
       
   794     }
       
   795 
       
   796 // ----------------------------------------------------------------------------
       
   797 // CIMSSettingsItemApprover::CheckItemAoConnectionTypeL()
       
   798 // ----------------------------------------------------------------------------
       
   799 //
       
   800 TIMSErrors CIMSSettingsItemApprover::CheckItemAoConnectionTypeL()
       
   801     {
       
   802     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAoConnectionTypeL, 0, KLogUi );
       
   803 
       
   804     if ( !iDialog.Flags().LF( EMailFeatureAlwaysOnlineCSD ) )
       
   805         {
       
   806         // Initialize incoming settings array before accessing
       
   807         // incoming accesspoints
       
   808         CIMSSettingsAccessPointItem* iapItem = NULL;
       
   809         User::LeaveIfError( iDialog.FindItem(
       
   810             iapItem, TUid::Uid( EIMASIncomingIap ) ) );
       
   811 
       
   812         if ( iCommsDbUtils.IsApBearerCircuitSwitchedL( iapItem->iIap.iId ) )
       
   813             {
       
   814             return EIMSAoIapTypeCSD;
       
   815             }
       
   816         }
       
   817 
       
   818     return EIMSNoError;
       
   819     }
       
   820 
       
   821 // ----------------------------------------------------------------------------
       
   822 // CIMSSettingsItemApprover::CheckItemAOFixFetchL()
       
   823 // ----------------------------------------------------------------------------
       
   824 //
       
   825 TIMSErrors CIMSSettingsItemApprover::CheckItemAOFixFetchL()
       
   826     {
       
   827     IMUM_CONTEXT( CIMSSettingsItemApprover::CheckItemAOFixFetchL, 0, KLogUi );
       
   828 
       
   829     // Turning on the always online requires of fetching all the mails,
       
   830     // without header limits. This means the header limit is ignored, which
       
   831     // has to be queried.
       
   832     TIMSErrors result = EIMSNoError;
       
   833 
       
   834     // Initalize fetch headers array
       
   835     CMuiuSettingsLinkExtended* inboxLimit = NULL;
       
   836     CMuiuSettingsLinkExtended* folderLimit = NULL;
       
   837     User::LeaveIfError( iDialog.FindItem(
       
   838         inboxLimit, TUid::Uid( EIMASLimitInbox ) ) );
       
   839     User::LeaveIfError( iDialog.FindItem(
       
   840         folderLimit, TUid::Uid( EIMASLimitFolders ) ) );
       
   841 
       
   842     // Check if the value in either of the settings is something else
       
   843     // than all
       
   844     TBool inboxOk = !inboxLimit->Value();
       
   845     TBool folderOk = !folderLimit->Value();
       
   846     TBool hasFolders = iMailboxApi.MailboxUtilitiesL().HasSubscribedFoldersL(
       
   847         iDialog.CurrentMailboxId() );
       
   848 
       
   849     // If inbox retrieval limit is not all, or user has subscribed folders
       
   850     // and limit is not all
       
   851     if ( !inboxOk || ( hasFolders && !folderOk ) )
       
   852         {
       
   853         // Show the note
       
   854         result = EIMSAoFetchNotAccepted;
       
   855         }
       
   856 
       
   857     inboxLimit = NULL;
       
   858     folderLimit = NULL;
       
   859 
       
   860     return result;
       
   861     }
       
   862 
       
   863 
       
   864 //  End of File