5
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <MVPbkFieldType.h>
|
|
20 |
#include <MVPbkContactFieldTextData.h>
|
|
21 |
#include <MVPbkContactLink.h>
|
|
22 |
#include <MVPbkContactLinkArray.h>
|
|
23 |
#include <MVPbkContactGroup.h>
|
|
24 |
#include <barsread.h>
|
|
25 |
#include <eikenv.h>
|
|
26 |
#include <TVPbkFieldTypeMapping.h>
|
|
27 |
#include <MVPbkContactFieldTextData.h>
|
|
28 |
#include <MVPbkContactFieldData.h>
|
|
29 |
#include <MVPbkContactFieldBinaryData.h>
|
|
30 |
#include <MVPbkContactFieldDateTimeData.h>
|
|
31 |
#include <MVPbkStoreContactField.h>
|
|
32 |
|
|
33 |
#include "singlecontact.h"
|
|
34 |
|
|
35 |
//NewL method for CSingleContact class. It holds MVPbkStoreContact variable as its member
|
|
36 |
CSingleContact* CSingleContact::NewL(MVPbkStoreContact* aSingleContact, Ttype aIndicator)
|
|
37 |
{
|
|
38 |
CSingleContact* self = new( ELeave ) CSingleContact();
|
|
39 |
CleanupStack::PushL( self );
|
|
40 |
self->ConstructL(aSingleContact, aIndicator);
|
|
41 |
CleanupStack::Pop( self );
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
EXPORT_C
|
|
46 |
CSingleContact* CSingleContact::NewL()
|
|
47 |
{
|
|
48 |
CSingleContact* self = new( ELeave ) CSingleContact();
|
|
49 |
CleanupStack::PushL( self );
|
|
50 |
self->iContactId = KNullDesC8().AllocL();
|
|
51 |
CleanupStack::Pop( self );
|
|
52 |
return self;
|
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
//Constructor
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
CSingleContact::CSingleContact()
|
|
60 |
{
|
|
61 |
}
|
|
62 |
|
|
63 |
void CSingleContact::ConstructL(MVPbkStoreContact* aSingleContact, Ttype aIndicator)
|
|
64 |
{
|
|
65 |
iIndicator = aIndicator;
|
|
66 |
iContactId = KNullDesC8().AllocL();
|
|
67 |
ConvertContactToFieldListL(aSingleContact);
|
|
68 |
}
|
|
69 |
|
|
70 |
void CSingleContact::ConvertContactToFieldListL(MVPbkStoreContact* aSingleContact)
|
|
71 |
{
|
|
72 |
|
|
73 |
if(aSingleContact)
|
|
74 |
{
|
|
75 |
TInt fieldCount = aSingleContact->Fields().FieldCount();
|
|
76 |
CSingleContactField* field = NULL;
|
|
77 |
for(TInt fieldIndex = 0; fieldIndex < fieldCount ; fieldIndex++)
|
|
78 |
{
|
|
79 |
field = NextFieldL(aSingleContact, fieldIndex);
|
|
80 |
if(field !=NULL)
|
|
81 |
{
|
|
82 |
iFields.AppendL(field);
|
|
83 |
}
|
|
84 |
}
|
|
85 |
}
|
|
86 |
delete aSingleContact;
|
|
87 |
|
|
88 |
}
|
|
89 |
//Returns the Next field in the contact if any, otherwise returns NULL
|
|
90 |
CSingleContactField* CSingleContact::NextFieldL(MVPbkStoreContact* aSingleContact, TInt aIndex)
|
|
91 |
{
|
|
92 |
TPtrC text(KNullDesC);
|
|
93 |
TTime time;
|
|
94 |
TPtrC8 val;
|
|
95 |
|
|
96 |
CSingleContactField* contactField = CSingleContactField::NewL();
|
|
97 |
CleanupStack::PushL(contactField);
|
|
98 |
if(iIndicator == EContacts)
|
|
99 |
{
|
|
100 |
//Get the field at iFieldIndex in the contact
|
|
101 |
MVPbkStoreContactField& field = aSingleContact->Fields().FieldAt(aIndex);
|
|
102 |
|
|
103 |
//Get the fieldKey of the field
|
|
104 |
TPtrC8 fieldKey = CSearchFields::GetFieldKeyFromId(field.BestMatchingFieldType()->FieldTypeResId());
|
|
105 |
if(fieldKey.Compare(KNullDesC8) == 0)
|
|
106 |
{
|
|
107 |
CleanupStack::PopAndDestroy(contactField);
|
|
108 |
return NULL;
|
|
109 |
}
|
|
110 |
//Get the label of the field
|
|
111 |
TPtrC label(field.FieldLabel());
|
|
112 |
|
|
113 |
//Get the value of the field
|
|
114 |
|
|
115 |
TVPbkFieldStorageType storageType = field.FieldData().DataType();
|
|
116 |
//TBuf<KMinHeapGrowBy> value;
|
|
117 |
|
|
118 |
if( EVPbkFieldStorageTypeBinary == storageType )
|
|
119 |
{
|
|
120 |
val.Set((MVPbkContactFieldBinaryData::Cast(field.FieldData())).BinaryData());
|
|
121 |
//value.Copy(val);
|
|
122 |
}
|
|
123 |
else if( EVPbkFieldStorageTypeDateTime == storageType )
|
|
124 |
{
|
|
125 |
time = (MVPbkContactFieldDateTimeData::Cast(field.FieldData())).DateTime();
|
|
126 |
contactField->SetDateTime(time);
|
|
127 |
}
|
|
128 |
else
|
|
129 |
{
|
|
130 |
text.Set((MVPbkContactFieldTextData::Cast(field.FieldData())).Text());
|
|
131 |
}
|
|
132 |
|
|
133 |
//Set the parameters in CSingleContactField object
|
|
134 |
contactField->SetFieldParamsL(fieldKey, label, text);
|
|
135 |
|
|
136 |
}
|
|
137 |
else if(iIndicator == EGroups)
|
|
138 |
{
|
|
139 |
TPtrC groupLabel = (aSingleContact->Group())->GroupLabel();
|
|
140 |
|
|
141 |
MVPbkContactLinkArray* linkArray = (aSingleContact->Group())->ItemsContainedLC();
|
|
142 |
TInt noOfEntries = linkArray->Count();
|
|
143 |
if(noOfEntries > 0)
|
|
144 |
{
|
|
145 |
RPointerArray<HBufC8> array(noOfEntries);
|
|
146 |
CleanupClosePushL(array);
|
|
147 |
const HBufC8* packedLink;
|
|
148 |
|
|
149 |
for(int i=0; i<noOfEntries; i++)
|
|
150 |
{
|
|
151 |
packedLink = const_cast <MVPbkContactLink&>(linkArray->At(i)).PackLC();
|
|
152 |
array.AppendL(packedLink);
|
|
153 |
}
|
|
154 |
|
|
155 |
//Set the parameters in CSingleContactField object
|
|
156 |
contactField->SetFieldParamsL(groupLabel, array);
|
|
157 |
|
|
158 |
CleanupStack::Pop(noOfEntries);
|
|
159 |
CleanupStack::Pop(&array);
|
|
160 |
}
|
|
161 |
else
|
|
162 |
{
|
|
163 |
RPointerArray<HBufC8> array;
|
|
164 |
//Set the parameters in CSingleContactField object
|
|
165 |
contactField->SetFieldParamsL(groupLabel, array);
|
|
166 |
}
|
|
167 |
CleanupStack::PopAndDestroy();
|
|
168 |
}
|
|
169 |
CleanupStack::Pop(contactField);
|
|
170 |
return contactField;
|
|
171 |
}
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//Sets the contact id of a contact
|
|
174 |
// ---------------------------------------------------------------------------
|
|
175 |
EXPORT_C void CSingleContact::SetContactIdL(const TDesC8& aContactId)
|
|
176 |
{
|
|
177 |
if(iContactId)
|
|
178 |
{
|
|
179 |
delete iContactId;
|
|
180 |
iContactId = NULL;
|
|
181 |
}
|
|
182 |
iContactId = aContactId.AllocL();
|
|
183 |
}
|
|
184 |
|
|
185 |
// ---------------------------------------------------------------------------
|
|
186 |
//Gets the contact id of a contact
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
EXPORT_C TDesC8& CSingleContact::GetContactId()
|
|
189 |
{
|
|
190 |
return *iContactId;
|
|
191 |
}
|
|
192 |
// ---------------------------------------------------------------------------
|
|
193 |
// CSingleContact::RemoveFieldL
|
|
194 |
// Removes the specified field from the contact
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
|
|
197 |
EXPORT_C TInt CSingleContact::RemoveField(TInt aIndex)
|
|
198 |
{
|
|
199 |
TInt retVal = KErrArgument;
|
|
200 |
|
|
201 |
if((aIndex >= 0) && (aIndex < iFields.Count()))
|
|
202 |
{
|
|
203 |
delete iFields[aIndex];
|
|
204 |
iFields[aIndex] = NULL;
|
|
205 |
iFields.Remove(aIndex);
|
|
206 |
retVal = KErrNone;
|
|
207 |
}
|
|
208 |
|
|
209 |
return retVal;
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
213 |
// ---------------------------------------------------------------------------
|
|
214 |
// CSingleContact::RemoveAllFields
|
|
215 |
// Removes all fields from the contact
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
|
|
218 |
EXPORT_C void CSingleContact::RemoveAllFields()
|
|
219 |
{
|
|
220 |
iFields.ResetAndDestroy();
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
// ---------------------------------------------------------------------------
|
|
225 |
// CSingleContact::AddFieldToContactL
|
|
226 |
// Add a Field to Contact
|
|
227 |
// ---------------------------------------------------------------------------
|
|
228 |
|
|
229 |
EXPORT_C void CSingleContact::AddFieldToContactL( const CSingleContactField* aField )
|
|
230 |
{
|
|
231 |
iFields.AppendL(aField);
|
|
232 |
}
|
|
233 |
|
|
234 |
|
|
235 |
//Destructor
|
|
236 |
CSingleContact::~CSingleContact()
|
|
237 |
{
|
|
238 |
iFields.ResetAndDestroy();
|
|
239 |
delete iContactId;
|
|
240 |
}
|
|
241 |
|
|
242 |
|
|
243 |
//Get the number of fields in the contact
|
|
244 |
EXPORT_C
|
|
245 |
TInt CSingleContact::FieldCount()
|
|
246 |
{
|
|
247 |
return iFields.Count();
|
|
248 |
}
|
|
249 |
//Get the field at the index;
|
|
250 |
EXPORT_C
|
|
251 |
CSingleContactField* CSingleContact::FieldAt(TInt aIndex)
|
|
252 |
{
|
|
253 |
if((aIndex >= 0) && (aIndex < iFields.Count()))
|
|
254 |
{
|
|
255 |
return iFields[aIndex];
|
|
256 |
}
|
|
257 |
else
|
|
258 |
{
|
|
259 |
return NULL;
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|