alarmui/src/alarmutils.cpp
branchRCL_3
changeset 65 12af337248b1
parent 30 d68a4b5d5885
child 66 bd7edf625bdd
--- a/alarmui/src/alarmutils.cpp	Thu Aug 19 09:53:43 2010 +0300
+++ b/alarmui/src/alarmutils.cpp	Tue Aug 31 15:13:43 2010 +0300
@@ -15,14 +15,10 @@
 *
 */
 
-
-
-// INCLUDE FILES
+// User includes.
 #include "alarmutils.h"
-
 #include "AlmAlertVariant.hrh"
 #include "pim_trace.h"
-
 #include "AlmAlarmPlayer.h"
 #include "AlmAlarmControl.h"
 #include "AlmAlarmInfo.h"
@@ -31,9 +27,10 @@
 #ifdef RD_ALMALERT__SENSOR_SUPPORT
 #include "alarmcontextfwsupport.h"
 #endif // RD_ALMALERT__SENSOR_SUPPORT
+#include "alarmalertwrapper.h"
 
-#include <w32std.h>
-#include <almconst.h>
+// System includes.
+// #include <almconst.h>
 #include <eikenv.h>
 #include <AknCapServer.h>
 #include <e32property.h>
@@ -44,40 +41,42 @@
 #include <ProfileEngineDomainConstants.h>
 #include <sbdefs.h>
 #include <coreapplicationuisdomainpskeys.h>
-#include <clockdomaincrkeys.h>
-#include <CalendarInternalCRKeys.h>
 #include <wakeupalarm.h>
 #include <calalarm.h> // KUidAgendaModelAlarmCategory - the alarm category id for calendar alarms
 #include <AknUtils.h>
-#include <hwrmpowerstatesdkpskeys.h>
-
 #ifndef SYMBIAN_CALENDAR_V2
 #include <agmalarm.h> // deprecated, use CalAlarm.h when SYMBIAN_CALENDAR_V2 flag is enabled
 #endif // SYMBIAN_CALENDAR_V2
 #include <calsession.h>
 #include <calentryview.h>
-#include <calenlauncher.h>  // for launching calendar entry view
-
+#include <clockdomaincrkeys.h>
+#include <calendardomaincrkeys.h>
 
-
-// CONSTANTS AND MACROS
+// Constants
 const TInt KAlmAlertMinSnooze( 100 );
 const TInt KAlmAlertMaxSnooze( 104 );
-
-const TInt KDefaultSnoozeTime( 5 ); // 5 minutes
+const TInt KDefaultSnoozeTime( 5 ); 
+const TUint KAlarmAutoHide( 60000000 );
+const TUint KAlarmAutoHideCalendar( 30000000 );
+const TUint KKeyBlockTime( 500000 );
+const TUint KShutdownTime( 1500000 );
+const TUint KAlarmDelayTime( 1000000 );
+const TUint KInactivityResetInterval( 1000000 );
+const TInt KMaxProfileVolume( 10 );
+const TInt KNoVolume(0);
+const TInt KVolumeRampPeriod( 3000000 );
+const TUid KAlarmClockOne = { 0x101F793A };
+const TUid KCRUidProfileEngine = {0x101F8798};
+//const TUint32 KProEngActiveReminderTone     = 0x7E00001C;
+const TUint32 KProEngActiveClockAlarmTone  = 0x7E00001D;
+//const TUint32 KProEngActiveAlertVibra           = 0x7E00001E;
+const TUint32 KProEngSilenceMode = {0x80000202};
+const TUint32 KProEngActiveRingingType = {0x7E000002};
+const TUint32 KProEngActiveRingingVolume = {0x7E000008};
 
-const TUint KAlarmAutoHide( 60000000 );  // 60 s
-const TUint KAlarmAutoHideCalendar( 30000000 );  // 30 s
-const TUint KKeyBlockTime( 500000 );  // 0.5 s
-const TUint KShutdownTime( 1500000 ); // 1.5 s
-const TUint KAlarmDelayTime( 1000000 ); // 1.0 s
-const TUint KInactivityResetInterval( 1000000 ); // 1.0 s
-
-const TInt KMaxProfileVolume( 10 );
-const TInt KVolumeRampPeriod( 3000000 );  // 3 seconds
+// Literals
 _LIT( KRngMimeType, "application/vnd.nokia.ringing-tone" );
 
-
 // ==========================================================
 // ================= MEMBER FUNCTIONS =======================
 
@@ -110,10 +109,11 @@
     iAlarmInfo = new( ELeave )CAlmAlarmInfo( this );
 
     // we can still work without profile engine
