|
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: s_vimpstengineavatarextention.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cvimpstengineavatarextention.h" |
|
20 |
|
21 #include <ximprequestcompleteevent.h> |
|
22 #include <PresenceObjectFactory.h> |
|
23 #include <presencefeatures.h> |
|
24 |
|
25 #include <presencepublishing.h> |
|
26 #include <personpresenceinfo.h> |
|
27 #include <presenceinfofield.h> |
|
28 #include <presenceinfofieldcollection.h> |
|
29 #include <presenceinfofieldvaluebinary.h> |
|
30 #include <ximpstatus.h> |
|
31 #include <presenceinfo.h> |
|
32 |
|
33 #include "cvimpstenginerequestmapper.h" |
|
34 #include "cvimpstenginerequest.h" |
|
35 #include "vimpstdebugprint.h" |
|
36 #include "tvimpstenums.h" |
|
37 |
|
38 |
|
39 #include "vimpstallerrors.h" |
|
40 #include "tvimpstconsts.h" |
|
41 |
|
42 #include "cvimpstsettingsstore.h" // settings store in cenrep used for own avatar data |
|
43 #include "imconnectionproviderconsts.h" |
|
44 |
|
45 // ================= MEMBER FUNCTIONS ======================= |
|
46 // --------------------------------------------------------- |
|
47 // CVIMPSTEngineAvatarExtention::NewL |
|
48 // Two-phased constructor. |
|
49 // --------------------------------------------------------- |
|
50 CVIMPSTEngineAvatarExtention* CVIMPSTEngineAvatarExtention::NewL( |
|
51 TInt aServiceId, |
|
52 MPresenceFeatures& aFeatures, |
|
53 CVIMPSTEngineRequestMapper& aRequestMapper) |
|
54 { |
|
55 CHAT_DP_FUNC_ENTER("CVIMPSTEngineAvatarExtention::NewL"); |
|
56 CVIMPSTEngineAvatarExtention* self = |
|
57 CVIMPSTEngineAvatarExtention::NewLC( aServiceId, aFeatures, |
|
58 aRequestMapper |
|
59 ); |
|
60 CleanupStack::Pop( self ); |
|
61 CHAT_DP_FUNC_DONE("CVIMPSTEngineAvatarExtention::NewL"); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CVIMPSTEngineAvatarExtention::NewLC |
|
67 // Two-phased constructor. |
|
68 // --------------------------------------------------------- |
|
69 CVIMPSTEngineAvatarExtention* CVIMPSTEngineAvatarExtention::NewLC( |
|
70 TInt aServiceId, |
|
71 MPresenceFeatures& aFeatures, |
|
72 CVIMPSTEngineRequestMapper& aRequestMapper) |
|
73 { |
|
74 CHAT_DP_FUNC_ENTER("CVIMPSTEngineAvatarExtention::NewLC"); |
|
75 CVIMPSTEngineAvatarExtention* self = new (ELeave) |
|
76 CVIMPSTEngineAvatarExtention(aServiceId, aFeatures,aRequestMapper); |
|
77 CleanupStack::PushL( self ); |
|
78 |
|
79 CHAT_DP_FUNC_DONE("CVIMPSTEngineAvatarExtention::NewLC"); |
|
80 return self; |
|
81 } |
|
82 |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CVIMPSTEngineAvatarExtention::CVIMPSTEngineAvatarExtention |
|
86 // --------------------------------------------------------- |
|
87 CVIMPSTEngineAvatarExtention::CVIMPSTEngineAvatarExtention( |
|
88 TInt aServiceId, |
|
89 MPresenceFeatures& aFeatures, |
|
90 CVIMPSTEngineRequestMapper& aRequestMapper) |
|
91 : |
|
92 iServiceId(aServiceId), |
|
93 iFeatures(aFeatures), |
|
94 iRequestMapper(aRequestMapper), |
|
95 iSupported(TVIMPSTEnums::ESupportUnKnown) |
|
96 { |
|
97 |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // CVIMPSTEngineAvatarExtention::~CVIMPSTEngineAvatarExtention |
|
102 // --------------------------------------------------------- |
|
103 CVIMPSTEngineAvatarExtention::~CVIMPSTEngineAvatarExtention() |
|
104 { |
|
105 CHAT_DP_FUNC_ENTER("CVIMPSTEngineAvatarExtention::~CVIMPSTEngineAvatarExtention"); |
|
106 |
|
107 CHAT_DP_FUNC_DONE("CVIMPSTEngineAvatarExtention::~CVIMPSTEngineAvatarExtention"); |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CVIMPSTEngineAvatarExtention::IsSupported() |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 TVIMPSTEnums::FeatureSupport CVIMPSTEngineAvatarExtention::IsSupported() const |
|
116 { |
|
117 return iSupported; |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CVIMPSTEngineAvatarExtention::Type() |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TVIMPSTEnums::ExtentionType CVIMPSTEngineAvatarExtention::Type() const |
|
126 { |
|
127 return TVIMPSTEnums::EAvatar; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CVIMPSTEngineAvatarExtention::UpdateAvtarToServerL |
|
132 // |
|
133 // --------------------------------------------------------- |
|
134 TInt CVIMPSTEngineAvatarExtention::UpdateAvtarToServerL(const TDesC& aFilename, const TDesC8& aMimetype) |
|
135 { |
|
136 TInt error = KErrNone; |
|
137 HBufC8* avatarContent = NULL; |
|
138 if ( aFilename.Length()) |
|
139 { |
|
140 CVIMPSTEngineImageHandler* imageHandler = CVIMPSTEngineImageHandler::NewL(); |
|
141 CleanupStack::PushL(imageHandler); |
|
142 // get the avatar content from the image processor |
|
143 // returns image content if the processing succesful |
|
144 avatarContent = imageHandler->ProcessImageFromFileL( aFilename , aMimetype); |
|
145 if ( !avatarContent ) |
|
146 { |
|
147 // some problem in the image processing , so set as general error |
|
148 error = KErrGeneral; |
|
149 } |
|
150 CleanupStack::PopAndDestroy(imageHandler); // imageHandler |
|
151 } |
|
152 // if there is no error in processing or to set default avatar |
|
153 if( ! error) |
|
154 { |
|
155 MPresencePublishing& publisher = iFeatures.PresencePublishing(); |
|
156 MPresenceInfo* myPresence = iFeatures.PresenceObjectFactory().NewPresenceInfoLC();//1 |
|
157 MPersonPresenceInfo *PersonPresence = iFeatures.PresenceObjectFactory().NewPersonPresenceInfoLC();//2 |
|
158 MPresenceInfoFieldCollection& attributeFields = PersonPresence->Fields(); |
|
159 MPresenceInfoField* infoField = iFeatures.PresenceObjectFactory().NewInfoFieldLC();//3 |
|
160 MPresenceInfoFieldValueBinary* avatarField = iFeatures.PresenceObjectFactory().NewBinaryInfoFieldLC();//4 |
|
161 // "avatar" attribute |
|
162 |
|
163 if(avatarContent) |
|
164 { |
|
165 avatarField->SetBinaryValueL(*avatarContent); |
|
166 } |
|
167 else |
|
168 { |
|
169 // this is to clear the avatar |
|
170 avatarField->SetBinaryValueL(KNullDesC8); |
|
171 } |
|
172 // Take handles to object factory and publish interface |
|
173 |
|
174 CleanupStack::Pop(); // (4)avatarField, pop before passing the ownership to infofiled |
|
175 |
|
176 //Fill presence doc with presence components and attributes |
|
177 infoField->SetFieldTypeL( NPresenceInfo::NFieldType::KAvatar ); |
|
178 // for clear avatar mimetye is KNUllDesc so set for all the cases |
|
179 avatarField->SetMimeTypeL(aMimetype); |
|
180 infoField->SetFieldValue( avatarField ); |
|
181 CleanupStack::Pop(); // (3)infoField ownership is passed to attributeFields |
|
182 |
|
183 attributeFields.AddOrReplaceFieldL(infoField );// |
|
184 CleanupStack::Pop(); // (2)PersonPresence, as ownership is transfered to mypresence |
|
185 |
|
186 myPresence->SetPersonPresenceL(PersonPresence); |
|
187 TXIMPRequestId reqId = publisher.PublishOwnPresenceL( *myPresence ); |
|
188 // wait completion |
|
189 iRequestMapper.CreateRequestL(reqId, ETrue, EVIMPSTXimpOperationSetAvatar ); |
|
190 if( !iReqResult ) |
|
191 { |
|
192 // singleton object owned by tabbedview : dont delete |
|
193 MVIMPSTSettingsStore* store = CVIMPSTSettingsStoreFactory ::NewL(); |
|
194 if(avatarContent) |
|
195 { |
|
196 error = store->SetL(iServiceId ,EServiceAvatar ,*avatarContent); |
|
197 } |
|
198 else |
|
199 { |
|
200 error = store->SetL(iServiceId ,EServiceAvatar ,KNullDesC8); |
|
201 } |
|
202 } |
|
203 else |
|
204 { |
|
205 error = iReqResult; |
|
206 } |
|
207 |
|
208 CleanupStack::Pop(); // (1) myPresence |
|
209 |
|
210 delete avatarContent; |
|
211 avatarContent = NULL; |
|
212 } |
|
213 // return the error |
|
214 return error; |
|
215 } |
|
216 |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CVIMPSTEngineAvatarExtention::HandleSessionContextEventL |
|
220 // --------------------------------------------------------- |
|
221 void CVIMPSTEngineAvatarExtention::HandleSessionContextEventL(const MXIMPContext& /*aContext*/, |
|
222 const MXIMPBase& aEvent, |
|
223 TXimpOperation aXimpOperation /*= EVIMPSTXimpOperationNoOperation*/ ) |
|
224 { |
|
225 |
|
226 CHAT_DP_FUNC_ENTER("CVIMPSTEngineAvatarExtention::HandleSessionContextEventL"); |
|
227 |
|
228 switch( aEvent.GetInterfaceId() ) |
|
229 { |
|
230 case MXIMPRequestCompleteEvent::KInterfaceId: |
|
231 { |
|
232 CHAT_DP_FUNC_ENTER("InsideCallbackswitch::MXIMPRequestCompleteEvent"); |
|
233 if (EVIMPSTXimpOperationSetAvatar == aXimpOperation) |
|
234 { |
|
235 const MXIMPRequestCompleteEvent* event = |
|
236 TXIMPGetInterface< const MXIMPRequestCompleteEvent >::From( |
|
237 aEvent, MXIMPBase::EPanicIfUnknown ); |
|
238 |
|
239 iReqResult = event->CompletionResult().ResultCode(); |
|
240 const TXIMPRequestId& reqId = event->RequestId(); |
|
241 CVIMPSTEngineRequest *req = iRequestMapper.FindRequestId( reqId ); |
|
242 |
|
243 if ( req ) |
|
244 { |
|
245 req->StopWait() ; |
|
246 iRequestMapper.RemoveRequestId(reqId); |
|
247 delete req; |
|
248 } |
|
249 } |
|
250 break; |
|
251 } |
|
252 |
|
253 default: |
|
254 { |
|
255 break; |
|
256 } |
|
257 } |
|
258 CHAT_DP_FUNC_DONE("CVIMPSTEngineAvatarExtention::HandleSessionContextEventL"); |
|
259 } |
|
260 |
|
261 //---------------------------------------------------------------------------- |
|
262 // CVIMPSTEngineAvatarExtention::SetSupported() |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CVIMPSTEngineAvatarExtention::SetSupported(TVIMPSTEnums::FeatureSupport aSupported) |
|
266 { |
|
267 iSupported = aSupported; |
|
268 } |
|
269 |
|
270 // end of file |