|
1 /* |
|
2 * Copyright (c) 2005 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 "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: Container of one contact item. It includes contact ID and WV IDs |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32std.h> |
|
23 #include <cntfldst.h> |
|
24 #include "CPEngContact.h" |
|
25 #include "PEngContactIdTools.h" |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CPEngContact::CPEngContact |
|
32 // C++ default constructor can NOT contain any code, that |
|
33 // might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CPEngContact::CPEngContact( |
|
37 TContactItemId& aContactId ) |
|
38 : iWVIds( 1 ), // usually only one WV per contact |
|
39 iContactItemId( aContactId ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CPEngContact::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CPEngContact::ConstructL( |
|
49 CContactItem* aContactItem ) |
|
50 { |
|
51 iWVIds.Reset(); |
|
52 // if there is no WV ID field then the array of the WV IDs will be empty |
|
53 CContactItemFieldSet& cardFieldSet = aContactItem->CardFields(); |
|
54 |
|
55 TInt fieldIndex ( cardFieldSet.FindNext( KPbkFieldIMAddress, |
|
56 KPbkFieldWVIdMapping, |
|
57 KContactFieldSetSearchAll ) ); |
|
58 // now read all wv ID fields |
|
59 while ( fieldIndex != KErrNotFound ) |
|
60 { |
|
61 CContactTextField* textField = ( cardFieldSet[fieldIndex] ).TextStorage(); // does not take ownership |
|
62 // read contact only if it's length is more then 0 |
|
63 TPtrC wvId ( textField->Text() ); |
|
64 if ( wvId.Length() != 0 ) |
|
65 { |
|
66 // if it leaves, it is cause of KErrNoMemory |
|
67 AddContactIdToArrayL( iWVIds, wvId ); |
|
68 } |
|
69 // +1 is to start from next field |
|
70 fieldIndex = cardFieldSet.FindNext( KPbkFieldIMAddress, KPbkFieldWVIdMapping, fieldIndex + 1 ); |
|
71 } |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CPEngContact::NewL |
|
76 // Two-phased constructor. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CPEngContact* CPEngContact::NewL( |
|
80 CContactItem* aContactItem ) |
|
81 { |
|
82 CPEngContact* self = NewLC( aContactItem ); |
|
83 |
|
84 CleanupStack::Pop( self ); // self |
|
85 |
|
86 return self; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CPEngContact::NewLC |
|
91 // Two-phased constructor. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CPEngContact* CPEngContact::NewLC( |
|
95 CContactItem* aContactItem ) |
|
96 { |
|
97 TContactItemId contactID( aContactItem->Id() ); |
|
98 CPEngContact* self = new( ELeave ) CPEngContact( contactID ); |
|
99 |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL( aContactItem ); |
|
102 |
|
103 return self; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CPEngContact::NewLC |
|
108 // Two-phased constructor. |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 CPEngContact* CPEngContact::NewL( |
|
112 TContactItemId& aContactID ) |
|
113 { |
|
114 CPEngContact* self = new( ELeave ) CPEngContact( aContactID ); |
|
115 |
|
116 // no need to call ConstructL |
|
117 |
|
118 return self; |
|
119 } |
|
120 |
|
121 // Destructor |
|
122 CPEngContact::~CPEngContact() |
|
123 { |
|
124 iWVIds.Reset(); |
|
125 } |
|
126 // ============================================================================= |
|
127 // ===============Function of base class ======================================= |
|
128 // ============================================================================= |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CPEngContact::ContactId() |
|
132 // Return contact Item ID |
|
133 // (other items were commented in a header). |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 TContactItemId CPEngContact::ContactId() const |
|
137 { |
|
138 return iContactItemId; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // CPEngContact::WvIds() |
|
143 // Get List of the WV IDs |
|
144 // (other items were commented in a header). |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 const MDesCArray& CPEngContact::WvIds() const |
|
148 { |
|
149 return iWVIds; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CPEngContact::Compare() |
|
154 // Compare two Contacts if they match, based on Contact Item ID |
|
155 // (other items were commented in a header). |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CPEngContact::Compare( |
|
159 const CPEngContact& aContactA, |
|
160 const CPEngContact& aContactB ) |
|
161 { |
|
162 return aContactA.Compare( aContactB ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPEngContact::CompareContactID() |
|
167 // Compare two Contacts if they match, based on Contact Item ID |
|
168 // (other items were commented in a header). |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TInt CPEngContact::Compare( |
|
172 const CPEngContact& aContact ) const |
|
173 { |
|
174 if ( aContact.ContactId() == iContactItemId ) |
|
175 { |
|
176 return KErrNone; |
|
177 } |
|
178 if ( aContact.ContactId() < iContactItemId ) |
|
179 { |
|
180 return 1; // does not match |
|
181 } |
|
182 return -1; // does not match |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPEngContact::ValidateWVId() |
|
187 // Search if WV Id is presented in the contact |
|
188 // (other items were commented in a header). |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 TBool CPEngContact::ValidateWVId( |
|
192 const TDesC& aWVId ) const |
|
193 { |
|
194 return !( KErrNotFound == FindContactIdInArray( iWVIds, aWVId ) ); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CPEngContact::WVIdsCount() |
|
199 // Count of the WV IDs in the contact |
|
200 // (other items were commented in a header). |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CPEngContact::WVIdsCount() |
|
204 { |
|
205 return iWVIds.Count(); |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CPEngContact::UpdateContactL() |
|
210 // Update contact from the contact db |
|
211 // (other items were commented in a header). |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CPEngContact::UpdateContactL( |
|
215 CContactDatabase& aContactDatabase ) |
|
216 { |
|
217 // update content of the Contact from the database |
|
218 CContactItem* contactItem = |
|
219 aContactDatabase.ReadMinimalContactLC( iContactItemId ); |
|
220 |
|
221 iWVIds.Reset(); |
|
222 ConstructL( contactItem ); |
|
223 CleanupStack::PopAndDestroy(); // contactItem |
|
224 } |
|
225 |
|
226 |
|
227 // End of File |