-    PIM_TRAPD_ASSERT( iProfileEng = CreateProfileEngineL(); )
+    // PIM_TRAPD_ASSERT( iProfileEng = CreateProfileEngineL(); )
 
-    iNotifierDialogController = ((CAknCapServer*)CEikonEnv::Static()->AppServer())->GlobalNoteControllerL();
-    iNotifierDialogController->SetNoteObserver( iAlarmControl );
+    // iNotifierDialogController = ((CAknCapServer*)CEikonEnv::Static()->AppServer())->GlobalNoteControllerL();
+    // iNotifierDialogController->SetNoteObserver( iAlarmControl );
+    iAlarmAlert = new AlarmAlert(iAlarmControl);
 
     // create timers
     iShutdownTimer   = CPeriodic::NewL( CActive::EPriorityStandard );
@@ -155,9 +155,14 @@
 CAlarmUtils::~CAlarmUtils()
     {
     TRACE_ENTRY_POINT;
-    if( iNotifierDialogController )
+    /*if( iNotifierDialogController )
         {
         iNotifierDialogController->SetNoteObserver( NULL );
+        }*/
+    if( iAlarmAlert )
+        {
+        delete iAlarmAlert;
+        iAlarmAlert = NULL;
         }
 
     if( iShutdownTimer )
@@ -255,7 +260,7 @@
     TRACE_ENTRY_POINT;
     StopAlarmSound();
     PIM_TRAPD_ASSERT( iAlarmPlayer = CAlmAlarmPlayer::NewL( this ); )
-    SetBackLight( ETrue );
+    //SetBackLight( ETrue );
     TRACE_EXIT_POINT;
     }
 
@@ -276,7 +281,7 @@
     #endif // RD_ALMALERT__SENSOR_SUPPORT
     delete iAlarmPlayer;
     iAlarmPlayer = NULL;
-    SetBackLight( EFalse );
+    //SetBackLight( EFalse );
     TRACE_EXIT_POINT;
     }
 
@@ -358,7 +363,7 @@
     TRACE_ENTRY_POINT;
     TBool isSilent( EFalse );
 
-    if( iProfileEng )
+    /*if( iProfileEng )
         {
         MProfile* profile = NULL;
         PIM_TRAPD_ASSERT( profile = iProfileEng->ActiveProfileL(); )
@@ -373,7 +378,7 @@
             profile->Release();
             }
         }
-    TRACE_EXIT_POINT;
+    TRACE_EXIT_POINT;*/
     return isSilent;
     }
 
@@ -411,33 +416,51 @@
 // -----------------------------------------------------------------------------
 //
 void CAlarmUtils::GetAlarmSoundFilenames()
-    {
-    TRACE_ENTRY_POINT;
-    CRepository* repository = NULL;
+{
+	TRACE_ENTRY_POINT;
+	CRepository* profileRepository = NULL;
+	CRepository* repository = NULL;
 
-    if( IsClockAlarm() )
-        {
-        PIM_TRAPD_ASSERT( repository = CRepository::NewL( KCRUidClockApp ); )
+	if( IsClockAlarm() )
+	{
+		PIM_TRAPD_ASSERT( repository = CRepository::NewL( TUid::Uid(KCRUidClockApp) ); ) 
+		PIM_TRAPD_ASSERT( profileRepository = CRepository::NewL( 
+														KCRUidProfileEngine ); )
 
-        if( repository )
-            {
-            PIM_ASSERT( repository->Get( KClockAppSoundFile, iAlarmData.iAlarmTone ); )
-            PIM_ASSERT( repository->Get( KClockAppDefaultSoundFile, iAlarmData.iDefaultAlarmTone ); )
-            }
-        }
-    else
-        {
-        PIM_TRAPD_ASSERT( repository = CRepository::NewL( KCRUidCalendar ); )
+		if( repository )
+		{
+			PIM_ASSERT( repository->Get( KClockAppDefaultSoundFile, 
+											iAlarmData.iDefaultAlarmTone ); )
+		}
+		if( profileRepository )
+		{
+			// TODO: Need to use KProEngActiveClockAlarmTone once its released
+			//PIM_ASSERT( profileRepository->Get( KProEngActiveClockAlarmTone , iAlarmData.iAlarmTone); )
+			PIM_ASSERT( repository->Get( KClockAppDefaultSoundFile, 
+													iAlarmData.iAlarmTone ); )
+		}
+	}
+	else
+	{
+		PIM_TRAPD_ASSERT( repository =
+				CRepository::NewL( TUid::Uid(KCRUidCalendar) ); )
+		PIM_TRAPD_ASSERT( profileRepository =
+				CRepository::NewL( KCRUidProfileEngine ); )
 
-        if( repository )
-            {
-            PIM_ASSERT( repository->Get( KCalendarSoundFile, iAlarmData.iAlarmTone ); )
-            PIM_ASSERT( repository->Get( KCalendarDefaultSoundFile, iAlarmData.iDefaultAlarmTone ); )
-            }
-        }
-    delete repository;
-    TRACE_EXIT_POINT;
-    }
+		if( repository )
+		{
+			PIM_ASSERT( repository->Get( KCalendarDefaultSoundFile, 
+											iAlarmData.iDefaultAlarmTone ); )
+		}
+		if( profileRepository )
+		{
+			PIM_ASSERT( profileRepository->Get( KProEngActiveClockAlarmTone, iAlarmData.iAlarmTone ); )
+		}
+	}
+	delete repository;
+	delete profileRepository;
+	TRACE_EXIT_POINT;
+}
 
 // -----------------------------------------------------------------------------
 // Check if the alarm sound file is a KRngMimeType file.
