author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 21 | 9da50d567e3c |
parent 20 | f4a778e096c2 |
permissions | -rw-r--r-- |
20 | 1 |
/* |
2 |
* Copyright (c) 2009 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 merge conflict. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// Phonebook2 includes |
|
19 |
#include <Pbk2AddressTools.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
20 |
#include <pbk2uicontrols.rsg> |
20 | 21 |
#include <CPbk2PresentationContact.h> |
22 |
#include <CPbk2PresentationContactFieldCollection.h> |
|
23 |
#include <CPbk2PresentationContactField.h> |
|
24 |
#include <MPbk2FieldProperty.h> |
|
25 |
||
26 |
//Virtual Phonebook |
|
27 |
#include <MVPbkContactFieldTextData.h> |
|
28 |
#include <MVPbkContactFieldDateTimeData.h> |
|
29 |
#include <MVPbkContactFieldUriData.h> |
|
30 |
#include <MVPbkContactFieldBinaryData.h> |
|
31 |
#include <MVPbkFieldType.h> |
|
32 |
#include <TVPbkFieldVersitProperty.h> |
|
33 |
||
34 |
// System includes |
|
35 |
#include <StringLoader.h> |
|
36 |
#include <avkon.rsg> |
|
37 |
||
38 |
#include "CPbk2MergeConflict.h" |
|
39 |
||
40 |
// Debugging headers |
|
41 |
#include <Pbk2Debug.h> |
|
42 |
#include <Pbk2Profile.h> |
|
43 |
||
44 |
/// Unnamed namespace for local definitions |
|
45 |
namespace |
|
46 |
{ |
|
47 |
const TInt KMaxDateLenght = 64; |
|
48 |
enum TPbk2PanicCodes |
|
49 |
{ |
|
50 |
EPbk2NotInitialized, |
|
51 |
EPbk2NotChosen, |
|
52 |
EPbk2UnexpectedCase, |
|
53 |
EPbk2FieldTypeNotExists |
|
54 |
}; |
|
55 |
||
56 |
void Panic(TPbk2PanicCodes aReason) |
|
57 |
{ |
|
58 |
_LIT( KPanicText, "CPbk2_Merge_Conflict" ); |
|
59 |
User::Panic( KPanicText, aReason ); |
|
60 |
} |
|
61 |
} /// namespace |
|
62 |
||
63 |
// -------------------------------------------------------------------------- |
|
64 |
// CPbk2MergeConflict::GetConflictType |
|
65 |
// -------------------------------------------------------------------------- |
|
66 |
// |
|
67 |
EPbk2ConflictType CPbk2MergeConflict::GetConflictType() |
|
68 |
{ |
|
69 |
return iConflictType; |
|
70 |
} |
|
71 |
||
72 |
// -------------------------------------------------------------------------- |
|
73 |
// CPbk2MergeConflict::CPbk2MergeConflict |
|
74 |
// -------------------------------------------------------------------------- |
|
75 |
// |
|
76 |
CPbk2MergeConflict::CPbk2MergeConflict() |
|
77 |
{ |
|
78 |
iConflictType = EPbk2ConflictTypeNormal; |
|
79 |
} |
|
80 |
||
81 |
// -------------------------------------------------------------------------- |
|
82 |
// CPbk2MergeConflict::~CPbk2MergeConflict |
|
83 |
// -------------------------------------------------------------------------- |
|
84 |
// |
|
85 |
CPbk2MergeConflict::~CPbk2MergeConflict() |
|
86 |
{ |
|
87 |
delete iDisplayFieldFirst; |
|
88 |
delete iDisplayFieldSecond; |
|
89 |
} |
|
90 |
||
91 |
// -------------------------------------------------------------------------- |
|
92 |
// CPbk2MergeConflict::NewL |
|
93 |
// -------------------------------------------------------------------------- |
|
94 |
// |
|
95 |
CPbk2MergeConflict* CPbk2MergeConflict::NewL() |
|
96 |
{ |
|
97 |
CPbk2MergeConflict* self = new ( ELeave ) CPbk2MergeConflict(); |
|
98 |
return self; |
|
99 |
} |
|
100 |
||
101 |
// -------------------------------------------------------------------------- |
|
102 |
// CPbk2MergeConflict::GetFieldsL |
|
103 |
// -------------------------------------------------------------------------- |
|
104 |
// |
|
105 |
void CPbk2MergeConflict::GetFieldsL( |
|
106 |
const MVPbkStoreContactField*& aFieldFirst, |
|
107 |
const MVPbkStoreContactField*& aFieldSecond ) |
|
108 |
{ |
|
109 |
__ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) ); |
|
110 |
||
111 |
aFieldFirst = iFieldFirst; |
|
112 |
aFieldSecond = iFieldSecond; |
|
113 |
} |
|
114 |
||
115 |
// -------------------------------------------------------------------------- |
|
116 |
// CPbk2MergeConflict::AddFields |
|
117 |
// -------------------------------------------------------------------------- |
|
118 |
// |
|
119 |
void CPbk2MergeConflict::AddFields( |
|
120 |
const MVPbkStoreContactField& aFieldFirst, |
|
121 |
const MVPbkStoreContactField& aFieldSecond ) |
|
122 |
{ |
|
123 |
iFieldFirst = &aFieldFirst; |
|
124 |
iFieldSecond = &aFieldSecond; |
|
125 |
||
126 |
const MVPbkFieldType* fieldType = aFieldFirst.BestMatchingFieldType(); |
|
127 |
if ( fieldType ) |
|
128 |
{ |
|
129 |
if( fieldType->NonVersitType() == EVPbkNonVersitTypeCodImage ) |
|
130 |
{ |
|
131 |
iConflictType = EPbk2ConflictTypeImage; |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
TArray<TVPbkFieldVersitProperty> versitPropArr = fieldType->VersitProperties(); |
|
136 |
TInt count = versitPropArr.Count(); |
|
137 |
||
138 |
for( TInt idx = 0; idx < count; idx++ ) |
|
139 |
{ |
|
140 |
TVPbkFieldVersitProperty versitProp = versitPropArr[idx]; |
|
141 |
if( versitProp.Name() == EVPbkVersitNameLOGO || |
|
142 |
versitProp.Name() == EVPbkVersitNamePHOTO ) |
|
143 |
{ |
|
144 |
iConflictType = EPbk2ConflictTypeImage; |
|
145 |
break; |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
151 |
||
152 |
// -------------------------------------------------------------------------- |
|
153 |
// CPbk2MergeConflict::AddDisplayFields |
|
154 |
// -------------------------------------------------------------------------- |
|
155 |
// |
|
156 |
void CPbk2MergeConflict::AddDisplayFields( |
|
157 |
HBufC* aDisplayFieldFirst, |
|
158 |
HBufC* aDisplayFieldSecond ) |
|
159 |
{ |
|
160 |
iDisplayFieldFirst = aDisplayFieldFirst; |
|
161 |
iDisplayFieldSecond = aDisplayFieldSecond; |
|
162 |
} |
|
163 |
||
164 |
// -------------------------------------------------------------------------- |
|
165 |
// CPbk2MergeConflict::GetLabelLC |
|
166 |
// -------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
HBufC* CPbk2MergeConflict::GetLabelLC() |
|
169 |
{ |
|
170 |
__ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) ); |
|
171 |
||
172 |
return iFieldFirst->FieldLabel().AllocLC(); |
|
173 |
} |
|
174 |
||
175 |
// -------------------------------------------------------------------------- |
|
176 |
// CPbk2MergeConflict::GetTextLC |
|
177 |
// -------------------------------------------------------------------------- |
|
178 |
// |
|
179 |
HBufC* CPbk2MergeConflict::GetTextLC( EPbk2ConflictedNumber aNumber ) |
|
180 |
{ |
|
181 |
__ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) ); |
|
182 |
||
183 |
const MVPbkStoreContactField* field; |
|
184 |
HBufC* retText = NULL; |
|
185 |
||
186 |
if( aNumber == EPbk2ConflictedFirst ) |
|
187 |
{ |
|
188 |
field = iFieldFirst; |
|
189 |
} |
|
190 |
else |
|
191 |
{ |
|
192 |
field = iFieldSecond; |
|
193 |
} |
|
194 |
||
195 |
//Prefer display texts if both available |
|
196 |
if( iDisplayFieldFirst && iDisplayFieldSecond ) |
|
197 |
{ |
|
198 |
retText = aNumber==EPbk2ConflictedFirst ? |
|
199 |
iDisplayFieldFirst->AllocLC() : iDisplayFieldSecond->AllocLC(); |
|
200 |
} |
|
201 |
else |
|
202 |
{ |
|
203 |
retText = GetContentTextLC( aNumber , field); |
|
204 |
} |
|
205 |
return retText; |
|
206 |
} |
|
207 |
||
208 |
// -------------------------------------------------------------------------- |
|
209 |
// CPbk2MergeConflict::GetContentTextLC |
|
210 |
// -------------------------------------------------------------------------- |
|
211 |
// |
|
212 |
HBufC* CPbk2MergeConflict::GetContentTextLC( |
|
213 |
EPbk2ConflictedNumber aNumber, |
|
214 |
const MVPbkStoreContactField* aField ) |
|
215 |
{ |
|
216 |
const MVPbkContactFieldData& data = aField->FieldData(); |
|
217 |
TVPbkFieldStorageType storageType = data.DataType(); |
|
218 |
||
219 |
HBufC* retText = NULL; |
|
220 |
||
221 |
switch( storageType ) |
|
222 |
{ |
|
223 |
case EVPbkFieldStorageTypeText: |
|
224 |
retText = MVPbkContactFieldTextData::Cast( data ).Text().AllocLC(); |
|
225 |
break; |
|
226 |
case EVPbkFieldStorageTypeUri: |
|
227 |
retText = MVPbkContactFieldUriData::Cast( data ).Text().AllocLC(); |
|
228 |
break; |
|
229 |
case EVPbkFieldStorageTypeBinary: |
|
230 |
// Bad method for getting binary data, get it from field |
|
231 |
Panic( EPbk2UnexpectedCase ); |
|
232 |
break; |
|
233 |
case EVPbkFieldStorageTypeDateTime: |
|
234 |
{ |
|
235 |
const MVPbkContactFieldDateTimeData& date = |
|
236 |
MVPbkContactFieldDateTimeData::Cast( data ); |
|
237 |
||
238 |
TTime time( date.DateTime() ); |
|
239 |
TBuf<KMaxDateLenght> dateBuffer; |
|
240 |
HBufC* dateFormat = CCoeEnv::Static()->AllocReadResourceLC |
|
241 |
( R_QTN_DATE_USUAL_WITH_ZERO ); // in avkon.rsg |
|
242 |
||
243 |
time.FormatL( dateBuffer, *dateFormat, TLocale() ); |
|
244 |
CleanupStack::PopAndDestroy( dateFormat ); |
|
245 |
retText = dateBuffer.AllocLC(); |
|
246 |
} |
|
247 |
break; |
|
248 |
default: |
|
249 |
Panic( EPbk2UnexpectedCase ); |
|
250 |
} |
|
251 |
TPtr ptr = retText->Des(); |
|
252 |
CustomizeTextValueL( *aField, ptr ); |
|
253 |
return retText; |
|
254 |
} |
|
255 |
||
256 |
// -------------------------------------------------------------------------- |
|
257 |
// CPbk2MergeConflict::ResolveConflict |
|
258 |
// -------------------------------------------------------------------------- |
|
259 |
// |
|
260 |
void CPbk2MergeConflict::ResolveConflict( EPbk2ConflictedNumber aNumber ) |
|
261 |
{ |
|
262 |
__ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) ); |
|
263 |
||
264 |
if( aNumber == EPbk2ConflictedFirst ) |
|
265 |
{ |
|
266 |
iChosenField = iFieldFirst; |
|
267 |
} |
|
268 |
else |
|
269 |
{ |
|
270 |
iChosenField = iFieldSecond; |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
// -------------------------------------------------------------------------- |
|
275 |
// CPbk2MergeConflict::GetChosenFieldsL |
|
276 |
// -------------------------------------------------------------------------- |
|
277 |
// |
|
278 |
void CPbk2MergeConflict::GetChosenFieldsL( |
|
279 |
RPointerArray<MVPbkStoreContactField>& aAddressFields ) |
|
280 |
{ |
|
281 |
__ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotChosen ) ); |
|
282 |
CleanupClosePushL( aAddressFields ); |
|
283 |
||
284 |
if ( iChosenField ) |
|
285 |
{ |
|
286 |
aAddressFields.AppendL( iChosenField ); |
|
287 |
} |
|
288 |
CleanupStack::Pop(); |
|
289 |
} |
|
290 |
||
291 |
// -------------------------------------------------------------------------- |
|
292 |
// CPbk2MergeConflict::CustomizeTextValueL |
|
293 |
// -------------------------------------------------------------------------- |
|
294 |
// |
|
295 |
void CPbk2MergeConflict::CustomizeTextValueL( const MVPbkStoreContactField& aField, TDes& aBuf ) |
|
296 |
{ |
|
297 |
const MVPbkFieldType* fieldType= aField.BestMatchingFieldType(); |
|
298 |
if ( fieldType ) |
|
299 |
{ |
|
300 |
TVPbkNonVersitFieldType nonVersitType = fieldType->NonVersitType(); |
|
301 |
if ( nonVersitType == EVPbkNonVersitTypeRingTone ) |
|
302 |
{ |
|
303 |
TParsePtr fileName = TParsePtr( aBuf ); |
|
304 |
if ( fileName.NamePresent() ) |
|
305 |
{ |
|
306 |
TPtrC namePtr = fileName.Name(); |
|
307 |
HBufC* name = namePtr.AllocL(); |
|
308 |
aBuf.Copy( *name ); |
|
309 |
delete name; |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
// -------------------------------------------------------------------------- |
|
316 |
// CPbk2MergeConflictAddress::CPbk2MergeConflictAddress |
|
317 |
// -------------------------------------------------------------------------- |
|
318 |
// |
|
319 |
CPbk2MergeConflictAddress::CPbk2MergeConflictAddress() |
|
320 |
{ |
|
321 |
iConflictType = EPbk2ConflictTypeAddress; |
|
322 |
} |
|
323 |
||
324 |
// -------------------------------------------------------------------------- |
|
325 |
// CPbk2MergeConflictAddress::GetConflictType |
|
326 |
// -------------------------------------------------------------------------- |
|
327 |
// |
|
328 |
EPbk2ConflictType CPbk2MergeConflictAddress::GetConflictType() |
|
329 |
{ |
|
330 |
return iConflictType; |
|
331 |
} |
|
332 |
||
333 |
// -------------------------------------------------------------------------- |
|
334 |
// CPbk2MergeConflictAddress::NewL |
|
335 |
// -------------------------------------------------------------------------- |
|
336 |
// |
|
337 |
CPbk2MergeConflictAddress* CPbk2MergeConflictAddress::NewL() |
|
338 |
{ |
|
339 |
CPbk2MergeConflictAddress* self = new ( ELeave ) CPbk2MergeConflictAddress(); |
|
340 |
return self; |
|
341 |
} |
|
342 |
||
343 |
// -------------------------------------------------------------------------- |
|
344 |
// CPbk2MergeConflictAddress::AddAddress |
|
345 |
// -------------------------------------------------------------------------- |
|
346 |
// |
|
347 |
void CPbk2MergeConflictAddress::AddAddress( |
|
348 |
CPbk2PresentationContact& aContactFirst, |
|
349 |
CPbk2PresentationContact& aContactSecond, |
|
350 |
TPbk2FieldGroupId aAddressGroup ) |
|
351 |
{ |
|
352 |
iContactFirst = &aContactFirst; |
|
353 |
iContactSecond = &aContactSecond; |
|
354 |
iAddressGroup = aAddressGroup; |
|
355 |
} |
|
356 |
||
357 |
// -------------------------------------------------------------------------- |
|
358 |
// CPbk2MergeConflictAddress::GetLabelLC |
|
359 |
// -------------------------------------------------------------------------- |
|
360 |
// |
|
361 |
HBufC* CPbk2MergeConflictAddress::GetLabelLC() |
|
362 |
{ |
|
363 |
HBufC* retLebel = NULL; |
|
364 |
switch( iAddressGroup ) |
|
365 |
{ |
|
366 |
case EPbk2FieldGroupIdPostalAddress: |
|
367 |
retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS ); |
|
368 |
break; |
|
369 |
case EPbk2FieldGroupIdHomeAddress: |
|
370 |
retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_HOME ); |
|
371 |
break; |
|
372 |
case EPbk2FieldGroupIdCompanyAddress: |
|
373 |
retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_WORK ); |
|
374 |
break; |
|
375 |
default: |
|
376 |
Panic( EPbk2NotInitialized ); |
|
377 |
} |
|
378 |
return retLebel; |
|
379 |
} |
|
380 |
||
381 |
// -------------------------------------------------------------------------- |
|
382 |
// CPbk2MergeConflictAddress::GetTextLC |
|
383 |
// -------------------------------------------------------------------------- |
|
384 |
// |
|
385 |
HBufC* CPbk2MergeConflictAddress::GetTextLC( EPbk2ConflictedNumber aNumber ) |
|
386 |
{ |
|
387 |
__ASSERT_ALWAYS( iContactFirst && iContactSecond, Panic( EPbk2NotInitialized ) ); |
|
388 |
||
389 |
RBuf addressText; |
|
390 |
if( aNumber == EPbk2ConflictedFirst ) |
|
391 |
{ |
|
392 |
Pbk2AddressTools::GetAddressPreviewLC( *iContactFirst , |
|
393 |
iAddressGroup, addressText ); |
|
394 |
} |
|
395 |
else |
|
396 |
{ |
|
397 |
Pbk2AddressTools::GetAddressPreviewLC( *iContactSecond , |
|
398 |
iAddressGroup, addressText ); |
|
399 |
} |
|
400 |
||
401 |
HBufC* retText = addressText.AllocL(); |
|
402 |
CleanupStack::PopAndDestroy( &addressText ); |
|
403 |
CleanupStack::PushL( retText ); |
|
404 |
return retText; |
|
405 |
} |
|
406 |
||
407 |
// -------------------------------------------------------------------------- |
|
408 |
// CPbk2MergeConflictAddress::ResolveConflict |
|
409 |
// -------------------------------------------------------------------------- |
|
410 |
// |
|
411 |
void CPbk2MergeConflictAddress::ResolveConflict( EPbk2ConflictedNumber aNumber ) |
|
412 |
{ |
|
413 |
__ASSERT_ALWAYS( iContactFirst && iContactSecond, Panic( EPbk2NotInitialized ) ); |
|
414 |
||
415 |
if( aNumber == EPbk2ConflictedFirst ) |
|
416 |
{ |
|
417 |
iContactChosenAddress = iContactFirst; |
|
418 |
} |
|
419 |
else |
|
420 |
{ |
|
421 |
iContactChosenAddress = iContactSecond; |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
// -------------------------------------------------------------------------- |
|
426 |
// CPbk2MergeConflictAddress::GetChosenFieldsL |
|
427 |
// -------------------------------------------------------------------------- |
|
428 |
// |
|
429 |
void CPbk2MergeConflictAddress::GetChosenFieldsL( |
|
430 |
RPointerArray<MVPbkStoreContactField>& aAddressFields ) |
|
431 |
{ |
|
432 |
__ASSERT_ALWAYS( iContactChosenAddress, Panic( EPbk2NotChosen ) ); |
|
433 |
||
434 |
CleanupClosePushL( aAddressFields ); |
|
435 |
CPbk2PresentationContactFieldCollection& fields = iContactChosenAddress->PresentationFields(); |
|
436 |
||
437 |
for( TInt idx = 0; idx < fields.FieldCount(); idx++ ) |
|
438 |
{ |
|
439 |
CPbk2PresentationContactField& field = fields.At( idx ); |
|
440 |
const MPbk2FieldProperty& property = field.FieldProperty(); |
|
441 |
if( property.GroupId() == iAddressGroup ) |
|
442 |
{ |
|
443 |
aAddressFields.AppendL( &field ); |
|
444 |
} |
|
445 |
} |
|
446 |
CleanupStack::Pop(); |
|
447 |
} |
|
448 |