23
|
1 |
/*
|
|
2 |
* Copyright (c) 2008-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 of the presence handler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "cvimpstdetailspresencehandler.h"
|
|
20 |
|
|
21 |
#include "tvimpstconsts.h"
|
|
22 |
|
|
23 |
//presence cache header
|
|
24 |
#include <presencecachereader2.h> // cache reader
|
|
25 |
#include <avabilitytext.h>
|
|
26 |
|
|
27 |
// ximpfw
|
|
28 |
#include <ximpclient.h>
|
|
29 |
#include <ximpcontext.h>
|
|
30 |
#include <StringLoader.h>
|
|
31 |
#include <vimpstdetailsviewpluginrsc.rsg>
|
|
32 |
#include "uiservicetabtracer.h"
|
|
33 |
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
// NewL, two-phase construction
|
|
36 |
// ---------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CVIMPSTDetailsPresenceHandler* CVIMPSTDetailsPresenceHandler::NewL(const TDesC& aServiceName ,
|
|
39 |
MVIMPSTDetailsPresenceObserver& aObserver,
|
|
40 |
TBool aPresenceSupported )
|
|
41 |
{
|
|
42 |
CVIMPSTDetailsPresenceHandler* self= new (ELeave) CVIMPSTDetailsPresenceHandler( aObserver, aPresenceSupported );
|
|
43 |
CleanupStack::PushL(self);
|
|
44 |
self->ConstructL( aServiceName );
|
|
45 |
CleanupStack::Pop(self);
|
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
// C++ (first phase) constructor
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
CVIMPSTDetailsPresenceHandler::CVIMPSTDetailsPresenceHandler(MVIMPSTDetailsPresenceObserver& aObserver,
|
|
54 |
TBool aPresenceSupported)
|
|
55 |
: iPresenceObserver( aObserver ),
|
|
56 |
iStatus( TVIMPSTEnums::EOffline ),
|
|
57 |
iPresenceSupported( aPresenceSupported )
|
|
58 |
{
|
|
59 |
// No implementation required
|
|
60 |
}
|
|
61 |
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
// ConstructL, second phase constructor
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
void CVIMPSTDetailsPresenceHandler::ConstructL(const TDesC& aServiceName )
|
|
67 |
{
|
|
68 |
TRACER_AUTO;
|
|
69 |
iServiceName = aServiceName.AllocL();
|
|
70 |
|
|
71 |
|
|
72 |
iXIMClient = MXIMPClient::NewClientL();
|
|
73 |
//Create new sink to receive ximp context events
|
|
74 |
iPresenceContext = iXIMClient->NewPresenceContextLC();
|
|
75 |
CleanupStack::Pop(); // iPresenceContext
|
|
76 |
|
|
77 |
//initialize the presence cache.
|
|
78 |
iPresenceCacheReader = MPresenceCacheReader2::CreateReaderL();
|
|
79 |
iPresenceCacheReader->SetObserverForSubscribedNotifications(this);
|
|
80 |
iUserId = NULL;
|
|
81 |
}
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// Destructor
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
CVIMPSTDetailsPresenceHandler::~CVIMPSTDetailsPresenceHandler()
|
|
88 |
{
|
|
89 |
delete iStatusMessage;
|
|
90 |
delete iUserId;
|
|
91 |
delete iStatusText;
|
|
92 |
delete iServiceName;
|
|
93 |
delete iPresenceCacheReader;
|
|
94 |
delete iPresenceContext;
|
|
95 |
delete iXIMClient;
|
|
96 |
}
|
|
97 |
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
// CVIMPSTDetailsPresenceHandler::SubscribePresenceL
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
void CVIMPSTDetailsPresenceHandler::SubscribePresenceL(const TDesC& aUserId )
|
|
103 |
{
|
|
104 |
TRACER_AUTO;
|
|
105 |
if( iUserId )
|
|
106 |
{
|
|
107 |
delete iUserId;
|
|
108 |
iUserId = NULL;
|
|
109 |
}
|
|
110 |
iUserId = aUserId.AllocL();
|
|
111 |
iStatus = TVIMPSTEnums::EOffline;
|
|
112 |
if( !iPresenceSupported )
|
|
113 |
{
|
|
114 |
return;
|
|
115 |
}
|
|
116 |
HBufC* name = HBufC::NewLC( aUserId.Length() + iServiceName->Length() + KColon().Length() );
|
|
117 |
TPtr namePtr( name->Des() );
|
|
118 |
namePtr.Zero();
|
|
119 |
|
|
120 |
// append the service name followed by user id ,seperated by colon
|
|
121 |
namePtr.Append(*iServiceName);
|
|
122 |
namePtr.Append(KColon);
|
|
123 |
namePtr.Append(aUserId);
|
|
124 |
|
|
125 |
iPresenceCacheReader->SubscribePresenceBuddyChangeL(namePtr);
|
|
126 |
MPresenceBuddyInfo2* presenceBuddyInfo = iPresenceCacheReader->PresenceInfoLC(namePtr);
|
|
127 |
|
|
128 |
if ( presenceBuddyInfo )
|
|
129 |
{
|
|
130 |
TPtrC buddyXSPId = presenceBuddyInfo->BuddyId(); // read the buddyID : returns in XSP format
|
|
131 |
TPtrC buddyId = buddyXSPId.Right( buddyXSPId.Length() - iServiceName->Length() - KColon().Length());
|
|
132 |
// read the availability /presence state enum value
|
|
133 |
MPresenceBuddyInfo2::TAvailabilityValues availabilityEnum = presenceBuddyInfo->Availability();
|
|
134 |
TPtrC avablityText = presenceBuddyInfo->AvailabilityText();
|
|
135 |
ConvertPresenceCacheEnums( availabilityEnum ,avablityText ); // convert the presence cache enum value to service tab enum
|
|
136 |
if(TVIMPSTEnums::EUnknown == iStatus)
|
|
137 |
{
|
|
138 |
//get the blocked and pending state
|
|
139 |
GetKeyFieldsAndValuesL(*presenceBuddyInfo);
|
|
140 |
}
|
|
141 |
TPtrC statusMsg = presenceBuddyInfo->StatusMessage(); // read the status message
|
|
142 |
ProcessStatusMesssageL( statusMsg );
|
|
143 |
CleanupStack::PopAndDestroy(); // presenceBuddyInfo
|
|
144 |
}
|
|
145 |
CleanupStack::PopAndDestroy(); // name
|
|
146 |
}
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
// ---------------------------------------------------------------------------
|
|
151 |
// CVIMPSTDetailsPresenceHandler::HandlePresenceReadL
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
//
|
|
154 |
void CVIMPSTDetailsPresenceHandler::HandlePresenceReadL(TInt /*aErrorCode*/,
|
|
155 |
RPointerArray<MPresenceBuddyInfo2>& /*aPresenceBuddyInfoList*/)
|
|
156 |
{
|
|
157 |
//Not required as we are not subcribing to all buddies presence
|
|
158 |
|
|
159 |
}
|
|
160 |
|
|
161 |
// ---------------------------------------------------------------------------
|
|
162 |
// CVIMPSTDetailsPresenceHandler::HandlePresenceNotificationL
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
//
|
|
165 |
void CVIMPSTDetailsPresenceHandler::HandlePresenceNotificationL(TInt /*aErrorCode*/,
|
|
166 |
MPresenceBuddyInfo2* aPresenceBuddyInfo)
|
|
167 |
{
|
|
168 |
TRACER_AUTO;
|
|
169 |
if ( aPresenceBuddyInfo )
|
|
170 |
{
|
|
171 |
CleanupDeletePushL( aPresenceBuddyInfo );
|
|
172 |
TPtrC buddyXSPId = aPresenceBuddyInfo->BuddyId(); // read the buddyID : returns in XSP format
|
|
173 |
TPtrC buddyId = buddyXSPId.Right( buddyXSPId.Length() - iServiceName->Length() - KColon().Length());
|
|
174 |
// read the availability /presence state enum value
|
|
175 |
MPresenceBuddyInfo2::TAvailabilityValues availabilityEnum = aPresenceBuddyInfo->Availability();
|
|
176 |
TPtrC avablityText = aPresenceBuddyInfo->AvailabilityText();
|
|
177 |
// convert the presence cache enum value to service tab enum
|
|
178 |
ConvertPresenceCacheEnums( availabilityEnum ,avablityText );
|
|
179 |
|
|
180 |
// its either blocked or pending stats, hence get the corrrect state
|
|
181 |
if(TVIMPSTEnums::EUnknown == iStatus)
|
|
182 |
{
|
|
183 |
//get the blocked and pending state
|
|
184 |
GetKeyFieldsAndValuesL(*aPresenceBuddyInfo);
|
|
185 |
}
|
|
186 |
|
|
187 |
TPtrC statusMsg = aPresenceBuddyInfo->StatusMessage(); // read the status message
|
|
188 |
ProcessStatusMesssageL( statusMsg );
|
|
189 |
CleanupStack::PopAndDestroy(); // aPresenceBuddyInfo
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
// CVIMPSTDetailsPresenceHandler::ConvertPresenceCacheEnums
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
void CVIMPSTDetailsPresenceHandler::ConvertPresenceCacheEnums(MPresenceBuddyInfo2::TAvailabilityValues aAvailabilityEnum, TPtrC aAvabilityText)
|
|
198 |
{
|
|
199 |
// convert the presence cache enums to UI enumvalues
|
|
200 |
// by default if the enum doesnot match then its TVIMPSTEnums::UnKnown
|
|
201 |
switch( aAvailabilityEnum )
|
|
202 |
{
|
|
203 |
case MPresenceBuddyInfo2::EBusy:
|
|
204 |
{
|
|
205 |
if(0==aAvabilityText.Compare(KAwayState))
|
|
206 |
{
|
|
207 |
iStatus = TVIMPSTEnums::EAway;
|
|
208 |
}
|
|
209 |
else if(0==aAvabilityText.Compare(KOnPhoneState))
|
|
210 |
{
|
|
211 |
iStatus = TVIMPSTEnums::EOnPhone;
|
|
212 |
}
|
|
213 |
else if(0==aAvabilityText.Compare(KDndState))
|
|
214 |
{
|
|
215 |
iStatus = TVIMPSTEnums::EDoNotDisturb;
|
|
216 |
}
|
|
217 |
else
|
|
218 |
{
|
|
219 |
iStatus = TVIMPSTEnums::EBusy;
|
|
220 |
}
|
|
221 |
break;
|
|
222 |
}
|
|
223 |
case MPresenceBuddyInfo2::EAvailable:
|
|
224 |
{
|
|
225 |
iStatus = TVIMPSTEnums::EOnline;
|
|
226 |
break;
|
|
227 |
}
|
|
228 |
case MPresenceBuddyInfo2::ENotAvailable:
|
|
229 |
{
|
|
230 |
iStatus = TVIMPSTEnums::EOffline;
|
|
231 |
break;
|
|
232 |
}
|
|
233 |
case MPresenceBuddyInfo2::EUnknownAvailability:
|
|
234 |
{
|
|
235 |
iStatus = TVIMPSTEnums::EUnknown;
|
|
236 |
if(0==aAvabilityText.Compare(KInvisibleState))
|
|
237 |
{
|
|
238 |
iStatus = TVIMPSTEnums::EInvisible;
|
|
239 |
}
|
|
240 |
|
|
241 |
break;
|
|
242 |
}
|
|
243 |
default:
|
|
244 |
{
|
|
245 |
iStatus = TVIMPSTEnums::EOffline;
|
|
246 |
break;
|
|
247 |
}
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
// CVIMPSTDetailsPresenceHandler::ProcessStatusMesssageL
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
//
|
|
255 |
void CVIMPSTDetailsPresenceHandler::ProcessStatusMesssageL(const TDesC& aStatusMessage )
|
|
256 |
{
|
|
257 |
TRACER_AUTO;
|
|
258 |
if( iStatusMessage )
|
|
259 |
{
|
|
260 |
delete iStatusMessage ;
|
|
261 |
iStatusMessage = NULL;
|
|
262 |
}
|
|
263 |
if( aStatusMessage.Length() > 0 )
|
|
264 |
{
|
|
265 |
// MAx length of KStatusMsgMaxLength is allocated
|
|
266 |
// if status message is longer than KStatusMsgMaxLength
|
|
267 |
iStatusMessage = aStatusMessage.Left( KStatusMsgMaxLength ).AllocL();
|
|
268 |
}
|
|
269 |
iPresenceObserver.HandlePresenceChangedL();
|
|
270 |
}
|
|
271 |
|
|
272 |
// --------------------------------------------------------------------------
|
|
273 |
// CVIMPSTDetailsPresenceHandler::GetPresenceStatus
|
|
274 |
// --------------------------------------------------------------------------
|
|
275 |
//
|
|
276 |
TVIMPSTEnums::TOnlineStatus CVIMPSTDetailsPresenceHandler::GetPresenceStatus()
|
|
277 |
{
|
|
278 |
if(!iUserId)
|
|
279 |
{
|
|
280 |
return TVIMPSTEnums::EUnknown;
|
|
281 |
}
|
|
282 |
return iStatus;
|
|
283 |
}
|
|
284 |
|
|
285 |
// --------------------------------------------------------------------------
|
|
286 |
// CVIMPSTDetailsPresenceHandler::GetHeaderLabelDataL
|
|
287 |
// --------------------------------------------------------------------------
|
|
288 |
//
|
|
289 |
const TDesC& CVIMPSTDetailsPresenceHandler::GetHeaderLabelDataL( TInt aIndex )
|
|
290 |
{
|
|
291 |
TRACER_AUTO;
|
|
292 |
if( aIndex == 0 && iServiceName ) // first label data
|
|
293 |
{
|
|
294 |
return *iServiceName;
|
|
295 |
}
|
|
296 |
else if( aIndex == 2 && iPresenceSupported ) // second label data
|
|
297 |
{
|
|
298 |
return GetStatusTextL();
|
|
299 |
}
|
|
300 |
return KNullDesC; // return empty string for index 1 (label 2) for line in between the service name and presence
|
|
301 |
}
|
|
302 |
|
|
303 |
// --------------------------------------------------------------------------
|
|
304 |
// CVIMPSTDetailsPresenceHandler::GetStatusMessageL
|
|
305 |
// --------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
const TDesC& CVIMPSTDetailsPresenceHandler::GetStatusMessageL()
|
|
308 |
{
|
|
309 |
TRACER_AUTO;
|
|
310 |
if( iStatusMessage && iStatusMessage->Length() )
|
|
311 |
{
|
|
312 |
return *iStatusMessage;
|
|
313 |
}
|
|
314 |
return GetStatusTextL();
|
|
315 |
}
|
|
316 |
|
|
317 |
|
|
318 |
// --------------------------------------------------------------------------
|
|
319 |
// CVIMPSTDetailsPresenceHandler::IsSupported
|
|
320 |
// --------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
TBool CVIMPSTDetailsPresenceHandler::IsSupported() const
|
|
323 |
{
|
|
324 |
return iPresenceSupported;
|
|
325 |
}
|
|
326 |
// --------------------------------------------------------------------------
|
|
327 |
// CVIMPSTDetailsPresenceHandler::GetStatusTextL
|
|
328 |
// --------------------------------------------------------------------------
|
|
329 |
//
|
|
330 |
const TDesC& CVIMPSTDetailsPresenceHandler::GetStatusTextL()
|
|
331 |
{
|
|
332 |
TRACER_AUTO;
|
|
333 |
TInt resourceId = R_SERVDETAIL_STATUSTEXT_OFFLINE;
|
|
334 |
|
|
335 |
switch( iStatus )
|
|
336 |
{
|
|
337 |
case TVIMPSTEnums::EOffline:
|
|
338 |
{
|
|
339 |
resourceId = R_SERVDETAIL_STATUSTEXT_OFFLINE;
|
|
340 |
break;
|
|
341 |
}
|
|
342 |
case TVIMPSTEnums::EBusy:
|
|
343 |
{
|
|
344 |
resourceId = R_SERVDETAIL_STATUSTEXT_BUSY;
|
|
345 |
break;
|
|
346 |
}
|
|
347 |
case TVIMPSTEnums::EOnline:
|
|
348 |
{
|
|
349 |
resourceId = R_SERVDETAIL_STATUSTEXT_ONLINE;
|
|
350 |
break;
|
|
351 |
}
|
|
352 |
case TVIMPSTEnums::EInvisible:
|
|
353 |
{
|
|
354 |
resourceId = R_SERVDETAIL_STATUSTEXT_DND;
|
|
355 |
break;
|
|
356 |
}
|
|
357 |
case TVIMPSTEnums::EOnPhone:
|
|
358 |
{
|
|
359 |
resourceId = R_SERVDETAIL_STATUSTEXT_ONTHEPHONE;
|
|
360 |
break;
|
|
361 |
}
|
|
362 |
case TVIMPSTEnums::EDoNotDisturb:
|
|
363 |
{
|
|
364 |
resourceId = R_SERVDETAIL_STATUSTEXT_DND;
|
|
365 |
break;
|
|
366 |
}
|
|
367 |
case TVIMPSTEnums::EAway:
|
|
368 |
{
|
|
369 |
resourceId = R_SERVDETAIL_STATUSTEXT_AWAY;
|
|
370 |
break;
|
|
371 |
}
|
|
372 |
case TVIMPSTEnums::EBlocked:
|
|
373 |
{
|
|
374 |
resourceId = R_SERVDETAIL_STATUSTEXT_BLOCKED;
|
|
375 |
break;
|
|
376 |
}
|
|
377 |
case TVIMPSTEnums::EPending:
|
|
378 |
{
|
|
379 |
resourceId = R_SERVDETAIL_STATUSTEXT_PENDING;
|
|
380 |
break;
|
|
381 |
}
|
|
382 |
case TVIMPSTEnums::ECallForward:
|
|
383 |
{
|
|
384 |
resourceId = R_SERVDETAIL_STATUSTEXT_CALLFORWARD;
|
|
385 |
break;
|
|
386 |
}
|
|
387 |
case TVIMPSTEnums::EUnknown:
|
|
388 |
case TVIMPSTEnums::EServiceOut:
|
|
389 |
default:
|
|
390 |
{
|
|
391 |
break;
|
|
392 |
}
|
|
393 |
}
|
|
394 |
if( iStatusText )
|
|
395 |
{
|
|
396 |
delete iStatusText;
|
|
397 |
iStatusText = NULL;
|
|
398 |
}
|
|
399 |
|
|
400 |
if( CCoeEnv::Static() && TVIMPSTEnums::EServiceOut != iStatus
|
|
401 |
&& TVIMPSTEnums::EUnknown != iStatus )
|
|
402 |
{
|
|
403 |
iStatusText = StringLoader::LoadL( resourceId );
|
|
404 |
}
|
|
405 |
if( iStatusText )
|
|
406 |
{
|
|
407 |
return *iStatusText;
|
|
408 |
}
|
|
409 |
return KNullDesC;
|
|
410 |
}
|
|
411 |
|
|
412 |
// ---------------------------------------------------------------------------
|
|
413 |
// CVIMPSTDetailsPresenceHandler::GetKeyFieldsAndValuesL
|
|
414 |
// ---------------------------------------------------------------------------
|
|
415 |
//
|
|
416 |
void CVIMPSTDetailsPresenceHandler::GetKeyFieldsAndValuesL(MPresenceBuddyInfo2& aPresenceBuddyInfo)
|
|
417 |
{
|
|
418 |
TRACER_AUTO;
|
|
419 |
// At any point of time fro remote and blocked contact only one of the keys
|
|
420 |
// KPendingRequestExtensionValue/KBlockedExtensionValue will be assigned, and not both the keys.
|
|
421 |
TPtrC8 value = aPresenceBuddyInfo.GetAnyField( KExtensionKey() ) ;
|
|
422 |
if(value.Compare( KPendingRequestExtensionValue ) == 0)
|
|
423 |
{
|
|
424 |
iStatus = TVIMPSTEnums::EPending;
|
|
425 |
}
|
|
426 |
else if(value.Compare( KBlockedExtensionValue ) == 0)
|
|
427 |
{
|
|
428 |
iStatus = TVIMPSTEnums::EBlocked;
|
|
429 |
}
|
|
430 |
else if(value.Compare( KServiceExtensionValue ) == 0)
|
|
431 |
{
|
|
432 |
iStatus = TVIMPSTEnums::EServiceOut;
|
|
433 |
}
|
|
434 |
else if(value.Compare( KCallForwardExtensionValue ) == 0)
|
|
435 |
{
|
|
436 |
iStatus = TVIMPSTEnums::ECallForward;
|
|
437 |
}
|
|
438 |
else
|
|
439 |
{
|
|
440 |
iStatus = TVIMPSTEnums::EOffline;
|
|
441 |
}
|
|
442 |
}
|
|
443 |
|
|
444 |
// end of file
|
|
445 |
|
|
446 |
|
|
447 |
|