|
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 #include <avkon.hrh> |
|
19 #include <coemain.h> |
|
20 #include <aknappui.h> |
|
21 |
|
22 // includes |
|
23 #include "calendarui_debug.h" // Debug macros |
|
24 #include "calenstatemachine.h" |
|
25 #include "calenstate.h" |
|
26 #include "calenidlestate.h" |
|
27 #include "calenbackgroundstate.h" |
|
28 #include "calendeletingstate.h" |
|
29 #include "caleneditingstate.h" |
|
30 #include "calenexitingstate.h" |
|
31 #include "calenhelpstate.h" |
|
32 #include "calenpopulationstate.h" |
|
33 #include "calenprintingstate.h" |
|
34 #include "calensendingstate.h" |
|
35 #include "calensettingsstate.h" |
|
36 #include "calenviewingstate.h" |
|
37 #include "calenmapstate.h" |
|
38 #include "calenattachmentstate.h" |
|
39 #include "calenalarmstate.h" |
|
40 |
|
41 const TInt KHashLength = 64; |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CCalenStateMachine::NewL |
|
45 // Two phased constructor. |
|
46 // (other items were commented in a header). |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CCalenStateMachine* CCalenStateMachine::NewL( CCalenController& aController ) |
|
50 { |
|
51 TRACE_ENTRY_POINT; |
|
52 |
|
53 CCalenStateMachine* self = new ( ELeave ) CCalenStateMachine( aController ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL(); |
|
56 CleanupStack::Pop( self ); |
|
57 |
|
58 TRACE_EXIT_POINT; |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ---------------------------------------------------------------------------- |
|
63 // CCalenStateMachine::CCalenStateMachine |
|
64 // Constructor. |
|
65 // (other items were commented in a header). |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 CCalenStateMachine::CCalenStateMachine( CCalenController& aController ) |
|
69 : iController( aController ) , |
|
70 iOutstandingNotifications(&::HashCalenNotificationFunction,&::HashCalenNotificationIdentityRelation) |
|
71 { |
|
72 TRACE_ENTRY_POINT; |
|
73 TRACE_EXIT_POINT; |
|
74 } |
|
75 |
|
76 // ---------------------------------------------------------------------------- |
|
77 // CCalenStateMachine::ConstructL |
|
78 // Second phase of construction. |
|
79 // (other items were commented in a header). |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 void CCalenStateMachine::ConstructL() |
|
83 { |
|
84 TRACE_ENTRY_POINT; |
|
85 |
|
86 CCalenState* state = NULL; |
|
87 |
|
88 iOutstandingNotifications.ReserveL(KHashLength); |
|
89 state = CCalenIdleState::NewLC( iController, iOutstandingNotifications ); |
|
90 iStates.InsertL( state, ECalenIdleState ); |
|
91 CleanupStack::Pop( state ); |
|
92 |
|
93 state = CCalenPopulationState::NewLC( iController, iOutstandingNotifications); |
|
94 iStates.InsertL( state, ECalenPopulationState ); |
|
95 CleanupStack::Pop( state ); |
|
96 |
|
97 state = CCalenBackgroundState::NewLC( iController, iOutstandingNotifications ); |
|
98 iStates.InsertL( state, ECalenBackgroundState ); |
|
99 CleanupStack::Pop( state ); |
|
100 |
|
101 state = CCalenViewingState::NewLC( iController, iOutstandingNotifications ); |
|
102 iStates.InsertL( state, ECalenViewingState ); |
|
103 CleanupStack::Pop( state ); |
|
104 |
|
105 state = CCalenEditingState::NewLC( iController, iOutstandingNotifications ); |
|
106 iStates.InsertL( state, ECalenEditingState ); |
|
107 CleanupStack::Pop( state ); |
|
108 |
|
109 state = CCalenDeletingState::NewLC( iController, iOutstandingNotifications ); |
|
110 iStates.InsertL( state, ECalenDeletingState ); |
|
111 CleanupStack::Pop( state ); |
|
112 |
|
113 state = CCalenPrintingState::NewLC( iController, iOutstandingNotifications ); |
|
114 iStates.InsertL( state, ECalenPrintingState ); |
|
115 CleanupStack::Pop( state ); |
|
116 |
|
117 state = CCalenSendingState::NewLC( iController, iOutstandingNotifications ); |
|
118 iStates.InsertL( state, ECalenSendingState ); |
|
119 CleanupStack::Pop( state ); |
|
120 |
|
121 state = CCalenSettingsState::NewLC( iController, iOutstandingNotifications ); |
|
122 iStates.InsertL( state, ECalenSettingsState ); |
|
123 CleanupStack::Pop( state ); |
|
124 |
|
125 state = CCalenHelpState::NewLC( iController, iOutstandingNotifications ); |
|
126 iStates.InsertL( state, ECalenHelpState ); |
|
127 CleanupStack::Pop( state ); |
|
128 |
|
129 state = CCalenExitingState::NewLC( iController, iOutstandingNotifications ); |
|
130 iStates.InsertL( state, ECalenExitingState ); |
|
131 CleanupStack::Pop( state ); |
|
132 |
|
133 state = CCalenMapState::NewLC( iController, iOutstandingNotifications ); |
|
134 iStates.InsertL( state, ECalenMapState ); |
|
135 CleanupStack::Pop( state ); |
|
136 |
|
137 state = CCalenAttachmentState::NewLC( iController, iOutstandingNotifications ); |
|
138 iStates.InsertL( state, ECalenAttachmentState ); |
|
139 CleanupStack::Pop( state ); |
|
140 |
|
141 state = CCalenAlarmState::NewLC( iController, iOutstandingNotifications ); |
|
142 iStates.InsertL( state, ECalenAlarmState ); |
|
143 CleanupStack::Pop( state ); |
|
144 |
|
145 |
|
146 ASSERT( iStates.Count() == KCalenLastState ); |
|
147 |
|
148 TRACE_EXIT_POINT; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CCalenStateMachine::~CCalenStateMachine |
|
153 // Destructor. |
|
154 // (other items were commented in a header). |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 CCalenStateMachine::~CCalenStateMachine() |
|
158 { |
|
159 TRACE_ENTRY_POINT; |
|
160 |
|
161 iOutstandingNotifications.Close(); |
|
162 iStates.ResetAndDestroy(); |
|
163 |
|
164 TRACE_EXIT_POINT; |
|
165 } |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // CCalenStateMachine::HandleNotification |
|
169 // Notification handler interface. |
|
170 // (other items were commented in a header). |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 void CCalenStateMachine::HandleNotification(const TCalenNotification aNotification ) |
|
174 { |
|
175 TRACE_ENTRY_POINT; |
|
176 |
|
177 TRAPD(error,iStates[iCurrentState]->HandleNotificationL( aNotification, *this)); |
|
178 if(error!=KErrNone) |
|
179 { |
|
180 // do avoid warning |
|
181 } |
|
182 |
|
183 TRACE_EXIT_POINT; |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // CCalenStateMachine::HandleCommandL |
|
188 // Command handler interface. |
|
189 // (other items were commented in a header). |
|
190 // ---------------------------------------------------------------------------- |
|
191 // |
|
192 TBool CCalenStateMachine::HandleCommandL( const TCalenCommand& aCommand ) |
|
193 { |
|
194 TRACE_ENTRY_POINT; |
|
195 |
|
196 if( aCommand.Command() == EAknSoftkeyExit |
|
197 || aCommand.Command() == EAknCmdExit |
|
198 || aCommand.Command() == EEikCmdExit ) |
|
199 { |
|
200 iAvkonAppUi->Exit(); |
|
201 } |
|
202 |
|
203 TBool cmdUsed = iStates[iCurrentState]->HandleCommandL( aCommand, *this); |
|
204 |
|
205 TRACE_EXIT_POINT; |
|
206 return cmdUsed; |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // CCalenStateMachine::CancelPreviousCmd |
|
211 // Interface to cancel the previous command |
|
212 // (other items were commented in a header). |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 void CCalenStateMachine::CancelPreviousCmd() |
|
216 { |
|
217 TRACE_ENTRY_POINT; |
|
218 |
|
219 TCalenStateIndex previousState = iStates[iCurrentState]->PreviousState(); |
|
220 iStates[iCurrentState]->CancelExecutingCmd(); |
|
221 |
|
222 if(previousState != iCurrentState) |
|
223 { |
|
224 iCurrentState = previousState; |
|
225 } |
|
226 |
|
227 TRACE_EXIT_POINT; |
|
228 } |
|
229 |
|
230 // ---------------------------------------------------------------------------- |
|
231 // CCalenStateMachine::GetCurrentState |
|
232 // Interface to get the current state |
|
233 // (other items were commented in a header). |
|
234 // ---------------------------------------------------------------------------- |
|
235 // |
|
236 CCalenStateMachine::TCalenStateIndex CCalenStateMachine::GetCurrentState() |
|
237 { |
|
238 TRACE_ENTRY_POINT; |
|
239 TRACE_EXIT_POINT; |
|
240 |
|
241 return iCurrentState; |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CCalenStateMachine::SetCurrentState |
|
246 // Interface to set the current state |
|
247 // (other items were commented in a header). |
|
248 // ---------------------------------------------------------------------------- |
|
249 // |
|
250 void CCalenStateMachine::SetCurrentState(const TCalenStateIndex& aState) |
|
251 { |
|
252 TRACE_ENTRY_POINT; |
|
253 |
|
254 iCurrentState = aState; |
|
255 |
|
256 TRACE_EXIT_POINT; |
|
257 } |
|
258 |
|
259 // ---------------------------------------------------------------------------- |
|
260 // CCalenStateMachine::SetPreviousState |
|
261 // Interface to set previous state |
|
262 // (other items were commented in a header). |
|
263 // ---------------------------------------------------------------------------- |
|
264 // |
|
265 void CCalenStateMachine::SetCurrentPreviousState(const TCalenStateIndex& aState) |
|
266 { |
|
267 TRACE_ENTRY_POINT; |
|
268 |
|
269 iStates[iCurrentState]->SetPreviousState(aState); |
|
270 |
|
271 TRACE_EXIT_POINT; |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------------------------- |
|
275 // CCalenStateMachine::ActivateCurrentStateL |
|
276 // Interface to activate the current state |
|
277 // (other items were commented in a header). |
|
278 // ---------------------------------------------------------------------------- |
|
279 // |
|
280 void CCalenStateMachine::ActivateCurrentStateL() |
|
281 { |
|
282 TRACE_ENTRY_POINT; |
|
283 |
|
284 iStates[iCurrentState]->HandleStateActivationL(*this); |
|
285 |
|
286 TRACE_EXIT_POINT; |
|
287 } |
|
288 // End of file |