|
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 /*! |
|
21 \class NmFwaMessageCreationOperation |
|
22 |
|
23 \brief NmFwaMessageCreationOperation is an async operation which creates a new message. |
|
24 |
|
25 NmFwaMessageCreationOperation is an async operation which creates a new message. |
|
26 \sa NmOperation |
|
27 */ |
|
28 |
|
29 /*! |
|
30 Constructor |
|
31 |
|
32 \param mailboxId Id of mailbox the message is to be created with. |
|
33 \param mailClient Reference to mail client object. |
|
34 */ |
|
35 NmFwaMessageCreationOperation::NmFwaMessageCreationOperation( |
|
36 const NmId &mailboxId, |
|
37 CFSMailClient &mailClient) : |
|
38 mMailboxId(mailboxId), |
|
39 mMessage(NULL), |
|
40 mMailClient(mailClient), |
|
41 mRequestId(NmNotFoundError) |
|
42 { |
|
43 NM_FUNCTION; |
|
44 } |
|
45 |
|
46 /*! |
|
47 Destructor |
|
48 */ |
|
49 NmFwaMessageCreationOperation::~NmFwaMessageCreationOperation() |
|
50 { |
|
51 NM_FUNCTION; |
|
52 |
|
53 doCancelOperation(); |
|
54 delete mMessage; |
|
55 } |
|
56 |
|
57 /*! |
|
58 Called after base object construction via timer event, runs the async operation. |
|
59 |
|
60 \sa NmOperation |
|
61 */ |
|
62 void NmFwaMessageCreationOperation::doRunAsyncOperation() |
|
63 { |
|
64 NM_FUNCTION; |
|
65 |
|
66 const TFSMailMsgId mailMsgId(mMailboxId.pluginId32(), mMailboxId.id32()); |
|
67 |
|
68 CFSMailBox *mailBox = NULL; |
|
69 TRAP_IGNORE(mailBox = mMailClient.GetMailBoxByUidL(mailMsgId)); |
|
70 |
|
71 // Call the asynchronous version first. If it returns KErrNotSupported |
|
72 // then use the synchronous version. Thus a protocol plugin does not need |
|
73 // implement the asynchronous version if there is no hit to UI performance |
|
74 // or overall robustness when using the synchronous version. |
|
75 if (mailBox) { |
|
76 TRAPD(err, mRequestId = mailBox->CreateMessageToSendL(*this)); |
|
77 |
|
78 if (err == KErrFSMailPluginNotSupported) { |
|
79 CFSMailMessage *fsMessage = mailBox->CreateMessageToSend(); |
|
80 |
|
81 if (fsMessage) |
|
82 { |
|
83 mMessage = fsMessage->GetNmMessage(); |
|
84 |
|
85 delete fsMessage; |
|
86 fsMessage = NULL; |
|
87 completeOperation(NmNoError); |
|
88 } |
|
89 else |
|
90 { |
|
91 completeOperation(NmNotFoundError); |
|
92 } |
|
93 } |
|
94 else if (err != KErrNone) |
|
95 { |
|
96 completeOperation(NmGeneralError); |
|
97 } |
|
98 |
|
99 delete mailBox; |
|
100 mailBox = NULL; |
|
101 } |
|
102 else { |
|
103 completeOperation(NmNotFoundError); |
|
104 } |
|
105 } |
|
106 |
|
107 /*! |
|
108 * Complete the operation |
|
109 */ |
|
110 void NmFwaMessageCreationOperation::doCompleteOperation() |
|
111 { |
|
112 NM_FUNCTION; |
|
113 |
|
114 mRequestId = NmNotFoundError; |
|
115 } |
|
116 |
|
117 /*! |
|
118 Cancels the async operation. \sa NmOperation |
|
119 */ |
|
120 void NmFwaMessageCreationOperation::doCancelOperation() |
|
121 { |
|
122 NM_FUNCTION; |
|
123 |
|
124 if (mRequestId >= 0) { |
|
125 TRAP_IGNORE(mMailClient.CancelL(mRequestId)); |
|
126 mRequestId = NmNotFoundError; |
|
127 } |
|
128 } |
|
129 |
|
130 /*! |
|
131 Returns the message created by the operation, or null if the operation has not |
|
132 completed, ownership is transferred to caller and following calls will return null. |
|
133 |
|
134 \return NmMessage* The new message. |
|
135 */ |
|
136 NmMessage *NmFwaMessageCreationOperation::getMessage() |
|
137 { |
|
138 NM_FUNCTION; |
|
139 |
|
140 // Ownership changes |
|
141 NmMessage *ret = mMessage; |
|
142 mMessage = NULL; |
|
143 return ret; |
|
144 } |
|
145 |
|
146 /*! |
|
147 Returns the id of the message created by the operation, or NmId() if operation has not |
|
148 completed or ownership has already been transferred through getMessage(). |
|
149 |
|
150 \return NmId Id of the new message. |
|
151 */ |
|
152 NmId NmFwaMessageCreationOperation::getMessageId() |
|
153 { |
|
154 NM_FUNCTION; |
|
155 |
|
156 NmId messageId; |
|
157 |
|
158 if (mMessage) { |
|
159 messageId = mMessage->envelope().messageId(); |
|
160 } |
|
161 |
|
162 return messageId; |
|
163 } |
|
164 |
|
165 /*! |
|
166 Asynchronous request response message. |
|
167 |
|
168 \param aEvent Plugin event description. |
|
169 \param aRequestId Request id of asyncronous operation. |
|
170 */ |
|
171 void NmFwaMessageCreationOperation::RequestResponseL(TFSProgress aEvent, |
|
172 TInt aRequestId) |
|
173 { |
|
174 NM_FUNCTION; |
|
175 |
|
176 TFSProgress::TFSProgressStatus status = aEvent.iProgressStatus; |
|
177 |
|
178 if (aRequestId == mRequestId) { |
|
179 if (status == TFSProgress::EFSStatus_RequestComplete |
|
180 && aEvent.iParam) { |
|
181 |
|
182 CFSMailMessage *fsMessage = |
|
183 static_cast<CFSMailMessage *>(aEvent.iParam); |
|
184 |
|
185 mMessage = fsMessage->GetNmMessage(); |
|
186 |
|
187 delete fsMessage; |
|
188 fsMessage = NULL; |
|
189 |
|
190 completeOperation(NmNoError); |
|
191 } |
|
192 else if (status == TFSProgress::EFSStatus_RequestCancelled) { |
|
193 completeOperation(NmCancelError); |
|
194 } |
|
195 else { |
|
196 completeOperation(NmGeneralError); |
|
197 } |
|
198 } |
|
199 } |
|
200 |