phonebookui/Phonebook2/CommonUI/inc/CPbk2NavigationBase.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:  Phonebook 2 contact navigator base.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPBK2NAVIGATIONBASE_H
       
    20 #define CPBK2NAVIGATIONBASE_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <MPbk2ContactNavigation.h>
       
    25 #include <MVPbkContactStoreObserver.h>
       
    26 
       
    27 //  FORWARD DECLARATIONS
       
    28 class MPbk2ContactNavigationLoader;
       
    29 class MPbk2NavigationObserver;
       
    30 
       
    31 //  CLASS DECLARATION
       
    32 
       
    33 /**
       
    34  * Phonebook 2 navigator base.
       
    35  * Common base class for all navigation strategies.
       
    36  * Listens contact stores for store events and drives navigation loader
       
    37  * and navigation observer accordingly.
       
    38  */
       
    39 class CPbk2NavigationBase : public CBase,
       
    40                             public MPbk2ContactNavigation,
       
    41                             private MVPbkContactStoreObserver
       
    42     {
       
    43     protected: // Construction and destruction
       
    44 
       
    45         /**
       
    46          * Constructor.
       
    47          *
       
    48          * @param aObserver             Observer.
       
    49          * @param aNavigationLoader     Navigation interface for
       
    50          *                              loading contacts.
       
    51          * @param aStoreList            List of stores this
       
    52          *                              navigator observes.
       
    53          */
       
    54         CPbk2NavigationBase(
       
    55                 MPbk2NavigationObserver& aObserver,
       
    56                 MPbk2ContactNavigationLoader& aNavigationLoader,
       
    57                 TArray<MVPbkContactStore*> aStoreList );
       
    58 
       
    59         /**
       
    60          * Destructor.
       
    61          */
       
    62         ~CPbk2NavigationBase();
       
    63 
       
    64     public: // Interface
       
    65 
       
    66         /**
       
    67          * Returns the contact navigation loader.
       
    68          *
       
    69          * @return The contact navigation loader.
       
    70          */
       
    71         inline MPbk2ContactNavigationLoader& NavigationLoader() const;
       
    72 
       
    73         /**
       
    74          * Returns the scroll view or NULL if not set. Ownership
       
    75          * is not given.
       
    76          *
       
    77          * @return The scroll view or NULL if not set. Ownership is not
       
    78          *         given.
       
    79          */
       
    80         inline MVPbkContactViewBase* ScrollView() const;
       
    81 
       
    82     protected: // Base class interface
       
    83 
       
    84         /**
       
    85          * Second phase base constructor.
       
    86          */
       
    87         void BaseConstructL();
       
    88 
       
    89     protected: // From MPbk2ContactNavigation
       
    90         void SetScrollViewL(
       
    91                 MVPbkContactViewBase* aScrollView,
       
    92                 TBool aOwnershipTransfered );
       
    93         MVPbkContactLink* CurrentContactLC() const;
       
    94 
       
    95     protected: // From MVPbkContactViewObserver
       
    96         void ContactViewReady(
       
    97                 MVPbkContactViewBase& aView );
       
    98         void ContactViewUnavailable(
       
    99                 MVPbkContactViewBase& aView );
       
   100         void ContactAddedToView(
       
   101                 MVPbkContactViewBase& aView,
       
   102                 TInt aIndex,
       
   103                 const MVPbkContactLink& aContactLink );
       
   104         void ContactRemovedFromView(
       
   105                 MVPbkContactViewBase& aView,
       
   106                 TInt aIndex,
       
   107                 const MVPbkContactLink& aContactLink );
       
   108         void ContactViewError(
       
   109                 MVPbkContactViewBase& aView,
       
   110                 TInt aError,
       
   111                 TBool aErrorNotified );
       
   112 
       
   113     private: // From MVPbkContactStoreObserver
       
   114         void StoreReady(
       
   115                 MVPbkContactStore& aContactStore );
       
   116         void StoreUnavailable(
       
   117                 MVPbkContactStore& aContactStore,
       
   118                 TInt aReason );
       
   119         void HandleStoreEventL(
       
   120                 MVPbkContactStore& aContactStore,
       
   121                 TVPbkContactStoreEvent aStoreEvent );
       
   122 
       
   123     private: // Implementation
       
   124         void HandleContactRemovedFromViewL(
       
   125                 MVPbkContactViewBase& aView,
       
   126                 TInt aIndex,
       
   127                 const MVPbkContactLink& aContactLink );
       
   128         void CloseStores();
       
   129         void RemoveViewObserver();
       
   130         void StartIdleCallBackL();
       
   131         static TInt IdleNotifierCallBack(
       
   132                 TAny* aSelf );
       
   133         void HandleIdleNotify();
       
   134 
       
   135     protected: // Data
       
   136         /// Ref: Navigation observer
       
   137         MPbk2NavigationObserver& iNavigationObserver;
       
   138 
       
   139     private: // Data
       
   140         /// Ref: The contact loader.
       
   141         MPbk2ContactNavigationLoader& iNavigationLoader;
       
   142         /// Ref: List of used stores
       
   143         TArray<MVPbkContactStore*> iStoreList;
       
   144         /// Own: For asynchronously notifying observers
       
   145         CIdle* iIdleNotifier;
       
   146         /// Ref: This can be NULL if not set by SetScrollViewL.
       
   147         MVPbkContactViewBase* iScrollView;
       
   148         /// Own: Owned view. This can be NULL.
       
   149         MVPbkContactViewBase* iOwnedView;
       
   150         class CDeletedContactInfo;
       
   151         /// Own: knows the right contact after the current one is deleted.
       
   152         CDeletedContactInfo* iDeletedContactInfo;
       
   153     };
       
   154 
       
   155 /**
       
   156  * A helper class to keep current contact also when the contact is deleted.
       
   157  */
       
   158 NONSHARABLE_CLASS( CPbk2NavigationBase::CDeletedContactInfo ) : public CBase
       
   159     {
       
   160     public: // Construction and destruction
       
   161 
       
   162         /**
       
   163          * @param aNavigationBase The parent of the contact information
       
   164          */
       
   165         CDeletedContactInfo( CPbk2NavigationBase& aNavigationBase );
       
   166 
       
   167         /**
       
   168          * Destructor
       
   169          */
       
   170         ~CDeletedContactInfo();
       
   171 
       
   172     public: // Interface
       
   173 
       
   174         /**
       
   175          * Saves the removed contact information.
       
   176          *
       
   177          * @param aView         This must be the scroll view of the parent.
       
   178          * @param aIndex        The index of the removed contact.
       
   179          * @param aContactLink  The identifier of the removed contact.
       
   180          */
       
   181         void HandleContactRemovedFromViewL(
       
   182                 MVPbkContactViewBase& aView,
       
   183                 TInt aIndex,
       
   184                 const MVPbkContactLink& aContactLink );
       
   185 
       
   186         /**
       
   187          * Saves deleted contact information.
       
   188          *
       
   189          * @param aContactStore     The store whose contact was deleted
       
   190          * @param aStoreEvent       In case of delete event this contains
       
   191          *                          the deleted contact link.
       
   192          */
       
   193         void HandleStoreEventL(
       
   194                 MVPbkContactStore& aContactStore,
       
   195                 TVPbkContactStoreEvent aStoreEvent );
       
   196 
       
   197         /**
       
   198          * Returns ETrue if contact is deleted from the store and removed
       
   199          * from the view.
       
   200          *
       
   201          * @return  ETrue if contact is deleted from the store and removed
       
   202          *          from the view.
       
   203          */
       
   204         TBool DeletedAndRemoved() const;
       
   205 
       
   206         /**
       
   207          * Returns the contact that is focused after the current one
       
   208          * is deleted and removed.
       
   209          *
       
   210          * @return  The contact identifier of the contact that is focused
       
   211          *          after the current contact is deleted.
       
   212          */
       
   213         MVPbkContactLink* FocusedContactOrNullLC();
       
   214 
       
   215     private: // Data
       
   216         /// Ref: The parent of this class
       
   217         CPbk2NavigationBase& iNavigationBase;
       
   218         /// Own: An identifier of the deleted contact from the store
       
   219         MVPbkContactLink* iDeletedContact;
       
   220         /// Own: An identifier of the removed contact from the view
       
   221         MVPbkContactLink* iRemovedContact;
       
   222         /// Own: An index of the removed contact
       
   223         TInt iRemovedContactIndex;
       
   224     };
       
   225 
       
   226 // INLINE FUNCTIONS
       
   227 
       
   228 // --------------------------------------------------------------------------
       
   229 // CPbk2NavigationBase::NavigationLoader
       
   230 // --------------------------------------------------------------------------
       
   231 //
       
   232 inline MPbk2ContactNavigationLoader&
       
   233         CPbk2NavigationBase::NavigationLoader() const
       
   234     {
       
   235     return iNavigationLoader;
       
   236     }
       
   237 
       
   238 // --------------------------------------------------------------------------
       
   239 // CPbk2NavigationBase::ScrollView
       
   240 // --------------------------------------------------------------------------
       
   241 //
       
   242 inline MVPbkContactViewBase* CPbk2NavigationBase::ScrollView() const
       
   243     {
       
   244     return iScrollView;
       
   245     }
       
   246 
       
   247 #endif // CPBK2NAVIGATIONBASE_H
       
   248 
       
   249 // End of File