securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtvalidatorusername.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
child 55 9c2aa05919d9
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
     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 username format validator
       
    16  *
       
    17  */
       
    18 
       
    19 /*
       
    20  * %version: 11 %
       
    21  */
       
    22 
       
    23 // System includes
       
    24 #include <HbEditorInterface>
       
    25 #include <HbLineEdit>
       
    26 
       
    27 // User includes
       
    28 #include "eapqtvalidatorusername.h"
       
    29 #include "eapqtconfiginterface_p.h"
       
    30 
       
    31 /*!
       
    32  *  \class EapQtValidatorUsername
       
    33  *  \brief EAP method username format validator
       
    34  */
       
    35 
       
    36 // External function prototypes
       
    37 
       
    38 // Local constants
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 EapQtValidatorUsername::EapQtValidatorUsername(const EapQtExpandedEapType& type) :
       
    45     mEapType(type)
       
    46 {
       
    47 }
       
    48 
       
    49 EapQtValidatorUsername::~EapQtValidatorUsername()
       
    50 {
       
    51 }
       
    52 
       
    53 EapQtValidator::Status EapQtValidatorUsername::validate(const QVariant& value)
       
    54 {
       
    55     qDebug("EapQtValidatorUsername::validate()");
       
    56 
       
    57     Status status(StatusOk);
       
    58 
       
    59     switch (mEapType.type()) {
       
    60     case EapQtExpandedEapType::TypeEapAka:
       
    61     case EapQtExpandedEapType::TypeEapFast:
       
    62     case EapQtExpandedEapType::TypeEapGtc:
       
    63     case EapQtExpandedEapType::TypeEapMschapv2:
       
    64     case EapQtExpandedEapType::TypeEapSim:
       
    65     case EapQtExpandedEapType::TypeEapTls:
       
    66     case EapQtExpandedEapType::TypeEapTtls:
       
    67     case EapQtExpandedEapType::TypeLeap:
       
    68     case EapQtExpandedEapType::TypePeap:
       
    69     case EapQtExpandedEapType::TypePap:
       
    70     case EapQtExpandedEapType::TypePlainMschapv2:
       
    71         status = validateGeneral(value);
       
    72         break;
       
    73     default:
       
    74         // for methods that do not have a realm
       
    75         status = StatusInvalid;
       
    76         break;
       
    77     }
       
    78 
       
    79     return status;
       
    80 }
       
    81 
       
    82 EapQtValidator::Status EapQtValidatorUsername::validateGeneral(const QVariant& value)
       
    83 {
       
    84     Status status(StatusOk);
       
    85     QString str = value.toString();
       
    86 
       
    87     // input must be of correct type
       
    88     if (value.type() != QVariant::String) {
       
    89         status = StatusInvalid;
       
    90     }
       
    91     else if (str.length() <= 0 && !isEmptyAllowed()) {
       
    92         status = StatusTooShort;
       
    93     }
       
    94     // zero length username is ok
       
    95     else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) {
       
    96         status = StatusTooLong;
       
    97     }
       
    98     else if (!validateCharacters(str)) {
       
    99         status = StatusInvalidCharacters;
       
   100     }
       
   101 
       
   102     qDebug("EapQtValidatorUsername::validateGeneral - return status: %d", status);
       
   103 
       
   104     return status;
       
   105 }
       
   106 
       
   107 bool EapQtValidatorUsername::isEmptyAllowed()
       
   108 {
       
   109     qDebug("EapQtValidatorUsername::isEmptyAllowed()");
       
   110 
       
   111     bool ret(true);
       
   112 
       
   113     switch (mEapType.type()) {
       
   114     case EapQtExpandedEapType::TypeEapGtc:
       
   115     case EapQtExpandedEapType::TypeEapMschapv2:
       
   116     case EapQtExpandedEapType::TypeLeap:
       
   117     case EapQtExpandedEapType::TypePap:
       
   118     case EapQtExpandedEapType::TypePlainMschapv2:
       
   119         ret = false;
       
   120         break;
       
   121     default:
       
   122         // other methods can have empty username
       
   123         break;
       
   124     }
       
   125 
       
   126     return ret;
       
   127 }
       
   128 
       
   129 bool EapQtValidatorUsername::validateCharacters(const QString& str)
       
   130 {
       
   131     qDebug("EapQtValidatorUsername::validateCharacters()");
       
   132 
       
   133     bool ret(true);
       
   134 
       
   135     switch (mEapType.type()) {
       
   136     case EapQtExpandedEapType::TypeEapAka:
       
   137     case EapQtExpandedEapType::TypeEapFast:
       
   138     case EapQtExpandedEapType::TypeEapSim:
       
   139     case EapQtExpandedEapType::TypeEapTls:
       
   140     case EapQtExpandedEapType::TypeEapTtls:
       
   141     case EapQtExpandedEapType::TypePeap:
       
   142         // these methods have a separate UI setting for realm,
       
   143         // hence @ is not allowed in username field
       
   144         ret = !(str.contains(QChar('@'), Qt::CaseInsensitive));
       
   145         break;
       
   146     default:
       
   147         // username field can contain realm separated with @
       
   148         break;
       
   149     }
       
   150 
       
   151     return ret;
       
   152 }
       
   153 
       
   154 void EapQtValidatorUsername::updateEditor(HbLineEdit* const edit)
       
   155 {
       
   156     qDebug("EapQtValidatorUsername::updateEditor()");
       
   157 
       
   158     Q_ASSERT(edit);
       
   159     if(edit == NULL) {
       
   160         return;
       
   161     }
       
   162 
       
   163     switch (mEapType.type()) {
       
   164     case EapQtExpandedEapType::TypeEapAka:
       
   165     case EapQtExpandedEapType::TypeEapFast:
       
   166     case EapQtExpandedEapType::TypeEapGtc:
       
   167     case EapQtExpandedEapType::TypeEapMschapv2:
       
   168     case EapQtExpandedEapType::TypeEapSim:
       
   169     case EapQtExpandedEapType::TypeEapTls:
       
   170     case EapQtExpandedEapType::TypeEapTtls:
       
   171     case EapQtExpandedEapType::TypeLeap:
       
   172     case EapQtExpandedEapType::TypePeap:
       
   173     case EapQtExpandedEapType::TypePap:
       
   174     case EapQtExpandedEapType::TypePlainMschapv2:
       
   175         updateEditorGeneral(edit);
       
   176         // falls through on purpose
       
   177     default:
       
   178         // no editor preferences for other types
       
   179         break;
       
   180     }
       
   181 }
       
   182 
       
   183 void EapQtValidatorUsername::updateEditorGeneral(HbLineEdit* const edit)
       
   184 {
       
   185     qDebug("EapQtValidatorUsername::updateEditorGeneral()");
       
   186 
       
   187     Q_ASSERT(edit);
       
   188 
       
   189     edit->setMaxLength(EapQtConfigInterfacePrivate::StringMaxLength);
       
   190     edit->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase
       
   191         | Qt::ImhNoPredictiveText);
       
   192 
       
   193     HbEditorInterface editInterface(edit);
       
   194     editInterface.setEditorClass(HbInputEditorClassUsername);
       
   195 
       
   196     HbEditorConstraints constraints = HbEditorConstraintAutoCompletingField;
       
   197     editInterface.setInputConstraints(constraints);
       
   198 
       
   199     // no smileys :)
       
   200     editInterface.setSmileyTheme(HbSmileyTheme());
       
   201 }