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