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: VIMPST command for add contact |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "cvimpstcmdaddcontact.h" |
|
21 |
|
22 #include "vimpstcmd.hrh" |
|
23 #include "mvimpstcmdobserver.h" |
|
24 |
|
25 |
|
26 #include <e32def.h> |
|
27 #include "mvimpstengine.h" |
|
28 #include "mvimpstenginecontactmgmtextention.h" |
|
29 #include "mvimpstengineextentionfeatures.h" |
|
30 #include <MVPbkStoreContact.h> |
|
31 #include <MVPbkFieldType.h> |
|
32 #include <MVPbkContactFieldTextData.h> |
|
33 #include <MVPbkContactFieldUriData.h> |
|
34 |
|
35 #include "cvimpststoragemanagerfactory.h" |
|
36 #include "mvimpststorageserviceview.h" |
|
37 #include "mvimpststoragecontact.h" |
|
38 #include "tvimpstenums.h" |
|
39 #include "tvimpstconsts.h" |
|
40 #include "mvimpstenginesubservice.h" |
|
41 #include "mvimpstenginepresencesubservice.h" |
|
42 |
|
43 #include "uiservicetabtracer.h" |
|
44 |
|
45 // Constants |
|
46 _LIT( KListNameAllBuddy ,"buddylist" ); |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // CVIMPSTCmdAddContact::CVIMPSTCmdAddContact |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 CVIMPSTCmdAddContact::CVIMPSTCmdAddContact( |
|
53 const TInt aCommandId ,const TDesC& aContactId, |
|
54 MVIMPSTEngine& aEngine) : |
|
55 iCommandId( aCommandId ), |
|
56 iContactId( aContactId ), |
|
57 iEngine(aEngine) |
|
58 { |
|
59 TRACER_AUTO; |
|
60 } |
|
61 |
|
62 // -------------------------------------------------------------------------- |
|
63 // CVIMPSTCmdAddContact::~CVIMPSTCmdAddContact |
|
64 // -------------------------------------------------------------------------- |
|
65 // |
|
66 CVIMPSTCmdAddContact::~CVIMPSTCmdAddContact() |
|
67 { |
|
68 TRACER_AUTO; |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CVIMPSTCmdAddContact::NewL |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 CVIMPSTCmdAddContact* CVIMPSTCmdAddContact::NewL( |
|
76 const TInt aCommandId,const TDesC& aContactId, |
|
77 MVIMPSTEngine& aEngine) |
|
78 { |
|
79 TRACER_AUTO; |
|
80 CVIMPSTCmdAddContact* self = new (ELeave ) CVIMPSTCmdAddContact( aCommandId ,aContactId, aEngine); |
|
81 self->ConstructL(); //use contsurctL if necessary |
|
82 return self; |
|
83 } |
|
84 // -------------------------------------------------------------------------- |
|
85 // CVIMPSTCmdAddContact::ConstructL |
|
86 // -------------------------------------------------------------------------- |
|
87 // |
|
88 void CVIMPSTCmdAddContact::ConstructL() |
|
89 { |
|
90 TRACER_AUTO; |
|
91 iError = KErrNone; |
|
92 } |
|
93 |
|
94 // -------------------------------------------------------------------------- |
|
95 // CVIMPSTCmdAddContact::ExecuteLD |
|
96 // -------------------------------------------------------------------------- |
|
97 // |
|
98 void CVIMPSTCmdAddContact::ExecuteLD() |
|
99 { |
|
100 |
|
101 TRACER_AUTO; |
|
102 //push to the cleanupstack |
|
103 CleanupStack::PushL( this ); |
|
104 MVIMPSTStorageServiceView* storage = CVIMPSTStorageManagerFactory::ContactListInterfaceL(iEngine.ServiceId()) ; |
|
105 if(storage ) |
|
106 { |
|
107 if( !IsContactBlocked(iContactId) ) |
|
108 { |
|
109 MVIMPSTStorageContact* alreadyExist = storage->FindContactByUserId( iContactId ); |
|
110 if( !alreadyExist ) |
|
111 { |
|
112 iError = KErrNone; |
|
113 MVIMPSTEngineExtentionFeatures* feature = iEngine.ExtentionFeatures(TVIMPSTEnums::EContactManagement); |
|
114 if (feature) |
|
115 { |
|
116 MVIMPSTEngineContactMgmtExtention& contactMgr = |
|
117 MVIMPSTEngineContactMgmtExtention::Cast (*feature); |
|
118 // if there is a scenario when the user enters only the firstname , then userid is null. |
|
119 //In this case don't send it to the server, Add the contact to the servicetab and |
|
120 //presence will not be visible. |
|
121 // check if contact is in the blocked list. |
|
122 // iError already exist |
|
123 if( iContactId.Length() ) |
|
124 { |
|
125 iError = contactMgr.AddServerContactL(KListNameAllBuddy,iContactId, KNullDesC() ); |
|
126 }//End if(iContactId) |
|
127 } //End if(feature) |
|
128 if(KErrNone == iError) |
|
129 { |
|
130 storage->CreateNewContactL( iContactId ); |
|
131 } |
|
132 }//End if(alreadyExist) |
|
133 else |
|
134 { |
|
135 iError = EErrExistInContactList; |
|
136 } |
|
137 } |
|
138 else |
|
139 { |
|
140 iError = EErrExistInBlockList; |
|
141 } |
|
142 }//End if(storage) |
|
143 |
|
144 |
|
145 |
|
146 if(iObserver) |
|
147 { |
|
148 iObserver->CommandFinishedL(*this); |
|
149 } |
|
150 |
|
151 CleanupStack::PopAndDestroy(); |
|
152 |
|
153 } |
|
154 |
|
155 // -------------------------------------------------------------------------- |
|
156 // CVIMPSTCmdAddContact::IsContactBlocked |
|
157 // -------------------------------------------------------------------------- |
|
158 TBool CVIMPSTCmdAddContact::IsContactBlocked(const TDesC& aUserId) |
|
159 { |
|
160 TRACER_AUTO; |
|
161 TRACE("userId: %S", &aUserId); |
|
162 MVIMPSTEngineSubService* subService = |
|
163 (iEngine.SubService(TVIMPSTEnums::EPresence)); |
|
164 if(subService) |
|
165 { |
|
166 MVIMPSTEnginePresenceSubService& presence = |
|
167 MVIMPSTEnginePresenceSubService::Cast (*subService); |
|
168 |
|
169 RPointerArray<HBufC> *blockedlist = presence .GetBlockedList(); |
|
170 |
|
171 if(blockedlist) |
|
172 { |
|
173 for(TInt i=0; i<blockedlist->Count(); ++i) |
|
174 { |
|
175 if(0 == aUserId.CompareC((*blockedlist)[i]->Des())) |
|
176 { |
|
177 return ETrue; |
|
178 } |
|
179 } |
|
180 } |
|
181 } |
|
182 return EFalse; |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CVIMPSTCmdAddContact::AddObserver |
|
187 // -------------------------------------------------------------------------- |
|
188 // |
|
189 void CVIMPSTCmdAddContact::AddObserver( MVIMPSTCmdObserver& aObserver ) |
|
190 { |
|
191 // store the observer to notify the command completion |
|
192 iObserver = &aObserver; |
|
193 } |
|
194 |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CVIMPSTCmdAddContact::CommandId |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 TInt CVIMPSTCmdAddContact::CommandId() const |
|
201 { |
|
202 return iCommandId; |
|
203 } |
|
204 |
|
205 // -------------------------------------------------------------------------- |
|
206 // CVIMPSTCmdAddContact::Result |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 TInt CVIMPSTCmdAddContact::Result() const |
|
210 { |
|
211 //return valid data regd the command operation |
|
212 return iError; |
|
213 } |
|
214 |
|
215 // End of File |
|