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