phoneengine/phonemodel/src/cpeprofilesettingmonitor.cpp
changeset 0 5f000ab63145
child 21 92ab7f8d0eab
child 61 41a7f70b3818
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     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:  This module contains the implementation of CPEProfileSettingMonitor
       
    15 *                class 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cpeprofilesettingmonitor.h"
       
    22 #include "mpephonemodelinternal.h"
       
    23 #include <mpedatastore.h>
       
    24 #include <MProfileExtraTones.h>
       
    25 #include <talogger.h>
       
    26 
       
    27 
       
    28 /////////////////////////////////////////////////////////////////////////
       
    29 // CPEProfileSettingMonitor
       
    30 /////////////////////////////////////////////////////////////////////////
       
    31 
       
    32 CPEProfileSettingMonitor* CPEProfileSettingMonitor::NewL(
       
    33         MPEPhoneModelInternal& aModel )
       
    34     {
       
    35     TEFLOGSTRING( KTAOBJECT, "PE CPEProfileSettingMonitor::NewL" );
       
    36     CPEProfileSettingMonitor* self = new ( ELeave ) CPEProfileSettingMonitor( aModel );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return ( self );                                                         
       
    41     }
       
    42 
       
    43 // Destructor
       
    44 CPEProfileSettingMonitor::~CPEProfileSettingMonitor( )
       
    45     {
       
    46     TEFLOGSTRING( KTAOBJECT, "PE CPEProfileSettingMonitor::~CPEProfileSettingMonitor" );
       
    47     if ( iProfileEventHandler )
       
    48         {
       
    49         delete iProfileEventHandler;
       
    50         iProfileEventHandler = NULL;
       
    51         }
       
    52     if ( iProfileEngine )
       
    53         {
       
    54         iProfileEngine->Release();
       
    55         }
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CPEProfileSettingMonitor::CPEProfileSettingMonitor
       
    60 // C++ default constructor can NOT contain any code, that
       
    61 // might leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPEProfileSettingMonitor::CPEProfileSettingMonitor(
       
    65         MPEPhoneModelInternal& aModel
       
    66         ) : iModel( aModel )
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPEProfileSettingMonitor::ConstructL
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CPEProfileSettingMonitor::ConstructL()
       
    76     {
       
    77     // Create the profile engine
       
    78     iProfileEngine = CreateProfileEngineL();
       
    79     
       
    80     // Retrieve current profile settings    
       
    81     GetProfileSettingsL();
       
    82     
       
    83     iModel.SendMessage( MEngineMonitor::EPEMessageProfileChanged ); 
       
    84     
       
    85     // Start listening for profiles change notifications
       
    86     iProfileEventHandler = CProfileChangeNotifyHandler::NewL( this );    
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPEProfileSettingMonitor::GetProfileSettingsL
       
    91 // Retrieves settings from profiles that are relevant to Phone Engine
       
    92 // Called on construction and whenever notification is received that
       
    93 // a change has occurred to the profile settings
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CPEProfileSettingMonitor::GetProfileSettingsL()
       
    97     {
       
    98     TEFLOGSTRING( KTAINT, "PE CPEProfileSettingMonitor::GetProfileSettings" );
       
    99     __UHEAP_MARK;
       
   100     //  Get a pointer to the active profile (with ownership)
       
   101     MProfile* activeProfile = iProfileEngine->ActiveProfileLC();
       
   102     
       
   103     // Get profile id
       
   104     iModel.DataStore()->SetProfileId( activeProfile->ProfileName().Id() );
       
   105     // Get profile name
       
   106     iModel.DataStore()->SetProfileName( activeProfile->ProfileName().Name() );
       
   107     
       
   108     const MProfileTones& activeTones = activeProfile->ProfileTones();
       
   109     
       
   110     // Get ringtones for line 1 and 2
       
   111     iModel.DataStore()->SetRingingTone1( activeTones.RingingTone1() );
       
   112     iModel.DataStore()->SetRingingTone2( activeTones.RingingTone2() );
       
   113     
       
   114     // Get video call ringing tone, if it is supported
       
   115     if ( iProfileEngine->IsFeatureSupported( EProfileFeatureVTRingingTone ) )
       
   116         {
       
   117         const MProfileExtraTones& extraTones = activeProfile->ProfileExtraTones();
       
   118         iModel.DataStore()->SetVideoCallRingingTone( 
       
   119             extraTones.VideoCallRingingTone() );
       
   120         }
       
   121     const TProfileToneSettings& toneSettings = activeTones.ToneSettings();  
       
   122     
       
   123     // Get ringing type and volume and keypad volume
       
   124     TProfileRingingType ringingType = toneSettings.iRingingType;    
       
   125     iModel.DataStore()->SetRingingType( static_cast<TProfileRingingType>( ringingType ) );
       
   126     iModel.DataStore()->SetRingingVolume( toneSettings.iRingingVolume );
       
   127     iModel.DataStore()->SetTextToSpeech( toneSettings.iTextToSpeech );
       
   128                   
       
   129     TProfileKeypadVolume keypadVolume = toneSettings.iKeypadVolume;
       
   130     	
       
   131     if ( keypadVolume < EProfileKeypadVolumeOff 
       
   132         || keypadVolume > EProfileKeypadVolumeLevel3 )
       
   133 	    {
       
   134         // Value is out of range - use default
       
   135 		keypadVolume = EProfileKeypadVolumeLevel2; // default value
       
   136 	    }
       
   137 	
       
   138 	const TInt KKeypadVolume[4] = {0, 2, 5, 10}; // Previous PE settings
       
   139 	TInt volume = KKeypadVolume[ keypadVolume ];
       
   140 	iModel.DataStore()->SetKeypadVolume( volume );
       
   141 
       
   142     //  Get alert for group Ids
       
   143     iModel.DataStore()->SetAlertForGroup( activeProfile->AlertForL() );
       
   144 
       
   145     // Pop( activeProfile ) does not recognize ActiveProfileLC created 
       
   146     // item because of casting. However, functionality and cleanup works OK.
       
   147     CleanupStack::Pop(); // activeProfile
       
   148 	activeProfile->Release();
       
   149 	__UHEAP_MARKEND;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CPEProfileSettingMonitor::HandleActiveProfileEventL
       
   154 // Callback function - implements virtual function from MProfileChangeObserver
       
   155 // This is called whenever profiles settings change
       
   156 // We're not interested in aProfileId which identifies the number of the active profile changed
       
   157 // This notifier doesn't identify the property changed - so update them all by 
       
   158 // calling the GetProfileSettingsL() method
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 void CPEProfileSettingMonitor::HandleActiveProfileEventL(
       
   162         TProfileEvent aProfileEvent,
       
   163         TInt /*aProfileId*/ )
       
   164     {
       
   165     TEFLOGSTRING2( KTAINT, "PE CPEProfileSettingMonitor::HandleActiveProfileEventL %d", aProfileEvent );
       
   166     
       
   167     ASSERT( aProfileEvent != EProfileUnknownEvent );
       
   168     
       
   169     // Update the iEngineInfo with the required profile settings    
       
   170     GetProfileSettingsL();
       
   171     
       
   172     if ( aProfileEvent != EProfileUnknownEvent )
       
   173         {
       
   174         // A new profile has been set
       
   175         iModel.SendMessage( MEngineMonitor::EPEMessageProfileChanged );        
       
   176         }        
       
   177     }
       
   178 
       
   179 // End of file