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 file processing |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32property.h> |
|
20 #include "cmdmmain.h" |
|
21 #include "cmstorerule.h" |
|
22 #include "cmstorelistitem.h" |
|
23 #include "cmfilllistitem.h" |
|
24 #include "cmsmfileprocessingobserver.h" |
|
25 #include "cmsmcontentchangeobserver.h" |
|
26 #include "cmsmvideoandimagemngr.h" |
|
27 #include "cmsmclfmngr.h" |
|
28 #include "cmsmiteminfo.h" |
|
29 #include "cmsmmsinfo.h" |
|
30 #include "cmsmfilemngr.h" |
|
31 #include "msdebug.h" |
|
32 |
|
33 // CONSTANTS |
|
34 const TInt KCmSmIniStoreTransferSpeed = 200; // 200 kBs |
|
35 const TInt KCmSmIniStoreTransferTime = 1; // One second |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CCmSmFileMngr::NewL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CCmSmFileMngr* CCmSmFileMngr::NewL( |
|
43 MCmSmFileProcessingObserver* aObserver, CMdESession& aSession, |
|
44 CCmDmMain* aDBMngr, RPointerArray<CCmStoreListItem>& aItems ) |
|
45 { |
|
46 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::NewL() start")); |
|
47 CCmSmFileMngr* self = CCmSmFileMngr::NewLC( |
|
48 aObserver, aSession, aDBMngr, aItems ); |
|
49 CleanupStack::Pop( self ); |
|
50 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::NewL() end")); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // CCmSmFileMngr::NewLC |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CCmSmFileMngr* CCmSmFileMngr::NewLC( |
|
59 MCmSmFileProcessingObserver* aObserver, CMdESession& aSession, |
|
60 CCmDmMain* aDBMngr, |
|
61 RPointerArray<CCmStoreListItem>& aItems ) |
|
62 { |
|
63 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::NewLC() start")); |
|
64 CCmSmFileMngr* self = new ( ELeave ) CCmSmFileMngr( |
|
65 aObserver, aDBMngr, aItems ); |
|
66 CleanupStack::PushL( self ); |
|
67 self->ConstructL( aSession ); |
|
68 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::NewLC() end")); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CCmSmFileMngr::~CCmSmFileMngr |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CCmSmFileMngr::~CCmSmFileMngr() |
|
77 { |
|
78 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::\ |
|
79 ~CCmSmFileMngr() start")); |
|
80 Cancel(); |
|
81 |
|
82 delete iVideoAndImageMngr; |
|
83 delete iClfMusicMngr; |
|
84 iRuleArray.ResetAndDestroy(); |
|
85 iRuleArray.Close(); |
|
86 |
|
87 iFilledItems.ResetAndDestroy(); |
|
88 iFilledItems.Close(); |
|
89 |
|
90 iStoredArray.ResetAndDestroy(); |
|
91 iStoredArray.Close(); |
|
92 |
|
93 iMsIds.ResetAndDestroy(); |
|
94 iMsIds.Close(); |
|
95 |
|
96 iMediaTypes.Reset(); |
|
97 iMediaTypes.Close(); |
|
98 |
|
99 delete iCcObserver; |
|
100 |
|
101 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::\ |
|
102 ~CCmSmFileMngr() end")); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // CCmSmFileMngr::CCmSmFileMngr |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CCmSmFileMngr::CCmSmFileMngr( |
|
110 MCmSmFileProcessingObserver* aObserver, CCmDmMain* aDBMngr, |
|
111 RPointerArray<CCmStoreListItem>& aItems ) |
|
112 :CActive( EPriorityStandard ), |
|
113 iObserver( aObserver ), iDBManager( aDBMngr ), iItems( aItems ) |
|
114 { |
|
115 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::CCmSmFileMngr()")); |
|
116 |
|
117 CActiveScheduler::Add( this ); |
|
118 iTransferInfo.iTotalItems = KErrNone; |
|
119 iTransferInfo.iProcessedItems = KErrNone; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CCmSmFileMngr::ConstructL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CCmSmFileMngr::ConstructL( CMdESession& aSession ) |
|
127 { |
|
128 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ConstructL()")); |
|
129 iVideoAndImageMngr = |
|
130 CCmSmVideoAndImageMngr::NewL( *this, *this, aSession, iItems ); |
|
131 iClfMusicMngr = CCmSmClfMngr::NewL( *this, *this, iItems ); |
|
132 iCcObserver = |
|
133 CCmSmContentChangeObserver::NewL( aSession, *iObserver ); |
|
134 iProcessingStatus = ECmSmNone; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // CCmSmFileMngr::StartProcessing |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CCmSmFileMngr::StartProcessing() |
|
142 { |
|
143 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::StartProcessing()")); |
|
144 |
|
145 iTransferInfo.iTotalItems = KErrNone; |
|
146 iTransferInfo.iProcessedItems = KErrNone; |
|
147 if( !iCcObserver->IsStarted() ) |
|
148 { |
|
149 TRAPD( err, iCcObserver->StartObserversL() ); |
|
150 if( err ) |
|
151 { |
|
152 TRACE(Print( _L("[STORE MNGR] StartObserversL err = %d"), |
|
153 err ) ); |
|
154 } |
|
155 } |
|
156 CompleteRequest( ECmSmPreProcessingStarted ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CCmSmFileMngr::ProcessAlbumList |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 void CCmSmFileMngr::ProcessAlbumList( TCmMediaType /*aMedia*/, |
|
164 CDesCArray& /*aArray*/ ) |
|
165 { |
|
166 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ProcessAlbumList()")); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CCmSmFileMngr::StoreItemCount |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 TInt CCmSmFileMngr::StoreItemCount() |
|
174 { |
|
175 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::StoreItemCount()")); |
|
176 |
|
177 return iDBManager->StoreFileCount( |
|
178 ECmToBeRemoved|ECmToBeShrinked|ECmKeepOnDevice ); |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // CCmSmFileMngr::FillItemCount |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 TInt CCmSmFileMngr::FillItemCount() |
|
186 { |
|
187 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::FillItemCount()")); |
|
188 |
|
189 return iDBManager->FillFileCount( ECmToBeShrinked|ECmToBeFilled ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CCmSmFileMngr::GetStoreFileCountNoDuplicatesL |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CCmSmFileMngr::GetStoreFileCountNoDuplicatesL( TInt& aCount ) |
|
197 { |
|
198 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::\ |
|
199 GetStoreFileCountNoDuplicatesL()")); |
|
200 |
|
201 iDBManager->GetStoreFileCountNoDuplicatesL( aCount, |
|
202 ECmToBeRemoved|ECmToBeShrinked|ECmKeepOnDevice ); |
|
203 TRACE(Print( _L("[STORE MNGR] GetStoreFileCountNoDuplicatesL count = %d"), |
|
204 aCount ) ); |
|
205 TInt count = 0; |
|
206 TInt time = 0; |
|
207 iDBManager->GetTransferInfo( ECmServiceStore, count, time ); |
|
208 iDBManager->UpdateTransferInfo( ECmServiceStore, aCount, |
|
209 time ); |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CCmSmFileMngr::UpdateTransferHistoryData |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CCmSmFileMngr::UpdateTransferHistoryData( |
|
217 TInt64 aInterval, TInt64 aDataAmount, |
|
218 TUint8 aServerId ) |
|
219 { |
|
220 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::UpdateTransferHistoryData()")); |
|
221 |
|
222 iDBManager->UpdateUploadHistory( aServerId, |
|
223 aDataAmount, aInterval ); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CCmSmFileMngr::CancelOperation |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CCmSmFileMngr::CancelOperation() |
|
231 { |
|
232 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::CancelOperation()")); |
|
233 |
|
234 Cancel(); |
|
235 iVideoAndImageMngr->CancelOperation(); |
|
236 iClfMusicMngr->CancelOperation(); |
|
237 iObserver->FileProcessingStatus( ECmSmProcessingCanceled ); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CCmSmFileMngr::ImagesAndVideosReady |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CCmSmFileMngr::ImagesAndVideosReady( const TInt /*aStatus*/ ) |
|
245 { |
|
246 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ImagesAndVideosReady()")); |
|
247 |
|
248 CompleteRequest( ECmSmMediaTypesSelected ); |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CCmSmFileMngr::MusicReady |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CCmSmFileMngr::MusicReady( const TInt /*aStatus*/ ) |
|
256 { |
|
257 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::MusicReady()")); |
|
258 |
|
259 CompleteRequest( ECmSmMediaTypesSelected ); |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // CCmSmFileMngr::LoadSelectedStoreRulesL |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CCmSmFileMngr::LoadSelectedStoreRulesL() |
|
267 { |
|
268 LOG(_L("[FILL MNGR]\t CCmSmFileMngr::LoadSelectedStoreRulesL()")); |
|
269 |
|
270 RPointerArray<HBufC8> array; |
|
271 CleanupClosePushL( array ); |
|
272 iDBManager->PrepareQueryCmdL( ESelectedStoreRuleQuery ); |
|
273 iDBManager->QuerySelectedStoreRuleNamesL( array, 1 ); |
|
274 // Load selected store rules to array ( using names as a qyery |
|
275 // parameter ) |
|
276 for( TInt i = 0; i < array.Count(); i++ ) |
|
277 { |
|
278 CCmStoreRule* storeRule = CCmStoreRule::NewLC(); |
|
279 iDBManager->PrepareQueryCmdL(EStoreRuleQuery); |
|
280 storeRule->SetNameL( *array[i] ); |
|
281 iDBManager->QueryStoreRuleL( storeRule ); |
|
282 iRuleArray.AppendL( storeRule ); |
|
283 CleanupStack::Pop(storeRule); |
|
284 } |
|
285 array.ResetAndDestroy(); |
|
286 CleanupStack::PopAndDestroy( &array ); |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CCmSmFileMngr::ProcessStoreRules |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CCmSmFileMngr::ProcessStoreRules() |
|
294 { |
|
295 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ProcessStoreRules()")); |
|
296 |
|
297 TPtrC8 mediaServer; |
|
298 for( TInt i = iRuleArray.Count() - 1; i >= 0; i-- ) |
|
299 { |
|
300 if( KErrNone == iRuleArray[i]->MediaServerCount() ) |
|
301 { |
|
302 // If no servers defined => DO NOT use rule at all |
|
303 // First delete the object |
|
304 delete iRuleArray[i]; |
|
305 // Then delete the pointer |
|
306 iRuleArray.Remove(i); |
|
307 LOG(_L("[STORE MNGR]\t Store rule doesn't have any \ |
|
308 defined servers")); |
|
309 LOG(_L("[STORE MNGR]\t ******* ==> RULE SKIPPED \ |
|
310 ******************")); |
|
311 } |
|
312 else |
|
313 { |
|
314 // Do nothing |
|
315 } |
|
316 } |
|
317 iRuleArray.Compress(); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // CCmSmFileMngr::LoadFilledAndStoredL |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 void CCmSmFileMngr::LoadFilledAndStoredL() |
|
325 { |
|
326 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::LoadFilledAndStoredL()")); |
|
327 |
|
328 LoadMediaServerIdsL(); |
|
329 LoadFilledL(); |
|
330 for( TInt i = 0; i < iMsIds.Count(); i++ ) |
|
331 { |
|
332 LoadStoredL( *iMsIds[i]->iUuid ); |
|
333 } |
|
334 CompleteRequest( ECmSmAllLoaded ); |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // CCmSmFileMngr::LoadFilledL |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CCmSmFileMngr::LoadFilledL() |
|
342 { |
|
343 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::LoadFilledL()")); |
|
344 |
|
345 iFilledItems.ResetAndDestroy(); |
|
346 iFilledItems.Close(); |
|
347 iDBManager->PrepareQueryCmdL(EAllFillFilesStatusQuery); |
|
348 iDBManager->GetAllFillFilesL( |
|
349 iFilledItems,ECmFilled|ECmToBeRemoved|ECmLocalCopy ); |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CCmSmFileMngr::LoadStoredL |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 void CCmSmFileMngr::LoadStoredL( const TDesC8& aUDN ) |
|
357 { |
|
358 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::LoadStoredL()")); |
|
359 |
|
360 // Load to spesific server filled items |
|
361 iDBManager->PrepareQueryCmdL( EMediaServerIdQuery ); |
|
362 TInt64 id( iDBManager->QueryMediaServerId( aUDN ) ); |
|
363 if( KErrNone < id ) |
|
364 { |
|
365 RPointerArray<HBufC16> array; |
|
366 CleanupClosePushL( array ); |
|
367 iDBManager->PrepareQueryCmdL(EStoredRowQuery); |
|
368 iDBManager->QueryStoredRowL( array, aUDN, KErrNotFound ); |
|
369 for( TInt i = 0; i < array.Count(); i++ ) |
|
370 { |
|
371 CCmSmItemInfo* storedItemInfo = |
|
372 CCmSmItemInfo::NewLC( *array[i], id ); |
|
373 iStoredArray.Append( storedItemInfo ); |
|
374 CleanupStack::Pop( storedItemInfo ); |
|
375 } |
|
376 // Ownership didn't change, reset and destroy |
|
377 array.ResetAndDestroy(); |
|
378 CleanupStack::PopAndDestroy( &array ); |
|
379 } |
|
380 else |
|
381 { |
|
382 LOG(_L("[STORE MNGR]\t No media server id found")); |
|
383 } |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------------------------- |
|
387 // CCmSmFileMngr::ResetFilledArray |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 void CCmSmFileMngr::ResetFilledArray() |
|
391 { |
|
392 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ResetFilledArray()")); |
|
393 |
|
394 iFilledItems.ResetAndDestroy(); |
|
395 iFilledItems.Close(); |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------------------------- |
|
399 // CCmSmFileMngr::SelectMediaTypes |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 void CCmSmFileMngr::SelectMediaTypes() |
|
403 { |
|
404 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::SelectMediaTypes()")); |
|
405 |
|
406 TCmMediaType mediaType; |
|
407 for( TInt i = 0; i < iRuleArray.Count(); i++ ) |
|
408 { |
|
409 for( TInt j = 0; j < iRuleArray[i]->DefCount(); j++ ) |
|
410 { |
|
411 iRuleArray[i]->StoreRule( j, &mediaType ); |
|
412 if( KErrNotFound == iMediaTypes.Find( mediaType ) ) |
|
413 { |
|
414 iMediaTypes.Append( mediaType ); |
|
415 } |
|
416 } |
|
417 } |
|
418 iRefreshIndex = 0; |
|
419 CompleteRequest( ECmSmMediaTypesSelected ); |
|
420 } |
|
421 |
|
422 // --------------------------------------------------------------------------- |
|
423 // CCmSmFileMngr::CheckIsFilledFileL |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 TBool CCmSmFileMngr::CheckIsFilledFileL( const TDesC& aPathAndFileName ) |
|
427 { |
|
428 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::CheckIsFilledFileL()")); |
|
429 |
|
430 TBool processed( EFalse ); |
|
431 // Check if file is filled from some listed server |
|
432 for( TInt j = 0; j < iFilledItems.Count() && !processed; j++ ) |
|
433 { |
|
434 if( KErrNotFound != aPathAndFileName.FindC( |
|
435 iFilledItems[j]->Path() ) ) |
|
436 { |
|
437 LOG(_L("[STORE MNGR]\t Filled file!!!")); |
|
438 LOG(_L("[STORE MNGR]\t File not stored!!!")); |
|
439 processed = ETrue; |
|
440 // End loop |
|
441 j = iFilledItems.Count(); |
|
442 } |
|
443 } |
|
444 return processed; |
|
445 } |
|
446 |
|
447 // --------------------------------------------------------------------------- |
|
448 // CCmSmFileMngr::IsAlreadyStoreL |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 void CCmSmFileMngr::IsAlreadyStoreL( const TDesC& aPathAndFileName, |
|
452 RArray<TInt>& aStoredIds, RArray<TInt>& aStoreIds ) |
|
453 { |
|
454 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::IsAlreadyStoreL()")); |
|
455 |
|
456 // Check if file is already stored to some of the defined servers |
|
457 for( TInt k = 0; k < iStoredArray.Count() ;k++ ) |
|
458 { |
|
459 if( KErrNone == iStoredArray[k]->iFile-> |
|
460 Compare( aPathAndFileName ) ) |
|
461 { |
|
462 for( TInt l = aStoreIds.Count() - 1; l >= 0; l-- ) |
|
463 { |
|
464 if( aStoreIds[l] == iStoredArray[k]->iId ) |
|
465 { |
|
466 aStoredIds.Append( aStoreIds[l] ); |
|
467 aStoreIds.Remove(l); |
|
468 LOG(_L("[STORE MNGR]\t Stored file!!!")); |
|
469 } |
|
470 } |
|
471 aStoreIds.Compress(); |
|
472 } |
|
473 } |
|
474 } |
|
475 |
|
476 // --------------------------------------------------------------------------- |
|
477 // CCmSmFileMngr::MediaTypesL |
|
478 // --------------------------------------------------------------------------- |
|
479 // |
|
480 void CCmSmFileMngr::MediaTypesL( RArray<TInt>& aIds, TCmMediaType aType ) |
|
481 { |
|
482 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::MediaTypesL()")); |
|
483 |
|
484 // Loop for store rules |
|
485 for( TInt i = 0; i < iRuleArray.Count(); i++ ) |
|
486 { |
|
487 TBool addServers = EFalse; |
|
488 TInt msCount(iRuleArray[i]->MediaServerCount()); |
|
489 TInt defCount( iRuleArray[i]->DefCount() ); |
|
490 TCmMediaType temptype; |
|
491 |
|
492 // In specific store rule, loop to check if the rule has relevant |
|
493 // media type. |
|
494 for( TInt n = 0; n < defCount; n++ ) |
|
495 { |
|
496 iRuleArray[i]->StoreRule(n, &temptype ); |
|
497 if( aType == temptype ) |
|
498 { |
|
499 addServers = ETrue; |
|
500 } |
|
501 } |
|
502 if( addServers ) |
|
503 { |
|
504 // Loop for media servers |
|
505 for( TInt k = 0; k < msCount ; k++ ) |
|
506 { |
|
507 const TPtrC8 ms = iRuleArray[i]->MediaServerL( k ); |
|
508 |
|
509 // To find if Uuid of ms has been in iMsIds. |
|
510 for( TInt l = 0 ; l < iMsIds.Count(); l++ ) |
|
511 { |
|
512 if( KErrNone == ms.Compare( *iMsIds[l]->iUuid ) ) |
|
513 { |
|
514 aIds.InsertInOrderL( iMsIds[l]->iId ); |
|
515 // End loop |
|
516 l = iMsIds.Count(); |
|
517 } |
|
518 } |
|
519 } |
|
520 } |
|
521 } |
|
522 } |
|
523 |
|
524 // --------------------------------------------------------------------------- |
|
525 // CCmSmFileMngr::LoadMediaServerIdsL |
|
526 // --------------------------------------------------------------------------- |
|
527 // |
|
528 void CCmSmFileMngr::LoadMediaServerIdsL() |
|
529 { |
|
530 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::LoadMediaServerIdsL()")); |
|
531 |
|
532 TInt64 id(KErrNone); |
|
533 RArray<TInt64> tempIds; |
|
534 CleanupClosePushL( tempIds ); |
|
535 for( TInt i = 0; i < iRuleArray.Count(); i++ ) |
|
536 { |
|
537 for( TInt j = 0 ; j < iRuleArray[i]->MediaServerCount(); j++ ) |
|
538 { |
|
539 const TDesC8& mediaServer = iRuleArray[i]->MediaServerL( j ); |
|
540 iDBManager->PrepareQueryCmdL( EMediaServerIdQuery ); |
|
541 id = iDBManager->QueryMediaServerId( mediaServer ); |
|
542 if( KErrNone < id && KErrNotFound == tempIds.Find(id) ) |
|
543 { |
|
544 HBufC8* uuid = mediaServer.AllocLC(); |
|
545 CCmSmMsInfo* msInfo = CCmSmMsInfo::NewLC( *uuid, id ); |
|
546 tempIds.AppendL(id); |
|
547 iMsIds.AppendL(msInfo); |
|
548 CleanupStack::Pop( msInfo ); |
|
549 CleanupStack::PopAndDestroy( uuid ); |
|
550 } |
|
551 } |
|
552 } |
|
553 tempIds.Reset(); |
|
554 CleanupStack::PopAndDestroy( &tempIds ); |
|
555 } |
|
556 |
|
557 // --------------------------------------------------------------------------- |
|
558 // CCmSmFileMngr::GetDevId |
|
559 // --------------------------------------------------------------------------- |
|
560 // |
|
561 TInt64 CCmSmFileMngr::GetDevId( const TDesC8& aUuid ) |
|
562 { |
|
563 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::GetDevId()")); |
|
564 |
|
565 TInt64 id( KErrNone ); |
|
566 TBool flag( EFalse ); |
|
567 for( TInt i = 0; i < iMsIds.Count() && !flag; i++ ) |
|
568 { |
|
569 if( KErrNotFound != iMsIds[i]->iUuid->Match( aUuid ) ) |
|
570 { |
|
571 id = iMsIds[i]->iId; |
|
572 flag = ETrue; |
|
573 } |
|
574 } |
|
575 return id; |
|
576 } |
|
577 |
|
578 // --------------------------------------------------------------------------- |
|
579 // CCmSmFileMngr::GetItemsL |
|
580 // --------------------------------------------------------------------------- |
|
581 // |
|
582 void CCmSmFileMngr::GetItemsL( RArray<TInt>& aItemIds, |
|
583 const TDesC8& aUuid, TInt64& aId ) |
|
584 { |
|
585 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::GetItemsL()")); |
|
586 |
|
587 aItemIds.Reset(); |
|
588 |
|
589 RArray<TInt>ids; |
|
590 RArray<TCmListItemStatus> statusValues; |
|
591 |
|
592 aId = GetDevId( aUuid ); |
|
593 for( TInt i = 0; i < iItems.Count() && aId != KErrNone; i++ ) |
|
594 { |
|
595 ids = iItems[i]->DevIds(); |
|
596 statusValues = iItems[i]->StatusValues(); |
|
597 TInt index( ids.FindInOrder( aId ) ); |
|
598 if( KErrNotFound != index ) |
|
599 { |
|
600 TBool itemOnSelectedList( EFalse ); |
|
601 // check that item belongs to selected list |
|
602 for ( TInt j = 0; j < iRuleArray.Count(); j++ ) |
|
603 { |
|
604 CCmStoreRule* rule = iRuleArray[j]; |
|
605 if ( iItems[i]->ListId() == rule->ListId() ) |
|
606 { |
|
607 itemOnSelectedList = ETrue; |
|
608 } |
|
609 } |
|
610 |
|
611 // Check that item isn't stored yet |
|
612 if( index < statusValues.Count() ) |
|
613 { |
|
614 if( itemOnSelectedList && |
|
615 ECmStored != statusValues[ index ] ) |
|
616 { |
|
617 aItemIds.AppendL( i ); |
|
618 } |
|
619 } |
|
620 } |
|
621 } |
|
622 } |
|
623 |
|
624 // --------------------------------------------------------------------------- |
|
625 // CCmSmFileMngr::UpdateStoreFileListL |
|
626 // --------------------------------------------------------------------------- |
|
627 // |
|
628 void CCmSmFileMngr::UpdateStoreFileListL() |
|
629 { |
|
630 TRACE( Print( _L("[STORE MNGR]\t UpdateStoreFileListL iItemsCount = %d"), |
|
631 iItems.Count() )); |
|
632 |
|
633 iDBManager->DeleteStoreFiles(); |
|
634 iDBManager->SetStoreFilesL( iItems ); |
|
635 iItems.ResetAndDestroy(); |
|
636 iItems.Close(); |
|
637 CalculateAvgTransferTimeL(); |
|
638 SendAvgTransferTime(); |
|
639 } |
|
640 |
|
641 // --------------------------------------------------------------------------- |
|
642 // CCmSmFileMngr::LoadStoreFileListL |
|
643 // --------------------------------------------------------------------------- |
|
644 // |
|
645 void CCmSmFileMngr::LoadStoreFileListL() |
|
646 { |
|
647 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::LoadStoreFileListL()")); |
|
648 |
|
649 iItems.ResetAndDestroy(); |
|
650 iItems.Close(); |
|
651 ResetArrays(); |
|
652 LoadSelectedStoreRulesL(); |
|
653 ProcessStoreRules(); |
|
654 LoadMediaServerIdsL(); |
|
655 |
|
656 iDBManager->PrepareQueryCmdL( EAllStoreFilesQuery ); |
|
657 iDBManager->QueryAllStoreFilesL( iItems ); |
|
658 } |
|
659 |
|
660 // --------------------------------------------------------------------------- |
|
661 // CCmSmFileMngr::RetrieveListId |
|
662 // --------------------------------------------------------------------------- |
|
663 // |
|
664 TInt64 CCmSmFileMngr::RetrieveListId( TCmMediaType aType ) |
|
665 { |
|
666 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::RetrieveListId()")); |
|
667 |
|
668 TCmMediaType type; |
|
669 TUint id( KErrNone ); |
|
670 TBool flag( EFalse ); |
|
671 for( TInt i = 0; i < iRuleArray.Count() && !flag; i++ ) |
|
672 { |
|
673 TInt defCount = iRuleArray[i]->DefCount(); |
|
674 for( TInt j = 0; j < defCount && !flag; j++ ) |
|
675 { |
|
676 iRuleArray[i]->StoreRule( j, &type ); |
|
677 if( type == aType ) |
|
678 { |
|
679 flag = ETrue; |
|
680 id = iRuleArray[i]->ListId(); |
|
681 } |
|
682 } |
|
683 } |
|
684 return id; |
|
685 } |
|
686 |
|
687 // --------------------------------------------------------------------------- |
|
688 // CCmSmFileMngr::RetrieveListStatusValues |
|
689 // --------------------------------------------------------------------------- |
|
690 // |
|
691 void CCmSmFileMngr::RetrieveListStatusValues( TCmMediaType aType, |
|
692 TCmListItemStatus& aStatus ) |
|
693 { |
|
694 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::RetrieveListStatusValues()")); |
|
695 |
|
696 TCmMediaType type; |
|
697 TBool flag( EFalse ); |
|
698 for( TInt i = 0; i < iRuleArray.Count() && !flag; i++ ) |
|
699 { |
|
700 TInt defCount = iRuleArray[i]->DefCount(); |
|
701 for( TInt j = 0; j < defCount && !flag; j++ ) |
|
702 { |
|
703 iRuleArray[i]->StoreRule( j, &type ); |
|
704 if( type == aType ) |
|
705 { |
|
706 flag = ETrue; |
|
707 // Set found status value |
|
708 aStatus = iRuleArray[i]->Status(); |
|
709 } |
|
710 } |
|
711 } |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // CCmSmFileMngr::DeleteItems |
|
716 // --------------------------------------------------------------------------- |
|
717 // |
|
718 void CCmSmFileMngr::DeleteItems( RArray<TInt>& aIds ) |
|
719 { |
|
720 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::DeleteItems()")); |
|
721 |
|
722 TInt i( 0 ); |
|
723 // aIds has indexes to iItems array. |
|
724 while( aIds.Count() ) |
|
725 { |
|
726 if( ( aIds[0] - i ) < iItems.Count() ) |
|
727 { |
|
728 delete iItems[aIds[0] - i]; |
|
729 iItems.Remove( aIds[0] - i ); |
|
730 aIds.Remove(0); |
|
731 } |
|
732 i++; |
|
733 } |
|
734 iItems.Compress(); |
|
735 } |
|
736 |
|
737 // --------------------------------------------------------------------------- |
|
738 // CCmSmFileMngr::ResetArrays |
|
739 // --------------------------------------------------------------------------- |
|
740 // |
|
741 void CCmSmFileMngr::ResetArrays() |
|
742 { |
|
743 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ResetArrays()")); |
|
744 |
|
745 // Let's reset all needed array |
|
746 iRuleArray.ResetAndDestroy(); |
|
747 iRuleArray.Close(); |
|
748 |
|
749 iFilledItems.ResetAndDestroy(); |
|
750 iFilledItems.Close(); |
|
751 iStoredArray.ResetAndDestroy(); |
|
752 iStoredArray.Close(); |
|
753 |
|
754 iMsIds.ResetAndDestroy(); |
|
755 iMsIds.Close(); |
|
756 } |
|
757 |
|
758 // --------------------------------------------------------------------------- |
|
759 // CCmSmFileMngr::ProcessMedia |
|
760 // --------------------------------------------------------------------------- |
|
761 // |
|
762 void CCmSmFileMngr::ProcessMedia( TCmMediaType aType ) |
|
763 { |
|
764 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ProcessMedia")); |
|
765 switch( aType ) |
|
766 { |
|
767 case ECmAudio: |
|
768 { |
|
769 ProcessMusics(); |
|
770 break; |
|
771 } |
|
772 case ECmVideo: // Fall through |
|
773 case ECmImage: // Fall through |
|
774 case ECmOtherImage: // Fall through |
|
775 case ECmOtherVideo: // Fall through |
|
776 { |
|
777 iVideoAndImageMngr->ProcessMedia( aType ); |
|
778 break; |
|
779 } |
|
780 default: |
|
781 { |
|
782 User::Invariant(); |
|
783 break; |
|
784 } |
|
785 } |
|
786 } |
|
787 |
|
788 // --------------------------------------------------------------------------- |
|
789 // CCmSmFileMngr::ProcessMusics |
|
790 // --------------------------------------------------------------------------- |
|
791 // |
|
792 void CCmSmFileMngr::ProcessMusics() |
|
793 { |
|
794 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::ProcessMusics()")); |
|
795 |
|
796 TRAPD( err, iClfMusicMngr->DoRefreshL( ECmAudio ) ); |
|
797 if( err ) |
|
798 { |
|
799 TRACE( Print( _L( "ProcessMusics err = %d"), err )); |
|
800 CompleteRequest( ECmSmPreProcessingReady ); |
|
801 } |
|
802 } |
|
803 |
|
804 // --------------------------------------------------------------------------- |
|
805 // CCmSmFileMngr::CalculateAvgTransferTimeL |
|
806 // --------------------------------------------------------------------------- |
|
807 // |
|
808 void CCmSmFileMngr::CalculateAvgTransferTimeL() |
|
809 { |
|
810 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::CalculateAvgTransferTimeL()")); |
|
811 |
|
812 TInt64 ud(KErrNone); |
|
813 TInt64 dd(KErrNone); |
|
814 TInt64 ut(KErrNone); |
|
815 TInt64 dt(KErrNone); |
|
816 TInt64 size( KErrNone ); |
|
817 TInt64 shrinkTime(KErrNone); |
|
818 TInt64 transferTime(KErrNone); |
|
819 for( TInt i = 0; i < iMsIds.Count(); i++ ) |
|
820 { |
|
821 iDBManager->PrepareQueryCmdL(ETransferHistoryQuery); |
|
822 iDBManager->QueryTransferHistory( |
|
823 *iMsIds[i]->iUuid, dd, ud, dt, ut ); |
|
824 size = iDBManager->KBytesToBeStored( iMsIds[i]->iId, |
|
825 ECmToBeRemoved|ECmToBeShrinked|ECmKeepOnDevice ); |
|
826 if( ud == KErrNone || ut == KErrNone ) |
|
827 { |
|
828 ud = KCmSmIniStoreTransferSpeed; |
|
829 ut = KCmSmIniStoreTransferTime; |
|
830 } |
|
831 transferTime = transferTime + (( ut * size ) / ud ); |
|
832 } |
|
833 |
|
834 TInt shrinkCount( iDBManager->StoreFileCount(ECmToBeShrinked) ); |
|
835 |
|
836 shrinkTime = (iDBManager->GetAvgImageShrinkTime() * shrinkCount); |
|
837 |
|
838 TInt totalCount(KErrNone); |
|
839 totalCount = iDBManager->StoreFileCountNoDuplicates(); |
|
840 transferTime = transferTime + (shrinkTime / 1000 ); |
|
841 if( KErrNone >= totalCount ) |
|
842 { |
|
843 transferTime = KErrNone; |
|
844 } |
|
845 iDBManager->UpdateTransferInfo( ECmServiceStore, totalCount, |
|
846 transferTime ); |
|
847 } |
|
848 |
|
849 // --------------------------------------------------------------------------- |
|
850 // CCmSmFileMngr::SendAvgTransferTime |
|
851 // --------------------------------------------------------------------------- |
|
852 // |
|
853 void CCmSmFileMngr::SendAvgTransferTime() |
|
854 { |
|
855 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::SendAvgTransferTime()")); |
|
856 |
|
857 iDBManager->GetTransferInfo( ECmServiceStore, |
|
858 iTransferInfo.iProcessedItems, iTransferInfo.iTotalItems ); |
|
859 iTransferInfo.iService = ECmServiceTransferInfoStore; |
|
860 |
|
861 TRACE( Print( _L("[STORE MNGR]\t Store file count %d"), |
|
862 iTransferInfo.iProcessedItems)); |
|
863 |
|
864 TCmProgressInfoPckg transferInfoPckg( iTransferInfo ); |
|
865 |
|
866 TInt err = RProperty::Set( KCmPropertyCat, KCmProperty, |
|
867 transferInfoPckg ); |
|
868 |
|
869 TRACE( Print( _L("[STORE MNGR]\t RProperty::Set returned %d"), err)); |
|
870 } |
|
871 |
|
872 // --------------------------------------------------------------------------- |
|
873 // CCmSmFileMngr::SetProcessingStatus |
|
874 // --------------------------------------------------------------------------- |
|
875 // |
|
876 void CCmSmFileMngr::SetProcessingStatus( TCmSmFileProcessingStatus aStatus ) |
|
877 { |
|
878 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::SetProcessingStatus()")); |
|
879 |
|
880 iProcessingStatus = aStatus; |
|
881 } |
|
882 |
|
883 // --------------------------------------------------------------------------- |
|
884 // CCmSmFileMngr::CompleteRequest |
|
885 // --------------------------------------------------------------------------- |
|
886 // |
|
887 void CCmSmFileMngr::CompleteRequest( |
|
888 TCmSmFileProcessingStatus aStatus ) |
|
889 { |
|
890 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::CompleteRequest()")); |
|
891 |
|
892 __ASSERT_DEBUG(!IsActive(),\ |
|
893 User::Panic( KCmSmManager, KErrInUse )); |
|
894 SetActive(); |
|
895 TRequestStatus* pStatus = &iStatus; |
|
896 User::RequestComplete( pStatus, aStatus ); |
|
897 } |
|
898 |
|
899 // --------------------------------------------------------------------------- |
|
900 // CCmSmFileMngr::RunL |
|
901 // --------------------------------------------------------------------------- |
|
902 // |
|
903 void CCmSmFileMngr::RunL() |
|
904 { |
|
905 TRACE(Print(_L("[STORE MNGR]\t CCmSmFileMngr::RunL\ |
|
906 status = %d"), iStatus.Int() )); |
|
907 switch( iStatus.Int() ) |
|
908 { |
|
909 case ECmSmPreProcessingStarted: |
|
910 { |
|
911 LoadSelectedStoreRulesL(); |
|
912 CompleteRequest( ECmSmStoreRulesLoaded ); |
|
913 break; |
|
914 } |
|
915 case ECmSmStoreRulesLoaded: |
|
916 { |
|
917 ProcessStoreRules(); |
|
918 if( KErrNone < iRuleArray.Count() ) |
|
919 { |
|
920 CompleteRequest( ECmSmLoadFilledAndStored ); |
|
921 } |
|
922 else |
|
923 { |
|
924 // No selected rules => Delete all store files |
|
925 TInt err( iDBManager->DeleteStoreFiles() ); |
|
926 TRACE(Print(_L("[STORE MNGR]\t DeleteStoreFiles error = %d"), |
|
927 err )); |
|
928 CalculateAvgTransferTimeL(); |
|
929 SendAvgTransferTime(); |
|
930 iObserver->FileProcessingStatus( ECmSmNoStoreRulesSelected ); |
|
931 } |
|
932 break; |
|
933 } |
|
934 case ECmSmLoadFilledAndStored: |
|
935 { |
|
936 LoadFilledAndStoredL(); |
|
937 break; |
|
938 } |
|
939 case ECmSmAllLoaded: |
|
940 { |
|
941 SelectMediaTypes(); |
|
942 break; |
|
943 } |
|
944 case ECmSmMediaTypesSelected: |
|
945 { |
|
946 if( iMediaTypes.Count() > iRefreshIndex ) |
|
947 { |
|
948 ProcessMedia( iMediaTypes[iRefreshIndex] ); |
|
949 iRefreshIndex++; |
|
950 if( iProcessingStatus == ECmSmProcessingFilesStarted ) |
|
951 { |
|
952 iObserver->FileProcessingStatus( iProcessingStatus ); |
|
953 iProcessingStatus = ECmSmNone; |
|
954 } |
|
955 } |
|
956 else |
|
957 { |
|
958 LOG(_L("[STORE MNGR]\t Store list processing ready")); |
|
959 UpdateStoreFileListL(); |
|
960 CompleteRequest( ECmSmPreProcessingReady ); |
|
961 } |
|
962 break; |
|
963 } |
|
964 case ECmSmPreProcessingReady: |
|
965 { |
|
966 ResetArrays(); |
|
967 if( iProcessingStatus == ECmSmProcessingFilesStarted ) |
|
968 { |
|
969 iObserver->FileProcessingStatus( iProcessingStatus ); |
|
970 iProcessingStatus = ECmSmNone; |
|
971 } |
|
972 iObserver->FileProcessingStatus( ECmSmPreProcessingReady ); |
|
973 break; |
|
974 } |
|
975 default: |
|
976 { |
|
977 LOG(_L("[STORE MNGR]\t Store file processing RunL default")); |
|
978 User::Invariant(); |
|
979 break; |
|
980 } |
|
981 } |
|
982 } |
|
983 |
|
984 // --------------------------------------------------------------------------- |
|
985 // CCmSmFileMngr::DoCancel |
|
986 // --------------------------------------------------------------------------- |
|
987 // |
|
988 void CCmSmFileMngr::DoCancel() |
|
989 { |
|
990 LOG(_L("[STORE MNGR]\t CCmSmFileMngr::DoCancel()")); |
|
991 } |
|
992 |
|
993 // --------------------------------------------------------------------------- |
|
994 // CCmSmFileMngr::RunError |
|
995 // --------------------------------------------------------------------------- |
|
996 // |
|
997 TInt CCmSmFileMngr::RunError( TInt aError ) |
|
998 { |
|
999 TRACE(Print(_L("[STORE MNGR]\t CCmSmFileMngr::RunError\ |
|
1000 aError = %d"), aError )); |
|
1001 return aError; |
|
1002 } |
|
1003 |
|
1004 // End of file |
|
1005 |
|
1006 |
|
1007 |
|