|
1 /* |
|
2 * Copyright (c) 2006 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: Array of voip matches. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tphcntvoipmatchArray.h" |
|
20 #include "CPhCntContact.h" |
|
21 #include "tphcntsipuri.h" |
|
22 #include "tphcntcontactutil.h" |
|
23 |
|
24 // ======== MEMBER FUNCTIONS ======== |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // Constructor |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 TPhCntVoipMatchArray::TPhCntVoipMatchArray() |
|
31 { |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Destructor |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 TPhCntVoipMatchArray::~TPhCntVoipMatchArray() |
|
39 { |
|
40 iMatches.Reset(); |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Addes contact to array. |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 void TPhCntVoipMatchArray::AppendL( |
|
48 CPhCntContact* aVoipMatch ) |
|
49 { |
|
50 User::LeaveIfError( iMatches.Append( aVoipMatch ) ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Finds first match that has voip number. |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CPhCntContact* TPhCntVoipMatchArray::FindFullMatch( |
|
58 const TPhCntSipURI& aSipURI ) |
|
59 { |
|
60 CPhCntContact* foundContact = NULL; |
|
61 CPhCntContact* contact = NULL; |
|
62 |
|
63 const TPhCntVoipMatchArray::TMatchType type = |
|
64 FindFullOrUsernameMatch( aSipURI, contact ); |
|
65 |
|
66 if( type == TPhCntVoipMatchArray::EFullMatch ) |
|
67 { |
|
68 foundContact = contact; |
|
69 } |
|
70 RemoveMatchFromArray( foundContact ); |
|
71 return foundContact; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // Finds full or username match. |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 CPhCntContact* TPhCntVoipMatchArray::FindFullOrUsernameMatch( |
|
79 const TPhCntSipURI& aSipUri, |
|
80 const TInt aCharsForMatch ) |
|
81 { |
|
82 CPhCntContact* contact = NULL; |
|
83 FindFullOrUsernameMatch( aSipUri, contact, aCharsForMatch ); |
|
84 RemoveMatchFromArray( contact ); |
|
85 return contact; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // Destroys the items in array. |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 void TPhCntVoipMatchArray::ReleaseMatches() |
|
93 { |
|
94 const TInt matchesCount( iMatches.Count() ); |
|
95 for( TInt i = 0; i < matchesCount; i++ ) |
|
96 { |
|
97 iMatches[i]->Release(); |
|
98 } |
|
99 iMatches.Reset(); |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Removes match from array. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void TPhCntVoipMatchArray::RemoveMatchFromArray( |
|
107 const CPhCntContact* const aMatch ) |
|
108 { |
|
109 const TInt index( iMatches.Find( aMatch ) ); |
|
110 if( index >= 0 ) |
|
111 { |
|
112 iMatches.Remove( index ); |
|
113 } |
|
114 iMatches.Compress(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // Determines if contact has aSipURI voip number. |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 TPhCntVoipMatchArray::TMatchType TPhCntVoipMatchArray::HasVoipNumber( |
|
122 CPhCntContact& aContact, |
|
123 const TPhCntSipURI& aSipURI, |
|
124 const TInt aCharsForMatch ) const |
|
125 { |
|
126 const RArray<TPhCntNumber>& allNumbers = aContact.AllNumbers(); |
|
127 const TInt numbers( allNumbers.Count() ); |
|
128 TMatchType matchType = TPhCntVoipMatchArray::ENone; |
|
129 |
|
130 for( TInt i = 0; i < numbers; i++ ) |
|
131 { |
|
132 TPhCntNumber number = allNumbers[i]; |
|
133 if( number.Type() == CPhCntContact::EVoipNumber || |
|
134 number.Type() == CPhCntContact::EMobileNumber || |
|
135 number.Type() == CPhCntContact::EStandardNumber || |
|
136 number.Type() == CPhCntContact::EPagerNumber || |
|
137 number.Type() == CPhCntContact::EVideoNumber || |
|
138 number.Type() == CPhCntContact::EAssistantNumber || |
|
139 number.Type() == CPhCntContact::EFaxNumber || |
|
140 number.Type() == CPhCntContact::ECarNumber |
|
141 ) |
|
142 { |
|
143 // If uris are the same then we have a full match. |
|
144 TPhCntSipURI matchURI( number.Number(), aCharsForMatch ); |
|
145 // full match if uris are the same (usernamepart requires |
|
146 // case sensitive match, domain is not sensitive) |
|
147 if ( matchURI.SipURI().CompareF( aSipURI.SipURI() ) |
|
148 == KErrNone && |
|
149 matchURI.UserNamePart().Compare( aSipURI.UserNamePart() ) |
|
150 == KErrNone ) |
|
151 { |
|
152 matchType = TPhCntVoipMatchArray::EFullMatch; |
|
153 aContact.SetMatchedVoipNumber( matchURI ); |
|
154 break; |
|
155 } |
|
156 else if( matchURI.UserNamePart().Compare( aSipURI.UserNamePart() ) |
|
157 == KErrNone ) |
|
158 { |
|
159 matchType = TPhCntVoipMatchArray::EUserNameMatch; |
|
160 aContact.SetMatchedVoipNumber( matchURI ); |
|
161 } |
|
162 else if( 0 != aCharsForMatch && matchURI.FixedUserNamePart().Compare( |
|
163 aSipURI.FixedUserNamePart() ) == KErrNone ) |
|
164 { |
|
165 matchType = TPhCntVoipMatchArray::EUserNameMatch; |
|
166 aContact.SetMatchedVoipNumber( matchURI ); |
|
167 } |
|
168 } |
|
169 } |
|
170 return matchType; |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Finds contact that has aSipURI voip number |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 TPhCntVoipMatchArray::TMatchType |
|
178 TPhCntVoipMatchArray::FindFullOrUsernameMatch( |
|
179 const TPhCntSipURI& aSipUri, |
|
180 CPhCntContact*& aFoundContact, |
|
181 const TInt aCharsForMatch ) |
|
182 { |
|
183 CPhCntContact* userNameMatch = NULL; |
|
184 CPhCntContact* fullMatch = NULL; |
|
185 TBool duplicateMatch( EFalse ); |
|
186 TMatchType matchType = TPhCntVoipMatchArray::ENone; |
|
187 // Go through all voip matches. |
|
188 const TInt matchesCount( iMatches.Count() ); |
|
189 |
|
190 for( TInt i = 0; i < matchesCount; i++ ) |
|
191 { |
|
192 |
|
193 CPhCntContact* possibleMatch = iMatches[i]; |
|
194 |
|
195 matchType = HasVoipNumber( *possibleMatch, aSipUri, aCharsForMatch ) ; |
|
196 if( matchType == TPhCntVoipMatchArray::EFullMatch ) |
|
197 { |
|
198 if ( fullMatch && |
|
199 !TPhCntContactUtil::AreFirstAndLastAndCompanyNameSame( |
|
200 *fullMatch, *possibleMatch ) ) |
|
201 { |
|
202 // Duplicate match means no match found |
|
203 fullMatch = NULL; |
|
204 userNameMatch = NULL; |
|
205 break; |
|
206 } |
|
207 fullMatch = possibleMatch; |
|
208 } |
|
209 // Once username match is found it |
|
210 // will be the match if fullmatch is not found. |
|
211 else if( matchType == TPhCntVoipMatchArray::EUserNameMatch && |
|
212 EFalse == duplicateMatch ) |
|
213 { |
|
214 if ( userNameMatch ) |
|
215 { |
|
216 // Duplicate username match. |
|
217 duplicateMatch = ETrue; |
|
218 } |
|
219 userNameMatch = possibleMatch; |
|
220 } |
|
221 } |
|
222 |
|
223 if( fullMatch ) |
|
224 { |
|
225 aFoundContact = fullMatch; |
|
226 } |
|
227 else if ( duplicateMatch ) |
|
228 { |
|
229 aFoundContact = NULL; |
|
230 } |
|
231 else |
|
232 { |
|
233 aFoundContact = userNameMatch; |
|
234 } |
|
235 return matchType; |
|
236 } |
|
237 |
|
238 // End of File |