connectionutilities/ConnectionDialogs/ConnectionUiUtilities/NotifSrc/ActiveSelectWLanDlgPlugin.cpp
changeset 0 5a93021fdf25
child 12 ea6e024ea6f9
child 41 bbb64eb3bdee
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2005 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 CActiveSelectWLanDlgPlugin.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknWaitDialog.h>
       
    21 #include <ConnUiUtilsNotif.rsg>
       
    22 #include <AknGlobalNote.h>
       
    23 #include <StringLoader.h>
       
    24 #include <centralrepository.h>
       
    25 #include <AknSgcc.h>
       
    26 #include <AknCapServerClient.h>
       
    27 //#include <aknnotewrappers.h>
       
    28 
       
    29 #include "ActiveSelectWLanDlgPlugin.h"
       
    30 #include "SelectWLANDlg.h"
       
    31 #include "ConnectionDialogsLogger.h"
       
    32 #include "ConnectionUiUtilitiesPrivateCRKeys.h"
       
    33 
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 /**
       
    38 * For iPeriodic Timer, 10 seconds
       
    39 * The interval between refreshing available wlan networks.
       
    40 */
       
    41 LOCAL_D const TInt KTickDefaultInterval = 10000000;
       
    42 
       
    43 // ================= MEMBER FUNCTIONS =======================
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CActiveSelectWLanDlgPlugin* CActiveSelectWLanDlgPlugin::NewL()
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 CActiveSelectWLanDlgPlugin* CActiveSelectWLanDlgPlugin::NewL( 
       
    50                                               CSelectWLanDlgPlugin* aPlugin )
       
    51     {
       
    52     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::NewL " );  
       
    53     
       
    54     CActiveSelectWLanDlgPlugin* self = 
       
    55                          new ( ELeave ) CActiveSelectWLanDlgPlugin( aPlugin );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     
       
    60     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::NewL " );      
       
    61 
       
    62     return self;        
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // CActiveSelectWLanDlgPlugin::ConstructL()
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 void CActiveSelectWLanDlgPlugin::ConstructL()
       
    70     {     
       
    71     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::ConstructL " );
       
    72        
       
    73     CActiveScheduler::Add( this );            
       
    74     iWlanDataProv = CWlanNetworkDataProvider::NewL();
       
    75     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
    76     
       
    77     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::ConstructL " );
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // CActiveSelectWLanDlgPlugin::CActiveSelectWLanDlgPlugin()
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 CActiveSelectWLanDlgPlugin::CActiveSelectWLanDlgPlugin( 
       
    85                                                 CSelectWLanDlgPlugin* aPlugin )
       
    86 : CActive( EPriorityStandard ), 
       
    87   iPlugin( aPlugin )
       
    88     {
       
    89     }
       
    90     
       
    91 // ---------------------------------------------------------
       
    92 // CActiveSelectWLanDlgPlugin::~CActiveSelectWLanDlgPlugin()
       
    93 // ---------------------------------------------------------
       
    94 //    
       
    95 CActiveSelectWLanDlgPlugin::~CActiveSelectWLanDlgPlugin()
       
    96     {
       
    97     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::~CActiveSelectWLanDlgPlugin " );
       
    98     Cancel();
       
    99 
       
   100     StopTimer();
       
   101     DestroyWaitDialog();
       
   102 
       
   103     if ( iResultsListDialog  && !( iResultsListDialog->GetOkToExit() ) )
       
   104         {
       
   105         CLOG_WRITEF( _L( "OkToExit %b" ), iResultsListDialog->GetOkToExit() );
       
   106         delete iResultsListDialog;
       
   107         iResultsListDialog = NULL;
       
   108         }
       
   109     
       
   110     delete iWlanDataProv;
       
   111 
       
   112     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::~CActiveSelectWLanDlgPlugin " );
       
   113     }
       
   114 
       
   115 
       
   116 // ---------------------------------------------------------
       
   117 // CActiveSelectWLanDlgPlugin::DoCancel()
       
   118 // ---------------------------------------------------------
       
   119 // 
       
   120 void CActiveSelectWLanDlgPlugin::DoCancel()
       
   121     {
       
   122     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::DoCancel " );
       
   123 
       
   124     CLOG_WRITE( "stopping timer" );
       
   125     StopTimer();
       
   126 
       
   127     CLOG_WRITE( "deleting results list dialog" );
       
   128     DestroyResultsListDialog();
       
   129 
       
   130     CLOG_WRITE( "deleting wait dialog" );
       
   131     DestroyWaitDialog();
       
   132 
       
   133     CLOG_WRITE( "deleting wlan data provider" );
       
   134     delete iWlanDataProv;
       
   135     iWlanDataProv = NULL;
       
   136 
       
   137     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::DoCancel " );
       
   138     }
       
   139     
       
   140 // ---------------------------------------------------------
       
   141 // CActiveSelectWLanDlgPlugin::StartTimerL
       
   142 // ---------------------------------------------------------
       
   143 //    
       
   144 void CActiveSelectWLanDlgPlugin::StartTimerL( TInt aTickInterval )
       
   145     {    
       
   146     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::StartTimerL " );  
       
   147     
       
   148     if( !iPeriodic )
       
   149         {
       
   150         iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard ); 
       
   151         }
       
   152         
       
   153     iPeriodic->Start( aTickInterval, aTickInterval, TCallBack( Tick, this ) );
       
   154     
       
   155     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::StartTimerL " );
       
   156     }
       
   157 
       
   158 
       
   159 // ---------------------------------------------------------
       
   160 // CActiveSelectWLanDlgPlugin::StopTimer
       
   161 // ---------------------------------------------------------
       
   162 //
       
   163 void CActiveSelectWLanDlgPlugin::StopTimer()
       
   164     {
       
   165     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::StopTimer " );  
       
   166     
       
   167     if( iPeriodic )
       
   168         {
       
   169         CLOG_WRITE( "iPeriodic" );
       
   170         iPeriodic->Cancel();
       
   171         CLOG_WRITE( "Cancel" );
       
   172         
       
   173         delete iPeriodic;
       
   174         CLOG_WRITE( "delete" );
       
   175         
       
   176         iPeriodic = NULL;
       
   177         }        
       
   178     
       
   179     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::StopTimer " );
       
   180     }
       
   181     
       
   182 // ---------------------------------------------------------
       
   183 // CActiveSelectWLanDlgPlugin::DoTick
       
   184 // ---------------------------------------------------------
       
   185 //
       
   186 void CActiveSelectWLanDlgPlugin::DoTick()
       
   187     {
       
   188     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::DoTick " );
       
   189 
       
   190     if ( IsActive() == EFalse )
       
   191         {
       
   192         CLOG_WRITE( "not active anymore - making another scan request..." );
       
   193 
       
   194         SetActive();
       
   195 
       
   196 #ifdef __WINS__
       
   197         TRequestStatus* clientStatus = &iStatus;
       
   198         User::RequestComplete( clientStatus, KErrNone );
       
   199 #else
       
   200         iWlanDataProv->RefreshScanInfo( iStatus );
       
   201 #endif
       
   202         }
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CActiveSelectWLanDlgPlugin::Tick
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 TInt CActiveSelectWLanDlgPlugin::Tick( TAny* aObject )
       
   210     {
       
   211     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::Tick " );
       
   212 
       
   213     CActiveSelectWLanDlgPlugin* myself =
       
   214                         static_cast<CActiveSelectWLanDlgPlugin*>( aObject );
       
   215     myself->DoTick();
       
   216 
       
   217     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::Tick " );
       
   218 
       
   219     return 1;
       
   220     }
       
   221 
       
   222 
       
   223 // ---------------------------------------------------------
       
   224 // CActiveSelectWLanDlgPlugin::RunL()
       
   225 // ---------------------------------------------------------
       
   226 //     
       
   227 void CActiveSelectWLanDlgPlugin::RunL()
       
   228     {
       
   229     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::RunL " );  
       
   230     
       
   231     if ( iWaitDialog )
       
   232         {
       
   233         iWaitDialog->ProcessFinishedL();     
       
   234         delete iWaitDialog;
       
   235         iWaitDialog = NULL;    
       
   236         }
       
   237     
       
   238     CLOG_WRITEF( _L( "iStatus.Int() : %d" ), iStatus.Int() );
       
   239     
       
   240     if( iStatus == KErrNone )
       
   241         {             
       
   242         iWlanDataProv->OnTimerExpiredL();
       
   243         
       
   244         CNetworkInfoArray* *const networkArray = 
       
   245                                    iWlanDataProv->GetNetworkInfoArray();
       
   246          
       
   247         const TInt resultsCount = ( *networkArray )->MdcaCount();
       
   248 
       
   249         CLOG_WRITEF( _L( "resultsCount : %d" ),resultsCount );
       
   250 
       
   251         if ( resultsCount > 0 )
       
   252             {
       
   253             if( iResultsListDialog )
       
   254                 {
       
   255                 iResultsListDialog->RefreshDialogL();
       
   256                 }
       
   257             else
       
   258                 {
       
   259                 iResultsListDialog = CSelectWLANDlg::NewL( iPlugin, 
       
   260                                                            networkArray );
       
   261 
       
   262                 iResultsListDialog->ExecuteLD( R_SELECT_WLAN_LIST_QUERY );
       
   263 
       
   264                 TInt interval = GetRefreshInterval();
       
   265                 CLOG_WRITEF( _L( "interval : %d" ),  interval );
       
   266 
       
   267                 if( interval )
       
   268                     {
       
   269                     StartTimerL( interval );
       
   270                     }
       
   271                 }
       
   272             }
       
   273         else
       
   274             {
       
   275             StopTimer();
       
   276             
       
   277             DestroyWaitDialog();
       
   278             DestroyResultsListDialog();
       
   279 
       
   280             HBufC* stringLabel = StringLoader::LoadLC( 
       
   281                                                     R_INFO_NO_NETWORKS_FOUND );
       
   282 /*** Deadlock                                              
       
   283             CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
       
   284             globalNote->ShowNoteL( EAknGlobalInformationNote, *stringLabel );
       
   285 
       
   286             CleanupStack::PopAndDestroy( globalNote );
       
   287             CleanupStack::PopAndDestroy( stringLabel );
       
   288 ***/
       
   289 
       
   290 //// 3.1 solution: prevent deadlock, does not work in 3.0 because of avkon 
       
   291             RAknUiServer* globalNote = CAknSgcClient::AknSrv();
       
   292             if ( globalNote->Handle() )
       
   293                 {
       
   294                 globalNote->ShowGlobalNoteL( *stringLabel, 
       
   295                                             EAknGlobalInformationNote );
       
   296                 }
       
   297             CleanupStack::PopAndDestroy( stringLabel );
       
   298 
       
   299 //// End of 3.1 solution
       
   300 
       
   301 /*** 3.0 solution
       
   302             CAknInformationNote* myLocalGlobalNote = new ( ELeave ) 
       
   303                                                 CAknInformationNote( EFalse );
       
   304             myLocalGlobalNote->ExecuteLD( *stringLabel );
       
   305             CleanupStack::PopAndDestroy( stringLabel );
       
   306 
       
   307 *** End of 3.0 solution    ***/
       
   308             
       
   309             iPlugin->SetCancelledFlag( ETrue );
       
   310             iPlugin->CompleteL( KErrNotFound );            
       
   311             }
       
   312         }
       
   313     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::RunL " );      
       
   314         
       
   315     }
       
   316     
       
   317 // ---------------------------------------------------------
       
   318 // CActiveSelectWLanDlgPlugin::StartSearchWlanNetworkL()
       
   319 // ---------------------------------------------------------
       
   320 //    
       
   321 void CActiveSelectWLanDlgPlugin::StartSearchWlanNetworkL()
       
   322     {    
       
   323     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::StartSearchWlanNetworkL " );  
       
   324     
       
   325     DestroyWaitDialog();
       
   326 
       
   327     iWaitDialog = new( ELeave )CAknWaitDialog
       
   328                     ( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ), ETrue );
       
   329     iWaitDialog->ExecuteLD( R_SEARCHING_WLAN_WAIT_NOTE ); 
       
   330     
       
   331     SetActive();    
       
   332 
       
   333 #ifdef __WINS__
       
   334     TRequestStatus* clientStatus = &iStatus;
       
   335     User::RequestComplete( clientStatus, KErrNone );
       
   336 #else
       
   337     iWlanDataProv->RefreshScanInfo( iStatus );
       
   338 #endif
       
   339 
       
   340     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::StartSearchWlanNetworkL " );
       
   341     }
       
   342     
       
   343 // ---------------------------------------------------------
       
   344 // CActiveSelectWLanDlgPlugin::GetRefreshInterval()
       
   345 // ---------------------------------------------------------
       
   346 //    
       
   347 TInt CActiveSelectWLanDlgPlugin::GetRefreshInterval()
       
   348     {
       
   349     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::GetRefreshInterval " );
       
   350 
       
   351     CRepository* repository = NULL;
       
   352     TInt err( KErrNone );
       
   353 
       
   354     TRAP( err, 
       
   355           repository = CRepository::NewL( KCRUidConnectionUiUtilities ) );
       
   356           
       
   357     TInt variant( 0 );  
       
   358     CLOG_WRITEF( _L( "err : %d" ), err );
       
   359       
       
   360     if ( err == KErrNone )
       
   361         {
       
   362         TInt retval = repository->Get( KConnectionUiUtilitiesScanInterval, 
       
   363                                        variant ); 
       
   364                                        
       
   365         CLOG_WRITEF( _L( "retval : %d" ), retval );
       
   366                                                                              
       
   367         if ( retval == KErrNotFound )
       
   368             {
       
   369             variant = KTickDefaultInterval;
       
   370             }
       
   371         }
       
   372      else
       
   373         {
       
   374         variant = KTickDefaultInterval;
       
   375         }
       
   376 
       
   377     delete repository;
       
   378 
       
   379     CLOG_WRITEF( _L( "variant : %d" ), variant );
       
   380     
       
   381     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::GetRefreshInterval " );
       
   382     
       
   383     return variant;            
       
   384     }
       
   385 
       
   386 
       
   387 // ---------------------------------------------------------
       
   388 // CActiveSelectWLanDlgPlugin::DestroyWaitDialog()
       
   389 // ---------------------------------------------------------
       
   390 //
       
   391 void CActiveSelectWLanDlgPlugin::DestroyWaitDialog()
       
   392     {
       
   393     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::DestroyWaitDialog " );
       
   394 
       
   395     delete iWaitDialog;
       
   396     iWaitDialog = NULL;
       
   397 
       
   398     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::DestroyWaitDialog " );
       
   399     }
       
   400 
       
   401 
       
   402 // ---------------------------------------------------------
       
   403 // CActiveSelectWLanDlgPlugin::DestroyResultsListDialog()
       
   404 // ---------------------------------------------------------
       
   405 //
       
   406 void CActiveSelectWLanDlgPlugin::DestroyResultsListDialog()
       
   407     {
       
   408     CLOG_ENTERFN( "CActiveSelectWLanDlgPlugin::DestroyResultsListDialog " );
       
   409 
       
   410     if ( iResultsListDialog  && !( iResultsListDialog->GetOkToExit() ) )
       
   411         {
       
   412         delete iResultsListDialog;
       
   413         iResultsListDialog = NULL;
       
   414         }
       
   415 
       
   416     CLOG_LEAVEFN( "CActiveSelectWLanDlgPlugin::DestroyResultsListDialog " );
       
   417     }
       
   418 
       
   419 // End of File
       
   420