|
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: Resolving meeting request method asynchronoysly |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "emailtrace.h" |
|
21 #include "cesmricalviewerresponsetomrcmd.h" |
|
22 #include "cesmruilauncher.h" |
|
23 #include "cesmricalvieweremailasynccmd.h" |
|
24 #include "cesmricalvieweremailsynccmd.h" |
|
25 #include "esmricalviewerutils.h" |
|
26 #include "cesmrattachmentinfo.h" |
|
27 |
|
28 //<cmail> |
|
29 #include "esmricalvieweropcodes.hrh" |
|
30 #include <calsession.h> |
|
31 #include "CFSMailClient.h" |
|
32 //</cmail> |
|
33 #include <calentry.h> |
|
34 |
|
35 #include "cesmrmrinfoicalretriever.h" |
|
36 #include "cesmrimapicalretriever.h" |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CESMRIcalViewerResponseToMRCmd::CESMRIcalViewerResponseToMRCmd |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CESMRIcalViewerResponseToMRCmd::CESMRIcalViewerResponseToMRCmd( |
|
45 MESMRIcalViewerCallback& aCallback, |
|
46 CCalSession& aCalSession, |
|
47 CFSMailClient& aMailClient, |
|
48 TESMRAttendeeStatus aAttendeeStatus ) |
|
49 : CESMRIcalViewerAsyncCommand( EESMRResponseToMR, aCalSession ), |
|
50 iCallback( aCallback ), |
|
51 iMailClient( aMailClient ), |
|
52 iAttendeeStatus( aAttendeeStatus ), |
|
53 iCurrentCbCommand( EESMREmailCommand ) |
|
54 { |
|
55 FUNC_LOG; |
|
56 //do nothing |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CESMRIcalViewerResponseToMRCmd::~CESMRIcalViewerResponseToMRCmd |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CESMRIcalViewerResponseToMRCmd::~CESMRIcalViewerResponseToMRCmd() |
|
64 { |
|
65 FUNC_LOG; |
|
66 CancelCommand(); |
|
67 delete iUILauncher; |
|
68 |
|
69 iMRRetrieverCommands.ResetAndDestroy(); |
|
70 iMRRetrieverCommands.Close(); |
|
71 delete iEmailCommand; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CESMRIcalViewerResponseToMRCmd::NewL |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CESMRIcalViewerResponseToMRCmd* CESMRIcalViewerResponseToMRCmd::NewL( |
|
79 MESMRIcalViewerCallback& aCallback, |
|
80 CCalSession& aCalSession, |
|
81 CFSMailClient& aMailClient, |
|
82 TESMRAttendeeStatus aAttendeeStatus ) |
|
83 { |
|
84 FUNC_LOG; |
|
85 CESMRIcalViewerResponseToMRCmd* self = |
|
86 new (ELeave) CESMRIcalViewerResponseToMRCmd( |
|
87 aCallback, |
|
88 aCalSession, |
|
89 aMailClient, |
|
90 aAttendeeStatus ); |
|
91 |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL(); |
|
94 CleanupStack::Pop( self ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CESMRIcalViewerResponseToMRCmd::ConstructL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CESMRIcalViewerResponseToMRCmd::ConstructL() |
|
103 { |
|
104 FUNC_LOG; |
|
105 BaseConstructL(); |
|
106 } |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CESMRIcalViewerResponseToMRCmd::OperationCompleted |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CESMRIcalViewerResponseToMRCmd::OperationCompleted( |
|
113 MESMRIcalViewerObserver::TIcalViewerOperationResult aResult ) |
|
114 { |
|
115 FUNC_LOG; |
|
116 TRAPD( err, HandleOperationCompletedL(aResult) ); |
|
117 if (KErrNone != err ) |
|
118 { |
|
119 aResult.iOpType = OperationType(); |
|
120 aResult.iResultCode = err; |
|
121 Observer()->OperationError( aResult ); |
|
122 } |
|
123 else if ( !iUILauncher && ((EESMREmailCommand == iCurrentCbCommand) || |
|
124 (iCurrentCbCommand == EESMRCmdMailDelete)) ) |
|
125 { |
|
126 aResult.iOpType = OperationType(); |
|
127 aResult.iAttendeeStatus = iAttendeeStatus; |
|
128 Observer()->OperationCompleted( aResult ); |
|
129 } |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CESMRIcalViewerResponseToMRCmd::LaunchUiL |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CESMRIcalViewerResponseToMRCmd::LaunchUiL() |
|
137 { |
|
138 FUNC_LOG; |
|
139 if ( !iUILauncher ) |
|
140 { |
|
141 iUILauncher = CESMRUiLauncher::NewL( |
|
142 CalSession(), |
|
143 iESMRInputParams, |
|
144 *this ); |
|
145 } |
|
146 |
|
147 iUILauncher->ExecuteCommandL( *Message(), *this ); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CESMRIcalViewerResponseToMRCmd::OperationError |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CESMRIcalViewerResponseToMRCmd::OperationError( |
|
155 MESMRIcalViewerObserver::TIcalViewerOperationResult aResult ) |
|
156 { |
|
157 FUNC_LOG; |
|
158 if ( aResult.iOpType == EESMRLoadMRInfoData ) |
|
159 { |
|
160 if ( aResult.iResultCode == KErrNotFound && iMRRetrieverCommands.Count() > iCurrentCommand + 1 ) |
|
161 { |
|
162 TRAPD( error, iMRRetrieverCommands[++iCurrentCommand]->ExecuteCommandL( |
|
163 *Message(), |
|
164 *this ) ); |
|
165 if ( error != KErrNone ) |
|
166 { |
|
167 aResult.iOpType = OperationType(); |
|
168 aResult.iResultCode = error; |
|
169 aResult.iMessage = Message(); |
|
170 Observer()->OperationError( aResult ); |
|
171 } |
|
172 } |
|
173 else |
|
174 { |
|
175 aResult.iOpType = OperationType(); |
|
176 aResult.iMessage = Message(); |
|
177 Observer()->OperationError( aResult ); |
|
178 } |
|
179 } |
|
180 else |
|
181 { |
|
182 aResult.iOpType = OperationType(); |
|
183 aResult.iMessage = Message(); |
|
184 aResult.iResultCode = KErrNotSupported; |
|
185 |
|
186 Observer()->OperationError( aResult ); |
|
187 } |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CESMRIcalViewerResponseToMRCmd::ExecuteAsyncCommandL |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CESMRIcalViewerResponseToMRCmd::ExecuteAsyncCommandL() |
|
195 { |
|
196 FUNC_LOG; |
|
197 CESMRInfoIcalRetrieverCmd* cmd = CESMRInfoIcalRetrieverCmd::NewL( |
|
198 CalSession(), |
|
199 iESMRInputParams ); |
|
200 |
|
201 CleanupStack::PushL( cmd ); |
|
202 User::LeaveIfError( |
|
203 iMRRetrieverCommands.Append( cmd ) ); |
|
204 CleanupStack::Pop( cmd ); cmd = NULL; |
|
205 |
|
206 CESMRImapIcalRetrieverCmd* cmd2 = |
|
207 CESMRImapIcalRetrieverCmd::NewL( |
|
208 CalSession(), |
|
209 iMailClient, |
|
210 iESMRInputParams ); |
|
211 |
|
212 CleanupStack::PushL( cmd2 ); |
|
213 User::LeaveIfError( |
|
214 iMRRetrieverCommands.Append( cmd2 ) ); |
|
215 CleanupStack::Pop( cmd2 ); cmd2 = NULL; |
|
216 |
|
217 iCurrentCommand = 0; |
|
218 |
|
219 if(iMRRetrieverCommands.Count() > iCurrentCommand) |
|
220 { |
|
221 iMRRetrieverCommands[iCurrentCommand]->ExecuteCommandL( |
|
222 *Message(), |
|
223 *this ); |
|
224 } |
|
225 else |
|
226 { |
|
227 User::Leave(KErrOverflow); |
|
228 } |
|
229 |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CESMRIcalViewerResolveMRMethodASyncCmd::CancelAsyncCommand |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CESMRIcalViewerResponseToMRCmd::CancelAsyncCommand() |
|
237 { |
|
238 FUNC_LOG; |
|
239 TInt commandCount( iMRRetrieverCommands.Count() ); |
|
240 |
|
241 for ( TInt i(0); i < commandCount; ++i ) |
|
242 { |
|
243 iMRRetrieverCommands[iCurrentCommand]->CancelCommand(); |
|
244 } |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CESMRIcalViewerResponseToMRCmd::ProcessCommandL |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CESMRIcalViewerResponseToMRCmd::ProcessCommandL(TInt aCommandId) |
|
252 { |
|
253 FUNC_LOG; |
|
254 ProcessCommandWithResultL( aCommandId ); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CESMRIcalViewerResponseToMRCmd::ProcessCommandWithResultL |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CESMRIcalViewerResponseToMRCmd::ProcessCommandWithResultL( TInt aCommandId ) |
|
262 { |
|
263 FUNC_LOG; |
|
264 TInt retValue( KErrNotSupported ); |
|
265 |
|
266 if ( IsCommandAvailable( aCommandId ) ) |
|
267 { |
|
268 iMRViewerCommand = aCommandId; |
|
269 |
|
270 iCurrentCbCommand = |
|
271 ESMRIcalViewerUtils::EmailOperation(aCommandId); |
|
272 |
|
273 TBool asyncCommand( |
|
274 ESMRIcalViewerUtils::IsAsyncEmailCommand( iCurrentCbCommand ) ); |
|
275 |
|
276 if ( asyncCommand ) |
|
277 { |
|
278 iEmailCommand = CESMRIcalViewerEmailAsyncCmd::NewL( |
|
279 iCurrentCbCommand, |
|
280 CalSession(), |
|
281 iCallback ); |
|
282 } |
|
283 else |
|
284 { |
|
285 iEmailCommand = CESMRIcalViewerEmailSyncCmd::NewL( |
|
286 iCurrentCbCommand, |
|
287 CalSession(), |
|
288 iCallback ); |
|
289 } |
|
290 |
|
291 iEmailCommand->ExecuteCommandL( *Message(), *this ); |
|
292 |
|
293 if ( !asyncCommand ) |
|
294 { |
|
295 // Email specific sync command has been executed. |
|
296 iCurrentCbCommand = EESMREmailCommand; |
|
297 } |
|
298 retValue = KErrNone; |
|
299 } |
|
300 |
|
301 return retValue; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CESMRIcalViewerResponseToMRCmd::IsCommandAvailable |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 TBool CESMRIcalViewerResponseToMRCmd::IsCommandAvailable( TInt aCommandId ) |
|
309 { |
|
310 FUNC_LOG; |
|
311 TESMRIcalViewerOperationType command( |
|
312 ESMRIcalViewerUtils::EmailOperation(aCommandId) ); |
|
313 |
|
314 return iCallback.CanProcessCommand( command ); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CESMRIcalViewerResponseToMRCmd::HandleOperationCompletedL |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void CESMRIcalViewerResponseToMRCmd::HandleOperationCompletedL( |
|
322 MESMRIcalViewerObserver::TIcalViewerOperationResult aResult ) |
|
323 { |
|
324 FUNC_LOG; |
|
325 if ( EESMRLaunchUI == aResult.iOpType ) |
|
326 { |
|
327 delete iUILauncher; |
|
328 iUILauncher = NULL; |
|
329 } |
|
330 |
|
331 if ( aResult.iOpType == EESMRLoadMRInfoData || |
|
332 aResult.iOpType == EESMRLoadMRIcalData || |
|
333 (aResult.iOpType == iCurrentCbCommand && |
|
334 aResult.iOpType != EESMRCmdMailDelete) ) // <cmail> |
|
335 { |
|
336 // MRINFO data was parsed succesfully |
|
337 CCalEntry::TMethod method( CCalEntry::EMethodNone ); |
|
338 method = iESMRInputParams.iCalEntry->MethodL(); |
|
339 |
|
340 if ( CCalEntry::EMethodRequest == method ) |
|
341 { |
|
342 iESMRInputParams.iMailClient = &iMailClient; |
|
343 iESMRInputParams.iMailMessage = Message(); |
|
344 iESMRInputParams.iCommand = EESMRCmdAcceptMR; |
|
345 iESMRInputParams.iSpare = 0; |
|
346 |
|
347 if ( EESMRAttendeeStatusTentative == iAttendeeStatus ) |
|
348 { |
|
349 iESMRInputParams.iCommand = EESMRCmdTentativeMR; |
|
350 } |
|
351 else if ( EESMRAttendeeStatusDecline == iAttendeeStatus ) |
|
352 { |
|
353 iESMRInputParams.iCommand = EESMRCmdDeclineMR; |
|
354 } |
|
355 if ( ESMRIcalViewerUtils::ContainsAttachments(iESMRInputParams) && |
|
356 iMRViewerCommand != iCurrentCbCommand && |
|
357 aResult.iOpType == iCurrentCbCommand ) |
|
358 { |
|
359 iCurrentCbCommand = EESMREmailCommand; |
|
360 iESMRInputParams.iCommand = |
|
361 ESMRIcalViewerUtils::MRResponseCommandWithoutAttachmentCheck( |
|
362 iMRViewerCommand); |
|
363 } |
|
364 LaunchUiL(); |
|
365 } |
|
366 |
|
367 if ( iCurrentCbCommand == EESMREmailCommand && |
|
368 method != CCalEntry::EMethodNone && |
|
369 !iUILauncher ) |
|
370 { |
|
371 // No email command in execution --> Notify observer |
|
372 aResult.iOpType = OperationType(); |
|
373 aResult.iAttendeeStatus = iAttendeeStatus; |
|
374 Observer()->OperationCompleted( aResult ); |
|
375 } |
|
376 } |
|
377 } |
|
378 |
|
379 // EOF |
|
380 |