26
|
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
|
34
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
26
|
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:
|
34
|
15 |
* EAP method username format validator
|
26
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
/*
|
49
|
20 |
* %version: 12 %
|
26
|
21 |
*/
|
|
22 |
|
34
|
23 |
// System includes
|
26
|
24 |
#include <HbEditorInterface>
|
|
25 |
#include <HbLineEdit>
|
|
26 |
|
34
|
27 |
// User includes
|
26
|
28 |
#include "eapqtvalidatorusername.h"
|
|
29 |
#include "eapqtconfiginterface_p.h"
|
|
30 |
|
34
|
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) :
|
26
|
45 |
mEapType(type)
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
EapQtValidatorUsername::~EapQtValidatorUsername()
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
34
|
53 |
EapQtValidator::Status EapQtValidatorUsername::validate(const QVariant& value)
|
26
|
54 |
{
|
34
|
55 |
qDebug("EapQtValidatorUsername::validate()");
|
|
56 |
|
26
|
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:
|
34
|
69 |
case EapQtExpandedEapType::TypePap:
|
|
70 |
case EapQtExpandedEapType::TypePlainMschapv2:
|
26
|
71 |
status = validateGeneral(value);
|
|
72 |
break;
|
|
73 |
default:
|
|
74 |
// for methods that do not have a realm
|
|
75 |
status = StatusInvalid;
|
34
|
76 |
break;
|
26
|
77 |
}
|
|
78 |
|
|
79 |
return status;
|
|
80 |
}
|
|
81 |
|
34
|
82 |
EapQtValidator::Status EapQtValidatorUsername::validateGeneral(const QVariant& value)
|
26
|
83 |
{
|
|
84 |
Status status(StatusOk);
|
49
|
85 |
const QString str = value.toString();
|
26
|
86 |
|
|
87 |
// input must be of correct type
|
|
88 |
if (value.type() != QVariant::String) {
|
|
89 |
status = StatusInvalid;
|
|
90 |
}
|
34
|
91 |
else if (str.length() <= 0 && !isEmptyAllowed()) {
|
|
92 |
status = StatusTooShort;
|
|
93 |
}
|
26
|
94 |
// zero length username is ok
|
|
95 |
else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) {
|
|
96 |
status = StatusTooLong;
|
|
97 |
}
|
27
|
98 |
else if (!validateCharacters(str)) {
|
26
|
99 |
status = StatusInvalidCharacters;
|
|
100 |
}
|
|
101 |
|
|
102 |
qDebug("EapQtValidatorUsername::validateGeneral - return status: %d", status);
|
|
103 |
|
|
104 |
return status;
|
|
105 |
}
|
|
106 |
|
34
|
107 |
bool EapQtValidatorUsername::isEmptyAllowed()
|
27
|
108 |
{
|
34
|
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 |
|
27
|
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 |
|
34
|
154 |
void EapQtValidatorUsername::updateEditor(HbLineEdit* const edit)
|
26
|
155 |
{
|
34
|
156 |
qDebug("EapQtValidatorUsername::updateEditor()");
|
|
157 |
|
27
|
158 |
Q_ASSERT(edit);
|
|
159 |
if(edit == NULL) {
|
|
160 |
return;
|
|
161 |
}
|
|
162 |
|
26
|
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:
|
34
|
173 |
case EapQtExpandedEapType::TypePap:
|
|
174 |
case EapQtExpandedEapType::TypePlainMschapv2:
|
26
|
175 |
updateEditorGeneral(edit);
|
|
176 |
// falls through on purpose
|
|
177 |
default:
|
34
|
178 |
// no editor preferences for other types
|
26
|
179 |
break;
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
34
|
183 |
void EapQtValidatorUsername::updateEditorGeneral(HbLineEdit* const edit)
|
26
|
184 |
{
|
|
185 |
qDebug("EapQtValidatorUsername::updateEditorGeneral()");
|
|
186 |
|
27
|
187 |
Q_ASSERT(edit);
|
|
188 |
|
26
|
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 |
}
|