summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cviewcontactmanager.h
blob: d4a0d06f44c0b7136fe2917a0445915dd52088bd (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
/*
* 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: 
*
*/




/**
 @file
 @internalComponent
 @released
*/


#ifndef __CVIEWCONTACTMANAGER_H__
#define __CVIEWCONTACTMANAGER_H__

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

class MContactViewSortObserver
    {
    public:
    enum TIccViewNotify
        {
        TIccViewNotify_IccOnlyLocked,
        TIccViewNotify_IccUnlocked          
        };
        
    public:
    	virtual TBool IdleSorterNotifyL(TInt aSortErr) =0;
    	virtual void  IccViewNotifyL(TInt aIccViewReady) =0;
    };


/**
The CViewContactManager is an internal class responsible to sort contact view items, 
according to sort plug-in, and provide CViewContact items for CContactLocalView.
And it's the only view class interact with persistence layer(CPplContactViewItemManager)
to retrieve contact view item from database.
@internalComponent
*/
NONSHARABLE_CLASS(CViewContactManager) : public CBase, public MContactViewSortObserver
	{
public:
    static CViewContactManager* NewL(CContactLocalView& aLocalView, MLplPersistenceLayerFactory& aFactory, const CContactTextDef& aTextDef, TContactViewPreferences aViewPerference, CViewContactSortPlugin* aSortPlugin);
	~CViewContactManager();
	
	TContactItemId AtL(TInt aIndex) const;
	TInt Count() const;
	TInt FindL(TContactItemId aContactId) const;
	void SortL();
	void SortL(const CContactTextDef& aTextDef);
	void StopSortL();
    TInt InsertL(const TContactItemId aContactId, TContactViewPreferences& aViewPreference);
	TInt RemoveL(const TContactItemId aContactId);
	HBufC* AllFieldsLC(TInt aIndex, const TDesC& aSeparator) const;
	
	const CViewContact& ContactAtL(TInt aIndex) const;

	TBool IsICCSynchronised() const;
	
    //Implementation for MContactSortObserver
	TBool IdleSorterNotifyL(TInt aSortErr);
    void  IccViewNotifyL(TInt aIccViewReady);
	
private:
	/* To represent the state when retrieving data from database */
	enum TReadState 
	    {
	    EReadFullChunk,    // The read items reached the number of limitation per invocation
	    EReadFullForMerge, // The read items reached the number of limitation per merge
	    EReadCompleted     // Read is completed, no more view contact item in database.
	    };
	    
private: 
	CViewContactManager(CContactLocalView& aLocalView, MLplViewIteratorManager& aLplViewMgr, TContactViewPreferences aViewPerference, CViewContactSortPlugin* aSortPlugin);
	void ConstructL(MLplPersistenceLayerFactory& aFactory, const CContactTextDef& aTextDef);
	
    TInt InsertViewContactL(const CViewContact* aNewContact, TBool aSortByIdOnly, TInt aStart);
	void HeapSortL(RPointerArray<CViewContact>& aViewContacts);
	RPointerArray<CViewContact>* MergeL(RPointerArray<CViewContact>& aLeftContacts, RPointerArray<CViewContact>& aRightContacts);
	
	TReadState ReadInViewContactsL(RPointerArray<CViewContact>& aViewContacts);
	CViewContact& ViewContactAtL(TInt aIndex) const;
	
    void ResetSort();
    
	static TBool ContactCorrectType(TUid aType, TContactViewPreferences aTypeToInclude);
	static void  ResetAndDestroyRPointerArrayPointer(TAny *aArray);
	
	//These functions are copied from CContactViewBase classes
	TBool  IsContactSortable(const CViewContact& aContact, TContactViewPreferences& aViewPreferences) const;
	TInt   CompareContactsAndIdsL(const CViewContact& aFirst, const CViewContact& aSecond) const;
	TInt   TextCompareFieldsL(const CViewContact& aFirst, const CViewContact& aSecond) const;
	HBufC* FieldsWithSeparatorLC(const CViewContact& aViewContact, const TDesC& aSeparator) const;
	static TInt CompareFieldsWithCollationLevel(const CViewContact& aFirst, const CViewContact& aSecond, TInt aCollationLevel, const TCollationMethod* aCollateMethod);
    	
private:
	CContactLocalView& 		        iLocalView;
	
	CIdleContactSorter*				iIdleSorter;
	
	TInt                            iViewSessionId;
	
	RPointerArray<CViewContact>*	iViewContacts;
	RPointerArray<CViewContact>*    iUnsortedViewContacts;
	RPointerArray<CViewContact>*    iViewContactsBuffer;

	CViewContactSortPlugin*			iSortPluginImpl;  //this is not owned by the class
	
    TContactViewPreferences         iViewPreferences;
    TCollationMethod				iCollationMethod;	
	
	MLplViewIteratorManager& 		iLplViewItemMgr;
	};

#endif // __CVIEWCONTACTMANAGER_H__