@@ -486,30 +509,38 @@
     iAlarmData.iVolumeRampTime = iAlarmData.iVolume * KVolumeRampPeriod; // volume ramp only for clock alarms
 
     if( !IsClockAlarm() )
-        {
-        if( iProfileEng )
-            {
-            MProfile* profile = NULL;
-            PIM_TRAPD_ASSERT( profile = iProfileEng->ActiveProfileL(); )
-
-            if( profile )
-                {
-                const TProfileToneSettings& setting = profile->ProfileTones().ToneSettings();
-                iAlarmData.iRingType = setting.iRingingType;
-
-                // calendar alarms: if profile is "silent" -> set volume to zero
-                iAlarmData.iVolume = (iAlarmData.iRingType == EProfileRingingTypeSilent ? 0 : setting.iRingingVolume);
-
-                profile->Release();
-                }
-            }
-
-        if( iAlarmData.iRingType == EProfileRingingTypeRingingOnce )
-            {
-            iAlarmData.iRepeatValue = 1;
-            }
-        iAlarmData.iVolumeRampTime = 0;
-        }
+    {
+        CRepository* repository = NULL;
+        PIM_TRAPD_ASSERT( repository = CRepository::NewL( KCRUidProfileEngine ); )
+    	
+    	TInt ringType;
+    	repository->Get( KProEngActiveRingingType , ringType);
+    	iAlarmData.iRingType = static_cast< TProfileRingingType >( ringType );
+    	
+    	TBool silentMode;
+    	TInt ringingVolume;
+    	repository->Get( KProEngSilenceMode, silentMode);
+    	if(silentMode)
+    	    {
+    	    ringingVolume = KNoVolume;
+    	    }
+    	else
+    	    {
+			// It seems the wrong key has been associated with calendar alarm tone
+			// settings. It would be changed once it's rectified by profile team.
+    	    repository->Get( KProEngActiveRingingVolume , ringingVolume );
+    	    }
+    	
+    	iAlarmData.iVolume = ringingVolume;
+    	
+    	iAlarmData.iVolumeRampTime = 0;
+    } else {
+    	TInt volumeOn = iAlarmData.iAlarm.ClientData2();
+    	if (!volumeOn) {
+    		iAlarmData.iRingType = EProfileRingingTypeSilent;
+    		iAlarmData.iVolume = KNoVolume;
+    	}
+    }
     TRACE_EXIT_POINT;
     }
 
