|
1 /* |
|
2 * Copyright (c) 2007-2009 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: ESMR esmricalviewer implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "emailtrace.h" |
|
22 #include "cesmricalviewercmdhandler.h" |
|
23 #include "cesmricalvieweropenmrcmd.h" |
|
24 #include "cesmricalviewercanviewmr.h" |
|
25 #include "cesmricalviewerresolvemrmethodsync.h" |
|
26 #include "cesmricalviewerresolvemrmethodasync.h" |
|
27 #include "cesmricalviewerresponsetomrcmd.h" |
|
28 #include "cesmricalviewerremovemrfromcalcmd.h" |
|
29 |
|
30 #include <calsession.h> |
|
31 //<cmail> |
|
32 #include "cfsmailclient.h" |
|
33 #include "esmricalvieweropcodes.hrh" |
|
34 #include "esmricalviewerdefs.hrh" |
|
35 //</cmail> |
|
36 #include <eikenv.h> |
|
37 |
|
38 /// Unnamed namespace for local definitions |
|
39 namespace { |
|
40 |
|
41 // Panic literal |
|
42 _LIT( KESMRIcalViewerCmdHandler, "ESMRIcalViewerCmdHandler" ); |
|
43 |
|
44 enum TESMRIcalViewerCmdHandlerPanic |
|
45 { |
|
46 EInvalidCommand = 0, // Trying to execute invalid command |
|
47 EInvalidObserverCall |
|
48 }; |
|
49 |
|
50 void Panic( TESMRIcalViewerCmdHandlerPanic aPanic ) |
|
51 { |
|
52 User::Panic( KESMRIcalViewerCmdHandler, aPanic ); |
|
53 } |
|
54 |
|
55 } // namespace |
|
56 |
|
57 // ======== MEMBER FUNCTIONS ======== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CESMRIcalViewerCmdHandler::CESMRIcalViewerCmdHandler |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CESMRIcalViewerCmdHandler::CESMRIcalViewerCmdHandler( |
|
64 MESMRIcalViewerCallback& aCallback ) |
|
65 : iCallback( aCallback ) |
|
66 { |
|
67 FUNC_LOG; |
|
68 //do nothing |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CESMRIcalViewerCmdHandler::~CESMRIcalViewerCmdHandler |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CESMRIcalViewerCmdHandler::~CESMRIcalViewerCmdHandler() |
|
76 { |
|
77 FUNC_LOG; |
|
78 CancelOperation(); |
|
79 |
|
80 delete iCommand; |
|
81 delete iMessage; |
|
82 if ( iMailClient ) |
|
83 { |
|
84 iMailClient->Close(); |
|
85 } |
|
86 delete iCalSession; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CESMRIcalViewerCmdHandler::NewL |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CESMRIcalViewerCmdHandler* CESMRIcalViewerCmdHandler::NewL( |
|
94 MESMRIcalViewerCallback& aCallback ) |
|
95 { |
|
96 FUNC_LOG; |
|
97 CESMRIcalViewerCmdHandler* self = |
|
98 new (ELeave) CESMRIcalViewerCmdHandler( aCallback ); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL(); |
|
101 CleanupStack::Pop( self ); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CESMRIcalViewerCmdHandler::ConstructL |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CESMRIcalViewerCmdHandler::ConstructL() |
|
110 { |
|
111 FUNC_LOG; |
|
112 iCalSession = CCalSession::NewL(); |
|
113 iCalSession->OpenL( KNullDesC ); |
|
114 iMailClient = CFSMailClient::NewL(); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CESMRIcalViewerCmdHandler::ExecuteCommandL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CESMRIcalViewerCmdHandler::ExecuteCommandL( |
|
122 TESMRIcalViewerOperationType aOpType, |
|
123 MESMRIcalViewerObserver* aObserver, |
|
124 CFSMailMessage& aMessage ) |
|
125 { |
|
126 FUNC_LOG; |
|
127 ExecuteCommandL( aOpType, aObserver, aMessage, NULL ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CESMRIcalViewerCmdHandler::ExecuteCommandL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 void CESMRIcalViewerCmdHandler::ExecuteCommandL( |
|
135 TESMRIcalViewerOperationType aOpType, |
|
136 MESMRIcalViewerObserver* aObserver, |
|
137 CFSMailMessage& aMessage, |
|
138 TAny* aParam ) |
|
139 { |
|
140 FUNC_LOG; |
|
141 TRAPD( err, ExecuteCommandInternalL( aOpType, |
|
142 aObserver, |
|
143 aMessage, |
|
144 aParam ) ); |
|
145 |
|
146 if ( KErrNone != err && EIdle != iState ) |
|
147 { |
|
148 // Make sure that error is notified to caller in all cases |
|
149 if ( iObserver) |
|
150 { |
|
151 iResult.iMessage = &aMessage; |
|
152 iResult.iResultCode = err; |
|
153 iResult.iOpType = aOpType; |
|
154 iObserver->OperationError( iResult ); |
|
155 } |
|
156 iState = EIdle; |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CESMRIcalViewerCmdHandler::CancelOperation |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CESMRIcalViewerCmdHandler::CancelOperation() |
|
165 { |
|
166 FUNC_LOG; |
|
167 if ( iCommand ) |
|
168 { |
|
169 iCommand->CancelCommand(); |
|
170 } |
|
171 |
|
172 iState = EIdle; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CESMRIcalViewerCmdHandler::OperationCompleted |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CESMRIcalViewerCmdHandler::OperationCompleted( |
|
180 TIcalViewerOperationResult aResult ) |
|
181 { |
|
182 FUNC_LOG; |
|
183 __ASSERT_DEBUG( iCommand, Panic(EInvalidObserverCall) ); |
|
184 __ASSERT_DEBUG( |
|
185 iCommand->OperationType() == aResult.iOpType, |
|
186 Panic(EInvalidObserverCall) ); |
|
187 |
|
188 if ( iObserver ) |
|
189 { |
|
190 aResult.iOpType = iCommand->OperationType(); |
|
191 iObserver->OperationCompleted( aResult ); |
|
192 } |
|
193 |
|
194 iState = EIdle; |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CESMRIcalViewerCmdHandler::OperationError |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CESMRIcalViewerCmdHandler::OperationError( |
|
202 TIcalViewerOperationResult aResult ) |
|
203 { |
|
204 FUNC_LOG; |
|
205 __ASSERT_DEBUG( iCommand, Panic(EInvalidObserverCall) ); |
|
206 __ASSERT_DEBUG( |
|
207 iCommand->OperationType() == aResult.iOpType, |
|
208 Panic(EInvalidObserverCall) ); |
|
209 |
|
210 if ( iObserver ) |
|
211 { |
|
212 aResult.iOpType = iCommand->OperationType(); |
|
213 iObserver->OperationError( aResult ); |
|
214 } |
|
215 |
|
216 iState = EIdle; |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CESMRIcalViewerCmdHandler::ExecuteCommandInternalL |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CESMRIcalViewerCmdHandler::ExecuteCommandInternalL( |
|
224 TESMRIcalViewerOperationType aOpType, |
|
225 MESMRIcalViewerObserver* aObserver, |
|
226 CFSMailMessage& aMessage, |
|
227 TAny* aParam ) |
|
228 { |
|
229 FUNC_LOG; |
|
230 if ( EExecuting == iState ) |
|
231 { |
|
232 User::Leave( KErrInUse ); |
|
233 } |
|
234 |
|
235 delete iCommand; iCommand = NULL; |
|
236 |
|
237 iState = EExecuting; |
|
238 iObserver = aObserver; |
|
239 |
|
240 // Get own copy of the message before executing commands |
|
241 delete iMessage; iMessage = NULL; |
|
242 iMessage = iMailClient->GetMessageByUidL( |
|
243 aMessage.GetMailBoxId(), |
|
244 aMessage.GetFolderId(), |
|
245 aMessage.GetMessageId(), |
|
246 EFSMsgDataStructure ); |
|
247 |
|
248 switch ( aOpType ) |
|
249 { |
|
250 case EESMRViewLaunch: |
|
251 { |
|
252 iCommand = CESMRIcalViewerOpenMRCmd:: NewL( |
|
253 iCallback, |
|
254 *iMailClient, |
|
255 *iCalSession ); |
|
256 } |
|
257 break; |
|
258 |
|
259 case EESMRCanViewMR: |
|
260 { |
|
261 TBool* flag = static_cast<TBool*>( aParam ); |
|
262 iCommand = CESMRIcalViewerCanViewMsgCmd:: NewL( |
|
263 *iCalSession, |
|
264 *flag ); |
|
265 } |
|
266 break; |
|
267 |
|
268 case EESMRResolveMRMethod: |
|
269 { |
|
270 iCommand = CESMRIcalViewerResolveMRMethodASyncCmd::NewL( |
|
271 *iCalSession, |
|
272 *iMailClient ); |
|
273 } |
|
274 break; |
|
275 |
|
276 case EESMRResolveMRMethodSync: |
|
277 { |
|
278 TESMRMeetingRequestMethod* mrMethod = |
|
279 static_cast<TESMRMeetingRequestMethod*>( aParam ); |
|
280 |
|
281 iCommand = CESMRIcalViewerResolveMRMethodSyncCmd::NewL( |
|
282 *iCalSession, |
|
283 *iMailClient, |
|
284 *mrMethod ); |
|
285 } |
|
286 break; |
|
287 |
|
288 case EESMRResponseToMR: |
|
289 { |
|
290 TESMRAttendeeStatus* attendeeStatus = |
|
291 static_cast<TESMRAttendeeStatus*>( aParam ); |
|
292 |
|
293 iCommand = CESMRIcalViewerResponseToMRCmd::NewL( |
|
294 iCallback, |
|
295 *iCalSession, |
|
296 *iMailClient, |
|
297 *attendeeStatus); |
|
298 |
|
299 } |
|
300 break; |
|
301 |
|
302 case EESMRRemoveMR: |
|
303 { |
|
304 iCommand = CESMRIcalViewerRemoveMRFromCalCmd::NewL( |
|
305 *iCalSession, |
|
306 *iMailClient ); |
|
307 } |
|
308 break; |
|
309 |
|
310 default: |
|
311 break; |
|
312 } |
|
313 |
|
314 __ASSERT_ALWAYS( iCommand, Panic( EInvalidCommand) ); |
|
315 iCommand->ExecuteCommandL( *iMessage, *this ); |
|
316 } |
|
317 |
|
318 // EOF |
|
319 |