|
1 /* |
|
2 * Copyright (c) 2004 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: Presence Publish Level Policy which offers publish level changing and initializing |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <E32Base.h> |
|
20 |
|
21 #include "IMPSPublishLevelPolicy.h" |
|
22 #include "MIMPSSharedData.h" |
|
23 #include "CIMPSSharedDataFactory.h" |
|
24 #include "IMPSUIDDefs.h" |
|
25 #include "impspresenceconnectionuiconstsng.h" |
|
26 |
|
27 // Attribute lists support |
|
28 #include <CPEngAttributeListStore2.h> |
|
29 #include <MPEngAttributeList2.h> |
|
30 #include <MPEngPresenceAttrTypeProperties2.h> |
|
31 #include <MPEngContactList2.h> |
|
32 #include <CPEngNWSessionSlotID2.h> |
|
33 #include <PEngWVPresenceAttributes2.h> |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // IMPSPublishLevelPolicy::InitializePublishLevelL() |
|
37 // Public |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void IMPSPublishLevelPolicy::InitializePublishLevelL( CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
41 { |
|
42 |
|
43 MIMPSSharedData* sharedData = |
|
44 CIMPSSharedDataFactory::CreatePermanentKeyHandlerL( |
|
45 NULL, |
|
46 KIMPSPresenceKeyUid ); |
|
47 |
|
48 TInt newPublishLevel( 0 ); |
|
49 if ( KErrNotFound == sharedData->GetIntKey( EIMPSSharedKeysPECAppKeyNamePublishing, |
|
50 newPublishLevel ) ) |
|
51 { |
|
52 // shared data key does not exists, it means we are probably running first time |
|
53 // create key and set it to the defaul value EPECDopPrivateAndPublic |
|
54 sharedData->SetIntKey( EIMPSSharedKeysPECAppKeyNamePublishing, EPECDopPrivateAndPublic ); |
|
55 newPublishLevel = EPECDopPrivateAndPublic; |
|
56 } |
|
57 |
|
58 delete sharedData; |
|
59 // update attribute lists |
|
60 IMPSPublishLevelPolicy::UpdateAttributeListsL( newPublishLevel, aNWSessionSlotID ); |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // IMPSPublishLevelPolicy::UpdateAttributeListsL() |
|
66 // Static updater |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void IMPSPublishLevelPolicy::UpdateAttributeListsL( TInt aPublishLevel, |
|
70 CPEngNWSessionSlotID2& aNWSessionSlotID ) |
|
71 { |
|
72 |
|
73 // set new settings of the attribute lists |
|
74 CPEngAttributeListStore2* attrListFactory = |
|
75 CPEngAttributeListStore2::NewLC( aNWSessionSlotID ); |
|
76 switch ( aPublishLevel ) |
|
77 { |
|
78 case EPECDopPrivateAndPublic: |
|
79 { |
|
80 SetPrivatePublicPublishingL( *attrListFactory ); |
|
81 break; |
|
82 } |
|
83 |
|
84 case EPECDopOnlyPrivate: |
|
85 { |
|
86 SetOnlyPrivatePublishingL( *attrListFactory ); |
|
87 break; |
|
88 } |
|
89 |
|
90 case EPECDopOnlyPublic: |
|
91 { |
|
92 SetOnlyPublicPublishingL( *attrListFactory ); |
|
93 break; |
|
94 } |
|
95 |
|
96 case EPECDopOff: |
|
97 { |
|
98 SetPublishOffL( *attrListFactory ); |
|
99 break; |
|
100 } |
|
101 default: |
|
102 { |
|
103 User::Leave( KErrNotSupported ); |
|
104 } |
|
105 } |
|
106 |
|
107 CleanupStack::PopAndDestroy( attrListFactory ); // attributeFactory |
|
108 |
|
109 } |
|
110 |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // IMPSPublishLevelPolicy::SetPrivatePresenceL() |
|
114 // Value handler |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void IMPSPublishLevelPolicy::SetPrivatePresenceL( |
|
118 MPEngAttributeList2& aAttrListModel ) |
|
119 { |
|
120 aAttrListModel.AddPresenceAttributeL( KUidPrAttrUserAvailability ); |
|
121 aAttrListModel.AddPresenceAttributeL( KUidPrAttrOnlineStatus ); |
|
122 aAttrListModel.AddPresenceAttributeL( KUidPrAttrClientInfo ); |
|
123 aAttrListModel.AddPresenceAttributeL( KUidPrAttrStatusText ); |
|
124 aAttrListModel.AddPresenceAttributeL( KUidPrAttrStatusContent ); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // IMPSPublishLevelPolicy::SetPublicPresenceL() |
|
129 // Value handler |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void IMPSPublishLevelPolicy::SetPublicPresenceL( |
|
133 MPEngAttributeList2& aAttrListModel ) |
|
134 { |
|
135 aAttrListModel.AddPresenceAttributeL( KUidPrAttrUserAvailability ); |
|
136 aAttrListModel.AddPresenceAttributeL( KUidPrAttrOnlineStatus ); |
|
137 aAttrListModel.RemovePresenceAttribute( KUidPrAttrClientInfo ); |
|
138 aAttrListModel.RemovePresenceAttribute( KUidPrAttrStatusText ); |
|
139 aAttrListModel.RemovePresenceAttribute( KUidPrAttrStatusContent ); |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // PAppPublishLevelPolicy::SetNoPresence() |
|
144 // Value handler |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void IMPSPublishLevelPolicy::SetNoPresence( |
|
148 MPEngAttributeList2& aAttrListModel ) |
|
149 { |
|
150 aAttrListModel.RemovePresenceAttribute( KUidPrAttrUserAvailability ); |
|
151 aAttrListModel.RemovePresenceAttribute( KUidPrAttrOnlineStatus ); |
|
152 aAttrListModel.RemovePresenceAttribute( KUidPrAttrClientInfo ); |
|
153 aAttrListModel.RemovePresenceAttribute( KUidPrAttrStatusText ); |
|
154 aAttrListModel.RemovePresenceAttribute( KUidPrAttrStatusContent ); |
|
155 } |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // IMPSPublishLevelPolicy::SetPrivatePublicPublishingL() |
|
160 // Value handler |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void IMPSPublishLevelPolicy::SetPrivatePublicPublishingL( |
|
164 CPEngAttributeListStore2& aAttributeListFactory ) |
|
165 { |
|
166 |
|
167 // contacts of private contact list, get all presence attributes |
|
168 // default attribute lists is with default attributes |
|
169 // block lists is empty |
|
170 |
|
171 // default attr list |
|
172 UpdateDefaultAttrListL( aAttributeListFactory, SetPublicPresenceL ); |
|
173 |
|
174 // block list |
|
175 UpdateAttributeListL( aAttributeListFactory, KIMPSBlockList, SetNoPresence ); |
|
176 |
|
177 // private list |
|
178 UpdateAttributeListL( aAttributeListFactory, KIMPSPrivateList, SetPrivatePresenceL ); |
|
179 |
|
180 } |
|
181 |
|
182 |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // IMPSPublishLevelPolicy::SetOnlyPrivatePublishingL() |
|
186 // Value handler |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void IMPSPublishLevelPolicy::SetOnlyPrivatePublishingL( |
|
190 CPEngAttributeListStore2& aAttributeListFactory ) |
|
191 { |
|
192 |
|
193 // contacts of private contact list, get all presence attributes |
|
194 // default attribute lists is empty, block lists is empty |
|
195 |
|
196 // default attr list |
|
197 UpdateDefaultAttrListL( aAttributeListFactory, SetNoPresence ); |
|
198 |
|
199 // block list |
|
200 UpdateAttributeListL( aAttributeListFactory, KIMPSBlockList, SetNoPresence ); |
|
201 |
|
202 // private list |
|
203 UpdateAttributeListL( aAttributeListFactory, KIMPSPrivateList, SetPrivatePresenceL ); |
|
204 } |
|
205 |
|
206 |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // IMPSPublishLevelPolicy::SetOnlyPublicPublishingL() |
|
210 // Value handler |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void IMPSPublishLevelPolicy::SetOnlyPublicPublishingL( |
|
214 CPEngAttributeListStore2& aAttributeListFactory ) |
|
215 { |
|
216 // contacts of private contact list, get only public attributes |
|
217 // default attribute lists is set to public attributes, block lists is empty |
|
218 |
|
219 // default attr list |
|
220 UpdateDefaultAttrListL( aAttributeListFactory, SetPublicPresenceL ); |
|
221 |
|
222 // block list |
|
223 UpdateAttributeListL( aAttributeListFactory, KIMPSBlockList, SetNoPresence ); |
|
224 |
|
225 // private list |
|
226 UpdateAttributeListL( aAttributeListFactory, KIMPSPrivateList, SetPublicPresenceL ); |
|
227 } |
|
228 |
|
229 |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // IMPSPublishLevelPolicy::SetPublishOffL() |
|
233 // Value handler |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void IMPSPublishLevelPolicy::SetPublishOffL( CPEngAttributeListStore2& aAttributeListFactory ) |
|
237 { |
|
238 // all contacts shouldn't receive any presence attributes => all attribute lists without presence attributes |
|
239 |
|
240 // default attribut elist |
|
241 UpdateDefaultAttrListL( aAttributeListFactory, SetNoPresence ); |
|
242 |
|
243 // private list |
|
244 UpdateAttributeListL( aAttributeListFactory, KIMPSPrivateList, SetNoPresence ); |
|
245 |
|
246 // block list |
|
247 UpdateAttributeListL( aAttributeListFactory, KIMPSBlockList, SetNoPresence ); |
|
248 } |
|
249 |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // IMPSPublishLevelPolicy::UpdateAttributeListL() |
|
253 // Value handler |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void IMPSPublishLevelPolicy::UpdateAttributeListL( |
|
257 CPEngAttributeListStore2& aAttrLstStore, |
|
258 const TDesC& aContactList, |
|
259 TSetPresenceL aPresenceCall ) |
|
260 { |
|
261 MPEngAttributeList2* attrListModel = NULL; |
|
262 TRAPD( e , attrListModel = |
|
263 aAttrLstStore.GetAttributeListForContactListL( aContactList, |
|
264 EPEngLocalAttributeLists ) ); |
|
265 // if attribute list does not exists, create it |
|
266 if ( ( e != KErrNone ) && ( e != KErrNotFound ) ) |
|
267 { |
|
268 User::Leave( e ); |
|
269 } |
|
270 if ( e == KErrNotFound ) |
|
271 { |
|
272 // have a look in network attributes |
|
273 TRAP( e , attrListModel = |
|
274 aAttrLstStore.GetAttributeListForContactListL( aContactList, |
|
275 EPEngNetworkAttributeLists ) ); |
|
276 if ( ( e != KErrNone ) && ( e != KErrNotFound ) ) |
|
277 { |
|
278 User::Leave( e ); |
|
279 } |
|
280 if ( e == KErrNotFound ) |
|
281 { |
|
282 attrListModel = aAttrLstStore.CreateEmptyAttributeListL(); |
|
283 } |
|
284 } |
|
285 |
|
286 CleanupClosePushL( *attrListModel ); |
|
287 ( *aPresenceCall )( *attrListModel ); |
|
288 aAttrLstStore.AttachAttributeListToContactListL( aContactList, *attrListModel ); |
|
289 CleanupStack::PopAndDestroy(); // attrListModel |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // IMPSPublishLevelPolicy::UpdateDefaultAttrListL() |
|
294 // Value handler |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void IMPSPublishLevelPolicy::UpdateDefaultAttrListL( |
|
298 CPEngAttributeListStore2& aAttrLstStore, |
|
299 TSetPresenceL aPresenceCall ) |
|
300 { |
|
301 MPEngAttributeList2* attrListModel = NULL; |
|
302 TRAPD( e , attrListModel = aAttrLstStore.GetDefaultAttributeListL( EPEngLocalAttributeLists ) ); |
|
303 // if attribute list does not exists, create it |
|
304 if ( ( e != KErrNone ) && ( e != KErrNotFound ) ) |
|
305 { |
|
306 User::Leave( e ); |
|
307 } |
|
308 if ( e == KErrNotFound ) |
|
309 { |
|
310 // have a look in network attributes |
|
311 TRAPD( e , attrListModel = |
|
312 aAttrLstStore.GetDefaultAttributeListL( EPEngNetworkAttributeLists ) ); |
|
313 if ( ( e != KErrNone ) && ( e != KErrNotFound ) ) |
|
314 { |
|
315 User::Leave( e ); |
|
316 } |
|
317 if ( e == KErrNotFound ) |
|
318 { |
|
319 attrListModel = aAttrLstStore.CreateEmptyAttributeListL(); |
|
320 } |
|
321 } |
|
322 CleanupClosePushL( *attrListModel ); |
|
323 ( *aPresenceCall )( *attrListModel ); |
|
324 aAttrLstStore.SetAsDefaultAttributeListL( *attrListModel ); |
|
325 CleanupStack::PopAndDestroy(); // attrListModel |
|
326 } |
|
327 |
|
328 |
|
329 // End of File |