|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Calendar state machine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // includes |
|
21 #include "calenbackgroundstate.h" |
|
22 #include "calendarui_debug.h" // Debug macros |
|
23 #include "calencontroller.h" |
|
24 #include "calenstatemachine.h" |
|
25 #include "calennotifier.h" |
|
26 |
|
27 // ---------------------------------------------------------------------------- |
|
28 // CCalenBackgroundState::NewLC |
|
29 // First stage construction |
|
30 // ---------------------------------------------------------------------------- |
|
31 CCalenBackgroundState* CCalenBackgroundState::NewLC( CCalenController& aController, |
|
32 RHashSet<TCalenNotification>& aOutstandingNotifications ) |
|
33 { |
|
34 TRACE_ENTRY_POINT; |
|
35 |
|
36 CCalenBackgroundState* self = new ( ELeave ) CCalenBackgroundState( aController,aOutstandingNotifications ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 |
|
40 TRACE_EXIT_POINT; |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CCalenBackgroundState::ConstructL |
|
46 // Second stage construction |
|
47 // ---------------------------------------------------------------------------- |
|
48 void CCalenBackgroundState::ConstructL() |
|
49 { |
|
50 TRACE_ENTRY_POINT; |
|
51 BaseConstructL(); |
|
52 |
|
53 TRACE_EXIT_POINT; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // CCalenBackgroundState::CCalenBackgroundState |
|
58 // C++ Constructor |
|
59 // ---------------------------------------------------------------------------- |
|
60 CCalenBackgroundState::CCalenBackgroundState( CCalenController& aController, |
|
61 RHashSet<TCalenNotification>& aOutstandingNotifications ) |
|
62 : CCalenState( aController, aOutstandingNotifications ) |
|
63 { |
|
64 TRACE_ENTRY_POINT; |
|
65 |
|
66 TRACE_EXIT_POINT; |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CCalenBackgroundState::CCalenBackgroundState |
|
71 // Destructor |
|
72 // ---------------------------------------------------------------------------- |
|
73 CCalenBackgroundState::~CCalenBackgroundState() |
|
74 { |
|
75 TRACE_ENTRY_POINT; |
|
76 |
|
77 TRACE_EXIT_POINT; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CCalenBackgroundState::HandleCommandL |
|
82 // From CCalenState |
|
83 // ---------------------------------------------------------------------------- |
|
84 TBool CCalenBackgroundState::HandleCommandL( const TCalenCommand& aCommand, |
|
85 CCalenStateMachine& aStateMachine ) |
|
86 { |
|
87 TRACE_ENTRY_POINT; |
|
88 |
|
89 //When application is pushed background |
|
90 //1,when launched from active idle ,( AI screen or missed alarm softnotification/small indicator), |
|
91 // multiple entires -> Day view |
|
92 //2,when launched from active idle ( AI screen or missed alarm softnotification/small indicator), |
|
93 // single entry -> Event view |
|
94 |
|
95 TInt cmd = aCommand.Command(); |
|
96 MCalenCommandHandler* handler = iController.GetCommandHandlerL( cmd ); |
|
97 |
|
98 ASSERT( handler ); // FIXME: error ui |
|
99 |
|
100 TBool cmdUsed = EFalse; |
|
101 |
|
102 switch( cmd ) |
|
103 { |
|
104 case ECalenDayView: |
|
105 SetCurrentState(aStateMachine,CCalenStateMachine::ECalenIdleState); |
|
106 cmdUsed = ETrue; |
|
107 break; |
|
108 case ECalenEventView: |
|
109 SetCurrentState(aStateMachine,CCalenStateMachine::ECalenViewingState); |
|
110 cmdUsed = ETrue; |
|
111 break; |
|
112 case ECalenEventViewFromAlarm: |
|
113 case ECalenEventViewFromAlarmStopOnly: |
|
114 SetCurrentState(aStateMachine,CCalenStateMachine::ECalenAlarmState); |
|
115 cmdUsed = ETrue; |
|
116 break; |
|
117 case ECalenFasterAppExit: |
|
118 if(iPreviousState == CCalenStateMachine::ECalenMapState) |
|
119 { |
|
120 // Issue map launch cancel notification |
|
121 iController.BroadcastNotification(ECalenNotifyCancelMapLaunch); |
|
122 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState ); |
|
123 ActivateCurrentStateL(aStateMachine); |
|
124 cmdUsed = ETrue; |
|
125 break; |
|
126 } |
|
127 else if(iPreviousState == CCalenStateMachine::ECalenDeletingState) |
|
128 { |
|
129 // Issue ECalenNotifyDeleteFailed notification to cancel the delete |
|
130 iController.BroadcastNotification(ECalenNotifyDeleteFailed); |
|
131 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState ); |
|
132 ActivateCurrentStateL(aStateMachine); |
|
133 cmdUsed = ETrue; |
|
134 } |
|
135 else if( iPreviousState == CCalenStateMachine::ECalenSettingsState |
|
136 || iPreviousState == CCalenStateMachine::ECalenEditingState |
|
137 || iPreviousState == CCalenStateMachine::ECalenSendingState |
|
138 || iPreviousState == CCalenStateMachine::ECalenIdleState |
|
139 || iPreviousState == CCalenStateMachine::ECalenViewingState) |
|
140 { |
|
141 SetCurrentState( aStateMachine, CCalenStateMachine::ECalenIdleState ); |
|
142 ActivateCurrentStateL(aStateMachine); |
|
143 cmdUsed = ETrue; |
|
144 } |
|
145 default: |
|
146 break; |
|
147 } |
|
148 if(cmdUsed) |
|
149 RequestCallbackL( handler, aCommand ); |
|
150 |
|
151 TRACE_EXIT_POINT; |
|
152 return cmdUsed; |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CCalenBackgroundState::HandleNotificationL |
|
157 // From CCalenState |
|
158 // ---------------------------------------------------------------------------- |
|
159 void CCalenBackgroundState::HandleNotificationL(const TCalenNotification& aNotification, |
|
160 CCalenStateMachine& aStateMachine ) |
|
161 { |
|
162 TRACE_ENTRY_POINT; |
|
163 |
|
164 switch( aNotification ) |
|
165 { |
|
166 case ECalenNotifyAppForegrounded: |
|
167 { |
|
168 SetCurrentState( aStateMachine, iPreviousState ); |
|
169 // We set iOutstandingNotifications for two reasons. |
|
170 // 1. The new state i.e. the state we are moving back can have notification info. |
|
171 // 2. When we move to newstate we broadcast all notification from iOutstandingNotifications |
|
172 // and inform the registered notifiers. |
|
173 iOutstandingNotifications.InsertL(aNotification); |
|
174 ActivateCurrentStateL(aStateMachine); |
|
175 } |
|
176 break; |
|
177 case ECalenNotifyAppBackgrounded: |
|
178 // may receive more background notifications, just ignore |
|
179 break; |
|
180 default: |
|
181 // default is defer all other notifications when app in background |
|
182 // iOutstandingNotifications.InsertL(aNotification); |
|
183 iController.Notifier().BroadcastApprovedNotification( aNotification ); |
|
184 break; |
|
185 } |
|
186 |
|
187 TRACE_EXIT_POINT; |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // CCalenBackgroundState::HandleStateActivationL |
|
192 // Behavior when state is activated. |
|
193 // ---------------------------------------------------------------------------- |
|
194 void CCalenBackgroundState::HandleStateActivationL(CCalenStateMachine& aStateMachine) |
|
195 { |
|
196 TRACE_ENTRY_POINT; |
|
197 if(iOutstandingNotifications.Find(ECalenNotifyAppBackgrounded)) |
|
198 { |
|
199 CCalenState::HandleStateActivationL(aStateMachine); |
|
200 } |
|
201 |
|
202 TRACE_EXIT_POINT; |
|
203 } |
|
204 |
|
205 // end of file |