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: Part of SyncML Data Synchronization Plug In Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mediadsstore.h" |
|
20 #include <mpxmessagegeneraldefs.h> |
|
21 #include <mpxcollectionmessage.h> |
|
22 |
|
23 #include "mediadsproviderdefs.h" |
|
24 #include "mediamanager.h" |
|
25 #include "cmdemanager.h" |
|
26 #include "playlistitem.h" |
|
27 #include "omadsfolderobject.h" |
|
28 #include "snapshotitem.h" |
|
29 #include "logger.h" |
|
30 |
|
31 _LIT8( KFolderMimeType, "application/vnd.omads-folder+xml" ); |
|
32 _LIT8( KFolderMimeVersion, "1.2" ); |
|
33 |
|
34 _LIT8( KPlaylistMimeType, "audio/x-mpegurl"); |
|
35 _LIT8( KPlaylistMimeVersion, "1.0"); |
|
36 |
|
37 _LIT8( KSongMimeType, "application/x-song"); |
|
38 _LIT8( KSongMimeVersion, "1.0"); |
|
39 |
|
40 |
|
41 const TInt KDataBufferSize = 1024; |
|
42 |
|
43 const TInt KAlbumsOffSet = 0x0000f000; |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CMediaDsDataStore::CMediaDsDataStore |
|
47 // C++ default constructor can NOT contain any code, that might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 CMediaDsDataStore::CMediaDsDataStore( RFs& aFs): |
|
50 iKey(TKeyArrayFix(_FOFF(TSnapshotItem, ItemId()), ECmpTInt)), |
|
51 iFs( aFs ) |
|
52 { |
|
53 TRACE_FUNC; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CMediaDsDataStore::ConstructL |
|
58 // Symbian 2nd phase constructor, can leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 void CMediaDsDataStore::ConstructL() |
|
61 { |
|
62 TRACE_FUNC_ENTRY; |
|
63 |
|
64 // Item UID sets, used to transfer change info |
|
65 iNewItems = new (ELeave) CNSmlDataItemUidSet; |
|
66 iDeletedItems = new (ELeave) CNSmlDataItemUidSet; |
|
67 iUpdatedItems = new (ELeave) CNSmlDataItemUidSet; |
|
68 iMovedItems = new (ELeave) CNSmlDataItemUidSet; |
|
69 iSoftDeletedItems = new (ELeave) CNSmlDataItemUidSet; |
|
70 |
|
71 iHasher = CMD5::NewL(); |
|
72 |
|
73 iMediaManager = CMediaManager::NewL( iFs, this, iKey, *iHasher ); |
|
74 |
|
75 iMdEManager = CMdEManager::NewL( *this ); |
|
76 |
|
77 TRACE_FUNC_EXIT; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMediaDsDataStore::NewLC |
|
82 // Two-phased constructor. |
|
83 // ----------------------------------------------------------------------------- |
|
84 CMediaDsDataStore* CMediaDsDataStore::NewLC( RFs& aFs) |
|
85 { |
|
86 TRACE_FUNC_ENTRY; |
|
87 CMediaDsDataStore* self = new (ELeave) CMediaDsDataStore( aFs ); |
|
88 CleanupStack::PushL( self ); |
|
89 self->ConstructL(); |
|
90 TRACE_FUNC_EXIT; |
|
91 return self; |
|
92 } |
|
93 |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CMediaDsDataStore::~CMediaDsDataStore |
|
97 // Destructor |
|
98 // ----------------------------------------------------------------------------- |
|
99 CMediaDsDataStore::~CMediaDsDataStore() |
|
100 { |
|
101 TRACE_FUNC_ENTRY; |
|
102 |
|
103 delete iDataBuffer; |
|
104 |
|
105 delete iChangeFinder; |
|
106 |
|
107 delete iNewItems; |
|
108 delete iDeletedItems; |
|
109 delete iUpdatedItems; |
|
110 delete iMovedItems; |
|
111 delete iSoftDeletedItems; |
|
112 |
|
113 delete iMediaManager; |
|
114 LOGGER_WRITE("iMediaManager deleted"); |
|
115 |
|
116 delete iMdEManager; |
|
117 LOGGER_WRITE("iMdEManager deleted"); |
|
118 |
|
119 delete iHasher; |
|
120 LOGGER_WRITE("iHasher deleted"); |
|
121 // normally iSnapshot is NULL, but if error has occured we need to delete it. |
|
122 delete iSnapshot; |
|
123 TRACE_FUNC_EXIT; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CMediaDsDataStore::DoOpenL |
|
128 // Opens database. This operation is performed SYNCHRONOUSLY |
|
129 // ----------------------------------------------------------------------------- |
|
130 void CMediaDsDataStore::DoOpenL( const TDesC& aStoreName, |
|
131 MSmlSyncRelationship& aContext, TRequestStatus& aStatus ) |
|
132 { |
|
133 TRACE_FUNC_ENTRY; |
|
134 |
|
135 iCallerStatus = &aStatus; |
|
136 *iCallerStatus = KRequestPending; |
|
137 |
|
138 if ( iCurrentState != EClosed ) |
|
139 { |
|
140 User::RequestComplete( iCallerStatus, KErrInUse ); |
|
141 LOGGER_WRITE("CMmsDataStore::DoOpenL failed with KErrInUse."); |
|
142 return; |
|
143 } |
|
144 |
|
145 // Create ChangeFinder object |
|
146 if ( iChangeFinder ) |
|
147 { |
|
148 delete iChangeFinder; |
|
149 iChangeFinder = NULL; |
|
150 } |
|
151 iChangeFinder = CChangeFinder::NewL( aContext, iKey, iHasHistory, KMediaDataProviderImplUid ); |
|
152 |
|
153 if ( aStoreName.CompareF( KMediaDsRefreshDbName ) == 0 ) |
|
154 { |
|
155 LOGGER_WRITE("Refresh library and open database"); |
|
156 // just kick off scanner, don't wait ready status |
|
157 // Async. func. HandleCollectionMessage is called when ready |
|
158 iMediaManager->ScanL(); |
|
159 |
|
160 } |
|
161 else if ( aStoreName.CompareF( KMediaDsDbName ) == 0 ) |
|
162 { |
|
163 LOGGER_WRITE("Open database"); |
|
164 |
|
165 if ( !iHasHistory ) |
|
166 { |
|
167 LOGGER_WRITE("No history, scan library"); |
|
168 // just kick off scanner, don't wait ready status |
|
169 // Async. func. HandleCollectionMessage is called when ready |
|
170 iMediaManager->ScanL(); |
|
171 } |
|
172 |
|
173 } |
|
174 else |
|
175 { |
|
176 LOGGER_WRITE("Unknown database"); |
|
177 User::Leave( KErrNotSupported ); |
|
178 } |
|
179 |
|
180 // Set current snapshot, this will be compared against the old one |
|
181 RegisterSnapshotL(); |
|
182 |
|
183 TRACE_FUNC_EXIT; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CMediaDsDataStore::DoCancelRequest |
|
188 // Not supported, does nothing. |
|
189 // ----------------------------------------------------------------------------- |
|
190 void CMediaDsDataStore::DoCancelRequest() |
|
191 { |
|
192 TRACE_FUNC_ENTRY; |
|
193 if ( iCurrentState == EOpening ) |
|
194 { |
|
195 LOGGER_WRITE("Cancel Open command"); |
|
196 iMediaManager->Cancel(); |
|
197 iMdEManager->Cancel(); |
|
198 } |
|
199 TRACE_FUNC_EXIT; |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CMediaDsDataStore::DoStoreName |
|
204 // Returns the name of the DataStore |
|
205 // ----------------------------------------------------------------------------- |
|
206 const TDesC& CMediaDsDataStore::DoStoreName() const |
|
207 { |
|
208 TRACE_FUNC; |
|
209 return KNullDesC; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CMediaDsDataStore::DoBeginTransactionL |
|
214 // Transactions are not supported. |
|
215 // ----------------------------------------------------------------------------- |
|
216 void CMediaDsDataStore::DoBeginTransactionL() |
|
217 { |
|
218 TRACE_FUNC; |
|
219 User::Leave( KErrNotSupported ); |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CMediaDsDataStore::DoCommitTransactionL |
|
224 // Transactions are not supported. |
|
225 // ----------------------------------------------------------------------------- |
|
226 void CMediaDsDataStore::DoCommitTransactionL( TRequestStatus& /*aStatus*/ ) |
|
227 { |
|
228 TRACE_FUNC; |
|
229 User::Leave( KErrNotSupported ); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMediaDsDataStore::DoRevertTransaction |
|
234 // Transactions are not supported. |
|
235 // ----------------------------------------------------------------------------- |
|
236 void CMediaDsDataStore::DoRevertTransaction( TRequestStatus& aStatus ) |
|
237 { |
|
238 TRACE_FUNC; |
|
239 iCallerStatus = &aStatus; |
|
240 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMediaDsDataStore::DoBeginBatchL |
|
245 // Batching is not supported. |
|
246 // ----------------------------------------------------------------------------- |
|
247 void CMediaDsDataStore::DoBeginBatchL() |
|
248 { |
|
249 TRACE_FUNC; |
|
250 User::Leave( KErrNotSupported ); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CMediaDsDataStore::DoCommitBatchL |
|
255 // Batching is not supported |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CMediaDsDataStore::DoCommitBatchL( RArray<TInt>& /*aResultArray*/, TRequestStatus& /*aStatus*/ ) |
|
259 { |
|
260 TRACE_FUNC; |
|
261 User::Leave( KErrNotSupported ); |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CMediaDsDataStore::DoCancelBatch |
|
266 // Batching is not supported |
|
267 // ----------------------------------------------------------------------------- |
|
268 void CMediaDsDataStore::DoCancelBatch() |
|
269 { |
|
270 TRACE_FUNC; |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CMediaDsDataStore::DoSetRemoteStoreFormatL |
|
275 // Not supported |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 void CMediaDsDataStore::DoSetRemoteStoreFormatL( const CSmlDataStoreFormat& /*aServerDataStoreFormat*/ ) |
|
279 { |
|
280 TRACE_FUNC; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CMediaDsDataStore::DoSetRemoteMaxObjectSize |
|
285 // Not supported |
|
286 // ----------------------------------------------------------------------------- |
|
287 void CMediaDsDataStore::DoSetRemoteMaxObjectSize( TInt /*aServerMaxObjectSize*/ ) |
|
288 { |
|
289 TRACE_FUNC; |
|
290 } |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CMediaDsDataStore::DoMaxObjectSize |
|
294 // Reads the maximum MMS Message size from the central repository |
|
295 // ----------------------------------------------------------------------------- |
|
296 TInt CMediaDsDataStore::DoMaxObjectSize() const |
|
297 { |
|
298 TRACE_FUNC; |
|
299 return 0; |
|
300 } |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CMediaDsDataStore::DoOpenItemL |
|
304 // Opens item in the DataStore, reads it (either completely or partially) |
|
305 // to the temporary buffer where it can be later read to the remote database. |
|
306 // ----------------------------------------------------------------------------- |
|
307 void CMediaDsDataStore::DoOpenItemL( TSmlDbItemUid aUid, TBool& /*aFieldChange*/, |
|
308 TInt& aSize, TSmlDbItemUid& aParent, TDes8& aMimeType, |
|
309 TDes8& aMimeVer, TRequestStatus& aStatus ) |
|
310 { |
|
311 TRACE_FUNC_ENTRY; |
|
312 |
|
313 LOGGER_WRITE_1( "Opening item %d.", aUid ); |
|
314 |
|
315 // Store these for later use |
|
316 iCallerStatus = &aStatus; |
|
317 *iCallerStatus = KRequestPending; |
|
318 |
|
319 iReadPosition=0; |
|
320 |
|
321 // Check that we're in a proper state |
|
322 if ( iCurrentState != EOpenAndWaiting ) |
|
323 { |
|
324 LOGGER_WRITE_1( "CMediaDsDataStore::DoOpenItemL, invalid state %d.", iCurrentState ); |
|
325 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
326 return; |
|
327 } |
|
328 |
|
329 if ( !iDataBuffer ) |
|
330 { |
|
331 iDataBuffer = CBufFlat::NewL( KDataBufferSize ); |
|
332 } |
|
333 iDataBuffer->Reset(); |
|
334 |
|
335 |
|
336 if ( aUid <= KLastFolderId ) |
|
337 { |
|
338 COMADSFolderObject* folderObject = COMADSFolderObject::NewLC(); |
|
339 |
|
340 switch ( aUid ) |
|
341 { |
|
342 case KAllSongsFolderId: |
|
343 folderObject->SetName( KAllSongs ); |
|
344 break; |
|
345 case KPlaylistsFolderId: |
|
346 folderObject->SetName( KPlaylists ); |
|
347 break; |
|
348 case KAlbumsFolderId: |
|
349 folderObject->SetName( KAlbums ); |
|
350 break; |
|
351 default: |
|
352 User::Leave( KErrNotFound ); |
|
353 break; |
|
354 } |
|
355 folderObject->ExportFolderXmlL( *iDataBuffer ); |
|
356 CleanupStack::PopAndDestroy( folderObject ); |
|
357 aMimeType.Copy( KFolderMimeType ); |
|
358 aMimeVer.Copy( KFolderMimeVersion ); |
|
359 aParent = KErrNotFound; |
|
360 } |
|
361 else |
|
362 { |
|
363 CSongItem* song = CSongItem::NewLC(); |
|
364 LOGGER_WRITE("Try to read song"); |
|
365 TRAPD( err, iMediaManager->GetSongL( aUid, *song )); |
|
366 if ( !err ) |
|
367 { |
|
368 RBufWriteStream stream( *iDataBuffer ); |
|
369 CleanupClosePushL( stream ); |
|
370 song->ExportL( stream ); |
|
371 CleanupStack::PopAndDestroy( &stream ); |
|
372 CleanupStack::PopAndDestroy( song ); |
|
373 |
|
374 aMimeType.Copy( KSongMimeType ); |
|
375 aMimeVer.Copy( KSongMimeVersion ); |
|
376 aParent = KAllSongsFolderId; |
|
377 } |
|
378 else // could not read song, maybe it is playlist |
|
379 { |
|
380 CleanupStack::PopAndDestroy( song ); |
|
381 CPlaylistItem* playList = CPlaylistItem::NewLC(); |
|
382 LOGGER_WRITE("Try to read playlist"); |
|
383 TRAP(err, iMediaManager->GetPlayListL( aUid, *playList )); |
|
384 if ( !err ) |
|
385 { |
|
386 RBufWriteStream stream( *iDataBuffer ); |
|
387 CleanupClosePushL( stream ); |
|
388 |
|
389 playList->ExportL( stream ); |
|
390 CleanupStack::PopAndDestroy( &stream ); |
|
391 CleanupStack::PopAndDestroy( playList ); |
|
392 |
|
393 aMimeType.Copy( KPlaylistMimeType ); |
|
394 aMimeVer.Copy( KPlaylistMimeVersion ); |
|
395 aParent = KPlaylistsFolderId; |
|
396 } |
|
397 else |
|
398 { |
|
399 CleanupStack::PopAndDestroy( playList ); |
|
400 LOGGER_WRITE("Try to read album"); |
|
401 // Could not read song, maybe it's a Album |
|
402 const CPlaylistItem& album = iMdEManager->AlbumL( MapSyncIdToAlbumId(aUid) ); |
|
403 RBufWriteStream stream( *iDataBuffer ); |
|
404 CleanupClosePushL( stream ); |
|
405 |
|
406 album.ExportL( stream ); |
|
407 CleanupStack::PopAndDestroy( &stream ); |
|
408 |
|
409 aMimeType.Copy( KPlaylistMimeType ); |
|
410 aMimeVer.Copy( KPlaylistMimeVersion ); |
|
411 aParent = KAlbumsFolderId; |
|
412 } |
|
413 } |
|
414 |
|
415 } |
|
416 |
|
417 aSize = iDataBuffer->Size(); |
|
418 |
|
419 LOGGER_WRITE_1("aSize: %d", aSize); |
|
420 |
|
421 // Signal we're complete |
|
422 User::RequestComplete( iCallerStatus, KErrNone ); |
|
423 |
|
424 TRACE_FUNC_EXIT; |
|
425 } |
|
426 |
|
427 // ----------------------------------------------------------------------------- |
|
428 // CMediaDsDataStore::DoCreateItemL |
|
429 // Create new item to the message store. |
|
430 // Return the id number of the newly created item |
|
431 // ----------------------------------------------------------------------------- |
|
432 void CMediaDsDataStore::DoCreateItemL( TSmlDbItemUid& aUid, TInt aSize, TSmlDbItemUid aParent, |
|
433 const TDesC8& aMimeType, const TDesC8& /*aMimeVer*/, TRequestStatus& aStatus ) |
|
434 { |
|
435 TRACE_FUNC_ENTRY; |
|
436 LOGGER_WRITE_1( "Parent folder: %d.", aParent ); |
|
437 |
|
438 // Store some variables for further use |
|
439 iCallerStatus = &aStatus; |
|
440 *iCallerStatus = KRequestPending; |
|
441 |
|
442 // Ensure that we're in proper state |
|
443 if ( iCurrentState != EOpenAndWaiting ) |
|
444 { |
|
445 LOGGER_WRITE_1( "Invalid state %d.", iCurrentState ); |
|
446 } |
|
447 |
|
448 iWrittenDataLength = 0; |
|
449 iCreatedUid = &aUid; |
|
450 LOGGER_WRITE8_1( "aMimeType: %S", &aMimeType ); |
|
451 |
|
452 if ( aMimeType.Compare( KPlaylistMimeType() ) == 0 ) |
|
453 { |
|
454 LOGGER_WRITE("Add Playlist"); |
|
455 iCurrentState = ECreatePlaylist; |
|
456 } |
|
457 else if ( aMimeType.Compare( KSongMimeType() ) == 0 ) |
|
458 { |
|
459 LOGGER_WRITE("Add Song not supported"); |
|
460 User::Leave( KErrNotSupported ); |
|
461 } |
|
462 else |
|
463 { |
|
464 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
465 LOGGER_WRITE("Bad MIME type"); |
|
466 return; |
|
467 } |
|
468 |
|
469 if ( iDataBuffer ) |
|
470 { |
|
471 iDataBuffer->ResizeL( aSize ); |
|
472 } |
|
473 else |
|
474 { |
|
475 iDataBuffer = CBufFlat::NewL( KDataBufferSize ); |
|
476 iDataBuffer->ResizeL( aSize ); |
|
477 } |
|
478 LOGGER_WRITE_1("iDataBuffer->Size: %d", iDataBuffer->Size()); |
|
479 |
|
480 LOGGER_WRITE_1("aSize: %d", aSize); |
|
481 iParentId = aParent; |
|
482 |
|
483 // Signal we're complete |
|
484 User::RequestComplete( iCallerStatus, KErrNone ); |
|
485 |
|
486 TRACE_FUNC_EXIT; |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CMediaDsDataStore::DoReplaceItemL |
|
491 // Begin the replace operation, ensure that the item really exists |
|
492 // ----------------------------------------------------------------------------- |
|
493 void CMediaDsDataStore::DoReplaceItemL( TSmlDbItemUid aUid, TInt aSize, TSmlDbItemUid aParent, |
|
494 TBool /*aFieldChange*/, TRequestStatus& aStatus ) |
|
495 { |
|
496 TRACE_FUNC_ENTRY; |
|
497 LOGGER_WRITE_1("Replacing item %d.", aUid); |
|
498 LOGGER_WRITE_1("Parent folder: %d.", aParent); |
|
499 |
|
500 // Store some variables for further use |
|
501 iCallerStatus = &aStatus; |
|
502 *iCallerStatus = KRequestPending; |
|
503 |
|
504 // Ensure proper state |
|
505 if ( iCurrentState != EOpenAndWaiting ) |
|
506 { |
|
507 LOGGER_WRITE_1("Invalid state %d.", iCurrentState); |
|
508 } |
|
509 |
|
510 iCurrentState = EReplace; |
|
511 |
|
512 iParentId = aParent; |
|
513 iCurrentId = aUid; |
|
514 |
|
515 if ( iDataBuffer ) |
|
516 { |
|
517 iDataBuffer->ResizeL( aSize ); |
|
518 } |
|
519 else |
|
520 { |
|
521 iDataBuffer = CBufFlat::NewL( KDataBufferSize ); |
|
522 iDataBuffer->ResizeL( aSize ); |
|
523 } |
|
524 |
|
525 // Signal we're complete |
|
526 User::RequestComplete( iCallerStatus, KErrNone ); |
|
527 |
|
528 TRACE_FUNC_EXIT; |
|
529 } |
|
530 |
|
531 // ----------------------------------------------------------------------------- |
|
532 // CMediaDsDataStore::DoReadItemL |
|
533 // Read specified amount of data from the temporary buffer |
|
534 // ----------------------------------------------------------------------------- |
|
535 void CMediaDsDataStore::DoReadItemL( TDes8& aBuffer ) |
|
536 { |
|
537 TRACE_FUNC_ENTRY; |
|
538 // Thiw is how much data there is left in the buffer |
|
539 TInt left = iDataBuffer->Size() - iReadPosition; |
|
540 |
|
541 if ( left > 0 ) |
|
542 { |
|
543 // This is how much there's space in the destination buffer |
|
544 TInt destSize = aBuffer.MaxSize(); |
|
545 |
|
546 // This is how much we can read |
|
547 TInt toRead = destSize < left ? destSize : left; |
|
548 |
|
549 // Read the data from the buffer, then update the position |
|
550 iDataBuffer->Read( iReadPosition, aBuffer, toRead ); |
|
551 iReadPosition += toRead; |
|
552 } |
|
553 else |
|
554 { |
|
555 LOGGER_WRITE( "No data to read" ); |
|
556 User::Leave( KErrEof ); |
|
557 } |
|
558 TRACE_FUNC_EXIT; |
|
559 } |
|
560 |
|
561 // ----------------------------------------------------------------------------- |
|
562 // CMediaDsDataStore::DoWriteItemL |
|
563 // Write specified amount of data to the temporary buffer |
|
564 // ----------------------------------------------------------------------------- |
|
565 void CMediaDsDataStore::DoWriteItemL( const TDesC8& aData ) |
|
566 { |
|
567 TRACE_FUNC_ENTRY; |
|
568 |
|
569 iDataBuffer->Write( iWrittenDataLength, aData ); |
|
570 iWrittenDataLength += aData.Size(); |
|
571 |
|
572 TRACE_FUNC_EXIT; |
|
573 } |
|
574 |
|
575 // ----------------------------------------------------------------------------- |
|
576 // CMediaDsDataStore::DoCommitItemL |
|
577 // Commits item from temporary buffer to the message store |
|
578 // ----------------------------------------------------------------------------- |
|
579 void CMediaDsDataStore::DoCommitItemL( TRequestStatus& aStatus ) |
|
580 { |
|
581 TRACE_FUNC_ENTRY; |
|
582 |
|
583 // Store some variables |
|
584 iCallerStatus = &aStatus; |
|
585 *iCallerStatus = KRequestPending; |
|
586 |
|
587 iDataBuffer->Compress(); |
|
588 |
|
589 // Read the playlist item |
|
590 CPlaylistItem* newItem = CPlaylistItem::NewLC(); |
|
591 |
|
592 const TUint8* ptr8 = iDataBuffer->Ptr(0).Ptr(); |
|
593 const TUint16* ptr16 = reinterpret_cast<const TUint16*>( ptr8 ); |
|
594 TPtrC dataPtr; |
|
595 dataPtr.Set( ptr16, iDataBuffer->Size()/2 ); |
|
596 newItem->ImportL( dataPtr ); |
|
597 |
|
598 iDataBuffer->Reset(); |
|
599 |
|
600 #ifdef _DEBUG |
|
601 LOGGER_WRITE_1("Name: %S", &newItem->Title()); |
|
602 LOGGER_WRITE_1("Items count: %d", newItem->ItemCount()); |
|
603 for ( TInt i=0; i<newItem->ItemCount(); i++ ) |
|
604 { |
|
605 TPtrC16 ptr = newItem->ItemAt(i); |
|
606 LOGGER_WRITE_1("item: %S", &ptr); |
|
607 } |
|
608 #endif |
|
609 |
|
610 |
|
611 TInt error(KErrNone); |
|
612 if ( iCurrentState == ECreatePlaylist ) |
|
613 { |
|
614 if ( iParentId == KPlaylistsFolderId ) |
|
615 { |
|
616 iMediaManager->CreateNewPlaylistL( *iCreatedUid, *newItem ); |
|
617 } |
|
618 else if ( iParentId == KAlbumsFolderId ) |
|
619 { |
|
620 iMdEManager->CreateAlbumL( *newItem ); |
|
621 *iCreatedUid = MapAlbumIdToSyncId( newItem->Id() ); |
|
622 } |
|
623 else |
|
624 { |
|
625 LOGGER_WRITE("Not supported"); |
|
626 User::Leave( KErrNotSupported); |
|
627 } |
|
628 |
|
629 // Inform ChangeFinder of the added item |
|
630 TSnapshotItem snapshotItem( *iCreatedUid ); |
|
631 snapshotItem.SetParentId( iParentId ); |
|
632 snapshotItem.SetItemHash( *newItem, *iHasher ); |
|
633 iChangeFinder->ItemAddedL( snapshotItem ); |
|
634 |
|
635 } |
|
636 else if ( iCurrentState == EReplace ) |
|
637 { |
|
638 if ( iParentId == KPlaylistsFolderId ) |
|
639 { |
|
640 iMediaManager->ReplacePlaylistL( iCurrentId, *newItem ); |
|
641 } |
|
642 else if ( iParentId == KAlbumsFolderId ) |
|
643 { |
|
644 iItemInReplacement.SetItemId( iCurrentId ); |
|
645 iItemInReplacement.SetParentId( iParentId ); |
|
646 iItemInReplacement.SetItemHash( *newItem, *iHasher ); |
|
647 // Async function, calls AlbumReplaced when completed |
|
648 iMdEManager->ReplaceAlbumL( MapSyncIdToAlbumId(iCurrentId), *newItem ); |
|
649 |
|
650 CleanupStack::PopAndDestroy( newItem ); |
|
651 return; |
|
652 } |
|
653 else |
|
654 { |
|
655 LOGGER_WRITE("Not supported"); |
|
656 User::Leave( KErrNotSupported); |
|
657 } |
|
658 |
|
659 // Inform ChangeFinder of the replaced item |
|
660 TSnapshotItem snapshotItem( iCurrentId ); |
|
661 snapshotItem.SetParentId( iParentId ); |
|
662 snapshotItem.SetItemHash( *newItem, *iHasher ); |
|
663 iChangeFinder->ItemUpdatedL( snapshotItem ); |
|
664 } |
|
665 else |
|
666 { |
|
667 LOGGER_WRITE_1("Wrong state: %d", iCurrentState); |
|
668 User::Leave( KErrNotSupported ); |
|
669 } |
|
670 CleanupStack::PopAndDestroy( newItem ); |
|
671 |
|
672 |
|
673 |
|
674 LOGGER_WRITE_1("error: %d", error); |
|
675 // We'll be waiting for next event, signal we're done |
|
676 iCurrentState = EOpenAndWaiting; |
|
677 User::RequestComplete( iCallerStatus, error ); |
|
678 |
|
679 TRACE_FUNC_EXIT; |
|
680 } |
|
681 |
|
682 // ----------------------------------------------------------------------------- |
|
683 // CMediaDsDataStore::DoCloseItem |
|
684 // Closes open item in the data store |
|
685 // ----------------------------------------------------------------------------- |
|
686 void CMediaDsDataStore::DoCloseItem() |
|
687 { |
|
688 TRACE_FUNC_ENTRY; |
|
689 if ( iDataBuffer ) |
|
690 { |
|
691 iDataBuffer->Reset(); |
|
692 } |
|
693 iCurrentState = EOpenAndWaiting; |
|
694 iReadPosition = 0; |
|
695 TRACE_FUNC_EXIT; |
|
696 } |
|
697 |
|
698 // ----------------------------------------------------------------------------- |
|
699 // CMediaDsDataStore::DoMoveItemL |
|
700 // Moves item from one folder to another in the message store |
|
701 // ----------------------------------------------------------------------------- |
|
702 void CMediaDsDataStore::DoMoveItemL( TSmlDbItemUid /*aUid*/, |
|
703 TSmlDbItemUid /*aNewParent*/, TRequestStatus& /*aStatus*/ ) |
|
704 { |
|
705 TRACE_FUNC; |
|
706 User::Leave( KErrNotSupported ); |
|
707 } |
|
708 |
|
709 // ----------------------------------------------------------------------------- |
|
710 // CMediaDsDataStore::DoDeleteItemL |
|
711 // Removes item from the message store |
|
712 // ----------------------------------------------------------------------------- |
|
713 void CMediaDsDataStore::DoDeleteItemL( TSmlDbItemUid aUid, TRequestStatus& aStatus ) |
|
714 { |
|
715 TRACE_FUNC_ENTRY; |
|
716 LOGGER_WRITE_1("Deleting item %d.", aUid); |
|
717 |
|
718 // Store some variables for further use |
|
719 iCallerStatus = &aStatus; |
|
720 *iCallerStatus = KRequestPending; |
|
721 |
|
722 TInt error(KErrNone); |
|
723 |
|
724 // Check that we're in proper state |
|
725 if ( iCurrentState != EOpenAndWaiting ) |
|
726 { |
|
727 LOGGER_WRITE_1("CMmsDataStore::DoDeleteItemL, invalid state %d.", iCurrentState); |
|
728 } |
|
729 |
|
730 TRAP( error, iMediaManager->DeletePlaylistL( aUid ) ); |
|
731 if ( error ) |
|
732 { |
|
733 error = KErrNone; |
|
734 iMdEManager->DeleteAlbumL( MapSyncIdToAlbumId( aUid ) ); |
|
735 } |
|
736 |
|
737 if ( !error ) |
|
738 { |
|
739 // Inform ChangeFinder of the deleted item |
|
740 TSnapshotItem snapshotItem( aUid ); |
|
741 iChangeFinder->ItemDeletedL( snapshotItem ); |
|
742 } |
|
743 |
|
744 LOGGER_WRITE_1("complete error: %d", error); |
|
745 // Signal we're done |
|
746 User::RequestComplete( iCallerStatus, error ); |
|
747 TRACE_FUNC_EXIT; |
|
748 } |
|
749 |
|
750 // ----------------------------------------------------------------------------- |
|
751 // CMediaDsDataStore::DoSoftDeleteItemL |
|
752 // Soft delete isn't supported. |
|
753 // ----------------------------------------------------------------------------- |
|
754 void CMediaDsDataStore::DoSoftDeleteItemL( TSmlDbItemUid /*aUid*/, TRequestStatus& aStatus ) |
|
755 { |
|
756 TRACE_FUNC_ENTRY; |
|
757 |
|
758 // Store some variables for further use |
|
759 iCallerStatus = &aStatus; |
|
760 *iCallerStatus = KRequestPending; |
|
761 |
|
762 // Signal we're done |
|
763 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
764 |
|
765 TRACE_FUNC_EXIT; |
|
766 } |
|
767 |
|
768 // ----------------------------------------------------------------------------- |
|
769 // CMediaDsDataStore::DoDeleteAllItemsL |
|
770 // Deletes all items in the standard folders of message store |
|
771 // ----------------------------------------------------------------------------- |
|
772 void CMediaDsDataStore::DoDeleteAllItemsL( TRequestStatus& aStatus ) |
|
773 { |
|
774 TRACE_FUNC_ENTRY; |
|
775 |
|
776 // Store some variables for further use |
|
777 iCallerStatus = &aStatus; |
|
778 *iCallerStatus = KRequestPending; |
|
779 |
|
780 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
781 |
|
782 TRACE_FUNC_EXIT; |
|
783 } |
|
784 |
|
785 // ----------------------------------------------------------------------------- |
|
786 // CMediaDsDataStore::DoHasSyncHistory |
|
787 // This method returns ETrue if Data Store has history information. |
|
788 // Slow-sync will be used if Data Store does not have history information. |
|
789 // ----------------------------------------------------------------------------- |
|
790 TBool CMediaDsDataStore::DoHasSyncHistory() const |
|
791 { |
|
792 TRACE_FUNC_RET( (TInt)iHasHistory ); |
|
793 |
|
794 // iHasHistory is initialized in DoOpenL method |
|
795 return iHasHistory; |
|
796 } |
|
797 |
|
798 // ----------------------------------------------------------------------------- |
|
799 // CMediaDsDataStore::DoAddedItems |
|
800 // This method returns UIDs of added items. Those items are added after previous |
|
801 // synchronization with current synchronization relationship. |
|
802 // ----------------------------------------------------------------------------- |
|
803 const MSmlDataItemUidSet& CMediaDsDataStore::DoAddedItems() const |
|
804 { |
|
805 TRACE_FUNC; |
|
806 |
|
807 // Ensure that we're in a proper state |
|
808 if ( iCurrentState != EOpenAndWaiting ) |
|
809 { |
|
810 LOGGER_WRITE_1("CMmsDataStore::DoAddedItems, invalid state %d.", iCurrentState); |
|
811 } |
|
812 |
|
813 TInt error(KErrNone); |
|
814 |
|
815 // Clear new-items array |
|
816 iNewItems->Reset(); |
|
817 |
|
818 // Set current snapshot, this will be compared against the old one |
|
819 // Search for new items |
|
820 TRAP( error, iChangeFinder->FindNewItemsL(*iNewItems) ) |
|
821 if ( error != KErrNone ) |
|
822 { |
|
823 LOGGER_WRITE_1("CMmsDataStore::DoAddedItems, iChangeFinder->FindNewItemsL leaved with %d.", error); |
|
824 } |
|
825 |
|
826 LOGGER_WRITE_1("New item count: %d.", iNewItems->ItemCount()); |
|
827 |
|
828 return *iNewItems; |
|
829 } |
|
830 |
|
831 // ----------------------------------------------------------------------------- |
|
832 // CMediaDsDataStore::DoDeletedItems |
|
833 // |
|
834 // ----------------------------------------------------------------------------- |
|
835 const MSmlDataItemUidSet& CMediaDsDataStore::DoDeletedItems() const |
|
836 { |
|
837 TRACE_FUNC; |
|
838 |
|
839 // Ensure that we're in a proper state |
|
840 if ( iCurrentState != EOpenAndWaiting ) |
|
841 { |
|
842 LOGGER_WRITE_1("CMmsDataStore::DoDeletedItems, invalid state %d.", iCurrentState); |
|
843 } |
|
844 |
|
845 TInt error(KErrNone); |
|
846 |
|
847 // Clear deleted-items array |
|
848 iDeletedItems->Reset(); |
|
849 |
|
850 // Search for deleted items |
|
851 TRAP( error, iChangeFinder->FindDeletedItemsL( *iDeletedItems ) ); |
|
852 if ( error != KErrNone ) |
|
853 { |
|
854 LOGGER_WRITE_1("CMmsDataStore::DoDeletedItems, iChangeFinder->FindDeletedItemsL leaved with %d.", error); |
|
855 } |
|
856 |
|
857 LOGGER_WRITE_1("Deleted item count: %d.", iDeletedItems->ItemCount()); |
|
858 return *iDeletedItems; |
|
859 } |
|
860 |
|
861 // ----------------------------------------------------------------------------- |
|
862 // CMediaDsDataStore::DoSoftDeletedItems |
|
863 // Not directly supported, equals to "hard" delete |
|
864 // ----------------------------------------------------------------------------- |
|
865 const MSmlDataItemUidSet& CMediaDsDataStore::DoSoftDeletedItems() const |
|
866 { |
|
867 TRACE_FUNC; |
|
868 |
|
869 iSoftDeletedItems->Reset(); |
|
870 return *iSoftDeletedItems; |
|
871 } |
|
872 |
|
873 // ----------------------------------------------------------------------------- |
|
874 // CMediaDsDataStore::DoModifiedItems |
|
875 // Finds all modified items in the data store |
|
876 // ----------------------------------------------------------------------------- |
|
877 const MSmlDataItemUidSet& CMediaDsDataStore::DoModifiedItems() const |
|
878 { |
|
879 TRACE_FUNC; |
|
880 |
|
881 // Ensure that we're in a proper state |
|
882 if ( iCurrentState != EOpenAndWaiting ) |
|
883 { |
|
884 LOGGER_WRITE_1("CMmsDataStore::DoModifiedItems, invalid state %d.", iCurrentState); |
|
885 } |
|
886 |
|
887 TInt error(KErrNone); |
|
888 |
|
889 // Clear updated-items array |
|
890 iUpdatedItems->Reset(); |
|
891 |
|
892 // Search for updated items |
|
893 TRAP( error, iChangeFinder->FindChangedItemsL( *iUpdatedItems ) ) |
|
894 if ( error != KErrNone ) |
|
895 { |
|
896 LOGGER_WRITE_1("CMmsDataStore::DoModifiedItems, iChangeFinder->FindChangedItemsL leaved with %d.", error); |
|
897 } |
|
898 |
|
899 LOGGER_WRITE_1("Modified item count: %d.", iUpdatedItems->ItemCount()); |
|
900 return *iUpdatedItems; |
|
901 } |
|
902 |
|
903 // ----------------------------------------------------------------------------- |
|
904 // CMediaDsDataStore::DoMovedItems |
|
905 // Finds all moved items in the data store |
|
906 // ----------------------------------------------------------------------------- |
|
907 const MSmlDataItemUidSet& CMediaDsDataStore::DoMovedItems() const |
|
908 { |
|
909 TRACE_FUNC; |
|
910 // return empty array |
|
911 return *iMovedItems; |
|
912 } |
|
913 |
|
914 // ----------------------------------------------------------------------------- |
|
915 // CMediaDsDataStore::DoResetChangeInfoL |
|
916 // Resets change history in the data store. All content is considered |
|
917 // new in the data store point of view. |
|
918 // ----------------------------------------------------------------------------- |
|
919 void CMediaDsDataStore::DoResetChangeInfoL( TRequestStatus& aStatus ) |
|
920 { |
|
921 TRACE_FUNC_ENTRY; |
|
922 |
|
923 iCallerStatus = &aStatus; |
|
924 *iCallerStatus = KRequestPending; |
|
925 |
|
926 // Check that we're in proper state |
|
927 if ( iCurrentState != EOpenAndWaiting ) |
|
928 { |
|
929 LOGGER_WRITE_1("CMmsDataStore::DoResetChangeInfoL, invalid state %d.", iCurrentState); |
|
930 } |
|
931 |
|
932 // Reset change info in ChangeFinder |
|
933 iChangeFinder->ResetL(); |
|
934 iHasHistory = EFalse; |
|
935 |
|
936 // Signal we're done |
|
937 User::RequestComplete( iCallerStatus, KErrNone ); |
|
938 |
|
939 TRACE_FUNC_EXIT; |
|
940 } |
|
941 |
|
942 // ----------------------------------------------------------------------------- |
|
943 // CMediaDsDataStore::DoCommitChangeInfoL |
|
944 // Commits change info. These items are no longer reported, when change |
|
945 // information is being queried. |
|
946 // ----------------------------------------------------------------------------- |
|
947 void CMediaDsDataStore::DoCommitChangeInfoL( TRequestStatus& aStatus, const MSmlDataItemUidSet& aItems ) |
|
948 { |
|
949 TRACE_FUNC_ENTRY; |
|
950 |
|
951 iCallerStatus = &aStatus; |
|
952 *iCallerStatus = KRequestPending; |
|
953 |
|
954 // Ensure that we're in a proper state |
|
955 if ( iCurrentState != EOpenAndWaiting ) |
|
956 { |
|
957 LOGGER_WRITE_1("CMmsDataStore::DoCommitChangeInfoL, invalid state %d.", iCurrentState); |
|
958 } |
|
959 |
|
960 // Notify ChangeFinder |
|
961 iChangeFinder->CommitChangesL(aItems); |
|
962 iHasHistory = ETrue; |
|
963 |
|
964 // Signal we're done |
|
965 User::RequestComplete(iCallerStatus, KErrNone); |
|
966 |
|
967 TRACE_FUNC_EXIT; |
|
968 } |
|
969 |
|
970 |
|
971 // ----------------------------------------------------------------------------- |
|
972 // CMediaDsDataStore::DoCommitChangeInfoL |
|
973 // Commits change info. There is no more nothing to report when change |
|
974 // information is being queried. |
|
975 // ----------------------------------------------------------------------------- |
|
976 void CMediaDsDataStore::DoCommitChangeInfoL(TRequestStatus& aStatus) |
|
977 { |
|
978 TRACE_FUNC_ENTRY; |
|
979 |
|
980 iCallerStatus = &aStatus; |
|
981 *iCallerStatus = KRequestPending; |
|
982 |
|
983 // Ensure that we're in a proper state |
|
984 if ( iCurrentState != EOpenAndWaiting ) |
|
985 { |
|
986 LOGGER_WRITE_1("CMmsDataStore::DoCommitChangeInfoL, invalid state %d.", iCurrentState); |
|
987 } |
|
988 |
|
989 // Notify ChangeFinder |
|
990 iChangeFinder->CommitChangesL(); |
|
991 iHasHistory = ETrue; |
|
992 |
|
993 // Signal we're done |
|
994 User::RequestComplete( iCallerStatus, KErrNone ); |
|
995 |
|
996 TRACE_FUNC_EXIT; |
|
997 } |
|
998 |
|
999 |
|
1000 void CMediaDsDataStore::HandleCollectionMessage(CMPXMessage* /*aMsg*/, TInt /*aErr*/) |
|
1001 { |
|
1002 TRACE_FUNC; |
|
1003 } |
|
1004 |
|
1005 void CMediaDsDataStore::HandleOpenL(const CMPXMedia& /*aEntries*/, |
|
1006 TInt /*aIndex*/,TBool /*aComplete*/,TInt /*aError*/) |
|
1007 { |
|
1008 TRACE_FUNC; |
|
1009 } |
|
1010 |
|
1011 void CMediaDsDataStore::HandleOpenL(const CMPXCollectionPlaylist& /*aPlaylist*/, |
|
1012 TInt /*aError*/) |
|
1013 { |
|
1014 TRACE_FUNC; |
|
1015 } |
|
1016 |
|
1017 void CMediaDsDataStore::HandleCommandComplete(CMPXCommand* /*aCommandResult*/, |
|
1018 TInt /*aError*/) |
|
1019 { |
|
1020 TRACE_FUNC; |
|
1021 } |
|
1022 |
|
1023 void CMediaDsDataStore::HandleCollectionMediaL(const CMPXMedia& /*aMedia*/, |
|
1024 TInt /*aError*/) |
|
1025 { |
|
1026 TRACE_FUNC; |
|
1027 } |
|
1028 |
|
1029 void CMediaDsDataStore::AlbumsReaded( TInt aError ) |
|
1030 { |
|
1031 TRACE_FUNC_ENTRY; |
|
1032 iMdEManagerReady = ETrue; |
|
1033 LOGGER_WRITE_1("aError: %d", aError ); |
|
1034 |
|
1035 if ( aError ) |
|
1036 { |
|
1037 iError = aError; |
|
1038 } |
|
1039 |
|
1040 FinalizeOpenStore(); |
|
1041 |
|
1042 TRACE_FUNC_EXIT; |
|
1043 } |
|
1044 |
|
1045 void CMediaDsDataStore::AlbumReplaced( TInt aError ) |
|
1046 { |
|
1047 TRACE_FUNC_ENTRY; |
|
1048 LOGGER_WRITE_1("aError: %d", aError); |
|
1049 if ( !aError ) |
|
1050 { |
|
1051 // Inform ChangeFinder of the replaced item |
|
1052 iChangeFinder->ItemUpdatedL( iItemInReplacement ); |
|
1053 } |
|
1054 |
|
1055 iCurrentState = EOpenAndWaiting; |
|
1056 User::RequestComplete( iCallerStatus, aError ); |
|
1057 TRACE_FUNC_EXIT; |
|
1058 } |
|
1059 |
|
1060 // ----------------------------------------------------------------------------- |
|
1061 // CMediaDsDataStore::RegisterSnapshotL |
|
1062 // Sets Changefinder to compare against current message store content |
|
1063 // ----------------------------------------------------------------------------- |
|
1064 void CMediaDsDataStore::RegisterSnapshotL() |
|
1065 { |
|
1066 TRACE_FUNC_ENTRY; |
|
1067 if ( iSnapshot ) |
|
1068 { |
|
1069 delete iSnapshot; |
|
1070 iSnapshot = NULL; |
|
1071 } |
|
1072 iSnapshot = new (ELeave) CSnapshotArray( KSnapshotGranularity ); |
|
1073 RegisterFoldersL( *iSnapshot ); |
|
1074 iMediaManager->SetSnapshot( iSnapshot ); |
|
1075 |
|
1076 iCurrentState = EOpening; |
|
1077 TInt err = iMediaManager->RegisterAllPlayLists(); |
|
1078 if ( err ) |
|
1079 { |
|
1080 LOGGER_WRITE_1("Could not start, err: %d", err); |
|
1081 iCurrentState = EClosed; |
|
1082 User::RequestComplete( iCallerStatus, err ); |
|
1083 } |
|
1084 else |
|
1085 { |
|
1086 iMdEManager->GetAlbumsL(); |
|
1087 } |
|
1088 |
|
1089 |
|
1090 TRACE_FUNC_EXIT; |
|
1091 } |
|
1092 |
|
1093 void CMediaDsDataStore::RegisterAllPlayListsCompleted( TInt aError ) |
|
1094 { |
|
1095 TRACE_FUNC_ENTRY; |
|
1096 if ( !aError ) |
|
1097 { |
|
1098 TInt err = iMediaManager->RegisterAllSongs(); |
|
1099 if ( err ) |
|
1100 { |
|
1101 LOGGER_WRITE_1("Could not start, err: %d", err); |
|
1102 iMediaManagerReady = ETrue; |
|
1103 iError = err; |
|
1104 } |
|
1105 } |
|
1106 else |
|
1107 { |
|
1108 // Error happened or cancelled. |
|
1109 iMediaManagerReady = ETrue; |
|
1110 iError = aError; |
|
1111 } |
|
1112 |
|
1113 FinalizeOpenStore(); |
|
1114 TRACE_FUNC_EXIT; |
|
1115 } |
|
1116 |
|
1117 void CMediaDsDataStore::RegisterAllSongsCompleted( TInt aError ) |
|
1118 { |
|
1119 TRACE_FUNC_ENTRY; |
|
1120 iMediaManagerReady = ETrue; |
|
1121 if ( aError ) |
|
1122 { |
|
1123 // Error happened or cancelled, save error code |
|
1124 iError = aError; |
|
1125 } |
|
1126 |
|
1127 FinalizeOpenStore(); |
|
1128 |
|
1129 TRACE_FUNC_EXIT; |
|
1130 } |
|
1131 |
|
1132 // ----------------------------------------------------------------------------- |
|
1133 // CMediaDsDataStore::RegisterFoldersL |
|
1134 // |
|
1135 // ----------------------------------------------------------------------------- |
|
1136 void CMediaDsDataStore::RegisterFoldersL( CSnapshotArray& aItemArray ) |
|
1137 { |
|
1138 TRACE_FUNC_ENTRY; |
|
1139 |
|
1140 TKeyArrayFix key( iKey ); |
|
1141 TSnapshotItem folder; |
|
1142 folder.SetItemId( KAllSongsFolderId ); |
|
1143 folder.SetItemHash( KAllSongs, *iHasher ); |
|
1144 aItemArray.InsertIsqL( folder, key ); |
|
1145 |
|
1146 folder.SetItemId( KPlaylistsFolderId ); |
|
1147 folder.SetItemHash( KPlaylists, *iHasher ); |
|
1148 aItemArray.InsertIsqL( folder, key ); |
|
1149 |
|
1150 folder.SetItemId( KAlbumsFolderId ); |
|
1151 folder.SetItemHash( KAlbums, *iHasher ); |
|
1152 aItemArray.InsertIsqL( folder, key ); |
|
1153 TRACE_FUNC_EXIT; |
|
1154 } |
|
1155 |
|
1156 void CMediaDsDataStore::FinalizeOpenStore() |
|
1157 { |
|
1158 TRACE_FUNC_ENTRY; |
|
1159 // Signal client if all ready |
|
1160 if ( iMediaManagerReady && iMdEManagerReady ) |
|
1161 { |
|
1162 if ( !iError ) |
|
1163 { |
|
1164 RPointerArray<CPlaylistItem> albums = iMdEManager->AlbumsArray(); |
|
1165 TKeyArrayFix key( iKey ); |
|
1166 LOGGER_WRITE("Album snapshots:") |
|
1167 for (TInt i=0; i<albums.Count(); i++) |
|
1168 { |
|
1169 TSnapshotItem playlistItem( MapAlbumIdToSyncId( albums[i]->Id() ) ); |
|
1170 playlistItem.SetItemHash( *albums[i], *iHasher ); |
|
1171 playlistItem.SetParentId( KAlbumsFolderId ); |
|
1172 TRAP(iError, iSnapshot->InsertIsqL( playlistItem, key )); |
|
1173 if ( iError ) |
|
1174 { |
|
1175 LOGGER_WRITE_1("iSnapshot->InsertIsqL err: %d", iError); |
|
1176 iError = KErrGeneral; |
|
1177 } |
|
1178 } |
|
1179 |
|
1180 if ( !iError ) |
|
1181 { |
|
1182 // Set new snapshot to compare against |
|
1183 iChangeFinder->SetNewSnapshot(iSnapshot); |
|
1184 |
|
1185 // Changefinder takes ownership of the snapshot |
|
1186 iSnapshot = NULL; |
|
1187 iCurrentState = EOpenAndWaiting; |
|
1188 } |
|
1189 } |
|
1190 |
|
1191 if ( iError ) |
|
1192 { |
|
1193 iCurrentState = EClosed; |
|
1194 } |
|
1195 |
|
1196 LOGGER_WRITE_1("Signal client with %d", iError); |
|
1197 User::RequestComplete( iCallerStatus, iError ); |
|
1198 } |
|
1199 TRACE_FUNC_EXIT; |
|
1200 } |
|
1201 |
|
1202 inline TInt CMediaDsDataStore::MapSyncIdToAlbumId( TSmlDbItemUid aSyncId ) |
|
1203 { |
|
1204 return aSyncId - KAlbumsOffSet; |
|
1205 } |
|
1206 |
|
1207 inline TSmlDbItemUid CMediaDsDataStore::MapAlbumIdToSyncId( TInt aAlbumId ) |
|
1208 { |
|
1209 return KAlbumsOffSet + aAlbumId; |
|
1210 } |
|