wvuing/IMPSAlwaysOnlinePlugin/src/CIMPSAlwaysOnlinePluginImp.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Offers the always online functionality for the Presence Engine
       
    15 *                and the Chat application
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CIMPSAlwaysOnlinePluginImp.h"
       
    22 #include "CPEngAOPluginTimer.h"
       
    23 #include "CPEngAOCallObserver.h"
       
    24 #include "IMPSCommonUiDebugPrint.h"
       
    25 //#include "PresenceErrors.h"
       
    26 
       
    27 #include "CIMPSAlwaysOnlineScheduler.h"
       
    28 #include "CPEngAONwStatusObserver.h"
       
    29 #include "cimpsconnuiconnectionmodenotifierng.h"
       
    30 #include "cimpspresenceaaconnectionng.h"
       
    31 #include "CIMPSSharedDataFactory.h"
       
    32 #include "MIMPSSharedData.h"
       
    33 #include "CIMPSReconnectNoteHandler.h"
       
    34 #include "IMPSUIDDefs.h"
       
    35 #include "impspresenceconnectionuiconstsng.h"
       
    36 
       
    37 #include <PEngAOPluginNG.rsg>
       
    38 #include <flogger.h>
       
    39 #include <PEngPresenceEngineConsts2.h>
       
    40 #include <avkon.hrh>
       
    41 #include <errorui.h>
       
    42 #include <e32property.h>    // RProperty
       
    43 
       
    44 #include <APGCLI.H>
       
    45 #include <APACMDLN.H>
       
    46 #include <aknglobalmsgquery.h>
       
    47 #include <bautils.h>
       
    48 
       
    49 #include "cpengaodialogmonitor.h"
       
    50 #include "impscommonuibuilddefinitions.h"
       
    51 
       
    52 // CONSTANTS
       
    53 
       
    54 // after first 12 connection tries is shown global note for continuation
       
    55 // if user accepts continuation then 8 new tries and after that note
       
    56 // is shown again user accepts again then 8 new tries and so on....
       
    57 const TInt KFirstReconnectionRetryCycleLength( 12 );
       
    58 
       
    59 const TInt KRestReconnectionRetryCyclesLength( 8 );
       
    60 
       
    61 
       
    62 //wait time after changing from offline to not offline state, in microseconds
       
    63 const TInt KWaitTimeFromOfflineToNotOffline = 22000000;
       
    64 
       
    65 // the wait times are from IMPS Service Settings UI specification and they are
       
    66 // in minutes. They are also relative to the previously waited, not
       
    67 // absolute wait times. For first fife tries are defined values and after that
       
    68 // reconnection is tried after 15 minutes intervals
       
    69 const TInt KMaxNumberOfDefinedWaitTimes( 5 );
       
    70 
       
    71 const TInt KLoginWaitTime[KMaxNumberOfDefinedWaitTimes] = { 0, 2, 3, 5, 5 };
       
    72 
       
    73 const TInt KDefaultLoginWaitTime = 15;
       
    74 
       
    75 _LIT_SECURITY_POLICY_PASS( KIMPSSharedReadPolicy );
       
    76 _LIT_SECURITY_POLICY_PASS( KIMPSSharedWritePolicy );
       
    77 
       
    78 _LIT( KAOPluginResourceFile, "PENGAOPluginNG.rsc" );
       
    79 _LIT( KAOPluginResourcePath, "\\Resource\\" );
       
    80 
       
    81 
       
    82 // ============================ MEMBER FUNCTIONS ===============================
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CIMPSAlwaysOnlinePluginImp::CIMPSAlwaysOnlinePluginImp
       
    86 // C++ default constructor can NOT contain any code, that
       
    87 // might leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 CIMPSAlwaysOnlinePluginImp::CIMPSAlwaysOnlinePluginImp() :
       
    91         iNetworkOpsAllowed( ETrue ),
       
    92 //iPreviousEvent( EPEngPresenceServiceSAPChanged ),
       
    93         iLoginCount( 1 ), // first attempt
       
    94         iPluginState( EIMPSAOPluginRunning ),
       
    95         iRoaming( EFalse ),
       
    96         iScheduledLoginOk( EFalse ),
       
    97         iUserControlledConnection( EFalse ),
       
    98         iEventInQueue( EFalse ),
       
    99         iQueuedLogoutIsScheduledLogout( EFalse ),
       
   100         iCurServerDisconnectDenied( EFalse )
       
   101     {
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CIMPSAlwaysOnlinePluginImp::ConstructL
       
   106 // Symbian 2nd phase constructor can leave.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CIMPSAlwaysOnlinePluginImp::ConstructL()
       
   110     {
       
   111     iAutoLogin = iKeys.LoginManualEnum();
       
   112 
       
   113     // client for notice setting changes
       
   114     iSettingChangesNotifier =
       
   115         CIMPSSharedDataFactory::CreateTemporaryKeyHandlerL( this,
       
   116                                                             KIMPSServSettNotifyUid );
       
   117 
       
   118     // create shared data client
       
   119     iSharedDataServiceSettings =
       
   120         CIMPSSharedDataFactory::CreatePermanentKeyHandlerL( this,
       
   121                                                             KIMPSServSettUid );
       
   122 
       
   123     iNwObserver = CPEngAONwStatusObserver::NewL( *this );
       
   124 
       
   125     // Create monitor for roam ing warning dialog
       
   126     iDlgMonitor = CPEngAODialogMonitor::NewL( *this );
       
   127 
       
   128     User::LeaveIfError( iFs.Connect() );
       
   129 
       
   130     TFileName resourceFileName;
       
   131     resourceFileName.Zero();
       
   132     TFileName drivePath;
       
   133     Dll::FileName( drivePath );
       
   134     resourceFileName.Append( TParsePtrC( drivePath ).Drive() );
       
   135     resourceFileName.Append( KAOPluginResourcePath() );
       
   136     resourceFileName.Append( KAOPluginResourceFile );
       
   137 
       
   138     if ( resourceFileName.Length() > 0 )
       
   139         {
       
   140         // when baflutils gets an empty string, it returns "C:",
       
   141         // which breaks things
       
   142         BaflUtils::NearestLanguageFile( iFs, resourceFileName );
       
   143         }
       
   144 
       
   145     iResFile.OpenL( iFs, resourceFileName );
       
   146     iResFile.ConfirmSignatureL();
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CIMPSAlwaysOnlinePluginImp::NewL
       
   151 // Two-phased constructor.
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 CIMPSAlwaysOnlinePluginImp* CIMPSAlwaysOnlinePluginImp::NewL()
       
   155     {
       
   156     CIMPSAlwaysOnlinePluginImp* self = new( ELeave ) CIMPSAlwaysOnlinePluginImp();
       
   157 
       
   158     CleanupStack::PushL( self );
       
   159     self->ConstructL();
       
   160     CleanupStack::Pop( self );
       
   161 
       
   162     return self;
       
   163     }
       
   164 
       
   165 // Destructor
       
   166 CIMPSAlwaysOnlinePluginImp::~CIMPSAlwaysOnlinePluginImp()
       
   167     {
       
   168     FreeMemory();
       
   169     delete iSettingChangesNotifier;
       
   170     delete iSharedDataServiceSettings;
       
   171     delete iNwObserver;
       
   172     delete iRoamingQueryText;
       
   173     delete iRoamingQueryTitle;
       
   174     if (	iGlobalMsgQuery )
       
   175         {
       
   176         iGlobalMsgQuery->CancelMsgQuery();
       
   177         }
       
   178     delete iGlobalMsgQuery;
       
   179     delete iDlgMonitor;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------
       
   183 // CIMPSAlwaysOnlinePluginImp::DoLogin
       
   184 // Logs out from the wv server
       
   185 // ---------------------------------------------------------
       
   186 //
       
   187 void CIMPSAlwaysOnlinePluginImp::DoLogin()
       
   188     {
       
   189     IMPSCUI_DP_FUNC_ENTER( "DoLogin" );
       
   190     // if already in doing login state or
       
   191     // if the call is active, just return when the call ends, we get a notify->
       
   192     // just return (a possible leave can be ignored)
       
   193     if ( iCallObserver->CallActive( this ) )
       
   194         {
       
   195         // if call is active, this is set as the call observer
       
   196         IMPSCUI_DP_TXT( "Call is active, cannot do login currently" );
       
   197         return;
       
   198         }
       
   199     else if ( iPluginState == EIMPSAOPluginDoingLogin )
       
   200         {
       
   201         // emptying event queue,
       
   202         // because is currently doing login, and we
       
   203         // want to be in logged state after login is done
       
   204         iEventInQueue = EFalse;
       
   205         return;
       
   206         }
       
   207     else if ( iPluginState == EIMPSAOPluginDoingLogout )
       
   208         {
       
   209         // currently doing logout, adding login action to
       
   210         // event queue
       
   211         iEventInQueue = ETrue;
       
   212         return;
       
   213         }
       
   214 
       
   215     // start login procedure and set correct state
       
   216     iPluginState = EIMPSAOPluginDoingLogin;
       
   217     iReconnectNoteHandler->CancelNoteShowing( this );
       
   218 
       
   219     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::DoLogin try[%d]" ), iLoginCount );
       
   220     TInt retVal( KErrNone );
       
   221     TInt err( KErrNone );
       
   222 
       
   223     iTimeBeforeLoginTry.HomeTime();
       
   224 
       
   225 #ifdef DEBUG
       
   226     TDateTime loginTime;
       
   227     loginTime = iTimeBeforeLoginTry.DateTime();
       
   228     IMPSCUI_DP_TXT( "Time before login try: " );
       
   229     IMPSCUI_DP( D_IMPSCUI_LIT( "year [%d] " ), loginTime.Year() );
       
   230     // +1 added to get human readable form of day and month on debug print
       
   231     IMPSCUI_DP( D_IMPSCUI_LIT( "day [%d], month [%d]" ), loginTime.Day() + 1,
       
   232                 loginTime.Month() + 1 );
       
   233     IMPSCUI_DP( D_IMPSCUI_LIT( "hour [%d], minu [%d]" ), loginTime.Hour(),
       
   234                 loginTime.Minute() );
       
   235 #endif
       
   236 
       
   237 
       
   238     TRAP( err, retVal =  iConnectionUI->LoginL( EIMPSConnClientIM ) );
       
   239 
       
   240     iPluginState = EIMPSAOPluginRunning;
       
   241 
       
   242     // regardless of the result of login, if there came a logout event during
       
   243     // the login, call DoLogout
       
   244     if ( iEventInQueue )
       
   245         {
       
   246         iEventInQueue = EFalse;
       
   247         DoLogout( iQueuedLogoutIsScheduledLogout );
       
   248         iQueuedLogoutIsScheduledLogout = EFalse;
       
   249         return;
       
   250         }
       
   251 
       
   252     // handle leaves with memory related errors
       
   253     CheckMemoryErrors( err );
       
   254 
       
   255     if ( err < KErrNone )
       
   256         {
       
   257         IMPSCUI_DP( D_IMPSCUI_LIT( "LoginL leaved with code [%d]" ), err );
       
   258         IMPSCUI_DP_TXT( "All leaves are handled as retval KErrCouldNotConnect" );
       
   259         // if the LoginL-call leaves set the return value to normal
       
   260         // return value when connection could not be made, to get reconnect
       
   261         // later working.
       
   262         retVal = KErrCouldNotConnect;
       
   263         }
       
   264 
       
   265     switch ( retVal )
       
   266         {
       
   267         case KErrAlreadyExists: // fallthrough
       
   268         case KErrNone:
       
   269             {
       
   270             // Login succeeded, reset the plugin states and counts
       
   271             IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::DoLogin successful try[%d]" ), iLoginCount + 1 );
       
   272             Reset();
       
   273             break;
       
   274             }
       
   275         case KErrNotFound: // fallthrough
       
   276         case KErrArgument:
       
   277         case KErrNotSupported:
       
   278             {
       
   279             // wrong password, don't try to relogin, ConnectionUI shows the note
       
   280             Reset();
       
   281             // reset because we can't retry the login if the username and / or
       
   282             // password are incorrect
       
   283             break;
       
   284             }
       
   285 
       
   286         case KErrAccessDenied: // fallthrough
       
   287         case KErrGeneral:
       
   288         case KErrCouldNotConnect:
       
   289             {
       
   290             // login failed with some network failure (time out or other network error) ->
       
   291             // wait and try again, show confirmation query if needed
       
   292             if ( iLoginCount == KFirstReconnectionRetryCycleLength )
       
   293                 {
       
   294                 iReconnectNoteHandler->ShowNote( this );
       
   295                 }
       
   296             else if ( ( iLoginCount > KFirstReconnectionRetryCycleLength ) &&
       
   297                       ( ( ( iLoginCount - KFirstReconnectionRetryCycleLength )
       
   298                           % KRestReconnectionRetryCyclesLength ) == 0
       
   299                       )
       
   300                     )
       
   301                 {
       
   302                 iReconnectNoteHandler->ShowNote( this );
       
   303                 }
       
   304             else
       
   305                 {
       
   306                 StartWaiting();
       
   307                 iLoginCount++;
       
   308                 }
       
   309             break;
       
   310             }
       
   311         case KErrCouldNotDisconnect:
       
   312             {
       
   313             // there was connection to different server than default
       
   314             // and user denied disconnecting
       
   315             iCurServerDisconnectDenied = ETrue;
       
   316             }
       
   317         break;
       
   318         default:
       
   319             {
       
   320             // something else, undefined return value
       
   321             // these errors don't affect reconnection functionality
       
   322             // For just in case checking memory related errors
       
   323             CheckMemoryErrors( retVal );
       
   324             break;
       
   325             }
       
   326         }
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------
       
   330 // CIMPSAlwaysOnlinePluginImp::DoLogout
       
   331 // Logs out from the wv server
       
   332 // ---------------------------------------------------------
       
   333 //
       
   334 void CIMPSAlwaysOnlinePluginImp::DoLogout( TBool aIsScheduledLogout /* = EFalse */ )
       
   335     {
       
   336     IMPSCUI_DP_FUNC_ENTER( "DoLogout" );
       
   337 
       
   338     // do logout only if we are logged in
       
   339     TBool loggedIn( EFalse );
       
   340     TInt err( KErrNone );
       
   341     TRAP( err, loggedIn = iConnectionUI->LoggedInL( EIMPSConnClientIM ) );
       
   342 
       
   343     // Checking memory errors
       
   344     CheckMemoryErrors( err );
       
   345 
       
   346     if ( ( !loggedIn ) || err )
       
   347         {
       
   348         // not logged in just return
       
   349         // errors are handled as not logged in.
       
   350         return;
       
   351         }
       
   352     else if ( iPluginState == EIMPSAOPluginDoingLogout )
       
   353         {
       
   354         // emptying event queue,
       
   355         // because is currently doing logout, and we
       
   356         // want to be in logged out state after logout is done
       
   357         iEventInQueue = EFalse;
       
   358         iQueuedLogoutIsScheduledLogout = EFalse;
       
   359         return;
       
   360         }
       
   361     else if ( iPluginState == EIMPSAOPluginDoingLogin )
       
   362         {
       
   363         // currently doing login, adding logout action to
       
   364         // event queue
       
   365         iEventInQueue = ETrue;
       
   366         iQueuedLogoutIsScheduledLogout = aIsScheduledLogout;
       
   367         return;
       
   368         }
       
   369 
       
   370     iPluginState = EIMPSAOPluginDoingLogout;
       
   371 
       
   372     TInt retVal( KErrNone );
       
   373     TRAP( err, retVal = iConnectionUI->LogoutL( EIMPSConnClientIM,
       
   374                                                 aIsScheduledLogout ) );
       
   375 
       
   376     // checking memory related errors
       
   377     // other errors are  ignored, because want only forward most
       
   378     // importand errors to framework
       
   379     CheckMemoryErrors( err );
       
   380 
       
   381     if ( retVal == KErrAccessDenied )
       
   382         {
       
   383         iCurServerDisconnectDenied = ETrue;
       
   384         }
       
   385 
       
   386     iPluginState = EIMPSAOPluginRunning;
       
   387 
       
   388     // regardless of the result of logout, if there came a login event during
       
   389     // the login, call DoLogout
       
   390     if ( iEventInQueue )
       
   391         {
       
   392         iEventInQueue = EFalse;
       
   393         iQueuedLogoutIsScheduledLogout = EFalse;
       
   394         DoLogin();
       
   395         }
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // CIMAlwaysOnlinePlugin::CheckPluginNeed()
       
   400 // Checks if the autologin option is set.
       
   401 // ---------------------------------------------------------
       
   402 //
       
   403 TBool CIMPSAlwaysOnlinePluginImp::CheckPluginNeed()
       
   404     {
       
   405     IMPSCUI_DP_FUNC_ENTER( "CheckPluginNeed" );
       
   406 
       
   407     TInt readValue( KErrCouldNotConnect ); // initialize to an error value
       
   408 
       
   409     TInt err( iSharedDataServiceSettings->GetIntKey( iKeys.LoginTypeKey(), readValue ) );
       
   410     if ( ( err != KErrNone ) ||
       
   411          ( readValue < iKeys.MinLoginTypeEnum()  ) ||
       
   412          ( readValue > iKeys.MaxLoginTypeEnum() ) )
       
   413         {
       
   414         return EFalse;
       
   415         }
       
   416 
       
   417     iAutoLogin = readValue;
       
   418 
       
   419     IMPSCUI_DP_FUNC_DONE( "CheckPluginNeed" );
       
   420     if ( iShowRoamingWarning )
       
   421         {
       
   422         return ETrue;
       
   423         }
       
   424     else
       
   425         {
       
   426         return ( ( readValue == iKeys.LoginAutoAlwaysEnum() ) ||
       
   427                  ( readValue == iKeys.LoginAutoInHomeNWEnum() ) );
       
   428         }
       
   429     }
       
   430 
       
   431 
       
   432 void CIMPSAlwaysOnlinePluginImp::SetShowRoamingWarning( TBool aShowRoamWarning )
       
   433     {
       
   434     iShowRoamingWarning = aShowRoamWarning;
       
   435     }
       
   436 
       
   437 
       
   438 // ---------------------------------------------------------
       
   439 // CIMPSAlwaysOnlinePluginImp::CheckAllConnectionVariables
       
   440 // Checks the plugin variables and makes a login or logout
       
   441 // if needed.
       
   442 // ---------------------------------------------------------
       
   443 //
       
   444 void CIMPSAlwaysOnlinePluginImp::CheckAllConnectionVariables()
       
   445     {
       
   446     IMPSCUI_DP_FUNC_ENTER( "CheckAllConnectionVariablesL" );
       
   447 
       
   448     IMPSCUI_DP( D_IMPSCUI_LIT( "iNetworkOpsAllowed = %d " ), iNetworkOpsAllowed );
       
   449     IMPSCUI_DP( D_IMPSCUI_LIT( "iUserControlledConnection = %d " ), iUserControlledConnection );
       
   450     IMPSCUI_DP( D_IMPSCUI_LIT( "iAutoLogin = %d " ), iAutoLogin );
       
   451     IMPSCUI_DP( D_IMPSCUI_LIT( "iScheduledLoginOk = %d " ), iScheduledLoginOk );
       
   452     IMPSCUI_DP( D_IMPSCUI_LIT( "iCurServerDisconnectDenied = %d " ), iCurServerDisconnectDenied );
       
   453     IMPSCUI_DP( D_IMPSCUI_LIT( "iRoaming = %d " ), iRoaming );
       
   454 
       
   455     // network operations not allowed
       
   456     if ( !IsNetworkOperationsAllowed() )
       
   457         {
       
   458         IMPSCUI_DP_TXT( "NetworkOps NOT allowed" );
       
   459         IMPSCUI_DP_FUNC_DONE( "CheckAllConnectionVariablesL" );
       
   460         return;
       
   461         }
       
   462 
       
   463     // autogin not set
       
   464     // -> don't do anything
       
   465     else if ( ( iAutoLogin != iKeys.LoginAutoAlwaysEnum() ) &&
       
   466               ( iAutoLogin != iKeys.LoginAutoInHomeNWEnum() ) )
       
   467         {
       
   468         IMPSCUI_DP_TXT( "autologin NOT set" );
       
   469         IMPSCUI_DP_FUNC_DONE( "CheckAllConnectionVariablesL" );
       
   470         return;
       
   471         }
       
   472     // we already know that autologin is set -> no need to check that
       
   473     // check if scheduled login not ok
       
   474     else if ( !iScheduledLoginOk )
       
   475         {
       
   476         IMPSCUI_DP_TXT( "Scheduled Login NOT on" );
       
   477         DoLogout( ETrue );
       
   478         }
       
   479 
       
   480     else if ( ( iAutoLogin == iKeys.LoginAutoAlwaysEnum() ) ||
       
   481               ( !iRoaming && ( iAutoLogin == iKeys.LoginAutoInHomeNWEnum() ) ) )
       
   482         {
       
   483         // If its Alwayslogin, roaing and roaing warning flag is enabled
       
   484         // then ask user if wants to login
       
   485         if ( ( iAutoLogin == iKeys.LoginAutoAlwaysEnum() ) &&
       
   486              iRoaming &&
       
   487              iShowRoamingWarning )
       
   488             {
       
   489 
       
   490             TBool isUserLoggedIn( EFalse );
       
   491             TRAP_IGNORE( isUserLoggedIn = IsUserLoggedInL() );
       
   492             // If the dialog is not displaying now then show it
       
   493             if ( !( iDlgMonitor &&
       
   494                     iDlgMonitor->IsActive() &&
       
   495                     !isUserLoggedIn ) )
       
   496                 {
       
   497                 TBool isRoamingDlgShown( EFalse );
       
   498                 RProperty roaming;
       
   499                 TInt error = roaming.Get( KIMPSConnUiTemporaryUid, EIMPSSharedKeysRoamingDlgShown, isRoamingDlgShown );
       
   500                 if ( !isRoamingDlgShown && !error )
       
   501                     {
       
   502                     TRAP_IGNORE( HandleRoamingL() );
       
   503                     }
       
   504                 }
       
   505             }
       
   506         else
       
   507             {
       
   508             DoLogin();
       
   509             TBool isLoggedIn( EFalse );
       
   510             TRAP_IGNORE( isLoggedIn = iConnectionUI->LoggedInL( EIMPSConnClientIM ) );
       
   511             if ( iIsToLogoutForRoaming && isLoggedIn )
       
   512                 {
       
   513                 iIsToLogoutForRoaming = EFalse;
       
   514                 DoLogout();
       
   515                 }
       
   516             }
       
   517         }
       
   518     // check the roaing is on and we are in autologin state
       
   519     else if ( ( iAutoLogin == iKeys.LoginAutoInHomeNWEnum() ) && iRoaming )
       
   520         {
       
   521         DoLogout();
       
   522         }
       
   523     IMPSCUI_DP_FUNC_DONE( "CheckAllConnectionVariablesL" );
       
   524     }
       
   525 
       
   526 // ---------------------------------------------------------
       
   527 // CIMPSAlwaysOnlinePluginImp::HandlePresenceEventL
       
   528 // Handles the presence event change
       
   529 // ---------------------------------------------------------
       
   530 //
       
   531 #if 0
       
   532 void HandlePresenceEventL( CIMPSConnUiPresEventNotifier* /*aNotifier*/,
       
   533                            const CPEngNWSessionSlotID2& /*aSessionSlotID*/,
       
   534                            TIMPSConnectionClient /*aClient*/,
       
   535                            TIMPSPresenceServiceEvent aEvent )
       
   536     {
       
   537     IMPSCUI_DP_FUNC_ENTER( "HandlePresenceEventL" );
       
   538     IMPSCUI_DP( D_IMPSCUI_LIT( "aEvent [%d]" ), aEvent );
       
   539 
       
   540     // check the previous state before deciding what to do?
       
   541     if ( ( aEvent == EPEngEventAppNWPresenceSessionClosed ) &&
       
   542          ( iPreviousEvent == EPEngPresenceServiceNetworkDown ) )
       
   543         {
       
   544 
       
   545         CheckAllConnectionVariables();
       
   546         }
       
   547     iPreviousEvent = aEvent;
       
   548 
       
   549     IMPSCUI_DP_FUNC_DONE( "HandlePresenceEventL" );
       
   550     }
       
   551 #endif
       
   552 
       
   553 // ---------------------------------------------------------
       
   554 // CIMPSAlwaysOnlinePluginImp::HandlePermanentKeyNotifyL()
       
   555 //
       
   556 // (other items were commented in a header).
       
   557 // ---------------------------------------------------------
       
   558 //
       
   559 void  CIMPSAlwaysOnlinePluginImp::HandlePermanentKeyNotifyL( const TUid /* aUid */,
       
   560                                                              const TIMPSSharedKeys /* aKey */ )
       
   561     {
       
   562     IMPSCUI_DP_FUNC_ENTER( "HandlePermanentKeyNotifyL" );
       
   563     IMPSCUI_DP_FUNC_DONE( "HandlePermanentKeyNotifyL" );
       
   564     }
       
   565 
       
   566 // ---------------------------------------------------------
       
   567 // CIMPSAlwaysOnlinePluginImp::HandleTemporaryKeyNotifyL()
       
   568 //
       
   569 // (other items were commented in a header).
       
   570 // ---------------------------------------------------------
       
   571 //
       
   572 void CIMPSAlwaysOnlinePluginImp::HandleTemporaryKeyNotifyL( const TUid aUid,
       
   573                                                             const TIMPSSharedKeys aKey )
       
   574     {
       
   575     IMPSCUI_DP_FUNC_ENTER( "HandleTemporaryKeyNotifyL" );
       
   576     if ( ( aUid == KIMPSServSettNotifyUid ) &&
       
   577          ( aKey == iKeys.LoginTypeChangedKey() ) )
       
   578         {
       
   579         CheckPluginNeed();
       
   580         CheckAllConnectionVariables();
       
   581         }
       
   582     IMPSCUI_DP_FUNC_DONE( "HandleTemporaryKeyNotifyL" );
       
   583     }
       
   584 
       
   585 #if 0
       
   586 // ---------------------------------------------------------
       
   587 // CIMPSAlwaysOnlinePluginImp::HandleEventNotifyError
       
   588 // ---------------------------------------------------------
       
   589 //
       
   590 void CIMPSAlwaysOnlinePluginImp::HandlePresenceEventNotifyError(
       
   591     CIMPSConnUiPresEventNotifier* /*aNotifier*/,
       
   592     TInt aError )
       
   593     {
       
   594     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::HandleEventNotifyError [%d]" ), aError );
       
   595     // check memory errors, other errors ignored
       
   596     CheckMemoryErrors( aError );
       
   597     }
       
   598 #endif
       
   599 
       
   600 // ---------------------------------------------------------
       
   601 // CIMPSAlwaysOnlinePluginImp::HandleScheduleEvent
       
   602 // ---------------------------------------------------------
       
   603 //
       
   604 void CIMPSAlwaysOnlinePluginImp::HandleScheduleEvent( TBool aIsScheduledLoginOk )
       
   605     {
       
   606     IMPSCUI_DP_FUNC_ENTER( "HandleScheduleEvent" );
       
   607     IMPSCUI_DP( D_IMPSCUI_LIT( "aIsScheduledLoginOk [%d]" ), aIsScheduledLoginOk );
       
   608     iUserControlledConnection = EFalse;
       
   609     iScheduledLoginOk = aIsScheduledLoginOk;
       
   610     if ( !aIsScheduledLoginOk )
       
   611         {
       
   612         iReconnectNoteHandler->CancelNoteShowing( this );
       
   613         }
       
   614     CheckPluginNeed(); // just in case that login type has changed same time
       
   615     CheckAllConnectionVariables();
       
   616     IMPSCUI_DP_FUNC_DONE( "HandleScheduleEvent" );
       
   617     }
       
   618 
       
   619 // ---------------------------------------------------------
       
   620 // CIMPSAlwaysOnlinePluginImp::HandleNwStatusChangeL
       
   621 // ---------------------------------------------------------
       
   622 //
       
   623 void CIMPSAlwaysOnlinePluginImp::HandleNwStatusChange( TBool aNwAvailable )
       
   624     {
       
   625     IMPSCUI_DP_FUNC_ENTER( "HandleNwStatusChange" );
       
   626     IMPSCUI_DP( D_IMPSCUI_LIT( "aNwAvailable [%d]" ), aNwAvailable );
       
   627 
       
   628     if ( aNwAvailable )
       
   629         {
       
   630         CheckAllConnectionVariables();
       
   631         }
       
   632     IMPSCUI_DP_FUNC_DONE( "HandleNwStatusChange" );
       
   633     }
       
   634 
       
   635 // ---------------------------------------------------------
       
   636 // CIMPSAlwaysOnlinePluginImp::HandleNoteAnswered
       
   637 // ---------------------------------------------------------
       
   638 //
       
   639 void CIMPSAlwaysOnlinePluginImp::HandleNoteAnswered( TInt aAnswer )
       
   640     {
       
   641     IMPSCUI_DP_FUNC_ENTER( "HandleNoteAnswered" );
       
   642     IMPSCUI_DP( D_IMPSCUI_LIT( "aAnswer [%d]" ), aAnswer );
       
   643 
       
   644     if ( aAnswer == EAknSoftkeyYes )
       
   645         {
       
   646         iLoginCount++; // competing login "round" to
       
   647         // avoid note showing too early next time
       
   648         CheckAllConnectionVariables();
       
   649         }
       
   650     else
       
   651         {
       
   652         Reset();
       
   653         }
       
   654     IMPSCUI_DP_FUNC_DONE( "HandleNoteAnswered" );
       
   655     }
       
   656 
       
   657 // ---------------------------------------------------------
       
   658 // CIMPSAlwaysOnlinePluginImp::HandleNoteCancelled
       
   659 // ---------------------------------------------------------
       
   660 //
       
   661 void CIMPSAlwaysOnlinePluginImp::HandleNoteCancelled()
       
   662     {
       
   663     IMPSCUI_DP_FUNC_ENTER( "HandleNoteCancelled" );
       
   664     IMPSCUI_DP_FUNC_DONE( "HandleNoteCancelled" );
       
   665     }
       
   666 
       
   667 // ---------------------------------------------------------
       
   668 // CIMPSAlwaysOnlinePluginImp::HandleRoamingChangeL
       
   669 // Handles network change event
       
   670 // ---------------------------------------------------------
       
   671 //
       
   672 void CIMPSAlwaysOnlinePluginImp::SetRoaming( TBool aRoamingStatus )
       
   673     {
       
   674     IMPSCUI_DP_FUNC_ENTER( "SetRoaming" );
       
   675     IMPSCUI_DP( D_IMPSCUI_LIT( "aRoamingStatus [%d]" ), aRoamingStatus );
       
   676     iRoaming = aRoamingStatus;
       
   677 
       
   678     CheckAllConnectionVariables();
       
   679     IMPSCUI_DP_FUNC_DONE( "SetRoaming" );
       
   680     }
       
   681 
       
   682 
       
   683 //----------------------------------------------------------
       
   684 // Checks if setting is Auto login in home n/w
       
   685 //----------------------------------------------------------
       
   686 //
       
   687 TBool CIMPSAlwaysOnlinePluginImp::IsLoginAutoInHomeNW()
       
   688     {
       
   689     if ( iAutoLogin == iKeys.LoginAutoInHomeNWEnum() )
       
   690         {
       
   691         return ETrue;
       
   692         }
       
   693 
       
   694     return EFalse;
       
   695     }
       
   696 
       
   697 
       
   698 //----------------------------------------------------------
       
   699 // Checks if user is logged in or not
       
   700 //----------------------------------------------------------
       
   701 //
       
   702 TBool CIMPSAlwaysOnlinePluginImp::IsUserLoggedInL()
       
   703     {
       
   704     if ( iConnectionUI )
       
   705         {
       
   706         return iConnectionUI->LoggedInL( EIMPSConnClientIM );
       
   707         }
       
   708     return EFalse;
       
   709     }
       
   710 
       
   711 
       
   712 //----------------------------------------------------------
       
   713 // Handles the roaing status
       
   714 // Handles roaing status
       
   715 //----------------------------------------------------------
       
   716 //
       
   717 void CIMPSAlwaysOnlinePluginImp::HandleRoamingL()
       
   718     {
       
   719     if ( !iGlobalMsgQuery )
       
   720         {
       
   721         iGlobalMsgQuery = CAknGlobalMsgQuery::NewL();
       
   722         }
       
   723     iGlobalMsgQuery->CancelMsgQuery();
       
   724     iDlgMonitor->Start();
       
   725 
       
   726     if ( !iRoamingQueryText )
       
   727         {
       
   728         iRoamingQueryText = ReadResourceLC( R_QTN_NOTE_ROAMING_ORANGE );
       
   729         CleanupStack::Pop();
       
   730         }
       
   731 
       
   732     if ( !iRoamingQueryTitle )
       
   733         {
       
   734         iRoamingQueryTitle = ReadResourceLC( R_QTN_NOTE_TITLE_ROAMING_ORANGE );
       
   735         CleanupStack::Pop();
       
   736         }
       
   737 
       
   738     iGlobalMsgQuery->ShowMsgQueryL( iDlgMonitor->iStatus, *iRoamingQueryText,
       
   739                                     R_AVKON_SOFTKEYS_YES_NO,
       
   740                                     *iRoamingQueryTitle ,
       
   741                                     KNullDesC );
       
   742     }
       
   743 
       
   744 
       
   745 //----------------------------------------------------------
       
   746 // CIMPSAlwaysOnlinePluginImp::CommonDialogDismissedL()
       
   747 // Handle user action for roaing warning dialog.
       
   748 //----------------------------------------------------------
       
   749 //
       
   750 void CIMPSAlwaysOnlinePluginImp::CommonDialogDismissedL( const TInt aStatusCode )
       
   751     {
       
   752     // Handle user action for roaing warning.
       
   753     switch ( aStatusCode )
       
   754         {
       
   755         case EAknSoftkeyNo:
       
   756             {
       
   757             if ( iConnectionUI->LoggedInL( EIMPSConnClientIM ) )
       
   758                 {
       
   759                 DoLogout();
       
   760                 }
       
   761             else
       
   762                 {
       
   763                 iIsToLogoutForRoaming = ETrue;
       
   764                 }
       
   765             break;
       
   766             }
       
   767         case EAknSoftkeyYes:
       
   768             {
       
   769             // Set the key that warning is shown once for session
       
   770             User::LeaveIfError( RProperty::Set( KIMPSConnUiTemporaryUid,
       
   771                                                 EIMPSSharedKeysRoamingDlgShown,
       
   772                                                 ETrue ) );
       
   773 
       
   774             // Do nothing if user is already logged in. Else login
       
   775             if ( !iConnectionUI->LoggedInL( EIMPSConnClientIM ) )
       
   776                 {
       
   777                 DoLogin();
       
   778                 }
       
   779             }
       
   780         default:
       
   781             {
       
   782             break;
       
   783             }
       
   784         }
       
   785     }
       
   786 
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CPEngAlwaysOnlinePlugin::ReadResourceLC()
       
   790 // -----------------------------------------------------------------------------
       
   791 //
       
   792 HBufC* CIMPSAlwaysOnlinePluginImp::ReadResourceLC( TInt aResourceId )
       
   793     {
       
   794     //Own resource reader for AA plug-in environment (no CONE facilities available)
       
   795     TInt plainResourceId = 0x00000fff & aResourceId; // Remove offset from id
       
   796 
       
   797     HBufC8* rawDataBuf = iResFile.AllocReadLC( plainResourceId );
       
   798 
       
   799     //raw data buffer is actually unicode text ==> treat it so
       
   800     TPtrC16 rawData( ( TUint16* ) rawDataBuf->Ptr(),
       
   801                      rawDataBuf->Length() / 2 );
       
   802 
       
   803     HBufC16* resourceData = rawData.AllocL();
       
   804     CleanupStack::PopAndDestroy( rawDataBuf );
       
   805 
       
   806     CleanupStack::PushL( resourceData );
       
   807 
       
   808     return resourceData;
       
   809     }
       
   810 
       
   811 
       
   812 // ---------------------------------------------------------
       
   813 // CIMPSAlwaysOnlinePluginImp::HandleTimeWaited
       
   814 //
       
   815 // ---------------------------------------------------------
       
   816 //
       
   817 void CIMPSAlwaysOnlinePluginImp::HandleTimeWaited()
       
   818     {
       
   819     IMPSCUI_DP_FUNC_ENTER( "HandleTimeWaited" );
       
   820     CheckAllConnectionVariables();
       
   821     IMPSCUI_DP_FUNC_DONE( "HandleTimeWaited" );
       
   822     }
       
   823 
       
   824 void CIMPSAlwaysOnlinePluginImp::HandleTimeWaitedError( TInt aError )
       
   825     {
       
   826     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::HandleTimeWaitedError [%d]" ), aError );
       
   827     if ( aError != KErrCancel )
       
   828         {
       
   829         CheckAllConnectionVariables();
       
   830         }
       
   831     IMPSCUI_DP_FUNC_DONE( "HandleTimeWaitedError" );
       
   832     }
       
   833 
       
   834 // ---------------------------------------------------------
       
   835 // CIMPSAlwaysOnlinePluginImp::HandleConnectionModeEventL
       
   836 //
       
   837 // ---------------------------------------------------------
       
   838 //
       
   839 void CIMPSAlwaysOnlinePluginImp::HandleConnectionModeEventL(
       
   840     CIMPSConnUiConnectionModeNotifier* aNotifier,
       
   841     TIMPSConnectionModeEvent aEvent )
       
   842     {
       
   843     IMPSCUI_DP_FUNC_ENTER( "HandleConnectionModeEventL" );
       
   844     IMPSCUI_DP( D_IMPSCUI_LIT( "aEvent [%d]" ), aEvent );
       
   845     if ( aNotifier == iConnectionNotifier )
       
   846         {
       
   847         if ( aEvent == EIMPSCMEUserLevelLogin )
       
   848             {
       
   849             iUserControlledConnection = ETrue;
       
   850             // reset connection count and stop timer
       
   851             Reset();
       
   852             // no need for checking connection variables in this case --> return
       
   853             IMPSCUI_DP_FUNC_DONE( "HandleConnectionModeEventL" );
       
   854 
       
   855             if ( iIsToLogoutForRoaming )
       
   856                 {
       
   857                 iIsToLogoutForRoaming = EFalse;
       
   858                 DoLogout();
       
   859                 }
       
   860             return;
       
   861             }
       
   862 
       
   863         if ( aEvent == EIMPSCMEUserLevelLogout )
       
   864             {
       
   865             if ( iCurServerDisconnectDenied )
       
   866                 {
       
   867                 // logout from different server than default
       
   868                 // because current server disconnect was denied
       
   869                 // free to open connection to default server
       
   870                 iUserControlledConnection = EFalse;
       
   871                 }
       
   872             else
       
   873                 {
       
   874                 // logout from default server, user controlled
       
   875                 // logout, because cannot make new login default
       
   876                 // server until next connection start time.
       
   877                 iUserControlledConnection = ETrue;
       
   878                 }
       
   879             iCurServerDisconnectDenied = EFalse;
       
   880             }
       
   881 
       
   882         else if ( aEvent == EIMPSCMELastSSClientStop )
       
   883             {
       
   884             iUserControlledConnection = EFalse;
       
   885             iCurServerDisconnectDenied = EFalse;
       
   886             }
       
   887         CheckAllConnectionVariables();
       
   888         }
       
   889     IMPSCUI_DP_FUNC_DONE( "HandleConnectionModeEventL" );
       
   890     }
       
   891 
       
   892 // ---------------------------------------------------------
       
   893 // CIMPSAlwaysOnlinePluginImp::HandleConnectionModeEventNotifyError
       
   894 //
       
   895 // ---------------------------------------------------------
       
   896 //
       
   897 void CIMPSAlwaysOnlinePluginImp::HandleConnectionModeEventNotifyError(
       
   898     CIMPSConnUiConnectionModeNotifier* aNotifier,
       
   899     TInt aError )
       
   900     {
       
   901     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::HandleConnectionModeEventNotifyError [%d]" ), aError );
       
   902 
       
   903     CheckMemoryErrors( aError );
       
   904 
       
   905     if ( ( aError != KErrCancel ) && ( aError != KErrServerTerminated ) )
       
   906         {
       
   907         // must be trapped as the inherited method isn't leavable
       
   908         // leave can be ignored as there's nothing we can do about it
       
   909         if ( aNotifier == iConnectionNotifier )
       
   910             {
       
   911             TRAPD( err, iConnectionNotifier->StartL() );
       
   912             CheckMemoryErrors( err );
       
   913             }
       
   914         }
       
   915     }
       
   916 
       
   917 // ---------------------------------------------------------
       
   918 // CIMPSAlwaysOnlinePluginImp::AllowNetworkOperations
       
   919 //
       
   920 // ---------------------------------------------------------
       
   921 //
       
   922 void CIMPSAlwaysOnlinePluginImp::SetNetworkOpsAllowed( TBool aAllowed )
       
   923     {
       
   924     IMPSCUI_DP_FUNC_ENTER( "SetNetworkOpsAllowed" );
       
   925     IMPSCUI_DP( D_IMPSCUI_LIT( "aAllowed [%d]" ), aAllowed );
       
   926 
       
   927     TBool previousNetworkOpsAllowed( iNetworkOpsAllowed );
       
   928     iNetworkOpsAllowed = aAllowed;
       
   929     // wait for a while before checking the variables after setting this on
       
   930     // because the network isn't available immediately
       
   931     // and only do it if we changed from offline to not-offline
       
   932     if ( !previousNetworkOpsAllowed && iNetworkOpsAllowed )
       
   933         {
       
   934         iWaitReason = EIMPSAOPluginWaitingForLogin;
       
   935         if ( iTimer->IsActive() )
       
   936             {
       
   937             iTimer->Cancel();
       
   938             }
       
   939 
       
   940         TTimeIntervalMicroSeconds32 wTime( KWaitTimeFromOfflineToNotOffline );
       
   941         iTimer->After( wTime );
       
   942         }
       
   943     else
       
   944         {
       
   945         CheckAllConnectionVariables();
       
   946         }
       
   947 
       
   948     IMPSCUI_DP_FUNC_DONE( "SetNetworkOpsAllowed" );
       
   949     }
       
   950 
       
   951 // ---------------------------------------------------------
       
   952 // CIMPSAlwaysOnlinePluginImp::StartPluginL
       
   953 //
       
   954 // ---------------------------------------------------------
       
   955 //
       
   956 void CIMPSAlwaysOnlinePluginImp::InitializePluginL()
       
   957     {
       
   958     if ( !iReconnectNoteHandler )
       
   959         {
       
   960         iReconnectNoteHandler = CIMPSReconnectNoteHandler::NewL( EIMPSConnClientIM );
       
   961         }
       
   962     if ( !iCallObserver )
       
   963         {
       
   964         iCallObserver = CPEngAOCallObserver::NewL();
       
   965         }
       
   966 
       
   967     if ( !iScheduler )
       
   968         {
       
   969         iScheduler = CIMPSAlwaysOnlineScheduler::NewL( iKeys );
       
   970         iScheduler->SetObserver( this );
       
   971         }
       
   972 
       
   973     if ( !iTimer )
       
   974         {
       
   975         iTimer = CPEngAOPluginTimer::NewL();
       
   976         }
       
   977 
       
   978     if ( !iConnectionNotifier )
       
   979         {
       
   980         // get notifys when the connection mode changes
       
   981         iConnectionNotifier =
       
   982             CIMPSConnUiConnectionModeNotifier::NewL( EIMPSConnClientIM );
       
   983         iConnectionNotifier->AddObserverL( this );
       
   984         }
       
   985 
       
   986     iConnectionUI = CIMPSPresenceAAConnection::NewL( EIMPSConnClientIM );
       
   987 
       
   988     if ( !iErrorUI )
       
   989         {
       
   990         // error ui for error notes showing
       
   991         iErrorUI = CErrorUI::NewL();
       
   992         }
       
   993     }
       
   994 
       
   995 // ---------------------------------------------------------
       
   996 // CIMPSAlwaysOnlinePluginImp::InitializePluginL
       
   997 //
       
   998 // ---------------------------------------------------------
       
   999 //
       
  1000 void CIMPSAlwaysOnlinePluginImp::FreeMemory()
       
  1001     {
       
  1002     delete iTimer;
       
  1003     iTimer = NULL;
       
  1004 
       
  1005     delete iCallObserver;
       
  1006     iCallObserver = NULL;
       
  1007 
       
  1008     delete iConnectionNotifier;
       
  1009     iConnectionNotifier = NULL;
       
  1010 
       
  1011     delete iConnectionUI;
       
  1012     iConnectionUI = NULL;
       
  1013 
       
  1014     delete iScheduler;
       
  1015     iScheduler = NULL;
       
  1016 
       
  1017     delete iErrorUI;
       
  1018     iErrorUI = NULL;
       
  1019 
       
  1020     delete iReconnectNoteHandler;
       
  1021     iReconnectNoteHandler = NULL;
       
  1022     }
       
  1023 
       
  1024 // ---------------------------------------------------------
       
  1025 // CIMPSAlwaysOnlinePluginImp::InitializePluginL
       
  1026 //
       
  1027 // ---------------------------------------------------------
       
  1028 //
       
  1029 void CIMPSAlwaysOnlinePluginImp::StartPluginL()
       
  1030     {
       
  1031     IMPSCUI_DP_FUNC_ENTER( "StartPluginL" );
       
  1032 
       
  1033     // start listening the shared data key events
       
  1034     User::LeaveIfError(
       
  1035         iSettingChangesNotifier->SubscribeSet( KIMPSServSettNotifyUid,
       
  1036                                                iKeys.LoginTypeChangedKey() ) );
       
  1037 
       
  1038     // check need of plugin
       
  1039     if ( CheckPluginNeed() )
       
  1040         {
       
  1041         InitializeSharedKeysL();
       
  1042         InitializePluginL();
       
  1043 
       
  1044         // set this as the timer's observer
       
  1045         iTimer->SetObserver( this );
       
  1046 
       
  1047         iConnectionNotifier->StartL();
       
  1048 
       
  1049         TRAPD( err, iScheduler->StartSchedulingL() );
       
  1050         if ( err )
       
  1051             {
       
  1052             IMPSCUI_DP_TXT( "Scheduling start failed --> autologin NOT on" );
       
  1053             iAutoLogin = iKeys.LoginManualEnum();
       
  1054             Reset(); // reset reconnect functionality
       
  1055             }
       
  1056         iScheduledLoginOk = iScheduler->IsScheduledLoginOk();
       
  1057         }
       
  1058     else
       
  1059         {
       
  1060         IMPSCUI_DP( D_IMPSCUI_LIT( "AutoLogin NOT on --> stopping scheduling" ) );
       
  1061         if ( iScheduler )
       
  1062             {
       
  1063             iScheduler->StopScheduling();
       
  1064             iScheduledLoginOk = iScheduler->IsScheduledLoginOk();
       
  1065             }
       
  1066         Reset(); // reset reconnect functionality
       
  1067         }
       
  1068 
       
  1069     IMPSCUI_DP_FUNC_DONE( "StartPluginL" );
       
  1070     }
       
  1071 
       
  1072 // ---------------------------------------------------------
       
  1073 // CIMPSAlwaysOnlinePluginImp::StopPlugin
       
  1074 //
       
  1075 // ---------------------------------------------------------
       
  1076 //
       
  1077 void CIMPSAlwaysOnlinePluginImp::StopPlugin()
       
  1078     {
       
  1079     IMPSCUI_DP_FUNC_ENTER( "StopPlugin" );
       
  1080 
       
  1081     if ( iScheduler )
       
  1082         {
       
  1083         iScheduler->StopScheduling();
       
  1084         }
       
  1085 
       
  1086     // stop listening to presence events
       
  1087     if ( iConnectionNotifier )
       
  1088         {
       
  1089         iConnectionNotifier->Stop();
       
  1090         }
       
  1091 
       
  1092     iSettingChangesNotifier->UnSubscribe( KIMPSServSettNotifyUid,
       
  1093                                           iKeys.LoginTypeChangedKey() );
       
  1094     if ( iCallObserver )
       
  1095         {
       
  1096         iCallObserver->StopObserving();
       
  1097         }
       
  1098 
       
  1099     if ( iTimer )
       
  1100         {
       
  1101         if ( iTimer->IsActive() )
       
  1102             {
       
  1103             iTimer->Cancel();
       
  1104             }
       
  1105         }
       
  1106 
       
  1107     iNwObserver->StopObserving();
       
  1108 
       
  1109     if ( iConnectionUI )
       
  1110         {
       
  1111         DoLogout();
       
  1112         }
       
  1113 
       
  1114     FreeMemory();
       
  1115     IMPSCUI_DP_FUNC_DONE( "StopPlugin" );
       
  1116     }
       
  1117 
       
  1118 // ---------------------------------------------------------
       
  1119 // CIMPSAlwaysOnlinePluginImp::Reset()
       
  1120 // Resets the plugin
       
  1121 // ---------------------------------------------------------
       
  1122 //
       
  1123 void CIMPSAlwaysOnlinePluginImp::Reset()
       
  1124     {
       
  1125     IMPSCUI_DP_FUNC_ENTER( "Reset" );
       
  1126 
       
  1127     iLoginCount = 1; // first login
       
  1128     iPluginState = EIMPSAOPluginRunning;
       
  1129     if ( iTimer )
       
  1130         {
       
  1131         if ( iTimer->IsActive() )
       
  1132             {
       
  1133             iTimer->Cancel();
       
  1134             }
       
  1135         }
       
  1136     IMPSCUI_DP_FUNC_DONE( "Reset" );
       
  1137     }
       
  1138 
       
  1139 // ---------------------------------------------------------
       
  1140 // CIMPSAlwaysOnlinePluginImp::StartWaiting
       
  1141 //
       
  1142 // ---------------------------------------------------------
       
  1143 //
       
  1144 void CIMPSAlwaysOnlinePluginImp::StartWaiting()
       
  1145     {
       
  1146     IMPSCUI_DP_FUNC_ENTER( "StartWaiting" );
       
  1147 
       
  1148     TTimeIntervalMinutes waitInMinutes( KDefaultLoginWaitTime );
       
  1149 
       
  1150     // then add the wait time according to what login try it is
       
  1151     if ( iLoginCount < KMaxNumberOfDefinedWaitTimes )
       
  1152         {
       
  1153         waitInMinutes = KLoginWaitTime[iLoginCount];
       
  1154         }
       
  1155 
       
  1156 
       
  1157     TTime timeToKickIn;
       
  1158 
       
  1159     // get the what the time is right now
       
  1160     timeToKickIn.HomeTime();
       
  1161 
       
  1162     if ( timeToKickIn >= ( iTimeBeforeLoginTry + waitInMinutes ) )
       
  1163         {
       
  1164         // login attempt has
       
  1165         // taken more time than defined wait time
       
  1166         // --> starting new login immediately
       
  1167         IMPSCUI_DP_TXT( "Login attempt has taken more time than wait time" );
       
  1168         IMPSCUI_DP_TXT( "Check all connection variables immediately" );
       
  1169         CheckAllConnectionVariables();
       
  1170         IMPSCUI_DP_FUNC_DONE( "StartWaiting" );
       
  1171         return;
       
  1172         }
       
  1173 
       
  1174     if ( timeToKickIn <= iTimeBeforeLoginTry )
       
  1175         {
       
  1176         // clock turned backwards during login attempt
       
  1177         // so current time used as base for calculations of new login attempt
       
  1178         IMPSCUI_DP_TXT( "Clock turned backwards during login attempt" );
       
  1179         IMPSCUI_DP_TXT( "Using current time as base for new login attempt calculations" );
       
  1180         timeToKickIn += waitInMinutes;
       
  1181         }
       
  1182     else
       
  1183         {
       
  1184         IMPSCUI_DP_TXT( "Normal situation" );
       
  1185         IMPSCUI_DP_TXT( "Using time before login as base for new login attempt calculations" );
       
  1186         timeToKickIn = ( iTimeBeforeLoginTry + waitInMinutes );
       
  1187         }
       
  1188 
       
  1189     // and start waiting
       
  1190     iWaitReason = EIMPSAOPluginWaitingForLogin;
       
  1191     StartTimer( timeToKickIn );
       
  1192     IMPSCUI_DP_FUNC_DONE( "StartWaiting" );
       
  1193     }
       
  1194 
       
  1195 // ---------------------------------------------------------
       
  1196 // CIMPSAlwaysOnlinePluginImp::StartTimer
       
  1197 //
       
  1198 // ---------------------------------------------------------
       
  1199 //
       
  1200 void CIMPSAlwaysOnlinePluginImp::StartTimer( TTime aTime )
       
  1201     {
       
  1202     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSAlwaysOnlinePluginImp::StartTimer" ) );
       
  1203 
       
  1204     if ( iTimer->IsActive() )
       
  1205         {
       
  1206         iTimer->Cancel();
       
  1207         }
       
  1208 
       
  1209     TDateTime launchTime( aTime.DateTime() );
       
  1210 
       
  1211     IMPSCUI_DP( D_IMPSCUI_LIT( "Waiting for [%d] at:" ), iWaitReason );
       
  1212     IMPSCUI_DP( D_IMPSCUI_LIT( "year [%d] " ), launchTime.Year() );
       
  1213     IMPSCUI_DP( D_IMPSCUI_LIT( "day [%d], month [%d]" ), launchTime.Day() + 1,
       
  1214                 launchTime.Month() + 1 );
       
  1215     IMPSCUI_DP( D_IMPSCUI_LIT( "hour [%d], minu [%d]" ), launchTime.Hour(),
       
  1216                 launchTime.Minute() );
       
  1217 
       
  1218     iTimer->At( aTime );
       
  1219     }
       
  1220 
       
  1221 // ---------------------------------------------------------
       
  1222 // CIMPSAlwaysOnlinePluginImp::HandleCallEnded
       
  1223 //
       
  1224 // ---------------------------------------------------------
       
  1225 //
       
  1226 void CIMPSAlwaysOnlinePluginImp::HandleCallEndedL( TBool aEnded )
       
  1227     {
       
  1228     IMPSCUI_DP_FUNC_ENTER( "HandleCallEndedL" );
       
  1229     IMPSCUI_DP( D_IMPSCUI_LIT( "aEnded [%d]" ), aEnded );
       
  1230 
       
  1231     if ( aEnded )
       
  1232         {
       
  1233         CheckAllConnectionVariables();
       
  1234         }
       
  1235 
       
  1236     IMPSCUI_DP_FUNC_DONE( "HandleCallEndedL" );
       
  1237     }
       
  1238 
       
  1239 
       
  1240 // ---------------------------------------------------------
       
  1241 // CIMPSAlwaysOnlinePluginImp::CheckMemoryErrors
       
  1242 //
       
  1243 // ---------------------------------------------------------
       
  1244 //
       
  1245 TBool CIMPSAlwaysOnlinePluginImp::CheckMemoryErrors( TInt aError )
       
  1246     {
       
  1247     TInt retval( EFalse );
       
  1248     if ( ( aError == KErrNoMemory ) || ( aError == KErrDiskFull ) )
       
  1249         {
       
  1250         // Leaves on errornote showing are ignored, because
       
  1251         // cannot do anymore if errorhandling itself fails.
       
  1252         TInt ignore;
       
  1253         TRAP( ignore, iErrorUI->ShowGlobalErrorNoteL( aError ) );
       
  1254         retval = ETrue;
       
  1255         }
       
  1256     return retval;
       
  1257     }
       
  1258 
       
  1259 // ---------------------------------------------------------
       
  1260 // CIMPSAlwaysOnlinePluginImp::IsNetworkOperationsAllowed
       
  1261 //
       
  1262 // ---------------------------------------------------------
       
  1263 //
       
  1264 TBool CIMPSAlwaysOnlinePluginImp::IsNetworkOperationsAllowed()
       
  1265     {
       
  1266     TInt retval( ETrue );
       
  1267 
       
  1268     // Network operations are not allowed
       
  1269     // the user controlled login / logout event is active or
       
  1270     // network is not available
       
  1271     // or with previous login attempt disconnect from previous
       
  1272     // server ( other than default, which ao plugin is using )
       
  1273     // was denied
       
  1274     if ( !iNetworkOpsAllowed ||
       
  1275          iUserControlledConnection ||
       
  1276          !iNwObserver->IsNetworkAvailable() ||
       
  1277          iCurServerDisconnectDenied )
       
  1278         {
       
  1279         retval = EFalse;
       
  1280         }
       
  1281     return retval;
       
  1282     }
       
  1283 
       
  1284 // ---------------------------------------------------------
       
  1285 // CIMPSAlwaysOnlinePluginImp::InitializeSharedKeysL
       
  1286 //
       
  1287 // ---------------------------------------------------------
       
  1288 //
       
  1289 void CIMPSAlwaysOnlinePluginImp::InitializeSharedKeysL()
       
  1290     {
       
  1291     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1292                        EIMPSSharedKeysServSettLoginTypeChangedPEC,
       
  1293                        RProperty::EInt,
       
  1294                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1295     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1296                        EIMPSSharedKeysServSettLoginTypeChangedIM,
       
  1297                        RProperty::EInt,
       
  1298                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1299     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1300                        EIMPSSharedKeysServSettScheduleChangedPEC,
       
  1301                        RProperty::EInt,
       
  1302                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1303     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1304                        EIMPSSharedKeysServSettScheduleChangedIM,
       
  1305                        RProperty::EInt,
       
  1306                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1307     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1308                        EIMPSSharedKeysIMClientLoginLogoutStateChannel,
       
  1309                        RProperty::EInt,
       
  1310                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1311     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1312                        EIMPSSharedKeysIMLoginLogoutEventChannel,
       
  1313                        RProperty::EInt,
       
  1314                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1315     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1316                        EIMPSSharedKeysIMSSClientReqistrationChannel,
       
  1317                        RProperty::EInt,
       
  1318                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1319     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1320                        EIMPSSharedKeysIMGlobalOperationSignalChannel,
       
  1321                        RProperty::EInt,
       
  1322                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1323     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1324                        EIMPSSharedKeysIMRemoteUiNotificationsChannel,
       
  1325                        RProperty::EInt,
       
  1326                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1327     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1328                        EIMPSSharedKeysPECClientLoginLogoutStateChannel,
       
  1329                        RProperty::EInt,
       
  1330                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1331     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1332                        EIMPSSharedKeysPECLoginLogoutEventChannel,
       
  1333                        RProperty::EInt,
       
  1334                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1335     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1336                        EIMPSSharedKeysPECSSClientReqistrationChannel,
       
  1337                        RProperty::EInt,
       
  1338                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1339     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1340                        EIMPSSharedKeysPECGlobalOperationSignalChannel,
       
  1341                        RProperty::EInt,
       
  1342                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1343     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1344                        EIMPSSharedKeysPECRemoteUiNotificationsChannel,
       
  1345                        RProperty::EInt,
       
  1346                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1347     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1348                        EIMPSSharedKeysCommonClientLoginLogoutStateChannel,
       
  1349                        RProperty::EInt,
       
  1350                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1351     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1352                        EIMPSSharedKeysCommonLoginLogoutEventChannel,
       
  1353                        RProperty::EInt,
       
  1354                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1355     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1356                        EIMPSSharedKeysCommonSSClientReqistrationChannel,
       
  1357                        RProperty::EInt,
       
  1358                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1359     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1360                        EIMPSSharedKeysCommonGlobalOperationSignalChannel,
       
  1361                        RProperty::EInt,
       
  1362                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1363     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1364                        EIMPSSharedKeysCommonRemoteUiNotificationsChannel,
       
  1365                        RProperty::EInt,
       
  1366                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1367 
       
  1368     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1369                        EIMPSSharedKeysIMClientLoginLogoutStateData,
       
  1370                        RProperty::EByteArray,
       
  1371                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1372     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1373                        EIMPSSharedKeysIMLoginLogoutEventData,
       
  1374                        RProperty::EByteArray,
       
  1375                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1376     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1377                        EIMPSSharedKeysIMSSClientReqistrationData,
       
  1378                        RProperty::EByteArray,
       
  1379                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1380     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1381                        EIMPSSharedKeysIMGlobalOperationSignalData,
       
  1382                        RProperty::EByteArray,
       
  1383                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1384     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1385                        EIMPSSharedKeysIMRemoteUiNotificationsData,
       
  1386                        RProperty::EByteArray,
       
  1387                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1388     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1389                        EIMPSSharedKeysPECClientLoginLogoutStateData,
       
  1390                        RProperty::EByteArray,
       
  1391                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1392     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1393                        EIMPSSharedKeysPECLoginLogoutEventData,
       
  1394                        RProperty::EByteArray,
       
  1395                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1396     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1397                        EIMPSSharedKeysPECSSClientReqistrationData,
       
  1398                        RProperty::EByteArray,
       
  1399                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1400     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1401                        EIMPSSharedKeysPECGlobalOperationSignalData,
       
  1402                        RProperty::EByteArray,
       
  1403                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1404     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1405                        EIMPSSharedKeysPECRemoteUiNotificationsData,
       
  1406                        RProperty::EByteArray,
       
  1407                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1408     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1409                        EIMPSSharedKeysCommonClientLoginLogoutStateData,
       
  1410                        RProperty::EByteArray,
       
  1411                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1412     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1413                        EIMPSSharedKeysCommonLoginLogoutEventData,
       
  1414                        RProperty::EByteArray,
       
  1415                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1416     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1417                        EIMPSSharedKeysCommonSSClientReqistrationData,
       
  1418                        RProperty::EByteArray,
       
  1419                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1420     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1421                        EIMPSSharedKeysCommonGlobalOperationSignalData,
       
  1422                        RProperty::EByteArray,
       
  1423                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1424     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1425                        EIMPSSharedKeysCommonRemoteUiNotificationsData,
       
  1426                        RProperty::EByteArray,
       
  1427                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1428 
       
  1429     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1430                        EIMPSSharedKeysIMGlobalChannel,
       
  1431                        RProperty::EInt,
       
  1432                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1433     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1434                        EIMPSSharedKeysPECGlobalChannel,
       
  1435                        RProperty::EInt,
       
  1436                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1437 
       
  1438 
       
  1439     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1440                        EIMPSSharedKeysIMGlobalData,
       
  1441                        RProperty::EByteArray,
       
  1442                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1443     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1444                        EIMPSSharedKeysPECGlobalData,
       
  1445                        RProperty::EByteArray,
       
  1446                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1447 
       
  1448     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1449                        EIMPSSharedKeysRoaming,
       
  1450                        RProperty::EInt,
       
  1451                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1452 
       
  1453     RProperty::Define( KIMPSConnUiTemporaryUid,
       
  1454                        EIMPSSharedKeysRoamingDlgShown,
       
  1455                        RProperty::EInt,
       
  1456                        KIMPSSharedReadPolicy, KIMPSSharedWritePolicy );
       
  1457     }
       
  1458 
       
  1459 //  End of File