|
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: username |
|
16 * |
|
17 */ |
|
18 |
|
19 /* |
|
20 * %version: 5 % |
|
21 */ |
|
22 |
|
23 #include <HbEditorInterface> |
|
24 #include <HbLineEdit> |
|
25 |
|
26 #include "eapqtvalidatorusername.h" |
|
27 #include "eapqtconfiginterface_p.h" |
|
28 |
|
29 EapQtValidatorUsername::EapQtValidatorUsername(EapQtExpandedEapType type) : |
|
30 mEapType(type) |
|
31 { |
|
32 } |
|
33 |
|
34 EapQtValidatorUsername::~EapQtValidatorUsername() |
|
35 { |
|
36 } |
|
37 |
|
38 EapQtValidator::Status EapQtValidatorUsername::validate(QVariant value) |
|
39 { |
|
40 Status status(StatusOk); |
|
41 |
|
42 switch (mEapType.type()) { |
|
43 case EapQtExpandedEapType::TypeEapAka: |
|
44 case EapQtExpandedEapType::TypeEapFast: |
|
45 case EapQtExpandedEapType::TypeEapGtc: |
|
46 case EapQtExpandedEapType::TypeEapMschapv2: |
|
47 case EapQtExpandedEapType::TypeEapSim: |
|
48 case EapQtExpandedEapType::TypeEapTls: |
|
49 case EapQtExpandedEapType::TypeEapTtls: |
|
50 case EapQtExpandedEapType::TypeLeap: |
|
51 case EapQtExpandedEapType::TypePeap: |
|
52 status = validateGeneral(value); |
|
53 break; |
|
54 default: |
|
55 // for methods that do not have a realm |
|
56 status = StatusInvalid; |
|
57 } |
|
58 |
|
59 return status; |
|
60 } |
|
61 |
|
62 EapQtValidator::Status EapQtValidatorUsername::validateGeneral(QVariant value) |
|
63 { |
|
64 Status status(StatusOk); |
|
65 QString str = value.toString(); |
|
66 |
|
67 // input must be of correct type |
|
68 if (value.type() != QVariant::String) { |
|
69 status = StatusInvalid; |
|
70 } |
|
71 // zero length username is ok |
|
72 else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) { |
|
73 status = StatusTooLong; |
|
74 } |
|
75 // username and realm are separated with @, not allowed to be part of username |
|
76 else if (str.contains(QChar('@'), Qt::CaseInsensitive)) { |
|
77 status = StatusInvalidCharacters; |
|
78 } |
|
79 |
|
80 qDebug("EapQtValidatorUsername::validateGeneral - return status: %d", status); |
|
81 |
|
82 return status; |
|
83 } |
|
84 |
|
85 void EapQtValidatorUsername::updateEditor(HbLineEdit *edit) |
|
86 { |
|
87 switch (mEapType.type()) { |
|
88 case EapQtExpandedEapType::TypeEapAka: |
|
89 case EapQtExpandedEapType::TypeEapFast: |
|
90 case EapQtExpandedEapType::TypeEapGtc: |
|
91 case EapQtExpandedEapType::TypeEapMschapv2: |
|
92 case EapQtExpandedEapType::TypeEapSim: |
|
93 case EapQtExpandedEapType::TypeEapTls: |
|
94 case EapQtExpandedEapType::TypeEapTtls: |
|
95 case EapQtExpandedEapType::TypeLeap: |
|
96 case EapQtExpandedEapType::TypePeap: |
|
97 updateEditorGeneral(edit); |
|
98 // falls through on purpose |
|
99 default: |
|
100 // no realm for other types |
|
101 break; |
|
102 } |
|
103 } |
|
104 |
|
105 void EapQtValidatorUsername::updateEditorGeneral(HbLineEdit *edit) |
|
106 { |
|
107 qDebug("EapQtValidatorUsername::updateEditorGeneral()"); |
|
108 |
|
109 edit->setMaxLength(EapQtConfigInterfacePrivate::StringMaxLength); |
|
110 edit->setInputMethodHints(Qt::ImhNoAutoUppercase | Qt::ImhPreferLowercase |
|
111 | Qt::ImhNoPredictiveText); |
|
112 |
|
113 HbEditorInterface editInterface(edit); |
|
114 editInterface.setEditorClass(HbInputEditorClassUsername); |
|
115 |
|
116 HbEditorConstraints constraints = HbEditorConstraintAutoCompletingField; |
|
117 editInterface.setInputConstraints(constraints); |
|
118 |
|
119 // no smileys :) |
|
120 editInterface.setSmileyTheme(HbSmileyTheme()); |
|
121 } |