wvuing/wvuiave/AppSrc/ccasyncchecker.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 checking synch state.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "ccasyncchecker.h"
       
    21 #include "ccaappui.h"
       
    22 #include "ccauisessionmanager.h"
       
    23 #include "MCAGlobalNotificationObserverPC.h"
       
    24 #include "MCAProcessManager.h"
       
    25 #include "impsbuilddefinitions.h"
       
    26 #include "chatdebugprint.h"
       
    27 // The Settings have been moved to Cenrep (also retained in the Resource file),
       
    28 // so the enums for keys and central repository header is added here
       
    29 #include 	"VariantKeys.h"
       
    30 
       
    31 #include <chatNG.rsg>
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 
       
    36 // ---------------------------------------------------------
       
    37 // CCASyncChecker::NewLC()
       
    38 // Called when a contact is deleted
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CCASyncChecker* CCASyncChecker::NewLC()
       
    42     {
       
    43     CCASyncChecker* self = new ( ELeave ) CCASyncChecker();
       
    44     CleanupStack::PushL( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CCASyncChecker::CCASyncChecker()
       
    50 // Called when a contact is deleted
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 CCASyncChecker::CCASyncChecker()
       
    54         : iAppUi( static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() ) )
       
    55     {
       
    56     iGlobalNotificationPC = iAppUi->GetProcessManager().GetGlobalNotificationInterface();
       
    57     delete iWaitNote;
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------
       
    62 // CCASyncChecker::~CCASyncChecker()
       
    63 // Called when a contact is deleted
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CCASyncChecker::~CCASyncChecker()
       
    67     {
       
    68     delete iWaitNote;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------
       
    72 // CCASyncChecker::WaitForSyncCompleteL()
       
    73 // Called when a contact is deleted
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 TBool CCASyncChecker::WaitForSyncCompleteL()
       
    77     {
       
    78     if ( !LoggedIn() )
       
    79         {
       
    80         // Not logged in. No reason to wait
       
    81         return EFalse;
       
    82         }
       
    83 
       
    84     TBool failed;
       
    85     if ( !iGlobalNotificationPC->StoredContactsIsAllSynchronised( failed ) ||
       
    86          !iGlobalNotificationPC->IsContactListsSyncDoneL() )
       
    87         {
       
    88         iWaitNoteCanceled = EFalse;
       
    89         iGlobalNotificationPC->AddGlobalObserverL( this );
       
    90         iWaitNote = CCAWaitNote::ShowWaitNoteL(
       
    91                         R_QTN_CHAT_FETCHING_LISTS_ONGOING,
       
    92                         ETrue, ETrue, this );
       
    93 
       
    94         if ( ! iWait.IsStarted() )
       
    95             {
       
    96             iWait.Start();  // CSI: 10 # iWait is not an active object
       
    97             }
       
    98         delete iWaitNote;
       
    99         iGlobalNotificationPC->RemoveGlobalObserver( this );
       
   100         iWaitNote = NULL;
       
   101         if ( iWaitNoteCanceled )
       
   102             {
       
   103             return EFalse;
       
   104             }
       
   105         }
       
   106     TBool allSync = iGlobalNotificationPC->StoredContactsIsAllSynchronised( failed );
       
   107     TBool syncDone = iGlobalNotificationPC->IsContactListsSyncDoneL();
       
   108     return ( allSync && !failed && syncDone );
       
   109     }
       
   110 
       
   111 
       
   112 // ---------------------------------------------------------
       
   113 // CCASyncChecker::LoggedIn()
       
   114 // Called when a contact is deleted
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 TBool CCASyncChecker::LoggedIn()
       
   118     {
       
   119     return iAppUi->UISessionManager().IsLoggedIn();
       
   120     }
       
   121 // ---------------------------------------------------------
       
   122 // CCASyncChecker::CheckSyncStateL()
       
   123 // Called when a contact is deleted
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 TBool CCASyncChecker::CheckSyncStateL()
       
   127     {
       
   128     TBool retVal = ETrue;
       
   129 #ifdef IMPS_CONTACT_FETCH_BACKGROUND
       
   130     //Code scanner warning ignored, since this is a static method
       
   131     CCAAppUi* appUi = static_cast<CCAAppUi*>( CCoeEnv::Static()->AppUi() );
       
   132     MCAGlobalNotificationObserverPC* globalNotificationPC =
       
   133         appUi->GetProcessManager().GetGlobalNotificationInterface();
       
   134     if ( globalNotificationPC->IsValidListInterfaceL() == EFalse )
       
   135         {
       
   136         // not logged in yet, so sync state is ok
       
   137         return ETrue;
       
   138         }
       
   139 
       
   140     TBool syncDone = globalNotificationPC->IsContactListsSyncDoneL();
       
   141     TBool ignoreFailed;
       
   142     if ( !globalNotificationPC->StoredContactsIsAllSynchronised( ignoreFailed ) ||
       
   143          !syncDone )
       
   144         {
       
   145         CCASyncChecker* checker = NewLC();
       
   146         retVal = checker->WaitForSyncCompleteL();
       
   147         CleanupStack::PopAndDestroy(); //checker
       
   148         }
       
   149 #endif //IMPS_CONTACT_FETCH_BACKGROUND
       
   150     return retVal;
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CCASyncChecker::HandleDelete()
       
   155 // Called when a contact is deleted
       
   156 // ---------------------------------------------------------
       
   157 //
       
   158 
       
   159 void CCASyncChecker::HandleDelete( const TDesC& /*aContactId*/ , TEnumsPC::TItem /*type*/ )
       
   160     {
       
   161     // Not used
       
   162     }
       
   163 
       
   164 // ---------------------------------------------------------
       
   165 // CCASyncChecker::HandleAddition()
       
   166 // Called when a contact is added
       
   167 // ---------------------------------------------------------
       
   168 //
       
   169 void CCASyncChecker::HandleAddition(  TEnumsPC::TItem /*type*/ )
       
   170     {
       
   171     // Not used
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // CCASyncChecker::HandleChange()
       
   176 // Called when a contact is changed
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CCASyncChecker::HandleChange( TEnumsPC::TItem /*aType*/, TEnumsPC::TChange /*aChangeType*/ )
       
   180     {
       
   181     CHAT_DP_FUNC_ENTER( "CCASyncChecker::HandleChange" );
       
   182 
       
   183     if ( !iGlobalNotificationPC->IsValidStoredContactsInterface() )
       
   184         {
       
   185         return;
       
   186         }
       
   187 
       
   188     TBool ignoreFailed;
       
   189     TBool syncDone = EFalse;
       
   190     TRAP_IGNORE( syncDone = iGlobalNotificationPC->IsContactListsSyncDoneL() );
       
   191     if ( iWaitNote &&
       
   192          iGlobalNotificationPC->StoredContactsIsAllSynchronised( ignoreFailed ) &&
       
   193          syncDone )
       
   194         {
       
   195         iWaitNote->DismissDialog();
       
   196         iWaitNoteCanceled = EFalse;
       
   197         }
       
   198 
       
   199     CHAT_DP_FUNC_DONE( "CCASyncChecker::HandleChange" );
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CCASyncChecker::NoteCanceled
       
   204 // (other items were commented in a header).
       
   205 // ---------------------------------------------------------
       
   206 //
       
   207 void CCASyncChecker::NoteCanceled( TInt aButtonId )
       
   208     {
       
   209     if ( aButtonId == EAknSoftkeyCancel )
       
   210         {
       
   211         iWaitNoteCanceled = ETrue;
       
   212         }
       
   213     if ( iWait.IsStarted() )
       
   214         {
       
   215         iWait.AsyncStop();
       
   216         }
       
   217     }
       
   218 
       
   219 // end of file