summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/cntplsql/inc/cntpplviewmanager.h
blob: f4b5db39cd32da1ec2c4913194e4c393dc9cd974 (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
/*
* 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 __CNTPPLVIEWMANAGER_H__
#define __CNTPPLVIEWMANAGER_H__

#include "cntsqlprovider.h"
#include "persistencelayer.h" // for interface definitions.
#include "persistencelayerimpl.h"
#include <sqldb.h>

class CViewContact;
class CCntPplViewSession;
class CCntSqlStatement;

/**
The CCntPplViewManager class provides the data source for the Contacts Model
view framework.  The view item manager provides support for multiple
iterators (used for view population) as well as the random access to the
Contacts database (used for keeping the views synchronised with the changing
database).
*/
class NONSHARED CCntPplViewManager : public CBase, public MLplViewIteratorManager
	{
public:
	static CCntPplViewManager* NewL(CPplContactsFile& aContactsFile, const CLplContactProperties& aContactProperties);
	~CCntPplViewManager();
	
	//Methods defined in MLplViewIteratorManager
	TInt OpenViewL(const CContactTextDef& aTextDef, const TContactViewPreferences aViewPrefs);
	void CloseView(TInt aViewId);
	void ChangeSortOrderL(TInt aViewId, const CContactTextDef& aTextDef);
	void BeginIterateL(TInt aViewId);
	void EndIterateL(TInt aViewId);
	CViewContact* NextItemL(TInt aViewId, TContactViewPreferences aViewPrefs);
	CViewContact* ItemAtL(TContactItemId aContactId, TInt aViewId);
	
	TUid ReadContactTextDefL(TContactItemId aContactId, TDes &aResult,const CContactTextDef& aTextDef);
    void TextFieldL(TInt aCntItemId,TFieldType aFieldType, TDes& aText);

private:
	void ConstructL();
	CCntPplViewManager(CPplContactsFile& aContactsFile, const CLplContactProperties& aContactProperties);
	
	TInt FindViewSessionIndexById(TInt aViewId) const;
	CCntPplViewSession* FindViewSessionByIdL(TInt aViewId) const;
	
private:
	CPplContactsFile& iContactsFile;
	const CLplContactProperties& iContactProperties;
	
	TInt  iNextViewId;
	RPointerArray<CCntPplViewSession> iViewSessions;
	
	CCntSqlStatement* 		iSelectFullFieldsStmt;
	};

class NONSHARED CCntPplViewSession: public CTimer,
    public MLplSqlDatabaseObserver
	{
public:	
	static CCntPplViewSession* NewL(CPplContactsFile& aContactsFile, const CLplContactProperties& aContactProperties, CCntSqlStatement& aSelectAllFields, TInt aViewId, const CContactTextDef& aTextDef, TContactViewPreferences aViewPrefs);
	~CCntPplViewSession();
	
	void ChangeSortOrderL(const CContactTextDef& aTextDef);
	
	void BeginIterateL();
	void EndIterate();
	CViewContact* NextItemL(TContactViewPreferences aViewPrefs);
	CViewContact* ItemAtL(TContactItemId aContactId);
	
	TInt ViewId() const;
	
	static void  TextFieldL(RSqlStatement& aSqlStatement, const CCntSqlStatement& aCntSqlStmt, const CContactTemplate& aSystemTemplate, TFieldType aFieldType, TDes& aText);
	
	// From MLplSqlDatabaseObserver
    void OnCloseL(); 
	
private:
	void ConstructL(const CContactTextDef& aTextDef);
	CCntPplViewSession(CPplContactsFile& aContactsFile, const CLplContactProperties& aContactProperties, CCntSqlStatement& aSelectAllFields, TInt aViewId, TContactViewPreferences aViewPrefs);
	
	CViewContact* CreateViewItemL(RSqlStatement& aSqlStmt, const CCntSqlStatement& aCntSqlStmt, const TContactViewPreferences& aViewPrefs);
	void  FillViewItemL(CViewContact& aViewContact, RSqlStatement& aSqlStmt, const TContactViewPreferences& aViewPrefs);
	
	static CViewContact* InitialiseViewItemL(RSqlStatement& aSqlStmt, const CCntSqlStatement& aCntSqlStmt, const TContactViewPreferences& aViewPrefs);
	static TBool HasTxtFieldInFastAccessFieldsL(RSqlStatement& aSelectStmt, const CCntSqlStatement& aCntSqlStmt, TDes& aText);
	static TBool SpecificTxtFieldInFastAccessFieldsL(RSqlStatement& aSelectStmt, const CCntSqlStatement& aCntSqlStmt, const TFieldType aFieldType, TDes& aText);
	static TUid  GetContactFieldMatchUid(const CViewContact& aViewContact, const TContactViewPreferences& aViewPreferences);
	static void  AddFieldInViewContactL(CViewContact& aViewContact, TPtrC& aFieldPtrC, const TContactViewPreferences& aViewPreferences);
    static TBool ContactCorrectType(TUid aContactTypeUid, TContactViewPreferences aTypeToInclude);	
    
    void RunL();  //interface for CTimer
   
    CViewContact* doItemAtL(TContactItemId aContactId);
    void CleanupCachedPrepareStatement();
private:
	const TInt 				iViewId;
	const CLplContactProperties& iContactProperties;
	
	CPplContactsFile& 		iContactsFile;
	CCntSqlStatement&       iSqlSmtSelectAllFieldsById;
	
	TContactViewPreferences iViewPrefs;
	
	CContactTextDef*		iTextDef;			
	CCntSqlStatement*		iCntSqlStatement;
    RSqlStatement           iRSqlStatement;
    TBool                   iRSqlStatementReady;
    RSqlStatement           iCachedSqlStatement;
    TBool                   iCachedSqlStatementReady;
	TBool 					iIsFastAccessFieldsOnly;
	};
	
	
#endif //__CNTPPLVIEWMANAGER_H__