phonebookengines/contactsmodel/inc/cntviewprivate.h
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CNTVIEWPRIVATE_H__
       
    17 #define __CNTVIEWPRIVATE_H__
       
    18 
       
    19 #include <cntviewbase.h>
       
    20 #include "CNTPHBKSYNCWATCHER.H"
       
    21 
       
    22 /** 
       
    23  * This class adds the ability to change sort orders to the functionality
       
    24  * provided by CContactLocalView. If the sort order is changed, a notification
       
    25  * will be sent to all observers. This class is only intended for use by the 
       
    26  * contact server. Clients should use CContactNamedRemoteView.
       
    27  */
       
    28 class CContactNamedLocalView : public CContactLocalView
       
    29 	{
       
    30 public:
       
    31 	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude);
       
    32 	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude, const TDesC8& aSortPluginName);
       
    33 	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude, MLplPersistenceLayerFactory* aFactory, const TDesC8& aSortPluginName);
       
    34 	IMPORT_C const TDesC& Name();
       
    35 	IMPORT_C void ChangeSortOrderL(RContactViewSortOrder& aSortOrder);
       
    36 private:
       
    37 	~CContactNamedLocalView();
       
    38 	CContactNamedLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes,MLplPersistenceLayerFactory* aFactory);
       
    39 	CContactNamedLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypeToInclude);
       
    40 	void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,
       
    41 										TBool aUseNamedPlugin, const TDesC8& aSortPluginName);
       
    42 private:
       
    43 	HBufC* iName;
       
    44 	};
       
    45 
       
    46 /** 
       
    47  * This class is owned by CContactRemoteViewBase and is used to 
       
    48  * receive view events
       
    49  */
       
    50 NONSHARABLE_CLASS (CContactRemoteViewNotifier) : public CActive
       
    51 	{
       
    52 public:
       
    53 	CContactRemoteViewNotifier(RContactRemoteView& aView,TCallBack aCallBack);
       
    54 	~CContactRemoteViewNotifier();
       
    55 	void Start();
       
    56 	const TContactViewEvent& Event() const;
       
    57 private: // From CActive.
       
    58 	void RunL();
       
    59 	void DoCancel();
       
    60 private:
       
    61 	RContactRemoteView& iView;
       
    62 	TPckgBuf<TContactViewEvent> iEvent;
       
    63 	TCallBack iCallBack;
       
    64 	};
       
    65 
       
    66 	
       
    67 class MContactViewSortObserver;
       
    68 
       
    69 /** 
       
    70  * This class extends CAsyncOneShot to allow an initial notification request 
       
    71  * to be made to the phonebook synchroniser plug-in for ICC views.
       
    72  * 
       
    73  * This allows delaying the construction of the view until the ICC 
       
    74  * is synchronised and the phonebook synchroniser is in a cache-valid
       
    75  * state.
       
    76  */
       
    77 NONSHARABLE_CLASS (CIdleContactSorter) : public CAsyncOneShot, public MContactPhbkSyncObserver
       
    78 	{
       
    79 private:
       
    80 	enum TSorterState
       
    81 		{
       
    82 		EInsertSortFinal,
       
    83 		EInsertContactsOnlyIccLocked,
       
    84 		EWaitingForInitialICCReady,
       
    85 		EContactsReadyWaitICCUnlock,
       
    86 		ESortAllDone
       
    87 		};
       
    88 
       
    89 public:
       
    90 	static CIdleContactSorter* NewL(MContactViewSortObserver& aObserver, MLplPersistenceLayerFactory& aFactory, TContactViewPreferences aRequestedViewPrefs);
       
    91 	~CIdleContactSorter();
       
    92 	TBool IsICCSynchronised() const;
       
    93 	TContactViewPreferences SortViewPreferences() const;
       
    94 	TBool InsertViewPreferences(TContactViewPreferences &aInsertView) const;
       
    95 	void Start();
       
    96 	void Stop();
       
    97 	
       
    98 private: // From CAsyncOneShot
       
    99 	CIdleContactSorter(MContactViewSortObserver& aObserver, TContactViewPreferences aRequestedViewPrefs);
       
   100 	void ConstructL(MLplPersistenceLayerFactory& aFactory);
       
   101 	
       
   102 	void DoCancel();
       
   103 	void RunL();
       
   104 	TInt RunError(TInt aError);
       
   105 
       
   106 	void ChangeSortState(TSorterState aNewSortState);
       
   107 	
       
   108 	// From MContactPhbkSyncObserver
       
   109 	void ContactPhbkSyncEventHandler(TPhonebookState aPhbkState);
       
   110 
       
   111 private:
       
   112 	MContactViewSortObserver&	iSortObserver;
       
   113 	
       
   114 	// requested view
       
   115 	TContactViewPreferences iRequestedView;
       
   116 	// non-NULL if ICC contacts are included in view, & therefore a sync is expected
       
   117 	CContactPhbkSyncWatcher* iPhbkSyncWatcher;
       
   118 	
       
   119 	// subset of view we are actually insert sorting now
       
   120 	TContactViewPreferences iSortView;
       
   121 	TSorterState iSortState;
       
   122 	};
       
   123 
       
   124 	
       
   125 /**
       
   126  * Template classes to call ResetAndDestroy on array classes
       
   127  * automatically, when ::PopAndDestroy'ing from the cleanup stack.
       
   128  */
       
   129 template <class T>
       
   130 class CleanupResetAndDestroy
       
   131 	{
       
   132 public:
       
   133 	inline static void PushL(T& aRef);
       
   134 private:
       
   135 	static void ResetAndDestroy(TAny *aPtr);
       
   136 	};
       
   137 template <class T>
       
   138 inline void CleanupResetAndDestroyL(T& aRef);
       
   139 
       
   140 // Template class CleanupClose
       
   141 template <class T>
       
   142 inline void CleanupResetAndDestroy<T>::PushL(T& aRef)
       
   143 	{CleanupStack::PushL(TCleanupItem(&ResetAndDestroy, &aRef));}
       
   144 template <class T>
       
   145 void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr)
       
   146 	{static_cast<T*>(aPtr)->ResetAndDestroy();}
       
   147 template <class T>
       
   148 inline void CleanupResetAndDestroyPushL(T& aRef)
       
   149 	{CleanupResetAndDestroy<T>::PushL(aRef);}
       
   150 
       
   151 #endif //__CNTVIEWPRIVATE_H__