summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/inc/cntviewprivate.h
blob: aa1deccd7fe2ff83b11db9c2b8a4eb77e6929762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#ifndef __CNTVIEWPRIVATE_H__
#define __CNTVIEWPRIVATE_H__

#include <cntviewbase.h>
#include "cntphbksyncwatcher.h"

/** 
 * This class adds the ability to change sort orders to the functionality
 * provided by CContactLocalView. If the sort order is changed, a notification
 * will be sent to all observers. This class is only intended for use by the 
 * contact server. Clients should use CContactNamedRemoteView.
 */
class CContactNamedLocalView : public CContactLocalView
	{
public:
	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude);
	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude, const TDesC8& aSortPluginName);
	IMPORT_C static CContactNamedLocalView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypeToInclude, MLplPersistenceLayerFactory* aFactory, const TDesC8& aSortPluginName);
	IMPORT_C const TDesC& Name();
	IMPORT_C void ChangeSortOrderL(RContactViewSortOrder& aSortOrder);
private:
	~CContactNamedLocalView();
	CContactNamedLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes,MLplPersistenceLayerFactory* aFactory);
	CContactNamedLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypeToInclude);
	void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,
										TBool aUseNamedPlugin, const TDesC8& aSortPluginName);
private:
	HBufC* iName;
	};

/** 
 * This class is owned by CContactRemoteViewBase and is used to 
 * receive view events
 */
NONSHARABLE_CLASS (CContactRemoteViewNotifier) : public CActive
	{
public:
	CContactRemoteViewNotifier(RContactRemoteView& aView,TCallBack aCallBack);
	~CContactRemoteViewNotifier();
	void Start();
	const TContactViewEvent& Event() const;
private: // From CActive.
	void RunL();
	void DoCancel();
private:
	RContactRemoteView& iView;
	TPckgBuf<TContactViewEvent> iEvent;
	TCallBack iCallBack;
	};

	
class MContactViewSortObserver;

/** 
 * This class extends CAsyncOneShot to allow an initial notification request 
 * to be made to the phonebook synchroniser plug-in for ICC views.
 * 
 * This allows delaying the construction of the view until the ICC 
 * is synchronised and the phonebook synchroniser is in a cache-valid
 * state.
 */
NONSHARABLE_CLASS (CIdleContactSorter) : public CAsyncOneShot, public MContactPhbkSyncObserver
	{
private:
	enum TSorterState
		{
		EInsertSortFinal,
		EInsertContactsOnlyIccLocked,
		EWaitingForInitialICCReady,
		EContactsReadyWaitICCUnlock,
		ESortAllDone
		};

public:
	static CIdleContactSorter* NewL(MContactViewSortObserver& aObserver, MLplPersistenceLayerFactory& aFactory, TContactViewPreferences aRequestedViewPrefs);
	~CIdleContactSorter();
	TBool IsICCSynchronised() const;
	TContactViewPreferences SortViewPreferences() const;
	TBool InsertViewPreferences(TContactViewPreferences &aInsertView) const;
	void Start();
	void Stop();
	
private: // From CAsyncOneShot
	CIdleContactSorter(MContactViewSortObserver& aObserver, TContactViewPreferences aRequestedViewPrefs);
	void ConstructL(MLplPersistenceLayerFactory& aFactory);
	
	void DoCancel();
	void RunL();
	TInt RunError(TInt aError);

	void ChangeSortState(TSorterState aNewSortState);
	
	// From MContactPhbkSyncObserver
	void ContactPhbkSyncEventHandler(TPhonebookState aPhbkState);

private:
	MContactViewSortObserver&	iSortObserver;
	
	// requested view
	TContactViewPreferences iRequestedView;
	// non-NULL if ICC contacts are included in view, & therefore a sync is expected
	CContactPhbkSyncWatcher* iPhbkSyncWatcher;
	
	// subset of view we are actually insert sorting now
	TContactViewPreferences iSortView;
	TSorterState iSortState;
	};

	
/**
 * Template classes to call ResetAndDestroy on array classes
 * automatically, when ::PopAndDestroy'ing from the cleanup stack.
 */
template <class T>
class CleanupResetAndDestroy
	{
public:
	inline static void PushL(T& aRef);
private:
	static void ResetAndDestroy(TAny *aPtr);
	};
template <class T>
inline void CleanupResetAndDestroyL(T& aRef);

// Template class CleanupClose
template <class T>
inline void CleanupResetAndDestroy<T>::PushL(T& aRef)
	{CleanupStack::PushL(TCleanupItem(&ResetAndDestroy, &aRef));}
template <class T>
void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr)
	{static_cast<T*>(aPtr)->ResetAndDestroy();}
template <class T>
inline void CleanupResetAndDestroyPushL(T& aRef)
	{CleanupResetAndDestroy<T>::PushL(aRef);}

#endif //__CNTVIEWPRIVATE_H__