|
1 /* |
|
2 * Copyright (c) 2009 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: Status provider |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "spbstatusprovider.h" |
|
20 #include "spbcontent.h" |
|
21 |
|
22 #include <presencecachereader2.h> |
|
23 #include <mpresencebuddyinfo2.h> |
|
24 #include <presencecachebuddyidcreator.h> |
|
25 |
|
26 // --------------------------------------------------------------------------- |
|
27 // CSpbStatusProvider::NewL |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CSpbStatusProvider* CSpbStatusProvider::NewL( |
|
31 RPointerArray<CSpbContent>& aContentCache) |
|
32 { |
|
33 CSpbStatusProvider* self = new (ELeave) CSpbStatusProvider(aContentCache); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CSpbStatusProvider::CSpbStatusProvider |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 inline CSpbStatusProvider::CSpbStatusProvider( |
|
45 RPointerArray<CSpbContent>& aContentCache ) : |
|
46 iContentCache(aContentCache) |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CSpbStatusProvider::ConstructL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 inline void CSpbStatusProvider::ConstructL() |
|
55 { |
|
56 iPresenceCache = MPresenceCacheReader2::CreateReaderL(); |
|
57 iPresenceCache->SetObserverForSubscribedNotifications( this ); |
|
58 iBuddyIdCreator = CPresenceCacheBuddyIdCreator::NewL( ); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CSpbStatusProvider::~CSpbStatusProvider |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CSpbStatusProvider::~CSpbStatusProvider() |
|
66 { |
|
67 delete iBuddyIdCreator; |
|
68 delete iPresenceCache; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CSpbStatusProvider::FindContentByBuddyId |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CSpbContent* CSpbStatusProvider::FindContentByBuddyId( |
|
76 const TDesC& aBuddyId) |
|
77 { |
|
78 const TInt count(iContentCache.Count()); |
|
79 for( TInt i = 0 ; i < count ; ++i ) |
|
80 { |
|
81 CSpbContent* content = iContentCache[i]; |
|
82 if(content->Match(aBuddyId)) |
|
83 { |
|
84 return content; |
|
85 } |
|
86 } |
|
87 return NULL; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // CSpbStatusProvider::NotifyChangeEventL |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CSpbStatusProvider::NotifyChangeEventL( |
|
95 MPresenceBuddyInfo2& aBuddyInfo, |
|
96 CSpbContent& aContent) |
|
97 { |
|
98 // Check status text |
|
99 TPtrC statusMessage(aBuddyInfo.StatusMessage()); |
|
100 // Check service icon |
|
101 TPtrC8 brandingID( |
|
102 aBuddyInfo.GetAnyField( NPresenceCacheFieldName::KServiceIconBrand)); |
|
103 TPtrC8 iconEntry( |
|
104 aBuddyInfo.GetAnyField( NPresenceCacheFieldName::KServiceIconId)); |
|
105 aContent.StatusDataUpdatedL(statusMessage, brandingID, iconEntry); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CSpbStatusProvider::FetchStatusDataL |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 void CSpbStatusProvider::FetchStatusDataL( CSpbContent& aContent ) |
|
113 { |
|
114 HBufC8* linkbuf = aContent.Link().PackLC(); |
|
115 HBufC* buddyId = iBuddyIdCreator->CreateBuddyIdLC( *linkbuf ); |
|
116 aContent.SetBuddyId( buddyId ); // takes ownership |
|
117 CleanupStack::Pop( buddyId ); |
|
118 CleanupStack::PopAndDestroy( linkbuf ); |
|
119 |
|
120 iPresenceCache->SubscribePresenceBuddyChangeL(*buddyId); |
|
121 |
|
122 MPresenceBuddyInfo2* buddyInfo = iPresenceCache->PresenceInfoLC(*buddyId); |
|
123 if(buddyInfo) |
|
124 { |
|
125 NotifyChangeEventL(*buddyInfo,aContent); |
|
126 CleanupStack::PopAndDestroy(); // buddyInfo |
|
127 } |
|
128 else |
|
129 { |
|
130 aContent.StatusDataUpdatedL(KNullDesC, KNullDesC8, KNullDesC8); |
|
131 } |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CSpbStatusProvider::HandlePresenceReadL |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CSpbStatusProvider::HandlePresenceReadL( |
|
139 TInt /*aErrorCode*/, |
|
140 RPointerArray<MPresenceBuddyInfo2>& /*aPresenceBuddyInfoList*/ ) |
|
141 { |
|
142 // Not used |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CSpbStatusProvider::HandlePresenceNotificationL |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CSpbStatusProvider::HandlePresenceNotificationL( |
|
150 TInt aErrorCode, |
|
151 MPresenceBuddyInfo2* aPresenceBuddyInfo ) |
|
152 { |
|
153 CleanupDeletePushL( aPresenceBuddyInfo ); |
|
154 |
|
155 if( KErrNone == aErrorCode && aPresenceBuddyInfo ) |
|
156 { |
|
157 CSpbContent* content = |
|
158 FindContentByBuddyId( aPresenceBuddyInfo->BuddyId() ); |
|
159 if( content ) |
|
160 { |
|
161 NotifyChangeEventL( *aPresenceBuddyInfo,*content ); |
|
162 } |
|
163 } |
|
164 |
|
165 CleanupStack::PopAndDestroy(); // aPresenceBuddyInfo |
|
166 } |
|
167 |
|
168 |
|
169 // end of file |