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 * WPS Wizard Page: Step 3 Number enter mode. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <HbDocumentLoader> |
|
21 #include <HbWidget> |
|
22 #include <HbRadiobuttonList> |
|
23 #include <HbLineEdit> |
|
24 #include <HbLabel> |
|
25 #include <QTextStream> |
|
26 #include <QTime> |
|
27 #include <HbMainWindow> |
|
28 #include <HbParameterLengthLimiter> |
|
29 |
|
30 // User includes |
|
31 #include "wpswizardstepthreenumber.h" |
|
32 #include "wpswizard_p.h" |
|
33 |
|
34 // Trace includes |
|
35 #include "OstTraceDefinitions.h" |
|
36 #ifdef OST_TRACE_COMPILER_IN_USE |
|
37 #include "wpswizardstepthreenumberTraces.h" |
|
38 #endif |
|
39 |
|
40 // External function prototypes |
|
41 |
|
42 // Local constants |
|
43 const static int KMaxPINLength = 8; |
|
44 |
|
45 /*! |
|
46 \class WpsPageStepThreeNumber |
|
47 \brief Implementation of wps wizard page for step three PIN Entry mode. |
|
48 */ |
|
49 |
|
50 // ======== LOCAL FUNCTIONS ======== |
|
51 |
|
52 // ======== MEMBER FUNCTIONS ======== |
|
53 |
|
54 /*! |
|
55 Constructor for WPS page three number entry mode |
|
56 |
|
57 @param [in] parent Pointer to the WPS wizard private implementation |
|
58 */ |
|
59 WpsPageStepThreeNumber::WpsPageStepThreeNumber(WpsWizardPrivate* parent) : |
|
60 WpsWizardPage(parent), |
|
61 mWidget(NULL), |
|
62 mHeading(NULL), |
|
63 mLoader(NULL) |
|
64 { |
|
65 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_ENTRY, this); |
|
66 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_EXIT, this); |
|
67 |
|
68 } |
|
69 |
|
70 /*! |
|
71 Destructor |
|
72 */ |
|
73 WpsPageStepThreeNumber::~WpsPageStepThreeNumber() |
|
74 { |
|
75 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_ENTRY, this); |
|
76 delete mLoader; |
|
77 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_WPSPAGESTEPTHREENUMBER_DESTRUCTOR_EXIT, this); |
|
78 } |
|
79 |
|
80 /*! |
|
81 Loads the page with all the widgets |
|
82 |
|
83 @return HbWidget* Returns the view widget |
|
84 */ |
|
85 HbWidget* WpsPageStepThreeNumber::initializePage() |
|
86 { |
|
87 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_ENTRY, this); |
|
88 |
|
89 if (!mWidget) { |
|
90 bool ok; |
|
91 mLoader = new HbDocumentLoader(mWizard->mainWindow()); |
|
92 |
|
93 mLoader->load(":/docml/occ_wps_02_03.docml", &ok); |
|
94 Q_ASSERT(ok); |
|
95 |
|
96 mWidget = qobject_cast<HbWidget*> (mLoader->findWidget("occ_wps_P2")); |
|
97 Q_ASSERT(mWidget); |
|
98 |
|
99 mHeading= qobject_cast<HbLabel*> (mLoader->findWidget("label_heading")); |
|
100 Q_ASSERT(mHeading); |
|
101 } |
|
102 |
|
103 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_INITIALIZEPAGE_EXIT, this); |
|
104 |
|
105 return mWidget; |
|
106 } |
|
107 |
|
108 /*! |
|
109 Funtion to determine the next page to be displayed in the wizard process |
|
110 |
|
111 @param [out] removeFromStack bool indicating whether the current page should be |
|
112 removed from the stack |
|
113 |
|
114 @return int Page Id of the next page to be displayed. |
|
115 */ |
|
116 int WpsPageStepThreeNumber::nextId(bool &removeFromStack) const |
|
117 { |
|
118 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_NEXTID_ENTRY, this); |
|
119 removeFromStack = false; |
|
120 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_NEXTID_EXIT, this); |
|
121 |
|
122 return WpsWizardPage::PageWpsWizardStep4; |
|
123 } |
|
124 |
|
125 /*! |
|
126 Determines the Number of steps to move backwards when 'Prev' Button |
|
127 is clicked |
|
128 |
|
129 @return int Number of pages to move backwards |
|
130 */ |
|
131 int WpsPageStepThreeNumber::previousTriggered() |
|
132 { |
|
133 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_ENTRY, this); |
|
134 |
|
135 mWizard->setPin(0); |
|
136 |
|
137 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_PREVIOUSTRIGGERED_EXIT, this); |
|
138 return (PageWpsWizardStep3_Number - PageWpsWizardStep2) - 1; |
|
139 } |
|
140 |
|
141 /*! |
|
142 CallBack when the cancel button is clicked |
|
143 */ |
|
144 void WpsPageStepThreeNumber::cancelTriggered() |
|
145 { |
|
146 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_ENTRY, this); |
|
147 mWizard->setPin(0); |
|
148 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_CANCELTRIGGERED_EXIT, this); |
|
149 } |
|
150 |
|
151 |
|
152 /*! |
|
153 Determines whether the Next action button should be enabled or not |
|
154 |
|
155 @return bool Indicating whether next button is enabled or not. |
|
156 */ |
|
157 bool WpsPageStepThreeNumber::showPage() |
|
158 { |
|
159 int randomNumber = computeRandNumber(); |
|
160 mHeading->setPlainText( |
|
161 HbParameterLengthLimiter( |
|
162 "txt_occ_dialog_enter_1_on_the_wireless_station_t").arg( |
|
163 QString::number(randomNumber))); |
|
164 mWizard->setPin(randomNumber); |
|
165 return true; |
|
166 } |
|
167 |
|
168 /*! |
|
169 Computes the Random number based on current system time |
|
170 |
|
171 @return int Returns the generated random number |
|
172 */ |
|
173 int WpsPageStepThreeNumber::computeRandNumber() |
|
174 { |
|
175 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_ENTRY, this); |
|
176 |
|
177 int pin = 0; |
|
178 QTime time(0, 0); |
|
179 int seed = time.secsTo(QTime::currentTime()); |
|
180 |
|
181 do { |
|
182 qsrand(seed); |
|
183 pin = qrand(); |
|
184 } while (pin < (10 ^ (KMaxPINLength - 2)) || (((pin / 1000000) % 10)) == 0); |
|
185 |
|
186 //last digit is checksum, so we need 7 digits |
|
187 //and the first shouldn't be 0 |
|
188 pin = pin % 10000000; |
|
189 int checkSum = computeCheckSum(pin); |
|
190 pin *= 10; |
|
191 pin += checkSum; |
|
192 |
|
193 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTERANDNUMBER_EXIT, this); |
|
194 return pin; |
|
195 } |
|
196 |
|
197 /*! |
|
198 Computes the checksum for a given pin |
|
199 |
|
200 @return Returns the generated checksum |
|
201 */ |
|
202 int WpsPageStepThreeNumber::computeCheckSum(int aPin) |
|
203 { |
|
204 OstTraceFunctionEntry1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_ENTRY, this); |
|
205 |
|
206 int accum = 0; |
|
207 aPin *= 10; |
|
208 accum += 3 * ((aPin / 10000000) % 10); |
|
209 accum += 1 * ((aPin / 1000000) % 10); |
|
210 accum += 3 * ((aPin / 100000) % 10); |
|
211 accum += 1 * ((aPin / 10000) % 10); |
|
212 accum += 3 * ((aPin / 1000) % 10); |
|
213 accum += 1 * ((aPin / 100) % 10); |
|
214 accum += 3 * ((aPin / 10) % 10); |
|
215 int digit = (accum % 10); |
|
216 OstTraceFunctionExit1(WPSPAGESTEPTHREENUMBER_COMPUTECHECKSUM_EXIT, this); |
|
217 return (10 - digit) % 10; |
|
218 } |
|