|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "musuicontactutil.h" |
|
20 #include "musuidefinitions.h" |
|
21 #include "muslogger.h" |
|
22 #include "musenguriparser.h" |
|
23 #include "musuid.hrh" |
|
24 |
|
25 #include <RPbkViewResourceFile.h> // Phonebook view resource |
|
26 #include <CPbkContactEditorDlg.h> |
|
27 #include <CPbkFieldsInfo.h> |
|
28 #include <TPbkContactItemField.h> |
|
29 |
|
30 #include <cntdb.h> |
|
31 #include <cntitem.h> |
|
32 #include <cntfield.h> |
|
33 #include <cntdef.h> |
|
34 #include <cntfldst.h> |
|
35 #include <CPbkContactEngine.h> |
|
36 #include <apgtask.h> |
|
37 |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 TBool MusUiContactUtil::ShareViewFieldExistsL( CCoeEnv& aEnv, TInt aContactId ) |
|
44 { |
|
45 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::ShareViewFieldExistsL" ); |
|
46 |
|
47 TBool ret( EFalse ); |
|
48 |
|
49 RPbkViewResourceFile pbkResourceFile( aEnv ); |
|
50 CleanupClosePushL( pbkResourceFile ); |
|
51 pbkResourceFile.OpenL(); |
|
52 CPbkContactEngine* pbkContactEngine = CPbkContactEngine::NewL(); |
|
53 CleanupStack::PushL( pbkContactEngine ); |
|
54 CPbkContactItem* contactItem = NULL; |
|
55 CleanupStack::PushL( contactItem ); |
|
56 if ( aContactId > 0 ) |
|
57 { |
|
58 contactItem = pbkContactEngine->OpenContactL( aContactId ); |
|
59 if ( contactItem->FindField( EPbkFieldIdShareView ) ) |
|
60 { |
|
61 MUS_LOG( "mus: [MUSUI ] EPbkFieldIdShareView found!!" ); |
|
62 ret = ETrue; |
|
63 } |
|
64 else if ( contactItem->FindField( EPbkFieldIdSIPID ) ) |
|
65 { |
|
66 MUS_LOG( "mus: [MUSUI ] EPbkFieldIdSIPID found, NOT EPbkFieldIdShareView defined!!!" ); |
|
67 ret = ETrue; |
|
68 } |
|
69 else |
|
70 { |
|
71 ret = EFalse; |
|
72 } |
|
73 } |
|
74 else |
|
75 { |
|
76 ret = EFalse; |
|
77 } |
|
78 CleanupStack::PopAndDestroy( 3 ); // contactItem, pbkContactEngine, &pbkResourceFile |
|
79 MUS_LOG( "mus: [MUSUI ] <- MusUiContactUtil::ShareViewFieldExistsL" ); |
|
80 return ret; |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 TBool MusUiContactUtil::CheckPbContactForVSAddressesL( CCoeEnv& aEnv, |
|
89 const TDesC& aOriginator, |
|
90 TInt aContactId) |
|
91 { |
|
92 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::CheckPbContactForVSAddressesL" ); |
|
93 |
|
94 TBool sipAddrMatches(EFalse); |
|
95 TBool shareViewAddrMatches(EFalse); |
|
96 TBool ret(EFalse); |
|
97 |
|
98 if(MatchTextWithPbFieldsL(aEnv, EPbkFieldIdSIPID, aOriginator, aContactId)) |
|
99 { |
|
100 sipAddrMatches=ETrue; |
|
101 } |
|
102 if(MatchTextWithPbFieldsL(aEnv, EPbkFieldIdShareView, aOriginator, aContactId)) |
|
103 { |
|
104 shareViewAddrMatches=ETrue; |
|
105 } |
|
106 |
|
107 if(aOriginator.Find(KMusPrefixSipUri) != KErrNotFound) |
|
108 { |
|
109 //pb field without sip:-prefix are checked. |
|
110 HBufC * withoutPrefix; |
|
111 withoutPrefix = HBufC::NewLC(aOriginator.Length()); |
|
112 *withoutPrefix = aOriginator; |
|
113 TPtr ptr = withoutPrefix->Des(); |
|
114 ptr.Delete(0,KMusPrefixMaxLength); |
|
115 |
|
116 if(MatchTextWithPbFieldsL(aEnv, EPbkFieldIdSIPID, *withoutPrefix, aContactId)) |
|
117 { |
|
118 sipAddrMatches=ETrue; |
|
119 } |
|
120 if(MatchTextWithPbFieldsL(aEnv, EPbkFieldIdShareView, *withoutPrefix, aContactId)) |
|
121 { |
|
122 shareViewAddrMatches=ETrue; |
|
123 } |
|
124 |
|
125 CleanupStack::PopAndDestroy(withoutPrefix); |
|
126 } |
|
127 |
|
128 if(sipAddrMatches||shareViewAddrMatches) |
|
129 { |
|
130 ret=ETrue; |
|
131 } |
|
132 else |
|
133 { |
|
134 ret=EFalse; |
|
135 } |
|
136 |
|
137 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::CheckPbContactForVSAddressesL" ); |
|
138 return ret; |
|
139 } |
|
140 // ----------------------------------------------------------------------------- |
|
141 // @function MatchTextWithPbFieldsL |
|
142 // searches all contactId´s fieldIds of same type for a text |
|
143 // returns ETrue if text is found from at least one of them. |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TBool MusUiContactUtil::MatchTextWithPbFieldsL( CCoeEnv& aEnv, |
|
147 TPbkFieldId aFieldId, |
|
148 const TDesC& aText, |
|
149 TInt aContactId ) |
|
150 { |
|
151 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::MatchTextWithPbFieldsL" ); |
|
152 |
|
153 TBool textMatch(EFalse); |
|
154 |
|
155 RPbkViewResourceFile pbkResourceFile(aEnv); |
|
156 CleanupClosePushL( pbkResourceFile ); |
|
157 pbkResourceFile.OpenL(); |
|
158 CPbkContactEngine* pbkContactEngine = CPbkContactEngine::NewL(); |
|
159 CleanupStack::PushL( pbkContactEngine ); |
|
160 CPbkContactItem* contactItem = NULL; |
|
161 CleanupStack::PushL( contactItem ); |
|
162 |
|
163 if ( aContactId > 0 ) |
|
164 { |
|
165 contactItem = pbkContactEngine->OpenContactL( aContactId ); |
|
166 |
|
167 TInt index(0); |
|
168 |
|
169 while(index!=KErrNotFound) |
|
170 { |
|
171 TPbkContactItemField* contactItemField = |
|
172 contactItem->FindField( aFieldId, index ); |
|
173 |
|
174 if( contactItemField ) |
|
175 { |
|
176 if( contactItemField->Text() == aText && !textMatch ) |
|
177 { |
|
178 textMatch=ETrue; |
|
179 } |
|
180 } |
|
181 |
|
182 if( index != KErrNotFound ) |
|
183 { |
|
184 index++; |
|
185 } |
|
186 } |
|
187 |
|
188 } |
|
189 |
|
190 CleanupStack::PopAndDestroy( 3 ); // contactItem, pbkContactEngine, &pbkResourceFile |
|
191 |
|
192 MUS_LOG( "mus: [MUSUI ] <- MusUiContactUtil::MatchTextWithPbFieldsL" ); |
|
193 return textMatch; |
|
194 |
|
195 } |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void MusUiContactUtil::ActivateContactViewL( CCoeEnv& aEnv, |
|
201 TContactItemId aId, |
|
202 const TDesC& aTypedAddress, |
|
203 const TDesC& aMusTelNumberValue ) |
|
204 { |
|
205 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::ActivateContactViewL" ); |
|
206 RPbkViewResourceFile pbkResourceFile( aEnv ); |
|
207 CleanupClosePushL( pbkResourceFile ); |
|
208 pbkResourceFile.OpenL(); |
|
209 CPbkContactEngine* pbkContactEngine = CPbkContactEngine::NewL(); |
|
210 CleanupStack::PushL( pbkContactEngine ); |
|
211 |
|
212 CPbkContactItem* contactItem = NULL; |
|
213 CleanupStack::PushL( contactItem ); |
|
214 |
|
215 if ( aId > 0 ) |
|
216 { |
|
217 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::ActivateContactViewL\ |
|
218 TContactItemId > 0 => Opening Existing Contact..." ); |
|
219 contactItem = pbkContactEngine->OpenContactL( aId ); |
|
220 EditContactL( *contactItem, |
|
221 EFalse, |
|
222 pbkContactEngine, |
|
223 aTypedAddress, |
|
224 aMusTelNumberValue, |
|
225 aId ); |
|
226 } |
|
227 else |
|
228 { |
|
229 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::ActivateContactViewL\ |
|
230 TContactItemId < 1 => Creating new Contact..." ); |
|
231 contactItem = pbkContactEngine->CreateEmptyContactL(); |
|
232 EditContactL( *contactItem, |
|
233 ETrue, |
|
234 pbkContactEngine, |
|
235 aTypedAddress, |
|
236 aMusTelNumberValue, |
|
237 aId ); |
|
238 } |
|
239 |
|
240 CleanupStack::PopAndDestroy( 3 ); // contactItem, pbkContactEngine, &pbkResourceFile |
|
241 MUS_LOG( "mus: [MUSUI ] <- MusUiContactUtil::ActivateContactViewL" ); |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void MusUiContactUtil::EditContactL( CPbkContactItem& aContact, |
|
250 TBool aNewOne, |
|
251 CPbkContactEngine* aPbkContactEngine, |
|
252 const TDesC& aTypedAddress, |
|
253 const TDesC& aMusTelNumberValue, |
|
254 TContactItemId aContactId ) |
|
255 { |
|
256 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::EditContactL" ); |
|
257 |
|
258 TMusEngUriParser parser( aTypedAddress ); |
|
259 parser.ParseUriL(); |
|
260 HBufC* uri = NULL; |
|
261 CleanupStack::PushL( uri ); |
|
262 |
|
263 CContactTextField* addressField = NULL; |
|
264 CleanupStack::PushL( addressField ); |
|
265 |
|
266 if ( parser.UriType() == TMusEngUriParser::ESip ) |
|
267 { |
|
268 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL\ |
|
269 parser.UriType() == TMusEngUriParser::ESip" ); |
|
270 addressField = EditableContactFieldL( |
|
271 aContact, |
|
272 EPbkFieldIdShareView, |
|
273 aPbkContactEngine ); |
|
274 uri = parser.GetUri16L( ETrue ); |
|
275 } |
|
276 else if ( parser.UriType() == TMusEngUriParser::ETel ) |
|
277 { |
|
278 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL\ |
|
279 parser.UriType() == TMusEngUriParser::ETel" ); |
|
280 addressField = EditableContactFieldL( |
|
281 aContact, |
|
282 EPbkFieldIdPhoneNumberMobile, |
|
283 aPbkContactEngine ); |
|
284 uri = parser.GetUri16L( EFalse ); |
|
285 } |
|
286 |
|
287 if ( addressField ) |
|
288 { |
|
289 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL\ |
|
290 addressField OK" ); |
|
291 addressField->SetTextL( *uri ); |
|
292 } |
|
293 |
|
294 if ( ( aMusTelNumberValue.Length() > 0 ) && aContactId == KErrNotFound ) |
|
295 { |
|
296 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL\ |
|
297 !iPhoneNumberFieldFound" ); |
|
298 CContactTextField* phoneNumberField = EditableContactFieldL( |
|
299 aContact, |
|
300 EPbkFieldIdPhoneNumberMobile, |
|
301 aPbkContactEngine ); |
|
302 if ( phoneNumberField ) |
|
303 { |
|
304 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL\ |
|
305 phoneNumberField OK" ); |
|
306 phoneNumberField->SetTextL( aMusTelNumberValue ); |
|
307 } |
|
308 } |
|
309 |
|
310 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditContactL: Creating dialog..." ); |
|
311 |
|
312 // Bring MuSh UI foreground |
|
313 RWsSession wsSession; |
|
314 User::LeaveIfError( wsSession.Connect() ); |
|
315 CleanupClosePushL( wsSession ); |
|
316 TApaTaskList taskList( wsSession ); |
|
317 TUid appUid; |
|
318 appUid.iUid = KMusUiUid; |
|
319 TApaTask task = taskList.FindApp( appUid ); |
|
320 task.BringToForeground(); |
|
321 CleanupStack::PopAndDestroy( &wsSession ); |
|
322 |
|
323 // Launch pbk new entry editor dlg |
|
324 CPbkContactEditorDlg* editorDlg = CPbkContactEditorDlg::NewL( |
|
325 *aPbkContactEngine, |
|
326 aContact, |
|
327 aNewOne, |
|
328 -1, // Move focus to the topmost field |
|
329 ETrue ); |
|
330 editorDlg->ResetWhenDestroyed( &editorDlg ); |
|
331 editorDlg->HideExitCommand(); |
|
332 editorDlg->ExecuteLD(); |
|
333 |
|
334 CleanupStack::Pop( 2 ); // uri, addressField |
|
335 |
|
336 MUS_LOG( "mus: [MUSUI ] <- MusUiContactUtil::EditContactL" ); |
|
337 } |
|
338 |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // Get editable contact field. |
|
342 // ----------------------------------------------------------------------------- |
|
343 // |
|
344 CContactTextField* MusUiContactUtil::EditableContactFieldL( |
|
345 CPbkContactItem& aContact, |
|
346 TInt aFieldId, |
|
347 CPbkContactEngine* aPbkContactEngine ) |
|
348 { |
|
349 MUS_LOG( "mus: [MUSUI ] -> MusUiContactUtil::EditableContactFieldL" ); |
|
350 |
|
351 // Get fields info from pbk engine |
|
352 const CPbkFieldsInfo& fieldsInfo = aPbkContactEngine->FieldsInfo(); |
|
353 |
|
354 // Try to get the SIP URI storage field for this contact |
|
355 TPbkContactItemField* itemField = aContact.FindField( aFieldId ); |
|
356 |
|
357 if ( !itemField ) |
|
358 { |
|
359 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditableContactFieldL: !itemField" ); |
|
360 CPbkFieldInfo* fieldInfo = fieldsInfo.Find( aFieldId ); |
|
361 // Add field to this contact |
|
362 if ( fieldInfo ) |
|
363 { |
|
364 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditableContactFieldL\ |
|
365 fieldInfo OK" ); |
|
366 // Contact takes ownership of the field. |
|
367 aContact.AddFieldL( *fieldInfo ); |
|
368 itemField = aContact.FindField( aFieldId ); |
|
369 return ( itemField ) ? itemField->TextStorage() : NULL; |
|
370 } |
|
371 else |
|
372 { |
|
373 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditableContactFieldL\ |
|
374 fieldInfo == NULL" ); |
|
375 return NULL; |
|
376 } |
|
377 } |
|
378 else |
|
379 { |
|
380 // Does not pass ownership. |
|
381 MUS_LOG( "mus: [MUSUI ] MusUiContactUtil::EditableContactFieldL\ |
|
382 itemField OK" ); |
|
383 return itemField->TextStorage(); |
|
384 } |
|
385 } |
|
386 |
|
387 |
|
388 // end of file |