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