connectionmonitoring/connectionmonitorui/src/ConnectionMonitorUiAppUi.cpp
changeset 0 5a93021fdf25
child 2 086aae6fc07e
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Application UI class
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StringLoader.h>
       
    22 #include <aknnotedialog.h>
       
    23 #include <AknUtils.h>
       
    24 #include <cmmanagerext.h>
       
    25 #include <ConnectionMonitorUi.rsg>
       
    26 #include "ConnectionMonitorUi.hrh"
       
    27 #include "ConnectionMonitorUiAppUi.h"
       
    28 #include "ConnectionMonitorUiView.h"
       
    29 #include "ConnectionMonitorUiDetailsView.h"
       
    30 #include "ConnectionArray.h"
       
    31 #include "CsdConnectionInfo.h"
       
    32 #include "GprsConnectionInfo.h"
       
    33 #include "WlanConnectionInfo.h"
       
    34 #include "EasyWLANConnectionInfo.h"
       
    35 #include "FeatureManagerWrapper.h"
       
    36 #include "ActiveWrapper.h"
       
    37 
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // ----------------------------------------------------------
       
    44 // CConnectionMonitorUiAppUi::ConstructL()
       
    45 // ----------------------------------------------------------
       
    46 //
       
    47 void CConnectionMonitorUiAppUi::ConstructL()
       
    48     {
       
    49     CMUILOGGER_CREATE;
       
    50 
       
    51     CMUILOGGER_WRITE( "Constructing CConnectionMonitorUiAppUi" );
       
    52 
       
    53     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible);
       
    54 
       
    55 #ifdef RD_CONTROL_PANEL
       
    56     
       
    57     TBool isEmbeddedApp = IsEmbedded();
       
    58     CMUILOGGER_WRITE_F( "IsEmbedded(): %d", isEmbeddedApp );
       
    59 
       
    60 #endif // RD_CONTROL_PANEL                                  
       
    61 
       
    62     iFeatureManagerWrapper = CFeatureManagerWrapper::NewL();
       
    63     TBool isWlanSupported = FeatureManager::FeatureSupported( 
       
    64                                                     KFeatureIdProtocolWlan );
       
    65           
       
    66    CMUILOGGER_WRITE_F( "isWlanSupported: %b", isWlanSupported );
       
    67 
       
    68     // connect to connection monitor engine
       
    69     CMUILOGGER_WRITE( "Connection monitor engine" );
       
    70     iMonitor.ConnectL();
       
    71     CMUILOGGER_WRITE( "Connected" );
       
    72 
       
    73     CMUILOGGER_WRITE( "Creating connection array" );
       
    74     iConnectionArray = new ( ELeave ) CConnectionArray();
       
    75     iConnectionArray->ConstructL();
       
    76     
       
    77     iActiveWrapper = CActiveWrapper::NewL(); // start ActiveWrapper
       
    78 
       
    79     if ( isWlanSupported )
       
    80         {
       
    81         GetEasyWlanIAPNameL();
       
    82         }
       
    83 
       
    84     InitializeConnectionArrayL();
       
    85 
       
    86     CMUILOGGER_WRITE( "Created" );
       
    87 
       
    88     CMUILOGGER_WRITE( "Creating main view" );
       
    89 
       
    90 #ifdef RD_CONTROL_PANEL
       
    91     CConnectionMonitorUiView* mainView =
       
    92         new ( ELeave ) CConnectionMonitorUiView( iConnectionArray,
       
    93                                                  &iMonitor,
       
    94                                                  isEmbeddedApp,
       
    95                                                  iActiveWrapper );
       
    96 #else
       
    97     CConnectionMonitorUiView* mainView =
       
    98         new ( ELeave ) CConnectionMonitorUiView( iConnectionArray,
       
    99                                                  &iMonitor,
       
   100                                                  iActiveWrapper );
       
   101 #endif // RD_CONTROL_PANEL
       
   102 
       
   103     CleanupStack::PushL( mainView );
       
   104     CMUILOGGER_WRITE( "Constructing main view" );
       
   105     mainView->ConstructL();
       
   106     CMUILOGGER_WRITE( "Adding main view" );
       
   107     AddViewL( mainView );      // transfer ownership to CAknViewAppUi
       
   108 
       
   109     SetDefaultViewL( *mainView );
       
   110     iTimerObserver = this;
       
   111 
       
   112     CleanupStack::Pop( mainView );
       
   113     CMUILOGGER_WRITE( "Done" );
       
   114 
       
   115     CMUILOGGER_WRITE( "Creating details view" );
       
   116     CConnectionMonitorUiDetailsView* detailsView =
       
   117         new ( ELeave ) CConnectionMonitorUiDetailsView( iConnectionArray );
       
   118     CleanupStack::PushL( detailsView );
       
   119     CMUILOGGER_WRITE( "Constructing details view" );
       
   120     detailsView->ConstructL();
       
   121     CMUILOGGER_WRITE( "Adding details view" );
       
   122     AddViewL( detailsView );      // transfer ownership to CAknViewAppUi
       
   123     CleanupStack::Pop( detailsView );
       
   124     CMUILOGGER_WRITE( "Done" );
       
   125     
       
   126     // from this point we can listen to events of RConnectionMonitor server
       
   127     iMonitor.NotifyEventL( *this );
       
   128     
       
   129     activateMainView = EFalse;
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------
       
   133 // CConnectionMonitorUiAppUi::~CConnectionMonitorUiAppUi()
       
   134 // Destructor
       
   135 // Frees reserved resources
       
   136 // ----------------------------------------------------
       
   137 //
       
   138 CConnectionMonitorUiAppUi::~CConnectionMonitorUiAppUi()
       
   139     {
       
   140     CMUILOGGER_ENTERFN( "~CConnectionMonitorUiAppUi" );
       
   141 
       
   142     StopTimer();
       
   143     delete iConnectionArray;
       
   144     delete iEasyWlanIAPName;
       
   145     delete iActiveWrapper;
       
   146     delete iFeatureManagerWrapper;
       
   147 
       
   148     // it's needed because views are still active here
       
   149     // and a call from handleforegroundevent from them
       
   150     // can cause exception in StopConnEventNotificationL
       
   151     iMonitor.CancelNotifications();
       
   152     iMonitor.Close();
       
   153     iNewConnectionIdArray.Close();
       
   154     iConnectionsWaitingFirstEvent.Close();
       
   155     CMUILOGGER_LEAVEFN( "~CConnectionMonitorUiAppUi" );
       
   156 
       
   157     CMUILOGGER_DELETE;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CConnectionMonitorUiAppUi::InitializeConnectionArrayL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CConnectionMonitorUiAppUi::InitializeConnectionArrayL()
       
   165     {
       
   166     CMUILOGGER_ENTERFN( "InitializeConnectionArrayL" );
       
   167 
       
   168     CConnectionInfoBase* connectionInfo = NULL;
       
   169     TUint connectionNumber( 0 );
       
   170     TUint connectionId( 0 );
       
   171     TUint subConnectionCount;
       
   172 
       
   173     TUint wlanConnectionCounter( 0 );
       
   174     TUint wlanConnectionId( 0 );
       
   175     TConnMonBearerType bearerType( EBearerUnknown );
       
   176     RArray<TUint> connIds;
       
   177     RArray<TInt> bearers;
       
   178     CleanupClosePushL( connIds );
       
   179     CleanupClosePushL( bearers );
       
   180 
       
   181     iActiveWrapper->StartGetConnectionCount( connectionNumber, iMonitor );
       
   182 
       
   183     if ( !iActiveWrapper->iStatus.Int() )
       
   184         {
       
   185         CMUILOGGER_WRITE_F( "Number of connections: %d",
       
   186                             connectionNumber );
       
   187 
       
   188         for ( TUint i = 1; i <= connectionNumber; ++i )
       
   189             {
       
   190             iMonitor.GetConnectionInfo( i, connectionId, subConnectionCount );
       
   191             connIds.AppendL( connectionId );
       
   192             
       
   193             iActiveWrapper->StartGetBearerType( connectionId,
       
   194                                                 iMonitor,
       
   195                                                 KBearer,
       
   196                                                 ( TInt& )bearerType );                                           
       
   197             CMUILOGGER_WRITE_F( "status.Int(): %d", 
       
   198                                 iActiveWrapper->iStatus.Int() );
       
   199             CMUILOGGER_WRITE_F( "bearerType: %d", ( TInt )bearerType );
       
   200             bearers.AppendL( (TInt)bearerType );
       
   201             
       
   202             if ( bearerType == EBearerWLAN )
       
   203                 {
       
   204                 wlanConnectionCounter++;
       
   205                 wlanConnectionId = connectionId;
       
   206                 }
       
   207             }
       
   208         
       
   209         for ( TInt i = 0; i < connectionNumber; i++ )
       
   210             {           
       
   211             if ( bearers[i] != EBearerWLAN || wlanConnectionCounter < 2 || connIds[i] == wlanConnectionId )
       
   212                 {
       
   213                 TInt err;
       
   214                 TRAP(err, connectionInfo = CreateConnectionInfoL( connIds[i], (TConnMonBearerType)bearers[i] ));
       
   215                 
       
   216                 if ( !err && connectionInfo )
       
   217                     {
       
   218                     CleanupStack::PushL( connectionInfo );
       
   219                     iConnectionArray->AppendL( connectionInfo );
       
   220                     CleanupStack::Pop( connectionInfo );
       
   221                     }
       
   222                 else
       
   223                     {
       
   224                     iNewConnectionIdArray.Append( connIds[i] );
       
   225                     }
       
   226                 }
       
   227             else
       
   228                 {
       
   229                 CMUILOGGER_WRITE( "Fake WLAN connection, skipping" );
       
   230                 }
       
   231             }
       
   232         }
       
   233     else
       
   234         {
       
   235         CMUILOGGER_WRITE_F( "GetConnectionCount status: %d", 
       
   236                             iActiveWrapper->iStatus.Int() );
       
   237         }
       
   238 
       
   239     CleanupStack::Pop( &bearers );
       
   240     bearers.Close();
       
   241     CleanupStack::Pop( &connIds );
       
   242     connIds.Close();
       
   243 
       
   244     CMUILOGGER_LEAVEFN( "InitializeConnectionArrayL Done" );
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CConnectionMonitorUiAppUi::EventL
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CConnectionMonitorUiAppUi::EventL(
       
   252                                        const CConnMonEventBase &aConnMonEvent )
       
   253     {
       
   254     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::EventL" );
       
   255 
       
   256     CMUILOGGER_WRITE_F( "EventL type: %d", aConnMonEvent.EventType() );
       
   257 
       
   258     CConnectionInfoBase* connectionInfo = NULL;
       
   259     TInt index( 0 );
       
   260     TConnMonEvent event = ( TConnMonEvent ) aConnMonEvent.EventType();
       
   261     TInt connectionId = aConnMonEvent.ConnectionId();
       
   262 
       
   263     CMUILOGGER_WRITE_F( "Connection Id:  %d", connectionId );
       
   264 
       
   265     switch ( event )
       
   266         {
       
   267         case EConnMonCreateConnection:
       
   268             {
       
   269             CMUILOGGER_WRITE( "EConnMonCreateConnection" );
       
   270 
       
   271             if ( connectionId > 0 )
       
   272                 {
       
   273                 iConnectionsWaitingFirstEvent.AppendL( connectionId );
       
   274                 }
       
   275             break;
       
   276             }
       
   277         case EConnMonDeleteConnection:
       
   278             {
       
   279             CMUILOGGER_WRITE( "EConnMonDeleteConnection" );
       
   280             TInt count = iNewConnectionIdArray.Count();
       
   281             TInt i = 0;
       
   282             TBool newConn = EFalse;
       
   283             
       
   284             for ( TInt cindex = 0; cindex < iConnectionsWaitingFirstEvent.Count(); cindex++ )
       
   285                 {
       
   286                 if ( iConnectionsWaitingFirstEvent[cindex] == connectionId )
       
   287                     {
       
   288                     newConn = ETrue;
       
   289                     iConnectionsWaitingFirstEvent.Remove(cindex);
       
   290                     break;
       
   291                     }
       
   292                 }
       
   293 
       
   294             if ( newConn )
       
   295                 {
       
   296                 // Job done
       
   297                 break;
       
   298                 }
       
   299                 
       
   300             while ( i < count )
       
   301                 {
       
   302                 if ( iNewConnectionIdArray[i] == connectionId )
       
   303                     {
       
   304                     iNewConnectionIdArray.Remove( i );
       
   305                     CMUILOGGER_WRITE_F( "Removed id %d from array", ( TUint )connectionId );
       
   306                     count--;
       
   307                     }
       
   308                 else 
       
   309                     {
       
   310                     i++;
       
   311                     }
       
   312                 }
       
   313             
       
   314             index = iConnectionArray->GetArrayIndex( connectionId );
       
   315             if ( index >= 0 )
       
   316                 {
       
   317                 connectionInfo = ( *iConnectionArray )[index]; 
       
   318             
       
   319                 if ( iView->Id() == KDetailsViewId )
       
   320                     {
       
   321                     CConnectionMonitorUiDetailsView* view = (CConnectionMonitorUiDetailsView*) iView;
       
   322                     if ( view->GetSelectedConnection() == ((TUint) index) )
       
   323                         {
       
   324                         view->CloseViewL();
       
   325                         activateMainView = ETrue;
       
   326                         }
       
   327                     }
       
   328                 else // MainView
       
   329                     {
       
   330                     TBool deleting = connectionInfo->GetDeletedFromCMUI();
       
   331                     if ( deleting )
       
   332                         {
       
   333                         ShowConnectionSummaryInformationNoteL( connectionInfo );
       
   334                         }
       
   335                     }
       
   336                 iConnectionArray->Delete( connectionId );
       
   337                 CMUILOGGER_WRITE_F( "Deleted: %d", connectionId );
       
   338                 }
       
   339             break;
       
   340             }
       
   341         case EConnMonConnectionStatusChange:
       
   342             {
       
   343             CMUILOGGER_WRITE( "EConnMonConnectionStatusChange" );
       
   344             
       
   345             TBool newConn = EFalse;
       
   346                 
       
   347             for ( TInt cindex = 0; cindex < iConnectionsWaitingFirstEvent.Count(); cindex++ )
       
   348                 {
       
   349                 if ( iConnectionsWaitingFirstEvent[cindex] == connectionId )
       
   350                     {
       
   351                     newConn = ETrue;
       
   352                     iConnectionsWaitingFirstEvent.Remove(cindex);
       
   353                     break;
       
   354                     }
       
   355                 }
       
   356             
       
   357             if ( newConn )
       
   358                 {
       
   359                 if ( connectionId > 0)
       
   360                     {
       
   361                     TConnMonBearerType bearerType( EBearerUnknown );
       
   362                     iActiveWrapper->StartGetBearerType( connectionId,
       
   363                                                         iMonitor,
       
   364                                                         KBearer,
       
   365                                                         ( TInt& )bearerType );  
       
   366                     CMUILOGGER_WRITE_F( "status.Int(): %d", 
       
   367                                         iActiveWrapper->iStatus.Int() );
       
   368                     CMUILOGGER_WRITE_F( "bearerType: %d", ( TInt )bearerType );
       
   369                     if ( bearerType == 0 )
       
   370                         {
       
   371                         if ( connectionId )
       
   372                             {
       
   373                             iNewConnectionIdArray.AppendL( connectionId );
       
   374                             CMUILOGGER_WRITE_F( "id %d added to array", ( TUint )connectionId );
       
   375                             break;
       
   376                             }
       
   377                         }          
       
   378                     
       
   379                     connectionInfo = CreateConnectionInfoL( connectionId, bearerType );
       
   380                     }
       
   381                 
       
   382                 if ( connectionInfo )
       
   383                     {
       
   384                     CleanupStack::PushL( connectionInfo );
       
   385                     iConnectionArray->AppendL( connectionInfo );
       
   386                     CleanupStack::Pop( connectionInfo );
       
   387                     }
       
   388                 }
       
   389             
       
   390             index = iConnectionArray->GetArrayIndex( connectionId );
       
   391             CMUILOGGER_WRITE_F( "Found index :  %d", index );
       
   392 
       
   393             if ( index >= 0 )
       
   394                 {
       
   395                 ( *iConnectionArray )[index]->StatusChangedL();
       
   396                 }
       
   397             break;
       
   398             }
       
   399         case EConnMonCreateSubConnection:
       
   400         case EConnMonDeleteSubConnection:
       
   401             {
       
   402             CMUILOGGER_WRITE( "SubConnection" );
       
   403             index = iConnectionArray->GetArrayIndex( connectionId );
       
   404             if ( index >= 0)
       
   405                 {
       
   406                 ( *iConnectionArray )[index]->RefreshDetailsL();
       
   407                 }
       
   408             break;
       
   409             }
       
   410         default:
       
   411             {
       
   412             CMUILOGGER_WRITE( "On event default" );
       
   413             break;
       
   414             }
       
   415         }
       
   416 
       
   417     if ( iObserver && ( index >= 0 ) )
       
   418         {
       
   419         CMUILOGGER_WRITE( "EventL calls observer" );
       
   420         iObserver->OnEventL( aConnMonEvent, index );
       
   421         }
       
   422 
       
   423     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::EventL" );
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CConnectionMonitorUiAppUi::Static
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 CConnectionMonitorUiAppUi* CConnectionMonitorUiAppUi::Static()
       
   431     {
       
   432     return REINTERPRET_CAST( CConnectionMonitorUiAppUi*,
       
   433                              CEikonEnv::Static()->EikAppUi() );
       
   434     }
       
   435 
       
   436 // ---------------------------------------------------------------------------
       
   437 //  CConnectionMonitorUiAppUi::::DynInitMenuPaneL( TInt aResourceId,
       
   438 //  CEikMenuPane* aMenuPane )
       
   439 //  This function is called by the EIKON framework just before it displays
       
   440 //  a menu pane. Its default implementation is empty, and by overriding it,
       
   441 //  the application can set the state of menu items dynamically according
       
   442 //  to the state of application data.
       
   443 // ---------------------------------------------------------------------------
       
   444 //
       
   445 void CConnectionMonitorUiAppUi::DynInitMenuPaneL(
       
   446     TInt /*aResourceId*/, CEikMenuPane* /*aMenuPane*/ )
       
   447     {
       
   448     }
       
   449 
       
   450 // ----------------------------------------------------
       
   451 // CConnectionMonitorUiAppUi::HandleKeyEventL(
       
   452 //     const TKeyEvent& aKeyEvent, TEventCode /*aType*/ )
       
   453 // ----------------------------------------------------
       
   454 //
       
   455 TKeyResponse CConnectionMonitorUiAppUi::HandleKeyEventL(
       
   456     const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/ )
       
   457     {
       
   458     return EKeyWasNotConsumed;
       
   459     }
       
   460 
       
   461 // ----------------------------------------------------
       
   462 // CConnectionMonitorUiAppUi::HandleCommandL( TInt aCommand )
       
   463 // ----------------------------------------------------
       
   464 //
       
   465 void CConnectionMonitorUiAppUi::HandleCommandL( TInt aCommand )
       
   466     {
       
   467     switch ( aCommand )
       
   468         {
       
   469         case EEikCmdExit:
       
   470         case EAknCmdExit:
       
   471         case EAknSoftkeyExit:
       
   472             {
       
   473             Exit();
       
   474             break;
       
   475             }
       
   476         default:
       
   477             break;
       
   478         }
       
   479     }
       
   480 
       
   481 // ---------------------------------------------------------
       
   482 // CConnectionMonitorUiAppUi::StartConnEventNotification
       
   483 // ---------------------------------------------------------
       
   484 //
       
   485 void CConnectionMonitorUiAppUi::StartConnEventNotification(
       
   486                                     MActiveEventObserverInterface* aObserver )
       
   487     {
       
   488     CMUILOGGER_ENTERFN
       
   489         ( "CConnectionMonitorUiAppUi::StartConnEventNotification" );
       
   490 
       
   491     iObserver = aObserver;
       
   492 
       
   493     CMUILOGGER_LEAVEFN
       
   494         ( "CConnectionMonitorUiAppUi::StartConnEventNotification" );
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // CConnectionMonitorUiAppUi::StopConnEventNotification
       
   499 // ---------------------------------------------------------
       
   500 //
       
   501 void CConnectionMonitorUiAppUi::StopConnEventNotification(
       
   502                                 MActiveEventObserverInterface* aObserver )
       
   503     {
       
   504     CMUILOGGER_ENTERFN
       
   505         ( "CConnectionMonitorUiAppUi::StopConnEventNotification" );
       
   506 
       
   507     if ( iObserver == aObserver )
       
   508         {
       
   509         iObserver = NULL;
       
   510         }
       
   511 
       
   512     CMUILOGGER_LEAVEFN
       
   513         ( "CConnectionMonitorUiAppUi::StopConnEventNotification" );
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------
       
   517 // CConnectionMonitorUiAppUi::StartTimerL
       
   518 // ---------------------------------------------------------
       
   519 //
       
   520 void CConnectionMonitorUiAppUi::StartTimerL( const TInt aInterval )
       
   521     {
       
   522     CMUILOGGER_WRITE( "Starting timer" );
       
   523 
       
   524     if ( !iPeriodic )
       
   525         {
       
   526         iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   527 	    CMUILOGGER_WRITE_F( "aInterval  :  %d", aInterval );
       
   528         
       
   529         iPeriodic->Start( aInterval, aInterval,
       
   530                           TCallBack( Tick, this ) );
       
   531         }
       
   532 
       
   533     CMUILOGGER_WRITE( "Timer started" );
       
   534     }
       
   535 
       
   536 // ---------------------------------------------------------
       
   537 // CConnectionMonitorUiAppUi::StopTimer
       
   538 // ---------------------------------------------------------
       
   539 //
       
   540 void CConnectionMonitorUiAppUi::StopTimer()
       
   541     {
       
   542     CMUILOGGER_WRITE( "Stopping timer" );
       
   543     if ( iPeriodic )
       
   544         {
       
   545         CMUILOGGER_WRITE( "Timer existing" );
       
   546         iPeriodic->Cancel();
       
   547         delete iPeriodic;
       
   548         iPeriodic = NULL;
       
   549         }
       
   550 
       
   551     CMUILOGGER_WRITE( "Timer stopped" );
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CConnectionMonitorUiAppUi::Tick
       
   556 // ---------------------------------------------------------
       
   557 //
       
   558 TInt CConnectionMonitorUiAppUi::Tick( TAny* aObject )
       
   559     {
       
   560     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::Tick(TAny* aObject)" );
       
   561 
       
   562     CConnectionMonitorUiAppUi* myself =
       
   563                         static_cast<CConnectionMonitorUiAppUi*>( aObject );
       
   564     myself->Tick();
       
   565 
       
   566     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::Tick(TAny* aObject)" );
       
   567     return 1;
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------
       
   571 // CConnectionMonitorUiAppUi::Tick
       
   572 // ---------------------------------------------------------
       
   573 //
       
   574 TInt CConnectionMonitorUiAppUi::Tick()
       
   575     {
       
   576     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::Tick()" );
       
   577 
       
   578     if ( iTimerObserver )
       
   579         {
       
   580         TInt error( KErrNone );
       
   581 
       
   582         TRAP( error, iTimerObserver->OnTimerExpiredL() );
       
   583         CMUILOGGER_WRITE_F( "OnTimerExpiredL error id  :  %d", error );
       
   584 
       
   585         // refresh listboxes
       
   586         if ( !error && ( iObserver ) )
       
   587             {
       
   588             CMUILOGGER_WRITE( "Tick !error && ( iObserver )" );
       
   589             TRAP( error, iObserver->OnTimerEventL() );
       
   590             }
       
   591         CMUILOGGER_WRITE( "after Tick !error && ( iObserver )" );
       
   592         }
       
   593 
       
   594     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::Tick()" );
       
   595     return 1;
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------
       
   599 // CConnectionMonitorUiAppUi::OnTimerExpiredL
       
   600 // ---------------------------------------------------------
       
   601 //
       
   602 void CConnectionMonitorUiAppUi::OnTimerExpiredL()
       
   603     {
       
   604     TInt count = iNewConnectionIdArray.Count();
       
   605     if ( count > 0 )
       
   606         {
       
   607         for ( TInt i = 0; i < count; i++ )
       
   608             {
       
   609             TConnMonBearerType bearerType( EBearerUnknown );
       
   610             iActiveWrapper->StartGetBearerType( iNewConnectionIdArray[i],
       
   611                                                 iMonitor,
       
   612                                                 KBearer,
       
   613                                                 ( TInt& )bearerType );  
       
   614             CMUILOGGER_WRITE_F( "status.Int(): %d", 
       
   615                                 iActiveWrapper->iStatus.Int() );
       
   616             CMUILOGGER_WRITE_F( "bearerType: %d", ( TInt )bearerType );
       
   617             if ( bearerType == 0 )
       
   618                 {
       
   619                 continue;
       
   620                 }
       
   621             CConnectionInfoBase* connectionInfo = NULL;
       
   622             TInt err;
       
   623             TRAP(err, connectionInfo = CreateConnectionInfoL( iNewConnectionIdArray[i], bearerType ));
       
   624             if ( err )
       
   625                 {
       
   626                 continue;
       
   627                 }
       
   628             
       
   629             
       
   630             if ( connectionInfo )
       
   631                 {
       
   632                 CleanupStack::PushL( connectionInfo );
       
   633                 iConnectionArray->AppendL( connectionInfo );
       
   634                 CleanupStack::Pop( connectionInfo );
       
   635                 
       
   636                 iNewConnectionIdArray.Remove( i );
       
   637                 count--;
       
   638                 i--;
       
   639                 CMUILOGGER_WRITE_F( "Removed index %d from array", ( TInt )i );
       
   640                 }
       
   641             
       
   642             }
       
   643         }
       
   644     RefreshAllConnectionsL();
       
   645     if ( iView )
       
   646         {
       
   647         CMUILOGGER_WRITE_F( "iView->Id() %d", iView->Id() );
       
   648         if ( iView->Id() == KConnectionsViewId )
       
   649             {
       
   650             CConnectionMonitorUiView* view =
       
   651                     ( CConnectionMonitorUiView* )iView;
       
   652             view->ConnectionKeyObserver();
       
   653             }
       
   654         }
       
   655     }
       
   656     
       
   657 // ---------------------------------------------------------
       
   658 // CConnectionMonitorUiAppUi::GetTickInerval
       
   659 // ---------------------------------------------------------
       
   660 //
       
   661 TInt CConnectionMonitorUiAppUi::GetTickInerval() const
       
   662 	{
       
   663 	return KTickInterval;
       
   664 	}    
       
   665 
       
   666 // ---------------------------------------------------------
       
   667 // CConnectionMonitorUiAppUi::RefreshAllConnectionsL
       
   668 // ---------------------------------------------------------
       
   669 //
       
   670 void CConnectionMonitorUiAppUi::RefreshAllConnectionsL()
       
   671     {
       
   672     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::RefreshAllConnectionsL" );
       
   673     TUint index( 0 );
       
   674     CConnectionInfoBase* connection = NULL;
       
   675     if ( iConnectionArray )
       
   676         {
       
   677         TUint count = iConnectionArray->MdcaCount();
       
   678         while ( index < count )
       
   679             {
       
   680             connection = ( *iConnectionArray )[index];
       
   681             // MainView Refresh
       
   682             if ( ( connection->IsAlive() ) && 
       
   683                  ( !connection->IsSuspended() ) )
       
   684                  {
       
   685                  CMUILOGGER_WRITE( "MainView Refresh" );
       
   686                  CMUILOGGER_WRITE_F( "RefreshAllConnectionsL index: %d", 
       
   687                                      index );
       
   688                  CMUILOGGER_WRITE_F( "RefreshAllConnectionsL connId: %d", 
       
   689                                      connection->GetConnectionId() );
       
   690                  connection->RefreshDetailsL();
       
   691                  }
       
   692             // DetailsView Refresh
       
   693             if ( ( connection->IsAlive() && 
       
   694                  ( iView->Id() == KDetailsViewId ) ) )
       
   695                 {
       
   696                 CMUILOGGER_WRITE( "DetailsView Refresh" );
       
   697                 connection->RefreshDetailsArrayL();
       
   698                 }
       
   699             connection->RefreshConnectionListBoxItemTextL();
       
   700             count = iConnectionArray->MdcaCount();
       
   701             ++index;
       
   702             }
       
   703         }
       
   704     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::RefreshAllConnectionsL" );
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------
       
   708 // CConnectionMonitorUiAppUi::HandleForegroundEventL
       
   709 // ---------------------------------------------------------
       
   710 //
       
   711 void CConnectionMonitorUiAppUi::HandleForegroundEventL( TBool aForeground )
       
   712     {
       
   713     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::HandleForegroundEventL" );
       
   714 
       
   715     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
   716     if ( aForeground )
       
   717         {
       
   718         CMUILOGGER_WRITE( "Foreground" );
       
   719         if ( activateMainView && iView != NULL && iView->Id() == KDetailsViewId )
       
   720             {
       
   721             ((CConnectionMonitorUiDetailsView*) iView)->ActivateMainViewL();
       
   722             activateMainView = EFalse;
       
   723             }
       
   724             
       
   725         TInt interval( KTickInterval );
       
   726         if ( iTimerObserver )
       
   727   	        {
       
   728 	          interval = iTimerObserver->GetTickInerval();	
       
   729 	          }
       
   730         StartTimerL( interval );
       
   731         }
       
   732     else
       
   733         {
       
   734         CMUILOGGER_WRITE( "Background" );
       
   735         StopTimer();
       
   736         activateMainView = EFalse;
       
   737         }
       
   738 
       
   739     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::HandleForegroundEventL" );
       
   740     }
       
   741 
       
   742 // ---------------------------------------------------------
       
   743 // CConnectionMonitorUiAppUi::CreateConnectionInfoL
       
   744 // ---------------------------------------------------------
       
   745 //
       
   746 CConnectionInfoBase* CConnectionMonitorUiAppUi::CreateConnectionInfoL(
       
   747                                                 TUint aConnectionId,
       
   748                                                 TConnMonBearerType aBearerType )
       
   749     {
       
   750     CMUILOGGER_ENTERFN( "CreateConnectionInfoL - start " );
       
   751 
       
   752     CConnectionInfoBase* connection = NULL;
       
   753 
       
   754     if ( aConnectionId > 0 )
       
   755         {
       
   756 
       
   757 #ifdef  __WINS__
       
   758         if ( aBearerType == EBearerLAN )
       
   759             {
       
   760             aBearerType = EBearerGPRS;
       
   761             }
       
   762 #endif
       
   763         switch ( aBearerType )
       
   764             {
       
   765             case EBearerGPRS:
       
   766             case EBearerWCDMA:
       
   767             case EBearerEdgeGPRS:
       
   768             case EBearerExternalGPRS:
       
   769             case EBearerExternalWCDMA:
       
   770             case EBearerExternalEdgeGPRS:
       
   771                 {
       
   772                 CMUILOGGER_WRITE( "CGprsConnectionInfo" );
       
   773                 
       
   774                 connection = CGprsConnectionInfo::NewL(
       
   775                         aConnectionId,
       
   776                         &iMonitor,
       
   777                         aBearerType,
       
   778                         iActiveWrapper );
       
   779                 break;
       
   780                 }
       
   781             case EBearerCSD:
       
   782             case EBearerHSCSD:
       
   783             case EBearerWcdmaCSD:
       
   784             case EBearerExternalCSD:
       
   785             case EBearerExternalHSCSD:
       
   786             case EBearerExternalWcdmaCSD:
       
   787                 {
       
   788                 CMUILOGGER_WRITE( "CCsdConnectionInfo" );
       
   789 
       
   790                 connection = CCsdConnectionInfo::NewL(
       
   791                         aConnectionId,
       
   792                         &iMonitor,
       
   793                         aBearerType,
       
   794                         iActiveWrapper );
       
   795                 break;
       
   796                 }
       
   797             case EBearerWLAN:
       
   798                 //case EBearerExternalWLAN:
       
   799                 {
       
   800                 CMUILOGGER_WRITE( "CWlanConnectionInfo" );
       
   801                 
       
   802                 connection = CWlanConnectionInfo::NewL(
       
   803                         aConnectionId,
       
   804                         &iMonitor,
       
   805                         aBearerType,
       
   806                         iEasyWlanIAPName,
       
   807                         iActiveWrapper );
       
   808                 break;
       
   809                 }
       
   810             default :
       
   811                 {
       
   812                 CMUILOGGER_WRITE( "CreateConnectionInfoL, default" );
       
   813                 break;
       
   814                 }
       
   815             }
       
   816             CMUILOGGER_WRITE_F( "Connection created: %d", aConnectionId );
       
   817 
       
   818         if (  connection && connection->CheckMrouterIap() )
       
   819             {
       
   820             CMUILOGGER_WRITE_F( "Connection deleted: %d", aConnectionId );
       
   821             delete connection;
       
   822             connection = NULL;
       
   823             }
       
   824         }
       
   825     else
       
   826         {
       
   827         CMUILOGGER_WRITE( "Connection id is invalid" );
       
   828         }
       
   829 
       
   830     CMUILOGGER_LEAVEFN( "CreateConnectionInfoL - end " );
       
   831 
       
   832     return connection;
       
   833     }
       
   834 
       
   835 // ---------------------------------------------------------
       
   836 // CConnectionMonitorUiAppUi::GetEasyWlanIAPNameL
       
   837 // ---------------------------------------------------------
       
   838 //
       
   839 void CConnectionMonitorUiAppUi::GetEasyWlanIAPNameL()
       
   840     {
       
   841     CMUILOGGER_ENTERFN( "CConnectionMonitorUiAppUi::GetEasyWlanIAPNameL" );
       
   842 
       
   843     delete iEasyWlanIAPName;
       
   844     iEasyWlanIAPName = NULL;
       
   845 
       
   846     RCmManagerExt cmManagerExt;
       
   847     cmManagerExt.OpenL();
       
   848     CleanupClosePushL( cmManagerExt );
       
   849     
       
   850     TUint32 easyWlanId = cmManagerExt.EasyWlanIdL();
       
   851     if ( easyWlanId )
       
   852             {
       
   853             CMUILOGGER_WRITE_F( "easyWlanId %d", easyWlanId );
       
   854             iEasyWlanIAPName = cmManagerExt
       
   855                                 .GetConnectionMethodInfoStringL( 
       
   856                                                         easyWlanId, 
       
   857                                                         CMManager::ECmName );
       
   858             CMUILOGGER_WRITE_F( "iEasyWlanIAPName: %S", iEasyWlanIAPName );
       
   859             }
       
   860 
       
   861     CleanupStack::PopAndDestroy( &cmManagerExt );
       
   862 
       
   863     CMUILOGGER_LEAVEFN( "CConnectionMonitorUiAppUi::GetEasyWlanIAPNameL" );
       
   864     }
       
   865 
       
   866 // ---------------------------------------------------------
       
   867 // CConnectionMonitorUiAppUi::ShowConnectionSummaryInformationNoteL
       
   868 // ---------------------------------------------------------
       
   869 //
       
   870 void CConnectionMonitorUiAppUi::ShowConnectionSummaryInformationNoteL( 
       
   871 										const CConnectionInfoBase* aConnection )
       
   872     {
       
   873     CMUILOGGER_ENTERFN( 
       
   874     	"CConnectionMonitorUiContainer::ShowConnectionSummaryInformationNoteL" );
       
   875     	
       
   876  	HBufC* total = aConnection->ToStringTotalTransmittedDataLC();
       
   877     HBufC* duration = aConnection->ToStringDurationLC();
       
   878     
       
   879     CMUILOGGER_WRITE_F( "total: %S", total );
       
   880     CMUILOGGER_WRITE_F( "duration: %S", duration );
       
   881       	
       
   882     CDesCArrayFlat* strings = new( ELeave ) CDesCArrayFlat( 2 );
       
   883     CleanupStack::PushL( strings );
       
   884 
       
   885     strings->AppendL( *total );
       
   886     strings->AppendL( *duration );    	
       
   887     	
       
   888     HBufC* informationText;
       
   889     informationText = StringLoader::LoadLC( R_QTN_CMON_CONNECTION_SUMMARY_NOTE_TEXT, 
       
   890     										*strings );
       
   891     										        
       
   892     CAknNoteDialog* dlg = new ( ELeave ) CAknNoteDialog( 
       
   893     										CAknNoteDialog::ENoTone, 
       
   894     										CAknNoteDialog::TTimeout( 5000000 ) );
       
   895     dlg->PrepareLC( R_QTN_CMON_CONNECTION_SUMMARY_NOTE );
       
   896     dlg->SetTextWrapping( EFalse );
       
   897     
       
   898     TPtr temp( informationText->Des() );
       
   899     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( temp );
       
   900     
       
   901     dlg->SetCurrentLabelL( EGeneralNote, temp ); //SetTextL
       
   902     
       
   903     dlg->RunDlgLD();    
       
   904         
       
   905     CleanupStack::PopAndDestroy( informationText );
       
   906     CleanupStack::PopAndDestroy( strings );
       
   907 	CleanupStack::PopAndDestroy( duration );
       
   908 	CleanupStack::PopAndDestroy( total );
       
   909     
       
   910     CMUILOGGER_LEAVEFN( 
       
   911     	"CConnectionMonitorUiContainer::ShowConnectionSummaryInformationNoteL" );        
       
   912     }
       
   913 
       
   914 // ---------------------------------------------------------
       
   915 // CConnectionMonitorUiAppUi::DeleteDetailsView
       
   916 // ---------------------------------------------------------
       
   917 //
       
   918 void CConnectionMonitorUiAppUi::DeleteDetailsView(
       
   919                                             TInt aConnId,
       
   920                                             CConnectionInfoBase* aConnInfo )
       
   921     {
       
   922     CMUILOGGER_WRITE( "CConnectionMonitorUiAppUi::DeleteDetailsView Start" );
       
   923     CMUILOGGER_WRITE_F( "aConnInfo:  %d", aConnInfo );
       
   924     CMUILOGGER_WRITE_F( "aConnId:  %d", aConnId );
       
   925 
       
   926 	TBool deleting = aConnInfo->GetDeletedFromCMUI();
       
   927     iConnectionArray->Delete( aConnId );
       
   928     
       
   929     CMUILOGGER_WRITE_F( "Deleted: %d", aConnId );
       
   930     CMUILOGGER_WRITE( "CConnectionMonitorUiAppUi::DeleteDetailsView End" );
       
   931     }
       
   932 
       
   933 #ifdef RD_CONTROL_PANEL
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CConnectionMonitorUiAppUi::IsEmbedded
       
   937 // -----------------------------------------------------------------------------
       
   938 //
       
   939 TBool CConnectionMonitorUiAppUi::IsEmbedded() const
       
   940     {
       
   941     return iEikonEnv->StartedAsServerApp();
       
   942     }
       
   943     
       
   944 #endif // RD_CONTROL_PANEL 
       
   945 
       
   946 
       
   947 // End of File