Archived:Notification of a change in the Active Profile Ringtone using Symbian C++
Article Metadata
Code Example
Tested with
Compatibility
Article
Overview
Profiles Engine API, part of the Extension plug-in package for S60 3rd Edition, MR, provides the class CProfileChangeNotifyHandler that can be used to get a notification for activation of a new profile and modifications of current active profile settings.
See also How to get notification of profile change
Description
Header files:
#include <CProfileChangeNotifyHandler.h> #include <MProfileChangeObserver.h> #include <MProfileEngine.h> // link against profileeng.lib #include <MProfile.h> #include <MProfileTones.h>
Derive a class from MProfileChangeObserver and implement a pure virtual function HandleActiveProfileEventL() in order to get notifications.
Create an instance of CProfileChangeNotifyHandler class in the ConstructL() of this class:
CProfileChangeNotifyHandler* iHandler =
CProfileChangeNotifyHandler::NewL( this );
First, store the ring tone from the active profile in a descriptor. Whenever a change notification for the active profile comes in, re-retrieve the ring tone and compare it with the old value.
The following code is used to get the active profile ring tone:
MProfileEngine* profileEngine = CreateProfileEngineL();
CleanupReleasePushL(*profileEngine);
MProfile* activProfile =
profileEngine->ActiveProfileL();
const MProfileTones& activeProfileTone =
activProfile->ProfileTones();
// iCurrentRingTone is of type TFileName
iCurrentRingTone = activeProfileTone.RingingTone1();
CleanupStack::PopAndDestroy(); // profileEngine
Implementation of HandleActiveProfileEventL():
HandleActiveProfileEventL( TProfileEvent aProfileEvent,
TInt aProfileId )
{
switch(aProfileEvent)
{
case EProfileActiveProfileModified:
{
// Active profile settings are modified
MProfileEngine* profileEngineNew =
CreateProfileEngineL();
CleanupReleasePushL(*profileEngineNew);
MProfile* activeProfileNew =
profileEngineNew->ActiveProfileL();
const MProfileTones& activeProfileToneNew =
activeProfileNew->ProfileTones();
TFileName ringToneNew =
activeProfileToneNew.RingingTone1();
TBool ringToneChanged =
iCurrentRingTone.operator!=(ringToneNew);
if( ringToneChanged )
{
// Active profile ring tone changed
iCurrentRingTone = ringToneNew;
}
else
{
// Some other profile settings have changed
}
CleanupStack::PopAndDestroy(); // profileEngineNew
break;
}
default:
break;
}
}