@@ -623,7 +654,7 @@
         case EAlarmTypeClock:
             {
             CRepository* repository = NULL;
-            PIM_TRAPD_ASSERT( repository = CRepository::NewL( KCRUidClockApp ); )
+            PIM_TRAPD_ASSERT( repository = CRepository::NewL( TUid::Uid(KCRUidClockApp) ); )
 
             if( repository )
                 {
@@ -636,7 +667,8 @@
         case EAlarmTypeCalendar:
             {
             CRepository* repository = NULL;
-            PIM_TRAPD_ASSERT( repository = CRepository::NewL( KCRUidCalendar ); )
+            PIM_TRAPD_ASSERT( repository =
+            		CRepository::NewL( TUid::Uid(KCRUidCalendar) ); )
 
             if( repository )
                 {
@@ -730,11 +762,12 @@
 // 
 // -----------------------------------------------------------------------------
 //
-CNotifierDialogController* CAlarmUtils::NotifierDialogController()
+AlarmAlert* CAlarmUtils::NotifierDialogController()
     {
     TRACE_ENTRY_POINT;
     TRACE_EXIT_POINT;
-    return iNotifierDialogController;
+    // return iNotifierDialogController;
+    return iAlarmAlert;
     }
 
 // ---------------------------------------------------------
@@ -962,20 +995,12 @@
 void CAlarmUtils::DeviceShutdown()
     {
     TRACE_ENTRY_POINT;
-    
-    // charging state added for the err EMDN-835CW2.
-    TInt chargingState;
-    RProperty::Get( KPSUidHWRMPowerState, KHWRMChargingStatus , chargingState );
-    
-    if( IsDeviceInAlarmState() && ( chargingState != EChargingStatusCharging ) )
-        {       
-            iShutdownTimer->Cancel();
-            if( StarterConnect() )
-                {
-                iStarter.Shutdown();
-                iStarter.Close();
-                }    
-        }
+    iShutdownTimer->Cancel();
+    if( StarterConnect() )
+        {
+        iStarter.Shutdown();
+        iStarter.Close();
+        }    
     TRACE_EXIT_POINT;
     }
 
@@ -1123,7 +1148,7 @@
 void CAlarmUtils::StartAccessoryObserver()
     {
     TRACE_ENTRY_POINT;    
-    PIM_TRAPD_ASSERT( iRemConHandler->StartL(); )    
+    // PIM_TRAPD_ASSERT( iRemConHandler->StartL(); )    
     TRACE_EXIT_POINT;
     }
 
@@ -1256,10 +1281,10 @@
 // Callback function for the auto snooze timer
 // ---------------------------------------------------------
 //
-TInt CAlarmUtils::SnoozeInfoCallBack(TAny* aPtr)
+TInt CAlarmUtils::SnoozeInfoCallBack(TAny* /*aPtr*/)
     {
     TRACE_ENTRY_POINT;
-    PIM_TRAPD_ASSERT( static_cast<CAlmAlarmControl*>( aPtr )->ShowSnoozeInfoNoteL(); )
+    // PIM_TRAPD_ASSERT( static_cast<CAlmAlarmControl*>( aPtr )->ShowSnoozeInfoNoteL(); )
     TRACE_EXIT_POINT;
     return 0;
     }
@@ -1624,11 +1649,12 @@
     TRACE_ENTRY_POINT;
     
     iCalendarAlarmViewer = ETrue;
-    
+    /*
     CalenLauncher::ViewEntryL( iAlarmData.iLocalUid,
                                iAlarmData.iInstanceTime, iAlarmData.iCalFileName,
                                CanSnooze() ? CalenLauncher::EAlarmViewer : 
                                              CalenLauncher::EAlarmViewerNoSnooze );
+											 */
     TRACE_EXIT_POINT;
     }
 
@@ -1669,51 +1695,10 @@
     return iCalendarAlarmViewer;
     }
 
-// ---------------------------------------------------------
-// Silence the notifying alarm 
-// ---------------------------------------------------------
-//
-void CAlarmUtils::DoSilence()
+SAlarmInfo* CAlarmUtils::GetAlarmInfo()
     {
-    TRACE_ENTRY_POINT;
-    
-    // silence only if snoozing is possible
-    // this way user must hear the last "call"
-    if( CanSnooze() )
-        {
-        delete iAlarmPlayer;
-        iAlarmPlayer = NULL;
-        SetBackLight( EFalse );
-        
-        if( IsCalendarAlarm() )
-            {
-    
-            // calendar alarm needs extra handling due to having stop - silence
-            //simulate right softkey pressing
-            RWsSession wsSession=CCoeEnv::Static()->WsSession();
-            TKeyEvent keyEvent;
-            keyEvent.iCode = EKeyCBA2;  
-            keyEvent.iScanCode = EStdKeyDevice1;
-            keyEvent.iModifiers = 0;
-            keyEvent.iRepeats = 0;
-            wsSession.SimulateKeyEvent( keyEvent );
-            wsSession.Flush();
-            }
-        // clockalarm
-        else
-            {
-            StartAutoSnoozeTimer();
-            }
-    
-        #if defined( RD_ALMALERT__SENSOR_SUPPORT )
-        // notify the result through the context framework
-        if( iCFSupport )
-            {
-            PIM_TRAPD_ASSERT( iCFSupport->PublishAlarmResultL( EResultAlarmSilenced ); )
-            }
-        #endif // RD_ALMALERT__SENSOR_SUPPORT
-        }
-    TRACE_EXIT_POINT;     
+    return iAlarmInfo->GetAlarmInfo(iAlarmData.iAlarm,
+                                    iAlarmData.iAlarmType);
     }
 
 // End of File