|
1 /* |
|
2 * Copyright (c) 2003-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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __CNTVCARDUTILS_H__ |
|
20 #define __CNTVCARDUTILS_H__ |
|
21 |
|
22 #include <cntvcard.h> |
|
23 #include "pbapconverter.h" |
|
24 |
|
25 // Constants |
|
26 const TUint KContactVCardSpaceCharacter = 0x20; |
|
27 const TInt KContactMaxVCardPropertyNameLength=75; |
|
28 const TInt KContactStandardCardValueLength=40; |
|
29 _LIT(KSingleSpacePropertyValue," "); |
|
30 |
|
31 // Literal constants |
|
32 _LIT8(KContactVCardXDashEPOCCNTMODEL,"X-EPOCCNTMODEL"); |
|
33 _LIT(KContactVarVCardXDashEPOCCNTMODEL,"X-EPOCCNTMODEL"); |
|
34 _LIT(KContactVCardFIELDLABEL,"FIELDLABEL"); |
|
35 _LIT8(KContactVCardLABELn,"LABEL%d"); |
|
36 _LIT(KContactVarVCardLABELn,"LABEL%d"); |
|
37 _LIT(KContactVCardLABEL0 ,"LABEL0"); |
|
38 _LIT(KContactVCardLABEL1 ,"LABEL1"); |
|
39 _LIT(KContactVCardLABEL2 ,"LABEL2"); |
|
40 _LIT(KContactVCardLABEL3 ,"LABEL3"); |
|
41 _LIT(KContactVCardLABEL4 ,"LABEL4"); |
|
42 _LIT(KContactVCardLABEL5 ,"LABEL5"); |
|
43 _LIT(KContactVCardLABEL6 ,"LABEL6"); |
|
44 _LIT(KContactVCardFIELDHIDDEN,"FIELDHIDDEN"); |
|
45 _LIT(KContactVCardFIELDREADONLY,"FIELDREADONLY"); |
|
46 // |
|
47 _LIT(KContactVCardCompositeSupportedButEmptyFieldValue, " "); |
|
48 _LIT(KContactVCardCompositeUnsupportedFieldValue, ""); |
|
49 _LIT(KContactVCardNonCompositeEmptyFieldValue, ""); |
|
50 _LIT(KContactVCardEmptyFieldValue, ""); |
|
51 _LIT8(KVersitTokenSIPID,"X-SIP"); |
|
52 _LIT8(KVersitParamPOC,"POC"); |
|
53 _LIT8(KVersitParamSWIS,"SWIS"); |
|
54 _LIT8(KVersitParamVOIP,"VOIP"); |
|
55 _LIT8(KVersitTokenWVID,"X-WV-ID"); |
|
56 |
|
57 |
|
58 /** |
|
59 Export converter, Converts contact items into vCard objects. |
|
60 also provides support for export of contacts to PBAP client. |
|
61 */ |
|
62 class CContactsAppToVCardConverter : public CBase |
|
63 { |
|
64 public: |
|
65 ~CContactsAppToVCardConverter(); |
|
66 CContactsAppToVCardConverter(TInt64 aMachineUniqueId, Versit::TVersitCharSet aCharSet, TVCardVersion aVCardVersion); |
|
67 CParserVCard* GetContactItemAsVCardL(CContactItem* aMainItem, CArrayPtr<CContactItem>* aAgentItemArray, TInt aOption, TBool aExportPrivateFields); |
|
68 void SetFilter(TInt64 aFilter); |
|
69 TBool NeedsToBeExported(TPBAPProperties aProp) const; |
|
70 TBool IsPBAPExport()const; |
|
71 private: |
|
72 void EncodeItemPropertiesL(const CContactItem& aContactItem,TInt aOption); |
|
73 void EncodeFieldPropertiesL(const CContactItem& aContactItem, CArrayPtr<CContactItem>* aAgentItemArray, TInt aOption, TBool aExportPrivateFields); |
|
74 void GetVCardNamePrnL(CContactItemFieldSet& aFields,TInt aOption,TBool aExportPrivateFields); |
|
75 void GetVCardNameL(CContactItemFieldSet& aFields,TInt aOption, TBool aExportPrivateFields); |
|
76 void GetVCardAddressL(const CContactItem& aContact, TUid aVCardMapping, const TDesC8& aToken, TInt aOption, TBool aExportPrivateFields); |
|
77 void MapContactFieldToVCardPropertyL(const CContactItemField& aField,CContactItem* aAgent,TInt aOption,TInt aDuplicateCount,TBool aExportPrivateFields); |
|
78 void MapContactMappingToVCardPropertyNameAndTypeL(const CContentType& aContactType,TDes8& aName,TUid& aPropertyUid,CArrayPtr<CParserParam>* aArrayOfParams) const; |
|
79 void RetrieveAddressFieldL(const CContactItemFieldSet& aFields, CArrayPtr<CParserParam>& aParams, CDesCArrayFlat& aDesArray, TFieldType aFieldType, TUid aMapping, const TDesC& aLabel, TInt aOption, TBool& aFound,TBool aExportPrivateFields,TBool aWithoutPref=ETrue) const; |
|
80 TBool LocateSpecificNameValueL(const CContactItemFieldSet& aFieldSet, TUid aSearchField, CDesCArray& aPropValueArray, CArrayPtr<CParserParam>& aPropParamArray, const TDesC& aLabelPrefix, TInt aOption, TBool aExportPrivateFields); |
|
81 static CParserPropertyValueDateTime* CreateDateTimePropertyL(const TTime& aDateTime, TVersitDateTime::TRelativeTime aRelativeTime); |
|
82 static CParserPropertyValueDate* CreateDatePropertyL(const TTime& aDateTime); |
|
83 void GetVCardOrgInfoL(const CContactItemFieldSet& aFields, TInt aOption, TBool aExportPrivateFields); |
|
84 void RemoveNewLineL(CDesCArray& aPropValueArray, const TPtrC& aFieldContents); |
|
85 TVCardVersion GetExportVersion()const; |
|
86 void GetVCardFormattedNameL(CContactItemFieldSet& aFields, TInt aOption, TBool aExportPrivateFields); |
|
87 TPBAPProperties AttributeFromMapping(TUid aMapping) const; |
|
88 TBool DefaultInternetParameterRequired(const CContentType& aContactType) const; |
|
89 void AddParamToArrayL(CArrayPtr<CParserParam>* aArrayOfParams, CParserParam* aParserParam, TInt32 aMappingUid, TInt32 aFieldTypeUid) const; |
|
90 private: // UTILITY methods |
|
91 static TInt FindAddressFieldByMappingAndType(const CContactItemFieldSet& aFields, TFieldType aFieldType, TUid aMapping); |
|
92 |
|
93 private: |
|
94 CParserVCard* iVCard; |
|
95 TInt64 iMachineUniqueId; |
|
96 Versit::TVersitCharSet iCharSet; |
|
97 TVCardVersion iVCardVersion; |
|
98 TInt64 iFilter; |
|
99 }; |
|
100 |
|
101 |
|
102 /** |
|
103 * Import and update converter |
|
104 */ |
|
105 class CVCardToContactsAppConverter : public CBase |
|
106 { |
|
107 public: |
|
108 enum TUnknownPropertyBehaviour |
|
109 { |
|
110 EPreserveAllProperties, |
|
111 EDiscardNonXDashUnknownProperties, |
|
112 EDiscardAllUnknownProperties |
|
113 }; |
|
114 |
|
115 public: |
|
116 CContactItem* GetVCardAsContactItemLC(CParserVCard& aSourceVCard, TUnknownPropertyBehaviour aUnknownPropertyBehaviour, TInt aOption); |
|
117 void GetVCardUidStringL(CParserVCard& aSourceVCard, TDes& aUidString) const; |
|
118 TBool MergeVCardWithContactItemL(CContactItem& aContact,CParserVCard& aSourceVCard,TUnknownPropertyBehaviour aUnknownPropertyBehaviour,TInt aOption); |
|
119 |
|
120 private: |
|
121 CContactItemField* GetVCardPropertyAsContactFieldLC(CParserProperty* aVCardProperty, TInt aOption,TBool& aUnsupportedProperty); |
|
122 static CContentType* MapVCardPropertyToContentAndStorageTypeL(const CParserProperty& aVCardProperty, TStorageType& aStorageType); |
|
123 // |
|
124 static void GetVCardModifiedTimeL(CParserVCard& aVCard,TTime& aLastModified); |
|
125 static TInt GetVCardPropertyTTNumber(CParserProperty* aVCardProperty); |
|
126 static void DeleteField(CContactItem& aContact, const CContactItemFieldSet& aFieldSet, TFieldType aFieldType, TUid aMapping); |
|
127 |
|
128 static void GetContactNameL(CParserVCard& aVCard,CDesCArray* aName,TInt aOption,CDesCArray* aLabels); |
|
129 static TBool GetSpecifiedAddressL(CArrayPtr<CParserProperty>& aProperties, TInt aOption, const TDesC8& aParamMustMatch, const TDesC8& aParamMustNotMatch1, const TDesC8& aParamMustNotMatch2, CDesCArray& aAddressRepository, CDesCArray& aAddressLabelRepository); |
|
130 |
|
131 void MergeNameFieldsL(CContactItem& aContact, CVCardItemAndLabel& aNames, TInt aOption, TBool aTreatAsPrn = EFalse); |
|
132 void MergeSpecifiedNameFieldL(CContactItem& aContact, TFieldType aFieldType, CVCardItemAndLabel& aNames, TInt aOption, TInt aNameIndex); |
|
133 void MergeAddressFieldsL(CContactItem& aContact, const CVCardAddress& aAddress, TInt aOption); |
|
134 void MergeSpecifiedAddressFieldL(CContactItem& aContact, const CVCardAddress& aAddresses, const TUid& aFieldUid, const TUid& aMappingUid, TInt aNameIndex, TInt aOption); |
|
135 |
|
136 |
|
137 private: // UTILITY methods |
|
138 TBool TextArrayContainsImportableData(const CDesCArray& aArray) const; |
|
139 static void RemoveWhitespaceFromCompositePropertyL(CDesCArray& aArray); |
|
140 static TFieldType MapVCardPhotoTypeToFieldType(TPtrC8 aBitmapStringPtr); |
|
141 inline void SetImportType(TCntVCardImportType aType) { iImportType = aType; } |
|
142 inline TCntVCardImportType ImportType() const { return iImportType; } |
|
143 HBufC* EncodeL(const TDesC& aText, TBool aTextTobeTruncated) const; |
|
144 TBool PropertyTobeTruncated(const TPtrC8& aFieldName) const; |
|
145 static void GetBitMapFormat(const CParserProperty& aVCardProperty, TFieldType& bitMapFormat); |
|
146 void AdjustForPrefRule(CContactItem& aContactItem, TFieldType aFieldType, TUid aMapping); |
|
147 |
|
148 private: // NAME handling |
|
149 static void DeleteNameFields(CContactItem& aContact); |
|
150 static CVCardItemAndLabel* GetContactNameLC(CParserVCard& aVCard, TInt aOption); |
|
151 static CVCardItemAndLabel* GetContactNamePrnLC(CParserVCard& aVCard, TInt aOption); |
|
152 void SetNameFieldsL(const CVCardItemAndLabel& aNames, CContactItem& aContact, TInt aOption, TBool aTreatAsPronunciation = EFalse) const; |
|
153 void SetNameFieldL(const CVCardItemAndLabel& aNames, CContactItem& aContact, TInt aOption, TInt aIndex, TFieldType aFieldType, TInt& aInsertPos) const; |
|
154 static CVCardItemAndLabel* MakeNamesFromItemsL(const CDesCArray& aItems, TInt aOption, const CParserProperty* aProperty ); |
|
155 |
|
156 private: // ADDRESS handling |
|
157 static void DeleteAddressFields(CContactItem& aContact, TFieldType aFieldType); |
|
158 static void GetAddressesL(CParserVCard& aVCard, TInt aOption, RPointerArray<CVCardAddress>& aAddresses); |
|
159 static void GetHomeAndWorkAddressL(CParserVCard& aVCard, CDesCArray* aAddressHome, CDesCArray* aAddressWork, TInt aOption, CDesCArray* aAddressHomeLabels, CDesCArray* aAddressWorkLabels); |
|
160 void SetAddressFieldsL(const CVCardAddress& aAddress, CContactItem& aContact, TInt aOption) const; |
|
161 void SetAddressFieldL(const CVCardAddress& aAddress, |
|
162 CContactItem& aContact, |
|
163 TInt aOption, |
|
164 TInt aIndex, |
|
165 TFieldType aFieldType, |
|
166 TInt& aInsertPos, |
|
167 TUid aMapping |
|
168 ) const; |
|
169 |
|
170 static CVCardAddress* GetSpecifiedAddressLC(const CArrayPtr<CParserProperty>& aProperties, |
|
171 TInt aOption, |
|
172 const TDesC8& aParamMustMatch, |
|
173 const TDesC8& aParamMustNotMatch1, |
|
174 const TDesC8& aParamMustNotMatch2, |
|
175 TUid aMapping |
|
176 ); |
|
177 |
|
178 private: // Organization handling |
|
179 TInt GetVCardPropertyAsArrayOfValuesL(const CParserVCard& aVCard, const TDesC8& aToken, CDesCArray& aItems); |
|
180 void SetOrgDetailsL(CContactItem& aContact, CDesCArray& aItems, const TInt aOption); |
|
181 void SetSpecificFieldL(CContactItem& aContact, CDesCArray& aItems, const TUid& aFieldType,const TUid& aMapping, TInt aOption, TInt aStartIndex, TInt aEndIndex); |
|
182 void MergeOrgDetailsL(CContactItem& aContact, CDesCArray& aItems, TInt aOption); |
|
183 void MergeSpecificFieldL(CContactItem& aContact, CDesCArray& aItems, const TFieldType& aFieldType, const TUid& aMapping, TInt aOption, TInt aStartIndex, TInt aEndIndex); |
|
184 |
|
185 private: // Class handling |
|
186 TInt GetSingleInstanceL(const CParserVCard& aVCard, const TDesC8& aToken, TDes& aClass); |
|
187 void SetSingleInstanceL(CContactItem& aContact, const TDes& aValue,const TFieldType& aFieldType, const TUid& aMapping, TInt aOption); |
|
188 void MergeSingleInstanceL(CContactItem& aContact, const TDes& aValue,const TFieldType& aFieldType, const TUid& aMapping, TInt aOption); |
|
189 |
|
190 private: // Parameter handling |
|
191 static TBool IsParameterValuePresent(CArrayPtr<CParserParam>* aParamArray, const TDesC8& aParamName, const TDesC8& aParamValue); |
|
192 |
|
193 private: |
|
194 TUnknownPropertyBehaviour iUnknownPropertyBehaviour; |
|
195 TCntVCardImportType iImportType; |
|
196 }; |
|
197 |
|
198 |
|
199 /** |
|
200 * Generic base class representing a collection of items (e.g. names sub-fields) and their |
|
201 * associated labels |
|
202 */ |
|
203 class CVCardItemAndLabel : public CBase |
|
204 { |
|
205 public: |
|
206 static CVCardItemAndLabel* NewLC(); |
|
207 ~CVCardItemAndLabel(); |
|
208 |
|
209 protected: |
|
210 CVCardItemAndLabel(); |
|
211 void ConstructL(); |
|
212 |
|
213 public: |
|
214 void AddItemL(const TDesC& aItem); |
|
215 void AddLabelL(const TDesC& aItem); |
|
216 // |
|
217 TInt ItemCount() const; |
|
218 TInt LabelCount() const; |
|
219 // |
|
220 TPtrC Item(TInt aIndex) const; |
|
221 TPtrC Label(TInt aIndex) const; |
|
222 // |
|
223 TInt FindLabel(const TDesC& aName, TInt& aPosition) const; |
|
224 |
|
225 public: |
|
226 static void CleanUpResetDestroyAndCloseArray(TAny* aArray); |
|
227 |
|
228 private: |
|
229 CDesCArray* iItems; |
|
230 CDesCArray* iLabels; |
|
231 }; |
|
232 |
|
233 |
|
234 /** |
|
235 * Class used to hold address sub-fields and their associated labels. |
|
236 */ |
|
237 class CVCardAddress : public CVCardItemAndLabel |
|
238 { |
|
239 public: |
|
240 static CVCardAddress* NewLC(TUid aMapping); |
|
241 |
|
242 private: |
|
243 CVCardAddress(TUid aMapping); |
|
244 |
|
245 public: |
|
246 inline TUid Mapping() const { return iMapping; } |
|
247 |
|
248 private: |
|
249 TUid iMapping; |
|
250 }; |
|
251 |
|
252 /** Panic enumeration */ |
|
253 enum TCntVCardPanic |
|
254 { |
|
255 ECntVPanicAgentNotNull, |
|
256 ECntVPanicBadParamName, |
|
257 ECntVPanicInvalidImportType, |
|
258 }; |
|
259 |
|
260 GLREF_C void Panic(TCntVCardPanic aPanic); |
|
261 GLREF_C void CleanUpResetAndDestroy(TAny *aArray); |
|
262 |
|
263 #endif |