calendarui/controller/src/calenbackgroundstate.cpp
branchRCL_3
changeset 66 bd7edf625bdd
parent 65 12af337248b1
child 74 97232defd20e
equal deleted inserted replaced
65:12af337248b1 66:bd7edf625bdd
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Calendar state machine
    14 * Description:   Calendar state machine
    15 *
    15 *
    16 */
    16 */
       
    17 
    17 
    18 
    18 
    19 
    19 // includes
    20 // includes
    20 #include "calenbackgroundstate.h"
    21 #include "calenbackgroundstate.h"
    21 #include "calendarui_debug.h"           // Debug macros
    22 #include "calendarui_debug.h"           // Debug macros
    22 #include "calencontroller.h"
    23 #include "calencontroller.h"
    23 #include "calenstatemachine.h"
    24 #include "calenstatemachine.h"
    24 #include "calennotifier.h"
    25 #include "calennotifier.h"
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "calenbackgroundstateTraces.h"
       
    28 #endif
       
    29 
    26 
    30 // ----------------------------------------------------------------------------
    27 // ----------------------------------------------------------------------------
    31 // CCalenBackgroundState::NewLC
    28 // CCalenBackgroundState::NewLC
    32 // First stage construction
    29 // First stage construction
    33 // ----------------------------------------------------------------------------
    30 // ----------------------------------------------------------------------------
    34 CCalenBackgroundState* CCalenBackgroundState::NewLC( CCalenController& aController,
    31 CCalenBackgroundState* CCalenBackgroundState::NewLC( CCalenController& aController,
    35                                                             RHashSet<TCalenNotification>&  aOutstandingNotifications )
    32                                                             RHashSet<TCalenNotification>&  aOutstandingNotifications )
    36     {
    33     {
    37     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_NEWLC_ENTRY );
    34     TRACE_ENTRY_POINT;
    38     
    35 
    39     CCalenBackgroundState* self = new ( ELeave ) CCalenBackgroundState( aController,aOutstandingNotifications );
    36     CCalenBackgroundState* self = new ( ELeave ) CCalenBackgroundState( aController,aOutstandingNotifications );
    40     CleanupStack::PushL( self );
    37     CleanupStack::PushL( self );
    41     self->ConstructL();
    38     self->ConstructL();
    42 
    39 
    43     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_NEWLC_EXIT );
    40     TRACE_EXIT_POINT;
    44     return self;
    41     return self;
    45     }
    42     }
    46 
    43 
    47 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    48 // CCalenBackgroundState::ConstructL
    45 // CCalenBackgroundState::ConstructL
    49 // Second stage construction
    46 // Second stage construction
    50 // ----------------------------------------------------------------------------
    47 // ----------------------------------------------------------------------------
    51 void CCalenBackgroundState::ConstructL()
    48 void CCalenBackgroundState::ConstructL()
    52     {
    49     {
    53     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_CONSTRUCTL_ENTRY );
    50     TRACE_ENTRY_POINT;
    54     
       
    55     BaseConstructL();
    51     BaseConstructL();
    56     
    52     
    57     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_CONSTRUCTL_EXIT );
    53     TRACE_EXIT_POINT;
    58     }
    54     }
    59     
    55     
    60 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    61 // CCalenBackgroundState::CCalenBackgroundState
    57 // CCalenBackgroundState::CCalenBackgroundState
    62 // C++ Constructor
    58 // C++ Constructor
    63 // ----------------------------------------------------------------------------
    59 // ----------------------------------------------------------------------------
    64 CCalenBackgroundState::CCalenBackgroundState( CCalenController& aController, 
    60 CCalenBackgroundState::CCalenBackgroundState( CCalenController& aController, 
    65                                                                 RHashSet<TCalenNotification>&  aOutstandingNotifications )
    61                                                                 RHashSet<TCalenNotification>&  aOutstandingNotifications )
    66     : CCalenState( aController, aOutstandingNotifications )
    62     : CCalenState( aController, aOutstandingNotifications )
    67     {
    63     {
    68     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_CCALENBACKGROUNDSTATE_ENTRY );
    64     TRACE_ENTRY_POINT;
    69     
    65     
    70     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_CCALENBACKGROUNDSTATE_EXIT );
    66     TRACE_EXIT_POINT;
    71     }
    67     }
    72     
    68     
    73 // ----------------------------------------------------------------------------
    69 // ----------------------------------------------------------------------------
    74 // CCalenBackgroundState::CCalenBackgroundState
    70 // CCalenBackgroundState::CCalenBackgroundState
    75 // Destructor
    71 // Destructor
    76 // ----------------------------------------------------------------------------    
    72 // ----------------------------------------------------------------------------    
    77 CCalenBackgroundState::~CCalenBackgroundState()
    73 CCalenBackgroundState::~CCalenBackgroundState()
    78     {
    74     {
    79     OstTraceFunctionEntry0( DUP1_CCALENBACKGROUNDSTATE_CCALENBACKGROUNDSTATE_ENTRY );
    75     TRACE_ENTRY_POINT;
    80     
    76     
    81     OstTraceFunctionExit0( DUP1_CCALENBACKGROUNDSTATE_CCALENBACKGROUNDSTATE_EXIT );
    77     TRACE_EXIT_POINT;
    82     }
    78     }
    83 
    79 
    84 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    85 // CCalenBackgroundState::HandleCommandL
    81 // CCalenBackgroundState::HandleCommandL
    86 // From CCalenState
    82 // From CCalenState
    87 // ----------------------------------------------------------------------------    
    83 // ----------------------------------------------------------------------------    
    88 TBool CCalenBackgroundState::HandleCommandL( const TCalenCommand& aCommand,
    84 TBool CCalenBackgroundState::HandleCommandL( const TCalenCommand& aCommand,
    89                                            CCalenStateMachine& aStateMachine )
    85                                            CCalenStateMachine& aStateMachine )
    90     {
    86     {
    91     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_HANDLECOMMANDL_ENTRY );
    87     TRACE_ENTRY_POINT;  
    92       
       
    93     
    88     
    94     //When application is pushed background
    89     //When application is pushed background
    95     //1,when launched from active idle ,( AI screen or missed alarm softnotification/small indicator),
    90     //1,when launched from active idle ,( AI screen or missed alarm softnotification/small indicator),
    96     //  multiple entires -> Day view
    91     //  multiple entires -> Day view
    97     //2,when launched from active idle ( AI screen or missed alarm softnotification/small indicator),
    92     //2,when launched from active idle ( AI screen or missed alarm softnotification/small indicator),
   104     
    99     
   105     TBool cmdUsed = EFalse;
   100     TBool cmdUsed = EFalse;
   106 
   101 
   107     switch( cmd )
   102     switch( cmd )
   108         {
   103         {
   109         case ECalenAgendaView:
       
   110         case ECalenDayView:
   104         case ECalenDayView:
       
   105         case ECalenTodoView:
       
   106         case ECalenMonthView:
       
   107         case ECalenWeekView:
   111             SetCurrentState(aStateMachine,CCalenStateMachine::ECalenIdleState);
   108             SetCurrentState(aStateMachine,CCalenStateMachine::ECalenIdleState);
   112             cmdUsed = ETrue;
   109             cmdUsed = ETrue;
   113             break;
   110             break;
   114         case ECalenEventView:
   111         case ECalenEventView:
   115             SetCurrentState(aStateMachine,CCalenStateMachine::ECalenViewingState);
   112             SetCurrentState(aStateMachine,CCalenStateMachine::ECalenViewingState);
   116             cmdUsed = ETrue;
   113             cmdUsed = ETrue;
   117             break;
   114             break;
   118         case ECalenFasterAppExit:        	
   115         case ECalenEventViewFromAlarm:
   119 			if(iPreviousState == CCalenStateMachine::ECalenDeletingState)
   116         case ECalenEventViewFromAlarmStopOnly:
       
   117             SetCurrentState(aStateMachine,CCalenStateMachine::ECalenAlarmState);
       
   118             cmdUsed = ETrue;
       
   119             break;
       
   120         case ECalenFasterAppExit:
       
   121         	if(iPreviousState == CCalenStateMachine::ECalenMapState)
       
   122 				{
       
   123 				// Issue map launch cancel notification
       
   124 				iController.BroadcastNotification(ECalenNotifyCancelMapLaunch);
       
   125 		        SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
       
   126 		        ActivateCurrentStateL(aStateMachine);
       
   127 		        cmdUsed = ETrue;
       
   128 		        break;
       
   129 		   		}
       
   130         	else if(iPreviousState == CCalenStateMachine::ECalenDeletingState)
   120         	    {
   131         	    {
   121                 // Issue ECalenNotifyDeleteFailed notification to cancel the delete
   132                 // Issue ECalenNotifyDeleteFailed notification to cancel the delete
   122                 iController.BroadcastNotification(ECalenNotifyDeleteFailed);
   133                 iController.BroadcastNotification(ECalenNotifyDeleteFailed);
   123                 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
   134                 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
   124                 ActivateCurrentStateL(aStateMachine);
   135                 ActivateCurrentStateL(aStateMachine);
   125                 cmdUsed = ETrue;                 
   136                 cmdUsed = ETrue;                 
   126         	    }
   137         	    }
   127         	else
   138         	else if( iPreviousState == CCalenStateMachine::ECalenSettingsState
   128 				{
       
   129 				if( iPreviousState == CCalenStateMachine::ECalenSettingsState
       
   130         	       || iPreviousState == CCalenStateMachine::ECalenEditingState
   139         	       || iPreviousState == CCalenStateMachine::ECalenEditingState
   131         	       || iPreviousState == CCalenStateMachine::ECalenSendingState )
   140         	       || iPreviousState == CCalenStateMachine::ECalenSendingState 
   132 	        	    {
   141         	       || iPreviousState == CCalenStateMachine::ECalenIdleState 
   133 	                SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
   142                    || iPreviousState == CCalenStateMachine::ECalenViewingState
   134 	                ActivateCurrentStateL(aStateMachine);
   143                    || iPreviousState == CCalenStateMachine::ECalenAttachmentState)
   135 	                cmdUsed = ETrue;                 
   144         	    {
   136 	        	    }
   145                 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
   137 				}
   146                 ActivateCurrentStateL(aStateMachine);
       
   147                 cmdUsed = ETrue;                 
       
   148         	    }
   138         default:
   149         default:
   139             break;
   150             break;
   140         }
   151         }
   141     
   152     if(cmdUsed)
   142     RequestCallbackL( handler, aCommand );
   153     RequestCallbackL( handler, aCommand );
   143     
   154     
   144     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_HANDLECOMMANDL_EXIT );
   155     TRACE_EXIT_POINT;
   145     return cmdUsed;
   156     return cmdUsed;
   146     }
   157     }
   147 
   158 
   148 // ----------------------------------------------------------------------------
   159 // ----------------------------------------------------------------------------
   149 // CCalenBackgroundState::HandleNotificationL
   160 // CCalenBackgroundState::HandleNotificationL
   150 // From CCalenState
   161 // From CCalenState
   151 // ----------------------------------------------------------------------------        
   162 // ----------------------------------------------------------------------------        
   152 void CCalenBackgroundState::HandleNotificationL(const TCalenNotification& aNotification,
   163 void CCalenBackgroundState::HandleNotificationL(const TCalenNotification& aNotification,
   153                                                  CCalenStateMachine& aStateMachine )
   164                                                  CCalenStateMachine& aStateMachine )
   154     {
   165     {
   155     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_HANDLENOTIFICATIONL_ENTRY );
   166     TRACE_ENTRY_POINT;
   156     
   167     
   157     switch( aNotification )
   168     switch( aNotification )
   158         {
   169         {
   159         case ECalenNotifyAppForegrounded:
   170         case ECalenNotifyAppForegrounded:
   160         	{
   171         	{
   161         	SetCurrentState( aStateMachine, iPreviousState );
   172         	if( iPreviousState == CCalenStateMachine::ECalenSendingState )
       
   173         	    {
       
   174         	    SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState );
       
   175         	    }
       
   176         	else
       
   177         	    {
       
   178                 SetCurrentState( aStateMachine, iPreviousState );
       
   179         	    }
   162         	// We set iOutstandingNotifications for two reasons.
   180         	// We set iOutstandingNotifications for two reasons.
   163         	// 1. The new state i.e. the state we are moving back can have notification info.
   181         	// 1. The new state i.e. the state we are moving back can have notification info.
   164         	// 2. When we move to newstate we broadcast all notification from iOutstandingNotifications
   182         	// 2. When we move to newstate we broadcast all notification from iOutstandingNotifications
   165         	//     and inform the registered notifiers.
   183         	//     and inform the registered notifiers.
   166         	iOutstandingNotifications.InsertL(aNotification);
   184         	iOutstandingNotifications.InsertL(aNotification);
   175             // iOutstandingNotifications.InsertL(aNotification);
   193             // iOutstandingNotifications.InsertL(aNotification);
   176             iController.Notifier().BroadcastApprovedNotification( aNotification );
   194             iController.Notifier().BroadcastApprovedNotification( aNotification );
   177             break;
   195             break;
   178         }
   196         }
   179     
   197     
   180     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_HANDLENOTIFICATIONL_EXIT );
   198     TRACE_EXIT_POINT;
   181     }
   199     }
   182 
   200 
   183 // ----------------------------------------------------------------------------
   201 // ----------------------------------------------------------------------------
   184 // CCalenBackgroundState::HandleStateActivationL
   202 // CCalenBackgroundState::HandleStateActivationL
   185 // Behavior when state is activated.
   203 // Behavior when state is activated.
   186 // ----------------------------------------------------------------------------
   204 // ----------------------------------------------------------------------------
   187 void CCalenBackgroundState::HandleStateActivationL(CCalenStateMachine& aStateMachine)
   205 void CCalenBackgroundState::HandleStateActivationL(CCalenStateMachine& aStateMachine)
   188     {
   206     {
   189     OstTraceFunctionEntry0( CCALENBACKGROUNDSTATE_HANDLESTATEACTIVATIONL_ENTRY );
   207     TRACE_ENTRY_POINT;
   190     
       
   191     if(iOutstandingNotifications.Find(ECalenNotifyAppBackgrounded))
   208     if(iOutstandingNotifications.Find(ECalenNotifyAppBackgrounded))
   192         {
   209         {
   193         CCalenState::HandleStateActivationL(aStateMachine);
   210         CCalenState::HandleStateActivationL(aStateMachine);
   194         }
   211         }
   195     
   212     
   196     OstTraceFunctionExit0( CCALENBACKGROUNDSTATE_HANDLESTATEACTIVATIONL_EXIT );
   213     TRACE_EXIT_POINT;
   197     }
   214     }
   198 
   215 
   199  // end of file
   216  // end of file