summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntmodel/inc/ccontactprivate.h
blob: 7b46bb3edf258b3bf5f856e0af2d9fbc51ec309b (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* 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: 
*
*/




/**
 @file
 @internalComponent
 @released
*/


#ifndef __CCONTACTPRIVATE_H__
#define __CCONTACTPRIVATE_H__

#include <cntitem.h>


const TInt KNoValueSet = -1; // Used in CContactDatabase - not published.
const TInt KFiveMins = 300000000; // Used in CContactDatabase - not published.


class CPrivConverter;
class CContactConverter;
class CTextFieldMinimal;


/** 
Base class for Contacts Model plug-ins.
*/
NONSHARABLE_CLASS(CContactPlugin) : public CBase
	{
public:
	~CContactPlugin();

protected:
	TUid LoadEComPluginFromInterface(TUid aInterfaceUid);
	CContactPlugin();

private:
	RLibrary iDll;
	};


/**
Class for all template related functionality.
*/
NONSHARABLE_CLASS(CCntTemplateCache) : public CBase
	{
public:
	static CCntTemplateCache* NewL(RCntModel& aCntSvr);
	~CCntTemplateCache();
	inline TContactItemId TemplateId()const {return iTemplateId;}
	void MergeWithTemplateL(CContactItem& aContact, const CContactItemViewDef* aViewDef = NULL);
	void RemoveTemplate(TContactItemId aId);
	CContactItem& SystemTemplateL();

private:
	CContactItem& TemplateL(TContactItemId aId);
	CCntTemplateCache(RCntModel& aCntSvr);
	void DeleteEntry(TInt aIndex);
	CContactItemViewDef& DefaultViewDefL();
	void ResetSystemTemplate();
	
private:
	RPointerArray <CContactItem> iCache;
	RCntModel& iCntSvr;
	CContactItem* iSystemTemplate;
	TContactItemId iTemplateId;
	CContactItemViewDef* iViewDef;
	};


/** 
Contact item to vCard converter plug-in.
*/
NONSHARABLE_CLASS(CPrivConverter) : public CContactPlugin
	{
public:
	static CPrivConverter* NewL(TUid aUid);
	static CPrivConverter* NewL(TUid aUid, TInt64 aContactFieldFilter, MConverterCallBack* aCallback, TVCardVersion aVersion, TBool aExportTel);
	TVCardVersion GetCurrentVersion() const;
	TInt64 GetPBAPFilter() const;
	TBool GetExportTel()const;
	void LoadEComPluginL(TUid aUid, TInt64 aFilter, MConverterCallBack* aCallback, TVCardVersion aVersion, TBool aExportTel);
	void LoadEComPluginL(TUid aUid);
	~CPrivConverter();
	inline CContactConverter* Converter() const;
private:
	TBool IsImplementationAvailableL(TUid aUid);
private:
	CContactConverter* iConverter;
	TVCardVersion iVersion;
	TInt64 iPBAPFilter;
	TBool iExportTel;
	};


inline CContactConverter* CPrivConverter::Converter() const { return iConverter;}


NONSHARABLE_CLASS(CSortArray) : public CBase
	{
public:
	CSortArray();
	~CSortArray();
	void AppendL(const TDesC &Text, TContactItemId aId);
	void SortL(CContactDatabase::TSortPref::TOrder aOrder);
	inline TInt Count() const;
	TContactItemId Id(TInt aIndex) const;
	HBufC *Text(TInt aIndex) const;
	void Merge(CSortArray *aDuplicates,TInt aStartPos);

private:
	static TInt DefaultAlgorithmToCompareNames(const CTextFieldMinimal& aName1, const CTextFieldMinimal& aName2);

private:
	RPointerArray<CTextFieldMinimal> iArray;
	};


inline TInt CSortArray::Count() const {return(iArray.Count());}


NONSHARABLE_CLASS(CTextFieldMinimal) : public CBase
	{
public:
	~CTextFieldMinimal();
	inline CTextFieldMinimal() : iId(KNullContactId) {};
	void ConstructL(const TDesC &aText, TContactItemId aId);

public:
	TContactItemId iId;
	HBufC *iText;
	};


NONSHARABLE_CLASS(CCntIdleSorter) : public CBase
	{
public:
	static CCntIdleSorter* NewL(CContactDatabase& aContactDatabase);
	~CCntIdleSorter();

public:
	// Access methods.
	void ResetL();
	void Cancel();
	void StartSortingL(CArrayFix<CContactDatabase::TSortPref>* aSortOrder, TRequestStatus& aStatus);
	void StartSortingL(CArrayFix<CContactDatabase::TSortPref>* aSortOrder, TRequestStatus& aStatus, MContactSortObserver& aObserver);

private:
	// Internal construction methods.
	CCntIdleSorter();
	CCntIdleSorter(CContactDatabase& aContactDatabase);
	void ConstructL();

private:
	// Sort state.
	enum TState {EReadContacts, ESortContacts};

private:
	static TInt SortCallBack(TAny* aThis);
	TInt PeformSortStep();
	TBool ReadContactsL(TInt aNumber = 4);
	void SortListAndSaveL();
	void CompleteRequest(TInt aError = KErrNone);
	void ReportProgressL();

private:
	inline TInt& TotalCount()			{ return iTotalCount; }
	inline TInt TotalCount() const		{ return iTotalCount; }
	inline TInt& ReadSoFar()			{ return iReadSoFar; }
	inline TInt ReadSoFar() const		{ return iReadSoFar; }
	inline TBool& HasObserver()			{ return iHasObserver; }
	inline TBool HasObserver() const	{ return iHasObserver; }

private:
	TBool iHasObserver;
	TInt iTotalCount;
	TInt iReadSoFar;

	MContactSortObserver* iObserver;
	CContactDatabase& iDb;
	CArrayFix<CContactDatabase::TSortPref>* iSortOrder;
	TRequestStatus* iStatus;

	CIdle* iIdle;
	TState iState;
	CContactIdArray* iFinalItems;
	CSortArray* iSortedList;
	TContactItemId iCurrentId;
	TBool iSortStarted;
	};


NONSHARABLE_CLASS (CDataBaseChangeObserver) :  public CBase, public MContactDbObserver
	{
public:
	void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
	static CDataBaseChangeObserver* NewL(MContactDbPrivObserver& aPrivateObserver);
	~CDataBaseChangeObserver(); 

private:
	CDataBaseChangeObserver (MContactDbPrivObserver& aPrivateObserver);
	MContactDbPrivObserver& iPrivateObserver;
	}; 


#endif //__CCONTACTPRIVATE_H__