|
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: . |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "spbphonenumberparser.h" |
|
20 #include "spbcontent.h" |
|
21 |
|
22 #include <MVPbkContactOperationBase.h> |
|
23 #include <CVPbkContactManager.h> |
|
24 #include <MVPbkStoreContact.h> |
|
25 #include <MVPbkStoreContactFieldCollection.h> |
|
26 #include <CVPbkDefaultAttribute.h> |
|
27 #include <MVPbkContactFieldTextData.h> |
|
28 #include <MVPbkFieldType.h> |
|
29 #include <VPbkEng.rsg> // resource ids for numbers |
|
30 |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CSpbPhoneNumberParser::NewL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CSpbPhoneNumberParser* CSpbPhoneNumberParser::NewL( |
|
37 CVPbkContactManager& aContactManager, |
|
38 CSpbContent& aContent) |
|
39 { |
|
40 CSpbPhoneNumberParser* self = |
|
41 new (ELeave) CSpbPhoneNumberParser(aContactManager, aContent); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // CSpbPhoneNumberParser::~CSpbPhoneNumberParser |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CSpbPhoneNumberParser::~CSpbPhoneNumberParser() |
|
53 { |
|
54 delete iOperation; |
|
55 iOperation = NULL; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CSpbPhoneNumberParser::CSpbPhoneNumberParser |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 inline CSpbPhoneNumberParser::CSpbPhoneNumberParser( |
|
63 CVPbkContactManager& aContactManager, |
|
64 CSpbContent& aContent) |
|
65 : iContactManager(aContactManager), |
|
66 iContent(aContent) |
|
67 { |
|
68 |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CSpbPhoneNumberParser::ConstructL |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 inline void CSpbPhoneNumberParser::ConstructL() |
|
76 { |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // CSpbPhoneNumberParser::VPbkSingleContactOperationComplete |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CSpbPhoneNumberParser::VPbkSingleContactOperationComplete( |
|
84 MVPbkContactOperationBase& /*aOperation*/, |
|
85 MVPbkStoreContact* aContact ) |
|
86 { |
|
87 delete iOperation; |
|
88 iOperation = NULL; |
|
89 TRAPD( err, SolvePhoneNumberL( *aContact ) ); |
|
90 if( err ) |
|
91 { |
|
92 //TODO error handling |
|
93 } |
|
94 delete aContact; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CSpbPhoneNumberParser::VPbkSingleContactOperationFailed |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 void CSpbPhoneNumberParser::VPbkSingleContactOperationFailed( |
|
102 MVPbkContactOperationBase& /*aOperation*/, |
|
103 TInt /*aError*/ ) |
|
104 { |
|
105 delete iOperation; |
|
106 iOperation = NULL; |
|
107 iContent.PhoneNumberUpdatedL(KNullDesC()); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CSpbPhoneNumberParser::SolvePhoneNumberL |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 void CSpbPhoneNumberParser::SolvePhoneNumberL( MVPbkStoreContact& aContact ) |
|
115 { |
|
116 RBuf number; |
|
117 TInt numberCount = 0; |
|
118 |
|
119 // check if the contact has default a number |
|
120 MVPbkContactAttributeManager& attributeManager = |
|
121 iContactManager.ContactAttributeManagerL(); |
|
122 |
|
123 CVPbkDefaultAttribute* attribute = |
|
124 CVPbkDefaultAttribute::NewL( EVPbkDefaultTypePhoneNumber ); |
|
125 CleanupStack::PushL( attribute ); |
|
126 |
|
127 MVPbkStoreContactField* field = |
|
128 attributeManager.FindFieldWithAttributeL( *attribute, aContact ); |
|
129 if( field ) |
|
130 { |
|
131 const MVPbkContactFieldTextData* textData = |
|
132 &MVPbkContactFieldTextData::Cast( field->FieldData() ); |
|
133 number.CreateL( textData->Text() ); |
|
134 } |
|
135 CleanupStack::PopAndDestroy(); //attribute |
|
136 |
|
137 // was the default number found? |
|
138 if( number.Length() == 0 ) |
|
139 { |
|
140 // get contact fields |
|
141 MVPbkStoreContactFieldCollection& fields = aContact.Fields(); |
|
142 const TInt fieldCount = fields.FieldCount(); |
|
143 // check fields |
|
144 for ( TInt i = 0; i < fieldCount; ++i ) |
|
145 { |
|
146 const MVPbkStoreContactField& field = fields.FieldAt( i ); |
|
147 // if correct data type |
|
148 if( field.FieldData().DataType() == EVPbkFieldStorageTypeText ) |
|
149 { |
|
150 const MVPbkFieldType* fieldType = field.BestMatchingFieldType(); |
|
151 if( fieldType ) |
|
152 { |
|
153 // if one of the number fields |
|
154 if( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_LANDPHONEHOME || |
|
155 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_MOBILEPHONEHOME || |
|
156 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VIDEONUMBERHOME || |
|
157 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_LANDPHONEWORK || |
|
158 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_MOBILEPHONEWORK || |
|
159 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VIDEONUMBERWORK || |
|
160 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_LANDPHONEGEN || |
|
161 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_MOBILEPHONEGEN || |
|
162 fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VIDEONUMBERGEN ) |
|
163 { |
|
164 numberCount++; |
|
165 // if only one number, store it |
|
166 if( numberCount == 1 ) |
|
167 { |
|
168 const MVPbkContactFieldTextData* textData = |
|
169 &MVPbkContactFieldTextData::Cast( field.FieldData() ); |
|
170 number.CreateL( textData->Text() ); |
|
171 } |
|
172 } |
|
173 } |
|
174 } |
|
175 } |
|
176 // if several numbers |
|
177 if( numberCount > 1 ) |
|
178 { |
|
179 // empty |
|
180 number.Copy( KNullDesC ); |
|
181 // this is for future use. |
|
182 // load localization text for multiple numbers |
|
183 // number = StringLoader::LoadLC( QTN_PHOB_N_NUMBERS, |
|
184 // numberCount, |
|
185 // CCoeEnv::Static() ); |
|
186 } |
|
187 } |
|
188 // no number was found |
|
189 if( number.Length() == 0 ) |
|
190 { |
|
191 iContent.PhoneNumberUpdatedL( KNullDesC() ); |
|
192 } |
|
193 else |
|
194 { |
|
195 // inform the observer |
|
196 iContent.PhoneNumberUpdatedL( number ); |
|
197 } |
|
198 number.Close(); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CSpbPhoneNumberParser::FetchPhoneNumber |
|
203 // --------------------------------------------------------------------------- |
|
204 // |
|
205 void CSpbPhoneNumberParser::FetchPhoneNumber( |
|
206 const MVPbkContactLink& aLink) |
|
207 { |
|
208 delete iOperation; |
|
209 iOperation = NULL; |
|
210 |
|
211 iOperation = iContactManager.RetrieveContactL(aLink, *this); |
|
212 } |
|
213 |
|
214 // end of file |