phonebookui/Phonebook2/NamesListExtension/inc/CPbk2AddFavoritesVisibility.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef  CPBK2ADDFAVORITESVISIBILITY_H_
       
    20 #define  CPBK2ADDFAVORITESVISIBILITY_H_
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 
       
    25 // VPbk
       
    26 #include <MVPbkContactViewObserver.h>
       
    27 
       
    28 // Pbk2
       
    29 #include <MPbk2StoreConfigurationObserver.h>
       
    30 #include "MPbk2AddFavoritesVisibility.h"
       
    31 #include <MPbk2CmdItemVisibilityObserver.h>
       
    32 
       
    33 // FORWARD DECLARATIONS
       
    34 class MVPbkContactViewBase;
       
    35 class CPbk2AddFavoritesVisibilityImpl;
       
    36 class MPbk2ApplicationServices;
       
    37 
       
    38 /**
       
    39  * In order to know whether or not "Add favorites" should be visible
       
    40  * The following must be known:
       
    41  * 
       
    42  * (1) Are there Top Contacts? (favorites) 
       
    43  * (2) Number of contacts in all contacts view
       
    44  * (3) Whether "Settings / Memory selection" contains Phone memory
       
    45  * (4) Store Configuration changes
       
    46  *
       
    47  * (1) & (2) require all contacts and top contacts database
       
    48  * view creation and and error handling regarding those. 
       
    49  *
       
    50  * (4) requires store configuration observation & event handling
       
    51  * 
       
    52  * This class does all these and gathers all data needed for decesion
       
    53  * and forwards it to CPbk2AddFavoritesVisibilityImpl class
       
    54  */
       
    55 NONSHARABLE_CLASS( CPbk2AddFavoritesVisibility ) : public CBase,
       
    56     public MVPbkContactViewObserver,
       
    57     public MPbk2StoreConfigurationObserver
       
    58 	{
       
    59 	public: // Construction & destruction
       
    60 
       
    61         /* @param aCmdId: a nameslist command item id
       
    62          * @MPbk2ApplicationServices& aAppServices: Pbk2 App Services
       
    63          * object.
       
    64          */
       
    65 		static CPbk2AddFavoritesVisibility* NewL(		    
       
    66 		    TInt aCmdId, MPbk2ApplicationServices& aAppServices);
       
    67 		
       
    68 		~CPbk2AddFavoritesVisibility();
       
    69     
       
    70     public: // visibility observer setting
       
    71     
       
    72         /*
       
    73         * Set's the observer for the impl class and  
       
    74         * triggers and async callback to observer
       
    75         *
       
    76         * @param aObserver: (i.e. nameslistcontrol's ready state obj)
       
    77         * obj who is interested in visibility on/off events
       
    78         * 
       
    79         */        
       
    80         void SetVisibilityObserver
       
    81             (MPbk2CmdItemVisibilityObserver* aObserver);          
       
    82         
       
    83         /*  
       
    84          * Sets visibility
       
    85          *
       
    86          * @param aVisibility new visiblity value
       
    87         */
       
    88         void SetVisibility(TBool aVisibility);   
       
    89         
       
    90         /* 
       
    91          * Get visibility
       
    92          *
       
    93          * @return visiblity value
       
    94         */
       
    95         TBool Visibility();        
       
    96 
       
    97     private: // MPbk2StoreConfigurationObserver
       
    98     
       
    99         void ConfigurationChanged();
       
   100  
       
   101         void ConfigurationChangedComplete();
       
   102     
       
   103         	
       
   104 	private: //	MVPbkContactViewObserver
       
   105 	    
       
   106 	    void ContactViewReady(
       
   107 	            MVPbkContactViewBase& aView );
       
   108 	            
       
   109 	    void ContactViewUnavailable(
       
   110             MVPbkContactViewBase& aView );
       
   111             
       
   112 	    void ContactAddedToView(
       
   113             MVPbkContactViewBase& aView,
       
   114             TInt aIndex,
       
   115             const MVPbkContactLink& aContactLink );
       
   116             
       
   117 	    void ContactRemovedFromView(
       
   118             MVPbkContactViewBase& aView,
       
   119             TInt aIndex,
       
   120             const MVPbkContactLink& aContactLink );
       
   121             
       
   122 	    void ContactViewError(
       
   123             MVPbkContactViewBase& aView,
       
   124             TInt aError,
       
   125             TBool aErrorNotified );
       
   126 	    
       
   127 	private:
       
   128 	
       
   129 		CPbk2AddFavoritesVisibility(MPbk2ApplicationServices& aAppServices);
       
   130 	
       
   131 	    void ConstructL( TInt aCmdId );
       
   132 		
       
   133         TBool IsContactDatabaseLoadedL() const;
       
   134         TBool ObserveContactViewsL();
       
   135 		void StartObservingStoreConfigurationL();  
       
   136         void Reset();
       
   137 		void HandleConfigurationChangedL();    
       
   138         void ReadAddFavoritiesVisibilityKeyL();		                                          
       
   139         void StopObservingStoreConfiguration();
       
   140         void NotifyVisibilityChange();        
       
   141         void UpdateContactCount(MVPbkContactViewBase& aView);
       
   142         void SetContactCount(MVPbkContactViewBase& aView, TInt aCount);
       
   143         TInt TopContactCount();
       
   144         TInt AllContactsCount();        
       
   145         void StartL();               
       
   146 	
       
   147 	private: // data
       
   148 	          
       
   149 	    // Ref: top contacts view
       
   150 	    MVPbkContactViewBase* iTopContactsView;
       
   151 
       
   152 	    // Ref: all contacts view
       
   153 	    MVPbkContactViewBase* iAllContactsView;	    	    
       
   154 	    
       
   155 	    // Handle to implementor in bridge pattern
       
   156 	    // Taking care of decesion logic on visibility plus
       
   157 	    // informing the visibility observer
       
   158 	    CPbk2AddFavoritesVisibilityImpl* iImpl;
       
   159 
       
   160 	    // Own:  top contact count if the view is in valid, KErrNotFound otherwise
       
   161         TInt iTcCount;
       
   162         // Own:  all contacts view count if the view is valid, KErrNotFound otherwise
       
   163         TInt iAllContactsCount;    
       
   164         // ref, used to reach view suplier & database views
       
   165         MPbk2ApplicationServices& iApplicationServices;
       
   166 	};
       
   167 
       
   168 #endif /* CPBK2ADDFAVORITESVISIBILITY_H_*/