summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/integration/cntperftest/src/viewdefbase.cpp
blob: 1c4ab3d257d79653a6a66d9cd0434125702ae461 (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
/*
* Copyright (c) 2006-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
 @publishedAll
 @released
*/

#include <e32panic.h>
#include <test/testexecutelog.h>
#include <cntfldst.h>
#include "viewdefbase.h"


//Number of contacts
CViewDefBase::CViewDefBase(const TInt aContacts):CCntBaseStep(aContacts)
	{
	}

/**More items to be initilized within the uheap macro pair*/	
void CViewDefBase::InitializeL()
	{
	
	CCntBaseStep::InitializeL();
	
	iViewII = CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
	CContactItemViewDef::EIncludeHiddenFields);
	
	iViewIM = CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
	CContactItemViewDef::EMaskHiddenFields);
	
	iViewMI = CContactItemViewDef::NewL(CContactItemViewDef::EMaskFields,
	CContactItemViewDef::EIncludeHiddenFields);
	
	iViewMM = CContactItemViewDef::NewL(CContactItemViewDef::EMaskFields,
	CContactItemViewDef::EMaskHiddenFields);
	
	iDefView=CContactItemViewDef::NewL(CContactItemViewDef::EIncludeFields,
	CContactItemViewDef::EMaskHiddenFields);
	iDefView->AddL(KUidContactFieldMatchAll);
	
	}

/**More items to be cleaned up within the uheap macro pair*/		
void CViewDefBase::Cleanup()
	{
	CCntBaseStep::Cleanup();
	
	delete iViewII;
	iViewII = NULL;
	delete iViewIM;
	iViewIM = NULL;
	delete iViewMI;
	iViewMI = NULL;
	delete iViewMM;
	iViewMM = NULL;
	delete iDefView;
	iDefView = NULL;
	}

/**returns the number of nonhidden, hidden and empty fields,
that match aView for the current contact item*/	
void CViewDefBase::FieldsInView(const CContactItemViewDef &aView, TInt &aRetNormal, 
								TInt &aRetHidden, const TBool aHasEmpty)
	{
	TInt length = 0;
	length = iFields->Count();
	
	for(TInt i = 0; i < length; )
		{
		if( !( (*iFields)[i].Storage()->IsFull() ) )
			{
			if(aHasEmpty)
				{
				++i;
				continue;
				}
			else
				{
				_LIT(KUnfullView,"FieldsInView field is not full");
				User::Panic(KUnfullView, EInvariantFalse);
				}
			}
		if( ( i = FindInFieldSet(aView, i) ) != KErrNotFound )
			{
			if( (*iFields)[i].IsHidden() )
				{
				++aRetHidden;
				}
			else
				{
				++aRetNormal;
				}
			++i;
			}
		else
			{
			break;
			}
		}
	
	}

/**returns the position of the next field that matches aView for the current contact item,
returns KErrNotFound when it reaches end of fieldset or if it doesnt find a match*/		
TInt CViewDefBase::FindInFieldSet(const CContactItemViewDef &aView, const TInt &aFrom)
	{
	const TInt length = iFields->Count();
	const TInt viewLength = aView.Count();
	CContentType * ctype = NULL;
	TUid tuidback = KUidContactFieldNone;
	TBool allUids = EFalse;
	
	for(TInt i = aFrom; i < length; i++ )
		{
		ctype = CONST_CAST( CContentType *, &((*iFields)[i].ContentType()) );
		tuidback = ctype->Mapping();
		ctype->SetMapping(KUidContactFieldNone);//contain now should ignore mapping
		allUids = EFalse;
		
		for(TInt k = 0; k < viewLength; ++k)
			{	
			if( ctype->ContainsFieldType( aView[k] ) )
				{
				allUids = ETrue;
				break;
				}
			}
		ctype->SetMapping(tuidback);
		if(allUids)
			{
			return i;
			}
		}
	return KErrNotFound;
	}

/**adds a pair of existing uids, in every possible combination, to aView, 
aView is reset before the pair are added to aview.if aMany is greater than one, more than a pair
of uids are added but not in every possible combination*/		
void CViewDefBase::AddMultipleUidsL( CContactItemViewDef &aView, TInt &aPos, const TInt &aMany )
	{
	
	static TInt lastPlace = 0;
	const static TInt count = iExistingUidsArray->Count();	
	aView.Reset();
	aView.AddL( TUid::Uid( (*iExistingUidsArray)[aPos] ) );
	
	for(TInt i = 0; (lastPlace < count) && (i < aMany); ++lastPlace, ++i)
		{
		if(lastPlace == aPos || ((*iExistingUidsArray)[lastPlace] == 0) )
			{
			--i;
			continue;
			}
		aView.AddL( TUid::Uid( (*iExistingUidsArray)[lastPlace] ) );
		}
	if( lastPlace == count )
		{
		lastPlace = 0;
		++aPos;//this should never equal count
		_LIT(KNext,"next %d");
		INFO_PRINTF2(KNext, aPos);
		if( (aPos < count) && ((*iExistingUidsArray)[aPos] == 0) )
			{
			++aPos;
			}
		}
		
	}