|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Capsulating store rule |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32std.h> |
|
25 #include <s32mem.h> |
|
26 #include "cmmediaserver.h" |
|
27 #include "cmstorerule.h" |
|
28 #include "msdebug.h" |
|
29 |
|
30 // CONSTANTS |
|
31 const TInt KArrayGranularity = 16; |
|
32 const TInt KArrayGranularityContainer = 8; |
|
33 |
|
34 // ======== LOCAL FUNCTIONS ======== |
|
35 // --------------------------------------------------------------------------- |
|
36 // NewL |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CCmStoreRule* CCmStoreRule::NewL() |
|
40 { |
|
41 CCmStoreRule* self = CCmStoreRule::NewLC(); |
|
42 CleanupStack::Pop( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // NewLC |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CCmStoreRule* CCmStoreRule::NewLC() |
|
51 { |
|
52 CCmStoreRule* self = new ( ELeave ) CCmStoreRule(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // Destructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C CCmStoreRule::~CCmStoreRule() |
|
63 { |
|
64 delete iName; |
|
65 |
|
66 iRuleDefs.Reset(); |
|
67 iRuleDefs.Close(); |
|
68 |
|
69 iMediaServers.ResetAndDestroy(); |
|
70 iMediaServers.Close(); |
|
71 |
|
72 iExcPlayLists->Reset(); |
|
73 iExcAlbums->Reset(); |
|
74 |
|
75 delete iExcPlayLists; |
|
76 delete iExcAlbums; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Add new rule into StoreRule |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 EXPORT_C TInt CCmStoreRule::AddStoreRuleL( TCmMediaType aMediaType ) |
|
84 { |
|
85 iRuleDefs.AppendL( aMediaType ); |
|
86 TInt index = iRuleDefs.Count() - 1; |
|
87 return index; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Get rule |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C void CCmStoreRule::StoreRule( TInt aIndex, TCmMediaType* aMediaType ) |
|
95 { |
|
96 *aMediaType = (TCmMediaType)iRuleDefs[aIndex]; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Add new media server into FillRule |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 EXPORT_C TInt CCmStoreRule::AddMediaServerL( const TDesC8& aUDN ) |
|
104 { |
|
105 CCmMediaServer* server = CCmMediaServer::NewLC(); |
|
106 server->SetUDNL( aUDN ); |
|
107 iMediaServers.Append( server ); |
|
108 CleanupStack::Pop( server ); |
|
109 TInt index = iMediaServers.Count() - 1; |
|
110 return index; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // Delete media server from the store rule |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C void CCmStoreRule::DeleteMediaServer( const TDesC8& aUDN ) |
|
118 { |
|
119 TBool deleted( EFalse ); |
|
120 for( TInt i = 0; i < iMediaServers.Count() && !deleted; i++ ) |
|
121 { |
|
122 if( KErrNone == iMediaServers[i]->MediaServer().Compare(aUDN) ) |
|
123 { |
|
124 delete iMediaServers[i]; |
|
125 iMediaServers.Remove(i); |
|
126 iMediaServers.Compress(); |
|
127 deleted = ETrue; |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // Adds one album into excluded list |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C void CCmStoreRule::AddExcAlbumL( const TDesC& aAlbum ) |
|
137 { |
|
138 TRACE(Print(_L("[COMMON]\t AddExcAlbumL( %S )"), &aAlbum )); |
|
139 HBufC* temp = aAlbum.AllocL(); |
|
140 CleanupStack::PushL( temp ); |
|
141 iExcAlbums->AppendL( *temp ); |
|
142 CleanupStack::Pop( temp ); |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // Adds one playlist into excluded list |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 EXPORT_C void CCmStoreRule::AddExcPlayListL( const TDesC& aPlayList ) |
|
150 { |
|
151 HBufC* temp = aPlayList.AllocL(); |
|
152 CleanupStack::PushL( temp ); |
|
153 iExcPlayLists->AppendL( *temp ); |
|
154 CleanupStack::Pop( temp ); |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Removes one album from the excluded list |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 EXPORT_C void CCmStoreRule::RemoveExcAlbum( const TDesC& aAlbum ) |
|
162 { |
|
163 TInt pos( KErrNone ); |
|
164 TInt err( iExcAlbums->Find( aAlbum, pos, ECmpNormal ) ); |
|
165 if( err == KErrNone ) |
|
166 { |
|
167 iExcAlbums->Delete( pos ); |
|
168 iExcAlbums->Compress(); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // Removes one playlist from the excluded list |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C void CCmStoreRule::RemoveExcPlayList( const TDesC& aPlayList ) |
|
177 { |
|
178 TInt pos( KErrNone ); |
|
179 TInt err( iExcPlayLists->Find( aPlayList, pos, ECmpNormal ) ); |
|
180 if( err == KErrNone ) |
|
181 { |
|
182 iExcPlayLists->Delete( pos ); |
|
183 iExcPlayLists->Compress(); |
|
184 } |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // Returns excluded albums |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C CDesCArray& CCmStoreRule::ExcAlbums() |
|
192 { |
|
193 return *iExcAlbums; |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // Returns excluded playlists |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 EXPORT_C CDesCArray& CCmStoreRule::ExcPlayLists() |
|
201 { |
|
202 return *iExcPlayLists; |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // Get media server |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 EXPORT_C const TDesC8& CCmStoreRule::MediaServerL( TInt aIndex ) |
|
210 { |
|
211 // check parameter |
|
212 if ( aIndex < 0 || aIndex >= iMediaServers.Count() ) |
|
213 { |
|
214 User::Leave( KErrArgument ); |
|
215 } |
|
216 |
|
217 return iMediaServers[aIndex]->MediaServer(); |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // Returns count of rules |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 EXPORT_C TInt CCmStoreRule::DefCount() const |
|
225 { |
|
226 return iRuleDefs.Count(); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Returns count of media servers |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C TInt CCmStoreRule::MediaServerCount() const |
|
234 { |
|
235 return iMediaServers.Count(); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // Sets FillRule name |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 EXPORT_C void CCmStoreRule::SetNameL( const TDesC8& aName ) |
|
243 { |
|
244 delete iName; |
|
245 iName = NULL; |
|
246 iName = aName.AllocL(); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // Get Name |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 EXPORT_C TDesC8& CCmStoreRule::Name() const |
|
254 { |
|
255 return *iName; |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // Sets list id, when storing data into db this values isn't used as a |
|
260 // db list id |
|
261 // --------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C void CCmStoreRule::SetListId( const TUint aId ) |
|
264 { |
|
265 iId = aId; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // Get list id |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 EXPORT_C TUint CCmStoreRule::ListId() const |
|
273 { |
|
274 return iId; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // Sets selected state |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 EXPORT_C void CCmStoreRule::SetSelected( TCmFillRuleStatus aSelected ) |
|
282 { |
|
283 iSelected = aSelected; |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // Returns method |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 EXPORT_C TCmFillRuleStatus CCmStoreRule::Selected() const |
|
291 { |
|
292 return iSelected; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // Sets rule's status ( e.g ECmToBeRemoved ) |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 EXPORT_C void CCmStoreRule::SetStatus( TCmListItemStatus aStatus ) |
|
300 { |
|
301 iStatus = aStatus; |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // Returns status |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 EXPORT_C TCmListItemStatus CCmStoreRule::Status() const |
|
309 { |
|
310 return iStatus; |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CCmStoreRule::ExternalizeL |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CCmStoreRule::ExternalizeL( RWriteStream& aStream ) const |
|
318 { |
|
319 aStream.WriteInt32L( iName->Length() ); |
|
320 if ( iName ) |
|
321 { |
|
322 aStream << *iName; |
|
323 } |
|
324 else |
|
325 { |
|
326 aStream << KNullDesC8(); |
|
327 } |
|
328 |
|
329 aStream.WriteInt16L((TInt)iSelected ); |
|
330 aStream.WriteInt16L((TInt)iStatus ); |
|
331 |
|
332 aStream.WriteInt16L( iRuleDefs.Count() ); |
|
333 for ( TInt index(0); index < iRuleDefs.Count(); index++ ) |
|
334 { |
|
335 aStream.WriteInt16L((TInt)iRuleDefs[index] ); |
|
336 } |
|
337 |
|
338 aStream.WriteInt16L( iMediaServers.Count() ); |
|
339 for ( TInt index(0); index < iMediaServers.Count(); index++ ) |
|
340 { |
|
341 iMediaServers[index]->ExternalizeL( aStream ); |
|
342 } |
|
343 TRACE(Print(_L("[COMMON]\t iExcAlbums->Count() = %d"), |
|
344 iExcAlbums->Count() )); |
|
345 aStream.WriteInt16L( iExcAlbums->Count() ); |
|
346 for ( TInt index(0); index < iExcAlbums->Count(); index++ ) |
|
347 { |
|
348 TRACE(Print(_L("[COMMON]\t iExcAlbums[index].Length() = %d"), |
|
349 iExcAlbums->MdcaPoint(index).Length() )); |
|
350 aStream.WriteInt32L( iExcAlbums->MdcaPoint(index).Length() ); |
|
351 aStream << iExcAlbums->MdcaPoint(index); |
|
352 } |
|
353 TRACE(Print(_L("[COMMON]\t iExcPlayLists->Count() = %d"), |
|
354 iExcPlayLists->Count() )); |
|
355 aStream.WriteInt16L( iExcPlayLists->Count() ); |
|
356 for ( TInt index(0); index < iExcPlayLists->Count(); index++ ) |
|
357 { |
|
358 TRACE(Print(_L("[COMMON]\t iExcPlayLists[index].Length() = %d"), |
|
359 iExcPlayLists->MdcaPoint(index).Length() )); |
|
360 aStream.WriteInt32L( iExcPlayLists->MdcaPoint(index).Length() ); |
|
361 aStream << iExcPlayLists->MdcaPoint(index); |
|
362 } |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // CCmFillRule::InternalizeL |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 void CCmStoreRule::InternalizeL( RReadStream& aStream ) |
|
370 { |
|
371 // Content |
|
372 if ( iName ) |
|
373 { |
|
374 delete iName; |
|
375 iName = NULL; |
|
376 } |
|
377 TInt bufLength = aStream.ReadInt32L(); |
|
378 iName = HBufC8::NewL( aStream, bufLength ); |
|
379 |
|
380 // cleanup |
|
381 iRuleDefs.Reset(); |
|
382 |
|
383 iSelected = (TCmFillRuleStatus)aStream.ReadInt16L(); |
|
384 iStatus = (TCmListItemStatus)aStream.ReadInt16L(); |
|
385 |
|
386 // rule count |
|
387 TInt ruleCount = aStream.ReadInt16L(); |
|
388 |
|
389 // Then internalize them from the stream one by one |
|
390 for (TInt index = 0; index < ruleCount; index++ ) |
|
391 { |
|
392 iRuleDefs.Append((TCmMediaType)aStream.ReadInt16L()); |
|
393 } |
|
394 |
|
395 // cleanup |
|
396 iMediaServers.ResetAndDestroy(); |
|
397 |
|
398 // media Server count |
|
399 TInt mediaServerCount = aStream.ReadInt16L(); |
|
400 |
|
401 // Then internalize them from the stream one by one |
|
402 for (TInt index = 0; index < mediaServerCount; index++ ) |
|
403 { |
|
404 CCmMediaServer* server = CCmMediaServer::NewLC(); |
|
405 server->InternalizeL( aStream ); |
|
406 iMediaServers.Append( server ); |
|
407 CleanupStack::Pop( server ); |
|
408 server = NULL; |
|
409 } |
|
410 iExcAlbums->Reset(); |
|
411 TInt excAlbumsCount( aStream.ReadInt16L() ); |
|
412 bufLength = KErrNone; |
|
413 HBufC* temp; |
|
414 TRACE(Print(_L("[COMMON]\t excAlbumsCount = %d"), excAlbumsCount )); |
|
415 for ( TInt index(0); index < excAlbumsCount ; index++ ) |
|
416 { |
|
417 bufLength = aStream.ReadInt32L(); |
|
418 TRACE(Print(_L("[COMMON]\t bufLength = %d"), bufLength )); |
|
419 temp = HBufC::NewL( aStream, bufLength ); |
|
420 CleanupStack::PushL( temp ); |
|
421 iExcAlbums->AppendL( *temp ); |
|
422 CleanupStack::Pop( temp ); |
|
423 temp = NULL; |
|
424 } |
|
425 iExcPlayLists->Reset(); |
|
426 TInt excPlayListCount( aStream.ReadInt16L() ); |
|
427 bufLength = KErrNone; |
|
428 TRACE(Print(_L("[COMMON]\t excPlayListCount = %d"), excPlayListCount )); |
|
429 for ( TInt index(0); index < excPlayListCount ; index++ ) |
|
430 { |
|
431 bufLength = aStream.ReadInt32L(); |
|
432 TRACE(Print(_L("[COMMON]\t bufLength = %d"), bufLength )); |
|
433 temp = HBufC::NewL( aStream, bufLength ); |
|
434 CleanupStack::PushL( temp ); |
|
435 iExcPlayLists->AppendL( *temp ); |
|
436 CleanupStack::Pop( temp ); |
|
437 temp = NULL; |
|
438 } |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // Default constructor |
|
443 // C++ default constructor can NOT contain any code, that might leave. |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 CCmStoreRule::CCmStoreRule() : |
|
447 iRuleDefs( KArrayGranularity ), |
|
448 iMediaServers( KArrayGranularity ) |
|
449 { |
|
450 |
|
451 } |
|
452 |
|
453 // --------------------------------------------------------------------------- |
|
454 // ConstructL |
|
455 // --------------------------------------------------------------------------- |
|
456 // |
|
457 void CCmStoreRule::ConstructL() |
|
458 { |
|
459 iExcAlbums = new ( ELeave ) CDesCArrayFlat( KArrayGranularityContainer ); |
|
460 iExcPlayLists = |
|
461 new ( ELeave ) CDesCArrayFlat( KArrayGranularityContainer ); |
|
462 } |
|
463 |
|
464 // End of file |
|
465 |