|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implementation of CWsfMainView. |
|
15 * |
|
16 */ |
|
17 |
|
18 //External Includes |
|
19 #include <coemain.h> |
|
20 #include <eikmenub.h> |
|
21 #include <aknViewAppUi.h> |
|
22 #include <wlansniffer.rsg> |
|
23 #include <featmgr.h> |
|
24 #include <rconnmon.h> |
|
25 #include <apgcli.h> |
|
26 |
|
27 //Internal Includes |
|
28 #include "wsfdocument.h" |
|
29 #include "wsfwlaninfoarrayvisitor.h" |
|
30 #include "wsfwlaninfoarray.h" |
|
31 #include "wsfmainview.h" |
|
32 #include "wsfmainviewmodel.h" |
|
33 #include "wsfmainviewcontainer.h" |
|
34 #include "wsfmainapplication.hrh" |
|
35 #include "wsfactivewaiter.h" |
|
36 #include "wsfappui.h" |
|
37 |
|
38 #include "wsflogger.h" |
|
39 |
|
40 |
|
41 // Standard construction sequence |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // CWsfMainView::NewL |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CWsfMainView* CWsfMainView::NewL( TBool aIsEmbedded ) |
|
48 { |
|
49 LOG_ENTERFN( "CWsfMainView::NewL" ); |
|
50 CWsfMainView* self = CWsfMainView::NewLC( aIsEmbedded ); |
|
51 CleanupStack::Pop( self ); |
|
52 return self; |
|
53 } |
|
54 |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CWsfMainView::NewLC |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 CWsfMainView* CWsfMainView::NewLC( TBool aIsEmbedded ) |
|
61 { |
|
62 LOG_ENTERFN( "CWsfMainView::NewLC" ); |
|
63 CWsfMainView* self = new ( ELeave ) CWsfMainView; |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL( aIsEmbedded ); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CWsfMainView::CWsfMainView |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 CWsfMainView::CWsfMainView() |
|
75 { |
|
76 // no implementation required |
|
77 } |
|
78 |
|
79 |
|
80 // --------------------------------------------------------------------------- |
|
81 // CWsfMainView::~CWsfMainView |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 CWsfMainView::~CWsfMainView() |
|
85 { |
|
86 LOG_ENTERFN( "CWsfMainView::~CWsfMainView" ); |
|
87 if ( iContainer ) |
|
88 { |
|
89 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
90 } |
|
91 |
|
92 delete iContainer; |
|
93 delete iModel; |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CWsfMainView::ConstructL |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CWsfMainView::ConstructL( TBool aIsEmbedded ) |
|
102 { |
|
103 LOG_ENTERFN( "CWsfMainView::ConstructL" ); |
|
104 TInt actView( NULL ); |
|
105 |
|
106 if ( aIsEmbedded ) // started from CP |
|
107 { |
|
108 actView = R_SNIFFER_CP_MAINVIEW; |
|
109 } |
|
110 else |
|
111 { |
|
112 actView = R_SNIFFER_MAINVIEW; |
|
113 } |
|
114 |
|
115 BaseConstructL( actView ); |
|
116 iModel = CWsfMainViewModel::NewL(); |
|
117 iController.SetModel( iModel ); |
|
118 } |
|
119 |
|
120 |
|
121 // --------------------------------------------------------------------------- |
|
122 // CWsfMainView::Id |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TUid CWsfMainView::Id() const |
|
126 { |
|
127 return TUid::Uid( EMainViewId ); |
|
128 } |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // CWsfMainView::HandleCommandL |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CWsfMainView::HandleCommandL( TInt aCommand ) |
|
136 { |
|
137 switch ( aCommand ) |
|
138 { |
|
139 case EAknSoftkeyOk: |
|
140 { |
|
141 break; |
|
142 } |
|
143 case EAknSoftkeyBack: |
|
144 { |
|
145 AppUi()->HandleCommandL( EAknCmdExit ); |
|
146 break; |
|
147 } |
|
148 case EAknSoftkeyContextOptions: |
|
149 { |
|
150 MenuBar()->SetMenuTitleResourceId( R_SNIFFER_CONTEXT_MENUBAR ); |
|
151 MenuBar()->SetMenuType( CEikMenuBar::EMenuContext ); |
|
152 MenuBar()->TryDisplayMenuBarL(); |
|
153 MenuBar()->SetMenuTitleResourceId( R_SNIFFER_MENUBAR ); |
|
154 MenuBar()->SetMenuType( CEikMenuBar::EMenuOptions ); |
|
155 break; |
|
156 } |
|
157 default: |
|
158 { |
|
159 AppUi()->HandleCommandL( aCommand ); |
|
160 break; |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CWsfMainView::DoActivateL |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CWsfMainView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, |
|
171 TUid /*aCustomMessageId*/, |
|
172 const TDesC8& /*aCustomMessage*/) |
|
173 { |
|
174 LOG_ENTERFN( "CWsfMainView::DoActivateL" ); |
|
175 if ( !iContainer ) |
|
176 { |
|
177 iContainer = CWsfMainViewContainer::NewL( ClientRect() ); |
|
178 // set icons array to list |
|
179 iContainer->SetMopParent( this ); |
|
180 iContainer->SetPartner( iController ); |
|
181 iContainer->ListBox()->SetListBoxObserver( this ); |
|
182 AppUi()->AddToViewStackL( *this, iContainer ); |
|
183 iController.SetContainer( iContainer ); |
|
184 } |
|
185 |
|
186 iContainer->MakeVisible( ETrue ); |
|
187 iController.RefreshL(); |
|
188 MenuBar()->SetContextMenuTitleResourceId( R_SNIFFER_CONTEXT_MENUBAR ); |
|
189 } |
|
190 |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CWsfMainView::DoDeactivate |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CWsfMainView::DoDeactivate() |
|
197 { |
|
198 LOG_ENTERFN( "CWsfMainView::DoDeactivate" ); |
|
199 if ( iContainer ) |
|
200 { |
|
201 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
202 iController.SetContainer( NULL ); |
|
203 delete iContainer; |
|
204 iContainer = NULL; |
|
205 } |
|
206 } |
|
207 |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CWsfMainView::Controller |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 MWsfMainViewControllerIf& CWsfMainView::Controller() |
|
214 { |
|
215 return iController; |
|
216 } |
|
217 |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // CWsfMainView::DynInitMenuPaneL |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CWsfMainView::DynInitMenuPaneL( TInt aResourceId, |
|
224 CEikMenuPane* aMenuPane ) |
|
225 { |
|
226 iController.UpdateSelectedItemL(); |
|
227 |
|
228 if ( aResourceId == R_SNIFFER_MENU ) |
|
229 { |
|
230 LOG_ENTERFN( "CWsfMainView::DynInitMenuPaneL" ); |
|
231 const CWsfDocument* doc = static_cast<const CWsfDocument*>( |
|
232 AppUi()->Document() ); |
|
233 TBool blacklistEmpty( !doc->WlanInfoBranding().BlackListItemCount() ); |
|
234 TWsfWlanInfo *selectedItem = iController.SelectedItem(); |
|
235 CWsfWlanInfoArray *infoArray = iModel->GetInfoArray(); |
|
236 |
|
237 CWsfAppUi* appui = static_cast<CWsfAppUi*>( AppUi() ); |
|
238 TBool connecting( appui->SuppressingKeyEvents() ); |
|
239 |
|
240 if ( !selectedItem ) |
|
241 { |
|
242 // no real items available, but hidden item is present |
|
243 aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, EFalse ); |
|
244 aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, ETrue ); |
|
245 aMenuPane->SetItemDimmed( ESnifferCmdConnect, EFalse ); |
|
246 aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, ETrue ); |
|
247 aMenuPane->SetItemDimmed( ESnifferCmdRefresh, connecting ); |
|
248 aMenuPane->SetItemDimmed( ESnifferCmdFilterWlans, |
|
249 connecting || !infoArray || blacklistEmpty ); |
|
250 aMenuPane->SetItemDimmed( ESnifferCmdDetails, ETrue ); |
|
251 aMenuPane->SetItemDimmed( ESnifferCmdSettings, connecting ); |
|
252 return; |
|
253 } |
|
254 |
|
255 TBool connectedAndUsed( StartWebBrowsingVisibleL() ); |
|
256 TBool connected( selectedItem->Connected() ); |
|
257 TBool known( selectedItem->Known() ); |
|
258 |
|
259 TBool selectedItemConnecting ( |
|
260 selectedItem->ConnectionStatus() == EConnecting ); |
|
261 |
|
262 aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, |
|
263 connectedAndUsed || selectedItemConnecting ); |
|
264 aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, |
|
265 !connectedAndUsed || selectedItemConnecting ); |
|
266 |
|
267 aMenuPane->SetItemDimmed( ESnifferCmdConnect, |
|
268 connected || selectedItemConnecting ); |
|
269 |
|
270 aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, |
|
271 !connected && !selectedItemConnecting); |
|
272 |
|
273 aMenuPane->SetItemDimmed( ESnifferCmdRefresh, connecting ); |
|
274 |
|
275 // dim filtering if no scan has been performed |
|
276 // or there is nothing to filter |
|
277 aMenuPane->SetItemDimmed( ESnifferCmdFilterWlans, |
|
278 connecting || |
|
279 !infoArray || |
|
280 ( blacklistEmpty && |
|
281 ( !infoArray->Count() || |
|
282 ( infoArray->Count() == 1 && |
|
283 (*infoArray)[0]->Connected() ) ) ) ); |
|
284 |
|
285 aMenuPane->SetItemDimmed( ESnifferCmdDetails, |
|
286 connecting || |
|
287 selectedItem->Hidden() && !known ); |
|
288 aMenuPane->SetItemDimmed( ESnifferCmdSettings, connecting ); |
|
289 } |
|
290 else if ( aResourceId == R_SNIFFER_CONTEXT_MENU ) |
|
291 { |
|
292 TWsfWlanInfo *selectedItem = iController.SelectedItem(); |
|
293 |
|
294 // there must be always at least one item: "Other (unlisted)..." |
|
295 TBool connectedAndUsed( StartWebBrowsingVisibleL() ); |
|
296 TBool connected( EFalse ); |
|
297 TBool known( EFalse ); |
|
298 TBool hidden( ETrue ); |
|
299 |
|
300 CWsfAppUi* appui = static_cast<CWsfAppUi*>( AppUi() ); |
|
301 TBool connecting( appui->SuppressingKeyEvents() ); |
|
302 TBool selectedItemConnecting( EFalse ); |
|
303 |
|
304 if ( selectedItem ) |
|
305 { |
|
306 // workaround: even if the model reports no elements, we know that |
|
307 // the hidden item must always be there |
|
308 connected = selectedItem->Connected(); |
|
309 known = selectedItem->Known(); |
|
310 hidden = selectedItem->Hidden(); |
|
311 selectedItemConnecting = |
|
312 ( selectedItem->ConnectionStatus() == EConnecting ); |
|
313 } |
|
314 |
|
315 aMenuPane->SetItemDimmed( ESnifferCmdStartBrowsing, |
|
316 connectedAndUsed || selectedItemConnecting ); |
|
317 aMenuPane->SetItemDimmed( ESnifferCmdContinueBrowsing, |
|
318 !connectedAndUsed || selectedItemConnecting ); |
|
319 |
|
320 aMenuPane->SetItemDimmed( ESnifferCmdConnect, |
|
321 connected || selectedItemConnecting ); |
|
322 aMenuPane->SetItemDimmed( ESnifferCmdDisconnect, |
|
323 !connected && !selectedItemConnecting ); |
|
324 aMenuPane->SetItemDimmed( ESnifferCmdDetails, |
|
325 connecting || hidden && !known ); |
|
326 } |
|
327 |
|
328 } |
|
329 |
|
330 |
|
331 // --------------------------------------------------------------------------- |
|
332 // CWsfMainView::HandleListBoxEventL |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 void CWsfMainView::HandleListBoxEventL( CEikListBox* /*aListBox*/, |
|
336 TListBoxEvent aEventType ) |
|
337 { |
|
338 switch ( aEventType ) |
|
339 { |
|
340 case EEventEnterKeyPressed: |
|
341 case EEventItemSingleClicked: |
|
342 { |
|
343 HandleCommandL( EAknSoftkeyContextOptions ); |
|
344 } |
|
345 break; |
|
346 default: |
|
347 break; |
|
348 } |
|
349 } |
|
350 |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CWsfMainView::SelectionKeyPressed |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CWsfMainView::SelectionKeyPressed() |
|
357 { |
|
358 iSelectionKey = ETrue; |
|
359 } |
|
360 |
|
361 |
|
362 // --------------------------------------------------------------------------- |
|
363 // CWsfMainView::StartWebBrowsingVisibleL |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 TBool CWsfMainView::StartWebBrowsingVisibleL() |
|
367 { |
|
368 LOG_ENTERFN( "CWsfMainView::StartWebBrowsingVisibleL" ); |
|
369 const TInt KBrowserUid = 0x10008D39; |
|
370 TUid id( TUid::Uid( KBrowserUid ) ); |
|
371 |
|
372 // Check if the Browser application is already running. |
|
373 TApaTaskList taskList( iEikonEnv->WsSession() ); |
|
374 TApaTask task = taskList.FindApp( id ); |
|
375 TBool isBrowserRuning( EFalse ); |
|
376 |
|
377 #ifndef __WINS__ |
|
378 |
|
379 if ( task.Exists() ) |
|
380 { |
|
381 LOG_WRITE( "The Browser is running." ); |
|
382 // The Browser is already running. |
|
383 // Check if the selected WLAN is connected. |
|
384 TWsfWlanInfo* selectedItem = iController.SelectedItem(); |
|
385 TBool connected( EFalse ); |
|
386 if( selectedItem ) |
|
387 { |
|
388 connected = selectedItem->Connected(); |
|
389 } |
|
390 LOG_WRITEF("Selected network Connected? %d", connected); |
|
391 |
|
392 if ( connected ) |
|
393 { |
|
394 RConnectionMonitor connectionMonitor; |
|
395 connectionMonitor.ConnectL(); |
|
396 // We have to check if the Browser using the selected |
|
397 // connection. |
|
398 // We have get the connectiond ID first. |
|
399 CWsfActiveWaiter* waiter = CWsfActiveWaiter::NewL(); |
|
400 CleanupStack::PushL( waiter ); |
|
401 |
|
402 // first call, need to get the connection parameters |
|
403 TUint connectionCount( 0 ); |
|
404 |
|
405 connectionMonitor.GetConnectionCount( connectionCount, |
|
406 waiter->iStatus ); |
|
407 waiter->WaitForRequest(); |
|
408 |
|
409 // find the connection with WLAN bearer |
|
410 // that will be the selected WLAN |
|
411 TUint connectionId( 0 ); |
|
412 for ( TUint i = 1; i <= connectionCount; ++i ) |
|
413 { |
|
414 TUint tmpConnectionId( 0 ); |
|
415 TUint subConnectionCount( 0 ); |
|
416 TConnMonBearerType bearerType( EBearerUnknown ); |
|
417 |
|
418 connectionMonitor.GetConnectionInfo( i, |
|
419 tmpConnectionId, |
|
420 subConnectionCount ); |
|
421 connectionMonitor.GetIntAttribute( tmpConnectionId, |
|
422 0, |
|
423 KBearer, |
|
424 ( TInt& )bearerType, |
|
425 waiter->iStatus ); |
|
426 waiter->WaitForRequest(); |
|
427 if( bearerType == EBearerWLAN ) |
|
428 { |
|
429 connectionId = tmpConnectionId; |
|
430 break; |
|
431 } |
|
432 } |
|
433 // Now we have the connectiond ID. |
|
434 LOG_WRITEF( "connectionId: %d", connectionId ); |
|
435 |
|
436 TInt count( 0 ); |
|
437 TConnMonClientEnumBuf clientBuf; |
|
438 |
|
439 connectionMonitor.GetPckgAttribute( connectionId, |
|
440 0, |
|
441 KClientInfo, |
|
442 clientBuf, |
|
443 waiter->iStatus ); |
|
444 waiter->WaitForRequest(); |
|
445 if ( !waiter->iStatus.Int() ) |
|
446 { |
|
447 count = clientBuf().iCount; |
|
448 } |
|
449 |
|
450 RApaLsSession appSess; |
|
451 TApaAppInfo appInfo; |
|
452 |
|
453 // The connection could be shared by several applications |
|
454 User::LeaveIfError( appSess.Connect() ); |
|
455 |
|
456 TUint i; |
|
457 for ( i = 0; i < count; i++ ) |
|
458 { |
|
459 appInfo.iCaption.Zero(); |
|
460 TInt result = appSess.GetAppInfo( appInfo, |
|
461 clientBuf().iUid[i] ); |
|
462 |
|
463 LOG_WRITEF( "result: %d", result ); |
|
464 LOG_WRITEF( "iClientInfo.iUid[i].iUid: %x", |
|
465 clientBuf().iUid[i].iUid ); |
|
466 |
|
467 if ( clientBuf().iUid[i].iUid == KBrowserUid ) |
|
468 { |
|
469 isBrowserRuning = ETrue; |
|
470 } |
|
471 } |
|
472 CleanupStack::PopAndDestroy( waiter ); |
|
473 appSess.Close(); |
|
474 connectionMonitor.Close(); |
|
475 } |
|
476 } |
|
477 else |
|
478 { |
|
479 LOG_WRITE( "No Browser running." ); |
|
480 } |
|
481 |
|
482 #endif // __WINS__ |
|
483 |
|
484 LOG_WRITEF( "isBrowserRuning: %d", isBrowserRuning ); |
|
485 return isBrowserRuning; |
|
486 } |
|
487 |
|
488 |
|
489 |
|
490 // End of file |