mpx/tsrc/public/basic/common/testviewframework/src/testplaybackview.cpp
changeset 62 b276843a15ba
equal deleted inserted replaced
58:c76ea6caa649 62:b276843a15ba
       
     1 /*
       
     2 * Copyright (c) 2002 - 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:  A view displaying basic playback state and feature
       
    15 *
       
    16 */
       
    17 
       
    18 #include <stiflogger.h>
       
    19 #include <e32const.h>
       
    20 #include "testplaybackviewobserver.h"
       
    21 #include "testplaybackview.h"
       
    22 
       
    23 // CONSTANTS
       
    24 _LIT(KSpacer,           " ");
       
    25 _LIT(KPlay,             " Play-1 ");
       
    26 _LIT(KPlaySel,          "(Play-1)");
       
    27 _LIT(KBackward,         " <<-2 ");
       
    28 _LIT(KForward,          " >>-3 ");
       
    29 _LIT(KStop,             " Stop-4 ");
       
    30 _LIT(KStopSel,          "(Stop-4)");
       
    31 _LIT(KFastRewind,       " FR-5 ");
       
    32 _LIT(KFastRewindSel,    "(FR-5)");
       
    33 _LIT(KFastForward,      " FF-6 ");
       
    34 _LIT(KFastForwardSel,   "(FF-6)");
       
    35 _LIT(KPause,            " Pause-7 ");
       
    36 _LIT(KPauseSel,         "(Pause-7)");
       
    37     
       
    38 _LIT(KExit,             "Exit-Esc"  );
       
    39 
       
    40 const TInt KSongInfoYOffset = 10;
       
    41 const TInt KDisplayScreenWidthOffset = 10;
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Symbian 2-phrase constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CTestPlaybackView* CTestPlaybackView::NewL(CConsoleMain* aConsoleMain,
       
    50                                             CTestBaseView* aParent,
       
    51                                             const TDesC& aName,
       
    52                                             CStifLogger* aLogger)
       
    53     {
       
    54     CTestPlaybackView* self = new (ELeave) CTestPlaybackView(aConsoleMain,
       
    55                                                              aParent,
       
    56                                                              aName,
       
    57                                                              aLogger);
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62     
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // C++ destructor
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C CTestPlaybackView::~CTestPlaybackView()
       
    70     {
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Add observer
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C void CTestPlaybackView::AddObserver(MTestPlaybackViewObserver* aObs)
       
    78     {
       
    79     iTestPlaybackViewObs = aObs;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Update current index
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C void CTestPlaybackView::UpdateItemIndex(TInt aIndex, TInt aTotalItem)
       
    87     {
       
    88     iCurrentStatus.iItemIndex = aIndex;
       
    89     iCurrentStatus.iMaxItems = aTotalItem;
       
    90     RedrawIndex();
       
    91     }
       
    92     
       
    93 // ---------------------------------------------------------------------------
       
    94 // Update position in the song
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C void CTestPlaybackView::UpdateProgress(TInt aPosition, TInt aDuration)
       
    98     {
       
    99     iCurrentStatus.iProgressPos = aPosition;
       
   100     iCurrentStatus.iProgressDur = aDuration;
       
   101     RedrawProgress();
       
   102     }
       
   103     
       
   104 // ---------------------------------------------------------------------------
       
   105 // Update volume
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 EXPORT_C void CTestPlaybackView::UpdateVolume(TInt aVolume, TInt aMaxVolume)
       
   109     {
       
   110     iCurrentStatus.iVolume = aVolume;
       
   111     iCurrentStatus.iMaxVolume = aMaxVolume;
       
   112     RedrawVolume();
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // Update artist and song name
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C void CTestPlaybackView::UpdateSongInfo(const TDesC& aArtist, 
       
   120                                        const TDesC& aSongName)
       
   121     {
       
   122     TInt y = iDisplaySize.iHeight/ 2 - 2;
       
   123     //erase previous text
       
   124     for(TInt i = 0; i < iDisplaySize.iWidth; i++)
       
   125         {
       
   126         iConsole->SetPos(i,y);
       
   127         iConsole->Printf(_L(" "));
       
   128         iConsole->SetPos(i,y+1);
       
   129         iConsole->Printf(_L(" "));
       
   130         }
       
   131     iConsole->SetPos(
       
   132                 Max((iDisplaySize.iWidth - aArtist.Length())/2, 0), y++);
       
   133     iConsole->Printf(_L("%S"), &aArtist);
       
   134     iConsole->SetPos(
       
   135                 Max((iDisplaySize.iWidth - aSongName.Length())/2, 0), y);
       
   136     iConsole->Printf(_L("%S"), &aSongName);
       
   137     //DisplayViewL();
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // Handles state changes in playbackutility
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 EXPORT_C void CTestPlaybackView::StateChanged(TTestPlaybackState aState)
       
   145     {
       
   146     
       
   147     switch(aState)
       
   148         {
       
   149     case ETPbStateInitialising:
       
   150         UpdateSongInfo(KNullDesC, _L("Opening file"));
       
   151     case ETPbStateShuttingDown:
       
   152     case ETPbStateBuffering:
       
   153     case ETPbStateDownloading:
       
   154     case ETPbStateStopped:
       
   155     case ETPbStateNotInitialised:
       
   156         iCurrentStatus.iPlaying = iCurrentStatus.iForwardSeek 
       
   157         = iCurrentStatus.iBackwardSeek = iCurrentStatus.iPause = EFalse;
       
   158         break;
       
   159     case ETPbStatePaused:
       
   160         iCurrentStatus.iPlaying = iCurrentStatus.iForwardSeek 
       
   161         = iCurrentStatus.iBackwardSeek = EFalse;
       
   162         iCurrentStatus.iPause = ETrue;
       
   163         break;
       
   164     case ETPbStatePlaying:
       
   165         iCurrentStatus.iPause = iCurrentStatus.iForwardSeek 
       
   166         = iCurrentStatus.iBackwardSeek = EFalse;
       
   167         iCurrentStatus.iPlaying = ETrue;
       
   168         break;
       
   169     case ETPbStateSeekingForward:
       
   170         iCurrentStatus.iBackwardSeek = EFalse;
       
   171         iCurrentStatus.iForwardSeek = ETrue;
       
   172         break;
       
   173     case ETPbStateSeekingBackward:
       
   174         iCurrentStatus.iForwardSeek = EFalse;
       
   175         iCurrentStatus.iBackwardSeek = ETrue;
       
   176         break;
       
   177         }
       
   178     RedrawPlayerStatue();
       
   179     }
       
   180     
       
   181 // ---------------------------------------------------------------------------
       
   182 // From class CTestBaseView.
       
   183 // Initialization of a view before first time activation
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CTestPlaybackView::InitializeViewL()
       
   187     {
       
   188     iConsole->ClearScreen();
       
   189     RedrawProgress();
       
   190     RedrawVolume();
       
   191     UpdateSongInfo(KNullDesC, KNullDesC);
       
   192     RedrawPlayerStatue();
       
   193     }
       
   194     
       
   195 // ---------------------------------------------------------------------------
       
   196 // From class CTestBaseView.
       
   197 // Cleanup the child view before deactivate/destroy view
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CTestPlaybackView::CleanupViewL()
       
   201     {
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // From class CTestBaseView.
       
   206 // Display this view 
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CTestPlaybackView::DisplayViewL()
       
   210     {
       
   211     DisplayViewBase();
       
   212     RedrawIndex();
       
   213     RedrawProgress();
       
   214     RedrawVolume();
       
   215     RedrawPlayerStatue();
       
   216     }
       
   217     
       
   218 // ---------------------------------------------------------------------------
       
   219 // From class CTestBaseView.
       
   220 // Process keypresses on this view - called by ConsoleMain
       
   221 // ---------------------------------------------------------------------------
       
   222 //
       
   223 void CTestPlaybackView::SelectL( TKeyCode aSelection, TBool& aContinue )
       
   224     {
       
   225     aContinue = ETrue;
       
   226     switch(aSelection)
       
   227         {
       
   228         case '1':
       
   229             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdPlay);
       
   230             break;
       
   231         case '2':
       
   232             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdPrevious);
       
   233             break;
       
   234         case '3':
       
   235             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdNext);
       
   236             break;
       
   237         case '4':
       
   238             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdStop);
       
   239             break;
       
   240         case '5':
       
   241             iTestPlaybackViewObs->HandleUiCommandL(iCurrentStatus.iBackwardSeek?
       
   242                                                   ETPbViewCmdStopSeeking : 
       
   243                                                   ETPbViewCmdStartSeekBackward);
       
   244             break;
       
   245         case '6':
       
   246             iTestPlaybackViewObs->HandleUiCommandL(iCurrentStatus.iForwardSeek?
       
   247                                                   ETPbViewCmdStopSeeking : 
       
   248                                                   ETPbViewCmdStartSeekForward);
       
   249             break;
       
   250         case '7':
       
   251             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdPause);
       
   252             break;
       
   253         case '8':
       
   254             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdDecreaseVolume);
       
   255             break;
       
   256         case '9':
       
   257             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdIncreaseVolume);
       
   258             break;
       
   259         case EKeyEscape:
       
   260             iTestPlaybackViewObs->HandleUiCommandL(ETPbViewCmdClose);
       
   261             aContinue = EFalse;
       
   262             CurrentViewDoneL();
       
   263             break;
       
   264         }
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // From class CTestBaseView.
       
   269 // Update display from timer - called by ConsoleMain
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 void CTestPlaybackView::TimerUpdate()
       
   273     {
       
   274     
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // C++ constructor
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 CTestPlaybackView::CTestPlaybackView(CConsoleMain* aConsoleMain,
       
   282                                       CTestBaseView* aParent,
       
   283                                       const TDesC& aName,
       
   284                                       CStifLogger* aLogger)
       
   285     : CTestBaseView(aConsoleMain, aParent, aName)
       
   286     {
       
   287     iDisplaySize = iConsole->ScreenSize();
       
   288     iDisplaySize.iWidth = iDisplaySize.iWidth - KDisplayScreenWidthOffset;
       
   289     iLogger = aLogger;
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // Symbian 2-phrase constructor
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CTestPlaybackView::ConstructL()
       
   297     {
       
   298     
       
   299     iCurrentStatus.iBackwardSeek = EFalse;
       
   300     iCurrentStatus.iForwardSeek = EFalse;
       
   301     iCurrentStatus.iPlaying = EFalse;
       
   302     iCurrentStatus.iPause = EFalse;
       
   303     iCurrentStatus.iVolume = 0;
       
   304     iCurrentStatus.iMaxVolume = 20; //magic number??
       
   305     iCurrentStatus.iProgressPos = 0;
       
   306     iCurrentStatus.iProgressDur = KMaxTInt;
       
   307     iCurrentStatus.iItemIndex = 0;
       
   308     iCurrentStatus.iMaxItems = 0;
       
   309     
       
   310     InitializeViewL();
       
   311     }
       
   312 
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // Redraw index in view
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CTestPlaybackView::RedrawIndex()
       
   319     {
       
   320     if(iCurrentStatus.iMaxItems <= 0)
       
   321         return;
       
   322     iConsole->SetPos(iDisplaySize.iWidth - 5, 3);   //##/## format
       
   323     iConsole->Printf(_L("     "));                  //clean
       
   324     iConsole->SetPos(iDisplaySize.iWidth - 5, 3);
       
   325     iConsole->Printf(_L("%d/%d"), iCurrentStatus.iItemIndex, 
       
   326                                   iCurrentStatus.iMaxItems);
       
   327     
       
   328     }
       
   329     
       
   330 // ---------------------------------------------------------------------------
       
   331 // Redraw progress bar in view
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CTestPlaybackView::RedrawProgress()
       
   335     {
       
   336     if(iCurrentStatus.iProgressDur <= 0)
       
   337         return;
       
   338     TInt pos = iCurrentStatus.iProgressPos * 
       
   339                     iDisplaySize.iWidth / iCurrentStatus.iProgressDur ;
       
   340     iConsole->SetPos(0,  iDisplaySize.iHeight / 2);
       
   341     for(TInt x = 1; x <= iDisplaySize.iWidth; x++)
       
   342         iConsole->Printf(x<=pos? _L("=") : _L("-"));
       
   343     }
       
   344     
       
   345 // ---------------------------------------------------------------------------
       
   346 // Redraw volume bar in view
       
   347 // ---------------------------------------------------------------------------
       
   348 //
       
   349 void CTestPlaybackView::RedrawVolume()
       
   350     {
       
   351     if(iCurrentStatus.iMaxVolume <= 0)
       
   352         return;
       
   353     TInt pos = iCurrentStatus.iVolume * 
       
   354                     iCurrentStatus.iMaxVolume / iCurrentStatus.iMaxVolume ;
       
   355     iConsole->SetPos(0, 1);
       
   356     iConsole->Printf(_L("Volume(8|9):"));
       
   357     for(TInt x = 1; x <= iCurrentStatus.iMaxVolume; x++)
       
   358         iConsole->Printf(x <= pos? _L("=") : _L("-"));
       
   359     iConsole->Printf(_L(" %d/%d"), 
       
   360                      iCurrentStatus.iVolume, 
       
   361                      iCurrentStatus.iMaxVolume);
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // Redraw status/control part of the view
       
   366 // ---------------------------------------------------------------------------
       
   367 //
       
   368 void CTestPlaybackView::RedrawPlayerStatue()
       
   369     {
       
   370     TInt linePosY = iDisplaySize.iHeight - KSongInfoYOffset;
       
   371     
       
   372     //Line 1
       
   373     iConsole->SetPos(0, linePosY);
       
   374     iConsole->Printf(iCurrentStatus.iPlaying?
       
   375                         KStop : KStopSel);
       
   376     iConsole->Printf(KSpacer);
       
   377     iConsole->Printf(iCurrentStatus.iBackwardSeek?
       
   378                         KFastRewindSel : KFastRewind);
       
   379     iConsole->Printf(KSpacer);
       
   380     iConsole->Printf(iCurrentStatus.iForwardSeek?
       
   381                         KFastForwardSel : KFastForward);
       
   382     iConsole->Printf(KSpacer);
       
   383     iConsole->Printf(iCurrentStatus.iPause?
       
   384                         KPauseSel : KPause);
       
   385     
       
   386     //Line 2
       
   387     iConsole->SetPos(0, ++linePosY);
       
   388     iConsole->Printf(iCurrentStatus.iPlaying?
       
   389                         KPlaySel : KPlay);
       
   390     iConsole->Printf(KSpacer);
       
   391     iConsole->Printf(KBackward);
       
   392     iConsole->Printf(KSpacer);
       
   393     iConsole->Printf(KForward);
       
   394     
       
   395     //Line Exit
       
   396     iConsole->SetPos(iDisplaySize.iWidth - KExit().Length(),  
       
   397                      iDisplaySize.iHeight - 1);    
       
   398     iConsole->Printf(KExit);
       
   399     }
       
   400