phonebookui/Phonebook2/Commands/src/cpbk2storestatechecker.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:  Checks store state
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cpbk2storestatechecker.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <Pbk2UIControls.rsg>
       
    24 #include <MPbk2ApplicationServices.h>
       
    25 #include <MPbk2AppUi.h>
       
    26 #include <CPbk2StoreProperty.h>
       
    27 #include <CPbk2StorePropertyArray.h>
       
    28 #include "MPbk2StoreStateCheckerObserver.h"
       
    29 
       
    30 // Virtual Phonebook
       
    31 #include <MVPbkStoreContact.h>
       
    32 #include <MVPbkContactStore.h>
       
    33 #include <MVPbkContactStoreProperties.h>
       
    34 
       
    35 // System includes
       
    36 #include <aknnotewrappers.h> 
       
    37 #include <coemain.h>
       
    38 #include <StringLoader.h>
       
    39 
       
    40 // --------------------------------------------------------------------------
       
    41 // CPbk2StoreStateChecker::CPbk2StoreStateChecker
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CPbk2StoreStateChecker::CPbk2StoreStateChecker(
       
    47         MVPbkContactStore& aContactStore,
       
    48         MPbk2StoreStateCheckerObserver& aObserver ) :  
       
    49     iContactStore( aContactStore ),
       
    50     iObserver( aObserver )
       
    51     {
       
    52     // Do nothing
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CPbk2StoreStateChecker::CPbk2StoreStateChecker
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 CPbk2StoreStateChecker::~CPbk2StoreStateChecker()
       
    60     {
       
    61     iContactStore.Close( *this );
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // CPbk2StoreStateChecker::NewL
       
    66 // Two-phased constructor.
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 CPbk2StoreStateChecker* CPbk2StoreStateChecker::NewL( 
       
    70         MVPbkContactStore& aContactStore,
       
    71         MPbk2StoreStateCheckerObserver& aObserver )
       
    72     {
       
    73     CPbk2StoreStateChecker* self = new( ELeave ) CPbk2StoreStateChecker
       
    74         ( aContactStore, aObserver );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CPbk2StoreStateChecker::ConstructL
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 void CPbk2StoreStateChecker::ConstructL()
       
    86     {
       
    87     iContactStore.OpenL( *this );
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPbk2StoreStateChecker::StoreReady
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 void CPbk2StoreStateChecker::StoreReady( MVPbkContactStore& aContactStore )
       
    95     {
       
    96     aContactStore.Close( *this );
       
    97     iObserver.StoreState( MPbk2StoreStateCheckerObserver::EStoreAvailable );
       
    98     }
       
    99 
       
   100 // --------------------------------------------------------------------------
       
   101 // CPbk2StoreStateChecker::StoreUnavailable
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 void CPbk2StoreStateChecker::StoreUnavailable( 
       
   105         MVPbkContactStore& /*aContactStore*/, 
       
   106         TInt /*aReason*/ )
       
   107     {
       
   108     iObserver.StoreState( MPbk2StoreStateCheckerObserver::EStoreUnavailable );
       
   109     }
       
   110 // --------------------------------------------------------------------------
       
   111 // CPbk2StoreStateChecker::HandleStoreEventL
       
   112 // --------------------------------------------------------------------------
       
   113 //
       
   114 void CPbk2StoreStateChecker::HandleStoreEventL(
       
   115                         MVPbkContactStore& /*aContactStore*/, 
       
   116                         TVPbkContactStoreEvent /*aStoreEvent*/)
       
   117     {
       
   118     // No need to handle store event
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CPbk2StoreStateChecker::ShowUnavailableNoteL
       
   123 // --------------------------------------------------------------------------
       
   124 //
       
   125 void CPbk2StoreStateChecker::ShowUnavailableNoteL()
       
   126     {
       
   127     const CPbk2StoreProperty* prop =
       
   128         Phonebook2::Pbk2AppUi()->ApplicationServices().StoreProperties().
       
   129             FindProperty( iContactStore.StoreProperties().Uri() );
       
   130             
       
   131     HBufC* text = NULL;
       
   132     if ( prop )
       
   133         {
       
   134         if ( prop->StoreName().Length() > 0 )
       
   135             {
       
   136             text = StringLoader::LoadLC
       
   137                         ( R_QTN_PHOB_STORE_NOT_AVAILABLE,
       
   138                           prop->StoreName() );            
       
   139             }
       
   140         }
       
   141     if ( !text )
       
   142         {
       
   143         text = StringLoader::LoadLC
       
   144                     ( R_QTN_PHOB_STORE_NOT_AVAILABLE,
       
   145                       iContactStore.StoreProperties().Uri().UriDes() );            
       
   146         }
       
   147     CAknInformationNote* note =
       
   148         new(ELeave) CAknInformationNote( ETrue );
       
   149     // Show "not available" note
       
   150     note->ExecuteLD(*text);
       
   151     CleanupStack::PopAndDestroy(text);
       
   152     }
       
   153 
       
   154 //  End of File