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