|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <mmsvattachmentmanager.h> |
|
17 #include "CImAttachmentWaiter.h" |
|
18 #include "MIUTMSG.H" |
|
19 |
|
20 /** |
|
21 Allocates & Creates a new CImAttachmentWaiter object. |
|
22 @return A pointer to the newly created object |
|
23 */ |
|
24 EXPORT_C CImAttachmentWaiter* CImAttachmentWaiter::NewL() |
|
25 { |
|
26 CImAttachmentWaiter* self = new(ELeave) CImAttachmentWaiter(); |
|
27 return self; |
|
28 } |
|
29 |
|
30 /** |
|
31 Adds the attachment waiter active object to the active scheduler. |
|
32 */ |
|
33 CImAttachmentWaiter::CImAttachmentWaiter() |
|
34 : CActive(EPriorityStandard) |
|
35 { |
|
36 CActiveScheduler::Add(this); |
|
37 } |
|
38 |
|
39 /** |
|
40 Cancels the outstanding request. |
|
41 Frees all resources owned by the object prior to its destruction |
|
42 */ |
|
43 EXPORT_C CImAttachmentWaiter::~CImAttachmentWaiter() |
|
44 { |
|
45 Cancel(); |
|
46 if (iDeleteMessage) |
|
47 { |
|
48 delete iMailMessage; |
|
49 iMailMessage = NULL; |
|
50 } |
|
51 } |
|
52 |
|
53 /** |
|
54 Issues a waiting request for adding an attachment . |
|
55 |
|
56 @param aStatus The TRequestStatus to complete when request has completed. |
|
57 @param aMailMessage The CImEmailMessage pointer to which the attachment is to be added |
|
58 @param aDeleteMessage TBool indicating if the CImEmailMessage needs to be deleted when CImAttachmentWaiter is Reset or destroyed |
|
59 @leave KErrInUse |
|
60 */ |
|
61 EXPORT_C void CImAttachmentWaiter::StartWaitingL(TRequestStatus& aStatus, CImEmailMessage* aMailMessage, TBool aDeleteMessage) |
|
62 { |
|
63 if( IsActive() ) |
|
64 { |
|
65 aMailMessage->AttachmentManager().CancelRequest(); |
|
66 User::Leave(KErrInUse); |
|
67 } |
|
68 |
|
69 aStatus = KRequestPending; |
|
70 iReportStatus = &aStatus; |
|
71 iMailMessage = aMailMessage; |
|
72 iDeleteMessage = aDeleteMessage; |
|
73 SetActive(); |
|
74 } |
|
75 |
|
76 /** |
|
77 Resets the values. |
|
78 */ |
|
79 void CImAttachmentWaiter::Reset() |
|
80 { |
|
81 iReportStatus = NULL; |
|
82 if (iDeleteMessage) |
|
83 { |
|
84 delete iMailMessage; |
|
85 iMailMessage = NULL; |
|
86 } |
|
87 } |
|
88 |
|
89 void CImAttachmentWaiter::RunL() |
|
90 { |
|
91 User::RequestComplete(iReportStatus, iStatus.Int()); |
|
92 Reset(); |
|
93 } |
|
94 |
|
95 /** |
|
96 It cancels an outstanding request. |
|
97 */ |
|
98 void CImAttachmentWaiter::DoCancel() |
|
99 { |
|
100 iMailMessage->Cancel(); |
|
101 User::RequestComplete(iReportStatus, KErrCancel); |
|
102 Reset(); |
|
103 } |
|
104 |