wvuing/wvuiave/AppSrc/ccafetchwaiter.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Helper class for waiting fetch process.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "ccafetchwaiter.h"
       
    21 
       
    22 #include "ccaappui.h"
       
    23 #include "CCAUISessionManager.h"
       
    24 
       
    25 #include "impsbuilddefinitions.h"
       
    26 #include "chatdebugprint.h"
       
    27 
       
    28 #include "MCASessionHandlerCmd.h"
       
    29 #include "CCACommandManagerFactory.h"
       
    30 #include "CCACommandManager.h"
       
    31 #include <chatNG.rsg>
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CCAFetchWaiter::NewLC()
       
    38 // ---------------------------------------------------------
       
    39 //
       
    40 CCAFetchWaiter* CCAFetchWaiter::NewLC()
       
    41     {
       
    42     CCAFetchWaiter* self = new ( ELeave ) CCAFetchWaiter();
       
    43     CleanupStack::PushL( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CCAFetchWaiter::~CCAFetchWaiter()
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CCAFetchWaiter::~CCAFetchWaiter()
       
    53     {
       
    54     delete iWaitNote;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CCAFetchWaiter::WaitForSyncCompleteL()
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 TBool CCAFetchWaiter::WaitForFetchCompleteL()
       
    62     {
       
    63     if ( !LoggedIn() )
       
    64         {
       
    65         // Not logged in. No reason to wait
       
    66         return EFalse;
       
    67         }
       
    68 
       
    69     if ( !IsFetchDone() )
       
    70         {
       
    71         iWaitNoteCanceled = EFalse;
       
    72         CCACommandManager* commandManager =  CCACommandManagerFactory::InstanceL()->GetCommandManager();
       
    73         MCASessionHandlerCmd* sessHandlerCmd =  commandManager->GetSessionHandlerCmd() ;
       
    74         if ( sessHandlerCmd )
       
    75             {
       
    76             sessHandlerCmd->AddContactFetchObserverL( this );
       
    77             }
       
    78 
       
    79 
       
    80 
       
    81         iWaitNote = CCAWaitNote::ShowWaitNoteL(
       
    82                         R_QTN_GEN_CHAT_NOTE_PROCESSING,
       
    83                         ETrue, EFalse, this );
       
    84 
       
    85         CHAT_DP_TXT( "CCAFetchWaiter::WaitForFetchCompleteL - start wait" );
       
    86         if ( !iWait.IsStarted() )
       
    87             {
       
    88             iWait.Start();  // CSI: 10 # iWait is not an active object
       
    89             }
       
    90         CHAT_DP_TXT( "CCAFetchWaiter::WaitForFetchCompleteL - end wait" );
       
    91         delete iWaitNote;
       
    92 
       
    93         if ( sessHandlerCmd )
       
    94             {
       
    95             sessHandlerCmd->RemoveContactFetchObserver( this );
       
    96             }
       
    97         iWaitNote = NULL;
       
    98         if ( iWaitNoteCanceled )
       
    99             {
       
   100             return EFalse;
       
   101             }
       
   102         }
       
   103 
       
   104     return ETrue;
       
   105     }
       
   106 
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // CCAFetchWaiter::LoggedIn()
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 TBool CCAFetchWaiter::LoggedIn()
       
   113     {
       
   114     return UISessionManager().IsLoggedIn();
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // CCAFetchWaiter::UISessionManager()
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 CCAUISessionManager& CCAFetchWaiter::UISessionManager()
       
   122     {
       
   123     return static_cast<CCAAppUi*>
       
   124            ( CCoeEnv::Static()->AppUi() )->UISessionManager();
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------
       
   128 // CCAFetchWaiter::IsFetchDone()
       
   129 // ---------------------------------------------------------
       
   130 //
       
   131 TBool CCAFetchWaiter::IsFetchDone()
       
   132     {
       
   133     CCACommandManager* commandManager( NULL );
       
   134     TRAPD( err, commandManager = CCACommandManagerFactory::InstanceL()->GetCommandManager() );
       
   135     if ( err != KErrNone )
       
   136         {
       
   137         return EFalse;
       
   138         }
       
   139     MCASessionHandlerCmd* sessHandlerCmd =  commandManager->GetSessionHandlerCmd() ;
       
   140     if ( sessHandlerCmd )
       
   141         {
       
   142         return sessHandlerCmd->IsFetchDone();
       
   143         }
       
   144     return EFalse;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------
       
   148 // CCAFetchWaiter::CheckFetchStateL()
       
   149 // ---------------------------------------------------------
       
   150 //
       
   151 TBool CCAFetchWaiter::CheckFetchStateL()
       
   152     {
       
   153     TBool retVal = ETrue;
       
   154 
       
   155 #ifndef IMPS_CONTACT_FETCH_BACKGROUND
       
   156 
       
   157     CCAFetchWaiter* waiter = NewLC();
       
   158     retVal = waiter->WaitForFetchCompleteL();
       
   159     CleanupStack::PopAndDestroy(); //waiter
       
   160 
       
   161 #endif //IMPS_CONTACT_FETCH_BACKGROUND
       
   162 
       
   163     return retVal;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CCAFetchWaiter::HandleFetchCompleteL()
       
   168 // ---------------------------------------------------------
       
   169 //
       
   170 void CCAFetchWaiter::HandleFetchCompleteL( TInt aError )
       
   171     {
       
   172     if ( iWait.IsStarted() )
       
   173         {
       
   174         CHAT_DP_TXT( "CCAFetchWaiter::HandleFetchCompleteL - stop wait" );
       
   175         iWait.AsyncStop();
       
   176         iWaitNoteCanceled = ( aError == KErrNone ) ? EFalse : ETrue;
       
   177         }
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------
       
   181 // CCAFetchWaiter::NoteCanceled
       
   182 // ---------------------------------------------------------
       
   183 //
       
   184 void CCAFetchWaiter::NoteCanceled( TInt /*aButtonId*/ )
       
   185     {
       
   186     if ( iWait.IsStarted() )
       
   187         {
       
   188         CHAT_DP_TXT( "CCAFetchWaiter::NoteCanceled - stop wait" );
       
   189         iWait.AsyncStop();
       
   190         iWaitNoteCanceled = ETrue;
       
   191         }
       
   192     }
       
   193 
       
   194 // end of file