|
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: Store object for single buddy in a service |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpresencebuddyinfo2.h> |
|
20 |
|
21 #include "presencecachebuddystore.h" |
|
22 #include "presencecacheservicestore.h" |
|
23 #include "presencecachesession.h" |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CPresenceCacheBuddyStore::NewLC() |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CPresenceCacheBuddyStore* CPresenceCacheBuddyStore::NewLC( |
|
30 CPresenceCacheServiceStore* aServiceStore, |
|
31 const TDesC& aIdentity) |
|
32 { |
|
33 CPresenceCacheBuddyStore* self = new( ELeave ) CPresenceCacheBuddyStore( |
|
34 aServiceStore); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(aIdentity); |
|
37 return self; |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CPresenceCacheBuddyStore::NewL() |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C CPresenceCacheBuddyStore* CPresenceCacheBuddyStore::NewL( |
|
45 CPresenceCacheServiceStore* aServiceStore, |
|
46 const TDesC& aIdentity) |
|
47 { |
|
48 CPresenceCacheBuddyStore* self = NewLC(aServiceStore,aIdentity); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CPresenceCacheBuddyStore::~CPresenceCacheBuddyStore() |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CPresenceCacheBuddyStore::~CPresenceCacheBuddyStore() |
|
58 { |
|
59 if (iPresenceBuddyInfo) |
|
60 delete iPresenceBuddyInfo; |
|
61 if(iIdentity) |
|
62 delete iIdentity; |
|
63 iSubscribedSessions.Close(); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CPresenceCacheBuddyStore::CPresenceCacheBuddyStore() |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CPresenceCacheBuddyStore::CPresenceCacheBuddyStore( |
|
71 CPresenceCacheServiceStore* aServiceStore):iPresenceBuddyInfo(NULL), |
|
72 iServiceStore(aServiceStore) |
|
73 { |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CPresenceCacheBuddyStore::ConstructL() |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CPresenceCacheBuddyStore::ConstructL(const TDesC& aIdentity) |
|
81 { |
|
82 iIdentity = aIdentity.AllocL(); |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CPresenceCacheBuddyStore::SetPresenceBuddyInfo() |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CPresenceCacheBuddyStore::SetPresenceBuddyInfo(MPresenceBuddyInfo2* aPresBuddyInfo) |
|
90 { |
|
91 delete iPresenceBuddyInfo; |
|
92 iPresenceBuddyInfo = aPresBuddyInfo; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CPresenceCacheBuddyStore::RemovePresenceBuddyInfo() |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CPresenceCacheBuddyStore::RemovePresenceBuddyInfo() |
|
100 { |
|
101 if (iPresenceBuddyInfo) |
|
102 delete iPresenceBuddyInfo; |
|
103 iPresenceBuddyInfo = NULL; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CPresenceCacheBuddyStore::GetSubscribedSessions() |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 RPointerArray<CPresenceCacheSession>& CPresenceCacheBuddyStore::GetSubscribedSessions() |
|
111 { |
|
112 return iSubscribedSessions; |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CPresenceCacheBuddyStore::AddSubscribedSession() |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CPresenceCacheBuddyStore::AddSubscribedSession(CPresenceCacheSession* aSession) |
|
120 { |
|
121 if(iSubscribedSessions.Find(aSession)<0) |
|
122 iSubscribedSessions.Append(aSession); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CPresenceCacheBuddyStore::RemoveSubscribedSession() |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CPresenceCacheBuddyStore::RemoveSubscribedSession(CPresenceCacheSession* aSession) |
|
130 { |
|
131 TInt index = iSubscribedSessions.Find(aSession); |
|
132 if(index>-1) |
|
133 iSubscribedSessions.Remove(index); |
|
134 |
|
135 // delete this object if it doesnt have any presence or subscribers |
|
136 if(!(iPresenceBuddyInfo || HasSubscribers())) |
|
137 { |
|
138 if(iServiceStore) |
|
139 { |
|
140 iServiceStore->RemoveBlind(this); |
|
141 } |
|
142 } |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // CPresenceCacheBuddyStore::SetBuddyId() |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 void CPresenceCacheBuddyStore::SetBuddyIdL(const TDesC& aIdentity) |
|
150 { |
|
151 delete iIdentity; |
|
152 iIdentity = NULL; |
|
153 iIdentity = aIdentity.AllocL(); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CPresenceCacheBuddyStore::ServiceName() |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TPtrC CPresenceCacheBuddyStore::ServiceName() const |
|
161 { |
|
162 _LIT(KColon, ":"); |
|
163 TInt pos = 0; |
|
164 if ( iIdentity ) |
|
165 { |
|
166 pos = iIdentity->Des().Find(KColon); |
|
167 } |
|
168 TPtrC serviceName; |
|
169 if(pos>0) // if colon found and there is something before colon, i.e. xsp id |
|
170 { |
|
171 serviceName.Set( iIdentity->Des().Left(pos) ); |
|
172 } |
|
173 else |
|
174 serviceName.Set(TPtrC()); |
|
175 return serviceName; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CPresenceCacheBuddyStore::PresenceBuddyInfo() |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 MPresenceBuddyInfo2* CPresenceCacheBuddyStore::PresenceBuddyInfo() const |
|
183 { |
|
184 return iPresenceBuddyInfo; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CPresenceCacheBuddyStore::BuddyId() |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 TPtrC CPresenceCacheBuddyStore::BuddyId() const |
|
192 { |
|
193 return iIdentity ? iIdentity->Des() : TPtrC(); |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CPresenceCacheBuddyStore::EqualsIdentity() |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 TBool CPresenceCacheBuddyStore::EqualsIdentity( |
|
201 const CPresenceCacheBuddyStore* aOtherInstance ) const |
|
202 { |
|
203 TBool ret(EFalse); |
|
204 if(aOtherInstance) |
|
205 { |
|
206 ret = 0 == BuddyId().CompareF( aOtherInstance->BuddyId() ); |
|
207 } |
|
208 return ret; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CPresenceCacheBuddyStore::EqualsIdentity() |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 TBool CPresenceCacheBuddyStore::EqualsIdentity( |
|
216 const MPresenceBuddyInfo2* aOtherInstance ) const |
|
217 { |
|
218 TBool ret(EFalse); |
|
219 if(aOtherInstance) |
|
220 { |
|
221 ret = 0 == BuddyId().CompareF( aOtherInstance->BuddyId() ); |
|
222 } |
|
223 return ret; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CPresenceCacheBuddyStore::EqualsIdentity() |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 TBool CPresenceCacheBuddyStore::EqualsIdentity( |
|
231 const TDesC& aOtherIdentity ) const |
|
232 { |
|
233 return 0 == BuddyId().CompareF( aOtherIdentity ); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // CPresenceCacheBuddyStore::HasPresence() |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 TBool CPresenceCacheBuddyStore::HasPresence() const |
|
241 { |
|
242 if (iPresenceBuddyInfo) |
|
243 return ETrue; |
|
244 return EFalse; |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CPresenceCacheBuddyStore::HasSubscribers() |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 TBool CPresenceCacheBuddyStore::HasSubscribers() const |
|
252 { |
|
253 if (iSubscribedSessions.Count()) |
|
254 return ETrue; |
|
255 return EFalse; |
|
256 } |
|
257 |