javauis/mmapi_akn/baseline/src/cmmavolumecontrol.cpp
branchRCL_3
changeset 60 6c158198356e
parent 46 4376525cdefb
equal deleted inserted replaced
59:e5618cc85d74 60:6c158198356e
    18 
    18 
    19 //  INCLUDE FILES
    19 //  INCLUDE FILES
    20 #include "cmmaplayer.h"
    20 #include "cmmaplayer.h"
    21 #include "cmmavolumecontrol.h"
    21 #include "cmmavolumecontrol.h"
    22 #include <jdebug.h>
    22 #include <jdebug.h>
    23 #include <mprofile.h>
    23 #include <MProfile.h>
    24 #include <mprofileengine.h>
    24 #include <MProfileEngine.h>
    25 #include <cprofilechangenotifyhandler.h>
    25 #include <CProfileChangeNotifyHandler.h>
    26 
    26 
    27 _LIT(KMMAVolumeErrorMsg, "Can't set volume level");
    27 _LIT(KMMAVolumeErrorMsg, "Can't set volume level");
    28 
    28 
    29 const TInt KMMAJavaSoundIndex = 0;
    29 const TInt KMMAJavaSoundIndex = 0;
    30 const TInt KMMAProfileSoundIndex = 1;
    30 const TInt KMMAProfileSoundIndex = 1;
    44     // Java level is the first
    44     // Java level is the first
    45     aVolumeControl->GetVolumeLevelL(KMMAJavaSoundIndex, aLevel);
    45     aVolumeControl->GetVolumeLevelL(KMMAJavaSoundIndex, aLevel);
    46 }
    46 }
    47 
    47 
    48 
    48 
    49 CMMAVolumeControl::CMMAVolumeControl(CMMAPlayer* aPlayer)
    49 EXPORT_C CMMAVolumeControl::CMMAVolumeControl(CMMAPlayer* aPlayer)
    50         : iPlayer(aPlayer), iLevel(KMMAVolumeMaxLevel)
    50         : iPlayer(aPlayer), iLevel(KMMAVolumeMaxLevel)
    51 {
    51 {
    52 }
    52 }
    53 
    53 
    54 
    54 
    55 CMMAVolumeControl::~CMMAVolumeControl()
    55 EXPORT_C CMMAVolumeControl::~CMMAVolumeControl()
    56 {
    56 {
    57     delete iProfChangeNotifier;
    57     delete iProfChangeNotifier;
    58     iLevels.Close();
    58     iLevels.Close();
    59 }
    59 }
    60 
    60 
    61 
    61 
    62 void CMMAVolumeControl::ConstructBaseL()
    62 EXPORT_C void CMMAVolumeControl::ConstructBaseL()
    63 {
    63 {
    64     iPlayer->AddStateListenerL(this);
    64     iPlayer->AddStateListenerL(this);
    65 
    65 
    66     // Add level for javasound, will set in StaticSetLevelL method.
    66     // Add level for javasound, will set in StaticSetLevelL method.
    67     SetJavaSoundVolumeLevelL();
    67     SetJavaSoundVolumeLevelL();
   112     iProfChangeNotifier = CProfileChangeNotifyHandler::NewL( this );
   112     iProfChangeNotifier = CProfileChangeNotifyHandler::NewL( this );
   113     // Sets level to 0 if profile isn't on
   113     // Sets level to 0 if profile isn't on
   114     iLevel = CalculateLevel();
   114     iLevel = CalculateLevel();
   115 
   115 
   116 }
   116 }
   117 void CMMAVolumeControl::HandleActiveProfileEventL(TProfileEvent aProfileEvent,
   117 EXPORT_C void CMMAVolumeControl::HandleActiveProfileEventL(
   118         TInt aProfileId)
   118                                  TProfileEvent aProfileEvent, TInt aProfileId)
   119 {
   119 {
   120     switch (aProfileEvent)
   120     switch (aProfileEvent)
   121     {
   121     {
   122     case EProfileNewActiveProfile:
   122     case EProfileNewActiveProfile:
   123     {
   123     {
   155     }
   155     }
   156 }
   156 }
   157 
   157 
   158 
   158 
   159 
   159 
   160 const TDesC& CMMAVolumeControl::ClassName() const
   160 EXPORT_C const TDesC& CMMAVolumeControl::ClassName() const
   161 {
   161 {
   162     return KMMAVolumeControlName;
   162     return KMMAVolumeControlName;
   163 }
   163 }
   164 
   164 
   165 void CMMAVolumeControl::SetLevelL(TInt aLevel)
   165 void CMMAVolumeControl::SetLevelL(TInt aLevel)
   170         DoSetLevelL(aLevel);
   170         DoSetLevelL(aLevel);
   171     }
   171     }
   172     iLevel = aLevel;
   172     iLevel = aLevel;
   173 }
   173 }
   174 
   174 
   175 void CMMAVolumeControl::StateChanged(TInt aState)
   175 EXPORT_C void CMMAVolumeControl::StateChanged(TInt aState)
   176 {
   176 {
   177     DEBUG_INT("CMMAVolumeControl::StateChanged - state %d", aState);
   177     DEBUG_INT("CMMAVolumeControl::StateChanged - state %d", aState);
   178     // Set the volume if the player is prefetched
   178     // Set the volume if the player is prefetched
   179     if (aState == CMMAPlayer::EPrefetched)
   179     if (aState == CMMAPlayer::EPrefetched)
   180     {
   180     {
   202     // Error ID AKUR-7G69Q5 GLOBAL VOLUME EVENT CR
   202     // Error ID AKUR-7G69Q5 GLOBAL VOLUME EVENT CR
   203     if (aState == CMMAPlayer::ERealized)
   203     if (aState == CMMAPlayer::ERealized)
   204     {
   204     {
   205         if ((iLevels.Count() - 1) == KMMAGlobalVolumeSoundIndex)
   205         if ((iLevels.Count() - 1) == KMMAGlobalVolumeSoundIndex)
   206         {
   206         {
   207             DEBUG("MMA::CMMAVolumeControl::StateChanged : Post GLOBAL VOL EVENT  ");
   207             if ((iLevels[ KMMAGlobalVolumeSoundIndex ] != KErrNotFound) && 
   208             if (iLevels[ KMMAGlobalVolumeSoundIndex ] != KErrNotFound)
   208             (iLevels[ KMMAGlobalVolumeSoundIndex] != iInitialGlobalVolumeLevel))
   209             {
   209             {
   210                 DEBUG_INT("MMA::CMMAVolumeControl::StateChanged : Post complete Val = %d ",iLevels[ KMMAGlobalVolumeSoundIndex ]);
   210                 DEBUG("MMA::CMMAVolumeControl::StateChanged : Post GLOBAL VOL EVENT  ");
       
   211                 DEBUG_INT("MMA::CMMAVolumeControl::StateChanged : Post complete Val = %d ",
       
   212                                        iLevels[ KMMAGlobalVolumeSoundIndex ]);
   211                 iPlayer->PostLongEvent(CMMAPlayerEvent::ENOKIA_EXTERNAL_VOLUME_EVENT,
   213                 iPlayer->PostLongEvent(CMMAPlayerEvent::ENOKIA_EXTERNAL_VOLUME_EVENT,
   212                                        iLevels[ KMMAGlobalVolumeSoundIndex ]);
   214                                        iLevels[ KMMAGlobalVolumeSoundIndex ]);
   213             }
   215             }
   214         }
   216         }
   215     }
   217     }
   216 }
   218 }
   217 
   219 
   218 void CMMAVolumeControl::RefreshVolume()
   220 EXPORT_C void CMMAVolumeControl::RefreshVolume()
   219 {
   221 {
   220     DEBUG("MMA::CMMAVolumeControl::RefreshVolume ++ ");
   222     DEBUG("MMA::CMMAVolumeControl::RefreshVolume ++ ");
   221     TRAPD(error,
   223     TRAPD(error,
   222     {
   224     {
   223         // Get the default value for the Java sound level
   225         // Get the default value for the Java sound level
   236                                  KMMAVolumeErrorMsg);
   238                                  KMMAVolumeErrorMsg);
   237     }
   239     }
   238     DEBUG("MMA::CMMAVolumeControl::RefreshVolume -- ");
   240     DEBUG("MMA::CMMAVolumeControl::RefreshVolume -- ");
   239 }
   241 }
   240 
   242 
   241 void CMMAVolumeControl::RefreshControl()
   243 EXPORT_C void CMMAVolumeControl::RefreshControl()
   242 {
   244 {
   243     RefreshVolume();
   245     RefreshVolume();
   244 }
   246 }
   245 
   247 
   246 EXPORT_C TInt CMMAVolumeControl::AddLevelL()
   248 EXPORT_C TInt CMMAVolumeControl::AddLevelL()
   281         iPlayer->PostLongEvent(CMMAPlayerEvent::ENOKIA_EXTERNAL_VOLUME_EVENT,
   283         iPlayer->PostLongEvent(CMMAPlayerEvent::ENOKIA_EXTERNAL_VOLUME_EVENT,
   282                                iLevels[ aLevelIndex ]);
   284                                iLevels[ aLevelIndex ]);
   283     }
   285     }
   284 }
   286 }
   285 
   287 
       
   288 void CMMAVolumeControl::InitializeGlobalVolumeLevel(TInt aGlobalVolumeLevel)
       
   289 {
       
   290     iInitialGlobalVolumeLevel = aGlobalVolumeLevel;
       
   291 }
   286 void CMMAVolumeControl::GetVolumeLevelL(TInt aLevelIndex,
   292 void CMMAVolumeControl::GetVolumeLevelL(TInt aLevelIndex,
   287                                         TInt* aVolumeLevel)
   293                                         TInt* aVolumeLevel)
   288 {
   294 {
   289     DEBUG_INT("CMMAVolumeControl::GetVolumeLevelL - level index %d", aLevelIndex);
   295     DEBUG_INT("CMMAVolumeControl::GetVolumeLevelL - level index %d", aLevelIndex);
   290 
   296 
   328 
   334 
   329     // All levels in the array are percentage of the max volume (0..100).
   335     // All levels in the array are percentage of the max volume (0..100).
   330     // Actual sound level will be multiplying all levels.
   336     // Actual sound level will be multiplying all levels.
   331     for (TInt i = 0; i < levelCount; i++)
   337     for (TInt i = 0; i < levelCount; i++)
   332     {
   338     {
       
   339         DEBUG_INT2("CMMAVolumeControl::CalculateLevel value at iLevels[ %d ] is %d",i,iLevels[i]);
   333         // If the level is not known it is expected to be max volume
   340         // If the level is not known it is expected to be max volume
   334         level = (iLevels[ i ] == KErrNotFound ?
   341         level = (iLevels[ i ] == KErrNotFound ?
   335                  level * KMMAVolumeMaxLevel :
   342                  level * KMMAVolumeMaxLevel :
   336                  level * iLevels[ i ]);
   343                  level * iLevels[ i ]);
   337         sum *= KMMAVolumeMaxLevel;
   344         sum *= KMMAVolumeMaxLevel;