securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtvalidatorpassword.cpp
branchRCL_3
changeset 18 bad0cc58d154
equal deleted inserted replaced
17:30e048a7b597 18:bad0cc58d154
       
     1 /*
       
     2  * Copyright (c) 2010 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: 
       
    15  *   EAP method password format validator
       
    16  *
       
    17  */
       
    18 
       
    19 /*
       
    20  * %version: 9 %
       
    21  */
       
    22 
       
    23 // System includes
       
    24 #include <HbEditorInterface>
       
    25 #include <HbLineEdit>
       
    26 
       
    27 // User includes
       
    28 #include "eapqtvalidatorpassword.h"
       
    29 #include "eapqtconfiginterface_p.h"
       
    30 
       
    31 /*!
       
    32  *  \class EapQtValidatorPassword
       
    33  *  \brief EAP method password format validator
       
    34  */
       
    35 
       
    36 // External function prototypes
       
    37 
       
    38 // Local constants
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 EapQtValidatorPassword::EapQtValidatorPassword(const EapQtExpandedEapType& type) :
       
    45     mEapType(type)
       
    46 {
       
    47 }
       
    48 
       
    49 EapQtValidatorPassword::~EapQtValidatorPassword()
       
    50 {
       
    51 }
       
    52 
       
    53 EapQtValidator::Status EapQtValidatorPassword::validate(const QVariant& value)
       
    54 {
       
    55     qDebug("EapQtValidatorPassword::validate()");
       
    56 
       
    57     Status status(StatusOk);
       
    58 
       
    59     switch (mEapType.type()) {
       
    60     case EapQtExpandedEapType::TypeEapGtc:
       
    61     case EapQtExpandedEapType::TypeEapMschapv2:
       
    62     case EapQtExpandedEapType::TypeLeap:
       
    63     case EapQtExpandedEapType::TypePap:
       
    64     case EapQtExpandedEapType::TypePlainMschapv2:
       
    65         status = validateGeneral(value);
       
    66         break;
       
    67     default:
       
    68         // for methods that do not have a password
       
    69         status = StatusInvalid;
       
    70     }
       
    71 
       
    72     return status;
       
    73 }
       
    74 
       
    75 EapQtValidator::Status EapQtValidatorPassword::validateGeneral(const QVariant& value)
       
    76 {
       
    77     Status status(StatusOk);
       
    78     QString str = value.toString();
       
    79 
       
    80     // input must be of correct type
       
    81     if (value.type() != QVariant::String) {
       
    82         status = StatusInvalid;
       
    83     }
       
    84     // zero length password is not ok
       
    85     else if (str.length() <= 0) {
       
    86         status = StatusTooShort;
       
    87     }
       
    88     // check maximum length
       
    89     else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) {
       
    90         status = StatusTooLong;
       
    91     }
       
    92 
       
    93     // any character is ok for passwords
       
    94     qDebug("EapQtValidatorPassword::validateGeneral - return status: %d", status);
       
    95 
       
    96     return status;
       
    97 }
       
    98 
       
    99 void EapQtValidatorPassword::updateEditor(HbLineEdit* const edit)
       
   100 {
       
   101     qDebug("EapQtValidatorPassword::updateEditor()");
       
   102 
       
   103     Q_ASSERT(edit);
       
   104     if(edit == NULL) {
       
   105         return;
       
   106     }
       
   107 
       
   108     switch (mEapType.type()) {
       
   109     case EapQtExpandedEapType::TypeEapGtc:
       
   110     case EapQtExpandedEapType::TypeEapMschapv2:
       
   111     case EapQtExpandedEapType::TypeLeap:
       
   112     case EapQtExpandedEapType::TypePap:
       
   113     case EapQtExpandedEapType::TypePlainMschapv2:
       
   114         updateEditorGeneral(edit);
       
   115         // falls through on purpose
       
   116     default:
       
   117         // nothing for methods that do not have a password
       
   118         break;
       
   119     }
       
   120 }
       
   121 
       
   122 void EapQtValidatorPassword::updateEditorGeneral(HbLineEdit* const edit)
       
   123 {
       
   124     qDebug("EapQtValidatorPassword::updateEditorGeneral()");
       
   125 
       
   126     Q_ASSERT(edit);
       
   127 
       
   128     edit->setMaxLength(EapQtConfigInterfacePrivate::StringMaxLength);
       
   129     edit->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase
       
   130         | Qt::ImhNoPredictiveText);
       
   131 
       
   132     // do not set editor class or auto completing since they might leak the pwd
       
   133     HbEditorInterface editInterface(edit);
       
   134     editInterface.setSmileyTheme(HbSmileyTheme());
       
   135 }