|
1 /* |
|
2 * Copyright (c) 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: Class create for testing. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "mediafiletest.h" |
|
24 #include "mediafiledialog.h" |
|
25 #include "mediafilepreview.h" |
|
26 #include "mediafilelistdebug.h" |
|
27 |
|
28 #include <mediafilelist.rsg> |
|
29 |
|
30 #include <aknappui.h> // for macro iAvkonAppUi |
|
31 #include <eikcapc.h> // for CEikCaptionedControl |
|
32 #include <e32math.h> // Math::FRand |
|
33 |
|
34 #include <bautils.h> // bafl.lib |
|
35 #include <s32file.h> // RFileReadStream |
|
36 |
|
37 |
|
38 |
|
39 #ifdef _DEBUG |
|
40 /****************************************************************************** |
|
41 * class CMFDialogTest |
|
42 ******************************************************************************/ |
|
43 |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CMFDialogTest::NewL |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 CMFDialogTest* CMFDialogTest::NewL( CMediaFileDialog* aDialog ) |
|
51 { |
|
52 CMFDialogTest* self = new (ELeave) CMFDialogTest( aDialog ); |
|
53 CleanupStack::PushL(self); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop(self); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CMFDialogTest::CMFDialogTest |
|
63 // |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CMFDialogTest::CMFDialogTest( CMediaFileDialog* aDialog ) |
|
67 { |
|
68 iDlg = aDialog; |
|
69 |
|
70 iTestCounter = 0; |
|
71 iBottomVisited = EFalse; |
|
72 iDestroyedPtr = NULL; |
|
73 } |
|
74 |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CMFDialogTest::~CMFDialogTest() |
|
82 { |
|
83 SetScreenSaverPeriod( iScreenSaverPeriod ); |
|
84 |
|
85 delete iTestCaller; |
|
86 delete iRandomNum; |
|
87 |
|
88 if ( iPopupNote ) |
|
89 { |
|
90 iPopupNote->HideInfoPopupNote(); |
|
91 delete iPopupNote; |
|
92 } |
|
93 |
|
94 if ( iDestroyedPtr ) |
|
95 { |
|
96 *iDestroyedPtr = ETrue; |
|
97 iDestroyedPtr = NULL; |
|
98 } |
|
99 } |
|
100 |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CMFDialogTest::ConstructL |
|
104 // |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CMFDialogTest::ConstructL() |
|
108 { |
|
109 const TInt KLongPeriod = 60*60*24; // 24 h in seconds |
|
110 |
|
111 iTestCaller = CMFActiveCaller::NewL( this ); |
|
112 iRandomNum = CRandomNum::NewL(); |
|
113 |
|
114 iScreenSaverPeriod = ScreenSaverPeriodL(); |
|
115 SetScreenSaverPeriod( KLongPeriod ); |
|
116 |
|
117 iPopupNote = CAknInfoPopupNoteController::NewL(); |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CMFDialogTest::TestL |
|
123 // |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 TBool CMFDialogTest::TestL( TInt /*aAttr*/ ) |
|
127 { |
|
128 TInt index = 0; |
|
129 CDesCArray *arr = new(ELeave) CDesCArrayFlat( 1 ); |
|
130 CleanupStack::PushL( arr ); |
|
131 |
|
132 arr->AppendL(_L("random play")); |
|
133 arr->AppendL(_L("test 1")); |
|
134 arr->AppendL(_L("test 2")); |
|
135 |
|
136 if ( !TMFDialogUtil::ShowListQueryL( _L("huu"), arr, &index ) ) |
|
137 { |
|
138 CleanupStack::PopAndDestroy( arr ); |
|
139 return EFalse; |
|
140 } |
|
141 if ( index == 0 ) |
|
142 { |
|
143 NextListItemL(); |
|
144 } |
|
145 else if ( index == 1 ) |
|
146 { |
|
147 Test1L( 0 ); |
|
148 } |
|
149 else if ( index == 2 ) |
|
150 { |
|
151 Test2L( 0 ); |
|
152 } |
|
153 else |
|
154 { |
|
155 } |
|
156 |
|
157 CleanupStack::PopAndDestroy( arr ); |
|
158 return ETrue; |
|
159 } |
|
160 |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CMFDialogTest::Test1L |
|
164 // |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CMFDialogTest::Test1L( TInt /*aAttr*/ ) |
|
168 { |
|
169 } |
|
170 |
|
171 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CMFDialogTest::Test2L |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CMFDialogTest::Test2L( TInt /*aAttr*/ ) |
|
179 { |
|
180 TInt num10 = 0; TInt num11 = 0; TInt num12 = 0; |
|
181 TInt num13 = 0; TInt num14 = 0; TInt num15 = 0; |
|
182 TInt num16 = 0; TInt num17 = 0; TInt num18 = 0; |
|
183 TInt num19 = 0; TInt num20 = 0; TInt numOther = 0; |
|
184 |
|
185 for (TInt i=0; i<100000; i++) |
|
186 { |
|
187 TInt num = iRandomNum->Random( 10, 20 ); |
|
188 |
|
189 if ( num == 10 ) |
|
190 { |
|
191 num10++; |
|
192 } |
|
193 else if ( num == 11 ) |
|
194 { |
|
195 num11++; |
|
196 } |
|
197 else if ( num == 12 ) |
|
198 { |
|
199 num12++; |
|
200 } |
|
201 else if ( num == 13 ) |
|
202 { |
|
203 num13++; |
|
204 } |
|
205 else if ( num == 14 ) |
|
206 { |
|
207 num14++; |
|
208 } |
|
209 else if ( num == 15 ) |
|
210 { |
|
211 num15++; |
|
212 } |
|
213 else if ( num == 16 ) |
|
214 { |
|
215 num16++; |
|
216 } |
|
217 else if ( num == 17 ) |
|
218 { |
|
219 num17++; |
|
220 } |
|
221 else if ( num == 18 ) |
|
222 { |
|
223 num18++; |
|
224 } |
|
225 else if ( num == 19 ) |
|
226 { |
|
227 num19++; |
|
228 } |
|
229 else if ( num == 20 ) |
|
230 { |
|
231 num20++; |
|
232 } |
|
233 else |
|
234 { |
|
235 numOther++; |
|
236 } |
|
237 |
|
238 } |
|
239 |
|
240 } |
|
241 |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMFDialogTest::NextFolderL |
|
245 // |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 void CMFDialogTest::NextFolderL() |
|
249 { |
|
250 const TInt KDelay = 2000; |
|
251 |
|
252 TBool destroyed = EFalse; |
|
253 iDestroyedPtr = &destroyed; // updated in this class destructor |
|
254 |
|
255 TInt currentFolder = iDlg->iState->CurrentFolder(); |
|
256 TInt currentIndex = iDlg->CurrentItemListIndex(); |
|
257 TInt folderId = iDlg->iState->FolderId( currentIndex ); |
|
258 |
|
259 if ( currentFolder == EEFolderRoot ) |
|
260 { |
|
261 // root folder |
|
262 iBottomVisited = EFalse; |
|
263 if ( iRandomNum->Match( 30 ) ) |
|
264 { |
|
265 SimulateSearchEventL(); // search |
|
266 } |
|
267 else if ( folderId == EEFolderMusic || folderId == EEFolderTones || |
|
268 folderId == EEFolderRecordings || folderId == EEFolderVideos ) |
|
269 { |
|
270 SimulateOpenEventL(); // go down |
|
271 } |
|
272 else |
|
273 { |
|
274 iTestCaller->Start( ENextListItem, KDelay ); |
|
275 } |
|
276 } |
|
277 else if ( currentIndex == KErrNotFound ) |
|
278 { |
|
279 // empty folder |
|
280 SimulateBackEventL(); // go up |
|
281 } |
|
282 else if ( folderId == KErrNotFound ) |
|
283 { |
|
284 // this folder has files, not subfolders |
|
285 iBottomVisited = ETrue; |
|
286 if ( iRandomNum->Match( 50 ) ) |
|
287 { |
|
288 // stay in this folder and select a file |
|
289 iTestCaller->Start( ENextListItem, KDelay ); |
|
290 return; |
|
291 } |
|
292 else |
|
293 { |
|
294 SimulateBackEventL(); // go up |
|
295 } |
|
296 } |
|
297 else // this folder has subfolders |
|
298 { |
|
299 TInt num = 15; |
|
300 if ( !iBottomVisited ) |
|
301 { |
|
302 num = 85; |
|
303 } |
|
304 |
|
305 if ( iRandomNum->Match( num ) ) |
|
306 { |
|
307 SimulateOpenEventL(); // go down |
|
308 } |
|
309 else |
|
310 { |
|
311 SimulateBackEventL(); // go up |
|
312 } |
|
313 } |
|
314 |
|
315 // select listbox item after delay |
|
316 if ( !destroyed ) |
|
317 { |
|
318 iDestroyedPtr = NULL; |
|
319 iTestCaller->Start( ENextListItem, KDelay ); |
|
320 } |
|
321 } |
|
322 |
|
323 |
|
324 // ----------------------------------------------------------------------------- |
|
325 // CMFDialogTest::NextListItemL |
|
326 // |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CMFDialogTest::NextListItemL() |
|
330 { |
|
331 const TInt KDelay = 250; |
|
332 const TInt KLongDelay = 2000; |
|
333 |
|
334 TInt delay = KDelay; |
|
335 |
|
336 TInt currentIndex = iDlg->CurrentItemListIndex(); |
|
337 TInt folderId = iDlg->iState->FolderId( currentIndex ); |
|
338 |
|
339 if ( folderId == KErrNotFound && currentIndex == 0 ) |
|
340 { |
|
341 // this folder contain files - make delay longer to |
|
342 // allow first file preview |
|
343 delay = KLongDelay; |
|
344 } |
|
345 |
|
346 TInt itemCount = iDlg->iListBox->Model()->NumberOfItems(); |
|
347 iNewIndex = iRandomNum->Random( itemCount - 1); |
|
348 |
|
349 if ( iDlg->iState->CurrentFolder() == EEFolderRoot ) |
|
350 { |
|
351 if ( iRandomNum->Match( 50 ) ) |
|
352 { |
|
353 iNewIndex = 2; // more chances to Music folder |
|
354 } |
|
355 } |
|
356 |
|
357 if ( iNewIndex == currentIndex ) |
|
358 { |
|
359 iTestCaller->Start( ENextFolder, delay ); |
|
360 } |
|
361 else |
|
362 { |
|
363 iTestCaller->Start( EMovePosition, delay ); |
|
364 } |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CMFDialogTest::MovePositionL |
|
370 // |
|
371 // Scrolls listbox until selected item (iNewIndex) is found. |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 void CMFDialogTest::MovePositionL() |
|
375 { |
|
376 const TInt KMoveDelay = 150; |
|
377 const TInt KThousand = 1000; |
|
378 |
|
379 TInt currentIndex = iDlg->CurrentItemListIndex(); |
|
380 TInt folderId = iDlg->iState->FolderId( currentIndex ); |
|
381 TInt itemCount = iDlg->iListBox->Model()->NumberOfItems(); |
|
382 |
|
383 TBool itemFound = EFalse; |
|
384 if ( currentIndex == iNewIndex ) |
|
385 { |
|
386 itemFound = ETrue; // listbox has scrolled to new item |
|
387 } |
|
388 if ( currentIndex == KErrNotFound ) |
|
389 { |
|
390 itemFound = ETrue; // folder is empty |
|
391 } |
|
392 if ( iNewIndex >= itemCount ) |
|
393 { |
|
394 itemFound = ETrue; // wrong folder |
|
395 } |
|
396 |
|
397 if ( itemFound ) |
|
398 { |
|
399 // next listbox selection found |
|
400 |
|
401 TInt delay = KMoveDelay; |
|
402 if ( folderId == KErrNotFound ) |
|
403 { |
|
404 // selection is file - allow time for preview |
|
405 delay = iRandomNum->Random( 3, 10 ); |
|
406 delay = delay * KThousand; |
|
407 } |
|
408 iTestCaller->Start( ENextFolder, delay ); |
|
409 return; |
|
410 } |
|
411 |
|
412 // Simulate listbox item selection. |
|
413 SimulateKeyEventL( EKeyUpArrow ); |
|
414 |
|
415 //FLOG( _L("CMediaFileDialog::MovePositionL '%d/%d'"), currentIndex, iNewIndex ); |
|
416 |
|
417 iTestCaller->Start( EMovePosition, KMoveDelay ); |
|
418 } |
|
419 |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CMFDialogTest::SimulateKeyEventL |
|
423 // |
|
424 // ----------------------------------------------------------------------------- |
|
425 // |
|
426 void CMFDialogTest::SimulateKeyEventL( TInt aEvent ) |
|
427 { |
|
428 TKeyEvent key; |
|
429 key.iModifiers = 0; |
|
430 key.iRepeats = 0; |
|
431 key.iCode = aEvent; |
|
432 key.iScanCode = aEvent; |
|
433 |
|
434 //iListBox->SetCurrentItemIndexAndDraw( newIndex ); |
|
435 CCoeEnv::Static()->SimulateKeyEventL( key, EEventKey ); |
|
436 } |
|
437 |
|
438 |
|
439 // ----------------------------------------------------------------------------- |
|
440 // CMFDialogTest::SimulateOpenEventL |
|
441 // |
|
442 // ----------------------------------------------------------------------------- |
|
443 // |
|
444 void CMFDialogTest::SimulateOpenEventL() |
|
445 { |
|
446 TKeyEvent keyEvent; |
|
447 keyEvent.iCode = EKeyDevice3; |
|
448 keyEvent.iScanCode = EStdKeyDevice3; |
|
449 keyEvent.iRepeats = 0; |
|
450 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKey ); |
|
451 } |
|
452 |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CMFDialogTest::SimulateBackEventL |
|
456 // |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 void CMFDialogTest::SimulateBackEventL() |
|
460 { |
|
461 TKeyEvent keyEvent; |
|
462 keyEvent.iCode = EKeyDevice1; |
|
463 keyEvent.iScanCode = EStdKeyDevice1; |
|
464 keyEvent.iRepeats = 0; |
|
465 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKey ); |
|
466 } |
|
467 |
|
468 |
|
469 // ----------------------------------------------------------------------------- |
|
470 // CMFDialogTest::SimulateSearchEventL |
|
471 // |
|
472 // ----------------------------------------------------------------------------- |
|
473 // |
|
474 void CMFDialogTest::SimulateSearchEventL() |
|
475 { |
|
476 // letter a 97/65 |
|
477 // letter b 98/66 |
|
478 |
|
479 TKeyEvent keyEvent; |
|
480 keyEvent.iCode = 97; |
|
481 keyEvent.iScanCode = 65; |
|
482 keyEvent.iRepeats = 0; |
|
483 CCoeEnv::Static()->SimulateKeyEventL( keyEvent, EEventKey ); |
|
484 } |
|
485 |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // CMFDialogTest::SetScreenSaverPeriod |
|
489 // |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 void CMFDialogTest::SetScreenSaverPeriod( TInt aPeriod ) |
|
493 { |
|
494 TRAP_IGNORE( SetScreenSaverPeriodL( aPeriod ) ); |
|
495 } |
|
496 |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CMFDialogTest::SetScreenSaverPeriodL |
|
500 // |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 void CMFDialogTest::SetScreenSaverPeriodL( TInt aPeriod ) |
|
504 { |
|
505 // from SettingsInternalCRKeys.h |
|
506 const TUid KCRUidPersonalizationSettings = {0x101F877C}; |
|
507 const TUint32 KSettingsScreenSaverPeriod = 0x00000008; |
|
508 |
|
509 CRepository* repository = |
|
510 CRepository::NewL( KCRUidPersonalizationSettings ); |
|
511 |
|
512 // ignore error |
|
513 repository->Set( KSettingsScreenSaverPeriod, aPeriod ); |
|
514 |
|
515 delete repository; |
|
516 } |
|
517 |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // CMFDialogTest::ScreenSaverPeriodL |
|
521 // |
|
522 // ----------------------------------------------------------------------------- |
|
523 // |
|
524 TInt CMFDialogTest::ScreenSaverPeriodL() |
|
525 { |
|
526 // from SettingsInternalCRKeys.h |
|
527 const TUid KCRUidPersonalizationSettings = {0x101F877C}; |
|
528 const TUint32 KSettingsScreenSaverPeriod = 0x00000008; |
|
529 |
|
530 CRepository* repository = |
|
531 CRepository::NewL( KCRUidPersonalizationSettings ); |
|
532 |
|
533 TInt period = 60; // 60 seconds |
|
534 // ignore error |
|
535 repository->Get( KSettingsScreenSaverPeriod, period ); |
|
536 |
|
537 delete repository; |
|
538 |
|
539 return period; |
|
540 } |
|
541 |
|
542 |
|
543 // ----------------------------------------------------------------------------- |
|
544 // CMFDialogTest::HandleActiveCallL (from MMFActiveCallerObserver) |
|
545 // |
|
546 // ----------------------------------------------------------------------------- |
|
547 // |
|
548 void CMFDialogTest::HandleActiveCallL( TInt aCallId ) |
|
549 { |
|
550 if ( aCallId == ENextFolder ) |
|
551 { |
|
552 //FLOG( _L("CMFDialogTest::HandleActiveCallL: ENextFolder") ); |
|
553 |
|
554 TRAP_IGNORE( NextFolderL() ); |
|
555 iDestroyedPtr = NULL; |
|
556 } |
|
557 if ( aCallId == ENextListItem ) |
|
558 { |
|
559 //FLOG( _L("CMFDialogTest::HandleActiveCallL: ENextListItem") ); |
|
560 NextListItemL(); |
|
561 } |
|
562 |
|
563 if ( aCallId == EMovePosition ) |
|
564 { |
|
565 //FLOG( _L("CMFDialogTest::HandleActiveCallL: EMovePosition") ); |
|
566 |
|
567 MovePositionL(); |
|
568 } |
|
569 } |
|
570 |
|
571 |
|
572 // ----------------------------------------------------------------------------- |
|
573 // CMFDialogTest::SetTime |
|
574 // |
|
575 // ----------------------------------------------------------------------------- |
|
576 // |
|
577 void CMFDialogTest::SetTime() |
|
578 { |
|
579 iTime = TimeBefore(); |
|
580 } |
|
581 |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CMFDialogTest::PrintTimeL |
|
585 // |
|
586 // ----------------------------------------------------------------------------- |
|
587 // |
|
588 void CMFDialogTest::PrintTimeL( const TDesC& aText ) |
|
589 { |
|
590 TBuf<128> buf; |
|
591 TInt milliSeconds = TimeAfter( iTime ); |
|
592 buf.Format( _L("%S %d ms"), &aText, milliSeconds ); |
|
593 |
|
594 ShowPopupNoteL( buf ); |
|
595 } |
|
596 |
|
597 |
|
598 // ----------------------------------------------------------------------------- |
|
599 // CMFDialogTest::TimeBefore |
|
600 // |
|
601 // Function returns TTime of the current time (needed with function TimeAfter). |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 TTime CMFDialogTest::TimeBefore() |
|
605 { |
|
606 TTime now; |
|
607 now.UniversalTime(); |
|
608 return now; |
|
609 } |
|
610 |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // CMFDialogTest::TimeAfter |
|
614 // |
|
615 // Function returns milliseconds passed since aBefore. |
|
616 // ----------------------------------------------------------------------------- |
|
617 // |
|
618 TInt64 CMFDialogTest::TimeAfter( TTime aBefore ) |
|
619 { |
|
620 TTime after; |
|
621 after.UniversalTime(); |
|
622 TTimeIntervalMicroSeconds microSeconds=after.MicroSecondsFrom( aBefore ); |
|
623 TInt64 milliSeconds=microSeconds.Int64()/1000; |
|
624 return milliSeconds; |
|
625 } |
|
626 |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CMFDialogTest::ShowPopupNote |
|
630 // |
|
631 // ----------------------------------------------------------------------------- |
|
632 // |
|
633 void CMFDialogTest::ShowPopupNoteL( const TDesC& aText ) |
|
634 { |
|
635 const TInt KPopupDisplayTime = 3*1000; |
|
636 const TInt KPopupDelayTime = 500; |
|
637 |
|
638 iPopupNote->SetTextL( aText ); |
|
639 iPopupNote->SetTimeDelayBeforeShow( KPopupDelayTime ); |
|
640 iPopupNote->SetTimePopupInView( KPopupDisplayTime ); |
|
641 iPopupNote->ShowInfoPopupNote(); |
|
642 } |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 /****************************************************************************** |
|
648 * class CRandomNum |
|
649 ******************************************************************************/ |
|
650 |
|
651 |
|
652 |
|
653 // ----------------------------------------------------------------------------- |
|
654 // CRandomNum::NewLC |
|
655 // |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 CRandomNum* CRandomNum::NewLC() |
|
659 { |
|
660 CRandomNum* randomdata = new (ELeave) CRandomNum; |
|
661 CleanupStack::PushL( randomdata ); |
|
662 return randomdata; |
|
663 } |
|
664 |
|
665 |
|
666 // ----------------------------------------------------------------------------- |
|
667 // CRandomNum::NewL |
|
668 // |
|
669 // ----------------------------------------------------------------------------- |
|
670 // |
|
671 CRandomNum* CRandomNum::NewL() |
|
672 { |
|
673 CRandomNum* randomdata = new (ELeave) CRandomNum; |
|
674 return randomdata; |
|
675 } |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // CRandomNum::CRandomNum |
|
679 // |
|
680 // ----------------------------------------------------------------------------- |
|
681 // |
|
682 CRandomNum::CRandomNum() |
|
683 { |
|
684 TTime now; |
|
685 now.UniversalTime(); |
|
686 iSeed = now.Int64(); |
|
687 } |
|
688 |
|
689 // ----------------------------------------------------------------------------- |
|
690 // CRandomNum::~CRandomNum |
|
691 // |
|
692 // ----------------------------------------------------------------------------- |
|
693 // |
|
694 CRandomNum::~CRandomNum() |
|
695 { |
|
696 } |
|
697 |
|
698 |
|
699 // ----------------------------------------------------------------------------- |
|
700 // CRandomNum::Random |
|
701 // |
|
702 // Return random integer from 0 to aMax (including 0 and aMax). |
|
703 // ----------------------------------------------------------------------------- |
|
704 // |
|
705 TInt CRandomNum::Random( TInt aMax ) |
|
706 { |
|
707 TReal real = Math::FRand( iSeed ); // FRand updates iSeed |
|
708 TReal real2 = real * ( aMax+1 ); |
|
709 TInt num = (TInt) real2; |
|
710 return num; |
|
711 } |
|
712 |
|
713 |
|
714 // ----------------------------------------------------------------------------- |
|
715 // CRandomNum::Random |
|
716 // |
|
717 // Return random integer from aMin to aMax (including aMin and aMax). |
|
718 // ----------------------------------------------------------------------------- |
|
719 // |
|
720 TInt CRandomNum::Random( TInt aMin, TInt aMax ) |
|
721 { |
|
722 if ( aMin >= aMax ) |
|
723 { |
|
724 return aMin; |
|
725 } |
|
726 |
|
727 TInt range = aMax - aMin; |
|
728 |
|
729 TInt num = Random( range ); |
|
730 |
|
731 return aMin + num; |
|
732 } |
|
733 |
|
734 |
|
735 // ----------------------------------------------------------------------------- |
|
736 // CRandomNum::Match |
|
737 // |
|
738 // Return ETrue according to percentage parameter (eg. in case |
|
739 // aPercentage is 10 Match returns ETrue in 10% of the calls). |
|
740 // ----------------------------------------------------------------------------- |
|
741 // |
|
742 TBool CRandomNum::Match( TInt aPercentage ) |
|
743 { |
|
744 if ( aPercentage < 1 ) |
|
745 { |
|
746 return EFalse; |
|
747 } |
|
748 |
|
749 TInt num = Random( 99 ); // 0..99 |
|
750 num++; // 1..100 |
|
751 |
|
752 if ( num <= aPercentage ) |
|
753 { |
|
754 return ETrue; |
|
755 } |
|
756 |
|
757 return EFalse; |
|
758 } |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 /****************************************************************************** |
|
766 * class CMediaFileDialog3 |
|
767 ******************************************************************************/ |
|
768 |
|
769 /* |
|
770 |
|
771 // ----------------------------------------------------------------------------- |
|
772 // media file dialog resource (test code). |
|
773 // ----------------------------------------------------------------------------- |
|
774 // |
|
775 RESOURCE DIALOG r_media_file_dialog_3 |
|
776 { |
|
777 //flags = EEikDialogFlagNoBackup | EEikDialogFlagFillAppClientRect; |
|
778 flags=EEikDialogFlagWait | EEikDialogFlagFillAppClientRect | EEikDialogFlagNotifyEsc; |
|
779 //buttons = R_AVKON_SOFTKEYS_OK_BACK__OK; |
|
780 buttons = r_media_file_dialog_3_cba; |
|
781 |
|
782 items= |
|
783 { |
|
784 DLG_LINE |
|
785 { |
|
786 type=EAknCtSingleGraphicListBox; |
|
787 itemflags=EEikDlgItemTakesEnterKey | EEikDlgItemOfferAllHotKeys; |
|
788 id=1; |
|
789 control=LISTBOX |
|
790 { |
|
791 flags = EAknListBoxSelectionList; |
|
792 }; |
|
793 } |
|
794 }; |
|
795 |
|
796 } |
|
797 |
|
798 |
|
799 //------------------------------------------------------------------------------ |
|
800 // Softkey resource |
|
801 //------------------------------------------------------------------------------ |
|
802 // |
|
803 RESOURCE CBA r_media_file_dialog_3_cba |
|
804 { |
|
805 buttons = |
|
806 { |
|
807 CBA_BUTTON |
|
808 { |
|
809 id = EAknSoftkeyOptions; |
|
810 txt = text_softkey_option; |
|
811 }, |
|
812 CBA_BUTTON |
|
813 { |
|
814 id = EAknSoftkeyBack; |
|
815 txt = text_softkey_back; |
|
816 }, |
|
817 CBA_BUTTON |
|
818 { |
|
819 id = EAknSoftkeySelect; |
|
820 txt = qtn_msk_select; |
|
821 } |
|
822 }; |
|
823 } |
|
824 |
|
825 RESOURCE MENU_BAR r_media_file_dialog_3_menu |
|
826 { |
|
827 titles= |
|
828 { |
|
829 MENU_TITLE |
|
830 { |
|
831 menu_pane=r_media_file_dialog_3_menu_pane; |
|
832 } |
|
833 }; |
|
834 } |
|
835 |
|
836 RESOURCE MENU_PANE r_media_file_dialog_3_menu_pane |
|
837 { |
|
838 items= |
|
839 { |
|
840 MENU_ITEM { command=EAknCmdOpen; txt=qtn_options_open; }, |
|
841 MENU_ITEM { command=EAknCmdHelp; txt=qtn_options_help; }, |
|
842 MENU_ITEM { command=EAknCmdExit; txt=qtn_options_exit; } |
|
843 }; |
|
844 } |
|
845 */ |
|
846 /* |
|
847 |
|
848 // ----------------------------------------------------------------------------- |
|
849 // CMediaFileDialog3::ShowDialogL |
|
850 // |
|
851 // ----------------------------------------------------------------------------- |
|
852 TBool CMediaFileDialog3::ShowDialogL() |
|
853 { |
|
854 CMediaFileDialog3* dlg = CMediaFileDialog3::NewL(); |
|
855 TBool ret = dlg->ExecuteLD( R_MEDIA_FILE_DIALOG_3 ); |
|
856 |
|
857 return ret; |
|
858 } |
|
859 |
|
860 // ---------------------------------------------------------------------------- |
|
861 // Destructor |
|
862 // |
|
863 // ---------------------------------------------------------------------------- |
|
864 // |
|
865 CMediaFileDialog3::~CMediaFileDialog3() |
|
866 { |
|
867 delete iVideoPreviewHandler; |
|
868 |
|
869 if ( iAvkonAppUi ) |
|
870 { |
|
871 iAvkonAppUi->RemoveFromStack( this ); |
|
872 } |
|
873 } |
|
874 |
|
875 |
|
876 // ----------------------------------------------------------------------------- |
|
877 // CMediaFileDialog3::CMediaFileDialog3 |
|
878 // |
|
879 // ----------------------------------------------------------------------------- |
|
880 // |
|
881 CMediaFileDialog3::CMediaFileDialog3() |
|
882 { |
|
883 } |
|
884 |
|
885 |
|
886 // ----------------------------------------------------------------------------- |
|
887 // CMediaFileDialog3::NewL |
|
888 // |
|
889 // ----------------------------------------------------------------------------- |
|
890 CMediaFileDialog3* CMediaFileDialog3::NewL() |
|
891 { |
|
892 CMediaFileDialog3* self = new (ELeave) CMediaFileDialog3(); |
|
893 CleanupStack::PushL(self); |
|
894 self->ConstructL(); |
|
895 CleanupStack::Pop(self); |
|
896 |
|
897 return self; |
|
898 } |
|
899 |
|
900 // ----------------------------------------------------------------------------- |
|
901 // CMediaFileDialog3::ConstructL |
|
902 // |
|
903 // ----------------------------------------------------------------------------- |
|
904 // |
|
905 void CMediaFileDialog3::ConstructL() |
|
906 { |
|
907 FLOG( _L("CMediaFileDialog3::ConstructL START") ); |
|
908 |
|
909 CAknDialog::ConstructL( R_MEDIA_FILE_DIALOG_3_MENU ); |
|
910 |
|
911 iVideoPreviewHandler = CMFVideoPreviewHandler::NewL(); |
|
912 |
|
913 FLOG( _L("CMediaFileDialog3::ConstructL END") ); |
|
914 } |
|
915 |
|
916 // ----------------------------------------------------------------------------- |
|
917 // CMediaFileDialog3::PreLayoutDynInitL |
|
918 // |
|
919 // ----------------------------------------------------------------------------- |
|
920 // |
|
921 void CMediaFileDialog3::PreLayoutDynInitL() |
|
922 { |
|
923 } |
|
924 |
|
925 //------------------------------------------------------------------------------ |
|
926 // CMediaFileDialog3::OkToExitL |
|
927 // |
|
928 //------------------------------------------------------------------------------ |
|
929 // |
|
930 TBool CMediaFileDialog3::OkToExitL(TInt aButtonId) |
|
931 { |
|
932 if ( aButtonId == EAknSoftkeyBack ) |
|
933 { |
|
934 } |
|
935 |
|
936 return CAknDialog::OkToExitL( aButtonId ); |
|
937 } |
|
938 |
|
939 |
|
940 |
|
941 //------------------------------------------------------------------------------ |
|
942 // CMediaFileDialog3::ProcessCommandL |
|
943 // |
|
944 // Handle commands from menu. |
|
945 //------------------------------------------------------------------------------ |
|
946 // |
|
947 void CMediaFileDialog3::ProcessCommandL(TInt aCommandId) |
|
948 { |
|
949 HideMenu(); |
|
950 |
|
951 |
|
952 switch (aCommandId) |
|
953 { |
|
954 case EAknCmdHelp: |
|
955 { |
|
956 break; |
|
957 } |
|
958 |
|
959 case EAknCmdOpen: |
|
960 { |
|
961 CEikCaptionedControl *ctrl = Line( 1 ); // dialog has one line (listbox) with id 1 |
|
962 iVideoPreviewHandler->SetAttrL( TMFDialogUtil::EAttrDrawingWindow, (ctrl->iControl->DrawableWindow()) ); |
|
963 |
|
964 iVideoPreviewHandler->SetAttrL( TMFDialogUtil::EAttrFileName, _L("C:\\Data\\Videos\\video2.mp4") ); |
|
965 iVideoPreviewHandler->PlayL(); |
|
966 |
|
967 break; |
|
968 } |
|
969 |
|
970 case EAknCmdExit: |
|
971 case EEikCmdExit: |
|
972 { |
|
973 // close dialog and exit calling application |
|
974 iAvkonAppUi->ProcessCommandL( EAknCmdExit ); |
|
975 break; |
|
976 } |
|
977 |
|
978 default: |
|
979 break; |
|
980 } |
|
981 } |
|
982 */ |
|
983 |
|
984 |
|
985 // ----------------------------------------------------------------------------- |
|
986 // CMediaFileHandler::QueryAllL (obsolete) |
|
987 // |
|
988 // Finds all tones, music, videos or recordings. |
|
989 // ----------------------------------------------------------------------------- |
|
990 // |
|
991 /* |
|
992 void CMediaFileHandler::QueryAllL( TInt aAttr ) |
|
993 { |
|
994 if ( !iSessionOpen ) |
|
995 { |
|
996 User::Leave( KErrDisconnected ); |
|
997 } |
|
998 |
|
999 if ( aAttr != EAttrMusic && aAttr != EAttrVideo ) |
|
1000 { |
|
1001 User::Leave( KErrNotSupported ); |
|
1002 } |
|
1003 |
|
1004 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1005 CMdEObjectDef& musicObjectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1006 CMdEObjectDef& videoObjectDef = defNS.GetObjectDefL( MdeConstants::Video::KVideoObject ); |
|
1007 |
|
1008 delete iQuery; |
|
1009 iQuery = NULL; |
|
1010 |
|
1011 if ( aAttr == EAttrVideo ) |
|
1012 { |
|
1013 iQuery = iSession->NewObjectQueryL( defNS, videoObjectDef, this ); |
|
1014 iQueryType = EQueryVideo; |
|
1015 } |
|
1016 else |
|
1017 { |
|
1018 iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this ); |
|
1019 iQueryType = EQueryAudio; |
|
1020 } |
|
1021 |
|
1022 |
|
1023 // set attributes that are included in query result |
|
1024 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
1025 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
1026 |
|
1027 // define sort order |
|
1028 iQuery->AppendOrderRuleL( TMdEOrderRule( namePropertyDef, ESortAscending ) ); |
|
1029 |
|
1030 iQuery->SetResultMode( EQueryResultModeItem ); |
|
1031 |
|
1032 iQuery->FindL(); |
|
1033 |
|
1034 iQueryType = EQueryAudio; |
|
1035 } |
|
1036 */ |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 // ----------------------------------------------------------------------------- |
|
1042 // CMediaFileHandler::QueryArtistUnknownL (obsolete) |
|
1043 // |
|
1044 // Finds all songs for aArtist that miss album property. |
|
1045 // ----------------------------------------------------------------------------- |
|
1046 // |
|
1047 /* |
|
1048 void CMediaFileHandler::QueryArtistUnknownL( const TDesC& aArtist ) |
|
1049 { |
|
1050 if ( !iSessionOpen ) |
|
1051 { |
|
1052 return; |
|
1053 } |
|
1054 |
|
1055 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1056 CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1057 |
|
1058 iQueryType = EQueryAudio; |
|
1059 |
|
1060 delete iQuery; |
|
1061 iQuery = NULL; |
|
1062 iQuery = iSession->NewObjectQueryL( defNS, objectDef, this ); |
|
1063 |
|
1064 iQuery->SetResultMode( EQueryResultModeItem ); |
|
1065 |
|
1066 CMdEPropertyDef& artistPropertyDef = PropertyDefL( EAttrArtist ); |
|
1067 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
1068 CMdEPropertyDef& albumPropertyDef = PropertyDefL( EAttrAlbum ); |
|
1069 |
|
1070 |
|
1071 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
1072 |
|
1073 // add root condition: get all songs by aArtist |
|
1074 conditions.AddPropertyConditionL( artistPropertyDef, |
|
1075 ETextPropertyConditionCompareEquals, |
|
1076 aArtist ); |
|
1077 |
|
1078 // set attributes that are included in query result |
|
1079 iQuery->AppendOrderRuleL( TMdEOrderRule( namePropertyDef, ESortAscending ) ); |
|
1080 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
1081 iQuery->AddPropertyFilterL( &artistPropertyDef ); |
|
1082 |
|
1083 |
|
1084 // add other condition: get songs that do not have album attribute |
|
1085 CMdELogicCondition& albumCondition = |
|
1086 conditions.AddLogicConditionL( ELogicConditionOperatorAnd ); |
|
1087 albumCondition.AddPropertyConditionL( albumPropertyDef ); |
|
1088 albumCondition.SetNegate( ETrue ); |
|
1089 |
|
1090 iQuery->FindL(); |
|
1091 } |
|
1092 */ |
|
1093 |
|
1094 // ----------------------------------------------------------------------------- |
|
1095 // CMediaFileHandler2::QueryAlbumsL (obsolete) |
|
1096 // |
|
1097 // Finds all albums for aArtist. |
|
1098 // ----------------------------------------------------------------------------- |
|
1099 // |
|
1100 /* |
|
1101 void CMediaFileHandler::QueryAlbumsL( const TDesC& aArtist ) |
|
1102 { |
|
1103 if ( !iSessionOpen ) |
|
1104 { |
|
1105 return; |
|
1106 } |
|
1107 |
|
1108 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1109 CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1110 |
|
1111 iQueryType = EQueryAudio; |
|
1112 |
|
1113 delete iQuery; |
|
1114 iQuery = NULL; |
|
1115 iQuery = iSession->NewObjectQueryL( defNS, objectDef, this ); |
|
1116 |
|
1117 iQuery->SetResultMode( EQueryResultModeDistinctValues ); |
|
1118 |
|
1119 CMdEPropertyDef& propertyDef = PropertyDefL( EAttrAlbum ); |
|
1120 |
|
1121 // distinct query requires exactly one property filter |
|
1122 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
1123 conditions.AddPropertyConditionL( propertyDef ); |
|
1124 iQuery->AppendOrderRuleL( TMdEOrderRule( propertyDef, ESortAscending ) ); |
|
1125 iQuery->AddPropertyFilterL( &propertyDef ); |
|
1126 |
|
1127 CMdEPropertyDef& propertyDef2 = PropertyDefL( EAttrArtist ); |
|
1128 conditions.AddPropertyConditionL( propertyDef2, |
|
1129 ETextPropertyConditionCompareEquals, aArtist ); |
|
1130 |
|
1131 iQuery->FindL(); |
|
1132 } |
|
1133 */ |
|
1134 |
|
1135 // ----------------------------------------------------------------------------- |
|
1136 // CMediaFileHandler::QueryArtistAlbumL (obsolete) |
|
1137 // |
|
1138 // Finds songs for aArtist/aAlbum. |
|
1139 // ----------------------------------------------------------------------------- |
|
1140 // |
|
1141 |
|
1142 /* |
|
1143 void CMediaFileHandler::QueryArtistAlbumL( const TDesC& aArtist, const TDesC& aAlbum ) |
|
1144 { |
|
1145 if ( !iSessionOpen ) |
|
1146 { |
|
1147 return; |
|
1148 } |
|
1149 |
|
1150 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1151 CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1152 |
|
1153 iQueryType = EQueryAudio; |
|
1154 |
|
1155 delete iQuery; |
|
1156 iQuery = NULL; |
|
1157 iQuery = iSession->NewObjectQueryL( defNS, objectDef, this ); |
|
1158 |
|
1159 iQuery->SetResultMode( EQueryResultModeItem ); |
|
1160 |
|
1161 CMdEPropertyDef& artistDef = PropertyDefL( EAttrArtist ); |
|
1162 CMdEPropertyDef& albumDef = PropertyDefL( EAttrAlbum ); |
|
1163 CMdEPropertyDef& nameDef = PropertyDefL( EAttrSongName ); |
|
1164 |
|
1165 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
1166 |
|
1167 conditions.AddPropertyConditionL( artistDef, |
|
1168 ETextPropertyConditionCompareEquals, aArtist ); |
|
1169 |
|
1170 conditions.AddPropertyConditionL( albumDef, |
|
1171 ETextPropertyConditionCompareEquals, aAlbum ); |
|
1172 |
|
1173 iQuery->AppendOrderRuleL( TMdEOrderRule( nameDef, ESortAscending ) ); |
|
1174 iQuery->AddPropertyFilterL( &nameDef ); |
|
1175 |
|
1176 |
|
1177 User::Leave(KErrNoMemory); |
|
1178 iQuery->FindL(); |
|
1179 |
|
1180 |
|
1181 } |
|
1182 */ |
|
1183 |
|
1184 |
|
1185 // ----------------------------------------------------------------------------- |
|
1186 // CMediaFileHandler::QueryL (test code) |
|
1187 // |
|
1188 // ----------------------------------------------------------------------------- |
|
1189 // |
|
1190 /* |
|
1191 void CMediaFileHandler::QueryL( TInt aAttr ) |
|
1192 { |
|
1193 if ( aAttr != EAttrArtist && aAttr != EAttrAlbum && |
|
1194 aAttr != EAttrGenre && aAttr != EAttrComposer ) |
|
1195 { |
|
1196 User::Leave( KErrNotSupported ); |
|
1197 } |
|
1198 |
|
1199 |
|
1200 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1201 CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1202 iQuery = iSession->NewObjectQueryL( defNS, objectDef, this ); |
|
1203 |
|
1204 |
|
1205 RArray<TItemId> itemIds; |
|
1206 itemIds.Append( 22 ); |
|
1207 itemIds.Append( 5 ); |
|
1208 itemIds.Append( 18 ); |
|
1209 //itemLogicCondition->AddObjectConditionL(itemIds); |
|
1210 |
|
1211 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
1212 conditions.AddObjectConditionL( itemIds ); |
|
1213 iQuery->SetResultMode( EQueryResultModeItem ); |
|
1214 |
|
1215 itemIds.Close(); |
|
1216 |
|
1217 iQuery->FindL(); |
|
1218 } |
|
1219 */ |
|
1220 |
|
1221 // ----------------------------------------------------------------------------- |
|
1222 // CMediaFileHandler::QueryL (test code) |
|
1223 // |
|
1224 // ----------------------------------------------------------------------------- |
|
1225 // |
|
1226 |
|
1227 /* |
|
1228 void CMediaFileHandler::QueryL() |
|
1229 { |
|
1230 if ( !iSession ) |
|
1231 { |
|
1232 User::Leave( KErrSessionClosed ); |
|
1233 } |
|
1234 |
|
1235 delete iQuery; |
|
1236 iQuery = NULL; |
|
1237 |
|
1238 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1239 |
|
1240 CMdEObjectDef& objectDef = defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
1241 iQuery = iSession->NewObjectQueryL( defNS, objectDef, this ); |
|
1242 iQuery->SetResultMode( EQueryResultModeId ); |
|
1243 iQuery->FindL(); |
|
1244 |
|
1245 |
|
1246 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
1247 |
|
1248 //conditions.AddPropertyConditionL(composerPropertyDef, |
|
1249 //CMdETextPropertyCondition::ECompareEquals, text); |
|
1250 |
|
1251 } |
|
1252 */ |
|
1253 |
|
1254 |
|
1255 // ----------------------------------------------------------------------------- |
|
1256 // CMediaFileHandler::HandleQueryCompletedOneL |
|
1257 // |
|
1258 // ----------------------------------------------------------------------------- |
|
1259 // |
|
1260 |
|
1261 /* |
|
1262 void CMediaFileHandler::HandleQueryCompletedOneL( CMdEQuery& aQuery, |
|
1263 TInt aError ) |
|
1264 { |
|
1265 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
1266 |
|
1267 CMdEObjectDef& objectDef = defNS.GetObjectDefL( |
|
1268 MdeConstants::Object::KBaseObject ); |
|
1269 CMdEObjectDef& mediaObjectDef = defNS.GetObjectDefL( |
|
1270 MdeConstants::MediaObject::KMediaObject ); |
|
1271 CMdEObjectDef& audioObjectDef = defNS.GetObjectDefL( |
|
1272 MdeConstants::Audio::KAudioObject ); |
|
1273 |
|
1274 |
|
1275 CMdEPropertyDef& songPropertyDef = objectDef.GetPropertyDefL( |
|
1276 MdeConstants::Object::KTitleProperty ); |
|
1277 CMdEPropertyDef& artistPropertyDef = mediaObjectDef.GetPropertyDefL( |
|
1278 MdeConstants::MediaObject::KArtistProperty ); |
|
1279 CMdEPropertyDef& albumPropertyDef = audioObjectDef.GetPropertyDefL( |
|
1280 MdeConstants::Audio::KAlbumProperty ); |
|
1281 CMdEPropertyDef& genrePropertyDef = mediaObjectDef.GetPropertyDefL( |
|
1282 MdeConstants::MediaObject::KGenreProperty ); |
|
1283 |
|
1284 CMdEProperty* property = NULL; |
|
1285 |
|
1286 const RArray<TItemId>& arr = iQuery->ResultIds(); |
|
1287 |
|
1288 TBuf<256> buf; |
|
1289 TInt count = arr.Count(); |
|
1290 for ( TInt i=0; i<count; i++ ) |
|
1291 { |
|
1292 TItemId id = arr[i]; |
|
1293 CMdEObject* object = iSession->GetFullObjectL( id ); |
|
1294 CleanupStack::PushL( object ); |
|
1295 |
|
1296 buf = object->Uri(); |
|
1297 TInt propertyCount = object->PropertyCount(); |
|
1298 for ( TInt j=0; j<propertyCount; j++ ) |
|
1299 { |
|
1300 CMdEProperty& pr = object->PropertyL( j ); |
|
1301 const CMdEPropertyDef& prDef = pr.Def(); |
|
1302 buf.Append(_L(" ")); |
|
1303 buf.Append(prDef.Name()); |
|
1304 } |
|
1305 TMFDialogUtil::ShowInformationQueryL( buf ); |
|
1306 |
|
1307 CMdEPropertyDef& tmpDef = object->Def().GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty ); |
|
1308 TInt ret = object->Property( tmpDef, property, 0 ); |
|
1309 if ( ret != KErrNotFound ) |
|
1310 { |
|
1311 buf = property->TextValueL(); |
|
1312 } |
|
1313 |
|
1314 |
|
1315 ret = object->Property( songPropertyDef, property, 0 ); |
|
1316 if ( ret != KErrNotFound ) |
|
1317 { |
|
1318 buf = property->TextValueL(); |
|
1319 } |
|
1320 |
|
1321 ret = object->Property( artistPropertyDef, property, 0 ); |
|
1322 if ( ret != KErrNotFound ) |
|
1323 { |
|
1324 buf = property->TextValueL(); |
|
1325 } |
|
1326 |
|
1327 ret = object->Property( albumPropertyDef, property, 0 ); |
|
1328 if ( ret != KErrNotFound ) |
|
1329 { |
|
1330 buf = property->TextValueL(); |
|
1331 } |
|
1332 |
|
1333 ret = object->Property( genrePropertyDef, property, 0 ); |
|
1334 if ( ret != KErrNotFound ) |
|
1335 { |
|
1336 buf = property->TextValueL(); |
|
1337 } |
|
1338 |
|
1339 |
|
1340 CleanupStack::PopAndDestroy( object ); |
|
1341 } |
|
1342 } |
|
1343 */ |
|
1344 |
|
1345 // ----------------------------------------------------------------------------- |
|
1346 // CMediaFileHandler::HandleQueryCompletedTwoL |
|
1347 // |
|
1348 // ----------------------------------------------------------------------------- |
|
1349 // |
|
1350 |
|
1351 /* |
|
1352 void CMediaFileHandler::HandleQueryCompletedTwoL( CMdEQuery& aQuery, |
|
1353 TInt aError ) |
|
1354 { |
|
1355 TBuf<256> buf; |
|
1356 |
|
1357 TInt count = iQuery->Count(); |
|
1358 for ( TInt i=0; i<count; i++ ) |
|
1359 { |
|
1360 buf = iQuery->ResultDistinctValue( i ); |
|
1361 |
|
1362 CMdEObject& object = iQuery->Result( i ); |
|
1363 |
|
1364 buf = object.Uri(); |
|
1365 TInt propertyCount = object.PropertyCount(); |
|
1366 for ( TInt j=0; j<propertyCount; j++ ) |
|
1367 { |
|
1368 CMdEProperty& pr = object.PropertyL( j ); |
|
1369 const CMdEPropertyDef& prDef = pr.Def(); |
|
1370 buf.Append(_L(" ")); |
|
1371 buf.Append(prDef.Name()); |
|
1372 } |
|
1373 TMFDialogUtil::ShowInformationQueryL( buf ); |
|
1374 |
|
1375 CMdEProperty* property = NULL; |
|
1376 CMdEPropertyDef& propDef = object.Def().GetPropertyDefL( MdeConstants::Audio::KAlbumProperty ); |
|
1377 TInt ret = object.Property( propDef, property, 0 ); |
|
1378 if ( ret != KErrNotFound ) |
|
1379 { |
|
1380 buf = property->TextValueL(); |
|
1381 } |
|
1382 } |
|
1383 } |
|
1384 */ |
|
1385 |
|
1386 |
|
1387 // ----------------------------------------------------------------------------- |
|
1388 // CMediaFileHandler::ResultCount |
|
1389 // |
|
1390 // ----------------------------------------------------------------------------- |
|
1391 // |
|
1392 |
|
1393 /* |
|
1394 TInt CMediaFileHandler::ResultCount() |
|
1395 { |
|
1396 if ( iQueryType == EQueryRomFile ) |
|
1397 { |
|
1398 return iRomFileList.Count(); |
|
1399 } |
|
1400 |
|
1401 if ( iQueryType == ESearchVideo ) |
|
1402 { |
|
1403 return iSearchList->Count(); |
|
1404 } |
|
1405 |
|
1406 if ( !iQuery || !iQueryReady || !iSessionOpen ) |
|
1407 { |
|
1408 return 0; |
|
1409 } |
|
1410 |
|
1411 TInt count = 0; |
|
1412 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
1413 |
|
1414 if ( resultMode == EQueryResultModeDistinctValues || |
|
1415 resultMode == EQueryResultModeItem || |
|
1416 resultMode == EQueryResultModeCount ) |
|
1417 { |
|
1418 count = iQuery->Count(); |
|
1419 } |
|
1420 else if ( resultMode == EQueryResultModeId ) |
|
1421 { |
|
1422 count = iQuery->Count(); |
|
1423 const RArray<TItemId>& arr = iQuery->ResultIds(); |
|
1424 count = arr.Count(); |
|
1425 } |
|
1426 |
|
1427 return count; |
|
1428 } |
|
1429 */ |
|
1430 |
|
1431 |
|
1432 // ----------------------------------------------------------------------------- |
|
1433 // CMediaFileHandler::GetRecentFileAttribute |
|
1434 // |
|
1435 // ----------------------------------------------------------------------------- |
|
1436 // |
|
1437 /* |
|
1438 void CMediaFileHandler::GetRecentFileAttribute( TInt aIndex, TInt aAttr, TDes& aValue ) |
|
1439 { |
|
1440 TInt count = iRecentList->Count(); |
|
1441 |
|
1442 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1443 |
|
1444 if ( aAttr == EAttrFullName ) |
|
1445 { |
|
1446 StrCopy( aValue, iRecentList->FileName( aIndex ) ); |
|
1447 } |
|
1448 else if ( aAttr == EAttrSongName || aAttr == EAttrFileName ) |
|
1449 { |
|
1450 TParsePtrC parse( iRecentList->FileName( aIndex ) ); |
|
1451 StrCopy( aValue, parse.Name() ); |
|
1452 } |
|
1453 } |
|
1454 */ |
|
1455 |
|
1456 |
|
1457 // ----------------------------------------------------------------------------- |
|
1458 // CMediaFileHandler::RecentFileAttribute |
|
1459 // |
|
1460 // ----------------------------------------------------------------------------- |
|
1461 // |
|
1462 /* |
|
1463 TInt CMediaFileHandler::RecentFileAttribute( TInt aIndex, TInt aAttr ) |
|
1464 { |
|
1465 TInt count = iRecentList->Count(); |
|
1466 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1467 |
|
1468 TInt ret = KErrNotFound; |
|
1469 |
|
1470 if ( aAttr == EAttrMediaType ) |
|
1471 { |
|
1472 ret = EAttrMusic; |
|
1473 } |
|
1474 if ( aAttr == EAttrStorageType ) |
|
1475 { |
|
1476 ret = EPhoneMemory; |
|
1477 } |
|
1478 |
|
1479 return ret; |
|
1480 } |
|
1481 */ |
|
1482 |
|
1483 |
|
1484 // ----------------------------------------------------------------------------- |
|
1485 // CMediaFileHandler::Attribute |
|
1486 // |
|
1487 // ----------------------------------------------------------------------------- |
|
1488 // |
|
1489 /* |
|
1490 TInt CMediaFileHandler::Attribute( TInt aIndex, TInt aAttr ) |
|
1491 { |
|
1492 if ( iQueryType == EQueryRomFile ) |
|
1493 { |
|
1494 return RomFileAttribute( aIndex, aAttr ); |
|
1495 } |
|
1496 if ( iQueryType == ESearchVideo ) |
|
1497 { |
|
1498 return iSearchList->Attribute( aIndex, aAttr ); |
|
1499 } |
|
1500 |
|
1501 if ( aAttr == EAttrMediaType ) |
|
1502 { |
|
1503 if ( iQueryType == EQueryVideo ) |
|
1504 { |
|
1505 return EAttrVideo; |
|
1506 } |
|
1507 else |
|
1508 { |
|
1509 return EAttrMusic; |
|
1510 } |
|
1511 } |
|
1512 else if ( aAttr == EAttrStorageType ) |
|
1513 { |
|
1514 TInt ret = CMediaFileHandler::EPhoneMemory; |
|
1515 |
|
1516 if ( !iQuery || !iQueryReady || !iSessionOpen ) |
|
1517 { |
|
1518 return ret; |
|
1519 } |
|
1520 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
1521 if ( resultMode != EQueryResultModeItem ) |
|
1522 { |
|
1523 return ret; |
|
1524 } |
|
1525 |
|
1526 CMdEObject& object = iQuery->Result( aIndex ); |
|
1527 if ( iDriveUtil->IsMemoryCard( object.Uri() ) ) |
|
1528 { |
|
1529 ret = CMediaFileHandler::EMemoryCard; |
|
1530 } |
|
1531 else if ( iDriveUtil->IsMassStorage( object.Uri() ) ) |
|
1532 { |
|
1533 ret = CMediaFileHandler::EMassStorage; |
|
1534 } |
|
1535 return ret; |
|
1536 } |
|
1537 |
|
1538 else if ( aAttr == EAttrMediaFileId ) |
|
1539 { |
|
1540 if ( !iQuery || !iQueryReady || !iSessionOpen ) |
|
1541 { |
|
1542 return KErrNotFound; |
|
1543 } |
|
1544 CMdEObject& object = iQuery->Result( aIndex ); |
|
1545 return object.Id(); |
|
1546 } |
|
1547 |
|
1548 return KErrNotFound; |
|
1549 } |
|
1550 */ |
|
1551 |
|
1552 |
|
1553 // ----------------------------------------------------------------------------- |
|
1554 // CMediaFileHandler::GetAttributeL |
|
1555 // |
|
1556 // ----------------------------------------------------------------------------- |
|
1557 // |
|
1558 /* |
|
1559 void CMediaFileHandler::GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue ) |
|
1560 { |
|
1561 aValue = KNullDesC; |
|
1562 |
|
1563 if ( iQueryType == EQueryRomFile ) |
|
1564 { |
|
1565 GetRomFileAttribute( aIndex, aAttr, aValue ); |
|
1566 return; |
|
1567 } |
|
1568 if ( iQueryType == ESearchVideo ) |
|
1569 { |
|
1570 if ( iSessionOpen ) |
|
1571 { |
|
1572 iSearchList->SetSession( iSession ); |
|
1573 } |
|
1574 else |
|
1575 { |
|
1576 iSearchList->SetSession( NULL ); |
|
1577 } |
|
1578 iSearchList->GetAttributeL( aIndex, aAttr, aValue ); |
|
1579 return; |
|
1580 } |
|
1581 |
|
1582 |
|
1583 if ( !iQuery || !iQueryReady || !iSessionOpen ) |
|
1584 { |
|
1585 return; |
|
1586 } |
|
1587 |
|
1588 TInt count = ResultCount(); |
|
1589 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1590 |
|
1591 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
1592 |
|
1593 if ( resultMode == EQueryResultModeDistinctValues ) |
|
1594 { |
|
1595 TPtrC ptr = iQuery->ResultDistinctValue( aIndex ); |
|
1596 StrCopy( aValue, ptr ); |
|
1597 } |
|
1598 |
|
1599 if ( resultMode == EQueryResultModeItem ) |
|
1600 { |
|
1601 CMdEObject& object = iQuery->Result( aIndex ); |
|
1602 |
|
1603 if ( aAttr == EAttrFullName ) |
|
1604 { |
|
1605 StrCopy( aValue, object.Uri() ); |
|
1606 return; |
|
1607 } |
|
1608 |
|
1609 CMdEPropertyDef& propDef = PropertyDefL( aAttr ); |
|
1610 CMdEProperty* property = NULL; |
|
1611 TInt ret = object.Property( propDef, property, 0 ); |
|
1612 if ( ret != KErrNotFound ) |
|
1613 { |
|
1614 StrCopy( aValue, property->TextValueL() ); |
|
1615 } |
|
1616 else if ( aAttr == EAttrSongName || aAttr == EAttrFileName) |
|
1617 { |
|
1618 TParsePtrC parse( object.Uri() ); |
|
1619 StrCopy( aValue, parse.Name() ); |
|
1620 } |
|
1621 } |
|
1622 } |
|
1623 */ |
|
1624 |
|
1625 |
|
1626 // ----------------------------------------------------------------------------- |
|
1627 // CMediaFileHandler::UpdateRecentListL |
|
1628 // |
|
1629 // ----------------------------------------------------------------------------- |
|
1630 // |
|
1631 /* |
|
1632 void CMediaFileHandler::UpdateRecentListL() |
|
1633 { |
|
1634 if ( !iSessionOpen ) |
|
1635 { |
|
1636 return; |
|
1637 } |
|
1638 |
|
1639 TInt count = iRecentList->Count(); |
|
1640 |
|
1641 for ( TInt i=0; i<count; i++ ) |
|
1642 { |
|
1643 TItemId id = iRecentList->Id( i ); |
|
1644 CMdEObject* object = NULL; |
|
1645 |
|
1646 TInt err = KErrNone; |
|
1647 TRAP( err, object = iSession->GetFullObjectL( id ) ); |
|
1648 if ( err != KErrNone || !object ) |
|
1649 { |
|
1650 iRecentList->SetPresent( EFalse, i ); |
|
1651 } |
|
1652 else |
|
1653 { |
|
1654 CleanupStack::PushL( object ); |
|
1655 iRecentList->SetFileNameL( object->Uri(), i ); |
|
1656 CleanupStack::PopAndDestroy( object ); |
|
1657 } |
|
1658 } |
|
1659 |
|
1660 iRecentList->Clean(); |
|
1661 } |
|
1662 */ |
|
1663 |
|
1664 // ----------------------------------------------------------------------------- |
|
1665 // CMediaFileHandler::StoreRecentFileL |
|
1666 // |
|
1667 // ----------------------------------------------------------------------------- |
|
1668 // |
|
1669 /* |
|
1670 void CMediaFileHandler::StoreRecentFileL( TInt aIndex ) |
|
1671 { |
|
1672 if ( iQueryType == EQueryRomFile ) |
|
1673 { |
|
1674 return; // tones not part of recent files |
|
1675 } |
|
1676 |
|
1677 if ( iQueryType == EQueryRecentFile ) |
|
1678 { |
|
1679 TInt64 id = iRecentList->Id( aIndex ); |
|
1680 iRecentList->AddItemL( id ); |
|
1681 return; |
|
1682 } |
|
1683 |
|
1684 if ( !iQuery || !iQueryReady || !iSessionOpen ) |
|
1685 { |
|
1686 return; |
|
1687 } |
|
1688 |
|
1689 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
1690 if ( resultMode == EQueryResultModeItem ) |
|
1691 { |
|
1692 CMdEObject& object = iQuery->Result( aIndex ); |
|
1693 TItemId id = object.Id(); |
|
1694 iRecentList->AddItemL( id ); |
|
1695 } |
|
1696 } |
|
1697 */ |
|
1698 |
|
1699 |
|
1700 // ----------------------------------------------------------------------------- |
|
1701 // CMediaFileHandler::HandleQueryCompletedL |
|
1702 // |
|
1703 // ----------------------------------------------------------------------------- |
|
1704 // |
|
1705 |
|
1706 /* |
|
1707 void CMediaFileHandler::HandleQueryCompletedL( CMdEQuery& aQuery, TInt aError ) |
|
1708 { |
|
1709 iQueryReady = ETrue; |
|
1710 |
|
1711 if ( !iQuery ) |
|
1712 { |
|
1713 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EError, KErrCancel ); |
|
1714 return; // query has been canceled |
|
1715 } |
|
1716 |
|
1717 if ( aError != KErrNone ) |
|
1718 { |
|
1719 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EError, aError ); |
|
1720 return; |
|
1721 } |
|
1722 |
|
1723 TQueryResultMode resultMode = iQuery->ResultMode(); |
|
1724 |
|
1725 if ( resultMode == EQueryResultModeDistinctValues ) |
|
1726 { |
|
1727 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EQueryComplete, aError ); |
|
1728 } |
|
1729 else if ( resultMode == EQueryResultModeId ) |
|
1730 { |
|
1731 // const RArray<TItemId>& arr = iQuery->ResultIds(); |
|
1732 // CopyArrayL( iResultArray, arr ); |
|
1733 // |
|
1734 // copy this arr into member iResultIds and perform full search |
|
1735 // for the whole set or a partial search if result set is very large |
|
1736 // partial search indexes could be in another member iPartialResultdIds |
|
1737 // observer gets notified after the first partial search |
|
1738 |
|
1739 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EError, KErrNotSupported ); |
|
1740 } |
|
1741 else if ( resultMode == EQueryResultModeCount ) |
|
1742 { |
|
1743 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EUnknownQueryComplete, aError ); |
|
1744 } |
|
1745 else if ( resultMode == EQueryResultModeItem ) |
|
1746 { |
|
1747 if ( iQueryType == ESearchAudio ) |
|
1748 { |
|
1749 iSearchList->Reset(); |
|
1750 iSearchList->TakeResultL( iQuery, EAttrMusic ); |
|
1751 SearchVideoL( iSearchText ); |
|
1752 } |
|
1753 else if ( iQueryType == ESearchVideo ) |
|
1754 { |
|
1755 iSearchList->TakeResultL( iQuery, EAttrVideo ); |
|
1756 iSearchList->Sort(); |
|
1757 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EQueryComplete, aError ); |
|
1758 } |
|
1759 else |
|
1760 { |
|
1761 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EQueryComplete, aError ); |
|
1762 } |
|
1763 } |
|
1764 else |
|
1765 { |
|
1766 iObserver->HandleMFEventL( MMediaFileHandlerObserver::EError, KErrNotSupported ); |
|
1767 } |
|
1768 } |
|
1769 */ |
|
1770 |
|
1771 |
|
1772 /* |
|
1773 //private: |
|
1774 //void ReadDirectoryL( const TDesC& aDirectory ); |
|
1775 //void ReadRomFilesL(); |
|
1776 //void SortRomFiles(); |
|
1777 //static TInt CompareFileName( const TFileName& aFirst, const TFileName& aSecond ); |
|
1778 //static TInt CompareStr( const TFileName& aFirst, const TFileName& aSecond ); |
|
1779 |
|
1780 // ----------------------------------------------------------------------------- |
|
1781 // CMediaFileHandler::ReadRomFilesL (to be removed) |
|
1782 // |
|
1783 // ----------------------------------------------------------------------------- |
|
1784 // |
|
1785 void CMediaFileHandler::ReadRomFilesL() |
|
1786 { |
|
1787 _LIT( KFormat, "%S%S" ); |
|
1788 |
|
1789 iRomFileList.Reset(); |
|
1790 |
|
1791 TFileName fileName; |
|
1792 fileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::SoundsPath() ); |
|
1793 TRAP_IGNORE( ReadDirectoryL( fileName ) ); |
|
1794 |
|
1795 fileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::DigitalSoundsPath() ); |
|
1796 TRAP_IGNORE( ReadDirectoryL( fileName ) ); |
|
1797 |
|
1798 fileName.Format( KFormat, &PathInfo::RomRootPath(), &PathInfo::SimpleSoundsPath() ); |
|
1799 TRAP_IGNORE( ReadDirectoryL( fileName ) ); |
|
1800 |
|
1801 TInt count = iRomFileList.Count(); |
|
1802 for ( TInt i=0; i<count; i++ ) |
|
1803 { |
|
1804 fileName = iRomFileList[i]; |
|
1805 } |
|
1806 |
|
1807 SortRomFiles(); |
|
1808 } |
|
1809 |
|
1810 |
|
1811 // ----------------------------------------------------------------------------- |
|
1812 // CMediaFileHandler::ReadDirectoryL (to be removed) |
|
1813 // |
|
1814 // ----------------------------------------------------------------------------- |
|
1815 // |
|
1816 void CMediaFileHandler::ReadDirectoryL( const TDesC& aDirectory ) |
|
1817 { |
|
1818 _LIT( KFormat, "%S%S" ); |
|
1819 |
|
1820 TBuf<128> buf( aDirectory ); |
|
1821 |
|
1822 CDir* dir = NULL; |
|
1823 RFs fsSession; |
|
1824 User::LeaveIfError( fsSession.Connect() ); |
|
1825 CleanupClosePushL( fsSession ); |
|
1826 |
|
1827 if ( !BaflUtils::FolderExists( fsSession, aDirectory ) ) |
|
1828 { |
|
1829 User::Leave( KErrNotFound ); |
|
1830 } |
|
1831 |
|
1832 TInt err = fsSession.GetDir( aDirectory, KEntryAttNormal, ESortByName, dir ); |
|
1833 User::LeaveIfError( err ); |
|
1834 CleanupStack::PushL( dir ); |
|
1835 |
|
1836 TInt count = dir->Count(); |
|
1837 |
|
1838 for ( TInt i=0; i<count; i++ ) |
|
1839 { |
|
1840 const TEntry item = (*dir)[i]; |
|
1841 TFileName fullName; |
|
1842 fullName.Format( KFormat, &aDirectory, &item.iName ); |
|
1843 iRomFileList.Append( fullName ); |
|
1844 } |
|
1845 |
|
1846 CleanupStack::PopAndDestroy( dir ); |
|
1847 |
|
1848 CleanupStack::PopAndDestroy(); // fsSession |
|
1849 } |
|
1850 |
|
1851 |
|
1852 // ----------------------------------------------------------------------------- |
|
1853 // CMediaFileHandler::SortRomFiles (to be removed) |
|
1854 // |
|
1855 // ----------------------------------------------------------------------------- |
|
1856 // |
|
1857 void CMediaFileHandler::SortRomFiles() |
|
1858 { |
|
1859 iRomFileList.Sort(TLinearOrder<TFileName>(CMediaFileHandler::CompareFileName)); |
|
1860 } |
|
1861 |
|
1862 |
|
1863 // ----------------------------------------------------------------------------- |
|
1864 // CMediaFileHandler::QueryRomFilesL (to be removed) |
|
1865 // |
|
1866 // Finds all tones from rom directories. |
|
1867 // ----------------------------------------------------------------------------- |
|
1868 // |
|
1869 void CMediaFileHandler::QueryRomFilesL( TInt aAttr ) |
|
1870 { |
|
1871 QueryEmptyL(); |
|
1872 |
|
1873 iQueryType = EQueryRomFile; |
|
1874 } |
|
1875 |
|
1876 |
|
1877 // ----------------------------------------------------------------------------- |
|
1878 // CMediaFileHandler::GetRomFileAttribute (to be removed) |
|
1879 // |
|
1880 // ----------------------------------------------------------------------------- |
|
1881 // |
|
1882 void CMediaFileHandler::GetRomFileAttribute( TInt aIndex, TInt aAttr, TDes& aValue ) |
|
1883 { |
|
1884 TInt count = iRomFileList.Count(); |
|
1885 |
|
1886 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1887 |
|
1888 if ( aAttr == EAttrFullName ) |
|
1889 { |
|
1890 StrCopy( aValue, iRomFileList[aIndex] ); |
|
1891 } |
|
1892 else if ( aAttr == EAttrSongName || aAttr == EAttrFileName ) |
|
1893 { |
|
1894 TParsePtrC parse( iRomFileList[aIndex] ); |
|
1895 StrCopy( aValue, parse.Name() ); |
|
1896 } |
|
1897 } |
|
1898 |
|
1899 |
|
1900 // ----------------------------------------------------------------------------- |
|
1901 // CMediaFileHandler::RomFileAttribute (to be removed) |
|
1902 // |
|
1903 // ----------------------------------------------------------------------------- |
|
1904 // |
|
1905 TInt CMediaFileHandler::RomFileAttribute( TInt aIndex, TInt aAttr ) |
|
1906 { |
|
1907 TInt count = iRomFileList.Count(); |
|
1908 |
|
1909 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < count, Panic( KErrGeneral ) ); |
|
1910 |
|
1911 TInt ret = KErrNotFound; |
|
1912 if ( aAttr == EAttrMediaType ) |
|
1913 { |
|
1914 ret = EMediaTypeTone; |
|
1915 } |
|
1916 else if ( aAttr == EAttrStorageType ) |
|
1917 { |
|
1918 ret = EPhoneMemory; |
|
1919 } |
|
1920 |
|
1921 return ret; |
|
1922 } |
|
1923 */ |
|
1924 |
|
1925 // ----------------------------------------------------------------------------- |
|
1926 // CMediaFileHandler::CompareFileName |
|
1927 // |
|
1928 // ----------------------------------------------------------------------------- |
|
1929 // |
|
1930 /* |
|
1931 TInt CMediaFileHandler::CompareFileName(const TFileName& aFirst, const TFileName& aSecond) |
|
1932 { |
|
1933 TParsePtrC parseFirst( aFirst ); |
|
1934 TParsePtrC parseSecond( aSecond ); |
|
1935 |
|
1936 return parseFirst.Name().Compare( parseSecond.Name() ); |
|
1937 } |
|
1938 */ |
|
1939 |
|
1940 // ----------------------------------------------------------------------------- |
|
1941 // CMediaFileHandler::CompareStr |
|
1942 // |
|
1943 // ----------------------------------------------------------------------------- |
|
1944 // |
|
1945 /* |
|
1946 TInt CMediaFileHandler::CompareStr(const TFileName& aFirst, const TFileName& aSecond) |
|
1947 { |
|
1948 return aFirst.Compare( aSecond ); |
|
1949 } |
|
1950 */ |
|
1951 |
|
1952 |
|
1953 |
|
1954 /******************************************************************************* |
|
1955 * class TMediaFileHistoryItem |
|
1956 *******************************************************************************/ |
|
1957 |
|
1958 /* |
|
1959 // ----------------------------------------------------------------------------- |
|
1960 // TMediaFileHistoryItem::Id |
|
1961 // |
|
1962 // ----------------------------------------------------------------------------- |
|
1963 // |
|
1964 TInt64 TMediaFileHistoryItem::Id() |
|
1965 { |
|
1966 return iId; |
|
1967 } |
|
1968 |
|
1969 |
|
1970 // ----------------------------------------------------------------------------- |
|
1971 // TMediaFileHistoryItem::SetId |
|
1972 // |
|
1973 // ----------------------------------------------------------------------------- |
|
1974 // |
|
1975 void TMediaFileHistoryItem::SetId( TInt64 aId ) |
|
1976 { |
|
1977 iId = aId; |
|
1978 } |
|
1979 |
|
1980 |
|
1981 // ----------------------------------------------------------------------------- |
|
1982 // TMediaFileHistoryItem::Time |
|
1983 // |
|
1984 // ----------------------------------------------------------------------------- |
|
1985 // |
|
1986 TTime TMediaFileHistoryItem::Time() |
|
1987 { |
|
1988 return iTime; |
|
1989 } |
|
1990 |
|
1991 |
|
1992 // ----------------------------------------------------------------------------- |
|
1993 // TMediaFileHistoryItem::SetTime |
|
1994 // |
|
1995 // ----------------------------------------------------------------------------- |
|
1996 // |
|
1997 void TMediaFileHistoryItem::SetTime( TTime aTime ) |
|
1998 { |
|
1999 iTime = aTime; |
|
2000 } |
|
2001 |
|
2002 |
|
2003 // ----------------------------------------------------------------------------- |
|
2004 // TMediaFileHistoryItem::InternalizeL |
|
2005 // |
|
2006 // ----------------------------------------------------------------------------- |
|
2007 // |
|
2008 void TMediaFileHistoryItem::InternalizeL( RReadStream& aStream ) |
|
2009 { |
|
2010 aStream >> iId; |
|
2011 |
|
2012 if ( iId < 0 ) |
|
2013 { |
|
2014 User::Leave( KErrCorrupt ); |
|
2015 } |
|
2016 |
|
2017 TInt64 temp = 0; |
|
2018 aStream >> temp; |
|
2019 |
|
2020 if ( temp <= 0 ) |
|
2021 { |
|
2022 User::Leave( KErrCorrupt ); |
|
2023 } |
|
2024 TTime time( temp ); |
|
2025 iTime = time; |
|
2026 |
|
2027 iPresent = ETrue; |
|
2028 iFullName = KNullDesC; |
|
2029 } |
|
2030 |
|
2031 |
|
2032 // ----------------------------------------------------------------------------- |
|
2033 // TMediaFileHistoryItem::ExternalizeL |
|
2034 // |
|
2035 // ----------------------------------------------------------------------------- |
|
2036 // |
|
2037 void TMediaFileHistoryItem::ExternalizeL( RWriteStream& aStream ) |
|
2038 { |
|
2039 aStream << iId; |
|
2040 aStream << iTime.Int64(); |
|
2041 } |
|
2042 */ |
|
2043 |
|
2044 |
|
2045 |
|
2046 /******************************************************************************* |
|
2047 * class CMediaFileHistory |
|
2048 *******************************************************************************/ |
|
2049 |
|
2050 /* |
|
2051 // ----------------------------------------------------------------------------- |
|
2052 // CMediaFileHistory::NewL |
|
2053 // |
|
2054 // ----------------------------------------------------------------------------- |
|
2055 // |
|
2056 CMediaFileHistory* CMediaFileHistory::NewL() |
|
2057 { |
|
2058 CMediaFileHistory* self = new (ELeave) CMediaFileHistory(); |
|
2059 CleanupStack::PushL( self ); |
|
2060 self->ConstructL(); |
|
2061 CleanupStack::Pop(self ); |
|
2062 |
|
2063 return self; |
|
2064 } |
|
2065 |
|
2066 |
|
2067 // ----------------------------------------------------------------------------- |
|
2068 // CMediaFileHistory::CMediaFileHistory |
|
2069 // |
|
2070 // ----------------------------------------------------------------------------- |
|
2071 // |
|
2072 CMediaFileHistory::CMediaFileHistory() |
|
2073 { |
|
2074 } |
|
2075 |
|
2076 |
|
2077 // ----------------------------------------------------------------------------- |
|
2078 // CMediaFileHistory::ConstructL |
|
2079 // |
|
2080 // Note: Sessionpath in emulator is '\epoc32\winscw\c\private\2000F85A' |
|
2081 // ----------------------------------------------------------------------------- |
|
2082 // |
|
2083 void CMediaFileHistory::ConstructL() |
|
2084 { |
|
2085 _LIT( KHistoryFile, "MediaFileHistory" ); |
|
2086 const TInt KHistoryDrive = EDriveC; |
|
2087 |
|
2088 User::LeaveIfError( iFsSession.Connect() ); |
|
2089 User::LeaveIfError( iFsSession.SetSessionToPrivate( KHistoryDrive ) ); |
|
2090 |
|
2091 User::LeaveIfError( iFsSession.SessionPath( iPath ) ); |
|
2092 BaflUtils::EnsurePathExistsL( iFsSession, iPath ); |
|
2093 iPath.Append( KHistoryFile ); |
|
2094 |
|
2095 TInt err = KErrNone; |
|
2096 TRAP( err, ReadHistoryL() ); |
|
2097 |
|
2098 if ( err != KErrNone && err != KErrNoMemory ) |
|
2099 { |
|
2100 // history file was just created or it is corrupted |
|
2101 iList.Reset(); |
|
2102 } |
|
2103 } |
|
2104 |
|
2105 |
|
2106 // ---------------------------------------------------------------------------- |
|
2107 // Destructor |
|
2108 // |
|
2109 // ---------------------------------------------------------------------------- |
|
2110 // |
|
2111 CMediaFileHistory::~CMediaFileHistory() |
|
2112 { |
|
2113 Clean(); |
|
2114 |
|
2115 TRAP_IGNORE( WriteHistoryL() ); |
|
2116 |
|
2117 iList.Close(); |
|
2118 iFsSession.Close(); |
|
2119 } |
|
2120 |
|
2121 |
|
2122 // ----------------------------------------------------------------------------- |
|
2123 // CMediaFileHistory::AddItemL |
|
2124 // |
|
2125 // ----------------------------------------------------------------------------- |
|
2126 // |
|
2127 void CMediaFileHistory::AddItemL( TInt64 aId ) |
|
2128 { |
|
2129 TMediaFileHistoryItem item; |
|
2130 |
|
2131 TTime t; |
|
2132 t.UniversalTime(); |
|
2133 |
|
2134 item.SetTime( t ); |
|
2135 item.SetId( aId ); |
|
2136 |
|
2137 AddItemL( item ); |
|
2138 } |
|
2139 |
|
2140 |
|
2141 // ----------------------------------------------------------------------------- |
|
2142 // CMediaFileHistory::Count |
|
2143 // |
|
2144 // ----------------------------------------------------------------------------- |
|
2145 // |
|
2146 TInt CMediaFileHistory::Count() |
|
2147 { |
|
2148 return iList.Count(); |
|
2149 } |
|
2150 |
|
2151 |
|
2152 // ----------------------------------------------------------------------------- |
|
2153 // CMediaFileHistory::Reset |
|
2154 // |
|
2155 // ----------------------------------------------------------------------------- |
|
2156 // |
|
2157 void CMediaFileHistory::Reset() |
|
2158 { |
|
2159 iList.Reset(); |
|
2160 } |
|
2161 |
|
2162 |
|
2163 // ----------------------------------------------------------------------------- |
|
2164 // CMediaFileHistory::SetFileNameL |
|
2165 // |
|
2166 // ----------------------------------------------------------------------------- |
|
2167 // |
|
2168 void CMediaFileHistory::SetFileNameL( const TDesC& aFullName, TInt aIndex ) |
|
2169 { |
|
2170 if ( aIndex < 0 || aIndex >= iList.Count() ) |
|
2171 { |
|
2172 TMFDialogUtil::Panic( KErrArgument ); |
|
2173 } |
|
2174 |
|
2175 TMediaFileHistoryItem& item = iList[aIndex]; |
|
2176 TMFDialogUtil::StrCopy( item.iFullName, aFullName ); |
|
2177 } |
|
2178 |
|
2179 |
|
2180 // ----------------------------------------------------------------------------- |
|
2181 // CMediaFileHistory::FileName |
|
2182 // |
|
2183 // ----------------------------------------------------------------------------- |
|
2184 // |
|
2185 const TDesC& CMediaFileHistory::FileName( TInt aIndex ) |
|
2186 { |
|
2187 if ( aIndex < 0 || aIndex >= iList.Count() ) |
|
2188 { |
|
2189 TMFDialogUtil::Panic( KErrArgument ); |
|
2190 } |
|
2191 |
|
2192 TMediaFileHistoryItem& item = iList[aIndex]; |
|
2193 return item.iFullName; |
|
2194 } |
|
2195 |
|
2196 |
|
2197 // ----------------------------------------------------------------------------- |
|
2198 // CMediaFileHistory::SetPresent |
|
2199 // |
|
2200 // ----------------------------------------------------------------------------- |
|
2201 // |
|
2202 void CMediaFileHistory::SetPresent( TBool aPresent, TInt aIndex ) |
|
2203 { |
|
2204 if ( aIndex < 0 || aIndex >= iList.Count() ) |
|
2205 { |
|
2206 TMFDialogUtil::Panic( KErrArgument ); |
|
2207 } |
|
2208 |
|
2209 TMediaFileHistoryItem& item = iList[aIndex]; |
|
2210 item.iPresent = aPresent; |
|
2211 } |
|
2212 |
|
2213 |
|
2214 // ----------------------------------------------------------------------------- |
|
2215 // CMediaFileHistory::Id |
|
2216 // |
|
2217 // ----------------------------------------------------------------------------- |
|
2218 // |
|
2219 TInt64 CMediaFileHistory::Id( TInt aIndex ) |
|
2220 { |
|
2221 if ( aIndex < 0 || aIndex >= iList.Count() ) |
|
2222 { |
|
2223 TMFDialogUtil::Panic( KErrArgument ); |
|
2224 } |
|
2225 |
|
2226 TMediaFileHistoryItem& item = iList[aIndex]; |
|
2227 return item.iId; |
|
2228 |
|
2229 } |
|
2230 |
|
2231 |
|
2232 // ----------------------------------------------------------------------------- |
|
2233 // CMediaFileHistory::InternalizeL |
|
2234 // |
|
2235 // ----------------------------------------------------------------------------- |
|
2236 // |
|
2237 void CMediaFileHistory::InternalizeL( RReadStream& aStream ) |
|
2238 { |
|
2239 TInt count = aStream.ReadInt32L(); |
|
2240 if ( count < 0 || count > KMaxHistoryItemCount ) |
|
2241 { |
|
2242 User::Leave( KErrCorrupt ); |
|
2243 } |
|
2244 |
|
2245 for ( TInt i=0; i<count; i++ ) |
|
2246 { |
|
2247 TMediaFileHistoryItem item; |
|
2248 TInt err = KErrNone; |
|
2249 TRAP( err, item.InternalizeL( aStream ) ); |
|
2250 if ( err != KErrNone ) |
|
2251 { |
|
2252 User::Leave( err ); |
|
2253 } |
|
2254 iList.AppendL( item ); |
|
2255 } |
|
2256 } |
|
2257 |
|
2258 |
|
2259 // ----------------------------------------------------------------------------- |
|
2260 // CMediaFileHistory::ExternalizeL |
|
2261 // |
|
2262 // ----------------------------------------------------------------------------- |
|
2263 // |
|
2264 void CMediaFileHistory::ExternalizeL(RWriteStream& aStream) |
|
2265 { |
|
2266 TInt count = iList.Count(); |
|
2267 aStream.WriteInt32L( count ); |
|
2268 |
|
2269 for ( TInt i=0; i<count; i++ ) |
|
2270 { |
|
2271 TMediaFileHistoryItem& item = iList[i]; |
|
2272 item.ExternalizeL( aStream ); |
|
2273 } |
|
2274 } |
|
2275 |
|
2276 |
|
2277 // ----------------------------------------------------------------------------- |
|
2278 // CMediaFileHistory::ReadHistoryL |
|
2279 // |
|
2280 // ----------------------------------------------------------------------------- |
|
2281 // |
|
2282 void CMediaFileHistory::ReadHistoryL() |
|
2283 { |
|
2284 RFile file; |
|
2285 TInt err = file.Open( iFsSession, iPath, EFileRead ); |
|
2286 if ( err == KErrNotFound ) |
|
2287 { |
|
2288 err = file.Create( iFsSession, iPath, EFileRead ); |
|
2289 } |
|
2290 User::LeaveIfError( err ); |
|
2291 |
|
2292 CleanupClosePushL( file ); |
|
2293 |
|
2294 RFileReadStream stream( file, 0 ); |
|
2295 CleanupClosePushL( stream ); |
|
2296 |
|
2297 TRAP( err, InternalizeL( stream ) ); |
|
2298 User::LeaveIfError( err ); |
|
2299 |
|
2300 CleanupStack::PopAndDestroy( &stream ); |
|
2301 CleanupStack::PopAndDestroy( &file ); |
|
2302 } |
|
2303 |
|
2304 |
|
2305 |
|
2306 // ----------------------------------------------------------------------------- |
|
2307 // CMediaFileHistory::WriteHistoryL |
|
2308 // |
|
2309 // ----------------------------------------------------------------------------- |
|
2310 // |
|
2311 void CMediaFileHistory::WriteHistoryL() |
|
2312 { |
|
2313 RFile file; |
|
2314 User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite ) ); |
|
2315 CleanupClosePushL( file ); |
|
2316 |
|
2317 RFileWriteStream stream( file, 0 ); |
|
2318 CleanupClosePushL( stream ); |
|
2319 |
|
2320 TInt err = KErrNone; |
|
2321 TRAP( err, ExternalizeL( stream ) ); |
|
2322 |
|
2323 if ( err == KErrNone ) |
|
2324 { |
|
2325 TRAP( err, stream.CommitL() ); |
|
2326 User::LeaveIfError( err ); |
|
2327 } |
|
2328 |
|
2329 CleanupStack::PopAndDestroy( &stream ); |
|
2330 CleanupStack::PopAndDestroy( &file ); |
|
2331 } |
|
2332 |
|
2333 |
|
2334 // ----------------------------------------------------------------------------- |
|
2335 // CMediaFileHistory::Clean |
|
2336 // |
|
2337 // ----------------------------------------------------------------------------- |
|
2338 // |
|
2339 void CMediaFileHistory::Clean() |
|
2340 { |
|
2341 Sort(); |
|
2342 |
|
2343 for (;;) |
|
2344 { |
|
2345 TInt ret = RemoveOldItem(); |
|
2346 if ( !ret ) |
|
2347 { |
|
2348 break; |
|
2349 } |
|
2350 } |
|
2351 } |
|
2352 |
|
2353 |
|
2354 // ----------------------------------------------------------------------------- |
|
2355 // CMediaFileHistory::RemoveOldItem |
|
2356 // |
|
2357 // ----------------------------------------------------------------------------- |
|
2358 // |
|
2359 TBool CMediaFileHistory::RemoveOldItem() |
|
2360 { |
|
2361 TInt count = iList.Count(); |
|
2362 |
|
2363 for ( TInt i=0; i<count; i++ ) |
|
2364 { |
|
2365 TMediaFileHistoryItem& item= iList[i]; |
|
2366 if ( !item.iPresent ) |
|
2367 { |
|
2368 iList.Remove( i ); |
|
2369 return ETrue; |
|
2370 } |
|
2371 } |
|
2372 |
|
2373 count = iList.Count(); |
|
2374 |
|
2375 if ( count > KMaxHistoryItemCount ) |
|
2376 { |
|
2377 iList.Remove( count - 1 ); |
|
2378 return ETrue; |
|
2379 } |
|
2380 |
|
2381 return EFalse; |
|
2382 } |
|
2383 |
|
2384 |
|
2385 // ----------------------------------------------------------------------------- |
|
2386 // CMediaFileHistory::AddItemL |
|
2387 // |
|
2388 // ----------------------------------------------------------------------------- |
|
2389 // |
|
2390 void CMediaFileHistory::AddItemL( TMediaFileHistoryItem aItem ) |
|
2391 { |
|
2392 TInt index = ItemIndex( aItem.iId ); |
|
2393 if ( index != KErrNotFound ) |
|
2394 { |
|
2395 iList.Remove(index); |
|
2396 } |
|
2397 |
|
2398 User::LeaveIfError( iList.Append( aItem ) ); |
|
2399 } |
|
2400 |
|
2401 |
|
2402 // ----------------------------------------------------------------------------- |
|
2403 // CMediaFileHistory::ItemIndex |
|
2404 // |
|
2405 // ----------------------------------------------------------------------------- |
|
2406 // |
|
2407 TInt CMediaFileHistory::ItemIndex( TInt aId ) |
|
2408 { |
|
2409 TInt count = iList.Count(); |
|
2410 |
|
2411 for (TInt i=0; i<count; i++) |
|
2412 { |
|
2413 TMediaFileHistoryItem& item= iList[i]; |
|
2414 if ( item.iId == aId ) |
|
2415 { |
|
2416 return i; |
|
2417 } |
|
2418 } |
|
2419 |
|
2420 return KErrNotFound; |
|
2421 } |
|
2422 |
|
2423 |
|
2424 // ----------------------------------------------------------------------------- |
|
2425 // CMediaFileHistory::Item |
|
2426 // |
|
2427 // ----------------------------------------------------------------------------- |
|
2428 // |
|
2429 TMediaFileHistoryItem& CMediaFileHistory::Item( TInt aIndex ) |
|
2430 { |
|
2431 if ( aIndex < 0 || aIndex >= iList.Count() ) |
|
2432 { |
|
2433 TMFDialogUtil::Panic( KErrArgument ); |
|
2434 } |
|
2435 |
|
2436 return iList[aIndex]; |
|
2437 } |
|
2438 |
|
2439 |
|
2440 // ----------------------------------------------------------------------------- |
|
2441 // CMediaFileHistory::Sort |
|
2442 // |
|
2443 // ----------------------------------------------------------------------------- |
|
2444 // |
|
2445 void CMediaFileHistory::Sort() |
|
2446 { |
|
2447 iList.Sort( TLinearOrder<TMediaFileHistoryItem>(CMediaFileHistory::CompareItems) ); |
|
2448 } |
|
2449 |
|
2450 |
|
2451 // ----------------------------------------------------------------------------- |
|
2452 // CMediaFileHistory::CompareItems |
|
2453 // |
|
2454 // ----------------------------------------------------------------------------- |
|
2455 // |
|
2456 TInt CMediaFileHistory::CompareItems( const TMediaFileHistoryItem& aFirst, |
|
2457 const TMediaFileHistoryItem& aSecond ) |
|
2458 { |
|
2459 if ( aFirst.iTime > aSecond.iTime ) |
|
2460 { |
|
2461 return -1; |
|
2462 } |
|
2463 else if ( aFirst.iTime < aSecond.iTime ) |
|
2464 { |
|
2465 return 1; |
|
2466 } |
|
2467 return 0; |
|
2468 } |
|
2469 |
|
2470 |
|
2471 // ----------------------------------------------------------------------------- |
|
2472 // CMediaFileHistory::GetTimeText |
|
2473 // |
|
2474 // ----------------------------------------------------------------------------- |
|
2475 // |
|
2476 void CMediaFileHistory::GetTimeText( TDes& aText, TTime aTime ) |
|
2477 { |
|
2478 _LIT( KFormat, "%02d.%02d.%04d %02d:%02d:%02d" ); |
|
2479 |
|
2480 TDateTime dt = aTime.DateTime(); |
|
2481 aText.Format( KFormat, dt.Day()+1, dt.Month()+1, dt.Year(), dt.Hour(), dt.Minute(), dt.Second() ); |
|
2482 } |
|
2483 |
|
2484 */ |
|
2485 |
|
2486 #endif // #ifdef _DEBUG |
|
2487 |
|
2488 // End of File |
|
2489 |