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: command process for selected contact |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 //include files |
|
20 #include "cvimpstcmdprocessselectedcontact.h" |
|
21 |
|
22 #include <MVPbkStoreContact.h> |
|
23 #include <MVPbkFieldType.h> |
|
24 #include <MVPbkContactFieldTextData.h> |
|
25 #include <MVPbkContactFieldUriData.h> |
|
26 |
|
27 #include "vimpstcmd.hrh" |
|
28 #include "mvimpstcmdobserver.h" |
|
29 |
|
30 #include "uiservicetabtracer.h" |
|
31 |
|
32 #include <e32def.h> |
|
33 #include <MVPbkContactLinkArray.h> |
|
34 #include "mvimpstengine.h" |
|
35 |
|
36 #include "mvimpststorageserviceview.h" |
|
37 #include "cvimpststoragemanagerfactory.h" |
|
38 #include "mvimpstenginecontactmgmtextention.h" |
|
39 #include "tvimpstconsts.h" |
|
40 #include "mvimpstenginesubservice.h" |
|
41 #include "mvimpstenginepresencesubservice.h" |
|
42 |
|
43 // Constants |
|
44 _LIT( KListNameAllBuddy ,"buddylist" ); |
|
45 |
|
46 // -------------------------------------------------------------------------- |
|
47 // CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 CVIMPSTCmdProcessSelectedContact::CVIMPSTCmdProcessSelectedContact( const TInt aCommandId , |
|
51 TVPbkSelectedData& aSelectedEntries, |
|
52 MVIMPSTEngine& aEngine ): |
|
53 iCommandId( aCommandId ), |
|
54 iSelectedEntries( aSelectedEntries ), |
|
55 iEngine(aEngine) |
|
56 { |
|
57 } |
|
58 |
|
59 // -------------------------------------------------------------------------- |
|
60 // CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact |
|
61 // -------------------------------------------------------------------------- |
|
62 // |
|
63 CVIMPSTCmdProcessSelectedContact::~CVIMPSTCmdProcessSelectedContact() |
|
64 { |
|
65 |
|
66 } |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CVIMPSTCmdProcessSelectedContact::NewL |
|
70 // -------------------------------------------------------------------------- |
|
71 // |
|
72 CVIMPSTCmdProcessSelectedContact* CVIMPSTCmdProcessSelectedContact::NewL( const TInt aCommandId, |
|
73 TVPbkSelectedData& aSelectedEntries, |
|
74 MVIMPSTEngine& aEngine ) |
|
75 { |
|
76 CVIMPSTCmdProcessSelectedContact* self = new (ELeave ) CVIMPSTCmdProcessSelectedContact( aCommandId ,aSelectedEntries, aEngine); |
|
77 self->ConstructL(); //use contsurctL if necessary |
|
78 return self; |
|
79 } |
|
80 // -------------------------------------------------------------------------- |
|
81 // CVIMPSTCmdProcessSelectedContact::ConstructL |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 void CVIMPSTCmdProcessSelectedContact::ConstructL() |
|
85 { |
|
86 iError = KErrNone; |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CVIMPSTCmdProcessSelectedContact::ExecuteLD |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 void CVIMPSTCmdProcessSelectedContact::ExecuteLD() |
|
94 { |
|
95 |
|
96 TRACER_AUTO; |
|
97 //push to the cleanupstack |
|
98 CleanupStack::PushL( this ); |
|
99 MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL( iEngine.ServiceId() ) ; |
|
100 if(storage) |
|
101 { |
|
102 TBool localStore = storage->IsLocalStore(); |
|
103 //retrieve contact from links |
|
104 TPtrC8 pacledLinks = iSelectedEntries.iPackedLinks->Des(); |
|
105 TInt count = storage->RetriveLinkXSPIdsL( pacledLinks ); |
|
106 if( !count ) |
|
107 { |
|
108 iError = KErrGeneral; |
|
109 } |
|
110 if( (iCommandId == ECmdProcessSelectedContactNew || |
|
111 iCommandId == ECmdProcessSelectedContactExist )&& |
|
112 iError == KErrNone ) |
|
113 { |
|
114 MVIMPSTEngineExtentionFeatures* contactFeature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement); |
|
115 MVIMPSTEngineSubService* presenceService = iEngine.SubService(TVIMPSTEnums::EPresence); |
|
116 for(TInt index = 0; index < count; index++ ) |
|
117 { |
|
118 TPtrC xspIdPtr = storage->GetRetrieveXSPIdL( index ); // xspId is owned here |
|
119 if( localStore ) |
|
120 { |
|
121 iError = KErrNone; |
|
122 if( xspIdPtr.Length() ) |
|
123 { |
|
124 if( IsContactBlocked( xspIdPtr ) ) |
|
125 { |
|
126 iError = EErrExistInBlockList; |
|
127 } |
|
128 else if( storage->FindContactByUserId( xspIdPtr ) ) |
|
129 { |
|
130 iError = EErrExistInContactList; |
|
131 } |
|
132 else if( contactFeature ) |
|
133 { |
|
134 // add to server and store if sucess |
|
135 MVIMPSTEngineContactMgmtExtention& contactMgr = |
|
136 MVIMPSTEngineContactMgmtExtention::Cast (*contactFeature); |
|
137 iError = contactMgr.AddServerContactL( KListNameAllBuddy, xspIdPtr ,KNullDesC ); |
|
138 } |
|
139 } |
|
140 if(KErrNone == iError ) |
|
141 { |
|
142 iError = storage->CreateNewContactFromRetrivedIdL( index ); |
|
143 } |
|
144 else if( iCommandId == ECmdProcessSelectedContactNew ) |
|
145 { |
|
146 // delete the contact which got created in phonebook but failed to add in servicetab |
|
147 storage->DeleteNewContactFromRetrivedIdL( index ); |
|
148 } |
|
149 } |
|
150 else if( xspIdPtr.Length() ) |
|
151 { |
|
152 // xspId ownership is transfered to iXSPList |
|
153 iSelectedEntries.iXSPList.AppendL( xspIdPtr.AllocL() ); |
|
154 } |
|
155 } |
|
156 } |
|
157 else if( ( iCommandId == ECmdProcessAcceptedContactNew || |
|
158 iCommandId == ECmdProcessAcceptedContactExist )&& |
|
159 iError == KErrNone )// for accepted contact |
|
160 { |
|
161 // just add and return |
|
162 // contact is already added in storage in RetrieveContactL |
|
163 // if sucess ,storage will take ownership else we need to delete contact |
|
164 iError = storage->CreateNewContactFromRetrivedIdL( 0 ); // for accepting invitation take the first contact which is retirved |
|
165 if( iError != KErrNone && iCommandId == ECmdProcessAcceptedContactNew ) |
|
166 { |
|
167 // delete the contact which got created in phonebook but failed to add in servicetab |
|
168 storage->DeleteNewContactFromRetrivedIdL( 0 ); |
|
169 } |
|
170 } |
|
171 if( !localStore ) |
|
172 { |
|
173 // in case of server we have a selection dialog |
|
174 // so this error does not matter |
|
175 // set to 0 |
|
176 iError = KErrNone; |
|
177 } |
|
178 } |
|
179 else |
|
180 { |
|
181 iError = KErrGeneral; |
|
182 } |
|
183 if(iObserver) |
|
184 { |
|
185 iObserver->CommandFinishedL(*this); |
|
186 } |
|
187 |
|
188 CleanupStack::PopAndDestroy(); |
|
189 |
|
190 } |
|
191 |
|
192 |
|
193 // -------------------------------------------------------------------------- |
|
194 // CVIMPSTCmdProcessSelectedContact::AddObserver |
|
195 // -------------------------------------------------------------------------- |
|
196 // |
|
197 void CVIMPSTCmdProcessSelectedContact::AddObserver( MVIMPSTCmdObserver& aObserver ) |
|
198 { |
|
199 // store the observer to notify the command completion |
|
200 iObserver = &aObserver; |
|
201 } |
|
202 |
|
203 |
|
204 // -------------------------------------------------------------------------- |
|
205 // CVIMPSTCmdProcessSelectedContact::CommandId |
|
206 // -------------------------------------------------------------------------- |
|
207 // |
|
208 TInt CVIMPSTCmdProcessSelectedContact::CommandId() const |
|
209 { |
|
210 return iCommandId; |
|
211 } |
|
212 |
|
213 // -------------------------------------------------------------------------- |
|
214 // CVIMPSTCmdProcessSelectedContact::Result |
|
215 // -------------------------------------------------------------------------- |
|
216 // |
|
217 TInt CVIMPSTCmdProcessSelectedContact::Result() const |
|
218 { |
|
219 //return valid data regd the command operation |
|
220 return iError; |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------- |
|
224 // CVIMPSTCmdProcessSelectedContact::Result |
|
225 // -------------------------------------------------------------------------- |
|
226 // |
|
227 // -------------------------------------------------------------------------- |
|
228 // CVIMPSTCmdProcessSelectedContact::IsContactBlocked |
|
229 // -------------------------------------------------------------------------- |
|
230 TBool CVIMPSTCmdProcessSelectedContact::IsContactBlocked(const TDesC& aUserId) |
|
231 { |
|
232 TRACER_AUTO; |
|
233 MVIMPSTEngineSubService* subService = |
|
234 (iEngine.SubService(TVIMPSTEnums::EPresence)); |
|
235 if(subService) |
|
236 { |
|
237 MVIMPSTEnginePresenceSubService& presence = |
|
238 MVIMPSTEnginePresenceSubService::Cast (*subService); |
|
239 |
|
240 RPointerArray<HBufC> *blockedlist = presence .GetBlockedList(); |
|
241 |
|
242 if(blockedlist) |
|
243 { |
|
244 for(TInt i=0; i<blockedlist->Count(); ++i) |
|
245 { |
|
246 if(0 == aUserId.CompareC((*blockedlist)[i]->Des())) |
|
247 { |
|
248 return ETrue; |
|
249 } |
|
250 } |
|
251 } |
|
252 } |
|
253 return EFalse; |
|
254 } |
|
255 // End of File |
|