ipsservices/ipssossettings/src/ipssetuiapprover.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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: This file implements class CIpsSetUiApprover.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "emailtrace.h"
       
    21 #include "ipssetutils.h"                // IpsSetUtils
       
    22 #include "ipssetuiitembase.h"           // CIpsSetUiItem
       
    23 #include "ipssetutils.h"
       
    24 #include "ipssetutilspageids.hrh"
       
    25 #include "ipssetutilsconsts.h"
       
    26 
       
    27 #include "ipssetuiapprover.h"
       
    28 
       
    29 
       
    30 // ============================ MEMBER FUNCTIONS ===============================
       
    31 
       
    32 // ----------------------------------------------------------------------------
       
    33 // CIpsSetUiApprover::CIpsSetUiApprover()
       
    34 // ----------------------------------------------------------------------------
       
    35 CIpsSetUiApprover::CIpsSetUiApprover()
       
    36     :
       
    37     iNoteUi( NULL )
       
    38     {
       
    39     FUNC_LOG;
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CIpsSetUiApprover::ConstructL()
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 void CIpsSetUiApprover::ConstructL()
       
    47     {
       
    48     FUNC_LOG;
       
    49     iNoteUi = CIpsSetUiNotes::NewL();
       
    50     }
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CIpsSetUiApprover::~CIpsSetUiApprover()
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CIpsSetUiApprover::~CIpsSetUiApprover()
       
    57     {
       
    58     FUNC_LOG;
       
    59     delete iNoteUi;
       
    60     iNoteUi = NULL;
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // CIpsSetUiApprover::NewL()
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CIpsSetUiApprover* CIpsSetUiApprover::NewL()
       
    68     {
       
    69     FUNC_LOG;
       
    70     CIpsSetUiApprover* self = NewLC();
       
    71     CleanupStack::Pop( self );
       
    72 
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CIpsSetUiApprover::NewLC()
       
    78 // ----------------------------------------------------------------------------
       
    79 //
       
    80 CIpsSetUiApprover* CIpsSetUiApprover::NewLC()
       
    81     {
       
    82     FUNC_LOG;
       
    83     CIpsSetUiApprover* self = new ( ELeave ) CIpsSetUiApprover();
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL();
       
    86 
       
    87     return self;
       
    88     }
       
    89 
       
    90 /******************************************************************************
       
    91 
       
    92     Common item validating
       
    93 
       
    94 ******************************************************************************/
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CIpsSetUiApprover::ValidateType()
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 TIpsSetUiNoteErrors CIpsSetUiApprover::ValidateType(
       
   101     const CIpsSetUiItem& aBaseItem,
       
   102     TDes& aNewText,
       
   103     TInt& aNewValue )
       
   104     {
       
   105     FUNC_LOG;
       
   106     // Handle the item, based on the type
       
   107     switch ( aBaseItem.Type() )
       
   108         {
       
   109         // Text editor
       
   110         case EIpsSetUiItemText:
       
   111             return ValidateText( aBaseItem, aNewText );
       
   112 
       
   113         // Number editor
       
   114         case EIpsSetUiCheckBoxArray:
       
   115         case EIpsSetUiItemValue:
       
   116             return ValidateValue( aBaseItem, aNewValue );
       
   117 
       
   118         case EIpsSetUiRadioButtonArray:
       
   119             return ValidateRadioButtons( aNewValue );
       
   120 
       
   121         // Type is not recognized or not supported
       
   122         default:
       
   123             break;
       
   124         }
       
   125 
       
   126     return EIpsSetUiNoError;
       
   127     }
       
   128 
       
   129 /******************************************************************************
       
   130 
       
   131     Special item validating
       
   132 
       
   133 ******************************************************************************/
       
   134 
       
   135 // ----------------------------------------------------------------------------
       
   136 // CIpsSetUiApprover::EvaluateServerAddress()
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 TIpsSetUiNoteErrors CIpsSetUiApprover::EvaluateServerAddress(
       
   140     const CIpsSetUiItem& aBaseItem,
       
   141     const TDesC& aNewText )
       
   142     {
       
   143     FUNC_LOG;
       
   144     TIpsSetUiNoteErrors result = ValidateText( aBaseItem, aNewText );
       
   145 
       
   146     // Check that dot isn't in start of the server address
       
   147     if ( result == EIpsSetUiNoError )
       
   148         {
       
   149         TBool ok = EFalse;
       
   150         TRAPD( error, ok = IpsSetUtils::IsValidDomainL( aNewText ) );
       
   151 
       
   152         result = ( error == KErrNone ) && ok ? 
       
   153             EIpsSetUiNoError : EIpsSetUiItemInvalid;
       
   154         }
       
   155 
       
   156     return result;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CIpsSetUiApprover::EvaluateEmailAddress()
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 TIpsSetUiNoteErrors CIpsSetUiApprover::EvaluateEmailAddress(
       
   164     const CIpsSetUiItem& aBaseItem,
       
   165     const TDesC& aNewText )
       
   166     {
       
   167     FUNC_LOG;
       
   168     // First make basic test
       
   169     TIpsSetUiNoteErrors result = ValidateText( aBaseItem, aNewText );
       
   170 
       
   171     // If text check was successful and the address is given, validate the
       
   172     // email address
       
   173     if ( result == EIpsSetUiNoError && aNewText.Length() )
       
   174         {
       
   175         // Trap any errors to prevent leaving
       
   176         TBool ok = EFalse;
       
   177         TRAPD( error, ok =
       
   178             IpsSetUtils::IsValidEmailAddressL( aNewText ) );
       
   179 
       
   180         result = ( ok && error == KErrNone ) ? 
       
   181             EIpsSetUiNoError : EIpsSetUiItemInvalid;
       
   182         }
       
   183 
       
   184     return result;
       
   185     }
       
   186 
       
   187 /******************************************************************************
       
   188 
       
   189     Brand new validating code
       
   190 
       
   191 ******************************************************************************/
       
   192 
       
   193 // ----------------------------------------------------------------------------
       
   194 // CIpsSetUiApprover::EvaluateSettingItems()
       
   195 // ----------------------------------------------------------------------------
       
   196 //
       
   197 TIpsSetUiNoteErrors CIpsSetUiApprover::EvaluateSettingItems(
       
   198     const CIpsSetUiItem& aBaseItem,
       
   199     TDes& aNewText,
       
   200     TInt& aNewValue )
       
   201     {
       
   202     FUNC_LOG;
       
   203     // Incoming settings
       
   204     switch ( aBaseItem.iItemId.iUid )
       
   205         {
       
   206         case EIpsSetUiIncomingMailServer:
       
   207         case EIpsSetUiOutgoingMailServer:
       
   208             return EvaluateServerAddress( aBaseItem, aNewText );
       
   209 
       
   210         case EIpsSetUiMailboxReplyToAddress:
       
   211         case EIpsSetUiMailboxEmailAddress:
       
   212             return EvaluateEmailAddress( aBaseItem, aNewText );
       
   213 
       
   214         default:
       
   215             break;
       
   216         }
       
   217 
       
   218     return ValidateType( aBaseItem, aNewText, aNewValue );
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // CIpsSetUiApprover::EvaluateItem()
       
   223 // ----------------------------------------------------------------------------
       
   224 //
       
   225 TIpsSetUiEventResult CIpsSetUiApprover::EvaluateItem(
       
   226     const CIpsSetUiItem& aBaseItem,
       
   227     TDes& aNewText,
       
   228     TInt& aNewValue )
       
   229     {
       
   230     FUNC_LOG;
       
   231     TIpsSetUiNoteErrors error = 
       
   232         EvaluateSettingItems( aBaseItem, aNewText, aNewValue );
       
   233 
       
   234     return iNoteUi->ShowDialog( aBaseItem, error, aNewText );
       
   235     }
       
   236 
       
   237 // ----------------------------------------------------------------------------
       
   238 // CIpsSetUiApprover::EvaluateText()
       
   239 // ----------------------------------------------------------------------------
       
   240 //
       
   241 TIpsSetUiEventResult CIpsSetUiApprover::EvaluateText(
       
   242     const CIpsSetUiItem& aBaseItem,
       
   243     TDes& aNewText )
       
   244     {
       
   245     FUNC_LOG;
       
   246     TInt nothing = 0;
       
   247     return EvaluateItem( aBaseItem, aNewText, nothing );
       
   248     }
       
   249 
       
   250  // ----------------------------------------------------------------------------
       
   251 // CIpsSetUiApprover::EvaluateValue()
       
   252 // ----------------------------------------------------------------------------
       
   253 //
       
   254 TIpsSetUiEventResult CIpsSetUiApprover::EvaluateValue(
       
   255     const CIpsSetUiItem& aBaseItem,
       
   256     TInt& aNewValue )
       
   257     {
       
   258     FUNC_LOG;
       
   259     TIpsSetUtilsTextPlain nothing;
       
   260     return EvaluateItem( aBaseItem, nothing, aNewValue );
       
   261     }
       
   262 
       
   263 /******************************************************************************
       
   264 
       
   265     Common code
       
   266 
       
   267 ******************************************************************************/
       
   268 
       
   269 // ----------------------------------------------------------------------------
       
   270 // CIpsSetUiApprover::IsItemFilled()
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 TBool CIpsSetUiApprover::IsItemFilled(
       
   274     const CIpsSetUiItem& aBaseItem,
       
   275     const TInt aLength )
       
   276     {
       
   277     FUNC_LOG;
       
   278     // At first, check if the item can be left empty
       
   279     TBool ok =
       
   280         !( aBaseItem.iItemFlags.Flag( KIpsSetUiFlagMustFill ) ||
       
   281            aBaseItem.iItemFlags.Flag( KIpsSetUiFlagForceMustFill ) );
       
   282 
       
   283     // The text field is considered filled, when:
       
   284     // A: Item has NO must fill -flags on
       
   285     // B: Item has must fill -flags on and length is higher than 0
       
   286     return ok || ( !ok && aLength > 0 );
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CIpsSetUiApprover::ValidateRadioButton()
       
   291 // ----------------------------------------------------------------------------
       
   292 //
       
   293 TIpsSetUiNoteErrors CIpsSetUiApprover::ValidateRadioButtons(
       
   294     const TInt& aNewValue )
       
   295     {
       
   296     FUNC_LOG;
       
   297     // Make sure item is checked
       
   298     return ( aNewValue != KErrNotFound ) ? EIpsSetUiNoError : EIpsSetUiItemEmpty;
       
   299     }
       
   300 
       
   301 // ----------------------------------------------------------------------------
       
   302 // CIpsSetUiApprover::ValidateValue()
       
   303 // ----------------------------------------------------------------------------
       
   304 //
       
   305 TIpsSetUiNoteErrors CIpsSetUiApprover::ValidateValue(
       
   306     const CIpsSetUiItem& aBaseItem,
       
   307     TInt& aNewValue )
       
   308     {
       
   309     FUNC_LOG;
       
   310     // This check makes sure, that the provided value is larger than 0
       
   311     return IsItemFilled( aBaseItem, aNewValue ) ?
       
   312         EIpsSetUiNoError : EIpsSetUiItemInvalid;
       
   313     }
       
   314 
       
   315 // ----------------------------------------------------------------------------
       
   316 // CIpsSetUiApprover::ValidateTextL()
       
   317 // ----------------------------------------------------------------------------
       
   318 //
       
   319 TIpsSetUiNoteErrors CIpsSetUiApprover::ValidateText(
       
   320     const CIpsSetUiItem& aBaseItem,
       
   321     const TDesC& aNewText )
       
   322     {
       
   323     FUNC_LOG;
       
   324     return IsItemFilled( aBaseItem, aNewText.Length() ) ?
       
   325         EIpsSetUiNoError : EIpsSetUiItemEmpty;
       
   326     }
       
   327 
       
   328 //  End of File
       
   329