1 /* |
|
2 * Copyright (c) 2008 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: implementation for CVIMPSTCmdAddFromPbk |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cvimpstcmdaddfrompbk.h" |
|
21 #include "vimpstcmd.hrh" |
|
22 #include "mvimpstcmdobserver.h" |
|
23 |
|
24 #include "uiservicetabtracer.h" |
|
25 |
|
26 #include <e32def.h> |
|
27 #include <mvpbkstorecontact.h> |
|
28 #include "mvimpstengine.h" |
|
29 #include "mvimpststorageserviceview.h" |
|
30 #include "cvimpststoragemanagerfactory.h" |
|
31 #include <mvpbkstorecontactfield.h> |
|
32 #include <mvpbkfieldtype.h> |
|
33 #include <vpbkeng.rsg> |
|
34 #include "mvimpstenginecontactmgmtextention.h" |
|
35 #include "mvimpstengineextentionfeatures.h" |
|
36 #include <mvpbkcontactfieldtextdata.h> |
|
37 |
|
38 // Constants |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CVIMPSTCmdAddFromPbk::CVIMPSTCmdAddFromPbk |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 CVIMPSTCmdAddFromPbk::CVIMPSTCmdAddFromPbk( const TInt aCommandId , |
|
45 const MVPbkStoreContact& aStoreContact, |
|
46 MVIMPSTEngine& aEngine ): |
|
47 iCommandId( aCommandId ), |
|
48 iStoreContact( aStoreContact ), |
|
49 iEngine(aEngine) |
|
50 { |
|
51 } |
|
52 |
|
53 // -------------------------------------------------------------------------- |
|
54 // CVIMPSTCmdAddFromPbk::~CVIMPSTCmdAddFromPbk |
|
55 // -------------------------------------------------------------------------- |
|
56 // |
|
57 CVIMPSTCmdAddFromPbk::~CVIMPSTCmdAddFromPbk() |
|
58 { |
|
59 |
|
60 } |
|
61 |
|
62 // -------------------------------------------------------------------------- |
|
63 // CVIMPSTCmdAddFromPbk::NewL |
|
64 // -------------------------------------------------------------------------- |
|
65 // |
|
66 CVIMPSTCmdAddFromPbk* CVIMPSTCmdAddFromPbk::NewL( const TInt aCommandId, |
|
67 const MVPbkStoreContact& aStoreContact, |
|
68 MVIMPSTEngine& aEngine ) |
|
69 { |
|
70 TRACER_AUTO; |
|
71 CVIMPSTCmdAddFromPbk* self = new (ELeave ) CVIMPSTCmdAddFromPbk( aCommandId ,aStoreContact, aEngine); |
|
72 self->ConstructL(); //use contsurctL if necessary |
|
73 return self; |
|
74 } |
|
75 // -------------------------------------------------------------------------- |
|
76 // CVIMPSTCmdAddFromPbk::ConstructL |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 void CVIMPSTCmdAddFromPbk::ConstructL() |
|
80 { |
|
81 iError = KErrNone; |
|
82 } |
|
83 |
|
84 // -------------------------------------------------------------------------- |
|
85 // CVIMPSTCmdAddFromPbk::ExecuteLD |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 void CVIMPSTCmdAddFromPbk::ExecuteLD() |
|
89 { |
|
90 |
|
91 TRACER_AUTO; |
|
92 //push to the cleanupstack |
|
93 CleanupStack::PushL( this ); |
|
94 MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL( iEngine.ServiceId() ) ; |
|
95 if(storage) |
|
96 { |
|
97 //storage->AddPhoneBookContactL(iStoreContact); |
|
98 // get the link and form link identify the servicedetails and then sedn it to |
|
99 //contact management to add it to server. |
|
100 //make search request using search manager in engine |
|
101 // Read all necessary data from contact and store to |
|
102 // own type |
|
103 CDesCArray* arrayForService = new (ELeave) CDesCArrayFlat( |
|
104 12 ); |
|
105 CleanupStack::PushL( arrayForService ); // 1 |
|
106 |
|
107 GetServiceFieldsL(*arrayForService); |
|
108 |
|
109 TInt count = arrayForService->Count(); |
|
110 MVIMPSTEngineContactMgmtExtention* contactMgr = |
|
111 dynamic_cast<MVIMPSTEngineContactMgmtExtention*> |
|
112 (iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement)); |
|
113 |
|
114 for(TInt i = 0; i< count; i++) |
|
115 { |
|
116 if(contactMgr) |
|
117 { |
|
118 iError = contactMgr->AddServerContactL(KNullDesC(),KNullDesC(),KNullDesC()); |
|
119 } |
|
120 } |
|
121 CleanupStack::PopAndDestroy(arrayForService); |
|
122 } |
|
123 else |
|
124 { |
|
125 iError = KErrGeneral; |
|
126 } |
|
127 if(iObserver) |
|
128 { |
|
129 iObserver->CommandFinishedL(*this); |
|
130 } |
|
131 |
|
132 CleanupStack::PopAndDestroy(); |
|
133 |
|
134 } |
|
135 |
|
136 |
|
137 // -------------------------------------------------------------------------- |
|
138 // CVIMPSTCmdAddFromPbk::AddObserver |
|
139 // -------------------------------------------------------------------------- |
|
140 // |
|
141 void CVIMPSTCmdAddFromPbk::AddObserver( MVIMPSTCmdObserver& aObserver ) |
|
142 { |
|
143 // store the observer to notify the command completion |
|
144 iObserver = &aObserver; |
|
145 } |
|
146 |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CVIMPSTCmdAddFromPbk::CommandId |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 TInt CVIMPSTCmdAddFromPbk::CommandId() const |
|
153 { |
|
154 return iCommandId; |
|
155 } |
|
156 |
|
157 // -------------------------------------------------------------------------- |
|
158 // CVIMPSTCmdAddFromPbk::Result |
|
159 // -------------------------------------------------------------------------- |
|
160 // |
|
161 TInt CVIMPSTCmdAddFromPbk::Result() const |
|
162 { |
|
163 //return valid data regd the command operation |
|
164 return iError; |
|
165 } |
|
166 // --------------------------------------------------------------------------- |
|
167 // CVIMPSTCmdAddFromPbk::GetServiceFieldsL |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CVIMPSTCmdAddFromPbk::GetServiceFieldsL( CDesCArray& aArrayForServiceFields ) |
|
171 { |
|
172 |
|
173 TRACER_AUTO; |
|
174 HBufC* values[40]; |
|
175 for( TInt index = 0 ; |
|
176 index < iStoreContact.Fields().FieldCount() ; |
|
177 index++ ) |
|
178 { |
|
179 const MVPbkStoreContactFieldCollection& fieldCollection = iStoreContact.Fields(); |
|
180 |
|
181 const MVPbkStoreContactField& field = fieldCollection.FieldAt( index ); |
|
182 const MVPbkFieldType* fieldType = field.BestMatchingFieldType(); |
|
183 |
|
184 //find the relevant voip fields/email id fileds. |
|
185 if ( fieldType ) |
|
186 { |
|
187 if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VOIPHOME ) || |
|
188 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VOIPWORK ) || |
|
189 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_VOIPGEN ) || |
|
190 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_SIP )|| |
|
191 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_EMAILWORK ) || |
|
192 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_EMAILHOME ) || |
|
193 ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_EMAILGEN )) |
|
194 { |
|
195 TRACE("GetServiceFieldsL - Found"); |
|
196 values[0] = MVPbkContactFieldTextData::Cast( |
|
197 iStoreContact.Fields().FieldAt( index ). |
|
198 FieldData() ).Text().AllocLC(); |
|
199 if ( values[0] ) |
|
200 { |
|
201 // Check for prefix and remove if found |
|
202 TInt prefixLocation = values[0]->Locate( ':' ); |
|
203 if ( KErrNotFound != prefixLocation ) |
|
204 { |
|
205 TRACE("Prefix found -> remove"); |
|
206 aArrayForServiceFields.AppendL( values[0]->Des().Mid( |
|
207 prefixLocation+1 ) ); |
|
208 } |
|
209 else |
|
210 { |
|
211 TRACE("No prefix"); |
|
212 aArrayForServiceFields.AppendL( values[0]->Des() ); |
|
213 } |
|
214 CleanupStack::PopAndDestroy( values[0] ); |
|
215 } |
|
216 } |
|
217 } |
|
218 } |
|
219 } |
|
220 |
|
221 // End of File |
|