20
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Phonebook 2 contact address tools.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "Pbk2AddressTools.h"
|
|
19 |
|
|
20 |
// Phonebook 2
|
|
21 |
#include <Pbk2UIControls.rsg>
|
|
22 |
#include "Pbk2UIFieldProperty.hrh"
|
|
23 |
|
|
24 |
// Virtual Phonebook
|
|
25 |
#include <MVPbkBaseContactField.h>
|
|
26 |
#include <MVPbkStoreContact.h>
|
|
27 |
#include <MVPbkFieldType.h>
|
|
28 |
#include <TVPbkFieldVersitProperty.h>
|
|
29 |
#include <MVPbkStoreContactFieldCollection.h>
|
|
30 |
#include <TVPbkFieldTypeParameters.h>
|
|
31 |
#include <MVPbkContactFieldData.h>
|
|
32 |
#include <MVPbkContactFieldTextData.h>
|
|
33 |
|
|
34 |
//System
|
|
35 |
#include <badesca.h>
|
|
36 |
#include <StringLoader.h>
|
|
37 |
|
|
38 |
// --------------------------------------------------------------------------
|
|
39 |
// Pbk2AddressTools::MapCtrlTypeToAddress
|
|
40 |
// --------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
EXPORT_C TPbk2FieldGroupId Pbk2AddressTools::MapCtrlTypeToAddress(TInt aCtrlType)
|
|
43 |
{
|
|
44 |
TPbk2FieldGroupId ret = EPbk2FieldGroupIdNone;
|
|
45 |
|
|
46 |
switch( aCtrlType )
|
|
47 |
{
|
|
48 |
case EPbk2FieldCtrlTypeExtAddressEditor:
|
|
49 |
ret = EPbk2FieldGroupIdPostalAddress;
|
|
50 |
break;
|
|
51 |
case EPbk2FieldCtrlTypeExtAddressHomeEditor:
|
|
52 |
ret = EPbk2FieldGroupIdHomeAddress;
|
|
53 |
break;
|
|
54 |
case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
|
|
55 |
ret = EPbk2FieldGroupIdCompanyAddress;
|
|
56 |
break;
|
|
57 |
}
|
|
58 |
|
|
59 |
return ret;
|
|
60 |
}
|
|
61 |
|
|
62 |
// --------------------------------------------------------------------------
|
|
63 |
// Pbk2AddressTools::MapCtrlTypeToAddress
|
|
64 |
// --------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
EXPORT_C TPbk2FieldGroupId Pbk2AddressTools::MapViewTypeToAddress(TPbk2ContactEditorParams::TActiveView aViewType)
|
|
67 |
{
|
|
68 |
TPbk2FieldGroupId ret = EPbk2FieldGroupIdNone;
|
|
69 |
|
|
70 |
switch( aViewType )
|
|
71 |
{
|
|
72 |
case TPbk2ContactEditorParams::EEditorAddressView:
|
|
73 |
ret = EPbk2FieldGroupIdPostalAddress;
|
|
74 |
break;
|
|
75 |
case TPbk2ContactEditorParams::EEditorAddressHomeView:
|
|
76 |
ret = EPbk2FieldGroupIdHomeAddress;
|
|
77 |
break;
|
|
78 |
case TPbk2ContactEditorParams::EEditorAddressOfficeView:
|
|
79 |
ret = EPbk2FieldGroupIdCompanyAddress;
|
|
80 |
break;
|
|
81 |
}
|
|
82 |
|
|
83 |
return ret;
|
|
84 |
}
|
|
85 |
|
|
86 |
// --------------------------------------------------------------------------
|
|
87 |
// Pbk2AddressTools::MapCtrlTypeToAddress
|
|
88 |
// --------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
EXPORT_C TInt Pbk2AddressTools::MapAddressToOrdering(TPbk2FieldGroupId aGroupAddress)
|
|
91 |
{
|
|
92 |
TPbk2FieldOrder ret = EPbk2FieldOrderUndefinied;
|
|
93 |
|
|
94 |
switch( aGroupAddress )
|
|
95 |
{
|
|
96 |
case EPbk2FieldGroupIdPostalAddress:
|
|
97 |
ret = EPbk2FieldOrderAddress;
|
|
98 |
break;
|
|
99 |
case EPbk2FieldGroupIdHomeAddress:
|
|
100 |
ret = EPbk2FieldOrderAddressHome;
|
|
101 |
break;
|
|
102 |
case EPbk2FieldGroupIdCompanyAddress:
|
|
103 |
ret = EPbk2FieldOrderAddressOffice;
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
|
|
107 |
return ret;
|
|
108 |
}
|
|
109 |
|
|
110 |
// --------------------------------------------------------------------------
|
|
111 |
// Pbk2AddressTools::MapCtrlTypeToViewType
|
|
112 |
// --------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
EXPORT_C TPbk2ContactEditorParams::TActiveView Pbk2AddressTools::MapCtrlTypeToViewType(TInt aCtrlType)
|
|
115 |
{
|
|
116 |
TPbk2ContactEditorParams::TActiveView ret = TPbk2ContactEditorParams::EEditorUndefinied;
|
|
117 |
|
|
118 |
switch( aCtrlType )
|
|
119 |
{
|
|
120 |
case EPbk2FieldCtrlTypeExtAddressEditor:
|
|
121 |
ret = TPbk2ContactEditorParams::EEditorAddressView;
|
|
122 |
break;
|
|
123 |
case EPbk2FieldCtrlTypeExtAddressHomeEditor:
|
|
124 |
ret = TPbk2ContactEditorParams::EEditorAddressHomeView;
|
|
125 |
break;
|
|
126 |
case EPbk2FieldCtrlTypeExtAddressOfficeEditor:
|
|
127 |
ret = TPbk2ContactEditorParams::EEditorAddressOfficeView;
|
|
128 |
break;
|
|
129 |
}
|
|
130 |
|
|
131 |
return ret;
|
|
132 |
}
|
|
133 |
|
|
134 |
// --------------------------------------------------------------------------
|
|
135 |
// Pbk2AddressTools::MapAddressToVersitParam
|
|
136 |
// --------------------------------------------------------------------------
|
|
137 |
//
|
|
138 |
EXPORT_C TVPbkFieldTypeParameter Pbk2AddressTools::MapAddressToVersitParam( TPbk2FieldGroupId aGroupId )
|
|
139 |
{
|
|
140 |
TVPbkFieldTypeParameter addressParameter = EVPbkVersitParamPREF;
|
|
141 |
switch(aGroupId)
|
|
142 |
{
|
|
143 |
case EPbk2FieldGroupIdPostalAddress:
|
|
144 |
addressParameter = EVPbkVersitParamPREF;
|
|
145 |
break;
|
|
146 |
case EPbk2FieldGroupIdHomeAddress:
|
|
147 |
addressParameter = EVPbkVersitParamHOME;
|
|
148 |
break;
|
|
149 |
case EPbk2FieldGroupIdCompanyAddress:
|
|
150 |
addressParameter = EVPbkVersitParamWORK;
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
return addressParameter;
|
|
154 |
}
|
|
155 |
|
|
156 |
// --------------------------------------------------------------------------
|
|
157 |
// CPbk2ContactEditorFieldArray::GetAddressPreviewLC
|
|
158 |
// --------------------------------------------------------------------------
|
|
159 |
//
|
|
160 |
EXPORT_C void Pbk2AddressTools::GetAddressPreviewLC(
|
|
161 |
MVPbkStoreContact& aContact,
|
|
162 |
TPbk2FieldGroupId aAddressGroup,
|
|
163 |
RBuf& aText )
|
|
164 |
{
|
|
165 |
if( aAddressGroup != EPbk2FieldGroupIdPostalAddress &&
|
|
166 |
aAddressGroup != EPbk2FieldGroupIdCompanyAddress &&
|
|
167 |
aAddressGroup != EPbk2FieldGroupIdHomeAddress )
|
|
168 |
{
|
|
169 |
User::Leave(KErrArgument);
|
|
170 |
}
|
|
171 |
|
|
172 |
const TInt KGranularity = 4;
|
|
173 |
CDesCArrayFlat* arrFields = new ( ELeave ) CDesCArrayFlat
|
|
174 |
( KGranularity );
|
|
175 |
CleanupStack::PushL(arrFields);
|
|
176 |
|
|
177 |
RHashMap<TInt, TPtrC> aFieldsMap;
|
|
178 |
GetAddressFieldsLC( aContact, aAddressGroup, aFieldsMap );
|
|
179 |
|
|
180 |
TBool appended = EFalse;
|
|
181 |
TPtrC* data = NULL;
|
|
182 |
data = aFieldsMap.Find( EVPbkVersitSubFieldStreet );
|
|
183 |
if( data )
|
|
184 |
{
|
|
185 |
arrFields->AppendL( *data );
|
|
186 |
appended = ETrue;
|
|
187 |
}
|
|
188 |
else
|
|
189 |
{
|
|
190 |
arrFields->AppendL( KNullDesC() );
|
|
191 |
}
|
|
192 |
|
|
193 |
data = aFieldsMap.Find( EVPbkVersitSubFieldLocality );
|
|
194 |
if( data )
|
|
195 |
{
|
|
196 |
arrFields->AppendL( *data );
|
|
197 |
appended = ETrue;
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
arrFields->AppendL( KNullDesC() );
|
|
202 |
}
|
|
203 |
|
|
204 |
data = aFieldsMap.Find( EVPbkVersitSubFieldRegion );
|
|
205 |
if( data )
|
|
206 |
{
|
|
207 |
arrFields->AppendL( *data );
|
|
208 |
appended = ETrue;
|
|
209 |
}
|
|
210 |
else
|
|
211 |
{
|
|
212 |
arrFields->AppendL( KNullDesC() );
|
|
213 |
}
|
|
214 |
|
|
215 |
data = aFieldsMap.Find( EVPbkVersitSubFieldCountry );
|
|
216 |
if( data )
|
|
217 |
{
|
|
218 |
arrFields->AppendL( *data );
|
|
219 |
appended = ETrue;
|
|
220 |
}
|
|
221 |
else
|
|
222 |
{
|
|
223 |
arrFields->AppendL( KNullDesC() );
|
|
224 |
}
|
|
225 |
|
|
226 |
_LIT(KComma, ",");
|
|
227 |
_LIT(KSpace, " ");
|
|
228 |
|
|
229 |
HBufC* addressPreview = NULL;
|
|
230 |
|
|
231 |
if( !appended )
|
|
232 |
{
|
|
233 |
if( aFieldsMap.Count() )
|
|
234 |
{
|
|
235 |
addressPreview = StringLoader::LoadLC( R_QTN_PHOB_POPUP_INCOMPLETE_ADDRESS );
|
|
236 |
}
|
|
237 |
else
|
|
238 |
{
|
|
239 |
addressPreview = StringLoader::LoadLC( R_QTN_PHOB_CONTACT_EDITOR_DEFINE );
|
|
240 |
}
|
|
241 |
}
|
|
242 |
else
|
|
243 |
{
|
|
244 |
addressPreview = StringLoader::LoadLC( R_QTN_PHOB_ADDRESS_PREVIEW, *arrFields );
|
|
245 |
TPtr16 addressPreviewTPtr = addressPreview->Des();
|
|
246 |
|
|
247 |
TBool prevField = EFalse;
|
|
248 |
TInt idx = 0;
|
|
249 |
while( idx < addressPreviewTPtr.Length() )
|
|
250 |
{
|
|
251 |
if( addressPreviewTPtr[idx] == KComma()[0] )
|
|
252 |
{
|
|
253 |
if( !prevField )
|
|
254 |
{
|
|
255 |
addressPreviewTPtr.Delete( idx, 1 );
|
|
256 |
if( idx < addressPreviewTPtr.Length() && addressPreviewTPtr[idx] == KSpace()[0] )
|
|
257 |
{
|
|
258 |
addressPreviewTPtr.Delete( idx, 1 );
|
|
259 |
}
|
|
260 |
continue;
|
|
261 |
}
|
|
262 |
else
|
|
263 |
{
|
|
264 |
prevField = EFalse;
|
|
265 |
}
|
|
266 |
}
|
|
267 |
else if( !(addressPreviewTPtr[idx] == KSpace()[0] && !prevField) )
|
|
268 |
{
|
|
269 |
prevField = ETrue;
|
|
270 |
}
|
|
271 |
idx++;
|
|
272 |
}
|
|
273 |
|
|
274 |
TInt lenght = addressPreviewTPtr.Length();
|
|
275 |
if( lenght > 2 && addressPreviewTPtr[lenght - 2] == KComma()[0] )
|
|
276 |
{
|
|
277 |
addressPreviewTPtr.Delete( lenght - 2, 2 );
|
|
278 |
}
|
|
279 |
}
|
|
280 |
CleanupStack::Pop( addressPreview );
|
|
281 |
CleanupStack::PopAndDestroy( &aFieldsMap );
|
|
282 |
CleanupStack::PopAndDestroy( arrFields );
|
|
283 |
|
|
284 |
aText.Assign( addressPreview );
|
|
285 |
CleanupClosePushL( aText );
|
|
286 |
}
|
|
287 |
|
|
288 |
// --------------------------------------------------------------------------
|
|
289 |
// CPbk2ContactEditorFieldArray::GetAddressShortPreviewLC
|
|
290 |
// --------------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
EXPORT_C void Pbk2AddressTools::GetAddressShortPreviewLC(
|
|
293 |
MVPbkStoreContact& aContact,
|
|
294 |
TPbk2FieldGroupId aAddressGroup,
|
|
295 |
RBuf& aText )
|
|
296 |
{
|
|
297 |
if( aAddressGroup != EPbk2FieldGroupIdPostalAddress &&
|
|
298 |
aAddressGroup != EPbk2FieldGroupIdCompanyAddress &&
|
|
299 |
aAddressGroup != EPbk2FieldGroupIdHomeAddress )
|
|
300 |
{
|
|
301 |
User::Leave(KErrArgument);
|
|
302 |
}
|
|
303 |
|
|
304 |
const TInt KGranularity = 4;
|
|
305 |
CDesCArrayFlat* arrFields = new ( ELeave ) CDesCArrayFlat
|
|
306 |
( KGranularity );
|
|
307 |
CleanupStack::PushL(arrFields);
|
|
308 |
|
|
309 |
RHashMap<TInt, TPtrC> aFieldsMap;
|
|
310 |
GetAddressFieldsLC( aContact, aAddressGroup, aFieldsMap );
|
|
311 |
|
|
312 |
TPtrC* data = aFieldsMap.Find( EVPbkVersitSubFieldStreet );
|
|
313 |
if( data )
|
|
314 |
{
|
|
315 |
arrFields->AppendL( *data );
|
|
316 |
}
|
|
317 |
|
|
318 |
data = aFieldsMap.Find( EVPbkVersitSubFieldLocality );
|
|
319 |
if( data )
|
|
320 |
{
|
|
321 |
arrFields->AppendL( *data );
|
|
322 |
}
|
|
323 |
|
|
324 |
HBufC* addressPreview = NULL;
|
|
325 |
|
|
326 |
if( arrFields->Count() != 2 )
|
|
327 |
{
|
|
328 |
addressPreview = StringLoader::LoadLC( R_QTN_PHOB_POPUP_INCOMPLETE_ADDRESS );
|
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
addressPreview = StringLoader::LoadLC( R_QTN_PHOB_COMMLAUNCHER_ONELINEPREVIEW, *arrFields );
|
|
333 |
}
|
|
334 |
|
|
335 |
CleanupStack::Pop( addressPreview );
|
|
336 |
CleanupStack::PopAndDestroy( &aFieldsMap );
|
|
337 |
CleanupStack::PopAndDestroy( arrFields );
|
|
338 |
|
|
339 |
aText.Assign( addressPreview );
|
|
340 |
CleanupClosePushL( aText );
|
|
341 |
}
|
|
342 |
|
|
343 |
// --------------------------------------------------------------------------
|
|
344 |
// CPbk2ContactEditorFieldArray::GetAddressFieldsLC
|
|
345 |
// --------------------------------------------------------------------------
|
|
346 |
//
|
|
347 |
EXPORT_C void Pbk2AddressTools::GetAddressFieldsLC(
|
|
348 |
MVPbkStoreContact& aContact,
|
|
349 |
TPbk2FieldGroupId aAddressGroup,
|
|
350 |
RHashMap<TInt, TPtrC>& aFieldsMap )
|
|
351 |
{
|
|
352 |
if( aAddressGroup != EPbk2FieldGroupIdPostalAddress &&
|
|
353 |
aAddressGroup != EPbk2FieldGroupIdCompanyAddress &&
|
|
354 |
aAddressGroup != EPbk2FieldGroupIdHomeAddress )
|
|
355 |
{
|
|
356 |
User::Leave(KErrArgument);
|
|
357 |
}
|
|
358 |
|
|
359 |
CleanupClosePushL( aFieldsMap );
|
|
360 |
|
|
361 |
MVPbkStoreContactFieldCollection& arrContactFields = aContact.Fields();
|
|
362 |
TInt countAll = arrContactFields.FieldCount();
|
|
363 |
for(TInt idx = 0; idx < countAll; idx++)
|
|
364 |
{
|
|
365 |
MVPbkStoreContactField& field = arrContactFields.FieldAt( idx );
|
|
366 |
if ( field.FieldData().IsEmpty() )
|
|
367 |
{
|
|
368 |
continue;
|
|
369 |
}
|
|
370 |
const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
|
|
371 |
if ( fieldType )
|
|
372 |
{
|
|
373 |
TArray<TVPbkFieldVersitProperty> arrProp =
|
|
374 |
fieldType->VersitProperties();
|
|
375 |
for (TInt idx2 = 0; idx2 < arrProp.Count(); idx2++ )
|
|
376 |
{
|
|
377 |
if ( arrProp[idx2].Name() != EVPbkVersitNameADR )
|
|
378 |
{
|
|
379 |
continue;
|
|
380 |
}
|
|
381 |
|
|
382 |
if ( !arrProp[idx2].Parameters().Contains(
|
|
383 |
MapAddressToVersitParam( aAddressGroup ) )
|
|
384 |
&& aAddressGroup != EPbk2FieldGroupIdPostalAddress )
|
|
385 |
{
|
|
386 |
continue;
|
|
387 |
}
|
|
388 |
|
|
389 |
if ( (arrProp[idx2].Parameters().Contains(
|
|
390 |
MapAddressToVersitParam( EPbk2FieldGroupIdCompanyAddress ) )
|
|
391 |
|| arrProp[idx2].Parameters().Contains(
|
|
392 |
MapAddressToVersitParam( EPbk2FieldGroupIdHomeAddress ) ))
|
|
393 |
&& aAddressGroup == EPbk2FieldGroupIdPostalAddress )
|
|
394 |
{
|
|
395 |
continue;
|
|
396 |
}
|
|
397 |
|
|
398 |
MVPbkContactFieldData& fieldData = field.FieldData();
|
|
399 |
if ( fieldData.DataType() != EVPbkFieldStorageTypeText )
|
|
400 |
{
|
|
401 |
continue;
|
|
402 |
}
|
|
403 |
|
|
404 |
MVPbkContactFieldTextData& data =
|
|
405 |
MVPbkContactFieldTextData::Cast( fieldData );
|
|
406 |
if ( data.Text().Length() )
|
|
407 |
{
|
|
408 |
aFieldsMap.InsertL( arrProp[idx2].SubField(), data.Text() );
|
|
409 |
}
|
|
410 |
}
|
|
411 |
}
|
|
412 |
}
|
|
413 |
}
|
|
414 |
|
|
415 |
// --------------------------------------------------------------------------
|
|
416 |
// Pbk2AddressTools::MapVPbkFieldTypeToAddressGroupId
|
|
417 |
// --------------------------------------------------------------------------
|
|
418 |
//
|
|
419 |
EXPORT_C TPbk2FieldGroupId Pbk2AddressTools::MapVPbkFieldTypeToAddressGroupId(
|
|
420 |
const MVPbkFieldType* aVPbkFieldType )
|
|
421 |
{
|
|
422 |
TPbk2FieldGroupId groupId = EPbk2FieldGroupIdNone;
|
|
423 |
TArray<TVPbkFieldVersitProperty> versitArr = aVPbkFieldType->VersitProperties();
|
|
424 |
if (versitArr.Count())
|
|
425 |
{
|
|
426 |
const TVPbkFieldVersitProperty& prop = versitArr[0];
|
|
427 |
|
|
428 |
if (prop.Name() == EVPbkVersitNameADR)
|
|
429 |
{
|
|
430 |
if (versitArr[0].Parameters().Contains(EVPbkVersitParamHOME))
|
|
431 |
{
|
|
432 |
groupId = EPbk2FieldGroupIdHomeAddress;
|
|
433 |
}
|
|
434 |
else if (versitArr[0].Parameters().Contains(EVPbkVersitParamWORK))
|
|
435 |
{
|
|
436 |
groupId = EPbk2FieldGroupIdCompanyAddress;
|
|
437 |
}
|
|
438 |
else
|
|
439 |
{
|
|
440 |
groupId = EPbk2FieldGroupIdPostalAddress;
|
|
441 |
}
|
|
442 |
}
|
|
443 |
}
|
|
444 |
return groupId;
|
|
445 |
}
|
|
446 |
|
|
447 |
// --------------------------------------------------------------------------
|
|
448 |
// Pbk2AddressTools::IsAddressPreviewEmptyL
|
|
449 |
// --------------------------------------------------------------------------
|
|
450 |
//
|
|
451 |
EXPORT_C TBool Pbk2AddressTools::IsAddressPreviewEmptyL(
|
|
452 |
MVPbkStoreContact& aContact,
|
|
453 |
TPbk2FieldGroupId aAddressGroup )
|
|
454 |
{
|
|
455 |
if( aAddressGroup != EPbk2FieldGroupIdPostalAddress &&
|
|
456 |
aAddressGroup != EPbk2FieldGroupIdCompanyAddress &&
|
|
457 |
aAddressGroup != EPbk2FieldGroupIdHomeAddress )
|
|
458 |
{
|
|
459 |
User::Leave(KErrArgument);
|
|
460 |
}
|
|
461 |
TBool isEmpty = ETrue;
|
|
462 |
RHashMap<TInt, TPtrC> fieldsMap;
|
|
463 |
GetAddressFieldsLC( aContact, aAddressGroup, fieldsMap );
|
|
464 |
if( fieldsMap.Find( EVPbkVersitSubFieldStreet ) )
|
|
465 |
{
|
|
466 |
isEmpty = EFalse;
|
|
467 |
}
|
|
468 |
else if( fieldsMap.Find( EVPbkVersitSubFieldLocality ) )
|
|
469 |
{
|
|
470 |
isEmpty = EFalse;
|
|
471 |
}
|
|
472 |
else if( fieldsMap.Find( EVPbkVersitSubFieldRegion ) )
|
|
473 |
{
|
|
474 |
isEmpty = EFalse;
|
|
475 |
}
|
|
476 |
else if( fieldsMap.Find( EVPbkVersitSubFieldCountry ) )
|
|
477 |
{
|
|
478 |
isEmpty = EFalse;
|
|
479 |
}
|
|
480 |
CleanupStack::PopAndDestroy( &fieldsMap );
|
|
481 |
return isEmpty;
|
|
482 |
}
|
|
483 |
|