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