|
1 /* |
|
2 * Copyright (c) 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: MR attahcment field implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cmrattachmentcommandhandler.h" |
|
19 #include "cmropenattachmentcommand.h" |
|
20 #include "cmrremoveattachmentcommand.h" |
|
21 #include "cmrsaveattachmentcommand.h" |
|
22 #include "cmrsaveandopenattachmentcommand.h" |
|
23 #include "cesmrrichtextlink.h" |
|
24 #include "mcalremoteattachmentinfo.h" |
|
25 #include "mcalremoteattachment.h" |
|
26 #include "mcalremoteattachmentoperation.h" |
|
27 #include "ccalremoteattachmentinfo.h" |
|
28 #include "ccalremoteattachmentapi.h" |
|
29 #include "cesmrgenericfieldevent.h" |
|
30 #include "cesmrfieldcommandevent.h" |
|
31 #include "mesmrfieldeventqueue.h" |
|
32 #include "esmrdef.h" |
|
33 |
|
34 #include <esmrgui.rsg> |
|
35 #include <calentry.h> |
|
36 #include <calattachment.h> |
|
37 #include <f32file.h> |
|
38 #include <apgcli.h> |
|
39 #include <DocumentHandler.h> |
|
40 #include <StringLoader.h> |
|
41 #include <AknGlobalNote.h> |
|
42 |
|
43 // DEBUG |
|
44 #include "emailtrace.h" |
|
45 |
|
46 |
|
47 // unnamed namespace for local definitions |
|
48 namespace { // codescanner::namespace |
|
49 |
|
50 _LIT8( KUnknownDatatype, "unknown"); |
|
51 |
|
52 #if defined(_DEBUG) |
|
53 |
|
54 // Panic literal |
|
55 _LIT( KMRAttachmentCommandHandler, "MRAttachmentCommandHandler" ); |
|
56 |
|
57 /** |
|
58 * Panic codes |
|
59 */ |
|
60 enum TMRAttachmentCommandHandlerPanic |
|
61 { |
|
62 // Invalid command |
|
63 EMRAttachmentCommandHandlerInvalidCommand, |
|
64 // Attachment is not found |
|
65 EMRAttachmentCommandHandlerAttachmentNotFound, |
|
66 // Remote attachment information not set |
|
67 EMRAttachmentCommandHandlerRemoteInfoNotSet, |
|
68 // Remote command cannot be found |
|
69 EMRAttachmentCommandHandlerRemoteCommandNotFound, |
|
70 // Remote attachment is not found |
|
71 EMRAttachmentCommandHandlerRemoteAttachmentNotFound |
|
72 }; |
|
73 |
|
74 void Panic( TMRAttachmentCommandHandlerPanic aPanic ) |
|
75 { |
|
76 User::Panic( KMRAttachmentCommandHandler, aPanic ); |
|
77 } |
|
78 |
|
79 #endif // _DEBUG |
|
80 |
|
81 /** |
|
82 * Shows information note when one attachment is saved. |
|
83 */ |
|
84 void ShowInfoNoteL() |
|
85 { |
|
86 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
87 HBufC* text = |
|
88 StringLoader::LoadLC( R_MEET_REQ_INFO_NOTE_ONE_ATTACHMENT_SAVED ); |
|
89 note->ShowNoteL( |
|
90 EAknGlobalInformationNote, |
|
91 *text ); |
|
92 CleanupStack::PopAndDestroy( 2, note ); |
|
93 } |
|
94 |
|
95 /** |
|
96 * Shows information note when multiple attachments have been saved. |
|
97 */ |
|
98 void ShowInfoNoteL( TInt aAttachmentCount ) |
|
99 { |
|
100 CAknGlobalNote* note = CAknGlobalNote::NewLC(); |
|
101 HBufC* text = StringLoader::LoadLC( |
|
102 R_MEET_REQ_INFO_NOTE_MULTIPLE_ATTACHMENTS_SAVED, |
|
103 aAttachmentCount ); |
|
104 note->ShowNoteL( |
|
105 EAknGlobalInformationNote, |
|
106 *text ); |
|
107 CleanupStack::PopAndDestroy( 2, note ); |
|
108 } |
|
109 |
|
110 } // namespace |
|
111 |
|
112 // ======== MEMBER FUNCTIONS ======== |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CMRAttachmentCommandHandler::CMRAttachmentCommandHandler |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 CMRAttachmentCommandHandler::CMRAttachmentCommandHandler( |
|
119 CCalEntry& aEntry, |
|
120 MESMRFieldEventQueue& aEventQueue) : |
|
121 iEntry( aEntry ), |
|
122 iEventQueue( aEventQueue ) |
|
123 { |
|
124 FUNC_LOG; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // CMRAttachmentCommandHandler::~CMRAttachmentCommandHandler |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 CMRAttachmentCommandHandler::~CMRAttachmentCommandHandler() |
|
132 { |
|
133 FUNC_LOG; |
|
134 |
|
135 iDownloadOperations.ResetAndDestroy(); |
|
136 delete iDocHandler; |
|
137 } |
|
138 |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CMRAttachmentCommandHandler::NewL |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 CMRAttachmentCommandHandler* CMRAttachmentCommandHandler::NewL( |
|
145 CCalEntry& aEntry, |
|
146 MESMRFieldEventQueue& aEventQueue ) |
|
147 { |
|
148 FUNC_LOG; |
|
149 |
|
150 CMRAttachmentCommandHandler* self = |
|
151 new (ELeave) CMRAttachmentCommandHandler( aEntry, aEventQueue ); |
|
152 CleanupStack::PushL( self ); |
|
153 self->ConstructL(); |
|
154 CleanupStack::Pop( self ); |
|
155 return self; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CMRAttachmentCommandHandler::ConstructL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CMRAttachmentCommandHandler::ConstructL() |
|
163 { |
|
164 FUNC_LOG; |
|
165 |
|
166 iDocHandler = CDocumentHandler::NewL(); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CMRAttachmentCommandHandler::HandleAttachmentCommandL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CMRAttachmentCommandHandler::HandleAttachmentCommandL( |
|
174 TInt aCommandId, |
|
175 const CESMRRichTextLink& aSelectedLink ) |
|
176 { |
|
177 FUNC_LOG; |
|
178 |
|
179 TInt attachmentIndex( ResolveAttachmentIndexL( aSelectedLink.Value() ) ); |
|
180 HandleAttachmentCommandInternalL( aCommandId, attachmentIndex ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CMRAttachmentCommandHandler::IsRemoteAttachmentL |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TBool CMRAttachmentCommandHandler::IsRemoteAttachmentL( |
|
188 const CESMRRichTextLink& aSelectedLink ) |
|
189 { |
|
190 FUNC_LOG; |
|
191 |
|
192 TInt index = ResolveAttachmentIndexL( aSelectedLink.Value() ); |
|
193 |
|
194 CCalAttachment* attachment = iEntry.AttachmentL( index ); |
|
195 |
|
196 TBool remoteAttachment( ETrue ); |
|
197 |
|
198 if ( CCalAttachment::EFile == attachment->Type() ) |
|
199 { |
|
200 remoteAttachment = EFalse; |
|
201 } |
|
202 |
|
203 return remoteAttachment; |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 void CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL( |
|
211 CCalRemoteAttachmentApi& aRemoteAttaApi, |
|
212 CCalRemoteAttachmentInfo& aAttachmentInfo ) |
|
213 { |
|
214 FUNC_LOG; |
|
215 |
|
216 iRemoteAttachmentApi = &aRemoteAttaApi; |
|
217 iAttachmentInfo = &aAttachmentInfo; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 // CMRAttachmentCommandHandler::SetRemoteAttachmentInformationL |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 void CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandL( |
|
225 TInt aCommandId, |
|
226 const CESMRRichTextLink& aSelectedLink ) |
|
227 { |
|
228 FUNC_LOG; |
|
229 |
|
230 // Check that remote attachment information is being set |
|
231 __ASSERT_DEBUG( |
|
232 iRemoteAttachmentApi, |
|
233 Panic(EMRAttachmentCommandHandlerRemoteInfoNotSet) ); |
|
234 |
|
235 __ASSERT_DEBUG( |
|
236 iAttachmentInfo, |
|
237 Panic(EMRAttachmentCommandHandlerRemoteInfoNotSet) ); |
|
238 |
|
239 HandleRemoteAttachmentCommandInternalL( |
|
240 aCommandId, |
|
241 aSelectedLink.Value() ); |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------------------------- |
|
245 // CMRAttachmentCommandHandler::RemoteOperations |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 RPointerArray<MCalRemoteAttachmentOperation>& |
|
249 CMRAttachmentCommandHandler::RemoteOperations() |
|
250 { |
|
251 FUNC_LOG; |
|
252 return iDownloadOperations; |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // CMRAttachmentCommandHandler::CurrentCommandInProgress |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 TInt CMRAttachmentCommandHandler::CurrentCommandInProgress() const |
|
260 { |
|
261 FUNC_LOG; |
|
262 |
|
263 return iCommandInProgress; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CMRAttachmentCommandHandler::Progress |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void CMRAttachmentCommandHandler::Progress( |
|
271 MCalRemoteAttachmentOperation* aOperation, |
|
272 TInt aPercentageCompleted ) |
|
273 { |
|
274 FUNC_LOG; |
|
275 |
|
276 TRAP_IGNORE( NotifyProgressL( |
|
277 aOperation->AttachmentInformation().AttachmentLabel(), |
|
278 aPercentageCompleted )); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // CMRAttachmentCommandHandler::OperationCompleted |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 void CMRAttachmentCommandHandler::OperationCompleted( |
|
286 MCalRemoteAttachmentOperation* aOperation, |
|
287 RFile& aAttachment ) |
|
288 { |
|
289 FUNC_LOG; |
|
290 |
|
291 TRAP_IGNORE( HandleOperationCompletedL( aOperation, aAttachment ) ); |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------------------------- |
|
295 // CMRAttachmentCommandHandler::OperationError |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 void CMRAttachmentCommandHandler::OperationError( |
|
299 MCalRemoteAttachmentOperation* /*aOperation*/, |
|
300 TInt aErrorCode ) |
|
301 { |
|
302 FUNC_LOG; |
|
303 |
|
304 // Operation failed or cancelled, hide download indicator |
|
305 TRAP_IGNORE( HideDownloadIndicatorL() ); |
|
306 iCommandInProgress = 0; |
|
307 |
|
308 if ( aErrorCode != KErrCancel ) |
|
309 { |
|
310 // Operation failed, show error note |
|
311 CCoeEnv::Static()->HandleError( aErrorCode ); |
|
312 } |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // CMRAttachmentCommandHandler::ResolveAttachmentIndexL |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 TInt CMRAttachmentCommandHandler::ResolveAttachmentIndexL( |
|
320 const TDesC& aAttachmentLabel ) |
|
321 { |
|
322 FUNC_LOG; |
|
323 |
|
324 TInt index( KErrNotFound ); |
|
325 |
|
326 TInt attachmentCount( iEntry.AttachmentCountL() ); |
|
327 for (TInt i(0); i < attachmentCount && KErrNotFound == index; ++i ) |
|
328 { |
|
329 CCalAttachment* attachment = iEntry.AttachmentL(i); |
|
330 |
|
331 TPtrC attachmentLabel( attachment->Label() ); |
|
332 if ( !aAttachmentLabel.Compare(attachmentLabel) ) |
|
333 { |
|
334 index = i; |
|
335 } |
|
336 } |
|
337 |
|
338 // Check that attachment is always found |
|
339 // If attachment is not found --> Our data is corrupted |
|
340 __ASSERT_DEBUG( |
|
341 KErrNotFound != index, |
|
342 Panic( EMRAttachmentCommandHandlerAttachmentNotFound) ); |
|
343 |
|
344 return index; |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 // CMRAttachmentCommandHandler::ResolveAttachmentIndexL |
|
349 // --------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CMRAttachmentCommandHandler::CommandIndex( |
|
352 const TDesC& aAttachmentLabel ) |
|
353 { |
|
354 FUNC_LOG; |
|
355 |
|
356 TInt index( KErrNotFound ); |
|
357 |
|
358 TInt commandCount( iDownloadOperations.Count() ); |
|
359 for ( TInt i(0); i < commandCount && KErrNotFound == index; ++i ) |
|
360 { |
|
361 // There are download operations in progress |
|
362 const MCalRemoteAttachment& attachInfo = |
|
363 iDownloadOperations[i]->AttachmentInformation(); |
|
364 |
|
365 TPtrC label( attachInfo.AttachmentLabel() ); |
|
366 if ( !label.Compare( aAttachmentLabel ) ) |
|
367 { |
|
368 index = i; |
|
369 } |
|
370 } |
|
371 |
|
372 return index; |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------------------------- |
|
376 // CMRAttachmentCommandHandler::RemoteAttachmentIndex |
|
377 // --------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CMRAttachmentCommandHandler::RemoteAttachmentIndexL( |
|
380 const TDesC& aAttachmentLabel ) |
|
381 { |
|
382 FUNC_LOG; |
|
383 |
|
384 TInt index( KErrNotFound ); |
|
385 |
|
386 TInt remoteAttCount( iAttachmentInfo->AttachmentCount() ); |
|
387 for ( TInt i(0); i < remoteAttCount && index == KErrNotFound; ++i ) |
|
388 { |
|
389 TPtrC remoteAttName( iAttachmentInfo->AttachmentL(i).AttachmentLabel() ); |
|
390 |
|
391 if ( !remoteAttName.Compare( aAttachmentLabel ) ) |
|
392 { |
|
393 index = i; |
|
394 } |
|
395 } |
|
396 |
|
397 return index; |
|
398 } |
|
399 |
|
400 // --------------------------------------------------------------------------- |
|
401 // CMRAttachmentCommandHandler::HandleOperationCompleted |
|
402 // --------------------------------------------------------------------------- |
|
403 // |
|
404 void CMRAttachmentCommandHandler::HandleOperationCompletedL( |
|
405 MCalRemoteAttachmentOperation* aOperation, |
|
406 RFile& aAttachment ) |
|
407 { |
|
408 FUNC_LOG; |
|
409 |
|
410 // Notify 'download ready' event |
|
411 CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( |
|
412 NULL, |
|
413 EMRCmdHideAttachmentIndicator ); |
|
414 |
|
415 iEventQueue.NotifyEventAsyncL( event ); |
|
416 |
|
417 CleanupStack::Pop( event ); |
|
418 |
|
419 // First search the correct operation from the list |
|
420 TInt operationIndex( CommandIndex(aOperation->AttachmentInformation().AttachmentLabel() ) ); |
|
421 |
|
422 __ASSERT_DEBUG( |
|
423 operationIndex != KErrNotFound, |
|
424 Panic( EMRAttachmentCommandHandlerRemoteCommandNotFound) ); |
|
425 |
|
426 // Resolve current download operation in progress |
|
427 MCalRemoteAttachmentOperation* operation = iDownloadOperations[ operationIndex ]; |
|
428 CleanupDeletePushL( operation ); |
|
429 iDownloadOperations.Remove( operationIndex ); |
|
430 |
|
431 TInt attachmentIndex( ResolveAttachmentIndexL( |
|
432 operation->AttachmentInformation().AttachmentLabel() ) ); |
|
433 |
|
434 if ( KErrNotFound == attachmentIndex ) |
|
435 { |
|
436 User::Leave( KErrNotFound ); |
|
437 } |
|
438 |
|
439 if ( EESMRViewerCancelAttachmentDownload != iCommandInProgress ) |
|
440 { |
|
441 // Update the remote attachment to be local attachment ... |
|
442 UpdateLocalAttachmentL( |
|
443 operation->AttachmentInformation().AttachmentLabel(), |
|
444 aAttachment, |
|
445 attachmentIndex ); |
|
446 } |
|
447 |
|
448 // Then execute normal local file attachment command |
|
449 if ( EESMRViewerOpenAttachment == iCommandInProgress || |
|
450 EESMRViewerSaveAttachment == iCommandInProgress || |
|
451 EESMRViewerSaveAllAttachments == iCommandInProgress ) |
|
452 { |
|
453 TInt attachmentIndex( |
|
454 ResolveAttachmentIndexL( |
|
455 operation->AttachmentInformation().AttachmentLabel() ) ); |
|
456 |
|
457 if ( EESMRViewerOpenAttachment == iCommandInProgress ) |
|
458 { |
|
459 // When opening attachment from remote storage --> Ask user to |
|
460 // save attachment first as well. |
|
461 HandleAttachmentCommandInternalL( |
|
462 EESMRViewerOpenAndSaveAttachment, attachmentIndex ); |
|
463 |
|
464 iCommandInProgress = 0; |
|
465 } |
|
466 else |
|
467 { |
|
468 HandleAttachmentCommandInternalL( |
|
469 EESMRViewerSaveAttachment, attachmentIndex ); |
|
470 |
|
471 if ( EESMRViewerSaveAllAttachments == iCommandInProgress ) |
|
472 { |
|
473 iCommandInProgress = 0; |
|
474 |
|
475 if ( iAttachmentInfo->AttachmentCount() > 0 ) |
|
476 { |
|
477 // There are more attachments to be downloaded --> Download next |
|
478 SaveNextRemoteAttachmentL(); |
|
479 } |
|
480 else |
|
481 { |
|
482 // All remote attachments have been saved. Show info note. |
|
483 ShowInfoNoteL( iEntry.AttachmentCountL() ); |
|
484 } |
|
485 } |
|
486 else |
|
487 { |
|
488 iCommandInProgress = 0; |
|
489 } |
|
490 } |
|
491 } |
|
492 |
|
493 CleanupStack::PopAndDestroy( operation ); |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------------------------- |
|
497 // CMRAttachmentCommandHandler::HandleAttachmentCommandInternalL |
|
498 // --------------------------------------------------------------------------- |
|
499 // |
|
500 void CMRAttachmentCommandHandler::HandleAttachmentCommandInternalL( |
|
501 TInt aCommandId, |
|
502 TInt aAttachmentIndex ) |
|
503 { |
|
504 FUNC_LOG; |
|
505 |
|
506 if ( iDownloadOperations.Count() ) |
|
507 { |
|
508 // Cancel ongoing remote operations ... |
|
509 iDownloadOperations.ResetAndDestroy(); |
|
510 } |
|
511 |
|
512 CMRAttachmentCommand* command = NULL; |
|
513 |
|
514 // Creating command |
|
515 switch ( aCommandId ) |
|
516 { |
|
517 case EESMRViewerOpenAttachment: |
|
518 case EESMREditorOpenAttachment: |
|
519 { |
|
520 command = CMROpenAttachmentCommand::NewL( *iDocHandler ); |
|
521 } |
|
522 break; |
|
523 case EESMREditorRemoveAttachment: |
|
524 case EESMREditorRemoveAllAttachments: |
|
525 { |
|
526 command = CMRRemoveAttachmentCommand::NewL(); |
|
527 } |
|
528 break; |
|
529 case EESMRViewerSaveAttachment: |
|
530 { |
|
531 command = CMRSaveAttachmentCommand::NewL( *iDocHandler ); |
|
532 } |
|
533 break; |
|
534 case EESMRViewerOpenAndSaveAttachment: |
|
535 { |
|
536 command = CMRSaveAndOpenAttachmentCommand::NewL( *iDocHandler ); |
|
537 } |
|
538 break; |
|
539 case EESMRViewerSaveAllAttachments: |
|
540 { |
|
541 SaveAllAttachmentsL(); |
|
542 } |
|
543 break; |
|
544 default: |
|
545 break; |
|
546 } |
|
547 |
|
548 if ( command ) |
|
549 { |
|
550 CleanupDeletePushL( command ); |
|
551 |
|
552 // Executing command. TRAP errors so cancellation can be handled |
|
553 // without an extra error note. |
|
554 TRAPD( error, |
|
555 ExecuteCommandL( aCommandId, *command, aAttachmentIndex ) ) |
|
556 |
|
557 if ( error != KErrCancel ) |
|
558 { |
|
559 User::LeaveIfError( error ); |
|
560 |
|
561 if ( aCommandId == EESMRViewerSaveAttachment |
|
562 && iCommandInProgress != EESMRViewerSaveAllAttachments ) |
|
563 { |
|
564 ShowInfoNoteL(); |
|
565 } |
|
566 } |
|
567 else // KErrCancel |
|
568 { |
|
569 iCommandInProgress = 0; |
|
570 } |
|
571 |
|
572 CleanupStack::PopAndDestroy( command ); |
|
573 } |
|
574 } |
|
575 |
|
576 // --------------------------------------------------------------------------- |
|
577 // CMRAttachmentCommandHandler::UpdateLocalAttachmentL |
|
578 // --------------------------------------------------------------------------- |
|
579 // |
|
580 void CMRAttachmentCommandHandler::UpdateLocalAttachmentL( |
|
581 const TDesC& aAttachmentLabel, |
|
582 RFile& aAttachment, |
|
583 TInt aAttachmentIndex ) |
|
584 { |
|
585 FUNC_LOG; |
|
586 |
|
587 // Create file attachment and add to calendar entry |
|
588 CCalAttachment* fileAttachment = CCalAttachment::NewFileL( aAttachment ); |
|
589 CleanupStack::PushL( fileAttachment ); |
|
590 |
|
591 RApaLsSession apaSession; |
|
592 TDataRecognitionResult dataType; |
|
593 User::LeaveIfError( apaSession.Connect() ); |
|
594 apaSession.RecognizeData( aAttachment, dataType ); |
|
595 apaSession.Close(); |
|
596 |
|
597 // set attachment properties |
|
598 TPtrC8 contentType( dataType.iDataType.Des8() ); |
|
599 |
|
600 if ( contentType.Length() ) |
|
601 { |
|
602 fileAttachment->SetMimeTypeL( contentType ); |
|
603 } |
|
604 else |
|
605 { |
|
606 fileAttachment->SetMimeTypeL( KUnknownDatatype ); |
|
607 } |
|
608 |
|
609 fileAttachment->SetLabelL( aAttachmentLabel ); |
|
610 iEntry.AddAttachmentL( *fileAttachment ); // calEntry takes ownership |
|
611 CleanupStack::Pop( fileAttachment ); |
|
612 |
|
613 // Remove remote attachment |
|
614 CCalAttachment* attachment = iEntry.AttachmentL( aAttachmentIndex ); |
|
615 iEntry.DeleteAttachmentL( *attachment ); |
|
616 attachment = NULL; |
|
617 |
|
618 TInt remoteAttachmentIndex( RemoteAttachmentIndexL( aAttachmentLabel ) ); |
|
619 if ( KErrNotFound != remoteAttachmentIndex ) |
|
620 { |
|
621 iAttachmentInfo->RemoveAttachmentAtL( remoteAttachmentIndex ); |
|
622 } |
|
623 } |
|
624 |
|
625 // --------------------------------------------------------------------------- |
|
626 // CMRAttachmentCommandHandler::NotifyProgressL |
|
627 // --------------------------------------------------------------------------- |
|
628 // |
|
629 void CMRAttachmentCommandHandler::NotifyProgressL( |
|
630 const TDesC& aAttachmentLabel, |
|
631 TInt aPercentageCompleted ) |
|
632 { |
|
633 FUNC_LOG; |
|
634 |
|
635 CDesCArray* descArray = new (ELeave) CDesCArrayFlat( 1 ); |
|
636 CleanupStack::PushL( descArray ); |
|
637 descArray->AppendL( aAttachmentLabel ); |
|
638 CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 ); |
|
639 CleanupStack::PushL( intArray ); |
|
640 intArray->AppendL( aPercentageCompleted ); |
|
641 |
|
642 HBufC* statusText = StringLoader::LoadL( |
|
643 R_QTN_MEET_REQ_ATTACHMENTS_DOWNLOAD_PREFIX, |
|
644 *descArray, |
|
645 *intArray ); |
|
646 |
|
647 CleanupStack::PushL( statusText ); |
|
648 |
|
649 // Create field change event |
|
650 CESMRGenericFieldEvent* event = CESMRGenericFieldEvent::NewLC( |
|
651 NULL, |
|
652 MESMRFieldEvent::EESMRFieldChangeEvent ); |
|
653 |
|
654 // Add this field as parameter |
|
655 TInt fieldId = EESMRFieldViewerAttachments; |
|
656 CESMRFieldEventValue* field = CESMRFieldEventValue::NewLC( |
|
657 MESMRFieldEventValue::EESMRInteger, |
|
658 &fieldId ); |
|
659 event->AddParamL( field ); |
|
660 CleanupStack::Pop( field ); |
|
661 |
|
662 // Add new value as parameter |
|
663 CESMRFieldEventValue* value = CESMRFieldEventValue::NewLC( |
|
664 CESMRFieldEventValue::EESMRString, |
|
665 statusText ); |
|
666 |
|
667 // Encapsulate value, so receiver gets the field value type |
|
668 event->AddParamL( value, ETrue ); |
|
669 CleanupStack::Pop( value ); |
|
670 |
|
671 // Send event |
|
672 iEventQueue.NotifyEventAsyncL( event ); |
|
673 CleanupStack::Pop( event ); |
|
674 |
|
675 // Ownership transferred to field event value |
|
676 CleanupStack::Pop( statusText ); |
|
677 CleanupStack::PopAndDestroy( intArray ); |
|
678 CleanupStack::PopAndDestroy( descArray ); |
|
679 } |
|
680 |
|
681 // --------------------------------------------------------------------------- |
|
682 // CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandInternalL |
|
683 // --------------------------------------------------------------------------- |
|
684 // |
|
685 void CMRAttachmentCommandHandler::HandleRemoteAttachmentCommandInternalL( |
|
686 TInt aCommandId, |
|
687 const TDesC& aRemoteAttachmentLabel ) |
|
688 { |
|
689 FUNC_LOG; |
|
690 |
|
691 // Fetch correct attachment from the entry |
|
692 TInt index = ResolveAttachmentIndexL( aRemoteAttachmentLabel ); |
|
693 CCalAttachment* attachment = iEntry.AttachmentL( index ); |
|
694 |
|
695 if ( CCalAttachment::EFile == attachment->Type() ) |
|
696 { |
|
697 // This is local attachment ... |
|
698 User::Leave( KErrArgument ); |
|
699 } |
|
700 |
|
701 switch ( aCommandId ) |
|
702 { |
|
703 case EESMRViewerOpenAttachment: |
|
704 case EESMRViewerSaveAttachment: |
|
705 { |
|
706 TInt remoteAttIndex( |
|
707 RemoteAttachmentIndexL( aRemoteAttachmentLabel ) ); |
|
708 |
|
709 RPointerArray<MCalRemoteAttachment> attachmentArray; |
|
710 CleanupClosePushL( attachmentArray ); |
|
711 const MCalRemoteAttachment& remoteAttachment( |
|
712 iAttachmentInfo->AttachmentL(remoteAttIndex) ); |
|
713 attachmentArray.Append( &remoteAttachment ); |
|
714 |
|
715 if ( !iCommandInProgress ) |
|
716 { |
|
717 // There are no ongoing command for this attachment |
|
718 // ==> We can start new one ... |
|
719 |
|
720 iCommandInProgress = aCommandId; |
|
721 |
|
722 // Before we can execute the actual command, we need to be sure |
|
723 // that attachments are being downloaded to device. |
|
724 iRemoteAttachmentApi->DownloadAttachmentsL( |
|
725 attachmentArray, |
|
726 iDownloadOperations, |
|
727 *this ); |
|
728 } |
|
729 |
|
730 CleanupStack::PopAndDestroy( &attachmentArray ); |
|
731 } |
|
732 break; |
|
733 |
|
734 case EESMRViewerCancelAttachmentDownload: |
|
735 { |
|
736 if ( EESMRViewerSaveAllAttachments == iCommandInProgress ) |
|
737 { |
|
738 iCommandInProgress = aCommandId; |
|
739 iDownloadOperations.ResetAndDestroy(); |
|
740 } |
|
741 else |
|
742 { |
|
743 // Cancelling is done by simply deleting the command |
|
744 iCommandInProgress = aCommandId; |
|
745 TInt remoteCommand( CommandIndex( |
|
746 aRemoteAttachmentLabel )); |
|
747 |
|
748 MCalRemoteAttachmentOperation* command = |
|
749 iDownloadOperations[remoteCommand]; |
|
750 |
|
751 iDownloadOperations.Remove( remoteCommand ); |
|
752 delete command; |
|
753 } |
|
754 } |
|
755 break; |
|
756 case EESMRViewerSaveAllAttachments: |
|
757 { |
|
758 SaveAllAttachmentsL(); |
|
759 } |
|
760 break; |
|
761 default: |
|
762 break; |
|
763 } |
|
764 } |
|
765 |
|
766 // --------------------------------------------------------------------------- |
|
767 // CMRAttachmentCommandHandler::HideDownloadIndicatorL |
|
768 // --------------------------------------------------------------------------- |
|
769 // |
|
770 void CMRAttachmentCommandHandler::HideDownloadIndicatorL() |
|
771 { |
|
772 FUNC_LOG; |
|
773 |
|
774 CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( |
|
775 NULL, |
|
776 EMRCmdHideAttachmentIndicator ); |
|
777 iEventQueue.NotifyEventAsyncL(event); |
|
778 CleanupStack::Pop(event); |
|
779 } |
|
780 |
|
781 // --------------------------------------------------------------------------- |
|
782 // CMRAttachmentCommandHandler::ExecuteCommandL |
|
783 // --------------------------------------------------------------------------- |
|
784 // |
|
785 void CMRAttachmentCommandHandler::ExecuteCommandL( |
|
786 TInt aCommandId, |
|
787 CMRAttachmentCommand& aCommand, |
|
788 TInt aAttachmentIndex ) |
|
789 { |
|
790 // Executing command |
|
791 switch ( aCommandId ) |
|
792 { |
|
793 case EESMREditorRemoveAllAttachments: |
|
794 { |
|
795 for( TInt i = iEntry.AttachmentCountL() ; i > 0; --i ) |
|
796 { |
|
797 aCommand.ExecuteAttachmentCommandL( iEntry, i - 1 ); |
|
798 } |
|
799 } |
|
800 case EESMRViewerSaveAllAttachments: |
|
801 { |
|
802 for( TInt i = 0; i < iEntry.AttachmentCountL(); ++i ) |
|
803 { |
|
804 aCommand.ExecuteAttachmentCommandL( iEntry, i ); |
|
805 } |
|
806 } |
|
807 break; |
|
808 default: |
|
809 { |
|
810 aCommand.ExecuteAttachmentCommandL( iEntry, aAttachmentIndex ); |
|
811 } |
|
812 break; |
|
813 } |
|
814 |
|
815 } |
|
816 |
|
817 // --------------------------------------------------------------------------- |
|
818 // CMRAttachmentCommandHandler::SaveAllAttachmentsL |
|
819 // --------------------------------------------------------------------------- |
|
820 // |
|
821 void CMRAttachmentCommandHandler::SaveAllAttachmentsL() |
|
822 { |
|
823 // Save local attachments |
|
824 CMRAttachmentCommand* command = |
|
825 CMRSaveAttachmentCommand::NewL( *iDocHandler ); |
|
826 |
|
827 TRAPD( error, |
|
828 ExecuteCommandL( EESMRViewerSaveAllAttachments, *command, 0 ) ) |
|
829 |
|
830 delete command; |
|
831 |
|
832 if ( error != KErrCancel ) |
|
833 { |
|
834 // Check if error happened during local attachment saving |
|
835 User::LeaveIfError( error ); |
|
836 |
|
837 // Proceed with remote attachments |
|
838 if ( iAttachmentInfo && iAttachmentInfo->AttachmentCount() > 0 ) |
|
839 { |
|
840 SaveNextRemoteAttachmentL(); |
|
841 } |
|
842 else // Show Save all info note |
|
843 { |
|
844 ShowInfoNoteL( iEntry.AttachmentCountL() ); |
|
845 } |
|
846 } |
|
847 } |
|
848 |
|
849 // --------------------------------------------------------------------------- |
|
850 // CMRAttachmentCommandHandler::SaveNextRemoteAttachmentL |
|
851 // --------------------------------------------------------------------------- |
|
852 // |
|
853 void CMRAttachmentCommandHandler::SaveNextRemoteAttachmentL() |
|
854 { |
|
855 __ASSERT_DEBUG( iAttachmentInfo->AttachmentCount() > 0, |
|
856 Panic( EMRAttachmentCommandHandlerRemoteAttachmentNotFound ) ); |
|
857 |
|
858 // Save first remote attachment of attachment info |
|
859 RPointerArray<MCalRemoteAttachment> attachmentArray; |
|
860 CleanupClosePushL( attachmentArray ); |
|
861 const MCalRemoteAttachment& remoteAttachment( |
|
862 iAttachmentInfo->AttachmentL( 0 ) ); |
|
863 attachmentArray.AppendL( &remoteAttachment ); |
|
864 |
|
865 if ( !iCommandInProgress ) |
|
866 { |
|
867 // There are no ongoing command for this attachment |
|
868 // ==> We can start new one ... |
|
869 iCommandInProgress = EESMRViewerSaveAllAttachments; |
|
870 |
|
871 // Before we can execute the actual command, we need to be sure |
|
872 // that attachments are being downloaded to device. |
|
873 iRemoteAttachmentApi->DownloadAttachmentsL( |
|
874 attachmentArray, |
|
875 iDownloadOperations, |
|
876 *this ); |
|
877 } |
|
878 |
|
879 CleanupStack::PopAndDestroy( &attachmentArray ); |
|
880 } |
|
881 |
|
882 // EOF |