|
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: |
|
15 * |
|
16 */ |
|
17 #include "nmframeworkadapterheaders.h" |
|
18 |
|
19 /*! |
|
20 \class NmFwaRemoveDraftMessageOperation |
|
21 |
|
22 \brief NmFwaRemoveDraftMessageOperation is an async operation which deletes a draft message. |
|
23 |
|
24 NmFwaRemoveDraftMessageOperation is an async operation which cdeletes a draft message. |
|
25 \sa NmOperation |
|
26 */ |
|
27 |
|
28 /*! |
|
29 Constructor |
|
30 |
|
31 \param message pointer to the message under sent, ownership is transferred to operation |
|
32 \param mailClient Reference to mail client object. |
|
33 */ |
|
34 NmFwaRemoveDraftMessageOperation::NmFwaRemoveDraftMessageOperation( |
|
35 NmDataPluginInterface &pluginInterface, |
|
36 NmMessage *message, |
|
37 CFSMailClient &mailClient) : |
|
38 mPluginInterface(pluginInterface), |
|
39 mMessage(message), |
|
40 mMailClient(mailClient), |
|
41 mRequestId(NmNotFoundError) |
|
42 { |
|
43 NM_FUNCTION; |
|
44 |
|
45 mMailClient.IncReferenceCount(); |
|
46 } |
|
47 |
|
48 /*! |
|
49 Destructor |
|
50 */ |
|
51 NmFwaRemoveDraftMessageOperation::~NmFwaRemoveDraftMessageOperation() |
|
52 { |
|
53 NM_FUNCTION; |
|
54 |
|
55 doCancelOperation(); |
|
56 mMailClient.Close(); // decrease ref count |
|
57 delete mMessage; |
|
58 mMessage = NULL; |
|
59 } |
|
60 |
|
61 /*! |
|
62 Called after base object construction via timer event, runs the |
|
63 async operation. |
|
64 |
|
65 \sa NmOperation |
|
66 */ |
|
67 void NmFwaRemoveDraftMessageOperation::doRunAsyncOperation() |
|
68 { |
|
69 NM_FUNCTION; |
|
70 |
|
71 TRAPD( err, removeMessageL() ); |
|
72 |
|
73 if (err != KErrNone) { |
|
74 completeOperation(NmGeneralError); |
|
75 } |
|
76 } |
|
77 |
|
78 /*! |
|
79 |
|
80 */ |
|
81 void NmFwaRemoveDraftMessageOperation::doCompleteOperation() |
|
82 { |
|
83 NM_FUNCTION; |
|
84 |
|
85 mRequestId = NmNotFoundError; |
|
86 } |
|
87 |
|
88 /*! |
|
89 |
|
90 */ |
|
91 void NmFwaRemoveDraftMessageOperation::doCancelOperation() |
|
92 { |
|
93 NM_FUNCTION; |
|
94 |
|
95 // remove draft operation is not cancellable |
|
96 } |
|
97 |
|
98 /*! |
|
99 Asynchronous request response message. |
|
100 |
|
101 \param aEvent Plugin event description. |
|
102 \param aRequestId Request id of asyncronous operation. |
|
103 */ |
|
104 void NmFwaRemoveDraftMessageOperation::RequestResponseL(TFSProgress aEvent, |
|
105 TInt aRequestId) |
|
106 { |
|
107 NM_FUNCTION; |
|
108 |
|
109 TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus; |
|
110 |
|
111 if (aRequestId == mRequestId) { |
|
112 if (status == TFSProgress::EFSStatus_RequestComplete && !aEvent.iError) { |
|
113 completeOperation(NmNoError); |
|
114 } |
|
115 else { |
|
116 completeOperation(NmGeneralError); |
|
117 } |
|
118 } |
|
119 } |
|
120 |
|
121 /*! |
|
122 Removes the message. |
|
123 */ |
|
124 void NmFwaRemoveDraftMessageOperation::removeMessageL() |
|
125 { |
|
126 NM_FUNCTION; |
|
127 |
|
128 TFSMailMsgId mailboxId( mMessage->envelope().mailboxId() ); |
|
129 TFSMailMsgId folderId( mMessage->envelope().folderId() ); |
|
130 TFSMailMsgId messageId( mMessage->envelope().messageId() ); |
|
131 |
|
132 CFSMailFolder* folder = mMailClient.GetFolderByUidL( mailboxId, folderId ); |
|
133 CleanupStack::PushL(folder); |
|
134 if ( folder ) { |
|
135 // try to use the asynchronous version first |
|
136 TRAPD(err, mRequestId = folder->RemoveMessageL( messageId, *this )); |
|
137 |
|
138 if(err == KErrFSMailPluginNotSupported) { |
|
139 // async version not supported, use sync version |
|
140 folder->RemoveMessageL( messageId ); |
|
141 completeOperation(NmNoError); |
|
142 } |
|
143 } |
|
144 else { |
|
145 User::Leave( KErrNotFound ); |
|
146 } |
|
147 CleanupStack::PopAndDestroy(folder); |
|
148 } |