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 * Main view for the WLAN Login application |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <QGraphicsLinearLayout> |
|
21 #include <QWebFrame> |
|
22 |
|
23 // System includes |
|
24 #include <HbToolbar> |
|
25 #include <HbAction> |
|
26 #include <HbProgressBar> |
|
27 #include <HbScrollBar> |
|
28 #include <HbScrollArea> |
|
29 #include <HbWidget> |
|
30 #include <HbMainWindow> |
|
31 |
|
32 // User includes |
|
33 #include "wlanlogindocumentloader.h" |
|
34 #include "wlanloginview.h" |
|
35 #include "wlanloginwebview.h" |
|
36 #include "wlanloginwebpage.h" |
|
37 #include "wlanloginmainwindow.h" |
|
38 #include "wlanloginengine.h" |
|
39 #include "ictsqtwrapper.h" |
|
40 |
|
41 #include "OstTraceDefinitions.h" |
|
42 #ifdef OST_TRACE_COMPILER_IN_USE |
|
43 #include "wlanloginviewTraces.h" |
|
44 #endif |
|
45 |
|
46 /*! |
|
47 \class WlanLoginView |
|
48 \brief Main view for the WLAN Login application |
|
49 */ |
|
50 |
|
51 // External function prototypes |
|
52 |
|
53 // Local constants |
|
54 //! WLAN Login view docml file |
|
55 static const QString wlanLoginViewDocml(":/docml/wlanloginview.docml"); |
|
56 |
|
57 // ======== LOCAL FUNCTIONS ======== |
|
58 |
|
59 // ======== MEMBER FUNCTIONS ======== |
|
60 |
|
61 /*! |
|
62 Constructor |
|
63 */ |
|
64 WlanLoginView::WlanLoginView(WlanLoginMainWindow* mainWindow): |
|
65 mMainWindow(mainWindow), |
|
66 mDocLoader(new WlanLoginDocumentLoader(mainWindow)), |
|
67 mProgressBar(NULL), |
|
68 mScrollAreaContent(NULL), |
|
69 mWebView(NULL), |
|
70 mNextAction(NULL), |
|
71 mFirstIctsOkResult(true) |
|
72 { |
|
73 OstTraceFunctionEntry0(WLANLOGINVIEW_WLANLOGINVIEW_ENTRY); |
|
74 |
|
75 loadDocml(); |
|
76 |
|
77 setTitleBarVisible(false); |
|
78 setStatusBarVisible(false); |
|
79 |
|
80 // Set white background to content widget |
|
81 QPixmap pixmap(10,10); |
|
82 pixmap.fill(Qt::white); |
|
83 QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap); |
|
84 mScrollAreaContent->setBackgroundItem(pixmapItem); |
|
85 |
|
86 mWebView->page()->setNetworkAccessManager(mMainWindow->application()->engine()->networkAccessManager()); |
|
87 |
|
88 bool connectStatus = connect( |
|
89 mWebView, |
|
90 SIGNAL(loadStarted()), |
|
91 this, |
|
92 SLOT(handleLoadStarted())); |
|
93 Q_ASSERT(connectStatus == true); |
|
94 |
|
95 connectStatus = connect( |
|
96 mWebView, |
|
97 SIGNAL(loadProgress(int)), |
|
98 this, |
|
99 SLOT(handleLoadProgress(int))); |
|
100 Q_ASSERT(connectStatus == true); |
|
101 |
|
102 connectStatus = connect( |
|
103 mWebView, |
|
104 SIGNAL(loadFinished(bool)), |
|
105 this, |
|
106 SLOT(handleLoadFinished(bool))); |
|
107 Q_ASSERT(connectStatus == true); |
|
108 |
|
109 connectStatus = connect( |
|
110 mWebView, |
|
111 SIGNAL(urlChanged(const QUrl&)), |
|
112 this, |
|
113 SLOT(handleUrlChanged(const QUrl&))); |
|
114 Q_ASSERT(connectStatus == true); |
|
115 |
|
116 connectStatus = connect( |
|
117 mWebView->page(), |
|
118 SIGNAL(formSubmitted()), |
|
119 this, |
|
120 SLOT(handleFormSubmitted())); |
|
121 Q_ASSERT(connectStatus == true); |
|
122 |
|
123 connectStatus = connect( |
|
124 mCancelAction, |
|
125 SIGNAL(triggered()), |
|
126 this, |
|
127 SLOT(handleCancelAction())); |
|
128 Q_ASSERT(connectStatus == true); |
|
129 |
|
130 connectStatus = connect( |
|
131 mNextAction, |
|
132 SIGNAL(triggered()), |
|
133 this, |
|
134 SLOT(handleNextAction())); |
|
135 Q_ASSERT(connectStatus == true); |
|
136 |
|
137 show(); |
|
138 |
|
139 OstTraceFunctionExit0(WLANLOGINVIEW_WLANLOGINVIEW_EXIT); |
|
140 } |
|
141 |
|
142 /*! |
|
143 Loads widgets and objects from the docml file. |
|
144 */ |
|
145 void WlanLoginView::loadDocml() |
|
146 { |
|
147 OstTraceFunctionEntry0( WLANLOGINVIEW_LOADDOCML_ENTRY ); |
|
148 |
|
149 setObjectName(QString("wlanLoginView")); |
|
150 QObjectList objectList; |
|
151 objectList.append(this); |
|
152 mDocLoader->setObjectTree(objectList); |
|
153 |
|
154 bool ok = false; |
|
155 |
|
156 mDocLoader->load(wlanLoginViewDocml, &ok); |
|
157 Q_ASSERT(ok); |
|
158 |
|
159 //Fetch pointer for progress bar |
|
160 mProgressBar = reinterpret_cast<HbProgressBar *>( |
|
161 mDocLoader->findObject("progressBar")); |
|
162 Q_ASSERT(mProgressBar); |
|
163 |
|
164 //Fetch pointer for scroll area content |
|
165 mScrollAreaContent = reinterpret_cast<HbWidget *>( |
|
166 mDocLoader->findObject("scrollAreaContent")); |
|
167 Q_ASSERT(mScrollAreaContent); |
|
168 |
|
169 //Fetch pointer for Web View |
|
170 mWebView = reinterpret_cast<WlanLoginWebView *>( |
|
171 mDocLoader->findObject("webView")); |
|
172 Q_ASSERT(mWebView); |
|
173 |
|
174 //Fetch pointer for cancel action |
|
175 mCancelAction = qobject_cast<HbAction*> ( |
|
176 mDocLoader->findObject("cancelAction")); |
|
177 Q_ASSERT(mCancelAction != NULL); |
|
178 |
|
179 //Fetch pointer for next action |
|
180 mNextAction = qobject_cast<HbAction*> ( |
|
181 mDocLoader->findObject("nextAction")); |
|
182 Q_ASSERT(mNextAction != NULL); |
|
183 |
|
184 OstTraceFunctionExit0( WLANLOGINVIEW_LOADDOCML_EXIT ); |
|
185 } |
|
186 |
|
187 /*! |
|
188 Destructor |
|
189 */ |
|
190 WlanLoginView::~WlanLoginView() |
|
191 { |
|
192 OstTraceFunctionEntry0(WLANLOGINVIEW_DESTRUCTOR_ENTRY); |
|
193 |
|
194 OstTraceFunctionExit0(WLANLOGINVIEW_DESTRUCTOR_EXIT); |
|
195 } |
|
196 |
|
197 |
|
198 /*! |
|
199 This function handles connectionReady signal from engine and starts loading of |
|
200 provided web page |
|
201 |
|
202 @param [in] url URL to be loaded |
|
203 */ |
|
204 void WlanLoginView::handleConnectionReady(QUrl url) |
|
205 { |
|
206 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECONNECTIONREADY_ENTRY); |
|
207 |
|
208 mWebView->load(url); |
|
209 |
|
210 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECONNECTIONREADY_EXIT); |
|
211 } |
|
212 |
|
213 |
|
214 /*! |
|
215 This function handles orientationChanged signal |
|
216 |
|
217 @param [in] orientation New Orientation of the screen |
|
218 */ |
|
219 void WlanLoginView::handleOrientationChanged(Qt::Orientation orientation) |
|
220 { |
|
221 Q_UNUSED(orientation); |
|
222 OstTraceFunctionEntry0( WLANLOGINVIEW_ORIENTATIONCHANGED_ENTRY ); |
|
223 |
|
224 adjustViewSize(); |
|
225 |
|
226 OstTraceFunctionEntry0( WLANLOGINVIEW_ORIENTATIONCHANGED_EXIT ); |
|
227 } |
|
228 |
|
229 void WlanLoginView::adjustViewSize() |
|
230 { |
|
231 OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY ); |
|
232 |
|
233 //Store current screen size |
|
234 QSizeF screenSize = mMainWindow->layoutRect().size(); |
|
235 |
|
236 //Store current content size |
|
237 QSize contentSize = mWebView->page()->mainFrame()->contentsSize(); |
|
238 |
|
239 //Set viewPortSize to biggest values of content size or current screen size |
|
240 QSize newViewPortSize; |
|
241 if (screenSize.toSize().width() > contentSize.width()) { |
|
242 newViewPortSize.setWidth(screenSize.toSize().width()); |
|
243 } else { |
|
244 newViewPortSize.setWidth(contentSize.width()); |
|
245 } |
|
246 |
|
247 if (screenSize.toSize().height() > contentSize.height()) { |
|
248 newViewPortSize.setHeight(screenSize.toSize().height()); |
|
249 } else { |
|
250 newViewPortSize.setHeight(contentSize.height()); |
|
251 } |
|
252 mWebView->page()->setViewportSize(newViewPortSize); |
|
253 |
|
254 |
|
255 //Set Web View size to same size as viewport |
|
256 mWebView->setMinimumWidth((qreal)newViewPortSize.width()); |
|
257 mWebView->setMaximumWidth((qreal)newViewPortSize.width()); |
|
258 mWebView->setPreferredWidth((qreal)newViewPortSize.width()); |
|
259 |
|
260 mWebView->setMinimumHeight((qreal)newViewPortSize.height()); |
|
261 mWebView->setMaximumHeight((qreal)newViewPortSize.height()); |
|
262 mWebView->setPreferredHeight((qreal)newViewPortSize.height()); |
|
263 |
|
264 |
|
265 //Set preferred content size to current screen size |
|
266 mWebView->page()->setPreferredContentsSize(mMainWindow->layoutRect().size().toSize()); |
|
267 |
|
268 OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT ); |
|
269 } |
|
270 |
|
271 |
|
272 /*! |
|
273 This function handles urlChanged signal from QGraphicsWebView |
|
274 |
|
275 @param [in] newUrl New URL |
|
276 */ |
|
277 void WlanLoginView::handleUrlChanged(const QUrl& newUrl ) |
|
278 { |
|
279 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEURLCHANGED_ENTRY); |
|
280 |
|
281 #ifdef OST_TRACE_COMPILER_IN_USE |
|
282 QString url = newUrl.toString(); |
|
283 TPtrC tmp(url.utf16(),url.length() ); |
|
284 |
|
285 OstTraceExt1( |
|
286 TRACE_NORMAL, |
|
287 WLANLOGINVIEW_HANDLEURLCHANGED_URL_TRACE, |
|
288 "WlanLoginEngine::handleUrlChanged;newUrl=%S", |
|
289 tmp); |
|
290 #endif |
|
291 |
|
292 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEURLCHANGED_EXIT); |
|
293 } |
|
294 |
|
295 |
|
296 /*! |
|
297 This function handles loadStarted signal from QGraphicsWebView |
|
298 */ |
|
299 void WlanLoginView::handleLoadStarted() |
|
300 { |
|
301 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADSTARTED_ENTRY); |
|
302 |
|
303 mProgressBar->setVisible(true); |
|
304 |
|
305 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADSTARTED_EXIT); |
|
306 } |
|
307 |
|
308 |
|
309 /*! |
|
310 This function handles loadProgress signal from QGraphicsWebView |
|
311 |
|
312 @param [in] progressValue Indicates page loading progress: 0..100 |
|
313 */ |
|
314 void WlanLoginView::handleLoadProgress(int progressValue) |
|
315 { |
|
316 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADPROGRESS_ENTRY); |
|
317 |
|
318 mProgressBar->setProgressValue(progressValue); |
|
319 |
|
320 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADPROGRESS_EXIT); |
|
321 } |
|
322 |
|
323 |
|
324 /*! |
|
325 This function handles loadfinished signal from QGraphicsWebView |
|
326 |
|
327 @param [in] status Success status |
|
328 */ |
|
329 void WlanLoginView::handleLoadFinished(bool status) |
|
330 { |
|
331 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADFINISHED_ENTRY); |
|
332 |
|
333 if(status) |
|
334 { |
|
335 adjustViewSize(); |
|
336 } |
|
337 |
|
338 mProgressBar->setVisible(false); |
|
339 |
|
340 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADFINISHED_EXIT); |
|
341 } |
|
342 |
|
343 |
|
344 /*! |
|
345 This function handles formSumitted signal from WlanLoginWebPage |
|
346 |
|
347 */ |
|
348 void WlanLoginView::handleFormSubmitted() |
|
349 { |
|
350 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_ENTRY); |
|
351 |
|
352 //User has submitted credentials, let's start internet connectivity test |
|
353 emit startIcts(); |
|
354 |
|
355 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_EXIT); |
|
356 } |
|
357 |
|
358 |
|
359 /*! |
|
360 This function handles triggered signal from "cancel" button |
|
361 |
|
362 */ |
|
363 void WlanLoginView::handleCancelAction() |
|
364 { |
|
365 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECANCELACTION_ENTRY); |
|
366 |
|
367 mWebView->stop(); |
|
368 emit cancelTriggered(); |
|
369 |
|
370 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECANCELACTION_EXIT); |
|
371 } |
|
372 |
|
373 |
|
374 /*! |
|
375 This function handles triggered signal from "next" button |
|
376 |
|
377 */ |
|
378 void WlanLoginView::handleNextAction() |
|
379 { |
|
380 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLENEXTACTION_ENTRY); |
|
381 |
|
382 emit nextTriggered(); |
|
383 |
|
384 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLENEXTACTION_EXIT); |
|
385 } |
|
386 |
|
387 |
|
388 /*! |
|
389 This function handles ictsOk signal from engine |
|
390 |
|
391 */ |
|
392 void WlanLoginView::handleIctsOk() |
|
393 { |
|
394 OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEICTSRESULT_ENTRY); |
|
395 |
|
396 mNextAction->setEnabled(true); |
|
397 |
|
398 //Send application to background automatically only in first successfull login |
|
399 //as in other cases WLAN Wizard won't exist in the underneath |
|
400 if (mFirstIctsOkResult) { |
|
401 mFirstIctsOkResult = false; |
|
402 emit nextTriggered(); |
|
403 } |
|
404 |
|
405 OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEICTSRESULT_EXIT); |
|
406 } |
|
407 |
|