|
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 "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: This shall hold all the contact data associated with a |
|
15 * conversation like name, numbers and contact link . |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // SYSTEM INCLUDE FILES |
|
21 #include <miutpars.h> |
|
22 |
|
23 // USER INCLUDE FILES |
|
24 #include "ccsconversation.h" |
|
25 #include "ccsconversationcontact.h" |
|
26 #include "ccsdebug.h" |
|
27 |
|
28 // ============================== MEMBER FUNCTIONS ============================ |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CCsConversationContact::CCsConversationContact |
|
32 // Default constructor |
|
33 // ---------------------------------------------------------------------------- |
|
34 CCsConversationContact::CCsConversationContact() |
|
35 { |
|
36 } |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CCsConversationContact::ConstructL |
|
40 // Two phase construction |
|
41 // ---------------------------------------------------------------------------- |
|
42 void |
|
43 CCsConversationContact::ConstructL() |
|
44 { |
|
45 iDisplayName = NULL; |
|
46 iContactId = KErrNotFound; |
|
47 iPhoneNumberList = new (ELeave) RPointerArray<HBufC> (); |
|
48 } |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CCsConversationContact::NewL |
|
52 // Two Phase constructor |
|
53 // ---------------------------------------------------------------------------- |
|
54 CCsConversationContact* |
|
55 CCsConversationContact::NewL() |
|
56 { |
|
57 CCsConversationContact* self = new (ELeave) CCsConversationContact(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CCsConversationContact::~CCsConversationContact |
|
66 // Destructor |
|
67 // ---------------------------------------------------------------------------- |
|
68 CCsConversationContact::~CCsConversationContact() |
|
69 { |
|
70 if(iDisplayName) |
|
71 { |
|
72 delete iDisplayName; |
|
73 iDisplayName = NULL; |
|
74 } |
|
75 |
|
76 if (iPhoneNumberList) |
|
77 { |
|
78 iPhoneNumberList->ResetAndDestroy(); |
|
79 iPhoneNumberList->Close(); |
|
80 delete iPhoneNumberList; |
|
81 iPhoneNumberList = NULL; |
|
82 } |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CCsConversationContact::GetDisplayName |
|
87 // get the display name of the conversation |
|
88 // ---------------------------------------------------------------------------- |
|
89 HBufC* |
|
90 CCsConversationContact::GetDisplayName() const |
|
91 { |
|
92 return iDisplayName; |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // CCsConversationContact::SetDisplayNameL |
|
97 // Sets the display name of the conversation |
|
98 // ---------------------------------------------------------------------------- |
|
99 void |
|
100 CCsConversationContact::SetDisplayNameL( |
|
101 const TDesC& aDisplayName) |
|
102 { |
|
103 TRAPD(error, iDisplayName = aDisplayName.AllocL()); |
|
104 if(error != KErrNone) |
|
105 { |
|
106 // handle error |
|
107 // call panic |
|
108 PRINT1 ( _L("CCsConversationContact::SetFirstNameL - Error:%d"), |
|
109 error ); |
|
110 } |
|
111 |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CCsConversationContact::GetContactId |
|
116 // get the phonebook Contact Id link for the conversation |
|
117 // ---------------------------------------------------------------------------- |
|
118 TInt32 |
|
119 CCsConversationContact::GetContactId() const |
|
120 { |
|
121 return iContactId; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CCsConversationContact::SetContactLink |
|
126 // Sets the phonebook Contact Id for the conversation |
|
127 // ---------------------------------------------------------------------------- |
|
128 void |
|
129 CCsConversationContact::SetContactId( |
|
130 TInt32 aContactId) |
|
131 { |
|
132 iContactId = aContactId; |
|
133 } |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // CCsConversationContact::AddPhoneNumber |
|
137 // Sets the phone number inside contact list |
|
138 // ---------------------------------------------------------------------------- |
|
139 void |
|
140 CCsConversationContact::AddPhoneNumberL( |
|
141 TDesC& aPhoneNumber) |
|
142 { |
|
143 HBufC* phoneNumber = aPhoneNumber.AllocL(); |
|
144 iPhoneNumberList->AppendL(phoneNumber); |
|
145 } |
|
146 |
|
147 // ---------------------------------------------------------------------------- |
|
148 // CCsConversationContact::GetPhoneNumberList |
|
149 // Returns a list of associated phone numbers |
|
150 // ---------------------------------------------------------------------------- |
|
151 void |
|
152 CCsConversationContact::GetPhoneNumberList( |
|
153 RPointerArray<TDesC>& aPhoneNumbers) |
|
154 { |
|
155 for ( int index = 0; index < iPhoneNumberList->Count(); index++ ) |
|
156 { |
|
157 HBufC* value = (*iPhoneNumberList)[index]; |
|
158 aPhoneNumbers.Append(value); |
|
159 } |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------------------------------- |
|
163 // CCsConversationContact::MatchPhoneNumber |
|
164 // Check if the input phone number (aPhoneNumber) is associated with this |
|
165 // contact. Compares for aNumDigits. |
|
166 // ---------------------------------------------------------------------------- |
|
167 TBool |
|
168 CCsConversationContact::MatchPhoneNumber( |
|
169 TDesC& aPhoneNumber, TInt aNumDigits) const |
|
170 { |
|
171 if (aPhoneNumber.Length() == 0) |
|
172 { |
|
173 return EFalse; |
|
174 } |
|
175 |
|
176 TInt useDigits = aNumDigits; |
|
177 |
|
178 // Check if phone number is an email address |
|
179 TImMessageField email; |
|
180 if ( email.ValidInternetEmailAddress(aPhoneNumber) ) |
|
181 { |
|
182 useDigits = aPhoneNumber.Length(); |
|
183 } |
|
184 |
|
185 TInt count = iPhoneNumberList->Count(); |
|
186 for ( TInt i = 0 ; i < count; i++) |
|
187 { |
|
188 HBufC* pno = (*iPhoneNumberList)[i]; |
|
189 |
|
190 // Compare only last useDigits dgits of the number/ address |
|
191 if (aPhoneNumber.Right(useDigits).CompareF(pno->Des(). |
|
192 Right(useDigits)) == 0) |
|
193 { |
|
194 return ETrue; |
|
195 } |
|
196 } |
|
197 return EFalse; |
|
198 } |
|
199 |
|
200 |
|
201 // EOF |