|
1 /* |
|
2 * Copyright (c) 2009-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 * WLAN Sniffer main window. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 |
|
22 #include "wlanqtutils.h" |
|
23 #include "wlanqtutilsap.h" |
|
24 |
|
25 #include "wlanwizard.h" |
|
26 |
|
27 #include "wlansnifferengine.h" |
|
28 #include "wlansnifferlistview.h" |
|
29 #include "wlansniffermainwindow.h" |
|
30 |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "wlansniffermainwindowTraces.h" |
|
34 #endif |
|
35 |
|
36 /*! |
|
37 \class WlanSnifferMainWindow |
|
38 \brief WLAN Sniffer main window. |
|
39 */ |
|
40 |
|
41 // External function prototypes |
|
42 |
|
43 // Local constants |
|
44 |
|
45 // ======== LOCAL FUNCTIONS ======== |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 /*! |
|
50 Constructor. |
|
51 |
|
52 @param [in] engine WLAN Sniffer application engine. |
|
53 */ |
|
54 |
|
55 WlanSnifferMainWindow::WlanSnifferMainWindow(WlanSnifferEngine *engine) : |
|
56 mWizard(0), |
|
57 mListView(0), |
|
58 mEngine(engine) |
|
59 { |
|
60 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOW_ENTRY); |
|
61 |
|
62 // Add the list view to the main window |
|
63 addListView(); |
|
64 bool connectStatus = connect( |
|
65 mEngine, |
|
66 SIGNAL(toListView(QString)), |
|
67 this, |
|
68 SLOT(toListView(QString))); |
|
69 Q_ASSERT(connectStatus == true); |
|
70 |
|
71 // When using WLAN Sniffer service, the view show is called after the service |
|
72 // request arrives. |
|
73 if (!mEngine->isEmbedded()) { |
|
74 // Show the list view |
|
75 toListView(hbTrId("txt_occ_title_wireless_lan")); |
|
76 } |
|
77 |
|
78 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOW_EXIT); |
|
79 } |
|
80 |
|
81 /*! |
|
82 Destructor. |
|
83 */ |
|
84 |
|
85 WlanSnifferMainWindow::~WlanSnifferMainWindow() |
|
86 { |
|
87 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOWDESTR_ENTRY); |
|
88 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOWDESTR_EXIT); |
|
89 } |
|
90 |
|
91 /*! |
|
92 Shows the WLAN Sniffer list view. |
|
93 |
|
94 @param [in] title View title. |
|
95 */ |
|
96 |
|
97 void WlanSnifferMainWindow::toListView(const QString &title) |
|
98 { |
|
99 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_ENTRY); |
|
100 |
|
101 // Show the list view |
|
102 mListView->setTitle(title); |
|
103 setCurrentView(mListView); |
|
104 show(); |
|
105 |
|
106 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_EXIT); |
|
107 } |
|
108 |
|
109 /*! |
|
110 Creates and adds the WLAN List View to main window. |
|
111 */ |
|
112 |
|
113 void WlanSnifferMainWindow::addListView() |
|
114 { |
|
115 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_ADDLISTVIEW_ENTRY); |
|
116 |
|
117 mListView = new WlanSnifferListView(mEngine, this); |
|
118 addView(mListView); |
|
119 |
|
120 bool connectStatus = connect( |
|
121 mListView, |
|
122 SIGNAL(wizardTriggered(const WlanQtUtilsAp *)), |
|
123 this, |
|
124 SLOT(startWlanWizard(const WlanQtUtilsAp *))); |
|
125 |
|
126 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_ADDLISTVIEW_EXIT); |
|
127 } |
|
128 |
|
129 /*! |
|
130 Starts WLAN Wizard for new WLAN IAP creation. |
|
131 |
|
132 @param [in] ap WLAN Access Point to create, or NULL for adding WLAN manually. |
|
133 */ |
|
134 |
|
135 void WlanSnifferMainWindow::startWlanWizard(const WlanQtUtilsAp *ap) |
|
136 { |
|
137 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_STARTWLANWIZARD_ENTRY); |
|
138 |
|
139 Q_ASSERT(mWizard == NULL); |
|
140 |
|
141 // Stop WLAN scanning for the duration of WLAN Wizard |
|
142 mEngine->stopWlanScanning(); |
|
143 |
|
144 mWizard = QSharedPointer<WlanWizard>(new WlanWizard(this)); |
|
145 bool connectStatus = connect( |
|
146 mWizard.data(), |
|
147 SIGNAL(finished(int,bool)), |
|
148 this, |
|
149 SLOT(handleWlanWizardComplete(int,bool)), |
|
150 Qt::QueuedConnection); |
|
151 Q_ASSERT(connectStatus == true); |
|
152 |
|
153 connectStatus = connect( |
|
154 mWizard.data(), |
|
155 SIGNAL(cancelled()), |
|
156 this, |
|
157 SLOT(handleWlanWizardCancelled()), |
|
158 Qt::QueuedConnection); |
|
159 Q_ASSERT(connectStatus == true); |
|
160 |
|
161 // Create an IAP for a specific AP |
|
162 if (ap) { |
|
163 mWizard->setParameters( |
|
164 ap->value(WlanQtUtilsAp::ConfIdSsid).toString(), |
|
165 ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), |
|
166 ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), |
|
167 ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toInt(), |
|
168 ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool()); |
|
169 } |
|
170 // else: Add WLAN IAP manually |
|
171 |
|
172 mWizard->show(); |
|
173 |
|
174 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_STARTWLANWIZARD_EXIT); |
|
175 } |
|
176 |
|
177 /*! |
|
178 WLAN Wizard successful completion handler. |
|
179 |
|
180 @param [in] iapId IAP ID of the new WLAN IAP. |
|
181 @param [in] connected TRUE if connected. |
|
182 */ |
|
183 |
|
184 void WlanSnifferMainWindow::handleWlanWizardComplete( |
|
185 int iapId, |
|
186 bool connected) |
|
187 { |
|
188 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_ENTRY); |
|
189 |
|
190 // The wizard must exist |
|
191 Q_ASSERT(mWizard); |
|
192 |
|
193 // Enable scanning again |
|
194 mEngine->startWlanScanning(); |
|
195 |
|
196 if (connected) { |
|
197 // The IAP ID must be valid |
|
198 Q_ASSERT(iapId != WlanQtUtils::IapIdNone); |
|
199 |
|
200 // Connect (share) the new IAP in order to keep the connection open when |
|
201 // deleting Wizard. |
|
202 mEngine->wlanQtUtils()->connectIap(iapId, false); |
|
203 } |
|
204 // else: created IAP not connected at all, or already dropped |
|
205 // (probably due to being out of coverage) so don't try to share it |
|
206 |
|
207 // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection. |
|
208 mWizard.clear(); |
|
209 |
|
210 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_EXIT); |
|
211 } |
|
212 |
|
213 /*! |
|
214 WLAN Wizard cancellation handler. |
|
215 */ |
|
216 |
|
217 void WlanSnifferMainWindow::handleWlanWizardCancelled() |
|
218 { |
|
219 OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_ENTRY); |
|
220 |
|
221 // The wizard must exist |
|
222 Q_ASSERT(mWizard); |
|
223 |
|
224 // Enable scanning again |
|
225 mEngine->startWlanScanning(); |
|
226 |
|
227 // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection. |
|
228 mWizard.clear(); |
|
229 |
|
230 OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_EXIT); |
|
231 } |