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